2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
44 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
45 * documentation provides more details of the demo application tasks.
\r
47 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
50 * The "Check" task. This only executes every three seconds but has the highest
\r
51 * priority so is guaranteed to get processor time. Its main function is to
\r
52 * check that all the other tasks are still operational. Most tasks maintain
\r
53 * a unique count that is incremented each time the task successfully completes
\r
54 * its function. Should any error occur within such a task the count is
\r
55 * permanently halted. The check task inspects the count of each task to ensure
\r
56 * it has changed since the last time the check task executed. If all the count
\r
57 * variables have changed all the tasks are still executing error free, and the
\r
58 * check task toggles the onboard LED. Should any task contain an error at any time
\r
59 * the LED toggle rate will change from 3 seconds to 500ms.
\r
64 /* Scheduler includes. */
\r
65 #include "FreeRTOS.h"
\r
68 #include "integer.h"
\r
69 #include "comtest2.h"
\r
70 #include "semtest.h"
\r
72 #include "dynamic.h"
\r
74 #include "GenQTest.h"
\r
76 #include "blocktim.h"
\r
78 #include "partest.h"
\r
79 #include "xcache_l.h"
\r
82 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
83 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
84 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
85 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
86 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
87 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
88 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
90 #define mainCOM_TEST_BAUD_RATE ( 115200UL )
\r
91 #define mainCOM_TEST_LED ( 4 )
\r
93 #define mainNO_ERROR_CHECK_DELAY ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
94 #define mainERROR_CHECK_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
96 #define mainCHECK_TEST_LED ( 3 )
\r
98 static void prvRegTestTask1( void *pvParameters );
\r
99 static void prvRegTestTask2( void *pvParameters );
\r
100 static void prvFlashTask( void *pvParameters );
\r
101 static void prvErrorChecks( void *pvParameters );
\r
103 static unsigned portBASE_TYPE xRegTestStatus = pdPASS;
\r
104 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
106 XIntc xInterruptController;
\r
107 extern void vPortISRWrapper( void );
\r
111 XCache_EnableICache( 0x80000000 );
\r
112 XCache_EnableDCache( 0x80000000 );
\r
115 XExc_mDisableExceptions( XEXC_NON_CRITICAL );
\r
116 XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler)vPortISRWrapper, &xInterruptController );
\r
118 XIntc_Initialize( &xInterruptController, XPAR_OPB_INTC_0_DEVICE_ID );
\r
119 XIntc_Start( &xInterruptController, XIN_REAL_MODE );
\r
121 vParTestInitialise();
\r
123 /* Start the standard demo application tasks. */
\r
124 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
125 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
126 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
127 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
128 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
129 vStartDynamicPriorityTasks();
\r
130 vStartMathTasks( tskIDLE_PRIORITY );
\r
131 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
132 vStartQueuePeekTasks();
\r
133 vCreateBlockTimeTasks();
\r
135 xTaskCreate( prvRegTestTask1, "Regtest1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
136 xTaskCreate( prvRegTestTask2, "Regtest2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
137 xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
139 /* The suicide tasks must be started last as they record the number of other
\r
140 tasks that exist within the system. The value is then used to ensure at run
\r
141 time the number of tasks that exists is within expected bounds. */
\r
142 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
144 /* Now start the scheduler. Following this call the created tasks should
\r
146 vTaskStartScheduler( );
\r
148 /* vTaskStartScheduler() will only return if an error occurs while the
\r
149 idle task is being created. */
\r
155 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
157 portBASE_TYPE lReturn = pdPASS;
\r
159 /* The demo tasks maintain a count that increments every cycle of the task
\r
160 provided that the task has never encountered an error. This function
\r
161 checks the counts maintained by the tasks to ensure they are still being
\r
162 incremented. A count remaining at the same value between calls therefore
\r
163 indicates that an error has been detected. */
\r
165 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
170 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
175 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
180 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
185 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
190 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
195 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
200 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
205 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
210 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
215 /* Have the register test tasks found any errors? */
\r
216 if( xRegTestStatus != pdPASS )
\r
223 /*-----------------------------------------------------------*/
\r
225 static void prvErrorChecks( void *pvParameters )
\r
227 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
228 volatile unsigned portBASE_TYPE uxFreeStack;
\r
230 uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
\r
232 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
233 works correctly. */
\r
234 xLastExecutionTime = xTaskGetTickCount();
\r
236 /* Cycle for ever, delaying then checking all the other tasks are still
\r
237 operating without error. */
\r
240 uxFreeStack = uxTaskGetStackHighWaterMark( NULL );
\r
242 /* Wait until it is time to check again. The time we wait here depends
\r
243 on whether an error has been detected or not. When an error is
\r
244 detected the time is shortened resulting in a faster LED flash rate. */
\r
245 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
246 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
248 /* See if the other tasks are all ok. */
\r
249 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
251 /* An error occurred in one of the tasks so shorten the delay
\r
252 period - which has the effect of increasing the frequency of the
\r
254 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
258 vParTestToggleLED( mainCHECK_TEST_LED );
\r
261 /*-----------------------------------------------------------*/
\r
264 static void prvRegTestTask1( void *pvParameters )
\r
268 "RegTest1Start: \n\t" \
\r
279 " li 10, 10 \n\t" \
\r
280 " li 11, 11 \n\t" \
\r
281 " li 12, 12 \n\t" \
\r
282 " li 13, 13 \n\t" \
\r
283 " li 14, 14 \n\t" \
\r
284 " li 15, 15 \n\t" \
\r
285 " li 16, 16 \n\t" \
\r
286 " li 17, 17 \n\t" \
\r
287 " li 18, 18 \n\t" \
\r
288 " li 19, 19 \n\t" \
\r
289 " li 20, 20 \n\t" \
\r
290 " li 21, 21 \n\t" \
\r
291 " li 22, 22 \n\t" \
\r
292 " li 23, 23 \n\t" \
\r
293 " li 24, 24 \n\t" \
\r
294 " li 25, 25 \n\t" \
\r
295 " li 26, 26 \n\t" \
\r
296 " li 27, 27 \n\t" \
\r
297 " li 28, 28 \n\t" \
\r
298 " li 29, 29 \n\t" \
\r
299 " li 30, 30 \n\t" \
\r
300 " li 31, 31 \n\t" \
\r
305 " cmpwi 0, 1 \n\t" \
\r
306 " bne RegTest1Fail \n\t" \
\r
307 " cmpwi 2, 2 \n\t" \
\r
308 " bne RegTest1Fail \n\t" \
\r
309 " cmpwi 3, 3 \n\t" \
\r
310 " bne RegTest1Fail \n\t" \
\r
311 " cmpwi 4, 4 \n\t" \
\r
312 " bne RegTest1Fail \n\t" \
\r
313 " cmpwi 5, 5 \n\t" \
\r
314 " bne RegTest1Fail \n\t" \
\r
315 " cmpwi 6, 6 \n\t" \
\r
316 " bne RegTest1Fail \n\t" \
\r
317 " cmpwi 7, 7 \n\t" \
\r
318 " bne RegTest1Fail \n\t" \
\r
319 " cmpwi 8, 8 \n\t" \
\r
320 " bne RegTest1Fail \n\t" \
\r
321 " cmpwi 9, 9 \n\t" \
\r
322 " bne RegTest1Fail \n\t" \
\r
323 " cmpwi 10, 10 \n\t" \
\r
324 " bne RegTest1Fail \n\t" \
\r
325 " cmpwi 11, 11 \n\t" \
\r
326 " bne RegTest1Fail \n\t" \
\r
327 " cmpwi 12, 12 \n\t" \
\r
328 " bne RegTest1Fail \n\t" \
\r
329 " cmpwi 13, 13 \n\t" \
\r
330 " bne RegTest1Fail \n\t" \
\r
331 " cmpwi 14, 14 \n\t" \
\r
332 " bne RegTest1Fail \n\t" \
\r
333 " cmpwi 15, 15 \n\t" \
\r
334 " bne RegTest1Fail \n\t" \
\r
335 " cmpwi 16, 16 \n\t" \
\r
336 " bne RegTest1Fail \n\t" \
\r
337 " cmpwi 17, 17 \n\t" \
\r
338 " bne RegTest1Fail \n\t" \
\r
339 " cmpwi 18, 18 \n\t" \
\r
340 " bne RegTest1Fail \n\t" \
\r
341 " cmpwi 19, 19 \n\t" \
\r
342 " bne RegTest1Fail \n\t" \
\r
343 " cmpwi 20, 20 \n\t" \
\r
344 " bne RegTest1Fail \n\t" \
\r
345 " cmpwi 21, 21 \n\t" \
\r
346 " bne RegTest1Fail \n\t" \
\r
347 " cmpwi 22, 22 \n\t" \
\r
348 " bne RegTest1Fail \n\t" \
\r
349 " cmpwi 23, 23 \n\t" \
\r
350 " bne RegTest1Fail \n\t" \
\r
351 " cmpwi 24, 24 \n\t" \
\r
352 " bne RegTest1Fail \n\t" \
\r
353 " cmpwi 25, 25 \n\t" \
\r
354 " bne RegTest1Fail \n\t" \
\r
355 " cmpwi 26, 26 \n\t" \
\r
356 " bne RegTest1Fail \n\t" \
\r
357 " cmpwi 27, 27 \n\t" \
\r
358 " bne RegTest1Fail \n\t" \
\r
359 " cmpwi 28, 28 \n\t" \
\r
360 " bne RegTest1Fail \n\t" \
\r
361 " cmpwi 29, 29 \n\t" \
\r
362 " bne RegTest1Fail \n\t" \
\r
363 " cmpwi 30, 30 \n\t" \
\r
364 " bne RegTest1Fail \n\t" \
\r
365 " cmpwi 31, 31 \n\t" \
\r
366 " bne RegTest1Fail \n\t" \
\r
368 " b RegTest1Start \n\t" \
\r
370 "RegTest1Fail: \n\t" \
\r
372 " xor 0, 0, 0 \n\t" \
\r
373 " stw 0, xRegTestStatus( 0 ) \n\t" \
\r
375 " b RegTest1Start \n\t" \
\r
379 static void prvRegTestTask2( void *pvParameters )
\r
383 "RegTest2Start: \n\t" \
\r
394 " li 10, 110 \n\t" \
\r
395 " li 11, 111 \n\t" \
\r
396 " li 12, 112 \n\t" \
\r
397 " li 13, 113 \n\t" \
\r
398 " li 14, 114 \n\t" \
\r
399 " li 15, 115 \n\t" \
\r
400 " li 16, 116 \n\t" \
\r
401 " li 17, 117 \n\t" \
\r
402 " li 18, 118 \n\t" \
\r
403 " li 19, 119 \n\t" \
\r
404 " li 20, 120 \n\t" \
\r
405 " li 21, 121 \n\t" \
\r
406 " li 22, 122 \n\t" \
\r
407 " li 23, 123 \n\t" \
\r
408 " li 24, 124 \n\t" \
\r
409 " li 25, 125 \n\t" \
\r
410 " li 26, 126 \n\t" \
\r
411 " li 27, 127 \n\t" \
\r
412 " li 28, 128 \n\t" \
\r
413 " li 29, 129 \n\t" \
\r
414 " li 30, 130 \n\t" \
\r
415 " li 31, 131 \n\t" \
\r
420 " cmpwi 0, 11 \n\t" \
\r
421 " bne RegTest2Fail \n\t" \
\r
422 " cmpwi 2, 12 \n\t" \
\r
423 " bne RegTest2Fail \n\t" \
\r
424 " cmpwi 3, 13 \n\t" \
\r
425 " bne RegTest2Fail \n\t" \
\r
426 " cmpwi 4, 14 \n\t" \
\r
427 " bne RegTest2Fail \n\t" \
\r
428 " cmpwi 5, 15 \n\t" \
\r
429 " bne RegTest2Fail \n\t" \
\r
430 " cmpwi 6, 16 \n\t" \
\r
431 " bne RegTest2Fail \n\t" \
\r
432 " cmpwi 7, 17 \n\t" \
\r
433 " bne RegTest2Fail \n\t" \
\r
434 " cmpwi 8, 18 \n\t" \
\r
435 " bne RegTest2Fail \n\t" \
\r
436 " cmpwi 9, 19 \n\t" \
\r
437 " bne RegTest2Fail \n\t" \
\r
438 " cmpwi 10, 110 \n\t" \
\r
439 " bne RegTest2Fail \n\t" \
\r
440 " cmpwi 11, 111 \n\t" \
\r
441 " bne RegTest2Fail \n\t" \
\r
442 " cmpwi 12, 112 \n\t" \
\r
443 " bne RegTest2Fail \n\t" \
\r
444 " cmpwi 13, 113 \n\t" \
\r
445 " bne RegTest2Fail \n\t" \
\r
446 " cmpwi 14, 114 \n\t" \
\r
447 " bne RegTest2Fail \n\t" \
\r
448 " cmpwi 15, 115 \n\t" \
\r
449 " bne RegTest2Fail \n\t" \
\r
450 " cmpwi 16, 116 \n\t" \
\r
451 " bne RegTest2Fail \n\t" \
\r
452 " cmpwi 17, 117 \n\t" \
\r
453 " bne RegTest2Fail \n\t" \
\r
454 " cmpwi 18, 118 \n\t" \
\r
455 " bne RegTest2Fail \n\t" \
\r
456 " cmpwi 19, 119 \n\t" \
\r
457 " bne RegTest2Fail \n\t" \
\r
458 " cmpwi 20, 120 \n\t" \
\r
459 " bne RegTest2Fail \n\t" \
\r
460 " cmpwi 21, 121 \n\t" \
\r
461 " bne RegTest2Fail \n\t" \
\r
462 " cmpwi 22, 122 \n\t" \
\r
463 " bne RegTest2Fail \n\t" \
\r
464 " cmpwi 23, 123 \n\t" \
\r
465 " bne RegTest2Fail \n\t" \
\r
466 " cmpwi 24, 124 \n\t" \
\r
467 " bne RegTest2Fail \n\t" \
\r
468 " cmpwi 25, 125 \n\t" \
\r
469 " bne RegTest2Fail \n\t" \
\r
470 " cmpwi 26, 126 \n\t" \
\r
471 " bne RegTest2Fail \n\t" \
\r
472 " cmpwi 27, 127 \n\t" \
\r
473 " bne RegTest2Fail \n\t" \
\r
474 " cmpwi 28, 128 \n\t" \
\r
475 " bne RegTest2Fail \n\t" \
\r
476 " cmpwi 29, 129 \n\t" \
\r
477 " bne RegTest2Fail \n\t" \
\r
478 " cmpwi 30, 130 \n\t" \
\r
479 " bne RegTest2Fail \n\t" \
\r
480 " cmpwi 31, 131 \n\t" \
\r
481 " bne RegTest2Fail \n\t" \
\r
483 " b RegTest2Start \n\t" \
\r
485 "RegTest2Fail: \n\t" \
\r
487 " xor 0, 0, 0 \n\t" \
\r
488 " stw 0, xRegTestStatus( 0 ) \n\t" \
\r
490 " b RegTest2Start \n\t" \
\r
497 static void prvRegTestTask2( void *pvParameters )
\r
499 volatile unsigned int i= 0;
\r
508 static void prvRegTestTask1( void *pvParameters )
\r
510 volatile unsigned int i= 0;
\r
521 void vApplicationStackOverflowHook( xTaskHandle xTask, signed portCHAR *pcTaskName );
\r
522 void vApplicationStackOverflowHook( xTaskHandle xTask, signed portCHAR *pcTaskName )
\r