rusEFI
The most advanced open source ECU
Functions | Variables
main_trigger_callback.cpp File Reference

Detailed Description

Main logic is here!

See http://rusefi.com/docs/html/

Date
Feb 7, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

This file is part of rusEfi - see http://rusefi.com

rusEfi is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file main_trigger_callback.cpp.

Functions

void endSimultaneousInjection (InjectionEvent *event)
 
void turnInjectionPinLow (InjectionEvent *event)
 
static void turnInjectionPinLowStage2 (InjectionEvent *event)
 
static void handleFuel (efitick_t nowNt, float currentPhase, float nextPhase)
 
void mainTriggerCallback (uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_t currentPhase, angle_t nextPhase)
 

Variables

bool printFuelDebug = false
 

Function Documentation

◆ endSimultaneousInjection()

void endSimultaneousInjection ( InjectionEvent event)

Definition at line 50 of file main_trigger_callback.cpp.

50  {
52  event->update();
53 }
void endSimultaneousInjectionOnlyTogglePins()

Referenced by InjectionEvent::onTriggerTooth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFuel()

static void handleFuel ( efitick_t  nowNt,
float  currentPhase,
float  nextPhase 
)
static

Definition at line 213 of file main_trigger_callback.cpp.

213  {
215 
216  efiAssertVoid(ObdCode::CUSTOM_STACK_6627, hasLotsOfRemainingStack(), "lowstck#3");
217 
218  LimpState limitedFuelState = getLimpManager()->allowInjection();
219 
220  // todo: eliminate state copy logic by giving limpManager it's owm limp_manager.txt and leveraging LiveData
221  engine->outputChannels.fuelCutReason = (int8_t)limitedFuelState.reason;
222  bool limitedFuel = !limitedFuelState.value;
223  if (limitedFuel) {
224  return;
225  }
226 
227  // This is called in the fast callback already, but since we may have just achieved engine sync (and RPM)
228  // for the first time, force update the schedule so that we can inject immediately if necessary
230  if (!fs->isReady) {
231  fs->addFuelEvents();
232  }
233 
234 #if FUEL_MATH_EXTREME_LOGGING
235  if (printFuelDebug) {
236  efiPrintf("handleFuel [%.1f, %.1f) %d", currentPhase, nextPhase, getRevolutionCounter());
237  }
238 #endif /* FUEL_MATH_EXTREME_LOGGING */
239 
240  fs->onTriggerTooth(nowNt, currentPhase, nextPhase);
241 }
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
void onTriggerTooth(efitick_t nowNt, float currentPhase, float nextPhase)
void addFuelEvents()
LimpState allowInjection() const
FuelSchedule * getFuelSchedule()
Definition: engine.cpp:599
LimpManager * getLimpManager()
Definition: engine.cpp:595
Engine * engine
bool printFuelDebug
@ CUSTOM_STACK_6627
@ HandleFuel
const bool value
Definition: limp_manager.h:76
const ClearReason reason
Definition: limp_manager.h:77

Referenced by mainTriggerCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mainTriggerCallback()

void mainTriggerCallback ( uint32_t  trgEventIndex,
efitick_t  edgeTimestamp,
angle_t  currentPhase,
angle_t  nextPhase 
)

This is the main trigger event handler. Both injection and ignition are controlled from this method.

In case on a major error we should not process any more events.

For fuel we schedule start of injection based on trigger angle, and then inject for specified duration of time

For spark we schedule both start of coil charge and actual spark based on trigger angle

Definition at line 247 of file main_trigger_callback.cpp.

247  {
249 
250 #if ! HW_CHECK_MODE
251  if (hasFirmwareError()) {
252  /**
253  * In case on a major error we should not process any more events.
254  */
255  return;
256  }
257 #endif // HW_CHECK_MODE
258 
259  int rpm = engine->rpmCalculator.getCachedRpm();
260  if (rpm == 0) {
261  // this happens while we just start cranking
262 
263  // todo: check for 'trigger->is_synchnonized?'
264  return;
265  }
266  if (rpm == NOISY_RPM) {
268  return;
269  }
270 
271 
272  if (trgEventIndex == 0) {
273 
274  if (getTriggerCentral()->checkIfTriggerConfigChanged()) {
275  getIgnitionEvents()->isReady = false; // we need to rebuild complete ignition schedule
276  getFuelSchedule()->isReady = false;
277  // moved 'triggerIndexByAngle' into trigger initialization (why was it invoked from here if it's only about trigger shape & optimization?)
278  // see updateTriggerWaveform() -> prepareOutputSignals()
279 
280  // we need this to apply new 'triggerIndexByAngle' values
282  }
283  }
284 
285  /**
286  * For fuel we schedule start of injection based on trigger angle, and then inject for
287  * specified duration of time
288  */
289  handleFuel(edgeTimestamp, currentPhase, nextPhase);
290 
291  engine->module<TriggerScheduler>()->scheduleEventsUntilNextTriggerTooth(
292  rpm, edgeTimestamp, currentPhase, nextPhase);
293 
294  /**
295  * For spark we schedule both start of coil charge and actual spark based on trigger angle
296  */
297  onTriggerEventSparkLogic(rpm, edgeTimestamp, currentPhase, nextPhase);
298 }
void periodicFastCallback()
Definition: engine.cpp:557
RpmCalculator rpmCalculator
Definition: engine.h:265
constexpr auto & module()
Definition: engine.h:174
float getCachedRpm() const
IgnitionEventList * getIgnitionEvents()
Definition: engine.cpp:603
TriggerCentral * getTriggerCentral()
Definition: engine.cpp:589
bool warning(ObdCode code, const char *fmt,...)
static void handleFuel(efitick_t nowNt, float currentPhase, float nextPhase)
@ OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction
@ MainTriggerCallback
void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase)

Referenced by TriggerCentral::handleShaftSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ turnInjectionPinLow()

void turnInjectionPinLow ( InjectionEvent event)

Definition at line 55 of file main_trigger_callback.cpp.

55  {
56  efitick_t nowNt = getTimeNowNt();
57 
58  for (size_t i = 0; i < efi::size(event->outputs); i++) {
59  InjectorOutputPin *output = event->outputs[i];
60  if (output) {
61  output->close(nowNt);
62  }
63  }
64  event->update();
65 }
InjectorOutputPin * outputs[MAX_WIRES_COUNT]
Definition: fuel_schedule.h:50
void close(efitick_t nowNt)
efitick_t getTimeNowNt()
Definition: efitime.cpp:19
composite packet size

Referenced by InjectionEvent::onTriggerTooth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ turnInjectionPinLowStage2()

static void turnInjectionPinLowStage2 ( InjectionEvent event)
static

Definition at line 67 of file main_trigger_callback.cpp.

67  {
68  efitick_t nowNt = getTimeNowNt();
69 
70  for (size_t i = 0; i < efi::size(event->outputsStage2); i++) {
71  InjectorOutputPin *output = event->outputsStage2[i];
72  if (output) {
73  output->close(nowNt);
74  }
75  }
76 }
InjectorOutputPin * outputsStage2[MAX_WIRES_COUNT]
Definition: fuel_schedule.h:51

Referenced by InjectionEvent::onTriggerTooth().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ printFuelDebug

bool printFuelDebug = false

Go to the source code of this file.