From 055fe76dd26f2f1cd973ff6c1efc039f1f18074d Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 13 Jan 2015 12:06:16 -0600 Subject: [PATCH] auto-sync --- firmware/console/status_loop.cpp | 9 ++-- firmware/controllers/algo/engine.cpp | 4 +- firmware/controllers/algo/engine.h | 2 +- firmware/controllers/algo/signal_executor.cpp | 11 ++--- firmware/controllers/algo/signal_executor.h | 8 ++-- firmware/controllers/engine_controller.cpp | 1 - firmware/controllers/injector_central.cpp | 7 +++- firmware/controllers/math/engine_math.cpp | 16 +++---- firmware/controllers/system/efiGpio.cpp | 38 ----------------- firmware/controllers/system/efiGpio.h | 3 +- .../trigger/main_trigger_callback.cpp | 4 +- .../controllers/trigger/rpm_calculator.cpp | 2 +- firmware/hw_layer/io_pins.cpp | 42 ++++++++++++++++++- firmware/hw_layer/microsecond_timer.c | 2 +- firmware/rusefi.cpp | 4 +- unit_tests/test_util.cpp | 4 +- 16 files changed, 76 insertions(+), 81 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 29a6ed51ee..a48bc1d04c 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -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 diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 5295e1883d..618f346205 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -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; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 9ce7d3dd12..75a1b6fb4c 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -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); }; /** diff --git a/firmware/controllers/algo/signal_executor.cpp b/firmware/controllers/algo/signal_executor.cpp index c5b722608c..5a13e6bf9b 100644 --- a/firmware/controllers/algo/signal_executor.cpp +++ b/firmware/controllers/algo/signal_executor.cpp @@ -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 } diff --git a/firmware/controllers/algo/signal_executor.h b/firmware/controllers/algo/signal_executor.h index 660fa1a987..25d684ee17 100644 --- a/firmware/controllers/algo/signal_executor.h +++ b/firmware/controllers/algo/signal_executor.h @@ -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 } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 591fd5be98..2d889c9871 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -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; diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 2e6d399c6a..41eaa16227 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -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); } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 5d060cb218..8c301b3ce6 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -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: diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index 5caf5a8818..10a4a05500 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -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() { } diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 86f83d5c19..15a2c13bfa 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -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_ */ diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index dd89edd247..adef8469d5 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -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 diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index cc57514e69..5437ffa89e 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -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 diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 19a1795461..468d15f98b 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -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"); diff --git a/firmware/hw_layer/microsecond_timer.c b/firmware/hw_layer/microsecond_timer.c index 829b2a54ab..ce210c3d7c 100644 --- a/firmware/hw_layer/microsecond_timer.c +++ b/firmware/hw_layer/microsecond_timer.c @@ -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 diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index d7853d867a..f210481986 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -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) { diff --git a/unit_tests/test_util.cpp b/unit_tests/test_util.cpp index 80f7ad0ed7..5bd454dba9 100644 --- a/unit_tests/test_util.cpp +++ b/unit_tests/test_util.cpp @@ -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) {