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