part of 2217 which may fix it alone (#2220)
This commit is contained in:
parent
604b0cd527
commit
a5266cd6ef
|
@ -58,6 +58,9 @@ class FuelSchedule {
|
||||||
public:
|
public:
|
||||||
FuelSchedule();
|
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.
|
// 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);
|
void onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
|
@ -73,10 +76,7 @@ public:
|
||||||
* injection events, per cylinder
|
* injection events, per cylinder
|
||||||
*/
|
*/
|
||||||
InjectionEvent elements[MAX_INJECTION_OUTPUT_COUNT];
|
InjectionEvent elements[MAX_INJECTION_OUTPUT_COUNT];
|
||||||
bool isReady;
|
bool isReady = false;
|
||||||
|
|
||||||
private:
|
|
||||||
void clear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class AngleBasedEvent {
|
class AngleBasedEvent {
|
||||||
|
|
|
@ -14,14 +14,13 @@ EXTERN_ENGINE;
|
||||||
#if EFI_ENGINE_CONTROL
|
#if EFI_ENGINE_CONTROL
|
||||||
|
|
||||||
FuelSchedule::FuelSchedule() {
|
FuelSchedule::FuelSchedule() {
|
||||||
clear();
|
|
||||||
for (int cylinderIndex = 0; cylinderIndex < MAX_INJECTION_OUTPUT_COUNT; cylinderIndex++) {
|
for (int cylinderIndex = 0; cylinderIndex < MAX_INJECTION_OUTPUT_COUNT; cylinderIndex++) {
|
||||||
InjectionEvent *ev = &elements[cylinderIndex];
|
InjectionEvent *ev = &elements[cylinderIndex];
|
||||||
ev->ownIndex = cylinderIndex;
|
ev->ownIndex = cylinderIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuelSchedule::clear() {
|
void FuelSchedule::invalidate() {
|
||||||
isReady = false;
|
isReady = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,19 +141,26 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuelSchedule::addFuelEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void FuelSchedule::addFuelEvents(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
clear();
|
|
||||||
|
|
||||||
for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
|
for (int cylinderIndex = 0; cylinderIndex < CONFIG(specs.cylindersCount); cylinderIndex++) {
|
||||||
InjectionEvent *ev = &elements[cylinderIndex];
|
InjectionEvent *ev = &elements[cylinderIndex];
|
||||||
ev->ownIndex = cylinderIndex; // todo: is this assignment needed here? we now initialize in constructor
|
ev->ownIndex = cylinderIndex; // todo: is this assignment needed here? we now initialize in constructor
|
||||||
bool result = addFuelEventsForCylinder(cylinderIndex PASS_ENGINE_PARAMETER_SUFFIX);
|
bool result = addFuelEventsForCylinder(cylinderIndex PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
if (!result)
|
if (!result) {
|
||||||
|
invalidate();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We made it through all cylinders, mark the schedule as ready so it can be used
|
||||||
isReady = true;
|
isReady = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuelSchedule::onTriggerTooth(size_t toothIndex, int rpm, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
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++) {
|
for (int i = 0; i < CONFIG(specs.cylindersCount); i++) {
|
||||||
elements[i].onTriggerTooth(toothIndex, rpm, nowNt);
|
elements[i].onTriggerTooth(toothIndex, rpm, nowNt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,6 +412,9 @@ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
prepareIgnitionPinIndices(CONFIG(ignitionMode) PASS_ENGINE_PARAMETER_SUFFIX);
|
prepareIgnitionPinIndices(CONFIG(ignitionMode) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
TRIGGER_WAVEFORM(prepareShape(&ENGINE(triggerCentral.triggerFormDetails) 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) {
|
void setTimingRpmBin(float from, float to DECLARE_CONFIG_PARAMETER_SUFFIX) {
|
||||||
|
|
|
@ -418,8 +418,13 @@ void findTriggerPosition(TriggerWaveform *triggerShape,
|
||||||
return;
|
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) {
|
void TriggerWaveform::prepareShape(TriggerFormDetails *details DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
|
Loading…
Reference in New Issue