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