1 /********************************** (C) COPYRIGHT *******************************
2 * File Name : ch32f20x_crc.c
3 * Author : WCH
4 * Version : V1.0.0
5 * Date : 2021/08/08
6 * Description : This file provides all the CRC firmware functions.
7 *******************************************************************************/
8 #include "ch32f20x_crc.h"
9
10 /*******************************************************************************
11 * Function Name : CRC_ResetDR
12 * Description : Resets the CRC Data register (DR).
13 * Input : None
14 * Return : None
15 *******************************************************************************/
CRC_ResetDR(void)16 void CRC_ResetDR(void)
17 {
18 CRC->CTLR = CRC_CTLR_RESET;
19 }
20
21 /*******************************************************************************
22 * Function Name : CRC_CalcCRC
23 * Description : Computes the 32-bit CRC of a given data word(32-bit).
24 * Input : Data: data word(32-bit) to compute its CRC.
25 * Return : 32-bit CRC.
26 *******************************************************************************/
CRC_CalcCRC(uint32_t Data)27 uint32_t CRC_CalcCRC(uint32_t Data)
28 {
29 CRC->DATAR = Data;
30
31 return (CRC->DATAR);
32 }
33
34 /*******************************************************************************
35 * Function Name : CRC_CalcBlockCRC
36 * Description : Computes the 32-bit CRC of a given buffer of data word(32-bit).
37 * Input : pBuffer: pointer to the buffer containing the data to be computed.
38 * BufferLength: length of the buffer to be computed.
39 * Return : 32-bit CRC.
40 *******************************************************************************/
CRC_CalcBlockCRC(uint32_t pBuffer[],uint32_t BufferLength)41 uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
42 {
43 uint32_t index = 0;
44
45 for(index = 0; index < BufferLength; index++)
46 {
47 CRC->DATAR = pBuffer[index];
48 }
49
50 return (CRC->DATAR);
51 }
52
53 /*******************************************************************************
54 * Function Name : CRC_GetCRC
55 * Description : Returns the current CRC value.
56 * Input : None
57 * Return : 32-bit CRC.
58 *******************************************************************************/
CRC_GetCRC(void)59 uint32_t CRC_GetCRC(void)
60 {
61 return (CRC->IDATAR);
62 }
63
64 /*******************************************************************************
65 * Function Name : CRC_SetIDRegister
66 * Description : Stores a 8-bit data in the Independent Data(ID) register.
67 * Input : IDValue: 8-bit value to be stored in the ID register.
68 * Return : None
69 *******************************************************************************/
CRC_SetIDRegister(uint8_t IDValue)70 void CRC_SetIDRegister(uint8_t IDValue)
71 {
72 CRC->IDATAR = IDValue;
73 }
74
75 /*******************************************************************************
76 * Function Name : CRC_GetIDRegister
77 * Description : Returns the 8-bit data stored in the Independent Data(ID) register.
78 * Input : None
79 * Return : 8-bit value of the ID register.
80 *******************************************************************************/
CRC_GetIDRegister(void)81 uint8_t CRC_GetIDRegister(void)
82 {
83 return (CRC->IDATAR);
84 }
85
86
87
88
89
90
91
92
93