From 22f3114f05d766f4f3f8389867205610ebb3c9c5 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 13 Sep 2014 16:02:50 -0500 Subject: [PATCH] auto-sync --- firmware/console_util/datalogging.c | 26 +++++++++++-------- .../controllers/algo/engine_configuration.h | 4 +-- firmware/controllers/algo/io_pins.h | 2 ++ .../system/SingleTimerExecutor.cpp | 3 +++ firmware/controllers/system/event_queue.cpp | 7 ++++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/firmware/console_util/datalogging.c b/firmware/console_util/datalogging.c index 63987f6e47..47ee0f2ed2 100644 --- a/firmware/console_util/datalogging.c +++ b/firmware/console_util/datalogging.c @@ -63,30 +63,34 @@ static uint8_t intermediateLoggingBufferData[INTERMEDIATE_LOGGING_BUFFER_SIZE] C //todo define max-printf-buffer static bool intermediateLoggingBufferInited = FALSE; -static int validateBuffer(Logging *logging, uint32_t extraLen, const char *text) { +/** + * @returns true if data does not fit into this buffer + */ +static bool validateBuffer(Logging *logging, uint32_t extraLen, const char *text) { if (logging->buffer == NULL) { firmwareError("Logging not initialized: %s", logging->name); - return TRUE; + return true; } if (remainingSize(logging) < extraLen + 1) { - strcpy(logging->SMALL_BUFFER, "Logging buffer overflow: "); - strcat(logging->SMALL_BUFFER, logging->name); - strcat(logging->SMALL_BUFFER, "/"); - strcat(logging->SMALL_BUFFER, text); - firmwareError(logging->SMALL_BUFFER); + warning(OBD_PCM_Processor_Fault, "buffer overflow %s", logging->name); +// strcpy(logging->SMALL_BUFFER, "Logging buffer overflow: "); +// strcat(logging->SMALL_BUFFER, logging->name); +// strcat(logging->SMALL_BUFFER, "/"); +// strcat(logging->SMALL_BUFFER, text); +// firmwareError(logging->SMALL_BUFFER); // unlockOutputBuffer(); // resetLogging(logging); - return TRUE; + return true; } - return FALSE; + return false; } void append(Logging *logging, const char *text) { efiAssertVoid(text != NULL, "append NULL"); uint32_t extraLen = strlen(text); - int errcode = validateBuffer(logging, extraLen, text); - if (errcode) { + int isError = validateBuffer(logging, extraLen, text); + if (isError) { return; } strcpy(logging->linePointer, text); diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index e3e6f4be75..897f28617f 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -163,7 +163,7 @@ typedef struct { adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX]; brain_pin_e triggerInputPins[3]; - int unused4; + brain_pin_e mainRelayPin; int idleThreadPeriod; int consoleLoopPeriod; @@ -197,7 +197,7 @@ typedef struct { int unrealisticRpmThreashold; - int unused2; + pin_output_mode_e mainRelayPinMode; } board_configuration_s; diff --git a/firmware/controllers/algo/io_pins.h b/firmware/controllers/algo/io_pins.h index b68283dd5a..bc0c65d029 100644 --- a/firmware/controllers/algo/io_pins.h +++ b/firmware/controllers/algo/io_pins.h @@ -108,6 +108,8 @@ typedef enum { SPI_CS_4, SPI_CS_SD_MODULE, + MAIN_RELAY, + /** * This output pin is used to turn alternator on or off diff --git a/firmware/controllers/system/SingleTimerExecutor.cpp b/firmware/controllers/system/SingleTimerExecutor.cpp index 01ea0bf3d5..a7403fef3a 100644 --- a/firmware/controllers/system/SingleTimerExecutor.cpp +++ b/firmware/controllers/system/SingleTimerExecutor.cpp @@ -84,6 +84,9 @@ void Executor::doExecute(uint64_t nowUs) { * further invocations */ reentrantLock = TRUE; + /** + * It's worth noting that that the actions might be adding new actions into the queue + */ queue.executeAll(nowUs); if (!isLocked()) { firmwareError("Someone has stolen my lock"); diff --git a/firmware/controllers/system/event_queue.cpp b/firmware/controllers/system/event_queue.cpp index 0540c2e810..de98f2fe08 100644 --- a/firmware/controllers/system/event_queue.cpp +++ b/firmware/controllers/system/event_queue.cpp @@ -26,7 +26,6 @@ void EventQueue::insertTask(scheduling_s *scheduling, uint64_t timeUs, schfunc_t if (callback == NULL) firmwareError("NULL callback"); - int alreadyPending = checkIfPending(scheduling); if (alreadyPending || hasFirmwareError()) return; @@ -57,6 +56,12 @@ uint64_t EventQueue::getNextEventTime(uint64_t nowUs) { firmwareError("Is this list looped #2?"); return EMPTY_QUEUE; } + if (current->momentUs <= nowUs) { + //firmwareError("temperror: executeAll should have been called %d/%d", current->momentUs, nowUs); + // todo: looks like we end up here after 'writeconfig' (which freezes the firmware) + // todo: figure this out + continue; + } efiAssert(current->momentUs > nowUs, "executeAll should have been called", EMPTY_QUEUE); if (current->momentUs < result) result = current->momentUs;