auto-sync

This commit is contained in:
rusEfi 2015-04-07 20:10:24 -05:00
parent b982d4985c
commit a2ce84475f
9 changed files with 84 additions and 77 deletions

View File

@ -21,7 +21,8 @@ public:
T pop();
T get(int index);
bool_t remove(T value);
int size();bool isEmpty();
int size();
bool isEmpty();
private:
int currentSize;
T values[MAXSIZE];
@ -30,6 +31,7 @@ private:
template<typename T, int MAXSIZE>
FLStack<T, MAXSIZE>::FLStack() {
reset();
memset(values, 0, sizeof(values));
}
template<typename T, int MAXSIZE>
@ -94,6 +96,7 @@ public:
Type elements[Dimention];
void reset(void);
Type *add(void);
void removeAt(int index);
};
template<class Type, int Dimention>
@ -102,6 +105,14 @@ ArrayList<Type, Dimention>::ArrayList(void) {
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>
void ArrayList<Type, Dimention>::reset(void) {
size = 0;

View File

@ -50,7 +50,7 @@ static THD_WORKING_AREA(waThreadStack, UTILITY_THREAD_STACK_SIZE);
static Logging * logger;
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__)
@ -104,7 +104,7 @@ static void waIcuPeriodCallback(WaveReader *reader) {
static void setWaveModeSilent(int index, int mode) {
WaveReader *reader = &readers[index];
startInputDriver(&reader->hw, mode);
startInputDriver(reader->hw, mode);
}
//static int getEventCounter(int index) {
@ -121,21 +121,25 @@ static void initWave(const char *name, int index) {
waveReaderCount++;
efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs");
WaveReader *reader = &readers[index];
WaveReaderHw *hw = &reader->hw;
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);
startInputDriver(hw, mode);
reader->hw->periodListeners.registerCallback((VoidInt) waIcuPeriodCallback, (void*) reader);
print("wave%d input on %s\r\n", index, hwPortname(brainPin));
startInputDriver(reader->hw, mode);
}
#endif
WaveReader::WaveReader() {
hw = NULL;
}
static void waTriggerEventListener(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S) {
(void)ckpSignalType;
if (index != 0) {
@ -195,7 +199,7 @@ static float getSignalPeriodMs(int index) {
//}
static void reportWave(Logging *logging, int index) {
if (readers[index].hw.started) {
if (readers[index].hw->started) {
// int counter = getEventCounter(index);
// debugInt2(logging, "ev", index, counter);

View File

@ -25,9 +25,10 @@
class WaveReader {
public:
WaveReader();
void onFallEvent();
WaveReaderHw hw;
WaveReaderHw *hw;
const char *name;
volatile int eventCounter;

View File

@ -177,6 +177,18 @@ static void adcConfigListener(Engine *engine) {
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) {
sharedLogger = l;
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
@ -277,10 +289,10 @@ void initHardware(Logging *l, Engine *engine) {
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
// todo: figure out better startup logic
initTriggerCentral(sharedLogger, engine);
initShaftPositionInputCapture();
#endif /* EFI_SHAFT_POSITION_INPUT */
turnOnHardware();
#if HAL_USE_SPI || defined(__DOXYGEN__)
initSpiModules(boardConfiguration);
#endif

View File

@ -18,13 +18,9 @@
#include "engine_configuration.h"
#include "wave_analyzer_hw.h"
static WaveReaderHw primaryCrankInput;
static WaveReaderHw secondaryCrankInput;
static ICUDriver *primaryCrankDriver;
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
@ -33,7 +29,7 @@ extern board_configuration_s *boardConfiguration;
static void shaft_icu_width_callback(ICUDriver *icup) {
// todo: support for 3rd trigger input channel
// 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) {
return;
}
@ -45,7 +41,7 @@ static void shaft_icu_width_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) {
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. */
shaft_icu_width_callback, shaft_icu_period_callback };
void initShaftPositionInputCapture(void) {
ICUDriver *driver;
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
*/
static ICUDriver *turnOnTriggerInputPin(brain_pin_e hwPin) {
// configure pin
turnOnCapturePin(hwPin);
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?
if (driver != NULL) {
efiIcuStart(driver, &shaft_icucfg);
icuEnable(driver);
}
driver = getInputCaptureDriver(boardConfiguration->triggerInputPins[1]);
// initialize secondary Input Capture Unit pin
initWaveAnalyzerDriver(&secondaryCrankInput, 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);
return driver;
}
void turnOnTriggerInputPins(void) {
primaryCrankDriver = turnOnTriggerInputPin(boardConfiguration->triggerInputPins[0]);
turnOnTriggerInputPin(boardConfiguration->triggerInputPins[1]);
print("crank input disabled\r\n");
}
void turnOffTriggerInputPins(void) {
}
#endif /* EFI_SHAFT_POSITION_INPUT */

View File

@ -9,15 +9,7 @@
#ifndef CRANK_INPUT_H_
#define CRANK_INPUT_H_
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
void initShaftPositionInputCapture(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
void turnOnTriggerInputPins(void);
void turnOffTriggerInputPins(void);
#endif /* CRANK_INPUT_H_ */

View File

@ -18,8 +18,6 @@ EXTERN_ENGINE
static Logging *logger;
static WaveReaderHw vehicleSpeedInput;
static uint64_t lastSignalTimeNt = 0;
static uint64_t vssDiff = 0;
static int vssCounter = 0;
@ -54,10 +52,10 @@ void initVehicleSpeed(Logging *l) {
logger = l;
if (boardConfiguration->vehicleSpeedSensorInputPin == GPIO_UNASSIGNED)
return;
initWaveAnalyzerDriver(&vehicleSpeedInput, boardConfiguration->vehicleSpeedSensorInputPin);
startInputDriver(&vehicleSpeedInput, true);
WaveReaderHw* vehicleSpeedInput = initWaveAnalyzerDriver(boardConfiguration->vehicleSpeedSensorInputPin);
startInputDriver(vehicleSpeedInput, true);
vehicleSpeedInput.widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
addConsoleAction("speedinfo", speedInfo);
}

View File

@ -8,6 +8,7 @@
#include "wave_analyzer_hw.h"
#include "mpu_util.h"
#include "fl_stack.h"
#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,
ICU_CHANNEL_1, 0 };
static int registeredIcuCount = 0;
static WaveReaderHw* registeredIcus[8];
static ArrayList<WaveReaderHw, 8> registeredIcus;
static WaveReaderHw * findWaveReaderHw(ICUDriver *driver) {
for (int i = 0; i < registeredIcuCount; i++) {
if (registeredIcus[i]->driver == driver) {
return registeredIcus[i];
for (int i = 0; i < registeredIcus.size; i++) {
if (registeredIcus.elements[i].driver == driver) {
return &registeredIcus.elements[i];
}
}
firmwareError("reader not found");
@ -140,25 +140,27 @@ ICUDriver * getInputCaptureDriver(brain_pin_e hwPin) {
return (ICUDriver *) NULL;
}
void initWaveAnalyzerDriver(WaveReaderHw *hw, brain_pin_e brainPin) {
void turnOnCapturePin(brain_pin_e brainPin) {
ioportid_t port = getHwPort(brainPin);
ioportmask_t pin = getHwPin(brainPin);
ICUDriver *driver = getInputCaptureDriver(brainPin);
hw->driver = driver;
hw->port = port;
hw->pin = pin;
if (driver != NULL) {
iomode_t mode = (iomode_t) PAL_MODE_ALTERNATE(getAlternateFunctions(driver));
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) {
hw->isActiveHigh = isActiveHigh;
if (hw->isActiveHigh) {

View File

@ -16,10 +16,8 @@
typedef struct {
ICUDriver *driver;
GPIO_TypeDef *port;
int pin;
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: would one listener be enough?
@ -27,7 +25,8 @@ typedef struct {
IntListenerArray periodListeners;
} 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);
ICUDriver * getInputCaptureDriver(brain_pin_e hwPin);