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