2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file event_registry.h
|
|
|
|
*
|
|
|
|
* @date Nov 27, 2013
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2019-10-07 22:49:42 -07:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "global.h"
|
2019-10-08 00:14:21 -07:00
|
|
|
#include "efi_gpio.h"
|
|
|
|
#include "scheduler.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "fl_stack.h"
|
2016-12-18 19:03:00 -08:00
|
|
|
#include "trigger_structure.h"
|
2020-07-20 00:04:05 -07:00
|
|
|
#include "accel_enrichment.h"
|
2021-10-16 17:16:40 -07:00
|
|
|
#include "wall_fuel.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-07 23:35:21 -07:00
|
|
|
#define MAX_WIRES_COUNT 2
|
2019-10-07 23:13:52 -07:00
|
|
|
|
2016-11-30 19:06:43 -08:00
|
|
|
class Engine;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class InjectionEvent {
|
|
|
|
public:
|
|
|
|
InjectionEvent();
|
2020-07-24 18:26:24 -07:00
|
|
|
|
|
|
|
// Call this every decoded trigger tooth. It will schedule any relevant events for this injector.
|
|
|
|
void onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
2016-07-17 09:02:12 -07:00
|
|
|
* This is a performance optimization for IM_SIMULTANEOUS fuel strategy.
|
|
|
|
* It's more efficient to handle all injectors together if that's the case
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2020-07-24 18:26:24 -07:00
|
|
|
bool isSimultanious = false;
|
2016-11-30 16:01:43 -08:00
|
|
|
InjectorOutputPin *outputs[MAX_WIRES_COUNT];
|
2021-05-09 06:37:07 -07:00
|
|
|
uint8_t ownIndex = 0;
|
|
|
|
uint8_t cylinderNumber = 0;
|
2019-12-02 20:08:18 -08:00
|
|
|
DECLARE_ENGINE_PTR;
|
2016-01-24 23:03:01 -08:00
|
|
|
event_trigger_position_s injectionStart;
|
2019-10-07 23:35:21 -07:00
|
|
|
|
2019-10-07 23:56:19 -07:00
|
|
|
scheduling_s signalTimerUp;
|
|
|
|
scheduling_s endOfInjectionEvent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed.
|
|
|
|
*
|
|
|
|
* That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see
|
|
|
|
* overlaps so we need the end counter to always have zero.
|
|
|
|
* TODO: make watchdog decrement relevant counter
|
|
|
|
*/
|
|
|
|
bool isScheduled = false;
|
2020-07-20 00:04:05 -07:00
|
|
|
|
|
|
|
WallFuel wallFuel;
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
2019-10-07 23:13:52 -07:00
|
|
|
/**
|
|
|
|
* This class knows about when to inject fuel
|
|
|
|
*/
|
|
|
|
class FuelSchedule {
|
|
|
|
public:
|
|
|
|
FuelSchedule();
|
2020-07-24 18:26:24 -07:00
|
|
|
|
2021-01-11 05:01:54 -08:00
|
|
|
// Call this function if something happens that requires a rebuild, like a change to the trigger pattern
|
|
|
|
void invalidate();
|
|
|
|
|
2020-07-24 18:26:24 -07:00
|
|
|
// Call this every trigger tooth. It will schedule all required injector events.
|
|
|
|
void onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
|
2019-10-07 23:13:52 -07:00
|
|
|
/**
|
|
|
|
* this method schedules all fuel events for an engine cycle
|
|
|
|
*/
|
|
|
|
void addFuelEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
bool addFuelEventsForCylinder(int cylinderIndex DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
|
2020-07-14 23:54:41 -07:00
|
|
|
void resetOverlapping();
|
|
|
|
|
2019-10-07 23:13:52 -07:00
|
|
|
/**
|
|
|
|
* injection events, per cylinder
|
|
|
|
*/
|
2021-07-06 17:14:08 -07:00
|
|
|
InjectionEvent elements[MAX_CYLINDER_COUNT];
|
2021-01-11 05:01:54 -08:00
|
|
|
bool isReady = false;
|
2019-10-07 23:13:52 -07:00
|
|
|
};
|
|
|
|
|
2019-11-23 16:47:53 -08:00
|
|
|
class AngleBasedEvent {
|
|
|
|
public:
|
|
|
|
scheduling_s scheduling;
|
|
|
|
event_trigger_position_s position;
|
|
|
|
action_s action;
|
2019-11-23 17:36:40 -08:00
|
|
|
/**
|
|
|
|
* Trigger-based scheduler maintains a linked list of all pending tooth-based events.
|
|
|
|
*/
|
|
|
|
AngleBasedEvent *nextToothEvent = nullptr;
|
2019-11-23 16:47:53 -08:00
|
|
|
};
|
|
|
|
|
2016-11-26 21:01:22 -08:00
|
|
|
#define MAX_OUTPUTS_FOR_IGNITION 2
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class IgnitionEvent {
|
|
|
|
public:
|
|
|
|
IgnitionEvent();
|
2016-11-27 18:04:45 -08:00
|
|
|
IgnitionOutputPin *outputs[MAX_OUTPUTS_FOR_IGNITION];
|
2019-10-07 23:01:41 -07:00
|
|
|
scheduling_s dwellStartTimer;
|
2019-11-23 16:47:53 -08:00
|
|
|
AngleBasedEvent sparkEvent;
|
2020-03-25 22:49:36 -07:00
|
|
|
|
2021-07-09 05:37:46 -07:00
|
|
|
scheduling_s trailingSparkCharge;
|
|
|
|
scheduling_s trailingSparkFire;
|
|
|
|
|
2020-03-25 22:49:36 -07:00
|
|
|
// How many additional sparks should we fire after the first one?
|
|
|
|
// For single sparks, this should be zero.
|
|
|
|
uint8_t sparksRemaining = 0;
|
|
|
|
|
2019-10-07 23:01:41 -07:00
|
|
|
/**
|
|
|
|
* Desired timing advance
|
|
|
|
*/
|
2019-11-23 20:49:39 -08:00
|
|
|
angle_t sparkAngle = NAN;
|
2020-07-29 02:22:54 -07:00
|
|
|
floatms_t sparkDwell = 0;
|
2019-10-07 23:01:41 -07:00
|
|
|
/**
|
|
|
|
* this timestamp allows us to measure actual dwell time
|
|
|
|
*/
|
2020-07-29 02:22:54 -07:00
|
|
|
uint32_t actualStartOfDwellNt = 0;
|
|
|
|
event_trigger_position_s dwellPosition{};
|
2016-11-28 11:01:52 -08:00
|
|
|
/**
|
2019-10-07 23:01:41 -07:00
|
|
|
* Sequential number of currently processed spark event
|
2019-10-07 22:36:03 -07:00
|
|
|
* @see globalSparkIdCounter
|
2016-11-28 11:01:52 -08:00
|
|
|
*/
|
2019-10-07 21:27:49 -07:00
|
|
|
int sparkId = 0;
|
2017-03-11 19:22:10 -08:00
|
|
|
/**
|
|
|
|
* [0, specs.cylindersCount)
|
|
|
|
*/
|
2019-10-07 21:27:49 -07:00
|
|
|
int cylinderIndex = 0;
|
2020-08-31 18:05:33 -07:00
|
|
|
int8_t cylinderNumber = 0;
|
2019-10-07 22:26:35 -07:00
|
|
|
char *name = nullptr;
|
2019-12-02 20:08:18 -08:00
|
|
|
DECLARE_ENGINE_PTR;
|
2016-11-27 18:04:45 -08:00
|
|
|
IgnitionOutputPin *getOutputForLoggins();
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
2016-11-28 10:02:24 -08:00
|
|
|
class IgnitionEventList {
|
2016-11-28 09:03:02 -08:00
|
|
|
public:
|
2019-10-07 23:13:52 -07:00
|
|
|
/**
|
|
|
|
* ignition events, per cylinder
|
|
|
|
*/
|
2021-07-06 17:14:08 -07:00
|
|
|
IgnitionEvent elements[MAX_CYLINDER_COUNT];
|
2019-10-07 23:01:41 -07:00
|
|
|
bool isReady = false;
|
2016-11-28 09:03:02 -08:00
|
|
|
};
|
2019-12-02 21:29:12 -08:00
|
|
|
|
|
|
|
class AuxActor {
|
|
|
|
public:
|
|
|
|
int phaseIndex;
|
|
|
|
int valveIndex;
|
|
|
|
angle_t extra;
|
|
|
|
|
|
|
|
AngleBasedEvent open;
|
|
|
|
AngleBasedEvent close;
|
|
|
|
DECLARE_ENGINE_PTR;
|
|
|
|
};
|