FreeRTOS taskSuspend() and taskResume() not working

akashmeras wrote on Monday, May 20, 2019:

Hai, I am new to free RTOS and I have tried a basic example code to understand the taskSuspend and taskResume function. when I use that inside the task it is not working as expected. If I use task delete and create I could achieve the expected output but while using taskSuspend and taskResume I could not achieve the same. But it has to works as same as taskDelete and create. When I use suspend inside the task it is working but when I use to resume the task in another task it is not working the task which running previously was only running I have attached my code below could anyone help me to solve the issue…

rtel wrote on Monday, May 20, 2019:

Imagine a sequence:

Task2 takes semaphore.
Task2 writes to uart
Task2 delays causing switch to Task1
Task1 attempts to take semaphore and blocks because Task1 has it,
causing switch to idle task
Eventually Task2 unblocks and gives the semaphore unblocking Task1
Task1 runs and delays for 500 ticks causing switch back to Task2
Task2 then also delays for 500 ticks causing switch back to idle task
Eventually Task1 ublocks and resumes task2…but task2 is not suspended
so nothing happens.

Now task 1 will loop back and take the mutex again. When Task2 unblocks
it will suspend itself, but task 1 has already tried to resume it so it
stays suspended until Task 1 comes around again.

akashmeras wrote on Tuesday, May 21, 2019:

I have tried to remove the semaphore and delay and increased the task2 priority high even though the same thing is happening only the task one is running. If task 2 is resumed in task1 the task 2 has to be executed because of high priority but here task1 was only running. Could you point out the error which I have done…