Resuming after vTaskSuspend(NULL);

Hi,
  I have a number of tasks and I am trying to synchronise one of them with another.
I am using the ST Cube tool to create the base code, and it starts all the tasks at boot time. I therefore, within the first task issue a vTaskSuspend(TIMER_TaskHandle); call. I was hoping that this would allow the second task to complete initializing some hardware (that takes a variable amount of time). I then, from the second task issue a vTaskResume(TIMER_TaskHandle); But, the first task does not continue after the suspend line. Code fragment :- Timer task:
TIMER_Task_Suspended = TRUE;
vTaskSuspend(TIMER_TaskHandle);     // Stop here until allowed to resume...
TIMER_Task_Suspended = FALSE;   <- Never reached :(.....
Supervisor task :
if(MODE_DC == my_mode)    <- This is true...
{
    vTaskResume(TIMER_TaskHandle);  // Re start the timer task.
}
So, Firstly, is what I am doing correct and allowed, and secondly, if it is, why does it not appar to work ?. Thanks, Andy Pevy

Resuming after vTaskSuspend(NULL);

Are you sure the value in TIMER_TaskHandle is correct? If so, then is the second task (the one that is calling vTaskResume()) higher, lower or equal priority to the first task? If it is higher priority then the first task will only execute when the higher priority task enters the Blocked state. It will enter the Blocked state if it makes a blocking FreeRTOS API call, such as vTaskDelay(), or xQueueReceive() on an empty queue with a block time specified. Regards.

Resuming after vTaskSuspend(NULL);

Hi, The value in Timer_TaskHandle is correct, and both tasks are running at the same priority. The unblocking task enters “retval = xQueueReceive(SupervisortaskqueueHandle, (TransferType *) &supervisorinds, slottime.sleeptime);” a few lines later so it should allow the timer task to run.

Resuming after vTaskSuspend(NULL);

Would adding a vTaskDelay or taskYIELD be a way of releasingf the timer task ?.

Resuming after vTaskSuspend(NULL);

That shouldn’t be necessary. Another thought – if the tasks are the same priority – are you 100% sure the task is suspended before you try un-suspending it? For example, if: 1) the first task set TIMERTaskSuspended to true, then got swapped out before it called vTaskSuspend(), 2) Then the second task executed, did its thing, and called vTaskResume(), 3) Then the first task executed again and called vTaskSuspend() you would end up with the behaviour your have observed. Try creating the first task with a priority above that of the second task, so you know there is no chance of the second task executing until the first task has actually entered the Suspended state. Then when the first task leaves the Suspended state it can call vTaskPrioritySet( NULL, [whatever] ); to set its priority back down to the one you really want it to run at. Alternatively, if the task is created before the scheduler has started, you can also suspend it before the scheduler starts, that way it will already be in the suspended state before any tasks run. vTaskSuspend() is one of the functions that it is ok to call before starting the scheduler. Regards.

Resuming after vTaskSuspend(NULL);

By the way, you can use eTaskGetState() to determine the state of a task.

Resuming after vTaskSuspend(NULL);

Bingo, looking at the relative timings, I think that this is a distinct possibility. I will re-work the control logic to ensure that the timings are correct. Thanks for your help. Andy