2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
77 * documentation provides more details of the standard demo application tasks.
\r
78 * In addition to the standard demo tasks, the following tasks and tests are
\r
79 * defined and/or created within this file:
\r
81 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
82 * is permitted to access the display directly. Other tasks wishing to write a
\r
83 * message to the LCD send the message on a queue to the LCD task instead of
\r
84 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
85 * for messages - waking and displaying the messages as they arrive.
\r
87 * "Check" hook - This only executes every five seconds from the tick hook.
\r
88 * Its main function is to check that all the standard demo tasks are still
\r
89 * operational. Should any unexpected behaviour within a demo task be discovered
\r
90 * the tick hook will write an error to the LCD (via the LCD task). If all the
\r
91 * demo tasks are executing with their expected behaviour then the check task
\r
92 * writes PASS to the LCD (again via the LCD task), as described above.
\r
94 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
95 * processing is performed in this task.
\r
98 /* Scheduler includes. */
\r
99 #include "FreeRTOS.h"
\r
102 #include "semphr.h"
\r
104 /* Demo app includes. */
\r
105 #include "BlockQ.h"
\r
107 #include "blocktim.h"
\r
108 #include "LCD/portlcd.h"
\r
110 #include "partest.h"
\r
111 #include "GenQTest.h"
\r
113 #include "dynamic.h"
\r
115 /* Demo application definitions. */
\r
116 #define mainQUEUE_SIZE ( 3 )
\r
117 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
118 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
120 /* Task priorities. */
\r
121 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
122 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
123 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
124 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
125 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
126 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
128 /* Constants to setup the PLL. */
\r
129 #define mainPLL_MUL ( ( unsigned portLONG ) ( 8 - 1 ) )
\r
130 #define mainPLL_DIV ( ( unsigned portLONG ) 0x0000 )
\r
131 #define mainCPU_CLK_DIV ( ( unsigned portLONG ) 0x0003 )
\r
132 #define mainPLL_ENABLE ( ( unsigned portLONG ) 0x0001 )
\r
133 #define mainPLL_CONNECT ( ( ( unsigned portLONG ) 0x0002 ) | mainPLL_ENABLE )
\r
134 #define mainPLL_FEED_BYTE1 ( ( unsigned portLONG ) 0xaa )
\r
135 #define mainPLL_FEED_BYTE2 ( ( unsigned portLONG ) 0x55 )
\r
136 #define mainPLL_LOCK ( ( unsigned portLONG ) 0x4000000 )
\r
137 #define mainPLL_CONNECTED ( ( unsigned portLONG ) 0x2000000 )
\r
138 #define mainOSC_ENABLE ( ( unsigned portLONG ) 0x20 )
\r
139 #define mainOSC_STAT ( ( unsigned portLONG ) 0x40 )
\r
140 #define mainOSC_SELECT ( ( unsigned portLONG ) 0x01 )
\r
142 /* Constants to setup the MAM. */
\r
143 #define mainMAM_TIM_3 ( ( unsigned portCHAR ) 0x03 )
\r
144 #define mainMAM_MODE_FULL ( ( unsigned portCHAR ) 0x02 )
\r
147 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
150 extern void vuIP_Task( void *pvParameters );
\r
153 * The LCD is written two by more than one task so is controlled by a
\r
154 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
155 * access the LCD directly. Other tasks wanting to display a message send
\r
156 * the message to the gatekeeper.
\r
158 static void vLCDTask( void *pvParameters );
\r
160 /* Configure the hardware as required by the demo. */
\r
161 static void prvSetupHardware( void );
\r
163 /* The queue used to send messages to the LCD task. */
\r
164 xQueueHandle xLCDQueue;
\r
166 /*-----------------------------------------------------------*/
\r
170 prvSetupHardware();
\r
172 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
173 are received via this queue. */
\r
174 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
176 /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/
\r
177 xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
179 /* Start the standard demo tasks. */
\r
180 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
181 vCreateBlockTimeTasks();
\r
182 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
183 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
184 vStartQueuePeekTasks();
\r
185 vStartDynamicPriorityTasks();
\r
187 /* Start the tasks defined within this file/specific to this demo. */
\r
188 xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
190 /* Start the scheduler. */
\r
191 vTaskStartScheduler();
\r
193 /* Will only get here if there was insufficient memory to create the idle
\r
197 /*-----------------------------------------------------------*/
\r
199 void vApplicationTickHook( void )
\r
201 unsigned portBASE_TYPE uxColumn = 0;
\r
202 static xLCDMessage xMessage = { 0, "PASS" };
\r
203 static unsigned portLONG ulTicksSinceLastDisplay = 0;
\r
204 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
206 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
207 time to perform our health status check again? */
\r
208 ulTicksSinceLastDisplay++;
\r
209 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
211 ulTicksSinceLastDisplay = 0;
\r
213 /* Has an error been found in any task? */
\r
215 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
217 xMessage.pcMessage = "ERROR - BLOCKQ";
\r
220 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
222 xMessage.pcMessage = "ERROR - BLOCKTIM";
\r
225 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
227 xMessage.pcMessage = "ERROR - GENQ";
\r
230 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
232 xMessage.pcMessage = "ERROR - PEEKQ";
\r
235 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
237 xMessage.pcMessage = "ERROR - DYNAMIC";
\r
240 xMessage.xColumn++;
\r
242 /* Send the message to the LCD gatekeeper for display. */
\r
243 xHigherPriorityTaskWoken = pdFALSE;
\r
244 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
247 /*-----------------------------------------------------------*/
\r
249 void vLCDTask( void *pvParameters )
\r
251 xLCDMessage xMessage;
\r
253 /* Initialise the LCD and display a startup message. */
\r
257 LCD_gotoxy( 1, 1 );
\r
258 LCD_puts( "www.FreeRTOS.org" );
\r
262 /* Wait for a message to arrive that requires displaying. */
\r
263 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
265 /* Display the message. Print each message to a different position. */
\r
267 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
268 LCD_puts( xMessage.pcMessage );
\r
272 /*-----------------------------------------------------------*/
\r
274 static void prvSetupHardware( void )
\r
276 #ifdef RUN_FROM_RAM
\r
277 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
281 /* Disable the PLL. */
\r
283 PLLFEED = mainPLL_FEED_BYTE1;
\r
284 PLLFEED = mainPLL_FEED_BYTE2;
\r
286 /* Configure clock source. */
\r
287 SCS |= mainOSC_ENABLE;
\r
288 while( !( SCS & mainOSC_STAT ) );
\r
289 CLKSRCSEL = mainOSC_SELECT;
\r
291 /* Setup the PLL to multiply the XTAL input by 4. */
\r
292 PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
\r
293 PLLFEED = mainPLL_FEED_BYTE1;
\r
294 PLLFEED = mainPLL_FEED_BYTE2;
\r
296 /* Turn on and wait for the PLL to lock... */
\r
297 PLLCON = mainPLL_ENABLE;
\r
298 PLLFEED = mainPLL_FEED_BYTE1;
\r
299 PLLFEED = mainPLL_FEED_BYTE2;
\r
300 CCLKCFG = mainCPU_CLK_DIV;
\r
301 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
303 /* Connecting the clock. */
\r
304 PLLCON = mainPLL_CONNECT;
\r
305 PLLFEED = mainPLL_FEED_BYTE1;
\r
306 PLLFEED = mainPLL_FEED_BYTE2;
\r
307 while( !( PLLSTAT & mainPLL_CONNECTED ) );
\r
310 This code is commented out as the MAM does not work on the original revision
\r
311 LPC2368 chips. If using Rev B chips then you can increase the speed though
\r
312 the use of the MAM.
\r
314 Setup and turn on the MAM. Three cycle access is used due to the fast
\r
315 PLL used. It is possible faster overall performance could be obtained by
\r
316 tuning the MAM and PLL settings.
\r
318 MAMTIM = mainMAM_TIM_3;
\r
319 MAMCR = mainMAM_MODE_FULL;
\r
322 /* Setup the led's on the MCB2300 board */
\r
323 vParTestInitialise();
\r