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