ETB target is using integer values #945

refactoring - ADC mocking is a mess
This commit is contained in:
rusefi 2019-09-22 09:56:06 -04:00
parent d09e096874
commit 533087f475
21 changed files with 53 additions and 41 deletions

View File

@ -982,13 +982,13 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
break;
#endif /* EFI_CAN_SUPPORT */
case DBG_ANALOG_INPUTS:
tsOutputChannels->debugFloatField1 = (engineConfiguration->vbattAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("vbatt", engineConfiguration->vbattAdcChannel) : 0.0f;
tsOutputChannels->debugFloatField2 = (engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE) ? getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel) : 0.0f;
tsOutputChannels->debugFloatField3 = (engineConfiguration->mafAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("maf", engineConfiguration->mafAdcChannel) : 0.0f;
tsOutputChannels->debugFloatField4 = (engineConfiguration->map.sensor.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel) : 0.0f;
tsOutputChannels->debugFloatField5 = (engineConfiguration->clt.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("clt", engineConfiguration->clt.adcChannel) : 0.0f;
tsOutputChannels->debugFloatField6 = (engineConfiguration->iat.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("iat", engineConfiguration->iat.adcChannel) : 0.0f;
tsOutputChannels->debugFloatField7 = (engineConfiguration->afr.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("ego", engineConfiguration->afr.hwChannel) : 0.0f;
tsOutputChannels->debugFloatField1 = (engineConfiguration->vbattAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("vbatt", engineConfiguration->vbattAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField2 = (engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE) ? getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField3 = (engineConfiguration->mafAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("maf", engineConfiguration->mafAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField4 = (engineConfiguration->map.sensor.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField5 = (engineConfiguration->clt.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("clt", engineConfiguration->clt.adcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField6 = (engineConfiguration->iat.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("iat", engineConfiguration->iat.adcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField7 = (engineConfiguration->afr.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("ego", engineConfiguration->afr.hwChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
break;
case DBG_ANALOG_INPUTS2:
tsOutputChannels->debugFloatField4 = getVoltage("debug", engineConfiguration->throttlePedalPositionAdcChannel);

View File

@ -164,7 +164,7 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// todo: move this logic somewhere to sensors folder?
if (CONFIG(fuelLevelSensor) != EFI_ADC_NONE) {
float fuelLevelVoltage = getVoltageDivided("fuel", engineConfiguration->fuelLevelSensor);
float fuelLevelVoltage = getVoltageDivided("fuel", engineConfiguration->fuelLevelSensor PASS_ENGINE_PARAMETER_SUFFIX);
sensors.fuelTankLevel = interpolateMsg("fgauge", CONFIGB(fuelLevelEmptyTankVoltage), 0,
CONFIGB(fuelLevelFullTankVoltage), 100,
fuelLevelVoltage);

View File

@ -29,5 +29,5 @@ bool getAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
* for now we are looking for a pull-up. High level means input switch is floating (which is OFF position)
* low value means input is ground - which means ON.
*/
return getVoltageDivided("A/C", engineConfiguration->acSwitchAdc) < 2.5;
return getVoltageDivided("A/C", engineConfiguration->acSwitchAdc PASS_ENGINE_PARAMETER_SUFFIX) < 2.5;
}

View File

@ -21,8 +21,6 @@
#include "thermistors.h"
#include "adc_inputs.h"
#include "adc_inputs.h"
void initSensors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX);
bool hasAcToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE);

View File

@ -111,7 +111,7 @@ float getAfr(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#endif /* EFI_CJ125 && HAL_USE_SPI */
afr_sensor_s * sensor = &CONFIG(afr);
float volts = getVoltageDivided("ego", sensor->hwChannel);
float volts = getVoltageDivided("ego", sensor->hwChannel PASS_ENGINE_PARAMETER_SUFFIX);
if (CONFIGB(afr_type) == ES_NarrowBand) {
float afr = interpolate2d("narrow", volts, engineConfiguration->narrowToWideOxygenBins, engineConfiguration->narrowToWideOxygen);

View File

@ -10,7 +10,7 @@ EXTERN_ENGINE
* @return MAF sensor voltage
*/
float getMafVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return getVoltageDivided("maf", engineConfiguration->mafAdcChannel);
return getVoltageDivided("maf", engineConfiguration->mafAdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
}
bool hasMafSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {

View File

@ -148,7 +148,7 @@ float getRawMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return interpolateMsg("rmap", CONFIGB(mapFrequency0Kpa), 0, CONFIGB(mapFrequency100Kpa), 100, mapFreq);
}
float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel);
float voltage = getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX);
return getMapByVoltage(voltage PASS_ENGINE_PARAMETER_SUFFIX);
}
@ -168,7 +168,7 @@ float getBaroPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// Override the real Baro sensor with the stored initial MAP value, if the option is set.
if (CONFIG(useFixedBaroCorrFromMap))
return storedInitialBaroPressure;
float voltage = getVoltageDivided("baro", engineConfiguration->baroSensor.hwChannel);
float voltage = getVoltageDivided("baro", engineConfiguration->baroSensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX);
return decodePressure(voltage, &engineConfiguration->baroSensor PASS_ENGINE_PARAMETER_SUFFIX);
}

View File

@ -89,7 +89,7 @@ temperature_t getTemperatureC(ThermistorConf *cfg, ThermistorMath *tm, bool useL
DISPLAY_TEXT(Analog_ECU_reads);
#if EFI_UNIT_TEST
// todo: get rid of this branch, unify unit test with real firmware. maybe analogInputDividerCoefficient needs to be set?
tm->voltageBoard = getVoltageDivided("term", cfg->adcChannel);
tm->voltageBoard = getVoltageDivided("term", cfg->adcChannel PASS_ENGINE_PARAMETER_SUFFIX);
// CONFIG(analogInputDividerCoefficient) = 1;
// tm-> ISPLAY_FIELD(voltageBoard) = ISPLAY_TEXT(Rdivider) tm->voltageMCU * CONFIG( ISPLAY_CONFIG(analogInputDividerCoefficient));
#else

View File

@ -133,7 +133,7 @@ percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX) {
* Return voltage on TPS AND channel
* */
float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel);
return getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
}
/*
@ -176,7 +176,7 @@ void grabTPSIsWideOpen() {
void grabPedalIsUp() {
#if EFI_PROD_CODE
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel);
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->throttlePedalUpVoltage = voltage;
printTPSInfo();
#endif /* EFI_PROD_CODE */
@ -184,7 +184,7 @@ void grabPedalIsUp() {
void grabPedalIsWideOpen() {
#if EFI_PROD_CODE
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel);
float voltage = getVoltageDivided("pPS", engineConfiguration->throttlePedalPositionAdcChannel PASS_ENGINE_PARAMETER_SUFFIX);
engineConfiguration->throttlePedalWOTVoltage = voltage;
printTPSInfo();
#endif /* EFI_PROD_CODE */
@ -211,7 +211,7 @@ percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
DISPLAY_TAG(PEDAL_SECTION);
DISPLAY_TEXT(Analog_MCU_reads);
float voltage = getVoltageDivided("pPS", CONFIG(DISPLAY_CONFIG(throttlePedalPositionAdcChannel)));
float voltage = getVoltageDivided("pPS", CONFIG(DISPLAY_CONFIG(throttlePedalPositionAdcChannel)) PASS_ENGINE_PARAMETER_SUFFIX);
percent_t result = interpolateMsg("pedal", engineConfiguration->throttlePedalUpVoltage, 0, engineConfiguration->throttlePedalWOTVoltage, 100, voltage);
// this would put the value into the 0-100 range

View File

@ -385,7 +385,7 @@ static char pinNameBuffer[16];
static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm, bool useLinear) {
adc_channel_e adcChannel = config->adcChannel;
float voltage = getVoltageDivided("term", adcChannel);
float voltage = getVoltageDivided("term", adcChannel PASS_ENGINE_PARAMETER_SUFFIX);
float r = getResistance(config, voltage);
float t = getTemperatureC(config, tm, useLinear);

View File

@ -520,7 +520,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D
if (trgEventIndex == CONFIG(ignMathCalculateAtIndex)) {
if (CONFIG(externalKnockSenseAdc) != EFI_ADC_NONE) {
float externalKnockValue = getVoltageDivided("knock", engineConfiguration->externalKnockSenseAdc);
float externalKnockValue = getVoltageDivided("knock", engineConfiguration->externalKnockSenseAdc PASS_ENGINE_PARAMETER_SUFFIX);
engine->knockLogic(externalKnockValue PASS_ENGINE_PARAMETER_SUFFIX);
}
}

View File

@ -46,6 +46,13 @@
static adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX];
static const char * adcHwChannelUsage[HW_MAX_ADC_INDEX];
EXTERN_ENGINE;
// Board voltage, with divider coefficient accounted for
float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
return getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient;
}
AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) {
this->hwConfig = hwConfig;
channelCount = 0;

View File

@ -11,6 +11,7 @@
#ifndef ADC_MATH_H_
#define ADC_MATH_H_
#include "global.h"
#define ADC_MAX_VALUE 4095
#define adcToVolts(adc) ((engineConfiguration->adcVcc) / ADC_MAX_VALUE * (adc))
@ -20,7 +21,7 @@
// voltage in MCU universe, from zero to VDD
#define getVoltage(msg, hwChannel) (adcToVolts(getAdcValue(msg, hwChannel)))
// Board voltage, with divider coefficient accounted for
#define getVoltageDivided(msg, hwChannel) (getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient)
// DECLARE_ENGINE_PARAMETER_SUFFIX
float getVoltageDivided(const char *msg, adc_channel_e channel);
#endif /* ADC_MATH_H_ */

View File

@ -114,7 +114,7 @@ static float getUr() {
return getVoltage("cj125ur", CONFIG(cj125ur));
} else {
// if a standard voltage division scheme with OpAmp is used
return getVoltageDivided("cj125ur", CONFIG(cj125ur));
return getVoltageDivided("cj125ur", CONFIG(cj125ur) PASS_ENGINE_PARAMETER_SUFFIX);
}
#endif /* EFI_PROD_CODE */
}
@ -129,7 +129,7 @@ static float getUa() {
if (CONFIG(cj125ua) != EFI_ADC_NONE) {
#if EFI_PROD_CODE
if (engineConfiguration->cj125isUaDivided) {
return getVoltageDivided("cj125ua", CONFIG(cj125ua));
return getVoltageDivided("cj125ua", CONFIG(cj125ua) PASS_ENGINE_PARAMETER_SUFFIX);
} else {
return getVoltage("cj125ua", CONFIG(cj125ua));
}

View File

@ -9,11 +9,17 @@
#include "boards.h"
#include "engine.h"
#include "engine_sniffer.h"
#include "adc_math.h"
static LoggingWithStorage logger("simulator board");
extern engine_configuration_s *engineConfiguration;
extern Engine *engine;
EXTERN_ENGINE;
int getAdcValue(const char *msg, int hwChannel) {
return engine->engineState.mockAdcState.getMockAdcValue(hwChannel);
}
// Board voltage, with divider coefficient accounted for
float getVoltageDivided(const char *msg, adc_channel_e hwChannel DECLARE_ENGINE_PARAMETER_SUFFIX) {
return getVoltage(msg, hwChannel) * engineConfiguration->analogInputDividerCoefficient;
}

View File

@ -8,4 +8,6 @@
#ifndef ADC_INPUTS_H_
#define ADC_INPUTS_H_
#include "boards.h"
#endif /* ADC_INPUTS_H_ */

View File

@ -11,7 +11,7 @@ float testMafValue = 0;
float testCltValue = 0;
float testIatValue = 0;
float getVoltageDivided(const char *msg, adc_channel_e channel) {
float getVoltageDivided(const char *msg, adc_channel_e channel DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch(channel) {
case TEST_MAF_CHANNEL:
return testMafValue;

View File

@ -1,18 +1,18 @@
/*
* boards.h
* @file boards.h
*
* Created on: Nov 15, 2013
* Author: Andrey Belomutskiy, (c) 2012-2015
* @date Nov 15, 2013
* @author Andrey Belomutskiy, (c) 2012-2019
*/
#ifndef BOARDS_H_
#define BOARDS_H_
#include "rusefi_enums.h"
#include "engine_configuration.h"
#define ADC_CHANNEL_VREF 0
float getVoltageDivided(const char *msg, adc_channel_e);
float getVoltageDivided(const char *msg, adc_channel_e channel DECLARE_ENGINE_PARAMETER_SUFFIX);
float getVoltage(const char *msg, int channel);
int getAdcValue(const char *msg, int channel);

View File

@ -15,8 +15,6 @@
#include "common_headers.h"
#include "boards.h"
typedef uint32_t iomode_t;
typedef uint32_t ioportid_t;
typedef uint32_t ioportmask_t;

View File

@ -1,6 +1,6 @@
#include "linear_sensor.h"
#include <gtest/gtest.h>
#include "unit_test_framework.h"
class SensorLinear : public ::testing::Test {
protected:
@ -21,7 +21,7 @@ protected:
auto result = dut.get(); \
\
EXPECT_TRUE(result.Valid); \
EXPECT_FLOAT_EQ(result.Value, (out)); \
ASSERT_NEAR(result.Value, (out), EPS4D) << "Not " << out << " for " << in; \
}
#define test_point_invalid(in) \

View File

@ -1,8 +1,8 @@
/*
* unit_test_framework.h
* @file unit_test_framework.h
*
* Created on: Mar 4, 2018
* Author: Andrey Belomutskiy, (c) 2012-2018
* @date Mar 4, 2018
* @author Andrey Belomutskiy, (c) 2012-2018
*/
#ifndef UNIT_TEST_FRAMEWORK_H_