HAL_CRC.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ******************************************************************************
  3. * @file HAL_CRC.h
  4. * @version V1.0.0
  5. * @date 2021
  6. * @brief Header file of CRC HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_CRC_H__
  10. #define __HAL_CRC_H__
  11. #include "ACM32Fxx_HAL.h"
  12. /** @defgroup CRC POLY Reverse
  13. * @{
  14. */
  15. #define CRC_POLY_REV_EN (0x00000400U) /*!< Poly Reverse Enable */
  16. #define CRC_POLY_REV_DIS (0x00000000U) /*!< Poly Reverse Disable */
  17. /**
  18. * @}
  19. */
  20. /** @defgroup CRC OUTXOR Reverse
  21. * @{
  22. */
  23. #define CRC_OUTXOR_REV_EN (0x00000200U) /*!< OUTXOR Reverse Enable */
  24. #define CRC_OUTXOR_REV_DIS (0x00000000U) /*!< OUTXOR Reverse Disable */
  25. /**
  26. * @}
  27. */
  28. /** @defgroup CRC INIT Reverse
  29. * @{
  30. */
  31. #define CRC_INIT_REV_EN (0x00000100U) /*!< INIT Reverse Enable */
  32. #define CRC_INIT_REV_DIS (0x00000000U) /*!< INIT Reverse Disable */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup CRC RSLT Reverse
  37. * @{
  38. */
  39. #define CRC_RSLT_REV_EN (0x00000080U) /*!< RSLT Reverse Enable */
  40. #define CRC_RSLT_REV_DIS (0x00000000U) /*!< RSLT Reverse Disable */
  41. /**
  42. * @}
  43. */
  44. /** @defgroup CRC DATA Reverse
  45. * @{
  46. */
  47. #define CRC_DATA_REV_DISABLE (0x00000000U) /*!< DATA Reverse Disable */
  48. #define CRC_DATA_REV_BY_BYTE (0x00000020U) /*!< DATA Reverse By Byte */
  49. #define CRC_DATA_REV_BY_HALFWORD (0x00000040U) /*!< DATA Reverse By HalfWord */
  50. #define CRC_DATA_REV_BY_WORD (0x00000060U) /*!< DATA Reverse By Word */
  51. /**
  52. * @}
  53. */
  54. /** @defgroup CRC Poly Len
  55. * @{
  56. */
  57. #define CRC_POLTY_LEN_32 (0x00000000U) /*!< POLY len = 32bit */
  58. #define CRC_POLTY_LEN_16 (0x00000008U) /*!< POLY len = 16bit */
  59. #define CRC_POLTY_LEN_8 (0x00000010U) /*!< POLY len = 8bit */
  60. #define CRC_POLTY_LEN_7 (0x00000018U) /*!< POLY len = 7bit */
  61. /**
  62. * @}
  63. */
  64. /** @defgroup CRC Data Len
  65. * @{
  66. */
  67. #define CRC_DATA_LEN_1B (0x00000000U) /*!< DATA len = 1 Byte */
  68. #define CRC_DATA_LEN_2B (0x00000002U) /*!< DATA len = 2 Byte */
  69. #define CRC_DATA_LEN_3B (0x00000004U) /*!< DATA len = 3 Byte */
  70. #define CRC_DATA_LEN_4B (0x00000006U) /*!< DATA len = 4 Byte */
  71. /**
  72. * @}
  73. */
  74. /** @defgroup CRC RST
  75. * @{
  76. */
  77. #define CRC_RST_EN (0x00000001U) /*!< RST CRC_DATA To CRC_INIT */
  78. #define CRC_RST_DIS (0x00000000U) /*!< RST CRC_DATA To CRC_INIT */
  79. /**
  80. * @}
  81. */
  82. /*
  83. * @brief CRC Init Structure definition
  84. */
  85. typedef struct
  86. {
  87. uint32_t PolyRev; /*!< Specifies if the Poly is reversed in CRC
  88. This parameter can be a value of @ref CRC POLY Reverse. */
  89. uint32_t OutxorRev; /*!< Specifies if the Outxor is reversed in CRC
  90. This parameter can be a value of @ref CRC OUTXOR Reverse. */
  91. uint32_t InitRev; /*!< Specifies if the Init is reversed in CRC
  92. This parameter can be a value of @ref CRC INIT Reverse. */
  93. uint32_t RsltRev; /*!< Specifies if the Result is reversed in CRC
  94. This parameter can be a value of @ref CRC RSLT Reverse. */
  95. uint32_t DataRev; /*!< Specifies if the Data is reversed in CRC
  96. This parameter can be a value of @ref CRC DATA Reverse. */
  97. uint32_t PolyLen; /*!< Specifies the Poly Len in CRC
  98. This parameter can be a value of @ref CRC Poly Len. */
  99. uint32_t DataLen; /*!< Specifies the Data Len in CRC
  100. This parameter can be a value of @ref CRC Data Len. */
  101. uint32_t RST; /*!< Specifies if CRC is reset
  102. This parameter can be a value of @ref CRC RST. */
  103. uint32_t InitData; /*!< This member configures the InitData. */
  104. uint32_t OutXorData; /*!< This member configures the OutXorData. */
  105. uint32_t PolyData; /*!< This member configures the PolyData. */
  106. uint32_t FData; /*!< This member configures the FData. */
  107. }CRC_InitTypeDef;
  108. /*
  109. * @brief UART handle Structure definition
  110. */
  111. typedef struct
  112. {
  113. CRC_TypeDef *Instance; /*!< CRC registers base address */
  114. CRC_InitTypeDef Init; /*!< CRC calculate parameters */
  115. uint8_t* CRC_Data_Buff; /*!< CRC databuff base address */
  116. uint32_t CRC_Data_Len; /*!< amount of CRC data to be calculated */
  117. }CRC_HandleTypeDef;
  118. /*********************************************************************************
  119. * Function : HAL_CRC_Calculate
  120. * Description : Calculate the crc calue of input data.
  121. * Input : hcrc: CRC handle.
  122. * Output : CRC value
  123. * Author : cl Data : 2021
  124. **********************************************************************************/
  125. uint32_t HAL_CRC_Calculate(CRC_HandleTypeDef *hcrc);
  126. #endif