2 * FreeRTOS Kernel V10.0.1
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
29 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
30 * project, and a more comprehensive test and demo application. The
\r
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
32 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
33 * in main.c. This file implements the comprehensive test and demo version.
\r
35 * NOTE 2: This file only contains the source code that is specific to the
\r
36 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
37 * required to configure the hardware, are defined in main.c.
\r
38 ******************************************************************************
\r
40 * main_full() creates all the demo application tasks and a software timer, then
\r
41 * starts the scheduler. The web documentation provides more details of the
\r
42 * standard demo application tasks, which provide no particular functionality,
\r
43 * but do provide a good example of how to use the FreeRTOS API.
\r
45 * In addition to the standard demo tasks, the following tasks and tests are
\r
46 * defined and/or created within this file:
\r
48 * "Reg test" tasks - These fill both the core and floating point registers with
\r
49 * known values, then check that each register maintains its expected value for
\r
50 * the lifetime of the task. Each task uses a different set of values. The reg
\r
51 * test tasks execute with a very low priority, so get preempted very
\r
52 * frequently. A register containing an unexpected value is indicative of an
\r
53 * error in the context switching mechanism.
\r
55 * "Check" timer - The check software timer period is initially set to three
\r
56 * seconds. The callback function associated with the check software timer
\r
57 * checks that all the standard demo tasks, and the register check tasks, are
\r
58 * not only still executing, but are executing without reporting any errors. If
\r
59 * the check software timer discovers that a task has either stalled, or
\r
60 * reported an error, then it changes its own execution period from the initial
\r
61 * three seconds, to just 200ms. The check software timer callback function
\r
62 * also toggles the single LED each time it is called. This provides a visual
\r
63 * indication of the system status: If the LED toggles every three seconds,
\r
64 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
65 * an issue has been discovered with at least one task.
\r
68 /* Standard includes. */
\r
71 /* Kernel includes. */
\r
72 #include "FreeRTOS.h"
\r
77 /* Standard demo application includes. */
\r
79 #include "semtest.h"
\r
80 #include "dynamic.h"
\r
81 #include "blocktim.h"
\r
82 #include "countsem.h"
\r
83 #include "GenQTest.h"
\r
84 #include "recmutex.h"
\r
86 /* Priorities for the demo application tasks. */
\r
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
88 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
89 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
90 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
91 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
93 /* A block time of zero simply means "don't block". */
\r
94 #define mainDONT_BLOCK ( 0UL )
\r
96 /* The period after which the check timer will expire, in ms, provided no errors
\r
97 have been reported by any of the standard demo tasks. ms are converted to the
\r
98 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
99 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
101 /* The period at which the check timer will expire, in ms, if an error has been
\r
102 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
103 in ticks using the portTICK_PERIOD_MS constant. */
\r
104 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
106 /*-----------------------------------------------------------*/
\r
109 * The check timer callback function, as described at the top of this file.
\r
111 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
114 * Register check tasks, and the tasks used to write over and check the contents
\r
115 * of the FPU registers, as described at the top of this file. The nature of
\r
116 * these files necessitates that they are written in an assembly file.
\r
118 extern void vRegTest1Task( void *pvParameters );
\r
119 extern void vRegTest2Task( void *pvParameters );
\r
121 /*-----------------------------------------------------------*/
\r
123 /* The following two variables are used to communicate the status of the
\r
124 register check tasks to the check software timer. If the variables keep
\r
125 incrementing, then the register check tasks have not discovered any errors. If
\r
126 a variable stops incrementing, then an error has been found. */
\r
127 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
129 /*-----------------------------------------------------------*/
\r
131 void main_full( void )
\r
133 TimerHandle_t xCheckTimer = NULL;
\r
135 /* Start all the other standard demo/test tasks. The have not particular
\r
136 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
138 vStartDynamicPriorityTasks();
\r
139 vCreateBlockTimeTasks();
\r
140 vStartCountingSemaphoreTasks();
\r
141 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
142 vStartRecursiveMutexTasks();
\r
143 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
144 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
146 /* Create the register check tasks, as described at the top of this
\r
148 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
149 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
\r
151 /* Create the software timer that performs the 'check' functionality,
\r
152 as described at the top of this file. */
\r
153 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
154 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
155 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
156 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
157 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
160 if( xCheckTimer != NULL )
\r
162 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
165 /* Start the scheduler. */
\r
166 vTaskStartScheduler();
\r
168 /* If all is well, the scheduler will now be running, and the following line
\r
169 will never be reached. If the following line does execute, then there was
\r
170 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
171 to be created. See the memory management section on the FreeRTOS web site
\r
172 for more details. */
\r
175 /*-----------------------------------------------------------*/
\r
177 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
179 static long lChangedTimerPeriodAlready = pdFALSE;
\r
180 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
181 unsigned long ulErrorFound = pdFALSE;
\r
183 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
184 that they are all still running, and that none have detected an error. */
\r
186 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
188 ulErrorFound = pdTRUE;
\r
191 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
193 ulErrorFound = pdTRUE;
\r
196 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
198 ulErrorFound = pdTRUE;
\r
201 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
203 ulErrorFound = pdTRUE;
\r
206 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
208 ulErrorFound = pdTRUE;
\r
211 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
213 ulErrorFound = pdTRUE;
\r
216 /* Check that the register test 1 task is still running. */
\r
217 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
219 ulErrorFound = pdTRUE;
\r
221 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
223 /* Check that the register test 2 task is still running. */
\r
224 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
226 ulErrorFound = pdTRUE;
\r
228 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
230 /* Toggle the check LED to give an indication of the system status. If
\r
231 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
232 everything is ok. A faster toggle indicates an error. */
\r
233 configTOGGLE_LED();
\r
235 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
236 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
237 This will result in an increase in the rate at which mainCHECK_LED
\r
239 if( ulErrorFound != pdFALSE )
\r
241 if( lChangedTimerPeriodAlready == pdFALSE )
\r
243 lChangedTimerPeriodAlready = pdTRUE;
\r
245 /* This call to xTimerChangePeriod() uses a zero block time.
\r
246 Functions called from inside of a timer callback function must
\r
247 *never* attempt to block. */
\r
248 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
252 /*-----------------------------------------------------------*/
\r