hc32f460_crc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_crc.h
  11. **
  12. ** A detailed description is available at
  13. ** @link CrcGroup Crc description @endlink
  14. **
  15. ** - 2019-03-07 CDT First version for Device Driver Library of Crc.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_CRC_H__
  19. #define __HC32F460_CRC_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_CRC_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup CrcGroup Cyclic Redundancy Check(CRC)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /* Bits definitions of CRC control register(CRC_CR). */
  41. /*
  42. * Definitions of CRC protocol.
  43. * NOTE: CRC16 polynomial is X16 + X12 + X5 + 1
  44. * CRC32 polynomial is X32 + X26 + X23 + X22 + X16 + X12 + X11 + X10 + \
  45. * X8 + X7 + X5 + X4 + X2 + X + 1
  46. */
  47. #define CRC_SEL_16B ((uint32_t)0x0)
  48. #define CRC_SEL_32B ((uint32_t)(0x1ul << 1u))
  49. /*
  50. * Identifies the transpose configuration of the source data.
  51. * If this function is enabled, the source data's bits in bytes are transposed.
  52. * e.g. There's a source data 0x1234 which will be calculated checksum and this
  53. * function is enabled, the final data be calculated is 0x482C.
  54. * 0x12: bit0->bit7, bit1->bit6, ..., bit7->bit0, the data byte changed to 0x48.
  55. * 0x48: bit0->bit7, bit1->bit6, ..., bit7->bit0, the data byte changed to 0x2C.
  56. * The same to 32 bit data while using CRC32.
  57. */
  58. #define CRC_REFIN_DISABLE ((uint32_t)0x0)
  59. #define CRC_REFIN_ENABLE ((uint32_t)(0x1ul << 2u))
  60. /*
  61. * Identifies the transpose configuration of the checksum.
  62. * If this function is enabled, bits of the checksum will be transposed.
  63. * e.g. There is a CRC16 checksum is 0x5678 before this function enabled, then
  64. * this function is enabled, the checksum will be 0x1E6A.
  65. * 0x5678: bit0->bit15, bit1->bit14, ..., bit15->bit0, the final data is 0x1E6A.
  66. * The same to CRC32 checksum while using CRC32.
  67. */
  68. #define CRC_REFOUT_DISABLE ((uint32_t)0x0)
  69. #define CRC_REFOUT_ENABLE ((uint32_t)(0x1ul << 3u))
  70. /*
  71. * XORs the CRC checksum with 0xFFFF(CRC16) or 0xFFFFFFFF(CRC32).
  72. * e.g. There is a CRC16 checksum is 0x5678 before this function enabled.
  73. * If this function enabled, the checksum will be 0xA987.
  74. * The same to CRC32 checksum while using CRC32.
  75. */
  76. #define CRC_XOROUT_DISABLE ((uint32_t)0x0)
  77. #define CRC_XOROUT_ENABLE ((uint32_t)(0x1ul << 4u))
  78. #define CRC_CONFIG_MASK ((uint32_t)(0x1Eu))
  79. /*******************************************************************************
  80. * Global pre-processor symbols/macros ('#define')
  81. ******************************************************************************/
  82. /*******************************************************************************
  83. * Global variable definitions ('extern')
  84. ******************************************************************************/
  85. /*******************************************************************************
  86. * Global function prototypes (definition in C source)
  87. ******************************************************************************/
  88. void CRC_Init(uint32_t u32Config);
  89. uint16_t CRC_Calculate16B(uint16_t u16InitVal, const uint16_t *pu16Data, uint32_t u32Length);
  90. uint32_t CRC_Calculate32B(uint32_t u32InitVal, const uint32_t *pu32Data, uint32_t u32Length);
  91. bool CRC_Check16B(uint16_t u16InitVal, uint16_t u16CheckSum, const uint16_t *pu16Data, uint32_t u32Length);
  92. bool CRC_Check32B(uint32_t u32InitVal, uint32_t u32CheckSum, const uint32_t *pu32Data, uint32_t u32Length);
  93. //@} // CrcGroup
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* DDL_CRC_ENABLE */
  98. #endif /* __HC32F460_CRC_H__ */
  99. /*******************************************************************************
  100. * EOF (not truncated)
  101. ******************************************************************************/