]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_LPC2368_Rowley/main.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / ARM7_LPC2368_Rowley / main.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* Environment includes. */\r
71 #include <targets/LPC2368.h>\r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 #include "queue.h"\r
77 #include "semphr.h"\r
78 \r
79 /* Demo app includes. */\r
80 #include "BlockQ.h"\r
81 #include "death.h"\r
82 #include "integer.h"\r
83 #include "blocktim.h"\r
84 #include "portlcd.h"\r
85 #include "flash.h"\r
86 #include "partest.h"\r
87 #include "semtest.h"\r
88 #include "PollQ.h"\r
89 \r
90 /* Demo application definitions. */\r
91 #define mainQUEUE_SIZE                                          ( 3 )\r
92 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )\r
93 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )\r
94 \r
95 /* Task priorities. */\r
96 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
97 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
98 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
99 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
100 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
101 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
102 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )\r
103 \r
104 \r
105 /*\r
106  * Checks the status of all the demo tasks then prints a message to the\r
107  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL\r
108  * depending on the status of the demo applications tasks.  A FAIL status will\r
109  * be latched.\r
110  *\r
111  * Messages are not written directly to the terminal, but passed to vPrintTask\r
112  * via a queue.\r
113  */\r
114 static void vCheckTask( void *pvParameters );\r
115 \r
116 /*\r
117  * The task that handles the uIP stack.  All TCP/IP processing is performed in\r
118  * this task.\r
119  */\r
120 extern void vuIP_Task( void *pvParameters );\r
121 \r
122 /*\r
123  * The LCD is written two by more than one task so is controlled by a\r
124  * 'gatekeeper' task.  This is the only task that is actually permitted to\r
125  * access the LCD directly.  Other tasks wanting to display a message send\r
126  * the message to the gatekeeper.\r
127  */\r
128 static void vLCDTask( void *pvParameters );\r
129 \r
130 /* The queue used to send messages to the LCD task. */\r
131 QueueHandle_t xLCDQueue;\r
132 \r
133 /*-----------------------------------------------------------*/\r
134 \r
135 int main (void)\r
136 {\r
137         /* Setup the led's on the MCB2300 board */\r
138         vParTestInitialise();\r
139 \r
140         /* Create the queue used by the LCD task.  Messages for display on the LCD\r
141         are received via this queue. */\r
142         xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );\r
143 \r
144         /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/\r
145     xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
146 \r
147         /* Start the standard demo tasks - these serve no useful purpose other than\r
148         to demonstrate the FreeRTOS API being used and to test the port. */\r
149         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
150     vCreateBlockTimeTasks();\r
151     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
152     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
153     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
154     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
155 \r
156         /* Start the tasks defined within this file/specific to this demo. */\r
157     xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
158         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
159 \r
160         /* The suicide tasks must be created last as they need to know how many\r
161         tasks were running prior to their creation in order to ascertain whether\r
162         or not the correct/expected number of tasks are running at any given time. */\r
163     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
164 \r
165         /* Start the scheduler. */\r
166         vTaskStartScheduler();\r
167 \r
168     /* Will only get here if there was insufficient memory to create the idle\r
169     task. */\r
170         return 0;\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 static void vCheckTask( void *pvParameters )\r
175 {\r
176 portBASE_TYPE xErrorOccurred = pdFALSE;\r
177 TickType_t xLastExecutionTime;\r
178 unsigned portBASE_TYPE uxColumn = 0;\r
179 xLCDMessage xMessage;\r
180 \r
181         xLastExecutionTime = xTaskGetTickCount();\r
182 \r
183         xMessage.xColumn = 0;\r
184         xMessage.pcMessage = "PASS";\r
185 \r
186     for( ;; )\r
187         {\r
188                 /* Perform this check every mainCHECK_DELAY milliseconds. */\r
189                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );\r
190 \r
191                 /* Has an error been found in any task? */\r
192 \r
193         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
194                 {\r
195                         xErrorOccurred = pdTRUE;\r
196                 }\r
197 \r
198                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
199                 {\r
200                         xErrorOccurred = pdTRUE;\r
201                 }\r
202 \r
203         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
204         {\r
205             xErrorOccurred = pdTRUE;\r
206         }\r
207 \r
208         if( xArePollingQueuesStillRunning() != pdTRUE )\r
209         {\r
210             xErrorOccurred = pdTRUE;\r
211         }\r
212 \r
213         if( xIsCreateTaskStillRunning() != pdTRUE )\r
214         {\r
215             xErrorOccurred = pdTRUE;\r
216         }\r
217 \r
218         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
219         {\r
220             xErrorOccurred = pdTRUE;\r
221         }\r
222 \r
223         LCD_cls();\r
224         xMessage.xColumn++;\r
225         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );\r
226 \r
227         if( xErrorOccurred == pdTRUE )\r
228         {\r
229             xMessage.pcMessage = "FAIL";\r
230         }\r
231 \r
232                 /* Send the message to the LCD gatekeeper for display. */\r
233                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
234         }\r
235 }\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 void vLCDTask( void *pvParameters )\r
239 {\r
240 xLCDMessage xMessage;\r
241 \r
242         /* Initialise the LCD and display a startup message. */\r
243         LCD_init();\r
244         LCD_cur_off();\r
245     LCD_cls();\r
246     LCD_gotoxy( 1, 1 );\r
247     LCD_puts( ( signed char * ) "www.FreeRTOS.org" );\r
248 \r
249         for( ;; )\r
250         {\r
251                 /* Wait for a message to arrive that requires displaying. */\r
252                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
253 \r
254                 /* Display the message.  Print each message to a different position. */\r
255                 LCD_cls();\r
256                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );\r
257                 LCD_puts( xMessage.pcMessage );\r
258         }\r
259 \r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 /* Keep the compiler quiet. */\r
264 #include <stdio.h>\r
265 int __putchar( int c )\r
266 {\r
267     return EOF;\r
268 }\r
269 \r
270 \r
271 \r
272 \r
273 \r