Hal Drivers for L4

Dependents:   BSP OneHopeOnePrayer FINAL_AUDIO_RECORD AudioDemo

Fork of STM32L4xx_HAL_Driver by Senior Design: Sound Monitor

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_ll_crc.h Source File

stm32l4xx_ll_crc.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_ll_crc.h
00004   * @author  MCD Application Team
00005   * @version V1.1.0
00006   * @date    16-September-2015
00007   * @brief   Header file of CRC LL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_LL_CRC_H
00040 #define __STM32L4xx_LL_CRC_H
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx.h"
00048 
00049 /** @addtogroup STM32L4xx_LL_Driver
00050   * @{
00051   */
00052 
00053 #if defined (CRC)
00054 
00055 /** @defgroup CRC_LL CRC
00056   * @{
00057   */
00058 
00059 /* Private types -------------------------------------------------------------*/
00060 /* Private variables ---------------------------------------------------------*/
00061 /* Private constants ---------------------------------------------------------*/
00062 /* Private macros ------------------------------------------------------------*/
00063 
00064 /* Exported types ------------------------------------------------------------*/
00065 /* Exported constants --------------------------------------------------------*/
00066 /** @defgroup CRC_LL_Exported_Constants CRC Exported Constants
00067   * @{
00068   */
00069 
00070 /** @defgroup CRC_LL_EC_POLYLENGTH POLYLENGTH
00071   * @{
00072   */
00073 #define LL_CRC_POLYLENGTH_32B          (uint32_t)0x00000000                     /*!< 32 bits Polynomial size */
00074 #define LL_CRC_POLYLENGTH_16B          CRC_CR_POLYSIZE_0                        /*!< 16 bits Polynomial size */
00075 #define LL_CRC_POLYLENGTH_8B           CRC_CR_POLYSIZE_1                        /*!< 8 bits Polynomial size */
00076 #define LL_CRC_POLYLENGTH_7B           (CRC_CR_POLYSIZE_1 | CRC_CR_POLYSIZE_0)  /*!< 7 bits Polynomial size */
00077 /**
00078   * @}
00079   */
00080 
00081 /** @defgroup CRC_LL_EC_INDATA_REVERSE INDATA REVERSE
00082   * @{
00083   */
00084 #define LL_CRC_INDATA_REVERSE_NONE     (uint32_t)0x00000000                     /*!< Input Data bit order not affected */
00085 #define LL_CRC_INDATA_REVERSE_BYTE     CRC_CR_REV_IN_0                          /*!< Input Data bit reversal done by byte */
00086 #define LL_CRC_INDATA_REVERSE_HALFWORD CRC_CR_REV_IN_1                          /*!< Input Data bit reversal done by half-word */
00087 #define LL_CRC_INDATA_REVERSE_WORD     (CRC_CR_REV_IN_1 | CRC_CR_REV_IN_0)      /*!< Input Data bit reversal done by word */
00088 /**
00089   * @}
00090   */
00091 
00092 /** @defgroup CRC_LL_EC_OUTDATA_REVERSE OUTDATA REVERSE
00093   * @{
00094   */
00095 #define LL_CRC_OUTDATA_REVERSE_NONE    (uint32_t)0x00000000                      /*!< Output Data bit order not affected */
00096 #define LL_CRC_OUTDATA_REVERSE_BIT     CRC_CR_REV_OUT                            /*!< Output Data bit reversal done by bit */
00097 /**
00098   * @}
00099   */
00100 
00101 /** @defgroup CRC_LL_EC_Default_Polynomial_Value    Default CRC generating polynomial value
00102   * @brief    Normal representation of this polynomial value is 
00103   *           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 .
00104   * @{
00105   */
00106 #define LL_CRC_DEFAULT_CRC32_POLY      0x04C11DB7                                /*!< Default CRC generating polynomial value */
00107 /**
00108   * @}
00109   */
00110 
00111 /** @defgroup CRC_LL_EC_Default_InitValue    Default CRC computation initialization value
00112   * @{
00113   */
00114 #define LL_CRC_DEFAULT_CRC_INITVALUE   0xFFFFFFFF                                /*!< Default CRC computation initialization value */
00115 /**
00116   * @}
00117   */
00118 
00119 /**
00120   * @}
00121   */
00122 
00123 /* Exported macro ------------------------------------------------------------*/
00124 /** @defgroup CRC_LL_Exported_Macros CRC Exported Macros
00125   * @{
00126   */
00127 
00128 /** @defgroup CRC_LL_EM_WRITE_READ Common Write and read registers Macros
00129   * @{
00130   */
00131 /**
00132   * @brief  Write a value in CRC register
00133   * @param  __INSTANCE__ CRC Instance
00134   * @param  __REG__ Register to be written
00135   * @param  __VALUE__ Value to be written in the register
00136   * @retval None
00137   */
00138 #define LL_CRC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
00139 
00140 /**
00141   * @brief  Read a value in CRC register
00142   * @param  __INSTANCE__ CRC Instance
00143   * @param  __REG__ Register to be read
00144   * @retval Register value
00145   */
00146 #define LL_CRC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
00147 /**
00148   * @}
00149   */
00150 
00151 /**
00152   * @}
00153   */
00154 
00155 /* Exported functions --------------------------------------------------------*/
00156 /** @defgroup CRC_LL_Exported_Functions CRC Exported Functions
00157   * @{
00158   */
00159 
00160 /** @defgroup CRC_LL_EF_Configuration CRC Configuration functions
00161   * @{
00162   */
00163 
00164 /**
00165   * @brief  Reset the CRC calculation unit.
00166   * 
00167   * @note   If Programmable Initial CRC value feature
00168   *         is available, also set the Data Register to the value stored in the
00169   *         CRC_INIT register, otherwise, reset Data Register to its default value.
00170   * @rmtoll CR           RESET         LL_CRC_ResetCRCCalculationUnit
00171   * @param  CRCx CRC Instance
00172   * @retval None
00173   */
00174 __STATIC_INLINE void LL_CRC_ResetCRCCalculationUnit(CRC_TypeDef *CRCx)
00175 {
00176   SET_BIT(CRCx->CR, CRC_CR_RESET);
00177 }
00178 
00179 /**
00180   * @brief  Configure size of the polynomial.
00181   * @rmtoll CR           POLYSIZE      LL_CRC_SetPolynomialSize
00182   * @param  CRCx CRC Instance
00183   * @param  PolySize This parameter can be one of the following values:
00184   *         @arg @ref LL_CRC_POLYLENGTH_32B
00185   *         @arg @ref LL_CRC_POLYLENGTH_16B
00186   *         @arg @ref LL_CRC_POLYLENGTH_8B
00187   *         @arg @ref LL_CRC_POLYLENGTH_7B
00188   * @retval None
00189   */
00190 __STATIC_INLINE void LL_CRC_SetPolynomialSize(CRC_TypeDef *CRCx, uint32_t PolySize)
00191 {
00192   MODIFY_REG(CRCx->CR, CRC_CR_POLYSIZE, PolySize);
00193 }
00194 
00195 /**
00196   * @brief  Return size of the polynomial.
00197   * @rmtoll CR           POLYSIZE      LL_CRC_GetPolynomialSize
00198   * @param  CRCx CRC Instance
00199   * @retval Returned value can be one of the following values:
00200   *         @arg @ref LL_CRC_POLYLENGTH_32B
00201   *         @arg @ref LL_CRC_POLYLENGTH_16B
00202   *         @arg @ref LL_CRC_POLYLENGTH_8B
00203   *         @arg @ref LL_CRC_POLYLENGTH_7B
00204   */
00205 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialSize(CRC_TypeDef *CRCx)
00206 {
00207   return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_POLYSIZE));
00208 }
00209 
00210 /**
00211   * @brief  Configure the reversal of the bit order of the input data
00212   * @rmtoll CR           REV_IN        LL_CRC_SetInputDataReverseMode
00213   * @param  CRCx CRC Instance
00214   * @param  ReverseMode This parameter can be one of the following values:
00215   *         @arg @ref LL_CRC_INDATA_REVERSE_NONE
00216   *         @arg @ref LL_CRC_INDATA_REVERSE_BYTE
00217   *         @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
00218   *         @arg @ref LL_CRC_INDATA_REVERSE_WORD
00219   * @retval None
00220   */
00221 __STATIC_INLINE void LL_CRC_SetInputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
00222 {
00223   MODIFY_REG(CRCx->CR, CRC_CR_REV_IN, ReverseMode);
00224 }
00225 
00226 /**
00227   * @brief  Return type of reversal for input data bit order
00228   * @rmtoll CR           REV_IN        LL_CRC_GetInputDataReverseMode
00229   * @param  CRCx CRC Instance
00230   * @retval Returned value can be one of the following values:
00231   *         @arg @ref LL_CRC_INDATA_REVERSE_NONE
00232   *         @arg @ref LL_CRC_INDATA_REVERSE_BYTE
00233   *         @arg @ref LL_CRC_INDATA_REVERSE_HALFWORD
00234   *         @arg @ref LL_CRC_INDATA_REVERSE_WORD
00235   */
00236 __STATIC_INLINE uint32_t LL_CRC_GetInputDataReverseMode(CRC_TypeDef *CRCx)
00237 {
00238   return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_IN));
00239 }
00240 
00241 /**
00242   * @brief  Configure the reversal of the bit order of the Output data
00243   * @rmtoll CR           REV_OUT       LL_CRC_SetOutputDataReverseMode
00244   * @param  CRCx CRC Instance
00245   * @param  ReverseMode This parameter can be one of the following values:
00246   *         @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
00247   *         @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
00248   * @retval None
00249   */
00250 __STATIC_INLINE void LL_CRC_SetOutputDataReverseMode(CRC_TypeDef *CRCx, uint32_t ReverseMode)
00251 {
00252   MODIFY_REG(CRCx->CR, CRC_CR_REV_OUT, ReverseMode);
00253 }
00254 
00255 /**
00256   * @brief  Configure the reversal of the bit order of the Output data
00257   * @rmtoll CR           REV_OUT       LL_CRC_GetOutputDataReverseMode
00258   * @param  CRCx CRC Instance
00259   * @retval Returned value can be one of the following values:
00260   *         @arg @ref LL_CRC_OUTDATA_REVERSE_NONE
00261   *         @arg @ref LL_CRC_OUTDATA_REVERSE_BIT
00262   */
00263 __STATIC_INLINE uint32_t LL_CRC_GetOutputDataReverseMode(CRC_TypeDef *CRCx)
00264 {
00265   return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_REV_OUT));
00266 }
00267 
00268 /**
00269   * @brief  Initialize the Programmable initial CRC value.
00270   * 
00271   * @note   If the CRC size is less than 32 bits, the least significant bits
00272   *         are used to write the correct value
00273   * @note   LL_CRC_DEFAULT_CRC_INITVALUE could be used as value for InitCrc parameter.
00274   * @rmtoll INIT         INIT          LL_CRC_SetInitialData
00275   * @param  CRCx CRC Instance
00276   * @param  InitCrc Value to be programmed in Programmable initial CRC value register
00277   * @retval None
00278   */
00279 __STATIC_INLINE void LL_CRC_SetInitialData(CRC_TypeDef *CRCx, uint32_t InitCrc)
00280 {
00281   WRITE_REG(CRCx->INIT, InitCrc);
00282 }
00283 
00284 /**
00285   * @brief  Return current Initial CRC value.
00286   * 
00287   * @note   If the CRC size is less than 32 bits, the least significant bits
00288   *         are used to read the correct value
00289   * @rmtoll INIT         INIT          LL_CRC_GetInitialData
00290   * @param  CRCx CRC Instance
00291   * @retval Value programmed in Programmable initial CRC value register
00292   */
00293 __STATIC_INLINE uint32_t LL_CRC_GetInitialData(CRC_TypeDef *CRCx)
00294 {
00295   return (uint32_t)(READ_REG(CRCx->INIT));
00296 }
00297 
00298 /**
00299   * @brief  Initialize the Programmable polynomial value
00300   *         (coefficients of the polynomial to be used for CRC calculation).
00301   * 
00302   * @note   LL_CRC_DEFAULT_CRC32_POLY could be used as value for PolynomCoef parameter.
00303   * @note   Please check Reference Manual and existing Errata Sheets,
00304   *         regarding possible limitations for Polynomial values usage.
00305   *         For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
00306   * @rmtoll POL          POL           LL_CRC_SetPolynomialCoef
00307   * @param  CRCx CRC Instance
00308   * @param  PolynomCoef Value to be programmed in Programmable Polynomial value register
00309   * @retval None
00310   */
00311 __STATIC_INLINE void LL_CRC_SetPolynomialCoef(CRC_TypeDef *CRCx, uint32_t PolynomCoef)
00312 {
00313   WRITE_REG(CRCx->POL, PolynomCoef);
00314 }
00315 
00316 /**
00317   * @brief  Return current Programmable polynomial value
00318   * @note   Please check Reference Manual and existing Errata Sheets,
00319   *         regarding possible limitations for Polynomial values usage.
00320   *         For example, for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65
00321   * @rmtoll POL          POL           LL_CRC_GetPolynomialCoef
00322   * @param  CRCx CRC Instance
00323   * @retval Value programmed in Programmable Polynomial value register
00324   */
00325 __STATIC_INLINE uint32_t LL_CRC_GetPolynomialCoef(CRC_TypeDef *CRCx)
00326 {
00327   return (uint32_t)(READ_REG(CRCx->POL));
00328 }
00329 
00330 /**
00331   * @}
00332   */
00333 
00334 /** @defgroup CRC_LL_EF_Data_Management Data_Management
00335   * @{
00336   */
00337 
00338 /**
00339   * @brief  Write given 32-bit data to the CRC calculator
00340   * @rmtoll DR           DR            LL_CRC_FeedData32
00341   * @param  CRCx CRC Instance
00342   * @param  InData 0 .. 0xFFFFFFFF : Value to be provided to CRC calculator.
00343   * @retval None
00344   */
00345 __STATIC_INLINE void LL_CRC_FeedData32(CRC_TypeDef *CRCx, uint32_t InData)
00346 {
00347   WRITE_REG(CRCx->DR, InData);
00348 }
00349 
00350 /**
00351   * @brief  Write given 16-bit data to the CRC calculator
00352   * @rmtoll DR           DR            LL_CRC_FeedData16
00353   * @param  CRCx CRC Instance
00354   * @param  InData 0 .. 0xFFFF : 16 bit value to be provided to CRC calculator.
00355   * @retval None
00356   */
00357 __STATIC_INLINE void LL_CRC_FeedData16(CRC_TypeDef *CRCx, uint16_t InData)
00358 {
00359   *(uint16_t __IO *)(&CRCx->DR) = (uint16_t) InData;
00360 }
00361 
00362 /**
00363   * @brief  Write given 8-bit data to the CRC calculator
00364   * @rmtoll DR           DR            LL_CRC_FeedData8
00365   * @param  CRCx CRC Instance
00366   * @param  InData 0 .. 0xFF : 8 bit value to be provided to CRC calculator.
00367   * @retval None
00368   */
00369 __STATIC_INLINE void LL_CRC_FeedData8(CRC_TypeDef *CRCx, uint8_t InData)
00370 {
00371   *(uint8_t __IO *)(&CRCx->DR) = (uint8_t) InData;
00372 }
00373 
00374 /**
00375   * @brief  Return current CRC calculation result. 32 bits value is returned.
00376   * @rmtoll DR           DR            LL_CRC_ReadData32
00377   * @param  CRCx CRC Instance
00378   * @retval Current CRC calculation result as stored in CRC_DR register (32 bits).
00379   */
00380 __STATIC_INLINE uint32_t LL_CRC_ReadData32(CRC_TypeDef *CRCx)
00381 {
00382   return (uint32_t)(READ_REG(CRCx->DR));
00383 }
00384 
00385 /**
00386   * @brief  Return current CRC calculation result. 16 bits value is returned.
00387   * @note   This function is expected to be used in a 16 bits CRC polynomial size context.
00388   * @rmtoll DR           DR            LL_CRC_ReadData16
00389   * @param  CRCx CRC Instance
00390   * @retval Current CRC calculation result as stored in CRC_DR register (16 bits).
00391   */
00392 __STATIC_INLINE uint16_t LL_CRC_ReadData16(CRC_TypeDef *CRCx)
00393 {
00394   return (uint16_t)READ_REG(CRCx->DR);
00395 
00396 }
00397 
00398 /**
00399   * @brief  Return current CRC calculation result. 8 bits value is returned.
00400   * @note   This function is expected to be used in a 8 bits CRC polynomial size context.
00401   * @rmtoll DR           DR            LL_CRC_ReadData8
00402   * @param  CRCx CRC Instance
00403   * @retval Current CRC calculation result as stored in CRC_DR register (8 bits).
00404   */
00405 __STATIC_INLINE uint8_t LL_CRC_ReadData8(CRC_TypeDef *CRCx)
00406 {
00407   return (uint8_t)READ_REG(CRCx->DR);
00408 }
00409 
00410 /**
00411   * @brief  Return current CRC calculation result. 7 bits value is returned.
00412   * @note   This function is expected to be used in a 7 bits CRC polynomial size context.
00413   * @rmtoll DR           DR            LL_CRC_ReadData7
00414   * @param  CRCx CRC Instance
00415   * @retval Current CRC calculation result as stored in CRC_DR register (7 bits).
00416   */
00417 __STATIC_INLINE uint8_t LL_CRC_ReadData7(CRC_TypeDef *CRCx)
00418 {
00419   return (uint8_t)(READ_REG(CRCx->DR) & 0x7F);
00420 }
00421 
00422 /**
00423   * @brief  Return data stored in the Independent Data(IDR) register.
00424   * 
00425   * @note   This register can be used as a temporary storage location for one byte.
00426   * @rmtoll IDR          IDR           LL_CRC_Read_IDR
00427   * @param  CRCx CRC Instance
00428   * @retval Value stored in CRC_IDR register (General-purpose 8-bit data register).
00429   */
00430 __STATIC_INLINE uint32_t LL_CRC_Read_IDR(CRC_TypeDef *CRCx)
00431 {
00432   return (uint32_t)(READ_REG(CRCx->IDR));
00433 }
00434 
00435 /**
00436   * @brief  Store data in the Independent Data(IDR) register.
00437   * 
00438   * @note   This register can be used as a temporary storage location for one byte.
00439   * @rmtoll IDR          IDR           LL_CRC_Write_IDR
00440   * @param  CRCx CRC Instance
00441   * @param  InData 0 .. 0xFF : Value to be stored in CRC_IDR register (General-purpose 8-bit data register).
00442   * @retval None
00443   */
00444 __STATIC_INLINE void LL_CRC_Write_IDR(CRC_TypeDef *CRCx, uint32_t InData)
00445 {
00446   *((uint8_t __IO *)(&CRCx->IDR)) = (uint8_t) InData;
00447 }
00448 
00449 /**
00450   * @}
00451   */
00452 
00453 
00454 /**
00455   * @}
00456   */
00457 
00458 /**
00459   * @}
00460   */
00461 
00462 #endif /* CRC */
00463 
00464 /**
00465   * @}
00466   */
00467 
00468 #ifdef __cplusplus
00469 }
00470 #endif
00471 
00472 #endif /* __STM32L4xx_LL_CRC_H */
00473 
00474 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
00475