auto-sync

This commit is contained in:
rusEfi 2014-12-27 21:05:10 -06:00
parent ef61491a58
commit 40c6109873
6 changed files with 23 additions and 24 deletions

View File

@ -458,6 +458,7 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_
boardConfiguration->logicAnalyzerPins[2] = GPIO_UNASSIGNED;
boardConfiguration->logicAnalyzerPins[3] = GPIO_UNASSIGNED;
engineConfiguration->vehicleSpeedSensorInputPin = GPIO_UNASSIGNED;
engineConfiguration->vehicleSpeedCoef = 100;
boardConfiguration->logicAnalyzerMode[0] = false;
boardConfiguration->logicAnalyzerMode[1] = false;

View File

@ -409,7 +409,12 @@ typedef struct {
brain_pin_e vehicleSpeedSensorInputPin;
int unused964;
/**
* This coefficient translates vehicle speed input frequency (in Hz) into vehicle speed
* (in km/h)
* offset 964
*/
float vehicleSpeedCoef;
// offset 968
can_nbc_e canNbcType;
// offset 972

View File

@ -114,10 +114,6 @@ static void setWaveModeSilent(int index, int mode) {
static void initWave(const char *name, int index) {
brain_pin_e brainPin = boardConfiguration->logicAnalyzerPins[index];
ioportid_t port = getHwPort(brainPin);
ioportmask_t pin = getHwPin(brainPin);
ICUDriver *driver = getInputCaptureDriver(brainPin);
bool mode = boardConfiguration->logicAnalyzerMode[index];
waveReaderCount++;
@ -131,7 +127,7 @@ static void initWave(const char *name, int index) {
registerCallback(&hw->periodListeners, (IntListener) waIcuPeriodCallback, (void*) reader);
initWaveAnalyzerDriver(hw, driver, port, pin);
initWaveAnalyzerDriver(hw, brainPin);
print("wave%d input on %s%d\r\n", index, portname(reader->hw.port), reader->hw.pin);
setWaveReaderMode(hw, mode);

View File

@ -25,14 +25,6 @@ extern engine_configuration_s *engineConfiguration;
extern engine_configuration2_s *engineConfiguration2;
extern board_configuration_s *boardConfiguration;
static inline ICUDriver *getPrimaryInputCaptureDriver(void) {
return getInputCaptureDriver(boardConfiguration->triggerInputPins[0]);
}
static inline ICUDriver *getSecondaryInputCaptureDriver(void) {
return getInputCaptureDriver(boardConfiguration->triggerInputPins[1]);
}
/**
* that's hardware timer input capture IRQ entry point
* 'width' events happens before the 'period' event
@ -40,7 +32,7 @@ static inline ICUDriver *getSecondaryInputCaptureDriver(void) {
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 == getPrimaryInputCaptureDriver();
int isPrimary = icup == primaryCrankInput.driver;
if (!isPrimary && !engineConfiguration->needSecondTriggerInput) {
return;
}
@ -52,7 +44,7 @@ static void shaft_icu_width_callback(ICUDriver *icup) {
}
static void shaft_icu_period_callback(ICUDriver *icup) {
int isPrimary = icup == getPrimaryInputCaptureDriver();
int isPrimary = icup == primaryCrankInput.driver;
if (!isPrimary && !engineConfiguration->needSecondTriggerInput) {
return;
}
@ -77,14 +69,14 @@ void initShaftPositionInputCapture(void) {
// todo: extract method!
// initialize primary Input Capture Unit pin
initWaveAnalyzerDriver(&primaryCrankInput, driver, getHwPort(boardConfiguration->triggerInputPins[0]),
getHwPin(boardConfiguration->triggerInputPins[0]));
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;
print("initShaftPositionInputCapture 1 %s\r\n", hwPortname(boardConfiguration->triggerInputPins[0]));
// todo: reuse 'setWaveReaderMode' method here?
if (driver != NULL) {
icuStart(driver, &shaft_icucfg);
icuEnable(driver);
@ -92,8 +84,7 @@ void initShaftPositionInputCapture(void) {
driver = getInputCaptureDriver(boardConfiguration->triggerInputPins[1]);
// initialize secondary Input Capture Unit pin
initWaveAnalyzerDriver(&secondaryCrankInput, getSecondaryInputCaptureDriver(),
getHwPort(boardConfiguration->triggerInputPins[1]), getHwPin(boardConfiguration->triggerInputPins[1]));
initWaveAnalyzerDriver(&secondaryCrankInput, boardConfiguration->triggerInputPins[1]);
shaft_icucfg.channel = ICU_CHANNEL_1;
print("initShaftPositionInputCapture 2 %s\r\n", hwPortname(boardConfiguration->triggerInputPins[1]));
if (driver != NULL) {

View File

@ -139,7 +139,12 @@ ICUDriver * getInputCaptureDriver(brain_pin_e hwPin) {
return (ICUDriver *) NULL;
}
void initWaveAnalyzerDriver(WaveReaderHw *hw, ICUDriver *driver, ioportid_t port, ioportmask_t pin) {
void initWaveAnalyzerDriver(WaveReaderHw *hw, 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;
@ -170,7 +175,7 @@ void setWaveReaderMode(WaveReaderHw *hw, bool mode) {
icuStart(driver, &wave_icucfg);
icuEnable(driver);
}
hw->started = TRUE;
hw->started = true;
}
#endif

View File

@ -21,6 +21,8 @@ typedef struct {
int activeMode; // 0 for ICU_INPUT_ACTIVE_LOW, 1 for ICU_INPUT_ACTIVE_HIGH
volatile int started;
// todo: make this a template & reduce number of listeners?
// todo: would one listener be enough?
IntListenerArray widthListeners;
IntListenerArray periodListeners;
} WaveReaderHw;
@ -30,8 +32,7 @@ extern "C"
{
#endif /* __cplusplus */
void initWaveAnalyzerDriver(WaveReaderHw *hw, ICUDriver *driver,
ioportid_t port, ioportmask_t pin);
void initWaveAnalyzerDriver(WaveReaderHw *hw, brain_pin_e brainPin);
void setWaveReaderMode(WaveReaderHw *hw, bool mode);
ICUDriver * getInputCaptureDriver(brain_pin_e hwPin);