2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the demo application tasks.
\r
70 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
73 * The "Check" task. This only executes every three seconds but has the highest
\r
74 * priority so is guaranteed to get processor time. Its main function is to
\r
75 * check that all the other tasks are still operational. Most tasks maintain
\r
76 * a unique count that is incremented each time the task successfully completes
\r
77 * its function. Should any error occur within such a task the count is
\r
78 * permanently halted. The check task inspects the count of each task to ensure
\r
79 * it has changed since the last time the check task executed. If all the count
\r
80 * variables have changed all the tasks are still executing error free, and the
\r
81 * check task toggles the onboard LED. Should any task contain an error at any time
\r
82 * the LED toggle rate will change from 3 seconds to 500ms.
\r
84 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
85 * information via UART1.
\r
89 /* Scheduler includes. */
\r
90 #include "FreeRTOS.h"
\r
94 /* Demo application includes. */
\r
96 #include "integer.h"
\r
97 #include "comtest2.h"
\r
99 #include "semtest.h"
\r
100 #include "BlockQ.h"
\r
101 #include "dynamic.h"
\r
103 #include "GenQTest.h"
\r
105 #include "blocktim.h"
\r
107 #include "taskutility.h"
\r
108 #include "partest.h"
\r
109 #include "crflash.h"
\r
110 #include "watchdog.h"
\r
112 /* Library includes. */
\r
113 #include <watchdog.h>
\r
115 /*-----------------------------------------------------------*/
\r
117 /* Demo task priorities. */
\r
118 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
119 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
120 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
121 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
122 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
123 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
124 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
125 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
126 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
127 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
129 /* Baud rate used by the COM test tasks. */
\r
130 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
132 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
133 top of the page. When the system is operating error free the 'Check' task
\r
134 toggles an LED every three seconds. If an error is discovered in any task the
\r
135 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
136 LCD represent LED's] */
\r
137 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
138 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
140 /* LED assignments for the demo tasks. */
\r
141 #define mainNUM_FLASH_CO_ROUTINES 8
\r
142 #define mainCOM_TEST_LED 0x05
\r
143 #define mainCHECK_TEST_LED 0x07
\r
145 /*-----------------------------------------------------------*/
\r
148 * The function that implements the Check task. See the comments at the head
\r
149 * of the page for implementation details.
\r
151 static void vErrorChecks( void *pvParameters );
\r
154 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
155 * to be operating without error - otherwise returns pdFAIL.
\r
157 static short prvCheckOtherTasksAreStillRunning( void );
\r
160 * Perform any hardware setup necessary for the demo.
\r
162 static void prvSetupHardware( void );
\r
164 /*-----------------------------------------------------------*/
\r
168 InitIrqLevels(); /* Initialize interrupts */
\r
169 __set_il( 7 ); /* Allow all levels */
\r
171 prvSetupHardware();
\r
173 #if WATCHDOG == WTC_IN_TASK
\r
174 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
177 /* Start the standard demo application tasks. */
\r
178 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
179 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
180 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
181 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
182 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
183 vStartDynamicPriorityTasks();
\r
184 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
185 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
186 vCreateBlockTimeTasks();
\r
188 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
189 #if INCLUDE_TraceListTasks == 1
\r
190 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
192 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
195 /* Start the 'Check' task which is defined in this file. */
\r
196 xTaskCreate( vErrorChecks, (signed char *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
198 /* The suicide tasks must be started last as they record the number of other
\r
199 tasks that exist within the system. The value is then used to ensure at run
\r
200 time the number of tasks that exists is within expected bounds. */
\r
201 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
203 /* Now start the scheduler. Following this call the created tasks should
\r
205 vTaskStartScheduler( );
\r
207 /* vTaskStartScheduler() will only return if an error occurs while the
\r
208 idle task is being created. */
\r
211 /*-----------------------------------------------------------*/
\r
213 static void prvSetupHardware( void )
\r
215 /* Initialise the port used by the LEDs. */
\r
216 vParTestInitialise();
\r
218 /* See watchdog.h for definitions relating to the watchdog use. */
\r
219 #if WATCHDOG != WTC_NONE
\r
223 /*-----------------------------------------------------------*/
\r
225 static void vErrorChecks( void *pvParameters )
\r
227 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
229 /* Just to remove compiler warnings. */
\r
230 ( void ) pvParameters;
\r
232 /* Cycle for ever, delaying then checking all the other tasks are still
\r
233 operating without error. */
\r
236 /* Wait until it is time to check again. The time we wait here depends
\r
237 on whether an error has been detected or not. When an error is
\r
238 detected the time is shortened resulting in a faster LED flash rate. */
\r
239 vTaskDelay( xDelayPeriod );
\r
241 /* See if the other tasks are all ok. */
\r
242 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
244 /* An error occurred in one of the tasks so shorten the delay
\r
245 period - which has the effect of increasing the frequency of the
\r
247 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
251 vParTestToggleLED( mainCHECK_TEST_LED );
\r
254 /*-----------------------------------------------------------*/
\r
256 static short prvCheckOtherTasksAreStillRunning( void )
\r
258 static short sNoErrorFound = pdTRUE;
\r
260 /* The demo tasks maintain a count that increments every cycle of the task
\r
261 provided that the task has never encountered an error. This function
\r
262 checks the counts maintained by the tasks to ensure they are still being
\r
263 incremented. A count remaining at the same value between calls therefore
\r
264 indicates that an error has been detected. Only tasks that do not flash
\r
265 an LED are checked. */
\r
266 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
268 sNoErrorFound = pdFALSE;
\r
271 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
273 sNoErrorFound = pdFALSE;
\r
276 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
278 sNoErrorFound = pdFALSE;
\r
281 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
283 sNoErrorFound = pdFALSE;
\r
286 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
288 sNoErrorFound = pdFALSE;
\r
291 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
293 sNoErrorFound = pdFALSE;
\r
296 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
298 sNoErrorFound = pdFALSE;
\r
301 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
303 sNoErrorFound = pdFALSE;
\r
306 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
308 sNoErrorFound = pdFALSE;
\r
311 #if INCLUDE_TraceListTasks == 0
\r
313 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
315 sNoErrorFound = pdFALSE;
\r
320 return sNoErrorFound;
\r
322 /*-----------------------------------------------------------*/
\r
324 /* Idle hook function. */
\r
325 #if configUSE_IDLE_HOOK == 1
\r
326 void vApplicationIdleHook( void )
\r
328 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
329 for watchdog kicking options. Note this is for demonstration only
\r
330 and is not a suggested method of servicing the watchdog in a real
\r
332 #if WATCHDOG == WTC_IN_IDLE
\r
336 vCoRoutineSchedule();
\r
339 #if WATCHDOG == WTC_IN_IDLE
\r
340 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
344 /*-----------------------------------------------------------*/
\r
346 /* Tick hook function. */
\r
347 #if configUSE_TICK_HOOK == 1
\r
348 void vApplicationTickHook( void )
\r
350 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
351 for watchdog kicking options. Note this is for demonstration
\r
352 only and is not a suggested method of servicing the watchdog in
\r
353 a real application. */
\r
354 #if WATCHDOG == WTC_IN_TICK
\r
359 #if WATCHDOG == WTC_IN_TICK
\r
360 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
363 /*-----------------------------------------------------------*/
\r