2 FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /******************************************************************************
\r
67 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
68 * project, and a more comprehensive test and demo application. The
\r
69 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
70 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
71 * in main.c. This file implements the comprehensive test and demo version.
\r
73 * NOTE 2: This file only contains the source code that is specific to the
\r
74 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
75 * required to configure the hardware, are defined in main.c.
\r
76 ******************************************************************************
\r
78 * main_full() creates all the demo application tasks and a software timer, then
\r
79 * starts the scheduler. The web documentation provides more details of the
\r
80 * standard demo application tasks, which provide no particular functionality,
\r
81 * but do provide a good example of how to use the FreeRTOS API.
\r
83 * In addition to the standard demo tasks, the following tasks and tests are
\r
84 * defined and/or created within this file:
\r
86 * "Reg test" tasks - These fill both the core and floating point registers with
\r
87 * known values, then check that each register maintains its expected value for
\r
88 * the lifetime of the task. Each task uses a different set of values. The reg
\r
89 * test tasks execute with a very low priority, so get preempted very
\r
90 * frequently. A register containing an unexpected value is indicative of an
\r
91 * error in the context switching mechanism.
\r
93 * "Check" timer - The check software timer period is initially set to three
\r
94 * seconds. The callback function associated with the check software timer
\r
95 * checks that all the standard demo tasks, and the register check tasks, are
\r
96 * not only still executing, but are executing without reporting any errors. If
\r
97 * the check software timer discovers that a task has either stalled, or
\r
98 * reported an error, then it changes its own execution period from the initial
\r
99 * three seconds, to just 200ms. The check software timer callback function
\r
100 * also toggles the single LED each time it is called. This provides a visual
\r
101 * indication of the system status: If the LED toggles every three seconds,
\r
102 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
103 * an issue has been discovered with at least one task.
\r
106 /* Standard includes. */
\r
109 /* Kernel includes. */
\r
110 #include "FreeRTOS.h"
\r
112 #include "timers.h"
\r
113 #include "semphr.h"
\r
115 /* Standard demo application includes. */
\r
117 #include "semtest.h"
\r
118 #include "dynamic.h"
\r
119 #include "blocktim.h"
\r
120 #include "countsem.h"
\r
121 #include "GenQTest.h"
\r
122 #include "recmutex.h"
\r
123 #include "QueueSet.h"
\r
124 #include "QueueOverwrite.h"
\r
126 /* Priorities for the demo application tasks. */
\r
127 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
128 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
129 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
130 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
131 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
133 /* A block time of zero simply means "don't block". */
\r
134 #define mainDONT_BLOCK ( 0UL )
\r
136 /* The period after which the check timer will expire, in ms, provided no errors
\r
137 have been reported by any of the standard demo tasks. ms are converted to the
\r
138 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
139 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
141 /* The period at which the check timer will expire, in ms, if an error has been
\r
142 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
143 in ticks using the portTICK_PERIOD_MS constant. */
\r
144 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
146 /*-----------------------------------------------------------*/
\r
149 * The check timer callback function, as described at the top of this file.
\r
151 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
154 * Register check tasks, and the tasks used to write over and check the contents
\r
155 * of the FPU registers, as described at the top of this file. The nature of
\r
156 * these files necessitates that they are written in an assembly file.
\r
158 static void vRegTest1Task( void *pvParameters );
\r
159 static void vRegTest2Task( void *pvParameters );
\r
161 /*-----------------------------------------------------------*/
\r
163 /* The following two variables are used to communicate the status of the
\r
164 register check tasks to the check software timer. If the variables keep
\r
165 incrementing, then the register check tasks has not discovered any errors. If
\r
166 a variable stops incrementing, then an error has been found. */
\r
167 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
169 /*-----------------------------------------------------------*/
\r
171 void main_full( void )
\r
173 TimerHandle_t xCheckTimer = NULL;
\r
175 /* Start all the other standard demo/test tasks. The have not particular
\r
176 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
178 vStartQueueSetTasks();
\r
179 vStartQueueOverwriteTask( tskIDLE_PRIORITY );
\r
180 vStartDynamicPriorityTasks();
\r
181 vCreateBlockTimeTasks();
\r
182 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
183 vStartRecursiveMutexTasks();
\r
184 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
186 /* Create the register check tasks, as described at the top of this
\r
188 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
189 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
191 /* Create the software timer that performs the 'check' functionality,
\r
192 as described at the top of this file. */
\r
193 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
194 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
195 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
196 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
197 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
200 if( xCheckTimer != NULL )
\r
202 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
205 /* Start the scheduler. */
\r
206 vTaskStartScheduler();
\r
208 /* If all is well, the scheduler will now be running, and the following line
\r
209 will never be reached. If the following line does execute, then there was
\r
210 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
211 to be created. See the memory management section on the FreeRTOS web site
\r
212 for more details. */
\r
215 __asm volatile( "NOP" );
\r
218 /*-----------------------------------------------------------*/
\r
220 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
222 static long lChangedTimerPeriodAlready = pdFALSE;
\r
223 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
224 unsigned long ulErrorFound = pdFALSE;
\r
226 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
227 that they are all still running, and that none have detected an error. */
\r
229 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
231 ulErrorFound = pdTRUE;
\r
234 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
236 ulErrorFound = pdTRUE;
\r
239 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
241 ulErrorFound = pdTRUE;
\r
244 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
246 ulErrorFound = pdTRUE;
\r
249 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
251 ulErrorFound = pdTRUE;
\r
254 if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
256 ulErrorFound = pdTRUE;
\r
259 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
261 ulErrorFound = pdTRUE;
\r
264 /* Check that the register test 1 task is still running. */
\r
265 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
267 ulErrorFound = pdTRUE;
\r
269 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
271 /* Check that the register test 2 task is still running. */
\r
272 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
274 ulErrorFound = pdTRUE;
\r
276 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
278 /* Toggle the check LED to give an indication of the system status. If
\r
279 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
280 everything is ok. A faster toggle indicates an error. */
\r
281 configTOGGLE_LED();
\r
283 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
284 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
285 This will result in an increase in the rate at which mainCHECK_LED
\r
287 if( ulErrorFound != pdFALSE )
\r
289 if( lChangedTimerPeriodAlready == pdFALSE )
\r
291 lChangedTimerPeriodAlready = pdTRUE;
\r
293 /* This call to xTimerChangePeriod() uses a zero block time.
\r
294 Functions called from inside of a timer callback function must
\r
295 *never* attempt to block. */
\r
296 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
300 /*-----------------------------------------------------------*/
\r
302 /* This is a naked function. */
\r
303 static void vRegTest1Task( void *pvParameters )
\r
307 " \n" /* Fill the core registers with known values. */
\r
318 " mov r10, #110 \n"
\r
319 " mov r11, #111 \n"
\r
320 " mov r12, #112 \n"
\r
322 " vmov d0, r0, r1 \n" /* Fill the VFP registers with known values. */
\r
323 " vmov d1, r2, r3 \n"
\r
324 " vmov d2, r4, r5 \n"
\r
325 " vmov d3, r6, r7 \n"
\r
326 " vmov d4, r8, r9 \n"
\r
327 " vmov d5, r10, r11 \n"
\r
328 " vmov d6, r0, r1 \n"
\r
329 " vmov d7, r2, r3 \n"
\r
330 " vmov d8, r4, r5 \n"
\r
331 " vmov d9, r6, r7 \n"
\r
332 " vmov d10, r8, r9 \n"
\r
333 " vmov d11, r10, r11 \n"
\r
334 " vmov d12, r0, r1 \n"
\r
335 " vmov d13, r2, r3 \n"
\r
336 " vmov d14, r4, r5 \n"
\r
337 " vmov d15, r6, r7 \n"
\r
339 "reg1_loop: \n" /* Check all the VFP registers still contain the values set above." */
\r
340 " push { r0-r1 } \n" /* First save registers that are clobbered by the test. */
\r
342 " vmov r0, r1, d0 \n"
\r
344 " bne reg1_error_loopf \n"
\r
346 " bne reg1_error_loopf \n"
\r
347 " vmov r0, r1, d1 \n"
\r
349 " bne reg1_error_loopf \n"
\r
351 " bne reg1_error_loopf \n"
\r
352 " vmov r0, r1, d2 \n"
\r
354 " bne reg1_error_loopf \n"
\r
356 " bne reg1_error_loopf \n"
\r
357 " vmov r0, r1, d3 \n"
\r
359 " bne reg1_error_loopf \n"
\r
361 " bne reg1_error_loopf \n"
\r
362 " vmov r0, r1, d4 \n"
\r
364 " bne reg1_error_loopf \n"
\r
366 " bne reg1_error_loopf \n"
\r
367 " vmov r0, r1, d5 \n"
\r
369 " bne reg1_error_loopf \n"
\r
371 " bne reg1_error_loopf \n"
\r
372 " vmov r0, r1, d6 \n"
\r
374 " bne reg1_error_loopf \n"
\r
376 " bne reg1_error_loopf \n"
\r
377 " vmov r0, r1, d7 \n"
\r
379 " bne reg1_error_loopf \n"
\r
381 " bne reg1_error_loopf \n"
\r
382 " vmov r0, r1, d8 \n"
\r
384 " bne reg1_error_loopf \n"
\r
386 " bne reg1_error_loopf \n"
\r
387 " vmov r0, r1, d9 \n"
\r
389 " bne reg1_error_loopf \n"
\r
391 " bne reg1_error_loopf \n"
\r
392 " vmov r0, r1, d10 \n"
\r
394 " bne reg1_error_loopf \n"
\r
396 " bne reg1_error_loopf \n"
\r
397 " vmov r0, r1, d11 \n"
\r
399 " bne reg1_error_loopf \n"
\r
401 " bne reg1_error_loopf \n"
\r
402 " vmov r0, r1, d12 \n"
\r
404 " bne reg1_error_loopf \n"
\r
406 " bne reg1_error_loopf \n"
\r
407 " vmov r0, r1, d13 \n"
\r
409 " bne reg1_error_loopf \n"
\r
411 " bne reg1_error_loopf \n"
\r
412 " vmov r0, r1, d14 \n"
\r
414 " bne reg1_error_loopf \n"
\r
416 " bne reg1_error_loopf \n"
\r
417 " vmov r0, r1, d15 \n"
\r
419 " bne reg1_error_loopf \n"
\r
421 " bne reg1_error_loopf \n"
\r
423 " pop {r0-r1} \n" /* Restore the registers that were clobbered by the test. */
\r
425 " b reg1_loopf_pass \n" /* VFP register test passed. Jump to the core register test. */
\r
427 "reg1_error_loopf: \n"
\r
428 " b reg1_error_loopf \n" /* If this line is hit then a VFP register value was found to be\n incorrect. */
\r
430 "reg1_loopf_pass: \n"
\r
433 " bne reg1_error_loop \n"
\r
435 " bne reg1_error_loop \n"
\r
437 " bne reg1_error_loop \n"
\r
439 " bne reg1_error_loop \n"
\r
441 " bne reg1_error_loop \n"
\r
443 " bne reg1_error_loop \n"
\r
445 " bne reg1_error_loop \n"
\r
447 " bne reg1_error_loop \n"
\r
449 " bne reg1_error_loop \n"
\r
451 " bne reg1_error_loop \n"
\r
452 " cmp r10, #110 \n"
\r
453 " bne reg1_error_loop \n"
\r
454 " cmp r11, #111 \n"
\r
455 " bne reg1_error_loop \n"
\r
456 " cmp r12, #112 \n"
\r
457 " bne reg1_error_loop \n"
\r
459 " push { r0-r1 } \n" /* Everything passed, increment the loop counter. */
\r
460 " ldr r0, =ulRegTest1LoopCounter \n"
\r
462 " adds r1, r1, #1 \n"
\r
464 " pop { r0-r1 } \n"
\r
466 " b reg1_loop \n" /* Start again. */
\r
468 "reg1_error_loop: \n" /* If this line is hit then there was an error in a core register value. */
\r
469 " b reg1_error_loop \n" /* The loop ensures the loop counter stops incrementing. */
\r
473 /*-----------------------------------------------------------*/
\r
475 /* This is a naked function. */
\r
476 static void vRegTest2Task( void *pvParameters )
\r
480 " mov r0, #-1 \n" /* Set all the core registers to known values. */
\r
494 " vmov d0, r0, r1 \n" /* Set all the VFP to known values. */
\r
495 " vmov d1, r2, r3 \n"
\r
496 " vmov d2, r4, r5 \n"
\r
497 " vmov d3, r6, r7 \n"
\r
498 " vmov d4, r8, r9 \n"
\r
499 " vmov d5, r10, r11 \n"
\r
500 " vmov d6, r0, r1 \n"
\r
501 " vmov d7, r2, r3 \n"
\r
502 " vmov d8, r4, r5 \n"
\r
503 " vmov d9, r6, r7 \n"
\r
504 " vmov d10, r8, r9 \n"
\r
505 " vmov d11, r10, r11 \n"
\r
506 " vmov d12, r0, r1 \n"
\r
507 " vmov d13, r2, r3 \n"
\r
508 " vmov d14, r4, r5 \n"
\r
509 " vmov d15, r6, r7 \n"
\r
513 " push { r0-r1 } \n" /* Check all the VFP registers still contain the values set above. */
\r
514 " vmov r0, r1, d0 \n" /*First save registers that are clobbered by the test. */
\r
516 " bne reg2_error_loopf \n"
\r
518 " bne reg2_error_loopf \n"
\r
519 " vmov r0, r1, d1 \n"
\r
521 " bne reg2_error_loopf \n"
\r
523 " bne reg2_error_loopf \n"
\r
524 " vmov r0, r1, d2 \n"
\r
526 " bne reg2_error_loopf \n"
\r
528 " bne reg2_error_loopf \n"
\r
529 " vmov r0, r1, d3 \n"
\r
531 " bne reg2_error_loopf \n"
\r
533 " bne reg2_error_loopf \n"
\r
534 " vmov r0, r1, d4 \n"
\r
536 " bne reg2_error_loopf \n"
\r
538 " bne reg2_error_loopf \n"
\r
539 " vmov r0, r1, d5 \n"
\r
541 " bne reg2_error_loopf \n"
\r
543 " bne reg2_error_loopf \n"
\r
544 " vmov r0, r1, d6 \n"
\r
546 " bne reg2_error_loopf \n"
\r
548 " bne reg2_error_loopf \n"
\r
549 " vmov r0, r1, d7 \n"
\r
551 " bne reg2_error_loopf \n"
\r
553 " bne reg2_error_loopf \n"
\r
554 " vmov r0, r1, d8 \n"
\r
556 " bne reg2_error_loopf \n"
\r
558 " bne reg2_error_loopf \n"
\r
559 " vmov r0, r1, d9 \n"
\r
561 " bne reg2_error_loopf \n"
\r
563 " bne reg2_error_loopf \n"
\r
564 " vmov r0, r1, d10 \n"
\r
566 " bne reg2_error_loopf \n"
\r
568 " bne reg2_error_loopf \n"
\r
569 " vmov r0, r1, d11 \n"
\r
571 " bne reg2_error_loopf \n"
\r
573 " bne reg2_error_loopf \n"
\r
574 " vmov r0, r1, d12 \n"
\r
576 " bne reg2_error_loopf \n"
\r
578 " bne reg2_error_loopf \n"
\r
579 " vmov r0, r1, d13 \n"
\r
581 " bne reg2_error_loopf \n"
\r
583 " bne reg2_error_loopf \n"
\r
584 " vmov r0, r1, d14 \n"
\r
586 " bne reg2_error_loopf \n"
\r
588 " bne reg2_error_loopf \n"
\r
589 " vmov r0, r1, d15 \n"
\r
591 " bne reg2_error_loopf \n"
\r
593 " bne reg2_error_loopf \n"
\r
595 " pop {r0-r1} \n" /* Restore the registers that were clobbered by the test. */
\r
597 " b reg2_loopf_pass \n" /* VFP register test passed. Jump to the core register test. */
\r
599 "reg2_error_loopf: \n"
\r
600 " b reg2_error_loopf \n" /* If this line is hit then a VFP register value was found to be incorrect. */
\r
602 "reg2_loopf_pass: \n"
\r
605 " bne reg2_error_loop \n"
\r
607 " bne reg2_error_loop \n"
\r
609 " bne reg2_error_loop \n"
\r
611 " bne reg2_error_loop \n"
\r
613 " bne reg2_error_loop \n"
\r
615 " bne reg2_error_loop \n"
\r
617 " bne reg2_error_loop \n"
\r
619 " bne reg2_error_loop \n"
\r
621 " bne reg2_error_loop \n"
\r
623 " bne reg2_error_loop \n"
\r
625 " bne reg2_error_loop \n"
\r
627 " bne reg2_error_loop \n"
\r
629 " bne reg2_error_loop \n"
\r
631 " push { r0-r1 } \n" /* Increment the loop counter to indicate this test is still functioning correctly. */
\r
632 " ldr r0, =ulRegTest2LoopCounter \n"
\r
634 " adds r1, r1, #1 \n"
\r
637 " movs r0, #0x01 \n" /* Yield to increase test coverage. */
\r
638 " ldr r1, =0xe000ed04 \n" /*NVIC_INT_CTRL */
\r
639 " lsl r0, r0, #28 \n" /* Shift to PendSV bit */
\r
642 " pop { r0-r1 } \n"
\r
644 " b reg2_loop \n" /* Start again. */
\r
646 "reg2_error_loop: \n" /* If this line is hit then there was an error in a core register value. */
\r
647 " b reg2_error_loop \n" /* This loop ensures the loop counter variable stops incrementing. */
\r