2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
73 * documentation provides more details of the demo application tasks.
\r
75 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
78 * The "Check" task. This only executes every three seconds but has the highest
\r
79 * priority so is guaranteed to get processor time. Its main function is to
\r
80 * check that all the other tasks are still operational. Most tasks maintain
\r
81 * a unique count that is incremented each time the task successfully completes
\r
82 * its function. Should any error occur within such a task the count is
\r
83 * permanently halted. The check task inspects the count of each task to ensure
\r
84 * it has changed since the last time the check task executed. If all the count
\r
85 * variables have changed all the tasks are still executing error free, and the
\r
86 * check task toggles the onboard LED. Should any task contain an error at any time
\r
87 * the LED toggle rate will change from 3 seconds to 500ms.
\r
89 * The "Register Check" tasks. These tasks fill the CPU registers with known
\r
90 * values, then check that each register still contains the expected value 0 the
\r
91 * discovery of an unexpected value being indicative of an error in the RTOS
\r
92 * context switch mechanism. The register check tasks operate at low priority
\r
93 * so are switched in and out frequently.
\r
95 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
96 * information via UART5.
\r
100 /* Hardware specific includes. */
\r
101 #include "mb91467d.h"
\r
102 #include "vectors.h"
\r
103 #include "watchdog.h"
\r
105 /* Scheduler includes. */
\r
106 #include "FreeRTOS.h"
\r
109 /* Demo app includes. */
\r
111 #include "integer.h"
\r
112 #include "comtest2.h"
\r
113 #include "semtest.h"
\r
114 #include "BlockQ.h"
\r
115 #include "dynamic.h"
\r
117 #include "GenQTest.h"
\r
119 #include "blocktim.h"
\r
121 #include "taskutility.h"
\r
122 #include "partest.h"
\r
123 #include "crflash.h"
\r
125 /* Demo task priorities. */
\r
126 #define mainWATCHDOG_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
127 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
128 #define mainUTILITY_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
129 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
130 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
131 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
132 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
133 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
134 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
136 /* Baud rate used by the COM test tasks. */
\r
137 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
139 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
140 top of the page. When the system is operating error free the 'Check' task
\r
141 toggles an LED every three seconds. If an error is discovered in any task the
\r
142 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
143 LCD represent LEDs]*/
\r
144 #define mainNO_ERROR_CHECK_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
145 #define mainERROR_CHECK_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
147 /* The total number of LEDs available. */
\r
148 #define mainNO_CO_ROUTINE_LEDs ( 8 )
\r
150 /* The first LED used by the comtest tasks. */
\r
151 #define mainCOM_TEST_LED ( 0x05 )
\r
153 /* The LED used by the check task. */
\r
154 #define mainCHECK_TEST_LED ( 0x07 )
\r
156 /* The number of interrupt levels to use. */
\r
157 #define mainINTERRUPT_LEVELS ( 31 )
\r
159 /* The number of 'flash' co-routines to create - each toggles a different LED. */
\r
160 #define mainNUM_FLASH_CO_ROUTINES ( 8 )
\r
162 /*---------------------------------------------------------------------------*/
\r
165 * The function that implements the Check task. See the comments at the head
\r
166 * of the page for implementation details.
\r
168 static void prvErrorChecks( void *pvParameters );
\r
171 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
172 * to be operating without error - otherwise returns pdFAIL.
\r
174 static short prvCheckOtherTasksAreStillRunning( void );
\r
177 * Setup the microcontroller as used by this demo.
\r
179 static void prvSetupHardware( void );
\r
182 * Tasks that test the context switch mechanism by filling the CPU registers
\r
183 * with known values then checking that each register contains the value
\r
184 * expected. Each of the two tasks use different values, and as low priority
\r
185 * tasks, get swapped in and out regularly.
\r
187 static void vFirstRegisterTestTask( void *pvParameters );
\r
188 static void vSecondRegisterTestTask( void *pvParameters );
\r
190 /*---------------------------------------------------------------------------*/
\r
192 /* The variable that is set to true should an error be found in one of the
\r
193 register test tasks. */
\r
194 unsigned long ulRegTestError = pdFALSE;
\r
196 /*---------------------------------------------------------------------------*/
\r
198 /* Start all the demo application tasks, then start the scheduler. */
\r
201 /* Initialise the hardware ready for the demo. */
\r
202 prvSetupHardware();
\r
204 /* Start the standard demo application tasks. */
\r
205 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
206 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
207 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
208 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
209 vStartBlockingQueueTasks ( mainQUEUE_BLOCK_PRIORITY );
\r
210 vStartDynamicPriorityTasks();
\r
211 vStartMathTasks( tskIDLE_PRIORITY );
\r
212 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
213 vStartQueuePeekTasks();
\r
214 vCreateBlockTimeTasks();
\r
215 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
217 /* Start the 'Check' task which is defined in this file. */
\r
218 xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
220 /* Start the 'Register Test' tasks as described at the top of this file. */
\r
221 xTaskCreate( vFirstRegisterTestTask, "Reg1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
222 xTaskCreate( vSecondRegisterTestTask, "Reg2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
224 /* Start the task that write trace information to the UART. */
\r
225 vUtilityStartTraceTask( mainUTILITY_TASK_PRIORITY );
\r
227 /* If we are going to service the watchdog from within a task, then create
\r
229 #if WATCHDOG == WTC_IN_TASK
\r
230 vStartWatchdogTask( mainWATCHDOG_TASK_PRIORITY );
\r
233 /* The suicide tasks must be started last as they record the number of other
\r
234 tasks that exist within the system. The value is then used to ensure at run
\r
235 time the number of tasks that exists is within expected bounds. */
\r
236 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
238 /* Now start the scheduler. Following this call the created tasks should
\r
240 vTaskStartScheduler( );
\r
242 /* vTaskStartScheduler() will only return if an error occurs while the
\r
243 idle task is being created. */
\r
246 /*-----------------------------------------------------------*/
\r
248 static void prvErrorChecks( void *pvParameters )
\r
250 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY, xLastExecutionTime;
\r
252 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
253 works correctly. */
\r
254 xLastExecutionTime = xTaskGetTickCount();
\r
256 /* Cycle for ever, delaying then checking all the other tasks are still
\r
257 operating without error. */
\r
260 /* Wait until it is time to check again. The time we wait here depends
\r
261 on whether an error has been detected or not. When an error is
\r
262 detected the time is shortened resulting in a faster LED flash rate. */
\r
263 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
264 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
266 /* See if the other tasks are all ok. */
\r
267 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
269 /* An error occurred in one of the tasks so shorten the delay
\r
270 period - which has the effect of increasing the frequency of the
\r
272 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
276 vParTestToggleLED( mainCHECK_TEST_LED );
\r
279 /*-----------------------------------------------------------*/
\r
281 static short prvCheckOtherTasksAreStillRunning( void )
\r
283 portBASE_TYPE lReturn = pdPASS;
\r
285 /* The demo tasks maintain a count that increments every cycle of the task
\r
286 provided that the task has never encountered an error. This function
\r
287 checks the counts maintained by the tasks to ensure they are still being
\r
288 incremented. A count remaining at the same value between calls therefore
\r
289 indicates that an error has been detected. */
\r
291 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
296 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
301 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
306 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
311 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
316 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
321 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
326 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
331 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
336 if ( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
341 /* Have the register test tasks found any errors? */
\r
342 if( ulRegTestError != pdFALSE )
\r
349 /*-----------------------------------------------------------*/
\r
351 static void prvSetupHardware( void )
\r
353 /* Allow all interrupt levels. */
\r
354 __set_il( mainINTERRUPT_LEVELS );
\r
356 /* Initialise interrupts. */
\r
359 /* Initialise the ports used by the LEDs. */
\r
360 vParTestInitialise();
\r
362 /* If we are going to use the watchdog, then initialise it now. */
\r
363 #if WATCHDOG != WTC_NONE
\r
367 /*-----------------------------------------------------------*/
\r
369 /* Idle hook function. */
\r
370 #if configUSE_IDLE_HOOK == 1
\r
371 void vApplicationIdleHook( void )
\r
373 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
374 for watchdog kicking options. Note this is for demonstration only
\r
375 and is not a suggested method of servicing the watchdog in a real
\r
377 #if WATCHDOG == WTC_IN_IDLE
\r
381 vCoRoutineSchedule();
\r
384 #if WATCHDOG == WTC_IN_IDLE
\r
385 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
389 /*-----------------------------------------------------------*/
\r
391 /* Tick hook function. */
\r
392 #if configUSE_TICK_HOOK == 1
\r
393 void vApplicationTickHook( void )
\r
395 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
396 for watchdog kicking options. Note this is for demonstration
\r
397 only and is not a suggested method of servicing the watchdog in
\r
398 a real application. */
\r
399 #if WATCHDOG == WTC_IN_TICK
\r
404 #if WATCHDOG == WTC_IN_TICK
\r
405 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
408 /*-----------------------------------------------------------*/
\r
410 static void vFirstRegisterTestTask( void *pvParameters )
\r
412 extern volatile unsigned long ulCriticalNesting;
\r
414 /* Fills the registers with known values (different to the values
\r
415 used in vSecondRegisterTestTask()), then checks that the registers still
\r
416 all contain the expected value. This is done to test the context save
\r
417 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
422 ;Load known values into each register.
\r
423 LDI #0x11111111, R0
\r
424 LDI #0x22222222, R1
\r
425 LDI #0x33333333, R2
\r
426 LDI #0x44444444, R3
\r
427 LDI #0x55555555, R4
\r
428 LDI #0x66666666, R5
\r
429 LDI #0x77777777, R6
\r
430 LDI #0x88888888, R7
\r
431 LDI #0x99999999, R8
\r
432 LDI #0xaaaaaaaa, R9
\r
433 LDI #0xbbbbbbbb, R10
\r
434 LDI #0xcccccccc, R11
\r
435 LDI #0xdddddddd, R12
\r
437 ;Check each register still contains the expected value.
\r
438 LDI #0x11111111, R13
\r
440 BNE First_Set_Error
\r
442 LDI #0x22222222, R13
\r
444 BNE First_Set_Error
\r
446 LDI #0x33333333, R13
\r
448 BNE First_Set_Error
\r
450 LDI #0x44444444, R13
\r
452 BNE First_Set_Error
\r
454 LDI #0x55555555, R13
\r
456 BNE First_Set_Error
\r
458 LDI #0x66666666, R13
\r
460 BNE First_Set_Error
\r
462 LDI #0x77777777, R13
\r
464 BNE First_Set_Error
\r
466 LDI #0x88888888, R13
\r
468 BNE First_Set_Error
\r
470 LDI #0x99999999, R13
\r
472 BNE First_Set_Error
\r
474 LDI #0xaaaaaaaa, R13
\r
476 BNE First_Set_Error
\r
478 LDI #0xbbbbbbbb, R13
\r
480 BNE First_Set_Error
\r
482 LDI #0xcccccccc, R13
\r
484 BNE First_Set_Error
\r
486 LDI #0xdddddddd, R13
\r
488 BNE First_Set_Error
\r
490 BRA First_Start_Next_Loop
\r
494 ; Latch that an error has occurred.
\r
495 LDI #_ulRegTestError, R0
\r
496 LDI #0x00000001, R1
\r
500 First_Start_Next_Loop:
\r
506 /*-----------------------------------------------------------*/
\r
508 static void vSecondRegisterTestTask( void *pvParameters )
\r
510 extern volatile unsigned long ulCriticalNesting;
\r
512 /* Fills the registers with known values (different to the values
\r
513 used in vFirstRegisterTestTask()), then checks that the registers still
\r
514 all contain the expected value. This is done to test the context save
\r
515 and restore mechanism as this task is swapped onto and off of the CPU. */
\r
520 ;Load known values into each register.
\r
521 LDI #0x11111111, R1
\r
522 LDI #0x22222222, R2
\r
524 LDI #0x33333333, R3
\r
525 LDI #0x44444444, R4
\r
526 LDI #0x55555555, R5
\r
527 LDI #0x66666666, R6
\r
528 LDI #0x77777777, R7
\r
529 LDI #0x88888888, R8
\r
530 LDI #0x99999999, R9
\r
532 LDI #0xaaaaaaaa, R10
\r
533 LDI #0xbbbbbbbb, R11
\r
534 LDI #0xcccccccc, R12
\r
535 LDI #0xdddddddd, R0
\r
537 ;Check each register still contains the expected value.
\r
538 LDI #0x11111111, R13
\r
540 BNE Second_Set_Error
\r
542 LDI #0x22222222, R13
\r
544 BNE Second_Set_Error
\r
546 LDI #0x33333333, R13
\r
548 BNE Second_Set_Error
\r
550 LDI #0x44444444, R13
\r
552 BNE Second_Set_Error
\r
554 LDI #0x55555555, R13
\r
556 BNE Second_Set_Error
\r
560 LDI #0x66666666, R13
\r
562 BNE Second_Set_Error
\r
564 LDI #0x77777777, R13
\r
566 BNE Second_Set_Error
\r
568 LDI #0x88888888, R13
\r
570 BNE Second_Set_Error
\r
572 LDI #0x99999999, R13
\r
574 BNE Second_Set_Error
\r
578 LDI #0xaaaaaaaa, R13
\r
580 BNE Second_Set_Error
\r
582 LDI #0xbbbbbbbb, R13
\r
584 BNE Second_Set_Error
\r
586 LDI #0xcccccccc, R13
\r
588 BNE Second_Set_Error
\r
590 LDI #0xdddddddd, R13
\r
592 BNE Second_Set_Error
\r
594 BRA Second_Start_Next_Loop
\r
598 ; Latch that an error has occurred.
\r
599 LDI #_ulRegTestError, R0
\r
600 LDI #0x00000001, R1
\r
604 Second_Start_Next_Loop:
\r
610 /*-----------------------------------------------------------*/
\r