2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /******************************************************************************
\r
66 * NOTE 1: This project provides two demo applications. A low power tickless
\r
67 * project, and a more comprehensive test and demo application. The
\r
68 * configCREATE_LOW_POWER_DEMO setting in FreeRTOSConfig.h is used to
\r
69 * select between the two. See the notes on using
\r
70 * configCREATE_LOW_POWER_DEMO in FreeRTOSConfig.h. This file implements
\r
71 * the comprehensive test and demo version.
\r
73 * NOTE 2: This file only contains the source code that is specific to the
\r
74 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
75 * required to configure the hardware, are defined in main.c.
\r
76 ******************************************************************************
\r
78 * main_full() creates all the demo application tasks and a software timer, then
\r
79 * starts the scheduler. The web documentation provides more details of the
\r
80 * standard demo application tasks, which provide no particular functionality,
\r
81 * but do provide a good example of how to use the FreeRTOS API.
\r
83 * In addition to the standard demo tasks, the following tasks and tests are
\r
84 * defined and/or created within this file:
\r
86 * "Check" timer - The check software timer period is initially set to three
\r
87 * seconds. The callback function associated with the check software timer
\r
88 * checks that all the standard demo tasks are not only still executing, but
\r
89 * are executing without reporting any errors. If the check software timer
\r
90 * discovers that a task has either stalled, or reported an error, then it
\r
91 * changes its own execution period from the initial three seconds, to just
\r
92 * 200ms. The check software timer callback function also toggles an LED each
\r
93 * time it is called. This provides a visual indication of the system status:
\r
94 * If the LED toggles every three seconds, then no issues have been discovered.
\r
95 * If the LED toggles every 200ms, then an issue has been discovered with at
\r
98 * See the documentation page for this demo on the FreeRTOS.org web site for
\r
99 * full information, including hardware setup requirements.
\r
102 /* Standard includes. */
\r
105 /* Kernel includes. */
\r
106 #include "FreeRTOS.h"
\r
108 #include "timers.h"
\r
109 #include "semphr.h"
\r
111 /* Standard demo application includes. */
\r
113 #include "semtest.h"
\r
114 #include "dynamic.h"
\r
115 #include "BlockQ.h"
\r
116 #include "blocktim.h"
\r
117 #include "countsem.h"
\r
118 #include "GenQTest.h"
\r
119 #include "recmutex.h"
\r
120 #include "partest.h"
\r
122 /* Atmel library includes. */
\r
125 /* Priorities for the demo application tasks. */
\r
126 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
127 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )
\r
128 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )
\r
130 /* A block time of zero simply means "don't block". */
\r
131 #define mainDONT_BLOCK ( 0UL )
\r
133 /* The period after which the check timer will expire providing no errors
\r
134 have been reported by any of the standard demo tasks. ms are converted to the
\r
135 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
136 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
138 /* The period at which the check timer will expire, in ms, if an error has been
\r
139 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
140 in ticks using the portTICK_RATE_MS constant. */
\r
141 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
143 /* The LED toggled by the check timer. */
\r
144 #define mainCHECK_LED ( 0 )
\r
146 /*-----------------------------------------------------------*/
\r
149 * The check timer callback function, as described at the top of this file.
\r
151 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
153 /*-----------------------------------------------------------*/
\r
155 void main_full( void )
\r
157 xTimerHandle xCheckTimer = NULL;
\r
159 /* Start all the other standard demo/test tasks. They have not particular
\r
160 functionality, but do demonstrate how to use the FreeRTOS API and test the
\r
162 vStartDynamicPriorityTasks();
\r
163 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
164 vCreateBlockTimeTasks();
\r
165 vStartCountingSemaphoreTasks();
\r
166 vStartGenericQueueTasks( tskIDLE_PRIORITY );
\r
167 vStartRecursiveMutexTasks();
\r
168 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
169 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
171 /* Create the software timer that performs the 'check' functionality,
\r
172 as described at the top of this file. */
\r
173 xCheckTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
174 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
175 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
176 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
177 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
180 if( xCheckTimer != NULL )
\r
182 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
185 /* Start the scheduler. */
\r
186 vTaskStartScheduler();
\r
188 /* If all is well, the scheduler will now be running, and the following line
\r
189 will never be reached. If the following line does execute, then there was
\r
190 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
191 to be created. See the memory management section on the FreeRTOS web site
\r
192 for more details. */
\r
195 /*-----------------------------------------------------------*/
\r
197 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
199 static long lChangedTimerPeriodAlready = pdFALSE;
\r
200 unsigned long ulErrorFound = pdFALSE;
\r
202 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
203 they are all still running, and that none have detected an error. */
\r
205 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
207 ulErrorFound = pdTRUE;
\r
210 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
212 ulErrorFound = pdTRUE;
\r
215 if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
217 ulErrorFound = pdTRUE;
\r
220 if ( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
222 ulErrorFound = pdTRUE;
\r
225 if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
227 ulErrorFound = pdTRUE;
\r
230 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
232 ulErrorFound = pdTRUE;
\r
235 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
237 ulErrorFound = pdTRUE;
\r
240 /* Toggle the check LED to give an indication of the system status. If
\r
241 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
242 everything is ok. A faster toggle indicates an error. */
\r
243 vParTestToggleLED( mainCHECK_LED );
\r
245 /* Have any errors been latch in ulErrorFound? If so, shorten the
\r
246 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
247 This will result in an increase in the rate at which mainCHECK_LED
\r
249 if( ulErrorFound != pdFALSE )
\r
251 if( lChangedTimerPeriodAlready == pdFALSE )
\r
253 lChangedTimerPeriodAlready = pdTRUE;
\r
255 /* This call to xTimerChangePeriod() uses a zero block time.
\r
256 Functions called from inside of a timer callback function must
\r
257 *never* attempt to block. */
\r
258 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
262 /*-----------------------------------------------------------*/
\r