#include <stdlib.h>
#include <math.h>
#include "FreeRTOS.h"
#include "task.h"
#include "flop.h"
Go to the source code of this file.
Defines | |
#define | mathNUMBER_OF_TASKS ( 8 ) |
#define | mathSTACK_SIZE configMINIMAL_STACK_SIZE |
Functions | |
static | portTASK_FUNCTION (vCompetingMathTask4, pvParameters) |
static | portTASK_FUNCTION (vCompetingMathTask3, pvParameters) |
static | portTASK_FUNCTION (vCompetingMathTask2, pvParameters) |
static | portTASK_FUNCTION (vCompetingMathTask1, pvParameters) |
static | portTASK_FUNCTION_PROTO (vCompetingMathTask4, pvParameters) |
static | portTASK_FUNCTION_PROTO (vCompetingMathTask3, pvParameters) |
static | portTASK_FUNCTION_PROTO (vCompetingMathTask2, pvParameters) |
static | portTASK_FUNCTION_PROTO (vCompetingMathTask1, pvParameters) |
void | vStartMathTasks (unsigned portBASE_TYPE uxPriority) |
portBASE_TYPE | xAreMathsTaskStillRunning (void) |
Variables | |
static volatile unsigned short | usTaskCheck [mathNUMBER_OF_TASKS] = { ( unsigned short ) 0 } |
#define mathNUMBER_OF_TASKS ( 8 ) |
#define mathSTACK_SIZE configMINIMAL_STACK_SIZE |
static portTASK_FUNCTION | ( | vCompetingMathTask4 | , | |
pvParameters | ||||
) | [static] |
Definition at line 269 of file flop.c.
References pdFALSE, pdTRUE, portDOUBLE, pvPortMalloc(), and taskYIELD.
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 /* The variable this task increments to show it is still running is passed in 00278 as the parameter. */ 00279 pusTaskCheckVariable = ( unsigned short * ) pvParameters; 00280 00281 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) ); 00282 00283 /* Keep filling an array, keeping a running total of the values placed in the 00284 array. Then run through the array adding up all the values. If the two totals 00285 do not match, stop the check variable from incrementing. */ 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 /* If the calculation has always been correct, increment the check 00319 variable so we know this task is still running okay. */ 00320 ( *pusTaskCheckVariable )++; 00321 } 00322 } 00323 }
static portTASK_FUNCTION | ( | vCompetingMathTask3 | , | |
pvParameters | ||||
) | [static] |
Definition at line 212 of file flop.c.
References pdFALSE, pdTRUE, portDOUBLE, pvPortMalloc(), and taskYIELD.
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 /* The variable this task increments to show it is still running is passed in 00221 as the parameter. */ 00222 pusTaskCheckVariable = ( unsigned short * ) pvParameters; 00223 00224 pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) ); 00225 00226 /* Keep filling an array, keeping a running total of the values placed in the 00227 array. Then run through the array adding up all the values. If the two totals 00228 do not match, stop the check variable from incrementing. */ 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 /* If the calculation has always been correct, increment the check 00262 variable so we know this task is still running okay. */ 00263 ( *pusTaskCheckVariable )++; 00264 } 00265 } 00266 }
static portTASK_FUNCTION | ( | vCompetingMathTask2 | , | |
pvParameters | ||||
) | [static] |
Definition at line 159 of file flop.c.
References pdFALSE, pdTRUE, portDOUBLE, and taskYIELD.
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 /* The variable this task increments to show it is still running is passed in 00174 as the parameter. */ 00175 pusTaskCheckVariable = ( unsigned short * ) pvParameters; 00176 00177 /* Keep performing a calculation and checking the result against a constant. */ 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 /* If the calculation does not match the expected constant, stop the 00191 increment of the check variable. */ 00192 if( fabs( d4 - dAnswer ) > 0.001 ) 00193 { 00194 sError = pdTRUE; 00195 } 00196 00197 if( sError == pdFALSE ) 00198 { 00199 /* If the calculation has always been correct, increment the check 00200 variable so we know 00201 this task is still running okay. */ 00202 ( *pusTaskCheckVariable )++; 00203 } 00204 00205 #if configUSE_PREEMPTION == 0 00206 taskYIELD(); 00207 #endif 00208 } 00209 }
static portTASK_FUNCTION | ( | vCompetingMathTask1 | , | |
pvParameters | ||||
) | [static] |
Definition at line 107 of file flop.c.
References pdFALSE, pdTRUE, portDOUBLE, and taskYIELD.
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 /* The variable this task increments to show it is still running is passed in 00121 as the parameter. */ 00122 pusTaskCheckVariable = ( unsigned short * ) pvParameters; 00123 00124 /* Keep performing a calculation and checking the result against a constant. */ 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 /* If the calculation does not match the expected constant, stop the 00138 increment of the check variable. */ 00139 if( fabs( d4 - dAnswer ) > 0.001 ) 00140 { 00141 sError = pdTRUE; 00142 } 00143 00144 if( sError == pdFALSE ) 00145 { 00146 /* If the calculation has always been correct, increment the check 00147 variable so we know this task is still running okay. */ 00148 ( *pusTaskCheckVariable )++; 00149 } 00150 00151 #if configUSE_PREEMPTION == 0 00152 taskYIELD(); 00153 #endif 00154 00155 } 00156 }
static portTASK_FUNCTION_PROTO | ( | vCompetingMathTask4 | , | |
pvParameters | ||||
) | [static] |
static portTASK_FUNCTION_PROTO | ( | vCompetingMathTask3 | , | |
pvParameters | ||||
) | [static] |
static portTASK_FUNCTION_PROTO | ( | vCompetingMathTask2 | , | |
pvParameters | ||||
) | [static] |
static portTASK_FUNCTION_PROTO | ( | vCompetingMathTask1 | , | |
pvParameters | ||||
) | [static] |
void vStartMathTasks | ( | unsigned portBASE_TYPE | uxPriority | ) |
Definition at line 94 of file flop.c.
References mathSTACK_SIZE, usTaskCheck, and xTaskCreate.
Referenced by main().
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 }
portBASE_TYPE xAreMathsTaskStillRunning | ( | void | ) |
Definition at line 327 of file flop.c.
References mathNUMBER_OF_TASKS, pdFALSE, pdTRUE, portBASE_TYPE, and usTaskCheck.
Referenced by prvCheckOtherTasksAreStillRunning().
00328 { 00329 /* Keep a history of the check variables so we know if they have been incremented 00330 since the last call. */ 00331 static unsigned short usLastTaskCheck[ mathNUMBER_OF_TASKS ] = { ( unsigned short ) 0 }; 00332 portBASE_TYPE xReturn = pdTRUE, xTask; 00333 00334 /* Check the maths tasks are still running by ensuring their check variables 00335 are still incrementing. */ 00336 for( xTask = 0; xTask < mathNUMBER_OF_TASKS; xTask++ ) 00337 { 00338 if( usTaskCheck[ xTask ] == usLastTaskCheck[ xTask ] ) 00339 { 00340 /* The check has not incremented so an error exists. */ 00341 xReturn = pdFALSE; 00342 } 00343 00344 usLastTaskCheck[ xTask ] = usTaskCheck[ xTask ]; 00345 } 00346 00347 return xReturn; 00348 }
volatile unsigned short usTaskCheck[mathNUMBER_OF_TASKS] = { ( unsigned short ) 0 } [static] |
Definition at line 90 of file flop.c.
Referenced by vStartMathTasks(), and xAreMathsTaskStillRunning().