auto-sync

This commit is contained in:
rusEfi 2017-01-02 15:03:26 -05:00
parent a73744a964
commit ff2cbd46aa
14 changed files with 90 additions and 113 deletions

View File

@ -119,6 +119,7 @@
<listOptionValue builtIn="false" value="&quot;../controllers/algo&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/core&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/trigger&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/trigger/decoders&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/sensors&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/system&quot;"/>
<listOptionValue builtIn="false" value="&quot;../controllers/math&quot;"/>

View File

@ -219,6 +219,7 @@ INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
controllers/algo \
controllers/core \
controllers/math \
controllers/trigger/decoders \
controllers/trigger
#

View File

@ -86,7 +86,7 @@
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
#define TS_OUTPUT_SIZE 276
#define TS_OUTPUT_SIZE 356
EXTERN_ENGINE
;

View File

@ -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_ */

View File

@ -18,8 +18,6 @@ extern "C"
#include "stdbool.h"
#include "rusefi_types.h"
void assertVtList(void);
void addWarningCode(obd_code_e code);
/**

View File

@ -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 <chprintf.h>
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
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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 \

View File

@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#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);

View File

@ -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

View File

@ -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;
}