gd32f10x_crc.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. ******************************************************************************
  3. * @brief CRC functions of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "gd32f10x_crc.h"
  8. /** @addtogroup GD32F10x_Firmware
  9. * @{
  10. */
  11. /** @defgroup CRC
  12. * @brief CRC driver modules
  13. * @{
  14. */
  15. /** @defgroup CRC_Private_Functions
  16. * @{
  17. */
  18. /**
  19. * @brief Reset CRC DTR register to the value of 0xFFFFFFFF.
  20. * @param None
  21. * @retval None
  22. */
  23. void CRC_ResetDTR(void)
  24. {
  25. CRC->CTLR = CRC_CTLR_RESET;
  26. }
  27. /**
  28. * @brief Compute the 32-bit CRC value of a 32-bit data.
  29. * @param CRC_data: data to compute its CRC value
  30. * @retval 32-bit CRC value
  31. */
  32. uint32_t CRC_CalcSingleData(uint32_t CRC_data)
  33. {
  34. CRC->DTR = CRC_data;
  35. return (CRC->DTR);
  36. }
  37. /**
  38. * @brief Compute the 32-bit CRC value of a 32-bit data array.
  39. * @param pbuffer[]: pointer to the data array
  40. * @param buffer_length: length of the data array
  41. * @retval 32-bit CRC value
  42. */
  43. uint32_t CRC_CalcDataFlow(uint32_t pbuffer[], uint32_t buffer_length)
  44. {
  45. uint32_t index = 0;
  46. for (index = 0; index < buffer_length; index++) {
  47. CRC->DTR = pbuffer[index];
  48. }
  49. return (CRC->DTR);
  50. }
  51. /**
  52. * @brief Read current CRC value.
  53. * @param None
  54. * @retval 32-bit CRC value
  55. */
  56. uint32_t CRC_ReadDTR(void)
  57. {
  58. return (CRC->DTR);
  59. }
  60. /**
  61. * @brief Write an 8-bit data in FDTR.
  62. * @param CRC_fdtr: 8-bit data to write
  63. * @retval None
  64. */
  65. void CRC_WriteFDTR(uint8_t CRC_fdtr)
  66. {
  67. CRC->FDTR = CRC_fdtr;
  68. }
  69. /**
  70. * @brief Read the 8-bit data stored in FDTR
  71. * @param None
  72. * @retval 8-bit data
  73. */
  74. uint8_t CRC_ReadFDTR(void)
  75. {
  76. return (CRC->FDTR);
  77. }
  78. /**
  79. * @}
  80. */
  81. /**
  82. * @}
  83. */
  84. /**
  85. * @}
  86. */