]> git.sur5r.net Git - freertos/blobdiff - Demo/SuperH_SH7216_Renesas/RTOSDemo/main.c
Just updated comments.
[freertos] / Demo / SuperH_SH7216_Renesas / RTOSDemo / main.c
index 9d6f718e738b6d68a5e3390ec8f27bfb5b30a24c..25105274f897b64594aa9ee4b487f95abf7135f9 100644 (file)
     licensing and training services.\r
 */\r
 \r
+\r
+\r
+/*\r
+ * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
+ * documentation provides more details of the standard demo application tasks,\r
+ * which provide no particular functionality but do provide a good example of\r
+ * how to use the FreeRTOS API.  In addition to the standard demo tasks, the \r
+ * following tasks and tests are defined and/or created within this file:\r
+ *\r
+ * "Reg test" tasks - These fill the registers with known values, then check\r
+ * that each register still contains its expected value.  Each task uses\r
+ * different values.  The tasks run with very low priority so get preempted very\r
+ * frequently.  A register containing an unexpected value is indicative of an\r
+ * error in the context switching mechanism.  Both standard and floating point\r
+ * registers are checked.  The nature of the reg test tasks necessitates that\r
+ * they are written in assembly code.  They are defined in regtest.src.\r
+ *\r
+ * "math" tasks - These are a set of 8 tasks that perform various double\r
+ * precision floating point calculations in order to check that the tasks \r
+ * floating point registers are being correctly saved and restored during\r
+ * context switches.  The math tasks are defined in flop.c.\r
+ *\r
+ * "Check" task - This only executes every five seconds but has a high priority\r
+ * to ensure it gets processor time.  Its main function is to check that all the\r
+ * standard demo tasks are still operational.  While no errors have been\r
+ * discovered the check task will toggle an LED every 5 seconds - the toggle\r
+ * rate increasing to 500ms being a visual indication that at least one task has\r
+ * reported unexpected behaviour.\r
+ *\r
+ * *NOTE 1* If LED5 is toggling every 5 seconds then all the demo application\r
+ * tasks are executing as expected and no errors have been reported in any \r
+ * tasks.  The toggle rate increasing to 200ms indicates that at least one task\r
+ * has reported unexpected behaviour.\r
+ * \r
+ * *NOTE 2* This file and flop.c both demonstrate the use of \r
+ * xPortUsesFloatingPoint() which informs the kernel that a task should maintain\r
+ * a floating point context.\r
+ *\r
+ * *NOTE 3* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
+ * the application set up a timer to generate the tick interrupt.  In this\r
+ * example a compare match timer is used for this purpose.  \r
+ * vApplicationTickHook() is used to clear the timer interrupt and relies on\r
+ * configUSE_TICK_HOOK being set to 1 in FreeRTOSConfig.h.\r
+ *\r
+ * *NOTE 4* The traceTASK_SWITCHED_IN and traceTASK_SWITCHED_OUT trace hooks\r
+ * are used to save and restore the floating point context respectively for\r
+ * those tasks that require it (those for which xPortUsesFloatingPoint() has\r
+ * been called).\r
+ * \r
+ */\r
+\r
 /* Kernel includes. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
@@ -94,18 +145,58 @@ without error. */
 by at least one task. */\r
 #define mainERROR_CYCLE_TIME                           ( 200 / portTICK_RATE_MS )\r
 \r
+/*\r
+ * vApplicationMallocFailedHook() will only be called if\r
+ * configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
+ * function that will execute if a call to pvPortMalloc() fails.\r
+ * pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
+ * semaphore is created.  It is also called by various parts of the demo\r
+ * application.  \r
+ */\r
 void vApplicationMallocFailedHook( void );\r
+\r
+/*\r
+ * vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1\r
+ * in FreeRTOSConfig.h.  It is a hook function that is called on each iteration\r
+ * of the idle task.  It is essential that code added to this hook function\r
+ * never attempts to block in any way (for example, call xQueueReceive() with\r
+ * a block time specified).  If the application makes use of the vTaskDelete()\r
+ * API function (as this demo application does) then it is also important that\r
+ * vApplicationIdleHook() is permitted to return to its calling function because\r
+ * it is the responsibility of the idle task to clean up memory allocated by the\r
+ * kernel to any task that has since been deleted.\r
+ */\r
 void vApplicationIdleHook( void );\r
+\r
+/*\r
+ * Just sets up clocks, ports, etc. used by the demo application.\r
+ */\r
 static void prvSetupHardware( void );\r
+\r
+/*\r
+ * The check task as described at the top of this file.\r
+ */\r
 static void prvCheckTask( void *pvParameters );\r
 \r
+/*\r
+ * The reg test tasks as described at the top of this file.\r
+ */\r
 extern void vRegTest1Task( void *pvParameters );\r
 extern void vRegTest2Task( void *pvParameters );\r
 \r
+/*-----------------------------------------------------------*/\r
+\r
+/* Variables that are incremented on each iteration of the reg test tasks - \r
+provided the tasks have not reported any errors.  The check task inspects these\r
+variables to ensure they are still incrementing as expected. */\r
 volatile unsigned long ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
+/*\r
+ * Creates the majority of the demo application tasks before starting the\r
+ * scheduler.\r
+ */\r
 void main(void)\r
 {\r
 xTaskHandle xCreatedTask;\r
@@ -113,10 +204,10 @@ xTaskHandle xCreatedTask;
        prvSetupHardware();\r
 \r
        /* Start the reg test tasks which test the context switching mechanism. */\r
-       xTaskCreate( vRegTest1Task, "RegTest1", configMINIMAL_STACK_SIZE, ( void * ) 0x12345678UL, tskIDLE_PRIORITY, &xCreatedTask );\r
+       xTaskCreate( vRegTest1Task, "RegTest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xCreatedTask );\r
        xPortUsesFloatingPoint( xCreatedTask );\r
        \r
-       xTaskCreate( vRegTest2Task, "RegTest2", configMINIMAL_STACK_SIZE, ( void * ) 0x11223344UL, tskIDLE_PRIORITY, &xCreatedTask );\r
+       xTaskCreate( vRegTest2Task, "RegTest2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xCreatedTask );\r
        xPortUsesFloatingPoint( xCreatedTask );\r
 \r
        /* Start the check task as described at the top of this file. */\r
@@ -133,6 +224,8 @@ xTaskHandle xCreatedTask;
        vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
     vStartQueuePeekTasks();\r
     vStartRecursiveMutexTasks();\r
+       \r
+       /* Start the math tasks as described at the top of this file. */\r
        vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
 \r
        /* The suicide tasks must be created last as they need to know how many\r
@@ -165,7 +258,7 @@ unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
                /* Place this task in the blocked state until it is time to run again. */\r
                vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
                \r
-               /* Inspect all the other tasks to esnure none have experienced any errors. */\r
+               /* Inspect all the other tasks to ensure none have experienced any errors. */\r
                if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
                {\r
                        /* Increase the rate at which this task cycles, which will increase the\r
@@ -253,7 +346,10 @@ void vApplicationIdleHook( void )
 \r
 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
 {\r
-       /* Just to remove compiler warnings. */\r
+       /* Just to remove compiler warnings.  This function will only actually\r
+       get called if configCHECK_FOR_STACK_OVERFLOW is set to a non zero value.\r
+       By default this demo does not use the stack overflow checking functionality\r
+       as the SuperH will normally execute an exception if the stack overflows. */\r
        ( void ) pxTask;\r
        ( void ) pcTaskName;\r
        \r
@@ -282,7 +378,7 @@ volatile unsigned long ul;
 void vApplicationSetupTimerInterrupt( void )\r
 {\r
 /* The peripheral clock is divided by 32 before feeding the compare match\r
-periphersl (CMT). */\r
+peripheral (CMT). */\r
 unsigned long ulCompareMatch = ( configPERIPHERAL_CLOCK_HZ / ( configTICK_RATE_HZ * 32 ) ) + 1;\r
 \r
        /* Configure a timer to create the RTOS tick interrupt.  This example uses\r