2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file global.h
|
|
|
|
*
|
2018-09-16 17:28:23 -07:00
|
|
|
* Global header file for firmware
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* @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
|
|
|
|
2018-09-16 19:00:14 -07:00
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
2015-07-10 06:01:56 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-04-16 10:53:13 -07:00
|
|
|
#ifndef DEFAULT_ENGINE_TYPE
|
2017-05-15 02:18:16 -07:00
|
|
|
#define DEFAULT_ENGINE_TYPE CUSTOM_ENGINE
|
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"
|
|
|
|
#include "io_pins.h"
|
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"
|
|
|
|
|
2018-09-16 19:00:14 -07:00
|
|
|
#include "efitime.h"
|
|
|
|
#include "efilib.h"
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/* 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
|
|
|
|
|
2017-05-03 18:24:18 -07:00
|
|
|
#if EFI_USE_CCM && defined __GNUC__
|
|
|
|
#define MAIN_RAM __attribute__((section(".ram0")))
|
|
|
|
#elif defined __GNUC__
|
|
|
|
#define MAIN_RAM
|
|
|
|
#else
|
|
|
|
#define MAIN_RAM @ ".ram0"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-05-17 17:29:22 -07:00
|
|
|
/**
|
|
|
|
* rusEfi is placing some of data structures into CCM memory simply
|
|
|
|
* in order to use that memory - no magic about which RAM is faster etc.
|
|
|
|
*
|
|
|
|
* Please note that DMA does not work with CCM memory
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
#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
|
2017-05-15 20:28:49 -07:00
|
|
|
#define DECLARE_ENGINE_PARAMETER_SIGNATURE void
|
2017-03-23 18:37:25 -07:00
|
|
|
// Use this version of the macro as the suffix if method has other parameters
|
2017-05-15 20:28:49 -07:00
|
|
|
#define DECLARE_ENGINE_PARAMETER_SUFFIX
|
2017-03-23 18:37:25 -07:00
|
|
|
// Pass this if only magic reference are needed
|
2017-05-15 20:28:49 -07:00
|
|
|
#define PASS_ENGINE_PARAMETER_SIGNATURE
|
2017-03-23 18:37:25 -07:00
|
|
|
// Pass this after some other parameters are passed
|
2017-05-15 20:28:49 -07:00
|
|
|
#define PASS_ENGINE_PARAMETER_SUFFIX
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* this macro allows the compiled to figure out the complete static address, that's a performance
|
2017-12-06 17:04:27 -08:00
|
|
|
* optimization which is hopefully useful at least for anything trigger-related
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
#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(); \
|
2018-07-26 12:51:06 -07:00
|
|
|
enginePins.communicationLedPin.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
|
|
|
|
2018-09-16 19:00:14 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "cli_registry.h"
|
|
|
|
#include "datalogging.h"
|
|
|
|
#include "loggingcentral.h"
|
|
|
|
#include "eficonsole.h"
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#include "chprintf.h"
|
|
|
|
|
2017-03-22 09:53:09 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2018-09-16 19:00:14 -07:00
|
|
|
// todo: access some existing configuration field
|
|
|
|
#define CORE_CLOCK 168000000
|
|
|
|
|
|
|
|
// 168 ticks in microsecond
|
|
|
|
#define US_TO_NT_MULTIPLIER 168
|
|
|
|
|
|
|
|
/**
|
|
|
|
* converts efitimeus_t to efitick_t
|
|
|
|
*/
|
|
|
|
#define US2NT(us) (((efitime_t)(us))*US_TO_NT_MULTIPLIER)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* converts efitick_t to efitimeus_t
|
|
|
|
*/
|
|
|
|
#define NT2US(nt) ((nt) / US_TO_NT_MULTIPLIER)
|
|
|
|
|
|
|
|
#define Delay(ms) chThdSleepMilliseconds(ms)
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool lockAnyContext(void);
|
|
|
|
void unlockAnyContext(void);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* GLOBAL_H_ */
|
2018-09-16 19:00:14 -07:00
|
|
|
|