Updated and Validated
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Inc / stm32f3xx_ll_crc.h
blobb07d93a29f06ab7b49cde12204d56c56c7a49bd9
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_crc.h
4 * @author MCD Application Team
5 * @brief Header file of CRC LL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32F3xx_LL_CRC_H
38 #define __STM32F3xx_LL_CRC_H
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f3xx.h"
47 /** @addtogroup STM32F3xx_LL_Driver
48 * @{
51 #if defined(CRC)
53 /** @defgroup CRC_LL CRC
54 * @{
57 /* Private types -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
59 /* Private constants ---------------------------------------------------------*/
60 /* Private macros ------------------------------------------------------------*/
62 /* Exported types ------------------------------------------------------------*/
63 /* Exported constants --------------------------------------------------------*/
64 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
65 * @{
68 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
69 * @{
71 #define LL_CRC_POLYLENGTH_32B 0x00000000U /*!< 32 bits Polynomial size */
72 #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */
73 #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */
74 #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */
75 /**
76 * @}
79 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
80 * @{
82 #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
83 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
84 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
85 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
86 /**
87 * @}
90 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
91 * @{
93 #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
94 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
95 /**
96 * @}
99 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
100 * @brief Normal representation of this polynomial value is
101 * X^32 + X^26 + X^23 + X^22 + X^16 + X^12 + X^11 + X^10 +X^8 + X^7 + X^5 + X^4 + X^2 + X + 1 .
102 * @{
104 #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
106 * @}
109 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
110 * @{
112 #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
114 * @}
118 * @}
121 /* Exported macro ------------------------------------------------------------*/
122 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
123 * @{
126 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
127 * @{
131 * @brief Write a value in CRC register
132 * @param __INSTANCE__ CRC Instance
133 * @param __REG__ Register to be written
134 * @param __VALUE__ Value to be written in the register
135 * @retval None
137 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
140 * @brief Read a value in CRC register
141 * @param __INSTANCE__ CRC Instance
142 * @param __REG__ Register to be read
143 * @retval Register value
145 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
147 * @}
151 * @}
155 /* Exported functions --------------------------------------------------------*/
156 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
157 * @{
160 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
161 * @{
165 * @brief Reset the CRC calculation unit.
166 * @note If Programmable Initial CRC value feature
167 * is available, also set the Data Register to the value stored in the
168 * CRC_INIT register, otherwise, reset Data Register to its default value.
169 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
170 * @param CRCx CRC Instance
171 * @retval None
173 __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx)
175 SET_BIT(CRCx->CR, CRC_CR_RESET);
179 * @brief Configure size of the polynomial.
180 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize
181 * @param CRCx CRC Instance
182 * @param PolySize This parameter can be one of the following values:
183 * @arg @ref LL_CRC_POLYLENGTH_32B
184 * @arg @ref LL_CRC_POLYLENGTH_16B
185 * @arg @ref LL_CRC_POLYLENGTH_8B
186 * @arg @ref LL_CRC_POLYLENGTH_7B
187 * @retval None
189 __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize)
191 MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize);
195 * @brief Return size of the polynomial.
196 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize
197 * @param CRCx CRC Instance
198 * @retval Returned value can be one of the following values:
199 * @arg @ref LL_CRC_POLYLENGTH_32B
200 * @arg @ref LL_CRC_POLYLENGTH_16B
201 * @arg @ref LL_CRC_POLYLENGTH_8B
202 * @arg @ref LL_CRC_POLYLENGTH_7B
204 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx)
206 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE));
210 * @brief Configure the reversal of the bit order of the input data
211 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode
212 * @param CRCx CRC Instance
213 * @param ReverseMode This parameter can be one of the following values:
214 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
215 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
216 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
217 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
218 * @retval None
220 __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
222 MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode);
226 * @brief Return type of reversal for input data bit order
227 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode
228 * @param CRCx CRC Instance
229 * @retval Returned value can be one of the following values:
230 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
231 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
232 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
233 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
235 __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx)
237 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN));
241 * @brief Configure the reversal of the bit order of the Output data
242 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
243 * @param CRCx CRC Instance
244 * @param ReverseMode This parameter can be one of the following values:
245 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
246 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
247 * @retval None
249 __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
251 MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode);
255 * @brief Configure the reversal of the bit order of the Output data
256 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
257 * @param CRCx CRC Instance
258 * @retval Returned value can be one of the following values:
259 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
260 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
262 __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx)
264 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT));
268 * @brief Initialize the Programmable initial CRC value.
269 * @note If the CRC size is less than 32 bits, the least significant bits
270 * are used to write the correct value
271 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
272 * @rmtoll INIT INIT LL_CRC_SetInitialData
273 * @param CRCx CRC Instance
274 * @param InitCrc Value to be programmed in Programmable initial CRC value register
275 * @retval None
277 __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc)
279 WRITE_REG(CRCx->INIT, InitCrc);
283 * @brief Return current Initial CRC value.
284 * @note If the CRC size is less than 32 bits, the least significant bits
285 * are used to read the correct value
286 * @rmtoll INIT INIT LL_CRC_GetInitialData
287 * @param CRCx CRC Instance
288 * @retval Value programmed in Programmable initial CRC value register
290 __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx)
292 return (uint32_t)(READ_REG(CRCx->INIT));
296 * @brief Initialize the Programmable polynomial value
297 * (coefficients of the polynomial to be used for CRC calculation).
298 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
299 * @note Please check Reference Manual and existing Errata Sheets,
300 * regarding possible limitations for Polynomial values usage.
301 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
302 * @rmtoll POL POL LL_CRC_SetPolynomialCoef
303 * @param CRCx CRC Instance
304 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
305 * @retval None
307 __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef)
309 WRITE_REG(CRCx->POL, PolynomCoef);
313 * @brief Return current Programmable polynomial value
314 * @note Please check Reference Manual and existing Errata Sheets,
315 * regarding possible limitations for Polynomial values usage.
316 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
317 * @rmtoll POL POL LL_CRC_GetPolynomialCoef
318 * @param CRCx CRC Instance
319 * @retval Value programmed in Programmable Polynomial value register
321 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx)
323 return (uint32_t)(READ_REG(CRCx->POL));
327 * @}
330 /** @defgroup CRC_LL_EF_Data_Management Data_Management
331 * @{
335 * @brief Write given 32-bit data to the CRC calculator
336 * @rmtoll DR DR LL_CRC_FeedData32
337 * @param CRCx CRC Instance
338 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
339 * @retval None
341 __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData)
343 WRITE_REG(CRCx->DR, InData);
347 * @brief Write given 16-bit data to the CRC calculator
348 * @rmtoll DR DR LL_CRC_FeedData16
349 * @param CRCx CRC Instance
350 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
351 * @retval None
353 __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)
355 *(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData;
359 * @brief Write given 8-bit data to the CRC calculator
360 * @rmtoll DR DR LL_CRC_FeedData8
361 * @param CRCx CRC Instance
362 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
363 * @retval None
365 __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData)
367 *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData;
371 * @brief Return current CRC calculation result. 32 bits value is returned.
372 * @rmtoll DR DR LL_CRC_ReadData32
373 * @param CRCx CRC Instance
374 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
376 __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx)
378 return (uint32_t)(READ_REG(CRCx->DR));
382 * @brief Return current CRC calculation result. 16 bits value is returned.
383 * @note This function is expected to be used in a 16 bits CRC polynomial size context.
384 * @rmtoll DR DR LL_CRC_ReadData16
385 * @param CRCx CRC Instance
386 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
388 __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx)
390 return (uint16_t)READ_REG(CRCx->DR);
394 * @brief Return current CRC calculation result. 8 bits value is returned.
395 * @note This function is expected to be used in a 8 bits CRC polynomial size context.
396 * @rmtoll DR DR LL_CRC_ReadData8
397 * @param CRCx CRC Instance
398 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
400 __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx)
402 return (uint8_t)READ_REG(CRCx->DR);
406 * @brief Return current CRC calculation result. 7 bits value is returned.
407 * @note This function is expected to be used in a 7 bits CRC polynomial size context.
408 * @rmtoll DR DR LL_CRC_ReadData7
409 * @param CRCx CRC Instance
410 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
412 __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx)
414 return (uint8_t)(READ_REG(CRCx->DR) & 0x7FU);
418 * @brief Return data stored in the Independent Data(IDR) register.
419 * @note This register can be used as a temporary storage location for one byte.
420 * @rmtoll IDR IDR LL_CRC_Read_IDR
421 * @param CRCx CRC Instance
422 * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register).
424 __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx)
426 return (uint32_t)(READ_REG(CRCx->IDR));
430 * @brief Store data in the Independent Data(IDR) register.
431 * @note This register can be used as a temporary storage location for one byte.
432 * @rmtoll IDR IDR LL_CRC_Write_IDR
433 * @param CRCx CRC Instance
434 * @param InData value to be stored in CRC_IDR register (8-bit) between between Min_Data=0 and Max_Data=0xFF
435 * @retval None
437 __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData)
439 *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData;
442 * @}
445 #if defined(USE_FULL_LL_DRIVER)
446 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
447 * @{
450 ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx);
453 * @}
455 #endif /* USE_FULL_LL_DRIVER */
458 * @}
462 * @}
465 #endif /* defined(CRC) */
468 * @}
471 #ifdef __cplusplus
473 #endif
475 #endif /* __STM32F3xx_LL_CRC_H */
477 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/