auto-sync

This commit is contained in:
rusEfi 2014-09-25 23:05:11 -05:00
parent 5c3b2df8d0
commit 3e37f1103b
10 changed files with 132 additions and 74 deletions

View File

@ -403,6 +403,9 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType, engine_co
* Let's apply global defaults first
*/
setDefaultConfiguration(engineConfiguration, boardConfiguration);
#if EFI_SIMULATOR
engineConfiguration->directSelfStimulation = true;
#endif /* */
engineConfiguration->engineType = engineType;
engineConfiguration->headerMagicValue = HEADER_MAGIC_NUMBER;
/**

View File

@ -9,6 +9,40 @@
#include "engine_configuration.h"
#include "LocalVersionHolder.h"
#include "ec2.h"
#include "trigger_central.h"
#if EFI_PROD_CODE
#include "pwm_generator.h"
#endif
TriggerEmulatorHelper::TriggerEmulatorHelper() {
primaryWheelState = false;
secondaryWheelState = false;
thirdWheelState = false;
}
void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIndex) {
int newPrimaryWheelState = state->multiWave.waves[0].pinStates[stateIndex];
int newSecondaryWheelState = state->multiWave.waves[1].pinStates[stateIndex];
int new3rdWheelState = state->multiWave.waves[2].pinStates[stateIndex];
if (primaryWheelState != newPrimaryWheelState) {
primaryWheelState = newPrimaryWheelState;
hwHandleShaftSignal(primaryWheelState ? SHAFT_PRIMARY_UP : SHAFT_PRIMARY_DOWN);
}
if (secondaryWheelState != newSecondaryWheelState) {
secondaryWheelState = newSecondaryWheelState;
hwHandleShaftSignal(secondaryWheelState ? SHAFT_SECONDARY_UP : SHAFT_SECONDARY_DOWN);
}
if (thirdWheelState != new3rdWheelState) {
thirdWheelState = new3rdWheelState;
hwHandleShaftSignal(thirdWheelState ? SHAFT_3RD_UP : SHAFT_3RD_DOWN);
}
// print("hello %d\r\n", chTimeNow());
}
extern engine_configuration_s *engineConfiguration;
extern engine_configuration2_s *engineConfiguration2;
@ -20,13 +54,19 @@ extern engine_configuration2_s *engineConfiguration2;
static int pinStates1[PWM_PHASE_MAX_COUNT];
static int pinStates2[PWM_PHASE_MAX_COUNT];
static int pinStates3[PWM_PHASE_MAX_COUNT];
static single_wave_s waves[PWM_PHASE_MAX_WAVE_PER_PWM] = {single_wave_s(pinStates1), single_wave_s(pinStates2), single_wave_s(pinStates3)};
static single_wave_s sr[PWM_PHASE_MAX_WAVE_PER_PWM] = {waves[0], waves[1], waves[2]};
static single_wave_s waves[PWM_PHASE_MAX_WAVE_PER_PWM] = { single_wave_s(pinStates1), single_wave_s(pinStates2),
single_wave_s(pinStates3) };
static single_wave_s sr[PWM_PHASE_MAX_WAVE_PER_PWM] = { waves[0], waves[1], waves[2] };
static float swtchTms[PWM_PHASE_MAX_COUNT];
PwmConfig triggerSignal(swtchTms, sr);
#define DO_NOT_STOP 999999999
static int stopEmulationAtIndex = DO_NOT_STOP;
static bool isEmulating = true;
static Logging logger;
static LocalVersionHolder localVersion;
@ -47,28 +87,63 @@ void setTriggerEmulatorRPM(int rpm) {
static void updateTriggerShapeIfNeeded(PwmConfig *state) {
if (localVersion.isOld()) {
scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(), getGlobalConfigurationVersion(), currentTimeMillis());
scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(),
getGlobalConfigurationVersion(), currentTimeMillis());
applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2);
trigger_shape_s *s = &engineConfiguration2->triggerShape;
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = {s->wave.waves[0].pinStates, s->wave.waves[1].pinStates, s->wave.waves[2].pinStates};
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates,
s->wave.waves[2].pinStates };
copyPwmParameters(state, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates);
state->safe.periodNt = -1; // this would cause loop re-initialization
}
}
void initTriggerEmulatorLogic(pwm_gen_callback *stateChangeCallback) {
initLogging(&logger, "position sensor(s) emulator");
static TriggerEmulatorHelper helper;
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
static void emulatorApplyPinState(PwmConfig *state, int stateIndex) {
if (stopEmulationAtIndex == stateIndex) {
isEmulating = false;
}
if (!isEmulating) {
return;
}
#if EFI_PROD_CODE
applyPinState(state, stateIndex);
#endif /* EFI_PROD_CODE */
if (engineConfiguration->directSelfStimulation) {
/**
* this callback would invoke the input signal handlers directly
*/
helper.handleEmulatorCallback(state, stateIndex);
}
}
#endif /* EFI_EMULATE_POSITION_SENSORS */
static void setEmulatorAtIndex(int index) {
stopEmulationAtIndex = index;
}
static void resumeStimulator(void) {
isEmulating = true;
stopEmulationAtIndex = DO_NOT_STOP;
}
void initTriggerEmulatorLogic(void) {
initLogging(&logger, "position sensor(s) emulator");
trigger_shape_s *s = &engineConfiguration2->triggerShape;
setTriggerEmulatorRPM(engineConfiguration->bc.triggerSimulatorFrequency);
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates, s->wave.waves[2].pinStates};
weComplexInit("position sensor", &triggerSignal, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates,
updateTriggerShapeIfNeeded, stateChangeCallback);
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates,
s->wave.waves[2].pinStates };
weComplexInit("position sensor", &triggerSignal, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM,
pinStates, updateTriggerShapeIfNeeded, emulatorApplyPinState);
addConsoleActionI("rpm", &setTriggerEmulatorRPM);
addConsoleActionI("stop_stimulator_at_index", setEmulatorAtIndex);
addConsoleAction("resume_stimulator", resumeStimulator);
}

View File

@ -10,6 +10,16 @@
#include "pwm_generator_logic.h"
void initTriggerEmulatorLogic(pwm_gen_callback *callback);
class TriggerEmulatorHelper {
public:
bool primaryWheelState;
bool secondaryWheelState;
bool thirdWheelState;
TriggerEmulatorHelper();
void handleEmulatorCallback(PwmConfig *state, int stateIndex);
};
void initTriggerEmulatorLogic(void);
#endif /* TRIGGER_EMULATOR_ALGO_H_ */

View File

@ -27,47 +27,6 @@ extern board_configuration_s *boardConfiguration;
extern PwmConfig triggerSignal;
TriggerEmulatorHelper::TriggerEmulatorHelper() {
primaryWheelState = false;
secondaryWheelState = false;
thirdWheelState = false;
}
void TriggerEmulatorHelper::handleEmulatorCallback(PwmConfig *state, int stateIndex) {
int newPrimaryWheelState = state->multiWave.waves[0].pinStates[stateIndex];
int newSecondaryWheelState = state->multiWave.waves[1].pinStates[stateIndex];
int new3rdWheelState = state->multiWave.waves[2].pinStates[stateIndex];
if (primaryWheelState != newPrimaryWheelState) {
primaryWheelState = newPrimaryWheelState;
hwHandleShaftSignal(primaryWheelState ? SHAFT_PRIMARY_UP : SHAFT_PRIMARY_DOWN);
}
if (secondaryWheelState != newSecondaryWheelState) {
secondaryWheelState = newSecondaryWheelState;
hwHandleShaftSignal(secondaryWheelState ? SHAFT_SECONDARY_UP : SHAFT_SECONDARY_DOWN);
}
if (thirdWheelState != new3rdWheelState) {
thirdWheelState = new3rdWheelState;
hwHandleShaftSignal(thirdWheelState ? SHAFT_3RD_UP : SHAFT_3RD_DOWN);
}
// print("hello %d\r\n", chTimeNow());
}
static TriggerEmulatorHelper helper;
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
static void emulatorApplyPinState(PwmConfig *state, int stateIndex) {
applyPinState(state, stateIndex);
if (engineConfiguration->directSelfStimulation) {
helper.handleEmulatorCallback(state, stateIndex);
}
}
#endif /* EFI_EMULATE_POSITION_SENSORS */
void initTriggerEmulator(void) {
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
print("Emulating %s\r\n", getConfigurationName(engineConfiguration->engineType));
@ -76,6 +35,7 @@ void initTriggerEmulator(void) {
triggerSignal.outputPins[1] = TRIGGER_EMULATOR_SECONDARY;
triggerSignal.outputPins[2] = TRIGGER_EMULATOR_3RD;
#if EFI_PROD_CODE
// todo: refactor, make this a loop
outputPinRegisterExt2("distributor ch1", triggerSignal.outputPins[0], boardConfiguration->triggerSimulatorPins[0],
&boardConfiguration->triggerSimulatorPinModes[0]);
@ -85,9 +45,9 @@ void initTriggerEmulator(void) {
outputPinRegisterExt2("distributor ch3", triggerSignal.outputPins[2], boardConfiguration->triggerSimulatorPins[2],
&boardConfiguration->triggerSimulatorPinModes[2]);
#endif /* EFI_PROD_CODE */
initTriggerEmulatorLogic(emulatorApplyPinState);
initTriggerEmulatorLogic();
#else
print("No position sensor(s) emulation\r\n");
#endif /* EFI_EMULATE_POSITION_SENSORS */

View File

@ -15,19 +15,6 @@
#include "engine_configuration.h"
#include "pwm_generator_logic.h"
class TriggerEmulatorHelper {
public:
bool primaryWheelState;
bool secondaryWheelState;
bool thirdWheelState;
TriggerEmulatorHelper();
void handleEmulatorCallback(PwmConfig *state, int stateIndex);
};
void initTriggerEmulator(void);
void setTriggerEmulatorRPM(int value);

View File

@ -131,6 +131,7 @@ CPPSRC = $(UTILSRC_CPP) \
$(CONTROLLERS_MATH_SRC_CPP) \
$(ENGINES_SRC_CPP) \
$(PROJECT_DIR)/simulator/rusEfiFunctionalTest.cpp \
$(PROJECT_DIR)/simulator/framework.cpp \
$(PROJECT_DIR)/emulation/trigger_emulator.cpp \
$(TEST_SRC_CPP)
# C sources to be compiled in ARM mode regardless of the global setting.

View File

@ -16,6 +16,11 @@
#define EFI_SUPPORT_NISSAN_PRIMERA TRUE
#define EFI_SUPPORT_1995_FORD_INLINE_6 TRUE
/**
* simulator works via self-stimulation which works via trigger emulation
*/
#define EFI_EMULATE_POSITION_SENSORS TRUE
#define EFI_SIGNAL_EXECUTOR_SLEEP TRUE
#define EFI_INTERNAL_ADC FALSE

View File

@ -0,0 +1,9 @@
/**
* @file framework.cpp
*
* @date Sep 25, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/

View File

@ -0,0 +1,14 @@
/**
* @file framework.h
*
* @date Sep 25, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#ifndef FRAMEWORK_H_
#define FRAMEWORK_H_
#endif /* FRAMEWORK_H_ */

View File

@ -68,12 +68,6 @@ float getMap(void) {
return getRawMap();
}
static TriggerEmulatorHelper helper;
static void triggerEmulatorCallback(PwmConfig *state, int stateIndex) {
helper.handleEmulatorCallback(state, stateIndex);
}
void rusEfiFunctionalTest(void) {
initializeConsole();
@ -93,7 +87,7 @@ void rusEfiFunctionalTest(void) {
initAnalogChart();
initTriggerEmulatorLogic(triggerEmulatorCallback);
initTriggerEmulator();
initMainEventListener(&engine, engineConfiguration2);