root/webserver/example/freeRTOSexample/Demo/Common/Full/flash.c

Revision 14, 5.1 kB (checked in by phil, 15 years ago)

added unmodified FreeRTOS package V5.4.1 with only web srv demo source for LPC2368 for CrossWorks?

Line 
1 /*
2         FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.
3
4         This file is part of the FreeRTOS distribution.
5
6         FreeRTOS is free software; you can redistribute it and/or modify it     under
7         the terms of the GNU General Public License (version 2) as published by the
8         Free Software Foundation and modified by the FreeRTOS exception.
9         **NOTE** The exception to the GPL is included to allow you to distribute a
10         combined work that includes FreeRTOS without being obliged to provide the
11         source code for proprietary components outside of the FreeRTOS kernel. 
12         Alternative commercial license and support terms are also available upon
13         request.  See the licensing section of http://www.FreeRTOS.org for full
14         license details.
15
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19         more details.
20
21         You should have received a copy of the GNU General Public License along
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.
24
25
26         ***************************************************************************
27         *                                                                         *
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *
29         * See http://www.FreeRTOS.org/Documentation for details                   *
30         *                                                                         *
31         ***************************************************************************
32
33         1 tab == 4 spaces!
34
35         Please ensure to read the configuration and relevant port sections of the
36         online documentation.
37
38         http://www.FreeRTOS.org - Documentation, latest information, license and
39         contact details.
40
41         http://www.SafeRTOS.com - A version that is certified for use in safety
42         critical systems.
43
44         http://www.OpenRTOS.com - Commercial support, development, porting,
45         licensing and training services.
46 */
47
48
49 /**
50  * Creates eight tasks, each of which flash an LED at a different rate.  The first
51  * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.
52  *
53  * The LED flash tasks provide instant visual feedback.  They show that the scheduler
54  * is still operational.
55  *
56  * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
57  * uses IO port F.
58  *
59  * \page flashC flash.c
60  * \ingroup DemoFiles
61  * <HR>
62  */
63
64 /*
65 Changes from V2.0.0
66
67         + Delay periods are now specified using variables and constants of
68           portTickType rather than unsigned portLONG.
69
70 Changes from V2.1.1
71
72         + The stack size now uses configMINIMAL_STACK_SIZE.
73         + String constants made file scope to decrease stack depth on 8051 port.
74 */
75
76 #include <stdlib.h>
77
78 /* Scheduler include files. */
79 #include "FreeRTOS.h"
80 #include "task.h"
81
82 /* Demo program include files. */
83 #include "partest.h"
84 #include "flash.h"
85 #include "print.h"
86
87 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE
88
89 /* Structure used to pass parameters to the LED tasks. */
90 typedef struct LED_PARAMETERS
91 {
92         unsigned portBASE_TYPE uxLED;           /*< The output the task should use. */
93         portTickType xFlashRate;        /*< The rate at which the LED should flash. */
94 } xLEDParameters;
95
96 /* The task that is created eight times - each time with a different xLEDParaemtes
97 structure passed in as the parameter. */
98 static void vLEDFlashTask( void *pvParameters );
99
100 /* String to print if USE_STDIO is defined. */
101 const portCHAR * const pcTaskStartMsg = "LED flash task started.\r\n";
102
103 /*-----------------------------------------------------------*/
104
105 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
106 {
107 unsigned portBASE_TYPE uxLEDTask;
108 xLEDParameters *pxLEDParameters;
109 const unsigned portBASE_TYPE uxNumOfLEDs = 8;
110 const portTickType xFlashRate = 125;
111
112         /* Create the eight tasks. */
113         for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
114         {
115                 /* Create and complete the structure used to pass parameters to the next
116                 created task. */
117                 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
118                 pxLEDParameters->uxLED = uxLEDTask;
119                 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( portTickType ) uxLEDTask ) );
120                 pxLEDParameters->xFlashRate /= portTICK_RATE_MS;
121
122                 /* Spawn the task. */
123                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( xTaskHandle * ) NULL );
124         }
125 }
126 /*-----------------------------------------------------------*/
127
128 static void vLEDFlashTask( void *pvParameters )
129 {
130 xLEDParameters *pxParameters;
131
132         /* Queue a message for printing to say the task has started. */
133         vPrintDisplayMessage( &pcTaskStartMsg );
134
135         pxParameters = ( xLEDParameters * ) pvParameters;
136
137         for(;;)
138         {
139                 /* Delay for half the flash period then turn the LED on. */
140                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );
141                 vParTestToggleLED( pxParameters->uxLED );
142
143                 /* Delay for half the flash period then turn the LED off. */
144                 vTaskDelay( pxParameters->xFlashRate / ( portTickType ) 2 );
145                 vParTestToggleLED( pxParameters->uxLED );
146         }
147 }
148
Note: See TracBrowser for help on using the browser.