auto-sync
This commit is contained in:
parent
af5b413ff8
commit
055fe76dd2
|
@ -66,6 +66,7 @@
|
|||
#endif
|
||||
|
||||
extern engine_pins_s enginePins;
|
||||
extern NamedOutputPin outputs[IO_PIN_COUNT];
|
||||
|
||||
// this 'true' value is needed for simulator
|
||||
static volatile bool fullLog = true;
|
||||
|
@ -276,10 +277,10 @@ static void printInfo(Engine *engine, systime_t nowSeconds) {
|
|||
// todo: extract method?
|
||||
io_pin_e pin = (io_pin_e) ((int) SPARKOUT_1_OUTPUT + i);
|
||||
|
||||
printOutPin(getPinName(pin), boardConfiguration->ignitionPins[i]);
|
||||
printOutPin(outputs[(int)pin].name, boardConfiguration->ignitionPins[i]);
|
||||
|
||||
pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + i);
|
||||
printOutPin(getPinName(pin), boardConfiguration->injectionPins[i]);
|
||||
printOutPin(outputs[(int)pin].name, boardConfiguration->injectionPins[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -387,13 +388,13 @@ static THD_WORKING_AREA(lcdThreadStack, UTILITY_THREAD_STACK_SIZE);
|
|||
*/
|
||||
static THD_WORKING_AREA(comBlinkingStack, UTILITY_THREAD_STACK_SIZE);
|
||||
|
||||
extern OutputPin errorLedPin;
|
||||
static OutputPin communicationPin;
|
||||
OutputPin checkEnginePin;
|
||||
OutputPin warningPin;
|
||||
OutputPin runningPin;
|
||||
extern engine_pins_s enginePins;
|
||||
|
||||
static OutputPin *leds[] = { &warningPin, &runningPin, &errorLedPin, &communicationPin, &checkEnginePin };
|
||||
static OutputPin *leds[] = { &warningPin, &runningPin, &enginePins.errorLedPin, &communicationPin, &checkEnginePin };
|
||||
|
||||
/**
|
||||
* This method would blink all the LEDs just to test them
|
||||
|
|
|
@ -58,10 +58,10 @@ void Engine::init() {
|
|||
}
|
||||
|
||||
static bool stopPin(io_pin_e pin) {
|
||||
OutputPin *output = &outputs[(int)pin];
|
||||
NamedOutputPin *output = &outputs[(int)pin];
|
||||
if (output->getLogicValue()) {
|
||||
doSetOutputPinValue2(output, false);
|
||||
scheduleMsg(&logger, "turning off %s", getPinName(pin));
|
||||
scheduleMsg(&logger, "turning off %s", output->name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
uint8_t hasEvents[PWM_PHASE_MAX_COUNT];
|
||||
private:
|
||||
void clear();
|
||||
void registerInjectionEvent(io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S);
|
||||
void registerInjectionEvent(NamedOutputPin *output, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,16 +48,11 @@ void initSignalExecutor(void) {
|
|||
initSignalExecutorImpl();
|
||||
}
|
||||
|
||||
void initOutputSignal(OutputSignal *signal, io_pin_e ioPin) {
|
||||
signal->io_pin = ioPin;
|
||||
}
|
||||
|
||||
//uint32_t dbgStart;
|
||||
//uint32_t dbgDurr;
|
||||
|
||||
extern const char *namedPinsArray[NAMED_PIN_COUNT];
|
||||
|
||||
void turnPinHigh(NamedOutputPin *output) {
|
||||
efiAssertVoid(output!=NULL, "NULL @ turnPinHigh");
|
||||
#if EFI_DEFAILED_LOGGING
|
||||
// signal->hi_time = hTimeNow();
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
@ -128,8 +123,8 @@ void scheduleOutput(OutputSignal *signal, float delayMs, float durationMs) {
|
|||
scheduling_s * sUp = &signal->signalTimerUp[index];
|
||||
scheduling_s * sDown = &signal->signalTimerDown[index];
|
||||
|
||||
scheduleTask("out up", sUp, (int) MS2US(delayMs), (schfunc_t) &turnPinHigh, &outputs[(int)signal->io_pin]);
|
||||
scheduleTask("out down", sDown, (int) MS2US(delayMs) + MS2US(durationMs), (schfunc_t) &turnPinLow, &outputs[(int)signal->io_pin]);
|
||||
scheduleTask("out up", sUp, (int) MS2US(delayMs), (schfunc_t) &turnPinHigh, signal->output);
|
||||
scheduleTask("out down", sDown, (int) MS2US(delayMs) + MS2US(durationMs), (schfunc_t) &turnPinLow, signal->output);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "efifeatures.h"
|
||||
#include "io_pins.h"
|
||||
#include "scheduler.h"
|
||||
#include "efiGpio.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "datalogging.h"
|
||||
|
@ -28,7 +29,7 @@
|
|||
*/
|
||||
typedef struct OutputSignal_struct OutputSignal;
|
||||
struct OutputSignal_struct {
|
||||
io_pin_e io_pin;
|
||||
NamedOutputPin *output;
|
||||
|
||||
/**
|
||||
* We are alternating instances so that events which extend into next revolution are not reused while
|
||||
|
@ -43,14 +44,11 @@ extern "C"
|
|||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
void initOutputSignal(OutputSignal *signal, io_pin_e ioPin);
|
||||
void scheduleOutput(OutputSignal *signal, float delayMs, float durationMs);
|
||||
void initOutputSignalBase(OutputSignal *signal);
|
||||
void scheduleOutputBase(OutputSignal *signal, float delayMs, float durationMs);
|
||||
|
||||
void initSignalExecutor(void);
|
||||
void initSignalExecutorImpl(void);
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, float angle, schfunc_t callback, void *param);
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
#include "pwm_generator.h"
|
||||
#include "lcd_controller.h"
|
||||
|
||||
extern OutputPin outputs[IO_PIN_COUNT];
|
||||
extern bool hasFirmwareErrorFlag;
|
||||
|
||||
persistent_config_container_s persistentState CCM_OPTIONAL;
|
||||
|
|
|
@ -48,7 +48,8 @@ extern engine_pins_s enginePins;
|
|||
void initIgnitionCentral(void) {
|
||||
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
|
||||
io_pin_e pin = (io_pin_e)((int)SPARKOUT_1_OUTPUT + i);
|
||||
outputPinRegisterExt2(getPinName(pin), &outputs[(int)pin], boardConfiguration->ignitionPins[i], &boardConfiguration->ignitionPinMode);
|
||||
NamedOutputPin *output = &outputs[(int)pin];
|
||||
outputPinRegisterExt2(output->name, output, boardConfiguration->ignitionPins[i], &boardConfiguration->ignitionPinMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -244,7 +245,9 @@ void initInjectorCentral(Engine *engine) {
|
|||
for (int i = 0; i < engineConfiguration->cylindersCount; i++) {
|
||||
io_pin_e pin = (io_pin_e) ((int) INJECTOR_1_OUTPUT + i);
|
||||
|
||||
outputPinRegisterExt2(getPinName(pin), &outputs[(int)pin], boardConfiguration->injectionPins[i],
|
||||
NamedOutputPin *output = &outputs[(int)pin];
|
||||
|
||||
outputPinRegisterExt2(output->name, output, boardConfiguration->injectionPins[i],
|
||||
&boardConfiguration->injectionPinMode);
|
||||
}
|
||||
|
||||
|
|
|
@ -118,10 +118,10 @@ void initializeIgnitionActions(angle_t advance, angle_t dwellAngle, IgnitionEven
|
|||
}
|
||||
}
|
||||
|
||||
void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
|
||||
if (!isSimultanious && !isPinAssigned(&outputs[(pin)])) {
|
||||
void FuelSchedule::registerInjectionEvent(NamedOutputPin *output, float angle, bool_t isSimultanious DECLARE_ENGINE_PARAMETER_S) {
|
||||
if (!isSimultanious && !isPinAssigned(output)) {
|
||||
// todo: extact method for this index math
|
||||
warning(OBD_PCM_Processor_Fault, "no_pin_inj #%d", (int) pin - (int) INJECTOR_1_OUTPUT + 1);
|
||||
warning(OBD_PCM_Processor_Fault, "no_pin_inj #%s", output->name);
|
||||
}
|
||||
|
||||
InjectionEvent *ev = events.add();
|
||||
|
@ -131,7 +131,7 @@ void FuelSchedule::registerInjectionEvent(io_pin_e pin, float angle, bool_t isSi
|
|||
}
|
||||
|
||||
OutputSignal *actuator = injectonSignals.add();
|
||||
initOutputSignal(actuator, pin);
|
||||
actuator->output = output;
|
||||
|
||||
ev->isSimultanious = isSimultanious;
|
||||
|
||||
|
@ -164,7 +164,7 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_
|
|||
io_pin_e pin = INJECTOR_PIN_BY_INDEX(getCylinderId(engineConfiguration->firingOrder, i) - 1);
|
||||
float angle = baseAngle
|
||||
+ (float) engineConfiguration->engineCycle * i / engineConfiguration->cylindersCount;
|
||||
registerInjectionEvent(pin, angle, false PASS_ENGINE_PARAMETER);
|
||||
registerInjectionEvent(&outputs[(pin)], angle, false PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
case IM_SIMULTANEOUS:
|
||||
|
@ -176,7 +176,7 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_
|
|||
* We do not need injector pin here because we will control all injectors
|
||||
* simultaniously
|
||||
*/
|
||||
registerInjectionEvent(IO_INVALID, angle, true PASS_ENGINE_PARAMETER);
|
||||
registerInjectionEvent(NULL, angle, true PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
case IM_BATCH:
|
||||
|
@ -185,13 +185,13 @@ void FuelSchedule::addFuelEvents(injection_mode_e mode DECLARE_ENGINE_PARAMETER_
|
|||
io_pin_e pin = INJECTOR_PIN_BY_INDEX(index);
|
||||
float angle = baseAngle
|
||||
+ i * (float) engineConfiguration->engineCycle / engineConfiguration->cylindersCount;
|
||||
registerInjectionEvent(pin, angle, false PASS_ENGINE_PARAMETER);
|
||||
registerInjectionEvent(&outputs[(pin)], angle, false PASS_ENGINE_PARAMETER);
|
||||
|
||||
/**
|
||||
* also fire the 2nd half of the injectors so that we can implement a batch mode on individual wires
|
||||
*/
|
||||
pin = INJECTOR_PIN_BY_INDEX(index + (engineConfiguration->cylindersCount / 2));
|
||||
registerInjectionEvent(pin, angle, false PASS_ENGINE_PARAMETER);
|
||||
registerInjectionEvent(&outputs[(pin)], angle, false PASS_ENGINE_PARAMETER);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -16,44 +16,6 @@ pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT;
|
|||
NamedOutputPin outputs[IO_PIN_COUNT];
|
||||
engine_pins_s enginePins;
|
||||
|
||||
const char *namedPinsArray[NAMED_PIN_COUNT] = { "spa1", "spa2", "spa3", "spa4", "spa5", "spa6", "spa7", "spa8",
|
||||
"spa9", "spa10", "spa11", "spa12", "inj1", "inj2", "inj3", "inj4", "inj5", "inj6", "inj7", "inj8", "inj9",
|
||||
"inj10", "inj11", "inj12", };
|
||||
|
||||
const char *getPinName(io_pin_e io_pin) {
|
||||
switch (io_pin) {
|
||||
// todo: refactor this hell - introduce arrays & checks?
|
||||
case SPARKOUT_1_OUTPUT:
|
||||
case SPARKOUT_2_OUTPUT:
|
||||
case SPARKOUT_3_OUTPUT:
|
||||
case SPARKOUT_4_OUTPUT:
|
||||
case SPARKOUT_5_OUTPUT:
|
||||
case SPARKOUT_6_OUTPUT:
|
||||
case SPARKOUT_7_OUTPUT:
|
||||
case SPARKOUT_8_OUTPUT:
|
||||
case SPARKOUT_9_OUTPUT:
|
||||
case SPARKOUT_10_OUTPUT:
|
||||
case SPARKOUT_11_OUTPUT:
|
||||
case SPARKOUT_12_OUTPUT:
|
||||
case INJECTOR_1_OUTPUT:
|
||||
case INJECTOR_2_OUTPUT:
|
||||
case INJECTOR_3_OUTPUT:
|
||||
case INJECTOR_4_OUTPUT:
|
||||
case INJECTOR_5_OUTPUT:
|
||||
case INJECTOR_6_OUTPUT:
|
||||
case INJECTOR_7_OUTPUT:
|
||||
case INJECTOR_8_OUTPUT:
|
||||
case INJECTOR_9_OUTPUT:
|
||||
case INJECTOR_10_OUTPUT:
|
||||
case INJECTOR_11_OUTPUT:
|
||||
case INJECTOR_12_OUTPUT:
|
||||
return namedPinsArray[io_pin];
|
||||
|
||||
default:
|
||||
return "Pin needs name";
|
||||
}
|
||||
}
|
||||
|
||||
NamedOutputPin::NamedOutputPin() : OutputPin() {
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef struct {
|
|||
OutputPin fuelPumpRelay;
|
||||
OutputPin o2heater;
|
||||
OutputPin alternatorField;
|
||||
OutputPin errorLedPin;
|
||||
} engine_pins_s;
|
||||
|
||||
/**
|
||||
|
@ -122,6 +123,4 @@ void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brain
|
|||
void turnPinHigh(NamedOutputPin *output);
|
||||
void turnPinLow(NamedOutputPin *output);
|
||||
|
||||
const char *getPinName(io_pin_e io_pin);
|
||||
|
||||
#endif /* EFIGPIO_H_ */
|
||||
|
|
|
@ -208,7 +208,7 @@ static ALWAYS_INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *i
|
|||
/**
|
||||
* The start of charge is always within the current trigger event range, so just plain time-based scheduling
|
||||
*/
|
||||
scheduleTask("spark up", sUp, sparkDelayUs, (schfunc_t) &turnPinHigh, (void *) iEvent->io_pin);
|
||||
scheduleTask("spark up", sUp, sparkDelayUs, (schfunc_t) &turnPinHigh, &outputs[(int)iEvent->io_pin]);
|
||||
/**
|
||||
* Spark event is often happening during a later trigger event timeframe
|
||||
* TODO: improve precision
|
||||
|
@ -222,7 +222,7 @@ static ALWAYS_INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *i
|
|||
*/
|
||||
float timeTillIgnitionUs = engine->rpmCalculator.oneDegreeUs * iEvent->sparkPosition.angleOffset;
|
||||
|
||||
scheduleTask("spark 1down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnPinLow, (void*) iEvent->io_pin);
|
||||
scheduleTask("spark 1down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnPinLow, &outputs[(int)iEvent->io_pin]);
|
||||
} else {
|
||||
/**
|
||||
* Spark should be scheduled in relation to some future trigger event, this way we get better firing precision
|
||||
|
|
|
@ -239,7 +239,7 @@ void initRpmCalculator(Engine *engine) {
|
|||
* The callback would be executed once after the duration of time which
|
||||
* it takes the crankshaft to rotate to the specified angle.
|
||||
*/
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, float angle, schfunc_t callback, void *param) {
|
||||
void scheduleByAngle(int rpm, scheduling_s *timer, angle_t angle, schfunc_t callback, void *param) {
|
||||
if (!isValidRpm(rpm)) {
|
||||
/**
|
||||
* this might happen in case of a single trigger event after a pause - this is normal, so no
|
||||
|
|
|
@ -91,11 +91,10 @@ void outputPinRegister(const char *msg, OutputPin *output, GPIO_TypeDef *port, u
|
|||
outputPinRegisterExt(msg, output, port, pin, &DEFAULT_OUTPUT);
|
||||
}
|
||||
|
||||
OutputPin errorLedPin;
|
||||
extern OutputPin checkEnginePin;
|
||||
|
||||
void initPrimaryPins(void) {
|
||||
outputPinRegister("LED_ERROR", &errorLedPin, LED_ERROR_PORT, LED_ERROR_PIN);
|
||||
outputPinRegister("LED_ERROR", &enginePins.errorLedPin, LED_ERROR_PORT, LED_ERROR_PIN);
|
||||
}
|
||||
|
||||
static void getPinValue(const char *name) {
|
||||
|
@ -108,6 +107,45 @@ static void getPinValue(const char *name) {
|
|||
scheduleMsg(&logger, "pin_value %s %d", name, value);
|
||||
}
|
||||
|
||||
static const char *namedPinsArray[NAMED_PIN_COUNT] = { "spa1", "spa2", "spa3", "spa4", "spa5", "spa6", "spa7", "spa8",
|
||||
"spa9", "spa10", "spa11", "spa12", "inj1", "inj2", "inj3", "inj4", "inj5", "inj6", "inj7", "inj8", "inj9",
|
||||
"inj10", "inj11", "inj12", };
|
||||
|
||||
static const char *getPinName(io_pin_e io_pin) {
|
||||
switch (io_pin) {
|
||||
// todo: refactor this hell - introduce arrays & checks?
|
||||
case SPARKOUT_1_OUTPUT:
|
||||
case SPARKOUT_2_OUTPUT:
|
||||
case SPARKOUT_3_OUTPUT:
|
||||
case SPARKOUT_4_OUTPUT:
|
||||
case SPARKOUT_5_OUTPUT:
|
||||
case SPARKOUT_6_OUTPUT:
|
||||
case SPARKOUT_7_OUTPUT:
|
||||
case SPARKOUT_8_OUTPUT:
|
||||
case SPARKOUT_9_OUTPUT:
|
||||
case SPARKOUT_10_OUTPUT:
|
||||
case SPARKOUT_11_OUTPUT:
|
||||
case SPARKOUT_12_OUTPUT:
|
||||
case INJECTOR_1_OUTPUT:
|
||||
case INJECTOR_2_OUTPUT:
|
||||
case INJECTOR_3_OUTPUT:
|
||||
case INJECTOR_4_OUTPUT:
|
||||
case INJECTOR_5_OUTPUT:
|
||||
case INJECTOR_6_OUTPUT:
|
||||
case INJECTOR_7_OUTPUT:
|
||||
case INJECTOR_8_OUTPUT:
|
||||
case INJECTOR_9_OUTPUT:
|
||||
case INJECTOR_10_OUTPUT:
|
||||
case INJECTOR_11_OUTPUT:
|
||||
case INJECTOR_12_OUTPUT:
|
||||
return namedPinsArray[io_pin];
|
||||
|
||||
default:
|
||||
return "Pin needs name";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void initOutputPins(void) {
|
||||
initLogging(&logger, "io_pins");
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
*/
|
||||
|
||||
#include "main.h"
|
||||
#include "signal_executor.h"
|
||||
#include "microsecond_timer.h"
|
||||
#include "scheduler.h"
|
||||
#include "rfiutil.h"
|
||||
|
||||
// https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fInterrupt%20on%20CEN%20bit%20setting%20in%20TIM7&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=474
|
||||
|
|
|
@ -229,13 +229,13 @@ void chDbgStackOverflowPanic(Thread *otp) {
|
|||
chDbgPanic3(panicMessage, __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
extern OutputPin errorLedPin;
|
||||
extern engine_pins_s enginePins;
|
||||
|
||||
// todo: why is this method here and not in error_handling.c ?
|
||||
void firmwareError(const char *fmt, ...) {
|
||||
if (hasFirmwareErrorFlag)
|
||||
return;
|
||||
errorLedPin.setValue(1);
|
||||
enginePins.errorLedPin.setValue(1);
|
||||
turnAllPinsOff();
|
||||
hasFirmwareErrorFlag = TRUE;
|
||||
if (indexOf(fmt, '%') == -1) {
|
||||
|
|
|
@ -352,8 +352,8 @@ void testFLStack(void) {
|
|||
}
|
||||
|
||||
void testMisc(void) {
|
||||
assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
|
||||
assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
|
||||
// assertEquals(true, strEqual("spa3", getPinName(SPARKOUT_3_OUTPUT)));
|
||||
// assertEquals(SPARKOUT_12_OUTPUT, getPinByName("spa12"));
|
||||
}
|
||||
|
||||
void testMenuTree(void) {
|
||||
|
|
Loading…
Reference in New Issue