FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [November 2008 Threads] vTaskSuspend and xTaskResumeAllPosted 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 xTaskResumeAllPosted 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 xTaskResumeAllPosted 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 xTaskResumeAllPosted 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 xTaskResumeAllPosted 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|