I would like to know if I can suspend all tasks, but then resume 1 or 2 while I’m completing a critical section of code. And then resume all tasks again when I’m done. Is this possible?
Hi @Glenn
Welcome to the FreeRTOS Community Forums !
When you mention "resume 1 or 2 tasks while I’m completing a critical section of code ", do you mean you intend to resume the tasks inside the critical section?
The critical section is used to make any application code inside the section run without being interrupted (it disables interrupts). Calling FreeRTOS API functions within a critical section is undefined behavior.
Also , what is your intention behind resuming 1 or 2 tasks, if you are looking for synchronization , you can try using task notifications as a signaling mechanism?
I need to receive a large amount of data at high speed (2Mbps from a uart. and write files from that data to an SD card. I created a task to do this and gave it a higher than normal priority but I always end up with missing or corrupt data. I’m using UART to DMA circular buffer but I still somehow get preempted at bad times.
My thought was to create a routine outside of the schedulers domain and suspend all tasks while I complete this process and then enable them when I’m done. The problem is I need to use the FATfs services and that task is also suspended. I thought if I could enable just that task and whatever it depends on.
Did you try to suspend the scheduler - The FreeRTOS vTaskSuspendAll() RTOS API function which is part of the RTOS scheduler control API. FreeRTOS is a professional grade, small footprint, open source RTOS for microcontrollers.?
@aggard
I have not tried it yet; I was hoping to see if what I was considering doing could work. e.g. Suspending the scheduler and unsuspending the FATfs task.
Also, I’m not sure if suspending the scheduler will also suspend the handling of the watchdog timers.
Thanks for the reply,
Glenn
Suspending the scheduler ensures that the currently running task is not switched out until the scheduler is resumed. It does not prevent interrupts from firing. So you should do something like the following in your FATfs task -
void FATfsTask( void * params )
{
( void ) params;
for( ;; )
{
...
vTaskSuspendAll();
{
/* Handle large amount of data here. This task will not be switched
* out until xTaskResumeAll is called. Note that interrupt will
* continue to fire. */
}
xTaskResumeAll();
...
}
}
Suspending the scheduler is a FreeRTOS operation and it will not interfere with your watchdog hardware. One thing that can happen is that your task that periodically feeds the watchdog, may fail to feed the watchdog as it would not run when the scheduler is suspended. You’d need to ensure that watchdog timer is configured appropriately so that it does not trip in that time.
aggard:
Thank you, I will proceed in this manner. I appreciate your assistance.