diff --git a/firmware/bootloader/src/Makefile b/firmware/bootloader/src/Makefile index 110a5e05fa..1e18d2b357 100644 --- a/firmware/bootloader/src/Makefile +++ b/firmware/bootloader/src/Makefile @@ -139,6 +139,7 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk # RTOS files (optional). include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk +include $(CHIBIOS)/os/various/cpp_wrappers/chcpp.mk include $(CONFIG)/boards/$(PROJECT_BOARD)/board.mk include $(PROJECT_DIR)/init/init.mk diff --git a/firmware/console/binary_log/binary_logging.cpp b/firmware/console/binary_log/binary_logging.cpp index f555029201..77c21eee2f 100644 --- a/firmware/console/binary_log/binary_logging.cpp +++ b/firmware/console/binary_log/binary_logging.cpp @@ -3,13 +3,13 @@ * See also mlq_file_format.txt */ - +#include "binary_logging.h" #include "tunerstudio_outputs.h" #include "log_field.h" #include "efilib.h" #include "efitime.h" #include "crc.h" - +#include "buffered_writer.h" #define TIME_PRECISION 1000 @@ -59,7 +59,8 @@ static const LogField fields[] = { {tsOutputChannels.massAirFlow, GAUGE_NAME_AIR_FLOW, "kg/h", 1}, }; -size_t writeHeader(char* buffer) { +void writeHeader(Writer& outBuffer) { + char buffer[MLQ_HEADER_SIZE]; // File format: MLVLG\0 strncpy(buffer, "MLVLG", 6); @@ -77,7 +78,13 @@ size_t writeHeader(char* buffer) { buffer[12] = 0; buffer[13] = 0; - // Index 14-17 are written at the end - header end offset + size_t headerSize = MLQ_HEADER_SIZE + efi::size(fields) * 55; + + // Data begin index: begins immediately after the header + buffer[14] = 0; + buffer[15] = 0; + buffer[16] = (headerSize >> 8) & 0xFF; + buffer[17] = headerSize & 0xFF; // Record length - length of a single data record: sum size of all fields uint16_t recLength = 0; @@ -92,23 +99,12 @@ size_t writeHeader(char* buffer) { buffer[20] = 0; buffer[21] = efi::size(fields); - size_t headerSize = MLQ_HEADER_SIZE; + outBuffer.write(buffer, MLQ_HEADER_SIZE); // Write the actual logger fields, offset 22 - char* entryHeaders = buffer + MLQ_HEADER_SIZE; for (size_t i = 0; i < efi::size(fields); i++) { - size_t sz = fields[i].writeHeader(entryHeaders); - entryHeaders += sz; - headerSize += sz; + fields[i].writeHeader(outBuffer); } - - // Data begin index: begins immediately after the header - buffer[14] = 0; - buffer[15] = 0; - buffer[16] = (headerSize >> 8) & 0xFF; - buffer[17] = headerSize & 0xFF; - - return headerSize; } static uint8_t blockRollCounter = 0; diff --git a/firmware/console/binary_log/binary_logging.h b/firmware/console/binary_log/binary_logging.h index dd0d6200f3..70cd7b7c78 100644 --- a/firmware/console/binary_log/binary_logging.h +++ b/firmware/console/binary_log/binary_logging.h @@ -1,4 +1,5 @@ #include -size_t writeHeader(char* buffer); +struct Writer; +void writeHeader(Writer& buffer); size_t writeBlock(char* buffer); diff --git a/firmware/console/binary_log/log_field.cpp b/firmware/console/binary_log/log_field.cpp index ae5a63ae6c..58e2c0bdbc 100644 --- a/firmware/console/binary_log/log_field.cpp +++ b/firmware/console/binary_log/log_field.cpp @@ -1,4 +1,5 @@ #include "log_field.h" +#include "buffered_writer.h" #include @@ -16,7 +17,9 @@ static void copyFloat(char* buffer, float value) { memcpy_swapend(buffer, reinterpret_cast(&value), sizeof(float)); } -size_t LogField::writeHeader(char* buffer) const { +void LogField::writeHeader(Writer& outBuffer) const { + char buffer[MLQ_FIELD_HEADER_SIZE]; + // Offset 0, length 1 = type buffer[0] = static_cast(m_type); @@ -40,7 +43,7 @@ size_t LogField::writeHeader(char* buffer) const { buffer[54] = m_digits; // Total size = 55 - return MLQ_FIELD_HEADER_SIZE; + outBuffer.write(buffer, MLQ_FIELD_HEADER_SIZE); } size_t LogField::writeData(char* buffer) const { diff --git a/firmware/console/binary_log/log_field.h b/firmware/console/binary_log/log_field.h index 0ab289fa9f..eb7a3c987d 100644 --- a/firmware/console/binary_log/log_field.h +++ b/firmware/console/binary_log/log_field.h @@ -4,6 +4,7 @@ #include #include +struct Writer; class LogField { public: template @@ -34,8 +35,7 @@ public: } // Write the header data describing this field. - // Returns the number of bytes written. - size_t writeHeader(char* buffer) const; + void writeHeader(Writer& outBuffer) const; // Write the field's data to the buffer. // Returns the number of bytes written. diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 35f85ff214..ebf5c9a4fc 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -120,15 +120,13 @@ static void setWarningEnabled(int value) { #if EFI_FILE_LOGGING // this one needs to be in main ram so that SD card SPI DMA works fine -static char sdLogBuffer[2200] MAIN_RAM; +static char sdLogBuffer[100] MAIN_RAM; static uint64_t binaryLogCount = 0; #endif /* EFI_FILE_LOGGING */ EXTERN_ENGINE; -static char buf[6]; - /** * This is useful if we are changing engine mode dynamically * For example http://rusefi.com/forum/viewtopic.php?f=5&t=1085 @@ -148,18 +146,15 @@ void writeLogLine(Writer& buffer) { if (!main_loop_started) return; - size_t length; if (binaryLogCount == 0) { - length = writeHeader(sdLogBuffer); + writeHeader(buffer); } else { updateTunerStudioState(&tsOutputChannels); - length = writeBlock(sdLogBuffer); + size_t length = writeBlock(sdLogBuffer); + efiAssertVoid(OBD_PCM_Processor_Fault, length <= efi::size(sdLogBuffer), "SD log buffer overflow"); + buffer.write(sdLogBuffer, length); } - efiAssertVoid(OBD_PCM_Processor_Fault, length <= efi::size(sdLogBuffer), "SD log buffer overflow"); - - buffer.write(sdLogBuffer, length); - binaryLogCount++; #endif /* EFI_FILE_LOGGING */ } @@ -773,7 +768,6 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ case DBG_FSIO_ADC: // todo: implement a proper loop if (engineConfiguration->fsioAdc[0] != EFI_ADC_NONE) { - strcpy(buf, "adcX"); tsOutputChannels->debugFloatField1 = getVoltage("fsio", engineConfiguration->fsioAdc[0] PASS_ENGINE_PARAMETER_SUFFIX); } break; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index a2e6537b6e..d790c9acff 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -50,7 +50,6 @@ #include "spark_logic.h" #include "aux_valves.h" #include "accelerometer.h" -#include "counter64.h" #include "perf_trace.h" #include "boost_control.h" #include "launch_control.h" @@ -220,8 +219,6 @@ static void doPeriodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT efiAssertVoid(CUSTOM_ERR_6661, getCurrentRemainingStack() > 64, "lowStckOnEv"); #if EFI_PROD_CODE - touchTimeCounter(); - slowStartStopButtonCallback(PASS_ENGINE_PARAMETER_SIGNATURE); #endif /* EFI_PROD_CODE */ @@ -707,7 +704,7 @@ void initEngineContoller(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) * UNUSED_SIZE constants. */ #ifndef RAM_UNUSED_SIZE -#define RAM_UNUSED_SIZE 2350 +#define RAM_UNUSED_SIZE 4000 #endif #ifndef CCM_UNUSED_SIZE #define CCM_UNUSED_SIZE 2900 diff --git a/firmware/controllers/engine_controller.h b/firmware/controllers/engine_controller.h index 28741d0ca5..549f439067 100644 --- a/firmware/controllers/engine_controller.h +++ b/firmware/controllers/engine_controller.h @@ -17,7 +17,6 @@ void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S void initStartStopButton(DECLARE_ENGINE_PARAMETER_SIGNATURE); void initDataStructures(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void touchTimeCounter(); void slowStartStopButtonCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/engine_controller_misc.cpp b/firmware/controllers/engine_controller_misc.cpp index 61d80dd722..35bc00bb68 100644 --- a/firmware/controllers/engine_controller_misc.cpp +++ b/firmware/controllers/engine_controller_misc.cpp @@ -7,7 +7,7 @@ #include "engine_controller.h" #include "perf_trace.h" -#include "counter64.h" +#include "os_access.h" #include "settings.h" EXTERN_ENGINE; @@ -84,8 +84,6 @@ void setMockState(brain_pin_e pin, bool state DECLARE_ENGINE_PARAMETER_SUFFIX) { #endif /* EFI_ENABLE_MOCK_ADC */ #if EFI_PROD_CODE -static Overflow64Counter halTime; - /** * 64-bit result would not overflow, but that's complex stuff for our 32-bit MCU */ @@ -95,34 +93,31 @@ efitimeus_t getTimeNowUs(void) { return getTimeNowNt() / (CORE_CLOCK / 1000000); } -//todo: macro to save method invocation -efitick_t getTimeNowNt(void) { -#if EFI_PROD_CODE - /* Entering a reentrant critical zone.*/ - syssts_t sts = chSysGetStatusAndLockX(); - efitime_t localH = halTime.state.highBits; - uint32_t localLow = halTime.state.lowBits; +volatile uint32_t lastLowerNt = 0; +volatile uint32_t upperTimeNt = 0; - uint32_t value = getTimeNowLowerNt(); +efitick_t getTimeNowNt() { + chibios_rt::CriticalSectionLocker csl; - if (value < localLow) { - // new value less than previous value means there was an overflow in that 32 bit counter - localH += 0x100000000LL; + uint32_t stamp = getTimeNowLowerNt(); + + // Lower 32 bits of the timer has wrapped - time to step upper bits + if (stamp < lastLowerNt) { + upperTimeNt++; } - efitime_t result = localH + value; + lastLowerNt = stamp; - /* Leaving the critical zone.*/ - chSysRestoreStatusX(sts); - return result; -#else /* EFI_PROD_CODE */ -// todo: why is this implementation not used? - /** - * this method is lock-free and thread-safe, that's because the 'update' method - * is atomic with a critical zone requirement. - * - * http://stackoverflow.com/questions/5162673/how-to-read-two-32bit-counters-as-a-64bit-integer-without-race-condition - */ + return ((int64_t)upperTimeNt << 32) | stamp; +} + +/* //Alternative lock free implementation (probably actually slower!) + // this method is lock-free and thread-safe, that's because the 'update' method + // is atomic with a critical zone requirement. + // + // http://stackoverflow.com/questions/5162673/how-to-read-two-32bit-counters-as-a-64bit-integer-without-race-condition + +etitick_t getTimeNowNt() { efitime_t localH; efitime_t localH2; uint32_t localLow; @@ -131,14 +126,11 @@ efitick_t getTimeNowNt(void) { localH = halTime.state.highBits; localLow = halTime.state.lowBits; localH2 = halTime.state.highBits; -#if EFI_PROD_CODE if (counter++ == 10000) chDbgPanic("lock-free frozen"); -#endif /* EFI_PROD_CODE */ } while (localH != localH2); - /** - * We need to take current counter after making a local 64 bit snapshot - */ + + // We need to take current counter after making a local 64 bit snapshot uint32_t value = getTimeNowLowerNt(); if (value < localLow) { @@ -147,20 +139,8 @@ efitick_t getTimeNowNt(void) { } return localH + value; -#endif /* EFI_PROD_CODE */ - -} - -void touchTimeCounter() { - /** - * We need to push current value into the 64 bit counter often enough so that we do not miss an overflow - */ - /* Entering a reentrant critical zone.*/ - syssts_t sts = chSysGetStatusAndLockX(); - updateAndSet(&halTime.state, getTimeNowLowerNt()); - /* Leaving the critical zone.*/ - chSysRestoreStatusX(sts); } +*/ static void onStartStopButtonToggle(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engine->startStopStateToggleCounter++; diff --git a/firmware/controllers/generated/signature_frankenso_na6.h b/firmware/controllers/generated/signature_frankenso_na6.h index 7f3844b5b7..b41f6a5fe0 100644 --- a/firmware/controllers/generated/signature_frankenso_na6.h +++ b/firmware/controllers/generated/signature_frankenso_na6.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD frankenso_na6 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 912264321 -#define TS_SIGNATURE "rusEFI 2020.10.15.frankenso_na6.912264321" +#define SIGNATURE_HASH 1874496581 +#define TS_SIGNATURE "rusEFI 2020.10.15.frankenso_na6.1874496581" diff --git a/firmware/controllers/generated/signature_mre_f4.h b/firmware/controllers/generated/signature_mre_f4.h index a173b73c47..f04e69ed3c 100644 --- a/firmware/controllers/generated/signature_mre_f4.h +++ b/firmware/controllers/generated/signature_mre_f4.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD mre_f4 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 2596085838 -#define TS_SIGNATURE "rusEFI 2020.10.15.mre_f4.2596085838" +#define SIGNATURE_HASH 640748912 +#define TS_SIGNATURE "rusEFI 2020.10.15.mre_f4.640748912" diff --git a/firmware/controllers/generated/signature_mre_f7.h b/firmware/controllers/generated/signature_mre_f7.h index 9e2a0cf167..78cc317410 100644 --- a/firmware/controllers/generated/signature_mre_f7.h +++ b/firmware/controllers/generated/signature_mre_f7.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD mre_f7 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 2596085838 -#define TS_SIGNATURE "rusEFI 2020.10.15.mre_f7.2596085838" +#define SIGNATURE_HASH 640748912 +#define TS_SIGNATURE "rusEFI 2020.10.15.mre_f7.640748912" diff --git a/firmware/controllers/generated/signature_prometheus_405.h b/firmware/controllers/generated/signature_prometheus_405.h index 6a106dca6a..ddc275cd39 100644 --- a/firmware/controllers/generated/signature_prometheus_405.h +++ b/firmware/controllers/generated/signature_prometheus_405.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD prometheus_405 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 1925279141 -#define TS_SIGNATURE "rusEFI 2020.10.15.prometheus_405.1925279141" +#define SIGNATURE_HASH 1854343583 +#define TS_SIGNATURE "rusEFI 2020.10.15.prometheus_405.1854343583" diff --git a/firmware/controllers/generated/signature_prometheus_469.h b/firmware/controllers/generated/signature_prometheus_469.h index 46723cc1b8..24a99ebee8 100644 --- a/firmware/controllers/generated/signature_prometheus_469.h +++ b/firmware/controllers/generated/signature_prometheus_469.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD prometheus_469 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 1925279141 -#define TS_SIGNATURE "rusEFI 2020.10.15.prometheus_469.1925279141" +#define SIGNATURE_HASH 1854343583 +#define TS_SIGNATURE "rusEFI 2020.10.15.prometheus_469.1854343583" diff --git a/firmware/controllers/generated/signature_proteus_f4.h b/firmware/controllers/generated/signature_proteus_f4.h index 66eddeeff0..61b552dea5 100644 --- a/firmware/controllers/generated/signature_proteus_f4.h +++ b/firmware/controllers/generated/signature_proteus_f4.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD proteus_f4 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 1345656303 -#define TS_SIGNATURE "rusEFI 2020.10.15.proteus_f4.1345656303" +#define SIGNATURE_HASH 1968121740 +#define TS_SIGNATURE "rusEFI 2020.10.15.proteus_f4.1968121740" diff --git a/firmware/controllers/generated/signature_proteus_f7.h b/firmware/controllers/generated/signature_proteus_f7.h index 5877acfdf3..86731cdbad 100644 --- a/firmware/controllers/generated/signature_proteus_f7.h +++ b/firmware/controllers/generated/signature_proteus_f7.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD proteus_f7 #define SIGNATURE_DATE 2020.10.15 -#define SIGNATURE_HASH 1345656303 -#define TS_SIGNATURE "rusEFI 2020.10.15.proteus_f7.1345656303" +#define SIGNATURE_HASH 1968121740 +#define TS_SIGNATURE "rusEFI 2020.10.15.proteus_f7.1968121740" diff --git a/firmware/os_access.h b/firmware/os_access.h index 339f580f7e..64a057ce51 100644 --- a/firmware/os_access.h +++ b/firmware/os_access.h @@ -9,19 +9,14 @@ #pragma once -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - #include #include #include "chprintf.h" - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #include "io_pins.h" +#ifdef __cplusplus +// ChibiOS c++ wrappers +#include "ch.hpp" +#endif /* __cplusplus */ + #define HAS_OS_ACCESS diff --git a/firmware/tunerstudio/generated/cache.zip b/firmware/tunerstudio/generated/cache.zip index 5746f19b69..2f04e2f348 100644 Binary files a/firmware/tunerstudio/generated/cache.zip and b/firmware/tunerstudio/generated/cache.zip differ diff --git a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini index e8599a5c69..a40ea3e137 100644 --- a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini +++ b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.frankenso_na6.912264321" + signature = "rusEFI 2020.10.15.frankenso_na6.1874496581" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.frankenso_na6.912264321" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.frankenso_na6.1874496581" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:49 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:58:57 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_mre_f4.ini b/firmware/tunerstudio/generated/rusefi_mre_f4.ini index 5125d6abfe..bcf0cc39ba 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f4.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.mre_f4.2596085838" + signature = "rusEFI 2020.10.15.mre_f4.640748912" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.mre_f4.2596085838" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.mre_f4.640748912" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:48 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:58:56 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_mre_f7.ini b/firmware/tunerstudio/generated/rusefi_mre_f7.ini index 38cda30cf1..93ecd27519 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f7.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.mre_f7.2596085838" + signature = "rusEFI 2020.10.15.mre_f7.640748912" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.mre_f7.2596085838" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.mre_f7.640748912" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:46 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:58:53 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini index f821360ce7..1838340aa4 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.prometheus_405.1925279141" + signature = "rusEFI 2020.10.15.prometheus_405.1854343583" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.prometheus_405.1925279141" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.prometheus_405.1854343583" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:52 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:59:01 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini index d598bc01f4..b5adc369ac 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.prometheus_469.1925279141" + signature = "rusEFI 2020.10.15.prometheus_469.1854343583" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.prometheus_469.1925279141" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.prometheus_469.1854343583" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:51 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:58:59 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini index a8f80400ab..7a931e5391 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.proteus_f4.1345656303" + signature = "rusEFI 2020.10.15.proteus_f4.1968121740" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.proteus_f4.1345656303" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.proteus_f4.1968121740" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:56 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:59:04 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini index 2ad63f303a..06529a0a60 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.10.15.proteus_f7.1345656303" + signature = "rusEFI 2020.10.15.proteus_f7.1968121740" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.10.15.proteus_f7.1345656303" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.10.15.proteus_f7.1968121740" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -74,7 +74,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 02:41:54 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Thu Oct 15 12:59:03 UTC 2020 pageSize = 20000 page = 1 diff --git a/firmware/util/containers/counter64.cpp b/firmware/util/containers/counter64.cpp deleted file mode 100644 index b541c1ca72..0000000000 --- a/firmware/util/containers/counter64.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * counter64.cpp - * - * Created on: Mar 31, 2019 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#include "counter64.h" - -/** - * The main use-case of this class is to keep track of a 64-bit global number of CPU ticks from reset. - * - * stm32f4 hardware has a 32-bit Cycle Count Register (CYCCNT), which is incremented with every CPU cycle. - * With 32 bits and 168MHz speed this counter overflows every 4B/168M = 23 seconds. The job of this class is to - * keep track of the current CYCCNT value, detect these overflows, and provide a nice, - * clean 64 bit global cycle counter. - * - * In order for this to function, it's your responsibility to invoke offer() method at least once a second. - */ -Overflow64Counter::Overflow64Counter() { - state.highBits = 0; - state.lowBits = 0; -} - -/** - * in order to have atomic writes this should be invoked within a critical section - */ -void updateAndSet(State64 *state, uint32_t value) { - if (value < state->lowBits) { - // new value less than previous value means there was an overflow in that 32 bit counter - state->highBits += 0x100000000LL; - } - state->lowBits = value; -} - -#if EFI_UNIT_TEST -efitime_t Overflow64Counter::update(uint32_t value) { - updateAndSet(&state, value); - return state.highBits + state.lowBits; -} -#endif - diff --git a/firmware/util/containers/counter64.h b/firmware/util/containers/counter64.h deleted file mode 100644 index 8696f654ff..0000000000 --- a/firmware/util/containers/counter64.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * @file counter64.h - * - * Created on: Mar 31, 2019 - * @author Andrey Belomutskiy, (c) 2012-2020 - */ - -#pragma once - -#include "global.h" - -typedef struct { - // todo: would probably be better to keep the high bits as 32 bit field to be sure - volatile efitime_t highBits; - volatile uint32_t lowBits; -} State64; - -void updateAndSet(State64 *state, uint32_t value); - -class Overflow64Counter -{ - public: - Overflow64Counter(); - - efitime_t get(); -#if EFI_UNIT_TEST - efitime_t update(uint32_t value); -#endif - - State64 state; -}; diff --git a/firmware/util/util.mk b/firmware/util/util.mk index 534439946b..3012b3cd71 100644 --- a/firmware/util/util.mk +++ b/firmware/util/util.mk @@ -8,7 +8,6 @@ UTILSRC = \ UTILSRC_CPP = \ $(UTIL_DIR)/containers/cyclic_buffer.cpp \ $(UTIL_DIR)/containers/listener_array.cpp \ - $(UTIL_DIR)/containers/counter64.cpp \ $(UTIL_DIR)/containers/local_version_holder.cpp \ $(UTIL_DIR)/containers/table_helper.cpp \ $(UTIL_DIR)/math/biquad.cpp \ diff --git a/unit_tests/tests/test_binary_log.cpp b/unit_tests/tests/test_binary_log.cpp index 7a42f10f3b..7a44eb18a2 100644 --- a/unit_tests/tests/test_binary_log.cpp +++ b/unit_tests/tests/test_binary_log.cpp @@ -1,18 +1,32 @@ #include "log_field.h" +#include "buffered_writer.h" #include +using ::testing::_; using ::testing::ElementsAre; +using ::testing::StrictMock; + +class MockWriter : public Writer { +public: + MOCK_METHOD(size_t, write, (const char* buffer, size_t count), (override)); + MOCK_METHOD(size_t, flush, (), (override)); +}; TEST(BinaryLogField, FieldHeader) { scaled_channel channel; LogField field(channel, "name", "units", 2); - char buffer[56]; - memset(buffer, 0xAA, sizeof(buffer)); + char buffer[55]; + StrictMock bufWriter; + EXPECT_CALL(bufWriter, write(_, 55)) + .WillOnce([&] (const char* buf, size_t count) { + memcpy(buffer, buf, count); + return 0; + }); // Should write 55 bytes - EXPECT_EQ(55, field.writeHeader(buffer)); + field.writeHeader(bufWriter); // Expect correctly written header EXPECT_THAT(buffer, ElementsAre( @@ -28,10 +42,7 @@ TEST(BinaryLogField, FieldHeader) { // Transform - we always use 0 0, 0, 0, 0, // Digits - 2, as configured - 2, - - // After end should be 0xAA, not touched - 0xAA + 2 )); } diff --git a/unit_tests/tests/test_util.cpp b/unit_tests/tests/test_util.cpp index e13f8f7b9b..968406bb81 100644 --- a/unit_tests/tests/test_util.cpp +++ b/unit_tests/tests/test_util.cpp @@ -22,7 +22,6 @@ #include "crc.h" #include "fl_stack.h" #include "io_pins.h" -#include "counter64.h" #include "efi_gpio.h" #include "efilib.h" @@ -66,20 +65,6 @@ TEST(util, crc) { assertEqualsM("crc32 line inc", 0x4775a7b1, c); } - -TEST(util, Overflow64Counter) { - print("*************************************** testOverflow64Counter\r\n"); - - Overflow64Counter o; - ASSERT_EQ(0, o.update(0)); - ASSERT_EQ(10, o.update(10)); - - ASSERT_EQ(20, o.update(20)); - - // overflow - ASSERT_EQ(4294967296, o.update(0)); -} - TEST(util, cyclicBufferContains) { cyclic_buffer sb; sb.add(10);