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
69 /******************************************************************************
\r
70 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
71 * project, and a more comprehensive test and demo application. The
\r
72 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
73 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
74 * in main.c. This file implements the comprehensive test and demo version.
\r
76 * NOTE 2: This file only contains the source code that is specific to the
\r
77 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
78 * required to configure the hardware, are defined in main.c.
\r
79 ******************************************************************************
\r
81 * main_full() creates all the demo application tasks and a software timer, then
\r
82 * starts the scheduler. The web documentation provides more details of the
\r
83 * standard demo application tasks, which provide no particular functionality,
\r
84 * but do provide a good example of how to use the FreeRTOS API.
\r
86 * In addition to the standard demo tasks, the following tasks and tests are
\r
87 * defined and/or created within this file:
\r
89 * "Check" timer - The check software timer period is initially set to three
\r
90 * seconds. The callback function associated with the check software timer
\r
91 * checks that all the standard demo tasks are not only still executing, but
\r
92 * are executing without reporting any errors. If the check software timer
\r
93 * discovers that a task has either stalled, or reported an error, then it
\r
94 * changes its own execution period from the initial three seconds, to just
\r
95 * 200ms. The check software timer callback function also toggles the green
\r
96 * LED each time it is called. This provides a visual indication of the system
\r
97 * status: If the green LED toggles every three seconds, then no issues have
\r
98 * been discovered. If the green LED toggles every 200ms, then an issue has
\r
99 * been discovered with at least one task.
\r
101 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
102 * full information, including hardware setup requirements.
\r
105 /* Standard includes. */
\r
108 /* Kernel includes. */
\r
109 #include "FreeRTOS.h"
\r
111 #include "timers.h"
\r
112 #include "semphr.h"
\r
114 /* Standard demo application includes. */
\r
115 #include "integer.h"
\r
117 #include "semtest.h"
\r
118 #include "dynamic.h"
\r
119 #include "BlockQ.h"
\r
120 #include "blocktim.h"
\r
121 #include "countsem.h"
\r
122 #include "GenQTest.h"
\r
123 #include "recmutex.h"
\r
125 #include "flash_timer.h"
\r
126 #include "partest.h"
\r
127 #include "comtest2.h"
\r
128 #include "QueueSet.h"
\r
130 /* Atmel library includes. */
\r
133 /* Priorities for the demo application tasks. */
\r
134 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
135 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
136 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
137 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
138 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
139 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
141 /* A block time of zero simply means "don't block". */
\r
142 #define mainDONT_BLOCK ( 0UL )
\r
144 /* The period after which the check timer will expire, in ms, provided no errors
\r
145 have been reported by any of the standard demo tasks. ms are converted to the
\r
146 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
147 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
149 /* The period at which the check timer will expire, in ms, if an error has been
\r
150 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
151 in ticks using the portTICK_RATE_MS constant. */
\r
152 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
154 /* The standard demo flash timers can be used to flash any number of LEDs. In
\r
155 this case, because only three LEDs are available, and one is in use by the
\r
156 check timer, only two are used by the flash timers. */
\r
157 #define mainNUMBER_OF_FLASH_TIMERS_LEDS ( 2 )
\r
159 /* The LED toggled by the check timer. The first two LEDs are toggle by the
\r
160 standard demo flash timers. */
\r
161 #define mainCHECK_LED ( 2 )
\r
163 /* Baud rate used by the comtest tasks. */
\r
164 #define mainCOM_TEST_BAUD_RATE ( 115200 )
\r
166 /* The LED used by the comtest tasks. In this case, there are no LEDs available
\r
167 for the comtest, so the LED number is deliberately out of range. */
\r
168 #define mainCOM_TEST_LED ( 3 )
\r
170 /*-----------------------------------------------------------*/
\r
173 * The check timer callback function, as described at the top of this file.
\r
175 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
177 /*-----------------------------------------------------------*/
\r
179 void main_full( void )
\r
181 xTimerHandle xCheckTimer = NULL;
\r
183 /* Start all the other standard demo/test tasks. The have not particular
\r
184 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
186 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
187 vStartDynamicPriorityTasks();
\r
188 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
189 vCreateBlockTimeTasks();
\r
190 vStartCountingSemaphoreTasks();
\r
191 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
192 vStartRecursiveMutexTasks();
\r
193 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
194 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
195 vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );
\r
196 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
197 vStartQueueSetTasks();
\r
199 /* Create the software timer that performs the 'check' functionality,
\r
200 as described at the top of this file. */
\r
201 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
202 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
203 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
204 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
205 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
208 if( xCheckTimer != NULL )
\r
210 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
213 /* The set of tasks created by the following function call have to be
\r
214 created last as they keep account of the number of tasks they expect to see
\r
216 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
218 /* Start the scheduler. */
\r
219 vTaskStartScheduler();
\r
221 /* If all is well, the scheduler will now be running, and the following line
\r
222 will never be reached. If the following line does execute, then there was
\r
223 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
224 to be created. See the memory management section on the FreeRTOS web site
\r
225 for more details. */
\r
228 /*-----------------------------------------------------------*/
\r
230 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
232 static long lChangedTimerPeriodAlready = pdFALSE;
\r
233 unsigned long ulErrorFound = pdFALSE;
\r
235 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
236 they are all still running, and that none have detected an error. */
\r
238 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
240 ulErrorFound = pdTRUE;
\r
243 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
245 ulErrorFound = pdTRUE;
\r
248 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
250 ulErrorFound = pdTRUE;
\r
253 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
255 ulErrorFound = pdTRUE;
\r
258 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
260 ulErrorFound = pdTRUE;
\r
263 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
265 ulErrorFound = pdTRUE;
\r
268 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
270 ulErrorFound = pdTRUE;
\r
273 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
275 ulErrorFound = pdTRUE;
\r
278 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
280 ulErrorFound = pdTRUE;
\r
283 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
285 ulErrorFound = pdTRUE;
\r
288 if( xAreQueueSetTasksStillRunning() != pdPASS )
\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