123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- /*!
- \file gd32f3x0_it.c
- \brief interrupt service routines
- */
- /*
- Copyright (C) 2022 GigaDevice
- 2022-12-01, V1.0.0, firmware for GD32F3x0
- */
- /******************************
- * Include File
- ******************************/
- #include "gd32f30x_it.h"
- #include "user.h"
- #include "TimeTask_Event.h"
- #include "can.h"
- #include "FSM_1st.h"
- #include "api_rt.h"
- #include "sys_ctrl.h"
- #include "enviolo_can.h"
- #include "string.h"
- /******************************
- * Parameter
- ******************************/
- extern uint8_t data;
- /******************************
- * Function
- ******************************/
- /*!
- \brief this function handles NMI exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void NMI_Handler(void)
- {
- }
- /*!
- \brief this function handles HardFault exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void HardFault_Handler(void)
- {
- sysctrl_stPwmState.blPwmOnflg = TRUE;/* HardFault_Handler无法被屏蔽,hw_blPWMOnFlg可能被RAMtest修改 */
- sysctrl_voPwmOff();
- /* if Hard Fault exception occurs, go to infinite loop */
- while (1)
- {
- //do nothing
- }
- }
- /*!
- \brief this function handles MemManage exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void MemManage_Handler(void)
- {
- /* if Memory Manage exception occurs, go to infinite loop */
- while (1)
- {
- //do nothing
- }
- }
- /*!
- \brief this function handles BusFault exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void BusFault_Handler(void)
- {
- /* if Bus Fault exception occurs, go to infinite loop */
- while (1)
- {
- //do nothing
- }
- }
- /*!
- \brief this function handles UsageFault exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void UsageFault_Handler(void)
- {
- /* if Usage Fault exception occurs, go to infinite loop */
- while (1)
- {
- //do nothing
- }
- }
- /*!
- \brief this function handles SVC exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void SVC_Handler(void)
- {
- }
- /*!
- \brief this function handles DebugMon exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void DebugMon_Handler(void)
- {
- }
- /*!
- \brief this function handles PendSV exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void PendSV_Handler(void)
- {
- }
- /*!
- \brief this function handles SysTick exception
- \param[in] none
- \param[out] none
- \retval none
- */
- void SysTick_Handler(void)
- {
- iRtTimer_Isr(HW_SYSTICK_TIMER);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void ADC0_1_IRQHandler(void)
- {
- /* MCU self check count */
- clasB_uwADCCnt++;
-
- iRtAdc_CompleteIsr(0);
-
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void TIMER0_UP_TIMER9_IRQHandler(void)
- {
- /* MCU self check count */
- clasB_uwTIM0Cnt ++;
- iRtPwm_UpdateIsr(0);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void TIMER1_IRQHandler(void)
- {
- /* MCU self check count */
- clasB_uwTIM1Cnt++;
-
- iRtCap_Isr(0);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void TIMER3_IRQHandler(void)
- {
- /* MCU self check count */
- clasB_uwTIM3Cnt++;
-
- iRtTimer_Isr(HW_TBS_TIMER);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void TIMER5_IRQHandler(void)
- {
- /* MCU self check count */
- clasB_uwTIM5Cnt++;
-
- iRtTimer_Isr(HW_EVENT1MS_TIMER);
-
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void DMA1_Channel2_IRQHandler(void)
- {
- iRtUart_RxIsr(0);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void DMA1_Channel4_IRQHandler(void)
- {
- /* USER CODE BEGIN DMA1_Channel2_3_IRQn 0 */
- if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
- {
- iRtUart_AsyncWriteCompleteIsr(0);
- DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
- }
- // TX error
- if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
- {
- iRtUart_AsyncWriteErrorIsr(0);
- DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
- }
-
- // if (dma_flag_get(DMA1, DMA_CH4, DMA_INT_FLAG_FTF) != 0)
- // {
- // if (UART_stParaStatus.bParaStart)
- // {
- // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
- // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
- // }
- // else
- // {
- // // do nothing
- // }
- // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
- // //dma_flag_clear(DMA1, DMA_CH4, DMA_INT_FLAG_FTF);
- // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_INT_FLAG_FTF, DMA_CH4);
- // UART_stParaStatus.bWriteBusy = FALSE;
- // }
- // /* TX error */
- // if (dma_flag_get(DMA1, DMA_CH4, DMA_FLAG_ERR) != 0)
- // {
- // if (UART_stParaStatus.bParaStart)
- // {
- // UART_bInsertPendTx = FALSE; // clear insertBuffer pending
- // UART_stParaStatus.bParaStart = FALSE; // clear parameter status
- // }
- // DMA_CH4CTL(DMA1) &= ~DMA_CHXCTL_CHEN;
- // //dma_flag_clear(DMA1, DMA_CH4, DMA_FLAG_ERR);
- // DMA_INTC(DMA1) |= DMA_FLAG_ADD(DMA_FLAG_ERR, DMA_CH4);
- // UART_stParaStatus.bWriteBusy = FALSE;
- // }
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void CAN0_RX0_IRQHandler(void)
- {
- can_message_receive(CAN0, CAN_FIFO0, pRxMsg);
- if((pRxMsg->rx_ff != CAN_FF_STANDARD) || (pRxMsg->rx_dlen == 0))
- {
- can_interrupt_enable(CAN0, CAN_INT_RFF0);
- return;
- }
-
- switch (pRxMsg->rx_sfid)
- {
- case ID_PBU_BC:
- case ID_PBU_TO_MC: //接收PBU数据
- {
- CAN_RxBuf_Struct_PBU.ucBufID = (UWORD)pRxMsg->rx_sfid;
- CAN_Rx_ISR(&CAN_RxBuf_Struct_PBU, pRxMsg->rx_dlen);
- break;
- }
- case ID_BMS_BC:
- case ID_BMS_TO_MC: //接收BMS数据
- {
- CAN_RxBuf_Struct_BMS.ucBufID = (UWORD)pRxMsg->rx_sfid;
- CAN_Rx_ISR(&CAN_RxBuf_Struct_BMS, pRxMsg->rx_dlen);
- break;
- }
- case ID_HMI_BC:
- case ID_HMI_TO_MC: //接收HMI数据
- {
- CAN_RxBuf_Struct_HMI.ucBufID = (UWORD)pRxMsg->rx_sfid;
- CAN_Rx_ISR(&CAN_RxBuf_Struct_HMI, pRxMsg->rx_dlen);
- break;
- }
- case ID_CDL_BC:
- case ID_CDL_TO_MC: // case ID_CDL_TO_MC_TE://接收CDL数据
- {
- CAN_RxBuf_Struct_CDL.ucBufID = (UWORD)pRxMsg->rx_sfid;
- CAN_Rx_ISR(&CAN_RxBuf_Struct_CDL, pRxMsg->rx_dlen);
- break;
- }
- default:
- break;
- }
- can_interrupt_enable(CAN0, CAN_INT_RFF0);
- }
- /*!
- \brief
- \param[in] none
- \param[out] none
- \retval none
- */
- void CAN0_RX1_IRQHandler(void)
- {
- can_message_receive(CAN0, CAN_FIFO1, pRxMsg2);
- if((pRxMsg2->rx_ff != CAN_FF_STANDARD) || (pRxMsg2->rx_dlen == 0))
- {
- can_interrupt_enable(CAN0, CAN_INT_RFF1);
- return;
- }
-
- switch (pRxMsg2->rx_sfid)
- {
- case ID_ENVIOLO_TO_MC_1:
- case ID_ENVIOLO_TO_MC_2:
- {
- if(pRxMsg2->rx_dlen == 8)//由于没有帧头帧尾和CRC,故保证数据的准确性必须为8字节才解析
- {
- GearBox_CanData.RefreshFlag = TRUE;
- GearBox_CanData.ID = pRxMsg2->rx_sfid;
- memcpy((uint8_t*)GearBox_CanData.Data, (uint8_t*)pRxMsg2->rx_data, 8);
- }
- break;
- }
- default:
- break;
- }
- can_interrupt_enable(CAN0, CAN_INT_RFF1);
- }
|