1 /*!
2  * @file        apm32f4xx_crc.c
3  *
4  * @brief       This file provides all the CRC firmware functions
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-06-23
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2022 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 usefull 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 "apm32f4xx_crc.h"
27 
28 /** @addtogroup APM32F4xx_StdPeriphDriver
29   @{
30 */
31 
32 /** @defgroup CRC_Driver
33   * @brief CRC driver modules
34   @{
35 */
36 
37 /** @defgroup CRC_Functions
38   @{
39 */
40 
41 /*!
42  * @brief     Reset CRC data register.
43  *
44  * @param     None
45  *
46  * @retval    None
47  */
CRC_ResetDATA(void)48 void CRC_ResetDATA(void)
49 {
50     CRC->CTRL_B.RST = BIT_SET;
51 }
52 
53 /*!
54  * @brief     Calculate CRC of a 32bit data word.
55  *
56  * @param     data: a data word to compute its CRC.
57  *                  This parameter can be a 32bit value:
58  *
59  * @retval    A 32-bit CRC value
60  */
CRC_CalculateCRC(uint32_t data)61 uint32_t CRC_CalculateCRC(uint32_t data)
62 {
63     CRC->DATA = data;
64 
65     return (CRC->DATA);
66 }
67 
68 /*!
69  * @brief     Computes the 32-bit CRC of a given buffer of data word(32-bit).
70  *
71  * @param     buf: Pointer to the buffer containing the data to be computed.
72  *
73  * @param     bufLen: The length of buffer which is computed.
74  *
75  * @retval    A 32-bit CRC value
76  */
CRC_CalculateBlockCRC(uint32_t * buf,uint32_t bufLen)77 uint32_t CRC_CalculateBlockCRC(uint32_t *buf, uint32_t bufLen)
78 {
79     while (bufLen--)
80     {
81         CRC->DATA = *buf++;
82     }
83 
84     return (CRC->DATA);
85 }
86 
87 /*!
88  * @brief     Returns the current CRC value.
89  *
90  * @param     None
91  *
92  * @retval    A 32-bit CRC value
93  */
CRC_ReadCRC(void)94 uint32_t CRC_ReadCRC(void)
95 {
96     return (CRC->DATA);
97 }
98 
99 /*!
100  * @brief     Saves a 8bit data in the Independent Data register(INDATA).
101  *
102  * @param     inData: a 8-bit value to be stored in the ID register
103  *
104  * @retval    None
105  */
CRC_WriteIDRegister(uint8_t inData)106 void CRC_WriteIDRegister(uint8_t inData)
107 {
108     CRC->INDATA = inData;
109 }
110 
111 /*!
112  * @brief      Reads a 8-bit data saved in the Independent Data register(INDATA).
113  *
114  * @param      None
115  *
116  * @retval     a 8-bit value from the INDATA register
117  */
CRC_ReadIDRegister(void)118 uint8_t CRC_ReadIDRegister(void)
119 {
120     return (CRC->INDATA);
121 }
122 
123 /**@} end of group CRC_Functions */
124 /**@} end of group CRC_Driver */
125 /**@} end of group APM32F4xx_StdPeriphDriver */
126