Quality RTOS & Embedded Software

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


Loading

FreeRTOS Privilege Status Detection

Posted by Jerry Ross on November 14, 2009
FreeRTOSS6.0.0:

Definition in: FreeRTOS.h

#ifndef portPRIVILEGE_BIT
#define portPRIVILEGE_BIT ( ( unsigned portBASE_TYPE ) 0x00 )
#endif

Usage in: tasks.c

/* Should the task be created in privileged mode? */
LINE: 403
if( ( uxPriority & portPRIVILEGE_BIT ) != 0x00 )
{
xRunPrivileged = pdTRUE;
}
else
{
xRunPrivileged = pdFALSE;
}
uxPriority &= ~portPRIVILEGE_BIT;

The code at line 403 will always fail the test ( uxPriority & portPRIVILEGE_BIT ) != 0x00 because portPRIVILEGE_BIT is the value 0 which represents the privilege bit position in uxPriority. It is being used as a value, zero (0), instead of a bit position of zero (0) so the expression (uxPriority & portPRIVILEGE_BIT) will always produce a value of zero (0) which will never be !=0x00.

Jerry Ross



RE: FreeRTOS Privilege Status Detection

Posted by Richard on November 14, 2009

#ifndef portPRIVILEGE_BIT
#define portPRIVILEGE_BIT ( ( unsigned portBASE_TYPE ) 0x00 )
#endif

This definition is the default setting when portPRIVILEGE_BIT is not defined anywhere else. In the Cortex M3 MPU ports portPRIVILEGE_BIT is defined as 0x80000000, which means bit 31 indicates the privilege status.


if( ( uxPriority & portPRIVILEGE_BIT ) != 0x00 )
{
xRunPrivileged = pdTRUE;
}
else
{
xRunPrivileged = pdFALSE;
}

If portPRIVILEGE_BIT is 0 then xRunPrivileged will always be set to pdFALSE as anything bitwise ANDed with 0 will always be zero. However, if portPRIVILEGE_BIT is set to 0 then the MPU is not being used and pdFALSE is the correct value for xRunPrivileged. A value of 0 does not mean bit 0, it means no bits are set.

Regards.

RE: FreeRTOS Privilege Status Detection

Posted by Jerry Ross on November 14, 2009
Thank you for the quick reply. I understand your logic now. I should have scanned the entire code base for an answer. I will be more thorough next time.

My compiler elides the expression because it has no effect.


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner