eTaskGetState reporting

casper0 wrote on Friday, October 11, 2013:

I am trying to understand the result reported by eTaskGetState(). In my simplified case I have Task 1 querying the state of Task 2. Task 2 gets put in suspend mode when it is not needed, during which Task 1 is not allowed to do some “thing”. But when Task 2 is not suspended, Task 1 'd better do this “thing” or it will go all haywire.

What I have noticed is that when I use eTaskGetState() to check Task 2 for !eSuspended and I know that Task 2 has been resumed, at times Task 2 still reports being suspended. It appears that when I think Task 2 may be blocked, it reports eSuspended instead. The code seems to bear this out, indicating something to the effect that if portMAX_DELAY is used as part of the blocking call, it puts the task into suspend mode–something that causes me to misinterpret its real state.

What’s the reason for this? And what’s a better way to identify if a task is suspended or not than using a variable in parallel with the suspend and resume calls?

FreeRTOS 7.4.2
IAR EWARM 6.60.2
STM32F205/STM32L151

Task 1:
while(1) {

if (eTaskGetState(task2_tid) != eSuspended) {
<<Important “thing” code>>
}

}

Task 2:
while(1) {

xSemaphoreTake(sem_id, portMAX_DELAY);

}

Other code:

vTaskSuspend(task2_tid);

vTaskResume(task2_tid);