Is it safe to suspend a task from an Interrupt SubRoutine using vTaskSuspend API function, since vTaskSuspendFromISR is not implemented?
I’m using FreeRTOS v10.2.1 with Microchip’s PIC18F port on MPLABx IDE.
Thanks in advance !
No - it’s not as you already assumed.
IMHO vTaskSuspend is not the appropriate way of task synchronization anyway.
It’s usually better to tell a task to do something even if it means to fall asleep (waiting for a wake-up event to resume).
You can add your own implementation of vTaskSuspendFromISR() into tasks.c without having to edit the source file by using the task C additions header file https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/master/tasks.c#L5300 - but as hs2 already mentioned, suspending and resuming tasks from an interrupt is a common source of error. See the note on https://www.freertos.org/taskresumefromisr.html for why this is considered dangerous.
I will add that I have NEVER found a case where it was useful for something other than the thread itself to suspend the thread. The biggest problem is you can’t in general know if the Task is currently holding some important resource, unless you know where it is executing, and generally if you know that, it is because it is blocked (or on the way to be blocked) on some resource, at which case you generally don’t need to suspend it.
Using Suspend/Resume as a synchronization mechanism is only really useful in the most simple cases, and is full of ‘gotchas’, and in my mind only useful for the smallest, most resource constrained systems. Much better to use higher level primitives like Direct-to-Task, Semaphores, Queues, Event Groups and the like to synchronize things.