crc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /******************************************************************************
  2. *
  3. * @brief Cyclic redundancy check (CRC) header file.
  4. *
  5. ******************************************************************************/
  6. #ifndef CRC_H_
  7. #define CRC_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /******************************************************************************
  12. * Includes
  13. ******************************************************************************/
  14. /******************************************************************************
  15. * Constants
  16. ******************************************************************************/
  17. /******************************************************************************
  18. * Macros
  19. ******************************************************************************/
  20. /******************************************************************************
  21. * CRC control bit definition
  22. *
  23. *//*! @addtogroup crc_controlbit
  24. * @{
  25. *******************************************************************************/
  26. /*!
  27. * @brief CRC control register bit definition.
  28. *
  29. */
  30. #define CRC_WIDTH_16BIT 0 /*!< select CRC16 protocol */
  31. #define CRC_WIDTH_32BIT 1 /*!< select CRC32 protocol */
  32. #define CRC_DATA_SEED 1 /*!< Write CRC Data Register are seed */
  33. #define CRC_DATA_DATA 0 /*!< Write CRC Data Register are data */
  34. #define CRC_READ_COMPLETE 1 /*!< Invert or complement read CRC Data register */
  35. #define CRC_READ_NONE 0 /*!< No XOR on reading */
  36. #define CRC_READ_TRANSPOSE_NONE 0 /*!< No transposition in read */
  37. #define CRC_READ_TRANSPOSE_BIT 1 /*!< only bits in bytes are transposed in read */
  38. #define CRC_READ_TRANSPOSE_ALL 2 /*!< both bits in bytes and bytes are transposed in read */
  39. #define CRC_READ_TRANSPOSE_BYTE 3 /*!< only bytes are transposed in read */
  40. #define CRC_WRITE_TRANSPOSE_NONE 0 /*!< No transposition write */
  41. #define CRC_WRITE_TRANSPOSE_BIT 1 /*!< only bits in bytes are transposed in write */
  42. #define CRC_WRITE_TRANSPOSE_ALL 2 /*!< both bits in bytes and bytes are transposed in write */
  43. #define CRC_WRITE_TRANSPOSE_BYTE 3 /*!< only bytes are transposed in write */
  44. /*! @} End of crc_controlbit */
  45. /******************************************************************************
  46. * Types
  47. ******************************************************************************/
  48. /* CRC configuration structure
  49. */
  50. /******************************************************************************
  51. * CRC Configuration Structure type.
  52. *
  53. *//*! @addtogroup crc_config_type
  54. * @{
  55. *******************************************************************************/
  56. /*!
  57. * @brief CRC Configuration Structure.
  58. *
  59. */
  60. typedef struct
  61. {
  62. uint8_t bWidth : 1; /*!< 1: 32-bit CRC protocol , 0: 16-bit CRC protocol */
  63. uint8_t bDataType : 1; /*!< 1: write seed , 0: write data */
  64. uint8_t bFinalXOR : 1; /*!< 1: Invert or complement read , 0: No XOR on reading */
  65. uint8_t bRESERVED : 1; /*!< reserved bit */
  66. uint8_t bTransposeReadType : 2; /*!< type of transpose For read, see reference manual */
  67. uint8_t bTransposeWriteType : 2; /*!< type of transpose For write, see reference manual */
  68. uint32_t u32PolyData ; /*!< 32bit or 16-biy poly data */
  69. } CRC_ConfigType, *CRC_ConfigPtr ;
  70. /*! @} End of crc_config_type */
  71. /******************************************************************************
  72. * Global variables
  73. ******************************************************************************/
  74. /******************************************************************************
  75. * CRC API list
  76. *
  77. *//*! @addtogroup crc_api_list
  78. * @{
  79. *******************************************************************************/
  80. /******************************************************************************
  81. * Global functions
  82. ******************************************************************************/
  83. void CRC_Init(CRC_ConfigType *pConfig);
  84. uint32_t CRC_Cal16(uint32_t u32Seed, uint8_t *msg, uint32_t u32SizeBytes);
  85. uint32_t CRC_Cal32(uint32_t u32Seed, uint8_t *msg, uint32_t u32SizeBytes);
  86. void CRC_DeInit(void);
  87. /*! @} End of crc_api_list */
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* CRC_H_ */