Part Number: TMS320F28377D
Tool/software:
Hi all,
I need a help to create a Hwi/Swi module to handle CAN-Bus interrupts.
My code looks like this:
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);
}
I have create a messagebox for the CAN interface.
I send CAN messages on the bus and I can see that the messagebox are ready, but the interrupt routine is newer called.
What I am doing wrong / missing in my code?
Thanks for any help.