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
97 * Creates eight tasks, each of which loops continuously performing a floating
\r
98 * point calculation - using single precision variables.
\r
100 * All the tasks run at the idle priority and never block or yield. This causes
\r
101 * all eight tasks to time slice with the idle task. Running at the idle priority
\r
102 * means that these tasks will get pre-empted any time another task is ready to run
\r
103 * or a time slice occurs. More often than not the pre-emption will occur mid
\r
104 * calculation, creating a good test of the schedulers context switch mechanism - a
\r
105 * calculation producing an unexpected result could be a symptom of a corruption in
\r
106 * the context of a task.
\r
109 #include <stdlib.h>
\r
112 /* Scheduler include files. */
\r
113 #include "FreeRTOS.h"
\r
116 /* Demo program include files. */
\r
119 #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
\r
120 #define mathNUMBER_OF_TASKS ( 8 )
\r
122 /* Four tasks, each of which performs a different floating point calculation.
\r
123 Each of the four is created twice. */
\r
124 static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
\r
125 static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
\r
126 static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
\r
127 static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
\r
129 /* These variables are used to check that all the tasks are still running. If a
\r
130 task gets a calculation wrong it will
\r
131 stop incrementing its check variable. */
\r
132 static volatile uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
\r
134 /*-----------------------------------------------------------*/
\r
136 void vStartMathTasks( UBaseType_t uxPriority )
\r
138 xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
\r
139 xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
\r
140 xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
\r
141 xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
\r
142 xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
\r
143 xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
\r
144 xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
\r
145 xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
\r
147 /*-----------------------------------------------------------*/
\r
149 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
\r
151 volatile float f1, f2, f3, f4;
\r
152 volatile uint16_t *pusTaskCheckVariable;
\r
153 volatile float fAnswer;
\r
154 short sError = pdFALSE;
\r
160 fAnswer = ( f1 + f2 ) * f3;
\r
162 /* The variable this task increments to show it is still running is passed in
\r
163 as the parameter. */
\r
164 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
166 /* Keep performing a calculation and checking the result against a constant. */
\r
173 f4 = ( f1 + f2 ) * f3;
\r
175 #if configUSE_PREEMPTION == 0
\r
179 /* If the calculation does not match the expected constant, stop the
\r
180 increment of the check variable. */
\r
181 if( fabs( f4 - fAnswer ) > 0.001F )
\r
186 if( sError == pdFALSE )
\r
188 /* If the calculation has always been correct, increment the check
\r
189 variable so we know this task is still running okay. */
\r
190 ( *pusTaskCheckVariable )++;
\r
193 #if configUSE_PREEMPTION == 0
\r
199 /*-----------------------------------------------------------*/
\r
201 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
\r
203 volatile float f1, f2, f3, f4;
\r
204 volatile uint16_t *pusTaskCheckVariable;
\r
205 volatile float fAnswer;
\r
206 short sError = pdFALSE;
\r
212 fAnswer = ( f1 / f2 ) * f3;
\r
215 /* The variable this task increments to show it is still running is passed in
\r
216 as the parameter. */
\r
217 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
219 /* Keep performing a calculation and checking the result against a constant. */
\r
226 f4 = ( f1 / f2 ) * f3;
\r
228 #if configUSE_PREEMPTION == 0
\r
232 /* If the calculation does not match the expected constant, stop the
\r
233 increment of the check variable. */
\r
234 if( fabs( f4 - fAnswer ) > 0.001F )
\r
239 if( sError == pdFALSE )
\r
241 /* If the calculation has always been correct, increment the check
\r
242 variable so we know
\r
243 this task is still running okay. */
\r
244 ( *pusTaskCheckVariable )++;
\r
247 #if configUSE_PREEMPTION == 0
\r
252 /*-----------------------------------------------------------*/
\r
254 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
\r
256 volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
\r
257 volatile uint16_t *pusTaskCheckVariable;
\r
258 const size_t xArraySize = 10;
\r
260 short sError = pdFALSE;
\r
262 /* The variable this task increments to show it is still running is passed in
\r
263 as the parameter. */
\r
264 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
266 pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
\r
268 /* Keep filling an array, keeping a running total of the values placed in the
\r
269 array. Then run through the array adding up all the values. If the two totals
\r
270 do not match, stop the check variable from incrementing. */
\r
277 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
279 pfArray[ xPosition ] = fPosition + 5.5F;
\r
280 fTotal1 += fPosition + 5.5F;
\r
283 #if configUSE_PREEMPTION == 0
\r
287 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
289 fTotal2 += pfArray[ xPosition ];
\r
292 fDifference = fTotal1 - fTotal2;
\r
293 if( fabs( fDifference ) > 0.001F )
\r
298 #if configUSE_PREEMPTION == 0
\r
302 if( sError == pdFALSE )
\r
304 /* If the calculation has always been correct, increment the check
\r
305 variable so we know this task is still running okay. */
\r
306 ( *pusTaskCheckVariable )++;
\r
310 /*-----------------------------------------------------------*/
\r
312 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
\r
314 volatile float *pfArray, fTotal1, fTotal2, fDifference, fPosition;
\r
315 volatile uint16_t *pusTaskCheckVariable;
\r
316 const size_t xArraySize = 10;
\r
318 short sError = pdFALSE;
\r
320 /* The variable this task increments to show it is still running is passed in
\r
321 as the parameter. */
\r
322 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
324 pfArray = ( float * ) pvPortMalloc( xArraySize * sizeof( float ) );
\r
326 /* Keep filling an array, keeping a running total of the values placed in the
\r
327 array. Then run through the array adding up all the values. If the two totals
\r
328 do not match, stop the check variable from incrementing. */
\r
335 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
337 pfArray[ xPosition ] = fPosition * 12.123F;
\r
338 fTotal1 += fPosition * 12.123F;
\r
341 #if configUSE_PREEMPTION == 0
\r
345 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
347 fTotal2 += pfArray[ xPosition ];
\r
350 fDifference = fTotal1 - fTotal2;
\r
351 if( fabs( fDifference ) > 0.001F )
\r
356 #if configUSE_PREEMPTION == 0
\r
360 if( sError == pdFALSE )
\r
362 /* If the calculation has always been correct, increment the check
\r
363 variable so we know this task is still running okay. */
\r
364 ( *pusTaskCheckVariable )++;
\r
368 /*-----------------------------------------------------------*/
\r
370 /* This is called to check that all the created tasks are still running. */
\r
371 BaseType_t xAreMathsTaskStillRunning( void )
\r
373 /* Keep a history of the check variables so we know if they have been incremented
\r
374 since the last call. */
\r
375 static uint16_t usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
\r
376 BaseType_t xReturn = pdTRUE, xTask;
\r
378 /* Check the maths tasks are still running by ensuring their check variables
\r
379 are still incrementing. */
\r
380 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
\r
382 if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
\r
384 /* The check has not incremented so an error exists. */
\r
388 usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
\r