This commit is contained in:
rusefi 2018-12-25 21:18:14 -05:00
parent 2585e4cad7
commit 72f87ce425
4 changed files with 39 additions and 28 deletions

View File

@ -30,6 +30,8 @@
#define isRunningBenchTest() true
#endif /* EFI_PROD_CODE */
static TriggerState initState CCM_OPTIONAL;
static LoggingWithStorage logger("engine");
extern fuel_Map3D_t veMap;
@ -59,6 +61,40 @@ int MockAdcState::getMockAdcValue(int hwChannel) {
return fakeAdcValues[hwChannel];
}
void Engine::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if !EFI_UNIT_TEST
// we have a confusing threading model so some synchronization would not hurt
bool alreadyLocked = lockAnyContext();
#endif /* EFI_UNIT_TEST */
TRIGGER_SHAPE(initializeTriggerShape(logger, engineConfiguration->useOnlyRisingEdgeForTrigger PASS_ENGINE_PARAMETER_SUFFIX));
if (!TRIGGER_SHAPE(shapeDefinitionError)) {
/**
* this instance is used only to initialize 'this' TriggerShape instance
* #192 BUG real hardware trigger events could be coming even while we are initializing trigger
*/
initState.reset();
TRIGGER_SHAPE(calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX));
if (engine->triggerCentral.triggerShape.getSize() == 0) {
firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero");
}
engine->engineCycleEventCount = TRIGGER_SHAPE(getLength());
}
#if !EFI_UNIT_TEST
if (!alreadyLocked) {
unlockAnyContext();
}
#endif
if (!TRIGGER_SHAPE(shapeDefinitionError)) {
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
}
}
/**
* We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons.
* See also periodicFastCallback

View File

@ -379,6 +379,7 @@ public:
void periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void updateSlowSensors(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMETER_SUFFIX);
bool clutchUpState;
bool clutchDownState;

View File

@ -54,8 +54,6 @@
EXTERN_ENGINE
;
static TriggerState initState CCM_OPTIONAL;
static cyclic_buffer<int> errorDetection;
static bool isInitializingTrigger = false; // #286 miata NA config - sync error on startup
@ -476,10 +474,6 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
*/
void TriggerShape::initializeTriggerShape(Logging *logger, bool useOnlyRisingEdgeForTrigger DECLARE_ENGINE_PARAMETER_SUFFIX) {
const trigger_config_s *triggerConfig = &engineConfiguration->trigger;
#if !EFI_UNIT_TEST
// we have a confusing threading model so some synchronization would not hurt
bool alreadyLocked = lockAnyContext();
#endif /* EFI_UNIT_TEST */
#if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssertVoid(CUSTOM_ERR_6641, getRemainingStack(chThdGetSelfX()) > 256, "init t");
@ -671,32 +665,12 @@ void TriggerShape::initializeTriggerShape(Logging *logger, bool useOnlyRisingEdg
warning(CUSTOM_ERR_NO_SHAPE, "initializeTriggerShape() not implemented: %d", triggerConfig->type);
}
calculateExpectedEventCounts(useOnlyRisingEdgeForTrigger);
version++;
if (!shapeDefinitionError) {
wave.checkSwitchTimes(getSize());
/**
* this instance is used only to initialize 'this' TriggerShape instance
* #192 BUG real hardware trigger events could be coming even while we are initializing trigger
*/
initState.reset();
calculateTriggerSynchPoint(&initState PASS_ENGINE_PARAMETER_SUFFIX);
if (engine->triggerCentral.triggerShape.getSize() == 0) {
firmwareError(CUSTOM_ERR_TRIGGER_ZERO, "triggerShape size is zero");
}
engine->engineCycleEventCount = getLength();
}
version++;
#if !EFI_UNIT_TEST
if (!alreadyLocked) {
unlockAnyContext();
}
#endif
if (!shapeDefinitionError) {
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
}
}
static void onFindIndexCallback(TriggerState *state) {

View File

@ -209,6 +209,7 @@ public:
int getTriggerShapeSynchPointIndex();
void prepareShape(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX);
private:
trigger_shape_helper h;
@ -247,7 +248,6 @@ private:
angle_t getAngle(int phaseIndex) const;
angle_t getCycleDuration() const;
void calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX);
};
void setToothedWheelConfiguration(TriggerShape *s, int total, int skipped, operation_mode_e operationMode);