/**** TASKS ****/ void vTaskADC_VoltPwr(void * pvParameters) { SENSOR_t SENSOR_Struct; vSENSOR_initStruct(&SENSOR_Struct); /* Local variables. */ static uint16_t v_divider = 4400; // resistor relation value of the voltage divider /* * ADC_CONVERTED_VALUES[0] is related to Power Supply voltage measurement * ADC_CONVERTED_VALUES[1] is related to IR Sensor voltage measurement */ static uint32_t moving_average = 0; static uint16_t buffor[21] = {0}; static uint8_t i = 0, k = 0; for(;;){ if( xSemaphoreTake(xSemaphoreADC_VoltPwr, 100 ) == pdTRUE) { /*** Moving average ***/ buffor[i] = ADC_CONVERTED_VALUES[0]; if( i >= 19 ) // collecting buffor { uint8_t j = 0; for( j = 0; j < 20; j++ ){ buffor[j] = buffor[j+1]; } } else i++; for( moving_average = 0, k = 0; k < 20; k++ ) //summing up the buffor { moving_average += buffor[k]; } moving_average /= 20; //calculating average of the buffor moving_average *= v_divider; /*** Moving average ***/ SENSOR_Struct.PS_Voltage = moving_average*3.3/4095; SENSOR_Struct.IR_Sensor = ADC_CONVERTED_VALUES[1]; xQueueSend(xQueueUART_1xSENSOR_t, &SENSOR_Struct, 0); } } }
/*----------------------------------------------------------- * @brief Task Name : vTaskUART_NAVIsns * @brief Description : This task is responsible for sending SENSOR data frames to the * NAVIGATION & FAULT INJECTION BOARD by managing a semaphore */ void vTaskUART_NAVIsns(void * pvParameters) { /* Local variables. */ portTickType xLastFlashTime; xLastFlashTime = xTaskGetTickCount(); SENSOR_t SENSOR_Struct; vSENSOR_initStruct(&SENSOR_Struct); /* 10 Hz task [100 ms delay] */ for(;;){ vTaskDelayUntil( &xLastFlashTime, 100 ); /* Receive IMU_Structure */ xQueueReceive(xQueueUART_1xSENSOR_t, &SENSOR_Struct, 100); /* Sharing xSemaphoreUART_NAVITX MUTEX with vTaskUART_NAVIimu task */ if( xSemaphoreTake(xSemaphoreUART_NAVITX, 0)) { /* Clear buffer before updating it */ vUART_ClearBuffer(UART_NaviBufferSEND); /* Send data to the Navigation & Fault injection board */ char tmp_buffer[NAVI_BUFFER_LENGTH] = {0}; sprintf(tmp_buffer, "%c,4,%i,%i,0,0,*", NAVI_DF_CHAR, SENSOR_Struct.PS_Voltage, SENSOR_Struct.IR_Sensor); // Add calculated CRC to this string. sprintf(GV_bufferNAVIsend, "%s%i\n\r", tmp_buffer, ucUART_calculateCRC(tmp_buffer, NAVI_DF_CHAR, NAVI_BUFFER_LENGTH) ); vUART_puts(USART2, GV_bufferNAVIsend); /* Allow putting another IMU_Structure to the xQueueUART_1xIMU_t */ xSemaphoreGive(xSemaphoreUART_NAVITX); } } /* sprintf(GV_bufferNAVIsend, "a%i\nb%i\n", SENSOR_Struct.PS_Voltage, SENSOR_Struct.IR_Sensor); vUART_puts(USART2, GV_bufferNAVIsend); // QUADROPLOT DATA FRAME*/ }
/**** TASKS ****/ void vTaskADC_VoltPwr(void * pvParameters) { SENSOR_t SENSOR_Struct; vSENSOR_initStruct(&SENSOR_Struct); /* Local variables. */ static uint16_t v_divider = 4400; // resistor relation value of the voltage divider /* * ADC_CONVERTED_VALUES[0] is related to Power Supply voltage measurement * ADC_CONVERTED_VALUES[1] is related to IR Sensor voltage measurement */ for(;;){ if( xSemaphoreTake(xSemaphoreADC_VoltPwr, 100 ) == pdTRUE) { uint32_t tmp = ADC_CONVERTED_VALUES[0] * v_divider; SENSOR_Struct.PS_Voltage = tmp*3.3/4095; SENSOR_Struct.IR_Sensor = ADC_CONVERTED_VALUES[1]; xQueueSend(xQueueUART_1xSENSOR_t, &SENSOR_Struct, 0); } } }