1 /* 2 ****************************************************************************** 3 * @file HAL_CRC.h 4 * @version V1.0.0 5 * @date 2021 6 * @brief Header file of CRC HAL module. 7 ****************************************************************************** 8 */ 9 #ifndef __HAL_CRC_H__ 10 #define __HAL_CRC_H__ 11 #include "ACM32Fxx_HAL.h" 12 13 /** @defgroup CRC POLY Reverse 14 * @{ 15 */ 16 #define CRC_POLY_REV_EN (0x00000400U) /*!< Poly Reverse Enable */ 17 #define CRC_POLY_REV_DIS (0x00000000U) /*!< Poly Reverse Disable */ 18 /** 19 * @} 20 */ 21 22 /** @defgroup CRC OUTXOR Reverse 23 * @{ 24 */ 25 #define CRC_OUTXOR_REV_EN (0x00000200U) /*!< OUTXOR Reverse Enable */ 26 #define CRC_OUTXOR_REV_DIS (0x00000000U) /*!< OUTXOR Reverse Disable */ 27 /** 28 * @} 29 */ 30 31 /** @defgroup CRC INIT Reverse 32 * @{ 33 */ 34 #define CRC_INIT_REV_EN (0x00000100U) /*!< INIT Reverse Enable */ 35 #define CRC_INIT_REV_DIS (0x00000000U) /*!< INIT Reverse Disable */ 36 /** 37 * @} 38 */ 39 40 /** @defgroup CRC RSLT Reverse 41 * @{ 42 */ 43 #define CRC_RSLT_REV_EN (0x00000080U) /*!< RSLT Reverse Enable */ 44 #define CRC_RSLT_REV_DIS (0x00000000U) /*!< RSLT Reverse Disable */ 45 /** 46 * @} 47 */ 48 49 /** @defgroup CRC DATA Reverse 50 * @{ 51 */ 52 #define CRC_DATA_REV_DISABLE (0x00000000U) /*!< DATA Reverse Disable */ 53 #define CRC_DATA_REV_BY_BYTE (0x00000020U) /*!< DATA Reverse By Byte */ 54 #define CRC_DATA_REV_BY_HALFWORD (0x00000040U) /*!< DATA Reverse By HalfWord */ 55 #define CRC_DATA_REV_BY_WORD (0x00000060U) /*!< DATA Reverse By Word */ 56 /** 57 * @} 58 */ 59 60 /** @defgroup CRC Poly Len 61 * @{ 62 */ 63 #define CRC_POLTY_LEN_32 (0x00000000U) /*!< POLY len = 32bit */ 64 #define CRC_POLTY_LEN_16 (0x00000008U) /*!< POLY len = 16bit */ 65 #define CRC_POLTY_LEN_8 (0x00000010U) /*!< POLY len = 8bit */ 66 #define CRC_POLTY_LEN_7 (0x00000018U) /*!< POLY len = 7bit */ 67 /** 68 * @} 69 */ 70 71 /** @defgroup CRC Data Len 72 * @{ 73 */ 74 #define CRC_DATA_LEN_1B (0x00000000U) /*!< DATA len = 1 Byte */ 75 #define CRC_DATA_LEN_2B (0x00000002U) /*!< DATA len = 2 Byte */ 76 #define CRC_DATA_LEN_3B (0x00000004U) /*!< DATA len = 3 Byte */ 77 #define CRC_DATA_LEN_4B (0x00000006U) /*!< DATA len = 4 Byte */ 78 /** 79 * @} 80 */ 81 82 /** @defgroup CRC RST 83 * @{ 84 */ 85 #define CRC_RST_EN (0x00000001U) /*!< RST CRC_DATA To CRC_INIT */ 86 #define CRC_RST_DIS (0x00000000U) /*!< RST CRC_DATA To CRC_INIT */ 87 88 /** 89 * @} 90 */ 91 92 /* 93 * @brief CRC Init Structure definition 94 */ 95 typedef struct 96 { 97 uint32_t PolyRev; /*!< Specifies if the Poly is reversed in CRC 98 This parameter can be a value of @ref CRC POLY Reverse. */ 99 uint32_t OutxorRev; /*!< Specifies if the Outxor is reversed in CRC 100 This parameter can be a value of @ref CRC OUTXOR Reverse. */ 101 uint32_t InitRev; /*!< Specifies if the Init is reversed in CRC 102 This parameter can be a value of @ref CRC INIT Reverse. */ 103 uint32_t RsltRev; /*!< Specifies if the Result is reversed in CRC 104 This parameter can be a value of @ref CRC RSLT Reverse. */ 105 uint32_t DataRev; /*!< Specifies if the Data is reversed in CRC 106 This parameter can be a value of @ref CRC DATA Reverse. */ 107 uint32_t PolyLen; /*!< Specifies the Poly Len in CRC 108 This parameter can be a value of @ref CRC Poly Len. */ 109 uint32_t DataLen; /*!< Specifies the Data Len in CRC 110 This parameter can be a value of @ref CRC Data Len. */ 111 uint32_t RST; /*!< Specifies if CRC is reset 112 This parameter can be a value of @ref CRC RST. */ 113 114 uint32_t InitData; /*!< This member configures the InitData. */ 115 116 uint32_t OutXorData; /*!< This member configures the OutXorData. */ 117 118 uint32_t PolyData; /*!< This member configures the PolyData. */ 119 120 uint32_t FData; /*!< This member configures the FData. */ 121 122 }CRC_InitTypeDef; 123 124 /* 125 * @brief UART handle Structure definition 126 */ 127 typedef struct 128 { 129 CRC_TypeDef *Instance; /*!< CRC registers base address */ 130 131 CRC_InitTypeDef Init; /*!< CRC calculate parameters */ 132 133 uint8_t* CRC_Data_Buff; /*!< CRC databuff base address */ 134 135 uint32_t CRC_Data_Len; /*!< amount of CRC data to be calculated */ 136 137 }CRC_HandleTypeDef; 138 139 140 /********************************************************************************* 141 * Function : HAL_CRC_Calculate 142 * Description : Calculate the crc calue of input data. 143 * Input : hcrc: CRC handle. 144 * Output : CRC value 145 * Author : cl Data : 2021 146 **********************************************************************************/ 147 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc); 148 149 150 #endif 151 152 153 154 155