From d77fac87c3796fb1b4ebe959c8f776f5c6bc05b8 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Fri, 7 Jun 2013 09:37:18 +0000 Subject: [PATCH] Add configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS mechanism to allow the user to define functions that will execute in privileged mode. Update the Rowley MPU demo to use a version of debug_printf that runs in privileged mode to get around the problem of the RAM it uses not being under the control of the kernel. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1918 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../FreeRTOSConfig.h | 17 ++++--- .../CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzp | 2 +- .../CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzs | 37 ++++++--------- ...application_defined_privileged_functions.h | 1 + .../Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c | 47 ++++++------------- 5 files changed, 42 insertions(+), 62 deletions(-) create mode 100644 FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/application_defined_privileged_functions.h diff --git a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/FreeRTOSConfig.h index ea75d60ac..b8095a9b5 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/FreeRTOSConfig.h @@ -56,19 +56,19 @@ *************************************************************************** - http://www.FreeRTOS.org - Documentation, books, training, latest versions, + http://www.FreeRTOS.org - Documentation, books, training, latest versions, license and Real Time Engineers Ltd. contact details. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, including FreeRTOS+Trace - an indispensable productivity tool, and our new fully thread aware and reentrant UDP/IP stack. - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and mission critical applications that require provable dependability. */ @@ -134,4 +134,9 @@ to exclude the API function. */ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ #define configMAX_SYSCALL_INTERRUPT_PRIORITY ( ( unsigned char ) 5 << configUNUSED_PRIO_BITS ) /* Priority 5, or 160 as only the top three bits are implemented. */ +/* The debug_printf() function uses RAM that is outside of the control of the +application writer. Therefore the application_defined_privileged_functions.h +header file is used to provide a version that executes with privileges. */ +#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1 + #endif /* FREERTOS_CONFIG_H */ diff --git a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzp b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzp index 3da154e39..646bbdf5a 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzp +++ b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzp @@ -8,7 +8,6 @@ - @@ -18,6 +17,7 @@ + diff --git a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzs b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzs index 9a0619ca5..637fe364e 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzs +++ b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/RTOSDemo.hzs @@ -2,63 +2,56 @@ - - - - - - + - + - + - + - + - - - + - + - + - + - + - + + + - - - + - + diff --git a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/application_defined_privileged_functions.h b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/application_defined_privileged_functions.h new file mode 100644 index 000000000..613c2c952 --- /dev/null +++ b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/application_defined_privileged_functions.h @@ -0,0 +1 @@ +/* FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd. FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. *************************************************************************** * * * FreeRTOS tutorial books are available in pdf and paperback. * * Complete, revised, and edited pdf reference manuals are also * * available. * * * * Purchasing FreeRTOS documentation will not only help you, by * * ensuring you get running as quickly as possible and with an * * in-depth knowledge of how to use FreeRTOS, it will also help * * the FreeRTOS project to continue with its mission of providing * * professional grade, cross platform, de facto standard solutions * * for microcontrollers - completely free of charge! * * * * >>> See http://www.FreeRTOS.org/Documentation for details. <<< * * * * Thank you for using FreeRTOS, and thank you for your support! * * * *************************************************************************** This file is part of the FreeRTOS distribution. FreeRTOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (version 2) as published by the Free Software Foundation AND MODIFIED BY the FreeRTOS exception. >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to distribute a combined work that includes FreeRTOS without being obliged to provide the source code for proprietary components outside of the FreeRTOS kernel. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License and the FreeRTOS license exception along with FreeRTOS; if not it can be viewed here: http://www.freertos.org/a00114.html and also obtained by writing to Real Time Engineers Ltd., contact details for whom are available on the FreeRTOS WEB site. 1 tab == 4 spaces! *************************************************************************** * * * Having a problem? Start by reading the FAQ "My application does * * not run, what could be wrong?" * * * * http://www.FreeRTOS.org/FAQHelp.html * * * *************************************************************************** http://www.FreeRTOS.org - Documentation, books, training, latest versions, license and Real Time Engineers Ltd. contact details. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, including FreeRTOS+Trace - an indispensable productivity tool, and our new fully thread aware and reentrant UDP/IP stack. http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell the code with commercial support, indemnification and middleware, under the OpenRTOS brand. http://www.SafeRTOS.com - High Integrity Systems also provide a safety engineered and independently SIL3 certified version for use in safety and mission critical applications that require provable dependability. */ #ifndef APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS_H #define APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS_H /* The Rowley library function debug_printf() uses data that is out of the control of the kernel, so run the function in a privileged mode. */ int MPU_debug_printf( const char *pcMessage ) { portBASE_TYPE xRunningPrivileged = prvRaisePrivilege(); debug_printf( pcMessage ); portRESET_PRIVILEGE( xRunningPrivileged ); } #endif /* APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS_H */ \ No newline at end of file diff --git a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c index 3a6356874..42258a46c 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c +++ b/FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley/main.c @@ -56,19 +56,19 @@ *************************************************************************** - http://www.FreeRTOS.org - Documentation, books, training, latest versions, + http://www.FreeRTOS.org - Documentation, books, training, latest versions, license and Real Time Engineers Ltd. contact details. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, including FreeRTOS+Trace - an indispensable productivity tool, and our new fully thread aware and reentrant UDP/IP stack. - http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High - Integrity Systems, who sell the code with commercial support, + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems, who sell the code with commercial support, indemnification and middleware, under the OpenRTOS brand. - - http://www.SafeRTOS.com - High Integrity Systems also provide a safety - engineered and independently SIL3 certified version for use in safety and + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and mission critical applications that require provable dependability. */ @@ -267,23 +267,6 @@ static const xTaskParameters xCheckTaskParameters = } }; -/* Three MPU regions are defined for use by the 'check' task when the task is -created. These are only used to demonstrate the MPU features and are not -actually necessary for the check task to fulfill its primary purpose. Instead -the MPU regions are replaced with those defined by xAltRegions prior to the -check task receiving any data on the queue or printing any messages to the -debug console. The region configured by xAltRegions just gives the check task -access to the debug variables that form part of the Rowley library, and are -accessed within the debug_printf() function. */ -extern unsigned long dbgCntrlWord_mempoll; -static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] = -{ - /* Base address Length Parameters */ - { ( void * ) &dbgCntrlWord_mempoll, 32, portMPU_REGION_READ_WRITE }, - { 0, 0, 0 }, - { 0, 0, 0 } -}; - /*-----------------------------------------------------------*/ @@ -396,22 +379,20 @@ long lMessage; unsigned long ulStillAliveCounts[ 2 ] = { 0 }; const char *pcStatusMessage = "PASS\r\n"; +/* The debug_printf() function uses RAM that is outside of the control of the +application writer. Therefore the application_defined_privileged_functions.h +header file is used to provide a version that executes with privileges. */ +extern int MPU_debug_printf( const char *pcMessage ); + /* Just to remove compiler warning. */ ( void ) pvParameters; - /* Print out the amount of free heap space so configTOTAL_HEAP_SIZE can be - tuned. The heap size is set to be very small in this example and will need - to be increased before many more tasks, queues or semaphores can be - created. */ - debug_printf( "There are %d bytes of unused heap space.\r\n", xPortGetFreeHeapSize() ); - /* Demonstrate how the various memory regions can and can't be accessed. The task privilege level is set down to user mode within this function. */ prvTestMemoryRegions(); - /* Change the memory regions allocated to this task to those initially - set up for demonstration purposes to those actually required by the task. */ - vTaskAllocateMPURegions( NULL, xAltRegions ); + /* Tests are done so lower the privilege status. */ + portSWITCH_TO_USER_MODE(); /* This loop performs the main function of the task, which is blocking on a message queue then processing each message as it arrives. */ @@ -445,7 +426,7 @@ const char *pcStatusMessage = "PASS\r\n"; /* Print a pass/fail message to the terminal. This will be visible in the CrossWorks IDE. */ - debug_printf( pcStatusMessage ); + MPU_debug_printf( pcStatusMessage ); /* Reset the count of 'still alive' messages. */ memset( ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) ); -- 2.39.5