2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
68 + The created tasks now include calls to tskYIELD(), allowing them to be used
\r
69 with the cooperative scheduler.
\r
73 * This does the same as flop. c, but uses variables of type long instead of
\r
76 * As with flop. c, the tasks created in this file are a good test of the
\r
77 * scheduler context switch mechanism. The processor has to access 32bit
\r
78 * variables in two or four chunks (depending on the processor). The low
\r
79 * priority of these tasks means there is a high probability that a context
\r
80 * switch will occur mid calculation. See the flop. c documentation for
\r
83 * \page IntegerC integer.c
\r
84 * \ingroup DemoFiles
\r
91 + The constants used in the calculations are larger to ensure the
\r
92 optimiser does not truncate them to 16 bits.
\r
97 /* Scheduler include files. */
\r
98 #include "FreeRTOS.h"
\r
102 /* Demo program include files. */
\r
103 #include "integer.h"
\r
105 #define intgSTACK_SIZE ( ( unsigned short ) 256 )
\r
106 #define intgNUMBER_OF_TASKS ( 8 )
\r
108 /* Four tasks, each of which performs a different calculation on four byte
\r
109 variables. Each of the four is created twice. */
\r
110 static void vCompeteingIntMathTask1( void *pvParameters );
\r
111 static void vCompeteingIntMathTask2( void *pvParameters );
\r
112 static void vCompeteingIntMathTask3( void *pvParameters );
\r
113 static void vCompeteingIntMathTask4( void *pvParameters );
\r
115 /* These variables are used to check that all the tasks are still running. If a
\r
116 task gets a calculation wrong it will stop incrementing its check variable. */
\r
117 static volatile unsigned short usTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
\r
118 /*-----------------------------------------------------------*/
\r
120 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
122 xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
\r
123 xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
\r
124 xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
\r
125 xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
\r
126 xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
\r
127 xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
\r
128 xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
\r
129 xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
\r
131 /*-----------------------------------------------------------*/
\r
133 static void vCompeteingIntMathTask1( void *pvParameters )
\r
135 long l1, l2, l3, l4;
\r
136 short sError = pdFALSE;
\r
137 volatile unsigned short *pusTaskCheckVariable;
\r
138 const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
\r
139 const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
\r
140 const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
\r
142 /* Queue a message for printing to say the task has started. */
\r
143 vPrintDisplayMessage( &pcTaskStartMsg );
\r
145 /* The variable this task increments to show it is still running is passed in
\r
146 as the parameter. */
\r
147 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
149 /* Keep performing a calculation and checking the result against a constant. */
\r
152 l1 = ( long ) 74565L;
\r
153 l2 = ( long ) 1234567L;
\r
154 l3 = ( long ) -918L;
\r
156 l4 = ( l1 + l2 ) * l3;
\r
160 /* If the calculation does not match the expected constant, stop the
\r
161 increment of the check variable. */
\r
162 if( l4 != lAnswer )
\r
164 vPrintDisplayMessage( &pcTaskFailMsg );
\r
168 if( sError == pdFALSE )
\r
170 /* If the calculation has always been correct, increment the check
\r
171 variable so we know this task is still running okay. */
\r
172 ( *pusTaskCheckVariable )++;
\r
176 /*-----------------------------------------------------------*/
\r
178 static void vCompeteingIntMathTask2( void *pvParameters )
\r
180 long l1, l2, l3, l4;
\r
181 short sError = pdFALSE;
\r
182 volatile unsigned short *pusTaskCheckVariable;
\r
183 const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
\r
184 const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
\r
185 const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
\r
187 /* Queue a message for printing to say the task has started. */
\r
188 vPrintDisplayMessage( &pcTaskStartMsg );
\r
190 /* The variable this task increments to show it is still running is passed in
\r
191 as the parameter. */
\r
192 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
194 /* Keep performing a calculation and checking the result against a constant. */
\r
201 l4 = ( l1 / l2 ) * l3;
\r
205 /* If the calculation does not match the expected constant, stop the
\r
206 increment of the check variable. */
\r
207 if( l4 != lAnswer )
\r
209 vPrintDisplayMessage( &pcTaskFailMsg );
\r
213 if( sError == pdFALSE )
\r
215 /* If the calculation has always been correct, increment the check
\r
216 variable so we know this task is still running okay. */
\r
217 ( *pusTaskCheckVariable )++;
\r
221 /*-----------------------------------------------------------*/
\r
223 static void vCompeteingIntMathTask3( void *pvParameters )
\r
225 long *plArray, lTotal1, lTotal2;
\r
226 short sError = pdFALSE;
\r
227 volatile unsigned short *pusTaskCheckVariable;
\r
228 const unsigned short usArraySize = ( unsigned short ) 250;
\r
229 unsigned short usPosition;
\r
230 const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
\r
231 const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
\r
233 /* Queue a message for printing to say the task has started. */
\r
234 vPrintDisplayMessage( &pcTaskStartMsg );
\r
236 /* The variable this task increments to show it is still running is passed in
\r
237 as the parameter. */
\r
238 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
240 /* Create the array we are going to use for our check calculation. */
\r
241 plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
\r
243 /* Keep filling the array, keeping a running total of the values placed in the
\r
244 array. Then run through the array adding up all the values. If the two totals
\r
245 do not match, stop the check variable from incrementing. */
\r
248 lTotal1 = ( long ) 0;
\r
249 lTotal2 = ( long ) 0;
\r
251 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
253 plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
\r
254 lTotal1 += ( long ) usPosition + ( long ) 5;
\r
259 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
261 lTotal2 += plArray[ usPosition ];
\r
264 if( lTotal1 != lTotal2 )
\r
266 vPrintDisplayMessage( &pcTaskFailMsg );
\r
272 if( sError == pdFALSE )
\r
274 /* If the calculation has always been correct, increment the check
\r
275 variable so we know this task is still running okay. */
\r
276 ( *pusTaskCheckVariable )++;
\r
280 /*-----------------------------------------------------------*/
\r
282 static void vCompeteingIntMathTask4( void *pvParameters )
\r
284 long *plArray, lTotal1, lTotal2;
\r
285 short sError = pdFALSE;
\r
286 volatile unsigned short *pusTaskCheckVariable;
\r
287 const unsigned short usArraySize = 250;
\r
288 unsigned short usPosition;
\r
289 const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
\r
290 const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
\r
292 /* Queue a message for printing to say the task has started. */
\r
293 vPrintDisplayMessage( &pcTaskStartMsg );
\r
295 /* The variable this task increments to show it is still running is passed in
\r
296 as the parameter. */
\r
297 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
299 /* Create the array we are going to use for our check calculation. */
\r
300 plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
\r
302 /* Keep filling the array, keeping a running total of the values placed in the
\r
303 array. Then run through the array adding up all the values. If the two totals
\r
304 do not match, stop the check variable from incrementing. */
\r
307 lTotal1 = ( long ) 0;
\r
308 lTotal2 = ( long ) 0;
\r
310 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
312 plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
\r
313 lTotal1 += ( long ) usPosition * ( long ) 12;
\r
318 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
320 lTotal2 += plArray[ usPosition ];
\r
324 if( lTotal1 != lTotal2 )
\r
326 vPrintDisplayMessage( &pcTaskFailMsg );
\r
332 if( sError == pdFALSE )
\r
334 /* If the calculation has always been correct, increment the check
\r
335 variable so we know this task is still running okay. */
\r
336 ( *pusTaskCheckVariable )++;
\r
340 /*-----------------------------------------------------------*/
\r
342 /* This is called to check that all the created tasks are still running. */
\r
343 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
345 /* Keep a history of the check variables so we know if they have been incremented
\r
346 since the last call. */
\r
347 static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
\r
348 portBASE_TYPE xReturn = pdTRUE, xTask;
\r
350 /* Check the maths tasks are still running by ensuring their check variables
\r
351 are still incrementing. */
\r
352 for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
\r
354 if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
\r
356 /* The check has not incremented so an error exists. */
\r
360 usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
\r