From ed4fed57fbf85139b61a3fec2a45dae11858feb8 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 31 Jan 2019 11:57:15 -0500 Subject: [PATCH] better conditional compilation --- firmware/console/status_loop.cpp | 14 ++++++++++---- firmware/controllers/algo/engine.cpp | 4 +++- firmware/controllers/algo/engine2.cpp | 4 ++++ firmware/controllers/algo/fuel_math.cpp | 4 ++++ firmware/controllers/engine_controller.cpp | 4 ++++ firmware/controllers/map_averaging.cpp | 8 ++++++-- firmware/controllers/map_averaging.h | 2 +- firmware/controllers/sensors/map.cpp | 2 +- firmware/controllers/tachometer.cpp | 2 ++ firmware/hw_layer/adc_inputs.h | 2 +- firmware/hw_layer/hardware.cpp | 8 ++++++-- firmware/hw_layer/lcd/lcd_HD44780.cpp | 3 ++- firmware/hw_layer/stepper.cpp | 2 +- firmware/hw_layer/stm32f4/mpu_util.h | 4 ++++ 14 files changed, 49 insertions(+), 14 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index ee2481bd8f..c0dcc74205 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -228,7 +228,7 @@ static void printSensors(Logging *log, bool fileFormat) { // below are the more advanced data points which only go into log file -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) reportSensorF(log, fileFormat, GAUGE_NAME_CPU_TEMP, "C", getMCUInternalTemperature(), 2); // log column #3 #endif @@ -869,16 +869,22 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->engineMode = packEngineMode(PASS_ENGINE_PARAMETER_SIGNATURE); -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC tsOutputChannels->internalMcuTemperature = getMCUInternalTemperature(); - tsOutputChannels->idlePosition = getIdlePosition(); - tsOutputChannels->isTriggerError = isTriggerErrorNow(); +#endif /* HAL_USE_ADC */ #if EFI_MAX_31855 || defined(__DOXYGEN__) for (int i = 0; i < EGT_CHANNEL_COUNT; i++) tsOutputChannels->egtValues.values[i] = getEgtValue(i); #endif /* EFI_MAX_31855 */ +#if EFI_IDLE_CONTROL + tsOutputChannels->idlePosition = getIdlePosition(); +#endif + +#if EFI_PROD_CODE || defined(__DOXYGEN__) + tsOutputChannels->isTriggerError = isTriggerErrorNow(); + #if EFI_INTERNAL_FLASH || defined(__DOXYGEN__) tsOutputChannels->needBurn = getNeedToWriteConfiguration(); #endif /* EFI_INTERNAL_FLASH */ diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 3afa697231..ef7593f26f 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -125,6 +125,7 @@ void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * See also periodicFastCallback */ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) int rpm = GET_RPM(); isEngineChartEnabled = CONFIG(isEngineChartEnabled) && rpm < CONFIG(engineSnifferRpmThreshold); sensorChartMode = rpm < CONFIG(sensorSnifferRpmThreshold) ? CONFIGB(sensorChartMode) : SC_OFF; @@ -141,6 +142,7 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) { sensors.vBatt = hasVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) ? getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) : 12; engineState.injectorLag = getInjectorLag(sensors.vBatt PASS_ENGINE_PARAMETER_SUFFIX); +#endif } void Engine::onTriggerSignalEvent(efitick_t nowNt) { @@ -189,7 +191,7 @@ void Engine::preCalculate(DECLARE_ENGINE_PARAMETER_SIGNATURE) { sparkTable.preCalc(engineConfiguration->sparkDwellRpmBins, engineConfiguration->sparkDwellValues); -#if ! EFI_UNIT_TEST +#if HAL_USE_ADC adcToVoltageInputDividerCoefficient = adcToVolts(1) * engineConfiguration->analogInputDividerCoefficient; #else adcToVoltageInputDividerCoefficient = engineConfigurationPtr->analogInputDividerCoefficient; diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 7a40578821..37b1e2018b 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -125,6 +125,7 @@ void EngineState::updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) if (!engine->slowCallBackWasInvoked) { warning(CUSTOM_ERR_6696, "Slow not invoked yet"); } @@ -213,9 +214,11 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } else { baseTableFuel = getBaseTableFuel(rpm, engineLoad); } +#endif } void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUFFIX) { +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) float coolantC = ENGINE(sensors.clt); float intakeC = ENGINE(sensors.iat); float newTCharge = getTCharge(rpm, tps, coolantC, intakeC PASS_ENGINE_PARAMETER_SUFFIX); @@ -228,6 +231,7 @@ void EngineState::updateTChargeK(int rpm, float tps DECLARE_ENGINE_PARAMETER_SUF tChargeK = convertCelsiusToKelvin(tCharge); timeSinceLastTChargeK = curTime; } +#endif } SensorsState::SensorsState() { diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 78f6538598..003b6d8507 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -47,6 +47,8 @@ extern fuel_Map3D_t ve2Map; extern afr_Map3D_t afrMap; extern baroCorr_Map3D_t baroCorrMap; +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) + /** * @return total duration of fuel injection per engine cycle, in milliseconds */ @@ -349,3 +351,5 @@ float getFuelRate(floatms_t totalInjDuration, efitick_t timePeriod DECLARE_ENGIN const float cc_min_to_L_h = 60.0f / 1000.0f; return fuelRate * CONFIG(injector.flow) * cc_min_to_L_h; } + +#endif diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 4840da3287..8699f2ff19 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -277,6 +277,7 @@ static void invokePerSecond(void) { } static void periodicSlowCallback(Engine *engine) { +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) efiAssertVoid(CUSTOM_ERR_6661, getRemainingStack(chThdGetSelfX()) > 64, "lowStckOnEv"); #if EFI_PROD_CODE /** @@ -319,6 +320,7 @@ static void periodicSlowCallback(Engine *engine) { engine->periodicSlowCallback(PASS_ENGINE_PARAMETER_SIGNATURE); scheduleNextSlowInvocation(); +#endif } void initPeriodicEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) { @@ -596,7 +598,9 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S printf("commonInitEngineController\n"); #endif initConfigActions(); +#if EFI_ENABLE_MOCK_ADC initMockVoltage(); +#endif /* EFI_ENABLE_MOCK_ADC */ #if EFI_PROD_CODE || EFI_SIMULATOR || defined(__DOXYGEN__) initSignalExecutor(); diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 074a9c839d..963517f598 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -122,7 +122,7 @@ static void startAveraging(void *arg) { mapAveragingPin.setHigh(); } -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) /** * This method is invoked from ADC callback. * @note This method is invoked OFTEN, this method is a potential bottle-next - the implementation should be @@ -179,7 +179,7 @@ static void endAveraging(void *arg) { bool wasLocked = lockAnyContext(); isAveraging = false; // with locking we would have a consistent state -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) if (mapMeasurementsCounter > 0) { v_averagedMapValue = adcToVoltsDivided(mapAdcAccumulator / mapMeasurementsCounter); // todo: move out of locked context? @@ -255,6 +255,7 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { */ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) { +#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) // this callback is invoked on interrupt thread UNUSED(ckpEventType); if (index != CONFIG(mapAveragingSchedulingAtIndex)) @@ -304,6 +305,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, engine->m.mapAveragingCbTime = GET_TIMESTAMP() - engine->m.beforeMapAveragingCb; } +#endif } static void showMapStats(void) { @@ -339,7 +341,9 @@ void initMapAveraging(Logging *sharedLogger, Engine *engine) { // endTimer[0].name = "map end0"; // endTimer[1].name = "map end1"; +#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine); +#endif /* EFI_SHAFT_POSITION_INPUT */ addConsoleAction("faststat", showMapStats); applyMapMinBufferLength(); } diff --git a/firmware/controllers/map_averaging.h b/firmware/controllers/map_averaging.h index 2142705c30..e8030bb3ad 100644 --- a/firmware/controllers/map_averaging.h +++ b/firmware/controllers/map_averaging.h @@ -12,7 +12,7 @@ #if EFI_MAP_AVERAGING || defined(__DOXYGEN__) -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) void mapAveragingAdcCallback(adcsample_t newValue); #endif diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index f1f6708d24..5829a6f8f0 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -263,7 +263,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { applyConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE); //engine->configurationListeners.registerCallback(applyConfiguration); -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ICU || defined(__DOXYGEN__) if (engineConfiguration->hasFrequencyReportingMapSensor) { digital_input_s* digitalMapInput = addWaveAnalyzerDriver("map freq", CONFIGB(frequencyReportingMapInputPin)); startInputDriver(digitalMapInput, true); diff --git a/firmware/controllers/tachometer.cpp b/firmware/controllers/tachometer.cpp index 099b8f74e4..b03d83b6fc 100644 --- a/firmware/controllers/tachometer.cpp +++ b/firmware/controllers/tachometer.cpp @@ -44,5 +44,7 @@ void initTachometer(void) { enginePins.tachOut.initPin("analog tach output", CONFIGB(tachOutputPin), &CONFIGB(tachOutputPinMode)); +#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) addTriggerEventListener(tachSignalCallback, "tach", engine); +#endif /* EFI_SHAFT_POSITION_INPUT */ } diff --git a/firmware/hw_layer/adc_inputs.h b/firmware/hw_layer/adc_inputs.h index e94f4794a7..ce81beb37b 100644 --- a/firmware/hw_layer/adc_inputs.h +++ b/firmware/hw_layer/adc_inputs.h @@ -10,9 +10,9 @@ #define ADC_INPUTS_H_ #include "global.h" +#include "adc_math.h" #if HAL_USE_ADC || defined(__DOXYGEN__) -#include "adc_math.h" const char * getAdcMode(adc_channel_e hwChannel); void initAdcInputs(bool boardTestMode); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 8d483a6d85..cbe201c764 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -165,8 +165,6 @@ static Logging *sharedLogger; #if EFI_PROD_CODE -extern AdcDevice fastAdc; - #define TPS_IS_SLOW -1 static int fastMapSampleIndex; @@ -175,6 +173,9 @@ static int tpsSampleIndex; extern int tpsFastAdc; +#if HAL_USE_ADC +extern AdcDevice fastAdc; + /** * This method is not in the adc* lower-level file because it is more business logic then hardware. */ @@ -205,8 +206,10 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) { // } } } +#endif /* HAL_USE_ADC */ static void calcFastAdcIndexes(void) { +#if HAL_USE_ADC fastMapSampleIndex = fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->map.sensor.hwChannel]; hipSampleIndex = engineConfiguration->hipOutputChannel == EFI_ADC_NONE ? @@ -216,6 +219,7 @@ static void calcFastAdcIndexes(void) { } else { tpsSampleIndex = TPS_IS_SLOW; } +#endif/* HAL_USE_ADC */ } static void adcConfigListener(Engine *engine) { diff --git a/firmware/hw_layer/lcd/lcd_HD44780.cpp b/firmware/hw_layer/lcd/lcd_HD44780.cpp index bec8c086dd..fb790b4386 100644 --- a/firmware/hw_layer/lcd/lcd_HD44780.cpp +++ b/firmware/hw_layer/lcd/lcd_HD44780.cpp @@ -106,6 +106,7 @@ static void lcd_HD44780_write(uint8_t data) { // LCD Pin RW -> P1 // LCD Pin E -> P2 +#if HAL_USE_I2C // todo: finish all this stuff i2cAcquireBus(&I2CD1); // @@ -117,7 +118,7 @@ static void lcd_HD44780_write(uint8_t data) { // i2cMasterTransmit(&I2CD1, LCD_PORT_EXP_ADDR, txbuf, 1, NULL, 0); // i2cReleaseBus(&I2CD1); - +#endif /* HAL_USE_I2C */ } } diff --git a/firmware/hw_layer/stepper.cpp b/firmware/hw_layer/stepper.cpp index e3a32d4cae..6d34586de0 100644 --- a/firmware/hw_layer/stepper.cpp +++ b/firmware/hw_layer/stepper.cpp @@ -42,7 +42,7 @@ static msg_t stThread(StepperMotor *motor) { // try to get saved stepper position (-1 for no data) motor->currentPosition = loadStepperPos(); -#if EFI_PROD_CODE || defined(__DOXYGEN__) +#if HAL_USE_ADC || defined(__DOXYGEN__) // first wait until at least 1 slowADC sampling is complete waitForSlowAdc(); #endif diff --git a/firmware/hw_layer/stm32f4/mpu_util.h b/firmware/hw_layer/stm32f4/mpu_util.h index 6481b8d60e..7222b61734 100644 --- a/firmware/hw_layer/stm32f4/mpu_util.h +++ b/firmware/hw_layer/stm32f4/mpu_util.h @@ -86,6 +86,7 @@ void HardFaultVector(void); #endif /* MPU_UTIL_H_ */ +#if HAL_USE_SPI void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, brain_pin_e mosi, int sckMode, @@ -95,7 +96,10 @@ void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso, * @see getSpiDevice */ void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin); +#endif /* HAL_USE_SPI */ bool isValidCanTxPin(brain_pin_e pin); bool isValidCanRxPin(brain_pin_e pin); +#if HAL_USE_CAN CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx); +#endif /* HAL_USE_CAN */