2 FreeRTOS.org V5.3.0 - Copyright (C) 2003-2009 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 it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the 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.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
53 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
54 * documentation provides more details of the demo application tasks.
\r
56 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
59 * The "Check" task. This only executes every three seconds but has the highest
\r
60 * priority so is guaranteed to get processor time. Its main function is to
\r
61 * check that all the other tasks are still operational. Most tasks maintain
\r
62 * a unique count that is incremented each time the task successfully completes
\r
63 * its function. Should any error occur within such a task the count is
\r
64 * permanently halted. The check task inspects the count of each task to ensure
\r
65 * it has changed since the last time the check task executed. If all the count
\r
66 * variables have changed all the tasks are still executing error free, and the
\r
67 * check task toggles the onboard LED. Should any task contain an error at any time
\r
68 * the LED toggle rate will change from 3 seconds to 500ms.
\r
70 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
71 * information via UART1.
\r
75 /* Scheduler includes. */
\r
76 #include "FreeRTOS.h"
\r
80 /* Demo application includes. */
\r
82 #include "integer.h"
\r
83 #include "comtest2.h"
\r
85 #include "semtest.h"
\r
87 #include "dynamic.h"
\r
89 #include "GenQTest.h"
\r
91 #include "blocktim.h"
\r
93 #include "taskutility.h"
\r
94 #include "partest.h"
\r
95 #include "crflash.h"
\r
96 #include "watchdog.h"
\r
98 /* Library includes. */
\r
99 #include <watchdog.h>
\r
101 /*-----------------------------------------------------------*/
\r
103 /* Demo task priorities. */
\r
104 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
105 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
106 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
107 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
108 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
109 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
112 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
115 /* Baud rate used by the COM test tasks. */
\r
116 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
118 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
119 top of the page. When the system is operating error free the 'Check' task
\r
120 toggles an LED every three seconds. If an error is discovered in any task the
\r
121 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
122 LCD represent LED's] */
\r
123 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
124 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
126 /* LED assignments for the demo tasks. */
\r
127 #define mainNUM_FLASH_CO_ROUTINES 8
\r
128 #define mainCOM_TEST_LED 0x05
\r
129 #define mainCHECK_TEST_LED 0x07
\r
131 /*-----------------------------------------------------------*/
\r
134 * The function that implements the Check task. See the comments at the head
\r
135 * of the page for implementation details.
\r
137 static void vErrorChecks( void *pvParameters );
\r
140 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
141 * to be operating without error - otherwise returns pdFAIL.
\r
143 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
146 * Perform any hardware setup necessary for the demo.
\r
148 static void prvSetupHardware( void );
\r
150 /*-----------------------------------------------------------*/
\r
154 InitIrqLevels(); /* Initialize interrupts */
\r
155 __set_il( 7 ); /* Allow all levels */
\r
157 prvSetupHardware();
\r
159 #if WATCHDOG == WTC_IN_TASK
\r
160 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
163 /* Start the standard demo application tasks. */
\r
164 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
165 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
166 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
167 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
168 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
169 vStartDynamicPriorityTasks();
\r
170 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
171 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
172 vCreateBlockTimeTasks();
\r
174 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
175 #if INCLUDE_TraceListTasks == 1
\r
176 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
178 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
181 /* Start the 'Check' task which is defined in this file. */
\r
182 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
184 /* The suicide tasks must be started last as they record the number of other
\r
185 tasks that exist within the system. The value is then used to ensure at run
\r
186 time the number of tasks that exists is within expected bounds. */
\r
187 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
189 /* Now start the scheduler. Following this call the created tasks should
\r
191 vTaskStartScheduler( );
\r
193 /* vTaskStartScheduler() will only return if an error occurs while the
\r
194 idle task is being created. */
\r
197 /*-----------------------------------------------------------*/
\r
199 static void prvSetupHardware( void )
\r
201 /* Initialise the port used by the LEDs. */
\r
202 vParTestInitialise();
\r
204 /* See watchdog.h for definitions relating to the watchdog use. */
\r
205 #if WATCHDOG != WTC_NONE
\r
209 /*-----------------------------------------------------------*/
\r
211 static void vErrorChecks( void *pvParameters )
\r
213 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
215 /* Just to remove compiler warnings. */
\r
216 ( void ) pvParameters;
\r
218 /* Cycle for ever, delaying then checking all the other tasks are still
\r
219 operating without error. */
\r
222 /* Wait until it is time to check again. The time we wait here depends
\r
223 on whether an error has been detected or not. When an error is
\r
224 detected the time is shortened resulting in a faster LED flash rate. */
\r
225 vTaskDelay( xDelayPeriod );
\r
227 /* See if the other tasks are all ok. */
\r
228 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
230 /* An error occurred in one of the tasks so shorten the delay
\r
231 period - which has the effect of increasing the frequency of the
\r
233 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
237 vParTestToggleLED( mainCHECK_TEST_LED );
\r
240 /*-----------------------------------------------------------*/
\r
242 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
244 static portSHORT sNoErrorFound = pdTRUE;
\r
246 /* The demo tasks maintain a count that increments every cycle of the task
\r
247 provided that the task has never encountered an error. This function
\r
248 checks the counts maintained by the tasks to ensure they are still being
\r
249 incremented. A count remaining at the same value between calls therefore
\r
250 indicates that an error has been detected. Only tasks that do not flash
\r
251 an LED are checked. */
\r
252 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
254 sNoErrorFound = pdFALSE;
\r
257 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
259 sNoErrorFound = pdFALSE;
\r
262 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
264 sNoErrorFound = pdFALSE;
\r
267 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
269 sNoErrorFound = pdFALSE;
\r
272 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
274 sNoErrorFound = pdFALSE;
\r
277 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
279 sNoErrorFound = pdFALSE;
\r
282 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
284 sNoErrorFound = pdFALSE;
\r
287 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
289 sNoErrorFound = pdFALSE;
\r
292 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
294 sNoErrorFound = pdFALSE;
\r
297 #if INCLUDE_TraceListTasks == 0
\r
299 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
301 sNoErrorFound = pdFALSE;
\r
306 return sNoErrorFound;
\r
308 /*-----------------------------------------------------------*/
\r
310 /* Idle hook function. */
\r
311 #if configUSE_IDLE_HOOK == 1
\r
312 void vApplicationIdleHook( void )
\r
314 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
315 for watchdog kicking options. Note this is for demonstration only
\r
316 and is not a suggested method of servicing the watchdog in a real
\r
318 #if WATCHDOG == WTC_IN_IDLE
\r
322 vCoRoutineSchedule();
\r
325 #if WATCHDOG == WTC_IN_IDLE
\r
326 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
330 /*-----------------------------------------------------------*/
\r
332 /* Tick hook function. */
\r
333 #if configUSE_TICK_HOOK == 1
\r
334 void vApplicationTickHook( void )
\r
336 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
337 for watchdog kicking options. Note this is for demonstration
\r
338 only and is not a suggested method of servicing the watchdog in
\r
339 a real application. */
\r
340 #if WATCHDOG == WTC_IN_TICK
\r
345 #if WATCHDOG == WTC_IN_TICK
\r
346 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
349 /*-----------------------------------------------------------*/
\r