From 0ceb38dd07b27c48237d969c07ec39908f56ff7e Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 8 Sep 2014 17:02:52 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/engine_controller.cpp | 8 ++++++++ firmware/controllers/trigger/trigger_central.cpp | 2 +- firmware/controllers/trigger/trigger_central.h | 3 ++- firmware/hw_layer/hardware.cpp | 13 +++++++------ firmware/hw_layer/hardware.h | 5 ++++- firmware/rusefi.cpp | 5 +++-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 737ff0b4ae..1fa73917d3 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -58,6 +58,11 @@ extern board_configuration_s *boardConfiguration; persistent_config_container_s persistentState CCM_OPTIONAL ; +/** + * todo: it really looks like these fields should become 'static', i.e. private + * the whole 'extern ...' pattern is less then perfect, I guess the 'God object' Engine + * would be a smaller evil. Whatever is needed should be passed into methods/modules/files as an explicit parameter. + */ engine_configuration_s *engineConfiguration = &persistentState.persistentConfiguration.engineConfiguration; board_configuration_s *boardConfiguration = &persistentState.persistentConfiguration.engineConfiguration.bc; @@ -79,6 +84,9 @@ static configuration_s cfg = { &persistentState.persistentConfiguration.engineCo configuration_s * configuration = &cfg; +/** + * todo: this should probably become 'static', i.e. private, and propagated around explicitly? + */ Engine engine; static msg_t csThread(void) { diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index a6dba5fea8..ccf4e741de 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -219,7 +219,7 @@ float getTriggerDutyCycle(int index) { return triggerCentral.triggerState.getTriggerDutyCycle(index); } -void initTriggerCentral(void) { +void initTriggerCentral(Engine *engine) { strcpy((char*) shaft_signal_msg_index, "_"); #if EFI_WAVE_CHART diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index 765a480f0a..cc0e12c2cf 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -16,6 +16,7 @@ typedef void (*ShaftPositionListener)(trigger_event_e signal, int index, void *a #ifdef __cplusplus #include "ec2.h" +#include "engine.h" #define HW_EVENT_TYPES 6 @@ -36,7 +37,7 @@ uint64_t getCrankEventCounter(void); uint64_t getStartOfRevolutionIndex(void); void hwHandleShaftSignal(trigger_event_e signal); float getTriggerDutyCycle(int index); -void initTriggerCentral(void); +void initTriggerCentral(Engine *engine); void printAllCallbacksHistogram(void); #ifdef __cplusplus diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 691011a22b..d3396b71ef 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -39,9 +39,7 @@ #include "engine_configuration.h" #include "ec2.h" -extern engine_configuration_s *engineConfiguration; extern engine_configuration2_s * engineConfiguration2; -extern board_configuration_s *boardConfiguration; static bool isSpiInitialized[5] = { false, false, false, false, false }; @@ -103,7 +101,7 @@ void turnOnSpi(spi_device_e device) { } } -void initSpiModules(void) { +static void initSpiModules(board_configuration_s *boardConfiguration) { if (boardConfiguration->is_enabled_spi_2) { turnOnSpi(SPI_DEVICE_2); } @@ -134,7 +132,10 @@ static void sendI2Cbyte(int addr, int data) { // i2cReleaseBus(&I2CD1); } -void initHardware(Logging *logger) { +void initHardware(Logging *logger, Engine *engine) { + engine_configuration_s *engineConfiguration = engine->engineConfiguration; + board_configuration_s *boardConfiguration = &engineConfiguration->bc; + printMsg(logger, "initHardware()"); // todo: enable protection. it's disabled because it takes // 10 extra seconds to re-flash the chip @@ -211,13 +212,13 @@ void initHardware(Logging *logger) { // requestAdcValue(&adcState, 0); // todo: figure out better startup logic - initTriggerCentral(); + initTriggerCentral(engine); #if EFI_SHAFT_POSITION_INPUT initShaftPositionInputCapture(); #endif /* EFI_SHAFT_POSITION_INPUT */ - initSpiModules(); + initSpiModules(boardConfiguration); #if EFI_FILE_LOGGING initMmcCard(); diff --git a/firmware/hw_layer/hardware.h b/firmware/hw_layer/hardware.h index 7b53155820..a62fd766e1 100644 --- a/firmware/hw_layer/hardware.h +++ b/firmware/hw_layer/hardware.h @@ -25,6 +25,9 @@ void unlockSpi(void); #define GET_BOARD_TEST_MODE_VALUE() (!palReadPad(getHwPort(boardConfiguration->boardTestModeJumperPin), getHwPin(boardConfiguration->boardTestModeJumperPin))) -void initHardware(Logging *logging); +#ifdef __cplusplus +#include "engine.h" +void initHardware(Logging *logging, Engine *engine); +#endif /* __cplusplus */ #endif /* HARDWARE_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 206a9f5c0b..fecdf037fd 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -120,6 +120,7 @@ static MemoryStream firmwareErrorMessageStream; uint8_t errorMessageBuffer[200]; static bool hasFirmwareErrorFlag = FALSE; extern board_configuration_s *boardConfiguration; +extern Engine engine; char *getFirmwareError(void) { return (char*)errorMessageBuffer; @@ -146,7 +147,7 @@ void runRusEfi(void) { /** * Initialize hardware drivers */ - initHardware(&logging); + initHardware(&logging, &engine); initStatusLoop(); /** @@ -229,5 +230,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20140907; + return 20140908; }