summaryrefslogtreecommitdiff
path: root/bsp/acm32/acm32f4xx-nucleo/libraries/HAL_Driver/Src/HAL_CRC.c
blob: bdd086b0b0fef5f21fe5992df8a0725865d7df97 (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
/*
  ******************************************************************************
  * @file    HAL_Crc.c
  * @author  Firmware Team
  * @version V1.0.0
  * @date    2020
  * @brief   CRC HAL module driver.
  *          This file provides firmware functions to manage the following
  *          functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
  *           @ Initialization and de-initialization functions
  *           @ IO operation functions
  *           @ Peripheral Control functions
  ******************************************************************************
*/
#include  "ACM32Fxx_HAL.h"

/*********************************************************************************
* Function    : HAL_CRC_Init
* Description : Initialize the CRC MSP.
* Input       : hcrc: CRC handle.
* Output      : 
* Author      : cl                         Data : 2021 
**********************************************************************************/
void HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
{
	System_Module_Enable(EN_CRC);
	hcrc->Instance->CTRL = hcrc->Init.PolyRev | hcrc->Init.OutxorRev | hcrc->Init.InitRev | hcrc->Init.RsltRev |
	                       hcrc->Init.DataRev | hcrc->Init.PolyLen   | hcrc->Init.DataLen;

	hcrc->Instance->INIT = hcrc->Init.InitData;	
	hcrc->Instance->OUTXOR = hcrc->Init.OutXorData;
	hcrc->Instance->POLY = hcrc->Init.PolyData;
}

/*********************************************************************************
* Function    : HAL_CRC_Calculate
* Description : Calculate the crc calue of input data.
* Input       : hcrc:         CRC handle.
* Output      : CRC value
* Author      : cl                        Data : 2021 
**********************************************************************************/
uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc)
{
	HAL_CRC_Init(hcrc);

    while(hcrc->CRC_Data_Len--)
    {
        hcrc->Instance->DATA = *hcrc->CRC_Data_Buff++;
    }

	return (hcrc->Instance->DATA);
}