diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 99869d0713..12e01aebe1 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -16,6 +16,7 @@ #include "event_registry.h" #include "trigger_structure.h" #include "table_helper.h" +#include "listener_array.h" /** * This class knows about when to inject fuel @@ -142,6 +143,9 @@ public: void updateSlowSensors(); void watchdog(); + + IntListenerArray configurationListeners; + private: /** * By the way: diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 4828df9895..387d85b718 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -361,7 +361,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_ engineConfiguration->knockDetectionWindowStart = 35; engineConfiguration->knockDetectionWindowEnd = 135; - + engineConfiguration->hipOutputChannel = EFI_ADC_NONE; /** * this is RPM. 10000 rpm is only 166Hz, 800 rpm is 13Hz diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 0d519c5019..2f4ab32222 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -536,7 +536,11 @@ typedef struct { bool_t hasMafSensor : 1; // bit 12 bool_t hasTpsSensor : 1; // bit 13 - int unused6284; + /** + * see also + * offset 6284 + */ + adc_channel_e hipOutputChannel; idle_mode_e idleMode; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index be207f5319..c941083836 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -393,7 +393,7 @@ void initEngineContoller(Logging *sharedLogger, Engine *engine) { #if EFI_IDLE_CONTROL || defined(__DOXYGEN__) if (engineConfiguration->isIdleThreadEnabled) { - startIdleThread(engine); + startIdleThread(sharedLogger, engine); } #endif diff --git a/firmware/controllers/flash_main.h b/firmware/controllers/flash_main.h index afedd96af7..1d296d0e31 100644 --- a/firmware/controllers/flash_main.h +++ b/firmware/controllers/flash_main.h @@ -12,7 +12,7 @@ #include "engine_configuration.h" #include "engine.h" -#define FLASH_DATA_VERSION 6130 +#define FLASH_DATA_VERSION 6385 void readFromFlash(void); void initFlash(Logging *sharedLogger, Engine *engine); diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index f3e32c1016..3ec51c2c53 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -36,7 +36,7 @@ static THD_WORKING_AREA(ivThreadStack, UTILITY_THREAD_STACK_SIZE); -static LoggingWithStorage logger; +static Logging *logger; EXTERN_ENGINE ; @@ -49,14 +49,13 @@ static SimplePwm idleValvePwm; static IdleValveState idle; void idleDebug(const char *msg, percent_t value) { - printMsg(&logger, "%s%f", msg, value); - scheduleLogging(&logger); + scheduleMsg(logger, "%s%f", msg, value); } static void showIdleInfo(void) { - scheduleMsg(&logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode), + scheduleMsg(logger, "idleMode=%s duty=%f", getIdle_mode_e(engineConfiguration->idleMode), boardConfiguration->idleSolenoidPwm); - scheduleMsg(&logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency, + scheduleMsg(logger, "idle valve freq=%d on %s", boardConfiguration->idleSolenoidFrequency, hwPortname(boardConfiguration->idleValvePin)); } @@ -68,7 +67,7 @@ static void setIdleControlEnabled(int value) { static void setIdleValvePwm(percent_t value) { if (value < 0.01 || value > 99.9) return; - scheduleMsg(&logger, "setting idle valve PWM %f", value); + scheduleMsg(logger, "setting idle valve PWM %f", value); float f = 0.01 * value; boardConfiguration->idleSolenoidPwm = f; showIdleInfo(); @@ -117,7 +116,7 @@ static msg_t ivThread(int param) { static void setIdleRpmAction(int value) { setIdleRpm(&idle, value); - scheduleMsg(&logger, "target idle RPM %d", value); + scheduleMsg(logger, "target idle RPM %d", value); } static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { @@ -129,8 +128,8 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { output->setValue(value); } -void startIdleThread(Engine *engine) { - initLogging(&logger, "Idle Valve Control"); +void startIdleThread(Logging*sharedLogger, Engine *engine) { + logger = sharedLogger; /** * Start PWM for IDLE_VALVE logical / idleValvePin physical @@ -139,7 +138,7 @@ void startIdleThread(Engine *engine) { boardConfiguration->idleSolenoidFrequency, boardConfiguration->idleSolenoidPwm, applyIdleSolenoidPinState); idle.init(); - scheduleMsg(&logger, "initial idle %d", idle.value); + scheduleMsg(logger, "initial idle %d", idle.value); chThdCreateStatic(ivThreadStack, sizeof(ivThreadStack), NORMALPRIO, (tfunc_t) ivThread, NULL); diff --git a/firmware/controllers/idle_thread.h b/firmware/controllers/idle_thread.h index bcd9592de6..8fd1a95bf9 100644 --- a/firmware/controllers/idle_thread.h +++ b/firmware/controllers/idle_thread.h @@ -11,6 +11,6 @@ #include "engine.h" -void startIdleThread(Engine *engine); +void startIdleThread(Logging*sharedLogger, Engine *engine); #endif /* IDLE_THREAD_H_ */ diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index 967ad3393f..b59873613d 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -189,6 +189,10 @@ static void endOfSpiCommunication(SPIDriver *spip) { isSendingSpiCommand = false; } +void hipAdcCallback(adcsample_t value) { + +} + void initHip9011(Logging *sharedLogger) { if (!boardConfiguration->isHip9011Enabled) return; diff --git a/firmware/hw_layer/HIP9011.h b/firmware/hw_layer/HIP9011.h index f1a3973533..2e7bad6d3d 100644 --- a/firmware/hw_layer/HIP9011.h +++ b/firmware/hw_layer/HIP9011.h @@ -31,5 +31,6 @@ void initHip9011(Logging *sharedLogger); void setHip9011FrankensoPinout(void); +void hipAdcCallback(adcsample_t value); #endif /* HIP9011_H_ */ diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 4c4535c89a..5aa8e7617d 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -137,6 +137,9 @@ static Logging *sharedLogger; extern AdcDevice fastAdc; +static int fastMapSampleIndex; +static int hipSampleIndex; + /** * This method is not in the adc* lower-level file because it is more business logic then hardware. */ @@ -154,11 +157,25 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) { efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9b"); #if EFI_MAP_AVERAGING - mapAveragingCallback(fastAdc.samples[0]); + mapAveragingCallback(fastAdc.samples[fastMapSampleIndex]); #endif /* EFI_MAP_AVERAGING */ + if (boardConfiguration->isHip9011Enabled) { + hipAdcCallback(fastAdc.samples[hipSampleIndex]); + } } } +static void calcFastAdcIndexes(void) { + fastMapSampleIndex = fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->map.sensor.hwChannel]; + hipSampleIndex = + engineConfiguration->hipOutputChannel == EFI_ADC_NONE ? + -1 : fastAdc.internalAdcIndexByHardwareIndex[engineConfiguration->hipOutputChannel]; +} + +static void adcConfigListener(void) { + calcFastAdcIndexes(); +} + void initHardware(Logging *l, Engine *engine) { sharedLogger = l; engine_configuration_s *engineConfiguration = engine->engineConfiguration; @@ -199,8 +216,7 @@ void initHardware(Logging *l, Engine *engine) { #if EFI_INTERNAL_FLASH - palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, - PAL_MODE_INPUT_PULLUP); + palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP); initFlash(sharedLogger, engine); /** @@ -209,8 +225,7 @@ void initHardware(Logging *l, Engine *engine) { */ if (SHOULD_INGORE_FLASH()) { engineConfiguration->engineType = DEFAULT_ENGINE_TYPE; - resetConfigurationExt(sharedLogger, engineConfiguration->engineType, - engine); + resetConfigurationExt(sharedLogger, engineConfiguration->engineType, engine); writeToFlash(); } else { readFromFlash(); @@ -244,8 +259,7 @@ void initHardware(Logging *l, Engine *engine) { initOutputPins(); #if EFI_MAX_31855 - initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), - boardConfiguration->max31855_cs); + initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), boardConfiguration->max31855_cs); #endif /* EFI_MAX_31855 */ // iacMotor.initialize(GPIOD_11, GPIOD_10); @@ -317,6 +331,9 @@ void initHardware(Logging *l, Engine *engine) { initJoystick(sharedLogger); + calcFastAdcIndexes(); + engine->configurationListeners.registerCallback(adcConfigListener); + printMsg(sharedLogger, "initHardware() OK!"); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 19ffbe10c1..47626300be 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -253,7 +253,7 @@ void firmwareError(const char *fmt, ...) { } } -static char UNUSED_RAM_SIZE[6000]; +static char UNUSED_RAM_SIZE[6500]; static char UNUSED_CCM_SIZE[8000] CCM_OPTIONAL; diff --git a/firmware/util/datalogging.h b/firmware/util/datalogging.h index e027635fdf..52b4e40582 100644 --- a/firmware/util/datalogging.h +++ b/firmware/util/datalogging.h @@ -14,27 +14,6 @@ #define DELIMETER "," -typedef enum { - LP_RPM = 0, - LP_ECT = 1, - LP_IAT = 2, - - LP_THROTTLE = 3, - LP_THROTTLE_ADC = 4, - - LP_MAP = 5, - LP_MAP_RAW = 6, - - LP_MAF = 7, - LP_TRG_CH0_DUTY = 8, - LP_TRG_CH1_DUTY = 9, - - - // LP_SECONDS, - LP_COUNT = 9 - -} LoggingPoints; - // todo: migrate to external buffer so that different instances have different // size of buffers? class Logging { @@ -81,10 +60,8 @@ void initLogging(LoggingWithStorage *logging, const char *name); void initLoggingExt(Logging *logging, const char *name, char *buffer, int bufferSize); void debugInt(Logging *logging, const char *caption, int value); -void logInt(Logging *logging, LoggingPoints loggingPoint, int value); void debugFloat(Logging *logging, const char *text, float value, int precision); -void logFloat(Logging *logging, LoggingPoints loggingPoint, float value); void appendFloat(Logging *logging, float value, int precision); void resetLogging(Logging *logging); diff --git a/firmware/util/listener_array.cpp b/firmware/util/listener_array.cpp index ab9e182d39..1a5a9214d9 100644 --- a/firmware/util/listener_array.cpp +++ b/firmware/util/listener_array.cpp @@ -8,6 +8,10 @@ #include "listener_array.h" #include "main.h" +IntListenerArray::IntListenerArray() { + currentListenersCount = 0; +} + void IntListenerArray::registerCallback(IntListener handler, void *arg) { efiAssertVoid(currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks"); int index = currentListenersCount++; diff --git a/firmware/util/listener_array.h b/firmware/util/listener_array.h index b50472ae9a..6b3bd4c20b 100644 --- a/firmware/util/listener_array.h +++ b/firmware/util/listener_array.h @@ -23,6 +23,7 @@ typedef void (*ArgIntListener)(void *arg, int value); class IntListenerArray { public: + IntListenerArray(); void registerCallback(IntListener handler, void *arg); void registerCallback(Void listener); void invokeJustArgCallbacks();