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
70 /******************************************************************************
\r
71 * NOTE 1: This project provides two demo applications. A low power tickless
\r
72 * project, and a more comprehensive test and demo application. The
\r
73 * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to
\r
74 * select between the two. See the notes on using
\r
75 * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h. This file implements
\r
76 * the comprehensive test and demo version.
\r
78 * NOTE 2: This file only contains the source code that is specific to the
\r
79 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
80 * required to configure the hardware, are defined in main.c.
\r
81 ******************************************************************************
\r
83 * main_full() creates all the demo application tasks and a software timer, then
\r
84 * starts the scheduler. The web documentation provides more details of the
\r
85 * standard demo application tasks, which provide no particular functionality,
\r
86 * but do provide a good example of how to use the FreeRTOS API.
\r
88 * In addition to the standard demo tasks, the following tasks and tests are
\r
89 * defined and/or created within this file:
\r
91 * "Check" timer - The check software timer period is initially set to three
\r
92 * seconds. The callback function associated with the check software timer
\r
93 * checks that all the standard demo tasks are not only still executing, but
\r
94 * are executing without reporting any errors. If the check software timer
\r
95 * discovers that a task has either stalled, or reported an error, then it
\r
96 * changes its own execution period from the initial three seconds, to just
\r
97 * 200ms. The check software timer callback function also toggles an LED each
\r
98 * time it is called. This provides a visual indication of the system status:
\r
99 * If the LED toggles every three seconds, then no issues have been discovered.
\r
100 * If the LED toggles every 200ms, then an issue has been discovered with at
\r
103 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
104 * full information, including hardware setup requirements.
\r
107 /* Standard includes. */
\r
110 /* Kernel includes. */
\r
111 #include "FreeRTOS.h"
\r
113 #include "timers.h"
\r
114 #include "semphr.h"
\r
116 /* Standard demo application includes. */
\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
125 #include "partest.h"
\r
127 /* Atmel library includes. */
\r
130 /* Priorities for the demo application tasks. */
\r
131 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
132 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
133 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
135 /* A block time of zero simply means "don't block". */
\r
136 #define mainDONT_BLOCK ( 0UL )
\r
138 /* The period after which the check timer will expire providing no errors
\r
139 have been reported by any of the standard demo tasks. ms are converted to the
\r
140 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
141 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
143 /* The period at which the check timer will expire, in ms, if an error has been
\r
144 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
145 in ticks using the portTICK_PERIOD_MS constant. */
\r
146 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
148 /* The LED toggled by the check timer. */
\r
149 #define mainCHECK_LED ( 0 )
\r
151 /*-----------------------------------------------------------*/
\r
154 * The check timer callback function, as described at the top of this file.
\r
156 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
158 /*-----------------------------------------------------------*/
\r
160 void main_full( void )
\r
162 TimerHandle_t xCheckTimer = NULL;
\r
164 /* Start all the other standard demo/test tasks. They have not particular
\r
165 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
167 vStartDynamicPriorityTasks();
\r
168 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
169 vCreateBlockTimeTasks();
\r
170 vStartCountingSemaphoreTasks();
\r
171 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
172 vStartRecursiveMutexTasks();
\r
173 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
174 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
176 /* Create the software timer that performs the 'check' functionality,
\r
177 as described at the top of this file. */
\r
178 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
179 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
180 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
181 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
182 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
185 if( xCheckTimer != NULL )
\r
187 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
190 /* Start the scheduler. */
\r
191 vTaskStartScheduler();
\r
193 /* If all is well, the scheduler will now be running, and the following line
\r
194 will never be reached. If the following line does execute, then there was
\r
195 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
196 to be created. See the memory management section on the FreeRTOS web site
\r
197 for more details. */
\r
200 /*-----------------------------------------------------------*/
\r
202 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
204 static long lChangedTimerPeriodAlready = pdFALSE;
\r
205 unsigned long ulErrorFound = pdFALSE;
\r
207 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
208 they are all still running, and that none have detected an error. */
\r
210 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
212 ulErrorFound = pdTRUE;
\r
215 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
217 ulErrorFound = pdTRUE;
\r
220 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
222 ulErrorFound = pdTRUE;
\r
225 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
227 ulErrorFound = pdTRUE;
\r
230 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
232 ulErrorFound = pdTRUE;
\r
235 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
237 ulErrorFound = pdTRUE;
\r
240 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
242 ulErrorFound = pdTRUE;
\r
245 /* Toggle the check LED to give an indication of the system status. If
\r
246 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
247 everything is ok. A faster toggle indicates an error. */
\r
248 vParTestToggleLED( mainCHECK_LED );
\r
250 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
251 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
252 This will result in an increase in the rate at which mainCHECK_LED
\r
254 if( ulErrorFound != pdFALSE )
\r
256 if( lChangedTimerPeriodAlready == pdFALSE )
\r
258 lChangedTimerPeriodAlready = pdTRUE;
\r
260 /* This call to xTimerChangePeriod() uses a zero block time.
\r
261 Functions called from inside of a timer callback function must
\r
262 *never* attempt to block. */
\r
263 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
267 /*-----------------------------------------------------------*/
\r