rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
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
21
22int 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
38
39void 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
57int getCurrentCdmValue(int currentRevolution) {
58 return instance.getValue(currentRevolution);
59}
60
61#if EFI_TUNER_STUDIO
62void ionPostState(TunerStudioOutputChannels *tsOutputChannels) {
63 tsOutputChannels->debugIntField1 = instance.totalCdmEvents;
64}
65#endif /* EFI_TUNER_STUDIO */
66
67static void extIonCallback(void *arg) {
68 UNUSED(arg);
70
72 instance.onNewSignal(currentRevolution);
73}
74
75void 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
int getValue(int currentRevolution)
int currentValue
void onNewSignal(int currentRevolution)
int currentValueAtIndex
int accumulatingCurrentValue
int accumilatingAtRevolution
TriggerCentral triggerCentral
Definition engine.h:318
PrimaryTriggerDecoder triggerState
int getSynchronizationCounter() const
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
UNUSED(samplingTimeSeconds)
bool isBrainPinValid(brain_pin_e brainPin)