mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_crc_ex.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 237:f3da66175598
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_crc_ex.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief Extended CRC HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the CRC peripheral: |
mbed_official | 237:f3da66175598 | 11 | * + Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 12 | * + I/O operation functions |
mbed_official | 237:f3da66175598 | 13 | * + Peripheral Control functions |
mbed_official | 237:f3da66175598 | 14 | * + Peripheral State functions |
mbed_official | 237:f3da66175598 | 15 | * |
mbed_official | 237:f3da66175598 | 16 | @verbatim |
mbed_official | 237:f3da66175598 | 17 | ================================================================================ |
mbed_official | 237:f3da66175598 | 18 | ##### <Product specific features/integration> ##### |
mbed_official | 237:f3da66175598 | 19 | ================================================================================ |
mbed_official | 237:f3da66175598 | 20 | |
mbed_official | 237:f3da66175598 | 21 | [..] < This section can contain: |
mbed_official | 237:f3da66175598 | 22 | (#) Description of the product specific implementation; all features |
mbed_official | 237:f3da66175598 | 23 | that is specific to this IP: separate clock for RTC/LCD/IWDG/ADC, |
mbed_official | 237:f3da66175598 | 24 | power domain (backup domain for the RTC)... |
mbed_official | 237:f3da66175598 | 25 | (#) IP main features, only when needed and not mandatory for all IPs, |
mbed_official | 237:f3da66175598 | 26 | ex. for xWDG, GPIO, COMP... |
mbed_official | 237:f3da66175598 | 27 | > |
mbed_official | 237:f3da66175598 | 28 | |
mbed_official | 237:f3da66175598 | 29 | [..] < You can add as much sections as needed.> |
mbed_official | 237:f3da66175598 | 30 | |
mbed_official | 237:f3da66175598 | 31 | [..] < You can add as much sections as needed.> |
mbed_official | 237:f3da66175598 | 32 | |
mbed_official | 237:f3da66175598 | 33 | |
mbed_official | 237:f3da66175598 | 34 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 35 | ================================================================================ |
mbed_official | 237:f3da66175598 | 36 | [..] |
mbed_official | 237:f3da66175598 | 37 | (+) Enable CRC AHB clock using __CRC_CLK_ENABLE(); |
mbed_official | 237:f3da66175598 | 38 | (+) Initialize CRC calculator |
mbed_official | 237:f3da66175598 | 39 | - specify generating polynomial (IP default or non-default one) |
mbed_official | 237:f3da66175598 | 40 | - specify initialization value (IP default or non-default one) |
mbed_official | 237:f3da66175598 | 41 | - specify input data format |
mbed_official | 237:f3da66175598 | 42 | - specify input or output data inversion mode if any |
mbed_official | 237:f3da66175598 | 43 | (+) Use HAL_CRC_Accumulate() function to compute the CRC value of the |
mbed_official | 237:f3da66175598 | 44 | input data buffer starting with the previously computed CRC as |
mbed_official | 237:f3da66175598 | 45 | initialization value |
mbed_official | 237:f3da66175598 | 46 | (+) Use HAL_CRC_Calculate() function to compute the CRC value of the |
mbed_official | 237:f3da66175598 | 47 | input data buffer starting with the defined initialization value |
mbed_official | 237:f3da66175598 | 48 | (default or non-default) to initiate CRC calculation |
mbed_official | 237:f3da66175598 | 49 | |
mbed_official | 237:f3da66175598 | 50 | @endverbatim |
mbed_official | 237:f3da66175598 | 51 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 52 | * @attention |
mbed_official | 237:f3da66175598 | 53 | * |
mbed_official | 237:f3da66175598 | 54 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 55 | * |
mbed_official | 237:f3da66175598 | 56 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 57 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 58 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 59 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 60 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 61 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 62 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 63 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 64 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 65 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 66 | * |
mbed_official | 237:f3da66175598 | 67 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 68 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 69 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 70 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 71 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 72 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 73 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 74 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 75 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 76 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 77 | * |
mbed_official | 237:f3da66175598 | 78 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 79 | */ |
mbed_official | 237:f3da66175598 | 80 | |
mbed_official | 237:f3da66175598 | 81 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 82 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 83 | |
mbed_official | 237:f3da66175598 | 84 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 85 | * @{ |
mbed_official | 237:f3da66175598 | 86 | */ |
mbed_official | 237:f3da66175598 | 87 | |
mbed_official | 237:f3da66175598 | 88 | /** @defgroup CRCEx |
mbed_official | 237:f3da66175598 | 89 | * @brief CRC Extended HAL module driver |
mbed_official | 237:f3da66175598 | 90 | * @{ |
mbed_official | 237:f3da66175598 | 91 | */ |
mbed_official | 237:f3da66175598 | 92 | |
mbed_official | 237:f3da66175598 | 93 | #ifdef HAL_CRC_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 94 | |
mbed_official | 237:f3da66175598 | 95 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 96 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 97 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 98 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 99 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 100 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 101 | |
mbed_official | 237:f3da66175598 | 102 | /** @defgroup CRCEx_Private_Functions |
mbed_official | 237:f3da66175598 | 103 | * @{ |
mbed_official | 237:f3da66175598 | 104 | */ |
mbed_official | 237:f3da66175598 | 105 | |
mbed_official | 237:f3da66175598 | 106 | /** @defgroup CRCEx_Group1 Extended Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 107 | * @brief Extended Initialization and Configuration functions. |
mbed_official | 237:f3da66175598 | 108 | * |
mbed_official | 237:f3da66175598 | 109 | @verbatim |
mbed_official | 237:f3da66175598 | 110 | =============================================================================== |
mbed_official | 237:f3da66175598 | 111 | ##### Initialization/de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 112 | =============================================================================== |
mbed_official | 237:f3da66175598 | 113 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 114 | (+) Initialize the CRC according to the specified parameters |
mbed_official | 237:f3da66175598 | 115 | in the CRC_InitTypeDef and create the associated handle |
mbed_official | 237:f3da66175598 | 116 | (+) DeInitialize the CRC peripheral |
mbed_official | 237:f3da66175598 | 117 | (+) Initialize the CRC MSP |
mbed_official | 237:f3da66175598 | 118 | (+) DeInitialize CRC MSP |
mbed_official | 237:f3da66175598 | 119 | |
mbed_official | 237:f3da66175598 | 120 | @endverbatim |
mbed_official | 237:f3da66175598 | 121 | * @{ |
mbed_official | 237:f3da66175598 | 122 | */ |
mbed_official | 237:f3da66175598 | 123 | |
mbed_official | 237:f3da66175598 | 124 | |
mbed_official | 237:f3da66175598 | 125 | /** |
mbed_official | 237:f3da66175598 | 126 | * @brief Initializes the CRC polynomial if different from default one. |
mbed_official | 237:f3da66175598 | 127 | * @param hcrc: CRC handle |
mbed_official | 237:f3da66175598 | 128 | * @param Pol: CRC generating polynomial (7, 8, 16 or 32-bit long) |
mbed_official | 237:f3da66175598 | 129 | * This parameter is written in normal representation, e.g. |
mbed_official | 237:f3da66175598 | 130 | * for a polynomial of degree 7, X^7 + X^6 + X^5 + X^2 + 1 is written 0x65 |
mbed_official | 237:f3da66175598 | 131 | * for a polynomial of degree 16, X^16 + X^12 + X^5 + 1 is written 0x1021 |
mbed_official | 237:f3da66175598 | 132 | * @param PolyLength: CRC polynomial length |
mbed_official | 237:f3da66175598 | 133 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 134 | * @arg CRC_POLYLENGTH_7B: 7-bit long CRC (generating polynomial of degree 7) |
mbed_official | 237:f3da66175598 | 135 | * @arg CRC_POLYLENGTH_8B: 8-bit long CRC (generating polynomial of degree 8) |
mbed_official | 237:f3da66175598 | 136 | * @arg CRC_POLYLENGTH_16B: 16-bit long CRC (generating polynomial of degree 16) |
mbed_official | 237:f3da66175598 | 137 | * @arg CRC_POLYLENGTH_32B: 32-bit long CRC (generating polynomial of degree 32) |
mbed_official | 237:f3da66175598 | 138 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 139 | */ |
mbed_official | 237:f3da66175598 | 140 | HAL_StatusTypeDef HAL_CRCEx_Polynomial_Set(CRC_HandleTypeDef *hcrc, uint32_t Pol, uint32_t PolyLength) |
mbed_official | 237:f3da66175598 | 141 | { |
mbed_official | 237:f3da66175598 | 142 | uint32_t msb = 31; /* polynomial degree is 32 at most, so msb is initialized to max value */ |
mbed_official | 237:f3da66175598 | 143 | |
mbed_official | 237:f3da66175598 | 144 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 145 | assert_param(IS_CRC_POL_LENGTH(PolyLength)); |
mbed_official | 237:f3da66175598 | 146 | |
mbed_official | 237:f3da66175598 | 147 | /* check polynomial definition vs polynomial size: |
mbed_official | 237:f3da66175598 | 148 | * polynomial length must be aligned with polynomial |
mbed_official | 237:f3da66175598 | 149 | * definition. HAL_ERROR is reported if Pol degree is |
mbed_official | 237:f3da66175598 | 150 | * larger than that indicated by PolyLength. |
mbed_official | 237:f3da66175598 | 151 | * Look for MSB position: msb will contain the degree of |
mbed_official | 237:f3da66175598 | 152 | * the second to the largest polynomial member. E.g., for |
mbed_official | 237:f3da66175598 | 153 | * X^7 + X^6 + X^5 + X^2 + 1, msb = 6. */ |
mbed_official | 237:f3da66175598 | 154 | while (((Pol & (0x1 << msb)) == 0) && (msb-- > 0)); |
mbed_official | 237:f3da66175598 | 155 | |
mbed_official | 237:f3da66175598 | 156 | switch (PolyLength) |
mbed_official | 237:f3da66175598 | 157 | { |
mbed_official | 237:f3da66175598 | 158 | case CRC_POLYLENGTH_7B: |
mbed_official | 237:f3da66175598 | 159 | if (msb >= HAL_CRC_LENGTH_7B) return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 160 | break; |
mbed_official | 237:f3da66175598 | 161 | case CRC_POLYLENGTH_8B: |
mbed_official | 237:f3da66175598 | 162 | if (msb >= HAL_CRC_LENGTH_8B) return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 163 | break; |
mbed_official | 237:f3da66175598 | 164 | case CRC_POLYLENGTH_16B: |
mbed_official | 237:f3da66175598 | 165 | if (msb >= HAL_CRC_LENGTH_16B) return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 166 | break; |
mbed_official | 237:f3da66175598 | 167 | case CRC_POLYLENGTH_32B: |
mbed_official | 237:f3da66175598 | 168 | /* no polynomial definition vs. polynomial length issue possible */ |
mbed_official | 237:f3da66175598 | 169 | break; |
mbed_official | 237:f3da66175598 | 170 | } |
mbed_official | 237:f3da66175598 | 171 | |
mbed_official | 237:f3da66175598 | 172 | /* set generating polynomial */ |
mbed_official | 237:f3da66175598 | 173 | WRITE_REG(hcrc->Instance->POL, Pol); |
mbed_official | 237:f3da66175598 | 174 | |
mbed_official | 237:f3da66175598 | 175 | /* set generating polynomial size */ |
mbed_official | 237:f3da66175598 | 176 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_POLYSIZE, PolyLength); |
mbed_official | 237:f3da66175598 | 177 | |
mbed_official | 237:f3da66175598 | 178 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 179 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 180 | } |
mbed_official | 237:f3da66175598 | 181 | |
mbed_official | 237:f3da66175598 | 182 | /** |
mbed_official | 237:f3da66175598 | 183 | * @brief Set the Reverse Input data mode. |
mbed_official | 237:f3da66175598 | 184 | * @param hcrc: CRC handle |
mbed_official | 237:f3da66175598 | 185 | * @param InputReverseMode: Input Data inversion mode |
mbed_official | 237:f3da66175598 | 186 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 187 | * @arg CRC_INPUTDATA_NOINVERSION: no change in bit order (default value) |
mbed_official | 237:f3da66175598 | 188 | * @arg CRC_INPUTDATA_INVERSION_BYTE: Byte-wise bit reversal |
mbed_official | 237:f3da66175598 | 189 | * @arg CRC_INPUTDATA_INVERSION_HALFWORD: HalfWord-wise bit reversal |
mbed_official | 237:f3da66175598 | 190 | * @arg CRC_INPUTDATA_INVERSION_WORD: Word-wise bit reversal |
mbed_official | 237:f3da66175598 | 191 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 192 | */ |
mbed_official | 237:f3da66175598 | 193 | HAL_StatusTypeDef HAL_CRCEx_Input_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t InputReverseMode) |
mbed_official | 237:f3da66175598 | 194 | { |
mbed_official | 237:f3da66175598 | 195 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 196 | assert_param(IS_CRC_INPUTDATA_INVERSION_MODE(InputReverseMode)); |
mbed_official | 237:f3da66175598 | 197 | |
mbed_official | 237:f3da66175598 | 198 | /* Change CRC peripheral state */ |
mbed_official | 237:f3da66175598 | 199 | hcrc->State = HAL_CRC_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 200 | |
mbed_official | 237:f3da66175598 | 201 | /* set input data inversion mode */ |
mbed_official | 237:f3da66175598 | 202 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_IN, InputReverseMode); |
mbed_official | 237:f3da66175598 | 203 | /* Change CRC peripheral state */ |
mbed_official | 237:f3da66175598 | 204 | hcrc->State = HAL_CRC_STATE_READY; |
mbed_official | 237:f3da66175598 | 205 | |
mbed_official | 237:f3da66175598 | 206 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 207 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 208 | } |
mbed_official | 237:f3da66175598 | 209 | |
mbed_official | 237:f3da66175598 | 210 | /** |
mbed_official | 237:f3da66175598 | 211 | * @brief Set the Reverse Output data mode. |
mbed_official | 237:f3da66175598 | 212 | * @param hcrc: CRC handle |
mbed_official | 237:f3da66175598 | 213 | * @param OutputReverseMode: Output Data inversion mode |
mbed_official | 237:f3da66175598 | 214 | * This parameter can be one of the following values: |
mbed_official | 237:f3da66175598 | 215 | * @arg CRC_OUTPUTDATA_INVERSION_DISABLED: no CRC inversion (default value) |
mbed_official | 237:f3da66175598 | 216 | * @arg CRC_OUTPUTDATA_INVERSION_ENABLED: bit-level inversion (e.g for a 8-bit CRC: 0xB5 becomes 0xAD) |
mbed_official | 237:f3da66175598 | 217 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 218 | */ |
mbed_official | 237:f3da66175598 | 219 | HAL_StatusTypeDef HAL_CRCEx_Output_Data_Reverse(CRC_HandleTypeDef *hcrc, uint32_t OutputReverseMode) |
mbed_official | 237:f3da66175598 | 220 | { |
mbed_official | 237:f3da66175598 | 221 | /* Check the parameters */ |
mbed_official | 237:f3da66175598 | 222 | assert_param(IS_CRC_OUTPUTDATA_INVERSION_MODE(OutputReverseMode)); |
mbed_official | 237:f3da66175598 | 223 | |
mbed_official | 237:f3da66175598 | 224 | /* Change CRC peripheral state */ |
mbed_official | 237:f3da66175598 | 225 | hcrc->State = HAL_CRC_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 226 | |
mbed_official | 237:f3da66175598 | 227 | /* set output data inversion mode */ |
mbed_official | 237:f3da66175598 | 228 | MODIFY_REG(hcrc->Instance->CR, CRC_CR_REV_OUT, OutputReverseMode); |
mbed_official | 237:f3da66175598 | 229 | |
mbed_official | 237:f3da66175598 | 230 | /* Change CRC peripheral state */ |
mbed_official | 237:f3da66175598 | 231 | hcrc->State = HAL_CRC_STATE_READY; |
mbed_official | 237:f3da66175598 | 232 | |
mbed_official | 237:f3da66175598 | 233 | /* Return function status */ |
mbed_official | 237:f3da66175598 | 234 | return HAL_OK; |
mbed_official | 237:f3da66175598 | 235 | } |
mbed_official | 237:f3da66175598 | 236 | |
mbed_official | 237:f3da66175598 | 237 | |
mbed_official | 237:f3da66175598 | 238 | |
mbed_official | 237:f3da66175598 | 239 | |
mbed_official | 237:f3da66175598 | 240 | /** |
mbed_official | 237:f3da66175598 | 241 | * @} |
mbed_official | 237:f3da66175598 | 242 | */ |
mbed_official | 237:f3da66175598 | 243 | |
mbed_official | 237:f3da66175598 | 244 | |
mbed_official | 237:f3da66175598 | 245 | /** |
mbed_official | 237:f3da66175598 | 246 | * @} |
mbed_official | 237:f3da66175598 | 247 | */ |
mbed_official | 237:f3da66175598 | 248 | |
mbed_official | 237:f3da66175598 | 249 | |
mbed_official | 237:f3da66175598 | 250 | #endif /* HAL_CRC_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 251 | /** |
mbed_official | 237:f3da66175598 | 252 | * @} |
mbed_official | 237:f3da66175598 | 253 | */ |
mbed_official | 237:f3da66175598 | 254 | |
mbed_official | 237:f3da66175598 | 255 | /** |
mbed_official | 237:f3da66175598 | 256 | * @} |
mbed_official | 237:f3da66175598 | 257 | */ |
mbed_official | 237:f3da66175598 | 258 | |
mbed_official | 237:f3da66175598 | 259 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |