1 /*
2   ******************************************************************************
3   * @file    HAL_Crc.c
4   * @author  Firmware Team
5   * @version V1.0.0
6   * @date    2020
7   * @brief   CRC HAL module driver.
8   *          This file provides firmware functions to manage the following
9   *          functionalities of the Universal Asynchronous Receiver Transmitter Peripheral (UART).
10   *           @ Initialization and de-initialization functions
11   *           @ IO operation functions
12   *           @ Peripheral Control functions
13   ******************************************************************************
14 */
15 #include  "ACM32Fxx_HAL.h"
16 
17 /*********************************************************************************
18 * Function    : HAL_CRC_Init
19 * Description : Initialize the CRC MSP.
20 * Input       : hcrc: CRC handle.
21 * Output      :
22 * Author      : cl                         Data : 2021
23 **********************************************************************************/
HAL_CRC_Init(CRC_HandleTypeDef * hcrc)24 void HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
25 {
26 	System_Module_Enable(EN_CRC);
27 	hcrc->Instance->CTRL = hcrc->Init.PolyRev | hcrc->Init.OutxorRev | hcrc->Init.InitRev | hcrc->Init.RsltRev |
28 	                       hcrc->Init.DataRev | hcrc->Init.PolyLen   | hcrc->Init.DataLen;
29 
30 	hcrc->Instance->INIT = hcrc->Init.InitData;
31 	hcrc->Instance->OUTXOR = hcrc->Init.OutXorData;
32 	hcrc->Instance->POLY = hcrc->Init.PolyData;
33 }
34 
35 /*********************************************************************************
36 * Function    : HAL_CRC_Calculate
37 * Description : Calculate the crc calue of input data.
38 * Input       : hcrc:         CRC handle.
39 * Output      : CRC value
40 * Author      : cl                        Data : 2021
41 **********************************************************************************/
HAL_CRC_Calculate(CRC_HandleTypeDef * hcrc)42 uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc)
43 {
44 	HAL_CRC_Init(hcrc);
45 
46     while(hcrc->CRC_Data_Len--)
47     {
48         hcrc->Instance->DATA = *hcrc->CRC_Data_Buff++;
49     }
50 
51 	return (hcrc->Instance->DATA);
52 }
53 
54 
55