Quality RTOS & Embedded Software

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




Loading

difference between taskENTER_CRITICAL and tas

Posted by Yuhui Lin on July 21, 2010
I'm a little confused about the different between taskENTER_CRITICAL and taskDISABLE_INTERRUPTS.

I read the user manual, it said "they working by disabling interrupt......Pre-emptive switch can only occur from interrupt, so as long as interrupt remains disabled, the task called the taskENTER_CRITICAL can guaranteed to remain in running state ". From my understanding, both of them can result in disabled interrupt and context switch. Any tips?

RE: difference between taskENTER_CRITICAL and tas

Posted by Dave on July 21, 2010
ENTER_CRITICAL() keeps a count of the call nesting and is the only one you should use really. It normally calls DISABLE_INTERRUPTS internally.

Some but not all ports can still context switch with interrupts disabled, but not from in a preemptive way because with interrupts being disabled they cannot be preempted.

RE: difference between taskENTER_CRITICAL and tas

Posted by Yuhui Lin on July 21, 2010
thanks davedoors for your answer, but I am still not very clear. Is there any 'extra benefit' ENTER_CRITICAL could provides, besides disabled interrupt.

They seem to be the same to me. I can't tell the differences betweens them. Then I start wonder why do I need two different interface, if they share nearly the same features. I guess there should be something unknown to me.

RE: difference between taskENTER_CRITICAL and tas

Posted by Richard Damon on July 21, 2010
The big difference is the ENTER/EXIT Critical takes into account nesting, Enable/Disable interrupt do not. Thus

ENTER
/* Interrupts now disabled */
ENTER
EXIT
/* Interrupts still disabled */
EXIT
/* unwound all the critical sections, so interrupt now enabled */

While with DISABLE you would get

DISABLE
/* Interrupts now disabled */
DISABLE

ENABLE
/* Interrupts now reenabled even though we disabled twice */
ENABLE


RE: difference between taskENTER_CRITICAL and tas

Posted by Yuhui Lin on July 21, 2010
Aha~ thanks~ I got it now. That's the reason I saw push and pop assembly code in one of the porting file for ENTER_CRITICAL and EXIT_CRITICAL

RE: difference between taskENTER_CRITICAL and tas

Posted by Richard Damon on July 21, 2010
Critical sections should not be storing the "stacking" of them on the stack, but tend to use a counter.

Some ports may use push/pop to access a status/control register. One thing to note is that a critical section may not disable ALL interrupts, but may just disable those interrupts at a level which is allowed to interact with the kernel, and this is sometimes done by setting the current interrupt priority level in the hardware.


[ 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