|
|
@ -13,7 +13,7 @@ |
|
|
|
* |
|
|
|
* FilePath: fcan_intr.c |
|
|
|
* Date: 2022-02-10 14:53:42 |
|
|
|
* LastEditTime: 2022-02-18 08:29:10 |
|
|
|
* LastEditTime: 2024-06-24 08:29:10 |
|
|
|
* Description: This files is for the can interrupt functions |
|
|
|
* |
|
|
|
* Modify History: |
|
|
@ -21,6 +21,7 @@ |
|
|
|
* ----- ------ -------- -------------------------------------- |
|
|
|
* 1.0 wangxiaodong 2022/5/26 first release |
|
|
|
* 1.1 zhangyan 2022/12/7 improve functions |
|
|
|
* 1.2 huangjin 2024/06/24 modify the FCanIntrHandler function |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "fcan.h" |
|
|
@ -74,6 +75,7 @@ void FCanIntrHandler(s32 vector, void *args) |
|
|
|
FASSERT(instance_p != NULL); |
|
|
|
FASSERT(instance_p->is_ready == FT_COMPONENT_IS_READY); |
|
|
|
config_p = &instance_p->config; |
|
|
|
/* 获取中断状态 */ |
|
|
|
irq_status = FCAN_READ_REG32(config_p->base_address, FCAN_INTR_OFFSET); |
|
|
|
|
|
|
|
if (0 == irq_status) |
|
|
@ -81,75 +83,62 @@ void FCanIntrHandler(s32 vector, void *args) |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
/* Check for the type of interrupt and Processing it */ |
|
|
|
if (irq_status & FCAN_INTR_TEIS_MASK) |
|
|
|
/* 检查接收FIFO满中断标志 */ |
|
|
|
if (irq_status & FCAN_INTR_RFIS_MASK) |
|
|
|
{ |
|
|
|
irq_status &= ~FCAN_INTR_REIS_MASK; |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, |
|
|
|
FCAN_INTR_TEIC_MASK | FCAN_INTR_REIC_MASK); |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK); |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_CTRL_OFFSET, FCAN_CTRL_TXREQ_MASK); |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK); |
|
|
|
|
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_SEND); |
|
|
|
FCAN_DEBUG("rx_fifo is full!!!"); |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_RFIE_MASK); |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_RFIC_MASK); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_FIFOFULL); |
|
|
|
} |
|
|
|
|
|
|
|
if (irq_status & (FCAN_INTR_EIS_MASK | FCAN_INTR_RFIS_MASK | FCAN_INTR_TFIS_MASK | |
|
|
|
FCAN_INTR_BOIS_MASK | FCAN_INTR_PEIS_MASK | FCAN_INTR_PWIS_MASK)) |
|
|
|
/* 检查发送FIFO空中断标志 */ |
|
|
|
if (irq_status & FCAN_INTR_TFIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, |
|
|
|
(FCAN_INTR_EIC_MASK | FCAN_INTR_RFIC_MASK | FCAN_INTR_BOIC_MASK | |
|
|
|
FCAN_INTR_PEIC_MASK | FCAN_INTR_PWIC_MASK | FCAN_INTR_TFIC_MASK)); |
|
|
|
FCAN_DEBUG("tx_fifo is empty!!!"); |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_TFIE_MASK); |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_TFIC_MASK); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_FIFOEMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
/* Check for rx fifo full interrupt and output error information */ |
|
|
|
if (irq_status & FCAN_INTR_RFIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_FIFOFULL); |
|
|
|
FCAN_DEBUG("rx_fifo is full!!!"); |
|
|
|
/* disable rx fifo full interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_RFIE_MASK); |
|
|
|
} |
|
|
|
if (irq_status & FCAN_INTR_TFIS_MASK) |
|
|
|
/* 检查错误中断的类型并处理 */ |
|
|
|
if ( irq_status & (FCAN_INTR_BOIS_MASK | FCAN_INTR_EIS_MASK | FCAN_INTR_PEIS_MASK | FCAN_INTR_PWIS_MASK) ) |
|
|
|
{ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, (FCAN_INTR_BOIE_MASK | FCAN_INTR_EIE_MASK | FCAN_INTR_PEIE_MASK | FCAN_INTR_PWIE_MASK)); |
|
|
|
if (irq_status & FCAN_INTR_BOIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_FIFOEMPTY); |
|
|
|
FCAN_DEBUG("tx_fifo is empty!!!"); |
|
|
|
/* disable tx fifo empty interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_TFIE_MASK); |
|
|
|
FCAN_ERROR("Bus off!!!"); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_BUSOFF); |
|
|
|
} |
|
|
|
if (irq_status & FCAN_INTR_EIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_ERROR("Error occurred!!!"); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_ERROR); |
|
|
|
FCAN_ERROR("Error occurred!!!"); |
|
|
|
/* disable error interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_EIE_MASK); |
|
|
|
} |
|
|
|
if (irq_status & FCAN_INTR_BOIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_BUSOFF); |
|
|
|
FCAN_ERROR("Bus off!!!"); |
|
|
|
/* disable busoff interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_BOIE_MASK); |
|
|
|
} |
|
|
|
if (irq_status & FCAN_INTR_PEIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_PERROE); |
|
|
|
FCAN_ERROR("Passive error occurred!!!"); |
|
|
|
/* disable passive error interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_PEIE_MASK); |
|
|
|
FCAN_ERROR("Passive error occurred!!!"); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_PERROE); |
|
|
|
} |
|
|
|
if (irq_status & FCAN_INTR_PWIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_PWARN); |
|
|
|
FCAN_ERROR("Passive warning!!!"); |
|
|
|
/* disable passive warning interrupt */ |
|
|
|
FCAN_CLEARBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_PWIE_MASK); |
|
|
|
FCAN_ERROR("Passive warning!!!"); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_PWARN); |
|
|
|
} |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, (FCAN_INTR_BOIC_MASK | FCAN_INTR_EIC_MASK | FCAN_INTR_PEIC_MASK | FCAN_INTR_PWIC_MASK)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* 检查发送完成中断标志 */ |
|
|
|
if (irq_status & FCAN_INTR_TEIS_MASK) |
|
|
|
{ |
|
|
|
irq_status &= ~FCAN_INTR_REIS_MASK; |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_TEIC_MASK | FCAN_INTR_REIC_MASK); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_SEND); |
|
|
|
} |
|
|
|
/* 检查接收完成中断标志 */ |
|
|
|
if (irq_status & FCAN_INTR_REIS_MASK) |
|
|
|
{ |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_REIE_MASK); |
|
|
|
FCAN_SETBIT(config_p->base_address, FCAN_INTR_OFFSET, FCAN_INTR_REIC_MASK); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_RECV); |
|
|
|
FCAN_CALL_INTR_EVENT_HANDLDER(instance_p, FCAN_INTR_EVENT_RECV); |
|
|
|
} |
|
|
|
} |
|
|
|