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-TM4C1294XL: TI-RTOS Scheduler Issue With General Purpose Timer Interrupts.

Part Number: EK-TM4C1294XL
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Dear All,

We are working with TI-RTOS and are using general purpose timers for button detection(short press and long press). We are using TI-RTOS GPIO drivers while for general purpose timers, we have developed drivers using TivaWare peripheral libraries. For long press and short press detection, we are using general purpose timer configured to few milliseconds timeout interrupt. When a button is pressed and its GPIO interrupt is served, we configure a timer, in GPIO interrupt handler, for a few milliseconds timeout interrupt. If we simply do not use timer for timeout interrupts and exit the GPIO interrupt handler after performing some action, the scheduler keeps working fine. On the other hand if we configure the timer for timeout interrupt, once the timer interrupt has been served, the scheduler stops working properly and remains stuck in any of the tasks' Task_sleep() function. We have also tried configuring the timer interrupt as Hwi and still face the same problem.

Given below is the timer configuration function which configures timer interrupt as Hwi. This function is called from GPIO interrupt handler and configures the timer for 40ms timeout interrupt.

void ButtonTimerInit(void)
{
// register ISR and enable hardware interrupt for timer
Hwi_Params params;
Hwi_Params_init(&params);
params.enableInt = TRUE;
params.arg = (UArg)timerHandle;
params.priority = (~0);
Hwi_construct(&timerHwi, INT_TIMER5A, ButtonTimerIRQHandler, &params, NULL);

// Variable to calculte timer counter value
unsigned int timerCounterValue = 0u;

// Enable Timer0 peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5);
// Wait for the Timer0 module to be ready
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER5));
// Configure Timer0 for concatinated one shot mode
TimerConfigure(TIMER5_BASE, TIMER_CFG_ONE_SHOT);
// Calculate timer load value for 40ms interrupt
timerCounterValue = ((SYSTEM_CLOCK_FREQUENCY/1000u)*40u);
// Load timer counter value
TimerLoadSet(TIMER5_BASE, TIMER_BOTH,timerCounterValue);
// Enable processor interrupts
IntMasterEnable();
// Configure the Timer interrupt for timer timeout.
TimerIntEnable(TIMER5_BASE, TIMER_TIMA_TIMEOUT);
// Enable Timer
TimerEnable(TIMER5_BASE, TIMER_BOTH);

Given below is the Timer timeout interrupt handler

void ButtonTimerIRQHandler(xdc_UArg arg)
{
// Variable to add temporary delay for timer interrupt to be cleared
unsigned char count;

// Clear the timer interrupt flag.
TimerIntClear(TIMER5_BASE, TIMER_TIMA_TIMEOUT);
// Add a little bit delay
for(count = 0; count <= 100u ; count++)
{
}
// Process timer interrupt for buttons
ButtonProcessTimerInterrupt();
}

NOTE: ButtonProcessTimerInterrupt() function is used to detect if any of the  button is still in pressed state. If true, it reloads the timer with new timeout interrupt value.

The problem we are facing is once timer interrupt is served by this function, TI-RTOS scheduler stops working properly and remains stuck in any of the tasks' Task_sleep() function. If any of the community members have encountered this problem in the past, any help in this regard shall be appreciated.

Thanks,

Muhammad Shuaib

  • Can you tell me what version of TIRTOS you are using?

    TIRTOS uses a Timer as its heartbeat and I'm wondering if you are reconfiguring the Timer that is being used by TIRTOS.

    Judah
  • Hi Judah,

    We are using tirtos_tivac_2_16_01_14.

    Thanks,

    Muhammad Shuaib

  • I looked and SYSBIOS by default uses GPTimer0 for its Clock so that should not conflict with you using GPTimer5.
    But I did have a question as to what is "timerHwi" and "timerHandle"?
    You should debug further to see if somehow your code is affecting GPTimer0.

    Judah
  • Hi Judah,

    Thank you for your response. Given below are the declarations of structures that i used in constructing the timer Hwi.

    Hwi_Handle timerHandle;
    Hwi_struct timerHwi;

    Although we are not creating & using timer Hwi now in our code, it would still be a great help if i you can point any mistake that i may be making in my code.

    Right now, we are using RTOS HAL timer in our code. Given below is the piece of code for configuring RTOS HAL timer . Please have a look at it. The declaration given below is contained in main file for making it globally available to other source files.

    extern Timer_Handle buttonTimerHandle;

    The following code is contained in our Timer source file.

    #define BUTTON_TIMER_ID 2

    void RTOSTimerInit(void)
    {
    // Timer parameters
    Timer_Params buttonTimerParams;

    // Initializae timer parameters
    Timer_Params_init(&buttonTimerParams);
    // Configure timer period type as micro seconds
    buttonTimerParams.periodType = Timer_PeriodType_MICROSECS;
    // Configure timer for 20 milli seconds interrupt
    buttonTimerParams.period = (1000u*20);
    // Set timer run mode to one shot
    buttonTimerParams.runMode = Timer_RunMode_ONESHOT;
    // Set timer shall be started by user
    buttonTimerParams.startMode = Timer_StartMode_USER;
    // Set the timer argument
    buttonTimerParams.arg = BUTTON_TIMER_ID;
    // Create the timer
    buttonTimerHandle = Timer_create(BUTTON_TIMER_ID, (Timer_FuncPtr)RTOSTimerIRQHandler, &buttonTimerParams, NULL);
    // If timer was not created successfully
    if(buttonTimerHandle == NULL)
    {
    // Abort
    System_abort("Timer could not be created");
    }
    }

    Whenever the 20 milli seconds timer interrupt is needed, we call Timer_start(buttonTimerHandle) function and the interrupt is handled by following function.

    void RTOSTimerIRQHandler(UArg arg)
    {
    // Process timer interrupt for buttons
    ButtonProcessTimerInterrupt();
    }

    So far, this code is working fine. Can you please have a look at it and let us know if we are using this timer the correct way?

    Thanks,
    Muhammad Shuaib
  • Muhammad,

    The code from your last post looks fine too me.  That's good to hear that you got that code working.  If your questions have been answered please mark this thread close.  Thanks!

    Judah