at32f413_crc.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. **************************************************************************
  3. * @file at32f413_crc.h
  4. * @brief at32f413 crc header file
  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. /* define to prevent recursive inclusion -------------------------------------*/
  25. #ifndef __AT32F413_CRC_H
  26. #define __AT32F413_CRC_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* includes ------------------------------------------------------------------*/
  31. #include "at32f413.h"
  32. /** @addtogroup AT32F413_periph_driver
  33. * @{
  34. */
  35. /** @addtogroup CRC
  36. * @{
  37. */
  38. /** @defgroup CRC_exported_types
  39. * @{
  40. */
  41. /**
  42. * @brief crc reverse input data
  43. */
  44. typedef enum
  45. {
  46. CRC_REVERSE_INPUT_NO_AFFECTE = 0x00, /*!< input data no reverse */
  47. CRC_REVERSE_INPUT_BY_BYTE = 0x01, /*!< input data reverse by byte */
  48. CRC_REVERSE_INPUT_BY_HALFWORD = 0x02, /*!< input data reverse by half word */
  49. CRC_REVERSE_INPUT_BY_WORD = 0x03 /*!< input data reverse by word */
  50. } crc_reverse_input_type;
  51. /**
  52. * @brief crc reverse output data
  53. */
  54. typedef enum
  55. {
  56. CRC_REVERSE_OUTPUT_NO_AFFECTE = 0x00, /*!< output data no reverse */
  57. CRC_REVERSE_OUTPUT_DATA = 0x01 /*!< output data reverse by word */
  58. } crc_reverse_output_type;
  59. /**
  60. * @brief crc polynomial size
  61. */
  62. typedef enum
  63. {
  64. CRC_POLY_SIZE_32B = 0x00, /*!< polynomial size 32 bits */
  65. CRC_POLY_SIZE_16B = 0x01, /*!< polynomial size 16 bits */
  66. CRC_POLY_SIZE_8B = 0x02, /*!< polynomial size 8 bits */
  67. CRC_POLY_SIZE_7B = 0x03 /*!< polynomial size 7 bits */
  68. } crc_poly_size_type;
  69. /**
  70. * @brief type define crc register all
  71. */
  72. typedef struct
  73. {
  74. /**
  75. * @brief crc dt register, offset:0x00
  76. */
  77. union
  78. {
  79. __IO uint32_t dt;
  80. struct
  81. {
  82. __IO uint32_t dt : 32; /* [31:0] */
  83. } dt_bit;
  84. };
  85. /**
  86. * @brief crc cdt register, offset:0x04
  87. */
  88. union
  89. {
  90. __IO uint32_t cdt;
  91. struct
  92. {
  93. __IO uint32_t cdt : 8 ; /* [7:0] */
  94. __IO uint32_t reserved1 : 24 ;/* [31:8] */
  95. } cdt_bit;
  96. };
  97. /**
  98. * @brief crc ctrl register, offset:0x08
  99. */
  100. union
  101. {
  102. __IO uint32_t ctrl;
  103. struct
  104. {
  105. __IO uint32_t rst : 1 ; /* [0] */
  106. __IO uint32_t reserved1 : 2 ; /* [2:1] */
  107. __IO uint32_t poly_size : 2 ; /* [4:3] */
  108. __IO uint32_t revid : 2 ; /* [6:5] */
  109. __IO uint32_t revod : 1 ; /* [7] */
  110. __IO uint32_t reserved2 : 24 ;/* [31:8] */
  111. } ctrl_bit;
  112. };
  113. /**
  114. * @brief crm reserved1 register, offset:0x0C
  115. */
  116. __IO uint32_t reserved1;
  117. /**
  118. * @brief crc idt register, offset:0x10
  119. */
  120. union
  121. {
  122. __IO uint32_t idt;
  123. struct
  124. {
  125. __IO uint32_t idt : 32; /* [31:0] */
  126. } idt_bit;
  127. };
  128. /**
  129. * @brief crc polynomial register, offset:0x14
  130. */
  131. union
  132. {
  133. __IO uint32_t poly;
  134. struct
  135. {
  136. __IO uint32_t poly : 32; /* [31:0] */
  137. } poly_bit;
  138. };
  139. } crc_type;
  140. /**
  141. * @}
  142. */
  143. #define CRC ((crc_type *) CRC_BASE)
  144. /** @defgroup CRC_exported_functions
  145. * @{
  146. */
  147. void crc_data_reset(void);
  148. uint32_t crc_one_word_calculate(uint32_t data);
  149. uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length);
  150. uint32_t crc_data_get(void);
  151. void crc_common_data_set(uint8_t cdt_value);
  152. uint8_t crc_common_data_get(void);
  153. void crc_init_data_set(uint32_t value);
  154. void crc_reverse_input_data_set(crc_reverse_input_type value);
  155. void crc_reverse_output_data_set(crc_reverse_output_type value);
  156. void crc_poly_value_set(uint32_t value);
  157. uint32_t crc_poly_value_get(void);
  158. void crc_poly_size_set(crc_poly_size_type size);
  159. crc_poly_size_type crc_poly_size_get(void);
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */
  166. /**
  167. * @}
  168. */
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif