part of 2217 which may fix it alone (#2220)

This commit is contained in:
Matthew Kennedy 2021-01-11 05:01:54 -08:00 committed by GitHub
parent 604b0cd527
commit a5266cd6ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 11 deletions

View File

@ -58,6 +58,9 @@ class FuelSchedule {
public:
FuelSchedule();
// Call this function if something happens that requires a rebuild, like a change to the trigger pattern
void invalidate();
// Call this every trigger tooth. It will schedule all required injector events.
void onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
@ -73,10 +76,7 @@ public:
* injection events, per cylinder
*/
InjectionEvent elements[MAX_INJECTION_OUTPUT_COUNT];
bool isReady;
private:
void clear();
bool isReady = false;
};
class AngleBasedEvent {

View File

@ -14,14 +14,13 @@ EXTERN_ENGINE;
#if EFI_ENGINE_CONTROL
FuelSchedule::FuelSchedule() {
clear();
for (int cylinderIndex = 0; cylinderIndex < MAX_INJECTION_OUTPUT_COUNT; cylinderIndex++) {
InjectionEvent *ev = &elements[cylinderIndex];
ev->ownIndex = cylinderIndex;
}
}
void FuelSchedule::clear() {
void FuelSchedule::invalidate() {
isReady = false;
}
@ -142,19 +141,26 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF
}
void FuelSchedule::addFuelEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
clear();
for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
InjectionEvent *ev = &elements[cylinderIndex];
ev->ownIndex = cylinderIndex; // todo: is this assignment needed here? we now initialize in constructor
bool result = addFuelEventsForCylinder(cylinderIndex PASS_ENGINE_PARAMETER_SUFFIX);
if (!result)
if (!result) {
invalidate();
return;
}
}
// We made it through all cylinders, mark the schedule as ready so it can be used
isReady = true;
}
void FuelSchedule::onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
// Wait for schedule to be built - this happens the first time we get RPM
if (!isReady) {
return;
}
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
elements[i].onTriggerTooth(toothIndex, rpm, nowNt);
}

View File

@ -412,6 +412,9 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
prepareIgnitionPinIndices(CONFIG(ignitionMode) PASS_ENGINE_PARAMETER_SUFFIX);
TRIGGER_WAVEFORM(prepareShape(&ENGINE(triggerCentral.triggerFormDetails) PASS_ENGINE_PARAMETER_SUFFIX));
// Fuel schedule may now be completely wrong, force a reset
ENGINE(injectionEvents).invalidate();
}
void setTimingRpmBin(float from, float to DECLARE_CONFIG_PARAMETER_SUFFIX) {

View File

@ -418,8 +418,13 @@ void findTriggerPosition(TriggerWaveform *triggerShape,
return;
}
position->triggerEventIndex = triggerEventIndex;
position->angleOffsetFromTriggerEvent = angle - triggerEventAngle;
{
// This must happen under lock so that the tooth and offset don't get partially read and mismatched
chibios_rt::CriticalSectionLocker csl;
position->triggerEventIndex = triggerEventIndex;
position->angleOffsetFromTriggerEvent = angle - triggerEventAngle;
}
}
void TriggerWaveform::prepareShape(TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX) {