gd32f30x_it.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /*!
  2. \file gd32f3x0_it.c
  3. \brief interrupt service routines
  4. */
  5. /*
  6. Copyright (C) 2022 GigaDevice
  7. 2022-12-01, V1.0.0, firmware for GD32F3x0
  8. */
  9. /******************************
  10. * Include File
  11. ******************************/
  12. #include "gd32f30x_it.h"
  13. #include "user.h"
  14. #include "TimeTask_Event.h"
  15. #include "can.h"
  16. #include "FSM_1st.h"
  17. #include "api_rt.h"
  18. #include "sys_ctrl.h"
  19. #include "enviolo_can.h"
  20. #include "string.h"
  21. /******************************
  22. * Parameter
  23. ******************************/
  24. extern uint8_t data;
  25. /******************************
  26. * Function
  27. ******************************/
  28. /*!
  29. \brief this function handles NMI exception
  30. \param[in] none
  31. \param[out] none
  32. \retval none
  33. */
  34. void NMI_Handler(void)
  35. {
  36. }
  37. /*!
  38. \brief this function handles HardFault exception
  39. \param[in] none
  40. \param[out] none
  41. \retval none
  42. */
  43. void HardFault_Handler(void)
  44. {
  45. sysctrl_stPwmState.blPwmOnflg = TRUE;/* HardFault_Handler无法被屏蔽,hw_blPWMOnFlg可能被RAMtest修改 */
  46. sysctrl_voPwmOff();
  47. /* if Hard Fault exception occurs, go to infinite loop */
  48. while (1)
  49. {
  50. //do nothing
  51. }
  52. }
  53. /*!
  54. \brief this function handles MemManage exception
  55. \param[in] none
  56. \param[out] none
  57. \retval none
  58. */
  59. void MemManage_Handler(void)
  60. {
  61. /* if Memory Manage exception occurs, go to infinite loop */
  62. while (1)
  63. {
  64. //do nothing
  65. }
  66. }
  67. /*!
  68. \brief this function handles BusFault exception
  69. \param[in] none
  70. \param[out] none
  71. \retval none
  72. */
  73. void BusFault_Handler(void)
  74. {
  75. /* if Bus Fault exception occurs, go to infinite loop */
  76. while (1)
  77. {
  78. //do nothing
  79. }
  80. }
  81. /*!
  82. \brief this function handles UsageFault exception
  83. \param[in] none
  84. \param[out] none
  85. \retval none
  86. */
  87. void UsageFault_Handler(void)
  88. {
  89. /* if Usage Fault exception occurs, go to infinite loop */
  90. while (1)
  91. {
  92. //do nothing
  93. }
  94. }
  95. /*!
  96. \brief this function handles SVC exception
  97. \param[in] none
  98. \param[out] none
  99. \retval none
  100. */
  101. void SVC_Handler(void)
  102. {
  103. }
  104. /*!
  105. \brief this function handles DebugMon exception
  106. \param[in] none
  107. \param[out] none
  108. \retval none
  109. */
  110. void DebugMon_Handler(void)
  111. {
  112. }
  113. /*!
  114. \brief this function handles PendSV exception
  115. \param[in] none
  116. \param[out] none
  117. \retval none
  118. */
  119. void PendSV_Handler(void)
  120. {
  121. }
  122. /*!
  123. \brief this function handles SysTick exception
  124. \param[in] none
  125. \param[out] none
  126. \retval none
  127. */
  128. void SysTick_Handler(void)
  129. {
  130. iRtTimer_Isr(HW_SYSTICK_TIMER);
  131. }
  132. /*!
  133. \brief
  134. \param[in] none
  135. \param[out] none
  136. \retval none
  137. */
  138. void ADC0_1_IRQHandler(void)
  139. {
  140. /* MCU self check count */
  141. clasB_uwADCCnt++;
  142. iRtAdc_CompleteIsr(0);
  143. }
  144. /*!
  145. \brief
  146. \param[in] none
  147. \param[out] none
  148. \retval none
  149. */
  150. void TIMER0_UP_TIMER9_IRQHandler(void)
  151. {
  152. /* MCU self check count */
  153. clasB_uwTIM0Cnt ++;
  154. iRtPwm_UpdateIsr(0);
  155. }
  156. /*!
  157. \brief
  158. \param[in] none
  159. \param[out] none
  160. \retval none
  161. */
  162. void TIMER1_IRQHandler(void)
  163. {
  164. /* MCU self check count */
  165. clasB_uwTIM1Cnt++;
  166. iRtCap_Isr(0);
  167. }
  168. /*!
  169. \brief
  170. \param[in] none
  171. \param[out] none
  172. \retval none
  173. */
  174. void TIMER3_IRQHandler(void)
  175. {
  176. /* MCU self check count */
  177. clasB_uwTIM3Cnt++;
  178. iRtTimer_Isr(HW_TBS_TIMER);
  179. }
  180. /*!
  181. \brief
  182. \param[in] none
  183. \param[out] none
  184. \retval none
  185. */
  186. void TIMER5_IRQHandler(void)
  187. {
  188. /* MCU self check count */
  189. clasB_uwTIM5Cnt++;
  190. iRtTimer_Isr(HW_EVENT1MS_TIMER);
  191. }
  192. /*!
  193. \brief
  194. \param[in] none
  195. \param[out] none
  196. \retval none
  197. */
  198. void DMA1_Channel2_IRQHandler(void)
  199. {
  200. iRtUart_RxIsr(0);
  201. }
  202. /*!
  203. \brief
  204. \param[in] none
  205. \param[out] none
  206. \retval none
  207. */
  208. void DMA1_Channel4_IRQHandler(void)
  209. {
  210. /* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
  211. if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
  212. {
  213. iRtUart_AsyncWriteCompleteIsr(0);
  214. DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
  215. }
  216. // TX error
  217. if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
  218. {
  219. iRtUart_AsyncWriteErrorIsr(0);
  220. DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
  221. }
  222. // if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
  223. // {
  224. // if (UART_stParaStatus.bParaStart)
  225. // {
  226. // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
  227. // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
  228. // }
  229. // else
  230. // {
  231. // // do nothing
  232. // }
  233. // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  234. // //dma_flag_clear(DMA1, DMA_CH4, DMA_INT_FLAG_FTF);
  235. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
  236. // UART_stParaStatus.bWriteBusy = FALSE;
  237. // }
  238. // /* TX error */
  239. // if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
  240. // {
  241. // if (UART_stParaStatus.bParaStart)
  242. // {
  243. // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
  244. // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
  245. // }
  246. // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  247. // //dma_flag_clear(DMA1, DMA_CH4, DMA_FLAG_ERR);
  248. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
  249. // UART_stParaStatus.bWriteBusy = FALSE;
  250. // }
  251. }
  252. /*!
  253. \brief
  254. \param[in] none
  255. \param[out] none
  256. \retval none
  257. */
  258. void CAN0_RX0_IRQHandler(void)
  259. {
  260. can_message_receive(CAN0, CAN_FIFO0, pRxMsg);
  261. if((pRxMsg->rx_ff != CAN_FF_STANDARD) || (pRxMsg->rx_dlen == 0))
  262. {
  263. can_interrupt_enable(CAN0, CAN_INT_RFF0);
  264. return;
  265. }
  266. switch (pRxMsg->rx_sfid)
  267. {
  268. case ID_PBU_BC:
  269. case ID_PBU_TO_MC: //接收PBU数据
  270. {
  271. CAN_RxBuf_Struct_PBU.ucBufID = (UWORD)pRxMsg->rx_sfid;
  272. CAN_Rx_ISR(&CAN_RxBuf_Struct_PBU, pRxMsg->rx_dlen);
  273. break;
  274. }
  275. case ID_BMS_BC:
  276. case ID_BMS_TO_MC: //接收BMS数据
  277. {
  278. CAN_RxBuf_Struct_BMS.ucBufID = (UWORD)pRxMsg->rx_sfid;
  279. CAN_Rx_ISR(&CAN_RxBuf_Struct_BMS, pRxMsg->rx_dlen);
  280. break;
  281. }
  282. case ID_HMI_BC:
  283. case ID_HMI_TO_MC: //接收HMI数据
  284. {
  285. CAN_RxBuf_Struct_HMI.ucBufID = (UWORD)pRxMsg->rx_sfid;
  286. CAN_Rx_ISR(&CAN_RxBuf_Struct_HMI, pRxMsg->rx_dlen);
  287. break;
  288. }
  289. case ID_CDL_BC:
  290. case ID_CDL_TO_MC: // case ID_CDL_TO_MC_TE://接收CDL数据
  291. {
  292. CAN_RxBuf_Struct_CDL.ucBufID = (UWORD)pRxMsg->rx_sfid;
  293. CAN_Rx_ISR(&CAN_RxBuf_Struct_CDL, pRxMsg->rx_dlen);
  294. break;
  295. }
  296. default:
  297. break;
  298. }
  299. can_interrupt_enable(CAN0, CAN_INT_RFF0);
  300. }
  301. /*!
  302. \brief
  303. \param[in] none
  304. \param[out] none
  305. \retval none
  306. */
  307. void CAN0_RX1_IRQHandler(void)
  308. {
  309. can_message_receive(CAN0, CAN_FIFO1, pRxMsg2);
  310. if((pRxMsg2->rx_ff != CAN_FF_STANDARD) || (pRxMsg2->rx_dlen == 0))
  311. {
  312. can_interrupt_enable(CAN0, CAN_INT_RFF1);
  313. return;
  314. }
  315. switch (pRxMsg2->rx_sfid)
  316. {
  317. case ID_ENVIOLO_TO_MC_1:
  318. case ID_ENVIOLO_TO_MC_2:
  319. {
  320. if(pRxMsg2->rx_dlen == 8)//由于没有帧头帧尾和CRC,故保证数据的准确性必须为8字节才解析
  321. {
  322. GearBox_CanData.RefreshFlag = TRUE;
  323. GearBox_CanData.ID = pRxMsg2->rx_sfid;
  324. memcpy((uint8_t*)GearBox_CanData.Data, (uint8_t*)pRxMsg2->rx_data, 8);
  325. }
  326. break;
  327. }
  328. default:
  329. break;
  330. }
  331. can_interrupt_enable(CAN0, CAN_INT_RFF1);
  332. }