rusEFI
The most advanced open source ECU
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;
35 private:
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 
51 public:
52  IgnitionEvent();
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  int sparkCounter = 0;
84  /**
85  * [0, cylindersCount)
86  */
87  int cylinderIndex = 0;
88  // previously known as cylinderNumber
89  int8_t coilIndex = 0;
90  char *name = nullptr;
92 };
93 
95 public:
96  /**
97  * ignition events, per cylinder
98  */
99  IgnitionEvent elements[MAX_CYLINDER_COUNT];
100  bool isReady = false;
101 };
102 
103 class AuxActor {
104 public:
108 
111 };
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
angle_t sparkAngle
IgnitionOutputPin * outputs[MAX_OUTPUTS_FOR_IGNITION]
Timer actualDwellTimer
scheduling_s trailingSparkCharge
IgnitionEvent elements[MAX_CYLINDER_COUNT]
EFI-related GPIO code.
IgnitionEventList * getIgnitionEvents()
Definition: engine.cpp:605
Fixed-length stack.
float floatms_t
Definition: rusefi_types.h:67
float angle_t
Definition: rusefi_types.h:58
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