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