1 /*!
2 * @file apm32e10x_crc.c
3 *
4 * @brief This file provides all the CRC firmware functions
5 *
6 * @version V1.0.2
7 *
8 * @date 2022-12-31
9 *
10 * @attention
11 *
12 * Copyright (C) 2021-2023 Geehy Semiconductor
13 *
14 * You may not use this file except in compliance with the
15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16 *
17 * The program is only for reference, which is distributed in the hope
18 * that it will be useful and instructional for customers to develop
19 * their software. Unless required by applicable law or agreed to in
20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23 * and limitations under the License.
24 */
25
26 #include "apm32e10x_crc.h"
27
28 /** @addtogroup APM32E10x_StdPeriphDriver
29 @{
30 */
31
32 /** @addtogroup CRC_Driver
33 * @brief CRC driver modules
34 @{
35 */
36
37 /** @defgroup CRC_Functions Functions
38 @{
39 */
40
41 /*!
42 * @brief Reset CRC data register.
43 *
44 * @param None
45 *
46 * @retval None
47 *
48 * @note
49 */
CRC_ResetDATA(void)50 void CRC_ResetDATA(void)
51 {
52 CRC->CTRL_B.RST = BIT_SET;
53 }
54
55 /*!
56 * @brief Calculate CRC of a 32bit data word.
57 *
58 * @param data: a data word to compute its CRC.
59 * This parameter can be a 32bit value:
60 *
61 * @retval A 32-bit CRC value
62 */
CRC_CalculateCRC(uint32_t data)63 uint32_t CRC_CalculateCRC(uint32_t data)
64 {
65 CRC->DATA = data;
66
67 return (CRC->DATA);
68 }
69
70 /*!
71 * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
72 *
73 * @param buf: Pointer to the buffer containing the data to be computed.
74 *
75 * @param bufLen: The length of buffer which is computed.
76 *
77 * @retval A 32-bit CRC value
78 */
CRC_CalculateBlockCRC(uint32_t * buf,uint32_t bufLen)79 uint32_t CRC_CalculateBlockCRC(uint32_t *buf, uint32_t bufLen)
80 {
81 while(bufLen--)
82 {
83 CRC->DATA = *buf++;
84 }
85
86 return (CRC->DATA);
87 }
88
89 /*!
90 * @brief Returns the current CRC value.
91 *
92 * @param None
93 *
94 * @retval A 32-bit CRC value
95 */
CRC_ReadCRC(void)96 uint32_t CRC_ReadCRC(void)
97 {
98 return (CRC->DATA);
99 }
100
101 /*!
102 * @brief Saves a 8bit data in the Independent Data register(INDATA).
103 *
104 * @param inData: a 8-bit value to be stored in the ID register
105 *
106 * @retval None
107 */
CRC_WriteIDRegister(uint8_t inData)108 void CRC_WriteIDRegister(uint8_t inData)
109 {
110 CRC->INDATA = inData;
111 }
112
113 /*!
114 * @brief Reads a 8-bit data saved in the Independent Data register(INDATA).
115 *
116 * @param None
117 *
118 * @retval a 8-bit value from the INDATA register
119 */
CRC_ReadIDRegister(void)120 uint8_t CRC_ReadIDRegister(void)
121 {
122 return (CRC->INDATA);
123 }
124
125 /**@} end of group CRC_Functions */
126 /**@} end of group CRC_Driver */
127 /**@} end of group APM32E10x_StdPeriphDriver */
128