2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
52 * documentation provides more details of the demo application tasks.
\r
54 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
57 * The "Check" task. This only executes every three seconds but has the highest
\r
58 * priority so is guaranteed to get processor time. Its main function is to
\r
59 * check that all the other tasks are still operational. Most tasks maintain
\r
60 * a unique count that is incremented each time the task successfully completes
\r
61 * its function. Should any error occur within such a task the count is
\r
62 * permanently halted. The check task inspects the count of each task to ensure
\r
63 * it has changed since the last time the check task executed. If all the count
\r
64 * variables have changed all the tasks are still executing error free, and the
\r
65 * check task toggles the onboard LED. Should any task contain an error at any time
\r
66 * the LED toggle rate will change from 3 seconds to 500ms.
\r
68 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
69 * information via UART1.
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\r
78 /* Demo application includes. */
\r
80 #include "integer.h"
\r
81 #include "comtest2.h"
\r
83 #include "semtest.h"
\r
85 #include "dynamic.h"
\r
87 #include "GenQTest.h"
\r
89 #include "blocktim.h"
\r
91 #include "taskutility.h"
\r
92 #include "partest.h"
\r
93 #include "crflash.h"
\r
94 #include "watchdog.h"
\r
96 /* Library includes. */
\r
97 #include <watchdog.h>
\r
99 /*-----------------------------------------------------------*/
\r
101 /* Demo task priorities. */
\r
102 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
103 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
104 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
105 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
106 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
108 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
110 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
111 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
113 /* Baud rate used by the COM test tasks. */
\r
114 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
116 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
117 top of the page. When the system is operating error free the 'Check' task
\r
118 toggles an LED every three seconds. If an error is discovered in any task the
\r
119 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
120 LCD represent LED's] */
\r
121 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
122 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
124 /* LED assignments for the demo tasks. */
\r
125 #define mainNUM_FLASH_CO_ROUTINES 8
\r
126 #define mainCOM_TEST_LED 0x05
\r
127 #define mainCHECK_TEST_LED 0x07
\r
129 /*-----------------------------------------------------------*/
\r
132 * The function that implements the Check task. See the comments at the head
\r
133 * of the page for implementation details.
\r
135 static void vErrorChecks( void *pvParameters );
\r
138 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
139 * to be operating without error - otherwise returns pdFAIL.
\r
141 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
144 * Perform any hardware setup necessary for the demo.
\r
146 static void prvSetupHardware( void );
\r
148 /*-----------------------------------------------------------*/
\r
152 InitIrqLevels(); /* Initialize interrupts */
\r
153 __set_il( 7 ); /* Allow all levels */
\r
155 prvSetupHardware();
\r
157 #if WATCHDOG == WTC_IN_TASK
\r
158 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
161 /* Start the standard demo application tasks. */
\r
162 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
163 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
164 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
165 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
166 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
167 vStartDynamicPriorityTasks();
\r
168 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
169 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
170 vCreateBlockTimeTasks();
\r
172 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
173 #if INCLUDE_TraceListTasks == 1
\r
174 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
176 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
179 /* Start the 'Check' task which is defined in this file. */
\r
180 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
182 /* The suicide tasks must be started last as they record the number of other
\r
183 tasks that exist within the system. The value is then used to ensure at run
\r
184 time the number of tasks that exists is within expected bounds. */
\r
185 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
187 /* Now start the scheduler. Following this call the created tasks should
\r
189 vTaskStartScheduler( );
\r
191 /* vTaskStartScheduler() will only return if an error occurs while the
\r
192 idle task is being created. */
\r
195 /*-----------------------------------------------------------*/
\r
197 static void prvSetupHardware( void )
\r
199 /* Initialise the port used by the LEDs. */
\r
200 vParTestInitialise();
\r
202 /* See watchdog.h for definitions relating to the watchdog use. */
\r
203 #if WATCHDOG != WTC_NONE
\r
207 /*-----------------------------------------------------------*/
\r
209 static void vErrorChecks( void *pvParameters )
\r
211 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
213 /* Just to remove compiler warnings. */
\r
214 ( void ) pvParameters;
\r
216 /* Cycle for ever, delaying then checking all the other tasks are still
\r
217 operating without error. */
\r
220 /* Wait until it is time to check again. The time we wait here depends
\r
221 on whether an error has been detected or not. When an error is
\r
222 detected the time is shortened resulting in a faster LED flash rate. */
\r
223 vTaskDelay( xDelayPeriod );
\r
225 /* See if the other tasks are all ok. */
\r
226 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
228 /* An error occurred in one of the tasks so shorten the delay
\r
229 period - which has the effect of increasing the frequency of the
\r
231 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
235 vParTestToggleLED( mainCHECK_TEST_LED );
\r
238 /*-----------------------------------------------------------*/
\r
240 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
242 static portSHORT sNoErrorFound = pdTRUE;
\r
244 /* The demo tasks maintain a count that increments every cycle of the task
\r
245 provided that the task has never encountered an error. This function
\r
246 checks the counts maintained by the tasks to ensure they are still being
\r
247 incremented. A count remaining at the same value between calls therefore
\r
248 indicates that an error has been detected. Only tasks that do not flash
\r
249 an LED are checked. */
\r
250 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
252 sNoErrorFound = pdFALSE;
\r
255 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
257 sNoErrorFound = pdFALSE;
\r
260 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
262 sNoErrorFound = pdFALSE;
\r
265 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
267 sNoErrorFound = pdFALSE;
\r
270 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
272 sNoErrorFound = pdFALSE;
\r
275 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
277 sNoErrorFound = pdFALSE;
\r
280 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
282 sNoErrorFound = pdFALSE;
\r
285 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
287 sNoErrorFound = pdFALSE;
\r
290 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
292 sNoErrorFound = pdFALSE;
\r
295 #if INCLUDE_TraceListTasks == 0
\r
297 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
299 sNoErrorFound = pdFALSE;
\r
304 return sNoErrorFound;
\r
306 /*-----------------------------------------------------------*/
\r
308 /* Idle hook function. */
\r
309 #if configUSE_IDLE_HOOK == 1
\r
310 void vApplicationIdleHook( void )
\r
312 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
313 for watchdog kicking options. Note this is for demonstration only
\r
314 and is not a suggested method of servicing the watchdog in a real
\r
316 #if WATCHDOG == WTC_IN_IDLE
\r
320 vCoRoutineSchedule();
\r
323 #if WATCHDOG == WTC_IN_IDLE
\r
324 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
328 /*-----------------------------------------------------------*/
\r
330 /* Tick hook function. */
\r
331 #if configUSE_TICK_HOOK == 1
\r
332 void vApplicationTickHook( void )
\r
334 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
335 for watchdog kicking options. Note this is for demonstration
\r
336 only and is not a suggested method of servicing the watchdog in
\r
337 a real application. */
\r
338 #if WATCHDOG == WTC_IN_TICK
\r
343 #if WATCHDOG == WTC_IN_TICK
\r
344 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
347 /*-----------------------------------------------------------*/
\r