mirror of https://github.com/FOME-Tech/fome-fw.git
auto-sync
This commit is contained in:
parent
b982d4985c
commit
a2ce84475f
|
@ -21,7 +21,8 @@ public:
|
||||||
T pop();
|
T pop();
|
||||||
T get(int index);
|
T get(int index);
|
||||||
bool_t remove(T value);
|
bool_t remove(T value);
|
||||||
int size();bool isEmpty();
|
int size();
|
||||||
|
bool isEmpty();
|
||||||
private:
|
private:
|
||||||
int currentSize;
|
int currentSize;
|
||||||
T values[MAXSIZE];
|
T values[MAXSIZE];
|
||||||
|
@ -30,6 +31,7 @@ private:
|
||||||
template<typename T, int MAXSIZE>
|
template<typename T, int MAXSIZE>
|
||||||
FLStack<T, MAXSIZE>::FLStack() {
|
FLStack<T, MAXSIZE>::FLStack() {
|
||||||
reset();
|
reset();
|
||||||
|
memset(values, 0, sizeof(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, int MAXSIZE>
|
template<typename T, int MAXSIZE>
|
||||||
|
@ -94,6 +96,7 @@ public:
|
||||||
Type elements[Dimention];
|
Type elements[Dimention];
|
||||||
void reset(void);
|
void reset(void);
|
||||||
Type *add(void);
|
Type *add(void);
|
||||||
|
void removeAt(int index);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Type, int Dimention>
|
template<class Type, int Dimention>
|
||||||
|
@ -102,6 +105,14 @@ ArrayList<Type, Dimention>::ArrayList(void) {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Type, int Dimention>
|
||||||
|
void ArrayList<Type, Dimention>::removeAt(int index) {
|
||||||
|
efiAssertVoid(index < size, "index greater then size");
|
||||||
|
memcpy(&elements[index], &elements[size - 1], sizeof(Type));
|
||||||
|
memset(&elements[size - 1], 0, sizeof(Type));
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
|
||||||
template<class Type, int Dimention>
|
template<class Type, int Dimention>
|
||||||
void ArrayList<Type, Dimention>::reset(void) {
|
void ArrayList<Type, Dimention>::reset(void) {
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
|
@ -50,7 +50,7 @@ static THD_WORKING_AREA(waThreadStack, UTILITY_THREAD_STACK_SIZE);
|
||||||
static Logging * logger;
|
static Logging * logger;
|
||||||
|
|
||||||
static void ensureInitialized(WaveReader *reader) {
|
static void ensureInitialized(WaveReader *reader) {
|
||||||
efiAssertVoid(reader->hw.started, "wave analyzer NOT INITIALIZED");
|
efiAssertVoid(reader->hw->started, "wave analyzer NOT INITIALIZED");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
|
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
|
||||||
|
@ -104,7 +104,7 @@ static void waIcuPeriodCallback(WaveReader *reader) {
|
||||||
static void setWaveModeSilent(int index, int mode) {
|
static void setWaveModeSilent(int index, int mode) {
|
||||||
WaveReader *reader = &readers[index];
|
WaveReader *reader = &readers[index];
|
||||||
|
|
||||||
startInputDriver(&reader->hw, mode);
|
startInputDriver(reader->hw, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
//static int getEventCounter(int index) {
|
//static int getEventCounter(int index) {
|
||||||
|
@ -121,21 +121,25 @@ static void initWave(const char *name, int index) {
|
||||||
waveReaderCount++;
|
waveReaderCount++;
|
||||||
efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs");
|
efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs");
|
||||||
WaveReader *reader = &readers[index];
|
WaveReader *reader = &readers[index];
|
||||||
WaveReaderHw *hw = &reader->hw;
|
|
||||||
|
|
||||||
reader->name = name;
|
reader->name = name;
|
||||||
|
|
||||||
hw->widthListeners.registerCallback((VoidInt) waAnaWidthCallback, (void*) reader);
|
reader->hw = initWaveAnalyzerDriver(brainPin);
|
||||||
|
|
||||||
hw->periodListeners.registerCallback((VoidInt) waIcuPeriodCallback, (void*) reader);
|
|
||||||
|
|
||||||
initWaveAnalyzerDriver(hw, brainPin);
|
reader->hw->widthListeners.registerCallback((VoidInt) waAnaWidthCallback, (void*) reader);
|
||||||
|
|
||||||
print("wave%d input on %s%d\r\n", index, portname(reader->hw.port), reader->hw.pin);
|
reader->hw->periodListeners.registerCallback((VoidInt) waIcuPeriodCallback, (void*) reader);
|
||||||
startInputDriver(hw, mode);
|
|
||||||
|
|
||||||
|
print("wave%d input on %s\r\n", index, hwPortname(brainPin));
|
||||||
|
startInputDriver(reader->hw, mode);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
WaveReader::WaveReader() {
|
||||||
|
hw = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
|
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
|
||||||
(void)ckpSignalType;
|
(void)ckpSignalType;
|
||||||
if (index != 0) {
|
if (index != 0) {
|
||||||
|
@ -195,7 +199,7 @@ static float getSignalPeriodMs(int index) {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
static void reportWave(Logging *logging, int index) {
|
static void reportWave(Logging *logging, int index) {
|
||||||
if (readers[index].hw.started) {
|
if (readers[index].hw->started) {
|
||||||
// int counter = getEventCounter(index);
|
// int counter = getEventCounter(index);
|
||||||
// debugInt2(logging, "ev", index, counter);
|
// debugInt2(logging, "ev", index, counter);
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,10 @@
|
||||||
|
|
||||||
class WaveReader {
|
class WaveReader {
|
||||||
public:
|
public:
|
||||||
|
WaveReader();
|
||||||
void onFallEvent();
|
void onFallEvent();
|
||||||
|
|
||||||
WaveReaderHw hw;
|
WaveReaderHw *hw;
|
||||||
const char *name;
|
const char *name;
|
||||||
volatile int eventCounter;
|
volatile int eventCounter;
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,18 @@ static void adcConfigListener(Engine *engine) {
|
||||||
calcFastAdcIndexes();
|
calcFastAdcIndexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void turnOnHardware(void) {
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
|
turnOnTriggerInputPins();
|
||||||
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
}
|
||||||
|
|
||||||
|
void turnOffHardware(void) {
|
||||||
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
|
turnOffTriggerInputPins();
|
||||||
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
}
|
||||||
|
|
||||||
void initHardware(Logging *l, Engine *engine) {
|
void initHardware(Logging *l, Engine *engine) {
|
||||||
sharedLogger = l;
|
sharedLogger = l;
|
||||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||||
|
@ -277,10 +289,10 @@ void initHardware(Logging *l, Engine *engine) {
|
||||||
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
|
||||||
// todo: figure out better startup logic
|
// todo: figure out better startup logic
|
||||||
initTriggerCentral(sharedLogger, engine);
|
initTriggerCentral(sharedLogger, engine);
|
||||||
|
|
||||||
initShaftPositionInputCapture();
|
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
|
||||||
|
turnOnHardware();
|
||||||
|
|
||||||
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
||||||
initSpiModules(boardConfiguration);
|
initSpiModules(boardConfiguration);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,13 +18,9 @@
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "wave_analyzer_hw.h"
|
#include "wave_analyzer_hw.h"
|
||||||
|
|
||||||
static WaveReaderHw primaryCrankInput;
|
static ICUDriver *primaryCrankDriver;
|
||||||
static WaveReaderHw secondaryCrankInput;
|
|
||||||
|
|
||||||
EXTERN_ENGINE;
|
EXTERN_ENGINE;
|
||||||
extern engine_configuration_s *engineConfiguration;
|
|
||||||
extern engine_configuration2_s *engineConfiguration2;
|
|
||||||
extern board_configuration_s *boardConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* that's hardware timer input capture IRQ entry point
|
* that's hardware timer input capture IRQ entry point
|
||||||
|
@ -33,7 +29,7 @@ extern board_configuration_s *boardConfiguration;
|
||||||
static void shaft_icu_width_callback(ICUDriver *icup) {
|
static void shaft_icu_width_callback(ICUDriver *icup) {
|
||||||
// todo: support for 3rd trigger input channel
|
// todo: support for 3rd trigger input channel
|
||||||
// todo: start using real event time from HW event, not just software timer?
|
// todo: start using real event time from HW event, not just software timer?
|
||||||
int isPrimary = icup == primaryCrankInput.driver;
|
int isPrimary = icup == primaryCrankDriver;
|
||||||
if (!isPrimary && !engine->triggerShape.needSecondTriggerInput) {
|
if (!isPrimary && !engine->triggerShape.needSecondTriggerInput) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +41,7 @@ static void shaft_icu_width_callback(ICUDriver *icup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void shaft_icu_period_callback(ICUDriver *icup) {
|
static void shaft_icu_period_callback(ICUDriver *icup) {
|
||||||
int isPrimary = icup == primaryCrankInput.driver;
|
int isPrimary = icup == primaryCrankDriver;
|
||||||
if (!isPrimary && !engine->triggerShape.needSecondTriggerInput) {
|
if (!isPrimary && !engine->triggerShape.needSecondTriggerInput) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -62,38 +58,30 @@ static void shaft_icu_period_callback(ICUDriver *icup) {
|
||||||
static ICUConfig shaft_icucfg = { ICU_INPUT_ACTIVE_LOW, 100000, /* 100kHz ICU clock frequency. */
|
static ICUConfig shaft_icucfg = { ICU_INPUT_ACTIVE_LOW, 100000, /* 100kHz ICU clock frequency. */
|
||||||
shaft_icu_width_callback, shaft_icu_period_callback };
|
shaft_icu_width_callback, shaft_icu_period_callback };
|
||||||
|
|
||||||
void initShaftPositionInputCapture(void) {
|
static ICUDriver *turnOnTriggerInputPin(brain_pin_e hwPin) {
|
||||||
|
// configure pin
|
||||||
ICUDriver *driver;
|
turnOnCapturePin(hwPin);
|
||||||
|
|
||||||
driver = getInputCaptureDriver(boardConfiguration->triggerInputPins[0]);
|
|
||||||
|
|
||||||
// todo: extract method!
|
|
||||||
// initialize primary Input Capture Unit pin
|
|
||||||
initWaveAnalyzerDriver(&primaryCrankInput, boardConfiguration->triggerInputPins[0]);
|
|
||||||
/**
|
|
||||||
* Start primary Input Capture Unit using given configuration
|
|
||||||
* @see shaft_icucfg for callback entry points
|
|
||||||
*/
|
|
||||||
shaft_icucfg.channel = ICU_CHANNEL_1;
|
shaft_icucfg.channel = ICU_CHANNEL_1;
|
||||||
print("initShaftPositionInputCapture 1 %s\r\n", hwPortname(boardConfiguration->triggerInputPins[0]));
|
|
||||||
|
ICUDriver *driver = getInputCaptureDriver(hwPin);
|
||||||
|
print("initShaftPositionInputCapture %s\r\n", hwPortname(hwPin));
|
||||||
// todo: reuse 'setWaveReaderMode' method here?
|
// todo: reuse 'setWaveReaderMode' method here?
|
||||||
if (driver != NULL) {
|
if (driver != NULL) {
|
||||||
efiIcuStart(driver, &shaft_icucfg);
|
efiIcuStart(driver, &shaft_icucfg);
|
||||||
icuEnable(driver);
|
icuEnable(driver);
|
||||||
}
|
}
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
driver = getInputCaptureDriver(boardConfiguration->triggerInputPins[1]);
|
void turnOnTriggerInputPins(void) {
|
||||||
// initialize secondary Input Capture Unit pin
|
primaryCrankDriver = turnOnTriggerInputPin(boardConfiguration->triggerInputPins[0]);
|
||||||
initWaveAnalyzerDriver(&secondaryCrankInput, boardConfiguration->triggerInputPins[1]);
|
turnOnTriggerInputPin(boardConfiguration->triggerInputPins[1]);
|
||||||
shaft_icucfg.channel = ICU_CHANNEL_1;
|
|
||||||
print("initShaftPositionInputCapture 2 %s\r\n", hwPortname(boardConfiguration->triggerInputPins[1]));
|
|
||||||
if (driver != NULL) {
|
|
||||||
efiIcuStart(driver, &shaft_icucfg);
|
|
||||||
icuEnable(driver);
|
|
||||||
}
|
|
||||||
|
|
||||||
print("crank input disabled\r\n");
|
print("crank input disabled\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void turnOffTriggerInputPins(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* EFI_SHAFT_POSITION_INPUT */
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
||||||
|
|
|
@ -9,15 +9,7 @@
|
||||||
#ifndef CRANK_INPUT_H_
|
#ifndef CRANK_INPUT_H_
|
||||||
#define CRANK_INPUT_H_
|
#define CRANK_INPUT_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
void turnOnTriggerInputPins(void);
|
||||||
extern "C"
|
void turnOffTriggerInputPins(void);
|
||||||
{
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
void initShaftPositionInputCapture(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* CRANK_INPUT_H_ */
|
#endif /* CRANK_INPUT_H_ */
|
||||||
|
|
|
@ -18,8 +18,6 @@ EXTERN_ENGINE
|
||||||
|
|
||||||
static Logging *logger;
|
static Logging *logger;
|
||||||
|
|
||||||
static WaveReaderHw vehicleSpeedInput;
|
|
||||||
|
|
||||||
static uint64_t lastSignalTimeNt = 0;
|
static uint64_t lastSignalTimeNt = 0;
|
||||||
static uint64_t vssDiff = 0;
|
static uint64_t vssDiff = 0;
|
||||||
static int vssCounter = 0;
|
static int vssCounter = 0;
|
||||||
|
@ -54,10 +52,10 @@ void initVehicleSpeed(Logging *l) {
|
||||||
logger = l;
|
logger = l;
|
||||||
if (boardConfiguration->vehicleSpeedSensorInputPin == GPIO_UNASSIGNED)
|
if (boardConfiguration->vehicleSpeedSensorInputPin == GPIO_UNASSIGNED)
|
||||||
return;
|
return;
|
||||||
initWaveAnalyzerDriver(&vehicleSpeedInput, boardConfiguration->vehicleSpeedSensorInputPin);
|
WaveReaderHw* vehicleSpeedInput = initWaveAnalyzerDriver(boardConfiguration->vehicleSpeedSensorInputPin);
|
||||||
startInputDriver(&vehicleSpeedInput, true);
|
startInputDriver(vehicleSpeedInput, true);
|
||||||
|
|
||||||
vehicleSpeedInput.widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
|
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
|
||||||
addConsoleAction("speedinfo", speedInfo);
|
addConsoleAction("speedinfo", speedInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "wave_analyzer_hw.h"
|
#include "wave_analyzer_hw.h"
|
||||||
#include "mpu_util.h"
|
#include "mpu_util.h"
|
||||||
|
#include "fl_stack.h"
|
||||||
|
|
||||||
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
|
#if EFI_WAVE_ANALYZER || defined(__DOXYGEN__)
|
||||||
|
|
||||||
|
@ -25,13 +26,12 @@ static void icuPeriordCallBack(ICUDriver *driver);
|
||||||
static ICUConfig wave_icucfg = { ICU_INPUT_ACTIVE_LOW, CORE_CLOCK / 100, icuWidthCallback, icuPeriordCallBack, 0,
|
static ICUConfig wave_icucfg = { ICU_INPUT_ACTIVE_LOW, CORE_CLOCK / 100, icuWidthCallback, icuPeriordCallBack, 0,
|
||||||
ICU_CHANNEL_1, 0 };
|
ICU_CHANNEL_1, 0 };
|
||||||
|
|
||||||
static int registeredIcuCount = 0;
|
static ArrayList<WaveReaderHw, 8> registeredIcus;
|
||||||
static WaveReaderHw* registeredIcus[8];
|
|
||||||
|
|
||||||
static WaveReaderHw * findWaveReaderHw(ICUDriver *driver) {
|
static WaveReaderHw * findWaveReaderHw(ICUDriver *driver) {
|
||||||
for (int i = 0; i < registeredIcuCount; i++) {
|
for (int i = 0; i < registeredIcus.size; i++) {
|
||||||
if (registeredIcus[i]->driver == driver) {
|
if (registeredIcus.elements[i].driver == driver) {
|
||||||
return registeredIcus[i];
|
return ®isteredIcus.elements[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
firmwareError("reader not found");
|
firmwareError("reader not found");
|
||||||
|
@ -140,25 +140,27 @@ ICUDriver * getInputCaptureDriver(brain_pin_e hwPin) {
|
||||||
return (ICUDriver *) NULL;
|
return (ICUDriver *) NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initWaveAnalyzerDriver(WaveReaderHw *hw, brain_pin_e brainPin) {
|
void turnOnCapturePin(brain_pin_e brainPin) {
|
||||||
ioportid_t port = getHwPort(brainPin);
|
ioportid_t port = getHwPort(brainPin);
|
||||||
ioportmask_t pin = getHwPin(brainPin);
|
ioportmask_t pin = getHwPin(brainPin);
|
||||||
|
|
||||||
ICUDriver *driver = getInputCaptureDriver(brainPin);
|
ICUDriver *driver = getInputCaptureDriver(brainPin);
|
||||||
|
|
||||||
hw->driver = driver;
|
|
||||||
hw->port = port;
|
|
||||||
hw->pin = pin;
|
|
||||||
if (driver != NULL) {
|
if (driver != NULL) {
|
||||||
iomode_t mode = (iomode_t) PAL_MODE_ALTERNATE(getAlternateFunctions(driver));
|
iomode_t mode = (iomode_t) PAL_MODE_ALTERNATE(getAlternateFunctions(driver));
|
||||||
mySetPadMode("wave input", port, pin, mode);
|
mySetPadMode("wave input", port, pin, mode);
|
||||||
|
|
||||||
// hw->widthListeners.currentListenersCount = 0;
|
|
||||||
|
|
||||||
registeredIcus[registeredIcuCount++] = hw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WaveReaderHw * initWaveAnalyzerDriver(brain_pin_e brainPin) {
|
||||||
|
ICUDriver *driver = getInputCaptureDriver(brainPin);
|
||||||
|
|
||||||
|
WaveReaderHw *hw = registeredIcus.add();
|
||||||
|
|
||||||
|
hw->driver = driver;
|
||||||
|
turnOnCapturePin(brainPin);
|
||||||
|
return hw;
|
||||||
|
}
|
||||||
|
|
||||||
void startInputDriver(WaveReaderHw *hw, bool isActiveHigh) {
|
void startInputDriver(WaveReaderHw *hw, bool isActiveHigh) {
|
||||||
hw->isActiveHigh = isActiveHigh;
|
hw->isActiveHigh = isActiveHigh;
|
||||||
if (hw->isActiveHigh) {
|
if (hw->isActiveHigh) {
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ICUDriver *driver;
|
ICUDriver *driver;
|
||||||
GPIO_TypeDef *port;
|
|
||||||
int pin;
|
|
||||||
bool_t isActiveHigh; // false for ICU_INPUT_ACTIVE_LOW, true for ICU_INPUT_ACTIVE_HIGH
|
bool_t isActiveHigh; // false for ICU_INPUT_ACTIVE_LOW, true for ICU_INPUT_ACTIVE_HIGH
|
||||||
volatile int started;
|
volatile bool_t started;
|
||||||
|
|
||||||
// todo: make this a template & reduce number of listeners?
|
// todo: make this a template & reduce number of listeners?
|
||||||
// todo: would one listener be enough?
|
// todo: would one listener be enough?
|
||||||
|
@ -27,7 +25,8 @@ typedef struct {
|
||||||
IntListenerArray periodListeners;
|
IntListenerArray periodListeners;
|
||||||
} WaveReaderHw;
|
} WaveReaderHw;
|
||||||
|
|
||||||
void initWaveAnalyzerDriver(WaveReaderHw *hw, brain_pin_e brainPin);
|
void turnOnCapturePin(brain_pin_e brainPin);
|
||||||
|
WaveReaderHw *initWaveAnalyzerDriver(brain_pin_e brainPin);
|
||||||
void startInputDriver(WaveReaderHw *hw, bool isActiveHigh);
|
void startInputDriver(WaveReaderHw *hw, bool isActiveHigh);
|
||||||
ICUDriver * getInputCaptureDriver(brain_pin_e hwPin);
|
ICUDriver * getInputCaptureDriver(brain_pin_e hwPin);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue