This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/EK-TM4C123GXL: CAN bus interrupt on TivaC

Part Number: EK-TM4C123GXL
Other Parts Discussed in Thread: TM4C123GH6PM, SYSBIOS

Tool/software: TI-RTOS

How can I make a CAN bus interrupt using the TI RTOS? (MCU: TM4C123GH6PM, CCS: 7.0.0.43)

Without the RTOS my code would be the following:

	// Set up CAN0
//I assume following lines to stay the same
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // enable CAN1 GPIO peripheral
	GPIOPinConfigure(GPIO_PB0_CAN1RX);
	GPIOPinConfigure(GPIO_PB1_CAN1TX);
	GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
	CANInit(CAN0_BASE);
	CANBitRateSet(CAN0_BASE, sysClock, 1000000);

//Here the Code has to be changed
l. 1:	CANIntRegister(CAN0_BASE, CANIntHandler); // use dynamic vector table allocation
l.2:   CANIntEnable(CAN1_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
l.3:   IntEnable(INT_CAN0);

//may stay the same
	CANEnable(CAN0_BASE);

The HWI may be configured in the **.cfg as follows:

ISR function: CANIntHandler

Interrupt Number: 55 //==CAN0_BASE

which replaces lines 1 and 3, but how may I replace line.2: "CANIntEnable(CAN1_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);" when using the **.cfg for configuring the HWI with TI-RTOS?

  • Do you want to create the Hwi at build time (.cfg file) or at runtime? Both result in the same thing.

    You might to look at one of the supported drivers (e.g. I2CTiva) to see how it is done at runtime.

    Todd
  • I would prefer to create the HWI at build time (**.cfg) file, but if this doesn't work, doing it at runtime is also OK.

    The I2C example doesn't include any HWI creation (or at least not visible in source code, as it does part of the configuration for the I2Cin the subfunction I2C_init() found in EK_TM4C123GXL.c ).
    The gpiointerrupt example seems to create the HWI inside the function "GPIO_setCallback()", but this is for GPIOs, not for CAN

    Both subfunctions can't be opened with F3, so I can't have a look at them and how the HWI is created.

    Do you have any example where a HWI is created directly in Source Code and not in any subfunction which is not accessible?
  • I had this runtime code handy, but the .cfg is very similar.

    To create the Hwi, here is the

    #include <xdc/runtime/Error.h>
    #include <ti/sysbios/family/arm/m3/Hwi.h>
    #include <inc/hw_ints.h>
    Hwi_Handle canHandle;

    void myCANISRFxn(UArg arg)
    {
    }


    main() {
    ...
    Hwi_Params hwiParams;
    Error_Block eb;

    Error_init(&eb);

    Hwi_Params_init(&hwiParams);
    hwiParams.arg = (UArg)NULL; // whatever you want to pass to the ISR
    //you can set other hwiParams fields as needed.
    canHandle = Hwi_create(INT_CAN0, myCANISRFxn, &hwiParams, &eb);


    The drivers use Hwi_construct because it saves some stack memory, but the Hwi_create is easier to understand and get going. You can always migrate to construct. Also note you supply the memory instead of allocating it with construct.

    Todd
  • There was a suggested answer and since there has been no active on this thread for more than a week, the suggested answer was marked as verify. Please feel free to select the "Reject Answer" button and reply with more details.