2 FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
54 * Creates eight tasks, each of which flash an LED at a different rate. The first
\r
55 * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.
\r
57 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
58 * is still operational.
\r
60 * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
\r
63 * \page flashC flash.c
\r
64 * \ingroup DemoFiles
\r
71 + Delay periods are now specified using variables and constants of
\r
72 portTickType rather than unsigned portLONG.
\r
76 + The stack size now uses configMINIMAL_STACK_SIZE.
\r
77 + String constants made file scope to decrease stack depth on 8051 port.
\r
82 /* Scheduler include files. */
\r
83 #include "FreeRTOS.h"
\r
86 /* Demo program include files. */
\r
87 #include "partest.h"
\r
91 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
93 /* Structure used to pass parameters to the LED tasks. */
\r
94 typedef struct LED_PARAMETERS
\r
96 unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
\r
97 portTickType xFlashRate; /*< The rate at which the LED should flash. */
\r
100 /* The task that is created eight times - each time with a different xLEDParaemtes
\r
101 structure passed in as the parameter. */
\r
102 static void vLEDFlashTask( void *pvParameters );
\r
104 /* String to print if USE_STDIO is defined. */
\r
105 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";
\r
107 /*-----------------------------------------------------------*/
\r
109 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
\r
111 unsigned portBASE_TYPE uxLEDTask;
\r
112 xLEDParameters *pxLEDParameters;
\r
113 const unsigned portBASE_TYPE uxNumOfLEDs = 8;
\r
114 const portTickType xFlashRate = 125;
\r
116 /* Create the eight tasks. */
\r
117 for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
\r
119 /* Create and complete the structure used to pass parameters to the next
\r
121 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
\r
122 pxLEDParameters->uxLED = uxLEDTask;
\r
123 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( portTickType ) uxLEDTask ) );
\r
124 pxLEDParameters->xFlashRate /= portTICK_RATE_MS;
\r
126 /* Spawn the task. */
\r
127 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );
\r
130 /*-----------------------------------------------------------*/
\r
132 static void vLEDFlashTask( void *pvParameters )
\r
134 xLEDParameters *pxParameters;
\r
136 /* Queue a message for printing to say the task has started. */
\r
137 vPrintDisplayMessage( &pcTaskStartMsg );
\r
139 pxParameters = ( xLEDParameters * ) pvParameters;
\r
143 /* Delay for half the flash period then turn the LED on. */
\r
144 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );
\r
145 vParTestToggleLED( pxParameters->uxLED );
\r
147 /* Delay for half the flash period then turn the LED off. */
\r
148 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );
\r
149 vParTestToggleLED( pxParameters->uxLED );
\r