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 |
|
|
/* Standard includes. */
|
70 |
|
|
#include <signal.h>
|
71 |
|
|
|
72 |
|
|
/* Scheduler includes. */
|
73 |
|
|
#include "FreeRTOS.h"
|
74 |
|
|
#include "task.h"
|
75 |
|
|
|
76 |
|
|
/* Demo application includes. */
|
77 |
|
|
#include "partest.h"
|
78 |
|
|
|
79 |
|
|
/* Constants required to setup the LCD. */
|
80 |
|
|
#define LCD_DIV_64 5
|
81 |
|
|
|
82 |
|
|
/* Constants required to access the "LED's". The LED segments are turned on
|
83 |
|
|
and off to generate '*' characters. */
|
84 |
|
|
#define partstNUM_LEDS ( ( unsigned char ) 6 )
|
85 |
|
|
#define partstSEGMENTS_ON ( ( unsigned char ) 0x0f )
|
86 |
|
|
#define partstSEGMENTS_OFF ( ( unsigned char ) 0x00 )
|
87 |
|
|
|
88 |
|
|
/* The LED number of the real on board LED, rather than a simulated LED. */
|
89 |
|
|
#define partstON_BOARD_LED ( ( unsigned portBASE_TYPE ) 10 )
|
90 |
|
|
#define mainON_BOARD_LED_BIT ( ( unsigned char ) 0x01 )
|
91 |
|
|
|
92 |
|
|
/* The LCD segments used to generate the '*' characters for LED's 0 to 5. */
|
93 |
|
|
unsigned char * const ucRHSSegments[ partstNUM_LEDS ] = { ( unsigned char * )0xa4,
|
94 |
|
|
( unsigned char * )0xa2,
|
95 |
|
|
( unsigned char * )0xa0,
|
96 |
|
|
( unsigned char * )0x9e,
|
97 |
|
|
( unsigned char * )0x9c,
|
98 |
|
|
( unsigned char * )0x9a };
|
99 |
|
|
|
100 |
|
|
unsigned char * const ucLHSSegments[ partstNUM_LEDS ] = { ( unsigned char * )0xa3,
|
101 |
|
|
( unsigned char * )0xa1,
|
102 |
|
|
( unsigned char * )0x9f,
|
103 |
|
|
( unsigned char * )0x9d,
|
104 |
|
|
( unsigned char * )0x9b,
|
105 |
|
|
( unsigned char * )0x99 };
|
106 |
|
|
|
107 |
|
|
/*
|
108 |
|
|
* Toggle the single genuine built in LED.
|
109 |
|
|
*/
|
110 |
|
|
static void prvToggleOnBoardLED( void );
|
111 |
|
|
|
112 |
|
|
/*-----------------------------------------------------------*/
|
113 |
|
|
|
114 |
|
|
void vParTestInitialise( void )
|
115 |
|
|
{
|
116 |
|
|
/* Initialise the LCD hardware. */
|
117 |
|
|
|
118 |
|
|
/* Used for the onboard LED. */
|
119 |
|
|
P1DIR = 0x01;
|
120 |
|
|
|
121 |
|
|
// Setup Basic Timer for LCD operation
|
122 |
|
|
BTCTL = (LCD_DIV_64+0x23);
|
123 |
|
|
|
124 |
|
|
// Setup port functions
|
125 |
|
|
P1SEL = 0x32;
|
126 |
|
|
P2SEL = 0x00;
|
127 |
|
|
P3SEL = 0x00;
|
128 |
|
|
P4SEL = 0xFC;
|
129 |
|
|
P5SEL = 0xFF;
|
130 |
|
|
|
131 |
|
|
/* Initialise all segments to off. */
|
132 |
|
|
LCDM1 = partstSEGMENTS_OFF;
|
133 |
|
|
LCDM2 = partstSEGMENTS_OFF;
|
134 |
|
|
LCDM3 = partstSEGMENTS_OFF;
|
135 |
|
|
LCDM4 = partstSEGMENTS_OFF;
|
136 |
|
|
LCDM5 = partstSEGMENTS_OFF;
|
137 |
|
|
LCDM6 = partstSEGMENTS_OFF;
|
138 |
|
|
LCDM7 = partstSEGMENTS_OFF;
|
139 |
|
|
LCDM8 = partstSEGMENTS_OFF;
|
140 |
|
|
LCDM9 = partstSEGMENTS_OFF;
|
141 |
|
|
LCDM10 = partstSEGMENTS_OFF;
|
142 |
|
|
LCDM11 = partstSEGMENTS_OFF;
|
143 |
|
|
LCDM12 = partstSEGMENTS_OFF;
|
144 |
|
|
LCDM13 = partstSEGMENTS_OFF;
|
145 |
|
|
LCDM14 = partstSEGMENTS_OFF;
|
146 |
|
|
LCDM15 = partstSEGMENTS_OFF;
|
147 |
|
|
LCDM16 = partstSEGMENTS_OFF;
|
148 |
|
|
LCDM17 = partstSEGMENTS_OFF;
|
149 |
|
|
LCDM18 = partstSEGMENTS_OFF;
|
150 |
|
|
LCDM19 = partstSEGMENTS_OFF;
|
151 |
|
|
LCDM20 = partstSEGMENTS_OFF;
|
152 |
|
|
|
153 |
|
|
/* Setup LCD control. */
|
154 |
|
|
LCDCTL = (LCDSG0_7|LCD4MUX|LCDON);
|
155 |
|
|
}
|
156 |
|
|
/*-----------------------------------------------------------*/
|
157 |
|
|
|
158 |
|
|
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
|
159 |
|
|
{
|
160 |
|
|
/* Set or clear the output [in this case show or hide the '*' character. */
|
161 |
|
|
if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )
|
162 |
|
|
{
|
163 |
|
|
vTaskSuspendAll();
|
164 |
|
|
{
|
165 |
|
|
if( xValue )
|
166 |
|
|
{
|
167 |
|
|
/* Turn on the segments required to show the '*'. */
|
168 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
169 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
170 |
|
|
}
|
171 |
|
|
else
|
172 |
|
|
{
|
173 |
|
|
/* Turn off all the segments. */
|
174 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
175 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
xTaskResumeAll();
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
/*-----------------------------------------------------------*/
|
182 |
|
|
|
183 |
|
|
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
|
184 |
|
|
{
|
185 |
|
|
if( uxLED < ( portBASE_TYPE ) partstNUM_LEDS )
|
186 |
|
|
{
|
187 |
|
|
vTaskSuspendAll();
|
188 |
|
|
{
|
189 |
|
|
/* If the '*' is already showing - hide it. If it is not already
|
190 |
|
|
showing then show it. */
|
191 |
|
|
if( *( ucRHSSegments[ uxLED ] ) )
|
192 |
|
|
{
|
193 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
194 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_OFF;
|
195 |
|
|
}
|
196 |
|
|
else
|
197 |
|
|
{
|
198 |
|
|
*( ucRHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
199 |
|
|
*( ucLHSSegments[ uxLED ] ) = partstSEGMENTS_ON;
|
200 |
|
|
}
|
201 |
|
|
}
|
202 |
|
|
xTaskResumeAll();
|
203 |
|
|
}
|
204 |
|
|
else
|
205 |
|
|
{
|
206 |
|
|
if( uxLED == partstON_BOARD_LED )
|
207 |
|
|
{
|
208 |
|
|
/* The request related to the genuine on board LED. */
|
209 |
|
|
prvToggleOnBoardLED();
|
210 |
|
|
}
|
211 |
|
|
}
|
212 |
|
|
}
|
213 |
|
|
/*-----------------------------------------------------------*/
|
214 |
|
|
|
215 |
|
|
static void prvToggleOnBoardLED( void )
|
216 |
|
|
{
|
217 |
|
|
static unsigned short sState = pdFALSE;
|
218 |
|
|
|
219 |
|
|
/* Toggle the state of the single genuine on board LED. */
|
220 |
|
|
if( sState )
|
221 |
|
|
{
|
222 |
|
|
P1OUT |= mainON_BOARD_LED_BIT;
|
223 |
|
|
}
|
224 |
|
|
else
|
225 |
|
|
{
|
226 |
|
|
P1OUT &= ~mainON_BOARD_LED_BIT;
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
sState = !sState;
|
230 |
|
|
}
|
231 |
|
|
/*-----------------------------------------------------------*/
|
232 |
|
|
|
233 |
|
|
|