/*\r
FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
+\r
\r
***************************************************************************\r
* *\r
* User mode and Privileged mode, and using both the original xTaskCreate() and\r
* the new xTaskCreateRestricted() API functions. The purpose of each created\r
* task is documented in the comments above the task function prototype (in\r
- * this file), with the task behaviour demonstrated and documented within the \r
+ * this file), with the task behaviour demonstrated and documented within the\r
* task function itself. In addition a queue is used to demonstrate passing\r
* data between protected/restricted tasks as well as passing data between an\r
* interrupt and a protected/restricted task.\r
/* Prototypes for functions that implement tasks. -----------*/\r
/*-----------------------------------------------------------*/\r
\r
-/* \r
+/*\r
* Prototype for the reg test tasks. Amongst other things, these fill the CPU\r
* registers with known values before checking that the registers still contain\r
* the expected values. Each of the two tasks use different values so an error\r
static void prvCheckTask( void *pvParameters );\r
\r
/*\r
- * Prototype for a task created in User mode using the original vTaskCreate() \r
+ * Prototype for a task created in User mode using the original vTaskCreate()\r
* API function. The task demonstrates the characteristics of such a task,\r
* before simply deleting itself.\r
*/\r
static void prvOldStyleUserModeTask( void *pvParameters );\r
\r
/*\r
- * Prototype for a task created in Privileged mode using the original \r
- * vTaskCreate() API function. The task demonstrates the characteristics of \r
+ * Prototype for a task created in Privileged mode using the original\r
+ * vTaskCreate() API function. The task demonstrates the characteristics of\r
* such a task, before simply deleting itself.\r
*/\r
static void prvOldStylePrivilegedModeTask( void *pvParameters );\r
/* The handle of the queue used to communicate between tasks and between tasks\r
and interrupts. Note that this is a file scope variable that falls outside of\r
any MPU region. As such other techniques have to be used to allow the tasks\r
-to gain access to the queue. See the comments in the tasks themselves for \r
+to gain access to the queue. See the comments in the tasks themselves for\r
further information. */\r
static xQueueHandle xFileScopeCheckQueue = NULL;\r
\r
#define mainCHECK_TASK_STACK_ALIGNMENT ( mainCHECK_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )\r
\r
/* Declare the stack that will be used by the check task. The kernel will\r
- automatically create an MPU region for the stack. The stack alignment must \r
- match its size, so if 128 words are reserved for the stack then it must be \r
+ automatically create an MPU region for the stack. The stack alignment must\r
+ match its size, so if 128 words are reserved for the stack then it must be\r
aligned to ( 128 * 4 ) bytes. */\r
static portSTACK_TYPE xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainCHECK_TASK_STACK_ALIGNMENT );\r
\r
MPU FUNCTIONALITY, the data is not used by the check tasks primary function\r
of monitoring the reg test tasks and printing out status information.\r
\r
-Note that the arrays allocate slightly more RAM than is actually assigned to \r
-the MPU region. This is to permit writes off the end of the array to be \r
-detected even when the arrays are placed in adjacent memory locations (with no \r
+Note that the arrays allocate slightly more RAM than is actually assigned to\r
+the MPU region. This is to permit writes off the end of the array to be\r
+detected even when the arrays are placed in adjacent memory locations (with no\r
gaps between them). The align size must be a power of two. */\r
#define mainREAD_WRITE_ARRAY_SIZE 130\r
#define mainREAD_WRITE_ALIGN_SIZE 128\r
created with different parameters. Again, THIS IS JUST TO DEMONSTRATE THE\r
MPU FUNCTIONALITY, the data is not used by the check tasks primary function\r
of monitoring the reg test tasks and printing out status information.*/\r
- { \r
+ {\r
/* Base address Length Parameters */\r
{ cReadWriteArray, mainREAD_WRITE_ALIGN_SIZE, portMPU_REGION_READ_WRITE },\r
{ cReadOnlyArray, mainREAD_ONLY_ALIGN_SIZE, portMPU_REGION_READ_ONLY },\r
}\r
};\r
\r
-/* Three MPU regions are defined for use by the 'check' task when the task is \r
+/* Three MPU regions are defined for use by the 'check' task when the task is\r
created. These are only used to demonstrate the MPU features and are not\r
actually necessary for the check task to fulfill its primary purpose. Instead\r
-the MPU regions are replaced with those defined by xAltRegions prior to the \r
+the MPU regions are replaced with those defined by xAltRegions prior to the\r
check task receiving any data on the queue or printing any messages to the\r
debug console. The region configured by xAltRegions just gives the check task\r
access to the debug variables that form part of the Rowley library, and are\r
accessed within the debug_printf() function. */\r
extern unsigned long dbgCntrlWord_mempoll;\r
static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =\r
-{ \r
+{\r
/* Base address Length Parameters */\r
{ ( void * ) &dbgCntrlWord_mempoll, 32, portMPU_REGION_READ_WRITE },\r
{ 0, 0, 0 },\r
#define mainREG_TEST_STACK_ALIGNMENT ( mainREG_TEST_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )\r
\r
/* Declare the stacks that will be used by the reg test tasks. The kernel will\r
-automatically create an MPU region for the stack. The stack alignment must \r
-match its size, so if 128 words are reserved for the stack then it must be \r
+automatically create an MPU region for the stack. The stack alignment must\r
+match its size, so if 128 words are reserved for the stack then it must be\r
aligned to ( 128 * 4 ) bytes. */\r
static portSTACK_TYPE xRegTest1Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );\r
static portSTACK_TYPE xRegTest2Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_TO( mainREG_TEST_STACK_ALIGNMENT );\r
\r
/* Print out the amount of free heap space so configTOTAL_HEAP_SIZE can be\r
tuned. The heap size is set to be very small in this example and will need\r
- to be increased before many more tasks, queues or semaphores can be \r
+ to be increased before many more tasks, queues or semaphores can be\r
created. */\r
debug_printf( "There are %d bytes of unused heap space.\r\n", xPortGetFreeHeapSize() );\r
\r
- /* Demonstrate how the various memory regions can and can't be accessed. \r
+ /* Demonstrate how the various memory regions can and can't be accessed.\r
The task privilege level is set down to user mode within this function. */\r
prvTestMemoryRegions();\r
\r
{\r
/* Wait for the next message to arrive. */\r
xQueueReceive( xQueue, &lMessage, portMAX_DELAY );\r
- \r
+\r
switch( lMessage )\r
{\r
- case mainREG_TEST_1_STILL_EXECUTING : \r
+ case mainREG_TEST_1_STILL_EXECUTING :\r
/* Message from task 1, so task 1 must still be executing. */\r
( ulStillAliveCounts[ 0 ] )++;\r
break;\r
\r
- case mainREG_TEST_2_STILL_EXECUTING : \r
+ case mainREG_TEST_2_STILL_EXECUTING :\r
/* Message from task 2, so task 2 must still be executing. */\r
( ulStillAliveCounts[ 1 ] )++;\r
break;\r
\r
- case mainPRINT_SYSTEM_STATUS : \r
+ case mainPRINT_SYSTEM_STATUS :\r
/* Message from tick hook, time to print out the system\r
status. If messages has stopped arriving from either reg\r
test task then the status must be set to fail. */\r
if( ( ulStillAliveCounts[ 0 ] == 0 ) || ( ulStillAliveCounts[ 1 ] == 0 ) )\r
{\r
- /* One or both of the test tasks are no longer sending \r
+ /* One or both of the test tasks are no longer sending\r
'still alive' messages. */\r
pcStatusMessage = "FAIL\r\n";\r
}\r
break;\r
\r
default :\r
- /* Something unexpected happened. Delete this task so the \r
+ /* Something unexpected happened. Delete this task so the\r
error is apparent (no output will be displayed). */\r
prvDeleteMe();\r
break;\r
long l;\r
char cTemp;\r
\r
- /* The check task (from which this function is called) is created in the \r
- Privileged mode. The privileged array can be both read from and written \r
+ /* The check task (from which this function is called) is created in the\r
+ Privileged mode. The privileged array can be both read from and written\r
to while this task is privileged. */\r
cPrivilegedOnlyAccessArray[ 0 ] = 'a';\r
if( cPrivilegedOnlyAccessArray[ 0 ] != 'a' )\r
}\r
\r
/* Writing off the end of the RAM allocated to this task will *NOT* cause a\r
- protection fault because the task is still executing in a privileged mode. \r
+ protection fault because the task is still executing in a privileged mode.\r
Uncomment the following to test. */\r
/*cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] = 'a';*/\r
\r
/* Now set the task into user mode. */\r
portSWITCH_TO_USER_MODE();\r
- \r
- /* Accessing the privileged only array will now cause a fault. Uncomment \r
- the following line to test. */ \r
+\r
+ /* Accessing the privileged only array will now cause a fault. Uncomment\r
+ the following line to test. */\r
/*cPrivilegedOnlyAccessArray[ 0 ] = 'a';*/\r
\r
/* The read/write array can still be successfully read and written. */\r
}\r
\r
/* But attempting to read or write off the end of the RAM allocated to this\r
- task will cause a fault. Uncomment either of the following two lines to \r
+ task will cause a fault. Uncomment either of the following two lines to\r
test. */\r
/* cReadWriteArray[ 0 ] = cReadWriteArray[ -1 ]; */\r
/* cReadWriteArray[ mainREAD_WRITE_ALIGN_SIZE ] = 0x00; */\r
/* ...but cannot be written. Uncomment the following line to test. */\r
/* cReadOnlyArray[ 0 ] = 'a'; */\r
\r
- /* Writing to the first and last locations in the stack array should not \r
+ /* Writing to the first and last locations in the stack array should not\r
cause a protection fault. Note that doing this will cause the kernel to\r
- detect a stack overflow if configCHECK_FOR_STACK_OVERFLOW is greater than \r
+ detect a stack overflow if configCHECK_FOR_STACK_OVERFLOW is greater than\r
1. */\r
xCheckTaskStack[ 0 ] = 0;\r
xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS - 1 ] = 0;\r
\r
- /* Writing off either end of the stack array should cause a protection \r
+ /* Writing off either end of the stack array should cause a protection\r
fault, uncomment either of the following two lines to test. */\r
/* xCheckTaskStack[ -1 ] = 0; */\r
/* xCheckTaskStack[ mainCHECK_TASK_STACK_SIZE_WORDS ] = 0; */\r
+\r
+ ( void ) cTemp;\r
}\r
/*-----------------------------------------------------------*/\r
\r
longer be accessible but the stack copy will. */\r
xQueueHandle xQueue = xFileScopeCheckQueue;\r
\r
- /* Now the queue handle has been obtained the task can switch to user \r
+ /* Now the queue handle has been obtained the task can switch to user\r
mode. This is just one method of passing a handle into a protected\r
task, the other reg test task uses the task parameter instead. */\r
portSWITCH_TO_USER_MODE();\r
\r
\r
for( ;; )\r
- { \r
+ {\r
/* This task tests the kernel context switch mechanism by reading and\r
writing directly to registers - which requires the test to be written\r
in assembly code. */\r
- __asm volatile \r
- ( \r
+ __asm volatile\r
+ (\r
" MOV R4, #104 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */\r
" MOV R5, #105 \n"\r
" MOV R6, #106 \n"\r
" BNE prvDeleteMe \n"\r
" CMP R3, #103 \n"\r
" BNE prvDeleteMe \n"\r
- " CMP R4, #104 \n" \r
- " BNE prvDeleteMe \n" \r
+ " CMP R4, #104 \n"\r
+ " BNE prvDeleteMe \n"\r
" CMP R5, #105 \n"\r
" BNE prvDeleteMe \n"\r
" CMP R6, #106 \n"\r
:::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
);\r
\r
- /* Send mainREG_TEST_1_STILL_EXECUTING to the check task to indicate that this \r
+ /* Send mainREG_TEST_1_STILL_EXECUTING to the check task to indicate that this\r
task is still functioning. */\r
prvSendImAlive( xQueue, mainREG_TEST_1_STILL_EXECUTING );\r
\r
static void prvRegTest2Task( void *pvParameters )\r
{\r
/* The queue handle is passed in as the task parameter. This is one method of\r
-passing data into a protected task, the other reg test task uses a different \r
+passing data into a protected task, the other reg test task uses a different\r
method. */\r
xQueueHandle xQueue = ( xQueueHandle ) pvParameters;\r
\r
/* This task tests the kernel context switch mechanism by reading and\r
writing directly to registers - which requires the test to be written\r
in assembly code. */\r
- __asm volatile \r
- ( \r
+ __asm volatile\r
+ (\r
" MOV R4, #4 \n" /* Set registers to a known value. R0 to R1 are done in the loop below. */\r
" MOV R5, #5 \n"\r
" MOV R6, #6 \n"\r
" MOV R8, #8 \n" /* Frame pointer is omitted as it must not be changed. */\r
" MOV R9, #9 \n"\r
" MOV R10, 10 \n"\r
- " MOV R11, #11 \n" \r
+ " MOV R11, #11 \n"\r
"reg2loop: \n"\r
" MOV R0, #13 \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
" MOV R1, #1 \n"\r
:::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
);\r
\r
- /* Send mainREG_TEST_2_STILL_EXECUTING to the check task to indicate that this \r
+ /* Send mainREG_TEST_2_STILL_EXECUTING to the check task to indicate that this\r
task is still functioning. */\r
prvSendImAlive( xQueue, mainREG_TEST_2_STILL_EXECUTING );\r
\r
\r
/* The idle task, and therefore this function, run in Supervisor mode and\r
can therefore access all memory. Try reading from corners of flash and\r
- RAM to ensure a memory fault does not occur. \r
- \r
+ RAM to ensure a memory fault does not occur.\r
+\r
Start with the edges of the privileged data area. */\r
pul = __privileged_data_start__;\r
ulReadData = *pul;\r
pul = __FLASH_segment_end__ - 1;\r
ulReadData = *pul;\r
\r
- /* Reading off the end of Flash or SRAM space should cause a fault. \r
+ /* Reading off the end of Flash or SRAM space should cause a fault.\r
Uncomment one of the following two pairs of lines to test. */\r
- \r
+\r
/* pul = __FLASH_segment_end__ + 4;\r
ulReadData = *pul; */\r
\r
/* pul = __SRAM_segment_end__ + 1;\r
ulReadData = *pul; */\r
+\r
+ ( void ) ulReadData;\r
}\r
/*-----------------------------------------------------------*/\r
\r
volatile unsigned long *pul;\r
volatile unsigned long ulReadData;\r
\r
-/* The following lines are commented out to prevent the unused variable \r
+/* The following lines are commented out to prevent the unused variable\r
compiler warnings when the tests that use the variable are also commented out.\r
extern unsigned long __privileged_functions_start__[];\r
const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned long * ) 0xe000e014; */\r
\r
/* pul = __privileged_functions_start__;\r
ulReadData = *pul; */\r
- \r
+\r
/* pul = __privileged_functions_end__ - 1;\r
ulReadData = *pul; */\r
\r
/* pul = __privileged_data_start__;\r
ulReadData = *pul; */\r
- \r
+\r
/* pul = __privileged_data_end__ - 1;\r
ulReadData = *pul; */\r
\r
- /* Must not just run off the end of a task function, so delete this task. \r
+ /* Must not just run off the end of a task function, so delete this task.\r
Note that because this task was created using xTaskCreate() the stack was\r
allocated dynamically and I have not included any code to free it again. */\r
vTaskDelete( NULL );\r
+\r
+ ( void ) ulReadData;\r
}\r
/*-----------------------------------------------------------*/\r
\r
\r
( void ) pvParameters;\r
\r
- /* This task is created in Privileged mode using the original xTaskCreate() \r
- API function. It should have access to all Flash and RAM including that \r
- marked as Privileged access only. So reading from the start and end of the \r
- non-privileged RAM should not cause a problem (the privileged RAM is the \r
+ /* This task is created in Privileged mode using the original xTaskCreate()\r
+ API function. It should have access to all Flash and RAM including that\r
+ marked as Privileged access only. So reading from the start and end of the\r
+ non-privileged RAM should not cause a problem (the privileged RAM is the\r
first block at the bottom of the RAM memory). */\r
pul = __privileged_data_end__ + 1;\r
ulReadData = *pul;\r
pul = __privileged_functions_end__ - 1;\r
ulReadData = *pul;\r
pul = __privileged_data_start__;\r
- ulReadData = *pul; \r
+ ulReadData = *pul;\r
pul = __privileged_data_end__ - 1;\r
ulReadData = *pul;\r
\r
ulReadData = *pulSystemPeripheralRegister;\r
ulReadData = *pulStandardPeripheralRegister;\r
\r
- /* Must not just run off the end of a task function, so delete this task. \r
+ /* Must not just run off the end of a task function, so delete this task.\r
Note that because this task was created using xTaskCreate() the stack was\r
allocated dynamically and I have not included any code to free it again. */\r
vTaskDelete( NULL );\r
+\r
+ ( void ) ulReadData;\r
}\r
/*-----------------------------------------------------------*/\r
\r
ulCallCount = 0;\r
\r
/* Send a message to the check task to command it to check that all\r
- the tasks are still running then print out the status. \r
- \r
+ the tasks are still running then print out the status.\r
+\r
This is running in an ISR so has to use the "FromISR" version of\r
xQueueSend(). Because it is in an ISR it is running with privileges\r
so can access xFileScopeCheckQueue directly. */\r
\r
void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
{\r
- /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 then this \r
+ /* If configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2 then this\r
function will automatically get called if a task overflows its stack. */\r
( void ) pxTask;\r
( void ) pcTaskName;\r
\r
/* Inspect stacked_pc to locate the offending instruction. */\r
for( ;; );\r
+\r
+ ( void ) stacked_psr;\r
+ ( void ) stacked_pc;\r
+ ( void ) stacked_lr;\r
+ ( void ) stacked_r12;\r
+ ( void ) stacked_r0;\r
+ ( void ) stacked_r1;\r
+ ( void ) stacked_r2;\r
+ ( void ) stacked_r3;\r
}\r
/*-----------------------------------------------------------*/\r
\r