2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\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
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
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
26 ***************************************************************************
\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
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
50 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
51 * documentation provides more details of the standard demo application tasks.
\r
52 * In addition to the standard demo tasks, the following tasks and tests are
\r
53 * defined and/or created within this file:
\r
55 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
56 * is permitted to access the display directly. Other tasks wishing to write a
\r
57 * message to the LCD send the message on a queue to the LCD task instead of
\r
58 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
59 * for messages - waking and displaying the messages as they arrive.
\r
61 * "Check" hook - This only executes every five seconds from the tick hook.
\r
62 * Its main function is to check that all the standard demo tasks are still
\r
63 * operational. Should any unexpected behaviour within a demo task be discovered
\r
64 * the tick hook will write an error to the LCD (via the LCD task). If all the
\r
65 * demo tasks are executing with their expected behaviour then the check task
\r
66 * writes PASS to the LCD (again via the LCD task), as described above.
\r
68 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
69 * processing is performed in this task.
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
78 /* Demo app includes. */
\r
81 #include "blocktim.h"
\r
82 #include "LCD/portlcd.h"
\r
84 #include "partest.h"
\r
85 #include "GenQTest.h"
\r
87 #include "dynamic.h"
\r
89 /* Demo application definitions. */
\r
90 #define mainQUEUE_SIZE ( 3 )
\r
91 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
92 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
94 /* Task priorities. */
\r
95 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
97 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
98 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
99 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
100 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
102 /* Constants to setup the PLL. */
\r
103 #define mainPLL_MUL ( ( unsigned portLONG ) ( 8 - 1 ) )
\r
104 #define mainPLL_DIV ( ( unsigned portLONG ) 0x0000 )
\r
105 #define mainCPU_CLK_DIV ( ( unsigned portLONG ) 0x0003 )
\r
106 #define mainPLL_ENABLE ( ( unsigned portLONG ) 0x0001 )
\r
107 #define mainPLL_CONNECT ( ( ( unsigned portLONG ) 0x0002 ) | mainPLL_ENABLE )
\r
108 #define mainPLL_FEED_BYTE1 ( ( unsigned portLONG ) 0xaa )
\r
109 #define mainPLL_FEED_BYTE2 ( ( unsigned portLONG ) 0x55 )
\r
110 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x4000000 )
\r
111 #define mainPLL_CONNECTED ( ( unsigned portLONG ) 0x2000000 )
\r
112 #define mainOSC_ENABLE ( ( unsigned portLONG ) 0x20 )
\r
113 #define mainOSC_STAT ( ( unsigned portLONG ) 0x40 )
\r
114 #define mainOSC_SELECT ( ( unsigned portLONG ) 0x01 )
\r
116 /* Constants to setup the MAM. */
\r
117 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
118 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
121 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
124 extern void vuIP_Task( void *pvParameters );
\r
127 * The LCD is written two by more than one task so is controlled by a
\r
128 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
129 * access the LCD directly. Other tasks wanting to display a message send
\r
130 * the message to the gatekeeper.
\r
132 static void vLCDTask( void *pvParameters );
\r
134 /* Configure the hardware as required by the demo. */
\r
135 static void prvSetupHardware( void );
\r
137 /* The queue used to send messages to the LCD task. */
\r
138 xQueueHandle xLCDQueue;
\r
140 /*-----------------------------------------------------------*/
\r
144 prvSetupHardware();
\r
146 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
147 are received via this queue. */
\r
148 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
150 /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/
\r
151 xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
153 /* Start the standard demo tasks. */
\r
154 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
155 vCreateBlockTimeTasks();
\r
156 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
157 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
158 vStartQueuePeekTasks();
\r
159 vStartDynamicPriorityTasks();
\r
161 /* Start the tasks defined within this file/specific to this demo. */
\r
162 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
164 /* Start the scheduler. */
\r
165 vTaskStartScheduler();
\r
167 /* Will only get here if there was insufficient memory to create the idle
\r
171 /*-----------------------------------------------------------*/
\r
173 void vApplicationTickHook( void )
\r
175 unsigned portBASE_TYPE uxColumn = 0;
\r
176 static xLCDMessage xMessage = { 0, "PASS" };
\r
177 static unsigned portLONG ulTicksSinceLastDisplay = 0;
\r
178 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
180 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
181 time to perform our health status check again? */
\r
182 ulTicksSinceLastDisplay++;
\r
183 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
185 ulTicksSinceLastDisplay = 0;
\r
187 /* Has an error been found in any task? */
\r
189 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
191 xMessage.pcMessage = "ERROR - BLOCKQ";
\r
194 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
196 xMessage.pcMessage = "ERROR - BLOCKTIM";
\r
199 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
201 xMessage.pcMessage = "ERROR - GENQ";
\r
204 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
206 xMessage.pcMessage = "ERROR - PEEKQ";
\r
209 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
211 xMessage.pcMessage = "ERROR - DYNAMIC";
\r
214 xMessage.xColumn++;
\r
216 /* Send the message to the LCD gatekeeper for display. */
\r
217 xHigherPriorityTaskWoken = pdFALSE;
\r
218 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
221 /*-----------------------------------------------------------*/
\r
223 void vLCDTask( void *pvParameters )
\r
225 xLCDMessage xMessage;
\r
227 /* Initialise the LCD and display a startup message. */
\r
231 LCD_gotoxy( 1, 1 );
\r
232 LCD_puts( "www.FreeRTOS.org" );
\r
236 /* Wait for a message to arrive that requires displaying. */
\r
237 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
239 /* Display the message. Print each message to a different position. */
\r
241 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
242 LCD_puts( xMessage.pcMessage );
\r
246 /*-----------------------------------------------------------*/
\r
248 static void prvSetupHardware( void )
\r
250 #ifdef RUN_FROM_RAM
\r
251 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
255 /* Disable the PLL. */
\r
257 PLLFEED = mainPLL_FEED_BYTE1;
\r
258 PLLFEED = mainPLL_FEED_BYTE2;
\r
260 /* Configure clock source. */
\r
261 SCS |= mainOSC_ENABLE;
\r
262 while( !( SCS & mainOSC_STAT ) );
\r
263 CLKSRCSEL = mainOSC_SELECT;
\r
265 /* Setup the PLL to multiply the XTAL input by 4. */
\r
266 PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
\r
267 PLLFEED = mainPLL_FEED_BYTE1;
\r
268 PLLFEED = mainPLL_FEED_BYTE2;
\r
270 /* Turn on and wait for the PLL to lock... */
\r
271 PLLCON = mainPLL_ENABLE;
\r
272 PLLFEED = mainPLL_FEED_BYTE1;
\r
273 PLLFEED = mainPLL_FEED_BYTE2;
\r
274 CCLKCFG = mainCPU_CLK_DIV;
\r
275 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
277 /* Connecting the clock. */
\r
278 PLLCON = mainPLL_CONNECT;
\r
279 PLLFEED = mainPLL_FEED_BYTE1;
\r
280 PLLFEED = mainPLL_FEED_BYTE2;
\r
281 while( !( PLLSTAT & mainPLL_CONNECTED ) );
\r
284 This code is commented out as the MAM does not work on the original revision
\r
285 LPC2368 chips. If using Rev B chips then you can increase the speed though
\r
286 the use of the MAM.
\r
288 Setup and turn on the MAM. Three cycle access is used due to the fast
\r
289 PLL used. It is possible faster overall performance could be obtained by
\r
290 tuning the MAM and PLL settings.
\r
292 MAMTIM = mainMAM_TIM_3;
\r
293 MAMCR = mainMAM_MODE_FULL;
\r
296 /* Setup the led's on the MCB2300 board */
\r
297 vParTestInitialise();
\r