2 FreeRTOS.org V4.5.0 - Copyright (C) 2003-2007 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 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
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
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
41 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
42 * is still operational.
\r
44 * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
\r
47 * \page flashC flash.c
\r
48 * \ingroup DemoFiles
\r
55 + Delay periods are now specified using variables and constants of
\r
56 portTickType rather than unsigned portLONG.
\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
66 /* Scheduler include files. */
\r
67 #include "FreeRTOS.h"
\r
70 /* Demo program include files. */
\r
71 #include "partest.h"
\r
75 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
77 /* Structure used to pass parameters to the LED tasks. */
\r
78 typedef struct LED_PARAMETERS
\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
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
88 /* String to print if USE_STDIO is defined. */
\r
89 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";
\r
91 /*-----------------------------------------------------------*/
\r
93 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
\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
100 /* Create the eight tasks. */
\r
101 for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
\r
103 /* Create and complete the structure used to pass parameters to the next
\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
110 /* Spawn the task. */
\r
111 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );
\r
114 /*-----------------------------------------------------------*/
\r
116 static void vLEDFlashTask( void *pvParameters )
\r
118 xLEDParameters *pxParameters;
\r
120 /* Queue a message for printing to say the task has started. */
\r
121 vPrintDisplayMessage( &pcTaskStartMsg );
\r
123 pxParameters = ( xLEDParameters * ) pvParameters;
\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
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