fome-fw/firmware/controllers/algo/engine.h

184 lines
4.1 KiB
C
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file engine.h
*
* @date May 21, 2014
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*/
#ifndef ENGINE_H_
#define ENGINE_H_
#include "main.h"
#include "engine_configuration.h"
2014-11-11 13:05:09 -08:00
#include "rpm_calculator.h"
2014-08-29 07:52:33 -07:00
2015-01-12 16:05:46 -08:00
#include "global.h"
#include "engine_configuration.h"
#include "event_registry.h"
#include "trigger_structure.h"
#include "table_helper.h"
2015-01-12 17:07:40 -08:00
/**
* This class knows about when to inject fuel
*/
2015-01-12 16:05:46 -08:00
class FuelSchedule {
public:
FuelSchedule();
ActuatorEventList events;
2015-01-12 17:07:40 -08:00
/**
* this method schedules all fuel events for an engine cycle
*/
2015-01-12 16:05:46 -08:00
void addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_S);
2015-01-12 17:07:40 -08:00
/**
* This is a performance optimization for https://sourceforge.net/p/rusefi/tickets/64/
* TODO: better data structure? better algorithm?
*/
2015-01-12 16:05:46 -08:00
uint8_t hasEvents[PWM_PHASE_MAX_COUNT];
2015-01-12 17:07:40 -08:00
private:
void clear();
void registerInjectionEvent(io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S);
2015-01-12 16:05:46 -08:00
};
/**
* this part of the structure is separate just because so far
* these fields are not integrated with Tuner Studio. Step by step :)
*/
class engine_configuration2_s {
// todo: move these fields into Engine class, eliminate this class
public:
engine_configuration2_s();
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
FuelSchedule crankingInjectionEvents;
FuelSchedule injectionEvents;
#endif
float fsioLastValue[LE_COMMAND_COUNT];
/**
* We are alternating two event lists in order to avoid a potential issue around revolution boundary
* when an event is scheduled within the next revolution.
*/
IgnitionEventList ignitionEvents[2];
};
2014-08-29 07:52:33 -07:00
class EngineState {
public:
/**
* Access to these two fields is not synchronized in any way - that should work since float read/write are atomic.
*/
float iat;
float clt;
2014-09-26 11:06:01 -07:00
2014-08-29 07:52:33 -07:00
};
class RpmCalculator;
class Engine {
public:
2014-11-07 20:03:53 -08:00
Engine();
2014-09-26 13:03:02 -07:00
void init();
2014-11-11 13:05:09 -08:00
RpmCalculator rpmCalculator;
2014-08-29 07:52:33 -07:00
engine_configuration_s *engineConfiguration;
2014-09-26 11:06:01 -07:00
engine_configuration2_s *engineConfiguration2;
2014-08-29 07:52:33 -07:00
2015-01-01 14:03:28 -08:00
uint64_t stopEngineRequestTimeNt;
2014-10-31 12:03:00 -07:00
Thermistor iat;
Thermistor clt;
2014-11-25 10:03:01 -08:00
float dwellAngle;
float advance;
2015-01-03 21:03:23 -08:00
bool_t clutchUpState;
bool_t clutchDownState;
2014-11-24 13:03:32 -08:00
trigger_shape_s triggerShape;
2014-11-25 17:03:21 -08:00
float angleExtra[IGNITION_PIN_COUNT];
io_pin_e ignitionPin[IGNITION_PIN_COUNT];
2014-11-11 06:03:18 -08:00
void onTriggerEvent(uint64_t nowNt);
2014-08-29 07:52:33 -07:00
EngineState engineState;
2014-11-11 06:03:18 -08:00
uint64_t lastTriggerEventTimeNt;
2014-08-29 07:52:33 -07:00
2014-10-31 12:03:00 -07:00
/**
* This coefficient translates ADC value directly into voltage adjusted according to
* voltage divider configuration. This is a future (?) performance optimization.
*/
float adcToVoltageInputDividerCoefficient;
/**
* This field is true if we are in 'cylinder cleanup' state right now
* see isCylinderCleanupEnabled
*/
bool isCylinderCleanupMode;
2014-11-25 06:03:01 -08:00
/**
* pre-calculating this value is a performance optimization
*/
int engineCycleEventCount;
2014-11-24 17:03:21 -08:00
uint32_t beforeIgnitionMath;
2014-11-24 15:04:41 -08:00
uint32_t ignitionMathTime;
2014-11-25 10:03:01 -08:00
uint32_t beforeIgnitionSch;
uint32_t ignitionSchTime;
2014-11-25 06:03:01 -08:00
uint32_t time2;
uint32_t time3;
uint32_t time4;
2014-11-25 16:04:39 -08:00
uint32_t time5;
uint32_t time6;
2014-11-25 06:03:01 -08:00
uint32_t before2;
uint32_t before3;
uint32_t before4;
2014-11-25 16:04:39 -08:00
uint32_t before5;
uint32_t before6;
2014-11-25 06:03:01 -08:00
2015-01-01 14:03:28 -08:00
float sparkAtable[DWELL_CURVE_SIZE];
float sparkBtable[DWELL_CURVE_SIZE];
2014-11-25 06:03:01 -08:00
2015-01-01 14:03:28 -08:00
Table2D sparkTable;
void precalc(engine_configuration_s *engineConfiguration);
2014-10-31 12:03:00 -07:00
2014-08-29 07:52:33 -07:00
void updateSlowSensors();
2014-09-26 13:03:02 -07:00
void watchdog();
private:
/**
* By the way:
* 'cranking' means engine is not stopped and the rpm are below crankingRpm
* 'running' means RPM are above crankingRpm
* 'spinning' means the engine is not stopped
*/
bool isSpinning;
2014-09-27 16:02:54 -07:00
bool stopPins();
2014-08-29 07:52:33 -07:00
};
2014-10-17 14:03:00 -07:00
/**
* 6 crossing over 50% TPS means pressing and releasing three times
*/
#define PUMPS_TO_PRIME 6
2014-10-17 13:05:16 -07:00
2014-10-17 12:02:59 -07:00
class StartupFuelPumping {
public:
StartupFuelPumping();
2014-11-24 19:03:19 -08:00
void update(DECLARE_ENGINE_PARAMETER_F);
2014-10-17 12:02:59 -07:00
bool isTpsAbove50;
int pumpsCounter;
private:
2014-10-17 13:05:16 -07:00
void setPumpsCounter(engine_configuration_s *engineConfiguration, int newValue);
2014-10-17 12:02:59 -07:00
};
2014-11-10 07:03:20 -08:00
void prepareShapes(Engine *engine);
2014-10-31 13:03:07 -07:00
void resetConfigurationExt(Logging * logger, engine_type_e engineType,
Engine *engine);
void applyNonPersistentConfiguration(Logging * logger, Engine *engine);
2014-11-25 10:03:01 -08:00
void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_F);
2014-10-31 13:03:07 -07:00
2014-08-29 07:52:33 -07:00
#endif /* ENGINE_H_ */