before merging master
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Inc / stm32f7xx_ll_crc.h
blobf100cadd38aa07b6bcd1802f52f6cc7e9e95f579
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_ll_crc.h
4 * @author MCD Application Team
5 * @version V1.2.2
6 * @date 14-April-2017
7 * @brief Header file of CRC LL module.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F7xx_LL_CRC_H
40 #define __STM32F7xx_LL_CRC_H
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f7xx.h"
49 /** @addtogroup STM32F7xx_LL_Driver
50 * @{
53 #if defined(CRC)
55 /** @defgroup CRC_LL CRC
56 * @{
59 /* Private types -------------------------------------------------------------*/
60 /* Private variables ---------------------------------------------------------*/
61 /* Private constants ---------------------------------------------------------*/
62 /* Private macros ------------------------------------------------------------*/
64 /* Exported types ------------------------------------------------------------*/
65 /* Exported constants --------------------------------------------------------*/
66 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
67 * @{
70 /** @defgroup CRC_LL_EC_POLYLENGTH Polynomial length
71 * @{
73 #define LL_CRC_POLYLENGTH_32B 0x00000000U /*!< 32 bits Polynomial size */
74 #define LL_CRC_POLYLENGTH_16B CRC_CR_POLYSIZE_0 /*!< 16 bits Polynomial size */
75 #define LL_CRC_POLYLENGTH_8B CRC_CR_POLYSIZE_1 /*!< 8 bits Polynomial size */
76 #define LL_CRC_POLYLENGTH_7B (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0) /*!< 7 bits Polynomial size */
77 /**
78 * @}
81 /** @defgroup CRC_LL_EC_INDATA_REVERSE Input Data Reverse
82 * @{
84 #define LL_CRC_INDATA_REVERSE_NONE 0x00000000U /*!< Input Data bit order not affected */
85 #define LL_CRC_INDATA_REVERSE_BYTE CRC_CR_REV_IN_0 /*!< Input Data bit reversal done by byte */
86 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1 /*!< Input Data bit reversal done by half-word */
87 #define LL_CRC_INDATA_REVERSE_WORD (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0) /*!< Input Data bit reversal done by word */
88 /**
89 * @}
92 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE Output Data Reverse
93 * @{
95 #define LL_CRC_OUTDATA_REVERSE_NONE 0x00000000U /*!< Output Data bit order not affected */
96 #define LL_CRC_OUTDATA_REVERSE_BIT CRC_CR_REV_OUT /*!< Output Data bit reversal done by bit */
97 /**
98 * @}
101 /** @defgroup CRC_LL_EC_Default_Polynomial_Value Default CRC generating polynomial value
102 * @brief Normal representation of this polynomial value is
103 * 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 .
104 * @{
106 #define LL_CRC_DEFAULT_CRC32_POLY 0x04C11DB7U /*!< Default CRC generating polynomial value */
108 * @}
111 /** @defgroup CRC_LL_EC_Default_InitValue Default CRC computation initialization value
112 * @{
114 #define LL_CRC_DEFAULT_CRC_INITVALUE 0xFFFFFFFFU /*!< Default CRC computation initialization value */
116 * @}
120 * @}
123 /* Exported macro ------------------------------------------------------------*/
124 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
125 * @{
128 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
129 * @{
133 * @brief Write a value in CRC register
134 * @param __INSTANCE__ CRC Instance
135 * @param __REG__ Register to be written
136 * @param __VALUE__ Value to be written in the register
137 * @retval None
139 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
142 * @brief Read a value in CRC register
143 * @param __INSTANCE__ CRC Instance
144 * @param __REG__ Register to be read
145 * @retval Register value
147 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
149 * @}
153 * @}
157 /* Exported functions --------------------------------------------------------*/
158 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
159 * @{
162 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
163 * @{
167 * @brief Reset the CRC calculation unit.
168 * @note If Programmable Initial CRC value feature
169 * is available, also set the Data Register to the value stored in the
170 * CRC_INIT register, otherwise, reset Data Register to its default value.
171 * @rmtoll CR RESET LL_CRC_ResetCRCCalculationUnit
172 * @param CRCx CRC Instance
173 * @retval None
175 __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx)
177 SET_BIT(CRCx->CR, CRC_CR_RESET);
181 * @brief Configure size of the polynomial.
182 * @rmtoll CR POLYSIZE LL_CRC_SetPolynomialSize
183 * @param CRCx CRC Instance
184 * @param PolySize This parameter can be one of the following values:
185 * @arg @ref LL_CRC_POLYLENGTH_32B
186 * @arg @ref LL_CRC_POLYLENGTH_16B
187 * @arg @ref LL_CRC_POLYLENGTH_8B
188 * @arg @ref LL_CRC_POLYLENGTH_7B
189 * @retval None
191 __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize)
193 MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize);
197 * @brief Return size of the polynomial.
198 * @rmtoll CR POLYSIZE LL_CRC_GetPolynomialSize
199 * @param CRCx CRC Instance
200 * @retval Returned value can be one of the following values:
201 * @arg @ref LL_CRC_POLYLENGTH_32B
202 * @arg @ref LL_CRC_POLYLENGTH_16B
203 * @arg @ref LL_CRC_POLYLENGTH_8B
204 * @arg @ref LL_CRC_POLYLENGTH_7B
206 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx)
208 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE));
212 * @brief Configure the reversal of the bit order of the input data
213 * @rmtoll CR REV_IN LL_CRC_SetInputDataReverseMode
214 * @param CRCx CRC Instance
215 * @param ReverseMode This parameter can be one of the following values:
216 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
217 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
218 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
219 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
220 * @retval None
222 __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
224 MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode);
228 * @brief Return type of reversal for input data bit order
229 * @rmtoll CR REV_IN LL_CRC_GetInputDataReverseMode
230 * @param CRCx CRC Instance
231 * @retval Returned value can be one of the following values:
232 * @arg @ref LL_CRC_INDATA_REVERSE_NONE
233 * @arg @ref LL_CRC_INDATA_REVERSE_BYTE
234 * @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
235 * @arg @ref LL_CRC_INDATA_REVERSE_WORD
237 __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx)
239 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN));
243 * @brief Configure the reversal of the bit order of the Output data
244 * @rmtoll CR REV_OUT LL_CRC_SetOutputDataReverseMode
245 * @param CRCx CRC Instance
246 * @param ReverseMode This parameter can be one of the following values:
247 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
248 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
249 * @retval None
251 __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
253 MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode);
257 * @brief Configure the reversal of the bit order of the Output data
258 * @rmtoll CR REV_OUT LL_CRC_GetOutputDataReverseMode
259 * @param CRCx CRC Instance
260 * @retval Returned value can be one of the following values:
261 * @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
262 * @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
264 __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx)
266 return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT));
270 * @brief Initialize the Programmable initial CRC value.
271 * @note If the CRC size is less than 32 bits, the least significant bits
272 * are used to write the correct value
273 * @note LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
274 * @rmtoll INIT INIT LL_CRC_SetInitialData
275 * @param CRCx CRC Instance
276 * @param InitCrc Value to be programmed in Programmable initial CRC value register
277 * @retval None
279 __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc)
281 WRITE_REG(CRCx->INIT, InitCrc);
285 * @brief Return current Initial CRC value.
286 * @note If the CRC size is less than 32 bits, the least significant bits
287 * are used to read the correct value
288 * @rmtoll INIT INIT LL_CRC_GetInitialData
289 * @param CRCx CRC Instance
290 * @retval Value programmed in Programmable initial CRC value register
292 __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx)
294 return (uint32_t)(READ_REG(CRCx->INIT));
298 * @brief Initialize the Programmable polynomial value
299 * (coefficients of the polynomial to be used for CRC calculation).
300 * @note LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
301 * @note Please check Reference Manual and existing Errata Sheets,
302 * regarding possible limitations for Polynomial values usage.
303 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
304 * @rmtoll POL POL LL_CRC_SetPolynomialCoef
305 * @param CRCx CRC Instance
306 * @param PolynomCoef Value to be programmed in Programmable Polynomial value register
307 * @retval None
309 __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef)
311 WRITE_REG(CRCx->POL, PolynomCoef);
315 * @brief Return current Programmable polynomial value
316 * @note Please check Reference Manual and existing Errata Sheets,
317 * regarding possible limitations for Polynomial values usage.
318 * For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
319 * @rmtoll POL POL LL_CRC_GetPolynomialCoef
320 * @param CRCx CRC Instance
321 * @retval Value programmed in Programmable Polynomial value register
323 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx)
325 return (uint32_t)(READ_REG(CRCx->POL));
329 * @}
332 /** @defgroup CRC_LL_EF_Data_Management Data_Management
333 * @{
337 * @brief Write given 32-bit data to the CRC calculator
338 * @rmtoll DR DR LL_CRC_FeedData32
339 * @param CRCx CRC Instance
340 * @param InData value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFFFFFF
341 * @retval None
343 __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData)
345 WRITE_REG(CRCx->DR, InData);
349 * @brief Write given 16-bit data to the CRC calculator
350 * @rmtoll DR DR LL_CRC_FeedData16
351 * @param CRCx CRC Instance
352 * @param InData 16 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFFFF
353 * @retval None
355 __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)
357 *(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData;
361 * @brief Write given 8-bit data to the CRC calculator
362 * @rmtoll DR DR LL_CRC_FeedData8
363 * @param CRCx CRC Instance
364 * @param InData 8 bit value to be provided to CRC calculator between between Min_Data=0 and Max_Data=0xFF
365 * @retval None
367 __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData)
369 *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData;
373 * @brief Return current CRC calculation result. 32 bits value is returned.
374 * @rmtoll DR DR LL_CRC_ReadData32
375 * @param CRCx CRC Instance
376 * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
378 __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx)
380 return (uint32_t)(READ_REG(CRCx->DR));
384 * @brief Return current CRC calculation result. 16 bits value is returned.
385 * @note This function is expected to be used in a 16 bits CRC polynomial size context.
386 * @rmtoll DR DR LL_CRC_ReadData16
387 * @param CRCx CRC Instance
388 * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
390 __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx)
392 return (uint16_t)READ_REG(CRCx->DR);
396 * @brief Return current CRC calculation result. 8 bits value is returned.
397 * @note This function is expected to be used in a 8 bits CRC polynomial size context.
398 * @rmtoll DR DR LL_CRC_ReadData8
399 * @param CRCx CRC Instance
400 * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
402 __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx)
404 return (uint8_t)READ_REG(CRCx->DR);
408 * @brief Return current CRC calculation result. 7 bits value is returned.
409 * @note This function is expected to be used in a 7 bits CRC polynomial size context.
410 * @rmtoll DR DR LL_CRC_ReadData7
411 * @param CRCx CRC Instance
412 * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
414 __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx)
416 return (uint8_t)(READ_REG(CRCx->DR) & 0x7FU);
420 * @brief Return data stored in the Independent Data(IDR) register.
421 * @note This register can be used as a temporary storage location for one byte.
422 * @rmtoll IDR IDR LL_CRC_Read_IDR
423 * @param CRCx CRC Instance
424 * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register).
426 __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx)
428 return (uint32_t)(READ_REG(CRCx->IDR));
432 * @brief Store data in the Independent Data(IDR) register.
433 * @note This register can be used as a temporary storage location for one byte.
434 * @rmtoll IDR IDR LL_CRC_Write_IDR
435 * @param CRCx CRC Instance
436 * @param InData value to be stored in CRC_IDR register (8-bit) between between Min_Data=0 and Max_Data=0xFF
437 * @retval None
439 __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData)
441 *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData;
444 * @}
447 #if defined(USE_FULL_LL_DRIVER)
448 /** @defgroup CRC_LL_EF_Init Initialization and de-initialization functions
449 * @{
452 ErrorStatus LL_CRC_DeInit(CRC_TypeDef *CRCx);
455 * @}
457 #endif /* USE_FULL_LL_DRIVER */
460 * @}
464 * @}
467 #endif /* defined(CRC) */
470 * @}
473 #ifdef __cplusplus
475 #endif
477 #endif /* __STM32F7xx_LL_CRC_H */
479 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/