2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 /******************************************************************************
\r
68 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
69 * project, and a more comprehensive test and demo application. The
\r
70 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
71 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
72 * in main.c. This file implements the comprehensive test and demo version.
\r
74 * NOTE 2: This file only contains the source code that is specific to the
\r
75 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
76 * required to configure the hardware, are defined in main.c.
\r
77 ******************************************************************************
\r
79 * main_full() creates all the demo application tasks and a software timer, then
\r
80 * starts the scheduler. The web documentation provides more details of the
\r
81 * standard demo application tasks, which provide no particular functionality,
\r
82 * but do provide a good example of how to use the FreeRTOS API.
\r
84 * In addition to the standard demo tasks, the following tasks and tests are
\r
85 * defined and/or created within this file:
\r
87 * "Check" timer - The check software timer period is initially set to three
\r
88 * seconds. The callback function associated with the check software timer
\r
89 * checks that all the standard demo tasks are not only still executing, but
\r
90 * are executing without reporting any errors. If the check software timer
\r
91 * discovers that a task has either stalled, or reported an error, then it
\r
92 * changes its own execution period from the initial three seconds, to just
\r
93 * 200ms. The check software timer callback function also toggles the green
\r
94 * LED each time it is called. This provides a visual indication of the system
\r
95 * status: If the green LED toggles every three seconds, then no issues have
\r
96 * been discovered. If the green LED toggles every 200ms, then an issue has
\r
97 * been discovered with at least one task.
\r
99 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
100 * full information, including hardware setup requirements.
\r
103 /* Standard includes. */
\r
106 /* Kernel includes. */
\r
107 #include "FreeRTOS.h"
\r
109 #include "timers.h"
\r
110 #include "semphr.h"
\r
112 /* Standard demo application includes. */
\r
113 #include "integer.h"
\r
115 #include "semtest.h"
\r
116 #include "dynamic.h"
\r
117 #include "BlockQ.h"
\r
118 #include "blocktim.h"
\r
119 #include "countsem.h"
\r
120 #include "GenQTest.h"
\r
121 #include "recmutex.h"
\r
123 #include "flash_timer.h"
\r
124 #include "partest.h"
\r
125 #include "comtest2.h"
\r
128 /* Atmel library includes. */
\r
131 /* Priorities for the demo application tasks. */
\r
132 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
133 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
134 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
135 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3UL )
\r
136 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
137 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
139 /* A block time of zero simply means "don't block". */
\r
140 #define mainDONT_BLOCK ( 0UL )
\r
142 /* The period after which the check timer will expire, in ms, provided no errors
\r
143 have been reported by any of the standard demo tasks. ms are converted to the
\r
144 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
145 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
147 /* The period at which the check timer will expire, in ms, if an error has been
\r
148 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
149 in ticks using the portTICK_RATE_MS constant. */
\r
150 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
152 /* The standard demo flash timers can be used to flash any number of LEDs. In
\r
153 this case, because only three LEDs are available, and one is in use by the
\r
154 check timer, only two are used by the flash timers. */
\r
155 #define mainNUMBER_OF_FLASH_TIMERS_LEDS ( 2 )
\r
157 /* The LED toggled by the check timer. The first two LEDs are toggle by the
\r
158 standard demo flash timers. */
\r
159 #define mainCHECK_LED ( 2 )
\r
161 /* Baud rate used by the comtest tasks. */
\r
162 #define mainCOM_TEST_BAUD_RATE ( 115200 )
\r
164 /* The LED used by the comtest tasks. In this case, there are no LEDs available
\r
165 for the comtest, so the LED number is deliberately out of range. */
\r
166 #define mainCOM_TEST_LED ( 3 )
\r
168 /*-----------------------------------------------------------*/
\r
171 * The check timer callback function, as described at the top of this file.
\r
173 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
175 /*-----------------------------------------------------------*/
\r
177 void main_full( void )
\r
179 xTimerHandle xCheckTimer = NULL;
\r
181 /* Start all the other standard demo/test tasks. The have not particular
\r
182 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
184 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
185 vStartDynamicPriorityTasks();
\r
186 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
187 vCreateBlockTimeTasks();
\r
188 vStartCountingSemaphoreTasks();
\r
189 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
190 vStartRecursiveMutexTasks();
\r
191 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
192 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
193 vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );
\r
194 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
196 /* Create the software timer that performs the 'check' functionality,
\r
197 as described at the top of this file. */
\r
198 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
199 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
200 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
201 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
202 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
205 if( xCheckTimer != NULL )
\r
207 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
210 /* The set of tasks created by the following function call have to be
\r
211 created last as they keep account of the number of tasks they expect to see
\r
213 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
215 /* Start the scheduler. */
\r
216 vTaskStartScheduler();
\r
218 /* If all is well, the scheduler will now be running, and the following line
\r
219 will never be reached. If the following line does execute, then there was
\r
220 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
221 to be created. See the memory management section on the FreeRTOS web site
\r
222 for more details. */
\r
225 /*-----------------------------------------------------------*/
\r
227 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
229 static long lChangedTimerPeriodAlready = pdFALSE;
\r
230 unsigned long ulErrorFound = pdFALSE;
\r
232 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
233 they are all still running, and that none have detected an error. */
\r
235 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
237 ulErrorFound = pdTRUE;
\r
240 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
242 ulErrorFound = pdTRUE;
\r
245 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
247 ulErrorFound = pdTRUE;
\r
250 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
252 ulErrorFound = pdTRUE;
\r
255 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
257 ulErrorFound = pdTRUE;
\r
260 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
262 ulErrorFound = pdTRUE;
\r
265 if( xIsCreateTaskStillRunning() != pdTRUE )
\r
267 ulErrorFound = pdTRUE;
\r
270 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
272 ulErrorFound = pdTRUE;
\r
275 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
277 ulErrorFound = pdTRUE;
\r
280 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
282 ulErrorFound = pdTRUE;
\r
285 /* Toggle the check LED to give an indication of the system status. If
\r
286 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
287 everything is ok. A faster toggle indicates an error. */
\r
288 vParTestToggleLED( mainCHECK_LED );
\r
290 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
291 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
292 This will result in an increase in the rate at which mainCHECK_LED
\r
294 if( ulErrorFound != pdFALSE )
\r
296 if( lChangedTimerPeriodAlready == pdFALSE )
\r
298 lChangedTimerPeriodAlready = pdTRUE;
\r
300 /* This call to xTimerChangePeriod() uses a zero block time.
\r
301 Functions called from inside of a timer callback function must
\r
302 *never* attempt to block. */
\r
303 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
307 /*-----------------------------------------------------------*/
\r