auto-sync

This commit is contained in:
rusEfi 2015-09-13 10:01:39 -04:00
parent e0fb25e958
commit c9852aa7b5
8 changed files with 43 additions and 23 deletions

View File

@ -29,7 +29,7 @@
#include "engine_math.h" #include "engine_math.h"
#include "speed_density.h" #include "speed_density.h"
#include "advance_map.h" #include "advance_map.h"
#if EFI_PROD_CODE #if EFI_PROD_CODE || defined(__DOXYGEN__)
#include "electronic_throttle.h" #include "electronic_throttle.h"
#include "alternatorController.h" #include "alternatorController.h"
#endif #endif
@ -66,7 +66,7 @@
EXTERN_ENGINE; EXTERN_ENGINE;
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
#include "tunerstudio.h" #include "tunerstudio.h"
#endif #endif
@ -177,7 +177,7 @@ void prepareVoidConfiguration(engine_configuration_s *activeConfiguration) {
boardConfiguration->acRelayPin = GPIO_UNASSIGNED; boardConfiguration->acRelayPin = GPIO_UNASSIGNED;
boardConfiguration->acRelayPinMode = OM_DEFAULT; boardConfiguration->acRelayPinMode = OM_DEFAULT;
#if EFI_PROD_CODE #if EFI_PROD_CODE || defined(__DOXYGEN__)
setDefaultAlternatorParameters(); setDefaultAlternatorParameters();
setDefaultEtbParameters(); setDefaultEtbParameters();
#endif #endif
@ -228,7 +228,7 @@ void prepareVoidConfiguration(engine_configuration_s *activeConfiguration) {
* and the settings saves in flash memory. * and the settings saves in flash memory.
*/ */
void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) { void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) {
#if ! EFI_UNIT_TEST #if (! EFI_UNIT_TEST) || defined(__DOXYGEN__)
memset(&persistentState.persistentConfiguration, 0, sizeof(persistentState.persistentConfiguration)); memset(&persistentState.persistentConfiguration, 0, sizeof(persistentState.persistentConfiguration));
#endif #endif
prepareVoidConfiguration(engineConfiguration); prepareVoidConfiguration(engineConfiguration);
@ -472,7 +472,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_F) {
engineConfiguration->idleStepperReactionTime = 10; engineConfiguration->idleStepperReactionTime = 10;
engineConfiguration->idleStepperTotalSteps = 150; engineConfiguration->idleStepperTotalSteps = 150;
#if EFI_PROD_CODE #if EFI_PROD_CODE || defined(__DOXYGEN__)
engineConfiguration->engineChartSize = 300; engineConfiguration->engineChartSize = 300;
#else #else
// need more events for automated test // need more events for automated test
@ -618,7 +618,7 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN
* Let's apply global defaults first * Let's apply global defaults first
*/ */
setDefaultConfiguration(PASS_ENGINE_PARAMETER_F); setDefaultConfiguration(PASS_ENGINE_PARAMETER_F);
#if EFI_SIMULATOR #if EFI_SIMULATOR || defined(__DOXYGEN__)
engineConfiguration->directSelfStimulation = true; engineConfiguration->directSelfStimulation = true;
#endif /* */ #endif /* */
engineConfiguration->engineType = engineType; engineConfiguration->engineType = engineType;
@ -758,13 +758,14 @@ engine_configuration2_s::engine_configuration2_s() {
} }
void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S) { void applyNonPersistentConfiguration(Logging * logger DECLARE_ENGINE_PARAMETER_S) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "apply c");
scheduleMsg(logger, "applyNonPersistentConfiguration()");
#endif
// todo: this would require 'initThermistors() to re-establish a reference, todo: fix // todo: this would require 'initThermistors() to re-establish a reference, todo: fix
// memset(engineConfiguration2, 0, sizeof(engine_configuration2_s)); // memset(engineConfiguration2, 0, sizeof(engine_configuration2_s));
#if EFI_PROD_CODE #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
scheduleMsg(logger, "applyNonPersistentConfiguration()");
#endif
#if EFI_ENGINE_CONTROL
engine->triggerShape.initializeTriggerShape(logger PASS_ENGINE_PARAMETER); engine->triggerShape.initializeTriggerShape(logger PASS_ENGINE_PARAMETER);
#endif #endif
if (engine->triggerShape.getSize() == 0) { if (engine->triggerShape.getSize() == 0) {

View File

@ -106,6 +106,7 @@ static bool hasValidEngineType(engine_configuration_s *engineConfiguration) {
} }
void readFromFlash(void) { void readFromFlash(void) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "read f");
printMsg(logger, "readFromFlash()"); printMsg(logger, "readFromFlash()");
flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE);

View File

@ -22,6 +22,7 @@ SimplePwm::SimplePwm() {
sr[0] = waveInstance; sr[0] = waveInstance;
init(_switchTimes, sr); init(_switchTimes, sr);
} }
void PwmConfig::baseConstructor() { void PwmConfig::baseConstructor() {
memset(&scheduling, 0, sizeof(scheduling)); memset(&scheduling, 0, sizeof(scheduling));
memset(&safe, 0, sizeof(safe)); memset(&safe, 0, sizeof(safe));

View File

@ -164,7 +164,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
bool_t isPrimary = triggerWheel == T_PRIMARY; bool_t isPrimary = triggerWheel == T_PRIMARY;
if (isLessImportant(signal)) { if (isLessImportant(signal)) {
#if EFI_UNIT_TEST #if EFI_UNIT_TEST || defined(__DOXYGEN__)
if (printTriggerDebug) { if (printTriggerDebug) {
printf("%s isLessImportant %s\r\n", printf("%s isLessImportant %s\r\n",
getTrigger_type_e(engineConfiguration->trigger.type), getTrigger_type_e(engineConfiguration->trigger.type),
@ -189,7 +189,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
isFirstEvent = false; isFirstEvent = false;
// todo: skip a number of signal from the beginning // todo: skip a number of signal from the beginning
#if EFI_PROD_CODE #if EFI_PROD_CODE || defined(__DOXYGEN__)
// scheduleMsg(&logger, "from %f to %f %d %d", triggerConfig->syncRatioFrom, triggerConfig->syncRatioTo, currentDuration, shaftPositionState->toothed_previous_duration); // scheduleMsg(&logger, "from %f to %f %d %d", triggerConfig->syncRatioFrom, triggerConfig->syncRatioTo, currentDuration, shaftPositionState->toothed_previous_duration);
// scheduleMsg(&logger, "ratio %f", 1.0 * currentDuration/ shaftPositionState->toothed_previous_duration); // scheduleMsg(&logger, "ratio %f", 1.0 * currentDuration/ shaftPositionState->toothed_previous_duration);
#else #else
@ -235,7 +235,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
} }
#if EFI_UNIT_TEST #if EFI_UNIT_TEST || defined(__DOXYGEN__)
if (printTriggerDebug) { if (printTriggerDebug) {
printf("%s isSynchronizationPoint=%d index=%d %s\r\n", printf("%s isSynchronizationPoint=%d index=%d %s\r\n",
getTrigger_type_e(engineConfiguration->trigger.type), getTrigger_type_e(engineConfiguration->trigger.type),
@ -258,7 +258,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
lastDecodingErrorTime = getTimeNowNt(); lastDecodingErrorTime = getTimeNowNt();
totalTriggerErrorCounter++; totalTriggerErrorCounter++;
if (engineConfiguration->isPrintTriggerSynchDetails) { if (engineConfiguration->isPrintTriggerSynchDetails) {
#if EFI_PROD_CODE #if EFI_PROD_CODE || defined(__DOXYGEN__)
scheduleMsg(logger, "error: synchronizationPoint @ index %d expected %d/%d/%d got %d/%d/%d", currentCycle.current_index, scheduleMsg(logger, "error: synchronizationPoint @ index %d expected %d/%d/%d got %d/%d/%d", currentCycle.current_index,
TRIGGER_SHAPE(expectedEventCount[0]), TRIGGER_SHAPE(expectedEventCount[1]), TRIGGER_SHAPE(expectedEventCount[0]), TRIGGER_SHAPE(expectedEventCount[1]),
TRIGGER_SHAPE(expectedEventCount[2]), currentCycle.eventCount[0], currentCycle.eventCount[1], currentCycle.eventCount[2]); TRIGGER_SHAPE(expectedEventCount[2]), currentCycle.eventCount[0], currentCycle.eventCount[1], currentCycle.eventCount[2]);
@ -365,11 +365,12 @@ static void configureOnePlus60_2(TriggerShape *s, operation_mode_e operationMode
* External logger is needed because at this point our logger is not yet initialized * External logger is needed because at this point our logger is not yet initialized
*/ */
void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_S) { void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_S) {
TriggerShape *triggerShape = this; #if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "init t");
#if EFI_PROD_CODE
scheduleMsg(logger, "initializeTriggerShape()"); scheduleMsg(logger, "initializeTriggerShape()");
#endif #endif
TriggerShape *triggerShape = this;
const trigger_config_s *triggerConfig = &engineConfiguration->trigger; const trigger_config_s *triggerConfig = &engineConfiguration->trigger;
clear(); clear();
@ -543,6 +544,9 @@ static uint32_t doFindTrigger(TriggerStimulatorHelper *helper, TriggerShape * sh
return EFI_ERROR_CODE; return EFI_ERROR_CODE;
} }
// todo: reuse trigger central state here to reduce RAM usage?
static TriggerState state;
/** /**
* Trigger shape is defined in a way which is convenient for trigger shape definition * Trigger shape is defined in a way which is convenient for trigger shape definition
* On the other hand, trigger decoder indexing begins from synchronization event. * On the other hand, trigger decoder indexing begins from synchronization event.
@ -551,11 +555,13 @@ static uint32_t doFindTrigger(TriggerStimulatorHelper *helper, TriggerShape * sh
*/ */
uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const*triggerConfig uint32_t findTriggerZeroEventIndex(TriggerShape * shape, trigger_config_s const*triggerConfig
DECLARE_ENGINE_PARAMETER_S) { DECLARE_ENGINE_PARAMETER_S) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
// todo: should this variable be declared 'static' to reduce stack usage? efiAssert(getRemainingStack(chThdSelf()) > 128, "findPos", -1);
TriggerState state; #endif
errorDetection.clear(); errorDetection.clear();
state.reset();
// todo: should this variable be declared 'static' to reduce stack usage? // todo: should this variable be declared 'static' to reduce stack usage?
TriggerStimulatorHelper helper; TriggerStimulatorHelper helper;
@ -594,7 +600,7 @@ void initTriggerDecoderLogger(Logging *sharedLogger) {
} }
void initTriggerDecoder(void) { void initTriggerDecoder(void) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
outputPinRegisterExt2("trg_err", &triggerDecoderErrorPin, boardConfiguration->triggerErrorPin, &boardConfiguration->triggerErrorPinMode); outputPinRegisterExt2("trg_err", &triggerDecoderErrorPin, boardConfiguration->triggerErrorPin, &boardConfiguration->triggerErrorPinMode);
#endif #endif
} }

View File

@ -88,6 +88,7 @@ public:
uint32_t orderingErrorCounter; uint32_t orderingErrorCounter;
uint32_t runningOrderingErrorCounter; uint32_t runningOrderingErrorCounter;
void reset();
void resetRunningCounters(); void resetRunningCounters();
uint32_t runningRevolutionCounter; uint32_t runningRevolutionCounter;

View File

@ -67,6 +67,9 @@ int TriggerShape::getTriggerShapeSynchPointIndex() {
} }
void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) { void TriggerShape::calculateTriggerSynchPoint(DECLARE_ENGINE_PARAMETER_F) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "calc s");
#endif
trigger_config_s const*triggerConfig = &engineConfiguration->trigger; trigger_config_s const*triggerConfig = &engineConfiguration->trigger;
triggerShapeSynchPointIndex = findTriggerZeroEventIndex(this, triggerConfig PASS_ENGINE_PARAMETER); triggerShapeSynchPointIndex = findTriggerZeroEventIndex(this, triggerConfig PASS_ENGINE_PARAMETER);
@ -151,6 +154,10 @@ void multi_wave_s::setSwitchTime(int index, float value) {
} }
TriggerState::TriggerState() { TriggerState::TriggerState() {
reset();
}
void TriggerState::reset() {
cycleCallback = NULL; cycleCallback = NULL;
shaft_is_synchronized = false; shaft_is_synchronized = false;
toothed_previous_time = 0; toothed_previous_time = 0;

View File

@ -212,6 +212,7 @@ void applyNewHardwareSettings(void) {
} }
void initHardware(Logging *l) { void initHardware(Logging *l) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "init h");
sharedLogger = l; sharedLogger = l;
engine_configuration_s *engineConfiguration = engine->engineConfiguration; engine_configuration_s *engineConfiguration = engine->engineConfiguration;
efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration"); efiAssertVoid(engineConfiguration!=NULL, "engineConfiguration");

View File

@ -164,6 +164,8 @@ void applyNewConfiguration(void) {
} }
void runRusEfi(void) { void runRusEfi(void) {
efiAssertVoid(getRemainingStack(chThdSelf()) > 512, "init s");
msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0); msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0);
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
@ -203,7 +205,7 @@ void runRusEfi(void) {
#if EFI_PERF_METRICS || defined(__DOXYGEN__) #if EFI_PERF_METRICS || defined(__DOXYGEN__)
initTimePerfActions(&sharedLogger); initTimePerfActions(&sharedLogger);
#endif #endif
#if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__) #if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__)
initEngineEmulator(&sharedLogger, engine); initEngineEmulator(&sharedLogger, engine);
#endif #endif
@ -273,5 +275,5 @@ int getRusEfiVersion(void) {
return 123; // this is here to make the compiler happy about the unused array return 123; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] * 0 != 0) if (UNUSED_CCM_SIZE[0] * 0 != 0)
return 3211; // this is here to make the compiler happy about the unused array return 3211; // this is here to make the compiler happy about the unused array
return 20150912; return 20150913;
} }