diff --git a/firmware/controllers/math/config_engine_specs.h b/firmware/controllers/math/config_engine_specs.h new file mode 100644 index 0000000000..403aa77a25 --- /dev/null +++ b/firmware/controllers/math/config_engine_specs.h @@ -0,0 +1,39 @@ +/* + * @file config_engine_specs.h + * + * @date Jan 28, 2019 + * @author Andrey Belomutskiy, (c) 2012-2019 + */ + +#ifndef CONTROLLERS_MATH_CONFIG_ENGINE_SPECS_H_ +#define CONTROLLERS_MATH_CONFIG_ENGINE_SPECS_H_ + +#include "global.h" + +/** + * All these scary macro are about three goals: + * 1) performance optimization: real ECU hardware firmware should access configuration via direct global variable access without any pointers + * 2) design enforcement: unit tests should access configuration via pointers, NOT via global variables + * 3) design enforcement: user code should take special considerations in order to access specific group of configuration and not have access to complete configuration by default + */ + +#if EFI_UNIT_TEST +#define DECLARE_GLOBAL_SIGNATURE Engine *engine, engine_configuration_s *___engineConfiguration, persistent_config_s *config, board_configuration_s *boardConfiguration +#define DECLARE_GLOBAL_SUFFIX , DECLARE_GLOBAL_SIGNATURE +#define PASS_GLOBAL_SIGNATURE engine, ___engineConfiguration, config, boardConfiguration +#define PASS_GLOBAL_SUFFIX , PASS_GLOBAL_SIGNATURE +#define CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(x) ___engineConfiguration->x +#else /* EFI_UNIT_TEST */ +#define DECLARE_GLOBAL_SIGNATURE void +// Use this version of the macro as the suffix if method has other parameters +#define DECLARE_GLOBAL_SUFFIX +// Pass this if only magic references are needed +#define PASS_GLOBAL_SIGNATURE +// Pass this after some other parameters are passed +#define PASS_GLOBAL_SUFFIX +#define CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(x) persistentState.persistentConfiguration.engineConfiguration.x +#endif /* EFI_UNIT_TEST */ + +#define get_operationMode CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(operationMode) + +#endif /* CONTROLLERS_MATH_CONFIG_ENGINE_SPECS_H_ */ diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 5913241679..c450110f78 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -28,12 +28,13 @@ #include "efiGpio.h" #include "fuel_math.h" #include "advance_map.h" +#include "config_engine_specs.h" EXTERN_ENGINE ; -floatms_t getEngineCycleDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { - return getCrankshaftRevolutionTimeMs(rpm) * (engineConfiguration->operationMode == TWO_STROKE ? 1 : 2); +floatms_t getEngineCycleDuration(int rpm DECLARE_GLOBAL_SUFFIX) { + return getCrankshaftRevolutionTimeMs(rpm) * (get_operationMode == TWO_STROKE ? 1 : 2); } /**