From 4ecfdd24b5418b02d3ed39c26474759a943eee27 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 14 Jan 2015 18:03:39 -0600 Subject: [PATCH] auto-sync --- firmware/console/status_loop.h | 6 +- firmware/console/tunerstudio/tunerstudio.cpp | 82 +++++++++---------- firmware/console/tunerstudio/tunerstudio.h | 11 +-- firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/flash_main.cpp | 44 +++++----- firmware/controllers/flash_main.h | 2 +- .../trigger/trigger_emulator_algo.cpp | 12 +-- .../trigger/trigger_emulator_algo.h | 2 +- firmware/development/engine_emulator.cpp | 4 +- firmware/development/engine_emulator.h | 2 +- firmware/development/trigger_emulator.cpp | 4 +- firmware/development/trigger_emulator.h | 2 +- firmware/hw_layer/HIP9011.cpp | 20 ++--- firmware/hw_layer/HIP9011.h | 2 +- firmware/hw_layer/hardware.cpp | 6 +- firmware/hw_layer/max31855.cpp | 22 ++--- firmware/hw_layer/max31855.h | 11 +-- firmware/rusefi.cpp | 4 +- firmware/util/datalogging.cpp | 4 +- 19 files changed, 112 insertions(+), 130 deletions(-) diff --git a/firmware/console/status_loop.h b/firmware/console/status_loop.h index f693b9af6f..7a962a5efd 100644 --- a/firmware/console/status_loop.h +++ b/firmware/console/status_loop.h @@ -24,12 +24,12 @@ extern "C" #endif /* __cplusplus */ void writeLogLine(void); -bool getFullLog(void); -void setFullLog(int value); -void sayOsHello(void); #ifdef __cplusplus } #endif /* __cplusplus */ +bool getFullLog(void); +void setFullLog(int value); + #endif /* CONSOLE_LOOP_H_ */ diff --git a/firmware/console/tunerstudio/tunerstudio.cpp b/firmware/console/tunerstudio/tunerstudio.cpp index 43b82c2255..99b3b47a67 100644 --- a/firmware/console/tunerstudio/tunerstudio.cpp +++ b/firmware/console/tunerstudio/tunerstudio.cpp @@ -72,7 +72,7 @@ BaseChannel * getTsSerialDevice(void) { #endif } -static LoggingWithStorage logger; +static Logging *logger; extern persistent_config_s configWorkingCopy; extern persistent_config_container_s persistentState; @@ -108,30 +108,30 @@ extern TunerStudioState tsState; static void printStats(void) { #if EFI_PROD_CODE if (!isSerialOverUart()) { - scheduleMsg(&logger, "TS RX on %s%d/TX on %s%d @%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN, + scheduleMsg(logger, "TS RX on %s%d/TX on %s%d @%d", portname(TS_SERIAL_RX_PORT), TS_SERIAL_RX_PIN, portname(TS_SERIAL_TX_PORT), TS_SERIAL_TX_PIN, boardConfiguration->tunerStudioSerialSpeed); } #endif /* EFI_PROD_CODE */ - scheduleMsg(&logger, "TunerStudio total/error counter=%d/%d H=%d / O counter=%d size=%d / P=%d / B=%d", tsCounter, tsState.errorCounter, tsState.queryCommandCounter, tsState.outputChannelsCommandCounter, + scheduleMsg(logger, "TunerStudio total/error counter=%d/%d H=%d / O counter=%d size=%d / P=%d / B=%d", tsCounter, tsState.errorCounter, tsState.queryCommandCounter, tsState.outputChannelsCommandCounter, sizeof(tsOutputChannels), tsState.readPageCommandsCounter, tsState.burnCommandCounter); - scheduleMsg(&logger, "TunerStudio W counter=%d / C = %d / P = %d / current page %d", tsState.writeValueCommandCounter, tsState.writeChunkCommandCounter, + scheduleMsg(logger, "TunerStudio W counter=%d / C = %d / P = %d / current page %d", tsState.writeValueCommandCounter, tsState.writeChunkCommandCounter, tsState.pageCommandCounter, tsState.currentPageId); - scheduleMsg(&logger, "page size=%d", sizeof(engine_configuration_s)); + scheduleMsg(logger, "page size=%d", sizeof(engine_configuration_s)); -// scheduleMsg(&logger, "analogChartFrequency %d", +// scheduleMsg(logger, "analogChartFrequency %d", // (int) (&engineConfiguration->analogChartFrequency) - (int) engineConfiguration); // // int fuelMapOffset = (int) (&engineConfiguration->fuelTable) - (int) engineConfiguration; -// scheduleMsg(&logger, "fuelTable %d", fuelMapOffset); +// scheduleMsg(logger, "fuelTable %d", fuelMapOffset); // int offset = (int) (&boardConfiguration->hip9011Gain) - (int) engineConfiguration; - scheduleMsg(&logger, "hip9011Gain %d", offset); + scheduleMsg(logger, "hip9011Gain %d", offset); // offset = (int) (&engineConfiguration->crankingCycleBins) - (int) engineConfiguration; - scheduleMsg(&logger, "crankingCycleBins %d", offset); + scheduleMsg(logger, "crankingCycleBins %d", offset); offset = (int) (&engineConfiguration->engineCycle) - (int) engineConfiguration; - scheduleMsg(&logger, "engineCycle %d", offset); + scheduleMsg(logger, "engineCycle %d", offset); } static void setTsSpeed(int value) { @@ -145,7 +145,7 @@ void tunerStudioWriteData(const uint8_t * buffer, int size) { void tunerStudioDebug(const char *msg) { #if EFI_TUNER_STUDIO_VERBOSE - scheduleMsg(&logger, "%s", msg); + scheduleMsg(logger, "%s", msg); printStats(); #endif } @@ -183,7 +183,7 @@ void handlePageSelectCommand(ts_response_format_e mode, uint16_t pageId) { tsState.pageCommandCounter++; tsState.currentPageId = pageId; - scheduleMsg(&logger, "page %d selected", tsState.currentPageId); + scheduleMsg(logger, "page %d selected", tsState.currentPageId); tsSendResponse(mode, NULL, 0); } @@ -194,17 +194,17 @@ void handlePageSelectCommand(ts_response_format_e mode, uint16_t pageId) { void handleWriteChunkCommand(ts_response_format_e mode, short offset, short count, void *content) { tsState.writeChunkCommandCounter++; - scheduleMsg(&logger, "receiving page %d chunk offset %d size %d", tsState.currentPageId, offset, count); + scheduleMsg(logger, "receiving page %d chunk offset %d size %d", tsState.currentPageId, offset, count); if (offset > getTunerStudioPageSize(tsState.currentPageId)) { - scheduleMsg(&logger, "ERROR offset %d", offset); + scheduleMsg(logger, "ERROR offset %d", offset); tunerStudioError("ERROR: out of range"); offset = 0; } if (count > getTunerStudioPageSize(tsState.currentPageId)) { tunerStudioError("ERROR: unexpected count"); - scheduleMsg(&logger, "ERROR count %d", count); + scheduleMsg(logger, "ERROR count %d", count); count = 0; } @@ -226,15 +226,15 @@ void handleWriteValueCommand(ts_response_format_e mode, uint16_t page, uint16_t //tunerStudioDebug("got W (Write)"); // we can get a lot of these #if EFI_TUNER_STUDIO_VERBOSE -// scheduleMsg(&logger, "Page number %d\r\n", pageId); // we can get a lot of these +// scheduleMsg(logger, "Page number %d\r\n", pageId); // we can get a lot of these #endif // int size = sizeof(TunerStudioWriteValueRequest); -// scheduleMsg(&logger, "Reading %d\r\n", size); +// scheduleMsg(logger, "Reading %d\r\n", size); if (offset > getTunerStudioPageSize(tsState.currentPageId)) { tunerStudioError("ERROR: out of range2"); - scheduleMsg(&logger, "ERROR offset %d", offset); + scheduleMsg(logger, "ERROR offset %d", offset); offset = 0; return; } @@ -242,12 +242,12 @@ void handleWriteValueCommand(ts_response_format_e mode, uint16_t page, uint16_t efitimems_t nowMs = currentTimeMillis(); if (nowMs - previousWriteReportMs > 5) { previousWriteReportMs = nowMs; - scheduleMsg(&logger, "page %d offset %d: value=%d", tsState.currentPageId, offset, value); + scheduleMsg(logger, "page %d offset %d: value=%d", tsState.currentPageId, offset, value); } getWorkingPageAddr(tsState.currentPageId)[offset] = value; -// scheduleMsg(&logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin); +// scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin); } static void sendErrorCode(void) { @@ -260,11 +260,11 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t tsState.currentPageId = pageId; #if EFI_TUNER_STUDIO_VERBOSE - scheduleMsg(&logger, "Page requested: page %d offset=%d count=%d", (int)tsState.currentPageId, offset, count); + scheduleMsg(logger, "Page requested: page %d offset=%d count=%d", (int)tsState.currentPageId, offset, count); #endif if (tsState.currentPageId > MAX_PAGE_ID) { - scheduleMsg(&logger, "invalid Page number %x", tsState.currentPageId); + scheduleMsg(logger, "invalid Page number %x", tsState.currentPageId); // something is not right here tsState.currentPageId = 0; @@ -275,7 +275,7 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t int size = getTunerStudioPageSize(tsState.currentPageId); if (size < offset + count) { - scheduleMsg(&logger, "invalid offset/count %d/%d", offset, count); + scheduleMsg(logger, "invalid offset/count %d/%d", offset, count); sendErrorCode(); return; } @@ -283,7 +283,7 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t const uint8_t *addr = (const uint8_t *) (getWorkingPageAddr(tsState.currentPageId) + offset); tsSendResponse(mode, addr, count); #if EFI_TUNER_STUDIO_VERBOSE - scheduleMsg(&logger, "Sending %d done", count); + scheduleMsg(logger, "Sending %d done", count); #endif } @@ -300,7 +300,7 @@ void handleBurnCommand(ts_response_format_e mode, uint16_t page) { #if EFI_TUNER_STUDIO_VERBOSE // pointless since we only have one page now -// scheduleMsg(&logger, "Page number %d", tsState.currentPageId); +// scheduleMsg(logger, "Page number %d", tsState.currentPageId); #endif // todo: how about some multi-threading? @@ -311,7 +311,7 @@ void handleBurnCommand(ts_response_format_e mode, uint16_t page) { #endif incrementGlobalConfigurationVersion(); tunerStudioWriteCrcPacket(TS_RESPONSE_BURN_OK, NULL, 0); - scheduleMsg(&logger, "burned in (ms): %d", currentTimeMillis() - nowMs); + scheduleMsg(logger, "burned in (ms): %d", currentTimeMillis() - nowMs); } static TunerStudioReadRequest readRequest; @@ -319,7 +319,7 @@ static short int pageIn; static bool handlePlainCommand(uint8_t command) { if (command == TS_HELLO_COMMAND) { - scheduleMsg(&logger, "Got naked Query command"); + scheduleMsg(logger, "Got naked Query command"); handleQueryCommand(TS_PLAIN); return true; } else if (command == 't' || command == 'T') { @@ -331,7 +331,7 @@ static bool handlePlainCommand(uint8_t command) { handlePageSelectCommand(TS_PLAIN, pageIn); return true; } else if (command == TS_READ_COMMAND) { - //scheduleMsg(&logger, "Got naked READ PAGE???"); + //scheduleMsg(logger, "Got naked READ PAGE???"); int recieved = chSequentialStreamRead(getTsSerialDevice(), (uint8_t *)&readRequest, sizeof(readRequest)); if (recieved != sizeof(readRequest)) { // todo: handler error @@ -340,7 +340,7 @@ static bool handlePlainCommand(uint8_t command) { handlePageReadCommand(TS_PLAIN, readRequest.page, readRequest.offset, readRequest.count); return true; } else if (command == TS_OUTPUT_COMMAND) { - //scheduleMsg(&logger, "Got naked Channels???"); + //scheduleMsg(logger, "Got naked Channels???"); handleOutputChannelsCommand(TS_PLAIN); return true; } else if (command == 'F') { @@ -416,7 +416,7 @@ static msg_t tsThreadEntryPoint(void *arg) { tunerStudioError("ERROR: no command"); continue; } -// scheduleMsg(&logger, "Got first=%x=[%c]", firstByte, firstByte); +// scheduleMsg(logger, "Got first=%x=[%c]", firstByte, firstByte); if (handlePlainCommand(firstByte)) continue; @@ -425,12 +425,12 @@ static msg_t tsThreadEntryPoint(void *arg) { tunerStudioError("ERROR: no second"); continue; } -// scheduleMsg(&logger, "Got secondByte=%x=[%c]", secondByte, secondByte); +// scheduleMsg(logger, "Got secondByte=%x=[%c]", secondByte, secondByte); uint32_t incomingPacketSize = firstByte * 256 + secondByte; if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(crcIoBuffer) - CRC_WRAPPING_SIZE)) { - scheduleMsg(&logger, "TunerStudio: invalid size: %d", incomingPacketSize); + scheduleMsg(logger, "TunerStudio: invalid size: %d", incomingPacketSize); tunerStudioError("ERROR: size"); sendErrorCode(); continue; @@ -444,18 +444,18 @@ static msg_t tsThreadEntryPoint(void *arg) { char command = crcIoBuffer[0]; if (!isKnownCommand(command)) { - scheduleMsg(&logger, "unexpected command %x", command); + scheduleMsg(logger, "unexpected command %x", command); sendErrorCode(); continue; } -// scheduleMsg(&logger, "TunerStudio: reading %d+4 bytes(s)", incomingPacketSize); +// scheduleMsg(logger, "TunerStudio: reading %d+4 bytes(s)", incomingPacketSize); recieved = chnReadTimeout(getTsSerialDevice(), (uint8_t * ) (crcIoBuffer + 1), incomingPacketSize + CRC_VALUE_SIZE - 1, MS2ST(TS_READ_TIMEOUT)); int expectedSize = incomingPacketSize + CRC_VALUE_SIZE - 1; if (recieved != expectedSize) { - scheduleMsg(&logger, "got ONLY %d for packet size %d/%d for command %c", recieved, incomingPacketSize, + scheduleMsg(logger, "got ONLY %d for packet size %d/%d for command %c", recieved, incomingPacketSize, expectedSize, command); tunerStudioError("ERROR: not enough"); continue; @@ -467,17 +467,17 @@ static msg_t tsThreadEntryPoint(void *arg) { uint32_t actualCrc = crc32(crcIoBuffer, incomingPacketSize); if (actualCrc != expectedCrc) { - scheduleMsg(&logger, "TunerStudio: CRC %x %x %x %x", crcIoBuffer[incomingPacketSize + 0], + scheduleMsg(logger, "TunerStudio: CRC %x %x %x %x", crcIoBuffer[incomingPacketSize + 0], crcIoBuffer[incomingPacketSize + 1], crcIoBuffer[incomingPacketSize + 2], crcIoBuffer[incomingPacketSize + 3]); - scheduleMsg(&logger, "TunerStudio: command %c actual CRC %x/expected %x", crcIoBuffer[0], actualCrc, + scheduleMsg(logger, "TunerStudio: command %c actual CRC %x/expected %x", crcIoBuffer[0], actualCrc, expectedCrc); tunerStudioError("ERROR: CRC issue"); continue; } -// scheduleMsg(&logger, "TunerStudio: P00-07 %x %x %x %x %x %x %x %x", crcIoBuffer[0], crcIoBuffer[1], +// scheduleMsg(logger, "TunerStudio: P00-07 %x %x %x %x %x %x %x %x", crcIoBuffer[0], crcIoBuffer[1], // crcIoBuffer[2], crcIoBuffer[3], crcIoBuffer[4], crcIoBuffer[5], crcIoBuffer[6], crcIoBuffer[7]); int success = tunerStudioHandleCrcCommand(crcIoBuffer, incomingPacketSize); @@ -507,13 +507,13 @@ void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uin uint32_t crc = crc32((void *) (crcIoBuffer + 2), (uint32_t) (size + 1)); *(uint32_t *) (crcIoBuffer + 2 + 1 + size) = SWAP_UINT32(crc); -// scheduleMsg(&logger, "TunerStudio: CRC command %x size %d", command, size); +// scheduleMsg(logger, "TunerStudio: CRC command %x size %d", command, size); tunerStudioWriteData(crcIoBuffer, size + 2 + 1 + 4); // with size, command and CRC } -void startTunerStudioConnectivity(void) { - initLogging(&logger, "tuner studio"); +void startTunerStudioConnectivity(Logging *sharedLogger) { + logger = sharedLogger; if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0)) firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0)); diff --git a/firmware/console/tunerstudio/tunerstudio.h b/firmware/console/tunerstudio/tunerstudio.h index 18a0a0aa2c..e2667605f7 100644 --- a/firmware/console/tunerstudio/tunerstudio.h +++ b/firmware/console/tunerstudio/tunerstudio.h @@ -16,19 +16,10 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputChannels); - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -void startTunerStudioConnectivity(void); +void startTunerStudioConnectivity(Logging *sharedLogger); void syncTunerStudioCopy(void); void tunerStudioWriteCrcPacket(const uint8_t command, const void *buf, const uint16_t size); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #if defined __GNUC__ // GCC #define pre_packed diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 1aa191ca1d..8cf1485a2d 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -340,7 +340,7 @@ void initEngineContoller(Logging *sharedLogger, Engine *engine) { #if EFI_TUNER_STUDIO if (engineConfiguration->isTunerStudioEnabled) { - startTunerStudioConnectivity(); + startTunerStudioConnectivity(sharedLogger); } #endif diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index 0622a95413..db3c48a40a 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -26,7 +26,7 @@ static bool needToWriteConfiguration = false; EXTERN_ENGINE; -static LoggingWithStorage logger; +static Logging* logger; extern persistent_config_container_s persistentState; @@ -41,7 +41,7 @@ crc_t flashStateCrc(persistent_config_container_s *state) { } void setNeedToWriteConfiguration(void) { - scheduleMsg(&logger, "Scheduling configuration write"); + scheduleMsg(logger, "Scheduling configuration write"); needToWriteConfiguration = true; } @@ -55,26 +55,26 @@ void writeToFlashIfPending() { } // todo: technically we need a lock here, realistically we should be fine. needToWriteConfiguration = false; - scheduleMsg(&logger, "Writing pending configuration"); + scheduleMsg(logger, "Writing pending configuration"); writeToFlash(); } extern uint32_t maxLockTime; void writeToFlash(void) { - scheduleMsg(&logger, " !!!!!!!!!!!!!!!!!!!! BE SURE NOT WRITE WITH IGNITION ON !!!!!!!!!!!!!!!!!!!!"); + scheduleMsg(logger, " !!!!!!!!!!!!!!!!!!!! BE SURE NOT WRITE WITH IGNITION ON !!!!!!!!!!!!!!!!!!!!"); persistentState.size = PERSISTENT_SIZE; persistentState.version = FLASH_DATA_VERSION; - scheduleMsg(&logger, "flash compatible with %d", persistentState.version); + scheduleMsg(logger, "flash compatible with %d", persistentState.version); crc_t result = flashStateCrc(&persistentState); persistentState.value = result; - scheduleMsg(&logger, "Reseting flash: size=%d", PERSISTENT_SIZE); + scheduleMsg(logger, "Reseting flash: size=%d", PERSISTENT_SIZE); flashErase(FLASH_ADDR, PERSISTENT_SIZE); - scheduleMsg(&logger, "Flashing with CRC=%d", result); + scheduleMsg(logger, "Flashing with CRC=%d", result); efitimems_t nowMs = currentTimeMillis(); result = flashWrite(FLASH_ADDR, (const char *) &persistentState, PERSISTENT_SIZE); - scheduleMsg(&logger, "Flash programmed in (ms): %d", currentTimeMillis() - nowMs); - scheduleMsg(&logger, "Flashing result: %d", result); + scheduleMsg(logger, "Flash programmed in (ms): %d", currentTimeMillis() - nowMs); + scheduleMsg(logger, "Flashing result: %d", result); maxLockTime = 0; } @@ -82,13 +82,13 @@ static bool isValidCrc(persistent_config_container_s *state) { crc_t result = flashStateCrc(state); int isValidCrc_b = result == state->value; if (!isValidCrc_b) { - scheduleMsg(&logger, "CRC got %d while %d expected", result, state->value); + scheduleMsg(logger, "CRC got %d while %d expected", result, state->value); } return isValidCrc_b; } static void doResetConfiguration(void) { - resetConfigurationExt(&logger, engineConfiguration->engineType, engine); + resetConfigurationExt(logger, engineConfiguration->engineType, engine); } static bool hasValidEngineType(engine_configuration_s *engineConfiguration) { @@ -97,21 +97,21 @@ static bool hasValidEngineType(engine_configuration_s *engineConfiguration) { } void readFromFlash(void) { - printMsg(&logger, "readFromFlash()"); + printMsg(logger, "readFromFlash()"); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); if (!isValidCrc(&persistentState)) { - printMsg(&logger, "Need to reset flash to default due to CRC"); - resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engine); + printMsg(logger, "Need to reset flash to default due to CRC"); + resetConfigurationExt(logger, DEFAULT_ENGINE_TYPE, engine); } else if (persistentState.version == FLASH_DATA_VERSION && persistentState.size == PERSISTENT_SIZE) { - printMsg(&logger, "Got valid configuration from flash!"); - applyNonPersistentConfiguration(&logger, engine); + printMsg(logger, "Got valid configuration from flash!"); + applyNonPersistentConfiguration(logger, engine); } else if (hasValidEngineType(engineConfiguration)) { - printMsg(&logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType); - resetConfigurationExt(&logger, engineConfiguration->engineType, engine); + printMsg(logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType); + resetConfigurationExt(logger, engineConfiguration->engineType, engine); } else { - printMsg(&logger, "Need to reset flash to default due to version change"); - resetConfigurationExt(&logger, DEFAULT_ENGINE_TYPE, engine); + printMsg(logger, "Need to reset flash to default due to version change"); + resetConfigurationExt(logger, DEFAULT_ENGINE_TYPE, engine); } // we can only change the state after the CRC check engineConfiguration->firmwareVersion = getRusEfiVersion(); @@ -122,8 +122,8 @@ static void rewriteConfig(Engine *engine) { writeToFlash(); } -void initFlash(Engine *engine) { - initLogging(&logger, "Flash memory"); +void initFlash(Logging *sharedLogger, Engine *engine) { + logger = sharedLogger; addConsoleAction("readconfig", readFromFlash); addConsoleAction("writeconfig", writeToFlash); diff --git a/firmware/controllers/flash_main.h b/firmware/controllers/flash_main.h index 335b121e90..afedd96af7 100644 --- a/firmware/controllers/flash_main.h +++ b/firmware/controllers/flash_main.h @@ -15,7 +15,7 @@ #define FLASH_DATA_VERSION 6130 void readFromFlash(void); -void initFlash(Engine *engine); +void initFlash(Logging *sharedLogger, Engine *engine); /** * Because of hardware-related issues, stm32f4 chip is totally diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index 3879ae4a3b..337b16114f 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -68,7 +68,7 @@ PwmConfig triggerSignal(swtchTms, sr); static int stopEmulationAtIndex = DO_NOT_STOP; static bool isEmulating = true; -static LoggingWithStorage logger; +static Logging *logger; static LocalVersionHolder localVersion; EXTERN_ENGINE; @@ -85,15 +85,15 @@ void setTriggerEmulatorRPM(int rpm, Engine *engine) { float gRpm = rpm * engineConfiguration->rpmMultiplier / 60.0; // per minute converted to per second triggerSignal.periodNt = US2NT(frequency2periodUs(gRpm)); } - scheduleMsg(&logger, "Emulating position sensor(s). RPM=%d", rpm); + scheduleMsg(logger, "Emulating position sensor(s). RPM=%d", rpm); } static void updateTriggerShapeIfNeeded(PwmConfig *state) { if (localVersion.isOld()) { - scheduleMsg(&logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(), + scheduleMsg(logger, "Stimulator: updating trigger shape: %d/%d %d", localVersion.getVersion(), getGlobalConfigurationVersion(), currentTimeMillis()); - applyNonPersistentConfiguration(&logger, engine); + applyNonPersistentConfiguration(logger, engine); TriggerShape *s = &engine->triggerShape; int *pinStates[PWM_PHASE_MAX_WAVE_PER_PWM] = { s->wave.waves[0].pinStates, s->wave.waves[1].pinStates, @@ -132,8 +132,8 @@ static void resumeStimulator(Engine *engine) { stopEmulationAtIndex = DO_NOT_STOP; } -void initTriggerEmulatorLogic(Engine *engine) { - initLogging(&logger, "position sensor(s) emulator"); +void initTriggerEmulatorLogic(Logging *sharedLogger, Engine *engine) { + logger = sharedLogger; TriggerShape *s = &engine->triggerShape; setTriggerEmulatorRPM(engineConfiguration->bc.triggerSimulatorFrequency, engine); diff --git a/firmware/controllers/trigger/trigger_emulator_algo.h b/firmware/controllers/trigger/trigger_emulator_algo.h index f365110e94..cfff4ffc79 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.h +++ b/firmware/controllers/trigger/trigger_emulator_algo.h @@ -21,6 +21,6 @@ public: void handleEmulatorCallback(PwmConfig *state, int stateIndex); }; -void initTriggerEmulatorLogic(Engine *engine); +void initTriggerEmulatorLogic(Logging *sharedLogger, Engine *engine); #endif /* TRIGGER_EMULATOR_ALGO_H_ */ diff --git a/firmware/development/engine_emulator.cpp b/firmware/development/engine_emulator.cpp index 2210cb185b..0e8b1d8dc3 100644 --- a/firmware/development/engine_emulator.cpp +++ b/firmware/development/engine_emulator.cpp @@ -93,7 +93,7 @@ static void initECUstimulator(Engine *engine) { chThdCreateStatic(eeThreadStack, sizeof(eeThreadStack), NORMALPRIO, (tfunc_t) eeThread, engine); } -void initEngineEmulator(Engine *engine) { +void initEngineEmulator(Logging *sharedLogger, Engine *engine) { if (hasFirmwareError()) return; @@ -102,5 +102,5 @@ void initEngineEmulator(Engine *engine) { #endif /* EFI_POTENTIOMETER */ //initECUstimulator(); - initTriggerEmulator(engine); + initTriggerEmulator(sharedLogger, engine); } diff --git a/firmware/development/engine_emulator.h b/firmware/development/engine_emulator.h index 66d13d620b..51ecb89965 100644 --- a/firmware/development/engine_emulator.h +++ b/firmware/development/engine_emulator.h @@ -9,6 +9,6 @@ #define ENGINE_EMULATOR_H_ #include "engine.h" -void initEngineEmulator(Engine *engine); +void initEngineEmulator(Logging *sharedLogger, Engine *engine); #endif /* ENGINE_EMULATOR_H_ */ diff --git a/firmware/development/trigger_emulator.cpp b/firmware/development/trigger_emulator.cpp index 50e94a4388..fa8f11ec0c 100644 --- a/firmware/development/trigger_emulator.cpp +++ b/firmware/development/trigger_emulator.cpp @@ -27,7 +27,7 @@ extern PwmConfig triggerSignal; static OutputPin emulatorOutputs[3]; -void initTriggerEmulator(Engine *engine) { +void initTriggerEmulator(Logging *sharedLogger, Engine *engine) { engine_configuration_s *engineConfiguration = engine->engineConfiguration; board_configuration_s *boardConfiguration = &engineConfiguration->bc; @@ -51,7 +51,7 @@ void initTriggerEmulator(Engine *engine) { &boardConfiguration->triggerSimulatorPinModes[2]); #endif /* EFI_PROD_CODE */ - initTriggerEmulatorLogic(engine); + initTriggerEmulatorLogic(sharedLogger, engine); #else print("No position sensor(s) emulation\r\n"); #endif /* EFI_EMULATE_POSITION_SENSORS */ diff --git a/firmware/development/trigger_emulator.h b/firmware/development/trigger_emulator.h index 415ea0372b..2a8158b5c3 100644 --- a/firmware/development/trigger_emulator.h +++ b/firmware/development/trigger_emulator.h @@ -14,7 +14,7 @@ #include "trigger_structure.h" #include "engine.h" -void initTriggerEmulator(Engine *engine); +void initTriggerEmulator(Logging *sharedLogger, Engine *engine); void setTriggerEmulatorRPM(int value, Engine *engine); #endif /* DIST_EMULATOR_H_ */ diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index e5c096c522..967ad3393f 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -61,7 +61,7 @@ static bool_t isSendingSpiCommand = false; static scheduling_s startTimer[2]; static scheduling_s endTimer[2]; -static LoggingWithStorage logger; +static Logging *logger; // SPI_CR1_BR_1 // 5MHz // SPI_CR1_CPHA Clock Phase @@ -92,14 +92,14 @@ EXTERN_ENGINE ; static void showHipInfo(void) { - printSpiState(&logger, boardConfiguration); - scheduleMsg(&logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore)); + printSpiState(logger, boardConfiguration); + scheduleMsg(logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore)); - scheduleMsg(&logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex); - scheduleMsg(&logger, "integrator index=%d", currentIntergratorIndex); + scheduleMsg(logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex); + scheduleMsg(logger, "integrator index=%d", currentIntergratorIndex); - scheduleMsg(&logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse); - scheduleMsg(&logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); + scheduleMsg(logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse); + scheduleMsg(logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount); } void setHip9011FrankensoPinout(void) { @@ -189,10 +189,10 @@ static void endOfSpiCommunication(SPIDriver *spip) { isSendingSpiCommand = false; } -void initHip9011(void) { +void initHip9011(Logging *sharedLogger) { if (!boardConfiguration->isHip9011Enabled) return; - initLogging(&logger, "HIP driver"); + logger = sharedLogger; // todo: apply new properties on the fly prepareHip9011RpmLookup( @@ -207,7 +207,7 @@ void initHip9011(void) { outputPinRegisterExt2("hip int/hold", &intHold, boardConfiguration->hip9011IntHoldPin, &DEFAULT_OUTPUT); outputPinRegisterExt2("hip CS", &hipCs, boardConfiguration->hip9011CsPin, &DEFAULT_OUTPUT); - scheduleMsg(&logger, "Starting HIP9011/TPIC8101 driver"); + scheduleMsg(logger, "Starting HIP9011/TPIC8101 driver"); spiStart(driver, &spicfg); bandIndex = getHip9011BandIndex(engineConfiguration->cylinderBore); diff --git a/firmware/hw_layer/HIP9011.h b/firmware/hw_layer/HIP9011.h index f3922c66df..f1a3973533 100644 --- a/firmware/hw_layer/HIP9011.h +++ b/firmware/hw_layer/HIP9011.h @@ -29,7 +29,7 @@ #define HIP_THREAD_PERIOD 100 -void initHip9011(void); +void initHip9011(Logging *sharedLogger); void setHip9011FrankensoPinout(void); #endif /* HIP9011_H_ */ diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 36a5b80022..457daa20ed 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -202,7 +202,7 @@ void initHardware(Logging *l, Engine *engine) { palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP); - initFlash(engine); + initFlash(sharedLogger, engine); /** * this call reads configuration from flash memory or sets default configuration * if flash state does not look right. @@ -244,7 +244,7 @@ void initHardware(Logging *l, Engine *engine) { initOutputPins(); #if EFI_MAX_31855 - initMax31855(getSpiDevice(boardConfiguration->max31855spiDevice), + initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), boardConfiguration->max31855_cs); #endif /* EFI_MAX_31855 */ @@ -269,7 +269,7 @@ void initHardware(Logging *l, Engine *engine) { #endif #if EFI_HIP_9011 - initHip9011(); + initHip9011(sharedLogger); #endif /* EFI_HIP_9011 */ #if EFI_FILE_LOGGING diff --git a/firmware/hw_layer/max31855.cpp b/firmware/hw_layer/max31855.cpp index 806b8040fd..42b6d2297c 100644 --- a/firmware/hw_layer/max31855.cpp +++ b/firmware/hw_layer/max31855.cpp @@ -29,7 +29,7 @@ static SPIDriver *driver; -static LoggingWithStorage logger; +static Logging* logger; static SPIConfig spiConfig[MAX31855_CS_COUNT]; @@ -37,13 +37,13 @@ EXTERN_ENGINE; static void showEgtInfo(void) { #if EFI_PROD_CODE - printSpiState(&logger, boardConfiguration); + printSpiState(logger, boardConfiguration); - scheduleMsg(&logger, "EGT spi: %d", boardConfiguration->max31855spiDevice); + scheduleMsg(logger, "EGT spi: %d", boardConfiguration->max31855spiDevice); for (int i = 0; i < MAX31855_CS_COUNT; i++) { if (boardConfiguration->max31855_cs[i] != GPIO_UNASSIGNED) { - scheduleMsg(&logger, "%d ETG @ %s", i, hwPortname(boardConfiguration->max31855_cs[i])); + scheduleMsg(logger, "%d ETG @ %s", i, hwPortname(boardConfiguration->max31855_cs[i])); } } #endif @@ -120,29 +120,29 @@ uint16_t getEgtValue(int egtChannel) { static void egtRead(void) { if (driver == NULL) { - scheduleMsg(&logger, "No SPI selected for EGT"); + scheduleMsg(logger, "No SPI selected for EGT"); return; } - scheduleMsg(&logger, "Reading egt"); + scheduleMsg(logger, "Reading egt"); uint32_t egtPacket = readEgtPacket(0); max_32855_code code = getResultCode(egtPacket); - scheduleMsg(&logger, "egt %x code=%d %s", egtPacket, code, getMcCode(code)); + scheduleMsg(logger, "egt %x code=%d %s", egtPacket, code, getMcCode(code)); if (code != MC_INVALID) { int refBits = ((egtPacket & 0xFFFF) / 16); // bits 15:4 float refTemp = refBits / 16.0; - scheduleMsg(&logger, "reference temperature %f", refTemp); + scheduleMsg(logger, "reference temperature %f", refTemp); - scheduleMsg(&logger, "EGT temperature %d", GET_TEMPERATURE_C(egtPacket)); + scheduleMsg(logger, "EGT temperature %d", GET_TEMPERATURE_C(egtPacket)); } } -void initMax31855(SPIDriver *drv, egt_cs_array_t max31855_cs) { - initLogging(&logger, "EGT"); +void initMax31855(Logging *sharedLogger, SPIDriver *drv, egt_cs_array_t max31855_cs) { + logger = sharedLogger; driver = drv; diff --git a/firmware/hw_layer/max31855.h b/firmware/hw_layer/max31855.h index ec6ed8024a..6e63cdc783 100644 --- a/firmware/hw_layer/max31855.h +++ b/firmware/hw_layer/max31855.h @@ -11,16 +11,7 @@ #include "main.h" #include "engine_configuration.h" -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -void initMax31855(SPIDriver *drv, egt_cs_array_t max31855_cs); +void initMax31855(Logging *sharedLogger, SPIDriver *drv, egt_cs_array_t max31855_cs); uint16_t getEgtValue(int egtChannel); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - #endif /* MAX31855_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 3c5f13d254..658f780380 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -175,7 +175,7 @@ void runRusEfi(void) { #endif #if EFI_ENGINE_EMULATOR || defined(__DOXYGEN__) - initEngineEmulator(engine); + initEngineEmulator(&sharedLogger, engine); #endif startStatusThreads(engine); @@ -253,7 +253,7 @@ void firmwareError(const char *fmt, ...) { } } -static char UNUSED_RAM_SIZE[3500]; +static char UNUSED_RAM_SIZE[5500]; static char UNUSED_CCM_SIZE[8000] CCM_OPTIONAL; diff --git a/firmware/util/datalogging.cpp b/firmware/util/datalogging.cpp index 21b77b1edc..edf385185a 100644 --- a/firmware/util/datalogging.cpp +++ b/firmware/util/datalogging.cpp @@ -149,7 +149,7 @@ void vappendPrintf(Logging *logging, const char *fmt, va_list arg) { } int wasLocked = lockAnyContext(); vappendPrintfI(logging, fmt, arg); - if (wasLocked) { + if (!wasLocked) { unlockAnyContext(); } } @@ -314,7 +314,7 @@ void scheduleMsg(Logging *logging, const char *fmt, ...) { appendMsgPostfix(logging); scheduleLogging(logging); - if (wasLocked) { + if (!wasLocked) { unlockAnyContext(); } }