2 FreeRTOS V8.2.3 - 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
83 /* Standard includes. */
\r
87 /* Scheduler include files. */
\r
88 #include "FreeRTOS.h"
\r
91 /* Demo program include files. */
\r
94 #ifndef mathSTACK_SIZE
\r
95 #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
\r
98 #define mathNUMBER_OF_TASKS ( 4 )
\r
100 /* Four tasks, each of which performs a different floating point calculation.
\r
101 Each of the four is created twice. */
\r
102 static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
\r
103 static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
\r
104 static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
\r
105 static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
\r
107 /* These variables are used to check that all the tasks are still running. If a
\r
108 task gets a calculation wrong it will stop setting its check variable. */
\r
109 static volatile uint16_t usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( uint16_t ) 0 };
\r
111 /*-----------------------------------------------------------*/
\r
113 void vStartMathTasks( UBaseType_t uxPriority )
\r
115 xTaskCreate( vCompetingMathTask1, "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
\r
116 xTaskCreate( vCompetingMathTask2, "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
\r
117 xTaskCreate( vCompetingMathTask3, "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
\r
118 xTaskCreate( vCompetingMathTask4, "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
\r
120 /*-----------------------------------------------------------*/
\r
122 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
\r
124 volatile portDOUBLE d1, d2, d3, d4;
\r
125 volatile uint16_t *pusTaskCheckVariable;
\r
126 volatile portDOUBLE dAnswer;
\r
127 short sError = pdFALSE;
\r
129 /* Some ports require that tasks that use a hardware floating point unit
\r
130 tell the kernel that they require a floating point context before any
\r
131 floating point instructions are executed. */
\r
132 portTASK_USES_FLOATING_POINT();
\r
138 dAnswer = ( d1 + d2 ) * d3;
\r
140 /* The variable this task increments to show it is still running is passed in
\r
141 as the parameter. */
\r
142 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
144 /* Keep performing a calculation and checking the result against a constant. */
\r
151 d4 = ( d1 + d2 ) * d3;
\r
153 #if configUSE_PREEMPTION == 0
\r
157 /* If the calculation does not match the expected constant, stop the
\r
158 increment of the check variable. */
\r
159 if( fabs( d4 - dAnswer ) > 0.001 )
\r
164 if( sError == pdFALSE )
\r
166 /* If the calculation has always been correct then set set the check
\r
167 variable. The check variable will get set to pdFALSE each time
\r
168 xAreMathsTaskStillRunning() is executed. */
\r
169 ( *pusTaskCheckVariable ) = pdTRUE;
\r
172 #if configUSE_PREEMPTION == 0
\r
178 /*-----------------------------------------------------------*/
\r
180 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
\r
182 volatile portDOUBLE d1, d2, d3, d4;
\r
183 volatile uint16_t *pusTaskCheckVariable;
\r
184 volatile portDOUBLE dAnswer;
\r
185 short sError = pdFALSE;
\r
187 /* Some ports require that tasks that use a hardware floating point unit
\r
188 tell the kernel that they require a floating point context before any
\r
189 floating point instructions are executed. */
\r
190 portTASK_USES_FLOATING_POINT();
\r
196 dAnswer = ( d1 / d2 ) * d3;
\r
199 /* The variable this task increments to show it is still running is passed in
\r
200 as the parameter. */
\r
201 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
203 /* Keep performing a calculation and checking the result against a constant. */
\r
210 d4 = ( d1 / d2 ) * d3;
\r
212 #if configUSE_PREEMPTION == 0
\r
216 /* If the calculation does not match the expected constant, stop the
\r
217 increment of the check variable. */
\r
218 if( fabs( d4 - dAnswer ) > 0.001 )
\r
223 if( sError == pdFALSE )
\r
225 /* If the calculation has always been correct then set set the check
\r
226 variable. The check variable will get set to pdFALSE each time
\r
227 xAreMathsTaskStillRunning() is executed. */
\r
228 ( *pusTaskCheckVariable ) = pdTRUE;
\r
231 #if configUSE_PREEMPTION == 0
\r
236 /*-----------------------------------------------------------*/
\r
238 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
\r
240 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
241 volatile uint16_t *pusTaskCheckVariable;
\r
242 const size_t xArraySize = 10;
\r
244 short sError = pdFALSE;
\r
246 /* Some ports require that tasks that use a hardware floating point unit
\r
247 tell the kernel that they require a floating point context before any
\r
248 floating point instructions are executed. */
\r
249 portTASK_USES_FLOATING_POINT();
\r
251 /* The variable this task increments to show it is still running is passed in
\r
252 as the parameter. */
\r
253 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
255 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
257 /* Keep filling an array, keeping a running total of the values placed in the
\r
258 array. Then run through the array adding up all the values. If the two totals
\r
259 do not match, stop the check variable from incrementing. */
\r
265 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
267 pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
\r
268 dTotal1 += ( portDOUBLE ) xPosition + 5.5;
\r
271 #if configUSE_PREEMPTION == 0
\r
275 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
277 dTotal2 += pdArray[ xPosition ];
\r
280 dDifference = dTotal1 - dTotal2;
\r
281 if( fabs( dDifference ) > 0.001 )
\r
286 #if configUSE_PREEMPTION == 0
\r
290 if( sError == pdFALSE )
\r
292 /* If the calculation has always been correct then set set the check
\r
293 variable. The check variable will get set to pdFALSE each time
\r
294 xAreMathsTaskStillRunning() is executed. */
\r
295 ( *pusTaskCheckVariable ) = pdTRUE;
\r
299 /*-----------------------------------------------------------*/
\r
301 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
\r
303 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
\r
304 volatile uint16_t *pusTaskCheckVariable;
\r
305 const size_t xArraySize = 10;
\r
307 short sError = pdFALSE;
\r
309 /* Some ports require that tasks that use a hardware floating point unit
\r
310 tell the kernel that they require a floating point context before any
\r
311 floating point instructions are executed. */
\r
312 portTASK_USES_FLOATING_POINT();
\r
314 /* The variable this task increments to show it is still running is passed in
\r
315 as the parameter. */
\r
316 pusTaskCheckVariable = ( uint16_t * ) pvParameters;
\r
318 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
\r
320 /* Keep filling an array, keeping a running total of the values placed in the
\r
321 array. Then run through the array adding up all the values. If the two totals
\r
322 do not match, stop the check variable from incrementing. */
\r
328 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
330 pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
\r
331 dTotal1 += ( portDOUBLE ) xPosition * 12.123;
\r
334 #if configUSE_PREEMPTION == 0
\r
338 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
\r
340 dTotal2 += pdArray[ xPosition ];
\r
343 dDifference = dTotal1 - dTotal2;
\r
344 if( fabs( dDifference ) > 0.001 )
\r
349 #if configUSE_PREEMPTION == 0
\r
353 if( sError == pdFALSE )
\r
355 /* If the calculation has always been correct then set set the check
\r
356 variable. The check variable will get set to pdFALSE each time
\r
357 xAreMathsTaskStillRunning() is executed. */
\r
358 ( *pusTaskCheckVariable ) = pdTRUE;
\r
362 /*-----------------------------------------------------------*/
\r
364 /* This is called to check that all the created tasks are still running. */
\r
365 BaseType_t xAreMathsTaskStillRunning( void )
\r
367 BaseType_t xReturn = pdPASS, xTask;
\r
369 /* Check the maths tasks are still running by ensuring their check variables
\r
370 have been set to pdPASS. */
\r
371 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
\r
373 if( usTaskCheck[ xTask ] != pdTRUE )
\r
375 /* The check has not been set so the associated task has either
\r
376 stalled or detected an error. */
\r
381 /* Reset the variable so it can be checked again the next time this
\r
382 function is executed. */
\r
383 usTaskCheck[ xTask ] = pdFALSE;
\r