2 FreeRTOS V8.1.1 - Copyright (C) 2014 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 ***************************************************************************
9 * FreeRTOS provides completely free yet professionally developed, *
10 * robust, strictly quality controlled, supported, and cross *
11 * platform software that has become a de facto standard. *
13 * Help yourself get started quickly and support the FreeRTOS *
14 * project by purchasing a FreeRTOS tutorial book, reference *
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
19 ***************************************************************************
21 This file is part of the FreeRTOS distribution.
23 FreeRTOS is free software; you can redistribute it and/or modify it under
24 the terms of the GNU General Public License (version 2) as published by the
25 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
28 >>! distribute a combined work that includes FreeRTOS without being !<<
29 >>! obliged to provide the source code for proprietary components !<<
30 >>! outside of the FreeRTOS kernel. !<<
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
35 link: http://www.freertos.org/a00114.html
39 ***************************************************************************
41 * Having a problem? Start by reading the FAQ "My application does *
42 * not run, what could be wrong?" *
44 * http://www.FreeRTOS.org/FAQHelp.html *
46 ***************************************************************************
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49 license and Real Time Engineers Ltd. contact details.
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57 licenses offer ticketed support, indemnification and middleware.
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60 engineered and independently SIL3 certified version for use in safety and
61 mission critical applications that require provable dependability.
68 * Creates all the demo application tasks, then starts the scheduler. The WEB
69 * documentation provides more details of the standard demo application tasks.
70 * In addition to the standard demo tasks, the following tasks and tests are
71 * defined and/or created within this file:
73 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
74 * processing is performed in this task. It manages the WEB server functionality.
76 * "Check" task - This only executes every five seconds but has a high priority
77 * to ensure it gets processor time. Its main function is to check that all the
78 * standard demo tasks are still operational. An error found in any task will be
79 * latched in the ulErrorCode variable for display through the WEB server (the
80 * error code is displayed at the foot of the table that contains information on
81 * the state of each task).
83 * "Reg test" tasks - These fill the registers with known values, then check
84 * that each register still contains its expected value. Each task uses
85 * different values. The tasks run with very low priority so get preempted very
86 * frequently. A register containing an unexpected value is indicative of an
87 * error in the context switching mechanism.
91 /* Standard includes. */
94 /* Scheduler includes. */
100 /* Demo app includes. */
103 #include "blocktim.h"
108 #include "GenQTest.h"
110 #include "recmutex.h"
111 #include "IntQueue.h"
112 #include "comtest2.h"
114 /*-----------------------------------------------------------*/
116 /* The time between cycles of the 'check' functionality - as described at the
118 #define mainCHECK_TASK_PERIOD ( ( portTickType ) 5000 / portTICK_RATE_MS )
120 /* Task priorities. */
121 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
122 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
123 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
124 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
125 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
127 /* The WEB server task uses more stack than most other tasks because of its
128 reliance on using sprintf(). */
129 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
132 * Configure the hardware for the demo.
134 static void prvSetupHardware( void );
137 * Implements the 'check' task functionality as described at the top of this
140 static void prvCheckTask( void *pvParameters );
143 * The task that implements the WEB server.
145 extern void vuIP_Task( void *pvParameters );
148 * Implement the 'Reg test' functionality as described at the top of this file.
150 static void vRegTest1Task( void *pvParameters );
151 static void vRegTest2Task( void *pvParameters );
153 /*-----------------------------------------------------------*/
155 /* Counters used to detect errors within the reg test tasks. */
156 static volatile unsigned long ulRegTest1Counter = 0x11111111, ulRegTest2Counter = 0x22222222;
158 /* Any errors that the check task finds in any tasks are latched into
159 ulErrorCode, and then displayed via the WEB server. */
160 static unsigned long ulErrorCode = 0UL;
162 /*-----------------------------------------------------------*/
166 /* Setup the hardware ready for this demo. */
169 /* Create the WEB server task. */
170 xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
172 /* Start the standard demo tasks. */
173 vStartLEDFlashTasks( tskIDLE_PRIORITY );
174 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
175 vCreateBlockTimeTasks();
176 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
177 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
178 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
179 vStartQueuePeekTasks();
180 vStartRecursiveMutexTasks();
182 /* Start the reg test tasks - defined in this file. */
183 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest1Counter, tskIDLE_PRIORITY, NULL );
184 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) &ulRegTest2Counter, tskIDLE_PRIORITY, NULL );
186 /* Create the check task. */
187 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
189 /* Start the scheduler. */
190 vTaskStartScheduler();
192 /* Will only get here if there was insufficient heap to create the idle
196 /*-----------------------------------------------------------*/
198 static void prvCheckTask( void *pvParameters )
200 unsigned ulLastRegTest1Count = 0, ulLastRegTest2Count = 0;
201 portTickType xLastExecutionTime;
203 /* To prevent compiler warnings. */
204 ( void ) pvParameters;
206 /* Initialise the variable used to control our iteration rate prior to
208 xLastExecutionTime = xTaskGetTickCount();
212 /* Wait until it is time to run the tests again. */
213 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_PERIOD );
215 /* Has an error been found in any task? */
216 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
218 ulErrorCode |= 0x01UL;
221 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
223 ulErrorCode |= 0x02UL;
226 if( xAreBlockingQueuesStillRunning() != pdTRUE )
228 ulErrorCode |= 0x04UL;
231 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
233 ulErrorCode |= 0x20UL;
236 if( xArePollingQueuesStillRunning() != pdTRUE )
238 ulErrorCode |= 0x40UL;
241 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
243 ulErrorCode |= 0x80UL;
246 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
248 ulErrorCode |= 0x100UL;
251 if( ulLastRegTest1Count == ulRegTest1Counter )
253 ulErrorCode |= 0x200UL;
256 if( ulLastRegTest2Count == ulRegTest2Counter )
258 ulErrorCode |= 0x200UL;
261 /* Remember the reg test counts so a stall in their values can be
262 detected next time around. */
263 ulLastRegTest1Count = ulRegTest1Counter;
264 ulLastRegTest2Count = ulRegTest2Counter;
267 /*-----------------------------------------------------------*/
269 unsigned long ulGetErrorCode( void )
271 /* Returns the error code for display via the WEB server. */
274 /*-----------------------------------------------------------*/
276 void prvSetupHardware( void )
278 __attribute__ ((section(".cfmconfig")))
279 static const unsigned long _cfm[6] = {
280 0, /* KEY_UPPER 0x00000400 */
281 0, /* KEY_LOWER 0x00000404 */
282 0, /* CFMPROT 0x00000408 */
283 0, /* CFMSACC 0x0000040C */
284 0, /* CFMDACC 0x00000410 */
285 0, /* CFMSEC 0x00000414 */
288 /* Just to stop compiler warnings. */
291 /* Ensure the watchdog is disabled. */
294 /* Initialize IPSBAR (0x40000000). */
296 "move.l #0x40000000,%d0 \n"
297 "andi.l #0xC0000000,%d0 \n"
299 "move.l %d0,0x40000000 "
302 /* Initialize FLASHBAR (0x00) */
304 "move.l #0x00,%d0 \n"
305 "andi.l #0xFFF80000,%d0 \n"
307 "movec %d0,%FLASHBAR "
310 portDISABLE_INTERRUPTS();
313 MCF_SCM_RAMBAR = MCF_SCM_RAMBAR_BA( RAMBAR_ADDRESS ) | MCF_SCM_RAMBAR_BDE;
315 /* Multiply 25MHz crystal by 12 to get 60MHz clock. */
316 MCF_CLOCK_SYNCR = MCF_CLOCK_SYNCR_MFD(4) | MCF_CLOCK_SYNCR_CLKSRC| MCF_CLOCK_SYNCR_PLLMODE | MCF_CLOCK_SYNCR_PLLEN ;
317 while (!(MCF_CLOCK_SYNSR & MCF_CLOCK_SYNSR_LOCK))
321 /* Setup the port used to toggle LEDs. */
322 vParTestInitialise();
324 /*-----------------------------------------------------------*/
326 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
328 /* This will get called if a stack overflow is detected during the context
329 switch. Set configCHECK_FOR_STACK_OVERFLOWS to 2 to also check for stack
330 problems within nested interrupts, but only do this for debug purposes as
331 it will increase the context switch time. */
338 /*-----------------------------------------------------------*/
340 static void vRegTest1Task( void *pvParameters )
342 /* Sanity check - did we receive the parameter expected? */
343 if( pvParameters != &ulRegTest1Counter )
345 /* Change here so the check task can detect that an error occurred. */
349 /* Set all the registers to known values, then check that each retains its
350 expected value - as described at the top of this file. If an error is
351 found then the loop counter will no longer be incremented allowing the check
352 task to recognise the error. */
353 asm volatile ( "reg_test_1_start: \n\t"
354 " moveq #1, %d0 \n\t"
355 " moveq #2, %d1 \n\t"
356 " moveq #3, %d2 \n\t"
357 " moveq #4, %d3 \n\t"
358 " moveq #5, %d4 \n\t"
359 " moveq #6, %d5 \n\t"
360 " moveq #7, %d6 \n\t"
361 " moveq #8, %d7 \n\t"
363 " move #10, %a1 \n\t"
364 " move #11, %a2 \n\t"
365 " move #12, %a3 \n\t"
366 " move #13, %a4 \n\t"
367 " move #14, %a5 \n\t"
368 " move #15, %a6 \n\t"
370 " cmpi.l #1, %d0 \n\t"
371 " bne reg_test_1_error \n\t"
372 " cmpi.l #2, %d1 \n\t"
373 " bne reg_test_1_error \n\t"
374 " cmpi.l #3, %d2 \n\t"
375 " bne reg_test_1_error \n\t"
376 " cmpi.l #4, %d3 \n\t"
377 " bne reg_test_1_error \n\t"
378 " cmpi.l #5, %d4 \n\t"
379 " bne reg_test_1_error \n\t"
380 " cmpi.l #6, %d5 \n\t"
381 " bne reg_test_1_error \n\t"
382 " cmpi.l #7, %d6 \n\t"
383 " bne reg_test_1_error \n\t"
384 " cmpi.l #8, %d7 \n\t"
385 " bne reg_test_1_error \n\t"
386 " move %a0, %d0 \n\t"
387 " cmpi.l #9, %d0 \n\t"
388 " bne reg_test_1_error \n\t"
389 " move %a1, %d0 \n\t"
390 " cmpi.l #10, %d0 \n\t"
391 " bne reg_test_1_error \n\t"
392 " move %a2, %d0 \n\t"
393 " cmpi.l #11, %d0 \n\t"
394 " bne reg_test_1_error \n\t"
395 " move %a3, %d0 \n\t"
396 " cmpi.l #12, %d0 \n\t"
397 " bne reg_test_1_error \n\t"
398 " move %a4, %d0 \n\t"
399 " cmpi.l #13, %d0 \n\t"
400 " bne reg_test_1_error \n\t"
401 " move %a5, %d0 \n\t"
402 " cmpi.l #14, %d0 \n\t"
403 " bne reg_test_1_error \n\t"
404 " move %a6, %d0 \n\t"
405 " cmpi.l #15, %d0 \n\t"
406 " bne reg_test_1_error \n\t"
407 " movel ulRegTest1Counter, %d0 \n\t"
408 " addql #1, %d0 \n\t"
409 " movel %d0, ulRegTest1Counter \n\t"
410 " bra reg_test_1_start \n\t"
411 "reg_test_1_error: \n\t"
412 " bra reg_test_1_error \n\t"
415 /*-----------------------------------------------------------*/
417 static void vRegTest2Task( void *pvParameters )
419 /* Sanity check - did we receive the parameter expected? */
420 if( pvParameters != &ulRegTest2Counter )
422 /* Change here so the check task can detect that an error occurred. */
426 /* Set all the registers to known values, then check that each retains its
427 expected value - as described at the top of this file. If an error is
428 found then the loop counter will no longer be incremented allowing the check
429 task to recognise the error. */
430 asm volatile ( "reg_test_2_start: \n\t"
431 " moveq #10, %d0 \n\t"
432 " moveq #20, %d1 \n\t"
433 " moveq #30, %d2 \n\t"
434 " moveq #40, %d3 \n\t"
435 " moveq #50, %d4 \n\t"
436 " moveq #60, %d5 \n\t"
437 " moveq #70, %d6 \n\t"
438 " moveq #80, %d7 \n\t"
439 " move #90, %a0 \n\t"
440 " move #100, %a1 \n\t"
441 " move #110, %a2 \n\t"
442 " move #120, %a3 \n\t"
443 " move #130, %a4 \n\t"
444 " move #140, %a5 \n\t"
445 " move #150, %a6 \n\t"
447 " cmpi.l #10, %d0 \n\t"
448 " bne reg_test_2_error \n\t"
449 " cmpi.l #20, %d1 \n\t"
450 " bne reg_test_2_error \n\t"
451 " cmpi.l #30, %d2 \n\t"
452 " bne reg_test_2_error \n\t"
453 " cmpi.l #40, %d3 \n\t"
454 " bne reg_test_2_error \n\t"
455 " cmpi.l #50, %d4 \n\t"
456 " bne reg_test_2_error \n\t"
457 " cmpi.l #60, %d5 \n\t"
458 " bne reg_test_2_error \n\t"
459 " cmpi.l #70, %d6 \n\t"
460 " bne reg_test_2_error \n\t"
461 " cmpi.l #80, %d7 \n\t"
462 " bne reg_test_2_error \n\t"
463 " move %a0, %d0 \n\t"
464 " cmpi.l #90, %d0 \n\t"
465 " bne reg_test_2_error \n\t"
466 " move %a1, %d0 \n\t"
467 " cmpi.l #100, %d0 \n\t"
468 " bne reg_test_2_error \n\t"
469 " move %a2, %d0 \n\t"
470 " cmpi.l #110, %d0 \n\t"
471 " bne reg_test_2_error \n\t"
472 " move %a3, %d0 \n\t"
473 " cmpi.l #120, %d0 \n\t"
474 " bne reg_test_2_error \n\t"
475 " move %a4, %d0 \n\t"
476 " cmpi.l #130, %d0 \n\t"
477 " bne reg_test_2_error \n\t"
478 " move %a5, %d0 \n\t"
479 " cmpi.l #140, %d0 \n\t"
480 " bne reg_test_2_error \n\t"
481 " move %a6, %d0 \n\t"
482 " cmpi.l #150, %d0 \n\t"
483 " bne reg_test_2_error \n\t"
484 " movel ulRegTest1Counter, %d0 \n\t"
485 " addql #1, %d0 \n\t"
486 " movel %d0, ulRegTest2Counter \n\t"
487 " bra reg_test_2_start \n\t"
488 "reg_test_2_error: \n\t"
489 " bra reg_test_2_error \n\t"
492 /*-----------------------------------------------------------*/