2 * FreeRTOS Kernel V10.3.1
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
28 /******************************************************************************
29 * NOTE 1: This project provides two demo applications. A low power tickless
30 * project, and a more comprehensive test and demo application. The
31 * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to
32 * select between the two. See the notes on using
33 * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h. This file implements
34 * the comprehensive test and demo version.
36 * NOTE 2: This file only contains the source code that is specific to the
37 * full demo. Generic functions, such FreeRTOS hook functions, and functions
38 * required to configure the hardware, are defined in main.c.
39 ******************************************************************************
41 * main_full() creates all the demo application tasks and a software timer, then
42 * starts the scheduler. The web documentation provides more details of the
43 * standard demo application tasks, which provide no particular functionality,
44 * but do provide a good example of how to use the FreeRTOS API.
46 * In addition to the standard demo tasks, the following tasks and tests are
47 * defined and/or created within this file:
49 * "Check" timer - The check software timer period is initially set to three
50 * seconds. The callback function associated with the check software timer
51 * checks that all the standard demo tasks are not only still executing, but
52 * are executing without reporting any errors. If the check software timer
53 * discovers that a task has either stalled, or reported an error, then it
54 * changes its own execution period from the initial three seconds, to just
55 * 200ms. The check software timer callback function also toggles an LED each
56 * time it is called. This provides a visual indication of the system status:
57 * If the LED toggles every three seconds, then no issues have been discovered.
58 * If the LED toggles every 200ms, then an issue has been discovered with at
61 * See the documentation page for this demo on the FreeRTOS.org web site for
62 * full information, including hardware setup requirements.
65 /* Standard includes. */
68 /* Kernel includes. */
74 /* Standard demo application includes. */
85 /* Atmel library includes. */
88 /* Priorities for the demo application tasks. */
89 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
90 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
91 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
93 /* A block time of zero simply means "don't block". */
94 #define mainDONT_BLOCK ( 0UL )
96 /* The period after which the check timer will expire providing no errors
97 have been reported by any of the standard demo tasks. ms are converted to the
98 equivalent in ticks using the portTICK_PERIOD_MS constant. */
99 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
101 /* The period at which the check timer will expire, in ms, if an error has been
102 reported in one of the standard demo tasks. ms are converted to the equivalent
103 in ticks using the portTICK_PERIOD_MS constant. */
104 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
106 /* The LED toggled by the check timer. */
107 #define mainCHECK_LED ( 0 )
109 /*-----------------------------------------------------------*/
112 * The check timer callback function, as described at the top of this file.
114 static void prvCheckTimerCallback( TimerHandle_t xTimer );
116 /*-----------------------------------------------------------*/
118 void main_full( void )
120 TimerHandle_t xCheckTimer = NULL;
122 /* Start all the other standard demo/test tasks. They have no particular
123 functionality, but do demonstrate how to use the FreeRTOS API and test the
125 vStartDynamicPriorityTasks();
126 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
127 vCreateBlockTimeTasks();
128 vStartCountingSemaphoreTasks();
129 vStartGenericQueueTasks( tskIDLE_PRIORITY );
130 vStartRecursiveMutexTasks();
131 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
132 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
134 /* Create the software timer that performs the 'check' functionality,
135 as described at the top of this file. */
136 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
137 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
138 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
139 ( void * ) 0, /* The ID is not used, so can be set to anything. */
140 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
143 if( xCheckTimer != NULL )
145 xTimerStart( xCheckTimer, mainDONT_BLOCK );
148 /* Start the scheduler. */
149 vTaskStartScheduler();
151 /* If all is well, the scheduler will now be running, and the following line
152 will never be reached. If the following line does execute, then there was
153 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
154 to be created. See the memory management section on the FreeRTOS web site
158 /*-----------------------------------------------------------*/
160 static void prvCheckTimerCallback( TimerHandle_t xTimer )
162 static long lChangedTimerPeriodAlready = pdFALSE;
163 unsigned long ulErrorFound = pdFALSE;
165 /* Check all the demo tasks (other than the flash tasks) to ensure
166 they are all still running, and that none have detected an error. */
168 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
170 ulErrorFound = pdTRUE;
173 if( xAreBlockingQueuesStillRunning() != pdTRUE )
175 ulErrorFound = pdTRUE;
178 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
180 ulErrorFound = pdTRUE;
183 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
185 ulErrorFound = pdTRUE;
188 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
190 ulErrorFound = pdTRUE;
193 if( xArePollingQueuesStillRunning() != pdTRUE )
195 ulErrorFound = pdTRUE;
198 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
200 ulErrorFound = pdTRUE;
203 /* Toggle the check LED to give an indication of the system status. If
204 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
205 everything is ok. A faster toggle indicates an error. */
206 vParTestToggleLED( mainCHECK_LED );
208 /* Have any errors been latch in ulErrorFound? If so, shorten the
209 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
210 This will result in an increase in the rate at which mainCHECK_LED
212 if( ulErrorFound != pdFALSE )
214 if( lChangedTimerPeriodAlready == pdFALSE )
216 lChangedTimerPeriodAlready = pdTRUE;
218 /* This call to xTimerChangePeriod() uses a zero block time.
219 Functions called from inside of a timer callback function must
220 *never* attempt to block. */
221 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
225 /*-----------------------------------------------------------*/