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] [July 2007 Threads] Task Switching in Critical RegionPosted by vipin on July 6, 2007 Hello, I am trying to use a IAR version of STR75x port. In which in blocktim.c file there is a task "vPrimaryBlockTimeTestTask". Inside this task there is folowing line of code (line no 115 - 129):
portENTER_CRITICAL(); { xTimeWhenBlocking = xTaskGetTickCount();
/* We should unblock after xTimeToBlock having not received anything on the queue. */ if( xQueueReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY ) { xErrorOccurred = pdTRUE; }
/* How long were we blocked for? */ xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking; } portEXIT_CRITICAL();
After doing the careful observation of these lines of code, it seems the context switching is taking place due to the xQueueReeceive() function. My queries are as follows- 1) How can context switching is allowed inside a critical region? 2) If it is allowed what we need to take care while using it?
Can anybody help to understand these points? BR,
RE: Task Switching in Critical RegionPosted by Richard on July 6, 2007 Each task maintains its own interrupt status. This permits context switches to occur within a critical region - but only if the task is coded specifically to do this. A preemptive context switch will never occur within a critical region.
This is a very powerful mechanism, and is used by the scheduler itself to implement the scheduler locking mechanism.
If a task enters a critical region, then yields, it is guaranteed that it will next start executing with interrupts disabled. The tasks that run in between it yielding and then running again might (most probably) have interrupts enabled though.
Regards.
RE: Task Switching in Critical RegionPosted by vipin on July 6, 2007 Hi Richard, Thanks for the clarification. I understood this through observation but had doubt as it is mentioned in freeRTOS website that "Preemptive context switches cannot occur when in a critical region."
Now regarding my second query- 2) If it is allowed what we need to take care while using it?
To more specific, what about the shared variable or resources which are shared between ISR and Task. As ISR will be enabled after context switching so how to take care whether these shared variables/resources are not getting corrupted during these context switching.
Thanks once again for your help. BR,
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|