HAL_CRC.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Function : HAL_CRC_Init
  18. * Description : Initialize the CRC MSP.
  19. * Input : hcrc: CRC handle.
  20. * Output :
  21. * Author : cl Data : 2021
  22. **********************************************************************************/
  23. void HAL_CRC_Init(CRC_HandleTypeDef *hcrc)
  24. {
  25. System_Module_Enable(EN_CRC);
  26. hcrc->Instance->CTRL = hcrc->Init.PolyRev | hcrc->Init.OutxorRev | hcrc->Init.InitRev | hcrc->Init.RsltRev |
  27. hcrc->Init.DataRev | hcrc->Init.PolyLen | hcrc->Init.DataLen;
  28. hcrc->Instance->INIT = hcrc->Init.InitData;
  29. hcrc->Instance->OUTXOR = hcrc->Init.OutXorData;
  30. hcrc->Instance->POLY = hcrc->Init.PolyData;
  31. }
  32. /*********************************************************************************
  33. * Function : HAL_CRC_Calculate
  34. * Description : Calculate the crc calue of input data.
  35. * Input : hcrc: CRC handle.
  36. * Output : CRC value
  37. * Author : cl Data : 2021
  38. **********************************************************************************/
  39. uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc)
  40. {
  41. HAL_CRC_Init(hcrc);
  42. while(hcrc->CRC_Data_Len--)
  43. {
  44. hcrc->Instance->DATA = *hcrc->CRC_Data_Buff++;
  45. }
  46. return (hcrc->Instance->DATA);
  47. }