2018-12-25 13:06:24 -08:00
|
|
|
/*
|
2019-11-19 22:35:08 -08:00
|
|
|
* @file global_shared.h
|
2018-12-25 13:06:24 -08:00
|
|
|
*
|
|
|
|
* part of global.h which is shared between firmware and simulator
|
|
|
|
* See also common_headers.h
|
|
|
|
*
|
|
|
|
* Dec 25, 2018
|
2019-01-27 21:44:30 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
2018-12-25 13:06:24 -08:00
|
|
|
*/
|
|
|
|
|
2019-11-19 22:35:08 -08:00
|
|
|
#pragma once
|
2018-12-25 13:06:24 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance
|
|
|
|
* optimization.
|
2019-12-13 13:47:26 -08:00
|
|
|
*
|
|
|
|
* Of note is that interrupts are NOT serviced on the stack of the thread that was running when the
|
|
|
|
* interrupt occurred. The only thing that happens on that thread's stack is that its registers are
|
|
|
|
* pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the
|
|
|
|
* main stack (currently 0x400=1024 bytes), where the ISR actually runs.
|
|
|
|
*
|
|
|
|
* see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks
|
2018-12-25 13:06:24 -08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-11-19 22:35:08 -08:00
|
|
|
#include "global.h"
|
|
|
|
|
2019-01-10 14:07:29 -08:00
|
|
|
#define EXTERN_CONFIG \
|
2018-12-25 13:06:24 -08:00
|
|
|
extern engine_configuration_s *engineConfiguration; \
|
2019-12-11 14:48:55 -08:00
|
|
|
extern engine_configuration_s *engineConfiguration; \
|
2019-10-31 13:06:34 -07:00
|
|
|
extern engine_configuration_s & activeConfiguration; \
|
2019-05-03 15:41:43 -07:00
|
|
|
extern persistent_config_container_s persistentState; \
|
|
|
|
extern persistent_config_s *config; \
|
|
|
|
|
2019-01-27 23:59:14 -08:00
|
|
|
#define EXTERN_ENGINE \
|
|
|
|
extern Engine ___engine; \
|
|
|
|
extern Engine *engine; \
|
2019-01-10 14:07:29 -08:00
|
|
|
EXTERN_CONFIG \
|
2019-05-03 15:41:43 -07:00
|
|
|
extern EnginePins enginePins \
|
|
|
|
|
2018-12-25 13:06:24 -08:00
|
|
|
|
|
|
|
// 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
|
2019-01-27 23:59:14 -08:00
|
|
|
// Pass this if only magic references are needed
|
2018-12-25 13:06:24 -08:00
|
|
|
#define PASS_ENGINE_PARAMETER_SIGNATURE
|
|
|
|
// Pass this after some other parameters are passed
|
|
|
|
#define PASS_ENGINE_PARAMETER_SUFFIX
|
|
|
|
|
2019-01-27 20:07:02 -08:00
|
|
|
// these macro are used when we should not have visibility to 'engine'
|
2019-01-10 14:07:29 -08:00
|
|
|
#define DECLARE_CONFIG_PARAMETER_SIGNATURE void
|
|
|
|
#define DECLARE_CONFIG_PARAMETER_SUFFIX
|
|
|
|
#define PASS_CONFIG_PARAMETER_SIGNATURE
|
|
|
|
#define PASS_CONFIG_PARAMETER_SUFFIX
|
|
|
|
|
2018-12-25 13:06:24 -08:00
|
|
|
/**
|
|
|
|
* 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
|
2019-11-13 19:47:49 -08:00
|
|
|
*
|
|
|
|
* 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
|
2018-12-25 13:06:24 -08:00
|
|
|
*/
|
|
|
|
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
|
2019-01-27 23:59:14 -08:00
|
|
|
#define ENGINE(x) ___engine.x
|
2018-12-25 13:06:24 -08:00
|
|
|
|
|
|
|
#define DEFINE_CONFIG_PARAM(x, y)
|
|
|
|
#define CONFIG_PARAM(x) CONFIG(x)
|
2018-12-25 19:47:29 -08:00
|
|
|
#define PASS_CONFIG_PARAM(x)
|
2018-12-25 13:06:24 -08:00
|
|
|
|
2019-12-13 15:02:24 -08:00
|
|
|
#define EXPECTED_REMAINING_STACK 128
|