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


Querying execution context

Posted by incrediball on January 15, 2009
I've written some functions that I need to use from a regular task context as well as from interrupts. Since the functions are dealing with a shared resource, I am using critical sections to synchronize access to it. However, critical sections cannot be used inside interrupts since (at least on the ARM7 GCC port) this crashes the system.

Rather than writing regular and "FromISR" versions of the functions, they should themselves check in which context they're being called and call taskENTER_CRITICAL & taskEXIT_CRITICAL in the regular case, or not if it's an ISR.

So, is there a way to determine the execution context? Or do I need to set a flag myself in my interrupt handlers?

RE: Querying execution context

Posted by woops_ on January 15, 2009
Setting your own flag would be easiest, but you can always look at the mode bits in CPSR to see if you are in IRQ mode or System mode.

RE: Querying execution context

Posted by incrediball on January 18, 2009
Thanks. Reading CPSR seems like a nice solution but I don't know how to code that in asm and it is of course platform dependent.

It would be nicer if on all ports FreeRTOS could provide this information and/or make taskENTER_CRITICAL & taskEXIT_CRITICAL interrupt safe. That would simply involve doing nothing if an interrupt is running, which would also make more of the API interrupt safe (e.g. uxQueueMessagesWaiting).

[ 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