crc_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #ifndef CRC_DRIVER_H
20 #define CRC_DRIVER_H
21 
24 #include <stddef.h>
25 #include "device_registers.h"
26 #include "status.h"
27 
34 /*******************************************************************************
35  * Variables
36  ******************************************************************************/
37 
38 /*******************************************************************************
39  * Definitions
40  ******************************************************************************/
41 
46 typedef enum
47 {
53 
54 #if defined(FEATURE_CRC_DRIVER_SOFT_POLYNOMIAL)
55 
59 typedef enum
60 {
61  CRC_BITS_16 = 0U,
64 
65 #elif defined(FEATURE_CRC_DRIVER_HARD_POLYNOMIAL)
66 
70 typedef enum
71 {
72  CRC_BITS_16_CCITT = 0U,
73  CRC_BITS_32 = 1U,
74  CRC_BITS_8 = 2U,
75 #if defined(FEATURE_CRC_BITS_8_H2F)
76  CRC_BITS_8_H2F = 3U
77 #endif
78 } crc_mode_polynomial_t;
79 #endif /* FEATURE_CRC_DRIVER_SOFT_POLYNOMIAL */
80 
85 typedef struct
86 {
87 #if defined(FEATURE_CRC_DRIVER_SOFT_POLYNOMIAL)
89  uint32_t polynomial;
92 #elif defined(FEATURE_CRC_DRIVER_HARD_POLYNOMIAL)
93  crc_mode_polynomial_t polynomial;
94  bool readTranspose;
95 #endif /* FEATURE_CRC_DRIVER_SOFT_POLYNOMIAL */
98  uint32_t seed;
100 
101 /*******************************************************************************
102  * API
103  ******************************************************************************/
109 #if defined(__cplusplus)
110 extern "C" {
111 #endif
112 
123 status_t CRC_DRV_Init(uint32_t instance,
124  const crc_user_config_t * userConfigPtr);
125 
134 status_t CRC_DRV_Deinit(uint32_t instance);
135 
151 uint32_t CRC_DRV_GetCrc32(uint32_t instance,
152  uint32_t data,
153  bool newSeed,
154  uint32_t seed);
155 
171 uint32_t CRC_DRV_GetCrc16(uint32_t instance,
172  uint16_t data,
173  bool newSeed,
174  uint32_t seed);
175 
191 uint32_t CRC_DRV_GetCrc8(uint32_t instance,
192  uint8_t data,
193  bool newSeed,
194  uint32_t seed);
195 
205 void CRC_DRV_WriteData(uint32_t instance,
206  const uint8_t * data,
207  uint32_t dataSize);
208 
217 uint32_t CRC_DRV_GetCrcResult(uint32_t instance);
218 
228 status_t CRC_DRV_Configure(uint32_t instance,
229  const crc_user_config_t * userConfigPtr);
230 
240 status_t CRC_DRV_GetConfig(uint32_t instance,
241  crc_user_config_t * const userConfigPtr);
242 
252 
255 #if defined(__cplusplus)
256 }
257 #endif
258 
261 #endif /* CRC_DRIVER_H */
262 /*******************************************************************************
263  * EOF
264  ******************************************************************************/
uint32_t CRC_DRV_GetCrc32(uint32_t instance, uint32_t data, bool newSeed, uint32_t seed)
Appends 32-bit data to the current CRC calculation and returns new result.
Definition: crc_driver.c:111
status_t CRC_DRV_Init(uint32_t instance, const crc_user_config_t *userConfigPtr)
Initializes the CRC module.
Definition: crc_driver.c:68
crc_bit_width_t
CRC bit width Implements : crc_bit_width_t_Class.
Definition: crc_driver.h:59
crc_transpose_t
CRC type of transpose of read write data Implements : crc_transpose_t_Class.
Definition: crc_driver.h:46
status_t CRC_DRV_Configure(uint32_t instance, const crc_user_config_t *userConfigPtr)
Configures the CRC module from a user configuration structure.
Definition: crc_driver.c:239
uint32_t polynomial
Definition: crc_driver.h:89
crc_transpose_t readTranspose
Definition: crc_driver.h:91
CRC configuration structure. Implements : crc_user_config_t_Class.
Definition: crc_driver.h:85
status_t CRC_DRV_GetConfig(uint32_t instance, crc_user_config_t *const userConfigPtr)
Get configures of the CRC module currently.
Definition: crc_driver.c:271
crc_bit_width_t crcWidth
Definition: crc_driver.h:88
uint32_t CRC_DRV_GetCrc8(uint32_t instance, uint8_t data, bool newSeed, uint32_t seed)
Appends 8-bit data to the current CRC calculation and returns new result.
Definition: crc_driver.c:172
uint32_t CRC_DRV_GetCrc16(uint32_t instance, uint16_t data, bool newSeed, uint32_t seed)
Appends 16-bit data to the current CRC calculation and returns new result.
Definition: crc_driver.c:142
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
bool complementChecksum
Definition: crc_driver.h:97
status_t CRC_DRV_Deinit(uint32_t instance)
Sets the default configuration.
Definition: crc_driver.c:91
status_t CRC_DRV_GetDefaultConfig(crc_user_config_t *const userConfigPtr)
Get default configures the CRC module for configuration structure.
Definition: crc_driver.c:303
crc_transpose_t writeTranspose
Definition: crc_driver.h:96
uint32_t CRC_DRV_GetCrcResult(uint32_t instance)
Returns the current result of the CRC calculation.
Definition: crc_driver.c:223
void CRC_DRV_WriteData(uint32_t instance, const uint8_t *data, uint32_t dataSize)
Appends a block of bytes to the current CRC calculation.
Definition: crc_driver.c:200