rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
trigger_input_exti.cpp
Go to the documentation of this file.
1/**
2 * @file trigger_input_exti.cpp
3 * @brief Position sensor hardware layer - PAL version
4 *
5 * todo: VVT implementation is a nasty copy-paste :(
6 *
7 * see digital_input_icu.cp
8 *
9 * @date Dec 30, 2012
10 * @author Andrey Belomutskiy, (c) 2012-2021
11 */
12
13#include "pch.h"
14
15#if EFI_SHAFT_POSITION_INPUT && (HAL_TRIGGER_USE_PAL == TRUE)
16
17#include "trigger_input.h"
18#include "digital_input_exti.h"
19
20#if (PAL_USE_CALLBACKS == FALSE)
21 #error "PAL_USE_CALLBACKS should be enabled to use HAL_TRIGGER_USE_PAL"
22#endif
23
24static ioline_t shaftLines[TRIGGER_INPUT_PIN_COUNT];
25static ioline_t camLines[CAM_INPUTS_COUNT];
26
27static void shaft_callback(void *arg, efitick_t stamp) {
28 // do the time sensitive things as early as possible!
29 int index = (int)arg;
30 ioline_t pal_line = shaftLines[index];
31 bool rise = (palReadLine(pal_line) == PAL_HIGH);
32
33 // todo: support for 3rd trigger input channel
34 // todo: start using real event time from HW event, not just software timer?
35
36 hwHandleShaftSignal(index, rise, stamp);
37}
38
39static void cam_callback(void *arg, efitick_t stamp) {
40 int index = (int)arg;
41 ioline_t pal_line = camLines[index];
42
43 bool rise = (palReadLine(pal_line) == PAL_HIGH);
44
45 hwHandleVvtCamSignal(rise, stamp, index);
46}
47
48/*==========================================================================*/
49/* Exported functions. */
50/*==========================================================================*/
51
52int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
53 brain_pin_e brainPin = isTriggerShaft ? engineConfiguration->triggerInputPins[index] : engineConfiguration->camInputs[index];
54
55 efiPrintf("extiTriggerTurnOnInputPin %s %s", msg, hwPortname(brainPin));
56
57 /* TODO:
58 * * do not set to both edges if we need only one
59 * * simplify callback in case of one edge */
60 if (efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES,
61 isTriggerShaft ? shaft_callback : cam_callback, (void *)index) < 0) {
62 return -1;
63 }
64
65 ioline_t pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin));
66 if (isTriggerShaft) {
67 shaftLines[index] = pal_line;
68 } else {
69 camLines[index] = pal_line;
70 }
71
72 return 0;
73}
74
76 efiExtiDisablePin(brainPin);
77}
78
79#endif /* (EFI_SHAFT_POSITION_INPUT && (HAL_TRIGGER_USE_PAL == TRUE)) */
void efiExtiDisablePin(brain_pin_e brainPin)
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]
void hwHandleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp)
void hwHandleVvtCamSignal(bool isRising, efitick_t nowNt, int index)
Position sensor hardware layer.
static void shaft_callback(void *arg, efitick_t stamp)
static void cam_callback(void *arg, efitick_t stamp)
void extiTriggerTurnOffInputPin(brain_pin_e brainPin)
static ioline_t shaftLines[TRIGGER_INPUT_PIN_COUNT]
static ioline_t camLines[CAM_INPUTS_COUNT]
int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft)