auto-sync
This commit is contained in:
parent
693a224c32
commit
b850039a96
|
@ -403,6 +403,9 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType, engine_co
|
||||||
* Let's apply global defaults first
|
* Let's apply global defaults first
|
||||||
*/
|
*/
|
||||||
setDefaultConfiguration(engineConfiguration, boardConfiguration);
|
setDefaultConfiguration(engineConfiguration, boardConfiguration);
|
||||||
|
#if EFI_SIMULATOR
|
||||||
|
engineConfiguration->directSelfStimulation = true;
|
||||||
|
#endif /* */
|
||||||
engineConfiguration->engineType = engineType;
|
engineConfiguration->engineType = engineType;
|
||||||
engineConfiguration->headerMagicValue = HEADER_MAGIC_NUMBER;
|
engineConfiguration->headerMagicValue = HEADER_MAGIC_NUMBER;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,40 @@
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "LocalVersionHolder.h"
|
#include "LocalVersionHolder.h"
|
||||||
#include "ec2.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_configuration_s *engineConfiguration;
|
||||||
extern engine_configuration2_s *engineConfiguration2;
|
extern engine_configuration2_s *engineConfiguration2;
|
||||||
|
@ -20,13 +54,19 @@ extern engine_configuration2_s *engineConfiguration2;
|
||||||
static int pinStates1[PWM_PHASE_MAX_COUNT];
|
static int pinStates1[PWM_PHASE_MAX_COUNT];
|
||||||
static int pinStates2[PWM_PHASE_MAX_COUNT];
|
static int pinStates2[PWM_PHASE_MAX_COUNT];
|
||||||
static int pinStates3[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 waves[PWM_PHASE_MAX_WAVE_PER_PWM] = { single_wave_s(pinStates1), single_wave_s(pinStates2),
|
||||||
static single_wave_s sr[PWM_PHASE_MAX_WAVE_PER_PWM] = {waves[0], waves[1], waves[2]};
|
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];
|
static float swtchTms[PWM_PHASE_MAX_COUNT];
|
||||||
|
|
||||||
PwmConfig triggerSignal(swtchTms, sr);
|
PwmConfig triggerSignal(swtchTms, sr);
|
||||||
|
|
||||||
|
#define DO_NOT_STOP 999999999
|
||||||
|
|
||||||
|
static int stopEmulationAtIndex = DO_NOT_STOP;
|
||||||
|
static bool isEmulating = true;
|
||||||
|
|
||||||
static Logging logger;
|
static Logging logger;
|
||||||
static LocalVersionHolder localVersion;
|
static LocalVersionHolder localVersion;
|
||||||
|
|
||||||
|
@ -47,28 +87,63 @@ void setTriggerEmulatorRPM(int rpm) {
|
||||||
|
|
||||||
static void updateTriggerShapeIfNeeded(PwmConfig *state) {
|
static void updateTriggerShapeIfNeeded(PwmConfig *state) {
|
||||||
if (localVersion.isOld()) {
|
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);
|
applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2);
|
||||||
|
|
||||||
trigger_shape_s *s = &engineConfiguration2->triggerShape;
|
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);
|
copyPwmParameters(state, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates);
|
||||||
state->safe.periodNt = -1; // this would cause loop re-initialization
|
state->safe.periodNt = -1; // this would cause loop re-initialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTriggerEmulatorLogic(pwm_gen_callback *stateChangeCallback) {
|
static TriggerEmulatorHelper helper;
|
||||||
initLogging(&logger, "position sensor(s) emulator");
|
|
||||||
|
|
||||||
|
#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;
|
trigger_shape_s *s = &engineConfiguration2->triggerShape;
|
||||||
setTriggerEmulatorRPM(engineConfiguration->bc.triggerSimulatorFrequency);
|
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};
|
int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates,
|
||||||
weComplexInit("position sensor", &triggerSignal, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates,
|
s->wave.waves[2].pinStates };
|
||||||
updateTriggerShapeIfNeeded, stateChangeCallback);
|
weComplexInit("position sensor", &triggerSignal, s->getSize(), s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM,
|
||||||
|
pinStates, updateTriggerShapeIfNeeded, emulatorApplyPinState);
|
||||||
|
|
||||||
addConsoleActionI("rpm", &setTriggerEmulatorRPM);
|
addConsoleActionI("rpm", &setTriggerEmulatorRPM);
|
||||||
|
addConsoleActionI("stop_stimulator_at_index", setEmulatorAtIndex);
|
||||||
|
addConsoleAction("resume_stimulator", resumeStimulator);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,16 @@
|
||||||
|
|
||||||
#include "pwm_generator_logic.h"
|
#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_ */
|
#endif /* TRIGGER_EMULATOR_ALGO_H_ */
|
||||||
|
|
|
@ -27,47 +27,6 @@ extern board_configuration_s *boardConfiguration;
|
||||||
|
|
||||||
extern PwmConfig triggerSignal;
|
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) {
|
void initTriggerEmulator(void) {
|
||||||
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
|
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
|
||||||
print("Emulating %s\r\n", getConfigurationName(engineConfiguration->engineType));
|
print("Emulating %s\r\n", getConfigurationName(engineConfiguration->engineType));
|
||||||
|
@ -76,6 +35,7 @@ void initTriggerEmulator(void) {
|
||||||
triggerSignal.outputPins[1] = TRIGGER_EMULATOR_SECONDARY;
|
triggerSignal.outputPins[1] = TRIGGER_EMULATOR_SECONDARY;
|
||||||
triggerSignal.outputPins[2] = TRIGGER_EMULATOR_3RD;
|
triggerSignal.outputPins[2] = TRIGGER_EMULATOR_3RD;
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE
|
||||||
// todo: refactor, make this a loop
|
// todo: refactor, make this a loop
|
||||||
outputPinRegisterExt2("distributor ch1", triggerSignal.outputPins[0], boardConfiguration->triggerSimulatorPins[0],
|
outputPinRegisterExt2("distributor ch1", triggerSignal.outputPins[0], boardConfiguration->triggerSimulatorPins[0],
|
||||||
&boardConfiguration->triggerSimulatorPinModes[0]);
|
&boardConfiguration->triggerSimulatorPinModes[0]);
|
||||||
|
@ -85,9 +45,9 @@ void initTriggerEmulator(void) {
|
||||||
|
|
||||||
outputPinRegisterExt2("distributor ch3", triggerSignal.outputPins[2], boardConfiguration->triggerSimulatorPins[2],
|
outputPinRegisterExt2("distributor ch3", triggerSignal.outputPins[2], boardConfiguration->triggerSimulatorPins[2],
|
||||||
&boardConfiguration->triggerSimulatorPinModes[2]);
|
&boardConfiguration->triggerSimulatorPinModes[2]);
|
||||||
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
|
initTriggerEmulatorLogic();
|
||||||
initTriggerEmulatorLogic(emulatorApplyPinState);
|
|
||||||
#else
|
#else
|
||||||
print("No position sensor(s) emulation\r\n");
|
print("No position sensor(s) emulation\r\n");
|
||||||
#endif /* EFI_EMULATE_POSITION_SENSORS */
|
#endif /* EFI_EMULATE_POSITION_SENSORS */
|
||||||
|
|
|
@ -15,19 +15,6 @@
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "pwm_generator_logic.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 initTriggerEmulator(void);
|
||||||
void setTriggerEmulatorRPM(int value);
|
void setTriggerEmulatorRPM(int value);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue