diff --git a/firmware/controllers/sensors/hip9011_lookup.h b/firmware/controllers/sensors/hip9011_lookup.h index ce62d5819e..9b55d2ce41 100644 --- a/firmware/controllers/sensors/hip9011_lookup.h +++ b/firmware/controllers/sensors/hip9011_lookup.h @@ -26,7 +26,6 @@ int getHip9011BandIndex(float frequency); void prepareHip9011RpmLookup(float angleWindowWidth); #define GAIN_INDEX(gain) (GAIN_LOOKUP_SIZE - 1 - findIndexMsg("fGain", gainLookupInReverseOrder, GAIN_LOOKUP_SIZE, (gain))) -#define BAND(bore) (900 / (PIF * (bore) / 2)) extern float rpmLookup[INT_LOOKUP_SIZE]; int getIntegrationIndexByRpm(float rpm); diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index e0f0b8fd0b..9b85d478db 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -117,10 +117,6 @@ static SPIDriver *driver; EXTERN_ENGINE ; -static float getBand(void) { - return engineConfiguration->knockBandCustom == 0 ? - BAND(engineConfiguration->cylinderBore) : engineConfiguration->knockBandCustom; -} static char hipPinNameBuffer[16]; @@ -134,7 +130,7 @@ static void showHipInfo(void) { scheduleMsg(logger, "enabled=%s state=%s bore=%.2fmm freq=%.2fkHz PaSDO=%d", boolToString(boardConfiguration->isHip9011Enabled), getHip_state_e(instance.state), - engineConfiguration->cylinderBore, getBand(), + engineConfiguration->cylinderBore, getHIP9011Band(PASS_HIP_PARAMS), engineConfiguration->hip9011PrescalerAndSDO); char *outputName = getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, hipPinNameBuffer); @@ -287,7 +283,7 @@ static void endOfSpiExchange(SPIDriver *spip) { } static int getBandIndex(void) { - float freq = getBand(); + float freq = getHIP9011Band(PASS_HIP_PARAMS); return getHip9011BandIndex(freq); } diff --git a/firmware/hw_layer/HIP9011_logic.cpp b/firmware/hw_layer/HIP9011_logic.cpp index 8ae325e134..1c2dcc24af 100644 --- a/firmware/hw_layer/HIP9011_logic.cpp +++ b/firmware/hw_layer/HIP9011_logic.cpp @@ -7,8 +7,19 @@ #include "HIP9011_logic.h" +EXTERN_ENGINE; + HIP9011::HIP9011() { needToInit = true; state = NOT_READY; } +#define BAND(bore) (900 / (PIF * (bore) / 2)) + +/** + * @return frequency band we are interested in + */ +float getHIP9011Band(DEFINE_HIP_PARAMS) { + return GET_CONFIG_VALUE(knockBandCustom) == 0 ? + BAND(GET_CONFIG_VALUE(cylinderBore)) : GET_CONFIG_VALUE(knockBandCustom); +} diff --git a/firmware/hw_layer/HIP9011_logic.h b/firmware/hw_layer/HIP9011_logic.h index 5ed486e48a..600b984a56 100644 --- a/firmware/hw_layer/HIP9011_logic.h +++ b/firmware/hw_layer/HIP9011_logic.h @@ -8,7 +8,9 @@ #ifndef HW_LAYER_HIP9011_LOGIC_H_ #define HW_LAYER_HIP9011_LOGIC_H_ +#include "efifeatures.h" #include "rusefi_enums.h" +#include "hip9011_lookup.h" /** * this interface defines SPI communication channel with HIP9011 chip @@ -36,4 +38,22 @@ public: }; +#if EFI_PROD_CODE || EFI_SIMULATOR +#define PASS_HIP_PARAMS +#define DEFINE_HIP_PARAMS +#define GET_CONFIG_VALUE(x) CONFIG(x) +#else + +#define PASS_HIP_PARAMS CONFIG(knockBandCustom), \ + CONFIG(cylinderBore) + +#define DEFINE_HIP_PARAMS float knockBandCustom,\ + float cylinderBore + +#define GET_CONFIG_VALUE(x) x +#endif + + +float getHIP9011Band(DEFINE_HIP_PARAMS); + #endif /* HW_LAYER_HIP9011_LOGIC_H_ */ diff --git a/unit_tests/test_hip9011.cpp b/unit_tests/test_hip9011.cpp index 068c411e06..3694cddeea 100644 --- a/unit_tests/test_hip9011.cpp +++ b/unit_tests/test_hip9011.cpp @@ -6,6 +6,7 @@ #include "unit_test_framework.h" #include "hip9011_lookup.h" +#include "HIP9011_logic.h" #include "gtest/gtest.h" TEST(hip9011, lookup) { @@ -28,3 +29,10 @@ TEST(hip9011, lookup) { EXPECT_EQ(1, getIntegrationIndexByRpm(6600)); EXPECT_EQ(0, getIntegrationIndexByRpm(16600)); } + +TEST(hip9011, band) { + + EXPECT_FLOAT_EQ(3, getHIP9011Band(/* knockBandCustom*/3, /*cylinderBore*/76)); + EXPECT_FLOAT_EQ(7.5389242, getHIP9011Band(/* knockBandCustom*/0, /*cylinderBore*/76)); + +}