2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
72 + The created tasks now include calls to tskYIELD(), allowing them to be used
\r
73 with the cooperative scheduler.
\r
77 * This does the same as flop. c, but uses variables of type long instead of
\r
80 * As with flop. c, the tasks created in this file are a good test of the
\r
81 * scheduler context switch mechanism. The processor has to access 32bit
\r
82 * variables in two or four chunks (depending on the processor). The low
\r
83 * priority of these tasks means there is a high probability that a context
\r
84 * switch will occur mid calculation. See the flop. c documentation for
\r
87 * \page IntegerC integer.c
\r
88 * \ingroup DemoFiles
\r
95 + The constants used in the calculations are larger to ensure the
\r
96 optimiser does not truncate them to 16 bits.
\r
101 /* Scheduler include files. */
\r
102 #include "FreeRTOS.h"
\r
106 /* Demo program include files. */
\r
107 #include "integer.h"
\r
109 #define intgSTACK_SIZE ( ( unsigned short ) 256 )
\r
110 #define intgNUMBER_OF_TASKS ( 8 )
\r
112 /* Four tasks, each of which performs a different calculation on four byte
\r
113 variables. Each of the four is created twice. */
\r
114 static void vCompeteingIntMathTask1( void *pvParameters );
\r
115 static void vCompeteingIntMathTask2( void *pvParameters );
\r
116 static void vCompeteingIntMathTask3( void *pvParameters );
\r
117 static void vCompeteingIntMathTask4( void *pvParameters );
\r
119 /* These variables are used to check that all the tasks are still running. If a
\r
120 task gets a calculation wrong it will stop incrementing its check variable. */
\r
121 static volatile unsigned short usTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
\r
122 /*-----------------------------------------------------------*/
\r
124 void vStartIntegerMathTasks( unsigned portBASE_TYPE uxPriority )
\r
126 xTaskCreate( vCompeteingIntMathTask1, "IntMath1", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
\r
127 xTaskCreate( vCompeteingIntMathTask2, "IntMath2", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
\r
128 xTaskCreate( vCompeteingIntMathTask3, "IntMath3", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
\r
129 xTaskCreate( vCompeteingIntMathTask4, "IntMath4", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
\r
130 xTaskCreate( vCompeteingIntMathTask1, "IntMath5", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
\r
131 xTaskCreate( vCompeteingIntMathTask2, "IntMath6", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
\r
132 xTaskCreate( vCompeteingIntMathTask3, "IntMath7", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
\r
133 xTaskCreate( vCompeteingIntMathTask4, "IntMath8", intgSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
\r
135 /*-----------------------------------------------------------*/
\r
137 static void vCompeteingIntMathTask1( void *pvParameters )
\r
139 long l1, l2, l3, l4;
\r
140 short sError = pdFALSE;
\r
141 volatile unsigned short *pusTaskCheckVariable;
\r
142 const long lAnswer = ( ( long ) 74565L + ( long ) 1234567L ) * ( long ) -918L;
\r
143 const char * const pcTaskStartMsg = "Integer math task 1 started.\r\n";
\r
144 const char * const pcTaskFailMsg = "Integer math task 1 failed.\r\n";
\r
146 /* Queue a message for printing to say the task has started. */
\r
147 vPrintDisplayMessage( &pcTaskStartMsg );
\r
149 /* The variable this task increments to show it is still running is passed in
\r
150 as the parameter. */
\r
151 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
153 /* Keep performing a calculation and checking the result against a constant. */
\r
156 l1 = ( long ) 74565L;
\r
157 l2 = ( long ) 1234567L;
\r
158 l3 = ( long ) -918L;
\r
160 l4 = ( l1 + l2 ) * l3;
\r
164 /* If the calculation does not match the expected constant, stop the
\r
165 increment of the check variable. */
\r
166 if( l4 != lAnswer )
\r
168 vPrintDisplayMessage( &pcTaskFailMsg );
\r
172 if( sError == pdFALSE )
\r
174 /* If the calculation has always been correct, increment the check
\r
175 variable so we know this task is still running okay. */
\r
176 ( *pusTaskCheckVariable )++;
\r
180 /*-----------------------------------------------------------*/
\r
182 static void vCompeteingIntMathTask2( void *pvParameters )
\r
184 long l1, l2, l3, l4;
\r
185 short sError = pdFALSE;
\r
186 volatile unsigned short *pusTaskCheckVariable;
\r
187 const long lAnswer = ( ( long ) -389000L / ( long ) 329999L ) * ( long ) -89L;
\r
188 const char * const pcTaskStartMsg = "Integer math task 2 started.\r\n";
\r
189 const char * const pcTaskFailMsg = "Integer math task 2 failed.\r\n";
\r
191 /* Queue a message for printing to say the task has started. */
\r
192 vPrintDisplayMessage( &pcTaskStartMsg );
\r
194 /* The variable this task increments to show it is still running is passed in
\r
195 as the parameter. */
\r
196 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
198 /* Keep performing a calculation and checking the result against a constant. */
\r
205 l4 = ( l1 / l2 ) * l3;
\r
209 /* If the calculation does not match the expected constant, stop the
\r
210 increment of the check variable. */
\r
211 if( l4 != lAnswer )
\r
213 vPrintDisplayMessage( &pcTaskFailMsg );
\r
217 if( sError == pdFALSE )
\r
219 /* If the calculation has always been correct, increment the check
\r
220 variable so we know this task is still running okay. */
\r
221 ( *pusTaskCheckVariable )++;
\r
225 /*-----------------------------------------------------------*/
\r
227 static void vCompeteingIntMathTask3( void *pvParameters )
\r
229 long *plArray, lTotal1, lTotal2;
\r
230 short sError = pdFALSE;
\r
231 volatile unsigned short *pusTaskCheckVariable;
\r
232 const unsigned short usArraySize = ( unsigned short ) 250;
\r
233 unsigned short usPosition;
\r
234 const char * const pcTaskStartMsg = "Integer math task 3 started.\r\n";
\r
235 const char * const pcTaskFailMsg = "Integer math task 3 failed.\r\n";
\r
237 /* Queue a message for printing to say the task has started. */
\r
238 vPrintDisplayMessage( &pcTaskStartMsg );
\r
240 /* The variable this task increments to show it is still running is passed in
\r
241 as the parameter. */
\r
242 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
244 /* Create the array we are going to use for our check calculation. */
\r
245 plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
\r
247 /* Keep filling the array, keeping a running total of the values placed in the
\r
248 array. Then run through the array adding up all the values. If the two totals
\r
249 do not match, stop the check variable from incrementing. */
\r
252 lTotal1 = ( long ) 0;
\r
253 lTotal2 = ( long ) 0;
\r
255 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
257 plArray[ usPosition ] = ( long ) usPosition + ( long ) 5;
\r
258 lTotal1 += ( long ) usPosition + ( long ) 5;
\r
263 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
265 lTotal2 += plArray[ usPosition ];
\r
268 if( lTotal1 != lTotal2 )
\r
270 vPrintDisplayMessage( &pcTaskFailMsg );
\r
276 if( sError == pdFALSE )
\r
278 /* If the calculation has always been correct, increment the check
\r
279 variable so we know this task is still running okay. */
\r
280 ( *pusTaskCheckVariable )++;
\r
284 /*-----------------------------------------------------------*/
\r
286 static void vCompeteingIntMathTask4( void *pvParameters )
\r
288 long *plArray, lTotal1, lTotal2;
\r
289 short sError = pdFALSE;
\r
290 volatile unsigned short *pusTaskCheckVariable;
\r
291 const unsigned short usArraySize = 250;
\r
292 unsigned short usPosition;
\r
293 const char * const pcTaskStartMsg = "Integer math task 4 started.\r\n";
\r
294 const char * const pcTaskFailMsg = "Integer math task 4 failed.\r\n";
\r
296 /* Queue a message for printing to say the task has started. */
\r
297 vPrintDisplayMessage( &pcTaskStartMsg );
\r
299 /* The variable this task increments to show it is still running is passed in
\r
300 as the parameter. */
\r
301 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
\r
303 /* Create the array we are going to use for our check calculation. */
\r
304 plArray = ( long * ) pvPortMalloc( ( size_t ) 250 * sizeof( long ) );
\r
306 /* Keep filling the array, keeping a running total of the values placed in the
\r
307 array. Then run through the array adding up all the values. If the two totals
\r
308 do not match, stop the check variable from incrementing. */
\r
311 lTotal1 = ( long ) 0;
\r
312 lTotal2 = ( long ) 0;
\r
314 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
316 plArray[ usPosition ] = ( long ) usPosition * ( long ) 12;
\r
317 lTotal1 += ( long ) usPosition * ( long ) 12;
\r
322 for( usPosition = 0; usPosition < usArraySize; usPosition++ )
\r
324 lTotal2 += plArray[ usPosition ];
\r
328 if( lTotal1 != lTotal2 )
\r
330 vPrintDisplayMessage( &pcTaskFailMsg );
\r
336 if( sError == pdFALSE )
\r
338 /* If the calculation has always been correct, increment the check
\r
339 variable so we know this task is still running okay. */
\r
340 ( *pusTaskCheckVariable )++;
\r
344 /*-----------------------------------------------------------*/
\r
346 /* This is called to check that all the created tasks are still running. */
\r
347 portBASE_TYPE xAreIntegerMathsTaskStillRunning( void )
\r
349 /* Keep a history of the check variables so we know if they have been incremented
\r
350 since the last call. */
\r
351 static unsigned short usLastTaskCheck[ intgNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
\r
352 portBASE_TYPE xReturn = pdTRUE, xTask;
\r
354 /* Check the maths tasks are still running by ensuring their check variables
\r
355 are still incrementing. */
\r
356 for( xTask = 0; xTask < intgNUMBER_OF_TASKS; xTask++ )
\r
358 if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
\r
360 /* The check has not incremented so an error exists. */
\r
364 usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
\r