From 89e6a3354539e07bf500995508ef9926334cf11f Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 27 Feb 2020 01:32:26 -0500 Subject: [PATCH] giving C code access to CONFIG --- .../controllers/algo/engine_configuration.h | 11 +------- .../algo/persistent_configuration.h | 19 +++++++++++++ firmware/controllers/global_shared.h | 27 ++++++++++++------- 3 files changed, 37 insertions(+), 20 deletions(-) create mode 100644 firmware/controllers/algo/persistent_configuration.h diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 97ed15c0da..5b98393966 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -8,9 +8,7 @@ #pragma once -#include "globalaccess.h" -#include "crc.h" -#include "engine_configuration_generated_structures.h" +#include "persistent_configuration.h" #ifndef DEFAULT_ENGINE_TYPE #define DEFAULT_ENGINE_TYPE DEFAULT_FRANKENSO @@ -26,13 +24,6 @@ float getRpmMultiplier(operation_mode_e mode); void setOperationMode(engine_configuration_s *engineConfiguration, operation_mode_e mode); -typedef struct { - int version; - int size; - persistent_config_s persistentConfiguration; - crc_t value; -} persistent_config_container_s; - void prepareVoidConfiguration(engine_configuration_s *activeConfiguration); void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX); int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/algo/persistent_configuration.h b/firmware/controllers/algo/persistent_configuration.h new file mode 100644 index 0000000000..041a76da14 --- /dev/null +++ b/firmware/controllers/algo/persistent_configuration.h @@ -0,0 +1,19 @@ +/* + * @file persistent_configuration.h + * + * @date Feb 27, 2020 + * @author Andrey Belomutskiy, (c) 2012-2020 + */ + +#pragma once + +#include "globalaccess.h" +#include "crc.h" +#include "engine_configuration_generated_structures.h" + +typedef struct { + int version; + int size; + persistent_config_s persistentConfiguration; + crc_t value; +} persistent_config_container_s; diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h index 313414ad84..21bf5e8b60 100644 --- a/firmware/controllers/global_shared.h +++ b/firmware/controllers/global_shared.h @@ -32,10 +32,24 @@ #define EXTERN_CONFIG \ extern engine_configuration_s *engineConfiguration; \ - extern engine_configuration_s & activeConfiguration; \ + extern engine_configuration_s activeConfiguration; \ extern persistent_config_container_s persistentState; \ extern persistent_config_s *config; \ + +/** + * this macro allows the compiled to figure out the complete static address, that's a performance + * optimization which is hopefully useful at least for anything trigger-related + * + * this is related to the fact that for unit tests we prefer to explicitly pass references in method signature thus code covered by + * unit tests would need to use by-reference access. These macro allow us to have faster by-address access in real firmware and by-reference + * access in unit tests + */ +#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x + + +#ifdef __cplusplus + #define EXTERN_ENGINE \ extern Engine ___engine; \ extern Engine *engine; \ @@ -58,15 +72,6 @@ #define PASS_CONFIG_PARAMETER_SIGNATURE #define PASS_CONFIG_PARAMETER_SUFFIX -/** - * this macro allows the compiled to figure out the complete static address, that's a performance - * optimization which is hopefully useful at least for anything trigger-related - * - * this is related to the fact that for unit tests we prefer to explicitly pass references in method signature thus code covered by - * unit tests would need to use by-reference access. These macro allow us to have faster by-address access in real firmware and by-reference - * access in unit tests - */ -#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x #define ENGINE(x) ___engine.x #define DEFINE_CONFIG_PARAM(x, y) @@ -74,3 +79,5 @@ #define PASS_CONFIG_PARAM(x) #define EXPECTED_REMAINING_STACK 128 + +#endif /* __cplusplus */