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

Nested Critical Region

Posted by jackson on October 18, 2007
Will it be a problem when a task(A) yield from within the function vTaskPrioritySet()?(also many other functions such as xQueueSend...)that have the code structure

taskENTER_CRITICAL();
{
...
taskYIELD();
}
taskEXIT_CRITICAL();

and if the succeding task(B) also has a code
taskENTER_CRITICAL();
{
...
}
taskEXIT_CRITICAL();

From the Source code (ARM IAR port)

void vPortEnterCritical( void ) //taskENTER_CRITICAL()
{
__disable_interrupt();
ulCriticalNesting++;
}

void vPortExitCritical( void ) //taskEXIT_CRITICAL()
{
if( ulCriticalNesting > portNO_CRITICAL_NESTING ) //(>0)
{
ulCriticalNesting--;
if( ulCriticalNesting == portNO_CRITICAL_NESTING ) // == 0
{
__enable_interrupt();
}
}
}

My question is, will the interrupt still be disabled after task B leave the critical region ? If yes then it certainly not meet our desire.
Do i miss something ?

RE: Nested Critical Region

Posted by Richard on October 18, 2007
I need to write an FAQ on this one :o)

No it is not a problem for the kernel to switch tasks from within a critical section - in fact the scheduler locking mechanism relies on the ability to do this.

Each task maintains its own interrupt state. Therefore task A may enter a critical section, then yield to task B. When task A starts executing again it will do so from within the critical section, so interrupts will again be disabled. Task B may or may not have interrupts enabled, it depends on the interrupt status when task B yielded, so interrupts will not necessarily be disabled between when task A stops executing and subsequently starts executing again.

Regards.

RE: Nested Critical Region

Posted by Dave on October 18, 2007
>Each task maintains its own interrupt state

and each task saves its uxCriticalNesting value as part of its context.

RE: Nested Critical Region

Posted by jackson on October 18, 2007
What i mean is task B never expect it will cause the interrupt disabled after leave the critical section.

RE: Nested Critical Region

Posted by jackson on October 18, 2007
Thanks for your explanation !

RE: Nested Critical Region

Posted by Dave on October 18, 2007
I don't understand what you mean here. As far as TaskB is concerned it is the only task in the system. It does not know or care what TaskA is doing. It always has the interrupt state as it expects it to have. If its in a critical region then it expects to have interrupts diabled. If its out of a critical region then it expects to have interrupts enabled. This is always the case and is not dependent on when it or any other task yields. Critical sections can nest quite happily so the critical section will only be exited when the same number of calls are made to portEXIT_CRITICAL as were already made to portENTER_CRITICAL.


[ 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