1 |
583 |
jeremybenn |
/*
|
2 |
|
|
FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
|
3 |
|
|
|
4 |
|
|
***************************************************************************
|
5 |
|
|
* *
|
6 |
|
|
* If you are: *
|
7 |
|
|
* *
|
8 |
|
|
* + New to FreeRTOS, *
|
9 |
|
|
* + Wanting to learn FreeRTOS or multitasking in general quickly *
|
10 |
|
|
* + Looking for basic training, *
|
11 |
|
|
* + Wanting to improve your FreeRTOS skills and productivity *
|
12 |
|
|
* *
|
13 |
|
|
* then take a look at the FreeRTOS books - available as PDF or paperback *
|
14 |
|
|
* *
|
15 |
|
|
* "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
16 |
|
|
* http://www.FreeRTOS.org/Documentation *
|
17 |
|
|
* *
|
18 |
|
|
* A pdf reference manual is also available. Both are usually delivered *
|
19 |
|
|
* to your inbox within 20 minutes to two hours when purchased between 8am *
|
20 |
|
|
* and 8pm GMT (although please allow up to 24 hours in case of *
|
21 |
|
|
* exceptional circumstances). Thank you for your support! *
|
22 |
|
|
* *
|
23 |
|
|
***************************************************************************
|
24 |
|
|
|
25 |
|
|
This file is part of the FreeRTOS distribution.
|
26 |
|
|
|
27 |
|
|
FreeRTOS is free software; you can redistribute it and/or modify it under
|
28 |
|
|
the terms of the GNU General Public License (version 2) as published by the
|
29 |
|
|
Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
30 |
|
|
***NOTE*** The exception to the GPL is included to allow you to distribute
|
31 |
|
|
a combined work that includes FreeRTOS without being obliged to provide the
|
32 |
|
|
source code for proprietary components outside of the FreeRTOS kernel.
|
33 |
|
|
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
34 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
35 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
36 |
|
|
more details. You should have received a copy of the GNU General Public
|
37 |
|
|
License and the FreeRTOS license exception along with FreeRTOS; if not it
|
38 |
|
|
can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
39 |
|
|
by writing to Richard Barry, contact details for whom are available on the
|
40 |
|
|
FreeRTOS WEB site.
|
41 |
|
|
|
42 |
|
|
1 tab == 4 spaces!
|
43 |
|
|
|
44 |
|
|
http://www.FreeRTOS.org - Documentation, latest information, license and
|
45 |
|
|
contact details.
|
46 |
|
|
|
47 |
|
|
http://www.SafeRTOS.com - A version that is certified for use in safety
|
48 |
|
|
critical systems.
|
49 |
|
|
|
50 |
|
|
http://www.OpenRTOS.com - Commercial support, development, porting,
|
51 |
|
|
licensing and training services.
|
52 |
|
|
*/
|
53 |
|
|
|
54 |
|
|
/*-----------------------------------------------------------
|
55 |
|
|
* Characters on the LCD are used to simulate LED's. In this case the 'ParTest'
|
56 |
|
|
* is really operating on the LCD display.
|
57 |
|
|
*-----------------------------------------------------------*/
|
58 |
|
|
|
59 |
|
|
/*
|
60 |
|
|
* This demo is configured to execute on the ES449 prototyping board from
|
61 |
|
|
* SoftBaugh. The ES449 has a built in LCD display and a single built in user
|
62 |
|
|
* LED. Therefore, in place of flashing an LED, the 'flash' and 'check' tasks
|
63 |
|
|
* toggle '*' characters on the LCD. The left most '*' represents LED 0, the
|
64 |
|
|
* next LED 1, etc.
|
65 |
|
|
*
|
66 |
|
|
* There is a single genuine on board LED referenced as LED 10.
|
67 |
|
|
*/
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
/* Scheduler includes. */
|
71 |
|
|
#include "FreeRTOS.h"
|
72 |
|
|
#include "task.h"
|
73 |
|
|
|
74 |
|
|
/* Demo application includes. */
|
75 |
|
|
#include "partest.h"
|
76 |
|
|
|
77 |
|
|
/* Constants required to setup the LCD. */
|
78 |
|
|
#define LCD_DIV_64 5
|
79 |
|
|
|
80 |
|
|
/* Constants required to access the "LED's". The LED segments are turned on
|
81 |
|
|
and off to generate '*' characters. */
|
82 |
|
|
#define partstNUM_LEDS ( ( unsigned char ) 6 )
|
83 |
|
|
#define partstSEGMENTS_ON ( ( unsigned char ) 0x0f )
|
84 |
|
|
#define partstSEGMENTS_OFF ( ( unsigned char ) 0x00 )
|
85 |
|
|
|
86 |
|
|
/* The LED number of the real on board LED, rather than a simulated LED. */
|
87 |
|
|
#define partstON_BOARD_LED ( ( unsigned portBASE_TYPE ) 10 )
|
88 |
|
|
#define mainON_BOARD_LED_BIT ( ( unsigned char ) 0x01 )
|
89 |
|
|
|
90 |
|
|
/* The LCD segments used to generate the '*' characters for LED's 0 to 5. */
|
91 |
|
|
unsigned char * const ucRHSSegments[ partstNUM_LEDS ] = { ( unsigned char * )0xa4,
|
92 |
|
|
( unsigned char * )0xa2,
|
93 |
|
|
( unsigned char * )0xa0,
|
94 |
|
|
( unsigned char * )0x9e,
|
95 |
|
|
( unsigned char * )0x9c,
|
96 |
|
|
( unsigned char * )0x9a };
|
97 |
|
|
|
98 |
|
|
unsigned char * const ucLHSSegments[ partstNUM_LEDS ] = { ( unsigned char * )0xa3,
|
99 |
|
|
( unsigned char * )0xa1,
|
100 |
|
|
( unsigned char * )0x9f,
|
101 |
|
|
( unsigned char * )0x9d,
|
102 |
|
|
( unsigned char * )0x9b,
|
103 |
|
|
( unsigned char * )0x99 };
|
104 |
|
|
|
105 |
|
|
/*
|
106 |
|
|
* Toggle the single genuine built in LED.
|
107 |
|
|
*/
|
108 |
|
|
static void prvToggleOnBoardLED( void );
|
109 |
|
|
|
110 |
|
|
/*-----------------------------------------------------------*/
|
111 |
|
|
|
112 |
|
|
void vParTestInitialise( void )
|
113 |
|
|
{
|
114 |
|
|
/* Initialise the LCD hardware. */
|
115 |
|
|
|
116 |
|
|
/* Used for the onboard LED. */
|
117 |
|
|
P1DIR = 0x01;
|
118 |
|
|
|
119 |
|
|
// Setup Basic Timer for LCD operation
|
120 |
|
|
BTCTL = (LCD_DIV_64+0x23);
|
121 |
|
|
|
122 |
|
|
// Setup port functions
|
123 |
|
|
P1SEL = 0x32;
|
124 |
|
|
P2SEL = 0x00;
|
125 |
|
|
P3SEL = 0x00;
|
126 |
|
|
P4SEL = 0xFC;
|
127 |
|
|
P5SEL = 0xFF;
|
128 |
|
|
|
129 |
|
|
/* Initialise all segments to off. */
|
130 |
|
|
LCDM1 = partstSEGMENTS_OFF;
|
131 |
|
|
LCDM2 = partstSEGMENTS_OFF;
|
132 |
|
|
LCDM3 = partstSEGMENTS_OFF;
|
133 |
|
|
LCDM4 = partstSEGMENTS_OFF;
|
134 |
|
|
LCDM5 = partstSEGMENTS_OFF;
|
135 |
|
|
LCDM6 = partstSEGMENTS_OFF;
|
136 |
|
|
LCDM7 = partstSEGMENTS_OFF;
|
137 |
|
|
LCDM8 = partstSEGMENTS_OFF;
|
138 |
|
|
LCDM9 = partstSEGMENTS_OFF;
|
139 |
|
|
LCDM10 = partstSEGMENTS_OFF;
|
140 |
|
|
LCDM11 = partstSEGMENTS_OFF;
|
141 |
|
|
LCDM12 = partstSEGMENTS_OFF;
|
142 |
|
|
LCDM13 = partstSEGMENTS_OFF;
|
143 |
|
|
LCDM14 = partstSEGMENTS_OFF;
|
144 |
|
|
LCDM15 = partstSEGMENTS_OFF;
|
145 |
|
|
LCDM16 = partstSEGMENTS_OFF;
|
146 |
|
|
LCDM17 = partstSEGMENTS_OFF;
|
147 |
|
|
LCDM18 = partstSEGMENTS_OFF;
|
148 |
|
|
LCDM19 = partstSEGMENTS_OFF;
|
149 |
|
|
LCDM20 = partstSEGMENTS_OFF;
|
150 |
|
|
|
151 |
|
|
/* Setup LCD control. */
|
152 |
|
|
LCDCTL = (LCDSG0_7|LCD4MUX|LCDON);
|
153 |
|
|
}
|
154 |
|
|
/*-----------------------------------------------------------*/
|
155 |
|
|
|
156 |
|
|
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
|
157 |
|
|
{
|
158 |
|
|
/* Set or clear the output [in this case show or hide the '*' character. */
|
159 |
|
|
if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )
|
160 |
|
|
{
|
161 |
|
|
vTaskSuspendAll();
|
162 |
|
|
{
|
163 |
|
|
if( xValue )
|
164 |
|
|
{
|
165 |
|
|
/* Turn on the segments required to show the '*'. */
|
166 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
167 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
168 |
|
|
}
|
169 |
|
|
else
|
170 |
|
|
{
|
171 |
|
|
/* Turn off all the segments. */
|
172 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
173 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
xTaskResumeAll();
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
/*-----------------------------------------------------------*/
|
180 |
|
|
|
181 |
|
|
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
|
182 |
|
|
{
|
183 |
|
|
if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )
|
184 |
|
|
{
|
185 |
|
|
vTaskSuspendAll();
|
186 |
|
|
{
|
187 |
|
|
/* If the '*' is already showing - hide it. If it is not already
|
188 |
|
|
showing then show it. */
|
189 |
|
|
if( *( ucRHSSegments[ uxLED ] ) )
|
190 |
|
|
{
|
191 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
192 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
193 |
|
|
}
|
194 |
|
|
else
|
195 |
|
|
{
|
196 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
197 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
xTaskResumeAll();
|
201 |
|
|
}
|
202 |
|
|
else
|
203 |
|
|
{
|
204 |
|
|
if( uxLED == partstON_BOARD_LED )
|
205 |
|
|
{
|
206 |
|
|
/* The request related to the genuine on board LED. */
|
207 |
|
|
prvToggleOnBoardLED();
|
208 |
|
|
}
|
209 |
|
|
}
|
210 |
|
|
}
|
211 |
|
|
/*-----------------------------------------------------------*/
|
212 |
|
|
|
213 |
|
|
static void prvToggleOnBoardLED( void )
|
214 |
|
|
{
|
215 |
|
|
static unsigned short sState = pdFALSE;
|
216 |
|
|
|
217 |
|
|
/* Toggle the state of the single genuine on board LED. */
|
218 |
|
|
if( sState )
|
219 |
|
|
{
|
220 |
|
|
P1OUT |= mainON_BOARD_LED_BIT;
|
221 |
|
|
}
|
222 |
|
|
else
|
223 |
|
|
{
|
224 |
|
|
P1OUT &= ~mainON_BOARD_LED_BIT;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
sState = !sState;
|
228 |
|
|
}
|
229 |
|
|
/*-----------------------------------------------------------*/
|
230 |
|
|
|
231 |
|
|
|