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

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 ]    [ 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