diff --git a/firmware/.cproject b/firmware/.cproject
index 9c1a61b643..3dc03e88bc 100644
--- a/firmware/.cproject
+++ b/firmware/.cproject
@@ -119,6 +119,7 @@
+
diff --git a/firmware/Makefile b/firmware/Makefile
index e296ef7be1..348031eb27 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -219,6 +219,7 @@ INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
controllers/algo \
controllers/core \
controllers/math \
+ controllers/trigger/decoders \
controllers/trigger
#
diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp
index 0a3b9e43e5..cf4f8b3d7e 100644
--- a/firmware/console/binary/tunerstudio.cpp
+++ b/firmware/console/binary/tunerstudio.cpp
@@ -86,7 +86,7 @@
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
-#define TS_OUTPUT_SIZE 276
+#define TS_OUTPUT_SIZE 356
EXTERN_ENGINE
;
diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h
index 2bb29f616a..32d2b84e87 100644
--- a/firmware/console/binary/tunerstudio_configuration.h
+++ b/firmware/console/binary/tunerstudio_configuration.h
@@ -132,7 +132,7 @@ typedef struct {
float debugFloatField6; // 256
float debugFloatField7; // 260
int firmwareVersion; // 264
- int unused3[2];
+ int unused3[22];
} TunerStudioOutputChannels;
#endif /* TUNERSTUDIO_CONFIGURATION_H_ */
diff --git a/firmware/controllers/algo/error_handling.h b/firmware/controllers/algo/error_handling.h
index fbb144ecb1..9eb62808e3 100644
--- a/firmware/controllers/algo/error_handling.h
+++ b/firmware/controllers/algo/error_handling.h
@@ -18,8 +18,6 @@ extern "C"
#include "stdbool.h"
#include "rusefi_types.h"
-void assertVtList(void);
-
void addWarningCode(obd_code_e code);
/**
diff --git a/firmware/controllers/error_handling.cpp b/firmware/controllers/error_handling.cpp
index 8edd2aead5..75ee530ef5 100644
--- a/firmware/controllers/error_handling.cpp
+++ b/firmware/controllers/error_handling.cpp
@@ -8,11 +8,24 @@
#include "main.h"
#include "error_handling.h"
#include "io_pins.h"
-#include "memstreams.h"
#include "efilib2.h"
#include "engine.h"
+
+#if EFI_SIMULATOR || EFI_PROD_CODE
//todo: move into simulator global
+#include "memstreams.h"
#include
+static MemoryStream warningStream;
+static MemoryStream firmwareErrorMessageStream;
+#endif
+
+
+#define WARNING_BUFFER_SIZE 80
+static char warningBuffer[WARNING_BUFFER_SIZE];
+static bool isWarningStreamInitialized = false;
+
+
+
#if EFI_HD44780_LCD || defined(__DOXYGEN__)
#include "lcd_HD44780.h"
@@ -26,11 +39,19 @@ EXTERN_ENGINE;
extern int warningEnabled;
extern bool main_loop_started;
-extern bool hasFirmwareErrorFlag;
+
+fatal_msg_t errorMessageBuffer;
+bool hasFirmwareErrorFlag = false;
const char *dbg_panic_file;
int dbg_panic_line;
+char *getFirmwareError(void) {
+ return (char*) errorMessageBuffer;
+}
+
+#if EFI_SIMULATOR || EFI_PROD_CODE
+
void chDbgPanic3(const char *msg, const char * file, int line) {
if (hasFatalError())
return;
@@ -58,10 +79,6 @@ void chDbgPanic3(const char *msg, const char * file, int line) {
}
}
-#define WARNING_BUFFER_SIZE 80
-static char warningBuffer[WARNING_BUFFER_SIZE];
-static bool isWarningStreamInitialized = false;
-static MemoryStream warningStream;
/**
* @param forIndicator if we want to retrieving value for TS indicator, this case a minimal period is applued
@@ -82,6 +99,9 @@ void printToStream(MemoryStream *stream, const char *fmt, va_list ap) {
chvprintf((BaseSequentialStream *) stream, fmt, ap);
stream->buffer[stream->eos] = 0;
}
+#endif
+
+int warningCounter = 0;
/**
* OBD_PCM_Processor_Fault is the general error code for now
@@ -91,12 +111,13 @@ void printToStream(MemoryStream *stream, const char *fmt, va_list ap) {
bool warning(obd_code_e code, const char *fmt, ...) {
if (hasFirmwareErrorFlag)
return true;
- efiAssert(isWarningStreamInitialized, "warn stream not initialized", false);
#if EFI_UNIT_TEST || EFI_SIMULATOR || defined(__DOXYGEN__)
printf("warning %s\r\n", fmt);
#endif
+#if EFI_SIMULATOR || EFI_PROD_CODE
+ efiAssert(isWarningStreamInitialized, "warn stream not initialized", false);
addWarningCode(code);
efitimesec_t now = getTimeNowSeconds();
@@ -117,8 +138,17 @@ bool warning(obd_code_e code, const char *fmt, ...) {
append(&logger, warningBuffer);
append(&logger, DELIMETER);
scheduleLogging(&logger);
+#else
+ warningCounter++;
+ printf("Warning: ");
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\r\n");
- return FALSE;
+#endif
+ return false;
}
char *getWarning(void) {
@@ -128,9 +158,6 @@ char *getWarning(void) {
uint32_t lastLockTime;
uint32_t maxLockTime = 0;
-// todo: move this field to trigger_central?
-bool isInsideTriggerHandler = false;
-
void onLockHook(void) {
lastLockTime = GET_TIMESTAMP();
}
@@ -147,35 +174,48 @@ void onUnlockHook(void) {
}
void initErrorHandling(void) {
+#if EFI_SIMULATOR || EFI_PROD_CODE
msObjectInit(&warningStream, (uint8_t *) warningBuffer, WARNING_BUFFER_SIZE, 0);
+ msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0);
+#endif
isWarningStreamInitialized = true;
}
-//todo: move into simulator global
-typedef VTList virtual_timers_list_t;
-
-extern virtual_timers_list_t vtlist;
-extern bool main_loop_started;
-
-int getVtSizeEstimate(void) {
- virtual_timer_t *first = vtlist.vt_next;
- virtual_timer_t *cur = first->vt_next;
- int c = 0;
- while (c++ < 20 && cur != first) {
- cur = cur->vt_next;
- }
- return c;
-}
-
-int globalVt;
-
-int allReady = 0;
-void assertVtList(void) {
- if (!main_loop_started)
+void firmwareError(obd_code_e code, const char *fmt, ...) {
+#if EFI_PROD_CODE
+ if (hasFirmwareErrorFlag)
return;
- globalVt = getVtSizeEstimate();
- //efiAssertVoid(globalVt > 3, "VT list?");
- if(globalVt <=3 ) {
- allReady++;
+ addWarningCode(code);
+ ON_FATAL_ERROR()
+ ;
+ hasFirmwareErrorFlag = true;
+ if (indexOf(fmt, '%') == -1) {
+ /**
+ * in case of simple error message let's reduce stack usage
+ * because chvprintf might be causing an error
+ */
+ strncpy((char*) errorMessageBuffer, fmt, sizeof(errorMessageBuffer) - 1);
+ errorMessageBuffer[sizeof(errorMessageBuffer) - 1] = 0; // just to be sure
+ } else {
+ firmwareErrorMessageStream.eos = 0; // reset
+ va_list ap;
+ va_start(ap, fmt);
+ chvprintf((BaseSequentialStream *) &firmwareErrorMessageStream, fmt, ap);
+ va_end(ap);
+ // todo: reuse warning buffer helper method
+ firmwareErrorMessageStream.buffer[firmwareErrorMessageStream.eos] = 0; // need to terminate explicitly
}
+#else
+ printf("firmwareError [%s]\r\n", fmt);
+
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+
+#if EFI_SIMULATOR
+ exit(-1);
+#endif /* EFI_SIMULATOR */
+#endif
}
+
diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp
index 9987c9f55b..ff53063fa7 100644
--- a/firmware/controllers/trigger/trigger_central.cpp
+++ b/firmware/controllers/trigger/trigger_central.cpp
@@ -74,7 +74,8 @@ int maxTriggerReentraint = 0;
uint32_t triggerDuration;
uint32_t triggerMaxDuration = 0;
-extern bool isInsideTriggerHandler;
+static bool isInsideTriggerHandler = false;
+
efitick_t previousVvtCamTime = 0;
efitick_t previousVvtCamDuration = 0;
diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp
index 6a204dd5a6..dc3c72ae81 100644
--- a/firmware/rusefi.cpp
+++ b/firmware/rusefi.cpp
@@ -123,21 +123,16 @@ LoggingWithStorage sharedLogger("main");
bool main_loop_started = false;
-static MemoryStream firmwareErrorMessageStream;
static char panicMessage[200];
-fatal_msg_t errorMessageBuffer;
-bool hasFirmwareErrorFlag = false;
+extern bool hasFirmwareErrorFlag;
+extern fatal_msg_t errorMessageBuffer;
static virtual_timer_t resetTimer;
EXTERN_ENGINE
;
-char *getFirmwareError(void) {
- return (char*) errorMessageBuffer;
-}
-
// todo: move this into a hw-specific file
static void rebootNow(void) {
NVIC_SystemReset();
@@ -178,9 +173,6 @@ void runRusEfi(void) {
* In order to have complete flexibility configuration has to go before anything else.
*/
readConfiguration(&sharedLogger);
-
- msObjectInit(&firmwareErrorMessageStream, errorMessageBuffer, sizeof(errorMessageBuffer), 0);
-
prepareVoidConfiguration(&activeConfiguration);
/**
@@ -248,32 +240,6 @@ void chDbgStackOverflowPanic(Thread *otp) {
chDbgPanic3(panicMessage, __FILE__, __LINE__);
}
-// todo: why is this method here and not in error_handling.cpp ?
-void firmwareError(obd_code_e code, const char *errorMsg, ...) {
- if (hasFirmwareErrorFlag)
- return;
- addWarningCode(code);
- ON_FATAL_ERROR()
- ;
- hasFirmwareErrorFlag = true;
- if (indexOf(errorMsg, '%') == -1) {
- /**
- * in case of simple error message let's reduce stack usage
- * because chvprintf might be causing an error
- */
- strncpy((char*) errorMessageBuffer, errorMsg, sizeof(errorMessageBuffer) - 1);
- errorMessageBuffer[sizeof(errorMessageBuffer) - 1] = 0; // just to be sure
- } else {
- firmwareErrorMessageStream.eos = 0; // reset
- va_list ap;
- va_start(ap, errorMsg);
- chvprintf((BaseSequentialStream *) &firmwareErrorMessageStream, errorMsg, ap);
- va_end(ap);
-
- firmwareErrorMessageStream.buffer[firmwareErrorMessageStream.eos] = 0; // need to terminate explicitly
- }
-}
-
static char UNUSED_RAM_SIZE[11100];
static char UNUSED_CCM_SIZE[16500] CCM_OPTIONAL;
diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini
index 5223de7fc1..f3711678f5 100644
--- a/firmware/tunerstudio/rusefi.ini
+++ b/firmware/tunerstudio/rusefi.ini
@@ -805,7 +805,7 @@ fileVersion = { 20161225 }
ochGetCommand = "O"
; see TS_OUTPUT_SIZE in console source code
- ochBlockSize = 276
+ ochBlockSize = 356
rpm = scalar, U32, 0, "RPM", 1, 0.00000
#if CELSIUS
diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input
index 1324bf2434..289827bbfb 100644
--- a/firmware/tunerstudio/rusefi.input
+++ b/firmware/tunerstudio/rusefi.input
@@ -750,7 +750,7 @@ fileVersion = { 20161225 }
ochGetCommand = "O"
; see TS_OUTPUT_SIZE in console source code
- ochBlockSize = 276
+ ochBlockSize = 356
rpm = scalar, U32, 0, "RPM", 1, 0.00000
#if CELSIUS
diff --git a/unit_tests/Makefile b/unit_tests/Makefile
index 470ed3d896..5a55a25d4c 100644
--- a/unit_tests/Makefile
+++ b/unit_tests/Makefile
@@ -103,6 +103,7 @@ CPPSRC = $(UTILSRC_CPP) \
$(CONTROLLERS_SENSORS_SRC_CPP) \
$(TEST_SRC_CPP) \
$(SYSTEMSRC_CPP) \
+ $(PROJECT_DIR)/controllers/error_handling.cpp \
$(PROJECT_DIR)/controllers/trigger/trigger_central.cpp \
$(PROJECT_DIR)/controllers/trigger/rpm_calculator.cpp \
$(PROJECT_DIR)/controllers/trigger/spark_logic.cpp \
@@ -141,6 +142,7 @@ INCDIR = . \
$(PROJECT_DIR)/controllers/math \
$(PROJECT_DIR)/controllers/system \
$(PROJECT_DIR)/controllers/trigger \
+ $(PROJECT_DIR)/controllers/trigger/decoders \
$(PROJECT_DIR)/ext_algo \
../firmware/chibios/os/kernel/include \
../firmware/chibios/os/various \
diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp
index 09d130dc34..c6cdb5377e 100644
--- a/unit_tests/main.cpp
+++ b/unit_tests/main.cpp
@@ -8,7 +8,7 @@
#include
#include
#include
-#include
+
#include "main.h"
#include "error_handling.h"
@@ -179,25 +179,6 @@ int main(void) {
return EXIT_SUCCESS;
}
-int warningCounter = 0;
-
-bool warning(obd_code_e code, const char *format, ...) {
- warningCounter++;
- printf("Warning: ");
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- va_end(ap);
- printf("\r\n");
-}
-
-bool hasFirmwareErrorFlag = false;
-
-void firmwareError(obd_code_e code, const char *fmt, ...) {
- printf(fmt);
- exit(-1);
-}
-
void print(const char *format, ...) {
va_list ap;
va_start(ap, format);
diff --git a/win32_functional_tests/Makefile b/win32_functional_tests/Makefile
index da5b4932c6..5a2ff2c9ae 100644
--- a/win32_functional_tests/Makefile
+++ b/win32_functional_tests/Makefile
@@ -201,6 +201,7 @@ $(PORTINC) $(KERNINC) $(TESTINC) \
$(PROJECT_DIR)/controllers/sensors \
$(PROJECT_DIR)/controllers/system \
$(PROJECT_DIR)/controllers/trigger \
+ $(PROJECT_DIR)/controllers/trigger/decoders \
${CHIBIOS}/os/various \
simulator
diff --git a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp
index ddd2d1b4a9..9ec258b4cb 100644
--- a/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp
+++ b/win32_functional_tests/simulator/rusEfiFunctionalTest.cpp
@@ -116,8 +116,6 @@ bool isConsoleReady(void) {
void applyNewConfiguration(void) {
}
-bool hasFirmwareErrorFlag = false;
-
void onFatalError(const char *msg, const char * file, int line) {
printf("onFatalError %s %s%d", msg, file, line);
exit(-1);
@@ -134,18 +132,6 @@ void logMsg(const char *format, ...) {
// fclose(fp);
}
-void firmwareError(obd_code_e code, const char *fmt, ...) {
- printf("firmwareError [%s]\r\n", fmt);
-
- va_list ap;
- va_start(ap, fmt);
- vprintf(fmt, ap);
- va_end(ap);
-
-
- exit(-1);
-}
-
SerialDriver * getConsoleChannel(void) {
return (SerialDriver *)EFI_CONSOLE_UART_DEVICE;
}