1 /** 2 ****************************************************************************** 3 * @file ft32f0xx_crc.c 4 * @author FMD AE 5 * @brief This file provides firmware functions to manage the following 6 * functionalities of CRC computation unit peripheral: 7 * + Configuration of the CRC computation unit 8 * + CRC computation of one/many 32-bit data 9 * + CRC Independent register (IDR) access 10 * @version V1.0.0 11 * @data 2021-07-01 12 ****************************************************************************** 13 */ 14 15 16 /* Includes ------------------------------------------------------------------*/ 17 #include "ft32f0xx_crc.h" 18 19 /** 20 * @brief Deinitializes CRC peripheral registers to their default reset values. 21 * @param None 22 * @retval None 23 */ CRC_DeInit(void)24void CRC_DeInit(void) 25 { 26 /* Set DR register to reset value */ 27 CRC->DR = 0xFFFFFFFF; 28 29 /* Reset IDR register */ 30 CRC->IDR = 0x00; 31 32 /* Set INIT register to reset value */ 33 CRC->INIT = 0xFFFFFFFF; 34 35 /* Reset the CRC calculation unit */ 36 CRC->CR = CRC_CR_RESET; 37 } 38 39 /** 40 * @brief Resets the CRC calculation unit and sets INIT register content in DR register. 41 * @param None 42 * @retval None 43 */ CRC_ResetDR(void)44void CRC_ResetDR(void) 45 { 46 /* Reset CRC generator */ 47 CRC->CR |= CRC_CR_RESET; 48 } 49 50 /** 51 * @brief Selects the polynomial size. This function is only applicable for 52 * FT32F072 devices. 53 * @param CRC_PolSize: Specifies the polynomial size. 54 * This parameter can be: 55 * @arg CRC_PolSize_7: 7-bit polynomial for CRC calculation 56 * @arg CRC_PolSize_8: 8-bit polynomial for CRC calculation 57 * @arg CRC_PolSize_16: 16-bit polynomial for CRC calculation 58 * @arg CRC_PolSize_32: 32-bit polynomial for CRC calculation 59 * @retval None 60 */ 61 //void CRC_PolynomialSizeSelect(uint32_t CRC_PolSize) 62 //{ 63 // uint32_t tmpcr = 0; 64 65 // /* Check the parameter */ 66 // assert_param(IS_CRC_POL_SIZE(CRC_PolSize)); 67 68 // /* Get CR register value */ 69 // tmpcr = CRC->CR; 70 71 // /* Reset POL_SIZE bits */ 72 // tmpcr &= (uint32_t)~((uint32_t)CRC_CR_POLSIZE); 73 // /* Set the polynomial size */ 74 // tmpcr |= (uint32_t)CRC_PolSize; 75 76 // /* Write to CR register */ 77 // CRC->CR = (uint32_t)tmpcr; 78 //} 79 80 /** 81 * @brief Selects the reverse operation to be performed on input data. 82 * @param CRC_ReverseInputData: Specifies the reverse operation on input data. 83 * This parameter can be: 84 * @arg CRC_ReverseInputData_No: No reverse operation is performed 85 * @arg CRC_ReverseInputData_8bits: reverse operation performed on 8 bits 86 * @arg CRC_ReverseInputData_16bits: reverse operation performed on 16 bits 87 * @arg CRC_ReverseInputData_32bits: reverse operation performed on 32 bits 88 * @retval None 89 */ CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData)90void CRC_ReverseInputDataSelect(uint32_t CRC_ReverseInputData) 91 { 92 uint32_t tmpcr = 0; 93 94 /* Check the parameter */ 95 assert_param(IS_CRC_REVERSE_INPUT_DATA(CRC_ReverseInputData)); 96 97 /* Get CR register value */ 98 tmpcr = CRC->CR; 99 100 /* Reset REV_IN bits */ 101 tmpcr &= (uint32_t)~((uint32_t)CRC_CR_REV_IN); 102 /* Set the reverse operation */ 103 tmpcr |= (uint32_t)CRC_ReverseInputData; 104 105 /* Write to CR register */ 106 CRC->CR = (uint32_t)tmpcr; 107 } 108 109 /** 110 * @brief Enables or disable the reverse operation on output data. 111 * The reverse operation on output data is performed on 32-bit. 112 * @param NewState: new state of the reverse operation on output data. 113 * This parameter can be: ENABLE or DISABLE. 114 * @retval None 115 */ CRC_ReverseOutputDataCmd(FunctionalState NewState)116void CRC_ReverseOutputDataCmd(FunctionalState NewState) 117 { 118 /* Check the parameters */ 119 assert_param(IS_FUNCTIONAL_STATE(NewState)); 120 121 if (NewState != DISABLE) 122 { 123 /* Enable reverse operation on output data */ 124 CRC->CR |= CRC_CR_REV_OUT; 125 } 126 else 127 { 128 /* Disable reverse operation on output data */ 129 CRC->CR &= (uint32_t)~((uint32_t)CRC_CR_REV_OUT); 130 } 131 } 132 133 /** 134 * @brief Initializes the INIT register. 135 * @note After resetting CRC calculation unit, CRC_InitValue is stored in DR register 136 * @param CRC_InitValue: Programmable initial CRC value 137 * @retval None 138 */ CRC_SetInitRegister(uint32_t CRC_InitValue)139void CRC_SetInitRegister(uint32_t CRC_InitValue) 140 { 141 CRC->INIT = CRC_InitValue; 142 } 143 144 /** 145 * @brief Initializes the polynomail coefficients. This function is only 146 * applicable for FT32F072 devices. 147 * @param CRC_Pol: Polynomial to be used for CRC calculation. 148 * @retval None 149 */ CRC_SetPolynomial(uint32_t CRC_Pol)150void CRC_SetPolynomial(uint32_t CRC_Pol) 151 { 152 // CRC->POL = CRC_Pol; 153 } 154 155 /** 156 * @} 157 */ 158 159 /** 160 * @brief Computes the 32-bit CRC of a given data word(32-bit). 161 * @param CRC_Data: data word(32-bit) to compute its CRC 162 * @retval 32-bit CRC 163 */ CRC_CalcCRC(uint32_t CRC_Data)164uint32_t CRC_CalcCRC(uint32_t CRC_Data) 165 { 166 CRC->DR = CRC_Data; 167 168 return (CRC->DR); 169 } 170 171 /** 172 * @brief Computes the 16-bit CRC of a given 16-bit data. 173 * @param CRC_Data: data half-word(16-bit) to compute its CRC 174 * @retval 16-bit CRC 175 */ CRC_CalcCRC16bits(uint16_t CRC_Data)176uint32_t CRC_CalcCRC16bits(uint16_t CRC_Data) 177 { 178 *(uint16_t*)(CRC_BASE) = (uint16_t) CRC_Data; 179 180 return (CRC->DR); 181 } 182 183 /** 184 * @brief Computes the 8-bit CRC of a given 8-bit data. 185 * @param CRC_Data: 8-bit data to compute its CRC 186 * @retval 8-bit CRC 187 */ CRC_CalcCRC8bits(uint8_t CRC_Data)188uint32_t CRC_CalcCRC8bits(uint8_t CRC_Data) 189 { 190 *(uint8_t*)(CRC_BASE) = (uint8_t) CRC_Data; 191 192 return (CRC->DR); 193 } 194 195 /** 196 * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 197 * @param pBuffer: pointer to the buffer containing the data to be computed 198 * @param BufferLength: length of the buffer to be computed 199 * @retval 32-bit CRC 200 */ CRC_CalcBlockCRC(uint32_t pBuffer[],uint32_t BufferLength)201uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 202 { 203 uint32_t index = 0; 204 205 for(index = 0; index < BufferLength; index++) 206 { 207 CRC->DR = pBuffer[index]; 208 } 209 return (CRC->DR); 210 } 211 212 /** 213 * @brief Returns the current CRC value. 214 * @param None 215 * @retval 32-bit CRC 216 */ CRC_GetCRC(void)217uint32_t CRC_GetCRC(void) 218 { 219 return (CRC->DR); 220 } 221 222 /** 223 * @} 224 */ 225 /** 226 * @brief Stores an 8-bit data in the Independent Data(ID) register. 227 * @param CRC_IDValue: 8-bit value to be stored in the ID register 228 * @retval None 229 */ CRC_SetIDRegister(uint8_t CRC_IDValue)230void CRC_SetIDRegister(uint8_t CRC_IDValue) 231 { 232 CRC->IDR = CRC_IDValue; 233 } 234 235 /** 236 * @brief Returns the 8-bit data stored in the Independent Data(ID) register 237 * @param None 238 * @retval 8-bit value of the ID register 239 */ CRC_GetIDRegister(void)240uint8_t CRC_GetIDRegister(void) 241 { 242 return (uint8_t)(CRC->IDR); 243 } 244 245 /** 246 * @} 247 */ 248 249 /** 250 * @} 251 */ 252 253 /** 254 * @} 255 */ 256 257 /** 258 * @} 259 */ 260 261 /************************ (C) COPYRIGHT FMD *****END OF FILE****/ 262