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

Functions

void efiExtiInit ()
 
int efiExtiEnablePin (const char *msg, brain_pin_e brainPin, uint32_t mode, ExtiCallback cb, void *cb_data)
 
void efiExtiDisablePin (brain_pin_e brainPin)
 
static void triggerInterrupt ()
 
 CH_IRQ_HANDLER (STM32_I2C1_EVENT_HANDLER)
 
uint8_t getExtiOverflowCounter ()
 
void handleExtiIsr (uint8_t index)
 
 CH_FAST_IRQ_HANDLER (Vector58)
 
 CH_FAST_IRQ_HANDLER (Vector5C)
 
 CH_FAST_IRQ_HANDLER (Vector60)
 
 CH_FAST_IRQ_HANDLER (Vector64)
 
 CH_FAST_IRQ_HANDLER (Vector68)
 
 CH_FAST_IRQ_HANDLER (Vector9C)
 
 CH_FAST_IRQ_HANDLER (VectorE0)
 

Variables

static ExtiChannel channels [16]
 
static ExtiQueue< ExtiQueueEntry, 32 > queue
 
static uint8_t overflowCounter = 0
 

Function Documentation

◆ CH_FAST_IRQ_HANDLER() [1/7]

CH_FAST_IRQ_HANDLER ( Vector58  )

Definition at line 215 of file digital_input_exti.cpp.

215 {
216 handleExtiIsr(0);
217}
void handleExtiIsr(uint8_t index)
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [2/7]

CH_FAST_IRQ_HANDLER ( Vector5C  )

Definition at line 219 of file digital_input_exti.cpp.

219 {
220 handleExtiIsr(1);
221}
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [3/7]

CH_FAST_IRQ_HANDLER ( Vector60  )

Definition at line 223 of file digital_input_exti.cpp.

223 {
224 handleExtiIsr(2);
225}
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [4/7]

CH_FAST_IRQ_HANDLER ( Vector64  )

Definition at line 227 of file digital_input_exti.cpp.

227 {
228 handleExtiIsr(3);
229}
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [5/7]

CH_FAST_IRQ_HANDLER ( Vector68  )

Definition at line 231 of file digital_input_exti.cpp.

231 {
232 handleExtiIsr(4);
233}
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [6/7]

CH_FAST_IRQ_HANDLER ( Vector9C  )

Definition at line 235 of file digital_input_exti.cpp.

235 {
236 handleExtiIsr(5);
237 handleExtiIsr(6);
238 handleExtiIsr(7);
239 handleExtiIsr(8);
240 handleExtiIsr(9);
241}
Here is the call graph for this function:

◆ CH_FAST_IRQ_HANDLER() [7/7]

CH_FAST_IRQ_HANDLER ( VectorE0  )

Definition at line 243 of file digital_input_exti.cpp.

243 {
244 handleExtiIsr(10);
245 handleExtiIsr(11);
246 handleExtiIsr(12);
247 handleExtiIsr(13);
248 handleExtiIsr(14);
249 handleExtiIsr(15);
250}
Here is the call graph for this function:

◆ CH_IRQ_HANDLER()

CH_IRQ_HANDLER ( STM32_I2C1_EVENT_HANDLER  )

Definition at line 164 of file digital_input_exti.cpp.

164 {
165 OSAL_IRQ_PROLOGUE();
166
167 while (true) {
168 // get the timestamp out under lock
169 // todo: lock freeeeee!
170 __disable_irq();
171 auto result = queue.pop();
172 __enable_irq();
173
174 // Queue empty, we're done here.
175 if (!result) {
176 break;
177 }
178
179 auto& entry = result.Value;
180 auto& timestamp = entry.Timestamp;
181
182 if (timestamp != 0) {
183 auto& channel = channels[entry.Channel];
184
185 if (channel.Callback) {
186 channel.Callback(channel.CallbackData, timestamp);
187 }
188 } else {
190 }
191 }
192
193 assertInterruptPriority(__func__, EFI_IRQ_EXTI_HANDOFF_PRIORITY);
194
195 OSAL_IRQ_EPILOGUE();
196}
uint16_t channel
Definition adc_inputs.h:104
static uint8_t overflowCounter
static ExtiChannel channels[16]
static ExtiQueue< ExtiQueueEntry, 32 > queue
void assertInterruptPriority(const char *func, uint8_t expectedPrio)
Here is the call graph for this function:

◆ efiExtiDisablePin()

void efiExtiDisablePin ( brain_pin_e  brainPin)

Definition at line 78 of file digital_input_exti.cpp.

79{
80 /* paranoid check, in case of Gpio::Unassigned getHwPort will return NULL
81 * and we will fail on next check */
82 if (!isBrainPinValid(brainPin))
83 return;
84
85 ioportid_t port = getHwPort("exti", brainPin);
86 if (port == NULL)
87 return;
88 brain_pin_markUnused(brainPin);
89
90 int index = getHwPin("exti", brainPin);
91
92 auto& channel = channels[index];
93
94 /* is this index was used? */
95 if (!channel.Callback) {
96 return;
97 }
98
99 ioline_t line = PAL_LINE(port, index);
100 palDisableLineEvent(line);
101
102 /* mark unused */
103 channel.Name = nullptr;
104 channel.Callback = nullptr;
105 channel.CallbackData = nullptr;
106}
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
GPIO_TypeDef * ioportid_t
Port Identifier.
uint32_t ioline_t
Type of an I/O line.
Definition hal_pal_lld.h:88
void brain_pin_markUnused(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by adcTriggerTurnOffInputPin(), FrequencySensor::deInit(), HellaOilLevelSensor::deInit(), deInitFlexSensor(), detectHellenBoardId(), extiTriggerTurnOffInputPin(), HellenBoardIdFinder< NumPins >::measureChargingTimes(), nm_bsp_interrupt_ctrl(), and stopLogicAnalyzerPins().

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

◆ efiExtiEnablePin()

int efiExtiEnablePin ( const char msg,
brain_pin_e  brainPin,
uint32_t  mode,
ExtiCallback  cb,
void *  cb_data 
)

Definition at line 38 of file digital_input_exti.cpp.

38 {
39 /* paranoid check, in case of Gpio::Unassigned getHwPort will return NULL
40 * and we will fail on next check */
41 if (!isBrainPinValid(brainPin)) {
42 return -1;
43 }
44
45 criticalAssert(msg, "efiExtiEnablePin msg must not be null", -1);
46
47 ioportid_t port = getHwPort(msg, brainPin);
48 if (port == NULL) {
49 return -1;
50 }
51
52 efiSetPadMode(msg, brainPin, PAL_MODE_INPUT);
53
54 int index = getHwPin(msg, brainPin);
55
56 auto& channel = channels[index];
57
58 /* is this index already used? */
59 if (channel.Callback) {
60 firmwareError(ObdCode::CUSTOM_ERR_PIN_ALREADY_USED_2, "%s: pin %s/index %d: exti index already used by %s (stm32 limitation, cannot use those two pins as event inputs simultaneously)",
61 msg,
62 hwPortname(brainPin),
63 index,
64 channel.Name);
65 return -1;
66 }
67
68 channel.Callback = cb;
69 channel.CallbackData = cb_data;
70 channel.Name = msg;
71
72 ioline_t line = PAL_LINE(port, index);
73 palEnableLineEvent(line, mode);
74
75 return 0;
76}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_PIN_ALREADY_USED_2
const char * hwPortname(brain_pin_e brainPin)

Referenced by adcTriggerTurnOnInputPin(), cdmIonInit(), extiTriggerTurnOnInputPin(), HellaOilLevelSensor::init(), initFlexSensor(), FrequencySensor::initIfValid(), initWave(), HellenBoardIdFinder< NumPins >::measureChargingTimes(), and nm_bsp_interrupt_ctrl().

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

◆ efiExtiInit()

void efiExtiInit ( )

EXTI is a funny thing: you can only use same pin on one port. For example, you can use PA0 PB5 PE2 PD7 but you cannot use PA0 PB0 PE2 PD7 because pin '0' would be used on two different ports

Definition at line 22 of file digital_input_exti.cpp.

22 {
23 nvicEnableVector(I2C1_EV_IRQn, EFI_IRQ_EXTI_HANDOFF_PRIORITY);
24}

Referenced by initHardwareNoConfig().

Here is the caller graph for this function:

◆ getExtiOverflowCounter()

uint8_t getExtiOverflowCounter ( )

Definition at line 198 of file digital_input_exti.cpp.

198 {
199 return overflowCounter;
200}

Referenced by updateTunerStudioState().

Here is the caller graph for this function:

◆ handleExtiIsr()

void handleExtiIsr ( uint8_t  index)

Definition at line 202 of file digital_input_exti.cpp.

202 {
203 // No need to lock anything, we're already the highest-pri interrupt!
204
205 uint32_t pr;
206 extiGetAndClearGroup1(1U << index, pr);
207
208 if (pr & (1 << index)) {
209 queue.push({getTimeNowNt(), index});
210
212 }
213}
static void triggerInterrupt()
efitick_t getTimeNowNt()
Definition efitime.cpp:19

Referenced by CH_FAST_IRQ_HANDLER(), CH_FAST_IRQ_HANDLER(), CH_FAST_IRQ_HANDLER(), CH_FAST_IRQ_HANDLER(), CH_FAST_IRQ_HANDLER(), CH_FAST_IRQ_HANDLER(), and CH_FAST_IRQ_HANDLER().

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

◆ triggerInterrupt()

static void triggerInterrupt ( )
inlinestatic

Definition at line 108 of file digital_input_exti.cpp.

108 {
109 // Manually fire the I2C1_EV interrupt, it will be queued after this interrupt returns
110 NVIC->STIR = I2C1_EV_IRQn;
111}

Referenced by handleExtiIsr().

Here is the caller graph for this function:

Variable Documentation

◆ channels

ExtiChannel channels[16]
static

Definition at line 35 of file digital_input_exti.cpp.

Referenced by CH_IRQ_HANDLER(), efiExtiDisablePin(), and efiExtiEnablePin().

◆ overflowCounter

uint8_t overflowCounter = 0
static

Definition at line 162 of file digital_input_exti.cpp.

Referenced by CH_IRQ_HANDLER(), and getExtiOverflowCounter().

◆ queue

ExtiQueue<ExtiQueueEntry, 32> queue
static

Definition at line 160 of file digital_input_exti.cpp.

Referenced by CH_IRQ_HANDLER(), and handleExtiIsr().

Go to the source code of this file.