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 an (emulated)
\r
98 * floating point calculation.
\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 unsigned long ulTaskCheck[ mathNUMBER_OF_TASKS ] = { 0 };
\r
134 /* Must be called before any hardware floating point operations are
\r
135 performed to let the RTOS portable layer know that this task requires
\r
136 a floating point context. */
\r
137 #if __TI_VFP_SUPPORT__
\r
138 extern void vPortTaskUsesFPU( void );
\r
141 /*-----------------------------------------------------------*/
\r
143 void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
\r
145 xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 0 ] ), uxPriority, NULL );
\r
146 xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 1 ] ), uxPriority, NULL );
\r
147 xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 2 ] ), uxPriority, NULL );
\r
148 xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 3 ] ), uxPriority, NULL );
\r
149 xTaskCreate( vCompetingMathTask1, "Math5", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 4 ] ), uxPriority, NULL );
\r
150 xTaskCreate( vCompetingMathTask2, "Math6", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 5 ] ), uxPriority, NULL );
\r
151 xTaskCreate( vCompetingMathTask3, "Math7", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 6 ] ), uxPriority, NULL );
\r
152 xTaskCreate( vCompetingMathTask4, "Math8", mathSTACK_SIZE, ( void * ) &( ulTaskCheck[ 7 ] ), uxPriority, NULL );
\r
154 /*-----------------------------------------------------------*/
\r
156 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
\r
158 volatile portDOUBLE d1, d2, d3, d4;
\r
159 volatile unsigned long *pulTaskCheckVariable;
\r
160 volatile portDOUBLE dAnswer;
\r
161 short sError = pdFALSE;
\r
164 /* Must be called before any hardware floating point operations are
\r
165 performed to let the RTOS portable layer know that this task requires
\r
166 a floating point context. */
\r
167 #if __TI_VFP_SUPPORT__
\r
168 vPortTaskUsesFPU();
\r
175 dAnswer = ( d1 + d2 ) * d3;
\r
177 /* The variable this task increments to show it is still running is passed in
\r
178 as the parameter. */
\r
179 pulTaskCheckVariable = ( unsigned long * ) pvParameters;
\r
181 /* Keep performing a calculation and checking the result against a constant. */
\r
188 d4 = ( d1 + d2 ) * d3;
\r
190 #if configUSE_PREEMPTION == 0
\r
194 /* If the calculation does not match the expected constant, stop the
\r
195 increment of the check variable. */
\r
196 if( fabs( d4 - dAnswer ) > 0.001 )
\r
201 if( sError == pdFALSE )
\r
203 /* If the calculation has always been correct, increment the check
\r
204 variable so we know this task is still running okay. */
\r
205 ( *pulTaskCheckVariable )++;
\r
208 #if configUSE_PREEMPTION == 0
\r
214 /*-----------------------------------------------------------*/
\r
216 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
\r
218 volatile portDOUBLE d1, d2, d3, d4;
\r
219 volatile unsigned long *pulTaskCheckVariable;
\r
220 volatile portDOUBLE dAnswer;
\r
221 short sError = pdFALSE;
\r
223 /* Must be called before any hardware floating point operations are
\r
224 performed to let the RTOS portable layer know that this task requires
\r
225 a floating point context. */
\r
226 #if __TI_VFP_SUPPORT__
\r
227 vPortTaskUsesFPU();
\r
234 dAnswer = ( d1 / d2 ) * d3;
\r
237 /* The variable this task increments to show it is still running is passed in
\r
238 as the parameter. */
\r
239 pulTaskCheckVariable = ( unsigned long * ) pvParameters;
\r
241 /* Keep performing a calculation and checking the result against a constant. */
\r
248 d4 = ( d1 / d2 ) * d3;
\r
250 #if configUSE_PREEMPTION == 0
\r
254 /* If the calculation does not match the expected constant, stop the
\r
255 increment of the check variable. */
\r
256 if( fabs( d4 - dAnswer ) > 0.001 )
\r
261 if( sError == pdFALSE )
\r
263 /* If the calculation has always been correct, increment the check
\r
264 variable so we know
\r
265 this task is still running okay. */
\r
266 ( *pulTaskCheckVariable )++;
\r
269 #if configUSE_PREEMPTION == 0
\r
274 /*-----------------------------------------------------------*/
\r
276 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
\r
278 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
279 volatile unsigned long *pulTaskCheckVariable;
\r
280 const size_t xArraySize = 10;
\r
282 short sError = pdFALSE;
\r
284 /* Must be called before any hardware floating point operations are
\r
285 performed to let the RTOS portable layer know that this task requires
\r
286 a floating point context. */
\r
287 #if __TI_VFP_SUPPORT__
\r
288 vPortTaskUsesFPU();
\r
291 /* The variable this task increments to show it is still running is passed in
\r
292 as the parameter. */
\r
293 pulTaskCheckVariable = ( unsigned long * ) pvParameters;
\r
295 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
297 /* Keep filling an array, keeping a running total of the values placed in the
\r
298 array. Then run through the array adding up all the values. If the two totals
\r
299 do not match, stop the check variable from incrementing. */
\r
305 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
307 pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
\r
308 dTotal1 += ( portDOUBLE ) xPosition + 5.5;
\r
311 #if configUSE_PREEMPTION == 0
\r
315 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
317 dTotal2 += pdArray[ xPosition ];
\r
320 dDifference = dTotal1 - dTotal2;
\r
321 if( fabs( dDifference ) > 0.001 )
\r
326 #if configUSE_PREEMPTION == 0
\r
330 if( sError == pdFALSE )
\r
332 /* If the calculation has always been correct, increment the check
\r
333 variable so we know this task is still running okay. */
\r
334 ( *pulTaskCheckVariable )++;
\r
338 /*-----------------------------------------------------------*/
\r
340 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
\r
342 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
343 volatile unsigned long *pulTaskCheckVariable;
\r
344 const size_t xArraySize = 10;
\r
346 short sError = pdFALSE;
\r
348 /* Must be called before any hardware floating point operations are
\r
349 performed to let the RTOS portable layer know that this task requires
\r
350 a floating point context. */
\r
351 #if __TI_VFP_SUPPORT__
\r
352 vPortTaskUsesFPU();
\r
355 /* The variable this task increments to show it is still running is passed in
\r
356 as the parameter. */
\r
357 pulTaskCheckVariable = ( unsigned long * ) pvParameters;
\r
359 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
361 /* Keep filling an array, keeping a running total of the values placed in the
\r
362 array. Then run through the array adding up all the values. If the two totals
\r
363 do not match, stop the check variable from incrementing. */
\r
369 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
371 pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
\r
372 dTotal1 += ( portDOUBLE ) xPosition * 12.123;
\r
375 #if configUSE_PREEMPTION == 0
\r
379 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
381 dTotal2 += pdArray[ xPosition ];
\r
384 dDifference = dTotal1 - dTotal2;
\r
385 if( fabs( dDifference ) > 0.001 )
\r
390 #if configUSE_PREEMPTION == 0
\r
394 if( sError == pdFALSE )
\r
396 /* If the calculation has always been correct, increment the check
\r
397 variable so we know this task is still running okay. */
\r
398 ( *pulTaskCheckVariable )++;
\r
402 /*-----------------------------------------------------------*/
\r
404 /* This is called to check that all the created tasks are still running. */
\r
405 portBASE_TYPE xAreMathsTaskStillRunning( void )
\r
407 /* Keep a history of the check variables so we know if they have been incremented
\r
408 since the last call. */
\r
409 static unsigned long ulLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
\r
410 portBASE_TYPE xReturn = pdTRUE, xTask;
\r
412 /* Check the maths tasks are still running by ensuring their check variables
\r
413 are still incrementing. */
\r
414 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
\r
416 if( ulTaskCheck[ xTask ] == ulLastTaskCheck[ xTask ] )
\r
418 /* The check has not incremented so an error exists. */
\r
422 ulLastTaskCheck[ xTask ] = ulTaskCheck[ xTask ];
\r