TMO event doesn't work 2nd time

I have a "button" task that receives
button down and button receive events.
I want to distinguish between short and
long button presses. This works the
first time; the second call to
os_evt_wait_and correctly detects
a timeout while waiting for the
button release event. However, the
second time around, no timeout is
detected because the button release
event fires right away.

while(1)
{
// Clear any previous events.
os_evt_clr( BUTTON_DOWN_EVENT,
gButtonTaskID );

os_evt_clr( BUTTON_RELEASE_EVENT,
gButtonTaskID );

os_evt_wait_and( BUTTON_DOWN_EVENT,
INFINITE_WAIT );

result =
os_evt_wait_and(BUTTON_RELEASE_EVENT,
5000 );

//LEDSetup( 0, 0, LED_COLOR_OFF,
LED_HOST_COMM_MODE );

// Stop the bluetooth setup task if
running.
if( gBluetoothSetupTaskID != 0 )
{
os_tsk_delete( gBluetoothSetupTaskID );
gBluetoothSetupTaskID = 0;
printf( "bluetooth task stopped\n" );
}

switch( result)
{
case OS_R_EVT:

// Button was released within 5 sec.
printf( "Short button press\n" );
break;

case OS_R_TMO:

// Button pressed longer than 5 seconds.
break;

default:
break;
}

} // end of while loop

More questions in this forum