]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2368_Rowley/main.c
Ready for V5.2.0 release.
[freertos] / Demo / ARM7_LPC2368_Rowley / main.c
1 /*\r
2         FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it \r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9 \r
10         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
11         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for \r
13         more details.\r
14 \r
15         You should have received a copy of the GNU General Public License along \r
16         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
17         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
18 \r
19         A special exception to the GPL is included to allow you to distribute a \r
20         combined work that includes FreeRTOS.org without being obliged to provide\r
21         the source code for any proprietary components.  See the licensing section\r
22         of http://www.FreeRTOS.org for full details.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /* Environment includes. */\r
53 #include <targets/LPC2368.h>\r
54 \r
55 /* Scheduler includes. */\r
56 #include "FreeRTOS.h"\r
57 #include "task.h"\r
58 #include "queue.h"\r
59 #include "semphr.h"\r
60 \r
61 /* Demo app includes. */\r
62 #include "BlockQ.h"\r
63 #include "death.h"\r
64 #include "integer.h"\r
65 #include "blocktim.h"\r
66 #include "portlcd.h"\r
67 #include "flash.h"\r
68 #include "partest.h"\r
69 #include "semtest.h"\r
70 #include "PollQ.h"\r
71 \r
72 /* Demo application definitions. */\r
73 #define mainQUEUE_SIZE                                          ( 3 )\r
74 #define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
75 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )\r
76 \r
77 /* Task priorities. */\r
78 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
79 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
80 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
81 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
82 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
83 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
84 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
85 \r
86 \r
87 /*\r
88  * Checks the status of all the demo tasks then prints a message to the\r
89  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL\r
90  * depending on the status of the demo applications tasks.  A FAIL status will\r
91  * be latched.\r
92  *\r
93  * Messages are not written directly to the terminal, but passed to vPrintTask\r
94  * via a queue.\r
95  */\r
96 static void vCheckTask( void *pvParameters );\r
97 \r
98 /* \r
99  * The task that handles the uIP stack.  All TCP/IP processing is performed in\r
100  * this task.\r
101  */\r
102 extern void vuIP_Task( void *pvParameters );\r
103 \r
104 /*\r
105  * The LCD is written two by more than one task so is controlled by a \r
106  * 'gatekeeper' task.  This is the only task that is actually permitted to \r
107  * access the LCD directly.  Other tasks wanting to display a message send\r
108  * the message to the gatekeeper.\r
109  */\r
110 static void vLCDTask( void *pvParameters );\r
111 \r
112 /* The queue used to send messages to the LCD task. */\r
113 xQueueHandle xLCDQueue;\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 int main (void)\r
118 {\r
119         /* Setup the led's on the MCB2300 board */\r
120         vParTestInitialise();\r
121 \r
122         /* Create the queue used by the LCD task.  Messages for display on the LCD\r
123         are received via this queue. */\r
124         xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );\r
125 \r
126         /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/\r
127     xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
128 \r
129         /* Start the standard demo tasks. */\r
130         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
131     vCreateBlockTimeTasks();\r
132     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
133     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
134     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
135     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
136 \r
137         /* Start the tasks defined within this file/specific to this demo. */\r
138     xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
139         xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
140 \r
141         /* The suicide tasks must be created last as they need to know how many\r
142         tasks were running prior to their creation in order to ascertain whether\r
143         or not the correct/expected number of tasks are running at any given time. */\r
144     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
145 \r
146         /* Start the scheduler. */\r
147         vTaskStartScheduler();\r
148 \r
149     /* Will only get here if there was insufficient memory to create the idle\r
150     task. */\r
151         return 0; \r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 static void vCheckTask( void *pvParameters )\r
156 {\r
157 portBASE_TYPE xErrorOccurred = pdFALSE;\r
158 portTickType xLastExecutionTime;\r
159 unsigned portBASE_TYPE uxColumn = 0;\r
160 xLCDMessage xMessage;\r
161 \r
162         xLastExecutionTime = xTaskGetTickCount();\r
163 \r
164         xMessage.xColumn = 0;\r
165         xMessage.pcMessage = "PASS";\r
166 \r
167     for( ;; )\r
168         {\r
169                 /* Perform this check every mainCHECK_DELAY milliseconds. */\r
170                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );\r
171 \r
172                 /* Has an error been found in any task? */\r
173 \r
174         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
175                 {\r
176                         xErrorOccurred = pdTRUE;\r
177                 }\r
178 \r
179                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
180                 {\r
181                         xErrorOccurred = pdTRUE;\r
182                 }\r
183 \r
184         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
185         {\r
186             xErrorOccurred = pdTRUE;\r
187         }\r
188 \r
189         if( xArePollingQueuesStillRunning() != pdTRUE )\r
190         {\r
191             xErrorOccurred = pdTRUE;\r
192         }\r
193 \r
194         if( xIsCreateTaskStillRunning() != pdTRUE )\r
195         {\r
196             xErrorOccurred = pdTRUE;\r
197         }\r
198 \r
199         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
200         {\r
201             xErrorOccurred = pdTRUE;\r
202         }\r
203 \r
204         LCD_cls();\r
205         xMessage.xColumn++;\r
206         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );\r
207 \r
208         if( xErrorOccurred == pdTRUE )\r
209         {\r
210             xMessage.pcMessage = "FAIL";\r
211         }\r
212 \r
213                 /* Send the message to the LCD gatekeeper for display. */\r
214                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
215         }\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 void vLCDTask( void *pvParameters )\r
220 {\r
221 xLCDMessage xMessage;\r
222 \r
223         /* Initialise the LCD and display a startup message. */\r
224         LCD_init();\r
225         LCD_cur_off();\r
226     LCD_cls();    \r
227     LCD_gotoxy( 1, 1 );\r
228     LCD_puts( ( signed portCHAR * ) "www.FreeRTOS.org" );\r
229 \r
230         for( ;; )\r
231         {\r
232                 /* Wait for a message to arrive that requires displaying. */\r
233                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
234                 \r
235                 /* Display the message.  Print each message to a different position. */\r
236                 LCD_cls();\r
237                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );\r
238                 LCD_puts( xMessage.pcMessage );\r
239         }\r
240 \r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 /* Keep the compiler quiet. */\r
245 #include <stdio.h>\r
246 int __putchar( int c )\r
247 {\r
248     return EOF;\r
249 }\r
250 \r
251 \r
252 \r
253 \r
254 \r