]> git.sur5r.net Git - freertos/blob - Demo/Common/Full/flash.c
Update to V4.5.0 files and directory structure.
[freertos] / Demo / Common / Full / flash.c
1 /*\r
2         FreeRTOS.org V4.5.0 - Copyright (C) 2003-2007 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         Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along\r
32         with commercial development and support options.\r
33         ***************************************************************************\r
34 */\r
35 \r
36 \r
37 /**\r
38  * Creates eight tasks, each of which flash an LED at a different rate.  The first \r
39  * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.\r
40  *\r
41  * The LED flash tasks provide instant visual feedback.  They show that the scheduler \r
42  * is still operational.\r
43  *\r
44  * The PC port uses the standard parallel port for outputs, the Flashlite 186 port \r
45  * uses IO port F.\r
46  *\r
47  * \page flashC flash.c\r
48  * \ingroup DemoFiles\r
49  * <HR>\r
50  */\r
51 \r
52 /*\r
53 Changes from V2.0.0\r
54 \r
55         + Delay periods are now specified using variables and constants of\r
56           portTickType rather than unsigned portLONG.\r
57 \r
58 Changes from V2.1.1\r
59 \r
60         + The stack size now uses configMINIMAL_STACK_SIZE.\r
61         + String constants made file scope to decrease stack depth on 8051 port.\r
62 */\r
63 \r
64 #include <stdlib.h>\r
65 \r
66 /* Scheduler include files. */\r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 \r
70 /* Demo program include files. */\r
71 #include "partest.h"\r
72 #include "flash.h"\r
73 #include "print.h"\r
74 \r
75 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE\r
76 \r
77 /* Structure used to pass parameters to the LED tasks. */\r
78 typedef struct LED_PARAMETERS\r
79 {\r
80         unsigned portBASE_TYPE uxLED;           /*< The output the task should use. */\r
81         portTickType xFlashRate;        /*< The rate at which the LED should flash. */\r
82 } xLEDParameters;\r
83 \r
84 /* The task that is created eight times - each time with a different xLEDParaemtes \r
85 structure passed in as the parameter. */\r
86 static void vLEDFlashTask( void *pvParameters );\r
87 \r
88 /* String to print if USE_STDIO is defined. */\r
89 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )\r
94 {\r
95 unsigned portBASE_TYPE uxLEDTask;\r
96 xLEDParameters *pxLEDParameters;\r
97 const unsigned portBASE_TYPE uxNumOfLEDs = 8;\r
98 const portTickType xFlashRate = 125;\r
99 \r
100         /* Create the eight tasks. */\r
101         for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )\r
102         {\r
103                 /* Create and complete the structure used to pass parameters to the next \r
104                 created task. */\r
105                 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );\r
106                 pxLEDParameters->uxLED = uxLEDTask;\r
107                 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( portTickType ) uxLEDTask ) );\r
108                 pxLEDParameters->xFlashRate /= portTICK_RATE_MS;\r
109 \r
110                 /* Spawn the task. */\r
111                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );\r
112         }\r
113 }\r
114 /*-----------------------------------------------------------*/\r
115 \r
116 static void vLEDFlashTask( void *pvParameters )\r
117 {\r
118 xLEDParameters *pxParameters;\r
119 \r
120         /* Queue a message for printing to say the task has started. */\r
121         vPrintDisplayMessage( &pcTaskStartMsg );\r
122 \r
123         pxParameters = ( xLEDParameters * ) pvParameters;\r
124 \r
125         for(;;)\r
126         {\r
127                 /* Delay for half the flash period then turn the LED on. */\r
128                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
129                 vParTestToggleLED( pxParameters->uxLED );\r
130 \r
131                 /* Delay for half the flash period then turn the LED off. */\r
132                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );\r
133                 vParTestToggleLED( pxParameters->uxLED );\r
134         }\r
135 }\r
136 \r