ch32v20x_it.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v20x_it.c
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2022/06/16
  6. * Description : Main Interrupt Service Routines.
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/
  12. /*********************************************************************
  13. * INCLUDES
  14. */
  15. #include <user_config.h>
  16. #include "ch32v20x_it.h"
  17. #include "user_nfc.h"
  18. #include "user_adc.h"
  19. #include "user_can.h"
  20. #include "ws2812b_spi.h"
  21. #include "user_ws2812b.h"
  22. /*********************************************************************
  23. * LOCAL FUNCTIONS
  24. */
  25. void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  26. void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  27. void BB_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  28. void DMA1_Channel1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  29. void USB_LP_CAN1_RX0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  30. void USER_WS2812B_DMA_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
  31. /*********************************************************************
  32. * @fn NMI_Handler
  33. *
  34. * @brief This function handles NMI exception.
  35. *
  36. * @return None
  37. */
  38. void NMI_Handler(void)
  39. {
  40. }
  41. /*********************************************************************
  42. * @fn HardFault_Handler
  43. *
  44. * @brief This function handles Hard Fault exception.
  45. *
  46. * @return None
  47. */
  48. void HardFault_Handler(void)
  49. {
  50. while(1)
  51. {
  52. }
  53. }
  54. /*********************************************************************
  55. * @fn BB_IRQHandler
  56. *
  57. * @brief BB Interrupt for BLE.
  58. *
  59. * @return None
  60. */
  61. void BB_IRQHandler(void)
  62. {
  63. BB_IRQLibHandler();
  64. }
  65. ///*********************************************************************
  66. // * @fn LLE_IRQHandler
  67. // *
  68. // * @brief LLE Interrupt for BLE.
  69. // *
  70. // * @return None
  71. // */
  72. //void LLE_IRQHandler(void)
  73. //{
  74. // LLE_IRQLibHandler();
  75. //}
  76. void DMA1_Channel1_IRQHandler(void)
  77. {
  78. if(DMA_GetITStatus(DMA1_IT_TC1))
  79. {
  80. DMA_ClearITPendingBit(DMA1_IT_TC1);
  81. vUser_adc_dma_finish();
  82. }
  83. }
  84. // CAN接收中断服务函数
  85. void USB_LP_CAN1_RX0_IRQHandler(void)
  86. {
  87. if(CAN_GetITStatus(CAN1, CAN_IT_FMP0)) // 检查FIFO0消息挂起中断
  88. {
  89. CanRxMsg RxMessage;
  90. CAN_Receive(CAN_TYPE, CAN_FIFO0, &RxMessage);
  91. vUser_can_recv_data(&RxMessage);
  92. // 清除中断标志
  93. CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0);
  94. }
  95. }
  96. void USER_WS2812B_DMA_IRQHandler(void)
  97. {
  98. if(DMA_GetITStatus(USER_WS2812B_DMA_IT_TC))
  99. {
  100. // 清除中断标志
  101. DMA_ClearITPendingBit(USER_WS2812B_DMA_IT_TC);
  102. DMA_Cmd(USER_WS2812B_DMA_CHANNEL, DISABLE);
  103. SPI_I2S_DMACmd(USER_WS2812B_SPI, SPI_I2S_DMAReq_Tx, DISABLE);
  104. // 在这里处理传输完成逻辑
  105. // 例如: 设置标志、准备下一次传输等
  106. vUser_ws2812b_set_tx_stat(false);
  107. }
  108. }