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