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