1 /**************************************************************************//** 2 * @file crc.h 3 * @version V1.00 4 * $Date: 20/05/28 2:08p $ 5 * @brief M2L31 series CRC driver header file 6 * 7 * SPDX-License-Identifier: Apache-2.0 8 * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved. 9 *****************************************************************************/ 10 #ifndef __CRC_H__ 11 #define __CRC_H__ 12 13 #ifdef __cplusplus 14 extern "C" 15 { 16 #endif 17 18 19 /** @addtogroup Standard_Driver Standard Driver 20 @{ 21 */ 22 23 /** @addtogroup CRC_Driver CRC Driver 24 @{ 25 */ 26 27 /** @addtogroup CRC_EXPORTED_CONSTANTS CRC Exported Constants 28 @{ 29 */ 30 /*---------------------------------------------------------------------------------------------------------*/ 31 /* CRC Polynomial Mode Constant Definitions */ 32 /*---------------------------------------------------------------------------------------------------------*/ 33 #define CRC_CCITT (0UL << CRC_CTL_CRCMODE_Pos) /*!<CRC Polynomial Mode - CCITT \hideinitializer */ 34 #define CRC_8 (1UL << CRC_CTL_CRCMODE_Pos) /*!<CRC Polynomial Mode - CRC8 \hideinitializer */ 35 #define CRC_16 (2UL << CRC_CTL_CRCMODE_Pos) /*!<CRC Polynomial Mode - CRC16 \hideinitializer */ 36 #define CRC_32 (3UL << CRC_CTL_CRCMODE_Pos) /*!<CRC Polynomial Mode - CRC32 \hideinitializer */ 37 38 /*---------------------------------------------------------------------------------------------------------*/ 39 /* Checksum, Write data Constant Definitions */ 40 /*---------------------------------------------------------------------------------------------------------*/ 41 #define CRC_CHECKSUM_COM (CRC_CTL_CHKSFMT_Msk) /*!<CRC Checksum Complement \hideinitializer */ 42 #define CRC_CHECKSUM_RVS (CRC_CTL_CHKSREV_Msk) /*!<CRC Checksum Reverse \hideinitializer */ 43 #define CRC_WDATA_COM (CRC_CTL_DATFMT_Msk) /*!<CRC Write Data Complement \hideinitializer */ 44 #define CRC_WDATA_RVS (CRC_CTL_DATREV_Msk) /*!<CRC Write Data Reverse \hideinitializer */ 45 46 /*---------------------------------------------------------------------------------------------------------*/ 47 /* CPU Write Data Length Constant Definitions */ 48 /*---------------------------------------------------------------------------------------------------------*/ 49 #define CRC_CPU_WDATA_8 (0UL << CRC_CTL_DATLEN_Pos) /*!<CRC CPU Write Data length is 8-bit \hideinitializer */ 50 #define CRC_CPU_WDATA_16 (1UL << CRC_CTL_DATLEN_Pos) /*!<CRC CPU Write Data length is 16-bit \hideinitializer */ 51 #define CRC_CPU_WDATA_32 (2UL << CRC_CTL_DATLEN_Pos) /*!<CRC CPU Write Data length is 32-bit \hideinitializer */ 52 53 /*@}*/ /* end of group CRC_EXPORTED_CONSTANTS */ 54 55 56 /** @addtogroup CRC_EXPORTED_FUNCTIONS CRC Exported Functions 57 @{ 58 */ 59 60 /** 61 * @brief Set CRC Seed Value 62 * 63 * @param[in] u32Seed Seed value 64 * 65 * @return None 66 * 67 * @details This macro is used to set CRC seed value. 68 * 69 * @note User must to perform CRC_CHKSINIT(CRC_CTL[1] CRC Engine Reset) to reload the new seed value 70 * to CRC controller. 71 * \hideinitializer 72 */ 73 #define CRC_SET_SEED(u32Seed) do{ CRC->SEED = (u32Seed); CRC->CTL |= CRC_CTL_CHKSINIT_Msk; }while(0) 74 75 /** 76 * @brief Get CRC Seed Value 77 * 78 * @param None 79 * 80 * @return CRC seed value 81 * 82 * @details This macro gets the current CRC seed value. 83 * \hideinitializer 84 */ 85 #define CRC_GET_SEED() (CRC->SEED) 86 87 /** 88 * @brief CRC Write Data 89 * 90 * @param[in] u32Data Write data 91 * 92 * @return None 93 * 94 * @details User can write data directly to CRC Write Data Register(CRC_DAT) by this macro to perform CRC operation. 95 * \hideinitializer 96 */ 97 #define CRC_WRITE_DATA(u32Data) (CRC->DAT = (u32Data)) 98 99 /** 100 * @brief Set CRC Polynomial Value 101 * 102 * @param[in] u32Polynomial Polynomial Value 103 * 104 * @return None 105 * 106 * @details This macro is used to set CRC Polynomial value. 107 * 108 * @note User can write Polynomial value directly to CRC Polynomial Register(CRC_POLYNOMIAL) by this macro to perform CRC operation. 109 * \hideinitializer 110 */ 111 #define CRC_SET_POLYNOMIAL(u32Polynomial) (CRC->POLYNOMIAL = (u32Polynomial)) 112 113 void CRC_Open(uint32_t u32Mode, uint32_t u32Attribute, uint32_t u32Seed, uint32_t u32DataLen); 114 uint32_t CRC_GetChecksum(void); 115 116 /*@}*/ /* end of group CRC_EXPORTED_FUNCTIONS */ 117 118 /*@}*/ /* end of group CRC_Driver */ 119 120 /*@}*/ /* end of group Standard_Driver */ 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif 127 128 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/ 129