apm32f10x_crc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*!
  2. * @file apm32f10x_crc.c
  3. *
  4. * @brief This file provides all the CRC firmware functions
  5. *
  6. * @version V1.0.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. #include "apm32f10x_crc.h"
  26. /** @addtogroup APM32F10x_StdPeriphDriver
  27. @{
  28. */
  29. /** @addtogroup CRC_Driver CRC Driver
  30. * @brief CRC driver modules
  31. @{
  32. */
  33. /** @defgroup CRC_Functions Functions
  34. @{
  35. */
  36. /*!
  37. * @brief Reset CRC data register.
  38. *
  39. * @param None
  40. *
  41. * @retval None
  42. */
  43. void CRC_ResetDATA(void)
  44. {
  45. CRC->CTRL_B.RST = BIT_SET;
  46. }
  47. /*!
  48. * @brief Calculate CRC of a 32bit data word.
  49. *
  50. * @param data: a data word to compute its CRC.
  51. * This parameter can be a 32bit value:
  52. *
  53. * @retval A 32-bit CRC value
  54. */
  55. uint32_t CRC_CalculateCRC(uint32_t data)
  56. {
  57. CRC->DATA = data;
  58. return (CRC->DATA);
  59. }
  60. /*!
  61. * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
  62. *
  63. * @param buf: Pointer to the buffer containing the data to be computed.
  64. *
  65. * @param bufLen: The length of buffer which is computed.
  66. *
  67. * @retval A 32-bit CRC value
  68. */
  69. uint32_t CRC_CalculateBlockCRC(uint32_t* buf, uint32_t bufLen)
  70. {
  71. while (bufLen--)
  72. {
  73. CRC->DATA = *buf++;
  74. }
  75. return (CRC->DATA);
  76. }
  77. /*!
  78. * @brief Returns the current CRC value.
  79. *
  80. * @param None
  81. *
  82. * @retval A 32-bit CRC value
  83. */
  84. uint32_t CRC_ReadCRC(void)
  85. {
  86. return (CRC->DATA);
  87. }
  88. /*!
  89. * @brief Saves a 8bit data in the Independent Data register(INDATA).
  90. *
  91. * @param inData: a 8-bit value to be stored in the ID register
  92. *
  93. * @retval None
  94. */
  95. void CRC_WriteIDRegister(uint8_t inData)
  96. {
  97. CRC->INDATA = inData;
  98. }
  99. /*!
  100. * @brief Reads a 8-bit data saved in the Independent Data register(INDATA).
  101. *
  102. * @param None
  103. *
  104. * @retval a 8-bit value from the INDATA register
  105. */
  106. uint8_t CRC_ReadIDRegister(void)
  107. {
  108. return (CRC->INDATA);
  109. }
  110. /**@} end of group CRC_Functions*/
  111. /**@} end of group CRC_Driver*/
  112. /**@} end of group APM32F10x_StdPeriphDriver */