gd32f30x_it.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. /******************************
  20. * Parameter
  21. ******************************/
  22. extern uint8_t data;
  23. /******************************
  24. * Function
  25. ******************************/
  26. /*!
  27. \brief this function handles NMI exception
  28. \param[in] none
  29. \param[out] none
  30. \retval none
  31. */
  32. void NMI_Handler(void)
  33. {
  34. }
  35. /*!
  36. \brief this function handles HardFault exception
  37. \param[in] none
  38. \param[out] none
  39. \retval none
  40. */
  41. void HardFault_Handler(void)
  42. {
  43. sysctrl_stPwmState.blPwmOnflg = TRUE;/* HardFault_Handler无法被屏蔽,hw_blPWMOnFlg可能被RAMtest修改 */
  44. sysctrl_voPwmOff();
  45. /* if Hard Fault exception occurs, go to infinite loop */
  46. while (1)
  47. {
  48. //do nothing
  49. }
  50. }
  51. /*!
  52. \brief this function handles MemManage exception
  53. \param[in] none
  54. \param[out] none
  55. \retval none
  56. */
  57. void MemManage_Handler(void)
  58. {
  59. /* if Memory Manage exception occurs, go to infinite loop */
  60. while (1)
  61. {
  62. //do nothing
  63. }
  64. }
  65. /*!
  66. \brief this function handles BusFault exception
  67. \param[in] none
  68. \param[out] none
  69. \retval none
  70. */
  71. void BusFault_Handler(void)
  72. {
  73. /* if Bus Fault exception occurs, go to infinite loop */
  74. while (1)
  75. {
  76. //do nothing
  77. }
  78. }
  79. /*!
  80. \brief this function handles UsageFault exception
  81. \param[in] none
  82. \param[out] none
  83. \retval none
  84. */
  85. void UsageFault_Handler(void)
  86. {
  87. /* if Usage Fault exception occurs, go to infinite loop */
  88. while (1)
  89. {
  90. //do nothing
  91. }
  92. }
  93. /*!
  94. \brief this function handles SVC exception
  95. \param[in] none
  96. \param[out] none
  97. \retval none
  98. */
  99. void SVC_Handler(void)
  100. {
  101. }
  102. /*!
  103. \brief this function handles DebugMon exception
  104. \param[in] none
  105. \param[out] none
  106. \retval none
  107. */
  108. void DebugMon_Handler(void)
  109. {
  110. }
  111. /*!
  112. \brief this function handles PendSV exception
  113. \param[in] none
  114. \param[out] none
  115. \retval none
  116. */
  117. void PendSV_Handler(void)
  118. {
  119. }
  120. /*!
  121. \brief this function handles SysTick exception
  122. \param[in] none
  123. \param[out] none
  124. \retval none
  125. */
  126. void SysTick_Handler(void)
  127. {
  128. iRtTimer_Isr(HW_SYSTICK_TIMER);
  129. }
  130. /*!
  131. \brief
  132. \param[in] none
  133. \param[out] none
  134. \retval none
  135. */
  136. void ADC0_1_IRQHandler(void)
  137. {
  138. /* MCU self check count */
  139. clasB_uwADCCnt++;
  140. iRtAdc_CompleteIsr(0);
  141. }
  142. /*!
  143. \brief
  144. \param[in] none
  145. \param[out] none
  146. \retval none
  147. */
  148. void TIMER0_UP_TIMER9_IRQHandler(void)
  149. {
  150. /* MCU self check count */
  151. clasB_uwTIM0Cnt ++;
  152. iRtPwm_UpdateIsr(0);
  153. }
  154. /*!
  155. \brief
  156. \param[in] none
  157. \param[out] none
  158. \retval none
  159. */
  160. void TIMER1_IRQHandler(void)
  161. {
  162. /* MCU self check count */
  163. clasB_uwTIM1Cnt++;
  164. iRtCap_Isr(0);
  165. // UWORD uwIntSource = 0;
  166. // if (timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_UP) != 0)
  167. // {
  168. // if(switch_flg.SysCoef_Flag == TRUE)
  169. // {
  170. // uwIntSource = 1;
  171. // cadence_voCadenceCal(uwIntSource);
  172. // bikespeed_voBikeSpeedCal(uwIntSource);
  173. // }
  174. // timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
  175. // }
  176. // else if (timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_CH2) != 0)
  177. // {
  178. // if(switch_flg.SysCoef_Flag == TRUE)
  179. // {
  180. // uwIntSource = 2;
  181. // cadence_voCadenceCal(uwIntSource);
  182. // /* Select rising or falling edge trigger */
  183. // if(gpio_input_bit_get(GPIOB, GPIO_PIN_10) != 0)
  184. // {
  185. // /* reset the CH2P and CH2NP bits */
  186. // TIMER_CHCTL2(TIMER1) &= ~(uint32_t)(TIMER_CHCTL2_CH2P|TIMER_CHCTL2_CH2NP);
  187. // TIMER_CHCTL2(TIMER1) |= (uint32_t)((uint32_t)(TIMER_IC_POLARITY_FALLING) << 8U);
  188. // }
  189. // else
  190. // {
  191. // /* reset the CH2P and CH2NP bits */
  192. // TIMER_CHCTL2(TIMER1) &= ~(uint32_t)(TIMER_CHCTL2_CH2P|TIMER_CHCTL2_CH2NP);
  193. // TIMER_CHCTL2(TIMER1) |= (uint32_t)((uint32_t)(TIMER_IC_POLARITY_RISING) << 8U);
  194. // }
  195. // }
  196. // timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_CH2);
  197. // }
  198. // else if (timer_interrupt_flag_get(TIMER1, TIMER_INT_FLAG_CH3) != 0)
  199. // {
  200. // if(switch_flg.SysCoef_Flag == TRUE)
  201. // {
  202. // uwIntSource = 3;
  203. // bikespeed_voBikeSpeedCal(uwIntSource);
  204. // }
  205. // timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_CH3);
  206. // }
  207. // else
  208. // {
  209. // //do noting
  210. // }
  211. }
  212. /*!
  213. \brief
  214. \param[in] none
  215. \param[out] none
  216. \retval none
  217. */
  218. void TIMER3_IRQHandler(void)
  219. {
  220. /* MCU self check count */
  221. clasB_uwTIM3Cnt++;
  222. iRtTimer_Isr(HW_TBS_TIMER);
  223. }
  224. /*!
  225. \brief
  226. \param[in] none
  227. \param[out] none
  228. \retval none
  229. */
  230. void TIMER5_IRQHandler(void)
  231. {
  232. /* MCU self check count */
  233. clasB_uwTIM5Cnt++;
  234. iRtTimer_Isr(HW_EVENT1MS_TIMER);
  235. }
  236. /*!
  237. \brief
  238. \param[in] none
  239. \param[out] none
  240. \retval none
  241. */
  242. void DMA1_Channel2_IRQHandler(void)
  243. {
  244. iRtUart_RxIsr(0);
  245. // /* Read PC Conmand */
  246. // if (dma_flag_get(DMA1, DMA_CH2, DMA_INT_FLAG_FTF) != 0)
  247. // {
  248. // UART_voCBDoneRead(UART_ERR_OK, 22);
  249. // DMA_CH2CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  250. // //dma_flag_clear(DMA1, DMA_CH2, DMA_INT_FLAG_FTF);
  251. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH2);
  252. // uwTempCount = 22 - DMA_CH2CNT(DMA1);
  253. // DMA_CH2CNT(DMA1) = uwTempCount;
  254. // DMA_CH2CTL(DMA1) |= DMA_CHXCTL_CHEN;
  255. // }
  256. // /* RX error */
  257. // if (dma_flag_get(DMA1, DMA_CH2, DMA_FLAG_ERR) != 0)
  258. // {
  259. // DMA_CH2CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  260. // //dma_flag_clear(DMA1, DMA_CH2, DMA_FLAG_ERR);
  261. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH2);
  262. // DMA_CH2CNT(DMA1) = 22;
  263. // DMA_CH2CTL(DMA1) |= DMA_CHXCTL_CHEN;
  264. // }
  265. }
  266. /*!
  267. \brief
  268. \param[in] none
  269. \param[out] none
  270. \retval none
  271. */
  272. void DMA1_Channel4_IRQHandler(void)
  273. {
  274. /* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
  275. if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
  276. {
  277. iRtUart_AsyncWriteCompleteIsr(0);
  278. DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
  279. }
  280. // TX error
  281. if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
  282. {
  283. iRtUart_AsyncWriteErrorIsr(0);
  284. DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
  285. }
  286. // if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
  287. // {
  288. // if (UART_stParaStatus.bParaStart)
  289. // {
  290. // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
  291. // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
  292. // }
  293. // else
  294. // {
  295. // // do nothing
  296. // }
  297. // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  298. // //dma_flag_clear(DMA1, DMA_CH4, DMA_INT_FLAG_FTF);
  299. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
  300. // UART_stParaStatus.bWriteBusy = FALSE;
  301. // }
  302. // /* TX error */
  303. // if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
  304. // {
  305. // if (UART_stParaStatus.bParaStart)
  306. // {
  307. // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
  308. // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
  309. // }
  310. // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
  311. // //dma_flag_clear(DMA1, DMA_CH4, DMA_FLAG_ERR);
  312. // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
  313. // UART_stParaStatus.bWriteBusy = FALSE;
  314. // }
  315. }
  316. /*!
  317. \brief
  318. \param[in] none
  319. \param[out] none
  320. \retval none
  321. */
  322. void CAN0_RX0_IRQHandler(void)
  323. {
  324. can_message_receive(CAN0, CAN_FIFO0, pRxMsg);
  325. if((pRxMsg->rx_ff != CAN_FF_STANDARD) || (pRxMsg->rx_dlen == 0))
  326. {
  327. can_interrupt_enable(CAN0, CAN_INT_RFF0);
  328. return;
  329. }
  330. switch (pRxMsg->rx_sfid)
  331. {
  332. case ID_PBU_BC:
  333. case ID_PBU_TO_MC: //接收PBU数据
  334. {
  335. CAN_RxBuf_Struct_PBU.ucBufID = (UWORD)pRxMsg->rx_sfid;
  336. CAN_Rx_ISR(&CAN_RxBuf_Struct_PBU, pRxMsg->rx_dlen);
  337. break;
  338. }
  339. case ID_BMS_BC:
  340. case ID_BMS_TO_MC: //接收BMS数据
  341. {
  342. CAN_RxBuf_Struct_BMS.ucBufID = (UWORD)pRxMsg->rx_sfid;
  343. CAN_Rx_ISR(&CAN_RxBuf_Struct_BMS, pRxMsg->rx_dlen);
  344. break;
  345. }
  346. case ID_HMI_BC:
  347. case ID_HMI_TO_MC: //接收HMI数据
  348. {
  349. CAN_RxBuf_Struct_HMI.ucBufID = (UWORD)pRxMsg->rx_sfid;
  350. CAN_Rx_ISR(&CAN_RxBuf_Struct_HMI, pRxMsg->rx_dlen);
  351. break;
  352. }
  353. case ID_CDL_BC:
  354. case ID_CDL_TO_MC: // case ID_CDL_TO_MC_TE://接收CDL数据
  355. {
  356. CAN_RxBuf_Struct_CDL.ucBufID = (UWORD)pRxMsg->rx_sfid;
  357. CAN_Rx_ISR(&CAN_RxBuf_Struct_CDL, pRxMsg->rx_dlen);
  358. break;
  359. }
  360. default:
  361. break;
  362. }
  363. can_interrupt_enable(CAN0, CAN_INT_RFF0);
  364. }