rusefi/firmware/global.h

93 lines
2.7 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/*
* @file global.h
*
* @date May 27, 2013
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <ch.h>
#include <hal.h>
#include <string.h>
// this is about MISRA not liking 'time.h'. todo: figure out something
#if defined __GNUC__
2014-11-11 14:03:38 -08:00
// GCC
2014-08-29 07:52:33 -07:00
#include <sys/types.h>
2014-11-11 14:03:38 -08:00
#define ALWAYS_INLINE __attribute__((always_inline))
2014-08-29 07:52:33 -07:00
#else
2014-11-11 14:03:38 -08:00
// IAR
2014-08-29 07:52:33 -07:00
typedef unsigned int time_t;
2014-11-11 14:03:38 -08:00
// todo: what's the IAR option?
#define ALWAYS_INLINE INLINE
2014-08-29 07:52:33 -07:00
#endif
#include "efifeatures.h"
#include "rusefi_enums.h"
2014-10-07 07:03:01 -07:00
#include "io_pins.h"
#include "auto_generated_enums.h"
2014-08-29 07:52:33 -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
2014-11-15 17:03:22 -08:00
#define UTILITY_THREAD_STACK_SIZE 400
2014-08-29 07:52:33 -07:00
#define EFI_ERROR_CODE 0xffffffff
#if EFI_USE_CCM && defined __GNUC__
2014-11-22 09:03:10 -08:00
#define CCM_OPTIONAL __attribute__((section(".ccm")))
2014-08-29 07:52:33 -07:00
#else
#define CCM_OPTIONAL @ ".ccm"
#endif
// this stuff is about ChibiOS 2.6 > Migration
typedef VirtualTimer virtual_timer_t;
typedef EventListener event_listener_t;
typedef Thread thread_t;
#define THD_WORKING_AREA WORKING_AREA
2014-11-07 19:04:45 -08:00
/**
* The following obscurantism is a hack to reduce stack usage, maybe even a questionable performance
* optimization.
*
* rusEfi main processing happends 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 comiler 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
*/
2014-11-07 20:03:53 -08:00
#define EXTERN_ENGINE extern Engine *engine; \
2014-11-14 12:03:04 -08:00
extern engine_configuration_s *engineConfiguration; \
2014-11-25 07:03:25 -08:00
extern board_configuration_s *boardConfiguration; \
2014-11-25 09:05:03 -08:00
extern persistent_config_container_s persistentState; \
2014-12-03 14:03:09 -08:00
extern Engine _engine; \
extern engine_configuration2_s * engineConfiguration2
2014-11-07 19:04:45 -08:00
2014-11-11 14:03:38 -08:00
#define DECLARE_ENGINE_PARAMETER_F void
#define DECLARE_ENGINE_PARAMETER_S
2014-11-24 18:03:34 -08:00
#define PASS_ENGINE_PARAMETER_F
2014-11-07 19:04:45 -08:00
#define PASS_ENGINE_PARAMETER
2014-11-25 07:03:25 -08:00
/**
* this macro allows the compiled to figure out the complete static address, that's a performance
* optimization
*/
#define CONFIG(x) persistentState.persistentConfiguration.engineConfiguration.x
2014-11-25 17:03:21 -08:00
#define ENGINE(x) _engine.x
2014-11-25 09:05:03 -08:00
#define TRIGGER_SHAPE(x) _engine.triggerShape.x
2014-11-25 07:03:25 -08:00
2014-08-29 07:52:33 -07:00
#endif /* GLOBAL_H_ */