2 * FreeRTOS Kernel V10.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
30 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
31 * project, and a more comprehensive test and demo application. The
\r
32 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
33 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
34 * in main.c. This file implements the comprehensive test and demo version.
\r
36 * NOTE 2: This file only contains the source code that is specific to the
\r
37 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
38 * required to configure the hardware, are defined in main.c.
\r
40 ******************************************************************************
\r
42 * main_full() creates all the demo application tasks and software timers, then
\r
43 * starts the scheduler. The web documentation provides more details of the
\r
44 * standard demo application tasks, which provide no particular functionality,
\r
45 * but do provide a good example of how to use the FreeRTOS API.
\r
47 * "Reg test" tasks - These fill both the core and floating point registers with
\r
48 * known values, then check that each register maintains its expected value for
\r
49 * the lifetime of the task. Each task uses a different set of values. The reg
\r
50 * test tasks execute with a very low priority, so get preempted very
\r
51 * frequently. A register containing an unexpected value is indicative of an
\r
52 * error in the context switching mechanism.
\r
54 * "Check" task - The check task period is initially set to three seconds. The
\r
55 * task checks that all the standard demo tasks, and the register check tasks,
\r
56 * are not only still executing, but are executing without reporting any errors.
\r
57 * If the check task discovers that a task has either stalled, or reported an
\r
58 * error, then it changes its own execution period from the initial three
\r
59 * seconds, to just 200ms. The check task also toggles an LED each time it is
\r
60 * called. This provides a visual indication of the system status: If the LED
\r
61 * toggles every three seconds, then no issues have been discovered. If the LED
\r
62 * toggles every 200ms, then an issue has been discovered with at least one
\r
66 /* Standard includes. */
\r
69 /* Kernel includes. */
\r
70 #include "FreeRTOS.h"
\r
75 /* Standard demo application includes. */
\r
77 #include "semtest.h"
\r
78 #include "dynamic.h"
\r
80 #include "blocktim.h"
\r
81 #include "countsem.h"
\r
82 #include "GenQTest.h"
\r
83 #include "recmutex.h"
\r
85 #include "partest.h"
\r
86 #include "TimerDemo.h"
\r
87 #include "QueueOverwrite.h"
\r
88 #include "IntQueue.h"
\r
89 #include "EventGroupsDemo.h"
\r
90 #include "IntSemTest.h"
\r
91 #include "QueueSet.h"
\r
92 #include "TaskNotify.h"
\r
94 /* Priorities for the demo application tasks. */
\r
95 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
96 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
97 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
98 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
99 #define mainCDC_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2UL )
\r
100 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
101 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
102 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
104 /* The initial priority used by the UART command console task. */
\r
105 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
107 /* A block time of zero simply means "don't block". */
\r
108 #define mainDONT_BLOCK ( 0UL )
\r
110 /* The period of the check task, in ms, provided no errors have been reported by
\r
111 any of the standard demo tasks. ms are converted to the equivalent in ticks
\r
112 using the pdMS_TO_TICKS() macro constant. */
\r
113 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 3000UL )
\r
115 /* The period of the check task, in ms, if an error has been reported in one of
\r
116 the standard demo tasks. ms are converted to the equivalent in ticks using the
\r
117 pdMS_TO_TICKS() macro. */
\r
118 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 200UL )
\r
120 /* Parameters that are passed into the register check tasks solely for the
\r
121 purpose of ensuring parameters are passed into tasks correctly. */
\r
122 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
123 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
125 /* The base period used by the timer test tasks. */
\r
126 #define mainTIMER_TEST_PERIOD ( 50 )
\r
128 /* The LED is used to show the demo status. (not connected on Rev A hardware) */
\r
129 #define mainTOGGLE_LED() HAL_GPIO_TogglePin( GPIOF, GPIO_PIN_10 )
\r
131 /*-----------------------------------------------------------*/
\r
134 * Called by main() to run the full demo (as opposed to the blinky demo) when
\r
135 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
137 void main_full( void );
\r
140 * The check task, as described at the top of this file.
\r
142 static void prvCheckTask( void *pvParameters );
\r
145 * Register check tasks, and the tasks used to write over and check the contents
\r
146 * of the FPU registers, as described at the top of this file. The nature of
\r
147 * these files necessitates that they are written in an assembly file, but the
\r
148 * entry points are kept in the C file for the convenience of checking the task
\r
151 static void prvRegTestTaskEntry1( void *pvParameters );
\r
152 extern void vRegTest1Implementation( void );
\r
153 static void prvRegTestTaskEntry2( void *pvParameters );
\r
154 extern void vRegTest2Implementation( void );
\r
157 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
158 * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
\r
160 extern void vRegisterSampleCLICommands( void );
\r
163 * The task that manages the FreeRTOS+CLI input and output.
\r
165 extern void vUSBCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
\r
167 /*-----------------------------------------------------------*/
\r
169 /* The following two variables are used to communicate the status of the
\r
170 register check tasks to the check task. If the variables keep incrementing,
\r
171 then the register check tasks have not discovered any errors. If a variable
\r
172 stops incrementing, then an error has been found. */
\r
173 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
175 /*-----------------------------------------------------------*/
\r
177 void main_full( void )
\r
179 /* Start all the other standard demo/test tasks. They have no particular
\r
180 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
182 vStartInterruptQueueTasks();
\r
183 vStartDynamicPriorityTasks();
\r
184 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
185 vCreateBlockTimeTasks();
\r
186 vStartCountingSemaphoreTasks();
\r
187 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
188 vStartRecursiveMutexTasks();
\r
189 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
190 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
191 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
192 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
\r
193 vStartEventGroupTasks();
\r
194 vStartInterruptSemaphoreTasks();
\r
195 vStartQueueSetTasks();
\r
196 vStartTaskNotifyTask();
\r
198 /* Create the register check tasks, as described at the top of this file */
\r
199 xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
200 xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
202 /* Create the task that performs the 'check' functionality, as described at
\r
203 the top of this file. */
\r
204 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
206 /* The set of tasks created by the following function call have to be
\r
207 created last as they keep account of the number of tasks they expect to see
\r
209 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
211 /* Start the scheduler. */
\r
212 vTaskStartScheduler();
\r
214 /* If all is well, the scheduler will now be running, and the following
\r
215 line will never be reached. If the following line does execute, then
\r
216 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
217 timer tasks to be created. See the memory management section on the
\r
218 FreeRTOS web site for more details on the FreeRTOS heap
\r
219 http://www.freertos.org/a00111.html. */
\r
222 /*-----------------------------------------------------------*/
\r
224 static void prvCheckTask( void *pvParameters )
\r
226 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
227 TickType_t xLastExecutionTime;
\r
228 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
229 unsigned long ulErrorFound = pdFALSE;
\r
231 /* Just to stop compiler warnings. */
\r
232 ( void ) pvParameters;
\r
234 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
235 works correctly. */
\r
236 xLastExecutionTime = xTaskGetTickCount();
\r
238 /* Cycle for ever, delaying then checking all the other tasks are still
\r
239 operating without error. The onboard LED is toggled on each iteration.
\r
240 If an error is detected then the delay period is decreased from
\r
241 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
242 effect of increasing the rate at which the onboard LED toggles, and in so
\r
243 doing gives visual feedback of the system status. */
\r
246 /* Delay until it is time to execute again. */
\r
247 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
249 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
250 that they are all still running, and that none have detected an error. */
\r
251 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
253 ulErrorFound = 1UL << 0UL;
\r
256 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
258 ulErrorFound = 1UL << 1UL;
\r
261 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
263 ulErrorFound = 1UL << 2UL;
\r
266 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
268 ulErrorFound = 1UL << 3UL;
\r
271 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
273 ulErrorFound = 1UL << 4UL;
\r
276 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
278 ulErrorFound = 1UL << 5UL;
\r
281 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
283 ulErrorFound = 1UL << 6UL;
\r
286 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
288 ulErrorFound = 1UL << 7UL;
\r
291 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
293 ulErrorFound = 1UL << 8UL;
\r
296 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) xDelayPeriod ) != pdPASS )
\r
298 ulErrorFound = 1UL << 9UL;
\r
301 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
303 ulErrorFound = 1UL << 10UL;
\r
306 if( xIsQueueOverwriteTaskStillRunning() != pdPASS )
\r
308 ulErrorFound = 1UL << 11UL;
\r
311 if( xAreEventGroupTasksStillRunning() != pdPASS )
\r
313 ulErrorFound = 1UL << 12UL;
\r
316 if( xAreInterruptSemaphoreTasksStillRunning() != pdPASS )
\r
318 ulErrorFound = 1UL << 13UL;
\r
321 if( xAreQueueSetTasksStillRunning() != pdPASS )
\r
323 ulErrorFound = 1UL << 14UL;
\r
326 if( xAreTaskNotificationTasksStillRunning() != pdPASS )
\r
328 ulErrorFound = 1UL << 15UL;
\r
331 /* Check that the register test 1 task is still running. */
\r
332 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
334 ulErrorFound = 1UL << 16UL;
\r
336 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
338 /* Check that the register test 2 task is still running. */
\r
339 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
341 ulErrorFound = 1UL << 17UL;
\r
343 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
345 /* Toggle the check LED to give an indication of the system status. If
\r
346 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then
\r
347 everything is ok. A faster toggle indicates an error. */
\r
350 if( ulErrorFound != pdFALSE )
\r
352 /* An error has been detected in one of the tasks - flash the LED
\r
353 at a higher frequency to give visible feedback that something has
\r
355 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
359 /*-----------------------------------------------------------*/
\r
361 static void prvRegTestTaskEntry1( void *pvParameters )
\r
363 /* Although the regtest task is written in assembler, its entry point is
\r
364 written in C for convenience of checking the task parameter is being passed
\r
366 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
368 /* Start the part of the test that is written in assembler. */
\r
369 vRegTest1Implementation();
\r
372 /* The following line will only execute if the task parameter is found to
\r
373 be incorrect. The check task will detect that the regtest loop counter is
\r
374 not being incremented and flag an error. */
\r
375 vTaskDelete( NULL );
\r
377 /*-----------------------------------------------------------*/
\r
379 static void prvRegTestTaskEntry2( void *pvParameters )
\r
381 /* Although the regtest task is written in assembler, its entry point is
\r
382 written in C for convenience of checking the task parameter is being passed
\r
384 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
386 /* Start the part of the test that is written in assembler. */
\r
387 vRegTest2Implementation();
\r
390 /* The following line will only execute if the task parameter is found to
\r
391 be incorrect. The check task will detect that the regtest loop counter is
\r
392 not being incremented and flag an error. */
\r
393 vTaskDelete( NULL );
\r
395 /*-----------------------------------------------------------*/
\r