Quality RTOS & Embedded Software

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




Loading

queue.c: *_interrupts vs. *_critical

Posted by Nobody/Anonymous on January 12, 2007
<<And yes, I'm using anonymous on purpose.>>

Looking at queue.c and trying to write my own counting semaphores (as an exercise and to contribute), I see the coroutine-specific portions calling portDISABLE_INTERRUPTS directly rather than using taskENTER_CRITICAL to count multiple depth. It would seem this could cause an error of enabling interrupts when the system is supposed to be in a nested critical section.

RE: queue.c: *_interrupts vs. *_critical

Posted by Richard on January 12, 2007
The coroutine versions don't nest interrupts. There is a very good reason for this, it just temporarily escapes me ;-)

There was in fact a bug fix about two versions ago where a co-routine called a utility function within an if() condition while interrupts were disabled. The utility function itself entered and exited a critical section - and in so doing resulted in interrupts being enabled when they should not have been for the very reason you point out. The utility macro was replaced with inlined code as the fix.

I think counting semaphores can be implemented in a similar way to the binary semaphores, just with a queue depth greater than 1 - which is where the 'binary' comes from.

Regards.

RE: queue.c: *_interrupts vs. *_critical

Posted by HAR on January 12, 2007
Maybe, but the queue implementation would try to allocate actual queue space which would be a waste. And it doesn't need to be as complicated, either - posting a semaphore should always work unlike adding to a queue.

RE: queue.c: *_interrupts vs. *_critical

Posted by Nobody/Anonymous on January 12, 2007
The binary semaphore has an item size of 0 so nothing is actually copied into the queue and I don't think any storage space allocated (?).

The return value from the post to the sem could be ignored, or a wrapper function that converts the return value to something more friendly for a sem.

Dave.

RE: queue.c: *_interrupts vs. *_critical

Posted by HAR on January 16, 2007
>>There was in fact a bug ... where a co-routine called a utility function ... while interrupts were disabled. The utility function itself entered and exited a critical section - and in so doing resulted in interrupts being enabled when they should not have been ... The utility macro was replaced with inlined code as the fix.

I have the vague memory that VRTX's interrupt-entry macro incremented the critical-section depth counter to avoid this problem . . . or else the critical-section code saved the status register on the first level, using the depth counter from zero *down* to use the condition code *after* the operation (on 80x86)? Maybe I'm mixing up two. Point is, that should be handled.

While acknowledging the specific goal of processor-independence, I would also like to see more processor- and compiler-specific inlining (all of which of course defaults to common standard C code). Call me old-fashioned....

RE: queue.c: *_interrupts vs. *_critical

Posted by Nobody/Anonymous on January 16, 2007
The interrupt macros do keep a count of the nesting depth. The coroutine thing is a special case. Normally you would not use portENABLE_INTERRUPTS or portDISABLE_INTERRUPTS from you code, but portENTER_CRITICAL and portEXIT_CRITICAL instead.

Dave.


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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