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/TM4C123GH6PM: CANIntHandler() on TI-RTOS

Part Number: TM4C123GH6PM

Tool/software: TI-RTOS

I have been trying to run CANIntHandler() on TI-RTOS as a Hardware Interrupt (Hwi) with interrupt number 55( As of datasheet 55 is assigned for can0 ). But the interrupt status was ended up showing ERROR .

I have  assigned can_rx() as a task.
Please help me out with the code 

/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/cfg/global.h>
#include <xdc/runtime/System.h>

/* BIOS Header files */
#include <ti/sysbios/BIOS.h>

/* Board Header file */
#include "Board.h"
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/qei.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "inc/hw_can.h"
#include "driverlib/can.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"


volatile bool rxFlag = 0; // msg recieved flag
volatile bool errFlag = 0; // error flag



void hardware_init(void);
void can_rx(void);
void CANIntHandler(void);




void main(void)
{
   hardware_init();
   BIOS_start();
}

void hardware_init(void)
{


     // Set the clocking to run directly from the crystal.
    SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    // Set up debugging UART
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioConfig(0, 115200, SysCtlClockGet());

// Set up CAN0
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    GPIOPinConfigure(GPIO_PE4_CAN0RX);
    GPIOPinConfigure(GPIO_PE5_CAN0TX);
    GPIOPinTypeCAN(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
    CANInit(CAN0_BASE);
    CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000);
    //CANIntRegister(CAN0_BASE, CANIntHandler); // use dynamic vector table allocation
    CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS);
    IntEnable(INT_CAN0);
    CANEnable(CAN0_BASE);

}
// CAN interrupt handler
void CANIntHandler(void) {

    unsigned long status = CANIntStatus(CAN0_BASE, CAN_INT_STS_CAUSE); // read interrupt status

    if(status == CAN_INT_INTID_STATUS) { // controller status interrupt
        status = CANStatusGet(CAN0_BASE, CAN_STS_CONTROL);
     UARTprintf("%l/", status); // this showed ERROR in my code
        errFlag = 1;
    } else if(status == 1) { // msg object 1
        CANIntClear(CAN0_BASE, 1); // clear interrupt
        rxFlag = 1; // set rx flag
        errFlag = 0; // clear any error flags
    } else { // should never happen
        UARTprintf("Unexpected CAN bus interrupt\n");
    }
}

void can_rx(void)
{
    tCANMsgObject msg; // the CAN msg object
   // uint8_t msgData[8];
    unsigned char msgData[8]; // 8 byte buffer for rx message data
    unsigned int uIdx;
    // Use ID and mask 0 to recieved messages with any CAN ID
    msg.ui32MsgID = 0;
    msg.ui32MsgIDMask = 0;
    msg.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
    msg.ui32MsgLen = 8; // allow up to 8 bytes

    // Load msg into CAN peripheral message object 1 so it can trigger interrupts on any matched rx messages
    CANMessageSet(CAN0_BASE, 1, &msg, MSG_OBJ_TYPE_RX);

    while(1) {

        if(rxFlag) { // rx interrupt has occured

            msg.pui8MsgData = msgData; // set pointer to rx buffer
            CANMessageGet(CAN0_BASE, 1, &msg, 0); // read CAN message object 1 from CAN peripheral

            rxFlag = 0; // clear rx flag

            if(msg.ui32Flags & MSG_OBJ_DATA_LOST) { // check msg flags for any lost messages
                UARTprintf("CAN message loss detected\n");
            }

            UARTprintf("Msg ID=0x%08X len=%u data=0x", msg.ui32MsgID, msg.ui32MsgLen);
                       for(uIdx = 0; uIdx < msg.ui32MsgLen; uIdx++)
                       {
                           UARTprintf("%d\ ", msgData[uIdx]);
        }
    }
    }
    return 0;
}

  • Respected sir,

    Please tell us more about your error?? Exactly which error you are getting??

    regards,

    digvijay

  • Respected sir,
    i can not see construction of hwi thread for can module. I have added (partial) following code in my project.

    Hwi_Params_init(&(paramsUnion.hwiParams));
    paramsUnion.hwiParams.arg = (UArg)handle;

    Hwi_construct(&(object->hwi), hwAttrs->intNum, CANTiva_hwiIntFxn,
    &(paramsUnion.hwiParams), NULL);

    Also go through the driver library of UART for better understanding of hwi generation.

    regards,
    digvijay
  • Respected sir,
    Thank you for the early reply!
    I am very new to Ti-RTOS . We just went through the TI-Rtos Workshop documentation and assigned CANIntHandler as HWI through GUI . I have no idea to place the above sent code by you in the program.
    And from line #84 it just printed "ERROR".
    Please let me know if you need other information.
  • Respected sir,
    i am also new to TI-RTOS. For can module i modified the driver library of UART and it worked for me. As u have constructed hwi using GUI there is no need to add the code suggested by me. But i have one doubt that how do you assign CANIntHandler() function to can interrupt using GUI??
    As the error is in UARTprintf function, the amateurs way is to remove all UARTprintf functions from CANIntHandler(). The reason is we cannot call some functions like create , destruct etc from hwi thread. If that does not solve your problem u have to get help from experts. I can not think of any other solution.

    regards,
    digvijay
  • Respected sir,
    CANIntHandler should be place as ISR function and interrupt number for can0 is 55( for TM4C123GH6PM, check out the datasheet).
    However my problem is sorted out using can_rx as task thread.
    thank you.
    regards,
    Nanda Kishore
  • respected sir,

    Nanda Kishore Moduga said:
    I have  assigned can_rx() as a task.

    In  your first post  , you said that you have assigned can_rx() as task. So i did not considered it as problem. And actualy what i want to ask is where to place the handler function CANIntHandler() in GUI??

    regards,

    digvijay

  • Respected sir,
    Create a instance in Hwi (for this refer Ti-RTOS workshop manual) and it asks for handle name, ISR function and Interrrupt number
    Handle name = can_xx (your wish')
    ISR function = CANIntHandler
    Interrupt number = 55 (check datasheet )
    regards,
    Nanda Kishore
  • Hi Nanda,

    Can you place a breakpoint immediately after reading the interrupt status?  What is the value received?  Also, can you please attach your *.cfg file to this post.

    Regards,

    -- Emmanuel

  • 7416.empty.cfgHi Emmanuel,

      the value received is 32768. Please find the *.cfg file in attachment.

    and can you please help me out with other one., the above code is on Rx function which is working well but when I added Tx function to the Rtos the Rx is receiving the messages(only message Id is received and Data is not received)  sent by the same Tx code but while sending the CAN message from other device the Rx function is receiving none.

  • Nanda,

    Sorry, this fell through the cracks. Is this still an issue?

    Todd

    [Update: marking this as TI Thinks Resolved due to inactivity by the poster. If this is still an issue, please post a response.]