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

123 lines
2.7 KiB
C
Raw Normal View History

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"
struct AngleBasedEventOld;
struct AngleBasedEventBase {
scheduling_s scheduling;
action_s action;
/**
* Trigger-based scheduler maintains a linked list of all pending tooth-based events.
*/
AngleBasedEventBase *nextToothEvent = nullptr;
virtual bool shouldSchedule(uint32_t trgEventIndex, float currentPhase, float nextPhase) const = 0;
virtual float getAngleFromNow(float currentPhase) const = 0;
virtual AngleBasedEventOld* asOld() { return nullptr; }
};
2022-11-05 22:11:33 -07:00
/**
* This structure defines an angle position in relation to specific tooth within trigger shape
*/
class event_trigger_position_s {
public:
size_t triggerEventIndex = 0;
angle_t angleOffsetFromTriggerEvent = 0;
void setAngle(angle_t angle);
};
struct AngleBasedEventOld : public AngleBasedEventBase {
event_trigger_position_s position;
bool shouldSchedule(uint32_t trgEventIndex, float currentPhase, float nextPhase) const override;
float getAngleFromNow(float currentPhase) const override;
AngleBasedEventOld* asOld() override { return this; }
};
struct AngleBasedEventNew : public AngleBasedEventBase {
float enginePhase;
bool shouldSchedule(uint32_t trgEventIndex, float currentPhase, float nextPhase) const override;
float getAngleFromNow(float currentPhase) const override;
};
2016-11-26 21:01:22 -08:00
#define MAX_OUTPUTS_FOR_IGNITION 2
class IgnitionEvent {
2015-07-10 06:01:56 -07:00
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;
AngleBasedEventNew sparkEvent;
scheduling_s trailingSparkCharge;
scheduling_s trailingSparkFire;
// 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;
float dwellAngle = 0;
2016-11-28 11:01:52 -08:00
/**
2019-10-07 23:01:41 -07:00
* Sequential number of currently processed spark event
* @see engineState.sparkCounter
2016-11-28 11:01:52 -08:00
*/
int sparkId = 0;
2017-03-11 19:22:10 -08:00
/**
* [0, specs.cylindersCount)
*/
int cylinderIndex = 0;
int8_t cylinderNumber = 0;
2019-10-07 22:26:35 -07:00
char *name = nullptr;
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:
/**
* ignition events, per cylinder
*/
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 {
2019-12-02 21:29:12 -08:00
public:
int phaseIndex;
int valveIndex;
angle_t extra;
AngleBasedEventOld open;
AngleBasedEventOld close;
2019-12-02 21:29:12 -08:00
};
IgnitionEventList *getIgnitionEvents();