]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_crc.c
2 ******************************************************************************
3 * @file stm32f30x_crc.c
4 * @author MCD Application Team
6 * @date 27-February-2014
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of CRC computation unit peripheral:
9 * + Configuration of the CRC computation unit
10 * + CRC computation of one/many 32-bit data
11 * + CRC Independent register (IDR) access
15 ===============================================================================
16 ##### How to use this driver #####
17 ===============================================================================
19 (#) Enable CRC AHB clock using RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE)
21 (#) Select the polynomial size: 7-bit, 8-bit, 16-bit or 32-bit.
22 (#) Set the polynomial coefficients using CRC_SetPolynomial();
23 (#) If required, select the reverse operation on input data
24 using CRC_ReverseInputDataSelect();
25 (#) If required, enable the reverse operation on output data
26 using CRC_ReverseOutputDataCmd(Enable);
27 (#) If required, set the initialization remainder value using
28 CRC_SetInitRegister();
29 (#) use CRC_CalcCRC() function to compute the CRC of a 32-bit data
30 or use CRC_CalcBlockCRC() function to compute the CRC if a 32-bit
35 ******************************************************************************
38 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
40 * Redistribution and use in source and binary forms, with or without modification,
41 * are permitted provided that the following conditions are met:
42 * 1. Redistributions of source code must retain the above copyright notice,
43 * this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright notice,
45 * this list of conditions and the following disclaimer in the documentation
46 * and/or other materials provided with the distribution.
47 * 3. Neither the name of STMicroelectronics nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
52 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
54 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
57 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
58 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 ******************************************************************************
65 /* Includes ------------------------------------------------------------------*/
66 #include "stm32f30x_crc.h"
68 /** @addtogroup STM32F30x_StdPeriph_Driver
73 * @brief CRC driver modules
77 /* Private typedef -----------------------------------------------------------*/
78 /* Private define ------------------------------------------------------------*/
79 /* Private macro -------------------------------------------------------------*/
80 /* Private variables ---------------------------------------------------------*/
81 /* Private function prototypes -----------------------------------------------*/
82 /* Private functions ---------------------------------------------------------*/
84 /** @defgroup CRC_Private_Functions
88 /** @defgroup CRC_Group1 Configuration of the CRC computation unit functions
89 * @brief Configuration of the CRC computation unit functions
92 ===============================================================================
93 ##### CRC configuration functions #####
94 ===============================================================================
101 * @brief Deinitializes CRC peripheral registers to their default reset values.
105 void CRC_DeInit(void)
107 /* Set DR register to reset value */
108 CRC
->DR
= 0xFFFFFFFF;
109 /* Set the POL register to the reset value: 0x04C11DB7 */
110 CRC
->POL
= 0x04C11DB7;
111 /* Reset IDR register */
113 /* Set INIT register to reset value */
114 CRC
->INIT
= 0xFFFFFFFF;
115 /* Reset the CRC calculation unit */
116 CRC
->CR
= CRC_CR_RESET
;
120 * @brief Resets the CRC calculation unit and sets INIT register content in DR register.
124 void CRC_ResetDR(void)
126 /* Reset CRC generator */
127 CRC
->CR
|= CRC_CR_RESET
;
131 * @brief Selects the polynomial size.
132 * @param CRC_PolSize: Specifies the polynomial size.
133 * This parameter can be:
134 * @arg CRC_PolSize_7: 7-bit polynomial for CRC calculation
135 * @arg CRC_PolSize_8: 8-bit polynomial for CRC calculation
136 * @arg CRC_PolSize_16: 16-bit polynomial for CRC calculation
137 * @arg CRC_PolSize_32: 32-bit polynomial for CRC calculation
140 void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize
)
144 /* Check the parameter */
145 assert_param(IS_CRC_POL_SIZE(CRC_PolSize
));
147 /* Get CR register value */
150 /* Reset POL_SIZE bits */
151 tmpcr
&= (uint32_t)~((uint32_t)CRC_CR_POLSIZE
);
152 /* Set the polynomial size */
153 tmpcr
|= (uint32_t)CRC_PolSize
;
155 /* Write to CR register */
156 CRC
->CR
= (uint32_t)tmpcr
;
160 * @brief Selects the reverse operation to be performed on input data.
161 * @param CRC_ReverseInputData: Specifies the reverse operation on input data.
162 * This parameter can be:
163 * @arg CRC_ReverseInputData_No: No reverse operation is performed
164 * @arg CRC_ReverseInputData_8bits: reverse operation performed on 8 bits
165 * @arg CRC_ReverseInputData_16bits: reverse operation performed on 16 bits
166 * @arg CRC_ReverseInputData_32bits: reverse operation performed on 32 bits
169 void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData
)
173 /* Check the parameter */
174 assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData
));
176 /* Get CR register value */
179 /* Reset REV_IN bits */
180 tmpcr
&= (uint32_t)~((uint32_t)CRC_CR_REV_IN
);
181 /* Set the reverse operation */
182 tmpcr
|= (uint32_t)CRC_ReverseInputData
;
184 /* Write to CR register */
185 CRC
->CR
= (uint32_t)tmpcr
;
189 * @brief Enables or disable the reverse operation on output data.
190 * The reverse operation on output data is performed on 32-bit.
191 * @param NewState: new state of the reverse operation on output data.
192 * This parameter can be: ENABLE or DISABLE.
195 void CRC_ReverseOutputDataCmd(FunctionalState NewState
)
197 /* Check the parameters */
198 assert_param(IS_FUNCTIONAL_STATE(NewState
));
200 if (NewState
!= DISABLE
)
202 /* Enable reverse operation on output data */
203 CRC
->CR
|= CRC_CR_REV_OUT
;
207 /* Disable reverse operation on output data */
208 CRC
->CR
&= (uint32_t)~((uint32_t)CRC_CR_REV_OUT
);
213 * @brief Initializes the INIT register.
214 * @note After resetting CRC calculation unit, CRC_InitValue is stored in DR register
215 * @param CRC_InitValue: Programmable initial CRC value
218 void CRC_SetInitRegister(uint32_t CRC_InitValue
)
220 CRC
->INIT
= CRC_InitValue
;
224 * @brief Initializes the polynomail coefficients.
225 * @param CRC_Pol: Polynomial to be used for CRC calculation.
228 void CRC_SetPolynomial(uint32_t CRC_Pol
)
237 /** @defgroup CRC_Group2 CRC computation of one/many 32-bit data functions
238 * @brief CRC computation of one/many 32-bit data functions
241 ===============================================================================
242 ##### CRC computation functions #####
243 ===============================================================================
250 * @brief Computes the 32-bit CRC of a given data word(32-bit).
251 * @param CRC_Data: data word(32-bit) to compute its CRC
254 uint32_t CRC_CalcCRC(uint32_t CRC_Data
)
262 * @brief Computes the 16-bit CRC of a given 16-bit data.
263 * @param CRC_Data: data half-word(16-bit) to compute its CRC
266 uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data
)
268 *(uint16_t*)(CRC_BASE
) = (uint16_t) CRC_Data
;
274 * @brief Computes the 8-bit CRC of a given 8-bit data.
275 * @param CRC_Data: 8-bit data to compute its CRC
278 uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data
)
280 *(uint8_t*)(CRC_BASE
) = (uint8_t) CRC_Data
;
286 * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
287 * @param pBuffer: pointer to the buffer containing the data to be computed
288 * @param BufferLength: length of the buffer to be computed
291 uint32_t CRC_CalcBlockCRC(uint32_t pBuffer
[], uint32_t BufferLength
)
295 for(index
= 0; index
< BufferLength
; index
++)
297 CRC
->DR
= pBuffer
[index
];
303 * @brief Returns the current CRC value.
307 uint32_t CRC_GetCRC(void)
316 /** @defgroup CRC_Group3 CRC Independent Register (IDR) access functions
317 * @brief CRC Independent Register (IDR) access (write/read) functions
320 ===============================================================================
321 ##### CRC Independent Register (IDR) access functions #####
322 ===============================================================================
329 * @brief Stores an 8-bit data in the Independent Data(ID) register.
330 * @param CRC_IDValue: 8-bit value to be stored in the ID register
333 void CRC_SetIDRegister(uint8_t CRC_IDValue
)
335 CRC
->IDR
= CRC_IDValue
;
339 * @brief Returns the 8-bit data stored in the Independent Data(ID) register
341 * @retval 8-bit value of the ID register
343 uint8_t CRC_GetIDRegister(void)
364 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/