at32f413_crc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. **************************************************************************
  3. * @file at32f413_crc.c
  4. * @brief contains all the functions for the crc firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f413_conf.h"
  25. /** @addtogroup AT32F413_periph_driver
  26. * @{
  27. */
  28. /** @defgroup CRC
  29. * @brief CRC driver modules
  30. * @{
  31. */
  32. #ifdef CRC_MODULE_ENABLED
  33. /** @defgroup CRC_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief reset the crc data register.
  38. * @param none
  39. * @retval none
  40. */
  41. void crc_data_reset(void)
  42. {
  43. /* reset crc generator */
  44. CRC->ctrl_bit.rst = 0x1;
  45. }
  46. /**
  47. * @brief compute the 32-bit crc of a given data word(32-bit).
  48. * @param data: data word(32-bit) to compute its crc
  49. * @retval 32-bit crc
  50. */
  51. uint32_t crc_one_word_calculate(uint32_t data)
  52. {
  53. CRC->dt = data;
  54. return (CRC->dt);
  55. }
  56. /**
  57. * @brief compute the 32-bit crc of a given buffer of data word(32-bit).
  58. * @param pbuffer: pointer to the buffer containing the data to be computed
  59. * @param length: length of the buffer to be computed
  60. * @retval 32-bit crc
  61. */
  62. uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length)
  63. {
  64. uint32_t index = 0;
  65. for(index = 0; index < length; index++)
  66. {
  67. CRC->dt = pbuffer[index];
  68. }
  69. return (CRC->dt);
  70. }
  71. /**
  72. * @brief return the current crc value.
  73. * @param none
  74. * @retval 32-bit crc
  75. */
  76. uint32_t crc_data_get(void)
  77. {
  78. return (CRC->dt);
  79. }
  80. /**
  81. * @brief store a 8-bit data in the common data register.
  82. * @param cdt_value: 8-bit value to be stored in the common data register
  83. * @retval none
  84. */
  85. void crc_common_data_set(uint8_t cdt_value)
  86. {
  87. CRC->cdt_bit.cdt = cdt_value;
  88. }
  89. /**
  90. * @brief return the 8-bit data stored in the common data register
  91. * @param none
  92. * @retval 8-bit value of the common data register
  93. */
  94. uint8_t crc_common_data_get(void)
  95. {
  96. return (CRC->cdt_bit.cdt);
  97. }
  98. /**
  99. * @brief set the 32-bit initial data of crc
  100. * @param value: initial data
  101. * @retval none
  102. */
  103. void crc_init_data_set(uint32_t value)
  104. {
  105. CRC->idt = value;
  106. }
  107. /**
  108. * @brief control the reversal of the bit order in the input data
  109. * @param value
  110. * this parameter can be one of the following values:
  111. * - CRC_REVERSE_INPUT_NO_AFFECTE
  112. * - CRC_REVERSE_INPUT_BY_BYTE
  113. * - CRC_REVERSE_INPUT_BY_HALFWORD
  114. * - CRC_REVERSE_INPUT_BY_WORD
  115. * @retval none.
  116. */
  117. void crc_reverse_input_data_set(crc_reverse_input_type value)
  118. {
  119. CRC->ctrl_bit.revid = value;
  120. }
  121. /**
  122. * @brief control the reversal of the bit order in the output data
  123. * @param value
  124. * this parameter can be one of the following values:
  125. * - CRC_REVERSE_OUTPUT_NO_AFFECTE
  126. * - CRC_REVERSE_OUTPUT_DATA
  127. * @retval none.
  128. */
  129. void crc_reverse_output_data_set(crc_reverse_output_type value)
  130. {
  131. CRC->ctrl_bit.revod = value;
  132. }
  133. /**
  134. * @}
  135. */
  136. #endif
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @}
  142. */