/********************************** (C) COPYRIGHT ******************************* * File Name : ch32v30x_it.c * Author : WCH * Version : V1.0.0 * Date : 2022/01/18 * Description : Main Interrupt Service Routines. ********************************************************************************* * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * Attention: This software (modified or not) and binary are used for * microcontroller manufactured by Nanjing Qinheng Microelectronics. *******************************************************************************/ #include #include "eth_driver.h" #include "ch32v30x_it.h" #include "string.h" #include "interface_config.h" void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void ETH_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void TIM2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void EXTI9_5_IRQHandler(void) __attribute__((interrupt())); void CAN2_RX1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); void USB_LP_CAN1_RX0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast"))); /********************************************************************* * @fn NMI_Handler * * @brief This function handles NMI exception. * * @return none */ void NMI_Handler(void) { } /********************************************************************* * @fn HardFault_Handler * * @brief This function handles Hard Fault exception. * * @return none */ u_int32_t mepc = 0; u_int32_t mcause = 0; u_int32_t mtval = 0; void HardFault_Handler(void) { printf("HardFault_Handler\r\n"); mepc = __get_MEPC(); mcause = __get_MCAUSE(); mtval = __get_MTVAL(); printf("mepc :%08x\r\n", __get_MEPC()); printf("mcause:%08x\r\n", __get_MCAUSE()); printf("mtval :%08x\r\n", __get_MTVAL()); while(1); } /********************************************************************* * @fn EXTI9_5_IRQHandler * * @brief This function handles GPIO exception. * * @return none */ void EXTI9_5_IRQHandler(void) { // ETH_PHYLink( ); EXTI_ClearITPendingBit(EXTI_Line7); /* Clear Flag */ } /********************************************************************* * @fn ETH_IRQHandler * * @brief This function handles ETH exception. * * @return none */ void ETH_IRQHandler(void) { enter_critical_section(); WCHNET_ETHIsr(); exit_critical_section(0); } /********************************************************************* * @fn TIM2_IRQHandler * * @brief This function handles TIM2 exception. * * @return none */ void TIM2_IRQHandler(void) { static uint16_t Tim2Cnt = 0; enter_critical_section(); Tim2Cnt ++; if(Tim2Cnt >= 10) { Tim2Cnt = 0; RgCntFlag10ms = 1;//10ms } //app timerUpdateAll(); // 调用定时器更新函数 WCHNET_TimeIsr(WCHNETTIMERPERIOD); TIM_ClearITPendingBit(TIM2, TIM_IT_Update); exit_critical_section(0); } /********************************************************************* * @fn TIM3_IRQHandler * * @brief This function handles TIM2 exception. * * @return none */ void TIM3_IRQHandler(void) { // funcStepDriveOut(&StepXAxisMotorData);//X轴频率 // PE10(StepXAxisMotorData.OutputFlg);//输出 // PE12(StepXAxisMotorData.OperatDir);//方向 // // funcStepDriveOut(&StepYAxisMotorData);//Y轴频率 // PE13(StepYAxisMotorData.OutputFlg);//输出 // PE11(StepYAxisMotorData.OperatDir);//方向 // // funcStepDriveOut(&StepZAxisMotorData);//Z轴频率 // PE07(StepZAxisMotorData.OutputFlg);//输出 // PA06(StepZAxisMotorData.OperatDir);//方向 // // funcStepDriveOut(&StepRAxisMotorData);//R轴频率 // PA04(StepRAxisMotorData.OutputFlg);//输出 // PC00(StepRAxisMotorData.OperatDir);//方向 // // funcStepDriveOut(&StepROGAxisMotorData);//ROG轴频率 // PE06(StepROGAxisMotorData.OutputFlg);//输出 // PE05(StepROGAxisMotorData.OperatDir);//方向 // // TIM_ClearITPendingBit(TIM3, TIM_IT_Update); } //中断服务函数 void USB_LP_CAN1_RX0_IRQHandler(void) { CanRxMsg CanRxStructure; enter_critical_section(); if(CAN_GetITStatus(CAN1, CAN_IT_FMP0) != RESET) //中断发生,接收到消息 { CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0); //清除中断标志 if( CAN_MessagePending( CAN1, CAN_FIFO0 ) > 0) { CAN_Receive( CAN1, CAN_FIFO0, &CanRxStructure ); } if(CanRxStructure.DLC > 0)//长度大于0 { CAN_Send_Msg(CAN1, 0x7F1, CAN_Id_Standard, CAN_RTR_Data, &CanRxStructure.Data[0], 8);//调试信息发送 } } exit_critical_section(0); } //中断服务函数 void CAN2_RX1_IRQHandler(void) { CanRxMsg CanRxStructure; enter_critical_section(); if(CAN_GetITStatus(CAN2, CAN_IT_FMP1) != RESET) //中断发生,接收到消息 { CAN_ClearITPendingBit(CAN2, CAN_IT_FMP1); //清除中断标志 if( CAN_MessagePending( CAN2, CAN_FIFO1 ) > 0) { CAN_Receive( CAN2, CAN_FIFO1, &CanRxStructure ); } if(CanRxStructure.DLC > 0)//长度大于0 { // if (CanRxStructure.ExtId == DF_CanIDbattery) // { // memcpy((uint8_t *)&un_wheel_speed_input.,(uint8_t *)&(CanRxStructure.Data[0]),8);//接受电池 // RgCanToBatteryCnt ++; // } // else if (CanRxStructure.ExtId == DF_CanIDRCH_3) // { // memcpy((uint8_t *)&UnRCH_3Signal_1.ArrData.ArrRx[0][0],(uint8_t *)&(CanRxStructure.Data[0]),8);//接受遥控器数据 // RgCanRC6GSCnt ++; // } CAN_Send_Msg(CAN2, 0x7F2, CAN_Id_Standard, CAN_RTR_Data, &CanRxStructure.Data[0], 8);//调试信息发送 } } exit_critical_section(0); }