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

[RTOS Kernel Control]

task. h

UBaseType_t taskENTER_CRITICAL_FROM_ISR( void );
void taskEXIT_CRITICAL_FROM_ISR( UBaseType_t uxSavedInterruptStatus );

Versions of taskENTER_CRITICAL() and taskEXIT_CRITICAL() that can be used in an interrupt service routine (ISR).

In an ISR critical sections are entered by calling taskENTER_CRITICAL_FROM_ISR(), and subsequently exited by calling taskEXIT_CRITICAL_FROM_ISR().

The taskENTER_CRITICAL_FROM_ISR() and taskEXIT_CRITICAL_FROM_ISR() macros provide a basic critical section implementation that works by simply disabling interrupts, either globally, or up to a specific interrupt priority level.

If the FreeRTOS port being used supports interrupt nesting then calling taskENTER_CRITICAL_FROM_ISR() will disable interrupts at and below the interrupt priority set by the configMAX_SYSCALL_INTERRUPT_PRIORITY (or configMAX_API_CALL_INTERRUPT_PRIORITY) kernel configuration constant, and leave all other interrupt priorities enabled. If the FreeRTOS port being used does not support interrupt nesting then taskENTER_CRITICAL_FROM_ISR() and taskEXIT_CRITICAL_FROM_ISR() will have no effect.

Calls to taskENTER_CRITICAL_FROM_ISR() and taskEXIT_CRITICAL_FROM_ISR() are designed to nest, but the semantics of how the macros are used is different to the taskENTER_CRITICAL() and taskEXIT_CRITICAL() equivalents.

Critical sections must be kept very short, otherwise they will adversely affect the response times of higher priority interrupts that would otherwise nest. Every call to taskENTER_CRITICAL_FROM_ISR() must be closely paired with a call to taskEXIT_CRITICAL_FROM_ISR().

FreeRTOS API functions must not be called from within a critical section.

uxSavedInterruptStatus taskEXIT_CRITICAL_FROM_ISR() takes uxSavedInterruptStatus as its only parameter. The value used as the uxSavedInterruptStatus parameter must be the value returned from the matching call to taskENTER_CRITICAL_FROM_ISR().

taskENTER_CRITICAL_FROM_ISR() does not take any parameters.

taskENTER_CRITICAL_FROM_ISR() returns the interrupt mask state as it was before the macro was called. The value returned by taskENTER_CRITICAL_FROM_ISR() must be used as the uxSavedInterruptStatus parameter in the matching call to taskEXIT_CRITICAL_FROM_ISR().

taskEXIT_CRITICAL_FROM_ISR() does not return a value.

Example usage:
/* A function called from an ISR. */
void vDemoFunction( void )
UBaseType_t uxSavedInterruptStatus;

    /* Enter the critical section.  In this example, this function is itself called from
    within a critical section, so entering this critical section will result in a nesting
    depth of 2. Save the value returned by taskENTER_CRITICAL_FROM_ISR() into a local
    stack variable so it can be passed into taskEXIT_CRITICAL_FROM_ISR(). */
    uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();

    /* Perform the action that is being protected by the critical section here. */

    /* Exit the critical section.  In this example, this function is itself called from a
    critical section, so interrupts will have already been disabled before a value was
    stored in uxSavedInterruptStatus, and therefore passing uxSavedInterruptStatus into
    taskEXIT_CRITICAL_FROM_ISR() will not result in interrupts being re-enabled. */
    taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );

/* A task that calls vDemoFunction() from within an interrupt service routine. */
void vDemoISR( void )
UBaseType_t uxSavedInterruptStatus;

    /* Call taskENTER_CRITICAL_FROM_ISR() to create a critical section, saving the
    returned value into a local stack variable. */
    uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();

    /* Execute the code that requires the critical section here. */

    /* Calls to taskENTER_CRITICAL_FROM_ISR() can be nested so it is safe to call a
    function that includes its own calls to taskENTER_CRITICAL_FROM_ISR() and

    /* The operation that required the critical section is complete so exit the
    critical section.  Assuming interrupts were enabled on entry to this ISR, the value
    saved in uxSavedInterruptStatus will result in interrupts being re-enabled.*/
    taskEXIT_CRITICAL_FROM_ISR( uxSavedInterruptStatus );

[ 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