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 that demonstrates the tickless low power features of FreeRTOS, and a
\r
32 * more comprehensive test and demo application. The configCREATE_LOW_POWER_DEMO
\r
33 * setting in FreeRTOSConifg.h is used to select between the two, and to select
\r
34 * the clock used when tickless mode is used. See the notes on using
\r
35 * conifgCREATE_LOW_POWER_DEMO in main.c. This file implements the
\r
36 * comprehensive test and demo version.
\r
38 * NOTE 2: This file only contains the source code that is specific to the
\r
39 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
40 * required to configure the hardware, are defined in main.c.
\r
42 ******************************************************************************
\r
44 * main_full() creates all the demo application tasks and software timers, then
\r
45 * starts the scheduler. The web documentation provides more details of the
\r
46 * standard demo application tasks, which provide no particular functionality,
\r
47 * but do provide a good example of how to use the FreeRTOS API.
\r
49 * In addition to the standard demo tasks, the following tasks and tests are
\r
50 * defined and/or created within this file:
\r
52 * "Reg test" tasks - These fill both the core and floating point registers with
\r
53 * known values, then check that each register maintains its expected value for
\r
54 * the lifetime of the task. Each task uses a different set of values. The reg
\r
55 * test tasks execute with a very low priority, so get preempted very
\r
56 * frequently. A register containing an unexpected value is indicative of an
\r
57 * error in the context switching mechanism.
\r
59 * "Check" task - The check task period is initially set to three seconds. The
\r
60 * task checks that all the standard demo tasks, and the register check tasks,
\r
61 * are not only still executing, but are executing without reporting any errors.
\r
62 * If the check task discovers that a task has either stalled, or reported an
\r
63 * error, then it changes its own execution period from the initial three
\r
64 * seconds, to just 200ms. The check task also toggles an LED each time it is
\r
65 * called. This provides a visual indication of the system status: If the LED
\r
66 * toggles every three seconds, then no issues have been discovered. If the LED
\r
67 * toggles every 200ms, then an issue has been discovered with at least one
\r
71 /* Standard includes. */
\r
74 /* Kernel includes. */
\r
75 #include "FreeRTOS.h"
\r
80 /* SiLabs includes. */
\r
83 /* Standard demo application includes. */
\r
85 #include "semtest.h"
\r
86 #include "dynamic.h"
\r
87 #include "blocktim.h"
\r
88 #include "GenQTest.h"
\r
89 #include "recmutex.h"
\r
90 #include "TimerDemo.h"
\r
91 #include "EventGroupsDemo.h"
\r
92 #include "TaskNotify.h"
\r
93 #include "StaticAllocation.h"
\r
95 /* Priorities for the demo application tasks. */
\r
96 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
97 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
98 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
99 #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
\r
101 /* A block time of zero simply means "don't block". */
\r
102 #define mainDONT_BLOCK ( 0UL )
\r
104 /* The period of the check task, in ms, provided no errors have been reported by
\r
105 any of the standard demo tasks. ms are converted to the equivalent in ticks
\r
106 using the portTICK_PERIOD_MS constant. */
\r
107 #define mainNO_ERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 3000UL )
\r
109 /* The period of the check task, in ms, if an error has been reported in one of
\r
110 the standard demo tasks. ms are converted to the equivalent in ticks using the
\r
111 portTICK_PERIOD_MS constant. */
\r
112 #define mainERROR_CHECK_TASK_PERIOD pdMS_TO_TICKS( 200UL )
\r
114 /* Parameters that are passed into the register check tasks solely for the
\r
115 purpose of ensuring parameters are passed into tasks correctly. */
\r
116 #define mainREG_TEST_TASK_1_PARAMETER ( ( void * ) 0x12345678 )
\r
117 #define mainREG_TEST_TASK_2_PARAMETER ( ( void * ) 0x87654321 )
\r
119 /* The base period used by the timer test tasks. */
\r
120 #define mainTIMER_TEST_PERIOD ( 50 )
\r
122 /* The LED toggled by the check task. */
\r
123 #define mainTASK_LED ( 0 )
\r
125 /*-----------------------------------------------------------*/
\r
128 * Called by main() to run the full demo (as opposed to the blinky demo) when
\r
129 * mainCREATE_LOW_POWER_DEMO is set to 0.
\r
131 void main_full( void );
\r
134 * The check task, as described at the top of this file.
\r
136 static void prvCheckTask( void *pvParameters );
\r
139 * Some of the tests and demo tasks executed by the full demo include
\r
140 * interaction from an interrupt - for which the tick interrupt is used via the
\r
141 * tick hook function.
\r
143 void vFullDemoTickHook( void );
\r
146 * Register check tasks, and the tasks used to write over and check the contents
\r
147 * of the FPU registers, as described at the top of this file. The nature of
\r
148 * these files necessitates that they are written in an assembly file, but the
\r
149 * entry points are kept in the C file for the convenience of checking the task
\r
152 static void prvRegTestTaskEntry1( void *pvParameters );
\r
153 extern void vRegTest1Implementation( void );
\r
154 static void prvRegTestTaskEntry2( void *pvParameters );
\r
155 extern void vRegTest2Implementation( void );
\r
157 /*-----------------------------------------------------------*/
\r
159 /* The following two variables are used to communicate the status of the
\r
160 register check tasks to the check task. If the variables keep incrementing,
\r
161 then the register check tasks have not discovered any errors. If a variable
\r
162 stops incrementing, then an error has been found. */
\r
163 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
165 /* The variable incremented in lieu of having a proper LED outout. */
\r
166 extern volatile uint32_t ulLED;
\r
168 /*-----------------------------------------------------------*/
\r
170 void main_full( void )
\r
172 /* Start all the other standard demo/test tasks. They have no particular
\r
173 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
175 vStartDynamicPriorityTasks();
\r
176 vCreateBlockTimeTasks();
\r
177 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
178 vStartRecursiveMutexTasks();
\r
179 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
180 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
181 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
182 vStartEventGroupTasks();
\r
183 vStartTaskNotifyTask();
\r
184 vStartStaticallyAllocatedTasks();
\r
186 /* Create the register check tasks, as described at the top of this file */
\r
187 xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
188 xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
190 /* Create the task that performs the 'check' functionality, as described at
\r
191 the top of this file. */
\r
192 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
194 /* Start the scheduler. */
\r
195 vTaskStartScheduler();
\r
197 /* If all is well, the scheduler will now be running, and the following
\r
198 line will never be reached. If the following line does execute, then
\r
199 there was insufficient FreeRTOS heap memory available for the Idle and/or
\r
200 timer tasks to be created. See the memory management section on the
\r
201 FreeRTOS web site for more details on the FreeRTOS heap
\r
202 http://www.freertos.org/a00111.html. */
\r
205 /*-----------------------------------------------------------*/
\r
207 static void prvCheckTask( void *pvParameters )
\r
209 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;
\r
210 TickType_t xLastExecutionTime;
\r
211 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
212 unsigned long ulErrorFound = pdFALSE;
\r
214 /* Just to stop compiler warnings. */
\r
215 ( void ) pvParameters;
\r
217 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
218 works correctly. */
\r
219 xLastExecutionTime = xTaskGetTickCount();
\r
221 /* Cycle for ever, delaying then checking all the other tasks are still
\r
222 operating without error. The onboard LED is toggled on each iteration.
\r
223 If an error is detected then the delay period is decreased from
\r
224 mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD. This has the
\r
225 effect of increasing the rate at which the onboard LED toggles, and in so
\r
226 doing gives visual feedback of the system status. */
\r
229 /* Delay until it is time to execute again. */
\r
230 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );
\r
232 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
233 that they are all still running, and that none have detected an error. */
\r
234 if( xAreMathsTaskStillRunning() != pdTRUE )
\r
236 ulErrorFound = 1UL << 1UL;
\r
239 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
241 ulErrorFound = 1UL << 2UL;
\r
244 if( xAreStaticAllocationTasksStillRunning() != pdPASS )
\r
246 ulErrorFound = 1UL << 3UL;
\r
249 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
251 ulErrorFound = 1UL << 4UL;
\r
254 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
256 ulErrorFound = 1UL << 5UL;
\r
259 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
261 ulErrorFound = 1UL << 6UL;
\r
264 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
266 ulErrorFound = 1UL << 8UL;
\r
269 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) xDelayPeriod ) != pdPASS )
\r
271 ulErrorFound = 1UL << 9UL;
\r
274 if( xAreEventGroupTasksStillRunning() != pdPASS )
\r
276 ulErrorFound = 1UL << 12UL;
\r
279 if( xAreTaskNotificationTasksStillRunning() != pdPASS )
\r
281 ulErrorFound = 1UL << 14UL;
\r
284 /* Check that the register test 1 task is still running. */
\r
285 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
287 ulErrorFound = 1UL << 15UL;
\r
289 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
291 /* Check that the register test 2 task is still running. */
\r
292 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
294 ulErrorFound = 1UL << 16UL;
\r
296 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
298 /* Toggle the check LED to give an indication of the system status. If
\r
299 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then
\r
300 everything is ok. A faster toggle indicates an error. */
\r
301 BSP_LedToggle( mainTASK_LED );
\r
303 if( ulErrorFound != pdFALSE )
\r
305 /* An error has been detected in one of the tasks - flash the LED
\r
306 at a higher frequency to give visible feedback that something has
\r
308 xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;
\r
311 configASSERT( ulErrorFound == pdFALSE );
\r
314 /*-----------------------------------------------------------*/
\r
316 static void prvRegTestTaskEntry1( void *pvParameters )
\r
318 /* Although the regtest task is written in assembler, its entry point is
\r
319 written in C for convenience of checking the task parameter is being passed
\r
321 if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )
\r
323 /* Start the part of the test that is written in assembler. */
\r
324 vRegTest1Implementation();
\r
327 /* The following line will only execute if the task parameter is found to
\r
328 be incorrect. The check task will detect that the regtest loop counter is
\r
329 not being incremented and flag an error. */
\r
330 vTaskDelete( NULL );
\r
332 /*-----------------------------------------------------------*/
\r
334 static void prvRegTestTaskEntry2( void *pvParameters )
\r
336 /* Although the regtest task is written in assembler, its entry point is
\r
337 written in C for convenience of checking the task parameter is being passed
\r
339 if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )
\r
341 /* Start the part of the test that is written in assembler. */
\r
342 vRegTest2Implementation();
\r
345 /* The following line will only execute if the task parameter is found to
\r
346 be incorrect. The check task will detect that the regtest loop counter is
\r
347 not being incremented and flag an error. */
\r
348 vTaskDelete( NULL );
\r
350 /*-----------------------------------------------------------*/
\r
352 void vFullDemoTickHook( void )
\r
354 /* Some of the tests and demo tasks executed by the full demo include
\r
355 interaction from an interrupt - for which the tick interrupt is used via
\r
356 the tick hook function. */
\r
358 /* The full demo includes a software timer demo/test that requires
\r
359 prodding periodically from the tick interrupt. */
\r
360 vTimerPeriodicISRTests();
\r
362 /* Call the periodic event group from ISR demo. */
\r
363 vPeriodicEventGroupsProcessing();
\r
365 /* Call the code that 'gives' a task notification from an ISR. */
\r
366 xNotifyTaskFromISR();
\r