Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

vTaskSuspend and xTaskResumeAll

Posted by Karsten Klein on November 14, 2008
Hi,
I have a question concerning taskSuspend and resuming it.

There is one Task (TASK_A) which will be suspended by using:
vTaskSuspend( NULL ).

The resume of TASK_A will be done in an ISR after a DMA transfer_complete_interrupt by:

xTaskResumeFromISR(xHandleBusTask);

In an other Task (TASK_B) it might happen in the meanwhile (where the TASK_A is suspended) , that a vTaskSuspendAll() and a xTaskResumeAll() is executed.

Does the xTaskResumeAll() from TASK_B automatically resume the TASK_A as well, or is there a difference between the both mechanisms.

Thank you very much in advance

Regards
Karsten

RE: vTaskSuspend and xTaskResumeAll

Posted by Richard on November 14, 2008
A couple of points:

1) Be careful with the usage scenario of using xTaskResumeFromISR(). If you are wanting to wake a task when an event occurs it is normally more appropriate to use a semaphore, otherwise events can be missed.

2) xTaskResumeAll() does not effect tasks that are in the suspeneded state. Probably not a good name for the function (in fact in SafeRTOS the name was changed to xTaskResumeScheduler()). SuspendAll() suspends the scheduler so no reschedules occur. ResumeAll() resumes the scheduler so priority based scheduling happens as per normal. The state of individual tasks is not effected.

Regards.

RE: vTaskSuspend and xTaskResumeAll

Posted by Karsten Klein on November 14, 2008
Hi Richard,
thank you very much. Item 2 is understood.

But how can events be missed by using xTaskResumeFromISR() ?

The DMA-Transfer_Complete interrupt (by the way it´s an AVR32) occured and xTaskResumeFromISR(xHandleBusTask) is executed.
So the TASK_A should be resumed, and scheduled again, as soon as possible.

Or are there other items I didn´t concider ?

Best regards
Karsten

RE: vTaskSuspend and xTaskResumeAll

Posted by Richard on November 14, 2008
Consider the case where a task is structured thus:

void vATask( void * pvParameters )
{
____for(;;)
____{
________/* Wait for an event. */
________vTaskSuspend( NULL );

________/* If the task is running now then the interrupt must have
________resumed it. */

________/* A */

________/* Process the event. */

________/* B */
____}
}


so this is a simple task that executes each time it is resumed, processes an event that resumed it, then suspends itself again to wait for the next event.

The problem is, if the event occurs again anywhere between A and B it will have occurred before the task had suspended itself - the interrupt will try to resume the task but it was not actually suspended. The task will then suspend itself when it goes back to the top of the loop, not knowing there is already data to process.

If you use a binary or counting semaphore this problem goes away. Instead of suspending itself the task blocks on the semaphore. In the ISR the code simply gives the semaphore to unblock the task.

Regards.

RE: vTaskSuspend and xTaskResumeAll

Posted by Karsten Klein on November 14, 2008
HI,
understood so far. This can happen. A semaphore is the better choise for that.

In my situation there is always a gap of at least 3ms between the TaskSuspend and the event (ISR) which resumes the task. The event is allways a direct followup of the start of the DMA-transfer which happen straight before the taskSuspend.

Anyway I understand the point and will investigate in going with a semaphore. This seems to be more safety.

Thank you very much.

Best Regards
Karsten


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner