2 FreeRTOS.org V5.3.1 - 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
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\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
53 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
54 * documentation provides more details of the standard demo application tasks.
\r
55 * In addition to the standard demo tasks, the following tasks and tests are
\r
56 * defined and/or created within this file:
\r
58 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
59 * is permitted to access the display directly. Other tasks wishing to write a
\r
60 * message to the LCD send the message on a queue to the LCD task instead of
\r
61 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
62 * for messages - waking and displaying the messages as they arrive.
\r
64 * "Check" hook - This only executes every five seconds from the tick hook.
\r
65 * Its main function is to check that all the standard demo tasks are still
\r
66 * operational. Should any unexpected behaviour within a demo task be discovered
\r
67 * the tick hook will write an error to the LCD (via the LCD task). If all the
\r
68 * demo tasks are executing with their expected behaviour then the check task
\r
69 * writes PASS to the LCD (again via the LCD task), as described above.
\r
71 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
72 * processing is performed in this task.
\r
75 /* Scheduler includes. */
\r
76 #include "FreeRTOS.h"
\r
81 /* Demo app includes. */
\r
84 #include "blocktim.h"
\r
85 #include "LCD/portlcd.h"
\r
87 #include "partest.h"
\r
88 #include "GenQTest.h"
\r
90 #include "dynamic.h"
\r
92 /* Demo application definitions. */
\r
93 #define mainQUEUE_SIZE ( 3 )
\r
94 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
95 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
97 /* Task priorities. */
\r
98 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
99 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
100 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
101 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
103 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
105 /* Constants to setup the PLL. */
\r
106 #define mainPLL_MUL ( ( unsigned portLONG ) ( 8 - 1 ) )
\r
107 #define mainPLL_DIV ( ( unsigned portLONG ) 0x0000 )
\r
108 #define mainCPU_CLK_DIV ( ( unsigned portLONG ) 0x0003 )
\r
109 #define mainPLL_ENABLE ( ( unsigned portLONG ) 0x0001 )
\r
110 #define mainPLL_CONNECT ( ( ( unsigned portLONG ) 0x0002 ) | mainPLL_ENABLE )
\r
111 #define mainPLL_FEED_BYTE1 ( ( unsigned portLONG ) 0xaa )
\r
112 #define mainPLL_FEED_BYTE2 ( ( unsigned portLONG ) 0x55 )
\r
113 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x4000000 )
\r
114 #define mainPLL_CONNECTED ( ( unsigned portLONG ) 0x2000000 )
\r
115 #define mainOSC_ENABLE ( ( unsigned portLONG ) 0x20 )
\r
116 #define mainOSC_STAT ( ( unsigned portLONG ) 0x40 )
\r
117 #define mainOSC_SELECT ( ( unsigned portLONG ) 0x01 )
\r
119 /* Constants to setup the MAM. */
\r
120 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
121 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
124 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
127 extern void vuIP_Task( void *pvParameters );
\r
130 * The LCD is written two by more than one task so is controlled by a
\r
131 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
132 * access the LCD directly. Other tasks wanting to display a message send
\r
133 * the message to the gatekeeper.
\r
135 static void vLCDTask( void *pvParameters );
\r
137 /* Configure the hardware as required by the demo. */
\r
138 static void prvSetupHardware( void );
\r
140 /* The queue used to send messages to the LCD task. */
\r
141 xQueueHandle xLCDQueue;
\r
143 /*-----------------------------------------------------------*/
\r
147 prvSetupHardware();
\r
149 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
150 are received via this queue. */
\r
151 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
153 /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/
\r
154 xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
156 /* Start the standard demo tasks. */
\r
157 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
158 vCreateBlockTimeTasks();
\r
159 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
160 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
161 vStartQueuePeekTasks();
\r
162 vStartDynamicPriorityTasks();
\r
164 /* Start the tasks defined within this file/specific to this demo. */
\r
165 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
167 /* Start the scheduler. */
\r
168 vTaskStartScheduler();
\r
170 /* Will only get here if there was insufficient memory to create the idle
\r
174 /*-----------------------------------------------------------*/
\r
176 void vApplicationTickHook( void )
\r
178 unsigned portBASE_TYPE uxColumn = 0;
\r
179 static xLCDMessage xMessage = { 0, "PASS" };
\r
180 static unsigned portLONG ulTicksSinceLastDisplay = 0;
\r
181 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
183 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
184 time to perform our health status check again? */
\r
185 ulTicksSinceLastDisplay++;
\r
186 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
188 ulTicksSinceLastDisplay = 0;
\r
190 /* Has an error been found in any task? */
\r
192 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
194 xMessage.pcMessage = "ERROR - BLOCKQ";
\r
197 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
199 xMessage.pcMessage = "ERROR - BLOCKTIM";
\r
202 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
204 xMessage.pcMessage = "ERROR - GENQ";
\r
207 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
209 xMessage.pcMessage = "ERROR - PEEKQ";
\r
212 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
214 xMessage.pcMessage = "ERROR - DYNAMIC";
\r
217 xMessage.xColumn++;
\r
219 /* Send the message to the LCD gatekeeper for display. */
\r
220 xHigherPriorityTaskWoken = pdFALSE;
\r
221 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
224 /*-----------------------------------------------------------*/
\r
226 void vLCDTask( void *pvParameters )
\r
228 xLCDMessage xMessage;
\r
230 /* Initialise the LCD and display a startup message. */
\r
234 LCD_gotoxy( 1, 1 );
\r
235 LCD_puts( "www.FreeRTOS.org" );
\r
239 /* Wait for a message to arrive that requires displaying. */
\r
240 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
242 /* Display the message. Print each message to a different position. */
\r
244 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
245 LCD_puts( xMessage.pcMessage );
\r
249 /*-----------------------------------------------------------*/
\r
251 static void prvSetupHardware( void )
\r
253 #ifdef RUN_FROM_RAM
\r
254 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
258 /* Disable the PLL. */
\r
260 PLLFEED = mainPLL_FEED_BYTE1;
\r
261 PLLFEED = mainPLL_FEED_BYTE2;
\r
263 /* Configure clock source. */
\r
264 SCS |= mainOSC_ENABLE;
\r
265 while( !( SCS & mainOSC_STAT ) );
\r
266 CLKSRCSEL = mainOSC_SELECT;
\r
268 /* Setup the PLL to multiply the XTAL input by 4. */
\r
269 PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
\r
270 PLLFEED = mainPLL_FEED_BYTE1;
\r
271 PLLFEED = mainPLL_FEED_BYTE2;
\r
273 /* Turn on and wait for the PLL to lock... */
\r
274 PLLCON = mainPLL_ENABLE;
\r
275 PLLFEED = mainPLL_FEED_BYTE1;
\r
276 PLLFEED = mainPLL_FEED_BYTE2;
\r
277 CCLKCFG = mainCPU_CLK_DIV;
\r
278 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
280 /* Connecting the clock. */
\r
281 PLLCON = mainPLL_CONNECT;
\r
282 PLLFEED = mainPLL_FEED_BYTE1;
\r
283 PLLFEED = mainPLL_FEED_BYTE2;
\r
284 while( !( PLLSTAT & mainPLL_CONNECTED ) );
\r
287 This code is commented out as the MAM does not work on the original revision
\r
288 LPC2368 chips. If using Rev B chips then you can increase the speed though
\r
289 the use of the MAM.
\r
291 Setup and turn on the MAM. Three cycle access is used due to the fast
\r
292 PLL used. It is possible faster overall performance could be obtained by
\r
293 tuning the MAM and PLL settings.
\r
295 MAMTIM = mainMAM_TIM_3;
\r
296 MAMCR = mainMAM_MODE_FULL;
\r
299 /* Setup the led's on the MCB2300 board */
\r
300 vParTestInitialise();
\r