2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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
29 /******************************************************************************
\r
30 * NOTE 1: This project provides three demo applications. A simple blinky
\r
31 * style project, a more comprehensive test and demo application, and an
\r
32 * lwIP example. The mainSELECTED_APPLICATION setting in main.c is used to
\r
33 * select between the three. See the notes on using mainSELECTED_APPLICATION
\r
34 * in main.c. This file implements the comprehensive 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 * In addition to the standard demo tasks, the following tasks and tests are
\r
48 * defined and/or created within this file:
\r
50 * FreeRTOS+CLI command console. The command console is access through the
\r
51 * UART to USB connector on the ZC702 Zynq development board (marked J2). For
\r
52 * reasons of robustness testing the UART driver is deliberately written to be
\r
53 * inefficient and should not be used as a template for a production driver.
\r
54 * Type "help" to see a list of registered commands. The FreeRTOS+CLI license
\r
55 * is different to the FreeRTOS license, see http://www.FreeRTOS.org/cli for
\r
56 * license and usage details. The default baud rate is 115200.
\r
58 * "Reg test" tasks - These fill both the core and floating point registers with
\r
59 * known values, then check that each register maintains its expected value for
\r
60 * the lifetime of the task. Each task uses a different set of values. The reg
\r
61 * test tasks execute with a very low priority, so get preempted very
\r
62 * frequently. A register containing an unexpected value is indicative of an
\r
63 * error in the context switching mechanism.
\r
65 * "Check" task - The check task period is initially set to three seconds. The
\r
66 * task checks that all the standard demo tasks, and the register check tasks,
\r
67 * are not only still executing, but are executing without reporting any errors.
\r
68 * If the check task discovers that a task has either stalled, or reported an
\r
69 * error, then it changes its own execution period from the initial three
\r
70 * seconds, to just 200ms. The check task also toggles an LED each time it is
\r
71 * called. This provides a visual indication of the system status: If the LED
\r
72 * toggles every three seconds, then no issues have been discovered. If the LED
\r
73 * toggles every 200ms, then an issue has been discovered with at least one
\r
77 /* Standard includes. */
\r
80 /* Kernel includes. */
\r
81 #include "FreeRTOS.h"
\r
86 /* Standard demo application includes. */
\r
87 #include "flash_timer.h"
\r
89 #include "semtest.h"
\r
90 #include "dynamic.h"
\r
91 #include "blocktim.h"
\r
92 #include "countsem.h"
\r
93 #include "GenQTest.h"
\r
94 #include "recmutex.h"
\r
95 #include "partest.h"
\r
97 #include "TimerDemo.h"
\r
98 #include "EventGroupsDemo.h"
\r
99 #include "TaskNotify.h"
\r
100 #include "IntSemTest.h"
\r
101 #include "AbortDelay.h"
\r
103 /* Priorities for the demo application tasks. */
\r
104 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
105 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
106 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
107 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
108 #define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2UL )
\r
109 #define mainCOM_TEST_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
111 #define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )
\r
112 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY )
\r
114 /* The priority used by the UART command console task. */
\r
115 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
117 /* The LED used by the check task. */
\r
118 #define mainCHECK_LED ( 7 )
\r
121 /* A block time of zero simply means "don't block". */
\r
122 #define mainDONT_BLOCK ( 0UL )
\r
124 /* The period of the check task, in ms, provided no errors have been reported by
\r
125 any of the standard demo tasks. ms are converted to the equivalent in ticks
\r
126 using the pdMS_TO_TICKS() macro constant. */
\r
127 #define mainNO_ERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 3000UL ) )
\r
129 /* The period of the check task, in ms, if an error has been reported in one of
\r
130 the standard demo tasks. ms are converted to the equivalent in ticks using the
\r
131 pdMS_TO_TICKS() macro. */
\r
132 #define mainERROR_CHECK_TASK_PERIOD ( pdMS_TO_TICKS( 200UL ) )
\r
134 /* Parameters that are passed into the register check tasks solely for the
\r
135 purpose of ensuring parameters are passed into tasks correctly. */
\r
136 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
137 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
139 /* The base period used by the timer test tasks. */
\r
140 #define mainTIMER_TEST_PERIOD ( 50 )
\r
142 /* The number of timers to create that just flash LEDs. */
\r
143 #define mainNUM_FLASH_TIMERS ( 3 )
\r
144 /*-----------------------------------------------------------*/
\r
148 * The check task, as described at the top of this file.
\r
150 static void prvCheckTask( void *pvParameters );
\r
153 * Register check tasks, and the tasks used to write over and check the contents
\r
154 * of the FPU registers, as described at the top of this file. The nature of
\r
155 * these files necessitates that they are written in an assembly file, but the
\r
156 * entry points are kept in the C file for the convenience of checking the task
\r
159 static void prvRegTestTaskEntry1( void *pvParameters );
\r
160 extern void vRegTest1Implementation( void );
\r
161 static void prvRegTestTaskEntry2( void *pvParameters );
\r
162 extern void vRegTest2Implementation( void );
\r
165 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
166 * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
\r
168 extern void vRegisterSampleCLICommands( void );
\r
171 * The task that manages the FreeRTOS+CLI input and output.
\r
173 extern void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
\r
176 * When the full demo is build the tick hook it used to demonstrate API
\r
177 * functions being called from an interrupt and to perform some tests.
\r
179 void vFullDemoTickHook( void );
\r
182 * When the full demo is build the idle hook is used to create some timers that
\r
183 * cannot be created in main() because the timer demo tasks need the entire
\r
186 void vFullDemoIdleHook( void );
\r
188 /*-----------------------------------------------------------*/
\r
190 /* The following two variables are used to communicate the status of the
\r
191 register check tasks to the check task. If the variables keep incrementing,
\r
192 then the register check tasks have not discovered any errors. If a variable
\r
193 stops incrementing, then an error has been found. */
\r
194 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
196 /*-----------------------------------------------------------*/
\r
198 void main_full( void )
\r
200 /* Start all the other standard demo/test tasks. They have no particular
\r
201 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
203 vStartDynamicPriorityTasks();
\r
204 vCreateBlockTimeTasks();
\r
205 vStartCountingSemaphoreTasks();
\r
206 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
207 vStartRecursiveMutexTasks();
\r
208 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
209 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
210 vStartEventGroupTasks();
\r
211 vStartTaskNotifyTask();
\r
212 vStartInterruptSemaphoreTasks();
\r
213 vCreateAbortDelayTasks();
\r
215 /* Note - the set of standard demo tasks contains two versions of
\r
216 vStartMathTasks.c. One is defined in flop.c, and uses double precision
\r
217 floating point numbers and variables. The other is defined in sp_flop.c,
\r
218 and uses single precision floating point numbers and variables. The
\r
219 MicroBlaze floating point unit only handles single precision floating.
\r
220 Therefore, to test the floating point hardware, sp_flop.c should be included
\r
221 in this project. */
\r
222 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
224 /* Start the tasks that implements the command console on the UART, as
\r
225 described above. */
\r
226 vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );
\r
228 /* Register the standard CLI commands. */
\r
229 vRegisterSampleCLICommands();
\r
231 /* Create the register check tasks, as described at the top of this file */
\r
232 xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
233 xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
235 /* Create the task that performs the 'check' functionality, as described at
\r
236 the top of this file. */
\r
237 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
239 /* Start the scheduler. */
\r
240 vTaskStartScheduler();
\r
242 /* If all is well, the scheduler will now be running, and the following
\r
243 line will never be reached. If the following line does execute, then
\r
244 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
245 timer tasks to be created. See the memory management section on the
\r
246 FreeRTOS web site for more details on the FreeRTOS heap
\r
247 http://www.freertos.org/a00111.html. */
\r
250 /*-----------------------------------------------------------*/
\r
252 static void prvCheckTask( void *pvParameters )
\r
254 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
255 TickType_t xLastExecutionTime;
\r
256 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
257 unsigned long ulErrorFound = pdFALSE;
\r
259 /* Just to stop compiler warnings. */
\r
260 ( void ) pvParameters;
\r
262 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
263 works correctly. */
\r
264 xLastExecutionTime = xTaskGetTickCount();
\r
266 /* Cycle for ever, delaying then checking all the other tasks are still
\r
267 operating without error. The onboard LED is toggled on each iteration.
\r
268 If an error is detected then the delay period is decreased from
\r
269 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
270 effect of increasing the rate at which the onboard LED toggles, and in so
\r
271 doing gives visual feedback of the system status. */
\r
274 /* Delay until it is time to execute again. */
\r
275 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
277 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
278 that they are all still running, and that none have detected an error. */
\r
279 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
281 ulErrorFound |= 1UL << 1UL;
\r
284 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
286 ulErrorFound |= 1UL << 2UL;
\r
289 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
291 ulErrorFound |= 1UL << 4UL;
\r
294 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
296 ulErrorFound |= 1UL << 5UL;
\r
299 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
301 ulErrorFound |= 1UL << 6UL;
\r
304 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
306 ulErrorFound |= 1UL << 8UL;
\r
309 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) mainNO_ERROR_CHECK_TASK_PERIOD ) != pdPASS )
\r
311 ulErrorFound |= 1UL << 9UL;
\r
314 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
316 ulErrorFound |= 1UL << 10UL;
\r
319 if( xAreEventGroupTasksStillRunning() != pdPASS )
\r
321 ulErrorFound |= 1UL << 12UL;
\r
324 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
326 ulErrorFound |= 1UL << 13UL;
\r
329 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
331 ulErrorFound |= 1UL << 14UL;
\r
334 if( xAreAbortDelayTestTasksStillRunning() != pdTRUE )
\r
336 ulErrorFound |= 1UL << 15UL;
\r
339 /* Check that the register test 1 task is still running. */
\r
340 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
342 ulErrorFound |= 1UL << 16UL;
\r
344 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
346 /* Check that the register test 2 task is still running. */
\r
347 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
349 ulErrorFound |= 1UL << 17UL;
\r
351 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
353 /* Toggle the check LED to give an indication of the system status. If
\r
354 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then
\r
355 everything is ok. A faster toggle indicates an error. */
\r
356 vParTestToggleLED( mainCHECK_LED );
\r
358 if( ulErrorFound != pdFALSE )
\r
360 /* An error has been detected in one of the tasks - flash the LED
\r
361 at a higher frequency to give visible feedback that something has
\r
363 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
367 /*-----------------------------------------------------------*/
\r
369 static void prvRegTestTaskEntry1( void *pvParameters )
\r
371 /* Although the regtest task is written in assembler, its entry point is
\r
372 written in C for convenience of checking the task parameter is being passed
\r
374 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
376 /* Start the part of the test that is written in assembler. */
\r
377 vRegTest1Implementation();
\r
380 /* The following line will only execute if the task parameter is found to
\r
381 be incorrect. The check task will detect that the regtest loop counter is
\r
382 not being incremented and flag an error. */
\r
383 vTaskDelete( NULL );
\r
385 /*-----------------------------------------------------------*/
\r
387 static void prvRegTestTaskEntry2( void *pvParameters )
\r
389 /* Although the regtest task is written in assembler, its entry point is
\r
390 written in C for convenience of checking the task parameter is being passed
\r
392 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
394 /* Start the part of the test that is written in assembler. */
\r
395 vRegTest2Implementation();
\r
398 /* The following line will only execute if the task parameter is found to
\r
399 be incorrect. The check task will detect that the regtest loop counter is
\r
400 not being incremented and flag an error. */
\r
401 vTaskDelete( NULL );
\r
403 /*-----------------------------------------------------------*/
\r
405 void vFullDemoTickHook( void )
\r
407 /* The full demo includes a software timer demo/test that requires
\r
408 prodding periodically from the tick interrupt. */
\r
409 vTimerPeriodicISRTests();
\r
411 /* Call the periodic event group from ISR demo. */
\r
412 vPeriodicEventGroupsProcessing();
\r
414 /* Use task notifications from an interrupt. */
\r
415 xNotifyTaskFromISR();
\r
417 /* Use mutexes from interrupts. */
\r
418 vInterruptSemaphorePeriodicTest();
\r
420 /*-----------------------------------------------------------*/
\r
422 void vFullDemoIdleHook( void )
\r
424 static uint32_t ulStartedTimers = pdFALSE;
\r
426 if( ulStartedTimers == pdFALSE )
\r
428 /* The flash timers are not created from main() as the timer demo needs
\r
429 the entire timer command queue in order to perform some tests. */
\r
430 vStartLEDFlashTimers( mainNUM_FLASH_TIMERS );
\r
431 ulStartedTimers = pdTRUE;
\r