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