2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /******************************************************************************
\r
67 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
68 * project, and a more comprehensive test and demo application. The
\r
69 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
70 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
71 * in main.c. This file implements 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 a set of standard demo tasks (including a set of tasks
\r
79 * that test the interrupt nesting behaviour), some application specific tasks,
\r
80 * and a timer. It then starts the scheduler. The web documentation provides
\r
81 * more details of the standard demo application tasks, which provide no
\r
82 * particular functionality, but do provide a good example of how to use the
\r
85 * The interrupt nesting test tasks require that two timers are configured to
\r
86 * generate interrupts. The interrupt service routines are defined in
\r
87 * IntQueueTimer.c, and can be used as examples for application writers. They
\r
88 * do not, however, directly demonstrate the use of FreeRTOS safe API functions
\r
89 * (those that end in "FromISR"). Therefore, a dummy interrupt implementation
\r
90 * called Dummy_IRQHandler() is provided at the end of main.c.
\r
92 * In addition to the standard demo tasks, the following tasks and timer are
\r
93 * defined and/or created within this file:
\r
95 * "Reg test" tasks - These fill the registers with known values, then check
\r
96 * that each register maintains its expected value for the lifetime of the
\r
97 * task. Each task uses a different set of values. The reg test tasks execute
\r
98 * with a very low priority, so get preempted very frequently. A register
\r
99 * containing an unexpected value is indicative of an error in the context
\r
100 * switching mechanism.
\r
102 * "Check" software timer - The check timer period is initially set to three
\r
103 * seconds. Its callback function checks that all the standard demo tasks, and
\r
104 * the register check tasks, are not only still executing, but are executing
\r
105 * without reporting any errors. If the check timer callback discovers that a
\r
106 * task has either stalled, or reported an error, then it changes the period of
\r
107 * the check timer from the initial three seconds, to just 200ms. The callback
\r
108 * function also toggles the LED each time it is called. This provides a visual
\r
109 * indication of the system status: If the LED toggles every three seconds,
\r
110 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
111 * an issue has been discovered with at least one task.
\r
114 /* Kernel includes. */
\r
115 #include "FreeRTOS.h"
\r
118 #include "timers.h"
\r
120 /* Common demo includes. */
\r
121 #include "blocktim.h"
\r
122 #include "countsem.h"
\r
123 #include "recmutex.h"
\r
124 #include "IntQueue.h"
\r
126 /* Hardware specific includes. */
\r
127 #include "lpc11xx.h"
\r
129 /* The period after which the check timer will expire provided no errors have
\r
130 been reported by any of the standard demo tasks. ms are converted to the
\r
131 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
132 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
134 /* The period at which the check timer will expire if an error has been
\r
135 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
136 in ticks using the portTICK_PERIOD_MS constant. */
\r
137 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
139 /* A block time of zero simply means "don't block". */
\r
140 #define mainDONT_BLOCK ( 0UL )
\r
142 /*-----------------------------------------------------------*/
\r
145 * Register check tasks, as described at the top of this file. The nature of
\r
146 * these files necessitates that they are written in an assembly.
\r
148 extern void vRegTest1Task( void *pvParameters );
\r
149 extern void vRegTest2Task( void *pvParameters );
\r
152 * The hardware only has a single LED. Simply toggle it.
\r
154 extern void vMainToggleLED( void );
\r
157 * The check timer callback function, as described at the top of this file.
\r
159 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
162 * Called by main() to create the comprehensive test/demo application if
\r
163 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not set to 1.
\r
165 void main_full( void );
\r
167 /*-----------------------------------------------------------*/
\r
169 /* The following two variables are used to communicate the status of the
\r
170 register check tasks to the check software timer. If the variables keep
\r
171 incrementing, then the register check tasks has not discovered any errors. If
\r
172 a variable stops incrementing, then an error has been found. */
\r
173 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
175 /*-----------------------------------------------------------*/
\r
177 void main_full( void )
\r
179 TimerHandle_t xCheckTimer = NULL;
\r
180 /* The register test tasks are asm functions that don't use a stack. The
\r
181 stack allocated just has to be large enough to hold the task context, and
\r
182 for the additional required for the stack overflow checking to work (if
\r
184 const size_t xRegTestStackSize = 25U;
\r
186 /* Create the standard demo tasks, including the interrupt nesting test
\r
188 vStartInterruptQueueTasks();
\r
189 vCreateBlockTimeTasks();
\r
190 vStartCountingSemaphoreTasks();
\r
191 vStartRecursiveMutexTasks();
\r
193 /* Create the register test tasks as described at the top of this file.
\r
194 These are naked functions that don't use any stack. A stack still has
\r
195 to be allocated to hold the task context. */
\r
196 xTaskCreate( vRegTest1Task, /* Function that implements the task. */
\r
197 "Reg1", /* Text name of the task. */
\r
198 xRegTestStackSize, /* Stack allocated to the task. */
\r
199 NULL, /* The task parameter is not used. */
\r
200 tskIDLE_PRIORITY, /* The priority to assign to the task. */
\r
201 NULL ); /* Don't receive a handle back, it is not needed. */
\r
203 xTaskCreate( vRegTest2Task, /* Function that implements the task. */
\r
204 "Reg2", /* Text name of the task. */
\r
205 xRegTestStackSize, /* Stack allocated to the task. */
\r
206 NULL, /* The task parameter is not used. */
\r
207 tskIDLE_PRIORITY, /* The priority to assign to the task. */
\r
208 NULL ); /* Don't receive a handle back, it is not needed. */
\r
210 /* Create the software timer that performs the 'check' functionality,
\r
211 as described at the top of this file. */
\r
212 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
213 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
214 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
215 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
216 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
219 /* If the software timer was created successfully, start it. It won't
\r
220 actually start running until the scheduler starts. A block time of
\r
221 zero is used in this call, although any value could be used as the block
\r
222 time will be ignored because the scheduler has not started yet. */
\r
223 if( xCheckTimer != NULL )
\r
225 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
228 /* Start the kernel. From here on, only tasks and interrupts will run. */
\r
229 vTaskStartScheduler();
\r
231 /* If all is well, the scheduler will now be running, and the following
\r
232 line will never be reached. If the following line does execute, then there
\r
233 was insufficient FreeRTOS heap memory available for the idle and/or timer
\r
234 tasks to be created. See the memory management section on the FreeRTOS web
\r
235 site, or the FreeRTOS tutorial books for more details. */
\r
238 /*-----------------------------------------------------------*/
\r
240 /* See the description at the top of this file. */
\r
241 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
243 static long lChangedTimerPeriodAlready = pdFALSE;
\r
244 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
245 unsigned long ulErrorFound = pdFALSE;
\r
247 /* Check all the demo and test tasks to ensure that they are all still
\r
248 running, and that none have detected an error. */
\r
249 if( xAreIntQueueTasksStillRunning() != pdPASS )
\r
251 ulErrorFound |= ( 0x01UL << 0UL );
\r
254 if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
256 ulErrorFound |= ( 0x01UL << 1UL );
\r
259 if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )
\r
261 ulErrorFound |= ( 0x01UL << 2UL );
\r
264 if( xAreRecursiveMutexTasksStillRunning() != pdPASS )
\r
266 ulErrorFound |= ( 0x01UL << 3UL );
\r
269 /* Check that the register test 1 task is still running. */
\r
270 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
272 ulErrorFound |= ( 0x01UL << 4UL );
\r
274 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
276 /* Check that the register test 2 task is still running. */
\r
277 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
279 ulErrorFound |= ( 0x01UL << 5UL );
\r
281 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
283 /* Toggle the check LED to give an indication of the system status. If
\r
284 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
285 everything is ok. A faster toggle indicates an error. */
\r
288 /* Have any errors been latched in ulErrorFound? If so, shorten the
\r
289 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
290 This will result in an increase in the rate at which mainCHECK_LED
\r
292 if( ulErrorFound != pdFALSE )
\r
294 if( lChangedTimerPeriodAlready == pdFALSE )
\r
296 lChangedTimerPeriodAlready = pdTRUE;
\r
298 /* This call to xTimerChangePeriod() uses a zero block time.
\r
299 Functions called from inside of a timer callback function must
\r
300 *never* attempt to block. */
\r
301 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
305 /*-----------------------------------------------------------*/
\r