Quality RTOS & Embedded Software

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


How does ulCriticalNesting work?

Posted by Nobody/Anonymous on September 20, 2006
Forgive me for what may be a very poor question. Maybe I just need to write this out... This is related to my work on the AT91SAM7S256 port of FreeRTOS (using WinARM to compile).

How is ulCriticalNesting supposed to work? I think that what I am seeing is that whenever a task is created, vPortEnterCritical() is called which increments ulCriticalNesting (initially it is 9999UL so now it would be 10000UL). When the creation of the task is complete then it calls vPortExitCritical() and first checks to see if ulCriticalNesting is greater than 0. It is. Then it decrements ulCriticalNesting (back to 9999UL in this case) and checks if ulCriticalNesting is equal to 0. It is NOT. Since it is NOT, then it does NOT enable the interrupts.

Am I not understanding this code correctly? How will ulCriticalNesting ever allow for the interrupts to be enabled again?


RE: How does ulCriticalNesting work?

Posted by Richard on September 20, 2006
ulCriticalNesting - I think I said uxCriticalNesting in my reply to another post a few moments ago which may be related to this question.

ulCriticalNesting is stored as part of the task context. It is initialised to zero *within the task* - so when a task starts executing it will get set to zero. As per my previous post if you set a break point at the start of the task, then inspect ulCriticalNesting, you should find that it is zero.

Before the scheduler is started ulCriticalNesting is set to a non-zero value to prevent it ever reaching zero before the scheduler is properly initialised. It will be overwritten with zero when the first task starts.


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

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

Latest News

Version 10.1.0 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.


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


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