| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- #include <Myproject.h>
- /**
- @function LVW_TSD_INT
- @brief 芯片过温 芯片欠压故障中断
- @date 2025-11-01
- */
- void LVW_TSD_INT(void) interrupt 0
- {
- if (ReadBit(LVSR, LVWIF))
- {
- if (ReadBit(LVSR, LVWF))
- {
- FaultProcess();
- ClrBit(LVSR, LVWF);
- }
-
- ClrBit(LVSR, LVWIF);
- }
-
- if (TSDIF)
- { TSDIF = 0; }
- }
- /**
- @function EXTERN_INT0
- @brief 外部中断0 用于预驱故障检测 中断优先级最高
- @date 2025-11-01
- */
- void EXTERN_INT0(void) interrupt 1
- {
- if (IF0)
- {
- FaultProcess();
- mcFaultSource = FaultHardOVCurrent;
- IF0 = 0;
- }
- }
- /* -------------------------------------------------------------------------------------------------
- Function Name : void CMP3_INT(void)
- Description : CMP3:硬件比较器过流保护,关断输出,中断优先级最高
- Input : 无
- Output : 无
- -------------------------------------------------------------------------------------------------*/
- void CMP3_INT(void) interrupt 12
- {
- if (ReadBit(CMP_SR, CMP3IF))
- {
- FaultProcess(); // 关闭输出
- mcFaultSource = FaultHardOVCurrent; // 硬件过流保护
- ClrBit(CMP_SR, CMP3IF);
- }
- }
- /**
- @function DRV_ISR
- @brief FOC中断(Drv中断),每个载波周期执行一次,用于处理响应较高的程序,中断优先级第二。DCEN开了就会产生中断。
- @date 2025-11-01
- */
- void DRV_ISR(void) interrupt 3
- {
- if (ReadBit(DRV_SR, DCIF)) // 比较中断
- {
- Fault_Overcurrent(); //软件过流保护
- DRV_SR = (DRV_SR | SYSTIF) & (~DCIF);
- }
- }
- /**
- @function SYStick_INT
- @brief 定时器中断(SYS TICK中断)
- @date 2025-11-01
- */
- void SYStick_INT(void) interrupt 10
- {
- if (ReadBit(DRV_SR, SYSTIF)) // SYS TICK中断
- {
- IsTick = true;
-
- if (mcFocCtrl.State_Count)
- { mcFocCtrl.State_Count--; }
-
- DRV_SR = (DRV_SR | DCIF) & (~SYSTIF);// 清零标志位
- }
- }
- /**
- @function COM1_INT_Handler
- @brief I2C/UART1 共用此中断
- @date 2025-11-05
- */
- void COM1_INT_Handler(void) interrupt 13
- {
- static uint8_t recv_index = 0;
- uint8_t byte = 0x00, expected_len = 0;
- uint16_t dataLen = 0x00;
-
- if (TI)
- { TI = 0; }
-
- if (RI)
- {
- byte = UT_DR;
- RI = 0;
- #if (CONTROL_MODE == UARTMODE)
- {
- // 安全写入检查
- if (recv_index >= MAX_FRAME_LEN)
- {
- recv_index = 0;
- return;
- }
-
- // 状态机处理
- // 阶段1:等待帧头
- if (recv_index == 0)
- {
- if (byte == FRAME_HEADER)
- { RecvBuffer[recv_index++] = byte; }
-
- return;
- }
-
- // 阶段2:接收功能码和长度
- if (recv_index < DATA_OFFSET)
- {
- RecvBuffer[recv_index++] = byte;
-
- // 校验长度字段有效性
- if (recv_index == DATA_OFFSET)
- {
- dataLen = ((uint16_t)RecvBuffer[5] << 8) | RecvBuffer[4];
-
- // 检查长度字节
- if (dataLen > (MAX_FRAME_LEN - DATA_OFFSET - CRC_OFFSET))
- { recv_index = 0; }
- }
-
- return;
- }
-
- // 阶段3:接收数据区
- dataLen = ((uint16_t)RecvBuffer[5] << 8) | RecvBuffer[4];
- expected_len = DATA_OFFSET + dataLen + CRC_OFFSET;
-
- if (recv_index < expected_len)
- {
- RecvBuffer[recv_index++] = byte;
-
- // 完整帧接收完成
- if (recv_index == expected_len)
- {
- RecMessageFalg = true;
- recv_index = 0;
- }
-
- return;
- }
-
- // 异常情况复位
- recv_index = 0;
- }
- #endif
- }
- }
- /**
- @function COM_INT_Handler
- @brief SPI/UART2/LIN 共用此中断
- @date 2025-11-05
- */
- void COM2_INT_Handler(void) interrupt 14
- {
- if (UT2TI)
- { UT2TI = 0; }
-
- if (UT2RI)
- { UT2RI = 0; }
- }
- /**
- @function DAM_INT_Handler
- @brief DMA中断函数
- @date 2025-11-05
- */
- void DAM_INT_Handler(void) interrupt 15
- {
- if (ReadBit(DMA0_CR0, DMAIF))
- {
- memset(&DebugDat, 0, MAX_FRAME_LEN);
- ClrBit(DMA0_CR0, DMAIF);
- }
-
- if (ReadBit(DMA1_CR0, DMAIF))
- {
- ClrBit(DMA1_CR0, DMAIF);
- }
- }
|