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
30 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
31 * documentation provides more details of the demo application tasks.
\r
33 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
36 * The "Check" task. This only executes every three seconds but has the highest
\r
37 * priority so is guaranteed to get processor time. Its main function is to
\r
38 * check that all the other tasks are still operational. Most tasks maintain
\r
39 * a unique count that is incremented each time the task successfully completes
\r
40 * its function. Should any error occur within such a task the count is
\r
41 * permanently halted. The check task inspects the count of each task to ensure
\r
42 * it has changed since the last time the check task executed. If all the count
\r
43 * variables have changed all the tasks are still executing error free, and the
\r
44 * check task toggles the onboard LED. Should any task contain an error at any time
\r
45 * the LED toggle rate will change from 3 seconds to 500ms.
\r
47 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
48 * information via UART1.
\r
52 /* Scheduler includes. */
\r
53 #include "FreeRTOS.h"
\r
57 /* Demo application includes. */
\r
59 #include "integer.h"
\r
60 #include "comtest2.h"
\r
62 #include "semtest.h"
\r
64 #include "dynamic.h"
\r
66 #include "GenQTest.h"
\r
68 #include "blocktim.h"
\r
70 #include "taskutility.h"
\r
71 #include "partest.h"
\r
72 #include "crflash.h"
\r
73 #include "watchdog.h"
\r
75 /* Library includes. */
\r
76 #include <watchdog.h>
\r
78 /*-----------------------------------------------------------*/
\r
80 /* Demo task priorities. */
\r
81 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
82 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
83 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
84 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
85 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
86 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
87 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
88 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
89 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
90 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
92 /* Baud rate used by the COM test tasks. */
\r
93 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
95 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
96 top of the page. When the system is operating error free the 'Check' task
\r
97 toggles an LED every three seconds. If an error is discovered in any task the
\r
98 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
99 LCD represent LED's] */
\r
100 #define mainNO_ERROR_CHECK_DELAY ( (TickType_t) 3000 / portTICK_PERIOD_MS )
\r
101 #define mainERROR_CHECK_DELAY ( (TickType_t) 500 / portTICK_PERIOD_MS )
\r
103 /* LED assignments for the demo tasks. */
\r
104 #define mainNUM_FLASH_CO_ROUTINES 8
\r
105 #define mainCOM_TEST_LED 0x05
\r
106 #define mainCHECK_TEST_LED 0x07
\r
108 /*-----------------------------------------------------------*/
\r
111 * The function that implements the Check task. See the comments at the head
\r
112 * of the page for implementation details.
\r
114 static void vErrorChecks( void *pvParameters );
\r
117 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
118 * to be operating without error - otherwise returns pdFAIL.
\r
120 static short prvCheckOtherTasksAreStillRunning( void );
\r
123 * Perform any hardware setup necessary for the demo.
\r
125 static void prvSetupHardware( void );
\r
127 /*-----------------------------------------------------------*/
\r
131 InitIrqLevels(); /* Initialize interrupts */
\r
132 __set_il( 7 ); /* Allow all levels */
\r
134 prvSetupHardware();
\r
136 #if WATCHDOG == WTC_IN_TASK
\r
137 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
140 /* Start the standard demo application tasks. */
\r
141 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
142 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
143 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
144 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
145 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
146 vStartDynamicPriorityTasks();
\r
147 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
148 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
149 vCreateBlockTimeTasks();
\r
151 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
152 #if INCLUDE_TraceListTasks == 1
\r
153 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
155 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
158 /* Start the 'Check' task which is defined in this file. */
\r
159 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
161 /* The suicide tasks must be started last as they record the number of other
\r
162 tasks that exist within the system. The value is then used to ensure at run
\r
163 time the number of tasks that exists is within expected bounds. */
\r
164 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
166 /* Now start the scheduler. Following this call the created tasks should
\r
168 vTaskStartScheduler( );
\r
170 /* vTaskStartScheduler() will only return if an error occurs while the
\r
171 idle task is being created. */
\r
174 /*-----------------------------------------------------------*/
\r
176 static void prvSetupHardware( void )
\r
178 /* Initialise the port used by the LEDs. */
\r
179 vParTestInitialise();
\r
181 /* See watchdog.h for definitions relating to the watchdog use. */
\r
182 #if WATCHDOG != WTC_NONE
\r
186 /*-----------------------------------------------------------*/
\r
188 static void vErrorChecks( void *pvParameters )
\r
190 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
192 /* Just to remove compiler warnings. */
\r
193 ( void ) pvParameters;
\r
195 /* Cycle for ever, delaying then checking all the other tasks are still
\r
196 operating without error. */
\r
199 /* Wait until it is time to check again. The time we wait here depends
\r
200 on whether an error has been detected or not. When an error is
\r
201 detected the time is shortened resulting in a faster LED flash rate. */
\r
202 vTaskDelay( xDelayPeriod );
\r
204 /* See if the other tasks are all ok. */
\r
205 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
207 /* An error occurred in one of the tasks so shorten the delay
\r
208 period - which has the effect of increasing the frequency of the
\r
210 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
214 vParTestToggleLED( mainCHECK_TEST_LED );
\r
217 /*-----------------------------------------------------------*/
\r
219 static short prvCheckOtherTasksAreStillRunning( void )
\r
221 static short sNoErrorFound = pdTRUE;
\r
223 /* The demo tasks maintain a count that increments every cycle of the task
\r
224 provided that the task has never encountered an error. This function
\r
225 checks the counts maintained by the tasks to ensure they are still being
\r
226 incremented. A count remaining at the same value between calls therefore
\r
227 indicates that an error has been detected. Only tasks that do not flash
\r
228 an LED are checked. */
\r
229 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
231 sNoErrorFound = pdFALSE;
\r
234 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
236 sNoErrorFound = pdFALSE;
\r
239 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
241 sNoErrorFound = pdFALSE;
\r
244 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
246 sNoErrorFound = pdFALSE;
\r
249 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
251 sNoErrorFound = pdFALSE;
\r
254 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
256 sNoErrorFound = pdFALSE;
\r
259 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
261 sNoErrorFound = pdFALSE;
\r
264 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
266 sNoErrorFound = pdFALSE;
\r
269 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
271 sNoErrorFound = pdFALSE;
\r
274 #if INCLUDE_TraceListTasks == 0
\r
276 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
278 sNoErrorFound = pdFALSE;
\r
283 return sNoErrorFound;
\r
285 /*-----------------------------------------------------------*/
\r
287 /* Idle hook function. */
\r
288 #if configUSE_IDLE_HOOK == 1
\r
289 void vApplicationIdleHook( void )
\r
291 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
292 for watchdog kicking options. Note this is for demonstration only
\r
293 and is not a suggested method of servicing the watchdog in a real
\r
295 #if WATCHDOG == WTC_IN_IDLE
\r
299 vCoRoutineSchedule();
\r
302 #if WATCHDOG == WTC_IN_IDLE
\r
303 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
307 /*-----------------------------------------------------------*/
\r
309 /* Tick hook function. */
\r
310 #if configUSE_TICK_HOOK == 1
\r
311 void vApplicationTickHook( void )
\r
313 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
314 for watchdog kicking options. Note this is for demonstration
\r
315 only and is not a suggested method of servicing the watchdog in
\r
316 a real application. */
\r
317 #if WATCHDOG == WTC_IN_TICK
\r
322 #if WATCHDOG == WTC_IN_TICK
\r
323 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
326 /*-----------------------------------------------------------*/
\r