From ad7e36c228a0e028213c43e03c60471be0529fe4 Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 20 Nov 2019 01:35:08 -0500 Subject: [PATCH] refactoring --- firmware/controllers/actuators/lcd_controller.h | 9 ++------- firmware/controllers/algo/algo.cpp | 1 - firmware/controllers/algo/engine.h | 1 - firmware/controllers/algo/engine_configuration.h | 3 +-- firmware/controllers/core/common_headers.h | 9 +++++++-- firmware/controllers/global_shared.h | 9 ++++----- .../trigger/decoders/trigger_structure.h | 3 +-- firmware/controllers/trigger/rpm_calculator.h | 2 +- firmware/globalaccess.h | 8 ++++---- simulator/simulator/globalaccess.h | 6 ++---- unit_tests/global.h | 15 +-------------- unit_tests/globalaccess.h | 2 ++ 12 files changed, 25 insertions(+), 43 deletions(-) diff --git a/firmware/controllers/actuators/lcd_controller.h b/firmware/controllers/actuators/lcd_controller.h index d61dc4109e..0651ee07fa 100644 --- a/firmware/controllers/actuators/lcd_controller.h +++ b/firmware/controllers/actuators/lcd_controller.h @@ -2,17 +2,12 @@ * @file lcd_controller.h * * @date Aug 14, 2014 - * @author Andrey Belomutskiy, (c) 2012-2017 + * @author Andrey Belomutskiy, (c) 2012-2019 */ -#ifndef LCD_CONTROLLER_H_ -#define LCD_CONTROLLER_H_ - -#include "engine.h" +#pragma once #define MAX_LCD_WIDTH 20 void initLcdController(void); void updateHD44780lcd(void); - -#endif /* LCD_CONTROLLER_H_ */ diff --git a/firmware/controllers/algo/algo.cpp b/firmware/controllers/algo/algo.cpp index 8acc176909..c9043fa298 100644 --- a/firmware/controllers/algo/algo.cpp +++ b/firmware/controllers/algo/algo.cpp @@ -19,7 +19,6 @@ * If not, see . */ -#include "global.h" #include "globalaccess.h" #include "algo.h" #include "advance_map.h" diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 7f8693f9e0..c4ff7f42bf 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -7,7 +7,6 @@ #pragma once -#include "global.h" #include "globalaccess.h" #include "engine_state.h" #include "rpm_calculator.h" diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 77bf37654c..8d181683c1 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -9,10 +9,9 @@ #ifndef ENGINE_CONFIGURATION_H_ #define ENGINE_CONFIGURATION_H_ -#include "global.h" +#include "globalaccess.h" #include "crc.h" #include "engine_configuration_generated_structures.h" -#include "globalaccess.h" #ifndef DEFAULT_ENGINE_TYPE #define DEFAULT_ENGINE_TYPE DEFAULT_FRANKENSO diff --git a/firmware/controllers/core/common_headers.h b/firmware/controllers/core/common_headers.h index ee39ba40c1..aa1b846cb0 100644 --- a/firmware/controllers/core/common_headers.h +++ b/firmware/controllers/core/common_headers.h @@ -65,19 +65,24 @@ #define DISPLAY_SENSOR(x) {} #define DISPLAY_IF(x) x -#define DECLARE_ENGINE_PTR \ +#define DECLARE_ENGINE_PTR \ Engine *engine = nullptr; \ engine_configuration_s *engineConfiguration = nullptr; \ persistent_config_s *config = nullptr; \ board_configuration_s *boardConfiguration = nullptr; -#define INJECT_ENGINE_REFERENCE(x) \ +#define INJECT_ENGINE_REFERENCE(x) \ x.engine = engine; \ x.engineConfiguration = engineConfiguration; \ x.config = config; \ x.boardConfiguration = boardConfiguration; +#define EXPAND_Engine \ + engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr; \ + persistent_config_s *config = engine->config; \ + board_configuration_s *boardConfiguration = &engineConfiguration->bc; + #define isConfigurationChanged(x) (engineConfiguration->x != activeConfiguration.x) #endif /* CONTROLLERS_CORE_COMMON_HEADERS_H_ */ diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h index d5203d8cb0..956e0d59cb 100644 --- a/firmware/controllers/global_shared.h +++ b/firmware/controllers/global_shared.h @@ -1,5 +1,5 @@ /* - * global_shared.h + * @file global_shared.h * * part of global.h which is shared between firmware and simulator * See also common_headers.h @@ -8,8 +8,7 @@ * @author Andrey Belomutskiy, (c) 2012-2019 */ -#ifndef GLOBAL_SHARED_H_ -#define GLOBAL_SHARED_H_ +#pragma once /** * The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance @@ -25,6 +24,8 @@ * On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter */ +#include "global.h" + #define EXTERN_CONFIG \ extern engine_configuration_s *engineConfiguration; \ extern board_configuration_s *boardConfiguration; \ @@ -70,5 +71,3 @@ #define CONFIG_PARAM(x) CONFIG(x) #define PASS_CONFIG_PARAM(x) - -#endif /* GLOBAL_SHARED_H_ */ diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index d3cb3e1c0c..b83f126406 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -8,10 +8,9 @@ #ifndef TRIGGER_STRUCTURE_H_ #define TRIGGER_STRUCTURE_H_ -#include "global.h" +#include "globalaccess.h" #include "engine_configuration_generated_structures.h" #include "efi_wave.h" -#include "globalaccess.h" #define FOUR_STROKE_ENGINE_CYCLE 720 diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index e539fdc95f..6df6cc0c9d 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -9,7 +9,7 @@ #ifndef RPM_REPORTER_H_ #define RPM_REPORTER_H_ -#include "global.h" +#include "globalaccess.h" #include "scheduler.h" // we use this value in case of noise on trigger input lines diff --git a/firmware/globalaccess.h b/firmware/globalaccess.h index cc310379dc..ddfb90bcd0 100644 --- a/firmware/globalaccess.h +++ b/firmware/globalaccess.h @@ -1,5 +1,7 @@ /* - * globalaccess.h + * @file globalaccess.h + * @bried version of global.h with DECLARE_ENGINE_PARAMETER_SIGNATURE & PASS_ENGINE_PARAMETER_SUFFIX + * * * unit_tests have a more meaningful version of this header * @@ -7,9 +9,7 @@ * @author Andrey Belomutskiy, (c) 2012-2019 */ -#ifndef GLOBALACCESS_H_ -#define GLOBALACCESS_H_ +#pragma once #include "global_shared.h" -#endif /* GLOBALACCESS_H_ */ diff --git a/simulator/simulator/globalaccess.h b/simulator/simulator/globalaccess.h index c5992e9254..96b2a406f3 100644 --- a/simulator/simulator/globalaccess.h +++ b/simulator/simulator/globalaccess.h @@ -1,13 +1,11 @@ /* * @file globalaccess.h + * @file See firmware/globalaccesss.h for more details. * * @date Jan 28, 2019 * @author Andrey Belomutskiy, (c) 2012-2019 */ -#ifndef SIMULATOR_GLOBALACCESS_H_ -#define SIMULATOR_GLOBALACCESS_H_ +#pragma once #include "global_shared.h" - -#endif /* SIMULATOR_GLOBALACCESS_H_ */ diff --git a/unit_tests/global.h b/unit_tests/global.h index 82a16765d0..8742efd29e 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -7,8 +7,7 @@ * @author Andrey Belomutskiy, (c) 2012-2017 */ -#ifndef GLOBAL_H_ -#define GLOBAL_H_ +#pragma once #include #include @@ -77,19 +76,9 @@ void print(const char *fmt, ...); #define EXTERN_CONFIG - #define DEFINE_CONFIG_PARAM(x, y) , x y #define PASS_CONFIG_PARAM(x) , x -/** - * this macro is a work-around for uint tests to get all needed pointers only - * if engine is in scope - */ -#define EXPAND_Engine \ - engine_configuration_s *engineConfiguration = engine->engineConfigurationPtr; \ - persistent_config_s *config = engine->config; \ - board_configuration_s *boardConfiguration = &engineConfiguration->bc; - /** * this macro provides references to engine from EngineTestHelper */ @@ -105,5 +94,3 @@ void print(const char *fmt, ...); #define lockAnyContext() false #define unlockAnyContext() {} - -#endif /* GLOBAL_H_ */ diff --git a/unit_tests/globalaccess.h b/unit_tests/globalaccess.h index a5d45353dc..03171a25c8 100644 --- a/unit_tests/globalaccess.h +++ b/unit_tests/globalaccess.h @@ -7,6 +7,8 @@ #pragma once +#include "global.h" + #define DECLARE_CONFIG_PARAMETER_SIGNATURE engine_configuration_s *engineConfiguration, persistent_config_s *config, board_configuration_s *boardConfiguration #define DECLARE_CONFIG_PARAMETER_SUFFIX , DECLARE_CONFIG_PARAMETER_SIGNATURE #define PASS_CONFIG_PARAMETER_SIGNATURE engineConfiguration, config, boardConfiguration