rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
trigger_input_adc.cpp File Reference

Detailed Description

Position sensor hardware layer, Using ADC and software comparator.

Date
Jan 27, 2020
Author
andreika prome.nosp@m.theu.nosp@m.s.pcb.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Andrey Belomutskiy, (c) 2012-2020

Definition in file trigger_input_adc.cpp.

Functions

void toggleLed (int led, int mode)
 
void setTriggerAdcMode (triggerAdcMode_t adcMode)
 
static void shaft_callback (void *arg, efitick_t stamp)
 
static void cam_callback (void *, efitick_t stamp)
 
void triggerAdcCallback (triggerAdcSample_t value)
 
static void printDumpBuf (void)
 
int adcTriggerTurnOnInputPin (const char *msg, int index, bool isTriggerShaft)
 
void adcTriggerTurnOffInputPin (brain_pin_e brainPin)
 
void adcTriggerTurnOnInputPins ()
 
adc_channel_e getAdcChannelForTrigger (void)
 
void addAdcChannelForTrigger (void)
 
void onTriggerChanged (efitick_t stamp, bool isPrimary, bool isRising)
 
triggerAdcMode_t getTriggerAdcMode (void)
 
float getTriggerAdcThreshold (void)
 
int getTriggerAdcModeCnt (void)
 

Variables

TriggerAdcDetector trigAdcState
 
static const int dumpBufNum = 100
 
static triggerAdcSample_t dumpBuf [dumpBufNum]
 
static int dumpBufCnt = 0
 
static ioportid_t triggerInputPort
 
static ioportmask_t triggerInputPin
 

Function Documentation

◆ adcTriggerTurnOffInputPin()

void adcTriggerTurnOffInputPin ( brain_pin_e  brainPin)

Definition at line 143 of file trigger_input_adc.cpp.

143 {
144 efiExtiDisablePin(brainPin);
145}
void efiExtiDisablePin(brain_pin_e brainPin)

Referenced by turnOffTriggerInputPin().

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

◆ adcTriggerTurnOnInputPin()

int adcTriggerTurnOnInputPin ( const char msg,
int  index,
bool  isTriggerShaft 
)

Definition at line 109 of file trigger_input_adc.cpp.

109 {
110 brain_pin_e brainPin = isTriggerShaft ?
112
114
115 triggerInputPort = getHwPort("trg", brainPin);
116 triggerInputPin = getHwPin("trg", brainPin);
117
118 ioline_t pal_line = PAL_LINE(triggerInputPort, triggerInputPin);
119 efiPrintf("turnOnTriggerInputPin %s l=%ld", hwPortname(brainPin), pal_line);
120
121 if (efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES,
122 isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line) < 0) {
123 return -1;
124 }
125
126 // ADC mode is default, because we don't know if the wheel is already spinning
128
129#ifdef TRIGGER_ADC_DEBUG_LED
130 palSetPadMode(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
131#ifdef DEBUG_OUTPUT_IGN1
132 palSetPadMode(GPIOI, 8, PAL_MODE_OUTPUT_PUSHPULL);
133#endif
134#endif /* TRIGGER_ADC_DEBUG_LED */
135
136#ifdef TRIGGER_ADC_DUMP_BUF
137 addConsoleAction("trigger_adc_dump", printDumpBuf);
138#endif /* TRIGGER_ADC_DUMP_BUF */
139
140 return 0;
141}
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
int efiExtiEnablePin(const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
static constexpr engine_configuration_s * engineConfiguration
uint32_t ioline_t
Type of an I/O line.
Definition hal_pal_lld.h:88
const char * hwPortname(brain_pin_e brainPin)
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
@ TRIGGER_ADC_ADC
void setTriggerAdcMode(triggerAdcMode_t adcMode)
static void shaft_callback(void *arg, efitick_t stamp)
TriggerAdcDetector trigAdcState
static void printDumpBuf(void)
static ioportmask_t triggerInputPin
static void cam_callback(void *, efitick_t stamp)
static ioportid_t triggerInputPort
Here is the call graph for this function:

◆ adcTriggerTurnOnInputPins()

void adcTriggerTurnOnInputPins ( )

Definition at line 147 of file trigger_input_adc.cpp.

147 {
148}

◆ addAdcChannelForTrigger()

void addAdcChannelForTrigger ( void  )

Definition at line 158 of file trigger_input_adc.cpp.

158 {
161 addFastAdcChannel("TRIG", channel);
162 }
163}
void addFastAdcChannel(const char *, adc_channel_e hwChannel)
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
uint16_t channel
Definition adc_inputs.h:104
adc_channel_e getAdcChannelForTrigger(void)

Referenced by setAdcChannelOverrides().

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

◆ cam_callback()

static void cam_callback ( void *  ,
efitick_t  stamp 
)
static

Definition at line 88 of file trigger_input_adc.cpp.

88 {
89 // TODO: implement...
90}

Referenced by adcTriggerTurnOnInputPin().

Here is the caller graph for this function:

◆ getAdcChannelForTrigger()

adc_channel_e getAdcChannelForTrigger ( void  )

Definition at line 150 of file trigger_input_adc.cpp.

150 {
151 // todo: add other trigger or cam channels?
153 if (!isBrainPinValid(brainPin))
154 return EFI_ADC_NONE;
155 return getAdcChannel(brainPin);
156}
adc_channel_e getAdcChannel(brain_pin_e pin)
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by addAdcChannelForTrigger(), and calcFastAdcIndexes().

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

◆ getTriggerAdcMode()

triggerAdcMode_t getTriggerAdcMode ( void  )

Definition at line 439 of file trigger_input_adc.cpp.

439 {
441}
triggerAdcMode_t curAdcMode

◆ getTriggerAdcModeCnt()

int getTriggerAdcModeCnt ( void  )

Definition at line 447 of file trigger_input_adc.cpp.

447 {
449}

◆ getTriggerAdcThreshold()

float getTriggerAdcThreshold ( void  )

Definition at line 443 of file trigger_input_adc.cpp.

443 {
445}

◆ onTriggerChanged()

void onTriggerChanged ( efitick_t  stamp,
bool  isPrimary,
bool  isRising 
)

Definition at line 165 of file trigger_input_adc.cpp.

165 {
166#ifdef TRIGGER_ADC_DEBUG_LED
167 toggleLed(0, 0);
168#endif /* TRIGGER_ADC_DEBUG_LED */
169
170#if 1
171 // todo: support for 3rd trigger input channel
172 // todo: start using real event time from HW event, not just software timer?
173
174 // call the main trigger handler
175 hwHandleShaftSignal(isPrimary ? 0 : 1, isRising, stamp);
176#endif // 1
177}
void hwHandleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp)
void toggleLed(int led, int mode)

Referenced by TriggerAdcDetector::analogCallback(), and TriggerAdcDetector::digitalCallback().

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

◆ printDumpBuf()

static void printDumpBuf ( void  )
static

Definition at line 98 of file trigger_input_adc.cpp.

98 {
99 efiPrintf("------");
100 for (int i = 0; i < dumpBufNum; i++) {
101 int pos = (dumpBufCnt - i - 1 + dumpBufNum) % dumpBufNum;
103 efiPrintf("[%d] %d", i, v);
104 }
105}
adcsample_t triggerAdcSample_t
static const int dumpBufNum
static triggerAdcSample_t dumpBuf[dumpBufNum]
static int dumpBufCnt

Referenced by adcTriggerTurnOnInputPin().

Here is the caller graph for this function:

◆ setTriggerAdcMode()

void setTriggerAdcMode ( triggerAdcMode_t  adcMode)

Definition at line 72 of file trigger_input_adc.cpp.

72 {
73 trigAdcState.curAdcMode = adcMode;
75
76 palSetPadMode(triggerInputPort, triggerInputPin,
77 (adcMode == TRIGGER_ADC_ADC) ? PAL_MODE_INPUT_ANALOG : PAL_MODE_EXTINT);
78}

Referenced by adcTriggerTurnOnInputPin(), TriggerAdcDetector::analogCallback(), and TriggerAdcDetector::digitalCallback().

Here is the caller graph for this function:

◆ shaft_callback()

static void shaft_callback ( void *  arg,
efitick_t  stamp 
)
static

Definition at line 80 of file trigger_input_adc.cpp.

80 {
81 // do the time sensitive things as early as possible!
82 ioline_t pal_line = (ioline_t)arg;
83 bool rise = (palReadLine(pal_line) == PAL_HIGH);
84
85 trigAdcState.digitalCallback(stamp, true, rise);
86}
void digitalCallback(efitick_t stamp, bool isPrimary, bool rise)

Referenced by adcTriggerTurnOnInputPin().

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

◆ toggleLed()

void toggleLed ( int  led,
int  mode 
)

!!!!!!!!!!

Definition at line 44 of file trigger_input_adc.cpp.

44 {
45#if 1
46 static uint8_t st[5] = { 0 };
47 if ((st[led] == 0 && mode == 0) || mode == 1) {
48 palClearPad(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN);
49#ifdef DEBUG_OUTPUT_IGN1
50 palClearPad(GPIOI, 8);
51#endif
52 }
53 else if ((st[led] != 0 && mode == 0) || mode == -1) {
54 palSetPad(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN);
55#ifdef DEBUG_OUTPUT_IGN1
56 palSetPad(GPIOI, 8);
57#endif
58 }
59 st[led] = (st[led] + 1) % 2/*10*/; //!!!!!!!!!!!
60#endif
61}

Referenced by onTriggerChanged().

Here is the caller graph for this function:

◆ triggerAdcCallback()

void triggerAdcCallback ( triggerAdcSample_t  value)

Definition at line 92 of file trigger_input_adc.cpp.

92 {
93 efitick_t stamp = getTimeNowNt();
94 trigAdcState.analogCallback(stamp, value);
95}
void analogCallback(efitick_t stamp, triggerAdcSample_t value)
efitick_t getTimeNowNt()
Definition efitime.cpp:19

Referenced by onFastAdcComplete().

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

Variable Documentation

◆ dumpBuf

triggerAdcSample_t dumpBuf[dumpBufNum]
static

Definition at line 40 of file trigger_input_adc.cpp.

Referenced by TriggerAdcDetector::analogCallback(), and printDumpBuf().

◆ dumpBufCnt

int dumpBufCnt = 0
static

Definition at line 41 of file trigger_input_adc.cpp.

Referenced by TriggerAdcDetector::analogCallback(), and printDumpBuf().

◆ dumpBufNum

const int dumpBufNum = 100
static

Definition at line 39 of file trigger_input_adc.cpp.

Referenced by TriggerAdcDetector::analogCallback(), and printDumpBuf().

◆ trigAdcState

TriggerAdcDetector trigAdcState

◆ triggerInputPin

ioportmask_t triggerInputPin
static

Definition at line 66 of file trigger_input_adc.cpp.

Referenced by adcTriggerTurnOnInputPin(), and setTriggerAdcMode().

◆ triggerInputPort

ioportid_t triggerInputPort
static

Definition at line 65 of file trigger_input_adc.cpp.

Referenced by adcTriggerTurnOnInputPin(), and setTriggerAdcMode().

Go to the source code of this file.