]> git.sur5r.net Git - freertos/blobdiff - Demo/CORTEX_Kinetis_K60_Tower_IAR/main-full.c
Move the MSVC/lwIP code into the main line.
[freertos] / Demo / CORTEX_Kinetis_K60_Tower_IAR / main-full.c
index eea1b4c4c62f51db783a0a547aa532c2c892fe5c..5d1c609c2a99351ee8f7e16bdf9ba3279d8c0137 100644 (file)
  *\r
  * main-full.c (this file) defines a comprehensive demo that creates many\r
  * tasks, queues, semaphores and timers.  It also demonstrates how Cortex-M3\r
- * interrupts can interact with FreeRTOS tasks/timers.\r
+ * interrupts can interact with FreeRTOS tasks/timers, a simple web server, and\r
+ * run time statistics gathering functionality.  ***IF YOU ARE LOOKING FOR A \r
+ * SIMPLER STARTING POINT THEN USE THE "BLINKY" BUILD CONFIGURATION FIRST.***\r
  *\r
- * This project runs on the SK-FM3-100PMC evaluation board, which is populated\r
- * with an MB9BF5006N Cortex-M3 based microcontroller.\r
+ * If the Ethernet functionality is excluded, then this demo will run 'stand \r
+ * alone' (without the rest of the tower system) on the TWR-K60N512 tower \r
+ * module.  If the Ethernet functionality is included, then the full Freescale\r
+ * K60 tower kit, including both the TWR-K60N512 and TWR-SER modules, is \r
+ * required (as the Ethernet connector is on the TWR-SER).  The TWR-K60N512 is \r
+ * populated with a K60N512 Cortex-M4 microcontroller.\r
  *\r
  * The main() Function:\r
- * main() creates three demo specific software timers, one demo specific queue,\r
- * and two demo specific tasks.  It then creates a whole host of 'standard\r
- * demo' tasks/queues/semaphores, before starting the scheduler.  The demo\r
- * specific tasks and timers are described in the comments here.  The standard\r
- * demo tasks are described on the FreeRTOS.org web site.\r
+ * main() creates four demo specific software timers, and one demo specific\r
+ * task (the web server task).  It also creates a whole host of 'standard\r
+ * demo' tasks/queues/semaphores/timers, before starting the scheduler.  The \r
+ * demo specific tasks and timers are described in the comments here.  The \r
+ * standard demo tasks are described on the FreeRTOS.org web site.\r
  *\r
  * The standard demo tasks provide no specific functionality.  They are\r
  * included to both test the FreeRTOS port, and provide examples of how the\r
  * various FreeRTOS API functions can be used.\r
  *\r
- * This demo creates 43 tasks in total.  If you want a simpler demo, use the\r
- * Blinky build configuration.\r
+ * This demo creates 37 persistent tasks, then dynamically creates and destroys\r
+ * another two tasks as the demo executes.\r
  *\r
- * The Demo Specific LED Software Timer and the Button Interrupt:\r
+ *\r
+ * The Demo Specific "LED" Timers and Callback Function:\r
+ * Two very simple LED timers are created.  All they do is toggle an LED each\r
+ * when the timer callback function is executed.  The two timers share a \r
+ * callback function, so the callback function parameter is used to determine \r
+ * which timer actually expired, and therefore, which LED to toggle.  Both \r
+ * timers use a different frequency, one toggles the blue LED and the other the \r
+ * green LED.\r
+ *\r
+ * The LED/Button Software Timer and the Button Interrupt:\r
  * The user button SW2 is configured to generate an interrupt each time it is\r
- * pressed.  The interrupt service routine switches an LED on, and resets the\r
- * LED software timer.  The LED timer has a 5000 millisecond (5 second) period,\r
- * and uses a callback function that is defined to just turn the LED off again.\r
- * Therefore, pressing the user button will turn the LED on, and the LED will\r
- * remain on until a full five seconds pass without the button being pressed.\r
- * See the documentation page for this demo on the FreeRTOS.org web site to see\r
- * which LED is used.\r
+ * pressed.  The interrupt service routine switches the orange/yellow LED on, \r
+ * and resets the LED software timer.  The LED timer has a 5000 millisecond (5 \r
+ * second) period, and uses a callback function that is defined to just turn the \r
+ * LED off again.  Therefore, pressing the user button will turn the LED on, and \r
+ * the LED will remain on until a full five seconds pass without the button \r
+ * being pressed.\r
+ *\r
+ * The Demo Specific "Check" Timer and Callback Function:\r
+ * The check timer period is initially set to three seconds.  The check timer \r
+ * callback function checks that all the standard demo tasks are not only still \r
+ * executing, but are executing without reporting any errors.  If the check \r
+ * timer discovers that a task has either stalled, or reported an error, then it \r
+ * changes its own period from the initial three seconds, to just 200ms.  The \r
+ * check timer callback function also toggles the orange/red LED each time it is \r
+ * called.  This provides a visual indication of the system status:  If the LED \r
+ * toggles every three seconds, then no issues have been discovered.  If the LED \r
+ * toggles every 200ms, then an issue has been discovered with at least one \r
+ * task.  The last reported issue is latched into the pcStatusMessage variable, \r
+ * and displayed at the bottom of the "task stats" web page served by the \r
+ * embedded web server task.\r
  *\r
- * The Demo Specific "Check" Callback Function:\r
- * This is called each time the 'check' timer expires.  The check timer\r
- * callback function inspects all the standard demo tasks to see if they are\r
- * all executing as expected.  The check timer is initially configured to\r
- * expire every three seconds, but will shorted this to every 500ms if an error\r
- * is ever discovered.  The check timer callback toggles the LED defined by\r
- * the mainCHECK_LED definition each time it executes.  Therefore, if LED\r
- * mainCHECK_LED is toggling every three seconds, then no error have been found.\r
- * If LED mainCHECK_LED is toggling every 500ms, then at least one errors has\r
- * been found.  The variable pcStatusMessage is set to a string that indicates\r
- * which task reported an error.  See the documentation page for this demo on\r
- * the FreeRTOS.org web site to see which LED in the 7 segment display is used.\r
+ * The web server task:\r
+ * The web server task implements a simple embedded web server that includes\r
+ * CGI scripting.  Pages are provided that allow task statistics, network\r
+ * statistics and run time statistics to be viewed.  In addition, an IO page is\r
+ * served that allows the orange/yellow LED to be turned on and off.  Finally,\r
+ * a page is included that serves a large jpg file.  See the documentation page\r
+ * for this demo on the http://www.FreeRTOS.org web site for web server\r
+ * configuration and usage instructions.\r
  *\r
  * The Demo Specific Idle Hook Function:\r
  * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
  * The Demo Specific Tick Hook Function:\r
  * The tick hook function is used to test the interrupt safe software timer\r
  * functionality.\r
+ * \r
  */\r
 \r
 /* Kernel includes. */\r
 #include "QPeek.h"\r
 #include "recmutex.h"\r
 #include "TimerDemo.h"\r
-#include "comtest2.h"\r
 #include "PollQ.h"\r
 #include "countsem.h"\r
 #include "dynamic.h"\r
 \r
-/* The rate at which data is sent to the queue, specified in milliseconds, and\r
-converted to ticks using the portTICK_RATE_MS constant. */\r
-#define mainQUEUE_SEND_FREQUENCY_MS    ( 200 / portTICK_RATE_MS )\r
-\r
-/* The number of items the queue can hold.  This is 1 as the receive task\r
-will remove items as they are added, meaning the send task should always find\r
-the queue empty. */\r
-#define mainQUEUE_LENGTH                       ( 1 )\r
-\r
 /* The LED toggled by the check timer callback function.  */\r
 #define mainCHECK_LED                          3UL\r
 \r
@@ -158,27 +173,20 @@ the queue empty. */
 #define mainLED0                                       0UL\r
 #define mainLED1                                       1UL\r
 \r
-/* The LED used by the comtest tasks. See the comtest.c file for more\r
-information.  In this case, the LED is deliberatly out of the valid range as\r
-all the available LEDs are already used by other tasks and timers. */\r
-#define mainCOM_TEST_LED                       ( 4 )\r
-\r
 /* Constant used by the standard timer test functions. */\r
 #define mainTIMER_TEST_PERIOD          ( 50 )\r
 \r
 /* Priorities used by the various different standard demo tasks. */\r
-#define mainCHECK_TASK_PRIORITY                ( configMAX_PRIORITIES - 1 )\r
 #define mainQUEUE_POLL_PRIORITY                ( tskIDLE_PRIORITY + 1 )\r
 #define mainSEM_TEST_PRIORITY          ( tskIDLE_PRIORITY + 1 )\r
 #define mainBLOCK_Q_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
-#define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
 #define mainGEN_QUEUE_TASK_PRIORITY    ( tskIDLE_PRIORITY )\r
-#define mainCOM_TEST_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
+#define mainuIP_TASK_PRIORITY          ( tskIDLE_PRIORITY + 2 )\r
 \r
-/* Priorities defined in this main-full.c file. */\r
-#define mainQUEUE_RECEIVE_TASK_PRIORITY                ( tskIDLE_PRIORITY + 2 )\r
-#define        mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
+/* The WEB server uses string handling functions, which in turn use a bit more\r
+stack than most of the other tasks. */\r
+#define mainuIP_STACK_SIZE                     ( configMINIMAL_STACK_SIZE * 3 )\r
 \r
 /* The period at which the check timer will expire, in ms, provided no errors\r
 have been reported by any of the standard demo tasks.  ms are converted to the\r
@@ -188,26 +196,23 @@ equivalent in ticks using the portTICK_RATE_MS constant. */
 /* The period at which the check timer will expire, in ms, if an error has been\r
 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
 in ticks using the portTICK_RATE_MS constant. */\r
-#define mainERROR_CHECK_TIMER_PERIOD_MS        ( 500UL / portTICK_RATE_MS )\r
+#define mainERROR_CHECK_TIMER_PERIOD_MS        ( 200UL / portTICK_RATE_MS )\r
 \r
-/* The LED will remain on until the button has not been pushed for a full\r
-5000ms. */\r
+/* The LED that is turned on by pressing SW2 remains on until the button has not \r
+been pushed for a full 5000ms. */\r
 #define mainBUTTON_LED_TIMER_PERIOD_MS         ( 5000UL / portTICK_RATE_MS )\r
 \r
 /* The period at which the two simple LED flash timers will execute their\r
 callback functions. */\r
-#define mainLED1_TIMER_PERIOD_MS                       ( 200 / portTICK_RATE_MS )\r
-#define mainLED2_TIMER_PERIOD_MS                       ( 600 / portTICK_RATE_MS )\r
+#define mainLED1_TIMER_PERIOD_MS                       ( 200UL / portTICK_RATE_MS )\r
+#define mainLED2_TIMER_PERIOD_MS                       ( 600UL / portTICK_RATE_MS )\r
 \r
 /* A block time of zero simply means "don't block". */\r
 #define mainDONT_BLOCK                                         ( 0UL )\r
 \r
-/* Baud rate used by the comtest tasks. */\r
-#define mainCOM_TEST_BAUD_RATE                         ( 115200UL )\r
-\r
 /* The vector used by the GPIO port E.  Button SW2 is configured to generate\r
-an interrput on this port. */\r
-#define mainGPIO_E_VECTOR                                      ( 107 - 16 )\r
+an interrupt on this port. */\r
+#define mainGPIO_E_VECTOR                                      ( 91 )\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
@@ -223,14 +228,15 @@ static void prvSetupHardware( void );
 static void prvCreateDemoSpecificTimers( void );\r
 \r
 /*\r
- * The LED timer callback function.  This does nothing but switch an LED off.\r
+ * The LED/button timer callback function.  This does nothing but switch an LED \r
+ * off.\r
  */\r
 static void prvButtonLEDTimerCallback( xTimerHandle xTimer );\r
 \r
 /*\r
  * The callback function used by both simple LED flash timers.  Both timers use\r
  * the same callback, so the function parameter is used to determine which LED\r
- * should be flashed (effectively to determine which timer has expired.\r
+ * should be flashed (effectively to determine which timer has expired).\r
  */\r
 static void prvLEDTimerCallback( xTimerHandle xTimer );\r
 \r
@@ -240,25 +246,22 @@ static void prvLEDTimerCallback( xTimerHandle xTimer );
 static void prvCheckTimerCallback( xTimerHandle xTimer );\r
 \r
 /*\r
- * This is not a 'standard' partest function, so the prototype is not in\r
- * partest.h, and is instead included here.\r
+ * Contains the implementation of the web server.\r
  */\r
-void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue );\r
+extern void vuIP_Task( void *pvParameters );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* The queue used by both application specific demo tasks defined in this file. */\r
-static xQueueHandle xQueue = NULL;\r
-\r
-/* The LED software timer.  This uses prvButtonLEDTimerCallback() as it's callback\r
-function. */\r
-static xTimerHandle xLEDTimer = NULL;\r
+/* The LED/Button software timer.  This uses prvButtonLEDTimerCallback() as it's \r
+callback function. */\r
+static xTimerHandle xLEDButtonTimer = NULL;\r
 \r
 /* The check timer.  This uses prvCheckTimerCallback() as its callback\r
 function. */\r
 static xTimerHandle xCheckTimer = NULL;\r
 \r
-/* LED timers - these simply flash LEDs, each using a different frequency. */\r
+/* LED timers - these simply flash LEDs, each using a different frequency.  Both\r
+use the same prvLEDTimerCallback() callback function. */\r
 static xTimerHandle xLED1Timer = NULL, xLED2Timer = NULL;\r
 \r
 /* If an error is detected in a standard demo task, then pcStatusMessage will\r
@@ -266,6 +269,9 @@ be set to point to a string that identifies the offending task.  This is just
 to make debugging easier. */\r
 static const char *pcStatusMessage = NULL;\r
 \r
+/* Used in the run time stats calculations. */\r
+static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 void main( void )\r
@@ -273,39 +279,35 @@ void main( void )
        /* Configure the NVIC, LED outputs and button inputs. */\r
        prvSetupHardware();\r
 \r
-       /* Create the queue. */\r
-       xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
+       /* Create the timers that are specific to this demo - other timers are\r
+       created as part of the standard demo within vStartTimerDemoTask. */\r
+       prvCreateDemoSpecificTimers();\r
+\r
+       /* Create a lot of 'standard demo' tasks.  Nearly 40 tasks are created in\r
+       this demo.  For a much simpler demo, select the 'blinky' build\r
+       configuration. */\r
+       vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
+       vCreateBlockTimeTasks();\r
+       vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+       vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
+       vStartQueuePeekTasks();\r
+       vStartRecursiveMutexTasks();\r
+       vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
+       vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+       vStartCountingSemaphoreTasks();\r
+       vStartDynamicPriorityTasks();\r
+       \r
+       /* The web server task. */\r
+       xTaskCreate( vuIP_Task, "uIP", mainuIP_STACK_SIZE, NULL, mainuIP_TASK_PRIORITY, NULL );\r
 \r
-       if( xQueue != NULL )\r
-       {\r
-               /* Create the timers that are specific to this demo - other timers are\r
-               created as part of the standard demo within vStartTimerDemoTask. */\r
-               prvCreateDemoSpecificTimers();\r
-\r
-               /* Create a lot of 'standard demo' tasks.  Over 40 tasks are created in\r
-               this demo.  For a much simpler demo, select the 'blinky' build\r
-               configuration. */\r
-               vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
-               vCreateBlockTimeTasks();\r
-               vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
-               vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
-               vStartQueuePeekTasks();\r
-               vStartRecursiveMutexTasks();\r
-               vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
-//_RB_         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
-               vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
-               vStartCountingSemaphoreTasks();\r
-               vStartDynamicPriorityTasks();\r
-               \r
-               /* The suicide tasks must be created last, as they need to know how many\r
-               tasks were running prior to their creation in order to ascertain whether\r
-               or not the correct/expected number of tasks are running at any given\r
-               time. */\r
-               vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
-\r
-               /* Start the tasks and timer running. */\r
-               vTaskStartScheduler();\r
-       }\r
+       /* The suicide tasks must be created last, as they need to know how many\r
+       tasks were running prior to their creation in order to ascertain whether\r
+       or not the correct/expected number of tasks are running at any given\r
+       time. */\r
+       vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
+\r
+       /* Start the tasks and timers running. */\r
+       vTaskStartScheduler();\r
 \r
        /* If all is well, the scheduler will now be running, and the following line\r
        will never be reached.  If the following line does execute, then there was\r
@@ -321,7 +323,9 @@ static void prvCheckTimerCallback( xTimerHandle xTimer )
 static long lChangedTimerPeriodAlready = pdFALSE;\r
 \r
        /* Check the standard demo tasks are running without error.   Latch the\r
-       latest reported error in the pcStatusMessage character pointer. */\r
+       latest reported error in the pcStatusMessage character pointer.  The latched\r
+       string can be viewed using the embedded web server - it is displayed at\r
+       the bottom of the served "task stats" page. */\r
        if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
        {\r
                pcStatusMessage = "Error: GenQueue";\r
@@ -357,11 +361,6 @@ static long lChangedTimerPeriodAlready = pdFALSE;
                pcStatusMessage = "Error: RecMutex\n";\r
        }\r
 \r
-if( 0 )//_RB_  if( xAreComTestTasksStillRunning() != pdPASS )\r
-       {\r
-               pcStatusMessage = "Error: ComTest\n";\r
-       }\r
-       \r
        if( xAreTimerDemoTasksStillRunning( ( mainCHECK_TIMER_PERIOD_MS ) ) != pdTRUE )\r
        {\r
                pcStatusMessage = "Error: TimerDemo\n";\r
@@ -398,9 +397,9 @@ if( 0 )//_RB_       if( xAreComTestTasksStillRunning() != pdPASS )
                        lChangedTimerPeriodAlready = pdTRUE;\r
                        printf( "%s", pcStatusMessage );\r
                        \r
-                       /* This call to xTimerChangePeriod() uses a zero block time.  Functions\r
-                       called from inside of a timer callback function must *never* attempt\r
-                       to block. */\r
+                       /* This call to xTimerChangePeriod() uses a zero block time.  \r
+                       Functions called from inside of a timer callback function must \r
+                       *never* attempt to block. */\r
                        xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
                }\r
        }\r
@@ -435,15 +434,14 @@ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
        /* The button was pushed, so ensure the LED is on before resetting the\r
        LED timer.  The LED timer will turn the LED off if the button is not\r
        pushed within 5000ms. */\r
-       vParTestToggleLED( mainTIMER_CONTROLLED_LED );\r
+       vParTestSetLED( mainTIMER_CONTROLLED_LED, pdTRUE );\r
 \r
        /* This interrupt safe FreeRTOS function can be called from this interrupt\r
-       because the interrupt priority is below the\r
-       configMAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
-       xTimerResetFromISR( xLEDTimer, &xHigherPriorityTaskWoken );\r
+       because the interrupt priority is equal to or below the\r
+       configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY setting in FreeRTOSConfig.h. */\r
+       xTimerResetFromISR( xLEDButtonTimer, &xHigherPriorityTaskWoken );\r
 \r
-       /* Clear the interrupt before leaving.  This just clears all the interrupts\r
-       for simplicity, as only one is actually used in this simple demo anyway. */\r
+       /* Clear the interrupt before leaving.  */\r
        PORTE_ISFR = 0xFFFFFFFFUL;\r
 \r
        /* If calling xTimerResetFromISR() caused a task (in this case the timer\r
@@ -462,6 +460,10 @@ static void prvSetupHardware( void )
        PORTE_PCR26 = PORT_PCR_MUX( 1 ) | PORT_PCR_IRQC( 0xA ) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;\r
        enable_irq( mainGPIO_E_VECTOR );\r
        \r
+       /* The interrupt calls an interrupt safe API function - so its priority must\r
+       be equal to or lower than configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY. */\r
+       set_irq_priority( mainGPIO_E_VECTOR, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );\r
+       \r
        /* Configure the LED outputs. */\r
        vParTestInitialise();\r
 }\r
@@ -470,18 +472,18 @@ static void prvSetupHardware( void )
 static void prvCreateDemoSpecificTimers( void )\r
 {\r
        /* This function creates the timers, but does not start them.  This is\r
-       because the standard demo timer test is started after this function is\r
-       called.  The standard demo timer test will deliberatly fill the timer\r
-       command queue - and will fail the test if the command queue already holds\r
-       start commands for the timers created here.  Instead, the timers created in\r
-       this function are started from the idle task, at which time, the timer\r
-       service/daemon task will be running, and will have drained the timer command\r
-       queue. */\r
+       because the standard demo timer test is started from main(), after this \r
+       function is     called.  The standard demo timer test will deliberately fill the \r
+       timer command queue - and will fail the test if the command queue already \r
+       holds start commands for the timers created here.  Instead, the timers \r
+       created in this function are started from the idle task, at which time, the \r
+       timer service/daemon task will be running, and will have drained the timer \r
+       command queue. */\r
        \r
        /* Create the software timer that is responsible for turning off the LED\r
        if the button is not pushed within 5000ms, as described at the top of\r
        this file. */\r
-       xLEDTimer = xTimerCreate(       ( const signed char * ) "ButtonLEDTimer",       /* A text name, purely to help debugging. */\r
+       xLEDButtonTimer = xTimerCreate(         ( const signed char * ) "ButtonLEDTimer",       /* A text name, purely to help debugging. */\r
                                                                ( mainBUTTON_LED_TIMER_PERIOD_MS ),                     /* The timer period, in this case 5000ms (5s). */\r
                                                                pdFALSE,                                                                        /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
                                                                ( void * ) 0,                                                           /* The ID is not used, so can be set to anything. */\r
@@ -534,7 +536,7 @@ void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName
        ( void ) pxTask;\r
 \r
        /* Run time stack overflow checking is performed if\r
-       configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
+       configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
        function is called if a stack overflow is detected. */\r
        taskDISABLE_INTERRUPTS();\r
        for( ;; );\r
@@ -554,14 +556,18 @@ volatile size_t xFreeHeapSpace;
                tasks were created in main() (this is part of the test they perform).\r
                Therefore, while the check and LED timers can be created in main(), they\r
                cannot be started from main().  Once the scheduler has started, the timer\r
-               service task will drain the command queue, and now the check and digit\r
-               counter timers can be started successfully. */\r
+               service task will drain the command queue, and now the check and LED\r
+               timers can be started successfully.  Normally the idle task must not\r
+               call a function that could cause it to block in case there are no tasks\r
+               that are able to run.  In this case, however, it is ok as posting to the\r
+               timer command queue guarantees that at least the timer service/daemon\r
+               task will be able to execute. */\r
                xTimerStart( xCheckTimer, portMAX_DELAY );\r
                xTimerStart( xLED1Timer, portMAX_DELAY );\r
                xTimerStart( xLED2Timer, portMAX_DELAY );\r
                \r
                xFreeHeapSpace = xPortGetFreeHeapSize();\r
-               printf( "%d bytes of FreeRTOS heap remain unused - configTOTAL_HEAP_SIZE can be reduced\n", xFreeHeapSpace );\r
+               printf( "%d bytes of FreeRTOS heap remain unused\nconfigTOTAL_HEAP_SIZE can be reduced\n", xFreeHeapSpace );\r
                \r
                if( xFreeHeapSpace > 100 )\r
                {\r
@@ -582,3 +588,70 @@ void vApplicationTickHook( void )
 }      \r
 /*-----------------------------------------------------------*/\r
 \r
+char *pcGetTaskStatusMessage( void )\r
+{\r
+       /* A simple GET function used by a CGI script so it can display the \r
+       execution status at the bottom of the task stats web page served by the\r
+       embedded web server. */\r
+       if( pcStatusMessage == NULL )\r
+       {\r
+               return "All tasks running without error";\r
+       }\r
+       else\r
+       {\r
+               return ( char * ) pcStatusMessage;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vMainConfigureTimerForRunTimeStats( void )\r
+{\r
+       /* How many clocks are there per tenth of a millisecond? */\r
+       ulClocksPer10thOfAMilliSecond = configCPU_CLOCK_HZ / 10000UL;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+unsigned long ulMainGetRunTimeCounterValue( void )\r
+{\r
+unsigned long ulSysTickCounts, ulTickCount, ulReturn;\r
+const unsigned long ulSysTickReloadValue = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;\r
+volatile unsigned long * const pulCurrentSysTickCount = ( ( volatile unsigned long *) 0xe000e018 );\r
+volatile unsigned long * const pulInterruptCTRLState = ( ( volatile unsigned long *) 0xe000ed04 );\r
+const unsigned long ulSysTickPendingBit = 0x04000000UL;\r
+\r
+       /* NOTE: There are potentially race conditions here.  However, it is used\r
+       anyway to keep the examples simple, and to avoid reliance on a separate\r
+       timer peripheral. */\r
+\r
+\r
+       /* The SysTick is a down counter.  How many clocks have passed since it was\r
+       last reloaded? */\r
+       ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;\r
+       \r
+       /* How many times has it overflowed? */\r
+       ulTickCount = xTaskGetTickCountFromISR();\r
+       \r
+       /* Is there a SysTick interrupt pending? */\r
+       if( ( *pulInterruptCTRLState & ulSysTickPendingBit ) != 0UL )\r
+       {\r
+               /* There is a SysTick interrupt pending, so the SysTick has overflowed\r
+               but the tick count not yet incremented. */\r
+               ulTickCount++;\r
+               \r
+               /* Read the SysTick again, as the overflow might have occurred since\r
+               it was read last. */\r
+               ulSysTickCounts = ulSysTickReloadValue - *pulCurrentSysTickCount;\r
+       }       \r
+       \r
+       /* Convert the tick count into tenths of a millisecond.  THIS ASSUMES\r
+       configTICK_RATE_HZ is 1000! */\r
+       ulReturn = ( ulTickCount * 10UL ) ;\r
+               \r
+       /* Add on the number of tenths of a millisecond that have passed since the\r
+       tick count last got updated. */\r
+       ulReturn += ( ulSysTickCounts / ulClocksPer10thOfAMilliSecond );\r
+       \r
+       return ulReturn;        \r
+}\r
+/*-----------------------------------------------------------*/\r
+\r