From af5b413ff8162be4a095b3a3b3e0710b091ec6a6 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 13 Jan 2015 11:05:05 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/io_pins.h | 21 +++++++++--------- firmware/controllers/algo/signal_executor.cpp | 22 +++++++++---------- firmware/controllers/algo/signal_executor.h | 3 --- firmware/controllers/core/fsio_impl.cpp | 3 --- firmware/controllers/injector_central.cpp | 2 +- .../controllers/malfunction_indicator.cpp | 2 -- firmware/controllers/math/engine_math.cpp | 2 +- firmware/controllers/system/efiGpio.cpp | 6 ++++- firmware/controllers/system/efiGpio.h | 9 ++++++++ .../trigger/main_trigger_callback.cpp | 7 +++--- firmware/hw_layer/io_pins.cpp | 5 ++++- firmware/rusefi.cpp | 2 -- 13 files changed, 46 insertions(+), 40 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 092999502a..5295e1883d 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -23,7 +23,7 @@ static Logging logger; -extern OutputPin outputs[IO_PIN_COUNT]; +extern NamedOutputPin outputs[IO_PIN_COUNT]; EXTERN_ENGINE ; diff --git a/firmware/controllers/algo/io_pins.h b/firmware/controllers/algo/io_pins.h index 4dc6a25a39..b63efc4fde 100644 --- a/firmware/controllers/algo/io_pins.h +++ b/firmware/controllers/algo/io_pins.h @@ -63,13 +63,13 @@ typedef enum { IO_INVALID, - /** - * these seven segment display pins are related to unused external tachometer code - * I still have the hardware so maybe one day I will fix it, but for now it's just dead code - * See https://www.youtube.com/watch?v=YYiHoN6MBqE - * todo: this should be re-implemented in a smarter way with some sort of multiplexing anyway - */ - /* digit 1 */ +/** + * these seven segment display pins are related to unused external tachometer code + * I still have the hardware so maybe one day I will fix it, but for now it's just dead code + * See https://www.youtube.com/watch?v=YYiHoN6MBqE + * todo: this should be re-implemented in a smarter way with some sort of multiplexing anyway + */ +/* digit 1 */ // LED_HUGE_0, // B2 // LED_HUGE_1, // LED_HUGE_2, @@ -94,20 +94,19 @@ typedef enum { // LED_HUGE_19, // LED_HUGE_20, - } io_pin_e; -#define IO_PIN_COUNT 100 +#define IO_PIN_COUNT 24 void initPrimaryPins(void); void initOutputPins(void); +io_pin_e getPinByName(const char *name); + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -io_pin_e getPinByName(const char *name); - #if EFI_GPIO void turnAllPinsOff(void); #else diff --git a/firmware/controllers/algo/signal_executor.cpp b/firmware/controllers/algo/signal_executor.cpp index b52ab5d95a..c5b722608c 100644 --- a/firmware/controllers/algo/signal_executor.cpp +++ b/firmware/controllers/algo/signal_executor.cpp @@ -41,7 +41,7 @@ extern WaveChart waveChart; static Logging logger; -extern OutputPin outputs[IO_PIN_COUNT]; +extern NamedOutputPin outputs[IO_PIN_COUNT]; void initSignalExecutor(void) { initLogging(&logger, "s exec"); @@ -52,12 +52,12 @@ void initOutputSignal(OutputSignal *signal, io_pin_e ioPin) { signal->io_pin = ioPin; } -uint32_t dbgStart; -uint32_t dbgDurr; +//uint32_t dbgStart; +//uint32_t dbgDurr; extern const char *namedPinsArray[NAMED_PIN_COUNT]; -void turnPinHigh(io_pin_e pin) { +void turnPinHigh(NamedOutputPin *output) { #if EFI_DEFAILED_LOGGING // signal->hi_time = hTimeNow(); #endif /* EFI_DEFAILED_LOGGING */ @@ -65,14 +65,14 @@ void turnPinHigh(io_pin_e pin) { #if EFI_GPIO // turn the output level ACTIVE // todo: this XOR should go inside the setOutputPinValue method - doSetOutputPinValue2((&outputs[pin]), true); + doSetOutputPinValue2(output, true); // sleep for the needed duration #endif #if EFI_WAVE_CHART // explicit check here is a performance optimization to speed up no-chart mode if (CONFIG(isDigitalChartEnabled)) { // this is a performance optimization - array index is cheaper then invoking a method with 'switch' - const char *pinName = namedPinsArray[pin]; + const char *pinName = output->name; // dbgDurr = hal_lld_get_counter_value() - dbgStart; addWaveChartEvent(pinName, WC_UP); @@ -81,10 +81,10 @@ void turnPinHigh(io_pin_e pin) { // dbgDurr = hal_lld_get_counter_value() - dbgStart; } -void turnPinLow(io_pin_e pin) { +void turnPinLow(NamedOutputPin *output) { #if EFI_GPIO // turn off the output - doSetOutputPinValue2((&outputs[pin]), false); + doSetOutputPinValue2(output, false); #endif #if EFI_DEFAILED_LOGGING @@ -96,7 +96,7 @@ void turnPinLow(io_pin_e pin) { #if EFI_WAVE_CHART if (CONFIG(isDigitalChartEnabled)) { // this is a performance optimization - array index is cheaper then invoking a method with 'switch' - const char *pinName = namedPinsArray[pin]; + const char *pinName = output->name; addWaveChartEvent(pinName, WC_DOWN); } @@ -128,8 +128,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, (void *) signal->io_pin); - scheduleTask("out down", sDown, (int) MS2US(delayMs) + MS2US(durationMs), (schfunc_t) &turnPinLow, (void*) signal->io_pin); + 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]); #endif } diff --git a/firmware/controllers/algo/signal_executor.h b/firmware/controllers/algo/signal_executor.h index 165fb6818a..660fa1a987 100644 --- a/firmware/controllers/algo/signal_executor.h +++ b/firmware/controllers/algo/signal_executor.h @@ -48,9 +48,6 @@ void scheduleOutput(OutputSignal *signal, float delayMs, float durationMs); void initOutputSignalBase(OutputSignal *signal); void scheduleOutputBase(OutputSignal *signal, float delayMs, float durationMs); -void turnPinHigh(io_pin_e pin); -void turnPinLow(io_pin_e pin); - void initSignalExecutor(void); void initSignalExecutorImpl(void); void scheduleByAngle(int rpm, scheduling_s *timer, float angle, schfunc_t callback, void *param); diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index ff9ed4d5be..ad0beebab2 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -149,7 +149,6 @@ static SimplePwm fsioPwm[LE_COMMAND_COUNT] CCM_OPTIONAL; static LECalculator calc; extern LEElement * fsioLogics[LE_COMMAND_COUNT]; -extern OutputPin outputs[IO_PIN_COUNT]; // that's crazy, but what's an alternative? we need const char *, a shared buffer would not work for pin repository static const char *getGpioPinName(int index) { @@ -357,8 +356,6 @@ void runFsio(void) { static pin_output_mode_e defa = OM_DEFAULT; -extern OutputPin outputs[IO_PIN_COUNT]; - void initFsioImpl(Engine *engine) { initLogging(&logger, "le"); diff --git a/firmware/controllers/injector_central.cpp b/firmware/controllers/injector_central.cpp index 71360cbe6d..2e6d399c6a 100644 --- a/firmware/controllers/injector_central.cpp +++ b/firmware/controllers/injector_central.cpp @@ -42,7 +42,7 @@ static bool_t isRunningBench = false; static int is_injector_enabled[MAX_INJECTOR_COUNT]; -extern OutputPin outputs[IO_PIN_COUNT]; +extern NamedOutputPin outputs[IO_PIN_COUNT]; extern engine_pins_s enginePins; void initIgnitionCentral(void) { diff --git a/firmware/controllers/malfunction_indicator.cpp b/firmware/controllers/malfunction_indicator.cpp index aa38c0ca26..43f1bd73ff 100644 --- a/firmware/controllers/malfunction_indicator.cpp +++ b/firmware/controllers/malfunction_indicator.cpp @@ -40,8 +40,6 @@ static THD_WORKING_AREA(mfiThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread -extern OutputPin outputs[IO_PIN_COUNT]; - extern OutputPin checkEnginePin; static void blink_digits(int digit, int duration) { diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index f4a18930a2..5d060cb218 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -32,7 +32,7 @@ EXTERN_ENGINE ; -extern OutputPin outputs[IO_PIN_COUNT]; +extern NamedOutputPin outputs[IO_PIN_COUNT]; /** * this cache allows us to find a close-enough (with one degree precision) trigger wheel index by diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index d4e6058d85..5caf5a8818 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -13,7 +13,7 @@ pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT; // todo: clean this mess, this should become 'static'/private -OutputPin outputs[IO_PIN_COUNT]; +NamedOutputPin outputs[IO_PIN_COUNT]; engine_pins_s enginePins; const char *namedPinsArray[NAMED_PIN_COUNT] = { "spa1", "spa2", "spa3", "spa4", "spa5", "spa6", "spa7", "spa8", @@ -54,6 +54,10 @@ const char *getPinName(io_pin_e io_pin) { } } +NamedOutputPin::NamedOutputPin() : OutputPin() { + +} + OutputPin::OutputPin() { modePtr = &OUTPUT_MODE_DEFAULT; } diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 40506252d5..86f83d5c19 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -36,6 +36,12 @@ public: int currentLogicValue; }; +class NamedOutputPin : public OutputPin { +public: + NamedOutputPin(); + const char *name; +}; + typedef struct { OutputPin mainRelay; OutputPin fanRelay; @@ -113,6 +119,9 @@ typedef struct { void outputPinRegisterExt2(const char *msg, OutputPin *output, brain_pin_e brainPin, pin_output_mode_e *outputMode); +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 d4ff36815e..dd89edd247 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -33,7 +33,7 @@ #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) #include "main_trigger_callback.h" - +#include "efiGpio.h" #include "engine_math.h" #include "trigger_central.h" #include "rpm_calculator.h" @@ -57,6 +57,7 @@ EXTERN_ENGINE ; extern bool hasFirmwareErrorFlag; +extern NamedOutputPin outputs[IO_PIN_COUNT]; static LocalVersionHolder localVersion; @@ -88,13 +89,13 @@ static Logging logger; static void startSimultaniousInjection(Engine *engine) { for (int i = 0; i < engine->engineConfiguration->cylindersCount; i++) { - turnPinHigh(INJECTOR_PIN_BY_INDEX(i)); + turnPinHigh(&outputs[(int)INJECTOR_PIN_BY_INDEX(i)]); } } static void endSimultaniousInjection(Engine *engine) { for (int i = 0; i < engine->engineConfiguration->cylindersCount; i++) { - turnPinLow(INJECTOR_PIN_BY_INDEX(i)); + turnPinLow(&outputs[(int)INJECTOR_PIN_BY_INDEX(i)]); } } diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 9701a80b62..19a1795461 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -27,7 +27,7 @@ static Logging logger; static OutputPin sdCsPin; -extern OutputPin outputs[IO_PIN_COUNT]; +extern NamedOutputPin outputs[IO_PIN_COUNT]; extern engine_pins_s enginePins; #if defined(STM32F4XX) @@ -111,6 +111,9 @@ static void getPinValue(const char *name) { void initOutputPins(void) { initLogging(&logger, "io_pins"); + for (int i = 0; i < IO_PIN_COUNT;i++) + outputs[i].name = getPinName((io_pin_e)i); + /** * want to make sure it's all zeros so that we can compare in initOutputPinExt() method */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 162dafe4ed..d7853d867a 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -229,8 +229,6 @@ void chDbgStackOverflowPanic(Thread *otp) { chDbgPanic3(panicMessage, __FILE__, __LINE__); } -extern OutputPin outputs[IO_PIN_COUNT]; - extern OutputPin errorLedPin; // todo: why is this method here and not in error_handling.c ?