gd32f30x_it.c 8.6 KB

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