2 FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\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
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
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
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
26 ***************************************************************************
\r
27 ***************************************************************************
\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
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\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
55 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
56 * is still operational.
\r
58 * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
\r
61 * \page flashC flash.c
\r
62 * \ingroup DemoFiles
\r
69 + Delay periods are now specified using variables and constants of
\r
70 portTickType rather than unsigned portLONG.
\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
80 /* Scheduler include files. */
\r
81 #include "FreeRTOS.h"
\r
84 /* Demo program include files. */
\r
85 #include "partest.h"
\r
89 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
91 /* Structure used to pass parameters to the LED tasks. */
\r
92 typedef struct LED_PARAMETERS
\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
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
102 /* String to print if USE_STDIO is defined. */
\r
103 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";
\r
105 /*-----------------------------------------------------------*/
\r
107 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
\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
114 /* Create the eight tasks. */
\r
115 for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
\r
117 /* Create and complete the structure used to pass parameters to the next
\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
124 /* Spawn the task. */
\r
125 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );
\r
128 /*-----------------------------------------------------------*/
\r
130 static void vLEDFlashTask( void *pvParameters )
\r
132 xLEDParameters *pxParameters;
\r
134 /* Queue a message for printing to say the task has started. */
\r
135 vPrintDisplayMessage( &pcTaskStartMsg );
\r
137 pxParameters = ( xLEDParameters * ) pvParameters;
\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
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