2 FreeRTOS V8.1.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the standard demo application tasks.
\r
69 * In addition to the standard demo tasks, the following tasks and tests are
\r
70 * defined and/or created within this file:
\r
72 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
73 * is permitted to access the display directly. Other tasks wishing to write a
\r
74 * message to the LCD send the message on a queue to the LCD task instead of
\r
75 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
76 * for messages - waking and displaying the messages as they arrive.
\r
78 * "Check" hook - This only executes every five seconds from the tick hook.
\r
79 * Its main function is to check that all the standard demo tasks are still
\r
80 * operational. Should any unexpected behaviour within a demo task be discovered
\r
81 * the tick hook will write an error to the LCD (via the LCD task). If all the
\r
82 * demo tasks are executing with their expected behaviour then the check task
\r
83 * writes PASS to the LCD (again via the LCD task), as described above.
\r
85 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
86 * processing is performed in this task.
\r
89 /* Scheduler includes. */
\r
90 #include "FreeRTOS.h"
\r
95 /* Demo app includes. */
\r
98 #include "blocktim.h"
\r
99 #include "LCD/portlcd.h"
\r
101 #include "partest.h"
\r
102 #include "GenQTest.h"
\r
104 #include "dynamic.h"
\r
106 /* Demo application definitions. */
\r
107 #define mainQUEUE_SIZE ( 3 )
\r
108 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
109 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
111 /* Task priorities. */
\r
112 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
113 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
114 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
115 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
116 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
117 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
119 /* Constants to setup the PLL. */
\r
120 #define mainPLL_MUL ( ( unsigned long ) ( 8 - 1 ) )
\r
121 #define mainPLL_DIV ( ( unsigned long ) 0x0000 )
\r
122 #define mainCPU_CLK_DIV ( ( unsigned long ) 0x0003 )
\r
123 #define mainPLL_ENABLE ( ( unsigned long ) 0x0001 )
\r
124 #define mainPLL_CONNECT ( ( ( unsigned long ) 0x0002 ) | mainPLL_ENABLE )
\r
125 #define mainPLL_FEED_BYTE1 ( ( unsigned long ) 0xaa )
\r
126 #define mainPLL_FEED_BYTE2 ( ( unsigned long ) 0x55 )
\r
127 #define mainPLL_LOCK ( ( unsigned long ) 0x4000000 )
\r
128 #define mainPLL_CONNECTED ( ( unsigned long ) 0x2000000 )
\r
129 #define mainOSC_ENABLE ( ( unsigned long ) 0x20 )
\r
130 #define mainOSC_STAT ( ( unsigned long ) 0x40 )
\r
131 #define mainOSC_SELECT ( ( unsigned long ) 0x01 )
\r
133 /* Constants to setup the MAM. */
\r
134 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
135 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
138 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
141 extern void vuIP_Task( void *pvParameters );
\r
144 * The LCD is written two by more than one task so is controlled by a
\r
145 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
146 * access the LCD directly. Other tasks wanting to display a message send
\r
147 * the message to the gatekeeper.
\r
149 static void vLCDTask( void *pvParameters );
\r
151 /* Configure the hardware as required by the demo. */
\r
152 static void prvSetupHardware( void );
\r
154 /* The queue used to send messages to the LCD task. */
\r
155 QueueHandle_t xLCDQueue;
\r
157 /*-----------------------------------------------------------*/
\r
161 prvSetupHardware();
\r
163 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
164 are received via this queue. */
\r
165 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
167 /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/
\r
168 xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
170 /* Start the standard demo tasks. */
\r
171 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
172 vCreateBlockTimeTasks();
\r
173 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
174 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
175 vStartQueuePeekTasks();
\r
176 vStartDynamicPriorityTasks();
\r
178 /* Start the tasks defined within this file/specific to this demo. */
\r
179 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
181 /* Start the scheduler. */
\r
182 vTaskStartScheduler();
\r
184 /* Will only get here if there was insufficient memory to create the idle
\r
188 /*-----------------------------------------------------------*/
\r
190 void vApplicationTickHook( void )
\r
192 unsigned portBASE_TYPE uxColumn = 0;
\r
193 static xLCDMessage xMessage = { 0, "PASS" };
\r
194 static unsigned long ulTicksSinceLastDisplay = 0;
\r
195 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
197 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
198 time to perform our health status check again? */
\r
199 ulTicksSinceLastDisplay++;
\r
200 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
202 ulTicksSinceLastDisplay = 0;
\r
204 /* Has an error been found in any task? */
\r
206 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
208 xMessage.pcMessage = "ERROR - BLOCKQ";
\r
211 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
213 xMessage.pcMessage = "ERROR - BLOCKTIM";
\r
216 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
218 xMessage.pcMessage = "ERROR - GENQ";
\r
221 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
223 xMessage.pcMessage = "ERROR - PEEKQ";
\r
226 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
228 xMessage.pcMessage = "ERROR - DYNAMIC";
\r
231 xMessage.xColumn++;
\r
233 /* Send the message to the LCD gatekeeper for display. */
\r
234 xHigherPriorityTaskWoken = pdFALSE;
\r
235 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
238 /*-----------------------------------------------------------*/
\r
240 void vLCDTask( void *pvParameters )
\r
242 xLCDMessage xMessage;
\r
244 /* Initialise the LCD and display a startup message. */
\r
248 LCD_gotoxy( 1, 1 );
\r
249 LCD_puts( "www.FreeRTOS.org" );
\r
253 /* Wait for a message to arrive that requires displaying. */
\r
254 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
256 /* Display the message. Print each message to a different position. */
\r
258 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
259 LCD_puts( xMessage.pcMessage );
\r
263 /*-----------------------------------------------------------*/
\r
265 static void prvSetupHardware( void )
\r
267 #ifdef RUN_FROM_RAM
\r
268 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
272 /* Disable the PLL. */
\r
274 PLLFEED = mainPLL_FEED_BYTE1;
\r
275 PLLFEED = mainPLL_FEED_BYTE2;
\r
277 /* Configure clock source. */
\r
278 SCS |= mainOSC_ENABLE;
\r
279 while( !( SCS & mainOSC_STAT ) );
\r
280 CLKSRCSEL = mainOSC_SELECT;
\r
282 /* Setup the PLL to multiply the XTAL input by 4. */
\r
283 PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
\r
284 PLLFEED = mainPLL_FEED_BYTE1;
\r
285 PLLFEED = mainPLL_FEED_BYTE2;
\r
287 /* Turn on and wait for the PLL to lock... */
\r
288 PLLCON = mainPLL_ENABLE;
\r
289 PLLFEED = mainPLL_FEED_BYTE1;
\r
290 PLLFEED = mainPLL_FEED_BYTE2;
\r
291 CCLKCFG = mainCPU_CLK_DIV;
\r
292 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
294 /* Connecting the clock. */
\r
295 PLLCON = mainPLL_CONNECT;
\r
296 PLLFEED = mainPLL_FEED_BYTE1;
\r
297 PLLFEED = mainPLL_FEED_BYTE2;
\r
298 while( !( PLLSTAT & mainPLL_CONNECTED ) );
\r
301 This code is commented out as the MAM does not work on the original revision
\r
302 LPC2368 chips. If using Rev B chips then you can increase the speed though
\r
303 the use of the MAM.
\r
305 Setup and turn on the MAM. Three cycle access is used due to the fast
\r
306 PLL used. It is possible faster overall performance could be obtained by
\r
307 tuning the MAM and PLL settings.
\r
309 MAMTIM = mainMAM_TIM_3;
\r
310 MAMCR = mainMAM_MODE_FULL;
\r
313 /* Setup the led's on the MCB2300 board */
\r
314 vParTestInitialise();
\r