1 /**************************************************************************//**
2 * @file crc.c
3 * @version V1.00
4 * @brief M480 CRC driver source file
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #include "NuMicro.h"
10
11 /** @addtogroup Standard_Driver Standard Driver
12 @{
13 */
14
15 /** @addtogroup CRC_Driver CRC Driver
16 @{
17 */
18
19 /** @addtogroup CRC_EXPORTED_FUNCTIONS CRC Exported Functions
20 @{
21 */
22
23 /**
24 * @brief CRC Open
25 *
26 * @param[in] u32Mode CRC operation polynomial mode. Valid values are:
27 * - \ref CRC_CCITT
28 * - \ref CRC_8
29 * - \ref CRC_16
30 * - \ref CRC_32
31 * @param[in] u32Attribute CRC operation data attribute. Valid values are combined with:
32 * - \ref CRC_CHECKSUM_COM
33 * - \ref CRC_CHECKSUM_RVS
34 * - \ref CRC_WDATA_COM
35 * - \ref CRC_WDATA_RVS
36 * @param[in] u32Seed Seed value.
37 * @param[in] u32DataLen CPU Write Data Length. Valid values are:
38 * - \ref CRC_CPU_WDATA_8
39 * - \ref CRC_CPU_WDATA_16
40 * - \ref CRC_CPU_WDATA_32
41 *
42 * @return None
43 *
44 * @details This function will enable the CRC controller by specify CRC operation mode, attribute, initial seed and write data length. \n
45 * After that, user can start to perform CRC calculate by calling CRC_WRITE_DATA macro or CRC_DAT register directly.
46 */
CRC_Open(uint32_t u32Mode,uint32_t u32Attribute,uint32_t u32Seed,uint32_t u32DataLen)47 void CRC_Open(uint32_t u32Mode, uint32_t u32Attribute, uint32_t u32Seed, uint32_t u32DataLen)
48 {
49 CRC->SEED = u32Seed;
50 CRC->CTL = u32Mode | u32Attribute | u32DataLen | CRC_CTL_CRCEN_Msk;
51
52 /* Setting CHKSINIT bit will reload the initial seed value(CRC_SEED register) to CRC controller */
53 CRC->CTL |= CRC_CTL_CHKSINIT_Msk;
54 }
55
56 /**
57 * @brief Get CRC Checksum
58 *
59 * @param[in] None
60 *
61 * @return Checksum Result
62 *
63 * @details This macro gets the CRC checksum result by current CRC polynomial mode.
64 */
CRC_GetChecksum(void)65 uint32_t CRC_GetChecksum(void)
66 {
67 uint32_t ret;
68
69 switch(CRC->CTL & CRC_CTL_CRCMODE_Msk)
70 {
71 case CRC_CCITT:
72 case CRC_16:
73 ret = (CRC->CHECKSUM & 0xFFFFU);
74 break;
75 case CRC_32:
76 ret = (CRC->CHECKSUM);
77 break;
78 case CRC_8:
79 ret = (CRC->CHECKSUM & 0xFFU);
80 break;
81 default:
82 ret = 0U;
83 break;
84 }
85
86 return ret;
87 }
88
89 /*@}*/ /* end of group CRC_EXPORTED_FUNCTIONS */
90
91 /*@}*/ /* end of group CRC_Driver */
92
93 /*@}*/ /* end of group Standard_Driver */
94
95 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
96