00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include <stdlib.h>
00068 #include <math.h>
00069
00070
00071 #include "FreeRTOS.h"
00072 #include "task.h"
00073
00074
00075 #include "flop.h"
00076
00077 #define mathSTACK_SIZE configMINIMAL_STACK_SIZE
00078 #define mathNUMBER_OF_TASKS ( 8 )
00079
00080
00081
00082 static portTASK_FUNCTION_PROTO( vCompetingMathTask1, pvParameters );
00083 static portTASK_FUNCTION_PROTO( vCompetingMathTask2, pvParameters );
00084 static portTASK_FUNCTION_PROTO( vCompetingMathTask3, pvParameters );
00085 static portTASK_FUNCTION_PROTO( vCompetingMathTask4, pvParameters );
00086
00087
00088
00089
00090 static volatile unsigned short usTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
00091
00092
00093
00094 void vStartMathTasks( unsigned portBASE_TYPE uxPriority )
00095 {
00096 xTaskCreate( vCompetingMathTask1, ( signed char * ) "Math1", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 0 ] ), uxPriority, NULL );
00097 xTaskCreate( vCompetingMathTask2, ( signed char * ) "Math2", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 1 ] ), uxPriority, NULL );
00098 xTaskCreate( vCompetingMathTask3, ( signed char * ) "Math3", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 2 ] ), uxPriority, NULL );
00099 xTaskCreate( vCompetingMathTask4, ( signed char * ) "Math4", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 3 ] ), uxPriority, NULL );
00100 xTaskCreate( vCompetingMathTask1, ( signed char * ) "Math5", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 4 ] ), uxPriority, NULL );
00101 xTaskCreate( vCompetingMathTask2, ( signed char * ) "Math6", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 5 ] ), uxPriority, NULL );
00102 xTaskCreate( vCompetingMathTask3, ( signed char * ) "Math7", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 6 ] ), uxPriority, NULL );
00103 xTaskCreate( vCompetingMathTask4, ( signed char * ) "Math8", mathSTACK_SIZE, ( void * ) &( usTaskCheck[ 7 ] ), uxPriority, NULL );
00104 }
00105
00106
00107 static portTASK_FUNCTION( vCompetingMathTask1, pvParameters )
00108 {
00109 volatile portDOUBLE d1, d2, d3, d4;
00110 volatile unsigned short *pusTaskCheckVariable;
00111 volatile portDOUBLE dAnswer;
00112 short sError = pdFALSE;
00113
00114 d1 = 123.4567;
00115 d2 = 2345.6789;
00116 d3 = -918.222;
00117
00118 dAnswer = ( d1 + d2 ) * d3;
00119
00120
00121
00122 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
00123
00124
00125 for(;;)
00126 {
00127 d1 = 123.4567;
00128 d2 = 2345.6789;
00129 d3 = -918.222;
00130
00131 d4 = ( d1 + d2 ) * d3;
00132
00133 #if configUSE_PREEMPTION == 0
00134 taskYIELD();
00135 #endif
00136
00137
00138
00139 if( fabs( d4 - dAnswer ) > 0.001 )
00140 {
00141 sError = pdTRUE;
00142 }
00143
00144 if( sError == pdFALSE )
00145 {
00146
00147
00148 ( *pusTaskCheckVariable )++;
00149 }
00150
00151 #if configUSE_PREEMPTION == 0
00152 taskYIELD();
00153 #endif
00154
00155 }
00156 }
00157
00158
00159 static portTASK_FUNCTION( vCompetingMathTask2, pvParameters )
00160 {
00161 volatile portDOUBLE d1, d2, d3, d4;
00162 volatile unsigned short *pusTaskCheckVariable;
00163 volatile portDOUBLE dAnswer;
00164 short sError = pdFALSE;
00165
00166 d1 = -389.38;
00167 d2 = 32498.2;
00168 d3 = -2.0001;
00169
00170 dAnswer = ( d1 / d2 ) * d3;
00171
00172
00173
00174
00175 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
00176
00177
00178 for( ;; )
00179 {
00180 d1 = -389.38;
00181 d2 = 32498.2;
00182 d3 = -2.0001;
00183
00184 d4 = ( d1 / d2 ) * d3;
00185
00186 #if configUSE_PREEMPTION == 0
00187 taskYIELD();
00188 #endif
00189
00190
00191
00192 if( fabs( d4 - dAnswer ) > 0.001 )
00193 {
00194 sError = pdTRUE;
00195 }
00196
00197 if( sError == pdFALSE )
00198 {
00199
00200
00201
00202 ( *pusTaskCheckVariable )++;
00203 }
00204
00205 #if configUSE_PREEMPTION == 0
00206 taskYIELD();
00207 #endif
00208 }
00209 }
00210
00211
00212 static portTASK_FUNCTION( vCompetingMathTask3, pvParameters )
00213 {
00214 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
00215 volatile unsigned short *pusTaskCheckVariable;
00216 const size_t xArraySize = 10;
00217 size_t xPosition;
00218 short sError = pdFALSE;
00219
00220
00221
00222 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
00223
00224 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
00225
00226
00227
00228
00229 for( ;; )
00230 {
00231 dTotal1 = 0.0;
00232 dTotal2 = 0.0;
00233
00234 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
00235 {
00236 pdArray[ xPosition ] = ( portDOUBLE ) xPosition + 5.5;
00237 dTotal1 += ( portDOUBLE ) xPosition + 5.5;
00238 }
00239
00240 #if configUSE_PREEMPTION == 0
00241 taskYIELD();
00242 #endif
00243
00244 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
00245 {
00246 dTotal2 += pdArray[ xPosition ];
00247 }
00248
00249 dDifference = dTotal1 - dTotal2;
00250 if( fabs( dDifference ) > 0.001 )
00251 {
00252 sError = pdTRUE;
00253 }
00254
00255 #if configUSE_PREEMPTION == 0
00256 taskYIELD();
00257 #endif
00258
00259 if( sError == pdFALSE )
00260 {
00261
00262
00263 ( *pusTaskCheckVariable )++;
00264 }
00265 }
00266 }
00267
00268
00269 static portTASK_FUNCTION( vCompetingMathTask4, pvParameters )
00270 {
00271 volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference;
00272 volatile unsigned short *pusTaskCheckVariable;
00273 const size_t xArraySize = 10;
00274 size_t xPosition;
00275 short sError = pdFALSE;
00276
00277
00278
00279 pusTaskCheckVariable = ( unsigned short * ) pvParameters;
00280
00281 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) );
00282
00283
00284
00285
00286 for( ;; )
00287 {
00288 dTotal1 = 0.0;
00289 dTotal2 = 0.0;
00290
00291 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
00292 {
00293 pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123;
00294 dTotal1 += ( portDOUBLE ) xPosition * 12.123;
00295 }
00296
00297 #if configUSE_PREEMPTION == 0
00298 taskYIELD();
00299 #endif
00300
00301 for( xPosition = 0; xPosition < xArraySize; xPosition++ )
00302 {
00303 dTotal2 += pdArray[ xPosition ];
00304 }
00305
00306 dDifference = dTotal1 - dTotal2;
00307 if( fabs( dDifference ) > 0.001 )
00308 {
00309 sError = pdTRUE;
00310 }
00311
00312 #if configUSE_PREEMPTION == 0
00313 taskYIELD();
00314 #endif
00315
00316 if( sError == pdFALSE )
00317 {
00318
00319
00320 ( *pusTaskCheckVariable )++;
00321 }
00322 }
00323 }
00324
00325
00326
00327 portBASE_TYPE xAreMathsTaskStillRunning( void )
00328 {
00329
00330
00331 static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 };
00332 portBASE_TYPE xReturn = pdTRUE, xTask;
00333
00334
00335
00336 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ )
00337 {
00338 if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] )
00339 {
00340
00341 xReturn = pdFALSE;
00342 }
00343
00344 usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ];
00345 }
00346
00347 return xReturn;
00348 }
00349
00350
00351