]> git.sur5r.net Git - freertos/blob - Demo/Common/Full/flash.c
Ready for V5.1.1 release.
[freertos] / Demo / Common / Full / flash.c
1 /*\r
2         FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 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     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 \r
51 /**\r
52  * Creates eight tasks, each of which flash an LED at a different rate.  The first \r
53  * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.\r
54  *\r
55  * The LED flash tasks provide instant visual feedback.  They show that the scheduler \r
56  * is still operational.\r
57  *\r
58  * The PC port uses the standard parallel port for outputs, the Flashlite 186 port \r
59  * uses IO port F.\r
60  *\r
61  * \page flashC flash.c\r
62  * \ingroup DemoFiles\r
63  * <HR>\r
64  */\r
65 \r
66 /*\r
67 Changes from V2.0.0\r
68 \r
69         + Delay periods are now specified using variables and constants of\r
70           portTickType rather than unsigned portLONG.\r
71 \r
72 Changes from V2.1.1\r
73 \r
74         + The stack size now uses configMINIMAL_STACK_SIZE.\r
75         + String constants made file scope to decrease stack depth on 8051 port.\r
76 */\r
77 \r
78 #include <stdlib.h>\r
79 \r
80 /* Scheduler include files. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 \r
84 /* Demo program include files. */\r
85 #include "partest.h"\r
86 #include "flash.h"\r
87 #include "print.h"\r
88 \r
89 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE\r
90 \r
91 /* Structure used to pass parameters to the LED tasks. */\r
92 typedef struct LED_PARAMETERS\r
93 {\r
94         unsigned portBASE_TYPE uxLED;           /*< The output the task should use. */\r
95         portTickType xFlashRate;        /*< The rate at which the LED should flash. */\r
96 } xLEDParameters;\r
97 \r
98 /* The task that is created eight times - each time with a different xLEDParaemtes \r
99 structure passed in as the parameter. */\r
100 static void vLEDFlashTask( void *pvParameters );\r
101 \r
102 /* String to print if USE_STDIO is defined. */\r
103 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";\r
104 \r
105 /*-----------------------------------------------------------*/\r
106 \r
107 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )\r
108 {\r
109 unsigned portBASE_TYPE uxLEDTask;\r
110 xLEDParameters *pxLEDParameters;\r
111 const unsigned portBASE_TYPE uxNumOfLEDs = 8;\r
112 const portTickType xFlashRate = 125;\r
113 \r
114         /* Create the eight tasks. */\r
115         for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )\r
116         {\r
117                 /* Create and complete the structure used to pass parameters to the next \r
118                 created task. */\r
119                 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );\r
120                 pxLEDParameters->uxLED = uxLEDTask;\r
121                 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( portTickType ) uxLEDTask ) );\r
122                 pxLEDParameters->xFlashRate /= portTICK_RATE_MS;\r
123 \r
124                 /* Spawn the task. */\r
125                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );\r
126         }\r
127 }\r
128 /*-----------------------------------------------------------*/\r
129 \r
130 static void vLEDFlashTask( void *pvParameters )\r
131 {\r
132 xLEDParameters *pxParameters;\r
133 \r
134         /* Queue a message for printing to say the task has started. */\r
135         vPrintDisplayMessage( &pcTaskStartMsg );\r
136 \r
137         pxParameters = ( xLEDParameters * ) pvParameters;\r
138 \r
139         for(;;)\r
140         {\r
141                 /* Delay for half the flash period then turn the LED on. */\r
142                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
143                 vParTestToggleLED( pxParameters->uxLED );\r
144 \r
145                 /* Delay for half the flash period then turn the LED off. */\r
146                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
147                 vParTestToggleLED( pxParameters->uxLED );\r
148         }\r
149 }\r
150 \r