Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




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 ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists