]> begriffs open source - freertos/blob - Demo/Common/Full/flash.c
Update to V4.1.0.
[freertos] / Demo / Common / Full / flash.c
1 /*\r
2         FreeRTOS.org V4.1.0 - Copyright (C) 2003-2006 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section \r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27         See http://www.FreeRTOS.org for documentation, latest information, license \r
28         and contact details.  Please ensure to read the configuration and relevant \r
29         port sections of the online documentation.\r
30         ***************************************************************************\r
31 */\r
32 \r
33 \r
34 /**\r
35  * Creates eight tasks, each of which flash an LED at a different rate.  The first \r
36  * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.\r
37  *\r
38  * The LED flash tasks provide instant visual feedback.  They show that the scheduler \r
39  * is still operational.\r
40  *\r
41  * The PC port uses the standard parallel port for outputs, the Flashlite 186 port \r
42  * uses IO port F.\r
43  *\r
44  * \page flashC flash.c\r
45  * \ingroup DemoFiles\r
46  * <HR>\r
47  */\r
48 \r
49 /*\r
50 Changes from V2.0.0\r
51 \r
52         + Delay periods are now specified using variables and constants of\r
53           portTickType rather than unsigned portLONG.\r
54 \r
55 Changes from V2.1.1\r
56 \r
57         + The stack size now uses configMINIMAL_STACK_SIZE.\r
58         + String constants made file scope to decrease stack depth on 8051 port.\r
59 */\r
60 \r
61 #include <stdlib.h>\r
62 \r
63 /* Scheduler include files. */\r
64 #include "FreeRTOS.h"\r
65 #include "task.h"\r
66 \r
67 /* Demo program include files. */\r
68 #include "partest.h"\r
69 #include "flash.h"\r
70 #include "print.h"\r
71 \r
72 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE\r
73 \r
74 /* Structure used to pass parameters to the LED tasks. */\r
75 typedef struct LED_PARAMETERS\r
76 {\r
77         unsigned portBASE_TYPE uxLED;           /*< The output the task should use. */\r
78         portTickType xFlashRate;        /*< The rate at which the LED should flash. */\r
79 } xLEDParameters;\r
80 \r
81 /* The task that is created eight times - each time with a different xLEDParaemtes \r
82 structure passed in as the parameter. */\r
83 static void vLEDFlashTask( void *pvParameters );\r
84 \r
85 /* String to print if USE_STDIO is defined. */\r
86 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";\r
87 \r
88 /*-----------------------------------------------------------*/\r
89 \r
90 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )\r
91 {\r
92 unsigned portBASE_TYPE uxLEDTask;\r
93 xLEDParameters *pxLEDParameters;\r
94 const unsigned portBASE_TYPE uxNumOfLEDs = 8;\r
95 const portTickType xFlashRate = 125;\r
96 \r
97         /* Create the eight tasks. */\r
98         for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )\r
99         {\r
100                 /* Create and complete the structure used to pass parameters to the next \r
101                 created task. */\r
102                 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );\r
103                 pxLEDParameters->uxLED = uxLEDTask;\r
104                 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( portTickType ) uxLEDTask ) );\r
105                 pxLEDParameters->xFlashRate /= portTICK_RATE_MS;\r
106 \r
107                 /* Spawn the task. */\r
108                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );\r
109         }\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 static void vLEDFlashTask( void *pvParameters )\r
114 {\r
115 xLEDParameters *pxParameters;\r
116 \r
117         /* Queue a message for printing to say the task has started. */\r
118         vPrintDisplayMessage( &pcTaskStartMsg );\r
119 \r
120         pxParameters = ( xLEDParameters * ) pvParameters;\r
121 \r
122         for(;;)\r
123         {\r
124                 /* Delay for half the flash period then turn the LED on. */\r
125                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
126                 vParTestToggleLED( pxParameters->uxLED );\r
127 \r
128                 /* Delay for half the flash period then turn the LED off. */\r
129                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
130                 vParTestToggleLED( pxParameters->uxLED );\r
131         }\r
132 }\r
133 \r