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

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