221 lines
6.2 KiB
C
221 lines
6.2 KiB
C
/********************************** (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 <interface_can.h>
|
||
#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(); // <20><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>º<EFBFBD><C2BA><EFBFBD>
|
||
|
||
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<><58>Ƶ<EFBFBD><C6B5>
|
||
// PE10(StepXAxisMotorData.OutputFlg);//<2F><><EFBFBD><EFBFBD>
|
||
// PE12(StepXAxisMotorData.OperatDir);//<2F><><EFBFBD><EFBFBD>
|
||
//
|
||
// funcStepDriveOut(&StepYAxisMotorData);//Y<><59>Ƶ<EFBFBD><C6B5>
|
||
// PE13(StepYAxisMotorData.OutputFlg);//<2F><><EFBFBD><EFBFBD>
|
||
// PE11(StepYAxisMotorData.OperatDir);//<2F><><EFBFBD><EFBFBD>
|
||
//
|
||
// funcStepDriveOut(&StepZAxisMotorData);//Z<><5A>Ƶ<EFBFBD><C6B5>
|
||
// PE07(StepZAxisMotorData.OutputFlg);//<2F><><EFBFBD><EFBFBD>
|
||
// PA06(StepZAxisMotorData.OperatDir);//<2F><><EFBFBD><EFBFBD>
|
||
//
|
||
// funcStepDriveOut(&StepRAxisMotorData);//R<><52>Ƶ<EFBFBD><C6B5>
|
||
// PA04(StepRAxisMotorData.OutputFlg);//<2F><><EFBFBD><EFBFBD>
|
||
// PC00(StepRAxisMotorData.OperatDir);//<2F><><EFBFBD><EFBFBD>
|
||
//
|
||
// funcStepDriveOut(&StepROGAxisMotorData);//ROG<4F><47>Ƶ<EFBFBD><C6B5>
|
||
// PE06(StepROGAxisMotorData.OutputFlg);//<2F><><EFBFBD><EFBFBD>
|
||
// PE05(StepROGAxisMotorData.OperatDir);//<2F><><EFBFBD><EFBFBD>
|
||
//
|
||
// TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
|
||
}
|
||
|
||
//<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
void USB_LP_CAN1_RX0_IRQHandler(void)
|
||
{
|
||
CanRxMsg CanRxStructure;
|
||
enter_critical_section();
|
||
if(CAN_GetITStatus(CAN1, CAN_IT_FMP0) != RESET) //<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ϣ
|
||
{
|
||
CAN_ClearITPendingBit(CAN1, CAN_IT_FMP0); //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
||
|
||
|
||
if( CAN_MessagePending( CAN1, CAN_FIFO0 ) > 0)
|
||
{
|
||
CAN_Receive( CAN1, CAN_FIFO0, &CanRxStructure );
|
||
}
|
||
|
||
if(CanRxStructure.DLC > 0)//<2F><><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>0
|
||
{
|
||
CAN_Send_Msg(CAN1, 0x7F1, CAN_Id_Standard, CAN_RTR_Data, &CanRxStructure.Data[0], 8);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||
|
||
}
|
||
}
|
||
exit_critical_section(0);
|
||
}
|
||
|
||
//<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
void CAN2_RX1_IRQHandler(void)
|
||
{
|
||
CanRxMsg CanRxStructure;
|
||
enter_critical_section();
|
||
if(CAN_GetITStatus(CAN2, CAN_IT_FMP1) != RESET) //<2F>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>Ϣ
|
||
{
|
||
CAN_ClearITPendingBit(CAN2, CAN_IT_FMP1); //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
||
|
||
|
||
if( CAN_MessagePending( CAN2, CAN_FIFO1 ) > 0)
|
||
{
|
||
CAN_Receive( CAN2, CAN_FIFO1, &CanRxStructure );
|
||
}
|
||
|
||
if(CanRxStructure.DLC > 0)//<2F><><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>0
|
||
{
|
||
|
||
// if (CanRxStructure.ExtId == DF_CanIDbattery)
|
||
// {
|
||
// memcpy((uint8_t *)&un_wheel_speed_input.,(uint8_t *)&(CanRxStructure.Data[0]),8);//<2F><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>
|
||
// RgCanToBatteryCnt ++;
|
||
// }
|
||
// else if (CanRxStructure.ExtId == DF_CanIDRCH_3)
|
||
// {
|
||
// memcpy((uint8_t *)&UnRCH_3Signal_1.ArrData.ArrRx[0][0],(uint8_t *)&(CanRxStructure.Data[0]),8);//<2F><><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
// RgCanRC6GSCnt ++;
|
||
// }
|
||
|
||
|
||
|
||
CAN_Send_Msg(CAN2, 0x7F2, CAN_Id_Standard, CAN_RTR_Data, &CanRxStructure.Data[0], 8);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||
}
|
||
}
|
||
exit_critical_section(0);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|