static portTASK_FUNCTION( vCompetingMathTask4, pvParameters ) { volatile portDOUBLE *pdArray, dTotal1, dTotal2, dDifference; volatile uint16_t *pusTaskCheckVariable; const size_t xArraySize = 10; size_t xPosition; short sError = pdFALSE; /* Some ports require that tasks that use a hardware floating point unit tell the kernel that they require a floating point context before any floating point instructions are executed. */ portTASK_USES_FLOATING_POINT(); /* The variable this task increments to show it is still running is passed in as the parameter. */ pusTaskCheckVariable = ( uint16_t * ) pvParameters; pdArray = ( portDOUBLE * ) pvPortMalloc( xArraySize * sizeof( portDOUBLE ) ); /* Keep filling an array, keeping a running total of the values placed in the array. Then run through the array adding up all the values. If the two totals do not match, stop the check variable from incrementing. */ for( ;; ) { dTotal1 = 0.0; dTotal2 = 0.0; for( xPosition = 0; xPosition < xArraySize; xPosition++ ) { pdArray[ xPosition ] = ( portDOUBLE ) xPosition * 12.123; dTotal1 += ( portDOUBLE ) xPosition * 12.123; } #if configUSE_PREEMPTION == 0 taskYIELD(); #endif for( xPosition = 0; xPosition < xArraySize; xPosition++ ) { dTotal2 += pdArray[ xPosition ]; } dDifference = dTotal1 - dTotal2; if( fabs( dDifference ) > 0.001 ) { sError = pdTRUE; } #if configUSE_PREEMPTION == 0 taskYIELD(); #endif if( sError == pdFALSE ) { /* If the calculation has always been correct then set set the check variable. The check variable will get set to pdFALSE each time xAreMathsTaskStillRunning() is executed. */ ( *pusTaskCheckVariable ) = pdTRUE; } } }
static portTASK_FUNCTION( vCompetingMathTask1, pvParameters ) { volatile portDOUBLE d1, d2, d3, d4; volatile uint16_t *pusTaskCheckVariable; volatile portDOUBLE dAnswer; short sError = pdFALSE; /* Some ports require that tasks that use a hardware floating point unit tell the kernel that they require a floating point context before any floating point instructions are executed. */ portTASK_USES_FLOATING_POINT(); d1 = 123.4567; d2 = 2345.6789; d3 = -918.222; dAnswer = ( d1 + d2 ) * d3; /* The variable this task increments to show it is still running is passed in as the parameter. */ pusTaskCheckVariable = ( volatile uint16_t * ) pvParameters; /* Keep performing a calculation and checking the result against a constant. */ for(;;) { d1 = 123.4567; d2 = 2345.6789; d3 = -918.222; d4 = ( d1 + d2 ) * d3; #if configUSE_PREEMPTION == 0 taskYIELD(); #endif /* If the calculation does not match the expected constant, stop the increment of the check variable. */ if( fabs( d4 - dAnswer ) > 0.001 ) { sError = pdTRUE; } if( sError == pdFALSE ) { /* If the calculation has always been correct then set set the check variable. The check variable will get set to pdFALSE each time xAreMathsTaskStillRunning() is executed. */ ( *pusTaskCheckVariable ) = pdTRUE; } #if configUSE_PREEMPTION == 0 taskYIELD(); #endif } }
void sonar_driver_task(void *pParam){ int i = 0; portTASK_USES_FLOATING_POINT(); rpi_irq_enable(RPI_IRQ_ID_GPIO_0); while(1){ for(i = 0; i < MAX_SONARS; ++i){ runMeasureCycle(i); vTaskDelay(10); } } vTaskDelete(NULL); (void)pParam; }
static void prvRegTestTask2( void *pvParameters ) { extern void vRegTest2( volatile unsigned long * ); /* Avoid compiler warnings. */ ( void ) pvParameters; /* Must be called before any hardware floating point operations are performed to let the RTOS portable layer know that this task requires a floating point context. */ portTASK_USES_FLOATING_POINT(); /* Pass the address of the RegTest2 loop counter into the test function, which is necessarily implemented in assembler. */ vRegTest2( &ulRegTest2Cycles ); /* vRegTest1 should never exit! */ vTaskDelete( NULL ); }