请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:TMS320F28377D 工具与软件:
大家好!
我需要一个帮助来创建一个处理 CAN 总线中断的 HwI/Swi 模块。
我的代码如下所示:
Void hwiCanHandler(xdc_UArg arg)
{
//
// Acknowledge this interrupt located in group 9
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
CanHwiCounter++;
Swi_post(Can_swi);
}
void CAN_INIT(uint32_t canX_base, uint32_t device_sysCLK_freq, uint32_t can_bitrate)
{
Hwi_Params hwiParams;
Swi_Params swiParams;
Error_Block eb;
uint32_t interruptNumber;
Error_init(&eb);
Hwi_Params_init(&hwiParams);
Swi_Params_init(&swiParams);
// pass CAN module base address to interrupt handler
hwiParams.arg = canX_base;
hwiParams.enableInt = 1;
swiParams.priority = 1;
swiParams.arg0 = canX_base;
// Function to turn on CAN peripherals, enabling reads and writes to the
// CANs' registers.
if(canX_base == CANA_BASE)
{
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_CANA);
// According to TI documentation: INT_CANA0 ==> id 100, INT_CANA1 ==> id 101
interruptNumber = 100;
}
else if( canX_base == CANB_BASE)
{
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_CANB);
// According to TI documentation: INT_CANB0 ==> id 102, INT_CANA1 ==> id 103
interruptNumber = 102;
}
else
{
ASSERT(0);
}
//
// Initialize the CAN controller
//
// Puts the module in Initialization mode, Disables the parity function
// Initializes the MBX RAM, Initiates a S/W reset of the module
// Seeks write-access to configuration registers.
//
CAN_initModule(canX_base);
//
// Set up the CAN bus bit rate up to 1 Mbps
// Refer to the Driver Library User Guide for information on how to set
// tighter timing control. Additionally, consult the device data sheet
// for more information about the CAN module clocking.
//
CAN_setBitRate(canX_base, device_sysCLK_freq, can_bitrate, 16);
//
// Enable interrupts on the CAN peripheral.
// Enables Interrupt line 0, Error & Status Change interrupts in CAN_CTL
// register.
//
CAN_enableInterrupt(canX_base, CAN_INT_IE0 | CAN_INT_ERROR |
CAN_INT_STATUS);
// Enable the CAN interrupt signal
CAN_enableInterrupt(canX_base, CAN_INT_IE0 | CAN_INT_ERROR | CAN_INT_STATUS);
if(canX_base == CANA_BASE)
{
Interrupt_enable(INT_CANA0);
}
else
{
Interrupt_enable(INT_CANB0);
}
// create SYS/BIOS HWI
Can_hwi = Hwi_create(interruptNumber, hwiCanHandler, &hwiParams, &eb);
if (Can_hwi == NULL)
{
System_abort("Hwi create failed");
}
Error_init(&eb);
Can_swi = Swi_create(swiCanHandler, &swiParams, &eb);
if (Can_swi == NULL)
{
System_abort("Swi create failed");
}
Error_init(&eb);
Can_event = Event_create(NULL, &eb);
if (Can_event == NULL) {
System_abort("Event create failed");
}
//
// Start CAN module operations
//
CAN_startModule(canX_base);
}
我已经为 CAN 接口创建了一个消息框。
我在总线上发送 CAN 消息、并且我可以看到消息框已就绪、但较新地调用了中断例程。
我的代码中有哪些错误/缺失?
感谢您的帮助。