parent
0cc1f729c4
commit
e9d092f975
|
@ -28,6 +28,9 @@ Release template (copy/paste this for new release):
|
|||
### Fixed
|
||||
- Lua CAN reception fixed for 11-bit IDs where the frame would be received, but a corrupt ID was passed to the handler function. #4321
|
||||
|
||||
### Removed
|
||||
- ICU trigger input logic since it is unused in any current ECU #639
|
||||
|
||||
## July 2022 Release - "Day 130"
|
||||
|
||||
### Added
|
||||
|
|
|
@ -12,7 +12,7 @@ DDEFS += -DEFI_MAIN_RELAY_CONTROL=TRUE
|
|||
DDEFS += -DFIRMWARE_ID=\"hellen81hd\"
|
||||
DDEFS += -DEFI_SOFTWARE_KNOCK=TRUE -DSTM32_ADC_USE_ADC3=TRUE
|
||||
|
||||
DDEFS += -DSTM32_PWM_USE_TIM3=TRUE -DHAL_USE_ICU=FALSE
|
||||
DDEFS += -DSTM32_PWM_USE_TIM3=TRUE
|
||||
|
||||
include $(BOARDS_DIR)/hellen/hellen-common144.mk
|
||||
|
||||
|
|
|
@ -44,10 +44,6 @@
|
|||
#define EFI_LOGIC_ANALYZER FALSE
|
||||
#endif
|
||||
|
||||
#ifndef EFI_ICU_INPUTS
|
||||
#define EFI_ICU_INPUTS FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TunerStudio support.
|
||||
*/
|
||||
|
|
|
@ -90,8 +90,6 @@
|
|||
#define EFI_ENABLE_ASSERTS TRUE
|
||||
#endif /* EFI_ENABLE_ASSERTS */
|
||||
|
||||
#define EFI_ICU_INPUTS FALSE
|
||||
|
||||
#ifndef HAL_TRIGGER_USE_PAL
|
||||
#define HAL_TRIGGER_USE_PAL TRUE
|
||||
#endif /* HAL_TRIGGER_USE_PAL */
|
||||
|
|
|
@ -71,9 +71,6 @@
|
|||
/* To remove futher possible conflict */
|
||||
#undef STM32_SPI_SPI6_RX_DMA_STREAM
|
||||
|
||||
#undef STM32_ICU_USE_TIM3
|
||||
#define STM32_ICU_USE_TIM3 TRUE
|
||||
|
||||
#undef STM32_CAN_USE_CAN2
|
||||
#define STM32_CAN_USE_CAN2 FALSE
|
||||
|
||||
|
|
|
@ -69,10 +69,6 @@
|
|||
#define EFI_LOGIC_ANALYZER TRUE
|
||||
#endif
|
||||
|
||||
#ifndef EFI_ICU_INPUTS
|
||||
#define EFI_ICU_INPUTS FALSE
|
||||
#endif
|
||||
|
||||
#ifndef HAL_TRIGGER_USE_PAL
|
||||
#define HAL_TRIGGER_USE_PAL TRUE
|
||||
#endif /* HAL_TRIGGER_USE_PAL */
|
||||
|
|
|
@ -38,8 +38,5 @@
|
|||
// H7 runs faster "slow" ADC to make up for reduced oversampling
|
||||
#define SLOW_ADC_RATE 1000
|
||||
|
||||
#undef EFI_ICU_INPUTS
|
||||
#define EFI_ICU_INPUTS FALSE
|
||||
|
||||
#undef LUA_USER_HEAP
|
||||
#define LUA_USER_HEAP 100000
|
||||
|
|
|
@ -67,8 +67,6 @@ extern bool main_loop_started;
|
|||
#include "max31855.h"
|
||||
#include "single_timer_executor.h"
|
||||
#include "periodic_task.h"
|
||||
extern int icuRisingCallbackCounter;
|
||||
extern int icuFallingCallbackCounter;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
#if EFI_CJ125
|
||||
|
@ -853,9 +851,6 @@ void updateTunerStudioState() {
|
|||
break;
|
||||
}
|
||||
case DBG_TRIGGER_COUNTERS:
|
||||
#if EFI_PROD_CODE && HAL_USE_ICU == TRUE
|
||||
tsOutputChannels->debugFloatField3 = icuRisingCallbackCounter + icuFallingCallbackCounter;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
#if EFI_SHAFT_POSITION_INPUT
|
||||
tsOutputChannels->debugIntField4 = engine->triggerCentral.triggerState.currentCycle.eventCount[0];
|
||||
|
|
|
@ -1822,7 +1822,7 @@ typedef enum {
|
|||
CUSTOM_ERR_UNKNOWN_PORT = 6132,
|
||||
CUSTOM_ERR_PIN_ALREADY_USED_1 = 6133,
|
||||
CUSTOM_ERR_PIN_ALREADY_USED_2 = 6134,
|
||||
CUSTOM_ERR_ICU_STATE = 6135,
|
||||
CUSTOM_ERR_6135 = 6135,
|
||||
CUSTOM_ERR_TCHARGE_NOT_READY = 6136,
|
||||
CUSTOM_ERR_TRIGGER_WAVEFORM_TOO_LONG = 6137,
|
||||
CUSTOM_ERR_FUEL_TABLE_NOT_READY = 6138,
|
||||
|
@ -1858,10 +1858,10 @@ typedef enum {
|
|||
CUSTOM_ERR_ADC_USED = 6517,
|
||||
CUSTOM_ERR_ADC_DEPTH_SLOW = 6518,
|
||||
CUSTOM_ERR_ADC_DEPTH_FAST = 6519,
|
||||
CUSTOM_ERR_ICU = 6520,
|
||||
CUSTOM_ERR_ICU_AF = 6521,
|
||||
CUSTOM_ERR_ICU_DRIVER = 6522,
|
||||
CUSTOM_ERR_ICU_PIN = 6523,
|
||||
CUSTOM_ERR_6520 = 6520,
|
||||
CUSTOM_ERR_6521 = 6521,
|
||||
CUSTOM_ERR_6522 = 6522,
|
||||
CUSTOM_ERR_6523 = 6523,
|
||||
CUSTOM_ERR_UNEXPECTED_SPI = 6524,
|
||||
CUSTOM_ERR_EXT_MODE = 6525,
|
||||
CUSTOM_ERR_TIMER_OVERFLOW = 6526,
|
||||
|
@ -2024,14 +2024,14 @@ typedef enum {
|
|||
|
||||
CUSTOM_ERR_6670 = 6670,
|
||||
CUSTOM_STACK_ADC_6671 = 6671,
|
||||
CUSTOM_ICU_DRIVER = 6672,
|
||||
CUSTOM_ICU_DRIVER_STATE = 6673,
|
||||
CUSTOM_ERR_6672 = 6672,
|
||||
CUSTOM_ERR_6673 = 6673,
|
||||
CUSTOM_STACK_SPI = 6674,
|
||||
CUSTOM_VVT_SYNC_POSITION = 6675,
|
||||
CUSTOM_STACK_ADC = 6676,
|
||||
CUSTOM_IH_STACK = 6677,
|
||||
CUSTOM_EC_NULL = 6678,
|
||||
CUSTOM_ERROR_ICU = 6679,
|
||||
CUSTOM_ERR6679 = 6679,
|
||||
|
||||
CUSTOM_ERR_ANGLE_CR = 6680,
|
||||
CUSTOM_DELTA_NOT_POSITIVE = 6681,
|
||||
|
@ -2054,7 +2054,7 @@ typedef enum {
|
|||
CUSTOM_PWM_CYCLE_START = 6697,
|
||||
CUSTOM_ERR_ARRAY_IS_FULL = 6698,
|
||||
CUSTOM_ERR_ARRAY_REMOVE_ERROR = 6699,
|
||||
CUSTOM_ERR_INVALID_INPUT_ICU_PIN = 6700,
|
||||
CUSTOM_ERR_6700 = 6700,
|
||||
|
||||
CUSTOM_CJ125_0 = 6700,
|
||||
CUSTOM_CJ125_1 = 6701,
|
||||
|
|
|
@ -567,24 +567,6 @@ void OutputPin::initPin(const char *msg, brain_pin_e brainPin, const pin_output_
|
|||
|
||||
#if EFI_GPIO_HARDWARE && EFI_PROD_CODE
|
||||
efiSetPadMode(msg, brainPin, mode);
|
||||
if (brain_pin_is_onchip(brainPin)) {
|
||||
int actualValue = palReadPad(port, pin);
|
||||
// we had enough drama with pin configuration in board.h and else that we shall self-check
|
||||
|
||||
// todo: handle OM_OPENDRAIN and OM_OPENDRAIN_INVERTED as well
|
||||
if (*outputMode == OM_DEFAULT || *outputMode == OM_INVERTED) {
|
||||
const int logicalValue =
|
||||
(*outputMode == OM_INVERTED)
|
||||
? !actualValue
|
||||
: actualValue;
|
||||
|
||||
// if the pin was set to logical 1, then set an error and disable the pin so that things don't catch fire
|
||||
if (logicalValue) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "HARDWARE VALIDATION FAILED %s: unexpected startup pin state %s actual value=%d logical value=%d mode=%s", msg, hwPortname(brainPin), actualValue, logicalValue, getPin_output_mode_e(*outputMode));
|
||||
OutputPin::deInit();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
||||
}
|
||||
|
||||
|
@ -625,7 +607,7 @@ uint8_t criticalErrorLedState;
|
|||
|
||||
void initPrimaryPins() {
|
||||
#if EFI_PROD_CODE
|
||||
enginePins.errorLedPin.initPin("led: CRITICAL status", LED_CRITICAL_ERROR_BRAIN_PIN, &(LED_ERROR_BRAIN_PIN_MODE));
|
||||
// enginePins.errorLedPin.initPin("led: CRITICAL status", LED_CRITICAL_ERROR_BRAIN_PIN, &(LED_ERROR_BRAIN_PIN_MODE));
|
||||
criticalErrorLedPort = getHwPort("CRITICAL", LED_CRITICAL_ERROR_BRAIN_PIN);
|
||||
criticalErrorLedPin = getHwPin("CRITICAL", LED_CRITICAL_ERROR_BRAIN_PIN);
|
||||
criticalErrorLedState = (LED_ERROR_BRAIN_PIN_MODE == INVERTED_OUTPUT) ? 0 : 1;
|
||||
|
|
|
@ -757,11 +757,6 @@ static void triggerShapeInfo() {
|
|||
extern PwmConfig triggerSignal;
|
||||
#endif /* #if EFI_PROD_CODE */
|
||||
|
||||
#if HAL_USE_ICU == TRUE
|
||||
extern int icuRisingCallbackCounter;
|
||||
extern int icuFallingCallbackCounter;
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
void triggerInfo(void) {
|
||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
|
||||
|
@ -772,10 +767,6 @@ void triggerInfo(void) {
|
|||
efiPrintf("trigger PAL mode %d", engine->hwTriggerInputEnabled);
|
||||
#else
|
||||
|
||||
#if HAL_USE_ICU == TRUE
|
||||
efiPrintf("trigger ICU hw: %d %d %d", icuRisingCallbackCounter, icuFallingCallbackCounter, engine->hwTriggerInputEnabled);
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
#endif /* HAL_TRIGGER_USE_PAL */
|
||||
|
||||
efiPrintf("Template %s (%d) trigger %s (%d) useRiseEdge=%s onlyFront=%s tdcOffset=%.2f",
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* @file digital_input.cpp
|
||||
*
|
||||
* @date Nov 11, 2019
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "digital_input.h"
|
||||
|
||||
void digital_input_s::setWidthCallback(VoidInt handler, void *arg) {
|
||||
widthListeners.registerCallback(handler, arg);
|
||||
}
|
||||
|
||||
void digital_input_s::setPeriodCallback(VoidInt handler, void *arg) {
|
||||
periodListeners.registerCallback(handler, arg);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* @file digital_input.h
|
||||
* Universal input capture API hiding platform/hardware implementation details
|
||||
*
|
||||
* @date Nov 11, 2019
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "listener_array.h"
|
||||
|
||||
struct digital_input_s {
|
||||
#if HAL_USE_ICU
|
||||
ICUDriver *driver;
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
volatile bool started = false;
|
||||
brain_pin_e brainPin = Gpio::Unassigned;
|
||||
IntListenerArray<1> widthListeners;
|
||||
IntListenerArray<1> periodListeners;
|
||||
|
||||
// Width/Period names are historically inherited from ICU implementation, todo: migrate to better names, high/low? rise/hall?
|
||||
void setWidthCallback(VoidInt handler, void *arg);
|
||||
void setPeriodCallback(VoidInt handler, void *arg);
|
||||
};
|
|
@ -107,16 +107,6 @@ void efiExtiDisablePin(brain_pin_e brainPin)
|
|||
channel.CallbackData = nullptr;
|
||||
}
|
||||
|
||||
digital_input_s* startDigitalCaptureExti(const char * /*msg*/, brain_pin_e /*brainPin*/) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if ! EFI_ICU_INPUTS
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
||||
return startDigitalCaptureExti(msg, brainPin);
|
||||
}
|
||||
#endif // EFI_ICU_INPUTS
|
||||
|
||||
static inline void triggerInterrupt() {
|
||||
// Manually fire the I2C1_EV interrupt, it will be queued after this interrupt returns
|
||||
NVIC->STIR = I2C1_EV_IRQn;
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "digital_input.h"
|
||||
|
||||
#if HAL_USE_PAL
|
||||
|
||||
using ExtiCallback = void(*)(void*, efitick_t);
|
||||
|
|
|
@ -1,288 +0,0 @@
|
|||
/*
|
||||
* @file digital_input_icu.cpp
|
||||
* @brief Helper methods related to Input Capture Unit (ICU)
|
||||
*
|
||||
* There are some ChibiOS limitation or STM32 limitations or limitations of my brain
|
||||
*
|
||||
* See http://www.chibios.com/forum/viewtopic.php?t=1461
|
||||
* "PWM input requires a whole timer on the STM32.
|
||||
* You could use channel 1 and channel 2 of the same timer but not simultaneously.
|
||||
* Giovanni"
|
||||
*
|
||||
* See http://www.chibios.com/forum/viewtopic.php?f=2&t=247&hilit=icu+channel&start=50
|
||||
* "It is not possible, the TIM timers support one ICU channel at time.
|
||||
* Giovanni"
|
||||
*
|
||||
* See https://stackoverflow.com/questions/43440599/stm32-multi-channel-input-capture-overcapturing-on-all-channels-interrupts-not
|
||||
* where they seem to be capturing something on multiple channels maybe not PWM mode of ICU is the key difference?
|
||||
*
|
||||
* rus084 is reminding that EXTI could be enough for our needs
|
||||
* See joystick.cpp
|
||||
* See trigger_input.cpp
|
||||
*
|
||||
* @date Jun 23, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include "digital_input_icu.h"
|
||||
|
||||
#if EFI_ICU_INPUTS && HAL_USE_ICU
|
||||
|
||||
#include "mpu_util.h"
|
||||
#include "eficonsole.h"
|
||||
|
||||
static void icuWidthCallback(ICUDriver *driver);
|
||||
static void icuPeriordCallBack(ICUDriver *driver);
|
||||
|
||||
/*
|
||||
* 30ms seems like width maximum, at 16bit precision that means
|
||||
* CORE_CLOCK / 33.33333 = TICKS * 65536
|
||||
* 168000000 / 33.333333 / 65536 = 76.90
|
||||
*/
|
||||
static ICUConfig wave_icucfg = {
|
||||
.mode = ICU_INPUT_ACTIVE_LOW,
|
||||
.frequency = CORE_CLOCK / 100,
|
||||
.width_cb = icuWidthCallback,
|
||||
.period_cb = icuPeriordCallBack,
|
||||
.overflow_cb = NULL,
|
||||
.channel = ICU_CHANNEL_1,
|
||||
.dier = 0,
|
||||
.arr = 0xFFFFFFFFU
|
||||
};
|
||||
|
||||
static ArrayList<digital_input_s, 8> registeredIcus;
|
||||
|
||||
//Nullable
|
||||
static digital_input_s * finddigital_input_s(ICUDriver *driver) {
|
||||
for (int i = 0; i < registeredIcus.size; i++) {
|
||||
if (registeredIcus.elements[i].driver == driver) {
|
||||
return ®isteredIcus.elements[i];
|
||||
}
|
||||
}
|
||||
firmwareError(CUSTOM_ERR_ICU, "reader not found");
|
||||
return (digital_input_s *) NULL;
|
||||
}
|
||||
|
||||
static void icuWidthCallback(ICUDriver *driver) {
|
||||
/*
|
||||
* see comment in icuPeriordCallBack
|
||||
int rowWidth = icuGetWidth(driver);
|
||||
*/
|
||||
digital_input_s * hw = finddigital_input_s(driver);
|
||||
hw->widthListeners.invokeJustArgCallbacks();
|
||||
}
|
||||
|
||||
static void icuPeriordCallBack(ICUDriver *driver) {
|
||||
/*
|
||||
* we do not use timer period at all - we just need the event. For all time characteristics,
|
||||
* we use system time
|
||||
* int period = icuGetPeriod(driver);
|
||||
*/
|
||||
|
||||
digital_input_s * hw = finddigital_input_s(driver);
|
||||
hw->periodListeners.invokeJustArgCallbacks();
|
||||
}
|
||||
|
||||
static uint32_t getAlternateFunctions(ICUDriver *driver) {
|
||||
if (driver == NULL) {
|
||||
firmwareError(CUSTOM_ERR_ICU_AF, "getAlternateFunctions(NULL)");
|
||||
return 0xffffffff;
|
||||
}
|
||||
#if STM32_ICU_USE_TIM1
|
||||
if (driver == &ICUD1) {
|
||||
return GPIO_AF_TIM1;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM2
|
||||
if (driver == &ICUD2) {
|
||||
return GPIO_AF_TIM2;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM3
|
||||
if (driver == &ICUD3) {
|
||||
return GPIO_AF_TIM3;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM4
|
||||
if (driver == &ICUD4) {
|
||||
return GPIO_AF_TIM4;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM8
|
||||
if (driver == &ICUD8) {
|
||||
return GPIO_AF_TIM8;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM9
|
||||
if (driver == &ICUD9) {
|
||||
return GPIO_AF_TIM9;
|
||||
}
|
||||
#endif
|
||||
firmwareError(CUSTOM_ERR_ICU_DRIVER, "No such driver");
|
||||
return 0xffffffff;
|
||||
}
|
||||
|
||||
icuchannel_t getInputCaptureChannel(brain_pin_e hwPin) {
|
||||
switch (hwPin) {
|
||||
case Gpio::A5: // TIM2 stm32f4discovery/Frankenso default
|
||||
case Gpio::A6: // TIM3
|
||||
case Gpio::A8: // TIM1
|
||||
case Gpio::A15: // TIM2
|
||||
case Gpio::C6: // TIM3 stm32f4discovery/Frankenso default
|
||||
case Gpio::E9: // TIM1
|
||||
return ICU_CHANNEL_1;
|
||||
|
||||
case Gpio::A1: // TIM2
|
||||
case Gpio::A7: // TIM3
|
||||
case Gpio::A9: // TIM1
|
||||
case Gpio::B3: // TIM2
|
||||
case Gpio::B5: // TIM2
|
||||
case Gpio::C7: // TIM3
|
||||
case Gpio::E11: // TIM1
|
||||
return ICU_CHANNEL_2;
|
||||
default:
|
||||
firmwareError(CUSTOM_ERR_ICU_PIN, "Unexpected hw pin in getInputCaptureChannel %s", hwPortname(hwPin));
|
||||
return ICU_CHANNEL_1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* as of Feb 2016, TIM1, TIM2, TIM3 and TIM9 are used for input capture
|
||||
* (that's the kind of event you need for shaft position sensor)
|
||||
* ChibiOS limitation is that only channels #1 and #2 could be used for input capture
|
||||
*
|
||||
* @return NULL if pin could not be used for ICU
|
||||
*/
|
||||
//Nullable
|
||||
ICUDriver * getInputCaptureDriver(const char *msg, brain_pin_e hwPin) {
|
||||
UNUSED(msg);
|
||||
|
||||
if (!isBrainPinValid(hwPin)) {
|
||||
return NULL;
|
||||
}
|
||||
#if STM32_ICU_USE_TIM1
|
||||
if (hwPin == Gpio::A8 ||
|
||||
hwPin == Gpio::A9 ||
|
||||
hwPin == Gpio::E9 ||
|
||||
hwPin == Gpio::E11) {
|
||||
return &ICUD1;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM2
|
||||
if (hwPin == Gpio::A1 ||
|
||||
hwPin == Gpio::A5 ||
|
||||
hwPin == Gpio::A15 ||
|
||||
hwPin == Gpio::B3) {
|
||||
return &ICUD2;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM3
|
||||
if (hwPin == Gpio::A6 ||
|
||||
hwPin == Gpio::A7 ||
|
||||
hwPin == Gpio::B4 ||
|
||||
hwPin == Gpio::B5 ||
|
||||
hwPin == Gpio::C6 ||
|
||||
hwPin == Gpio::C7) {
|
||||
return &ICUD3;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM8
|
||||
if (hwPin == Gpio::C6 ||
|
||||
hwPin == Gpio::C7) {
|
||||
return &ICUD8;
|
||||
}
|
||||
#endif
|
||||
#if STM32_ICU_USE_TIM9
|
||||
if (hwPin == Gpio::A2 ||
|
||||
hwPin == Gpio::A3 ||
|
||||
hwPin == Gpio::E5 ||
|
||||
hwPin == Gpio::E6) {
|
||||
return &ICUD9;
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void turnOnCapturePin(const char *msg, ICUDriver* driver, brain_pin_e brainPin) {
|
||||
if (driver) {
|
||||
iomode_t mode = (iomode_t) PAL_MODE_ALTERNATE(getAlternateFunctions(driver));
|
||||
efiSetPadMode(msg, brainPin, mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* turns pin off and returns digital_input_s back into registeredIcus pool
|
||||
*/
|
||||
void stopDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return;
|
||||
}
|
||||
efiSetPadUnused(brainPin);
|
||||
|
||||
ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
|
||||
if (driver == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
int regSize = registeredIcus.size;
|
||||
for (int i = 0; i < regSize; i++) {
|
||||
if (registeredIcus.elements[i].driver == driver) {
|
||||
// removing from driver from the list of used drivers
|
||||
memcpy(®isteredIcus.elements[i], ®isteredIcus.elements[regSize - 1],
|
||||
sizeof(digital_input_s));
|
||||
registeredIcus.size--;
|
||||
icuDisableNotificationsI(driver);
|
||||
icuStopCapture(driver);
|
||||
icuStop(driver);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw) {
|
||||
if (hw == NULL) {
|
||||
// we can get NULL driver if user somehow has invalid pin in his configuration
|
||||
warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "s_not input pin");
|
||||
return;
|
||||
}
|
||||
|
||||
ICUDriver *driver = hw->driver;
|
||||
|
||||
if (driver) {
|
||||
if (hw->started) {
|
||||
icuDisableNotificationsI(driver);
|
||||
icuStopCapture(driver);
|
||||
icuStop(driver);
|
||||
}
|
||||
wave_icucfg.channel = getInputCaptureChannel(hw->brainPin);
|
||||
efiIcuStart(msg, driver, &wave_icucfg);
|
||||
efiAssertVoid(CUSTOM_ICU_DRIVER, driver != NULL, "di: driver is NULL");
|
||||
efiAssertVoid(CUSTOM_ICU_DRIVER_STATE, driver->state == ICU_READY, "di: driver not ready");
|
||||
icuStartCapture(driver); // this would change state from READY to WAITING
|
||||
icuEnableNotifications(driver);
|
||||
}
|
||||
hw->started = true;
|
||||
}
|
||||
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
||||
ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
|
||||
if (!driver) {
|
||||
firmwareError(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "Invalid %s ICU input pin: %s", msg, hwPortname(brainPin));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
digital_input_s *hw = registeredIcus.add();
|
||||
hw->widthListeners.clear();
|
||||
hw->periodListeners.clear();
|
||||
hw->started = false;
|
||||
hw->brainPin = brainPin;
|
||||
hw->driver = driver;
|
||||
turnOnCapturePin(msg, driver, brainPin);
|
||||
|
||||
startInputDriver(msg, hw);
|
||||
return hw;
|
||||
}
|
||||
|
||||
#endif /* EFI_ICU_INPUTS */
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* @file digital_input_icu.h
|
||||
*
|
||||
* @date Jun 23, 2013
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "digital_input.h"
|
||||
|
||||
#if HAL_USE_ICU
|
||||
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin);
|
||||
|
||||
void stopDigitalCapture(const char *msg, brain_pin_e brainPin);
|
||||
|
||||
//Nullable
|
||||
ICUDriver * getInputCaptureDriver(const char *msg, brain_pin_e hwPin);
|
||||
//Nullable
|
||||
icuchannel_t getInputCaptureChannel(brain_pin_e hwPin);
|
||||
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
|
@ -14,23 +14,7 @@
|
|||
|
||||
#if (EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
|
||||
|
||||
#if (HAL_USE_ICU == TRUE) || (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE)
|
||||
|
||||
#if (HAL_USE_ICU == TRUE)
|
||||
void icuTriggerTurnOnInputPins();
|
||||
int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft);
|
||||
void icuTriggerTurnOffInputPin(brain_pin_e brainPin);
|
||||
#else
|
||||
#define icuTriggerTurnOnInputPins() ((void)0)
|
||||
int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
||||
UNUSED(msg);
|
||||
UNUSED(index);
|
||||
UNUSED(isTriggerShaft);
|
||||
|
||||
return -2;
|
||||
}
|
||||
#define icuTriggerTurnOffInputPin(brainPin) ((void)0)
|
||||
#endif
|
||||
#if (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE)
|
||||
|
||||
#if (HAL_TRIGGER_USE_PAL == TRUE)
|
||||
void extiTriggerTurnOnInputPins();
|
||||
|
@ -66,7 +50,6 @@
|
|||
|
||||
enum triggerType {
|
||||
TRIGGER_NONE,
|
||||
TRIGGER_ICU,
|
||||
TRIGGER_EXTI,
|
||||
TRIGGER_ADC,
|
||||
};
|
||||
|
@ -88,18 +71,6 @@ static int turnOnTriggerInputPin(const char *msg, int index, bool isTriggerShaft
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* try ICU first */
|
||||
#if EFI_ICU_INPUTS
|
||||
if (icuTriggerTurnOnInputPin(msg, index, isTriggerShaft) >= 0) {
|
||||
if (isTriggerShaft) {
|
||||
shaftTriggerType[index] = TRIGGER_ICU;
|
||||
} else {
|
||||
camTriggerType[index] = TRIGGER_ICU;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ... then ADC */
|
||||
#if HAL_TRIGGER_USE_ADC
|
||||
if (adcTriggerTurnOnInputPin(msg, index, isTriggerShaft) >= 0) {
|
||||
|
@ -132,11 +103,6 @@ static void turnOffTriggerInputPin(int index, bool isTriggerShaft) {
|
|||
activeConfiguration.triggerInputPins[index] : activeConfiguration.camInputs[index];
|
||||
|
||||
if (isTriggerShaft) {
|
||||
#if EFI_ICU_INPUTS
|
||||
if (shaftTriggerType[index] == TRIGGER_ICU) {
|
||||
icuTriggerTurnOffInputPin(brainPin);
|
||||
}
|
||||
#endif /* EFI_ICU_INPUTS */
|
||||
if (shaftTriggerType[index] == TRIGGER_ADC) {
|
||||
adcTriggerTurnOffInputPin(brainPin);
|
||||
}
|
||||
|
@ -147,11 +113,6 @@ static void turnOffTriggerInputPin(int index, bool isTriggerShaft) {
|
|||
|
||||
shaftTriggerType[index] = TRIGGER_NONE;
|
||||
} else {
|
||||
#if EFI_ICU_INPUTS
|
||||
if (camTriggerType[index] == TRIGGER_ICU) {
|
||||
icuTriggerTurnOffInputPin(brainPin);
|
||||
}
|
||||
#endif /* EFI_ICU_INPUTS */
|
||||
if (camTriggerType[index] == TRIGGER_ADC) {
|
||||
adcTriggerTurnOffInputPin(brainPin);
|
||||
}
|
||||
|
@ -200,13 +161,12 @@ void startTriggerInputPins() {
|
|||
|
||||
void turnOnTriggerInputPins() {
|
||||
/* init all trigger HW available */
|
||||
icuTriggerTurnOnInputPins();
|
||||
extiTriggerTurnOnInputPins();
|
||||
|
||||
applyNewTriggerInputPins();
|
||||
}
|
||||
|
||||
#endif /* (HAL_USE_ICU == TRUE) || (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE) */
|
||||
#endif /* (HAL_TRIGGER_USE_PAL == TRUE) || (HAL_TRIGGER_USE_ADC == TRUE) */
|
||||
|
||||
|
||||
void stopTriggerDebugPins() {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "hal_comp.h"
|
||||
|
||||
#include "trigger_input.h"
|
||||
#include "digital_input_icu.h"
|
||||
|
||||
static volatile int centeredDacValue = 127;
|
||||
static volatile int toothCnt = 0;
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
* @file trigger_input_icu.cpp
|
||||
* @brief Position sensor hardware layer - ICU version
|
||||
*
|
||||
* todo: code reuse with digital_input_icu.cpp was never finished
|
||||
* todo: at the moment due to half-done code reuse we already depend on EFI_ICU_INPUTS but still have custom code
|
||||
* todo: VVT implementation is a nasty copy-paste :(
|
||||
*
|
||||
* see digital_input_icu.cpp
|
||||
*
|
||||
* @date Dec 30, 2012
|
||||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
int icuRisingCallbackCounter = 0;
|
||||
int icuFallingCallbackCounter = 0;
|
||||
|
||||
#if EFI_SHAFT_POSITION_INPUT && (HAL_USE_ICU == TRUE)
|
||||
|
||||
#include "trigger_input.h"
|
||||
#include "digital_input_icu.h"
|
||||
#include "tooth_logger.h"
|
||||
|
||||
static void vvtRisingCallback(void *arg) {
|
||||
efitick_t now = getTimeNowNt();
|
||||
|
||||
int index = (int)arg;
|
||||
|
||||
#if EFI_TOOTH_LOGGER
|
||||
if (!engineConfiguration->displayLogicLevelsInEngineSniffer) {
|
||||
// real physical fronts go into engine sniffer
|
||||
LogTriggerTooth(SHAFT_SECONDARY_RISING, now);
|
||||
}
|
||||
#endif /* EFI_TOOTH_LOGGER */
|
||||
hwHandleVvtCamSignal(engineConfiguration->invertCamVVTSignal ? TV_FALL : TV_RISE, now, index);
|
||||
}
|
||||
|
||||
static void vvtFallingCallback(void * arg) {
|
||||
efitick_t now = getTimeNowNt();
|
||||
|
||||
int index = (int)arg;
|
||||
#if EFI_TOOTH_LOGGER
|
||||
if (!engineConfiguration->displayLogicLevelsInEngineSniffer) {
|
||||
LogTriggerTooth(SHAFT_SECONDARY_FALLING, now);
|
||||
}
|
||||
#endif /* EFI_TOOTH_LOGGER */
|
||||
hwHandleVvtCamSignal(engineConfiguration->invertCamVVTSignal ? TV_RISE : TV_FALL, now, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* that's hardware timer input capture IRQ entry point
|
||||
*/
|
||||
static void shaftRisingCallback(bool isPrimary) {
|
||||
efitick_t stamp = getTimeNowNt();
|
||||
|
||||
icuRisingCallbackCounter++;
|
||||
|
||||
// icucnt_t last_width = icuGetWidth(icup); so far we are fine with system time
|
||||
|
||||
hwHandleShaftSignal(isPrimary ? 0 : 1, true, stamp);
|
||||
}
|
||||
|
||||
static void shaftFallingCallback(bool isPrimary) {
|
||||
efitick_t stamp = getTimeNowNt();
|
||||
|
||||
icuFallingCallbackCounter++;
|
||||
|
||||
hwHandleShaftSignal(isPrimary ? 0 : 1, false, stamp);
|
||||
}
|
||||
|
||||
/*==========================================================================*/
|
||||
/* Exported functions. */
|
||||
/*==========================================================================*/
|
||||
|
||||
int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
||||
(void)msg;
|
||||
brain_pin_e brainPin = isTriggerShaft ? engineConfiguration->triggerInputPins[index] : engineConfiguration->camInputs[index];
|
||||
if (!isBrainPinValid(brainPin)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
digital_input_s* input = startDigitalCapture(msg, brainPin);
|
||||
if (input == NULL) {
|
||||
/* error already reported */
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isTriggerShaft) {
|
||||
void * arg = (void*) (index == 0);
|
||||
input->setWidthCallback((VoidInt)(void*)shaftRisingCallback, arg);
|
||||
input->setPeriodCallback((VoidInt)(void*)shaftFallingCallback, arg);
|
||||
} else {
|
||||
void * arg = (void *)index;
|
||||
input->setWidthCallback((VoidInt)(void*)vvtRisingCallback, arg);
|
||||
input->setPeriodCallback((VoidInt)(void*)vvtFallingCallback, arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void icuTriggerTurnOffInputPin(brain_pin_e brainPin) {
|
||||
stopDigitalCapture("trigger", brainPin);
|
||||
}
|
||||
|
||||
void icuTriggerTurnOnInputPins() {
|
||||
}
|
||||
#endif /* (EFI_SHAFT_POSITION_INPUT && (HAL_USE_ICU == TRUE)) */
|
|
@ -10,11 +10,8 @@ HW_INC = hw_layer/$(CPU_HWLAYER) \
|
|||
HW_LAYER_EMS_CPP = \
|
||||
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/microsecond_timer/microsecond_timer.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/digital_input.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/digital_input_icu.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/digital_input_exti.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/trigger/trigger_input.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/trigger/trigger_input_icu.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/trigger/trigger_input_exti.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/digital_input/trigger/trigger_input_adc.cpp \
|
||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||
|
|
|
@ -112,19 +112,6 @@ iomode_t getInputMode(pin_input_mode_e mode) {
|
|||
}
|
||||
}
|
||||
|
||||
#if HAL_USE_ICU
|
||||
static char icuError[30];
|
||||
|
||||
void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config) {
|
||||
if (icup->state != ICU_STOP && icup->state != ICU_READY) {
|
||||
chsnprintf(icuError, sizeof(icuError), "ICU already used %s", msg);
|
||||
firmwareError(CUSTOM_ERROR_ICU, icuError);
|
||||
return;
|
||||
}
|
||||
icuStart(icup, config);
|
||||
}
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
void writePad(const char *msg, brain_pin_e pin, int bit) {
|
||||
palWritePad(getHwPort(msg, pin), getHwPin(msg, pin), bit);
|
||||
}
|
||||
|
|
|
@ -36,9 +36,6 @@ EXTERNC void efiSetPadUnused(brain_pin_e brainPin);
|
|||
EXTERNC bool efiReadPin(brain_pin_e pin);
|
||||
|
||||
EXTERNC iomode_t getInputMode(pin_input_mode_e mode);
|
||||
#if HAL_USE_ICU
|
||||
EXTERNC void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config);
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
#endif /* EFI_GPIO_HARDWARE */
|
||||
|
||||
|
|
|
@ -177,9 +177,9 @@
|
|||
/*
|
||||
* ICU driver system settings.
|
||||
*/
|
||||
#define STM32_ICU_USE_TIM1 TRUE
|
||||
#define STM32_ICU_USE_TIM2 TRUE
|
||||
#define STM32_ICU_USE_TIM3 TRUE
|
||||
#define STM32_ICU_USE_TIM1 FALSE
|
||||
#define STM32_ICU_USE_TIM2 FALSE
|
||||
#define STM32_ICU_USE_TIM3 FALSE
|
||||
#define STM32_ICU_USE_TIM4 FALSE
|
||||
#define STM32_ICU_USE_TIM5 FALSE
|
||||
#define STM32_ICU_USE_TIM8 FALSE
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
* @brief Enables the ICU subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_ICU TRUE
|
||||
#define HAL_USE_ICU FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
* @brief Enables the ICU subsystem.
|
||||
*/
|
||||
#if !defined(HAL_USE_ICU) || defined(__DOXYGEN__)
|
||||
#define HAL_USE_ICU TRUE
|
||||
#define HAL_USE_ICU FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -105,7 +105,6 @@
|
|||
|
||||
#define EFI_ELECTRONIC_THROTTLE_BODY TRUE
|
||||
#define EFI_AUX_PID TRUE
|
||||
#define EFI_ICU_INPUTS FALSE
|
||||
|
||||
#ifndef HAL_TRIGGER_USE_PAL
|
||||
#define HAL_TRIGGER_USE_PAL FALSE
|
||||
|
|
Loading…
Reference in New Issue