ciu32f003_std_crc.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /************************************************************************************************/
  2. /**
  3. * @file ciu32f003_std_crc.c
  4. * @author MCU Ecosystem Development Team
  5. * @brief CRC STD库驱动。
  6. * 实现CRC初始化配置等功能API。
  7. *
  8. *
  9. **************************************************************************************************
  10. * @attention
  11. * Copyright (c) CEC Huada Electronic Design Co.,Ltd. All rights reserved.
  12. *
  13. **************************************************************************************************
  14. */
  15. /************************************************************************************************/
  16. /**
  17. * @addtogroup CIU32F003_STD_Driver
  18. * @{
  19. */
  20. /**
  21. * @addtogroup CRC
  22. * @{
  23. *
  24. */
  25. /************************************************************************************************/
  26. /*------------------------------------------includes--------------------------------------------*/
  27. #include "ciu32f003_std.h"
  28. #ifdef STD_CRC_PERIPHERAL_USED
  29. /*-------------------------------------------functions------------------------------------------*/
  30. /************************************************************************************************/
  31. /**
  32. * @addtogroup CRC_External_Functions
  33. * @{
  34. *
  35. */
  36. /************************************************************************************************/
  37. /**
  38. * @brief CRC去初始化
  39. * @retval 无
  40. */
  41. void std_crc_deinit(void)
  42. {
  43. /* 复位CRC */
  44. std_rcc_ahb_reset(RCC_PERIPH_RESET_CRC);
  45. }
  46. /**
  47. * @brief 将CRC初始值反转后写入寄存器
  48. * @param poly_sel 多项式选择
  49. * @param init_value 自定义初始值
  50. * @retval 无
  51. */
  52. void std_crc_set_init_value_invert(uint32_t poly_sel, uint32_t init_value)
  53. {
  54. uint32_t index, temp;
  55. uint32_t result = 0;
  56. /* 初始值按位翻转 */
  57. for (index = 0U; index < 4; index++)
  58. {
  59. temp = (init_value >> (8U * index));
  60. temp = (((temp & 0x55) << 1) | ((temp & 0xaa) >> 1));
  61. temp = (((temp & 0x33) << 2) | ((temp & 0xcc) >> 2));
  62. temp = (((temp & 0x0f) << 4) | ((temp & 0xf0) >> 4));
  63. result |= (temp << (8U * (3 - index)));
  64. }
  65. if (poly_sel == CRC_POLY_16)
  66. {
  67. result >>= 16;
  68. }
  69. CRC->RDR = result;
  70. }
  71. /**
  72. * @}
  73. */
  74. #endif /* STD_CRC_PERIPHERAL_USED */
  75. /**
  76. * @}
  77. */
  78. /**
  79. * @}
  80. */