2 FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the demo application tasks.
\r
74 * In addition to the standard demo tasks, the follow demo specific tasks are
\r
77 * The "Check" task. This only executes every three seconds but has the highest
\r
78 * priority so is guaranteed to get processor time. Its main function is to
\r
79 * check that all the other tasks are still operational. Most tasks maintain
\r
80 * a unique count that is incremented each time the task successfully completes
\r
81 * its function. Should any error occur within such a task the count is
\r
82 * permanently halted. The check task inspects the count of each task to ensure
\r
83 * it has changed since the last time the check task executed. If all the count
\r
84 * variables have changed all the tasks are still executing error free, and the
\r
85 * check task toggles the onboard LED. Should any task contain an error at any time
\r
86 * the LED toggle rate will change from 3 seconds to 500ms.
\r
88 * The "Trace Utility" task. This can be used to obtain trace and debug
\r
89 * information via UART1.
\r
93 /* Scheduler includes. */
\r
94 #include "FreeRTOS.h"
\r
98 /* Demo application includes. */
\r
100 #include "integer.h"
\r
101 #include "comtest2.h"
\r
103 #include "semtest.h"
\r
104 #include "BlockQ.h"
\r
105 #include "dynamic.h"
\r
107 #include "GenQTest.h"
\r
109 #include "blocktim.h"
\r
111 #include "taskutility.h"
\r
112 #include "partest.h"
\r
113 #include "crflash.h"
\r
114 #include "watchdog.h"
\r
116 /* Library includes. */
\r
117 #include <watchdog.h>
\r
119 /*-----------------------------------------------------------*/
\r
121 /* Demo task priorities. */
\r
122 #define WTC_TASK_PRIORITY ( tskIDLE_PRIORITY + 5 )
\r
123 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
124 #define TASK_UTILITY_PRIORITY ( tskIDLE_PRIORITY )
\r
125 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
126 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
127 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
128 #define mainQUEUE_BLOCK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
129 #define mainDEATH_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
130 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
131 #define mainGENERIC_QUEUE_PRIORITY ( tskIDLE_PRIORITY )
\r
133 /* Baud rate used by the COM test tasks. */
\r
134 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
\r
136 /* The frequency at which the 'Check' tasks executes. See the comments at the
\r
137 top of the page. When the system is operating error free the 'Check' task
\r
138 toggles an LED every three seconds. If an error is discovered in any task the
\r
139 rate is increased to 500 milliseconds. [in this case the '*' characters on the
\r
140 LCD represent LED's] */
\r
141 #define mainNO_ERROR_CHECK_DELAY ( (TickType_t) 3000 / portTICK_PERIOD_MS )
\r
142 #define mainERROR_CHECK_DELAY ( (TickType_t) 500 / portTICK_PERIOD_MS )
\r
144 /* LED assignments for the demo tasks. */
\r
145 #define mainNUM_FLASH_CO_ROUTINES 8
\r
146 #define mainCOM_TEST_LED 0x05
\r
147 #define mainCHECK_TEST_LED 0x07
\r
149 /*-----------------------------------------------------------*/
\r
152 * The function that implements the Check task. See the comments at the head
\r
153 * of the page for implementation details.
\r
155 static void vErrorChecks( void *pvParameters );
\r
158 * Called by the Check task. Returns pdPASS if all the other tasks are found
\r
159 * to be operating without error - otherwise returns pdFAIL.
\r
161 static short prvCheckOtherTasksAreStillRunning( void );
\r
164 * Perform any hardware setup necessary for the demo.
\r
166 static void prvSetupHardware( void );
\r
168 /*-----------------------------------------------------------*/
\r
172 InitIrqLevels(); /* Initialize interrupts */
\r
173 __set_il( 7 ); /* Allow all levels */
\r
175 prvSetupHardware();
\r
177 #if WATCHDOG == WTC_IN_TASK
\r
178 vStartWatchdogTask( WTC_TASK_PRIORITY );
\r
181 /* Start the standard demo application tasks. */
\r
182 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
183 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
184 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
185 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
186 vStartBlockingQueueTasks( mainQUEUE_BLOCK_PRIORITY );
\r
187 vStartDynamicPriorityTasks();
\r
188 vStartFlashCoRoutines( mainNUM_FLASH_CO_ROUTINES );
\r
189 vStartGenericQueueTasks( mainGENERIC_QUEUE_PRIORITY );
\r
190 vCreateBlockTimeTasks();
\r
192 /* The definition INCLUDE_TraceListTasks is set within FreeRTOSConfig.h. */
\r
193 #if INCLUDE_TraceListTasks == 1
\r
194 vUtilityStartTraceTask( TASK_UTILITY_PRIORITY );
\r
196 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
\r
199 /* Start the 'Check' task which is defined in this file. */
\r
200 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
202 /* The suicide tasks must be started last as they record the number of other
\r
203 tasks that exist within the system. The value is then used to ensure at run
\r
204 time the number of tasks that exists is within expected bounds. */
\r
205 vCreateSuicidalTasks( mainDEATH_PRIORITY );
\r
207 /* Now start the scheduler. Following this call the created tasks should
\r
209 vTaskStartScheduler( );
\r
211 /* vTaskStartScheduler() will only return if an error occurs while the
\r
212 idle task is being created. */
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvSetupHardware( void )
\r
219 /* Initialise the port used by the LEDs. */
\r
220 vParTestInitialise();
\r
222 /* See watchdog.h for definitions relating to the watchdog use. */
\r
223 #if WATCHDOG != WTC_NONE
\r
227 /*-----------------------------------------------------------*/
\r
229 static void vErrorChecks( void *pvParameters )
\r
231 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
\r
233 /* Just to remove compiler warnings. */
\r
234 ( void ) pvParameters;
\r
236 /* Cycle for ever, delaying then checking all the other tasks are still
\r
237 operating without error. */
\r
240 /* Wait until it is time to check again. The time we wait here depends
\r
241 on whether an error has been detected or not. When an error is
\r
242 detected the time is shortened resulting in a faster LED flash rate. */
\r
243 vTaskDelay( xDelayPeriod );
\r
245 /* See if the other tasks are all ok. */
\r
246 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
248 /* An error occurred in one of the tasks so shorten the delay
\r
249 period - which has the effect of increasing the frequency of the
\r
251 xDelayPeriod = mainERROR_CHECK_DELAY;
\r
255 vParTestToggleLED( mainCHECK_TEST_LED );
\r
258 /*-----------------------------------------------------------*/
\r
260 static short prvCheckOtherTasksAreStillRunning( void )
\r
262 static short sNoErrorFound = pdTRUE;
\r
264 /* The demo tasks maintain a count that increments every cycle of the task
\r
265 provided that the task has never encountered an error. This function
\r
266 checks the counts maintained by the tasks to ensure they are still being
\r
267 incremented. A count remaining at the same value between calls therefore
\r
268 indicates that an error has been detected. Only tasks that do not flash
\r
269 an LED are checked. */
\r
270 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
272 sNoErrorFound = pdFALSE;
\r
275 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
277 sNoErrorFound = pdFALSE;
\r
280 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
282 sNoErrorFound = pdFALSE;
\r
285 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
287 sNoErrorFound = pdFALSE;
\r
290 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
292 sNoErrorFound = pdFALSE;
\r
295 if( xAreFlashCoRoutinesStillRunning() != pdTRUE )
\r
297 sNoErrorFound = pdFALSE;
\r
300 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
302 sNoErrorFound = pdFALSE;
\r
305 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
307 sNoErrorFound = pdFALSE;
\r
310 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
312 sNoErrorFound = pdFALSE;
\r
315 #if INCLUDE_TraceListTasks == 0
\r
317 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
319 sNoErrorFound = pdFALSE;
\r
324 return sNoErrorFound;
\r
326 /*-----------------------------------------------------------*/
\r
328 /* Idle hook function. */
\r
329 #if configUSE_IDLE_HOOK == 1
\r
330 void vApplicationIdleHook( void )
\r
332 /* Are we using the idle task to kick the watchdog? See watchdog.h
\r
333 for watchdog kicking options. Note this is for demonstration only
\r
334 and is not a suggested method of servicing the watchdog in a real
\r
336 #if WATCHDOG == WTC_IN_IDLE
\r
340 vCoRoutineSchedule();
\r
343 #if WATCHDOG == WTC_IN_IDLE
\r
344 #error configUSE_IDLE_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the idle task hook.
\r
348 /*-----------------------------------------------------------*/
\r
350 /* Tick hook function. */
\r
351 #if configUSE_TICK_HOOK == 1
\r
352 void vApplicationTickHook( void )
\r
354 /* Are we using the tick to kick the watchdog? See watchdog.h
\r
355 for watchdog kicking options. Note this is for demonstration
\r
356 only and is not a suggested method of servicing the watchdog in
\r
357 a real application. */
\r
358 #if WATCHDOG == WTC_IN_TICK
\r
363 #if WATCHDOG == WTC_IN_TICK
\r
364 #error configUSE_TICK_HOOK must be set to 1 in FreeRTOSConfig.h if the watchdog is being cleared in the tick hook.
\r
367 /*-----------------------------------------------------------*/
\r