summaryrefslogtreecommitdiff
path: root/bsp/wch/arm/libraries/CH32F10x_StdPeriph_Driver/StdPeriph_Driver/src/ch32f10x_crc.c
blob: f7e8e333cb8d312ae7c24fc947e6e3f72a21b9eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/***************COPYRIGHT(C)  2019 WCH. A11 rights reserved*********************
* File Name          : ch32f10x_crc.c
* Author             : WCH
* Version            : V1.0.0
* Date               : 2019/10/15
* Description        : This file provides all the CRC firmware functions. 
*******************************************************************************/ 
#include "ch32f10x_crc.h"


/*******************************************************************************
* Function Name  : CRC_ResetDR
* Description    : Resets the CRC Data register (DR). 
* Input          : None
* Return         : None
*******************************************************************************/
void CRC_ResetDR(void)
{
  CRC->CTLR = CRC_CTLR_RESET;
}

/*******************************************************************************
* Function Name  : CRC_CalcCRC
* Description    : Computes the 32-bit CRC of a given data word(32-bit). 
* Input          : Data: data word(32-bit) to compute its CRC.
* Return         : 32-bit CRC.
*******************************************************************************/
uint32_t CRC_CalcCRC(uint32_t Data)
{
  CRC->DATAR = Data;
  
  return (CRC->DATAR);
}

/*******************************************************************************
* Function Name  : CRC_CalcBlockCRC
* Description    : Computes the 32-bit CRC of a given buffer of data word(32-bit).
* Input          : pBuffer: pointer to the buffer containing the data to be computed.
*                  BufferLength: length of the buffer to be computed.		
* Return         : 32-bit CRC.
*******************************************************************************/
uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
{
  uint32_t index = 0;
  
  for(index = 0; index < BufferLength; index++)
  {
    CRC->DATAR = pBuffer[index];
  }
	
  return (CRC->DATAR);
}

/*******************************************************************************
* Function Name  : CRC_GetCRC
* Description    : Returns the current CRC value.
* Input          : None
* Return         : 32-bit CRC.
*******************************************************************************/
uint32_t CRC_GetCRC(void)
{
  return (CRC->IDATAR);
}

/*******************************************************************************
* Function Name  : CRC_SetIDRegister
* Description    : Stores a 8-bit data in the Independent Data(ID) register.
* Input          : IDValue: 8-bit value to be stored in the ID register. 	
* Return         : None
*******************************************************************************/
void CRC_SetIDRegister(uint8_t IDValue)
{
  CRC->IDATAR = IDValue;
}

/*******************************************************************************
* Function Name  : CRC_GetIDRegister
* Description    : Returns the 8-bit data stored in the Independent Data(ID) register.
* Input          : None 	
* Return         : 8-bit value of the ID register.
*******************************************************************************/
uint8_t CRC_GetIDRegister(void)
{
  return (CRC->IDATAR);
}