2019-11-11 18:25:40 -08:00
|
|
|
/**
|
|
|
|
* @file trigger_input_exti.cpp
|
|
|
|
* @brief Position sensor hardware layer - PAL version
|
|
|
|
*
|
|
|
|
* todo: VVT implementation is a nasty copy-paste :(
|
|
|
|
*
|
2019-11-11 20:32:09 -08:00
|
|
|
* see digital_input_icu.cp
|
2019-11-11 18:25:40 -08:00
|
|
|
*
|
|
|
|
* @date Dec 30, 2012
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2019-11-11 18:25:40 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT && (HAL_TRIGGER_USE_PAL == TRUE)
|
2019-11-11 18:25:40 -08:00
|
|
|
|
2019-11-11 19:19:35 -08:00
|
|
|
#include "trigger_input.h"
|
|
|
|
#include "digital_input_exti.h"
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
#if (PAL_USE_CALLBACKS == FALSE)
|
|
|
|
#error "PAL_USE_CALLBACKS should be enabled to use HAL_TRIGGER_USE_PAL"
|
|
|
|
#endif
|
|
|
|
|
2019-11-11 19:19:35 -08:00
|
|
|
static Logging *logger;
|
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
static ioline_t primary_line;
|
|
|
|
|
|
|
|
static void shaft_callback(void *arg) {
|
2020-01-09 10:19:11 -08:00
|
|
|
// do the time sensitive things as early as possible!
|
|
|
|
efitick_t stamp = getTimeNowNt();
|
2019-11-11 19:19:35 -08:00
|
|
|
ioline_t pal_line = (ioline_t)arg;
|
2020-01-09 10:19:11 -08:00
|
|
|
bool rise = (palReadLine(pal_line) == PAL_HIGH);
|
|
|
|
|
2019-11-11 19:19:35 -08:00
|
|
|
// todo: support for 3rd trigger input channel
|
|
|
|
// todo: start using real event time from HW event, not just software timer?
|
|
|
|
if (hasFirmwareErrorFlag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool isPrimary = pal_line == primary_line;
|
2019-12-07 22:09:39 -08:00
|
|
|
if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) {
|
2019-11-11 19:19:35 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trigger_event_e signal;
|
|
|
|
// todo: add support for 3rd channel
|
|
|
|
if (rise) {
|
|
|
|
signal = isPrimary ?
|
|
|
|
(engineConfiguration->invertPrimaryTriggerSignal ? SHAFT_PRIMARY_FALLING : SHAFT_PRIMARY_RISING) :
|
|
|
|
(engineConfiguration->invertSecondaryTriggerSignal ? SHAFT_SECONDARY_FALLING : SHAFT_SECONDARY_RISING);
|
|
|
|
} else {
|
|
|
|
signal = isPrimary ?
|
|
|
|
(engineConfiguration->invertPrimaryTriggerSignal ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING) :
|
|
|
|
(engineConfiguration->invertSecondaryTriggerSignal ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING);
|
|
|
|
}
|
|
|
|
|
2020-01-09 10:19:11 -08:00
|
|
|
hwHandleShaftSignal(signal, stamp);
|
2019-11-11 19:19:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cam_callback(void *arg) {
|
2020-01-09 10:19:11 -08:00
|
|
|
efitick_t stamp = getTimeNowNt();
|
|
|
|
|
2019-11-11 19:19:35 -08:00
|
|
|
ioline_t pal_line = (ioline_t)arg;
|
|
|
|
|
|
|
|
bool rise = (palReadLine(pal_line) == PAL_HIGH);
|
|
|
|
|
|
|
|
if (rise) {
|
2020-01-09 10:19:11 -08:00
|
|
|
hwHandleVvtCamSignal(TV_RISE, stamp);
|
2019-11-11 19:19:35 -08:00
|
|
|
} else {
|
2020-01-09 10:19:11 -08:00
|
|
|
hwHandleVvtCamSignal(TV_FALL, stamp);
|
2019-11-11 19:19:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
/*==========================================================================*/
|
|
|
|
/* Exported functions. */
|
|
|
|
/*==========================================================================*/
|
|
|
|
|
|
|
|
int extiTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
2019-12-11 14:48:55 -08:00
|
|
|
brain_pin_e brainPin = isTriggerShaft ? CONFIG(triggerInputPins)[index] : engineConfiguration->camInputs[index];
|
2019-11-13 19:50:37 -08:00
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
scheduleMsg(logger, "extiTriggerTurnOnInputPin %s %s", msg, hwPortname(brainPin));
|
2019-11-11 19:19:35 -08:00
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* * do not set to both edges if we need only one
|
|
|
|
* * simplify callback in case of one edge */
|
2020-05-16 16:28:49 -07:00
|
|
|
ioline_t pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin));
|
|
|
|
efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, isTriggerShaft ? shaft_callback : cam_callback, (void *)pal_line);
|
2020-01-07 00:42:08 -08:00
|
|
|
|
|
|
|
return 0;
|
2019-11-11 19:19:35 -08:00
|
|
|
}
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
void extiTriggerTurnOffInputPin(brain_pin_e brainPin) {
|
2019-12-05 18:10:29 -08:00
|
|
|
efiExtiDisablePin(brainPin);
|
2019-11-11 19:19:35 -08:00
|
|
|
}
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
void extiTriggerSetPrimaryChannel(brain_pin_e brainPin) {
|
2019-11-11 19:19:35 -08:00
|
|
|
primary_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin));
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
void extiTriggerTurnOnInputPins(Logging *sharedLogger) {
|
2019-11-11 19:19:35 -08:00
|
|
|
logger = sharedLogger;
|
|
|
|
}
|
|
|
|
|
2020-01-07 00:42:08 -08:00
|
|
|
#endif /* (EFI_SHAFT_POSITION_INPUT && (HAL_TRIGGER_USE_PAL == TRUE)) */
|