rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
event_registry.h
Go to the documentation of this file.
1/**
2 * @file event_registry.h
3 *
4 * @date Nov 27, 2013
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#pragma once
9
10#include "global.h"
11#include "efi_gpio.h"
12#include "scheduler.h"
13#include "fl_stack.h"
14#include "trigger_structure.h"
15
19 /**
20 * Trigger-based scheduler maintains a linked list of all pending tooth-based events.
21 */
23
24 // angular position of this event
25 angle_t getAngle() const {
26 return enginePhase;
27 }
28
29 void setAngle(angle_t p_enginePhase) {
30 enginePhase = p_enginePhase;
31 }
32
33 bool shouldSchedule(float currentPhase, float nextPhase) const;
34 float getAngleFromNow(float currentPhase) const;
35private:
37};
38
39// this is related to wasted spark idea where engines fire each spark twice per 4 stroke 720 degree cycle of operations
40// first spark is happens on intake stroke and actually ignites fuel mixture, that's the useful one
41// the other spark 360 degrees later happens during exhaust stroke meaning there is nothing to ignite, that spark is known as "wasted" spark
42// historically this was about sharing ignition coils between opposite cylinders and having two high voltage wire coming from one physical coil
43// more recently same idea happens with two individual physical coils (meaning two outputs) since wasted spark of operation is useful
44// while exact engine phase is either not known YET (cranking) or just not known (broken cam sensor)
45// so, while in wasted spark we manage half of cylinder count _events_ potentially with each event having two outputs
46//
47// an interesting corner case is when we transition from wasted spark mode into individual/sequential mode
48#define MAX_OUTPUTS_FOR_IGNITION 2
49
51public:
53 // IgnitionEvent to IgnitionOutputPin is either 1 to 1 or 1 to 2 relationship, see large comment at 'MAX_OUTPUTS_FOR_IGNITION'
54 IgnitionOutputPin *outputs[MAX_OUTPUTS_FOR_IGNITION];
57
60
61 // How many additional sparks should we fire after the first one?
62 // For single sparks, this should be zero.
63 uint8_t sparksRemaining = 0;
64
65 // Track whether coil charge was intentionally skipped (spark limiter)
66 bool wasSparkLimited = false;
67
68 /**
69 * Desired timing advance
70 */
73
74 // this timer allows us to measure actual dwell time
76
77 float dwellAngle = 0;
78
79 /**
80 * Sequential number of currently processed spark event
81 * @see engineState.globalSparkCounter
82 */
83 uint32_t sparkCounter = 0;
84 /**
85 * [0, cylindersCount)
86 */
88 // previously known as cylinderNumber
89 int8_t coilIndex = 0;
90 char *name = nullptr;
92};
93
95public:
96 /**
97 * ignition events, per cylinder
98 */
99 IgnitionEvent elements[MAX_CYLINDER_COUNT];
100 bool isReady = false;
101};
102
112
113
angle_t extra
AngleBasedEvent close
AngleBasedEvent open
floatms_t sparkDwell
scheduling_s trailingSparkFire
uint8_t sparksRemaining
scheduling_s dwellStartTimer
IgnitionOutputPin * getOutputForLoggins()
AngleBasedEvent sparkEvent
uint32_t sparkCounter
IgnitionOutputPin * outputs[MAX_OUTPUTS_FOR_IGNITION]
scheduling_s trailingSparkCharge
IgnitionEvent elements[MAX_CYLINDER_COUNT]
EFI-related GPIO code.
IgnitionEventList * getIgnitionEvents()
Definition engine.cpp:604
Fixed-length stack.
void setAngle(angle_t p_enginePhase)
angle_t getAngle() const
bool shouldSchedule(float currentPhase, float nextPhase) const
float getAngleFromNow(float currentPhase) const
AngleBasedEvent * nextToothEvent
scheduling_s eventScheduling