rusefi/firmware/global.h

133 lines
3.5 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/*
* @file global.h
*
* @date May 27, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef GLOBAL_H_
#define GLOBAL_H_
2017-03-21 11:58:14 -07:00
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
2015-07-10 06:01:56 -07:00
#include <ch.h>
#include <hal.h>
2017-03-21 11:58:14 -07:00
2015-07-10 06:01:56 -07:00
#include <string.h>
2017-04-16 10:53:13 -07:00
#ifndef DEFAULT_ENGINE_TYPE
2017-04-27 11:33:46 -07:00
//#define DEFAULT_ENGINE_TYPE CUSTOM_ENGINE
// temporary measure until NJMP race
#define DEFAULT_ENGINE_TYPE MAZDA_MIATA_2003_BETTER
2017-04-16 10:53:13 -07:00
#endif
2016-09-21 21:03:00 -07:00
2015-07-10 06:01:56 -07:00
// this is about MISRA not liking 'time.h'. todo: figure out something
#if defined __GNUC__
// GCC
#include <sys/types.h>
#define ALWAYS_INLINE __attribute__((always_inline))
#else
// IAR
typedef unsigned int time_t;
// todo: what's the IAR option?
#define ALWAYS_INLINE INLINE
#endif
#include "efifeatures.h"
#include "rusefi_types.h"
#include "rusefi_enums.h"
#if EFI_PROD_CODE
#include "io_pins.h"
#endif
2016-01-24 15:01:56 -08:00
#include "auto_generated_enums.h"
2015-07-10 06:01:56 -07:00
#include "obd_error_codes.h"
#include "error_handling.h"
/* definition to expand macro then apply to pragma message */
#define VALUE_TO_STRING(x) #x
#define VALUE(x) VALUE_TO_STRING(x)
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
// project-wide default thread stack size
// see also PORT_INT_REQUIRED_STACK
#define UTILITY_THREAD_STACK_SIZE 400
#define EFI_ERROR_CODE 0xffffffff
#if EFI_USE_CCM && defined __GNUC__
2017-03-21 11:58:14 -07:00
#define CCM_OPTIONAL __attribute__((section(".ram4")))
2015-07-10 06:01:56 -07:00
#elif defined __GNUC__
#define CCM_OPTIONAL
#else
2017-03-21 11:58:14 -07:00
#define CCM_OPTIONAL @ ".ram4"
2015-07-10 06:01:56 -07:00
#endif
2016-02-05 12:02:36 -08:00
#if EFI_PROD_CODE || defined(__DOXYGEN__)
2015-07-10 06:01:56 -07:00
/**
* The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance
* optimization.
*
2017-03-06 22:43:58 -08:00
* rusEfi main processing happens on IRQ so PORT_INT_REQUIRED_STACK has to be pretty large. Problem
2015-07-10 06:01:56 -07:00
* is that PORT_INT_REQUIRED_STACK is included within each user thread stack, thus this large stack multiplies
2017-03-06 22:43:58 -08:00
* and this consumes a lot of valueable RAM. While forcing the compiler to inline helps to some degree,
2015-07-10 06:01:56 -07:00
* 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; \
extern Engine _engine; \
extern persistent_config_s *config; \
2016-12-19 17:01:37 -08:00
extern engine_configuration_s activeConfiguration; \
2016-11-03 20:02:58 -07:00
extern EnginePins enginePins
2015-07-10 06:01:56 -07:00
2017-03-23 18:37:25 -07:00
// Use this macro to declare a function which only takes magic references
2015-07-10 06:01:56 -07:00
#define DECLARE_ENGINE_PARAMETER_F void
2017-03-23 18:37:25 -07:00
// Use this version of the macro as the suffix if method has other parameters
2015-07-10 06:01:56 -07:00
#define DECLARE_ENGINE_PARAMETER_S
2017-03-23 18:37:25 -07:00
// Pass this if only magic reference are needed
2015-07-10 06:01:56 -07:00
#define PASS_ENGINE_PARAMETER_F
2017-03-23 18:37:25 -07:00
// Pass this after some other parameters are passed
2015-07-10 06:01:56 -07:00
#define PASS_ENGINE_PARAMETER
/**
* this macro allows the compiled to figure out the complete static address, that's a performance
* optimization
*/
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
#define ENGINE(x) _engine.x
2017-03-01 19:18:25 -08:00
#define TRIGGER_SHAPE(x) _engine.triggerCentral.triggerShape.x
2015-07-10 06:01:56 -07:00
#else
#define EXTERN_ENGINE
#endif
/**
* low-level function is used here to reduce stack usage
*/
#define ON_FATAL_ERROR() \
palWritePad(LED_ERROR_PORT, LED_ERROR_PIN, 1); \
2017-01-26 20:03:04 -08:00
turnAllPinsOff(); \
2017-02-24 16:42:34 -08:00
enginePins.communicationPin.setValue(1);
2015-07-10 06:01:56 -07:00
2017-03-21 11:58:14 -07:00
/*
* Stack debugging
*/
int getRemainingStack(thread_t *otp);
2015-07-10 06:01:56 -07:00
#ifdef __cplusplus
}
#endif /* __cplusplus */
2015-07-10 06:01:56 -07:00
#endif /* GLOBAL_H_ */