diff --git a/firmware/auxout.cpp b/firmware/auxout.cpp index e6f952a..380a78c 100644 --- a/firmware/auxout.cpp +++ b/firmware/auxout.cpp @@ -141,15 +141,15 @@ static float AuxGetInputSignal(int sel) static THD_WORKING_AREA(waAuxOutThread, 256); void AuxOutThread(void*) { - const auto& cfg = GetConfiguration(); + const auto cfg = GetConfiguration(); while(1) { for (int ch = 0; ch < AFR_CHANNELS; ch++) { auto cfg = GetConfiguration(); - float input = AuxGetInputSignal(cfg.auxInput[ch]); - float voltage = interpolate2d(input, cfg.auxOutBins[ch], cfg.auxOutValues[ch]); + float input = AuxGetInputSignal(cfg->auxInput[ch]); + float voltage = interpolate2d(input, cfg->auxOutBins[ch], cfg->auxOutValues[ch]); SetAuxDac(ch, voltage); } diff --git a/firmware/boards/f0_module/port.cpp b/firmware/boards/f0_module/port.cpp index 4bd360a..322f7f5 100644 --- a/firmware/boards/f0_module/port.cpp +++ b/firmware/boards/f0_module/port.cpp @@ -97,7 +97,7 @@ int InitConfiguration() static Configuration c; -Configuration& GetConfiguration() +Configuration* GetConfiguration() { const auto& cfg = __configflash__start__; @@ -129,10 +129,10 @@ Configuration& GetConfiguration() default: break; } - return c; + return &c; } -void SetConfiguration(const Configuration& newConfig) +void SetConfiguration() { // erase config page Flash::ErasePage(31); @@ -140,7 +140,7 @@ void SetConfiguration(const Configuration& newConfig) // Copy data to flash Flash::Write( reinterpret_cast(&__configflash__start__), - reinterpret_cast(&newConfig), + reinterpret_cast(&c), sizeof(Configuration) ); } diff --git a/firmware/boards/f1_common/f1_port.cpp b/firmware/boards/f1_common/f1_port.cpp index a6ec047..846a7e0 100644 --- a/firmware/boards/f1_common/f1_port.cpp +++ b/firmware/boards/f1_common/f1_port.cpp @@ -52,17 +52,13 @@ int InitConfiguration() return 0; } -static Configuration c; - -Configuration& GetConfiguration() +Configuration* GetConfiguration() { - return cfg; + return &cfg; } -void SetConfiguration(const Configuration& newConfig) +void SetConfiguration() { - cfg = newConfig; - SaveConfiguration(); } diff --git a/firmware/boards/port.h b/firmware/boards/port.h index 3c5be0a..398f721 100644 --- a/firmware/boards/port.h +++ b/firmware/boards/port.h @@ -48,8 +48,8 @@ public: }; int InitConfiguration(); -Configuration& GetConfiguration(); -void SetConfiguration(const Configuration& newConfig); +Configuration* GetConfiguration(); +void SetConfiguration(); /* TS stuff */ uint8_t *GetConfiguratiuonPtr(); diff --git a/firmware/can.cpp b/firmware/can.cpp index 66c92fd..027286b 100644 --- a/firmware/can.cpp +++ b/firmware/can.cpp @@ -12,14 +12,14 @@ // this same header is imported by rusEFI to get struct layouts and firmware version #include "../for_rusefi/wideband_can.h" -Configuration configuration; +static Configuration* configuration; static THD_WORKING_AREA(waCanTxThread, 256); void CanTxThread(void*) { while(1) { - SendRusefiFormat(configuration.CanIndexOffset); + SendRusefiFormat(configuration->CanIndexOffset); chThdSleepMilliseconds(10); } @@ -100,10 +100,9 @@ void CanRxThread(void*) // Check if it's an "index set" message else if (frame.DLC == 1 && frame.EID == WB_MSG_SET_INDEX) { - auto &newCfg = GetConfiguration(); - newCfg.CanIndexOffset = frame.data8[0]; - SetConfiguration(newCfg); configuration = GetConfiguration(); + configuration->CanIndexOffset = frame.data8[0]; + SetConfiguration(); SendAck(); } }