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