2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
71 * documentation provides more details of the demo application tasks.
\r
73 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
76 * The "Check" task. This only executes every three seconds but has the highest
\r
77 * priority so is guaranteed to get processor time. Its main function is to
\r
78 * check that all the other tasks are still operational. Most tasks maintain
\r
79 * a unique count that is incremented each time the task successfully completes
\r
80 * its function. Should any error occur within such a task the count is
\r
81 * permanently halted. The check task inspects the count of each task to ensure
\r
82 * it has changed since the last time the check task executed. If all the count
\r
83 * variables have changed all the tasks are still executing error free, and the
\r
84 * check task toggles the onboard LED. Should any task contain an error at any time
\r
85 * the LED toggle rate will change from 3 seconds to 500ms.
\r
87 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
88 * information via UART1.
\r
92 /* Scheduler includes. */
\r
93 #include "FreeRTOS.h"
\r
97 /* Demo application includes. */
\r
99 #include "integer.h"
\r
100 #include "comtest2.h"
\r
102 #include "semtest.h"
\r
103 #include "BlockQ.h"
\r
104 #include "dynamic.h"
\r
106 #include "GenQTest.h"
\r
108 #include "blocktim.h"
\r
110 #include "taskutility.h"
\r
111 #include "partest.h"
\r
112 #include "crflash.h"
\r
113 #include "watchdog.h"
\r
115 /* Library includes. */
\r
116 #include <watchdog.h>
\r
118 /*-----------------------------------------------------------*/
\r
120 /* Demo task priorities. */
\r
121 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
122 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
123 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
124 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
125 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
126 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
127 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
128 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
129 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
130 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
132 /* Baud rate used by the COM test tasks. */
\r
133 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
135 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
136 top of the page. When the system is operating error free the 'Check' task
\r
137 toggles an LED every three seconds. If an error is discovered in any task the
\r
138 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
139 LCD represent LED's] */
\r
140 #define mainNO_ERROR_CHECK_DELAY ( (portTickType) 3000 / portTICK_RATE_MS )
\r
141 #define mainERROR_CHECK_DELAY ( (portTickType) 500 / portTICK_RATE_MS )
\r
143 /* LED assignments for the demo tasks. */
\r
144 #define mainNUM_FLASH_CO_ROUTINES 8
\r
145 #define mainCOM_TEST_LED 0x05
\r
146 #define mainCHECK_TEST_LED 0x07
\r
148 /*-----------------------------------------------------------*/
\r
151 * The function that implements the Check task. See the comments at the head
\r
152 * of the page for implementation details.
\r
154 static void vErrorChecks( void *pvParameters );
\r
157 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
158 * to be operating without error - otherwise returns pdFAIL.
\r
160 static short prvCheckOtherTasksAreStillRunning( void );
\r
163 * Perform any hardware setup necessary for the demo.
\r
165 static void prvSetupHardware( void );
\r
167 /*-----------------------------------------------------------*/
\r
171 InitIrqLevels(); /* Initialize interrupts */
\r
172 __set_il( 7 ); /* Allow all levels */
\r
174 prvSetupHardware();
\r
176 #if WATCHDOG == WTC_IN_TASK
\r
177 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
180 /* Start the standard demo application tasks. */
\r
181 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
182 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
183 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
184 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
185 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
186 vStartDynamicPriorityTasks();
\r
187 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
188 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
189 vCreateBlockTimeTasks();
\r
191 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
192 #if INCLUDE_TraceListTasks == 1
\r
193 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
195 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
198 /* Start the 'Check' task which is defined in this file. */
\r
199 xTaskCreate( vErrorChecks, (signed char *) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
201 /* The suicide tasks must be started last as they record the number of other
\r
202 tasks that exist within the system. The value is then used to ensure at run
\r
203 time the number of tasks that exists is within expected bounds. */
\r
204 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
206 /* Now start the scheduler. Following this call the created tasks should
\r
208 vTaskStartScheduler( );
\r
210 /* vTaskStartScheduler() will only return if an error occurs while the
\r
211 idle task is being created. */
\r
214 /*-----------------------------------------------------------*/
\r
216 static void prvSetupHardware( void )
\r
218 /* Initialise the port used by the LEDs. */
\r
219 vParTestInitialise();
\r
221 /* See watchdog.h for definitions relating to the watchdog use. */
\r
222 #if WATCHDOG != WTC_NONE
\r
226 /*-----------------------------------------------------------*/
\r
228 static void vErrorChecks( void *pvParameters )
\r
230 portTickType xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
232 /* Just to remove compiler warnings. */
\r
233 ( void ) pvParameters;
\r
235 /* Cycle for ever, delaying then checking all the other tasks are still
\r
236 operating without error. */
\r
239 /* Wait until it is time to check again. The time we wait here depends
\r
240 on whether an error has been detected or not. When an error is
\r
241 detected the time is shortened resulting in a faster LED flash rate. */
\r
242 vTaskDelay( xDelayPeriod );
\r
244 /* See if the other tasks are all ok. */
\r
245 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
247 /* An error occurred in one of the tasks so shorten the delay
\r
248 period - which has the effect of increasing the frequency of the
\r
250 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
254 vParTestToggleLED( mainCHECK_TEST_LED );
\r
257 /*-----------------------------------------------------------*/
\r
259 static short prvCheckOtherTasksAreStillRunning( void )
\r
261 static short sNoErrorFound = pdTRUE;
\r
263 /* The demo tasks maintain a count that increments every cycle of the task
\r
264 provided that the task has never encountered an error. This function
\r
265 checks the counts maintained by the tasks to ensure they are still being
\r
266 incremented. A count remaining at the same value between calls therefore
\r
267 indicates that an error has been detected. Only tasks that do not flash
\r
268 an LED are checked. */
\r
269 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
271 sNoErrorFound = pdFALSE;
\r
274 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
276 sNoErrorFound = pdFALSE;
\r
279 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
281 sNoErrorFound = pdFALSE;
\r
284 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
286 sNoErrorFound = pdFALSE;
\r
289 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
291 sNoErrorFound = pdFALSE;
\r
294 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
296 sNoErrorFound = pdFALSE;
\r
299 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
301 sNoErrorFound = pdFALSE;
\r
304 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
306 sNoErrorFound = pdFALSE;
\r
309 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
311 sNoErrorFound = pdFALSE;
\r
314 #if INCLUDE_TraceListTasks == 0
\r
316 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
318 sNoErrorFound = pdFALSE;
\r
323 return sNoErrorFound;
\r
325 /*-----------------------------------------------------------*/
\r
327 /* Idle hook function. */
\r
328 #if configUSE_IDLE_HOOK == 1
\r
329 void vApplicationIdleHook( void )
\r
331 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
332 for watchdog kicking options. Note this is for demonstration only
\r
333 and is not a suggested method of servicing the watchdog in a real
\r
335 #if WATCHDOG == WTC_IN_IDLE
\r
339 vCoRoutineSchedule();
\r
342 #if WATCHDOG == WTC_IN_IDLE
\r
343 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
347 /*-----------------------------------------------------------*/
\r
349 /* Tick hook function. */
\r
350 #if configUSE_TICK_HOOK == 1
\r
351 void vApplicationTickHook( void )
\r
353 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
354 for watchdog kicking options. Note this is for demonstration
\r
355 only and is not a suggested method of servicing the watchdog in
\r
356 a real application. */
\r
357 #if WATCHDOG == WTC_IN_TICK
\r
362 #if WATCHDOG == WTC_IN_TICK
\r
363 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
366 /*-----------------------------------------------------------*/
\r