2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
49 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
50 * documentation provides more details of the demo application tasks.
\r
52 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
55 * The "Check" task. This only executes every three seconds but has the highest
\r
56 * priority so is guaranteed to get processor time. Its main function is to
\r
57 * check that all the other tasks are still operational. Most tasks maintain
\r
58 * a unique count that is incremented each time the task successfully completes
\r
59 * its function. Should any error occur within such a task the count is
\r
60 * permanently halted. The check task inspects the count of each task to ensure
\r
61 * it has changed since the last time the check task executed. If all the count
\r
62 * variables have changed all the tasks are still executing error free, and the
\r
63 * check task toggles the onboard LED. Should any task contain an error at any time
\r
64 * the LED toggle rate will change from 3 seconds to 500ms.
\r
66 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
67 * information via UART1.
\r
71 /* Scheduler includes. */
\r
72 #include "FreeRTOS.h"
\r
76 /* Demo application includes. */
\r
78 #include "integer.h"
\r
79 #include "comtest2.h"
\r
81 #include "semtest.h"
\r
83 #include "dynamic.h"
\r
85 #include "GenQTest.h"
\r
87 #include "blocktim.h"
\r
89 #include "taskutility.h"
\r
90 #include "partest.h"
\r
91 #include "crflash.h"
\r
92 #include "watchdog.h"
\r
94 /* Library includes. */
\r
95 #include <watchdog.h>
\r
97 /*-----------------------------------------------------------*/
\r
99 /* Demo task priorities. */
\r
100 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
101 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
102 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
103 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
104 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
105 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
108 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
109 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
111 /* Baud rate used by the COM test tasks. */
\r
112 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
114 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
115 top of the page. When the system is operating error free the 'Check' task
\r
116 toggles an LED every three seconds. If an error is discovered in any task the
\r
117 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
118 LCD represent LED's] */
\r
119 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
120 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
122 /* LED assignments for the demo tasks. */
\r
123 #define mainNUM_FLASH_CO_ROUTINES 8
\r
124 #define mainCOM_TEST_LED 0x05
\r
125 #define mainCHECK_TEST_LED 0x07
\r
127 /*-----------------------------------------------------------*/
\r
130 * The function that implements the Check task. See the comments at the head
\r
131 * of the page for implementation details.
\r
133 static void vErrorChecks( void *pvParameters );
\r
136 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
137 * to be operating without error - otherwise returns pdFAIL.
\r
139 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
142 * Perform any hardware setup necessary for the demo.
\r
144 static void prvSetupHardware( void );
\r
146 /*-----------------------------------------------------------*/
\r
150 InitIrqLevels(); /* Initialize interrupts */
\r
151 __set_il( 7 ); /* Allow all levels */
\r
153 prvSetupHardware();
\r
155 #if WATCHDOG == WTC_IN_TASK
\r
156 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
159 /* Start the standard demo application tasks. */
\r
160 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
161 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
162 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
163 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
164 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
165 vStartDynamicPriorityTasks();
\r
166 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
167 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
168 vCreateBlockTimeTasks();
\r
170 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
171 #if INCLUDE_TraceListTasks == 1
\r
172 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
174 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
177 /* Start the 'Check' task which is defined in this file. */
\r
178 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
180 /* The suicide tasks must be started last as they record the number of other
\r
181 tasks that exist within the system. The value is then used to ensure at run
\r
182 time the number of tasks that exists is within expected bounds. */
\r
183 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
185 /* Now start the scheduler. Following this call the created tasks should
\r
187 vTaskStartScheduler( );
\r
189 /* vTaskStartScheduler() will only return if an error occurs while the
\r
190 idle task is being created. */
\r
193 /*-----------------------------------------------------------*/
\r
195 static void prvSetupHardware( void )
\r
197 /* Initialise the port used by the LEDs. */
\r
198 vParTestInitialise();
\r
200 /* See watchdog.h for definitions relating to the watchdog use. */
\r
201 #if WATCHDOG != WTC_NONE
\r
205 /*-----------------------------------------------------------*/
\r
207 static void vErrorChecks( void *pvParameters )
\r
209 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
211 /* Just to remove compiler warnings. */
\r
212 ( void ) pvParameters;
\r
214 /* Cycle for ever, delaying then checking all the other tasks are still
\r
215 operating without error. */
\r
218 /* Wait until it is time to check again. The time we wait here depends
\r
219 on whether an error has been detected or not. When an error is
\r
220 detected the time is shortened resulting in a faster LED flash rate. */
\r
221 vTaskDelay( xDelayPeriod );
\r
223 /* See if the other tasks are all ok. */
\r
224 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
226 /* An error occurred in one of the tasks so shorten the delay
\r
227 period - which has the effect of increasing the frequency of the
\r
229 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
233 vParTestToggleLED( mainCHECK_TEST_LED );
\r
236 /*-----------------------------------------------------------*/
\r
238 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
240 static portSHORT sNoErrorFound = pdTRUE;
\r
242 /* The demo tasks maintain a count that increments every cycle of the task
\r
243 provided that the task has never encountered an error. This function
\r
244 checks the counts maintained by the tasks to ensure they are still being
\r
245 incremented. A count remaining at the same value between calls therefore
\r
246 indicates that an error has been detected. Only tasks that do not flash
\r
247 an LED are checked. */
\r
248 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
250 sNoErrorFound = pdFALSE;
\r
253 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
255 sNoErrorFound = pdFALSE;
\r
258 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
260 sNoErrorFound = pdFALSE;
\r
263 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
265 sNoErrorFound = pdFALSE;
\r
268 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
270 sNoErrorFound = pdFALSE;
\r
273 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
275 sNoErrorFound = pdFALSE;
\r
278 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
280 sNoErrorFound = pdFALSE;
\r
283 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
285 sNoErrorFound = pdFALSE;
\r
288 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
290 sNoErrorFound = pdFALSE;
\r
293 #if INCLUDE_TraceListTasks == 0
\r
295 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
297 sNoErrorFound = pdFALSE;
\r
302 return sNoErrorFound;
\r
304 /*-----------------------------------------------------------*/
\r
306 /* Idle hook function. */
\r
307 #if configUSE_IDLE_HOOK == 1
\r
308 void vApplicationIdleHook( void )
\r
310 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
311 for watchdog kicking options. Note this is for demonstration only
\r
312 and is not a suggested method of servicing the watchdog in a real
\r
314 #if WATCHDOG == WTC_IN_IDLE
\r
318 vCoRoutineSchedule();
\r
321 #if WATCHDOG == WTC_IN_IDLE
\r
322 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
326 /*-----------------------------------------------------------*/
\r
328 /* Tick hook function. */
\r
329 #if configUSE_TICK_HOOK == 1
\r
330 void vApplicationTickHook( void )
\r
332 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
333 for watchdog kicking options. Note this is for demonstration
\r
334 only and is not a suggested method of servicing the watchdog in
\r
335 a real application. */
\r
336 #if WATCHDOG == WTC_IN_TICK
\r
341 #if WATCHDOG == WTC_IN_TICK
\r
342 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
345 /*-----------------------------------------------------------*/
\r