Hi. My tasks implement a state machine and the task loop looks like this:
while(ulTaskNotifyTake( pdFALSE, portMAXDELAY))
I should mention that I’ve also tried with binary semaphores and also with a binary notify, i.e. ulTaskNotifyTake( pdTRUE, portMAX
DELAY). with the same results I’m describing here.
The problem is that the while loop exits with return value 0 without blocking. It happens occasionally. I have looked for stack errors and other obvious problems but have failed to find anything.
Inside the function:
uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait )
xClearCountOnExit == 0
xTicksToWait == 0xffffffff
pxCurrentTCB->ucNotifyState == 0
pxCurrentTCB->ulNotifiedValue == 0
ulReturn = 0
/* Only block if the notification count is not already non-zero. */
if( pxCurrentTCB->ulNotifiedValue == 0UL ) // ==> true
/* Mark this task as waiting for a notification. */
pxCurrentTCB->ucNotifyState = taskWAITING
NOTIFICATION; // ==> set to 1
if( xTicksToWait > ( TickType_t ) 0 ) // ==> true
prvAddCurrentTaskToDelayedList( xTicksToWait, pdTRUE );
portYIELD_WITHIN_API(); // NOT BLOCKING
ulReturn = pxCurrentTCB->ulNotifiedValue; // ==> 0
if( ulReturn != 0UL ) // ==> false
pxCurrentTCB->ucNotifyState = taskNOTWAITING
NOTIFICATION; // ==> 0
return ulReturn; // ==> 0
The task while loop now exits and you get stuck in the task exit trap.
Any suggestions what might be going wrong? I’m using FreeRTOS 9.0.0 and it’s working fine most of the time. Thanks!