2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /******************************************************************************
\r
66 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
67 * project, and a more comprehensive test and demo application. The
\r
68 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
69 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
70 * in main.c. This file implements the comprehensive test and demo version.
\r
72 * NOTE 2: This file only contains the source code that is specific to the
\r
73 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
74 * required to configure the hardware, are defined in main.c.
\r
75 ******************************************************************************
\r
77 * main_full() creates all the demo application tasks and a software timer, then
\r
78 * starts the scheduler. The web documentation provides more details of the
\r
79 * standard demo application tasks, which provide no particular functionality,
\r
80 * but do provide a good example of how to use the FreeRTOS API.
\r
82 * In addition to the standard demo tasks, the following tasks and tests are
\r
83 * defined and/or created within this file:
\r
85 * "Reg test" tasks - These fill both the core and floating point registers with
\r
86 * known values, then check that each register maintains its expected value for
\r
87 * the lifetime of the task. Each task uses a different set of values. The reg
\r
88 * test tasks execute with a very low priority, so get preempted very
\r
89 * frequently. A register containing an unexpected value is indicative of an
\r
90 * error in the context switching mechanism.
\r
92 * "Check" timer - The check software timer period is initially set to three
\r
93 * seconds. The callback function associated with the check software timer
\r
94 * checks that all the standard demo tasks, and the register check tasks, are
\r
95 * not only still executing, but are executing without reporting any errors. If
\r
96 * the check software timer discovers that a task has either stalled, or
\r
97 * reported an error, then it changes its own execution period from the initial
\r
98 * three seconds, to just 200ms. The check software timer callback function
\r
99 * also toggles the single LED each time it is called. This provides a visual
\r
100 * indication of the system status: If the LED toggles every three seconds,
\r
101 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
102 * an issue has been discovered with at least one task.
\r
105 /* Standard includes. */
\r
108 /* Kernel includes. */
\r
109 #include "FreeRTOS.h"
\r
111 #include "timers.h"
\r
112 #include "semphr.h"
\r
114 /* Standard demo application includes. */
\r
116 #include "semtest.h"
\r
117 #include "dynamic.h"
\r
118 #include "blocktim.h"
\r
119 #include "countsem.h"
\r
120 #include "GenQTest.h"
\r
121 #include "recmutex.h"
\r
123 /* Priorities for the demo application tasks. */
\r
124 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
125 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
126 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
127 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
128 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
130 /* A block time of zero simply means "don't block". */
\r
131 #define mainDONT_BLOCK ( 0UL )
\r
133 /* The period after which the check timer will expire, in ms, provided no errors
\r
134 have been reported by any of the standard demo tasks. ms are converted to the
\r
135 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
136 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
138 /* The period at which the check timer will expire, in ms, if an error has been
\r
139 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
140 in ticks using the portTICK_RATE_MS constant. */
\r
141 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
143 /*-----------------------------------------------------------*/
\r
146 * The check timer callback function, as described at the top of this file.
\r
148 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
151 * Register check tasks, and the tasks used to write over and check the contents
\r
152 * of the FPU registers, as described at the top of this file. The nature of
\r
153 * these files necessitates that they are written in an assembly file.
\r
155 static void prvRegTest1Task( void *pvParameters ) __attribute__((naked));
\r
156 static void prvRegTest2Task( void *pvParameters ) __attribute__((naked));
\r
158 /*-----------------------------------------------------------*/
\r
160 /* The following two variables are used to communicate the status of the
\r
161 register check tasks to the check software timer. If the variables keep
\r
162 incrementing, then the register check tasks has not discovered any errors. If
\r
163 a variable stops incrementing, then an error has been found. */
\r
164 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
166 /*-----------------------------------------------------------*/
\r
168 void main_full( void )
\r
170 xTimerHandle xCheckTimer = NULL;
\r
172 /* Start all the other standard demo/test tasks. The have not particular
\r
173 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
175 vStartDynamicPriorityTasks();
\r
176 vCreateBlockTimeTasks();
\r
177 vStartCountingSemaphoreTasks();
\r
178 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
179 vStartRecursiveMutexTasks();
\r
180 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
181 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
183 /* Create the register check tasks, as described at the top of this
\r
185 xTaskCreate( prvRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
186 xTaskCreate( prvRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
188 /* Create the software timer that performs the 'check' functionality,
\r
189 as described at the top of this file. */
\r
190 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
191 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
192 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
193 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
194 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
197 if( xCheckTimer != NULL )
\r
199 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
202 /* Start the scheduler. */
\r
203 vTaskStartScheduler();
\r
205 /* If all is well, the scheduler will now be running, and the following line
\r
206 will never be reached. If the following line does execute, then there was
\r
207 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
208 to be created. See the memory management section on the FreeRTOS web site
\r
209 for more details. */
\r
212 /*-----------------------------------------------------------*/
\r
214 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
216 static long lChangedTimerPeriodAlready = pdFALSE;
\r
217 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
218 unsigned long ulErrorFound = pdFALSE;
\r
220 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
221 that they are all still running, and that none have detected an error. */
\r
223 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
225 ulErrorFound = pdTRUE;
\r
228 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
230 ulErrorFound = pdTRUE;
\r
233 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
235 ulErrorFound = pdTRUE;
\r
238 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
240 ulErrorFound = pdTRUE;
\r
243 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
245 ulErrorFound = pdTRUE;
\r
248 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
250 ulErrorFound = pdTRUE;
\r
253 /* Check that the register test 1 task is still running. */
\r
254 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
256 ulErrorFound = pdTRUE;
\r
258 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
260 /* Check that the register test 2 task is still running. */
\r
261 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
263 ulErrorFound = pdTRUE;
\r
265 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
267 /* Toggle the check LED to give an indication of the system status. If
\r
268 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
269 everything is ok. A faster toggle indicates an error. */
\r
270 configTOGGLE_LED();
\r
272 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
273 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
274 This will result in an increase in the rate at which mainCHECK_LED
\r
276 if( ulErrorFound != pdFALSE )
\r
278 if( lChangedTimerPeriodAlready == pdFALSE )
\r
280 lChangedTimerPeriodAlready = pdTRUE;
\r
282 /* This call to xTimerChangePeriod() uses a zero block time.
\r
283 Functions called from inside of a timer callback function must
\r
284 *never* attempt to block. */
\r
285 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
289 /*-----------------------------------------------------------*/
\r
291 /* This is a naked function. */
\r
292 static void prvRegTest1Task( void *pvParameters )
\r
296 " /* Fill the core registers with known values. */ \n"
\r
307 " mov r10, #110 \n"
\r
308 " mov r11, #111 \n"
\r
309 " mov r12, #112 \n"
\r
311 " /* Fill the VFP registers with known values. */ \n"
\r
312 " vmov d0, r0, r1 \n"
\r
313 " vmov d1, r2, r3 \n"
\r
314 " vmov d2, r4, r5 \n"
\r
315 " vmov d3, r6, r7 \n"
\r
316 " vmov d4, r8, r9 \n"
\r
317 " vmov d5, r10, r11 \n"
\r
318 " vmov d6, r0, r1 \n"
\r
319 " vmov d7, r2, r3 \n"
\r
320 " vmov d8, r4, r5 \n"
\r
321 " vmov d9, r6, r7 \n"
\r
322 " vmov d10, r8, r9 \n"
\r
323 " vmov d11, r10, r11 \n"
\r
324 " vmov d12, r0, r1 \n"
\r
325 " vmov d13, r2, r3 \n"
\r
326 " vmov d14, r4, r5 \n"
\r
327 " vmov d15, r6, r7 \n"
\r
330 " /* Check all the VFP registers still contain the values set above.\n"
\r
331 " First save registers that are clobbered by the test. */ \n"
\r
332 " push { r0-r1 } \n"
\r
334 " vmov r0, r1, d0 \n"
\r
336 " bne reg1_error_loopf \n"
\r
338 " bne reg1_error_loopf \n"
\r
339 " vmov r0, r1, d1 \n"
\r
341 " bne reg1_error_loopf \n"
\r
343 " bne reg1_error_loopf \n"
\r
344 " vmov r0, r1, d2 \n"
\r
346 " bne reg1_error_loopf \n"
\r
348 " bne reg1_error_loopf \n"
\r
349 " vmov r0, r1, d3 \n"
\r
351 " bne reg1_error_loopf \n"
\r
353 " bne reg1_error_loopf \n"
\r
354 " vmov r0, r1, d4 \n"
\r
356 " bne reg1_error_loopf \n"
\r
358 " bne reg1_error_loopf \n"
\r
359 " vmov r0, r1, d5 \n"
\r
361 " bne reg1_error_loopf \n"
\r
363 " bne reg1_error_loopf \n"
\r
364 " vmov r0, r1, d6 \n"
\r
366 " bne reg1_error_loopf \n"
\r
368 " bne reg1_error_loopf \n"
\r
369 " vmov r0, r1, d7 \n"
\r
371 " bne reg1_error_loopf \n"
\r
373 " bne reg1_error_loopf \n"
\r
374 " vmov r0, r1, d8 \n"
\r
376 " bne reg1_error_loopf \n"
\r
378 " bne reg1_error_loopf \n"
\r
379 " vmov r0, r1, d9 \n"
\r
381 " bne reg1_error_loopf \n"
\r
383 " bne reg1_error_loopf \n"
\r
384 " vmov r0, r1, d10 \n"
\r
386 " bne reg1_error_loopf \n"
\r
388 " bne reg1_error_loopf \n"
\r
389 " vmov r0, r1, d11 \n"
\r
391 " bne reg1_error_loopf \n"
\r
393 " bne reg1_error_loopf \n"
\r
394 " vmov r0, r1, d12 \n"
\r
396 " bne reg1_error_loopf \n"
\r
398 " bne reg1_error_loopf \n"
\r
399 " vmov r0, r1, d13 \n"
\r
401 " bne reg1_error_loopf \n"
\r
403 " bne reg1_error_loopf \n"
\r
404 " vmov r0, r1, d14 \n"
\r
406 " bne reg1_error_loopf \n"
\r
408 " bne reg1_error_loopf \n"
\r
409 " vmov r0, r1, d15 \n"
\r
411 " bne reg1_error_loopf \n"
\r
413 " bne reg1_error_loopf \n"
\r
415 " /* Restore the registers that were clobbered by the test. */\n"
\r
418 " /* VFP register test passed. Jump to the core register test. */\n"
\r
419 " b reg1_loopf_pass \n"
\r
421 "reg1_error_loopf: \n"
\r
422 " /* If this line is hit then a VFP register value was found to be\n"
\r
423 " incorrect. */ \n"
\r
424 " b reg1_error_loopf \n"
\r
426 "reg1_loopf_pass: \n"
\r
429 " bne reg1_error_loop \n"
\r
431 " bne reg1_error_loop \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
448 " cmp r10, #110 \n"
\r
449 " bne reg1_error_loop \n"
\r
450 " cmp r11, #111 \n"
\r
451 " bne reg1_error_loop \n"
\r
452 " cmp r12, #112 \n"
\r
453 " bne reg1_error_loop \n"
\r
455 " /* Everything passed, increment the loop counter. */ \n"
\r
456 " push { r0-r1 } \n"
\r
457 " ldr r0, =ulRegTest1LoopCounter \n"
\r
459 " adds r1, r1, #1 \n"
\r
461 " pop { r0-r1 } \n"
\r
463 " /* Start again. */ \n"
\r
466 "reg1_error_loop: \n"
\r
467 " /* If this line is hit then there was an error in a core register value.\n"
\r
468 " The loop ensures the loop counter stops incrementing. */\n"
\r
469 " b reg1_error_loop \n"
\r
473 /*-----------------------------------------------------------*/
\r
475 /* This is a naked function. */
\r
476 static void prvRegTest2Task( void *pvParameters )
\r
480 " /* Set all the core registers to known values. */ \n"
\r
495 " /* Set all the VFP to known values. */ \n"
\r
496 " vmov d0, r0, r1 \n"
\r
497 " vmov d1, r2, r3 \n"
\r
498 " vmov d2, r4, r5 \n"
\r
499 " vmov d3, r6, r7 \n"
\r
500 " vmov d4, r8, r9 \n"
\r
501 " vmov d5, r10, r11 \n"
\r
502 " vmov d6, r0, r1 \n"
\r
503 " vmov d7, r2, r3 \n"
\r
504 " vmov d8, r4, r5 \n"
\r
505 " vmov d9, r6, r7 \n"
\r
506 " vmov d10, r8, r9 \n"
\r
507 " vmov d11, r10, r11 \n"
\r
508 " vmov d12, r0, r1 \n"
\r
509 " vmov d13, r2, r3 \n"
\r
510 " vmov d14, r4, r5 \n"
\r
511 " vmov d15, r6, r7 \n"
\r
515 " /* Check all the VFP registers still contain the values set above.\n"
\r
516 " First save registers that are clobbered by the test. */ \n"
\r
517 " push { r0-r1 } \n"
\r
519 " vmov r0, r1, d0 \n"
\r
521 " bne reg2_error_loopf \n"
\r
523 " bne reg2_error_loopf \n"
\r
524 " vmov r0, r1, d1 \n"
\r
526 " bne reg2_error_loopf \n"
\r
528 " bne reg2_error_loopf \n"
\r
529 " vmov r0, r1, d2 \n"
\r
531 " bne reg2_error_loopf \n"
\r
533 " bne reg2_error_loopf \n"
\r
534 " vmov r0, r1, d3 \n"
\r
536 " bne reg2_error_loopf \n"
\r
538 " bne reg2_error_loopf \n"
\r
539 " vmov r0, r1, d4 \n"
\r
541 " bne reg2_error_loopf \n"
\r
543 " bne reg2_error_loopf \n"
\r
544 " vmov r0, r1, d5 \n"
\r
546 " bne reg2_error_loopf \n"
\r
548 " bne reg2_error_loopf \n"
\r
549 " vmov r0, r1, d6 \n"
\r
551 " bne reg2_error_loopf \n"
\r
553 " bne reg2_error_loopf \n"
\r
554 " vmov r0, r1, d7 \n"
\r
556 " bne reg2_error_loopf \n"
\r
558 " bne reg2_error_loopf \n"
\r
559 " vmov r0, r1, d8 \n"
\r
561 " bne reg2_error_loopf \n"
\r
563 " bne reg2_error_loopf \n"
\r
564 " vmov r0, r1, d9 \n"
\r
566 " bne reg2_error_loopf \n"
\r
568 " bne reg2_error_loopf \n"
\r
569 " vmov r0, r1, d10 \n"
\r
571 " bne reg2_error_loopf \n"
\r
573 " bne reg2_error_loopf \n"
\r
574 " vmov r0, r1, d11 \n"
\r
576 " bne reg2_error_loopf \n"
\r
578 " bne reg2_error_loopf \n"
\r
579 " vmov r0, r1, d12 \n"
\r
581 " bne reg2_error_loopf \n"
\r
583 " bne reg2_error_loopf \n"
\r
584 " vmov r0, r1, d13 \n"
\r
586 " bne reg2_error_loopf \n"
\r
588 " bne reg2_error_loopf \n"
\r
589 " vmov r0, r1, d14 \n"
\r
591 " bne reg2_error_loopf \n"
\r
593 " bne reg2_error_loopf \n"
\r
594 " vmov r0, r1, d15 \n"
\r
596 " bne reg2_error_loopf \n"
\r
598 " bne reg2_error_loopf \n"
\r
600 " /* Restore the registers that were clobbered by the test. */\n"
\r
603 " /* VFP register test passed. Jump to the core register test. */\n"
\r
604 " b reg2_loopf_pass \n"
\r
606 "reg2_error_loopf: \n"
\r
607 " /* If this line is hit then a VFP register value was found to be\n"
\r
608 " incorrect. */ \n"
\r
609 " b reg2_error_loopf \n"
\r
611 "reg2_loopf_pass: \n"
\r
614 " bne reg2_error_loop \n"
\r
616 " bne reg2_error_loop \n"
\r
618 " bne reg2_error_loop \n"
\r
620 " bne reg2_error_loop \n"
\r
622 " bne reg2_error_loop \n"
\r
624 " bne reg2_error_loop \n"
\r
626 " bne reg2_error_loop \n"
\r
628 " bne reg2_error_loop \n"
\r
630 " bne reg2_error_loop \n"
\r
632 " bne reg2_error_loop \n"
\r
634 " bne reg2_error_loop \n"
\r
636 " bne reg2_error_loop \n"
\r
638 " bne reg2_error_loop \n"
\r
640 " /* Increment the loop counter to indicate this test is still functioning\n"
\r
641 " correctly. */ \n"
\r
642 " push { r0-r1 } \n"
\r
643 " ldr r0, =ulRegTest2LoopCounter \n"
\r
645 " adds r1, r1, #1 \n"
\r
648 " /* Yield to increase test coverage. */ \n"
\r
649 " movs r0, #0x01 \n"
\r
650 " ldr r1, =0xe000ed04 \n" /*NVIC_INT_CTRL */
\r
651 " lsl r0, #28 \n" /* Shift to PendSV bit */
\r
654 " pop { r0-r1 } \n"
\r
656 " /* Start again. */ \n"
\r
659 "reg2_error_loop: \n"
\r
660 " /* If this line is hit then there was an error in a core register value.\n"
\r
661 " This loop ensures the loop counter variable stops incrementing. */\n"
\r
662 " b reg2_error_loop \n"
\r