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 |
/* Environment includes. */ |
---|
49 |
#include <targets/LPC2368.h> |
---|
50 |
|
---|
51 |
/* Scheduler includes. */ |
---|
52 |
#include "FreeRTOS.h" |
---|
53 |
#include "task.h" |
---|
54 |
#include "queue.h" |
---|
55 |
#include "semphr.h" |
---|
56 |
|
---|
57 |
/* Demo app includes. */ |
---|
58 |
#include "BlockQ.h" |
---|
59 |
#include "death.h" |
---|
60 |
#include "integer.h" |
---|
61 |
#include "blocktim.h" |
---|
62 |
#include "portlcd.h" |
---|
63 |
#include "flash.h" |
---|
64 |
#include "partest.h" |
---|
65 |
#include "semtest.h" |
---|
66 |
#include "PollQ.h" |
---|
67 |
|
---|
68 |
/* Demo application definitions. */ |
---|
69 |
#define mainQUEUE_SIZE ( 3 ) |
---|
70 |
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS ) |
---|
71 |
#define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 ) |
---|
72 |
|
---|
73 |
/* Task priorities. */ |
---|
74 |
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 ) |
---|
75 |
#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) |
---|
76 |
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 ) |
---|
77 |
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 ) |
---|
78 |
#define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 ) |
---|
79 |
#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 ) |
---|
80 |
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY ) |
---|
81 |
|
---|
82 |
|
---|
83 |
/* |
---|
84 |
* Checks the status of all the demo tasks then prints a message to the |
---|
85 |
* CrossStudio terminal IO windows. The message will be either PASS or FAIL |
---|
86 |
* depending on the status of the demo applications tasks. A FAIL status will |
---|
87 |
* be latched. |
---|
88 |
* |
---|
89 |
* Messages are not written directly to the terminal, but passed to vPrintTask |
---|
90 |
* via a queue. |
---|
91 |
*/ |
---|
92 |
static void vCheckTask( void *pvParameters ); |
---|
93 |
|
---|
94 |
/* |
---|
95 |
* The task that handles the uIP stack. All TCP/IP processing is performed in |
---|
96 |
* this task. |
---|
97 |
*/ |
---|
98 |
extern void vuIP_Task( void *pvParameters ); |
---|
99 |
|
---|
100 |
/* |
---|
101 |
* The LCD is written two by more than one task so is controlled by a |
---|
102 |
* 'gatekeeper' task. This is the only task that is actually permitted to |
---|
103 |
* access the LCD directly. Other tasks wanting to display a message send |
---|
104 |
* the message to the gatekeeper. |
---|
105 |
*/ |
---|
106 |
static void vLCDTask( void *pvParameters ); |
---|
107 |
|
---|
108 |
/* The queue used to send messages to the LCD task. */ |
---|
109 |
xQueueHandle xLCDQueue; |
---|
110 |
|
---|
111 |
/*-----------------------------------------------------------*/ |
---|
112 |
|
---|
113 |
int main (void) |
---|
114 |
{ |
---|
115 |
/* Setup the led's on the MCB2300 board */ |
---|
116 |
vParTestInitialise(); |
---|
117 |
|
---|
118 |
/* Create the queue used by the LCD task. Messages for display on the LCD |
---|
119 |
are received via this queue. */ |
---|
120 |
xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) ); |
---|
121 |
|
---|
122 |
/* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/ |
---|
123 |
xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL ); |
---|
124 |
|
---|
125 |
/* Start the standard demo tasks. */ |
---|
126 |
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY ); |
---|
127 |
vCreateBlockTimeTasks(); |
---|
128 |
vStartLEDFlashTasks( mainFLASH_PRIORITY ); |
---|
129 |
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY ); |
---|
130 |
vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY ); |
---|
131 |
vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY ); |
---|
132 |
|
---|
133 |
/* Start the tasks defined within this file/specific to this demo. */ |
---|
134 |
xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); |
---|
135 |
xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL ); |
---|
136 |
|
---|
137 |
/* The suicide tasks must be created last as they need to know how many |
---|
138 |
tasks were running prior to their creation in order to ascertain whether |
---|
139 |
or not the correct/expected number of tasks are running at any given time. */ |
---|
140 |
vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); |
---|
141 |
|
---|
142 |
/* Start the scheduler. */ |
---|
143 |
vTaskStartScheduler(); |
---|
144 |
|
---|
145 |
/* Will only get here if there was insufficient memory to create the idle |
---|
146 |
task. */ |
---|
147 |
return 0; |
---|
148 |
} |
---|
149 |
/*-----------------------------------------------------------*/ |
---|
150 |
|
---|
151 |
static void vCheckTask( void *pvParameters ) |
---|
152 |
{ |
---|
153 |
portBASE_TYPE xErrorOccurred = pdFALSE; |
---|
154 |
portTickType xLastExecutionTime; |
---|
155 |
unsigned portBASE_TYPE uxColumn = 0; |
---|
156 |
xLCDMessage xMessage; |
---|
157 |
|
---|
158 |
xLastExecutionTime = xTaskGetTickCount(); |
---|
159 |
|
---|
160 |
xMessage.xColumn = 0; |
---|
161 |
xMessage.pcMessage = "PASS"; |
---|
162 |
|
---|
163 |
for( ;; ) |
---|
164 |
{ |
---|
165 |
/* Perform this check every mainCHECK_DELAY milliseconds. */ |
---|
166 |
vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY ); |
---|
167 |
|
---|
168 |
/* Has an error been found in any task? */ |
---|
169 |
|
---|
170 |
if( xAreBlockingQueuesStillRunning() != pdTRUE ) |
---|
171 |
{ |
---|
172 |
xErrorOccurred = pdTRUE; |
---|
173 |
} |
---|
174 |
|
---|
175 |
if( xAreBlockTimeTestTasksStillRunning() != pdTRUE ) |
---|
176 |
{ |
---|
177 |
xErrorOccurred = pdTRUE; |
---|
178 |
} |
---|
179 |
|
---|
180 |
if( xAreSemaphoreTasksStillRunning() != pdTRUE ) |
---|
181 |
{ |
---|
182 |
xErrorOccurred = pdTRUE; |
---|
183 |
} |
---|
184 |
|
---|
185 |
if( xArePollingQueuesStillRunning() != pdTRUE ) |
---|
186 |
{ |
---|
187 |
xErrorOccurred = pdTRUE; |
---|
188 |
} |
---|
189 |
|
---|
190 |
if( xIsCreateTaskStillRunning() != pdTRUE ) |
---|
191 |
{ |
---|
192 |
xErrorOccurred = pdTRUE; |
---|
193 |
} |
---|
194 |
|
---|
195 |
if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) |
---|
196 |
{ |
---|
197 |
xErrorOccurred = pdTRUE; |
---|
198 |
} |
---|
199 |
|
---|
200 |
LCD_cls(); |
---|
201 |
xMessage.xColumn++; |
---|
202 |
LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 ); |
---|
203 |
|
---|
204 |
if( xErrorOccurred == pdTRUE ) |
---|
205 |
{ |
---|
206 |
xMessage.pcMessage = "FAIL"; |
---|
207 |
} |
---|
208 |
|
---|
209 |
/* Send the message to the LCD gatekeeper for display. */ |
---|
210 |
xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY ); |
---|
211 |
} |
---|
212 |
} |
---|
213 |
/*-----------------------------------------------------------*/ |
---|
214 |
|
---|
215 |
void vLCDTask( void *pvParameters ) |
---|
216 |
{ |
---|
217 |
xLCDMessage xMessage; |
---|
218 |
|
---|
219 |
/* Initialise the LCD and display a startup message. */ |
---|
220 |
LCD_init(); |
---|
221 |
LCD_cur_off(); |
---|
222 |
LCD_cls(); |
---|
223 |
LCD_gotoxy( 1, 1 ); |
---|
224 |
LCD_puts( ( signed portCHAR * ) "www.FreeRTOS.org" ); |
---|
225 |
|
---|
226 |
for( ;; ) |
---|
227 |
{ |
---|
228 |
/* Wait for a message to arrive that requires displaying. */ |
---|
229 |
while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS ); |
---|
230 |
|
---|
231 |
/* Display the message. Print each message to a different position. */ |
---|
232 |
LCD_cls(); |
---|
233 |
LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 ); |
---|
234 |
LCD_puts( xMessage.pcMessage ); |
---|
235 |
} |
---|
236 |
|
---|
237 |
} |
---|
238 |
/*-----------------------------------------------------------*/ |
---|
239 |
|
---|
240 |
/* Keep the compiler quiet. */ |
---|
241 |
#include <stdio.h> |
---|
242 |
int __putchar( int c ) |
---|
243 |
{ |
---|
244 |
return EOF; |
---|
245 |
} |
---|
246 |
|
---|
247 |
|
---|
248 |
|
---|
249 |
|
---|
250 |
|
---|