2 FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 /* Environment includes. */
\r
53 #include <targets/LPC2368.h>
\r
55 /* Scheduler includes. */
\r
56 #include "FreeRTOS.h"
\r
61 /* Demo app includes. */
\r
64 #include "integer.h"
\r
65 #include "blocktim.h"
\r
66 #include "portlcd.h"
\r
68 #include "partest.h"
\r
69 #include "semtest.h"
\r
72 /* Demo application definitions. */
\r
73 #define mainQUEUE_SIZE ( 3 )
\r
74 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
75 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
77 /* Task priorities. */
\r
78 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
79 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
80 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
81 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
82 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
83 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
84 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
88 * Checks the status of all the demo tasks then prints a message to the
\r
89 * CrossStudio terminal IO windows. The message will be either PASS or FAIL
\r
90 * depending on the status of the demo applications tasks. A FAIL status will
\r
93 * Messages are not written directly to the terminal, but passed to vPrintTask
\r
96 static void vCheckTask( void *pvParameters );
\r
99 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
102 extern void vuIP_Task( void *pvParameters );
\r
105 * The LCD is written two by more than one task so is controlled by a
\r
106 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
107 * access the LCD directly. Other tasks wanting to display a message send
\r
108 * the message to the gatekeeper.
\r
110 static void vLCDTask( void *pvParameters );
\r
112 /* The queue used to send messages to the LCD task. */
\r
113 xQueueHandle xLCDQueue;
\r
115 /*-----------------------------------------------------------*/
\r
119 /* Setup the led's on the MCB2300 board */
\r
120 vParTestInitialise();
\r
122 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
123 are received via this queue. */
\r
124 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
126 /* Create the lwIP task. This uses the lwIP RTOS abstraction layer.*/
\r
127 xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
129 /* Start the standard demo tasks. */
\r
130 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
131 vCreateBlockTimeTasks();
\r
132 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
133 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
134 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
135 vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
\r
137 /* Start the tasks defined within this file/specific to this demo. */
\r
138 xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
139 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
141 /* The suicide tasks must be created last as they need to know how many
\r
142 tasks were running prior to their creation in order to ascertain whether
\r
143 or not the correct/expected number of tasks are running at any given time. */
\r
144 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
146 /* Start the scheduler. */
\r
147 vTaskStartScheduler();
\r
149 /* Will only get here if there was insufficient memory to create the idle
\r
153 /*-----------------------------------------------------------*/
\r
155 static void vCheckTask( void *pvParameters )
\r
157 portBASE_TYPE xErrorOccurred = pdFALSE;
\r
158 portTickType xLastExecutionTime;
\r
159 unsigned portBASE_TYPE uxColumn = 0;
\r
160 xLCDMessage xMessage;
\r
162 xLastExecutionTime = xTaskGetTickCount();
\r
164 xMessage.xColumn = 0;
\r
165 xMessage.pcMessage = "PASS";
\r
169 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
170 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
\r
172 /* Has an error been found in any task? */
\r
174 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
176 xErrorOccurred = pdTRUE;
\r
179 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
181 xErrorOccurred = pdTRUE;
\r
184 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
186 xErrorOccurred = pdTRUE;
\r
189 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
191 xErrorOccurred = pdTRUE;
\r
194 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
196 xErrorOccurred = pdTRUE;
\r
199 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
201 xErrorOccurred = pdTRUE;
\r
205 xMessage.xColumn++;
\r
206 LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );
\r
208 if( xErrorOccurred == pdTRUE )
\r
210 xMessage.pcMessage = "FAIL";
\r
213 /* Send the message to the LCD gatekeeper for display. */
\r
214 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
217 /*-----------------------------------------------------------*/
\r
219 void vLCDTask( void *pvParameters )
\r
221 xLCDMessage xMessage;
\r
223 /* Initialise the LCD and display a startup message. */
\r
227 LCD_gotoxy( 1, 1 );
\r
228 LCD_puts( ( signed portCHAR * ) "www.FreeRTOS.org" );
\r
232 /* Wait for a message to arrive that requires displaying. */
\r
233 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
235 /* Display the message. Print each message to a different position. */
\r
237 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
238 LCD_puts( xMessage.pcMessage );
\r
242 /*-----------------------------------------------------------*/
\r
244 /* Keep the compiler quiet. */
\r
246 int __putchar( int c )
\r