2 FreeRTOS V7.4.2 - Copyright (C) 2013 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
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
75 /******************************************************************************
\r
76 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
77 * project, and a more comprehensive test and demo application. The
\r
78 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
79 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
80 * in main.c. This file implements the comprehensive test and demo version.
\r
82 * NOTE 2: This file only contains the source code that is specific to the
\r
83 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
84 * required to configure the hardware, are defined in main.c.
\r
85 ******************************************************************************
\r
87 * main_full() creates all the demo application tasks and a software timer, then
\r
88 * starts the scheduler. The web documentation provides more details of the
\r
89 * standard demo application tasks, which provide no particular functionality,
\r
90 * but do provide a good example of how to use the FreeRTOS API.
\r
92 * In addition to the standard demo tasks, the following tasks and tests are
\r
93 * defined and/or created within this file:
\r
95 * "Check" timer - The check software timer period is initially set to three
\r
96 * seconds. The callback function associated with the check software timer
\r
97 * checks that all the standard demo tasks are not only still executing, but
\r
98 * are executing without reporting any errors. If the check software timer
\r
99 * discovers that a task has either stalled, or reported an error, then it
\r
100 * changes its own execution period from the initial three seconds, to just
\r
101 * 200ms. The check software timer callback function also toggles the green
\r
102 * LED each time it is called. This provides a visual indication of the system
\r
103 * status: If the green LED toggles every three seconds, then no issues have
\r
104 * been discovered. If the green LED toggles every 200ms, then an issue has
\r
105 * been discovered with at least one task.
\r
107 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
108 * full information, including hardware setup requirements.
\r
111 /* Standard includes. */
\r
114 /* Kernel includes. */
\r
115 #include "FreeRTOS.h"
\r
117 #include "timers.h"
\r
118 #include "semphr.h"
\r
120 /* Standard demo application includes. */
\r
121 #include "integer.h"
\r
123 #include "semtest.h"
\r
124 #include "dynamic.h"
\r
125 #include "BlockQ.h"
\r
126 #include "blocktim.h"
\r
127 #include "countsem.h"
\r
128 #include "GenQTest.h"
\r
129 #include "recmutex.h"
\r
131 #include "flash_timer.h"
\r
132 #include "partest.h"
\r
133 #include "comtest2.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_RATE_MS constant. */
\r
153 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\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_RATE_MS constant. */
\r
158 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\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 /*-----------------------------------------------------------*/
\r
179 * The check timer callback function, as described at the top of this file.
\r
181 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
183 /*-----------------------------------------------------------*/
\r
185 void main_full( void )
\r
187 xTimerHandle xCheckTimer = NULL;
\r
189 /* Start all the other standard demo/test tasks. The have not particular
\r
190 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
192 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
193 vStartDynamicPriorityTasks();
\r
194 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
195 vCreateBlockTimeTasks();
\r
196 vStartCountingSemaphoreTasks();
\r
197 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
198 vStartRecursiveMutexTasks();
\r
199 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
200 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
201 vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );
\r
202 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
204 /* Create the software timer that performs the 'check' functionality,
\r
205 as described at the top of this file. */
\r
206 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
207 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
208 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
209 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
210 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
213 if( xCheckTimer != NULL )
\r
215 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
218 /* The set of tasks created by the following function call have to be
\r
219 created last as they keep account of the number of tasks they expect to see
\r
221 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
223 /* Start the scheduler. */
\r
224 vTaskStartScheduler();
\r
226 /* If all is well, the scheduler will now be running, and the following line
\r
227 will never be reached. If the following line does execute, then there was
\r
228 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
229 to be created. See the memory management section on the FreeRTOS web site
\r
230 for more details. */
\r
233 /*-----------------------------------------------------------*/
\r
235 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
237 static long lChangedTimerPeriodAlready = pdFALSE;
\r
238 unsigned long ulErrorFound = pdFALSE;
\r
240 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
241 they are all still running, and that none have detected an error. */
\r
243 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
245 ulErrorFound = pdTRUE;
\r
248 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
250 ulErrorFound = pdTRUE;
\r
253 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
255 ulErrorFound = pdTRUE;
\r
258 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
260 ulErrorFound = pdTRUE;
\r
263 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
265 ulErrorFound = pdTRUE;
\r
268 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
270 ulErrorFound = pdTRUE;
\r
273 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
275 ulErrorFound = pdTRUE;
\r
278 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
280 ulErrorFound = pdTRUE;
\r
283 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
285 ulErrorFound = pdTRUE;
\r
288 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
290 ulErrorFound = pdTRUE;
\r
293 /* Toggle the check LED to give an indication of the system status. If
\r
294 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
295 everything is ok. A faster toggle indicates an error. */
\r
296 vParTestToggleLED( mainCHECK_LED );
\r
298 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
299 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
300 This will result in an increase in the rate at which mainCHECK_LED
\r
302 if( ulErrorFound != pdFALSE )
\r
304 if( lChangedTimerPeriodAlready == pdFALSE )
\r
306 lChangedTimerPeriodAlready = pdTRUE;
\r
308 /* This call to xTimerChangePeriod() uses a zero block time.
\r
309 Functions called from inside of a timer callback function must
\r
310 *never* attempt to block. */
\r
311 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
315 /*-----------------------------------------------------------*/
\r