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