Hi,
I need to use two timers (OSAL timer) at same time but so far I cannot even set event during timer is running. My scenario is like below.
1. Timer1 is for periodic status check. It checks status and changes led sign.
for example,
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{
...
...
...
if ( events & SIMPLEBLEPERIPHERAL_LED_EVT)
{
osal_start_timerEx( simpleBLEPeripheral_TaskID, SIMPLEBLEPERIPHERAL_LED_EVT, 10 );
if (status)
{
// generating LED sign using shift register
// clock and latch inputs are given from port 0 in CC2540 so I need to keep it running
}
else
{
// generating LED sign using shift register
// clock and latch inputs are given from port 0 in CC2540 so I need to keep it running
}
return events ^ SIMPLEBLEPERIPHERAL_LED_EVT;
}
...
...
}
2. Timer2 starts when you click the button (on rising interrupt). I need to check if this was long press or not. So I started timer and checked it for certain amount of time. When the button is released, it changes the status (global variable shared by both Timer1 and Timer2).
for example,
HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )
{
if ( P0IFG & BV(7) )
{
osal_set_event( simpleBLEPeripheral_TaskID, SIMPLEBLEPERIPHERAL_BUTTON_EVT);
}
P0IFG = 0;
P0IF = 0;
}
uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )
{
...
...
...
if ( events & SIMPLEBLEPERIPHERAL_BUTTON_EVT)
{
if ( buttonCount < BUTTON_LONG_COUNT )
{
if (P0_7)
{
buttonCount++;
osal_start_timerEx( simpleBLEPeripheral_TaskID, SIMPLEBLEPERIPHERAL_BUTTON_EVT, 100 );
}
else // short button press
{
status = 0;
}
}
else // long button press
{
status = 1;
}
return events ^ SIMPLEBLEPERIPHERAL_BUTTON_EVT;
}
...
...
}
Real usage is little different but concept is like above - I need to run two timers at same time (one is for output and the other one is for input) and they share one global variable.
The problem is that, while SIMPLEBLEPERIPHERAL_LED_EVT is running, I cannot initiate SIMPLEBLEPERIPHERAL_BUTTON_EVT. It seems that it skips SIMPLEBLEPERIPHERAL_BUTTON_EVT as another event keeps running. Can anyone please help me? If my implementation is not right, please guide me. Basically I want to see if it's long press or short press while LED is always on.
Thanks,
Brian