S32 SDK
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 /* Default CRC write transpose */
42 #define CRC_DEFAULT_WRITE_TRANSPOSE CRC_TRANSPOSE_NONE
43 /* Default seed value is 0xFFFFU */
44 #define CRC_DEFAULT_SEED (0xFFFFU)
45 
50 typedef enum
51 {
57 
58 #if defined(FEATURE_CRC_DRIVER_S32K1xx)
59 
63 typedef enum
64 {
65  CRC_BITS_16 = 0U,
66  CRC_BITS_32 = 1U
67 } crc_bit_width_t;
68 
69 #elif defined(FEATURE_CRC_DRIVER_MPC57xx)
70 
74 typedef enum
75 {
76  CRC_BITS_16_CCITT = 0U,
77  CRC_BITS_32 = 1U,
78  CRC_BITS_8 = 2U,
79  CRC_BITS_8_H2F = 3U
80 } crc_mode_polynomial_t;
81 #endif /* FEATURE_CRC_DRIVER_S32K1xx */
82 
87 typedef struct
88 {
89 #if defined(FEATURE_CRC_DRIVER_S32K1xx)
90  crc_bit_width_t crcWidth;
91  uint32_t polynomial;
93  crc_transpose_t readTranspose;
94 #elif defined(FEATURE_CRC_DRIVER_MPC57xx)
95  crc_mode_polynomial_t polynomial;
96  bool readTranspose;
97 #endif /* FEATURE_CRC_DRIVER_S32K1xx */
100  uint32_t seed;
102 
103 /*******************************************************************************
104  * API
105  ******************************************************************************/
111 #if defined(__cplusplus)
112 extern "C" {
113 #endif
114 
125 status_t CRC_DRV_Init(uint32_t instance,
126  const crc_user_config_t * userConfigPtr);
127 
136 status_t CRC_DRV_Deinit(uint32_t instance);
137 
153 uint32_t CRC_DRV_GetCrc32(uint32_t instance,
154  uint32_t data,
155  bool newSeed,
156  uint32_t seed);
157 
173 uint32_t CRC_DRV_GetCrc16(uint32_t instance,
174  uint16_t data,
175  bool newSeed,
176  uint32_t seed);
177 
193 uint32_t CRC_DRV_GetCrc8(uint32_t instance,
194  uint8_t data,
195  bool newSeed,
196  uint32_t seed);
197 
207 void CRC_DRV_WriteData(uint32_t instance,
208  const uint8_t * data,
209  uint32_t dataSize);
210 
219 uint32_t CRC_DRV_GetCrcResult(uint32_t instance);
220 
230 status_t CRC_DRV_Configure(uint32_t instance,
231  const crc_user_config_t * userConfigPtr);
232 
242 status_t CRC_DRV_GetConfig(uint32_t instance,
243  crc_user_config_t * const userConfigPtr);
244 
254 
257 #if defined(__cplusplus)
258 }
259 #endif
260 
263 #endif /* CRC_DRIVER_H */
264 /*******************************************************************************
265  * EOF
266  ******************************************************************************/
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_transpose_t
CRC type of transpose of read write data Implements : crc_transpose_t_Class.
Definition: crc_driver.h:50
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
CRC configuration structure. Implements : crc_user_config_t_Class.
Definition: crc_driver.h:87
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
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:99
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:98
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