mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_F303VC/stm32f30x_crc.c@157:90e3acc479a2, 2014-04-11 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Apr 11 17:15:06 2014 +0100
- Revision:
- 157:90e3acc479a2
Synchronized with git revision 6e20ca17847dceb62132bf3d8519876411e175bf
Full URL: https://github.com/mbedmicro/mbed/commit/6e20ca17847dceb62132bf3d8519876411e175bf/
[STM32F3-Discovery][DISCO_F303VC] initial port.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 157:90e3acc479a2 | 1 | /** |
mbed_official | 157:90e3acc479a2 | 2 | ****************************************************************************** |
mbed_official | 157:90e3acc479a2 | 3 | * @file stm32f30x_crc.c |
mbed_official | 157:90e3acc479a2 | 4 | * @author MCD Application Team |
mbed_official | 157:90e3acc479a2 | 5 | * @version V1.1.0 |
mbed_official | 157:90e3acc479a2 | 6 | * @date 27-February-2014 |
mbed_official | 157:90e3acc479a2 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 157:90e3acc479a2 | 8 | * functionalities of CRC computation unit peripheral: |
mbed_official | 157:90e3acc479a2 | 9 | * + Configuration of the CRC computation unit |
mbed_official | 157:90e3acc479a2 | 10 | * + CRC computation of one/many 32-bit data |
mbed_official | 157:90e3acc479a2 | 11 | * + CRC Independent register (IDR) access |
mbed_official | 157:90e3acc479a2 | 12 | * |
mbed_official | 157:90e3acc479a2 | 13 | @verbatim |
mbed_official | 157:90e3acc479a2 | 14 | |
mbed_official | 157:90e3acc479a2 | 15 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 16 | ##### How to use this driver ##### |
mbed_official | 157:90e3acc479a2 | 17 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 18 | [..] |
mbed_official | 157:90e3acc479a2 | 19 | (#) Enable CRC AHB clock using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE) |
mbed_official | 157:90e3acc479a2 | 20 | function. |
mbed_official | 157:90e3acc479a2 | 21 | (#) Select the polynomial size: 7-bit, 8-bit, 16-bit or 32-bit. |
mbed_official | 157:90e3acc479a2 | 22 | (#) Set the polynomial coefficients using CRC_SetPolynomial(); |
mbed_official | 157:90e3acc479a2 | 23 | (#) If required, select the reverse operation on input data |
mbed_official | 157:90e3acc479a2 | 24 | using CRC_ReverseInputDataSelect(); |
mbed_official | 157:90e3acc479a2 | 25 | (#) If required, enable the reverse operation on output data |
mbed_official | 157:90e3acc479a2 | 26 | using CRC_ReverseOutputDataCmd(Enable); |
mbed_official | 157:90e3acc479a2 | 27 | (#) If required, set the initialization remainder value using |
mbed_official | 157:90e3acc479a2 | 28 | CRC_SetInitRegister(); |
mbed_official | 157:90e3acc479a2 | 29 | (#) use CRC_CalcCRC() function to compute the CRC of a 32-bit data |
mbed_official | 157:90e3acc479a2 | 30 | or use CRC_CalcBlockCRC() function to compute the CRC if a 32-bit |
mbed_official | 157:90e3acc479a2 | 31 | data buffer. |
mbed_official | 157:90e3acc479a2 | 32 | |
mbed_official | 157:90e3acc479a2 | 33 | @endverbatim |
mbed_official | 157:90e3acc479a2 | 34 | |
mbed_official | 157:90e3acc479a2 | 35 | ****************************************************************************** |
mbed_official | 157:90e3acc479a2 | 36 | * @attention |
mbed_official | 157:90e3acc479a2 | 37 | * |
mbed_official | 157:90e3acc479a2 | 38 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 157:90e3acc479a2 | 39 | * |
mbed_official | 157:90e3acc479a2 | 40 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 157:90e3acc479a2 | 41 | * are permitted provided that the following conditions are met: |
mbed_official | 157:90e3acc479a2 | 42 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 157:90e3acc479a2 | 43 | * this list of conditions and the following disclaimer. |
mbed_official | 157:90e3acc479a2 | 44 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 157:90e3acc479a2 | 45 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 157:90e3acc479a2 | 46 | * and/or other materials provided with the distribution. |
mbed_official | 157:90e3acc479a2 | 47 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 157:90e3acc479a2 | 48 | * may be used to endorse or promote products derived from this software |
mbed_official | 157:90e3acc479a2 | 49 | * without specific prior written permission. |
mbed_official | 157:90e3acc479a2 | 50 | * |
mbed_official | 157:90e3acc479a2 | 51 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 157:90e3acc479a2 | 52 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 157:90e3acc479a2 | 53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 157:90e3acc479a2 | 54 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 157:90e3acc479a2 | 55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 157:90e3acc479a2 | 56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 157:90e3acc479a2 | 57 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 157:90e3acc479a2 | 58 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 157:90e3acc479a2 | 59 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 157:90e3acc479a2 | 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 157:90e3acc479a2 | 61 | * |
mbed_official | 157:90e3acc479a2 | 62 | ****************************************************************************** |
mbed_official | 157:90e3acc479a2 | 63 | */ |
mbed_official | 157:90e3acc479a2 | 64 | |
mbed_official | 157:90e3acc479a2 | 65 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 66 | #include "stm32f30x_crc.h" |
mbed_official | 157:90e3acc479a2 | 67 | |
mbed_official | 157:90e3acc479a2 | 68 | /** @addtogroup STM32F30x_StdPeriph_Driver |
mbed_official | 157:90e3acc479a2 | 69 | * @{ |
mbed_official | 157:90e3acc479a2 | 70 | */ |
mbed_official | 157:90e3acc479a2 | 71 | |
mbed_official | 157:90e3acc479a2 | 72 | /** @defgroup CRC |
mbed_official | 157:90e3acc479a2 | 73 | * @brief CRC driver modules |
mbed_official | 157:90e3acc479a2 | 74 | * @{ |
mbed_official | 157:90e3acc479a2 | 75 | */ |
mbed_official | 157:90e3acc479a2 | 76 | |
mbed_official | 157:90e3acc479a2 | 77 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 78 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 79 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 80 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 81 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 82 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 157:90e3acc479a2 | 83 | |
mbed_official | 157:90e3acc479a2 | 84 | /** @defgroup CRC_Private_Functions |
mbed_official | 157:90e3acc479a2 | 85 | * @{ |
mbed_official | 157:90e3acc479a2 | 86 | */ |
mbed_official | 157:90e3acc479a2 | 87 | |
mbed_official | 157:90e3acc479a2 | 88 | /** @defgroup CRC_Group1 Configuration of the CRC computation unit functions |
mbed_official | 157:90e3acc479a2 | 89 | * @brief Configuration of the CRC computation unit functions |
mbed_official | 157:90e3acc479a2 | 90 | * |
mbed_official | 157:90e3acc479a2 | 91 | @verbatim |
mbed_official | 157:90e3acc479a2 | 92 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 93 | ##### CRC configuration functions ##### |
mbed_official | 157:90e3acc479a2 | 94 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 95 | |
mbed_official | 157:90e3acc479a2 | 96 | @endverbatim |
mbed_official | 157:90e3acc479a2 | 97 | * @{ |
mbed_official | 157:90e3acc479a2 | 98 | */ |
mbed_official | 157:90e3acc479a2 | 99 | |
mbed_official | 157:90e3acc479a2 | 100 | /** |
mbed_official | 157:90e3acc479a2 | 101 | * @brief Deinitializes CRC peripheral registers to their default reset values. |
mbed_official | 157:90e3acc479a2 | 102 | * @param None |
mbed_official | 157:90e3acc479a2 | 103 | * @retval None |
mbed_official | 157:90e3acc479a2 | 104 | */ |
mbed_official | 157:90e3acc479a2 | 105 | void CRC_DeInit(void) |
mbed_official | 157:90e3acc479a2 | 106 | { |
mbed_official | 157:90e3acc479a2 | 107 | /* Set DR register to reset value */ |
mbed_official | 157:90e3acc479a2 | 108 | CRC->DR = 0xFFFFFFFF; |
mbed_official | 157:90e3acc479a2 | 109 | /* Set the POL register to the reset value: 0x04C11DB7 */ |
mbed_official | 157:90e3acc479a2 | 110 | CRC->POL = 0x04C11DB7; |
mbed_official | 157:90e3acc479a2 | 111 | /* Reset IDR register */ |
mbed_official | 157:90e3acc479a2 | 112 | CRC->IDR = 0x00; |
mbed_official | 157:90e3acc479a2 | 113 | /* Set INIT register to reset value */ |
mbed_official | 157:90e3acc479a2 | 114 | CRC->INIT = 0xFFFFFFFF; |
mbed_official | 157:90e3acc479a2 | 115 | /* Reset the CRC calculation unit */ |
mbed_official | 157:90e3acc479a2 | 116 | CRC->CR = CRC_CR_RESET; |
mbed_official | 157:90e3acc479a2 | 117 | } |
mbed_official | 157:90e3acc479a2 | 118 | |
mbed_official | 157:90e3acc479a2 | 119 | /** |
mbed_official | 157:90e3acc479a2 | 120 | * @brief Resets the CRC calculation unit and sets INIT register content in DR register. |
mbed_official | 157:90e3acc479a2 | 121 | * @param None |
mbed_official | 157:90e3acc479a2 | 122 | * @retval None |
mbed_official | 157:90e3acc479a2 | 123 | */ |
mbed_official | 157:90e3acc479a2 | 124 | void CRC_ResetDR(void) |
mbed_official | 157:90e3acc479a2 | 125 | { |
mbed_official | 157:90e3acc479a2 | 126 | /* Reset CRC generator */ |
mbed_official | 157:90e3acc479a2 | 127 | CRC->CR |= CRC_CR_RESET; |
mbed_official | 157:90e3acc479a2 | 128 | } |
mbed_official | 157:90e3acc479a2 | 129 | |
mbed_official | 157:90e3acc479a2 | 130 | /** |
mbed_official | 157:90e3acc479a2 | 131 | * @brief Selects the polynomial size. |
mbed_official | 157:90e3acc479a2 | 132 | * @param CRC_PolSize: Specifies the polynomial size. |
mbed_official | 157:90e3acc479a2 | 133 | * This parameter can be: |
mbed_official | 157:90e3acc479a2 | 134 | * @arg CRC_PolSize_7: 7-bit polynomial for CRC calculation |
mbed_official | 157:90e3acc479a2 | 135 | * @arg CRC_PolSize_8: 8-bit polynomial for CRC calculation |
mbed_official | 157:90e3acc479a2 | 136 | * @arg CRC_PolSize_16: 16-bit polynomial for CRC calculation |
mbed_official | 157:90e3acc479a2 | 137 | * @arg CRC_PolSize_32: 32-bit polynomial for CRC calculation |
mbed_official | 157:90e3acc479a2 | 138 | * @retval None |
mbed_official | 157:90e3acc479a2 | 139 | */ |
mbed_official | 157:90e3acc479a2 | 140 | void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize) |
mbed_official | 157:90e3acc479a2 | 141 | { |
mbed_official | 157:90e3acc479a2 | 142 | uint32_t tmpcr = 0; |
mbed_official | 157:90e3acc479a2 | 143 | |
mbed_official | 157:90e3acc479a2 | 144 | /* Check the parameter */ |
mbed_official | 157:90e3acc479a2 | 145 | assert_param(IS_CRC_POL_SIZE(CRC_PolSize)); |
mbed_official | 157:90e3acc479a2 | 146 | |
mbed_official | 157:90e3acc479a2 | 147 | /* Get CR register value */ |
mbed_official | 157:90e3acc479a2 | 148 | tmpcr = CRC->CR; |
mbed_official | 157:90e3acc479a2 | 149 | |
mbed_official | 157:90e3acc479a2 | 150 | /* Reset POL_SIZE bits */ |
mbed_official | 157:90e3acc479a2 | 151 | tmpcr &= (uint32_t)~((uint32_t)CRC_CR_POLSIZE); |
mbed_official | 157:90e3acc479a2 | 152 | /* Set the polynomial size */ |
mbed_official | 157:90e3acc479a2 | 153 | tmpcr |= (uint32_t)CRC_PolSize; |
mbed_official | 157:90e3acc479a2 | 154 | |
mbed_official | 157:90e3acc479a2 | 155 | /* Write to CR register */ |
mbed_official | 157:90e3acc479a2 | 156 | CRC->CR = (uint32_t)tmpcr; |
mbed_official | 157:90e3acc479a2 | 157 | } |
mbed_official | 157:90e3acc479a2 | 158 | |
mbed_official | 157:90e3acc479a2 | 159 | /** |
mbed_official | 157:90e3acc479a2 | 160 | * @brief Selects the reverse operation to be performed on input data. |
mbed_official | 157:90e3acc479a2 | 161 | * @param CRC_ReverseInputData: Specifies the reverse operation on input data. |
mbed_official | 157:90e3acc479a2 | 162 | * This parameter can be: |
mbed_official | 157:90e3acc479a2 | 163 | * @arg CRC_ReverseInputData_No: No reverse operation is performed |
mbed_official | 157:90e3acc479a2 | 164 | * @arg CRC_ReverseInputData_8bits: reverse operation performed on 8 bits |
mbed_official | 157:90e3acc479a2 | 165 | * @arg CRC_ReverseInputData_16bits: reverse operation performed on 16 bits |
mbed_official | 157:90e3acc479a2 | 166 | * @arg CRC_ReverseInputData_32bits: reverse operation performed on 32 bits |
mbed_official | 157:90e3acc479a2 | 167 | * @retval None |
mbed_official | 157:90e3acc479a2 | 168 | */ |
mbed_official | 157:90e3acc479a2 | 169 | void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData) |
mbed_official | 157:90e3acc479a2 | 170 | { |
mbed_official | 157:90e3acc479a2 | 171 | uint32_t tmpcr = 0; |
mbed_official | 157:90e3acc479a2 | 172 | |
mbed_official | 157:90e3acc479a2 | 173 | /* Check the parameter */ |
mbed_official | 157:90e3acc479a2 | 174 | assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData)); |
mbed_official | 157:90e3acc479a2 | 175 | |
mbed_official | 157:90e3acc479a2 | 176 | /* Get CR register value */ |
mbed_official | 157:90e3acc479a2 | 177 | tmpcr = CRC->CR; |
mbed_official | 157:90e3acc479a2 | 178 | |
mbed_official | 157:90e3acc479a2 | 179 | /* Reset REV_IN bits */ |
mbed_official | 157:90e3acc479a2 | 180 | tmpcr &= (uint32_t)~((uint32_t)CRC_CR_REV_IN); |
mbed_official | 157:90e3acc479a2 | 181 | /* Set the reverse operation */ |
mbed_official | 157:90e3acc479a2 | 182 | tmpcr |= (uint32_t)CRC_ReverseInputData; |
mbed_official | 157:90e3acc479a2 | 183 | |
mbed_official | 157:90e3acc479a2 | 184 | /* Write to CR register */ |
mbed_official | 157:90e3acc479a2 | 185 | CRC->CR = (uint32_t)tmpcr; |
mbed_official | 157:90e3acc479a2 | 186 | } |
mbed_official | 157:90e3acc479a2 | 187 | |
mbed_official | 157:90e3acc479a2 | 188 | /** |
mbed_official | 157:90e3acc479a2 | 189 | * @brief Enables or disable the reverse operation on output data. |
mbed_official | 157:90e3acc479a2 | 190 | * The reverse operation on output data is performed on 32-bit. |
mbed_official | 157:90e3acc479a2 | 191 | * @param NewState: new state of the reverse operation on output data. |
mbed_official | 157:90e3acc479a2 | 192 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 157:90e3acc479a2 | 193 | * @retval None |
mbed_official | 157:90e3acc479a2 | 194 | */ |
mbed_official | 157:90e3acc479a2 | 195 | void CRC_ReverseOutputDataCmd(FunctionalState NewState) |
mbed_official | 157:90e3acc479a2 | 196 | { |
mbed_official | 157:90e3acc479a2 | 197 | /* Check the parameters */ |
mbed_official | 157:90e3acc479a2 | 198 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 157:90e3acc479a2 | 199 | |
mbed_official | 157:90e3acc479a2 | 200 | if (NewState != DISABLE) |
mbed_official | 157:90e3acc479a2 | 201 | { |
mbed_official | 157:90e3acc479a2 | 202 | /* Enable reverse operation on output data */ |
mbed_official | 157:90e3acc479a2 | 203 | CRC->CR |= CRC_CR_REV_OUT; |
mbed_official | 157:90e3acc479a2 | 204 | } |
mbed_official | 157:90e3acc479a2 | 205 | else |
mbed_official | 157:90e3acc479a2 | 206 | { |
mbed_official | 157:90e3acc479a2 | 207 | /* Disable reverse operation on output data */ |
mbed_official | 157:90e3acc479a2 | 208 | CRC->CR &= (uint32_t)~((uint32_t)CRC_CR_REV_OUT); |
mbed_official | 157:90e3acc479a2 | 209 | } |
mbed_official | 157:90e3acc479a2 | 210 | } |
mbed_official | 157:90e3acc479a2 | 211 | |
mbed_official | 157:90e3acc479a2 | 212 | /** |
mbed_official | 157:90e3acc479a2 | 213 | * @brief Initializes the INIT register. |
mbed_official | 157:90e3acc479a2 | 214 | * @note After resetting CRC calculation unit, CRC_InitValue is stored in DR register |
mbed_official | 157:90e3acc479a2 | 215 | * @param CRC_InitValue: Programmable initial CRC value |
mbed_official | 157:90e3acc479a2 | 216 | * @retval None |
mbed_official | 157:90e3acc479a2 | 217 | */ |
mbed_official | 157:90e3acc479a2 | 218 | void CRC_SetInitRegister(uint32_t CRC_InitValue) |
mbed_official | 157:90e3acc479a2 | 219 | { |
mbed_official | 157:90e3acc479a2 | 220 | CRC->INIT = CRC_InitValue; |
mbed_official | 157:90e3acc479a2 | 221 | } |
mbed_official | 157:90e3acc479a2 | 222 | |
mbed_official | 157:90e3acc479a2 | 223 | /** |
mbed_official | 157:90e3acc479a2 | 224 | * @brief Initializes the polynomail coefficients. |
mbed_official | 157:90e3acc479a2 | 225 | * @param CRC_Pol: Polynomial to be used for CRC calculation. |
mbed_official | 157:90e3acc479a2 | 226 | * @retval None |
mbed_official | 157:90e3acc479a2 | 227 | */ |
mbed_official | 157:90e3acc479a2 | 228 | void CRC_SetPolynomial(uint32_t CRC_Pol) |
mbed_official | 157:90e3acc479a2 | 229 | { |
mbed_official | 157:90e3acc479a2 | 230 | CRC->POL = CRC_Pol; |
mbed_official | 157:90e3acc479a2 | 231 | } |
mbed_official | 157:90e3acc479a2 | 232 | |
mbed_official | 157:90e3acc479a2 | 233 | /** |
mbed_official | 157:90e3acc479a2 | 234 | * @} |
mbed_official | 157:90e3acc479a2 | 235 | */ |
mbed_official | 157:90e3acc479a2 | 236 | |
mbed_official | 157:90e3acc479a2 | 237 | /** @defgroup CRC_Group2 CRC computation of one/many 32-bit data functions |
mbed_official | 157:90e3acc479a2 | 238 | * @brief CRC computation of one/many 32-bit data functions |
mbed_official | 157:90e3acc479a2 | 239 | * |
mbed_official | 157:90e3acc479a2 | 240 | @verbatim |
mbed_official | 157:90e3acc479a2 | 241 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 242 | ##### CRC computation functions ##### |
mbed_official | 157:90e3acc479a2 | 243 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 244 | |
mbed_official | 157:90e3acc479a2 | 245 | @endverbatim |
mbed_official | 157:90e3acc479a2 | 246 | * @{ |
mbed_official | 157:90e3acc479a2 | 247 | */ |
mbed_official | 157:90e3acc479a2 | 248 | |
mbed_official | 157:90e3acc479a2 | 249 | /** |
mbed_official | 157:90e3acc479a2 | 250 | * @brief Computes the 32-bit CRC of a given data word(32-bit). |
mbed_official | 157:90e3acc479a2 | 251 | * @param CRC_Data: data word(32-bit) to compute its CRC |
mbed_official | 157:90e3acc479a2 | 252 | * @retval 32-bit CRC |
mbed_official | 157:90e3acc479a2 | 253 | */ |
mbed_official | 157:90e3acc479a2 | 254 | uint32_t CRC_CalcCRC(uint32_t CRC_Data) |
mbed_official | 157:90e3acc479a2 | 255 | { |
mbed_official | 157:90e3acc479a2 | 256 | CRC->DR = CRC_Data; |
mbed_official | 157:90e3acc479a2 | 257 | |
mbed_official | 157:90e3acc479a2 | 258 | return (CRC->DR); |
mbed_official | 157:90e3acc479a2 | 259 | } |
mbed_official | 157:90e3acc479a2 | 260 | |
mbed_official | 157:90e3acc479a2 | 261 | /** |
mbed_official | 157:90e3acc479a2 | 262 | * @brief Computes the 16-bit CRC of a given 16-bit data. |
mbed_official | 157:90e3acc479a2 | 263 | * @param CRC_Data: data half-word(16-bit) to compute its CRC |
mbed_official | 157:90e3acc479a2 | 264 | * @retval 16-bit CRC |
mbed_official | 157:90e3acc479a2 | 265 | */ |
mbed_official | 157:90e3acc479a2 | 266 | uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data) |
mbed_official | 157:90e3acc479a2 | 267 | { |
mbed_official | 157:90e3acc479a2 | 268 | *(uint16_t*)(CRC_BASE) = (uint16_t) CRC_Data; |
mbed_official | 157:90e3acc479a2 | 269 | |
mbed_official | 157:90e3acc479a2 | 270 | return (CRC->DR); |
mbed_official | 157:90e3acc479a2 | 271 | } |
mbed_official | 157:90e3acc479a2 | 272 | |
mbed_official | 157:90e3acc479a2 | 273 | /** |
mbed_official | 157:90e3acc479a2 | 274 | * @brief Computes the 8-bit CRC of a given 8-bit data. |
mbed_official | 157:90e3acc479a2 | 275 | * @param CRC_Data: 8-bit data to compute its CRC |
mbed_official | 157:90e3acc479a2 | 276 | * @retval 8-bit CRC |
mbed_official | 157:90e3acc479a2 | 277 | */ |
mbed_official | 157:90e3acc479a2 | 278 | uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data) |
mbed_official | 157:90e3acc479a2 | 279 | { |
mbed_official | 157:90e3acc479a2 | 280 | *(uint8_t*)(CRC_BASE) = (uint8_t) CRC_Data; |
mbed_official | 157:90e3acc479a2 | 281 | |
mbed_official | 157:90e3acc479a2 | 282 | return (CRC->DR); |
mbed_official | 157:90e3acc479a2 | 283 | } |
mbed_official | 157:90e3acc479a2 | 284 | |
mbed_official | 157:90e3acc479a2 | 285 | /** |
mbed_official | 157:90e3acc479a2 | 286 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). |
mbed_official | 157:90e3acc479a2 | 287 | * @param pBuffer: pointer to the buffer containing the data to be computed |
mbed_official | 157:90e3acc479a2 | 288 | * @param BufferLength: length of the buffer to be computed |
mbed_official | 157:90e3acc479a2 | 289 | * @retval 32-bit CRC |
mbed_official | 157:90e3acc479a2 | 290 | */ |
mbed_official | 157:90e3acc479a2 | 291 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) |
mbed_official | 157:90e3acc479a2 | 292 | { |
mbed_official | 157:90e3acc479a2 | 293 | uint32_t index = 0; |
mbed_official | 157:90e3acc479a2 | 294 | |
mbed_official | 157:90e3acc479a2 | 295 | for(index = 0; index < BufferLength; index++) |
mbed_official | 157:90e3acc479a2 | 296 | { |
mbed_official | 157:90e3acc479a2 | 297 | CRC->DR = pBuffer[index]; |
mbed_official | 157:90e3acc479a2 | 298 | } |
mbed_official | 157:90e3acc479a2 | 299 | return (CRC->DR); |
mbed_official | 157:90e3acc479a2 | 300 | } |
mbed_official | 157:90e3acc479a2 | 301 | |
mbed_official | 157:90e3acc479a2 | 302 | /** |
mbed_official | 157:90e3acc479a2 | 303 | * @brief Returns the current CRC value. |
mbed_official | 157:90e3acc479a2 | 304 | * @param None |
mbed_official | 157:90e3acc479a2 | 305 | * @retval 32-bit CRC |
mbed_official | 157:90e3acc479a2 | 306 | */ |
mbed_official | 157:90e3acc479a2 | 307 | uint32_t CRC_GetCRC(void) |
mbed_official | 157:90e3acc479a2 | 308 | { |
mbed_official | 157:90e3acc479a2 | 309 | return (CRC->DR); |
mbed_official | 157:90e3acc479a2 | 310 | } |
mbed_official | 157:90e3acc479a2 | 311 | |
mbed_official | 157:90e3acc479a2 | 312 | /** |
mbed_official | 157:90e3acc479a2 | 313 | * @} |
mbed_official | 157:90e3acc479a2 | 314 | */ |
mbed_official | 157:90e3acc479a2 | 315 | |
mbed_official | 157:90e3acc479a2 | 316 | /** @defgroup CRC_Group3 CRC Independent Register (IDR) access functions |
mbed_official | 157:90e3acc479a2 | 317 | * @brief CRC Independent Register (IDR) access (write/read) functions |
mbed_official | 157:90e3acc479a2 | 318 | * |
mbed_official | 157:90e3acc479a2 | 319 | @verbatim |
mbed_official | 157:90e3acc479a2 | 320 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 321 | ##### CRC Independent Register (IDR) access functions ##### |
mbed_official | 157:90e3acc479a2 | 322 | =============================================================================== |
mbed_official | 157:90e3acc479a2 | 323 | |
mbed_official | 157:90e3acc479a2 | 324 | @endverbatim |
mbed_official | 157:90e3acc479a2 | 325 | * @{ |
mbed_official | 157:90e3acc479a2 | 326 | */ |
mbed_official | 157:90e3acc479a2 | 327 | |
mbed_official | 157:90e3acc479a2 | 328 | /** |
mbed_official | 157:90e3acc479a2 | 329 | * @brief Stores an 8-bit data in the Independent Data(ID) register. |
mbed_official | 157:90e3acc479a2 | 330 | * @param CRC_IDValue: 8-bit value to be stored in the ID register |
mbed_official | 157:90e3acc479a2 | 331 | * @retval None |
mbed_official | 157:90e3acc479a2 | 332 | */ |
mbed_official | 157:90e3acc479a2 | 333 | void CRC_SetIDRegister(uint8_t CRC_IDValue) |
mbed_official | 157:90e3acc479a2 | 334 | { |
mbed_official | 157:90e3acc479a2 | 335 | CRC->IDR = CRC_IDValue; |
mbed_official | 157:90e3acc479a2 | 336 | } |
mbed_official | 157:90e3acc479a2 | 337 | |
mbed_official | 157:90e3acc479a2 | 338 | /** |
mbed_official | 157:90e3acc479a2 | 339 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register |
mbed_official | 157:90e3acc479a2 | 340 | * @param None |
mbed_official | 157:90e3acc479a2 | 341 | * @retval 8-bit value of the ID register |
mbed_official | 157:90e3acc479a2 | 342 | */ |
mbed_official | 157:90e3acc479a2 | 343 | uint8_t CRC_GetIDRegister(void) |
mbed_official | 157:90e3acc479a2 | 344 | { |
mbed_official | 157:90e3acc479a2 | 345 | return (CRC->IDR); |
mbed_official | 157:90e3acc479a2 | 346 | } |
mbed_official | 157:90e3acc479a2 | 347 | |
mbed_official | 157:90e3acc479a2 | 348 | /** |
mbed_official | 157:90e3acc479a2 | 349 | * @} |
mbed_official | 157:90e3acc479a2 | 350 | */ |
mbed_official | 157:90e3acc479a2 | 351 | |
mbed_official | 157:90e3acc479a2 | 352 | /** |
mbed_official | 157:90e3acc479a2 | 353 | * @} |
mbed_official | 157:90e3acc479a2 | 354 | */ |
mbed_official | 157:90e3acc479a2 | 355 | |
mbed_official | 157:90e3acc479a2 | 356 | /** |
mbed_official | 157:90e3acc479a2 | 357 | * @} |
mbed_official | 157:90e3acc479a2 | 358 | */ |
mbed_official | 157:90e3acc479a2 | 359 | |
mbed_official | 157:90e3acc479a2 | 360 | /** |
mbed_official | 157:90e3acc479a2 | 361 | * @} |
mbed_official | 157:90e3acc479a2 | 362 | */ |
mbed_official | 157:90e3acc479a2 | 363 | |
mbed_official | 157:90e3acc479a2 | 364 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |