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