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