From dd9c9e7a81f539c923045580c47f8833823cf204 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:12:11 -0700 Subject: [PATCH 01/16] printFloatArray --- .../controllers/algo/engine_configuration.h | 1 - firmware/controllers/settings.cpp | 32 ------------------- 2 files changed, 33 deletions(-) diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 550948181d..5931a0d673 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -39,7 +39,6 @@ void setWholeIatCorrTimingTable(float value DECLARE_CONFIG_PARAMETER_SUFFIX); void setWholeTimingTable_d(angle_t value DECLARE_CONFIG_PARAMETER_SUFFIX); #define setWholeTimingTable(x) setWholeTimingTable_d(x PASS_CONFIG_PARAMETER_SUFFIX); void setConstantDwell(floatms_t dwellMs DECLARE_CONFIG_PARAMETER_SUFFIX); -void printFloatArray(const char *prefix, float array[], int size); // needed by bootloader void setDefaultBasePins(DECLARE_CONFIG_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index e06e6f91d1..9cbe37b392 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -60,25 +60,6 @@ static Logging logger("settings control", LOGGING_BUFFER, sizeof(LOGGING_BUFFER) EXTERN_ENGINE; -/* - static void printIntArray(int array[], int size) { - for (int j = 0; j < size; j++) { - print("%d ", array[j]); - } - print("\r\n"); - } - */ - -void printFloatArray(const char *prefix, float array[], int size) { - appendMsgPrefix(&logger); - appendPrintf(&logger, prefix); - for (int j = 0; j < size; j++) { - appendPrintf(&logger, "%.2f ", array[j]); - } - appendMsgPostfix(&logger); - scheduleLogging(&logger); -} - void printSpiState(Logging *logger, const engine_configuration_s *engineConfiguration) { scheduleMsg(logger, "spi 1=%s/2=%s/3=%s/4=%s", boolToString(engineConfiguration->is_enabled_spi_1), @@ -211,19 +192,6 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) { // print("\r\n"); } -// printFloatArray("RPM bin: ", config->fuelRpmBins, FUEL_RPM_COUNT); -// -// printFloatArray("Y bin: ", config->fuelLoadBins, FUEL_LOAD_COUNT); -// -// printFloatArray("CLT: ", config->cltFuelCorr, CLT_CURVE_SIZE); -// printFloatArray("CLT bins: ", config->cltFuelCorrBins, CLT_CURVE_SIZE); -// -// printFloatArray("IAT: ", config->iatFuelCorr, IAT_CURVE_SIZE); -// printFloatArray("IAT bins: ", config->iatFuelCorrBins, IAT_CURVE_SIZE); -// -// printFloatArray("vBatt: ", engineConfiguration->injector.battLagCorr, VBAT_INJECTOR_CURVE_SIZE); -// printFloatArray("vBatt bins: ", engineConfiguration->injector.battLagCorrBins, VBAT_INJECTOR_CURVE_SIZE); - scheduleMsg(&logger, "rpmHardLimit: %d/operationMode=%d", engineConfiguration->rpmHardLimit, engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)); From 225e403973e0bfa687af97f7268ee42cca50795b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:22:31 -0700 Subject: [PATCH 02/16] parameter names --- firmware/controllers/actuators/electronic_throttle.cpp | 8 ++++---- firmware/controllers/actuators/electronic_throttle.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 599a2e42b4..1a93b3402f 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -323,7 +323,7 @@ expected EtbController::getClosedLoopAutotune(percent_t actualThrottl return autotuneAmplitude * (isPositive ? -1 : 1); } -expected EtbController::getClosedLoop(percent_t target, percent_t actualThrottlePosition) { +expected EtbController::getClosedLoop(percent_t target, percent_t observation) { if (m_shouldResetPid) { m_pid.reset(); m_shouldResetPid = false; @@ -333,16 +333,16 @@ expected EtbController::getClosedLoop(percent_t target, percent_t act if (m_myIndex == 0) { #if EFI_TUNER_STUDIO // Error is positive if the throttle needs to open further - tsOutputChannels.etb1Error = target - actualThrottlePosition; + tsOutputChannels.etb1Error = target - observation; #endif /* EFI_TUNER_STUDIO */ } // Only allow autotune with stopped engine if (GET_RPM() == 0 && engine->etbAutoTune) { - return getClosedLoopAutotune(actualThrottlePosition); + return getClosedLoopAutotune(observation); } else { // Normal case - use PID to compute closed loop part - return m_pid.getOutput(target, actualThrottlePosition, 1.0f / ETB_LOOP_FREQUENCY); + return m_pid.getOutput(target, observation, 1.0f / ETB_LOOP_FREQUENCY); } } diff --git a/firmware/controllers/actuators/electronic_throttle.h b/firmware/controllers/actuators/electronic_throttle.h index e4b1ca666e..9530e914f5 100644 --- a/firmware/controllers/actuators/electronic_throttle.h +++ b/firmware/controllers/actuators/electronic_throttle.h @@ -55,7 +55,7 @@ public: expected getSetpoint() const override; expected getOpenLoop(percent_t target) const override; - expected getClosedLoop(percent_t setpoint, percent_t target) override; + expected getClosedLoop(percent_t setpoint, percent_t observation) override; expected getClosedLoopAutotune(percent_t actualThrottlePosition); void setOutput(expected outputValue) override; From 7a85161a4a498ca2259526b9663e6409d06f7bcd Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:22:54 -0700 Subject: [PATCH 03/16] initialization --- firmware/controllers/algo/accel_enrichment.h | 10 +++++----- firmware/controllers/algo/engine_parts.h | 8 ++++---- firmware/controllers/algo/event_registry.h | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/firmware/controllers/algo/accel_enrichment.h b/firmware/controllers/algo/accel_enrichment.h index 5eb953f33a..b7f9c508bb 100644 --- a/firmware/controllers/algo/accel_enrichment.h +++ b/firmware/controllers/algo/accel_enrichment.h @@ -54,11 +54,11 @@ private: /** * Used for Fractional TPS enrichment. */ - floatms_t accumulatedValue; - floatms_t maxExtraPerCycle; - floatms_t maxExtraPerPeriod; - floatms_t maxInjectedPerPeriod; - int cycleCnt; + floatms_t accumulatedValue = 0; + floatms_t maxExtraPerCycle = 0; + floatms_t maxExtraPerPeriod = 0; + floatms_t maxInjectedPerPeriod = 0; + int cycleCnt = 0; }; /** diff --git a/firmware/controllers/algo/engine_parts.h b/firmware/controllers/algo/engine_parts.h index 703bee557b..a702db499f 100644 --- a/firmware/controllers/algo/engine_parts.h +++ b/firmware/controllers/algo/engine_parts.h @@ -37,7 +37,7 @@ public: Accelerometer accelerometer; float vBatt = 0; - float currentAfr; + float currentAfr = 0; /** * that's fuel in tank - just a gauge */ @@ -131,7 +131,7 @@ private: struct multispark_state { - efitick_t delay; - efitick_t dwell; - uint8_t count; + efitick_t delay = 0; + efitick_t dwell = 0; + uint8_t count = 0; }; diff --git a/firmware/controllers/algo/event_registry.h b/firmware/controllers/algo/event_registry.h index b483208fc1..b80ff2f8c5 100644 --- a/firmware/controllers/algo/event_registry.h +++ b/firmware/controllers/algo/event_registry.h @@ -107,12 +107,12 @@ public: * Desired timing advance */ angle_t sparkAngle = NAN; - floatms_t sparkDwell; + floatms_t sparkDwell = 0; /** * this timestamp allows us to measure actual dwell time */ - uint32_t actualStartOfDwellNt; - event_trigger_position_s dwellPosition; + uint32_t actualStartOfDwellNt = 0; + event_trigger_position_s dwellPosition{}; /** * Sequential number of currently processed spark event * @see globalSparkIdCounter From ecbec68a52f931483513e8915459cac64680f834 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:23:03 -0700 Subject: [PATCH 04/16] explicit --- firmware/controllers/algo/airmass/airmass.h | 2 +- firmware/controllers/algo/airmass/alphan_airmass.h | 2 +- firmware/controllers/algo/airmass/maf_airmass.h | 2 +- firmware/controllers/algo/airmass/speed_density_airmass.h | 2 +- firmware/controllers/algo/airmass/speed_density_base.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/algo/airmass/airmass.h b/firmware/controllers/algo/airmass/airmass.h index b9c157a18a..a7b1491d45 100644 --- a/firmware/controllers/algo/airmass/airmass.h +++ b/firmware/controllers/algo/airmass/airmass.h @@ -12,7 +12,7 @@ struct AirmassResult { struct AirmassModelBase { DECLARE_ENGINE_PTR; - AirmassModelBase(const ValueProvider3D& veTable); + explicit AirmassModelBase(const ValueProvider3D& veTable); virtual AirmassResult getAirmass(int rpm) = 0; protected: diff --git a/firmware/controllers/algo/airmass/alphan_airmass.h b/firmware/controllers/algo/airmass/alphan_airmass.h index aeb0201a83..416b5eaa5f 100644 --- a/firmware/controllers/algo/airmass/alphan_airmass.h +++ b/firmware/controllers/algo/airmass/alphan_airmass.h @@ -4,7 +4,7 @@ class AlphaNAirmass : public SpeedDensityBase { public: - AlphaNAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {} + explicit AlphaNAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {} AirmassResult getAirmass(int rpm) override; }; diff --git a/firmware/controllers/algo/airmass/maf_airmass.h b/firmware/controllers/algo/airmass/maf_airmass.h index ac557bd084..6d270beac2 100644 --- a/firmware/controllers/algo/airmass/maf_airmass.h +++ b/firmware/controllers/algo/airmass/maf_airmass.h @@ -4,7 +4,7 @@ class MafAirmass final : public AirmassModelBase { public: - MafAirmass(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {} + explicit MafAirmass(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {} AirmassResult getAirmass(int rpm) override; diff --git a/firmware/controllers/algo/airmass/speed_density_airmass.h b/firmware/controllers/algo/airmass/speed_density_airmass.h index ab8ccad157..d59fb9804d 100644 --- a/firmware/controllers/algo/airmass/speed_density_airmass.h +++ b/firmware/controllers/algo/airmass/speed_density_airmass.h @@ -4,6 +4,6 @@ class SpeedDensityAirmass : public SpeedDensityBase { public: - SpeedDensityAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {} + explicit SpeedDensityAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {} AirmassResult getAirmass(int rpm) override; }; diff --git a/firmware/controllers/algo/airmass/speed_density_base.h b/firmware/controllers/algo/airmass/speed_density_base.h index 19f5136578..457953b316 100644 --- a/firmware/controllers/algo/airmass/speed_density_base.h +++ b/firmware/controllers/algo/airmass/speed_density_base.h @@ -15,7 +15,7 @@ float idealGasLaw(float volume, float pressure, float temperature); class SpeedDensityBase : public AirmassModelBase { protected: - SpeedDensityBase(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {} + explicit SpeedDensityBase(const ValueProvider3D& veTable) : AirmassModelBase(veTable) {} public: static float getAirmassImpl(float ve, float manifoldPressure, float temperature DECLARE_ENGINE_PARAMETER_SUFFIX); From e3472b42274bab5faa2186e76a4ac35fa70aa91b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:23:11 -0700 Subject: [PATCH 05/16] scope --- firmware/controllers/can/can_dash.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/firmware/controllers/can/can_dash.cpp b/firmware/controllers/can/can_dash.cpp index fdb0b78d2c..6ac82efea8 100644 --- a/firmware/controllers/can/can_dash.cpp +++ b/firmware/controllers/can/can_dash.cpp @@ -182,11 +182,9 @@ void canDashboardVAG(void) { } void canDashboardW202(void) { - - uint16_t tmp; { CanTxMessage msg(W202_STAT_1); - tmp = GET_RPM(); + uint16_t tmp = GET_RPM(); msg[0] = 0x08; // Unknown msg[1] = (tmp >> 8); //RPM msg[2] = (tmp & 0xff); //RPM From bbe7ac43dba27d4783842e2ff62a18b04195e3b2 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:29:55 -0700 Subject: [PATCH 06/16] misc --- firmware/controllers/engine_cycle/spark_logic.cpp | 2 -- firmware/controllers/sensors/converters/thermistor_func.h | 6 +++--- firmware/controllers/sensors/proxy_sensor.h | 2 +- firmware/controllers/sensors/sensor.cpp | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 5827e45ee8..adbc811848 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -191,8 +191,6 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) { { event->sparksRemaining--; - efitick_t nowNt = getTimeNowNt(); - efitick_t nextDwellStart = nowNt + engine->engineState.multispark.delay; efitick_t nextFiring = nextDwellStart + engine->engineState.multispark.dwell; diff --git a/firmware/controllers/sensors/converters/thermistor_func.h b/firmware/controllers/sensors/converters/thermistor_func.h index 98627b4e32..416ae9c751 100644 --- a/firmware/controllers/sensors/converters/thermistor_func.h +++ b/firmware/controllers/sensors/converters/thermistor_func.h @@ -20,7 +20,7 @@ public: private: // Steinhart-Hart coefficients - float m_a; - float m_b; - float m_c; + float m_a = 0; + float m_b = 0; + float m_c = 0; }; diff --git a/firmware/controllers/sensors/proxy_sensor.h b/firmware/controllers/sensors/proxy_sensor.h index 5518d4e108..257b4068b1 100644 --- a/firmware/controllers/sensors/proxy_sensor.h +++ b/firmware/controllers/sensors/proxy_sensor.h @@ -24,7 +24,7 @@ public: void showInfo(Logging* logger, const char* sensorName) const override; private: - SensorResult get() const { + SensorResult get() const override { return Sensor::get(m_proxiedSensor); } diff --git a/firmware/controllers/sensors/sensor.cpp b/firmware/controllers/sensors/sensor.cpp index c0127c5305..b328fe7bfb 100644 --- a/firmware/controllers/sensors/sensor.cpp +++ b/firmware/controllers/sensors/sensor.cpp @@ -51,7 +51,7 @@ bool Sensor::Register() { return false; } else { // put ourselves in the registry - s_sensorRegistry[getIndex()].sensor = this; + entry.sensor = this; return true; } } From fc112d2526d456db23d4837b8903ca44d8d3e056 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:32:48 -0700 Subject: [PATCH 07/16] dead code --- .../controllers/trigger/trigger_central.cpp | 1 - firmware/development/logic_analyzer.cpp | 1 - firmware/util/containers/data_buffer.c | 66 ------------------- firmware/util/containers/data_buffer.h | 24 ------- firmware/util/util.mk | 1 - 5 files changed, 93 deletions(-) delete mode 100644 firmware/util/containers/data_buffer.c delete mode 100644 firmware/util/containers/data_buffer.h diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index aa6d9d1404..7885379d87 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -14,7 +14,6 @@ #include "main_trigger_callback.h" #include "engine_configuration.h" #include "listener_array.h" -#include "data_buffer.h" #include "pwm_generator_logic.h" #include "tooth_logger.h" diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index 3cf7259b3a..322b6c5851 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -16,7 +16,6 @@ #include "global.h" #include "os_access.h" #include "eficonsole.h" -#include "data_buffer.h" #include "pin_repository.h" #include "allsensors.h" #include "engine_configuration.h" diff --git a/firmware/util/containers/data_buffer.c b/firmware/util/containers/data_buffer.c deleted file mode 100644 index 52f31bffe5..0000000000 --- a/firmware/util/containers/data_buffer.c +++ /dev/null @@ -1,66 +0,0 @@ -/*@ - * @file data_buffer.c - * - * @date Dec 8, 2012 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "data_buffer.h" - -int dbIsFull(data_buffer_s *db) { - return db->size == DB_MAX_SIZE; -} - -void dbClear(data_buffer_s *db) { - db->size = 0; -} - -void dbCopy(data_buffer_s *source, data_buffer_s *target) { - int s = source->size; - target->size = s; - for (int i = 0; i < s; i++) - target->elements[i] = source->elements[i]; -} - -void dbAdd(data_buffer_s *db, int value) { - if (db->size == DB_MAX_SIZE) - return; - int s = db->size; - db->elements[s] = value; - db->size = s + 1; -} - -int modp(int param) { - return param > EF_PERIOD ? param - EF_PERIOD : param; -} - -//void dbPrint(data_buffer_s *db, char *message, int withDiff) { -// int s = db->size; -// print("buffer [%s] size=%d\r\n", message, s); -// int range = db->elements[s - 1] - db->elements[0]; -// print("range %d\r\n", range); -// -// for (int i = 0; i < s; i++) { -// print("%d: %d", i, db->elements[i]); -// if (withDiff && i > 0) { -// int diff = modp(db->elements[i]) - modp(db->elements[i - 1]); -// print(" t=%d", diff); -// } -// print("\r\n"); -// } -//} - -//void dbPrintTable(data_buffer_s *table[], char *caption[], int columns) { -// for (int c = 0; c < columns; c++) -// print("%7s", caption[c]); -// print("\r\n"); -// -// for (int r = 0; r < DB_MAX_SIZE; r++) { -// for (int c = 0; c < columns; c++) { -// data_buffer_s *buf = table[c]; -// print("%7d", buf->elements[r]); -// } -// print("\r\n"); -// } -//} - diff --git a/firmware/util/containers/data_buffer.h b/firmware/util/containers/data_buffer.h deleted file mode 100644 index 6aedb0977a..0000000000 --- a/firmware/util/containers/data_buffer.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * data_buffer.h - * - * @date Dec 8, 2012 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#define DB_MAX_SIZE 1024 - -#define EF_PERIOD 100000000 - -typedef struct { - int elements[DB_MAX_SIZE]; - int size; -} data_buffer_s; - -int dbIsFull(data_buffer_s *db); -void dbClear(data_buffer_s *db); -void dbAdd(data_buffer_s *db, int value); -void dbCopy(data_buffer_s *source, data_buffer_s *target); -void dbPrint(data_buffer_s *db, char *message, int withDiff); -void dbPrintTable(data_buffer_s *table[], char *caption[], int columns); diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 9e75e589d7..4eb73569b0 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -1,7 +1,6 @@ UTIL_DIR=$(PROJECT_DIR)/util UTILSRC = \ - $(UTIL_DIR)/containers/data_buffer.c \ $(UTIL_DIR)/math/crc.c \ $(UTIL_DIR)/os_util.c \ $(UTIL_DIR)/histogram.c \ From 6d102fcdcadb86db7d9235829e9fe2420f96d6e3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:34:30 -0700 Subject: [PATCH 08/16] more dead --- firmware/util/math/avg_values.cpp | 60 ------------------------- firmware/util/math/avg_values.h | 27 ------------ firmware/util/math/signal_filtering.c | 63 --------------------------- firmware/util/math/signal_filtering.h | 22 ---------- firmware/util/util.mk | 1 - 5 files changed, 173 deletions(-) delete mode 100644 firmware/util/math/avg_values.cpp delete mode 100644 firmware/util/math/avg_values.h delete mode 100644 firmware/util/math/signal_filtering.c delete mode 100644 firmware/util/math/signal_filtering.h diff --git a/firmware/util/math/avg_values.cpp b/firmware/util/math/avg_values.cpp deleted file mode 100644 index 17d78c3e8d..0000000000 --- a/firmware/util/math/avg_values.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * avg_values.c - * - * @date Jul 23, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "avg_values.h" -#include - -void avgFill(AvgTable *table, int count, float value) { - for (int i = 0; i < AVG_TAB_SIZE; i++) { - for (int j = 0; j < AVG_TAB_SIZE; j++) { - table->counts[i][j] = count; - table->values[i][j] = value; - } - } -} - -void avgReset(AvgTable *table) { - avgFill(table, 0, 0); -} - -void avgAddValue(AvgTable *table, int rpm, float key, float value) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - - table->values[i][j] += value; - table->counts[i][j]++; -} - -float avgGetValueByIndexes(AvgTable *table, int i, int j) { - int count = table->counts[i][j]; - if (count == 0) { - return NAN; - } - return table->values[i][j] / count; -} - -float avgGetValue(AvgTable *table, int rpm, float key) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return NAN; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - return avgGetValueByIndexes(table, i, j); -} - -int avgGetValuesCount(AvgTable *table, int rpm, float key) { - if (rpm >= MAX_RPM || key >= MAX_KEY) { - return 0; - } - int i = (int)(AVG_TAB_SIZE * rpm / MAX_RPM); - int j = (int)(AVG_TAB_SIZE * key / MAX_KEY); - - return table->counts[i][j]; -} diff --git a/firmware/util/math/avg_values.h b/firmware/util/math/avg_values.h deleted file mode 100644 index c7e4133662..0000000000 --- a/firmware/util/math/avg_values.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * avg_values.h - * - * @date Jul 23, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#define AVG_TAB_SIZE 48 - -#define MAX_RPM 8000 -#define MAX_KEY 5 - -typedef struct { - float values[AVG_TAB_SIZE][AVG_TAB_SIZE]; - int counts[AVG_TAB_SIZE][AVG_TAB_SIZE]; -} AvgTable; - - -void avgReset(AvgTable *table); -void avgFill(AvgTable *table, int count, float value); - -void avgAddValue(AvgTable *table, int rpm, float key, float value); -float avgGetValueByIndexes(AvgTable *table, int i, int j); -float avgGetValue(AvgTable *table, int rpm, float key); -int avgGetValuesCount(AvgTable *table, int rpm, float key); diff --git a/firmware/util/math/signal_filtering.c b/firmware/util/math/signal_filtering.c deleted file mode 100644 index 3b8454954b..0000000000 --- a/firmware/util/math/signal_filtering.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * @file signal_filtering.c - * - * @date Aug 5, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#ifndef SIGNAL_FILTERING_C_ -#define SIGNAL_FILTERING_C_ - -#include "signal_filtering.h" - -void sfInit(SignalFiltering *fs, float K, float initialValue) { - fs->pointer = 0; - fs->K = K; - fs->Vout = initialValue; - fs->Vacc = initialValue * K; -} - -static void addCopyAndSort(SignalFiltering *fs, float value) { - fs->values[fs->pointer] = value; - fs->pointer = ++fs->pointer == FILTER_SIZE ? 0 : fs->pointer; - - copyArray(fs->sorted, fs->values); - - for (int i = 0; i < FILTER_SIZE; i++) - for (int j = i + 1; j < FILTER_SIZE; j++) - if (fs->sorted[i] < fs->sorted[j]) { - float temp = fs->sorted[i]; - fs->sorted[i] = fs->sorted[j]; - fs->sorted[j] = temp; - } -} - -void sfAddValue(SignalFiltering *fs, float value) { - addCopyAndSort(fs, value); - float Vin = fs->sorted[FILTER_SIZE / 2]; - - fs->Vacc += Vin - fs->Vout; - fs->Vout = fs->Vacc / fs->K; -} - -void sfAddValue2(SignalFiltering *fs, float value) { - addCopyAndSort(fs, value); - - int fromIndex = FILTER_SIZE / 4; - int toIndex = FILTER_SIZE / 4 + FILTER_SIZE / 2; - - /** - * this implementation takes the average of the middle hald of the sorted values - */ - float result = 0; - for (int i = fromIndex; i < toIndex; i++) - result += fs->sorted[i]; - - fs->Vout = result / (FILTER_SIZE / 2); -} - -float sfGetValue(SignalFiltering *fs) { - return fs->Vout; -} - -#endif /* SIGNAL_FILTERING_C_ */ diff --git a/firmware/util/math/signal_filtering.h b/firmware/util/math/signal_filtering.h deleted file mode 100644 index 01df176e19..0000000000 --- a/firmware/util/math/signal_filtering.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * @file signal_filtering.h - * - * @date Aug 5, 2013 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#define FILTER_SIZE 5 - -typedef struct { - float values[FILTER_SIZE]; - float sorted[FILTER_SIZE]; - int pointer; - float K, Vacc, Vout; -} SignalFiltering; - -void sfInit(SignalFiltering *fs, float K, float initialValue); -void sfAddValue(SignalFiltering *fs, float value); -void sfAddValue2(SignalFiltering *fs, float value); -float sfGetValue(SignalFiltering *fs); diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 4eb73569b0..699aff16de 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -13,7 +13,6 @@ UTILSRC_CPP = \ $(UTIL_DIR)/containers/local_version_holder.cpp \ $(UTIL_DIR)/containers/table_helper.cpp \ $(UTIL_DIR)/math/pid.cpp \ - $(UTIL_DIR)/math/avg_values.cpp \ $(UTIL_DIR)/math/interpolation.cpp \ $(PROJECT_DIR)/util/datalogging.cpp \ $(PROJECT_DIR)/util/loggingcentral.cpp \ From 5e7585501cf9909a819a40edeb1e974eb821a729 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:36:47 -0700 Subject: [PATCH 09/16] even more dead --- firmware/util/unaligned.c | 113 -------------------------------------- firmware/util/unaligned.h | 105 ----------------------------------- firmware/util/util.mk | 3 +- 3 files changed, 1 insertion(+), 220 deletions(-) delete mode 100644 firmware/util/unaligned.c delete mode 100644 firmware/util/unaligned.h diff --git a/firmware/util/unaligned.c b/firmware/util/unaligned.c deleted file mode 100644 index 977abdcaf1..0000000000 --- a/firmware/util/unaligned.c +++ /dev/null @@ -1,113 +0,0 @@ -/** - * @file unaligned.c - * @brief unaligned data access helpers - * - * @date May, 2019 - * @author Andrey Gusakov, (c) 2019 - * - * This file is part of rusEfi - see http://rusefi.com - * - * rusEfi is free software; you can redistribute it and/or modify it under the terms of - * the GNU General Public License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. - * If not, see . - */ - -#include "unaligned.h" -#include "common.h" - -/* generate mask */ -static inline uint32_t bit_mask(unsigned int from, unsigned int to) -{ - uint32_t mask = 0; - uint32_t shift; - - if (to < from) - return 0; - - shift = to - from + 1U; - - if ((shift > 0U) && (shift <= 32U) && (from <= 31U)) { - if (shift < 32U) { - mask = (uint32_t)((1UL << shift) - 1UL); - mask = mask << from; - } else { - mask = 0xFFFFFFFFUL; - } - } - - return mask; -} - -/* get upto 32 bits from char array p, from bit position pos, lenght len */ -uint32_t bits_get(uint8_t *p, unsigned int pos, int len) -{ - int i; - unsigned int offset = 0; - uint32_t res = 0; - - i = (int)pos / 8; - - while (len > 0) { - uint32_t tmp; - uint32_t mask; - int nbits = 8 - ((int)pos % 8); - - /* get */ - tmp = (uint32_t)p[i]; - /* shift */ - tmp = tmp >> (8U - (uint32_t)nbits); - /* mask */ - mask = bit_mask(0, MIN((uint32_t)len - 1U, (uint32_t)nbits - 1U)); - tmp = tmp & mask; - res = res | ((tmp) << offset); - - /* adjust for the next iteration */ - offset += (unsigned int)nbits; - len -= nbits; - pos += (unsigned int)nbits; - i++; - } - return res; -} - -/* set upto 32 bits in char array p, from bit position pos, lenght len */ -void bits_set(uint8_t *p, unsigned int pos, int len, uint32_t val) -{ - int i; - unsigned int offset = 0; - - i = (int)pos / 8; - - while (len > 0) { - uint32_t tmp; - uint32_t mask; - - /* get number of bits to shift to get to the target range */ - int shift = (int)pos % 8; - /* get next byte */ - tmp = (val >> offset) & 0xffU; - /* shift temporary value to the start of the target range */ - tmp = tmp << (uint8_t)shift; - /* calculate mask */ - mask = bit_mask((uint32_t)shift, MIN(8U - 1U, (unsigned int)shift + (unsigned int)len - 1U)); - /* clean all bits outside of the target range */ - tmp &= mask; - /* pre-clean all target bits */ - p[i] = p[i] & ~((uint8_t)mask); - /* finally set active bits */ - p[i] |= (uint8_t)tmp; - - /* adjust for the next iteration */ - offset += ((uint32_t)8U - (uint32_t)shift); - len -= (8 - shift); - pos += ((unsigned int)8U - (unsigned int)shift); - i++; - } -} diff --git a/firmware/util/unaligned.h b/firmware/util/unaligned.h deleted file mode 100644 index 2b1a11217f..0000000000 --- a/firmware/util/unaligned.h +++ /dev/null @@ -1,105 +0,0 @@ -/** - * @file unaligned.h - * @brief unaligned data access helpers header file - * - * @date May, 2019 - * @author Andrey Gusakov, (c) 2019 - * - * This file is part of rusEfi - see http://rusefi.com - * - * rusEfi is free software; you can redistribute it and/or modify it under the terms of - * the GNU General Public License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without - * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. - * If not, see . - */ - -#ifndef UNALIGNED_H_INCLUDED -#define UNALIGNED_H_INCLUDED - -#include - -/* bit operations */ -uint32_t bits_get(uint8_t *p, unsigned int pos, int len); -void bits_set(uint8_t *p, unsigned int pos, int len, uint32_t val); -#define bit_set(p, pos) do {(p)[(pos) / 8] |= (1 << ((pos) % 8));} while(0) -#define bit_clr(p, pos) do {(p)[(pos) / 8] &= ~(1 << ((pos) % 8));} while(0) -#define bit_get(p, pos) (!!((p)[(pos) / 8] & (1 << ((pos) % 8)))) - -/* unaligned access */ -static inline void put_be8(uint8_t *p, uint8_t v) -{ - p[0] = v; -} - -static inline void put_le8(uint8_t *p, uint8_t v) -{ - p[0] = v; -} - -static inline void put_be16(uint8_t *p, uint16_t v) -{ - p[0] = (uint8_t)(v >> 8); - p[1] = (uint8_t)(v >> 0); -} - -static inline void put_le16(uint8_t *p, uint16_t v) -{ - p[0] = (uint8_t)(v >> 0); - p[1] = (uint8_t)(v >> 8); -} - -static inline void put_be32(uint8_t *p, uint32_t v) -{ - p[0] = (uint8_t)(v >> 24); - p[1] = (uint8_t)(v >> 16); - p[2] = (uint8_t)(v >> 8); - p[3] = (uint8_t)(v >> 0); -} - -static inline void put_le32(uint8_t *p, uint32_t v) -{ - p[0] = (uint8_t)(v >> 0); - p[1] = (uint8_t)(v >> 8); - p[2] = (uint8_t)(v >> 16); - p[3] = (uint8_t)(v >> 24); -} - -static inline uint8_t get_be8(uint8_t *p) -{ - return p[0]; -} - -static inline uint8_t get_le8(uint8_t *p) -{ - return p[0]; -} - -static inline uint16_t get_be16(uint8_t *p) -{ - return ((uint16_t)p[0] << 8) | p[1]; -} - -static inline uint16_t get_le16(uint8_t *p) -{ - return ((uint16_t)p[1] << 8) | p[0]; -} - -static inline uint32_t get_be32(uint8_t *p) -{ - return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | - ((uint32_t)p[2] << 8) | p[3]; -} - -static inline uint32_t get_le32(uint8_t *p) -{ - return ((uint32_t)p[3] << 24) | ((uint32_t)p[2] << 16) | - ((uint32_t)p[1] << 8) | p[0]; -} - -#endif /* UNALIGNED_H_INCLUDED */ diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 699aff16de..c227e632d9 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -3,8 +3,7 @@ UTIL_DIR=$(PROJECT_DIR)/util UTILSRC = \ $(UTIL_DIR)/math/crc.c \ $(UTIL_DIR)/os_util.c \ - $(UTIL_DIR)/histogram.c \ - $(UTIL_DIR)/unaligned.c + $(UTIL_DIR)/histogram.c UTILSRC_CPP = \ $(UTIL_DIR)/containers/cyclic_buffer.cpp \ From aac641b1f45acd5eca2eecbe49ebe40f9e1b8656 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:40:10 -0700 Subject: [PATCH 10/16] don't use register keyword --- firmware/util/datalogging.cpp | 2 +- firmware/util/efilib.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index d91f78a50a..1ea4f121cb 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -112,7 +112,7 @@ void append(Logging *logging, const char *text) { * @note This method if fast because it does not validate much, be sure what you are doing */ void appendFast(Logging *logging, const char *text) { - register char *s; + char *s; s = logging->linePointer; while ((*s++ = *text++) != 0) ; diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index b35322bab8..f50ae7cb5a 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -64,7 +64,7 @@ float clampF(float min, float clamp, float max) { } uint32_t efiStrlen(const char *param) { - register const char *s; + const char *s; for (s = param; *s; ++s) ; return (s - param); From cd62774be19b42c6a11ae5630e79aec90f262e5c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:45:30 -0700 Subject: [PATCH 11/16] dead --- firmware/controllers/system/timer/event_queue.cpp | 3 --- firmware/controllers/system/timer/event_queue.h | 1 - 2 files changed, 4 deletions(-) diff --git a/firmware/controllers/system/timer/event_queue.cpp b/firmware/controllers/system/timer/event_queue.cpp index 7efc24c3e6..c69397c532 100644 --- a/firmware/controllers/system/timer/event_queue.cpp +++ b/firmware/controllers/system/timer/event_queue.cpp @@ -25,9 +25,6 @@ extern bool verboseMode; uint32_t maxSchedulingPrecisionLoss = 0; -bool EventQueue::checkIfPending(scheduling_s *scheduling) { - assertNotInListMethodBody(scheduling_s, head, scheduling, nextScheduling_s); -} /** * @return true if inserted into the head of the list diff --git a/firmware/controllers/system/timer/event_queue.h b/firmware/controllers/system/timer/event_queue.h index ffda221811..f16939e7e9 100644 --- a/firmware/controllers/system/timer/event_queue.h +++ b/firmware/controllers/system/timer/event_queue.h @@ -64,7 +64,6 @@ public: scheduling_s * getHead(); void assertListIsSorted() const; private: - bool checkIfPending(scheduling_s *scheduling); /** * this list is sorted */ From 93d631b9115f86000ff3e55e1337f07ce020c113 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:45:39 -0700 Subject: [PATCH 12/16] init & override --- firmware/controllers/system/dc_motor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/controllers/system/dc_motor.h b/firmware/controllers/system/dc_motor.h index 51e64e9c28..fdf6272d28 100644 --- a/firmware/controllers/system/dc_motor.h +++ b/firmware/controllers/system/dc_motor.h @@ -77,7 +77,7 @@ private: OutputPin* const m_disable; float m_value = 0; - ControlType m_type; + ControlType m_type = ControlType::PwmDirectionPins; public: /** * @param enable SimplePwm driver for enable pin, for PWM speed control. @@ -90,8 +90,8 @@ public: float get() const override; bool isOpenDirection() const override; - void enable(); - void disable(); + void enable() override; + void disable() override; void setType(ControlType type) { m_type = type; } }; From 1f221043ed2b6d07d9650a51fe03297a6fac9cd3 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:49:23 -0700 Subject: [PATCH 13/16] shadowed --- firmware/hw_layer/serial_over_usb/usbcfg.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/firmware/hw_layer/serial_over_usb/usbcfg.c b/firmware/hw_layer/serial_over_usb/usbcfg.c index ae34ee5092..f74fad8d5d 100644 --- a/firmware/hw_layer/serial_over_usb/usbcfg.c +++ b/firmware/hw_layer/serial_over_usb/usbcfg.c @@ -268,8 +268,6 @@ static const USBEndpointConfig ep2config = { * Handles the USB driver global events. */ static void usb_event(USBDriver *usbp, usbevent_t event) { - extern SerialUSBDriver SDU1; - switch (event) { case USB_EVENT_ADDRESS: return; From 727f6e78baabe685ececc14e689c87f134ddd583 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:49:31 -0700 Subject: [PATCH 14/16] explicit --- firmware/hw_layer/drivers/can/can_msg_tx.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/hw_layer/drivers/can/can_msg_tx.h b/firmware/hw_layer/drivers/can/can_msg_tx.h index 00ed7da8a5..2ac51fe22c 100644 --- a/firmware/hw_layer/drivers/can/can_msg_tx.h +++ b/firmware/hw_layer/drivers/can/can_msg_tx.h @@ -28,7 +28,7 @@ public: /** * Create a new CAN message, with the specified extended ID. */ - CanTxMessage(uint32_t eid, uint8_t dlc = 8); + explicit CanTxMessage(uint32_t eid, uint8_t dlc = 8); /** * Destruction of an instance of CanTxMessage will transmit the message over the wire. @@ -71,7 +71,7 @@ class CanTxTyped final : public CanTxMessage static_assert(sizeof(TData) == sizeof(CANTxFrame::data8)); public: - CanTxTyped(uint32_t eid) : CanTxMessage(eid) { } + explicit CanTxTyped(uint32_t eid) : CanTxMessage(eid) { } /** * Access members of the templated type. From 8508be5ebdc46b764d50903fef9b6333d3ab9e1a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:49:37 -0700 Subject: [PATCH 15/16] dead --- firmware/hw_layer/hardware.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 8b6138f705..2ebcd3c299 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -149,15 +149,6 @@ static I2CConfig i2cfg = { HAL_I2C_F7_100_TIMINGR, 0, 0 }; // todo: does it work static I2CConfig i2cfg = { OPMODE_I2C, 100000, STD_DUTY_CYCLE, }; #endif /* defined(STM32F4XX) */ -void initI2Cmodule(void) { - print("Starting I2C module\r\n"); - i2cInit(); - i2cStart(&I2CD1, &i2cfg); - - efiSetPadMode("I2C clock", EFI_I2C_SCL_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN); - efiSetPadMode("I2C data", EFI_I2C_SDA_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN); -} - //static char txbuf[1]; static void sendI2Cbyte(int addr, int data) { @@ -474,7 +465,6 @@ void initHardware(Logging *l) { initSingleTimerExecutorHardware(); #if EFI_HD44780_LCD -// initI2Cmodule(); lcd_HD44780_init(sharedLogger); if (hasFirmwareError()) return; From cd696acbe2d99720ca97f720154fce7d9427ae2b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 29 Jul 2020 02:50:23 -0700 Subject: [PATCH 16/16] init --- firmware/hw_layer/stepper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/hw_layer/stepper.h b/firmware/hw_layer/stepper.h index 128afc6dc6..b79aa431ce 100644 --- a/firmware/hw_layer/stepper.h +++ b/firmware/hw_layer/stepper.h @@ -49,8 +49,8 @@ public: void step(bool positive) override; private: - DcMotor* m_motorPhaseA; - DcMotor* m_motorPhaseB; + DcMotor* m_motorPhaseA = nullptr; + DcMotor* m_motorPhaseB = nullptr; uint8_t m_phase = 0; };