EFM32 Zero Gecko Software Documentation  efm32zg-doc-4.2.1
em_crc.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef __SILICON_LABS_EM_CRC_H__
34 #define __SILICON_LABS_EM_CRC_H__
35 
36 #include "em_device.h"
37 #if defined(CRC_COUNT) && (CRC_COUNT > 0)
38 
39 #include <stdint.h>
40 #include <stdbool.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /***************************************************************************/
51 /***************************************************************************/
56 /*******************************************************************************
57  ******************************** ENUMS ************************************
58  ******************************************************************************/
59 
61 typedef enum
62 {
64  crcWidth8 = CRC_CTRL_CRCWIDTH_CRCWIDTH8,
65 
67  crcWidth16 = CRC_CTRL_CRCWIDTH_CRCWIDTH16,
68 
70  crcWidth24 = CRC_CTRL_CRCWIDTH_CRCWIDTH24,
71 
73  crcWidth32 = CRC_CTRL_CRCWIDTH_CRCWIDTH32
74 } CRC_Width_TypeDef;
75 
76 
78 typedef enum
79 {
82  crcByteOrderNormal = CRC_CTRL_BYTEREVERSE_NORMAL,
83 
86  crcByteOrderReversed = CRC_CTRL_BYTEREVERSE_REVERSED
87 } CRC_ByteOrder_TypeDef;
88 
89 
91 typedef enum
92 {
94  crcBitOrderLSBFirst = CRC_CTRL_INPUTBITORDER_LSBFIRST,
95 
97  crcBitOrderMSBFirst = CRC_CTRL_INPUTBITORDER_MSBFIRST
98 } CRC_BitOrder_TypeDef;
99 
100 
102 typedef enum
103 {
106  crcBitReverseNormal = CRC_CTRL_BITREVERSE_NORMAL,
107 
110  crcBitReverseReversed = CRC_CTRL_BITREVERSE_REVERSED
111 } CRC_BitReverse_TypeDef;
112 
113 
114 /*******************************************************************************
115  ******************************* STRUCTS ***********************************
116  ******************************************************************************/
117 
119 typedef struct
120 {
122  CRC_Width_TypeDef crcWidth;
123 
137  uint32_t crcPoly;
138 
143  uint32_t initValue;
144 
150  uint8_t bitsPerWord;
151 
154  CRC_ByteOrder_TypeDef byteReverse;
155 
159  CRC_BitOrder_TypeDef inputBitOrder;
160 
166  CRC_BitReverse_TypeDef bitReverse;
167 
172  bool inputPadding;
173 
175  bool invInput;
176 
178  bool invOutput;
179 } CRC_Init_TypeDef;
180 
182 #define CRC_INIT_DEFAULT \
183 { \
184  crcWidth16, /* CRC width is 16 bits. */ \
185  0x00008408UL, /* Polynomial value of IEEE 802.15.4-2006. */ \
186  0x00000000UL, /* Initialization value. */ \
187  8U, /* 8 bits per word. */ \
188  crcByteOrderNormal, /* Byte order is normal. */ \
189  crcBitOrderLSBFirst, /* Bit order (TBD). */ \
190  crcBitReverseNormal, /* Bit order is not reversed on output. */ \
191  false, /* No zero-padding. */ \
192  false, /* Input is not inverted. */ \
193  false /* Output is not inverted. */ \
194 }
195 
196 
197 /*******************************************************************************
198  ****************************** PROTOTYPES *********************************
199  ******************************************************************************/
200 
201 void CRC_Init(CRC_Init_TypeDef const *init);
202 void CRC_Reset(void);
203 
204 /***************************************************************************/
217 __STATIC_INLINE void CRC_InitCommand(void)
218 {
219  CRC->CMD = CRC_CMD_INITIALIZE;
220 }
221 
222 
223 /***************************************************************************/
227 __STATIC_INLINE void CRC_InitValueSet(uint32_t initValue)
228 {
229  CRC->INIT = initValue;
230 }
231 
232 
233 /***************************************************************************/
245 __STATIC_INLINE void CRC_InputDataWrite(uint16_t data)
246 {
247  CRC->INPUTDATA = (uint32_t)data;
248 }
249 
250 
251 /***************************************************************************/
261 __STATIC_INLINE uint32_t CRC_DataRead(void)
262 {
263  return CRC->DATA;
264 }
265 
266 
267 /***************************************************************************/
279 __STATIC_INLINE bool CRC_BusyGet(void)
280 {
281  return (bool)((CRC->STATUS & _CRC_STATUS_BUSY_MASK)
282  >> _CRC_STATUS_BUSY_SHIFT);
283 }
284 
285 
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif /* defined(CRC_COUNT) && (CRC_COUNT > 0) */
294 #endif /* __SILICON_LABS_EM_CRC_H__ */
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.