From 4e588ff8f139af3a6bebb682eb6dd045d09409bd Mon Sep 17 00:00:00 2001 From: rusEfi Date: Tue, 5 Jul 2016 20:02:56 -0400 Subject: [PATCH] auto-sync --- firmware/console/binary/tunerstudio.cpp | 14 ++- firmware/controllers/algo/engine.h | 2 +- .../controllers/trigger/trigger_central.h | 2 +- firmware/hw_layer/digital_input_hw.h | 6 +- firmware/rusefi.cpp | 6 +- firmware/util/listener_array.cpp | 55 ----------- firmware/util/listener_array.h | 94 +++++++++++++++++-- 7 files changed, 99 insertions(+), 80 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 6e3765c3fa..3e32efa4e7 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -103,15 +103,18 @@ extern short currentPageId; */ LoggingWithStorage tsLogger("binary"); -extern persistent_config_s configWorkingCopy; +/** + * this is a local copy of the configuration. Any changes to this copy + * have no effect until this copy is explicitly propagated to the main working copy + */ +persistent_config_s configWorkingCopy; + extern persistent_config_container_s persistentState; static efitimems_t previousWriteReportMs = 0; ts_channel_s tsChannel; -extern uint8_t crcWriteBuffer[300]; - static int ts_serial_ready(bool isConsoleRedirect) { #if EFI_PROD_CODE || defined(__DOXYGEN__) if (isSerialOverUart() ^ isConsoleRedirect) { @@ -557,11 +560,6 @@ void syncTunerStudioCopy(void) { tunerstudio_counters_s tsState; TunerStudioOutputChannels tsOutputChannels; -/** - * this is a local copy of the configuration. Any changes to this copy - * have no effect until this copy is explicitly propagated to the main working copy - */ -persistent_config_s configWorkingCopy; short currentPageId; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e58d486fdd..62270b1cf3 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -398,7 +398,7 @@ public: * here we have all the listeners which should be notified about a configuration * change */ - IntListenerArray configurationListeners; + IntListenerArray<15> configurationListeners; monitoring_timestamps_s m; diff --git a/firmware/controllers/trigger/trigger_central.h b/firmware/controllers/trigger/trigger_central.h index b303564802..372da922dc 100644 --- a/firmware/controllers/trigger/trigger_central.h +++ b/firmware/controllers/trigger/trigger_central.h @@ -32,7 +32,7 @@ public: efitick_t nowNt; volatile efitime_t previousShaftEventTimeNt; private: - IntListenerArray triggerListeneres; + IntListenerArray<15> triggerListeneres; int hwEventCounters[HW_EVENT_TYPES]; }; #endif diff --git a/firmware/hw_layer/digital_input_hw.h b/firmware/hw_layer/digital_input_hw.h index 4ecca9c2e1..b6d3d257df 100644 --- a/firmware/hw_layer/digital_input_hw.h +++ b/firmware/hw_layer/digital_input_hw.h @@ -19,10 +19,8 @@ typedef struct { bool isActiveHigh; // false for ICU_INPUT_ACTIVE_LOW, true for ICU_INPUT_ACTIVE_HIGH volatile bool started; - // todo: make this a template & reduce number of listeners? - // todo: would one listener be enough? - IntListenerArray widthListeners; - IntListenerArray periodListeners; + IntListenerArray<1> widthListeners; + IntListenerArray<1> periodListeners; } digital_input_s; void turnOnCapturePin(const char *msg, brain_pin_e brainPin); diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 2258e1639a..1562921b11 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -289,14 +289,14 @@ void firmwareError(const char *errorMsg, ...) { } } -static char UNUSED_RAM_SIZE[100]; +static char UNUSED_RAM_SIZE[2100]; -static char UNUSED_CCM_SIZE[3600] CCM_OPTIONAL; +static char UNUSED_CCM_SIZE[8500] CCM_OPTIONAL; int getRusEfiVersion(void) { if (UNUSED_RAM_SIZE[0] != 0) return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160630; + return 20160705; } diff --git a/firmware/util/listener_array.cpp b/firmware/util/listener_array.cpp index cfc53c24a5..e53c674eef 100644 --- a/firmware/util/listener_array.cpp +++ b/firmware/util/listener_array.cpp @@ -8,58 +8,3 @@ #include "listener_array.h" #include "main.h" -IntListenerArray::IntListenerArray() { - currentListenersCount = 0; - memset(&args, 0, sizeof(args)); - memset(&callbacks, 0, sizeof(callbacks)); -} - -void IntListenerArray::registerCallback(VoidInt handler, void *arg) { - efiAssertVoid(currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks"); - int index = currentListenersCount++; - callbacks[index] = handler; - args[index] = arg; -} - -void IntListenerArray::registerCallback(Void listener) { - registerCallback((VoidInt)listener, NULL); -} - -void invokeCallbacks(IntListenerArray *array, int value) { - for (int i = 0; i < array->currentListenersCount; i++) - (array->callbacks[i])(value); -} - -void IntListenerArray::invokeJustArgCallbacks() { - for (int i = 0; i < currentListenersCount; i++) { - VoidPtr listener = (VoidPtr)callbacks[i]; - void *arg = args[i]; - (listener)(arg); - } -} - -void invokeArgIntCallbacks(IntListenerArray *array, int value) { - for (int i = 0; i < array->currentListenersCount; i++) { - ArgIntListener listener = (ArgIntListener)array->callbacks[i]; - void *arg = array->args[i]; - (listener)(arg, value); - } -} - -void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2) { - for (int i = 0; i < array->currentListenersCount; i++) { - VoidIntInt listener = (VoidIntInt)array->callbacks[i]; - (listener)(value, value2); - } -} - -void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2) { - for (int i = 0; i < array->currentListenersCount; i++) { - IntIntVoidListener listener = (IntIntVoidListener)array->callbacks[i]; - (listener)(value, value2, array->args[i]); - } -} - -void clearCallbacks(IntListenerArray *array) { - array->currentListenersCount = 0; -} diff --git a/firmware/util/listener_array.h b/firmware/util/listener_array.h index e303b4a183..de861e8c71 100644 --- a/firmware/util/listener_array.h +++ b/firmware/util/listener_array.h @@ -8,9 +8,9 @@ #ifndef LISTENER_ARRAY_H_ #define LISTENER_ARRAY_H_ +#include #include "rusefi_types.h" - -#define MAX_INT_LISTENER_COUNT 15 +#include "error_handling.h" // todo: reorder parameters for consistency? typedef void (*IntIntVoidListener)(int value1, int value2, void *arg); @@ -20,6 +20,7 @@ typedef void (*ArgListener)(void *arg); typedef void (*ArgIntListener)(void *arg, int value); // todo: rename this class, that's not just 'callback(int param) anymore +template class IntListenerArray { public: IntListenerArray(); @@ -31,11 +32,88 @@ public: void * args[MAX_INT_LISTENER_COUNT]; }; -void invokeCallbacks(IntListenerArray *array, int value); -void invokeJustArgCallbacks(IntListenerArray *array); -void invokeArgIntCallbacks(IntListenerArray *array, int value); -void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2); -void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2); -void clearCallbacks(IntListenerArray *array); +//template +//void invokeCallbacks(IntListenerArray *array, int value); +// +//template +//void invokeJustArgCallbacks(IntListenerArray *array); +// +//template +//void invokeArgIntCallbacks(IntListenerArray *array, int value); +// +//template +//void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2); +// +//template +//void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2); + +//template +//void clearCallbacks(IntListenerArray *array); + +template +IntListenerArray::IntListenerArray() { + currentListenersCount = 0; + memset(&args, 0, sizeof(args)); + memset(&callbacks, 0, sizeof(callbacks)); +} + +template +void IntListenerArray::registerCallback(VoidInt handler, void *arg) { + efiAssertVoid(currentListenersCount < MAX_INT_LISTENER_COUNT, "Too many callbacks"); + int index = currentListenersCount++; + callbacks[index] = handler; + args[index] = arg; +} + +template +void IntListenerArray::registerCallback(Void listener) { + registerCallback((VoidInt)listener, NULL); +} + +template +void invokeCallbacks(IntListenerArray *array, int value) { + for (int i = 0; i < array->currentListenersCount; i++) + (array->callbacks[i])(value); +} + +template +void IntListenerArray::invokeJustArgCallbacks() { + for (int i = 0; i < currentListenersCount; i++) { + VoidPtr listener = (VoidPtr)callbacks[i]; + void *arg = args[i]; + (listener)(arg); + } +} + +template +void invokeArgIntCallbacks(IntListenerArray *array, int value) { + for (int i = 0; i < array->currentListenersCount; i++) { + ArgIntListener listener = (ArgIntListener)array->callbacks[i]; + void *arg = array->args[i]; + (listener)(arg, value); + } +} + +template +void invokeIntIntCallbacks(IntListenerArray *array, int value, int value2) { + for (int i = 0; i < array->currentListenersCount; i++) { + VoidIntInt listener = (VoidIntInt)array->callbacks[i]; + (listener)(value, value2); + } +} + +template +void invokeIntIntVoidCallbacks(IntListenerArray *array, int value, int value2) { + for (int i = 0; i < array->currentListenersCount; i++) { + IntIntVoidListener listener = (IntIntVoidListener)array->callbacks[i]; + (listener)(value, value2, array->args[i]); + } +} + +template +void clearCallbacks(IntListenerArray *array) { + array->currentListenersCount = 0; +} + #endif /* LISTENER_ARRAY_H_ */