stm32f30x_crc.c
Go to the documentation of this file.
1 
55 /* Includes ------------------------------------------------------------------*/
56 #include "stm32f30x_crc.h"
57 
67 /* Private typedef -----------------------------------------------------------*/
68 /* Private define ------------------------------------------------------------*/
69 /* Private macro -------------------------------------------------------------*/
70 /* Private variables ---------------------------------------------------------*/
71 /* Private function prototypes -----------------------------------------------*/
72 /* Private functions ---------------------------------------------------------*/
73 
95 void CRC_DeInit(void)
96 {
97  /* Set DR register to reset value */
98  CRC->DR = 0xFFFFFFFF;
99  /* Set the POL register to the reset value: 0x04C11DB7 */
100  CRC->POL = 0x04C11DB7;
101  /* Reset IDR register */
102  CRC->IDR = 0x00;
103  /* Set INIT register to reset value */
104  CRC->INIT = 0xFFFFFFFF;
105  /* Reset the CRC calculation unit */
106  CRC->CR = CRC_CR_RESET;
107 }
108 
114 void CRC_ResetDR(void)
115 {
116  /* Reset CRC generator */
117  CRC->CR |= CRC_CR_RESET;
118 }
119 
130 void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize)
131 {
132  uint32_t tmpcr = 0;
133 
134  /* Check the parameter */
135  assert_param(IS_CRC_POL_SIZE(CRC_PolSize));
136 
137  /* Get CR register value */
138  tmpcr = CRC->CR;
139 
140  /* Reset POL_SIZE bits */
141  tmpcr &= (uint32_t)~((uint32_t)CRC_CR_POLSIZE);
142  /* Set the polynomial size */
143  tmpcr |= (uint32_t)CRC_PolSize;
144 
145  /* Write to CR register */
146  CRC->CR = (uint32_t)tmpcr;
147 }
148 
159 void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData)
160 {
161  uint32_t tmpcr = 0;
162 
163  /* Check the parameter */
164  assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData));
165 
166  /* Get CR register value */
167  tmpcr = CRC->CR;
168 
169  /* Reset REV_IN bits */
170  tmpcr &= (uint32_t)~((uint32_t)CRC_CR_REV_IN);
171  /* Set the reverse operation */
172  tmpcr |= (uint32_t)CRC_ReverseInputData;
173 
174  /* Write to CR register */
175  CRC->CR = (uint32_t)tmpcr;
176 }
177 
186 {
187  /* Check the parameters */
189 
190  if (NewState != DISABLE)
191  {
192  /* Enable reverse operation on output data */
193  CRC->CR |= CRC_CR_REV_OUT;
194  }
195  else
196  {
197  /* Disable reverse operation on output data */
198  CRC->CR &= (uint32_t)~((uint32_t)CRC_CR_REV_OUT);
199  }
200 }
201 
208 void CRC_SetInitRegister(uint32_t CRC_InitValue)
209 {
210  CRC->INIT = CRC_InitValue;
211 }
212 
218 void CRC_SetPolynomial(uint32_t CRC_Pol)
219 {
220  CRC->POL = CRC_Pol;
221 }
222 
244 uint32_t CRC_CalcCRC(uint32_t CRC_Data)
245 {
246  CRC->DR = CRC_Data;
247 
248  return (CRC->DR);
249 }
250 
256 uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data)
257 {
258  *(uint16_t*)(CRC_BASE) = (uint16_t) CRC_Data;
259 
260  return (CRC->DR);
261 }
262 
268 uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data)
269 {
270  *(uint8_t*)(CRC_BASE) = (uint8_t) CRC_Data;
271 
272  return (CRC->DR);
273 }
274 
281 uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
282 {
283  uint32_t index = 0;
284 
285  for(index = 0; index < BufferLength; index++)
286  {
287  CRC->DR = pBuffer[index];
288  }
289  return (CRC->DR);
290 }
291 
297 uint32_t CRC_GetCRC(void)
298 {
299  return (CRC->DR);
300 }
301 
323 void CRC_SetIDRegister(uint8_t CRC_IDValue)
324 {
325  CRC->IDR = CRC_IDValue;
326 }
327 
333 uint8_t CRC_GetIDRegister(void)
334 {
335  return (CRC->IDR);
336 }
337 
354 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
Computes the 32-bit CRC of a given buffer of data word(32-bit).
FunctionalState
Definition: stm32f4xx.h:708
uint8_t CRC_GetIDRegister(void)
Returns the 8-bit data stored in the Independent Data(ID) register.
void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize)
Selects the polynomial size.
void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData)
Selects the reverse operation to be performed on input data.
void CRC_SetIDRegister(uint8_t CRC_IDValue)
Stores an 8-bit data in the Independent Data(ID) register.
void assert_param(int val)
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data)
Computes the 8-bit CRC of a given 8-bit data.
uint32_t CRC_CalcCRC(uint32_t CRC_Data)
Computes the 32-bit CRC of a given data word(32-bit).
This file contains all the functions prototypes for the CRC firmware library.
void CRC_SetPolynomial(uint32_t CRC_Pol)
Initializes the polynomail coefficients.
#define IS_CRC_REVERSE_INPUT_DATA(DATA)
Definition: stm32f30x_crc.h:59
#define IS_CRC_POL_SIZE(SIZE)
Definition: stm32f30x_crc.h:76
uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data)
Computes the 16-bit CRC of a given 16-bit data.
void CRC_DeInit(void)
Deinitializes CRC peripheral registers to their default reset values.
Definition: stm32f30x_crc.c:95
#define CRC_CR_RESET
Definition: stm32f4xx.h:3868
#define CRC
Definition: stm32f4xx.h:2121
#define CRC_BASE
Definition: stm32f4xx.h:1970
void CRC_ReverseOutputDataCmd(FunctionalState NewState)
Enables or disable the reverse operation on output data. The reverse operation on output data is perf...
uint32_t CRC_GetCRC(void)
Returns the current CRC value.
void CRC_ResetDR(void)
Resets the CRC calculation unit and sets INIT register content in DR register.
void CRC_SetInitRegister(uint32_t CRC_InitValue)
Initializes the INIT register.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:48