diff --git a/firmware/controllers/core/common_headers.h b/firmware/controllers/core/common_headers.h index 6a7894e9e8..573cf59553 100644 --- a/firmware/controllers/core/common_headers.h +++ b/firmware/controllers/core/common_headers.h @@ -1,6 +1,8 @@ /* * @file common_headers.h * + * Header file shared between firmware, simulator and unit_tests + * * @date Sep 16, 2018 * @author Andrey Belomutskiy, (c) 2012-2018 */ diff --git a/firmware/controllers/global_shared.h b/firmware/controllers/global_shared.h new file mode 100644 index 0000000000..7f1886f151 --- /dev/null +++ b/firmware/controllers/global_shared.h @@ -0,0 +1,57 @@ +/* + * global_shared.h + * + * part of global.h which is shared between firmware and simulator + * See also common_headers.h + * + * Dec 25, 2018 + * @author Andrey Belomutskiy, (c) 2012-2018 + */ + +#ifndef GLOBAL_SHARED_H_ +#define GLOBAL_SHARED_H_ + +/** + * The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance + * optimization. + * + * rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. Problem + * is that PORT_INT_REQUIRED_STACK is included within each user thread stack, thus this large stack multiplies + * and this consumes a lot of valueable RAM. While forcing the compiler to inline helps to some degree, + * it would be even better not to waste stack on passing the parameter. + * + * In the firmware we are using 'extern *Engine' - in the firmware Engine is a signleton + * + * On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter + */ + +#define COMMON_EXTERN_ENGINE extern Engine *engine; \ + extern engine_configuration_s *engineConfiguration; \ + extern board_configuration_s *boardConfiguration; \ + extern persistent_config_s *config; \ + extern persistent_config_container_s persistentState; \ + extern engine_configuration_s activeConfiguration; \ + extern EnginePins enginePins + + +// Use this macro to declare a function which only takes magic references +#define DECLARE_ENGINE_PARAMETER_SIGNATURE void +// Use this version of the macro as the suffix if method has other parameters +#define DECLARE_ENGINE_PARAMETER_SUFFIX +// Pass this if only magic reference are needed +#define PASS_ENGINE_PARAMETER_SIGNATURE +// Pass this after some other parameters are passed +#define PASS_ENGINE_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 + */ +#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x + + +#define DEFINE_CONFIG_PARAM(x, y) +#define CONFIG_PARAM(x) CONFIG(x) + + +#endif /* GLOBAL_SHARED_H_ */ diff --git a/firmware/global.h b/firmware/global.h index 4d6e9cdba3..993bbeacdc 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -36,6 +36,7 @@ typedef unsigned int time_t; #endif #include "common_headers.h" +#include "controllers/global_shared.h" #include "io_pins.h" @@ -91,43 +92,10 @@ typedef unsigned int time_t; #define CCM_OPTIONAL #endif /* EFI_USE_CCM */ -/** - * The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance - * optimization. - * - * rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. Problem - * is that PORT_INT_REQUIRED_STACK is included within each user thread stack, thus this large stack multiplies - * and this consumes a lot of valueable RAM. While forcing the compiler to inline helps to some degree, - * it would be even better not to waste stack on passing the parameter. - * - * In the firmware we are using 'extern *Engine' - in the firmware Engine is a signleton - * - * On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter - */ - -#define EXTERN_ENGINE extern Engine *engine; \ - extern engine_configuration_s *engineConfiguration; \ - extern board_configuration_s *boardConfiguration; \ - extern persistent_config_container_s persistentState; \ +#define EXTERN_ENGINE \ extern Engine _engine; \ - extern persistent_config_s *config; \ - extern engine_configuration_s activeConfiguration; \ - extern EnginePins enginePins + COMMON_EXTERN_ENGINE -// Use this macro to declare a function which only takes magic references -#define DECLARE_ENGINE_PARAMETER_SIGNATURE void -// Use this version of the macro as the suffix if method has other parameters -#define DECLARE_ENGINE_PARAMETER_SUFFIX -// Pass this if only magic reference are needed -#define PASS_ENGINE_PARAMETER_SIGNATURE -// Pass this after some other parameters are passed -#define PASS_ENGINE_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 - */ -#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x #define ENGINE(x) _engine.x /** diff --git a/simulator/simulator/global.h b/simulator/simulator/global.h index f42a19bb84..75d3d4ae03 100644 --- a/simulator/simulator/global.h +++ b/simulator/simulator/global.h @@ -4,7 +4,7 @@ * Global header file for win32 or posix simulator * * @date May 27, 2013 - * @author Andrey Belomutskiy, (c) 2012-2017 + * @author Andrey Belomutskiy, (c) 2012-2018 */ #ifndef GLOBAL_H_ @@ -17,6 +17,7 @@ #include #include "common_headers.h" +#include "global_shared.h" #include "boards.h" @@ -94,19 +95,8 @@ void applyNewConfiguration(void); #define hal_lld_get_counter_value() 0 -#define EXTERN_ENGINE extern Engine *engine; \ - extern engine_configuration_s *engineConfiguration; \ - extern board_configuration_s *boardConfiguration; \ - extern persistent_config_s *config; \ - extern persistent_config_container_s persistentState; \ - extern EnginePins enginePins - -#define DECLARE_ENGINE_PARAMETER_SIGNATURE void -#define DECLARE_ENGINE_PARAMETER_SUFFIX -#define PASS_ENGINE_PARAMETER_SIGNATURE -#define PASS_ENGINE_PARAMETER_SUFFIX - -#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x +#define EXTERN_ENGINE \ + COMMON_EXTERN_ENGINE #define ENGINE(x) engine->x #endif /* GLOBAL_H_ */