EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
em_gpcrc.c
Go to the documentation of this file.
1 /***************************************************************************/
33 #include "em_gpcrc.h"
34 #include "em_assert.h"
35 
36 #if defined(GPCRC_PRESENT) && (GPCRC_COUNT > 0)
37 
38 /***************************************************************************/
43 /***************************************************************************/
48 /*******************************************************************************
49  *************************** GLOBAL FUNCTIONS ******************************
50  ******************************************************************************/
51 
52 /***************************************************************************/
73 void GPCRC_Init(GPCRC_TypeDef * gpcrc, const GPCRC_Init_TypeDef * init)
74 {
75  uint32_t polySelect;
76 
77  if (init->crcPoly == 0x04C11DB7)
78  {
79  polySelect = GPCRC_CTRL_POLYSEL_CRC32;
80  }
81  else
82  {
83  // If not using the fixed CRC-32 polynomial then we must be using 16-bit
84  EFM_ASSERT((init->crcPoly & 0xFFFF0000) == 0);
85  polySelect = GPCRC_CTRL_POLYSEL_16;
86  }
87 
88  gpcrc->CTRL = (((uint32_t)init->autoInit << _GPCRC_CTRL_AUTOINIT_SHIFT)
89  | ((uint32_t)init->reverseByteOrder << _GPCRC_CTRL_BYTEREVERSE_SHIFT)
90  | ((uint32_t)init->reverseBits << _GPCRC_CTRL_BITREVERSE_SHIFT)
91  | ((uint32_t)init->enableByteMode << _GPCRC_CTRL_BYTEMODE_SHIFT)
92  | polySelect
93  | ((uint32_t)init->enable << _GPCRC_CTRL_EN_SHIFT));
94 
95  if (polySelect == GPCRC_CTRL_POLYSEL_16)
96  {
97  // Set CRC polynomial value
98  uint32_t revPoly = __RBIT(init->crcPoly) >> 16;
99  gpcrc->POLY = revPoly & _GPCRC_POLY_POLY_MASK;
100  }
101 
102  // Load CRC initialization value to GPCRC_INIT
103  gpcrc->INIT = init->initValue;
104 }
105 
106 /***************************************************************************/
117 {
118  gpcrc->CTRL = _GPCRC_CTRL_RESETVALUE;
119  gpcrc->POLY = _GPCRC_POLY_RESETVALUE;
120  gpcrc->INIT = _GPCRC_INIT_RESETVALUE;
121 }
122 
126 #endif /* defined(GPCRC_COUNT) && (GPCRC_COUNT > 0) */
Emlib peripheral API "assert" implementation.
void GPCRC_Init(GPCRC_TypeDef *gpcrc, const GPCRC_Init_TypeDef *init)
Initialize the General Purpose Cyclic Redundancy Check (GPCRC) module.
Definition: em_gpcrc.c:73
void GPCRC_Reset(GPCRC_TypeDef *gpcrc)
Reset GPCRC registers to the hardware reset state.
Definition: em_gpcrc.c:116
#define _GPCRC_CTRL_BITREVERSE_SHIFT
General Purpose Cyclic Redundancy Check (GPCRC) API.
#define _GPCRC_CTRL_BYTEMODE_SHIFT
__IOM uint32_t INIT
uint32_t crcPoly
Definition: em_gpcrc.h:118
#define _GPCRC_INIT_RESETVALUE
#define _GPCRC_CTRL_EN_SHIFT
#define GPCRC_CTRL_POLYSEL_CRC32
__IOM uint32_t CTRL
#define _GPCRC_CTRL_RESETVALUE
#define _GPCRC_POLY_POLY_MASK
#define _GPCRC_POLY_RESETVALUE
#define _GPCRC_CTRL_BYTEREVERSE_SHIFT
#define GPCRC_CTRL_POLYSEL_16
#define _GPCRC_CTRL_AUTOINIT_SHIFT
__IOM uint32_t POLY
uint32_t initValue
Definition: em_gpcrc.h:126