2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /******************************************************************************
\r
97 * NOTE 1: This project provides two demo applications. A simple blinky style
\r
98 * project, and a more comprehensive test and demo application. The
\r
99 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select
\r
100 * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY
\r
101 * in main.c. This file implements the comprehensive test and demo version.
\r
103 * NOTE 2: This file only contains the source code that is specific to the
\r
104 * full demo. Generic functions, such FreeRTOS hook functions, and functions
\r
105 * required to configure the hardware, are defined in main.c.
\r
106 ******************************************************************************
\r
108 * main_full() creates a set of standard demo tasks (including a set of tasks
\r
109 * that test the interrupt nesting behaviour), some application specific tasks,
\r
110 * and a timer. It then starts the scheduler. The web documentation provides
\r
111 * more details of the standard demo application tasks, which provide no
\r
112 * particular functionality, but do provide a good example of how to use the
\r
115 * The interrupt nesting test tasks require that two timers are configured to
\r
116 * generate interrupts. The interrupt service routines are defined in
\r
117 * IntQueueTimer.c, and can be used as examples for application writers. They
\r
118 * do not, however, directly demonstrate the use of FreeRTOS safe API functions
\r
119 * (those that end in "FromISR"). Therefore, a dummy interrupt implementation
\r
120 * called Dummy_IRQHandler() is provided at the end of main.c.
\r
122 * In addition to the standard demo tasks, the following tasks and timer are
\r
123 * defined and/or created within this file:
\r
125 * "Reg test" tasks - These fill the registers with known values, then check
\r
126 * that each register maintains its expected value for the lifetime of the
\r
127 * task. Each task uses a different set of values. The reg test tasks execute
\r
128 * with a very low priority, so get preempted very frequently. A register
\r
129 * containing an unexpected value is indicative of an error in the context
\r
130 * switching mechanism.
\r
132 * "Check" software timer - The check timer period is initially set to three
\r
133 * seconds. Its callback function checks that all the standard demo tasks, and
\r
134 * the register check tasks, are not only still executing, but are executing
\r
135 * without reporting any errors. If the check timer callback discovers that a
\r
136 * task has either stalled, or reported an error, then it changes the period of
\r
137 * the check timer from the initial three seconds, to just 200ms. The callback
\r
138 * function also toggles the LED each time it is called. This provides a visual
\r
139 * indication of the system status: If the LED toggles every three seconds,
\r
140 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
141 * an issue has been discovered with at least one task.
\r
144 /* Kernel includes. */
\r
145 #include "FreeRTOS.h"
\r
148 #include "timers.h"
\r
150 /* Common demo includes. */
\r
151 #include "blocktim.h"
\r
152 #include "countsem.h"
\r
153 #include "recmutex.h"
\r
154 #include "IntQueue.h"
\r
156 /* Hardware specific includes. */
\r
157 #include "lpc11xx.h"
\r
159 /* The period after which the check timer will expire provided no errors have
\r
160 been reported by any of the standard demo tasks. ms are converted to the
\r
161 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
162 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
164 /* The period at which the check timer will expire if an error has been
\r
165 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
166 in ticks using the portTICK_PERIOD_MS constant. */
\r
167 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
169 /* A block time of zero simply means "don't block". */
\r
170 #define mainDONT_BLOCK ( 0UL )
\r
172 /*-----------------------------------------------------------*/
\r
175 * Register check tasks, as described at the top of this file. The nature of
\r
176 * these files necessitates that they are written in an assembly.
\r
178 extern void vRegTest1Task( void *pvParameters );
\r
179 extern void vRegTest2Task( void *pvParameters );
\r
182 * The hardware only has a single LED. Simply toggle it.
\r
184 extern void vMainToggleLED( void );
\r
187 * The check timer callback function, as described at the top of this file.
\r
189 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
192 * Called by main() to create the comprehensive test/demo application if
\r
193 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not set to 1.
\r
195 void main_full( void );
\r
197 /*-----------------------------------------------------------*/
\r
199 /* The following two variables are used to communicate the status of the
\r
200 register check tasks to the check software timer. If the variables keep
\r
201 incrementing, then the register check tasks has not discovered any errors. If
\r
202 a variable stops incrementing, then an error has been found. */
\r
203 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;
\r
205 /*-----------------------------------------------------------*/
\r
207 void main_full( void )
\r
209 TimerHandle_t xCheckTimer = NULL;
\r
210 /* The register test tasks are asm functions that don't use a stack. The
\r
211 stack allocated just has to be large enough to hold the task context, and
\r
212 for the additional required for the stack overflow checking to work (if
\r
214 const size_t xRegTestStackSize = 25U;
\r
216 /* Create the standard demo tasks, including the interrupt nesting test
\r
218 vStartInterruptQueueTasks();
\r
219 vCreateBlockTimeTasks();
\r
220 vStartCountingSemaphoreTasks();
\r
221 vStartRecursiveMutexTasks();
\r
223 /* Create the register test tasks as described at the top of this file.
\r
224 These are naked functions that don't use any stack. A stack still has
\r
225 to be allocated to hold the task context. */
\r
226 xTaskCreate( vRegTest1Task, /* Function that implements the task. */
\r
227 "Reg1", /* Text name of the task. */
\r
228 xRegTestStackSize, /* Stack allocated to the task. */
\r
229 NULL, /* The task parameter is not used. */
\r
230 tskIDLE_PRIORITY, /* The priority to assign to the task. */
\r
231 NULL ); /* Don't receive a handle back, it is not needed. */
\r
233 xTaskCreate( vRegTest2Task, /* Function that implements the task. */
\r
234 "Reg2", /* Text name of the task. */
\r
235 xRegTestStackSize, /* Stack allocated to the task. */
\r
236 NULL, /* The task parameter is not used. */
\r
237 tskIDLE_PRIORITY, /* The priority to assign to the task. */
\r
238 NULL ); /* Don't receive a handle back, it is not needed. */
\r
240 /* Create the software timer that performs the 'check' functionality,
\r
241 as described at the top of this file. */
\r
242 xCheckTimer = xTimerCreate( "CheckTimer", /* A text name, purely to help debugging. */
\r
243 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
244 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
245 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
246 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
249 /* If the software timer was created successfully, start it. It won't
\r
250 actually start running until the scheduler starts. A block time of
\r
251 zero is used in this call, although any value could be used as the block
\r
252 time will be ignored because the scheduler has not started yet. */
\r
253 if( xCheckTimer != NULL )
\r
255 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
258 /* Start the kernel. From here on, only tasks and interrupts will run. */
\r
259 vTaskStartScheduler();
\r
261 /* If all is well, the scheduler will now be running, and the following
\r
262 line will never be reached. If the following line does execute, then there
\r
263 was insufficient FreeRTOS heap memory available for the idle and/or timer
\r
264 tasks to be created. See the memory management section on the FreeRTOS web
\r
265 site, or the FreeRTOS tutorial books for more details. */
\r
268 /*-----------------------------------------------------------*/
\r
270 /* See the description at the top of this file. */
\r
271 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
273 static long lChangedTimerPeriodAlready = pdFALSE;
\r
274 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;
\r
275 unsigned long ulErrorFound = pdFALSE;
\r
277 /* Check all the demo and test tasks to ensure that they are all still
\r
278 running, and that none have detected an error. */
\r
279 if( xAreIntQueueTasksStillRunning() != pdPASS )
\r
281 ulErrorFound |= ( 0x01UL << 0UL );
\r
284 if( xAreBlockTimeTestTasksStillRunning() != pdPASS )
\r
286 ulErrorFound |= ( 0x01UL << 1UL );
\r
289 if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )
\r
291 ulErrorFound |= ( 0x01UL << 2UL );
\r
294 if( xAreRecursiveMutexTasksStillRunning() != pdPASS )
\r
296 ulErrorFound |= ( 0x01UL << 3UL );
\r
299 /* Check that the register test 1 task is still running. */
\r
300 if( ulLastRegTest1Value == ulRegTest1LoopCounter )
\r
302 ulErrorFound |= ( 0x01UL << 4UL );
\r
304 ulLastRegTest1Value = ulRegTest1LoopCounter;
\r
306 /* Check that the register test 2 task is still running. */
\r
307 if( ulLastRegTest2Value == ulRegTest2LoopCounter )
\r
309 ulErrorFound |= ( 0x01UL << 5UL );
\r
311 ulLastRegTest2Value = ulRegTest2LoopCounter;
\r
313 /* Toggle the check LED to give an indication of the system status. If
\r
314 the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then
\r
315 everything is ok. A faster toggle indicates an error. */
\r
318 /* Have any errors been latched in ulErrorFound? If so, shorten the
\r
319 period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.
\r
320 This will result in an increase in the rate at which mainCHECK_LED
\r
322 if( ulErrorFound != pdFALSE )
\r
324 if( lChangedTimerPeriodAlready == pdFALSE )
\r
326 lChangedTimerPeriodAlready = pdTRUE;
\r
328 /* This call to xTimerChangePeriod() uses a zero block time.
\r
329 Functions called from inside of a timer callback function must
\r
330 *never* attempt to block. */
\r
331 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
335 /*-----------------------------------------------------------*/
\r