2 FreeRTOS.org V5.1.2 - 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
\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 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
31 * This is a concise, step by step, 'hands on' guide that describes both *
\r
32 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
33 * explains numerous examples that are written using the FreeRTOS API. *
\r
34 * Full source code for all the examples is provided in an accompanying *
\r
37 ***************************************************************************
\r
38 ***************************************************************************
\r
40 Please ensure to read the configuration and relevant port sections of the
\r
41 online documentation.
\r
43 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
46 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
49 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
50 licensing and training services.
\r
54 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
55 * documentation provides more details of the demo application tasks.
\r
57 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
60 * The "Check" task. This only executes every three seconds but has the highest
\r
61 * priority so is guaranteed to get processor time. Its main function is to
\r
62 * check that all the other tasks are still operational. Most tasks maintain
\r
63 * a unique count that is incremented each time the task successfully completes
\r
64 * its function. Should any error occur within such a task the count is
\r
65 * permanently halted. The check task inspects the count of each task to ensure
\r
66 * it has changed since the last time the check task executed. If all the count
\r
67 * variables have changed all the tasks are still executing error free, and the
\r
68 * check task toggles the onboard LED. Should any task contain an error at any time
\r
69 * the LED toggle rate will change from 3 seconds to 500ms.
\r
71 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
72 * information via UART1.
\r
76 /* Scheduler includes. */
\r
77 #include "FreeRTOS.h"
\r
81 /* Demo application includes. */
\r
83 #include "integer.h"
\r
84 #include "comtest2.h"
\r
86 #include "semtest.h"
\r
88 #include "dynamic.h"
\r
90 #include "GenQTest.h"
\r
92 #include "blocktim.h"
\r
94 #include "taskutility.h"
\r
95 #include "partest.h"
\r
96 #include "crflash.h"
\r
97 #include "watchdog.h"
\r
99 /* Library includes. */
\r
100 #include <watchdog.h>
\r
102 /*-----------------------------------------------------------*/
\r
104 /* Demo task priorities. */
\r
105 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
106 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
107 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
108 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
109 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
110 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
113 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
116 /* Baud rate used by the COM test tasks. */
\r
117 #define mainCOM_TEST_BAUD_RATE ( ( unsigned portLONG ) 19200 )
\r
119 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
120 top of the page. When the system is operating error free the 'Check' task
\r
121 toggles an LED every three seconds. If an error is discovered in any task the
\r
122 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
123 LCD represent LED's] */
\r
124 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
125 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
127 /* LED assignments for the demo tasks. */
\r
128 #define mainNUM_FLASH_CO_ROUTINES 8
\r
129 #define mainCOM_TEST_LED 0x05
\r
130 #define mainCHECK_TEST_LED 0x07
\r
132 /*-----------------------------------------------------------*/
\r
135 * The function that implements the Check task. See the comments at the head
\r
136 * of the page for implementation details.
\r
138 static void vErrorChecks( void *pvParameters );
\r
141 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
142 * to be operating without error - otherwise returns pdFAIL.
\r
144 static portSHORT prvCheckOtherTasksAreStillRunning( void );
\r
147 * Perform any hardware setup necessary for the demo.
\r
149 static void prvSetupHardware( void );
\r
151 /*-----------------------------------------------------------*/
\r
155 InitIrqLevels(); /* Initialize interrupts */
\r
156 __set_il( 7 ); /* Allow all levels */
\r
158 prvSetupHardware();
\r
160 #if WATCHDOG == WTC_IN_TASK
\r
161 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
164 /* Start the standard demo application tasks. */
\r
165 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
166 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
167 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
168 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
169 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
170 vStartDynamicPriorityTasks();
\r
171 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
172 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
173 vCreateBlockTimeTasks();
\r
175 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
176 #if INCLUDE_TraceListTasks == 1
\r
177 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
179 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
182 /* Start the 'Check' task which is defined in this file. */
\r
183 xTaskCreate( vErrorChecks, (signed portCHAR *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
185 /* The suicide tasks must be started last as they record the number of other
\r
186 tasks that exist within the system. The value is then used to ensure at run
\r
187 time the number of tasks that exists is within expected bounds. */
\r
188 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
190 /* Now start the scheduler. Following this call the created tasks should
\r
192 vTaskStartScheduler( );
\r
194 /* vTaskStartScheduler() will only return if an error occurs while the
\r
195 idle task is being created. */
\r
198 /*-----------------------------------------------------------*/
\r
200 static void prvSetupHardware( void )
\r
202 /* Initialise the port used by the LEDs. */
\r
203 vParTestInitialise();
\r
205 /* See watchdog.h for definitions relating to the watchdog use. */
\r
206 #if WATCHDOG != WTC_NONE
\r
210 /*-----------------------------------------------------------*/
\r
212 static void vErrorChecks( void *pvParameters )
\r
214 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
216 /* Just to remove compiler warnings. */
\r
217 ( void ) pvParameters;
\r
219 /* Cycle for ever, delaying then checking all the other tasks are still
\r
220 operating without error. */
\r
223 /* Wait until it is time to check again. The time we wait here depends
\r
224 on whether an error has been detected or not. When an error is
\r
225 detected the time is shortened resulting in a faster LED flash rate. */
\r
226 vTaskDelay( xDelayPeriod );
\r
228 /* See if the other tasks are all ok. */
\r
229 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
231 /* An error occurred in one of the tasks so shorten the delay
\r
232 period - which has the effect of increasing the frequency of the
\r
234 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
238 vParTestToggleLED( mainCHECK_TEST_LED );
\r
241 /*-----------------------------------------------------------*/
\r
243 static portSHORT prvCheckOtherTasksAreStillRunning( void )
\r
245 static portSHORT sNoErrorFound = pdTRUE;
\r
247 /* The demo tasks maintain a count that increments every cycle of the task
\r
248 provided that the task has never encountered an error. This function
\r
249 checks the counts maintained by the tasks to ensure they are still being
\r
250 incremented. A count remaining at the same value between calls therefore
\r
251 indicates that an error has been detected. Only tasks that do not flash
\r
252 an LED are checked. */
\r
253 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
255 sNoErrorFound = pdFALSE;
\r
258 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
260 sNoErrorFound = pdFALSE;
\r
263 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
265 sNoErrorFound = pdFALSE;
\r
268 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
270 sNoErrorFound = pdFALSE;
\r
273 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
275 sNoErrorFound = pdFALSE;
\r
278 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
280 sNoErrorFound = pdFALSE;
\r
283 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
285 sNoErrorFound = pdFALSE;
\r
288 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
290 sNoErrorFound = pdFALSE;
\r
293 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
295 sNoErrorFound = pdFALSE;
\r
298 #if INCLUDE_TraceListTasks == 0
\r
300 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
302 sNoErrorFound = pdFALSE;
\r
307 return sNoErrorFound;
\r
309 /*-----------------------------------------------------------*/
\r
311 /* Idle hook function. */
\r
312 #if configUSE_IDLE_HOOK == 1
\r
313 void vApplicationIdleHook( void )
\r
315 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
316 for watchdog kicking options. Note this is for demonstration only
\r
317 and is not a suggested method of servicing the watchdog in a real
\r
319 #if WATCHDOG == WTC_IN_IDLE
\r
323 vCoRoutineSchedule();
\r
326 #if WATCHDOG == WTC_IN_IDLE
\r
327 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
331 /*-----------------------------------------------------------*/
\r
333 /* Tick hook function. */
\r
334 #if configUSE_TICK_HOOK == 1
\r
335 void vApplicationTickHook( void )
\r
337 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
338 for watchdog kicking options. Note this is for demonstration
\r
339 only and is not a suggested method of servicing the watchdog in
\r
340 a real application. */
\r
341 #if WATCHDOG == WTC_IN_TICK
\r
346 #if WATCHDOG == WTC_IN_TICK
\r
347 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
350 /*-----------------------------------------------------------*/
\r