root/webserver/example/freeRTOS/Demo/Common/Minimal/flash.c

Revision 17, 4.8 kB (checked in by phil, 15 years ago)

adaptated example for LED flash to ETT eval board with 1 LED flashing,
changed portable.h to rowley setup
etc.

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  * This version of flash .c is for use on systems that have limited stack space
50  * and no display facilities.  The complete version can be found in the
51  * Demo/Common/Full directory.
52  *
53  * Three tasks are created, each of which flash an LED at a different rate.  The first
54  * LED flashes every 200ms, the second every 400ms, the third every 600ms.
55  *
56  * The LED flash tasks provide instant visual feedback.  They show that the scheduler
57  * is still operational.
58  *
59  */
60
61
62 #include <stdlib.h>
63
64 /* Scheduler include files. */
65 #include "FreeRTOS.h"
66 #include "task.h"
67
68 /* Demo program include files. */
69 #include "partest.h"
70 #include "flash.h"
71
72 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE
73 #define ledNUMBER_OF_LEDS       ( 1 )
74 #define ledFLASH_RATE_BASE      ( ( portTickType ) 333 )
75
76 /* Variable used by the created tasks to calculate the LED number to use, and
77 the rate at which they should flash the LED. */
78 static volatile unsigned portBASE_TYPE uxFlashTaskNumber = 0;
79
80 /* The task that is created three times. */
81 static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
82
83 /*-----------------------------------------------------------*/
84
85 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
86 {
87 signed portBASE_TYPE xLEDTask;
88
89         /* Create the three tasks. */
90         for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
91         {
92                 /* Spawn the task. */
93                 xTaskCreate( vLEDFlashTask, ( signed portCHAR * ) "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
94         }
95 }
96 /*-----------------------------------------------------------*/
97
98 static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
99 {
100 portTickType xFlashRate, xLastFlashTime;
101 unsigned portBASE_TYPE uxLED;
102
103         /* The parameters are not used. */
104         ( void ) pvParameters;
105
106         /* Calculate the LED and flash rate. */
107         portENTER_CRITICAL();
108         {
109                 /* See which of the eight LED's we should use. */
110                 uxLED = uxFlashTaskNumber;
111
112                 /* Update so the next task uses the next LED. */
113                 uxFlashTaskNumber++;
114         }
115         portEXIT_CRITICAL();
116
117         xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( portTickType ) uxLED );
118         xFlashRate /= portTICK_RATE_MS;
119
120         /* We will turn the LED on and off again in the delay period, so each
121         delay is only half the total period. */
122         xFlashRate /= ( portTickType ) 2;
123
124         /* We need to initialise xLastFlashTime prior to the first call to
125         vTaskDelayUntil(). */
126         xLastFlashTime = xTaskGetTickCount();
127
128         for(;;)
129         {
130                 /* Delay for half the flash period then turn the LED on. */
131                 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
132                 vParTestToggleLED( uxLED );
133
134                 /* Delay for half the flash period then turn the LED off. */
135                 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
136                 vParTestToggleLED( uxLED );
137         }
138 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
139
Note: See TracBrowser for help on using the browser.