auto-sync

This commit is contained in:
rusEfi 2016-09-26 21:03:18 -04:00
parent 25fb991d70
commit c2ae17977c
8 changed files with 148 additions and 126 deletions

View File

@ -88,8 +88,7 @@ public:
#endif
OutputSignal fuelActuators[INJECTION_PIN_COUNT];
scheduling_s overlappingFuelActuatorTimerUp[INJECTION_PIN_COUNT];
scheduling_s overlappingFuelActuatorTimerDown[INJECTION_PIN_COUNT];
OutputSignalPair overlappingFuelActuator[INJECTION_PIN_COUNT];
bool wasOverlapping[INJECTION_PIN_COUNT];

View File

@ -57,11 +57,10 @@ public:
char *name;
};
#define MAX_NUMBER_OF_CYLINDERS 12
/**
* two wire batch mode would generate twice the number of cylinders events, that's the max
*/
#define MAX_INJECTION_OUTPUT_COUNT 2 * MAX_NUMBER_OF_CYLINDERS
#define MAX_INJECTION_OUTPUT_COUNT 2 * INJECTION_PIN_COUNT
#define MAX_IGNITION_EVENT_COUNT 80
typedef ArrayList<InjectionEvent, MAX_INJECTION_OUTPUT_COUNT> InjectionEventList;

View File

@ -59,6 +59,11 @@ void initEnginePinsNames(void) {
}
}
OutputSignalPair::OutputSignalPair() {
isScheduled = false;
output = NULL;
}
void initSignalExecutor(void) {
initSignalExecutorImpl();
initEnginePinsNames();
@ -113,121 +118,5 @@ void turnPinLow(NamedOutputPin *output) {
extern LoggingWithStorage sharedLogger;
#endif /* FUEL_MATH_EXTREME_LOGGING */
// todo: make these macro? kind of a penny optimization if compiler is not smart to inline
void seTurnPinHigh(InjectorOutputPin *output) {
// output->overlappingCounter++;
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("seTurnPinHigh %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
if (output->overlappingCounter > 1) {
// if (output->cancelNextTurningInjectorOff) {
// // how comes AutoTest.testFordAspire ends up here?
// } else {
// /**
// * #299
// * this is another kind of overlap which happens in case of a small duty cycle after a large duty cycle
// */
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
// output->cancelNextTurningInjectorOff = true;
// return;
// }
}
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char * w = output->currentLogicValue == true ? "err" : "";
scheduleMsg(&sharedLogger, "^ %spin=%s eventIndex %d %d", w, output->name,
getRevolutionCounter(), getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if EFI_UNIT_TEST
// if (output->currentLogicValue == 1)
// firmwareError("Already high");
#endif
turnPinHigh(output);
}
void seTurnPinLow(InjectorOutputPin *output) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("seTurnPinLow %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
if (output->cancelNextTurningInjectorOff) {
/**
* in case of fuel schedule overlap between engine cycles,
* and if engine cycle is above say 75% for batch mode on 4 cylinders,
* we will get a secondary overlap between the special injection and a normal injection on the same injector.
* In such a case want to combine these two injection into one continues injection.
* Unneeded turn of injector on is handle while scheduling that second injection, but cancellation
* of special injection end has to be taken care of dynamically
*
*/
output->cancelNextTurningInjectorOff = false;
#if EFI_SIMULATOR || defined(__DOXYGEN__)
printf("was cancelled %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* EFI_SIMULATOR */
return;
}
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char * w = output->currentLogicValue == false ? "err" : "";
scheduleMsg(&sharedLogger, "- %spin=%s eventIndex %d %d", w, output->name,
getRevolutionCounter(), getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if EFI_UNIT_TEST
// if (output->currentLogicValue == 0)
// firmwareError("Already low");
#endif
output->overlappingCounter--;
if (output->overlappingCounter > 0) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("was overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
// return;
}
turnPinLow(output);
}
void seScheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, NamedOutputPin *param) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time);
scheduleMsg(&sharedLogger, "schX %s", param->name);
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char *direction = callback == (schfunc_t) &seTurnPinHigh ? "up" : "down";
printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling);
#endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */
scheduleByTime(prefix, scheduling, time, callback, param);
}
/**
*
* @param delay the number of ticks before the output signal
* immediate output if delay is zero
* @param dwell the number of ticks of output duration
*
*/
void scheduleOutput2(scheduling_s * sUp, scheduling_s * sDown, efitimeus_t nowUs, float delayUs, float durationUs, InjectorOutputPin *output) {
#if EFI_GPIO || defined(__DOXYGEN__)
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
printf("scheduling output %s\r\n", output->name);
#endif /* EFI_UNIT_TEST */
efitimeus_t turnOnTime = nowUs + (int) delayUs;
seScheduleByTime("out up", sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, output);
efitimeus_t turnOffTime = nowUs + (int) (delayUs + durationUs);
seScheduleByTime("out down", sDown, turnOffTime, (schfunc_t) &seTurnPinLow, output);
#endif /* EFI_GPIO */
}

View File

@ -24,6 +24,23 @@
#include "signal_executor_sleep.h"
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
class OutputSignalPair {
public:
OutputSignalPair();
scheduling_s signalTimerUp;
scheduling_s signalTimerDown;
/**
* we need atomic flag so that we do not schedule a new pair of up/down before previous down was executed.
*
* That's because we want to be sure that no 'down' side callback would be ignored since we are counting to see
* overlaps so we need the end counter to always have zero.
* TODO: make watchdog decrement relevant counter
*/
bool isScheduled;
InjectorOutputPin *output;
};
/**
* @brief Asynchronous output signal data structure
*/
@ -38,7 +55,6 @@ struct OutputSignal_struct {
scheduling_s signalTimerDown[2];
};
void scheduleOutput2(scheduling_s * sUp, scheduling_s * sDown, efitimeus_t nowUs, float delayUs, float durationUs, InjectorOutputPin *output);
void seScheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, NamedOutputPin *param);
void initSignalExecutor(void);
void initEnginePinsNames(void);

View File

@ -151,8 +151,6 @@ public:
void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode);
void seTurnPinHigh(InjectorOutputPin *output);
void seTurnPinLow(InjectorOutputPin *output);
void turnPinHigh(NamedOutputPin *output);
void turnPinLow(NamedOutputPin *output);

View File

@ -166,7 +166,7 @@ int EventQueue::executeAll(efitime_t now) {
int howFarOff = now - current->momentX;
maxHowFarOff = maxI(maxHowFarOff, howFarOff);
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
printf("execute %d %d\r\n", (int)current, (int)current->param);
printf("execute %d %d\r\n", (long)current, (long)current->param);
#endif
current->callback(current->param);
// even with overflow it's safe to subtract here

View File

@ -87,6 +87,101 @@ static void endSimultaniousInjection(Engine *engine) {
}
}
// todo: make these macro? kind of a penny optimization if compiler is not smart to inline
void seTurnPinHigh(InjectorOutputPin *output) {
// output->overlappingCounter++;
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("seTurnPinHigh %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
if (output->overlappingCounter > 1) {
// if (output->cancelNextTurningInjectorOff) {
// // how comes AutoTest.testFordAspire ends up here?
// } else {
// /**
// * #299
// * this is another kind of overlap which happens in case of a small duty cycle after a large duty cycle
// */
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
// output->cancelNextTurningInjectorOff = true;
// return;
// }
}
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char * w = output->currentLogicValue == true ? "err" : "";
scheduleMsg(&sharedLogger, "^ %spin=%s eventIndex %d %d", w, output->name,
getRevolutionCounter(), getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if EFI_UNIT_TEST
// if (output->currentLogicValue == 1)
// firmwareError("Already high");
#endif
turnPinHigh(output);
}
void seTurnPinLow(InjectorOutputPin *output) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("seTurnPinLow %s %d %d\r\n", output->name, output->overlappingCounter, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
if (output->cancelNextTurningInjectorOff) {
/**
* in case of fuel schedule overlap between engine cycles,
* and if engine cycle is above say 75% for batch mode on 4 cylinders,
* we will get a secondary overlap between the special injection and a normal injection on the same injector.
* In such a case want to combine these two injection into one continues injection.
* Unneeded turn of injector on is handle while scheduling that second injection, but cancellation
* of special injection end has to be taken care of dynamically
*
*/
output->cancelNextTurningInjectorOff = false;
#if EFI_SIMULATOR || defined(__DOXYGEN__)
printf("was cancelled %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* EFI_SIMULATOR */
return;
}
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char * w = output->currentLogicValue == false ? "err" : "";
scheduleMsg(&sharedLogger, "- %spin=%s eventIndex %d %d", w, output->name,
getRevolutionCounter(), getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if EFI_UNIT_TEST
// if (output->currentLogicValue == 0)
// firmwareError("Already low");
#endif
output->overlappingCounter--;
if (output->overlappingCounter > 0) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
printf("was overlapping, no need to touch pin %s %d\r\n", output->name, (int)getTimeNowUs());
#endif /* FUEL_MATH_EXTREME_LOGGING */
// return;
}
turnPinLow(output);
}
void seScheduleByTime(const char *prefix, scheduling_s *scheduling, efitimeus_t time, schfunc_t callback, NamedOutputPin *param) {
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
scheduleMsg(&sharedLogger, "schX %s %x %d", prefix, scheduling, time);
scheduleMsg(&sharedLogger, "schX %s", param->name);
#endif /* FUEL_MATH_EXTREME_LOGGING */
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
const char *direction = callback == (schfunc_t) &seTurnPinHigh ? "up" : "down";
printf("seScheduleByTime %s %s %d sch=%d\r\n", direction, param->name, (int)time, (int)scheduling);
#endif /* FUEL_MATH_EXTREME_LOGGING || EFI_UNIT_TEST */
scheduleByTime(prefix, scheduling, time, callback, param);
}
static void scheduleFuelInjection(int rpm, int injEventIndex, OutputSignal *signal, efitimeus_t nowUs, floatus_t delayUs, floatus_t durationUs, InjectorOutputPin *output DECLARE_ENGINE_PARAMETER_S) {
if (durationUs < 0) {
warning(CUSTOM_OBD_3, "duration cannot be negative: %d", durationUs);
@ -210,6 +305,29 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE
}
}
/**
*
* @param delay the number of ticks before the output signal
* immediate output if delay is zero
* @param dwell the number of ticks of output duration
*
*/
void scheduleOutput2(scheduling_s * sUp, scheduling_s * sDown, efitimeus_t nowUs, float delayUs, float durationUs, InjectorOutputPin *output) {
#if EFI_GPIO || defined(__DOXYGEN__)
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
printf("scheduling output %s\r\n", output->name);
#endif /* EFI_UNIT_TEST */
efitimeus_t turnOnTime = nowUs + (int) delayUs;
seScheduleByTime("out up", sUp, turnOnTime, (schfunc_t) &seTurnPinHigh, output);
efitimeus_t turnOffTime = nowUs + (int) (delayUs + durationUs);
seScheduleByTime("out down", sDown, turnOffTime, (schfunc_t) &seTurnPinLow, output);
#endif /* EFI_GPIO */
}
static void handleFuelScheduleOverlap(InjectionEventList *injectionEvents DECLARE_ENGINE_PARAMETER_S) {
/**
* here we need to avoid a fuel miss due to changes between previous and current fuel schedule
@ -227,8 +345,8 @@ static void handleFuelScheduleOverlap(InjectionEventList *injectionEvents DECLAR
// todo: recalc fuel? account for wetting?
floatms_t injectionDuration = ENGINE(fuelMs);
scheduling_s * sUp = &ENGINE(engineConfiguration2)->overlappingFuelActuatorTimerUp[injEventIndex];
scheduling_s * sDown = &ENGINE(engineConfiguration2)->overlappingFuelActuatorTimerDown[injEventIndex];
scheduling_s * sUp = &ENGINE(engineConfiguration2)->overlappingFuelActuator[injEventIndex].signalTimerUp;
scheduling_s * sDown = &ENGINE(engineConfiguration2)->overlappingFuelActuator[injEventIndex].signalTimerDown;
efitimeus_t nowUs = getTimeNowUs();

View File

@ -22,5 +22,8 @@ int isIgnitionTimingError(void);
void showMainHistogram(void);
void seTurnPinHigh(InjectorOutputPin *output);
void seTurnPinLow(InjectorOutputPin *output);
float getFuel(int rpm, float key);
#endif /* MAIN_LOOP_H_ */