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(¶ms);
params.enableInt = TRUE;
params.arg = (UArg)timerHandle;
params.priority = (~0);
Hwi_construct(&timerHwi, INT_TIMER5A, ButtonTimerIRQHandler, ¶ms, 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