2 FreeRTOS.org V4.7.1 - 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
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
44 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
45 * documentation provides more details of the demo application tasks.
\r
47 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
50 * The "Check" task. This only executes every three seconds but has the highest
\r
51 * priority so is guaranteed to get processor time. Its main function is to
\r
52 * check that all the other tasks are still operational. Most tasks maintain
\r
53 * a unique count that is incremented each time the task successfully completes
\r
54 * its function. Should any error occur within such a task the count is
\r
55 * permanently halted. The check task inspects the count of each task to ensure
\r
56 * it has changed since the last time the check task executed. If all the count
\r
57 * variables have changed all the tasks are still executing error free, and the
\r
58 * check task toggles the onboard LED. Should any task contain an error at any time
\r
59 * the LED toggle rate will change from 3 seconds to 500ms.
\r
61 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
62 * information via UART1.
\r
66 /* Scheduler includes. */
\r
67 #include "FreeRTOS.h"
\r
71 /* Demo application includes. */
\r
73 #include "integer.h"
\r
74 #include "comtest2.h"
\r
76 #include "semtest.h"
\r
78 #include "dynamic.h"
\r
80 #include "GenQTest.h"
\r
82 #include "BlockTim.h"
\r
84 #include "taskutility.h"
\r
85 #include "partest.h"
\r
86 #include "crflash.h"
\r
87 #include "watchdog.h"
\r
89 /* Library includes. */
\r
90 #include <watchdog.h>
\r
92 /*-----------------------------------------------------------*/
\r
94 /* Demo task priorities. */
\r
95 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
96 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
97 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
98 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
99 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
100 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
101 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
103 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
104 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
106 /* Baud rate used by the COM test tasks. */
\r
107 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
109 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
110 top of the page. When the system is operating error free the 'Check' task
\r
111 toggles an LED every three seconds. If an error is discovered in any task the
\r
112 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
113 LCD represent LED's] */
\r
114 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
115 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
117 /* LED assignments for the demo tasks. */
\r
118 #define mainNUM_FLASH_CO_ROUTINES 8
\r
119 #define mainCOM_TEST_LED 0x05
\r
120 #define mainCHECK_TEST_LED 0x07
\r
122 /*-----------------------------------------------------------*/
\r
125 * The function that implements the Check task. See the comments at the head
\r
126 * of the page for implementation details.
\r
128 static void vErrorChecks( void *pvParameters );
\r
131 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
132 * to be operating without error - otherwise returns pdFAIL.
\r
134 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
137 * Perform any hardware setup necessary for the demo.
\r
139 static void prvSetupHardware( void );
\r
141 /*-----------------------------------------------------------*/
\r
145 InitIrqLevels(); /* Initialize interrupts */
\r
146 __set_il( 7 ); /* Allow all levels */
\r
148 prvSetupHardware();
\r
150 #if WATCHDOG == WTC_IN_TASK
\r
151 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
154 /* Start the standard demo application tasks. */
\r
155 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
156 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
157 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
158 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
159 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
160 vStartDynamicPriorityTasks();
\r
161 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
162 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
163 vCreateBlockTimeTasks();
\r
165 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h.
\r
166 It should be set to 0 if using the EUROScope debugger. */
\r
167 #if INCLUDE_TraceListTasks == 1
\r
168 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
170 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
173 /* Start the 'Check' task which is defined in this file. */
\r
174 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
176 /* The suicide tasks must be started last as they record the number of other
\r
177 tasks that exist within the system. The value is then used to ensure at run
\r
178 time the number of tasks that exists is within expected bounds. */
\r
179 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
181 /* Now start the scheduler. Following this call the created tasks should
\r
183 vTaskStartScheduler( );
\r
185 /* vTaskStartScheduler() will only return if an error occurs while the
\r
186 idle task is being created. */
\r
189 /*-----------------------------------------------------------*/
\r
191 static void prvSetupHardware( void )
\r
193 /* Initialise the port used by the LEDs. */
\r
194 vParTestInitialise();
\r
196 /* See watchdog.h for definitions relating to the watchdog use. */
\r
197 #if WATCHDOG != WTC_NONE
\r
201 /*-----------------------------------------------------------*/
\r
203 static void vErrorChecks( void *pvParameters )
\r
205 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
207 /* Just to remove compiler warnings. */
\r
208 ( void ) pvParameters;
\r
210 /* Cycle for ever, delaying then checking all the other tasks are still
\r
211 operating without error. */
\r
214 /* Wait until it is time to check again. The time we wait here depends
\r
215 on whether an error has been detected or not. When an error is
\r
216 detected the time is shortened resulting in a faster LED flash rate. */
\r
217 vTaskDelay( xDelayPeriod );
\r
219 /* See if the other tasks are all ok. */
\r
220 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
222 /* An error occurred in one of the tasks so shorten the delay
\r
223 period - which has the effect of increasing the frequency of the
\r
225 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
229 vParTestToggleLED( mainCHECK_TEST_LED );
\r
232 /*-----------------------------------------------------------*/
\r
234 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
236 static portSHORT sNoErrorFound = pdTRUE;
\r
238 /* The demo tasks maintain a count that increments every cycle of the task
\r
239 provided that the task has never encountered an error. This function
\r
240 checks the counts maintained by the tasks to ensure they are still being
\r
241 incremented. A count remaining at the same value between calls therefore
\r
242 indicates that an error has been detected. Only tasks that do not flash
\r
243 an LED are checked. */
\r
244 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
246 sNoErrorFound = pdFALSE;
\r
249 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
251 sNoErrorFound = pdFALSE;
\r
254 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
256 sNoErrorFound = pdFALSE;
\r
259 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
261 sNoErrorFound = pdFALSE;
\r
264 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
266 sNoErrorFound = pdFALSE;
\r
269 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
271 sNoErrorFound = pdFALSE;
\r
274 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
276 sNoErrorFound = pdFALSE;
\r
279 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
281 sNoErrorFound = pdFALSE;
\r
284 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
286 sNoErrorFound = pdFALSE;
\r
289 #if INCLUDE_TraceListTasks == 0
\r
291 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
293 sNoErrorFound = pdFALSE;
\r
298 return sNoErrorFound;
\r
300 /*-----------------------------------------------------------*/
\r
302 /* Idle hook function. */
\r
303 #if configUSE_IDLE_HOOK == 1
\r
304 void vApplicationIdleHook( void )
\r
306 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
307 for watchdog kicking options. Note this is for demonstration only
\r
308 and is not a suggested method of servicing the watchdog in a real
\r
310 #if WATCHDOG == WTC_IN_IDLE
\r
314 vCoRoutineSchedule();
\r
317 #if WATCHDOG == WTC_IN_IDLE
\r
318 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
322 /*-----------------------------------------------------------*/
\r
324 /* Tick hook function. */
\r
325 #if configUSE_TICK_HOOK == 1
\r
326 void vApplicationTickHook( void )
\r
328 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
329 for watchdog kicking options. Note this is for demonstration
\r
330 only and is not a suggested method of servicing the watchdog in
\r
331 a real application. */
\r
332 #if WATCHDOG == WTC_IN_TICK
\r
337 #if WATCHDOG == WTC_IN_TICK
\r
338 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
341 /*-----------------------------------------------------------*/
\r