1 /** 2 ****************************************************************************** 3 * @file HAL_crc.c 4 * @author AE Team 5 * @version V1.0.0 6 * @date 28/7/2017 7 * @brief This file provides all the CRC firmware functions. 8 ****************************************************************************** 9 * @copy 10 * 11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY 14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 * 18 * <h2><center>© COPYRIGHT 2017 MindMotion</center></h2> 19 */ 20 21 /* Includes ------------------------------------------------------------------*/ 22 #include "HAL_crc.h" 23 24 /** @addtogroup StdPeriph_Driver 25 * @{ 26 */ 27 28 /** @defgroup CRC 29 * @brief CRC driver modules 30 * @{ 31 */ 32 33 /** @defgroup CRC_Private_TypesDefinitions 34 * @{ 35 */ 36 37 /** 38 * @} 39 */ 40 41 /** @defgroup CRC_Private_Defines 42 * @{ 43 */ 44 45 /* CR register bit mask */ 46 47 #define CR_RESET_Set ((uint32_t)0x00000001) 48 49 /** 50 * @} 51 */ 52 53 /** @defgroup CRC_Private_Macros 54 * @{ 55 */ 56 57 /** 58 * @} 59 */ 60 61 /** @defgroup CRC_Private_Variables 62 * @{ 63 */ 64 65 /** 66 * @} 67 */ 68 69 /** @defgroup CRC_Private_FunctionPrototypes 70 * @{ 71 */ 72 73 /** 74 * @} 75 */ 76 77 /** @defgroup CRC_Private_Functions 78 * @{ 79 */ 80 81 /** 82 * @brief Resets the CRC Data register (DR). 83 * @param None 84 * @retval : None 85 */ CRC_ResetDR(void)86void CRC_ResetDR(void) 87 { 88 /* Reset CRC generator */ 89 CRC->CR = CR_RESET_Set; 90 } 91 92 /** 93 * @brief Computes the 32-bit CRC of a given data word(32-bit). 94 * @param Data: data word(32-bit) to compute its CRC 95 * @retval : 32-bit CRC 96 */ CRC_CalcCRC(uint32_t Data)97uint32_t CRC_CalcCRC(uint32_t Data) 98 { 99 CRC->DR = Data; 100 CRC->DR = CRC_GetCRC();//gai 101 return (CRC->DR); 102 } 103 104 /** 105 * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 106 * @param pBuffer: pointer to the buffer containing the data to be 107 * computed 108 * @param BufferLength: length of the buffer to be computed 109 * @retval : 32-bit CRC 110 */ CRC_CalcBlockCRC(uint32_t pBuffer[],uint32_t BufferLength)111uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 112 { 113 uint32_t index = 0; 114 115 for(index = 0; index < BufferLength; index++) 116 { 117 CRC->DR = pBuffer[index]; 118 } 119 return (CRC->DR); 120 } 121 122 /** 123 * @brief Returns the current CRC value. 124 * @param None 125 * @retval : 32-bit CRC 126 */ CRC_GetCRC(void)127uint32_t CRC_GetCRC(void) 128 { 129 return (CRC->DR); 130 } 131 132 /** 133 * @brief Stores a 8-bit data in the Independent Data(ID) register. 134 * @param IDValue: 8-bit value to be stored in the ID register 135 * @retval : None 136 */ CRC_SetIDRegister(uint8_t IDValue)137void CRC_SetIDRegister(uint8_t IDValue) 138 { 139 CRC->IDR = IDValue; 140 } 141 142 /** 143 * @brief Returns the 8-bit data stored in the Independent Data(ID) register 144 * @param None 145 * @retval : 8-bit value of the ID register 146 */ CRC_GetIDRegister(void)147uint8_t CRC_GetIDRegister(void) 148 { 149 return (CRC->IDR); 150 } 151 152 /** 153 * @} 154 */ 155 156 /** 157 * @} 158 */ 159 160 /** 161 * @} 162 */ 163 164 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/ 165