2 FreeRTOS V8.2.1 - Copyright (C) 2015 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 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates eight tasks, each of which loops continuously performing a floating
\r
72 * point calculation.
\r
74 * All the tasks run at the idle priority and never block or yield. This causes
\r
75 * all eight tasks to time slice with the idle task. Running at the idle
\r
76 * priority means that these tasks will get pre-empted any time another task is
\r
77 * ready to run or a time slice occurs. More often than not the pre-emption
\r
78 * will occur mid calculation, creating a good test of the schedulers context
\r
79 * switch mechanism - a calculation producing an unexpected result could be a
\r
80 * symptom of a corruption in the context of a task.
\r
86 /* Scheduler include files. */
\r
87 #include "FreeRTOS.h"
\r
90 /* Demo program include files. */
\r
93 #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
\r
94 #define mathNUMBER_OF_TASKS ( 4 )
\r
96 /* Four tasks, each of which performs a different floating point calculation.
\r
97 Each of the four is created twice. */
\r
98 static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
\r
99 static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
\r
100 static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
\r
101 static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
\r
103 /* These variables are used to check that all the tasks are still running. If a
\r
104 task gets a calculation wrong it will stop setting its check variable. */
\r
105 static volatile uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
\r
107 /*-----------------------------------------------------------*/
\r
109 void vStartMathTasks( UBaseType_t uxPriority )
\r
111 xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
\r
112 xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
\r
113 xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
\r
114 xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
\r
116 /*-----------------------------------------------------------*/
\r
118 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
\r
120 volatile portDOUBLE d1, d2, d3, d4;
\r
121 volatile uint16_t *pusTaskCheckVariable;
\r
122 volatile portDOUBLE dAnswer;
\r
123 short sError = pdFALSE;
\r
125 /* Some ports require that tasks that use a hardware floating point unit
\r
126 tell the kernel that they require a floating point context before any
\r
127 floating point instructions are executed. */
\r
128 portTASK_USES_FLOATING_POINT();
\r
134 dAnswer = ( d1 + d2 ) * d3;
\r
136 /* The variable this task increments to show it is still running is passed in
\r
137 as the parameter. */
\r
138 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
140 /* Keep performing a calculation and checking the result against a constant. */
\r
147 d4 = ( d1 + d2 ) * d3;
\r
149 #if configUSE_PREEMPTION == 0
\r
153 /* If the calculation does not match the expected constant, stop the
\r
154 increment of the check variable. */
\r
155 if( fabs( d4 - dAnswer ) > 0.001 )
\r
160 if( sError == pdFALSE )
\r
162 /* If the calculation has always been correct then set set the check
\r
163 variable. The check variable will get set to pdFALSE each time
\r
164 xAreMathsTaskStillRunning() is executed. */
\r
165 ( *pusTaskCheckVariable ) = pdTRUE;
\r
168 #if configUSE_PREEMPTION == 0
\r
174 /*-----------------------------------------------------------*/
\r
176 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
\r
178 volatile portDOUBLE d1, d2, d3, d4;
\r
179 volatile uint16_t *pusTaskCheckVariable;
\r
180 volatile portDOUBLE dAnswer;
\r
181 short sError = pdFALSE;
\r
183 /* Some ports require that tasks that use a hardware floating point unit
\r
184 tell the kernel that they require a floating point context before any
\r
185 floating point instructions are executed. */
\r
186 portTASK_USES_FLOATING_POINT();
\r
192 dAnswer = ( d1 / d2 ) * d3;
\r
195 /* The variable this task increments to show it is still running is passed in
\r
196 as the parameter. */
\r
197 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
199 /* Keep performing a calculation and checking the result against a constant. */
\r
206 d4 = ( d1 / d2 ) * d3;
\r
208 #if configUSE_PREEMPTION == 0
\r
212 /* If the calculation does not match the expected constant, stop the
\r
213 increment of the check variable. */
\r
214 if( fabs( d4 - dAnswer ) > 0.001 )
\r
219 if( sError == pdFALSE )
\r
221 /* If the calculation has always been correct then set set the check
\r
222 variable. The check variable will get set to pdFALSE each time
\r
223 xAreMathsTaskStillRunning() is executed. */
\r
224 ( *pusTaskCheckVariable ) = pdTRUE;
\r
227 #if configUSE_PREEMPTION == 0
\r
232 /*-----------------------------------------------------------*/
\r
234 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
\r
236 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
237 volatile uint16_t *pusTaskCheckVariable;
\r
238 const size_t xArraySize = 10;
\r
240 short sError = pdFALSE;
\r
242 /* Some ports require that tasks that use a hardware floating point unit
\r
243 tell the kernel that they require a floating point context before any
\r
244 floating point instructions are executed. */
\r
245 portTASK_USES_FLOATING_POINT();
\r
247 /* The variable this task increments to show it is still running is passed in
\r
248 as the parameter. */
\r
249 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
251 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
253 /* Keep filling an array, keeping a running total of the values placed in the
\r
254 array. Then run through the array adding up all the values. If the two totals
\r
255 do not match, stop the check variable from incrementing. */
\r
261 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
263 pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
\r
264 dTotal1 += ( portDOUBLE ) xPosition + 5.5;
\r
267 #if configUSE_PREEMPTION == 0
\r
271 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
273 dTotal2 += pdArray[ xPosition ];
\r
276 dDifference = dTotal1 - dTotal2;
\r
277 if( fabs( dDifference ) > 0.001 )
\r
282 #if configUSE_PREEMPTION == 0
\r
286 if( sError == pdFALSE )
\r
288 /* If the calculation has always been correct then set set the check
\r
289 variable. The check variable will get set to pdFALSE each time
\r
290 xAreMathsTaskStillRunning() is executed. */
\r
291 ( *pusTaskCheckVariable ) = pdTRUE;
\r
295 /*-----------------------------------------------------------*/
\r
297 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
\r
299 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
300 volatile uint16_t *pusTaskCheckVariable;
\r
301 const size_t xArraySize = 10;
\r
303 short sError = pdFALSE;
\r
305 /* Some ports require that tasks that use a hardware floating point unit
\r
306 tell the kernel that they require a floating point context before any
\r
307 floating point instructions are executed. */
\r
308 portTASK_USES_FLOATING_POINT();
\r
310 /* The variable this task increments to show it is still running is passed in
\r
311 as the parameter. */
\r
312 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
314 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
316 /* Keep filling an array, keeping a running total of the values placed in the
\r
317 array. Then run through the array adding up all the values. If the two totals
\r
318 do not match, stop the check variable from incrementing. */
\r
324 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
326 pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
\r
327 dTotal1 += ( portDOUBLE ) xPosition * 12.123;
\r
330 #if configUSE_PREEMPTION == 0
\r
334 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
336 dTotal2 += pdArray[ xPosition ];
\r
339 dDifference = dTotal1 - dTotal2;
\r
340 if( fabs( dDifference ) > 0.001 )
\r
345 #if configUSE_PREEMPTION == 0
\r
349 if( sError == pdFALSE )
\r
351 /* If the calculation has always been correct then set set the check
\r
352 variable. The check variable will get set to pdFALSE each time
\r
353 xAreMathsTaskStillRunning() is executed. */
\r
354 ( *pusTaskCheckVariable ) = pdTRUE;
\r
358 /*-----------------------------------------------------------*/
\r
360 /* This is called to check that all the created tasks are still running. */
\r
361 BaseType_t xAreMathsTaskStillRunning( void )
\r
363 BaseType_t xReturn = pdPASS, xTask;
\r
365 /* Check the maths tasks are still running by ensuring their check variables
\r
366 have been set to pdPASS. */
\r
367 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
\r
369 if( usTaskCheck[ xTask ] != pdTRUE )
\r
371 /* The check has not been set so the associated task has either
\r
372 stalled or detected an error. */
\r
377 /* Reset the variable so it can be checked again the next time this
\r
378 function is executed. */
\r
379 usTaskCheck[ xTask ] = pdFALSE;
\r