]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c
Update version number in preparation for maintenance release.
[freertos] / FreeRTOS / Demo / CORTEX_MPU_Simulator_Keil_GCC / main.c
index 0c1e9465e2a28899d92dd6480bc238ce003bb97c..9d12c451ba420764034d0665e04fa27401301093 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
+    FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
 /*\r
  * This file demonstrates the use of FreeRTOS-MPU.  It creates tasks in both\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
- * 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
+ * User mode and Privileged mode, and using both the xTaskCreate() and\r
+ * xTaskCreateRestricted() API functions.  The purpose of each created task is\r
+ * documented in the comments above the task function prototype (in this file),\r
+ * with the task behaviour demonstrated and documented within the task function\r
+ * itself.\r
+ *\r
+ * In addition a queue is used to demonstrate passing data between\r
+ * protected/restricted tasks as well as passing data between an interrupt and\r
+ * a protected/restricted task.  A software timer is also used.\r
  */\r
 \r
 /* Standard includes. */\r
 #include "task.h"\r
 #include "queue.h"\r
 #include "semphr.h"\r
+#include "timers.h"\r
+#include "event_groups.h"\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 /* Misc constants. */\r
 #define mainDONT_BLOCK                                 ( 0 )\r
 \r
-/* Definitions for the messages that can be sent to the check task. */\r
-#define mainREG_TEST_1_STILL_EXECUTING ( 0 )\r
-#define mainREG_TEST_2_STILL_EXECUTING ( 1 )\r
-#define mainPRINT_SYSTEM_STATUS                        ( 2 )\r
-\r
 /* GCC specifics. */\r
 #define mainALIGN_TO( x )                              __attribute__((aligned(x)))\r
 \r
 /* Hardware register addresses. */\r
-#define mainVTOR                                       ( * ( volatile uint32_t * ) 0xE000ED08 )\r
-#define mainNVIC_AUX_ACTLR                     ( * ( volatile uint32_t * ) 0xE000E008 )\r
-#define mainEC_INTERRUPT_CONTROL       ( * ( volatile uint32_t * ) 0x4000FC18 )\r
+#define mainVTOR                                               ( * ( volatile uint32_t * ) 0xE000ED08 )\r
+\r
+/* The period of the timer must be less than the rate at which\r
+configPRINT_SYSTEM_STATUS messages are sent to the check task - otherwise the\r
+check task will think the timer has stopped. */\r
+#define mainTIMER_PERIOD                               pdMS_TO_TICKS( 200 )\r
+\r
+/* The name of the task that is deleted by the Idle task is used in a couple of\r
+places, so is #defined. */\r
+#define mainTASK_TO_DELETE_NAME                        "DeleteMe"\r
 \r
 /*-----------------------------------------------------------*/\r
 /* Prototypes for functions that implement tasks. -----------*/\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
+ * NOTE:  The filling and checking of the registers in the following two tasks\r
+ *        is only actually performed when the GCC compiler is used.  Use of the\r
+ *        queue to communicate with the check task is done with all compilers.\r
+ *\r
+ * Prototype for the first two register test tasks, which execute in User mode.\r
+ * Amongst other things, these fill the CPU registers (other than the FPU\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
- * in the context switch mechanism can be caught.  Both reg test tasks execute\r
- * at the idle priority so will get preempted regularly.  Each task repeatedly\r
- * sends a message on a queue so long as it remains functioning correctly.  If\r
- * an error is detected within the task the task is simply deleted.\r
+ * in the context switch mechanism can be caught.  Both tasks execute at the\r
+ * idle priority so will get preempted regularly.  Each task repeatedly sends a\r
+ * message on a queue to a 'check' task so the check task knows the register\r
+ * check task is still executing and has not detected any errors.  If an error\r
+ * is detected within the task the task is simply deleted so it no longer sends\r
+ * messages.\r
+ *\r
+ * For demonstration and test purposes, both tasks obtain access to the queue\r
+ * handle in different ways; vRegTest1Implementation() is created in Privileged\r
+ * mode and copies the queue handle to its local stack before setting itself to\r
+ * User mode, and vRegTest2Implementation() receives the task handle using its\r
+ * parameter.\r
  */\r
-static void prvRegTest1Task( void *pvParameters );\r
-static void prvRegTest2Task( void *pvParameters );\r
+extern void vRegTest1Implementation( void *pvParameters );\r
+extern void vRegTest2Implementation( void *pvParameters );\r
+\r
+/*\r
+ * The second two register test tasks are similar to the first two, but do test\r
+ * the floating point registers, execute in Privileged mode, and signal their\r
+ * execution status to the 'check' task by incrementing a loop counter on each\r
+ * iteration instead of sending a message on a queue.  The loop counters use a\r
+ * memory region to which the User mode 'check' task has read access.\r
+ *\r
+ * The functions ending 'Implementation' are called by the register check tasks.\r
+ */\r
+static void prvRegTest3Task( void *pvParameters );\r
+extern void vRegTest3Implementation( void );\r
+static void prvRegTest4Task( void *pvParameters );\r
+extern void vRegTest4Implementation( void );\r
 \r
 /*\r
  * Prototype for the check task.  The check task demonstrates various features\r
@@ -129,13 +162,13 @@ static void prvRegTest2Task( void *pvParameters );
  *\r
  * Two types of messages can be processes:\r
  *\r
- * 1) "I'm Alive" messages sent from the reg test tasks, indicating that the\r
- *    task is still operational.\r
+ * 1) "I'm Alive" messages sent from the first two register test tasks and a\r
+ *    software timer callback, as described above.\r
  *\r
  * 2) "Print Status commands" sent periodically by the tick hook function (and\r
- *    therefore from within an interrupt) which command the check task to write\r
+ *    therefore from within an interrupt) which commands the check task to write\r
  *    either pass or fail to the terminal, depending on the status of the reg\r
- *    test tasks.\r
+ *    test tasks (no write is performed in the simulator!).\r
  */\r
 static void prvCheckTask( void *pvParameters );\r
 \r
@@ -153,10 +186,18 @@ static void prvOldStyleUserModeTask( void *pvParameters );
  */\r
 static void prvOldStylePrivilegedModeTask( void *pvParameters );\r
 \r
+/*\r
+ * A task that exercises the API of various RTOS objects before being deleted by\r
+ * the Idle task.  This is done for MPU API code coverage test purposes.\r
+ */\r
+static void prvTaskToDelete( void *pvParameters );\r
 \r
-/*-----------------------------------------------------------*/\r
-/* Prototypes for other misc functions.  --------------------*/\r
-/*-----------------------------------------------------------*/\r
+/*\r
+ * Functions called by prvTaskToDelete() to exercise the MPU API.\r
+ */\r
+static void prvExerciseEventGroupAPI( void );\r
+static void prvExerciseSemaphoreAPI( void );\r
+static void prvExerciseTaskNotificationAPI( void );\r
 \r
 /*\r
  * Just configures any clocks and IO necessary.\r
@@ -168,15 +209,16 @@ static void prvSetupHardware( void );
  * is simpler to call from asm code than the normal vTaskDelete() API function.\r
  * It has the noinline attribute because it is called from asm code.\r
  */\r
-static void prvDeleteMe( void ) __attribute__((noinline));\r
+void vMainDeleteMe( void ) __attribute__((noinline));\r
 \r
 /*\r
- * Used by both reg test tasks to send messages to the check task.  The message\r
- * just lets the check task know that the task is still functioning correctly.\r
- * If a reg test task detects an error it will delete itself, and in so doing\r
- * prevent itself from sending any more 'I'm Alive' messages to the check task.\r
+ * Used by the first two reg test tasks and a software timer callback function\r
+ * to send messages to the check task.  The message just lets the check task\r
+ * know that the tasks and timer are still functioning correctly.  If a reg test\r
+ * task detects an error it will delete itself, and in so doing prevent itself\r
+ * from sending any more 'I'm Alive' messages to the check task.\r
  */\r
-static void prvSendImAlive( QueueHandle_t xHandle, unsigned long ulTaskNumber );\r
+void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );\r
 \r
 /*\r
  * The check task is created with access to three memory regions (plus its\r
@@ -188,16 +230,49 @@ static void prvSendImAlive( QueueHandle_t xHandle, unsigned long ulTaskNumber );
  */\r
 static void prvTestMemoryRegions( void );\r
 \r
+/*\r
+ * Callback function used with the timer that uses the queue to send messages\r
+ * to the check task.\r
+ */\r
+static void prvTimerCallback( TimerHandle_t xExpiredTimer );\r
+\r
 /*-----------------------------------------------------------*/\r
 \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
+and interrupts.  Note that this is a global 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
 further information. */\r
-static QueueHandle_t xFileScopeCheckQueue = NULL;\r
-\r
-\r
+QueueHandle_t xGlobalScopeCheckQueue = NULL;\r
+\r
+/* Holds the handle of a task that is deleted in the idle task hook - this is\r
+done for code coverage test purposes only. */\r
+static TaskHandle_t xTaskToDelete = NULL;\r
+\r
+/* The timer that periodically sends data to the check task on the queue. */\r
+static TimerHandle_t xTimer = NULL;\r
+\r
+#if defined ( __GNUC__ )\r
+       extern uint32_t __FLASH_segment_start__[];\r
+       extern uint32_t __FLASH_segment_end__[];\r
+       extern uint32_t __SRAM_segment_start__[];\r
+       extern uint32_t __SRAM_segment_end__[];\r
+       extern uint32_t __privileged_functions_start__[];\r
+       extern uint32_t __privileged_functions_end__[];\r
+       extern uint32_t __privileged_data_start__[];\r
+       extern uint32_t __privileged_data_end__[];\r
+       extern uint32_t __privileged_functions_actual_end__[];\r
+       extern uint32_t __privileged_data_actual_end__[];\r
+#else\r
+       const uint32_t * __FLASH_segment_start__ = ( uint32_t * ) 0x00UL;\r
+       const uint32_t * __FLASH_segment_end__ = ( uint32_t * ) 0x00080000UL;\r
+       const uint32_t * __SRAM_segment_start__ = ( uint32_t * ) 0x20000000UL;\r
+       const uint32_t * __SRAM_segment_end__ = ( uint32_t * ) 0x20008000UL;\r
+       const uint32_t * __privileged_functions_start__ = ( uint32_t * ) 0x00UL;\r
+       const uint32_t * __privileged_functions_end__ = ( uint32_t * ) 0x8000UL;\r
+       const uint32_t * __privileged_data_start__ = ( uint32_t * ) 0x20000000UL;\r
+       const uint32_t * __privileged_data_end__ = ( uint32_t * ) 0x20000200UL;\r
+#endif\r
 /*-----------------------------------------------------------*/\r
 /* Data used by the 'check' task. ---------------------------*/\r
 /*-----------------------------------------------------------*/\r
@@ -234,13 +309,23 @@ char cReadOnlyArray[ mainREAD_ONLY_ARRAY_SIZE ] mainALIGN_TO( mainREAD_ONLY_ALIG
 #define mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE 128\r
 char cPrivilegedOnlyAccessArray[ mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE ] mainALIGN_TO( mainPRIVILEGED_ONLY_ACCESS_ALIGN_SIZE );\r
 \r
+/* The following two variables are used to communicate the status of the second\r
+two register check tasks (tasks 3 and 4) to the check task.  If the variables\r
+keep incrementing, then the register check tasks have not discovered any errors.\r
+If a variable stops incrementing, then an error has been found.  The variables\r
+overlay the array that the check task has access to so they can be read by the\r
+check task without causing a memory fault.  The check task has the highest\r
+priority so will have finished with the array before the register test tasks\r
+start to access it. */\r
+volatile uint32_t *pulRegTest3LoopCounter = ( uint32_t * ) &( cReadWriteArray[ 0 ] ), *pulRegTest4LoopCounter = ( uint32_t * ) &( cReadWriteArray[ 4 ] );\r
+\r
 /* Fill in a TaskParameters_t structure to define the check task - this is the\r
 structure passed to the xTaskCreateRestricted() function. */\r
 static const TaskParameters_t xCheckTaskParameters =\r
 {\r
        prvCheckTask,                                                           /* pvTaskCode - the function that implements the task. */\r
-       "Check",                                                                        /* pcName                       */\r
-       mainCHECK_TASK_STACK_SIZE_WORDS,                        /* usStackDepth - defined in words, not bytes. */\r
+       "Check",                                                                        /* pcName */\r
+       mainCHECK_TASK_STACK_SIZE_WORDS,                        /* usStackDepth - defined in words, not bytes. */\r
        ( void * ) 0x12121212,                                          /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */\r
        ( tskIDLE_PRIORITY + 1 ) | portPRIVILEGE_BIT,/* uxPriority - this is the highest priority task in the system.  The task is created in privileged mode to demonstrate accessing the privileged only data. */\r
        xCheckTaskStack,                                                        /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
@@ -279,13 +364,13 @@ static portSTACK_TYPE xRegTest2Stack[ mainREG_TEST_STACK_SIZE_WORDS ] mainALIGN_
 /* Fill in a TaskParameters_t structure per reg test task to define the tasks. */\r
 static const TaskParameters_t xRegTest1Parameters =\r
 {\r
-       prvRegTest1Task,                                                /* pvTaskCode - the function that implements the task. */\r
-       "RegTest1",                                                             /* pcName                       */\r
-       mainREG_TEST_STACK_SIZE_WORDS,                  /* usStackDepth         */\r
-       ( void * ) 0x12345678,                                  /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */\r
-       tskIDLE_PRIORITY | portPRIVILEGE_BIT,   /* uxPriority - note that this task is created with privileges to demonstrate one method of passing a queue handle into the task. */\r
-       xRegTest1Stack,                                                 /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
-       {                                                                               /* xRegions - this task does not use any non-stack data hence all members are zero. */\r
+       vRegTest1Implementation,                                                        /* pvTaskCode - the function that implements the task. */\r
+       "RegTest1",                                                                     /* pcName                       */\r
+       mainREG_TEST_STACK_SIZE_WORDS,                          /* usStackDepth         */\r
+       ( void * ) configREG_TEST_TASK_1_PARAMETER,     /* pvParameters - this value is just to test that the parameter is being passed into the task correctly. */\r
+       tskIDLE_PRIORITY | portPRIVILEGE_BIT,           /* uxPriority - note that this task is created with privileges to demonstrate one method of passing a queue handle into the task. */\r
+       xRegTest1Stack,                                                         /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
+       {                                                                                       /* xRegions - this task does not use any non-stack data hence all members are zero. */\r
                /* Base address         Length          Parameters */\r
                { 0x00,                         0x00,                   0x00 },\r
                { 0x00,                         0x00,                   0x00 },\r
@@ -296,7 +381,7 @@ static const TaskParameters_t xRegTest1Parameters =
 \r
 static TaskParameters_t xRegTest2Parameters =\r
 {\r
-       prvRegTest2Task,                                /* pvTaskCode - the function that implements the task. */\r
+       vRegTest2Implementation,                                /* pvTaskCode - the function that implements the task. */\r
        "RegTest2",                                             /* pcName                       */\r
        mainREG_TEST_STACK_SIZE_WORDS,  /* usStackDepth         */\r
        ( void * ) NULL,                                /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */\r
@@ -310,27 +395,68 @@ static TaskParameters_t xRegTest2Parameters =
        }\r
 };\r
 \r
+/*-----------------------------------------------------------*/\r
+/* Configures the task that is deleted. ---------------------*/\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Define the constants used to allocate the stack of the task that is\r
+deleted.  Note that that stack size is defined in words, not bytes. */\r
+#define mainDELETE_TASK_STACK_SIZE_WORDS       128\r
+#define mainTASK_TO_DELETE_STACK_ALIGNMENT     ( mainDELETE_TASK_STACK_SIZE_WORDS * sizeof( portSTACK_TYPE ) )\r
+\r
+/* Declare the stack that will be used by the task that gets deleted.  The\r
+kernel will automatically create an MPU region for the stack.  The stack\r
+alignment must match its size, so if 128 words are reserved for the stack\r
+then it must be aligned to ( 128 * 4 ) bytes. */\r
+static portSTACK_TYPE xDeleteTaskStack[ mainDELETE_TASK_STACK_SIZE_WORDS ] mainALIGN_TO( mainTASK_TO_DELETE_STACK_ALIGNMENT );\r
+\r
+static TaskParameters_t xTaskToDeleteParameters =\r
+{\r
+       prvTaskToDelete,                                        /* pvTaskCode - the function that implements the task. */\r
+       mainTASK_TO_DELETE_NAME,                        /* pcName */\r
+       mainDELETE_TASK_STACK_SIZE_WORDS,       /* usStackDepth */\r
+       ( void * ) NULL,                                        /* pvParameters - this task uses the parameter to pass in a queue handle, but the queue is not created yet. */\r
+       tskIDLE_PRIORITY + 1,                           /* uxPriority */\r
+       xDeleteTaskStack,                                       /* puxStackBuffer - the array to use as the task stack, as declared above. */\r
+       {                                                                       /* xRegions - this task does not use any non-stack data hence all members are zero. */\r
+               /* Base address         Length          Parameters */\r
+               { 0x00,                         0x00,                   0x00 },\r
+               { 0x00,                         0x00,                   0x00 },\r
+               { 0x00,                         0x00,                   0x00 }\r
+       }\r
+};\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
+volatile uint32_t ul1 = 0x123, ul2 = 0;\r
+\r
 int main( void )\r
 {\r
+       configASSERT( ul1 == 0x123 );\r
+       configASSERT( ul2 == 0 );\r
        prvSetupHardware();\r
 \r
        /* Create the queue used to pass "I'm alive" messages to the check task. */\r
-       xFileScopeCheckQueue = xQueueCreate( 1, sizeof( unsigned long ) );\r
+       xGlobalScopeCheckQueue = xQueueCreate( 1, sizeof( uint32_t ) );\r
 \r
        /* One check task uses the task parameter to receive the queue handle.\r
        This allows the file scope variable to be accessed from within the task.\r
        The pvParameters member of xRegTest2Parameters can only be set after the\r
        queue has been created so is set here. */\r
-       xRegTest2Parameters.pvParameters = xFileScopeCheckQueue;\r
+       xRegTest2Parameters.pvParameters = xGlobalScopeCheckQueue;\r
 \r
-       /* Create the three test tasks.  Handles to the created tasks are not\r
-       required, hence the second parameter is NULL. */\r
+       /* Create three test tasks.  Handles to the created tasks are not required,\r
+       hence the second parameter is NULL. */\r
        xTaskCreateRestricted( &xRegTest1Parameters, NULL );\r
     xTaskCreateRestricted( &xRegTest2Parameters, NULL );\r
        xTaskCreateRestricted( &xCheckTaskParameters, NULL );\r
 \r
+       /* Create a task that does nothing but ensure some of the MPU API functions\r
+       can be called correctly, then get deleted.  This is done for code coverage\r
+       test purposes only.  The task's handle is saved in xTaskToDelete so it can\r
+       get deleted in the idle task hook. */\r
+       xTaskCreateRestricted( &xTaskToDeleteParameters, &xTaskToDelete );\r
+\r
        /* Create the tasks that are created using the original xTaskCreate() API\r
        function. */\r
        xTaskCreate(    prvOldStyleUserModeTask,        /* The function that implements the task. */\r
@@ -349,13 +475,26 @@ int main( void )
                                        NULL                                                    /* Handle. */\r
                                );\r
 \r
+       /* Create the third and fourth register check tasks, as described at the top\r
+       of this file. */\r
+       xTaskCreate( prvRegTest3Task, "Reg3", configMINIMAL_STACK_SIZE, configREG_TEST_TASK_3_PARAMETER, tskIDLE_PRIORITY, NULL );\r
+       xTaskCreate( prvRegTest4Task, "Reg4", configMINIMAL_STACK_SIZE, configREG_TEST_TASK_4_PARAMETER, tskIDLE_PRIORITY, NULL );\r
+\r
+       /* Create and start the software timer. */\r
+       xTimer = xTimerCreate( "Timer",                         /* Test name for the timer. */\r
+                                                       mainTIMER_PERIOD,       /* Period of the timer. */\r
+                                                       pdTRUE,                         /* The timer will auto-reload itself. */\r
+                                                       ( void * ) 0,           /* The timer's ID is used to count the number of times it expires - initialise this to 0. */\r
+                                                       prvTimerCallback );     /* The function called when the timer expires. */\r
+       configASSERT( xTimer );\r
+       xTimerStart( xTimer, mainDONT_BLOCK );\r
+\r
        /* Start the scheduler. */\r
        vTaskStartScheduler();\r
 \r
        /* Will only get here if there was insufficient memory to create the idle\r
        task. */\r
        for( ;; );\r
-       return 0;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -365,11 +504,21 @@ static void prvCheckTask( void *pvParameters )
 queue variable.  Take a stack copy of this before the task is set into user\r
 mode.  Once that task is in user mode the file scope queue variable will no\r
 longer be accessible but the stack copy will. */\r
-QueueHandle_t xQueue = xFileScopeCheckQueue;\r
-long lMessage;\r
-unsigned long ulStillAliveCounts[ 2 ] = { 0 };\r
+QueueHandle_t xQueue = xGlobalScopeCheckQueue;\r
+int32_t lMessage;\r
+uint32_t ulStillAliveCounts[ 3 ] = { 0 };\r
 const char *pcStatusMessage = "PASS\r\n";\r
+uint32_t ulLastRegTest3CountValue = 0, ulLastRegTest4Value = 0;\r
+\r
+/* The register test tasks that also test the floating point registers increment\r
+a counter on each iteration of their loop.  The counters are inside the array\r
+that this task has access to. */\r
+volatile uint32_t *pulOverlaidCounter3 = ( uint32_t * ) &( cReadWriteArray[ 0 ] ), *pulOverlaidCounter4 = ( uint32_t * ) &( cReadWriteArray[ 4 ] );\r
 \r
+/* ulCycleCount is incremented on each cycle of the check task.  It can be \r
+viewed updating in the Keil watch window as the simulator does not print to\r
+the ITM port. */\r
+volatile uint32_t ulCycleCount = 0;\r
 \r
        /* Just to remove compiler warning. */\r
        ( void ) pvParameters;\r
@@ -378,8 +527,9 @@ const char *pcStatusMessage = "PASS\r\n";
        The task privilege level is set down to user mode within this function. */\r
        prvTestMemoryRegions();\r
 \r
-       /* Tests are done so lower the privilege status. */\r
-       portSWITCH_TO_USER_MODE();\r
+       /* Clear overlaid reg test counters before entering the loop below. */\r
+       *pulOverlaidCounter3 = 0UL;\r
+       *pulOverlaidCounter4 = 0UL;\r
 \r
        /* This loop performs the main function of the task, which is blocking\r
        on a message queue then processing each message as it arrives. */\r
@@ -390,40 +540,61 @@ const char *pcStatusMessage = "PASS\r\n";
 \r
                switch( lMessage )\r
                {\r
-                       case mainREG_TEST_1_STILL_EXECUTING     :\r
-                                       /* Message from task 1, so task 1 must still be executing. */\r
-                                       ( ulStillAliveCounts[ 0 ] )++;\r
+                       case configREG_TEST_1_STILL_EXECUTING   :\r
+                       case configREG_TEST_2_STILL_EXECUTING   :\r
+                       case configTIMER_STILL_EXECUTING                :\r
+                                       /* Message from the first or second register check task, or\r
+                                       the timer callback function.  Increment the count of the\r
+                                       number of times the message source has sent the message as\r
+                                       the message source must still be executed. */\r
+                                       ( ulStillAliveCounts[ lMessage ] )++;\r
                                        break;\r
 \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 configPRINT_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
+                                       status.  If messages have stopped arriving from either of\r
+                                       the first two reg test task or the timer callback then the\r
+                                       status must be set to fail. */\r
+                                       if( ( ulStillAliveCounts[ 0 ] == 0 ) || ( ulStillAliveCounts[ 1 ] == 0 ) || ( ulStillAliveCounts[ 2 ] == 0 ) )\r
                                        {\r
                                                /* One or both of the test tasks are no longer sending\r
                                                'still alive' messages. */\r
                                                pcStatusMessage = "FAIL\r\n";\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               /* Reset the count of 'still alive' messages. */\r
+                                               memset( ( void * ) ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) );\r
+                                       }\r
 \r
-                                       /* Print a pass/fail message to the terminal.  This will be\r
-                                       visible in the CrossWorks IDE. */\r
-//                                     MPU_debug_printf( pcStatusMessage );\r
-( void ) pcStatusMessage;\r
+                                       /* Check that the register test 3 task is still incrementing\r
+                                       its counter, and therefore still running. */\r
+                                       if( ulLastRegTest3CountValue == *pulOverlaidCounter3 )\r
+                                       {\r
+                                               pcStatusMessage = "FAIL\r\n";\r
+                                       }\r
+                                       ulLastRegTest3CountValue = *pulOverlaidCounter3;\r
 \r
-                                       /* Reset the count of 'still alive' messages. */\r
-                                       memset( ulStillAliveCounts, 0x00, sizeof( ulStillAliveCounts ) );\r
+                                       /* Check that the register test 4 task is still incrementing\r
+                                       its counter, and therefore still running. */\r
+                                       if( ulLastRegTest4Value == *pulOverlaidCounter4 )\r
+                                       {\r
+                                               pcStatusMessage = "FAIL\r\n";\r
+                                       }\r
+                                       ulLastRegTest4Value = *pulOverlaidCounter4;\r
+\r
+                                       /**** Print pcStatusMessage here. ****/\r
+                                       ( void ) pcStatusMessage;\r
+                                       \r
+                                       /* The cycle count can be viewed updating in the Keil watch\r
+                                       window if ITM printf is not being used. */\r
+                                       ulCycleCount++;\r
                                        break;\r
 \r
                default :\r
                                        /* Something unexpected happened.  Delete this task so the\r
                                        error is apparent (no output will be displayed). */\r
-                                       prvDeleteMe();\r
+                                       vMainDeleteMe();\r
                                        break;\r
                }\r
        }\r
@@ -432,7 +603,7 @@ const char *pcStatusMessage = "PASS\r\n";
 \r
 static void prvTestMemoryRegions( void )\r
 {\r
-long l;\r
+int32_t x;\r
 char cTemp;\r
 \r
        /* The check task (from which this function is called) is created in the\r
@@ -443,7 +614,7 @@ char cTemp;
        {\r
                /* Something unexpected happened.  Delete this task so the error is\r
                apparent (no output will be displayed). */\r
-               prvDeleteMe();\r
+               vMainDeleteMe();\r
        }\r
 \r
        /* Writing off the end of the RAM allocated to this task will *NOT* cause a\r
@@ -459,14 +630,14 @@ char cTemp;
        /*cPrivilegedOnlyAccessArray[ 0 ] = 'a';*/\r
 \r
        /* The read/write array can still be successfully read and written. */\r
-       for( l = 0; l < mainREAD_WRITE_ALIGN_SIZE; l++ )\r
+       for( x = 0; x < mainREAD_WRITE_ALIGN_SIZE; x++ )\r
        {\r
-               cReadWriteArray[ l ] = 'a';\r
-               if( cReadWriteArray[ l ] != 'a' )\r
+               cReadWriteArray[ x ] = 'a';\r
+               if( cReadWriteArray[ x ] != 'a' )\r
                {\r
                        /* Something unexpected happened.  Delete this task so the error is\r
                        apparent (no output will be displayed). */\r
-                       prvDeleteMe();\r
+                       vMainDeleteMe();\r
                }\r
        }\r
 \r
@@ -477,9 +648,9 @@ char cTemp;
        /* cReadWriteArray[ mainREAD_WRITE_ALIGN_SIZE ] = 0x00; */\r
 \r
        /* The read only array can be successfully read... */\r
-       for( l = 0; l < mainREAD_ONLY_ALIGN_SIZE; l++ )\r
+       for( x = 0; x < mainREAD_ONLY_ALIGN_SIZE; x++ )\r
        {\r
-               cTemp = cReadOnlyArray[ l ];\r
+               cTemp = cReadOnlyArray[ x ];\r
        }\r
 \r
        /* ...but cannot be written.  Uncomment the following line to test. */\r
@@ -501,159 +672,143 @@ char cTemp;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvRegTest1Task( void *pvParameters )\r
+static void prvExerciseEventGroupAPI( void )\r
 {\r
-/* This task is created in privileged mode so can access the file scope\r
-queue variable.  Take a stack copy of this before the task is set into user\r
-mode.  Once this task is in user mode the file scope queue variable will no\r
-longer be accessible but the stack copy will. */\r
-QueueHandle_t xQueue = xFileScopeCheckQueue;\r
-\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
-       /* First check that the parameter value is as expected. */\r
-       if( pvParameters != ( void * ) 0x12345678 )\r
-       {\r
-               /* Error detected.  Delete the task so it stops communicating with\r
-               the check task. */\r
-               prvDeleteMe();\r
-       }\r
+EventGroupHandle_t xEventGroup;\r
+EventBits_t xBits;\r
+const EventBits_t xBitsToWaitFor = ( EventBits_t ) 0xff, xBitToClear = ( EventBits_t ) 0x01;\r
+\r
+       /* Exercise some event group functions. */\r
+       xEventGroup = xEventGroupCreate();\r
+       configASSERT( xEventGroup );\r
+\r
+       /* No bits should be set. */\r
+       xBits = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, mainDONT_BLOCK );\r
+       configASSERT( xBits == ( EventBits_t ) 0 );\r
+\r
+       /* Set bits and read back to ensure the bits were set. */\r
+       xEventGroupSetBits( xEventGroup, xBitsToWaitFor );\r
+       xBits = xEventGroupGetBits( xEventGroup );\r
+       configASSERT( xBits == xBitsToWaitFor );\r
+\r
+       /* Clear a bit and read back again using a different API function. */\r
+       xEventGroupClearBits( xEventGroup, xBitToClear );\r
+       xBits = xEventGroupSync( xEventGroup, 0x00, xBitsToWaitFor, mainDONT_BLOCK );\r
+       configASSERT( xBits == ( xBitsToWaitFor & ~xBitToClear ) );\r
+\r
+       /* Finished with the event group. */\r
+       vEventGroupDelete( xEventGroup );\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
+static void prvExerciseSemaphoreAPI( void )\r
+{\r
+SemaphoreHandle_t xSemaphore;\r
+const UBaseType_t uxMaxCount = 5, uxInitialCount = 0;\r
+\r
+       /* Most of the semaphore API is common to the queue API and is already being\r
+       used.  This function uses a few semaphore functions that are unique to the\r
+       RTOS objects, rather than generic and used by queues also.\r
+\r
+       First create and use a counting semaphore. */\r
+       xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount );\r
+       configASSERT( xSemaphore );\r
+\r
+       /* Give the semaphore a couple of times and ensure the count is returned\r
+       correctly. */\r
+       xSemaphoreGive( xSemaphore );\r
+       xSemaphoreGive( xSemaphore );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 );\r
+       vSemaphoreDelete( xSemaphore );\r
+\r
+       /* Create a recursive mutex, and ensure the mutex holder and count are\r
+       returned returned correctly. */\r
+       xSemaphore = xSemaphoreCreateRecursiveMutex();\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );\r
+       configASSERT( xSemaphore );\r
+       xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );\r
+       xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK );\r
+       configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );\r
+       configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) );\r
+       xSemaphoreGiveRecursive( xSemaphore );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );\r
+       xSemaphoreGiveRecursive( xSemaphore );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );\r
+       configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );\r
+       vSemaphoreDelete( xSemaphore );\r
+\r
+       /* Create a normal mutex, and sure the mutex holder and count are returned\r
+       returned correctly. */\r
+       xSemaphore = xSemaphoreCreateMutex();\r
+       configASSERT( xSemaphore );\r
+       xSemaphoreTake( xSemaphore, mainDONT_BLOCK );\r
+       xSemaphoreTake( xSemaphore, mainDONT_BLOCK );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */\r
+       configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() );\r
+       xSemaphoreGive( xSemaphore );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 );\r
+       configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL );\r
+       vSemaphoreDelete( xSemaphore );\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
-       for( ;; )\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
-                       "               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
-                       "               MOV     R8, #108                        \n"\r
-                       "               MOV     R9, #109                        \n"\r
-                       "               MOV     R10, #110                       \n"\r
-                       "               MOV     R11, #111                       \n"\r
-                       "reg1loop:                                              \n"\r
-                       "               MOV     R0, #100                        \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
-                       "               MOV     R1, #101                        \n"\r
-                       "               MOV     R2, #102                        \n"\r
-                       "               MOV R3, #103                    \n"\r
-                       "               MOV     R12, #112                       \n"\r
-                       "               SVC #1                                  \n" /* Yield just to increase test coverage. */\r
-                       "               CMP     R0, #100                        \n" /* Check all the registers still contain their expected values. */\r
-                       "               BNE     prvDeleteMe                     \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */\r
-                       "               CMP     R1, #101                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R2, #102                        \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     R5, #105                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R6, #106                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R8, #108                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R9, #109                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R10, #110                       \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R11, #111                       \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R12, #112                       \n"\r
-                       "               BNE     prvDeleteMe                     \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
-               task is still functioning. */\r
-               prvSendImAlive( xQueue, mainREG_TEST_1_STILL_EXECUTING );\r
-\r
-               /* Go back to check all the register values again. */\r
-               __asm volatile( "               B reg1loop      " );\r
-       }\r
+static void prvExerciseTaskNotificationAPI( void )\r
+{\r
+uint32_t ulNotificationValue;\r
+BaseType_t xReturned;\r
+\r
+       /* The task should not yet have a notification pending. */\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );\r
+       configASSERT( xReturned == pdFAIL );\r
+       configASSERT( ulNotificationValue == 0UL );\r
+\r
+       /* Exercise the 'give' and 'take' versions of the notification API. */\r
+       xTaskNotifyGive( xTaskGetCurrentTaskHandle() );\r
+       xTaskNotifyGive( xTaskGetCurrentTaskHandle() );\r
+       ulNotificationValue = ulTaskNotifyTake( pdTRUE, mainDONT_BLOCK );\r
+       configASSERT( ulNotificationValue == 2 );\r
+\r
+       /* Exercise the 'notify' and 'clear' API. */\r
+       ulNotificationValue = 20;\r
+       xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );\r
+       ulNotificationValue = 0;\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotificationValue, mainDONT_BLOCK );\r
+       configASSERT( xReturned == pdPASS );\r
+       configASSERT( ulNotificationValue == 20 );\r
+       xTaskNotify( xTaskGetCurrentTaskHandle(), ulNotificationValue, eSetValueWithOverwrite );\r
+       xReturned = xTaskNotifyStateClear( NULL );\r
+       configASSERT( xReturned == pdTRUE ); /* First time a notification was pending. */\r
+       xReturned = xTaskNotifyStateClear( NULL );\r
+       configASSERT( xReturned == pdFALSE ); /* Second time the notification was already clear. */\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvRegTest2Task( void *pvParameters )\r
+static void prvTaskToDelete( 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
-method. */\r
-QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;\r
+       /* Remove compiler warnings about unused parameters. */\r
+       ( void ) pvParameters;\r
 \r
-       for( ;; )\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
-                       "               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
-                       "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
-                       "               MOV     R2, #2                          \n"\r
-                       "               MOV R3, #3                              \n"\r
-                       "               MOV     R12, #12                        \n"\r
-                       "               CMP     R0, #13                         \n" /* Check all the registers still contain their expected values. */\r
-                       "               BNE     prvDeleteMe                     \n" /* Value was not as expected, delete the task so it stops communicating with the check task */\r
-                       "               CMP     R1, #1                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R2, #2                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP R3, #3                              \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R4, #4                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R5, #5                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R6, #6                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R8, #8                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R9, #9                          \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R10, #10                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R11, #11                        \n"\r
-                       "               BNE     prvDeleteMe                     \n"\r
-                       "               CMP     R12, #12                        \n"\r
-                       "               BNE     prvDeleteMe                     \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
-               task is still functioning. */\r
-               prvSendImAlive( xQueue, mainREG_TEST_2_STILL_EXECUTING );\r
-\r
-               /* Go back to check all the register values again. */\r
-               __asm volatile( "               B reg2loop      " );\r
-       }\r
+       /* Check the enter and exit critical macros are working correctly.  If the\r
+       SVC priority is below configMAX_SYSCALL_INTERRUPT_PRIORITY then this will\r
+       fault. */\r
+       taskENTER_CRITICAL();\r
+       taskEXIT_CRITICAL();\r
+\r
+       /* Exercise the API of various RTOS objects. */\r
+       prvExerciseEventGroupAPI();\r
+       prvExerciseSemaphoreAPI();\r
+       prvExerciseTaskNotificationAPI();\r
+\r
+       /* For code coverage test purposes it is deleted by the Idle task. */\r
+       configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 );\r
+       vTaskSuspend( NULL );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 void vApplicationIdleHook( void )\r
 {\r
-extern unsigned long __SRAM_segment_end__[];\r
-extern unsigned long __privileged_data_start__[];\r
-extern unsigned long __privileged_data_end__[];\r
-extern unsigned long __FLASH_segment_start__[];\r
-extern unsigned long __FLASH_segment_end__[];\r
-volatile unsigned long *pul;\r
-volatile unsigned long ulReadData;\r
+volatile const uint32_t *pul;\r
+volatile uint32_t ulReadData;\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
@@ -685,26 +840,28 @@ volatile unsigned long ulReadData;
        /* pul = __SRAM_segment_end__ + 1;\r
        ulReadData = *pul; */\r
 \r
+       /* One task is created purely so it can be deleted - done for code coverage\r
+       test purposes. */\r
+       if( xTaskToDelete != NULL )\r
+       {\r
+               vTaskDelete( xTaskToDelete );\r
+               xTaskToDelete = NULL;\r
+       }\r
+\r
        ( void ) ulReadData;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 static void prvOldStyleUserModeTask( void *pvParameters )\r
 {\r
-extern unsigned long __privileged_data_start__[];\r
-extern unsigned long __privileged_data_end__[];\r
-extern unsigned long __SRAM_segment_end__[];\r
-extern unsigned long __privileged_functions_end__[];\r
-extern unsigned long __FLASH_segment_start__[];\r
-extern unsigned long __FLASH_segment_end__[];\r
-//const volatile unsigned long *pulStandardPeripheralRegister = ( volatile unsigned long * ) 0x400FC0C4;\r
-volatile unsigned long *pul;\r
-volatile unsigned long ulReadData;\r
+/*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/\r
+volatile const uint32_t *pul;\r
+volatile uint32_t ulReadData;\r
 \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
+compiler warnings when the tests that use the variable are also commented out. */\r
+/* extern uint32_t __privileged_functions_start__[]; */\r
+/* const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014; */\r
 \r
        ( void ) pvParameters;\r
 \r
@@ -727,29 +884,29 @@ const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned
        ulReadData = *pul;\r
 \r
        /* Standard peripherals are accessible. */\r
-//     ulReadData = *pulStandardPeripheralRegister;\r
+       /*ulReadData = *pulStandardPeripheralRegister;*/\r
 \r
        /* System peripherals are not accessible.  Uncomment the following line\r
        to test.  Also uncomment the declaration of pulSystemPeripheralRegister\r
-       at the top of this function. */\r
-       /* ulReadData = *pulSystemPeripheralRegister; */\r
+       at the top of this function.\r
+       ulReadData = *pulSystemPeripheralRegister; */\r
 \r
        /* Reading from anywhere inside the privileged Flash or RAM should cause a\r
        fault.  This can be tested by uncommenting any of the following pairs of\r
        lines.  Also uncomment the declaration of __privileged_functions_start__\r
        at the top of this function. */\r
 \r
-       /* pul = __privileged_functions_start__;\r
-       ulReadData = *pul; */\r
+       /*pul = __privileged_functions_start__;\r
+       ulReadData = *pul;*/\r
 \r
-       /* pul = __privileged_functions_end__ - 1;\r
-       ulReadData = *pul; */\r
+       /*pul = __privileged_functions_end__ - 1;\r
+       ulReadData = *pul;*/\r
 \r
-       /* pul = __privileged_data_start__;\r
-       ulReadData = *pul; */\r
+       /*pul = __privileged_data_start__;\r
+       ulReadData = *pul;*/\r
 \r
-       /* pul = __privileged_data_end__ - 1;\r
-       ulReadData = *pul; */\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
        Note that because this task was created using xTaskCreate() the stack was\r
@@ -762,17 +919,10 @@ const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned
 \r
 static void prvOldStylePrivilegedModeTask( void *pvParameters )\r
 {\r
-extern unsigned long __privileged_data_start__[];\r
-extern unsigned long __privileged_data_end__[];\r
-extern unsigned long __SRAM_segment_end__[];\r
-extern unsigned long __privileged_functions_start__[];\r
-extern unsigned long __privileged_functions_end__[];\r
-extern unsigned long __FLASH_segment_start__[];\r
-extern unsigned long __FLASH_segment_end__[];\r
-volatile unsigned long *pul;\r
-volatile unsigned long ulReadData;\r
-const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned long * ) 0xe000e014; /* Systick */\r
-//const volatile unsigned long *pulStandardPeripheralRegister = ( volatile unsigned long * ) 0x400FC0C4;\r
+volatile const uint32_t *pul;\r
+volatile uint32_t ulReadData;\r
+const volatile uint32_t *pulSystemPeripheralRegister = ( volatile uint32_t * ) 0xe000e014; /* Systick */\r
+/*const volatile uint32_t *pulStandardPeripheralRegister = ( volatile uint32_t * ) 0x40000000;*/\r
 \r
        ( void ) pvParameters;\r
 \r
@@ -808,7 +958,7 @@ const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned
        /* Finally, accessing both System and normal peripherals should both be\r
        possible. */\r
        ulReadData = *pulSystemPeripheralRegister;\r
-//     ulReadData = *pulStandardPeripheralRegister;\r
+       /*ulReadData = *pulStandardPeripheralRegister;*/\r
 \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
@@ -819,13 +969,13 @@ const volatile unsigned long *pulSystemPeripheralRegister = ( volatile unsigned
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvDeleteMe( void )\r
+void vMainDeleteMe( void )\r
 {\r
        vTaskDelete( NULL );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvSendImAlive( QueueHandle_t xHandle, unsigned long ulTaskNumber )\r
+void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber )\r
 {\r
        if( xHandle != NULL )\r
        {\r
@@ -841,9 +991,9 @@ static void prvSetupHardware( void )
 \r
 void vApplicationTickHook( void )\r
 {\r
-static unsigned long ulCallCount;\r
-const unsigned long ulCallsBetweenSends = 5000 / portTICK_PERIOD_MS;\r
-const unsigned long ulMessage = mainPRINT_SYSTEM_STATUS;\r
+static uint32_t ulCallCount = 0;\r
+const uint32_t ulCallsBetweenSends = pdMS_TO_TICKS( 1000 );\r
+const uint32_t ulMessage = configPRINT_SYSTEM_STATUS;\r
 portBASE_TYPE xDummy;\r
 \r
        /* If configUSE_TICK_HOOK is set to 1 then this function will get called\r
@@ -862,8 +1012,8 @@ portBASE_TYPE xDummy;
 \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
-               xQueueSendFromISR( xFileScopeCheckQueue, &ulMessage, &xDummy );\r
+               so can access xGlobalScopeCheckQueue directly. */\r
+               xQueueSendFromISR( xGlobalScopeCheckQueue, &ulMessage, &xDummy );\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -887,75 +1037,106 @@ void vApplicationMallocFailedHook( void )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void hard_fault_handler(unsigned int * hardfault_args)\r
+static void prvTimerCallback( TaskHandle_t xExpiredTimer )\r
 {\r
-volatile unsigned int stacked_r0;\r
-volatile unsigned int stacked_r1;\r
-volatile unsigned int stacked_r2;\r
-volatile unsigned int stacked_r3;\r
-volatile unsigned int stacked_r12;\r
-volatile unsigned int stacked_lr;\r
-volatile unsigned int stacked_pc;\r
-volatile unsigned int stacked_psr;\r
-\r
-       stacked_r0 = ((unsigned long) hardfault_args[0]);\r
-       stacked_r1 = ((unsigned long) hardfault_args[1]);\r
-       stacked_r2 = ((unsigned long) hardfault_args[2]);\r
-       stacked_r3 = ((unsigned long) hardfault_args[3]);\r
-\r
-       stacked_r12 = ((unsigned long) hardfault_args[4]);\r
-       stacked_lr = ((unsigned long) hardfault_args[5]);\r
-       stacked_pc = ((unsigned long) hardfault_args[6]);\r
-       stacked_psr = ((unsigned long) hardfault_args[7]);\r
-\r
-       /* Inspect stacked_pc to locate the offending instruction. */\r
-       for( ;; );\r
+uint32_t ulCount;\r
+\r
+       /* The count of the number of times this timer has expired is saved in the\r
+       timer's ID.  Obtain the current count. */\r
+       ulCount = ( uint32_t ) pvTimerGetTimerID( xTimer );\r
+\r
+       /* Increment the count, and save it back into the timer's ID. */\r
+       ulCount++;\r
+       vTimerSetTimerID( xTimer, ( void * ) ulCount );\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
+       /* Let the check task know the timer is still running. */\r
+       vMainSendImAlive( xGlobalScopeCheckQueue, configTIMER_STILL_EXECUTING );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void HardFault_Handler( void ) __attribute__((naked));\r
-void HardFault_Handler( void )\r
+/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
+implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
+used by the Idle task. */\r
+void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
 {\r
-       __asm volatile\r
-       (\r
-               " tst lr, #4                                                                            \n"\r
-               " ite eq                                                                                        \n"\r
-               " mrseq r0, msp                                                                         \n"\r
-               " mrsne r0, psp                                                                         \n"\r
-               " ldr r1, [r0, #24]                                                                     \n"\r
-               " ldr r2, handler_address_const                                         \n"\r
-               " bx r2                                                                                         \n"\r
-               " handler_address_const: .word hard_fault_handler       \n"\r
-       );\r
+/* If the buffers to be provided to the Idle task are declared inside this\r
+function then they must be declared static - otherwise they will be allocated on\r
+the stack and so not exists after this function exits. */\r
+static StaticTask_t xIdleTaskTCB;\r
+static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
+\r
+       /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
+       state will be stored. */\r
+       *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
+\r
+       /* Pass out the array that will be used as the Idle task's stack. */\r
+       *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
+\r
+       /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
+       Note that, as the array is necessarily of type StackType_t,\r
+       configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
+       *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void MPU_Fault_ISR( void ) __attribute__((naked));\r
-void MemManage_Handler( void )\r
+/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
+application must provide an implementation of vApplicationGetTimerTaskMemory()\r
+to provide the memory that is used by the Timer service task. */\r
+void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
 {\r
-       __asm volatile\r
-       (\r
-               " tst lr, #4                                                                            \n"\r
-               " ite eq                                                                                        \n"\r
-               " mrseq r0, msp                                                                         \n"\r
-               " mrsne r0, psp                                                                         \n"\r
-               " ldr r1, [r0, #24]                                                                     \n"\r
-               " ldr r2, handler2_address_const                                        \n"\r
-               " bx r2                                                                                         \n"\r
-               " handler2_address_const: .word hard_fault_handler      \n"\r
-       );\r
+/* If the buffers to be provided to the Timer task are declared inside this\r
+function then they must be declared static - otherwise they will be allocated on\r
+the stack and so not exists after this function exits. */\r
+static StaticTask_t xTimerTaskTCB;\r
+static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
+\r
+       /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
+       task's state will be stored. */\r
+       *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
+\r
+       /* Pass out the array that will be used as the Timer task's stack. */\r
+       *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
+\r
+       /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
+       Note that, as the array is necessarily of type StackType_t,\r
+       configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
+       *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
 }\r
+/*-----------------------------------------------------------*/\r
 \r
+static void prvRegTest3Task( void *pvParameters )\r
+{\r
+       /* Although the regtest task is written in assembler, its entry point is\r
+       written in C for convenience of checking the task parameter is being passed\r
+       in correctly. */\r
+       if( pvParameters == configREG_TEST_TASK_3_PARAMETER )\r
+       {\r
+               /* Start the part of the test that is written in assembler. */\r
+               vRegTest3Implementation();\r
+       }\r
+\r
+       /* The following line will only execute if the task parameter is found to\r
+       be incorrect.  The check task will detect that the regtest loop counter is\r
+       not being incremented and flag an error. */\r
+       vTaskDelete( NULL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvRegTest4Task( void *pvParameters )\r
+{\r
+       /* Although the regtest task is written in assembler, its entry point is\r
+       written in C for convenience of checking the task parameter is being passed\r
+       in correctly. */\r
+       if( pvParameters == configREG_TEST_TASK_4_PARAMETER )\r
+       {\r
+               /* Start the part of the test that is written in assembler. */\r
+               vRegTest4Implementation();\r
+       }\r
+\r
+       /* The following line will only execute if the task parameter is found to\r
+       be incorrect.  The check task will detect that the regtest loop counter is\r
+       not being incremented and flag an error. */\r
+       vTaskDelete( NULL );\r
+}\r
 /*-----------------------------------------------------------*/\r
 \r
-#warning Why must configSUPPORT_STATIC_ALLOCATION be set to 1 when the MPU is used?\r
-#warning Linker script is crippled for use with the simulator.
\ No newline at end of file