2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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
70 /******************************************************************************
\r
71 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
72 * project, and a more comprehensive test and demo application. The
\r
73 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
74 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
75 * in main.c. This file implements the comprehensive test and demo version.
\r
77 * NOTE 2: This file only contains the source code that is specific to the
\r
78 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
79 * required to configure the hardware, are defined in main.c.
\r
80 ******************************************************************************
\r
82 * main_full() creates all the demo application tasks and a software timer, then
\r
83 * starts the scheduler. The web documentation provides more details of the
\r
84 * standard demo application tasks, which provide no particular functionality,
\r
85 * but do provide a good example of how to use the FreeRTOS API.
\r
87 * In addition to the standard demo tasks, the following tasks and tests are
\r
88 * defined and/or created within this file:
\r
90 * "Check" timer - The check software timer period is initially set to three
\r
91 * seconds. The callback function associated with the check software timer
\r
92 * checks that all the standard demo tasks are not only still executing, but
\r
93 * are executing without reporting any errors. If the check software timer
\r
94 * discovers that a task has either stalled, or reported an error, then it
\r
95 * changes its own execution period from the initial three seconds, to just
\r
96 * 200ms. The check software timer callback function also toggles the green
\r
97 * LED each time it is called. This provides a visual indication of the system
\r
98 * status: If the green LED toggles every three seconds, then no issues have
\r
99 * been discovered. If the green LED toggles every 200ms, then an issue has
\r
100 * been discovered with at least one task.
\r
102 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
103 * full information, including hardware setup requirements.
\r
106 /* Standard includes. */
\r
109 /* Kernel includes. */
\r
110 #include "FreeRTOS.h"
\r
112 #include "timers.h"
\r
113 #include "semphr.h"
\r
115 /* Standard demo application includes. */
\r
116 #include "integer.h"
\r
118 #include "semtest.h"
\r
119 #include "dynamic.h"
\r
120 #include "BlockQ.h"
\r
121 #include "blocktim.h"
\r
122 #include "countsem.h"
\r
123 #include "GenQTest.h"
\r
124 #include "recmutex.h"
\r
126 #include "flash_timer.h"
\r
127 #include "partest.h"
\r
128 #include "comtest2.h"
\r
129 #include "QueueSet.h"
\r
130 #include "IntQueue.h"
\r
131 #include "TaskNotify.h"
\r
132 #include "TimerDemo.h"
\r
133 #include "EventGroupsDemo.h"
\r
134 #include "IntSemTest.h"
\r
136 /* Atmel library includes. */
\r
139 /* Priorities for the demo application tasks. */
\r
140 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
141 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
142 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
143 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
144 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
145 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 /* A block time of zero simply means "don't block". */
\r
148 #define mainDONT_BLOCK ( 0UL )
\r
150 /* The period after which the check timer will expire, in ms, provided no errors
\r
151 have been reported by any of the standard demo tasks. ms are converted to the
\r
152 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
153 #define mainCHECK_TIMER_PERIOD_MS ( pdMS_TO_TICKS( 3000UL ) )
\r
155 /* The period at which the check timer will expire, in ms, if an error has been
\r
156 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
157 in ticks using the portTICK_PERIOD_MS constant. */
\r
158 #define mainERROR_CHECK_TIMER_PERIOD_MS ( pdMS_TO_TICKS( 200UL ) )
\r
160 /* The standard demo flash timers can be used to flash any number of LEDs. In
\r
161 this case, because only three LEDs are available, and one is in use by the
\r
162 check timer, only two are used by the flash timers. */
\r
163 #define mainNUMBER_OF_FLASH_TIMERS_LEDS ( 2 )
\r
165 /* The LED toggled by the check timer. The first two LEDs are toggle by the
\r
166 standard demo flash timers. */
\r
167 #define mainCHECK_LED ( 2 )
\r
169 /* Baud rate used by the comtest tasks. */
\r
170 #define mainCOM_TEST_BAUD_RATE ( 115200 )
\r
172 /* The LED used by the comtest tasks. In this case, there are no LEDs available
\r
173 for the comtest, so the LED number is deliberately out of range. */
\r
174 #define mainCOM_TEST_LED ( 3 )
\r
176 /* Used by the standard demo timer tasks. */
\r
177 #define mainTIMER_TEST_PERIOD ( 50 )
\r
179 /*-----------------------------------------------------------*/
\r
182 * Called by the idle hook function when the project is configured to run the
\r
183 * full (as opposed to the blinky) demo.
\r
185 void vFullDemoIdleHook( void );
\r
188 * Called by the tick hook function when the project is configured to run the
\r
189 * full (as opposed to the blinky) demo.
\r
191 void vFullDemoTickHook( void );
\r
194 * The check timer callback function, as described at the top of this file.
\r
196 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
198 /*-----------------------------------------------------------*/
\r
200 void main_full( void )
\r
202 /* Start all the other standard demo/test tasks. The have not particular
\r
203 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
205 vStartInterruptQueueTasks();
\r
206 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
207 vStartDynamicPriorityTasks();
\r
208 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
209 vCreateBlockTimeTasks();
\r
210 vStartCountingSemaphoreTasks();
\r
211 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
212 vStartRecursiveMutexTasks();
\r
213 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
214 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
215 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
216 vStartQueueSetTasks();
\r
217 vStartTaskNotifyTask();
\r
218 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
219 vStartEventGroupTasks();
\r
220 vStartInterruptSemaphoreTasks();
\r
222 /* The set of tasks created by the following function call have to be
\r
223 created last as they keep account of the number of tasks they expect to see
\r
225 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
227 /* Start the scheduler. */
\r
228 vTaskStartScheduler();
\r
230 /* If all is well, the scheduler will now be running, and the following line
\r
231 will never be reached. If the following line does execute, then there was
\r
232 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
233 to be created. See the memory management section on the FreeRTOS web site
\r
234 for more details. */
\r
237 /*-----------------------------------------------------------*/
\r
239 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
241 static long lChangedTimerPeriodAlready = pdFALSE;
\r
242 unsigned long ulErrorFound = pdFALSE;
\r
244 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
245 they are all still running, and that none have detected an error. */
\r
247 if( xAreIntQueueTasksStillRunning() != pdTRUE )
\r
249 ulErrorFound |= 1UL << 0UL;
\r
252 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
254 ulErrorFound |= 1UL << 1UL;
\r
257 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
259 ulErrorFound |= 1UL << 2UL;
\r
262 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
264 ulErrorFound |= 1UL << 3UL;
\r
267 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
269 ulErrorFound |= 1UL << 4UL;
\r
272 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
274 ulErrorFound |= 1UL << 5UL;
\r
277 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
279 ulErrorFound |= 1UL << 6UL;
\r
282 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
284 ulErrorFound |= 1UL << 7UL;
\r
287 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
289 ulErrorFound |= 1UL << 8UL;
\r
292 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
294 ulErrorFound |= 1UL << 9UL;
\r
297 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
299 ulErrorFound |= 1UL << 10UL;
\r
302 if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
304 ulErrorFound |= 1UL << 11UL;
\r
307 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )
\r
309 ulErrorFound |= 1UL << 12UL;
\r
312 if( xAreTimerDemoTasksStillRunning( mainCHECK_TIMER_PERIOD_MS ) != pdTRUE )
\r
314 ulErrorFound |= 1UL << 13UL;
\r
317 if( xAreEventGroupTasksStillRunning() != pdTRUE )
\r
319 ulErrorFound |= 1UL << 14UL;
\r
322 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )
\r
324 ulErrorFound |= 1UL << 15UL;
\r
328 /* Toggle the check LED to give an indication of the system status. If
\r
329 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
330 everything is ok. A faster toggle indicates an error. */
\r
331 vParTestToggleLED( mainCHECK_LED );
\r
333 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
334 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
335 This will result in an increase in the rate at which mainCHECK_LED
\r
337 if( ulErrorFound != pdFALSE )
\r
339 if( lChangedTimerPeriodAlready == pdFALSE )
\r
341 lChangedTimerPeriodAlready = pdTRUE;
\r
343 /* This call to xTimerChangePeriod() uses a zero block time.
\r
344 Functions called from inside of a timer callback function must
\r
345 *never* attempt to block. */
\r
346 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
350 /*-----------------------------------------------------------*/
\r
352 void vFullDemoIdleHook( void )
\r
354 static TimerHandle_t xCheckTimer = NULL;
\r
356 if( xCheckTimer == NULL )
\r
358 /* Create the software timer that performs the 'check'
\r
359 functionality, in the full demo. This is not done before the
\r
360 scheduler is started as to do so would prevent the standard demo
\r
361 timer tasks from passing their tests (they expect the timer
\r
362 command queue to be empty. */
\r
363 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
364 mainCHECK_TIMER_PERIOD_MS, /* The timer period, in this case 3000ms (3s). */
\r
365 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
366 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
367 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
370 if( xCheckTimer != NULL )
\r
372 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
375 /* Also start some timers that just flash LEDs. */
\r
376 vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );
\r
379 /*-----------------------------------------------------------*/
\r
381 void vFullDemoTickHook( void )
\r
383 /* In this case the tick hook is used as part of the queue set test. */
\r
384 vQueueSetAccessQueueSetFromISR();
\r
386 /* Use task notifications from an interrupt. */
\r
387 xNotifyTaskFromISR();
\r
389 /* Use timers from an interrupt. */
\r
390 vTimerPeriodicISRTests();
\r
392 /* Use event groups from an interrupt. */
\r
393 vPeriodicEventGroupsProcessing();
\r
395 /* Use mutexes from interrupts. */
\r
396 vInterruptSemaphorePeriodicTest();
\r