]> git.sur5r.net Git - freertos/blobdiff - Demo/MB96350_Softune_Dice_Kit/SegmentToggleTasks.c
Tidy up and prepare for release.
[freertos] / Demo / MB96350_Softune_Dice_Kit / SegmentToggleTasks.c
index fbd2b1391e5a57b7e757fd70ed67b188136e3170..f2e497c6504fd6721fb12f676ee734f391fc40dc 100644 (file)
 */\r
 \r
 /**\r
- * This version of flash .c is for use on systems that have limited stack space\r
- * and no display facilities.  The complete version can be found in the \r
- * Demo/Common/Full directory.\r
- * \r
- * Three tasks are created, each of which flash an LED at a different rate.  The first \r
- * LED flashes every 200ms, the second every 400ms, the third every 600ms.\r
- *\r
- * The LED flash tasks provide instant visual feedback.  They show that the scheduler \r
- * is still operational.\r
- *\r
+ * Defines the tasks and co-routines used to toggle the segments of the two\r
+ * seven segment displays, as described at the top of main.c\r
  */\r
 \r
 \r
 \r
 /* Demo program include files. */\r
 #include "partest.h"\r
-#include "flash.h"\r
 \r
-#define ledSTACK_SIZE          configMINIMAL_STACK_SIZE\r
-#define ledNUMBER_OF_LEDS      ( 7 )\r
+/*-----------------------------------------------------------*/\r
+\r
+/* One task per segment of the left side display. */\r
+#define ledNUM_OF_LED_TASKS    ( 7 )\r
+\r
+/* Each task toggles at a frequency that is a multiple of 333ms. */\r
 #define ledFLASH_RATE_BASE     ( ( portTickType ) 333 )\r
 \r
-#define ledMAX_FLASH_CO_ROUTINES       7\r
+/* One co-routine per segment of the right hand display. */\r
+#define ledNUM_OF_LED_CO_ROUTINES      7\r
+\r
+/* All co-routines run at the same priority. */\r
 #define ledCO_ROUTINE_PRIORITY         0\r
 \r
-/* The task that is created three times. */\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The task that is created 7 times. */\r
 static void vLEDFlashTask( void *pvParameters );\r
+\r
+/* The co-routine that is created 7 times. */\r
 static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned short usIndex );\r
 \r
 /* This task is created once, but itself creates 7 co-routines. */\r
 static void vLEDCoRoutineControlTask( void *pvParameters );\r
 \r
-static xTaskHandle xFlashTaskHandles[ ledNUMBER_OF_LEDS ] = { 0 };\r
+/* Handles to each of the 7 tasks.  Used so the tasks can be suspended\r
+and resumed. */\r
+static xTaskHandle xFlashTaskHandles[ ledNUM_OF_LED_TASKS ] = { 0 };\r
+\r
+/* Handle to the task in which the co-routines run.  Used so the\r
+co-routines can be suspended and resumed. */\r
 static xTaskHandle xCoroutineTask;\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
+/**\r
+ * Creates the tasks and co-routines used to toggle the segments of the two\r
+ * seven segment displays, as described at the top of main.c\r
+ */\r
 void vCreateFlashTasksAndCoRoutines( void )\r
 {\r
 signed short sLEDTask;\r
 \r
-       /* Create the three tasks that flash segments on the first LED. */\r
-       for( sLEDTask = 0; sLEDTask < ledNUMBER_OF_LEDS; ++sLEDTask )\r
+       /* Create the tasks that flash segments on the first LED. */\r
+       for( sLEDTask = 0; sLEDTask < ledNUM_OF_LED_TASKS; ++sLEDTask )\r
        {\r
                /* Spawn the task. */\r
-               xTaskCreate( vLEDFlashTask, ( signed char * ) "LEDt", ledSTACK_SIZE, ( void * ) sLEDTask, ( tskIDLE_PRIORITY + 1 ), &( xFlashTaskHandles[ sLEDTask ] ) );\r
+               xTaskCreate( vLEDFlashTask, ( signed char * ) "LEDt", configMINIMAL_STACK_SIZE, ( void * ) sLEDTask, ( tskIDLE_PRIORITY + 1 ), &( xFlashTaskHandles[ sLEDTask ] ) );\r
        }\r
 \r
-       /* Create the task in which the co-routines run. */\r
-       xTaskCreate( vLEDCoRoutineControlTask, ( signed char * ) "LEDc", ledSTACK_SIZE, NULL, tskIDLE_PRIORITY, &xCoroutineTask );\r
+       /* Create the task in which the co-routines run.  The co-routines themselves\r
+       are created within the task. */\r
+       xTaskCreate( vLEDCoRoutineControlTask, ( signed char * ) "LEDc", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xCoroutineTask );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -111,9 +123,11 @@ void vSuspendFlashTasks( unsigned char ucIndex, short sSuspendTasks )
 {\r
 short sLEDTask;\r
 \r
-       if( ucIndex == 0 )\r
+       if( ucIndex == configLEFT_DISPLAY )\r
        {\r
-               for( sLEDTask = 0; sLEDTask < ledNUMBER_OF_LEDS; ++sLEDTask )\r
+               /* Suspend or resume the tasks that are toggling the segments of the\r
+               left side display. */\r
+               for( sLEDTask = 0; sLEDTask < ledNUM_OF_LED_TASKS; ++sLEDTask )\r
                {\r
                        if( xFlashTaskHandles[ sLEDTask ] != NULL )\r
                        {\r
@@ -130,6 +144,8 @@ short sLEDTask;
        }\r
        else\r
        {\r
+               /* Suspend or resume the task in which the co-routines are running.  The\r
+               co-routines toggle the segments of the right side display. */\r
                if( sSuspendTasks == pdTRUE )\r
                {\r
                        vTaskSuspend( xCoroutineTask );\r
@@ -181,11 +197,14 @@ unsigned short usCoroutine;
 \r
        ( void ) pvParameters;\r
 \r
-       for( usCoroutine = 0; usCoroutine < ledMAX_FLASH_CO_ROUTINES; usCoroutine++ )\r
+       /* Create the co-routines - one of each segment of the right side display. */\r
+       for( usCoroutine = 0; usCoroutine < ledNUM_OF_LED_CO_ROUTINES; usCoroutine++ )\r
        {\r
                xCoRoutineCreate( prvFixedDelayCoRoutine, ledCO_ROUTINE_PRIORITY, usCoroutine );\r
        }\r
 \r
+       /* This task has nothing else to do except scheduler the co-routines it just\r
+       created. */\r
        for( ;; )\r
        {\r
                vCoRoutineSchedule();\r
@@ -197,7 +216,7 @@ static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned short usI
 {\r
 /* The usIndex parameter of the co-routine function is used as an index into\r
 the xFlashRates array to obtain the delay period to use. */\r
-static const portTickType xFlashRates[ ledMAX_FLASH_CO_ROUTINES ] = { 150 / portTICK_RATE_MS,\r
+static const portTickType xFlashRates[ ledNUM_OF_LED_CO_ROUTINES ] = { 150 / portTICK_RATE_MS,\r
                                                                                                                                300 / portTICK_RATE_MS,\r
                                                                                                                                450 / portTICK_RATE_MS,\r
                                                                                                                                600 / portTICK_RATE_MS,\r
@@ -210,7 +229,12 @@ static const portTickType xFlashRates[ ledMAX_FLASH_CO_ROUTINES ] = { 150 / port
 \r
        for( ;; )\r
        {\r
+               /* Toggle the LED.  An offset of 8 is used to skip over the segments of\r
+               the left side display which use the low numbers. */\r
                vParTestToggleLED( usIndex + 8 );\r
+\r
+               /* Delay until it is time to toggle the segment that this co-routine is\r
+               controlling again. */\r
                crDELAY( xHandle, xFlashRates[ usIndex ] );\r
        }\r
 \r