diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 8b3701588e..7ad69e2225 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -12,6 +12,7 @@ #include "efifeatures.h" #include "obd_error_codes.h" +#include "rusefi_generated.h" // we do not want to start the search for header from current folder so we use brackets here // https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename #include diff --git a/firmware/controllers/core/engine_ptr.h b/firmware/controllers/core/engine_ptr.h index ecfb13202c..a6332b3583 100644 --- a/firmware/controllers/core/engine_ptr.h +++ b/firmware/controllers/core/engine_ptr.h @@ -14,11 +14,15 @@ #ifdef __cplusplus class Engine; +#endif // def __cplusplus + + struct engine_configuration_s; struct persistent_config_s; #if EFI_UNIT_TEST +#ifdef __cplusplus #define DECLARE_ENGINE_PTR \ Engine *engine = nullptr; \ engine_configuration_s *engineConfiguration = nullptr; \ @@ -42,10 +46,20 @@ struct persistent_config_s; #define PASS_ENGINE_PARAMETER_SIGNATURE engine, PASS_CONFIG_PARAMETER_SIGNATURE #define PASS_ENGINE_PARAMETER_SUFFIX , PASS_ENGINE_PARAMETER_SIGNATURE + #define EXTERN_ENGINE extern EnginePins enginePins; \ + extern engine_configuration_s & activeConfiguration +#endif // def __cplusplus + + #define EXTERN_CONFIG + + #define DEFINE_CONFIG_PARAM(x, y) , x y + #define PASS_CONFIG_PARAM(x) , x + #else // EFI_UNIT_TEST // These are the non-unit-test (AKA real firmware) noop versions +#ifdef __cplusplus #define DECLARE_ENGINE_PTR #define INJECT_ENGINE_REFERENCE(x) {} @@ -65,6 +79,46 @@ struct persistent_config_s; // Pass this after some other parameters are passed #define PASS_ENGINE_PARAMETER_SUFFIX + #define EXTERN_ENGINE \ + extern Engine ___engine; \ + extern Engine *engine; \ + EXTERN_CONFIG \ + extern EnginePins enginePins \ + + #define ENGINE(x) ___engine.x +#endif // def __cplusplus + + /** + * 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 + + /** + * & is reference in C++ (not C) + * Ref is a pointer that: + * you access with dot instead of arrow + * Cannot be null + * This is about EFI_ACTIVE_CONFIGURATION_IN_FLASH + */ + #define EXTERN_CONFIG \ + EXTERN_ENGINE_CONFIGURATION \ + extern engine_configuration_s & activeConfiguration; \ + + #define EXTERN_ENGINE_CONFIGURATION \ + extern engine_configuration_s *engineConfiguration; \ + extern persistent_config_container_s persistentState; \ + extern persistent_config_s *config; + + + #define DEFINE_CONFIG_PARAM(x, y) + #define CONFIG_PARAM(x) CONFIG(x) + #define PASS_CONFIG_PARAM(x) + #endif // EFI_UNIT_TEST #define EXPAND_Engine \ @@ -72,5 +126,3 @@ struct persistent_config_s; persistent_config_s *config = engine->config; \ (void)engineConfiguration; \ (void)config; - -#endif // def __cplusplus diff --git a/firmware/controllers/core/state_sequence.h b/firmware/controllers/core/state_sequence.h index d94fd22cea..bf3a7120ba 100644 --- a/firmware/controllers/core/state_sequence.h +++ b/firmware/controllers/core/state_sequence.h @@ -7,7 +7,7 @@ #pragma once -#include "global.h" +#include "rusefi_enums.h" /** * This layer has two primary usages: diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h index 39e1a7a241..8ed10dbe57 100644 --- a/firmware/controllers/global_shared.h +++ b/firmware/controllers/global_shared.h @@ -31,50 +31,8 @@ #include "global.h" #include "engine_ptr.h" -#define EXTERN_ENGINE_CONFIGURATION \ - extern engine_configuration_s *engineConfiguration; \ - 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 - -/** - * & is reference in C++ (not C) - * Ref is a pointer that: - * you access with dot instead of arrow - * Cannot be null - * This is about EFI_ACTIVE_CONFIGURATION_IN_FLASH - */ -#define EXTERN_CONFIG \ - EXTERN_ENGINE_CONFIGURATION \ - extern engine_configuration_s & activeConfiguration; \ - -#define EXTERN_ENGINE \ - extern Engine ___engine; \ - extern Engine *engine; \ - EXTERN_CONFIG \ - extern EnginePins enginePins \ - -#define ENGINE(x) ___engine.x - -#define DEFINE_CONFIG_PARAM(x, y) -#define CONFIG_PARAM(x) CONFIG(x) -#define PASS_CONFIG_PARAM(x) - #define EXPECTED_REMAINING_STACK 128 -#endif /* __cplusplus */ - /* * Stack debugging */ diff --git a/firmware/controllers/trigger/decoders/trigger_mazda.cpp b/firmware/controllers/trigger/decoders/trigger_mazda.cpp index 0340a3ea52..bf06b34cd5 100644 --- a/firmware/controllers/trigger/decoders/trigger_mazda.cpp +++ b/firmware/controllers/trigger/decoders/trigger_mazda.cpp @@ -19,6 +19,7 @@ */ #include "trigger_mazda.h" +#include "error_handling.h" void initializeMazdaMiataNaShape(TriggerWaveform *s) { s->initialize(FOUR_STROKE_CAM_SENSOR); diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 07f14a5b78..947ce13697 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -10,8 +10,8 @@ #pragma once +#include "engine_ptr.h" #include "state_sequence.h" -#include "globalaccess.h" #include "engine_configuration_generated_structures.h" #define FOUR_STROKE_ENGINE_CYCLE 720 @@ -74,6 +74,7 @@ class Engine; class TriggerState; class TriggerFormDetails; class TriggerConfiguration; +class Logging; // https://github.com/rusefi/rusefi/issues/2010 shows the corner case wheel with huge depth requirement #define GAP_TRACKING_LENGTH 18 diff --git a/firmware/controllers/trigger/decoders/trigger_universal.cpp b/firmware/controllers/trigger/decoders/trigger_universal.cpp index e2985fadb9..bbcf005d8a 100644 --- a/firmware/controllers/trigger/decoders/trigger_universal.cpp +++ b/firmware/controllers/trigger/decoders/trigger_universal.cpp @@ -6,6 +6,7 @@ */ #include "trigger_universal.h" +#include "error_handling.h" /** * @see getCycleDuration diff --git a/firmware/controllers/trigger/decoders/trigger_vw.cpp b/firmware/controllers/trigger/decoders/trigger_vw.cpp index b27742e50b..36ac6b6d02 100644 --- a/firmware/controllers/trigger/decoders/trigger_vw.cpp +++ b/firmware/controllers/trigger/decoders/trigger_vw.cpp @@ -7,6 +7,7 @@ #include "trigger_vw.h" #include "trigger_universal.h" +#include "error_handling.h" void setVwConfiguration(TriggerWaveform *s) { efiAssertVoid(CUSTOM_ERR_6660, s != NULL, "TriggerWaveform is NULL"); diff --git a/unit_tests/global.h b/unit_tests/global.h index 7dca6bafec..c3d888402b 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -64,14 +64,6 @@ void print(const char *fmt, ...); #define CCM_OPTIONAL -#define EXTERN_ENGINE extern EnginePins enginePins; \ - extern engine_configuration_s & activeConfiguration - -#define EXTERN_CONFIG - -#define DEFINE_CONFIG_PARAM(x, y) , x y -#define PASS_CONFIG_PARAM(x) , x - /** * this macro provides references to engine from EngineTestHelper */