2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
55 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
56 * documentation provides more details of the demo application tasks.
\r
58 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
61 * The "Check" task. This only executes every three seconds but has the highest
\r
62 * priority so is guaranteed to get processor time. Its main function is to
\r
63 * check that all the other tasks are still operational. Most tasks maintain
\r
64 * a unique count that is incremented each time the task successfully completes
\r
65 * its function. Should any error occur within such a task the count is
\r
66 * permanently halted. The check task inspects the count of each task to ensure
\r
67 * it has changed since the last time the check task executed. If all the count
\r
68 * variables have changed all the tasks are still executing error free, and the
\r
69 * check task toggles the onboard LED. Should any task contain an error at any time
\r
70 * the LED toggle rate will change from 3 seconds to 500ms.
\r
72 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
73 * information via UART1.
\r
77 /* Scheduler includes. */
\r
78 #include "FreeRTOS.h"
\r
82 /* Demo application includes. */
\r
84 #include "integer.h"
\r
85 #include "comtest2.h"
\r
87 #include "semtest.h"
\r
89 #include "dynamic.h"
\r
91 #include "GenQTest.h"
\r
93 #include "blocktim.h"
\r
95 #include "taskutility.h"
\r
96 #include "partest.h"
\r
97 #include "crflash.h"
\r
98 #include "watchdog.h"
\r
100 /* Library includes. */
\r
101 #include <watchdog.h>
\r
103 /*-----------------------------------------------------------*/
\r
105 /* Demo task priorities. */
\r
106 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
107 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
108 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
109 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
110 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
111 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
112 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
113 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
114 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
115 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
117 /* Baud rate used by the COM test tasks. */
\r
118 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
120 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
121 top of the page. When the system is operating error free the 'Check' task
\r
122 toggles an LED every three seconds. If an error is discovered in any task the
\r
123 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
124 LCD represent LED's] */
\r
125 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
126 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
128 /* LED assignments for the demo tasks. */
\r
129 #define mainNUM_FLASH_CO_ROUTINES 8
\r
130 #define mainCOM_TEST_LED 0x05
\r
131 #define mainCHECK_TEST_LED 0x07
\r
133 /*-----------------------------------------------------------*/
\r
136 * The function that implements the Check task. See the comments at the head
\r
137 * of the page for implementation details.
\r
139 static void vErrorChecks( void *pvParameters );
\r
142 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
143 * to be operating without error - otherwise returns pdFAIL.
\r
145 static short prvCheckOtherTasksAreStillRunning( void );
\r
148 * Perform any hardware setup necessary for the demo.
\r
150 static void prvSetupHardware( void );
\r
152 /*-----------------------------------------------------------*/
\r
156 InitIrqLevels(); /* Initialize interrupts */
\r
157 __set_il( 7 ); /* Allow all levels */
\r
159 prvSetupHardware();
\r
161 #if WATCHDOG == WTC_IN_TASK
\r
162 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
165 /* Start the standard demo application tasks. */
\r
166 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
167 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
168 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
169 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
170 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
171 vStartDynamicPriorityTasks();
\r
172 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
173 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
174 vCreateBlockTimeTasks();
\r
176 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
177 #if INCLUDE_TraceListTasks == 1
\r
178 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
180 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
183 /* Start the 'Check' task which is defined in this file. */
\r
184 xTaskCreate( vErrorChecks, (signed char *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
186 /* The suicide tasks must be started last as they record the number of other
\r
187 tasks that exist within the system. The value is then used to ensure at run
\r
188 time the number of tasks that exists is within expected bounds. */
\r
189 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
191 /* Now start the scheduler. Following this call the created tasks should
\r
193 vTaskStartScheduler( );
\r
195 /* vTaskStartScheduler() will only return if an error occurs while the
\r
196 idle task is being created. */
\r
199 /*-----------------------------------------------------------*/
\r
201 static void prvSetupHardware( void )
\r
203 /* Initialise the port used by the LEDs. */
\r
204 vParTestInitialise();
\r
206 /* See watchdog.h for definitions relating to the watchdog use. */
\r
207 #if WATCHDOG != WTC_NONE
\r
211 /*-----------------------------------------------------------*/
\r
213 static void vErrorChecks( void *pvParameters )
\r
215 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
217 /* Just to remove compiler warnings. */
\r
218 ( void ) pvParameters;
\r
220 /* Cycle for ever, delaying then checking all the other tasks are still
\r
221 operating without error. */
\r
224 /* Wait until it is time to check again. The time we wait here depends
\r
225 on whether an error has been detected or not. When an error is
\r
226 detected the time is shortened resulting in a faster LED flash rate. */
\r
227 vTaskDelay( xDelayPeriod );
\r
229 /* See if the other tasks are all ok. */
\r
230 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
232 /* An error occurred in one of the tasks so shorten the delay
\r
233 period - which has the effect of increasing the frequency of the
\r
235 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
239 vParTestToggleLED( mainCHECK_TEST_LED );
\r
242 /*-----------------------------------------------------------*/
\r
244 static short prvCheckOtherTasksAreStillRunning( void )
\r
246 static short sNoErrorFound = pdTRUE;
\r
248 /* The demo tasks maintain a count that increments every cycle of the task
\r
249 provided that the task has never encountered an error. This function
\r
250 checks the counts maintained by the tasks to ensure they are still being
\r
251 incremented. A count remaining at the same value between calls therefore
\r
252 indicates that an error has been detected. Only tasks that do not flash
\r
253 an LED are checked. */
\r
254 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
256 sNoErrorFound = pdFALSE;
\r
259 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
261 sNoErrorFound = pdFALSE;
\r
264 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
266 sNoErrorFound = pdFALSE;
\r
269 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
271 sNoErrorFound = pdFALSE;
\r
274 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
276 sNoErrorFound = pdFALSE;
\r
279 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
281 sNoErrorFound = pdFALSE;
\r
284 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
286 sNoErrorFound = pdFALSE;
\r
289 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
291 sNoErrorFound = pdFALSE;
\r
294 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
296 sNoErrorFound = pdFALSE;
\r
299 #if INCLUDE_TraceListTasks == 0
\r
301 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
303 sNoErrorFound = pdFALSE;
\r
308 return sNoErrorFound;
\r
310 /*-----------------------------------------------------------*/
\r
312 /* Idle hook function. */
\r
313 #if configUSE_IDLE_HOOK == 1
\r
314 void vApplicationIdleHook( void )
\r
316 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
317 for watchdog kicking options. Note this is for demonstration only
\r
318 and is not a suggested method of servicing the watchdog in a real
\r
320 #if WATCHDOG == WTC_IN_IDLE
\r
324 vCoRoutineSchedule();
\r
327 #if WATCHDOG == WTC_IN_IDLE
\r
328 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
332 /*-----------------------------------------------------------*/
\r
334 /* Tick hook function. */
\r
335 #if configUSE_TICK_HOOK == 1
\r
336 void vApplicationTickHook( void )
\r
338 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
339 for watchdog kicking options. Note this is for demonstration
\r
340 only and is not a suggested method of servicing the watchdog in
\r
341 a real application. */
\r
342 #if WATCHDOG == WTC_IN_TICK
\r
347 #if WATCHDOG == WTC_IN_TICK
\r
348 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
351 /*-----------------------------------------------------------*/
\r