2 FreeRTOS V7.3.0 - Copyright (C) 2012 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
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the standard demo application tasks.
\r
73 * In addition to the standard demo tasks, the following tasks and tests are
\r
74 * defined and/or created within this file:
\r
76 * "Web server" - Very basic demonstration of the uIP stack. The WEB server
\r
77 * simply generates a page that shows the current state of all the tasks within
\r
78 * the system, including the high water mark of each task stack. The high water
\r
79 * mark is displayed as the amount of stack that has never been used, so the
\r
80 * closer the value is to zero the closer the task has come to overflowing its
\r
81 * stack. The IP address and net mask are set within FreeRTOSConfig.h. Sub
\r
82 * pages display some TCP/IP status information and permit LED3 to be turned on
\r
83 * and off using a check box.
\r
85 * Tick hook function that implements a "Check" function - This is executed
\r
86 * every 5 seconds from the tick hook function. It checks to ensure that all
\r
87 * the standard demo tasks are still operational and running without error.
\r
88 * The system status (pass/fail) is then displayed underneith the task table on
\r
89 * the served WEB pages.
\r
91 * "Reg test" tasks - These fill the registers with known values, then check
\r
92 * that each register still contains its expected value. Each task uses
\r
93 * different values. The tasks run with very low priority so get preempted very
\r
94 * frequently. A register containing an unexpected value is indicative of an
\r
95 * error in the context switching mechanism.
\r
99 /* Standard includes. */
\r
102 /* Scheduler includes. */
\r
103 #include "FreeRTOS.h"
\r
106 #include "semphr.h"
\r
108 /* Demo app includes. */
\r
109 #include "BlockQ.h"
\r
112 #include "partest.h"
\r
113 #include "GenQTest.h"
\r
115 #include "recmutex.h"
\r
117 /*-----------------------------------------------------------*/
\r
119 /* ComTest constants - there is no free LED for the comtest tasks. */
\r
120 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
121 #define mainCOM_TEST_LED ( 5 )
\r
123 /* Task priorities. */
\r
124 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
125 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
126 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
127 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
128 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
129 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
130 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
131 #define mainWEB_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
133 /* WEB server requires enough stack for the string handling functions. */
\r
134 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
137 * Configure the hardware for the demo.
\r
139 static void prvSetupHardware( void );
\r
142 * Implements the 'check' function as described at the top of this file.
\r
144 static void prvCheckFunction( void );
\r
147 * Implement the 'Reg test' functionality as described at the top of this file.
\r
149 static void vRegTest1Task( void *pvParameters );
\r
150 static void vRegTest2Task( void *pvParameters );
\r
153 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
156 extern void vuIP_Task( void *pvParameters );
\r
158 /*-----------------------------------------------------------*/
\r
160 /* Counters used to detect errors within the reg test tasks. */
\r
161 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
\r
163 /* Flag that latches any errors detected in the system. */
\r
164 unsigned long ulCheckErrors = 0;
\r
166 /*-----------------------------------------------------------*/
\r
170 extern void vBasicWEBServer( void *pv );
\r
172 /* Setup the hardware ready for this demo. */
\r
173 prvSetupHardware();
\r
175 xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
177 /* Start the standard demo tasks. */
\r
178 vStartLEDFlashTasks( tskIDLE_PRIORITY );
\r
179 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
180 vStartQueuePeekTasks();
\r
181 vStartRecursiveMutexTasks();
\r
182 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
184 /* Start the reg test tasks - defined in this file. */
\r
185 xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
\r
186 xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
\r
188 /* Start the scheduler. */
\r
189 vTaskStartScheduler();
\r
191 /* Will only get here if there was insufficient memory to create the idle
\r
197 /*-----------------------------------------------------------*/
\r
199 void vApplicationTickHook( void )
\r
201 static unsigned long ulExecutionCount = 0, ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
\r
202 const unsigned long ulExecutionRate = 5000 / portTICK_RATE_MS;
\r
204 /* Increment the count of how many times the tick hook has been called. */
\r
205 ulExecutionCount++;
\r
207 /* Is it time to perform the check again? */
\r
208 if( ulExecutionCount >= ulExecutionRate )
\r
210 /* Reset the execution count so this function is called again in 5
\r
212 ulExecutionCount = 0;
\r
214 /* Has an error been found in any task? */
\r
215 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
217 ulCheckErrors |= 0x01UL;
\r
220 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
222 ulCheckErrors |= 0x02UL;
\r
225 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
227 ulCheckErrors |= 0x04UL;
\r
230 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
232 ulCheckErrors |= 0x200UL;
\r
235 if( ulLastRegTest1Count == ulRegTest1Counter )
\r
237 ulCheckErrors |= 0x1000UL;
\r
240 if( ulLastRegTest2Count == ulRegTest2Counter )
\r
242 ulCheckErrors |= 0x1000UL;
\r
245 ulLastRegTest1Count = ulRegTest1Counter;
\r
246 ulLastRegTest2Count = ulRegTest2Counter;
\r
249 /*-----------------------------------------------------------*/
\r
251 static void prvSetupHardware( void )
\r
253 /* Disable the watchdog, STOP and WAIT modes. */
\r
256 /* --- Setup clock to use external 25MHz source. --- */
\r
258 /* Extal and xtal pin ON. */
\r
262 /* Switch from FEI to FBE (FLL bypassed external)
\r
263 enable external clock source */
\r
264 MCGC2 = MCGC2_ERCLKEN_MASK /* Activate external reference clock */
\r
265 | MCGC2_EREFS_MASK /* Because crystal is being used */
\r
266 | MCGC2_RANGE_MASK; /* High range */
\r
268 /* Select clock mode and clear IREFs. */
\r
269 MCGC1 = (0x02 << 6 ) /* CLKS = 10 -> external reference clock. */
\r
270 | (0x04 << 3 ) /* RDIV = 2^4 -> 25MHz/16 = 1.5625 MHz */
\r
271 | MCGC1_IRCLKEN_MASK; /* IRCLK to RTC enabled */
\r
273 /* Wait for Reference and Clock status bits to update. */
\r
274 while( MCGSC_IREFST | ( MCGSC_CLKST != 0x02 ) )
\r
276 /* Nothing to do here. */
\r
279 /* Switch from FBE to PBE (PLL bypassed internal) mode. */
\r
280 MCGC3 = 0x08 /* Set PLL multi 50MHz. */
\r
281 | MCGC3_PLLS_MASK; /* Select PLL. */
\r
283 /* Wait for PLL status and lock bits to update. */
\r
284 while( !MCGSC_PLLST | !MCGSC_LOCK )
\r
286 /* Nothing to do here. */
\r
290 /* Now in PBE Mode, finally switch from PBE to PEE (PLL enabled external
\r
292 MCGC1_CLKS = 0b00; /* PLL clock to system (MCGOUT) */
\r
294 /* Wait for the clock status bits to update. */
\r
295 while( MCGSC_CLKST != 0x03 )
\r
297 /* Nothing to do here. */
\r
300 /* Setup the IO for the LED outputs. */
\r
301 vParTestInitialise();
\r
303 /*-----------------------------------------------------------*/
\r
305 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
307 /* This will get called if a stack overflow is detected during the context
\r
308 switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
\r
309 problems within nested interrupts, but only do this for debug purposes as
\r
310 it will increase the context switch time. */
\r
313 ( void ) pcTaskName;
\r
319 /*-----------------------------------------------------------*/
\r
321 static void vRegTest1Task( void *pvParameters )
\r
323 /* Just to remove compiler warnings. */
\r
324 ( void ) pvParameters;
\r
326 /* Set all the registers to known values, then check that each retains its
\r
327 expected value - as described at the top of this file. If an error is
\r
328 found then the loop counter will no longer be incremented allowing the check
\r
329 task to recognise the error. */
\r
330 asm volatile ( "reg_test_1_start: \n\t"
\r
331 " moveq #1, d0 \n\t"
\r
332 " moveq #2, d1 \n\t"
\r
333 " moveq #3, d2 \n\t"
\r
334 " moveq #4, d3 \n\t"
\r
335 " moveq #5, d4 \n\t"
\r
336 " moveq #6, d5 \n\t"
\r
337 " moveq #7, d6 \n\t"
\r
338 " moveq #8, d7 \n\t"
\r
339 " move #9, a0 \n\t"
\r
340 " move #10, a1 \n\t"
\r
341 " move #11, a2 \n\t"
\r
342 " move #12, a3 \n\t"
\r
343 " move #13, a4 \n\t"
\r
344 " move #15, a6 \n\t"
\r
346 " cmpi.l #1, d0 \n\t"
\r
347 " bne reg_test_1_error \n\t"
\r
348 " cmpi.l #2, d1 \n\t"
\r
349 " bne reg_test_1_error \n\t"
\r
350 " cmpi.l #3, d2 \n\t"
\r
351 " bne reg_test_1_error \n\t"
\r
352 " cmpi.l #4, d3 \n\t"
\r
353 " bne reg_test_1_error \n\t"
\r
354 " cmpi.l #5, d4 \n\t"
\r
355 " bne reg_test_1_error \n\t"
\r
356 " cmpi.l #6, d5 \n\t"
\r
357 " bne reg_test_1_error \n\t"
\r
358 " cmpi.l #7, d6 \n\t"
\r
359 " bne reg_test_1_error \n\t"
\r
360 " cmpi.l #8, d7 \n\t"
\r
361 " bne reg_test_1_error \n\t"
\r
362 " move a0, d0 \n\t"
\r
363 " cmpi.l #9, d0 \n\t"
\r
364 " bne reg_test_1_error \n\t"
\r
365 " move a1, d0 \n\t"
\r
366 " cmpi.l #10, d0 \n\t"
\r
367 " bne reg_test_1_error \n\t"
\r
368 " move a2, d0 \n\t"
\r
369 " cmpi.l #11, d0 \n\t"
\r
370 " bne reg_test_1_error \n\t"
\r
371 " move a3, d0 \n\t"
\r
372 " cmpi.l #12, d0 \n\t"
\r
373 " bne reg_test_1_error \n\t"
\r
374 " move a4, d0 \n\t"
\r
375 " cmpi.l #13, d0 \n\t"
\r
376 " bne reg_test_1_error \n\t"
\r
377 " move a6, d0 \n\t"
\r
378 " cmpi.l #15, d0 \n\t"
\r
379 " bne reg_test_1_error \n\t"
\r
380 " move ulRegTest1Counter, d0 \n\t"
\r
381 " addq #1, d0 \n\t"
\r
382 " move d0, ulRegTest1Counter \n\t"
\r
383 " bra reg_test_1_start \n\t"
\r
384 "reg_test_1_error: \n\t"
\r
385 " bra reg_test_1_error \n\t"
\r
388 /*-----------------------------------------------------------*/
\r
390 static void vRegTest2Task( void *pvParameters )
\r
392 /* Just to remove compiler warnings. */
\r
393 ( void ) pvParameters;
\r
395 /* Set all the registers to known values, then check that each retains its
\r
396 expected value - as described at the top of this file. If an error is
\r
397 found then the loop counter will no longer be incremented allowing the check
\r
398 task to recognise the error. */
\r
399 asm volatile ( "reg_test_2_start: \n\t"
\r
400 " moveq #10, d0 \n\t"
\r
401 " moveq #20, d1 \n\t"
\r
402 " moveq #30, d2 \n\t"
\r
403 " moveq #40, d3 \n\t"
\r
404 " moveq #50, d4 \n\t"
\r
405 " moveq #60, d5 \n\t"
\r
406 " moveq #70, d6 \n\t"
\r
407 " moveq #80, d7 \n\t"
\r
408 " move #90, a0 \n\t"
\r
409 " move #100, a1 \n\t"
\r
410 " move #110, a2 \n\t"
\r
411 " move #120, a3 \n\t"
\r
412 " move #130, a4 \n\t"
\r
413 " move #150, a6 \n\t"
\r
415 " cmpi.l #10, d0 \n\t"
\r
416 " bne reg_test_2_error \n\t"
\r
417 " cmpi.l #20, d1 \n\t"
\r
418 " bne reg_test_2_error \n\t"
\r
419 " cmpi.l #30, d2 \n\t"
\r
420 " bne reg_test_2_error \n\t"
\r
421 " cmpi.l #40, d3 \n\t"
\r
422 " bne reg_test_2_error \n\t"
\r
423 " cmpi.l #50, d4 \n\t"
\r
424 " bne reg_test_2_error \n\t"
\r
425 " cmpi.l #60, d5 \n\t"
\r
426 " bne reg_test_2_error \n\t"
\r
427 " cmpi.l #70, d6 \n\t"
\r
428 " bne reg_test_2_error \n\t"
\r
429 " cmpi.l #80, d7 \n\t"
\r
430 " bne reg_test_2_error \n\t"
\r
431 " move a0, d0 \n\t"
\r
432 " cmpi.l #90, d0 \n\t"
\r
433 " bne reg_test_2_error \n\t"
\r
434 " move a1, d0 \n\t"
\r
435 " cmpi.l #100, d0 \n\t"
\r
436 " bne reg_test_2_error \n\t"
\r
437 " move a2, d0 \n\t"
\r
438 " cmpi.l #110, d0 \n\t"
\r
439 " bne reg_test_2_error \n\t"
\r
440 " move a3, d0 \n\t"
\r
441 " cmpi.l #120, d0 \n\t"
\r
442 " bne reg_test_2_error \n\t"
\r
443 " move a4, d0 \n\t"
\r
444 " cmpi.l #130, d0 \n\t"
\r
445 " bne reg_test_2_error \n\t"
\r
446 " move a6, d0 \n\t"
\r
447 " cmpi.l #150, d0 \n\t"
\r
448 " bne reg_test_2_error \n\t"
\r
449 " move ulRegTest1Counter, d0 \n\t"
\r
450 " addq #1, d0 \n\t"
\r
451 " move d0, ulRegTest2Counter \n\t"
\r
452 " bra reg_test_2_start \n\t"
\r
453 "reg_test_2_error: \n\t"
\r
454 " bra reg_test_2_error \n\t"
\r
457 /*-----------------------------------------------------------*/
\r