I’m developing FLASH memory driver under current LTS FreeRTOS version. For some types of hardware failures I’d prefer to re-initialise the whole driver including the task deletion.
As far as I know from FreeRTOS documentation, the deletion of the task has at least two phases: a calling for vTaskDelete() and background processing by Idle task.
So if I need to delete the task, I should ensure there will be at least one call for Idle task. Am I right?
Please, take a look at code snippet below:
if (TaskHandle != NULL) { /* Sanity check */
/* Begin task deletion sequence */
vTaskDelete(TaskHandle); /* Delete the task */
/* Now the priority should be dropped down to Idle
to ensure the Idle task will be called to finish the deletion */
/* Save currently running task priority */
UBaseType_t CurrentPriority = uxTaskPriorityGet(NULL);
/* Decrease currenlty running task priority to an Idle priority */
vTaskPrioritySet(NULL, tskIDLE_PRIORITY);
/* Ensure a turnaround of Idle priority tasks including
OS Idle task will be done */
vTaskDelay(1);
/* At this point the task deletion is completed for sure.
It is safe to create the task back */
/* Restore currently running task priority back */
vTaskPrioritySet(NULL, CurrentPriority);
}
Does this snippet make any sense? Are there other ways to delete the task for sure and without of excessive delays?