2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file engine_configuration.h
|
|
|
|
* @brief Main engine configuration data structure.
|
|
|
|
*
|
|
|
|
* @date Oct 30, 2013
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ENGINE_CONFIGURATION_H_
|
|
|
|
#define ENGINE_CONFIGURATION_H_
|
|
|
|
|
|
|
|
#include "efifeatures.h"
|
|
|
|
#include "crc.h"
|
|
|
|
#include "sensor_types.h"
|
|
|
|
#include "can_header.h"
|
|
|
|
#include "rusefi_enums.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
float coolantTempMinC;
|
|
|
|
float coolantTempMaxC;
|
|
|
|
float fuelAtMinTempMs;
|
|
|
|
float fuelAtMaxTempMs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')
|
|
|
|
* Anything above 'crankingRpm' would be 'running'
|
|
|
|
*/
|
|
|
|
short int crankingRpm;
|
|
|
|
} cranking_parameters_s;
|
|
|
|
|
2014-09-07 15:04:23 -07:00
|
|
|
#define INJECTION_PIN_COUNT 12
|
2014-09-07 16:02:51 -07:00
|
|
|
#define IGNITION_PIN_COUNT 12
|
2014-09-07 15:04:23 -07:00
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
#define FUEL_RPM_COUNT 16
|
|
|
|
#define FUEL_LOAD_COUNT 16
|
|
|
|
#define VE_RPM_COUNT 16
|
|
|
|
#define VE_LOAD_COUNT 16
|
|
|
|
#define AFR_RPM_COUNT 16
|
|
|
|
#define AFR_LOAD_COUNT 16
|
|
|
|
|
|
|
|
#define CLT_CURVE_SIZE 16
|
|
|
|
#define IAT_CURVE_SIZE 16
|
|
|
|
#define VBAT_INJECTOR_CURVE_SIZE 8
|
|
|
|
|
|
|
|
#define IGN_LOAD_COUNT 16
|
|
|
|
#define IGN_RPM_COUNT 16
|
|
|
|
|
|
|
|
#define DWELL_CURVE_SIZE 8
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
AC_OFF = 0,
|
|
|
|
/**
|
|
|
|
* You would use this value if you want to see a detailed graph of your trigger events
|
|
|
|
*/
|
|
|
|
AC_TRIGGER = 1, AC_MAP = 2,
|
|
|
|
|
|
|
|
Internal_ForceMyEnumIntSize_analog_chart_mode = ENUM_SIZE_HACK,
|
|
|
|
} analog_chart_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/**
|
|
|
|
* This is the default mode in which ECU controls timing dynamically
|
|
|
|
*/
|
|
|
|
TM_DYNAMIC = 0,
|
|
|
|
/**
|
|
|
|
* Fixed timing is useful while you are playing with a timing gun - you need to have fixed
|
|
|
|
* timing if you want to install your distributor at some specific angle
|
|
|
|
*/
|
|
|
|
TM_FIXED = 1,
|
|
|
|
|
|
|
|
Internal_ForceMyEnumIntSize_timing_mode = ENUM_SIZE_HACK,
|
|
|
|
} timing_mode_e;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CD_OFF = 0,
|
|
|
|
CD_USE_CAN1 = 1,
|
|
|
|
CD_USE_CAN2 = 2,
|
|
|
|
|
|
|
|
Internal_ForceMyEnumIntSize_can_device_mode = ENUM_SIZE_HACK,
|
|
|
|
} can_device_mode_e;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
adc_channel_e afrAdcChannel;
|
|
|
|
float v1;
|
|
|
|
float value1;
|
|
|
|
float v2;
|
|
|
|
float value2;
|
|
|
|
} afr_sensor_s;
|
|
|
|
|
|
|
|
#define DWELL_COUNT 8
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Trigger wheel(s) configuration
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
trigger_type_e triggerType;
|
|
|
|
|
|
|
|
int customIsSynchronizationNeeded;
|
|
|
|
|
|
|
|
int customTotalToothCount;
|
|
|
|
int customSkippedToothCount;
|
|
|
|
|
|
|
|
float customSyncRatioFrom;
|
|
|
|
float customSyncRatioTo;
|
|
|
|
|
|
|
|
int customUseRiseEdge;
|
|
|
|
|
|
|
|
} trigger_config_s;
|
|
|
|
|
|
|
|
|
|
|
|
#define HW_MAX_ADC_INDEX 16
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
// WARNING: by default, our small enums are ONE BYTE. this one is made 4-byte with the 'ENUM_SIZE_HACK' hack
|
|
|
|
brain_pin_e idleValvePin;
|
|
|
|
pin_output_mode_e idleValvePinMode;
|
|
|
|
|
|
|
|
brain_pin_e fuelPumpPin;
|
|
|
|
pin_output_mode_e fuelPumpPinMode;
|
|
|
|
|
2014-09-07 15:04:23 -07:00
|
|
|
brain_pin_e injectionPins[INJECTION_PIN_COUNT];
|
2014-08-29 07:52:33 -07:00
|
|
|
pin_output_mode_e injectionPinMode;
|
|
|
|
|
2014-09-07 16:02:51 -07:00
|
|
|
brain_pin_e ignitionPins[IGNITION_PIN_COUNT];
|
2014-08-29 07:52:33 -07:00
|
|
|
pin_output_mode_e ignitionPinMode;
|
|
|
|
|
|
|
|
brain_pin_e malfunctionIndicatorPin;
|
|
|
|
pin_output_mode_e malfunctionIndicatorPinMode;
|
|
|
|
|
|
|
|
brain_pin_e fanPin;
|
|
|
|
pin_output_mode_e fanPinMode;
|
|
|
|
|
|
|
|
brain_pin_e electronicThrottlePin1;
|
|
|
|
pin_output_mode_e electronicThrottlePin1Mode;
|
|
|
|
|
|
|
|
brain_pin_e idleSwitchPin;
|
|
|
|
pin_input_mode_e idleSwitchPinMode;
|
|
|
|
|
|
|
|
brain_pin_e alternatorControlPin;
|
|
|
|
pin_output_mode_e alternatorControlPinMode;
|
|
|
|
|
|
|
|
brain_pin_e HD44780_rs;
|
|
|
|
brain_pin_e HD44780_e;
|
|
|
|
brain_pin_e HD44780_db4;
|
|
|
|
brain_pin_e HD44780_db5;
|
|
|
|
brain_pin_e HD44780_db6;
|
|
|
|
brain_pin_e HD44780_db7;
|
|
|
|
|
|
|
|
brain_pin_e gps_rx_pin;
|
|
|
|
brain_pin_e gps_tx_pin;
|
|
|
|
|
|
|
|
int idleSolenoidFrequency;
|
|
|
|
|
|
|
|
int unused;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Digital Potentiometer is used by stock ECU stimulation code
|
|
|
|
*/
|
|
|
|
spi_device_e digitalPotentiometerSpiDevice;
|
|
|
|
brain_pin_e digitalPotentiometerChipSelect[DIGIPOT_COUNT];
|
|
|
|
|
|
|
|
adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX];
|
|
|
|
|
2014-09-06 15:02:55 -07:00
|
|
|
brain_pin_e triggerInputPins[3];
|
|
|
|
int unused4;
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
int idleThreadPeriod;
|
|
|
|
int consoleLoopPeriod;
|
|
|
|
int lcdThreadPeriod;
|
|
|
|
int tunerStudioThreadPeriod;
|
|
|
|
int generalPeriodicThreadPeriod;
|
|
|
|
|
|
|
|
int tunerStudioSerialSpeed;
|
|
|
|
|
|
|
|
brain_pin_e boardTestModeJumperPin;
|
|
|
|
|
|
|
|
can_device_mode_e canDeviceMode;
|
|
|
|
brain_pin_e canTxPin;
|
|
|
|
brain_pin_e canRxPin;
|
|
|
|
|
|
|
|
brain_pin_e triggerSimulatorPins[3];
|
|
|
|
pin_output_mode_e triggerSimulatorPinModes[3];
|
|
|
|
|
|
|
|
brain_pin_e o2heaterPin;
|
|
|
|
pin_output_mode_e o2heaterPinModeTodO;
|
|
|
|
|
2014-09-01 21:02:45 -07:00
|
|
|
unsigned int is_enabled_spi_1 : 1; // bit 0
|
|
|
|
unsigned int is_enabled_spi_2 : 1; // bit 1
|
|
|
|
unsigned int is_enabled_spi_3 : 1; // bit 2
|
|
|
|
unsigned int isSdCardEnabled : 1; // bit 3
|
2014-09-10 11:02:56 -07:00
|
|
|
unsigned int isFastAdcEnabled : 1; // bit 4
|
|
|
|
unsigned int isEngineControlEnabled : 1; // bit 5
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-09-06 15:02:55 -07:00
|
|
|
brain_pin_e logicAnalyzerPins[LOGIC_ANALYZER_CHANNEL_COUNT];
|
|
|
|
uint8_t logicAnalyzerMode[LOGIC_ANALYZER_CHANNEL_COUNT];
|
2014-08-31 15:02:50 -07:00
|
|
|
|
2014-09-06 15:02:55 -07:00
|
|
|
int unused2[2];
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
|
|
|
|
} board_configuration_s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Engine configuration.
|
|
|
|
* Values in this data structure are adjustable and persisted in on-board flash RAM.
|
|
|
|
*
|
|
|
|
* The offsets are tracked using
|
|
|
|
* https://docs.google.com/spreadsheet/ccc?key=0AiAmAn6tn3L_dGJXZDZOcVVhaG9SaHZKU1dyMjhEV0E
|
|
|
|
*
|
|
|
|
* todo: currently the fields here are simply in the order in which they were implemented
|
|
|
|
* todo: re-arrange this structure one we have a stable code version
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
float injectorLag; // size 4, offset 0
|
|
|
|
/**
|
|
|
|
* cc/min, cubic centimeter per minute
|
|
|
|
*
|
|
|
|
* By the way, g/s = 0.125997881 * (lb/hr)
|
|
|
|
* g/s = 0.125997881 * (cc/min)/10.5
|
|
|
|
* g/s = 0.0119997981 * cc/min
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
float injectorFlow; // size 4, offset 4
|
|
|
|
float battInjectorLagCorrBins[VBAT_INJECTOR_CURVE_SIZE]; // size 32, offset 8
|
|
|
|
float battInjectorLagCorr[VBAT_INJECTOR_CURVE_SIZE]; // size 32, offset 40
|
|
|
|
|
|
|
|
float cltFuelCorrBins[CLT_CURVE_SIZE]; // size 64, offset 72
|
|
|
|
float cltFuelCorr[CLT_CURVE_SIZE]; // size 64, offset 136
|
|
|
|
|
|
|
|
float iatFuelCorrBins[IAT_CURVE_SIZE]; // size 64, offset 200
|
|
|
|
float iatFuelCorr[IAT_CURVE_SIZE]; // size 64, offset 264
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Should the trigger emulator push data right into trigger input, eliminating the need for physical jumper wires?
|
|
|
|
* PS: Funny name, right? :)
|
|
|
|
*/
|
|
|
|
short int directSelfStimulation; // size 2, offset 328
|
|
|
|
|
|
|
|
// todo: extract these two fields into a structure
|
|
|
|
// todo: we need two sets of TPS parameters - modern ETBs have to sensors
|
|
|
|
short int tpsMin; // size 2, offset 330
|
|
|
|
// tpsMax value as 10 bit ADC value. Not Voltage!
|
|
|
|
short int tpsMax; // size 2, offset 332
|
|
|
|
short int analogChartMode;
|
|
|
|
|
|
|
|
cranking_parameters_s crankingSettings;
|
|
|
|
|
|
|
|
MAP_sensor_config_s map;
|
|
|
|
|
|
|
|
// todo: merge with channel settings, use full-scale Thermistor here!
|
|
|
|
ThermistorConf cltThermistorConf; // size 40 (10*4), offset 336
|
|
|
|
ThermistorConf iatThermistorConf; // size 40, offset 376
|
|
|
|
|
|
|
|
float sparkDwellBins[DWELL_COUNT]; // offset 580
|
|
|
|
float sparkDwell[DWELL_COUNT];
|
|
|
|
|
|
|
|
float ignitionLoadBins[IGN_LOAD_COUNT];
|
|
|
|
float ignitionRpmBins[IGN_RPM_COUNT];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this value could be used to offset the whole ignition timing table by a constant
|
|
|
|
*/
|
|
|
|
float ignitionOffset;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* While cranking (which causes battery voltage to drop) we can calculate dwell time in shaft
|
|
|
|
* degrees, not in absolute time as in running mode.
|
|
|
|
*/
|
|
|
|
float crankingChargeAngle;
|
|
|
|
|
|
|
|
timing_mode_e timingMode;
|
|
|
|
/**
|
|
|
|
* This value is used in 'fixed timing' mode, i.e. constant timing
|
|
|
|
* This mode is useful for instance while adjusting distributor location
|
|
|
|
*/
|
|
|
|
float fixedModeTiming;
|
|
|
|
|
|
|
|
// WARNING: by default, our small enums are ONE BYTE. but if the are surrounded by non-enums - alignments do the trick
|
|
|
|
engine_type_e engineType;
|
|
|
|
|
|
|
|
float fuelLoadBins[FUEL_LOAD_COUNT]; //
|
|
|
|
// RPM is float and not integer in order to use unified methods for interpolation
|
|
|
|
float fuelRpmBins[FUEL_RPM_COUNT]; //
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Engine displacement, in liters
|
|
|
|
* see also cylindersCount
|
|
|
|
*/
|
|
|
|
float displacement;
|
|
|
|
int rpmHardLimit;
|
|
|
|
|
|
|
|
injection_mode_e crankingInjectionMode;
|
|
|
|
injection_mode_e injectionMode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inside rusEfi all the angles are handled in relation to the trigger synchronization event
|
|
|
|
* which depends on the trigger shape and has nothing to do wit Top Dead Center (TDC)
|
|
|
|
*
|
|
|
|
* For engine configuration humans need angles from TDC.
|
|
|
|
*
|
|
|
|
* This field is the angle between Top Dead Center (TDC) and the first trigger event.
|
|
|
|
* Knowing this angle allows us to control timing and other angles in reference to TDC.
|
|
|
|
*/
|
|
|
|
float globalTriggerAngleOffset;
|
|
|
|
/**
|
|
|
|
* We have 3.3V ADC and most of the analog input signals are 5V, this forces us to use
|
|
|
|
* voltage dividers on the input circuits. This parameter holds the coefficient of these dividers.
|
|
|
|
* see also vbattDividerCoeff
|
|
|
|
*/
|
|
|
|
float analogInputDividerCoefficient;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This setting controls which algorithm is used for ENGINE LOAD
|
|
|
|
*/
|
|
|
|
engine_load_mode_e algorithm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* see
|
|
|
|
*/
|
|
|
|
float vbattDividerCoeff;
|
|
|
|
/**
|
|
|
|
* Cooling fan turn-on temperature threshold, in Celsuis
|
|
|
|
*/
|
|
|
|
float fanOnTemperature;
|
|
|
|
/**
|
|
|
|
* Cooling fan turn-off temperature threshold, in Celsuis
|
|
|
|
*/
|
|
|
|
float fanOffTemperature;
|
|
|
|
|
|
|
|
int canReadEnabled;
|
|
|
|
int canWriteEnabled;
|
|
|
|
can_nbc_e can_nbc_type;
|
|
|
|
int can_sleep_period;
|
|
|
|
|
|
|
|
int cylindersCount;
|
|
|
|
|
|
|
|
ignition_mode_e ignitionMode;
|
|
|
|
firing_order_e firingOrder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This magic constant is about four-stroke engines with camshaft position sensors.
|
|
|
|
* On any four stroke engine, each revolution of the camshaft is two revolutions
|
|
|
|
* of the crankshaft. If camshaft position is our primary sensor, we use this multiplier
|
|
|
|
* to convert from camshaft angles to crankshaft angles. All angels across the system
|
|
|
|
* should be crankshaft angles.
|
|
|
|
*/
|
|
|
|
|
|
|
|
float rpmMultiplier;
|
|
|
|
|
|
|
|
display_mode_e displayMode;
|
|
|
|
|
|
|
|
log_format_e logFormat;
|
|
|
|
|
|
|
|
int firmwareVersion;
|
|
|
|
int HD44780width;
|
|
|
|
int HD44780height;
|
|
|
|
|
|
|
|
adc_channel_e tpsAdcChannel;
|
|
|
|
int overrideCrankingIgnition;
|
|
|
|
int analogChartFrequency;
|
|
|
|
|
|
|
|
trigger_config_s triggerConfig;
|
|
|
|
|
|
|
|
int space;
|
2014-09-06 13:02:45 -07:00
|
|
|
adc_channel_e vbattAdcChannel;
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
float globalFuelCorrection;
|
|
|
|
|
|
|
|
// todo: merge with channel settings, use full-scale Thermistor!
|
|
|
|
adc_channel_e cltAdcChannel;
|
|
|
|
adc_channel_e iatAdcChannel;
|
|
|
|
adc_channel_e mafAdcChannel;
|
|
|
|
|
|
|
|
afr_sensor_s afrSensor;
|
|
|
|
|
|
|
|
float injectionOffset;
|
|
|
|
|
|
|
|
float crankingTimingAngle;
|
|
|
|
|
|
|
|
float diffLoadEnrichmentCoef;
|
|
|
|
|
|
|
|
air_pressure_sensor_config_s baroSensor;
|
|
|
|
|
|
|
|
float veLoadBins[VE_LOAD_COUNT];
|
|
|
|
float veRpmBins[VE_RPM_COUNT];
|
|
|
|
float afrLoadBins[AFR_LOAD_COUNT];
|
|
|
|
float afrRpmBins[AFR_RPM_COUNT];
|
|
|
|
|
|
|
|
// the large tables are always in the end - that's related to TunerStudio paging implementation
|
|
|
|
float fuelTable[FUEL_LOAD_COUNT][FUEL_RPM_COUNT]; // size 1024
|
|
|
|
float ignitionTable[IGN_LOAD_COUNT][IGN_RPM_COUNT]; // size 1024
|
|
|
|
|
|
|
|
float veTable[VE_LOAD_COUNT][VE_RPM_COUNT]; // size 1024
|
|
|
|
float afrTable[AFR_LOAD_COUNT][AFR_RPM_COUNT]; // size 1024
|
|
|
|
|
|
|
|
board_configuration_s bc;
|
|
|
|
|
|
|
|
int hasMapSensor;
|
|
|
|
int hasCltSensor;
|
|
|
|
|
|
|
|
idle_mode_e idleMode;
|
|
|
|
|
|
|
|
bool isInjectionEnabled : 1; // bit 0
|
|
|
|
bool isIgnitionEnabled : 1; // bit 1
|
|
|
|
bool isCylinderCleanupEnabled : 1; // bit 2
|
|
|
|
bool secondTriggerChannelEnabled : 1; // bit 3
|
|
|
|
bool needSecondTriggerInput : 1; // bit 4
|
|
|
|
|
2014-08-29 21:02:49 -07:00
|
|
|
int digitalChartSize;
|
|
|
|
|
|
|
|
int unused3[7];
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
} engine_configuration_s;
|
|
|
|
|
|
|
|
void setOperationMode(engine_configuration_s *engineConfiguration, operation_mode_e mode);
|
|
|
|
operation_mode_e getOperationMode(engine_configuration_s const *engineConfiguration);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
engine_configuration_s engineConfiguration;
|
|
|
|
} persistent_config_s;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int version;
|
|
|
|
int size;
|
|
|
|
persistent_config_s persistentConfiguration;
|
|
|
|
crc_t value;
|
|
|
|
} persistent_config_container_s;
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_configuration_s *boardConfiguration);
|
|
|
|
void setWholeFuelMap(engine_configuration_s *engineConfiguration, float value);
|
|
|
|
void setConstantDwell(engine_configuration_s *engineConfiguration, float dwellMs);
|
|
|
|
void printFloatArray(const char *prefix, float array[], int size);
|
|
|
|
|
|
|
|
void incrementGlobalConfigurationVersion(void);
|
|
|
|
int getGlobalConfigurationVersion(void);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif /* ENGINE_CONFIGURATION_H_ */
|