rusEFI
The most advanced open source ECU
cdm_ion_sense.cpp
Go to the documentation of this file.
1 /*
2  * @file cdm_ion_sense.cpp
3  *
4  * Saab Ion Sensing Module integration
5  *
6  * See https://github.com/rusefi/rusefi/wiki/Saab_Trionic_8_Combustion-Detection-Module_on_Mazda_Miata_running_rusEfi
7  *
8  * Created on: Dec 31, 2018
9  * @author Andrey Belomutskiy, (c) 2012-2020
10  */
11 
12 #include "pch.h"
13 
14 #include "cdm_ion_sense.h"
15 
18  currentValue = 0;
20 }
21 
22 int CdmState::getValue(int currentRevolution) {
23  applyAccumulatedData(currentRevolution);
24  if (currentRevolution == currentValueAtIndex + 1) {
25  // returning total result of previous engine cycle
26  return currentValue;
27  }
28  // we are here if previous engine cycle had no knock events
29  return 0;
30 }
31 
32 void CdmState::applyAccumulatedData(int currentRevolution) {
33  if (currentRevolution > accumilatingAtRevolution) {
36  }
37 }
38 
39 void CdmState::onNewSignal(int currentRevolution) {
40  if (this->accumilatingAtRevolution == currentRevolution) {
42  } else {
43  applyAccumulatedData(currentRevolution);
44  // start new accumulation
45  accumilatingAtRevolution = currentRevolution;
47  }
48 }
49 
50 // above logic compiles unconditionally so that unit tests are happy, but without an instance linker would have nothing to link
51 #if EFI_CDM_INTEGRATION
52 
53 #include "digital_input_exti.h"
54 
56 
57 int getCurrentCdmValue(int currentRevolution) {
58  return instance.getValue(currentRevolution);
59 }
60 
61 #if EFI_TUNER_STUDIO
62 void ionPostState(TunerStudioOutputChannels *tsOutputChannels) {
63  tsOutputChannels->debugIntField1 = instance.totalCdmEvents;
64 }
65 #endif /* EFI_TUNER_STUDIO */
66 
67 static void extIonCallback(void *arg) {
68  UNUSED(arg);
70 
72  instance.onNewSignal(currentRevolution);
73 }
74 
75 void cdmIonInit(void) {
77  return;
78  }
79 
80  efiExtiEnablePin("ion", engineConfiguration->cdmInputPin, PAL_EVENT_MODE_RISING_EDGE, extIonCallback, NULL);
81 }
82 
83 #endif /* EFI_CDM_INTEGRATION */
void ionPostState(TunerStudioOutputChannels *tsOutputChannels)
void cdmIonInit(void)
static void extIonCallback(void *arg)
int getCurrentCdmValue(int currentRevolution)
static CdmState instance
void applyAccumulatedData(int currentRevolution)
int totalCdmEvents
Definition: cdm_ion_sense.h:16
int getValue(int currentRevolution)
int currentValue
Definition: cdm_ion_sense.h:26
void onNewSignal(int currentRevolution)
int currentValueAtIndex
Definition: cdm_ion_sense.h:27
int accumulatingCurrentValue
Definition: cdm_ion_sense.h:22
int accumilatingAtRevolution
Definition: cdm_ion_sense.h:18
TriggerCentral triggerCentral
Definition: engine.h:278
PrimaryTriggerDecoder triggerState
int getCrankSynchronizationCounter() const
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
Engine * engine
UNUSED(samplingTimeSeconds)
engine_configuration_s * engineConfiguration
bool isBrainPinValid(brain_pin_e brainPin)