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