From 4b0d75ff926f89b0f31742bb0ee051a519b63f20 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 17 May 2021 02:44:02 -0700 Subject: [PATCH] make the simulator usable (#2717) * these start themselves now * dead * configure ports * start serial * dead * minimal pins * simulator logging works * why not enable lua * speeeeeed * start lua * spammy print --- firmware/console/binary/tunerstudio_io.cpp | 2 +- .../binary/tunerstudio_io_serial_ports.cpp | 2 +- firmware/controllers/lua/lua.cpp | 3 +- .../system/timer/signal_executor_sleep.cpp | 2 +- firmware/util/loggingcentral.cpp | 16 +---- simulator/main.c | 14 +--- simulator/simulator/boards.h | 10 --- simulator/simulator/efifeatures.h | 8 ++- simulator/simulator/framework.cpp | 68 ------------------- simulator/simulator/framework.h | 20 ------ simulator/simulator/global.h | 2 - simulator/simulator/rusEfiFunctionalTest.cpp | 13 ++-- 12 files changed, 24 insertions(+), 136 deletions(-) delete mode 100644 simulator/simulator/framework.h diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index 809c2d4da6..c8df7da382 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -15,7 +15,7 @@ EXTERN_ENGINE; -#if EFI_PROD_CODE +#if EFI_PROD_CODE || EFI_SIMULATOR size_t TsChannelBase::read(uint8_t* buffer, size_t size) { return readTimeout(buffer, size, SR5_READ_TIMEOUT); } diff --git a/firmware/console/binary/tunerstudio_io_serial_ports.cpp b/firmware/console/binary/tunerstudio_io_serial_ports.cpp index 77c8c93a9b..7618d26e80 100644 --- a/firmware/console/binary/tunerstudio_io_serial_ports.cpp +++ b/firmware/console/binary/tunerstudio_io_serial_ports.cpp @@ -6,7 +6,7 @@ #include "engine.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || EFI_SIMULATOR #include "tunerstudio.h" #include "tunerstudio_io.h" #include "connector_uart_dma.h" diff --git a/firmware/controllers/lua/lua.cpp b/firmware/controllers/lua/lua.cpp index 3cf49c3c0d..daa6856ffb 100644 --- a/firmware/controllers/lua/lua.cpp +++ b/firmware/controllers/lua/lua.cpp @@ -2,6 +2,7 @@ #include "rusefi_lua.h" #include "thread_controller.h" #include "perf_trace.h" +#include "thread_priority.h" #if EFI_LUA @@ -10,7 +11,7 @@ #define TAG "LUA " -#if EFI_PROD_CODE +#if EFI_PROD_CODE || EFI_SIMULATOR #include "ch.h" #include "engine.h" #include "tunerstudio_outputs.h" diff --git a/firmware/controllers/system/timer/signal_executor_sleep.cpp b/firmware/controllers/system/timer/signal_executor_sleep.cpp index cb26df8124..41dcbb06b5 100644 --- a/firmware/controllers/system/timer/signal_executor_sleep.cpp +++ b/firmware/controllers/system/timer/signal_executor_sleep.cpp @@ -83,7 +83,7 @@ static void doScheduleForLater(scheduling_s *scheduling, int delayUs, action_s a #if EFI_SIMULATOR if (action.getCallback() == (schfunc_t)&turnInjectionPinLow) { - printf("setTime cb=turnInjectionPinLow p=%d\r\n", (int)action.getArgument()); + //printf("setTime cb=turnInjectionPinLow p=%d\r\n", (int)action.getArgument()); } else { // printf("setTime cb=%d p=%d\r\n", (int)callback, (int)param); } diff --git a/firmware/util/loggingcentral.cpp b/firmware/util/loggingcentral.cpp index 4496583232..58aeb6f0d9 100644 --- a/firmware/util/loggingcentral.cpp +++ b/firmware/util/loggingcentral.cpp @@ -72,7 +72,7 @@ void LogBuffer::writeInternal(const char* buffer) { // for unit tests template class LogBuffer<10>; -#if EFI_PROD_CODE && EFI_TEXT_LOGGING +#if (EFI_PROD_CODE || EFI_SIMULATOR) && EFI_TEXT_LOGGING // This mutex protects the LogBuffer instances below chibios_rt::Mutex logBufferMutex; @@ -167,12 +167,6 @@ void startLoggingProcessor() { #endif // EFI_PROD_CODE -#if EFI_SIMULATOR -const char* swapOutputBuffers(size_t* actualOutputBufferSize) { - return nullptr; -} -#endif - #if EFI_UNIT_TEST || EFI_SIMULATOR extern bool verboseMode; #endif @@ -189,7 +183,7 @@ void efiPrintfInternal(const char *format, ...) { printf("\r\n"); } #endif -#if EFI_PROD_CODE && EFI_TEXT_LOGGING +#if (EFI_PROD_CODE || EFI_SIMULATOR) && EFI_TEXT_LOGGING for (unsigned int i = 0; i < strlen(format); i++) { // todo: open question which layer would not handle CR/LF properly? efiAssertVoid(OBD_PCM_Processor_Fault, format[i] != '\n', "No CRLF please"); @@ -222,10 +216,6 @@ void efiPrintfInternal(const char *format, ...) { // Push the buffer in to the written list so it can be written back chibios_rt::CriticalSectionLocker csl; - if ((void*)lineBuffer == (void*)&filledBuffers) { - __asm volatile("BKPT #0\n"); - } - filledBuffers.postI(lineBuffer); } #endif @@ -239,7 +229,7 @@ void efiPrintfInternal(const char *format, ...) { * This is a legacy function, most normal logging should use efiPrintf */ void scheduleLogging(Logging *logging) { -#if EFI_PROD_CODE && EFI_TEXT_LOGGING +#if (EFI_PROD_CODE || EFI_SIMULATOR) && EFI_TEXT_LOGGING // Lock the buffer mutex - inhibit buffer swaps while writing { chibios_rt::MutexLocker lock(logBufferMutex); diff --git a/simulator/main.c b/simulator/main.c index c2f24101bb..bdb39f84e8 100644 --- a/simulator/main.c +++ b/simulator/main.c @@ -17,7 +17,6 @@ #include "global.h" #include "chprintf.h" #include "rusEfiFunctionalTest.h" -#include "framework.h" #define CONSOLE_WA_SIZE THD_WORKING_AREA_SIZE(4096) @@ -31,8 +30,6 @@ void printToConsole(char *p) { cputs(p); } -BaseChannel serialAdapterInstance; - /* * Console print server done using synchronous messages. This makes the access * to the C printf() thread safe and the print operation atomic among threads. @@ -136,9 +133,6 @@ bool verboseMode = true; * Simulator main. * *------------------------------------------------------------------------*/ int main(void) { - - initTestStream(&serialAdapterInstance); - /* * System initializations. * - HAL initialization, this also initializes the configured device drivers @@ -149,12 +143,6 @@ int main(void) { halInit(); chSysInit(); - /* - * Serial ports (simulated) initialization. - */ - sdStart(&SD1, NULL); - sdStart(&SD2, NULL); - /* * Console thread started. */ @@ -179,7 +167,7 @@ int main(void) { while (!chThdShouldTerminateX()) { chEvtDispatch(fhandlers, chEvtWaitOne(ALL_EVENTS)); printPendingMessages(); - chThdSleepMilliseconds(100); + chThdSleepMilliseconds(1); } /* diff --git a/simulator/simulator/boards.h b/simulator/simulator/boards.h index 87d3fa55bd..c3ed2b4fa6 100644 --- a/simulator/simulator/boards.h +++ b/simulator/simulator/boards.h @@ -10,16 +10,6 @@ #define ADC_LOGIC_INTAKE_AIR 0 #define ADC_LOGIC_COOLANT 0 -// see SIM_SD1_PORT -#define CONSOLE_PORT (&SD1) -// see SIM_SD2_PORT -//#define TS_PRIMARY_SERIAL SD2 - -/** - * This implementation writes to both windows console and console port - */ -#define TS_PRIMARY_SERIAL (&serialAdapterInstance) - int getAdcValue(const char *msg, int channel); #define getSlowAdcCounter() 0 #define waitForSlowAdc(x) {} diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 0295667cfa..f0e6e07a65 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -9,13 +9,17 @@ #include "rusefi_true.h" +// see SIM_SD1_PORT and SIM_SD2_PORT +#define TS_PRIMARY_SERIAL SD1 +#define TS_SECONDARY_SERIAL SD2 + #define EFI_ENABLE_ASSERTS TRUE #define EFI_LAUNCH_CONTROL FALSE #define EFI_ENABLE_MOCK_ADC TRUE #define ENABLE_PERF_TRACE FALSE -#define EFI_PRINTF_FUEL_DETAILS TRUE +#define EFI_PRINTF_FUEL_DETAILS FALSE #define EFI_ENABLE_CRITICAL_ENGINE_STOP TRUE #define EFI_ENABLE_ENGINE_WARNING TRUE @@ -147,3 +151,5 @@ #define EFI_BOARD_TEST FALSE #define EFI_JOYSTICK FALSE + +#define EFI_LUA TRUE diff --git a/simulator/simulator/framework.cpp b/simulator/simulator/framework.cpp index c033563f12..a63e4b9dd4 100644 --- a/simulator/simulator/framework.cpp +++ b/simulator/simulator/framework.cpp @@ -6,7 +6,6 @@ */ #include "global.h" -#include "framework.h" #include "efitime.h" efitick_t getTimeNowNt(void) { @@ -20,70 +19,3 @@ uint32_t getTimeNowLowerNt(void) { efitimeus_t getTimeNowUs(void) { return chVTGetSystemTimeX() * (1000000 / CH_CFG_ST_FREQUENCY); } - -static size_t wt_writes(void *ip, const uint8_t *bp, size_t n) { - printToConsole((char*)bp); - return CONSOLE_PORT->vmt->write(CONSOLE_PORT, bp, n); -} - -static size_t wt_reads(void *ip, uint8_t *bp, size_t n) { - return CONSOLE_PORT->vmt->read(CONSOLE_PORT, bp, n); -} - -static msg_t wt_putt(void *instance, uint8_t b, systime_t time) { - return CONSOLE_PORT->vmt->putt(CONSOLE_PORT, b, time); -} - -static msg_t wt_gett(void *instance, systime_t time) { - return CONSOLE_PORT->vmt->gett(CONSOLE_PORT, time); -} - -static size_t wt_writet(void *instance, const uint8_t *bp, - size_t n, systime_t time) { - return CONSOLE_PORT->vmt->writet(CONSOLE_PORT, bp, n, time); -} - -static size_t wt_readt(void *instance, uint8_t *bp, size_t n, systime_t time) { - return CONSOLE_PORT->vmt->readt(CONSOLE_PORT, bp, n, time); -} - -static char putMessageBuffer[2]; - -static msg_t wt_put(void *ip, uint8_t b) { - putMessageBuffer[0] = b; - putMessageBuffer[1] = 0; - printToConsole((char*)putMessageBuffer); -// cputs("wt_put"); - return CONSOLE_PORT->vmt->put(CONSOLE_PORT, b); -} - -static msg_t wt_get(void *ip) { -// cputs("wt_get"); - //return 0; - return CONSOLE_PORT->vmt->get(CONSOLE_PORT); -} - -static msg_t _ctl(void *ip, unsigned int operation, void *arg) { - - (void)ip; - (void)operation; - (void)arg; - - return MSG_OK; -} - -/** - * These implementation print same content on console screen and send data over the underlying CONSOLE_PORT - * this is useful to see what's going on. - * See #wt_get() as a typical implementation - */ -static const struct BaseChannelVMT vmt = { - (size_t)0, - wt_writes, wt_reads, wt_put, wt_get, - wt_putt, wt_gett, wt_writet, wt_readt, - _ctl -}; - -void initTestStream(BaseChannel *ts) { - ts->vmt = &vmt; -} diff --git a/simulator/simulator/framework.h b/simulator/simulator/framework.h deleted file mode 100644 index 558cc3de7f..0000000000 --- a/simulator/simulator/framework.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * @file framework.h - * - * @date Sep 25, 2014 - * @author Andrey Belomutskiy, (c) 2012-2014 - */ - -#pragma once - -#ifdef __cplusplus -extern "C" -{ -#endif /* __cplusplus */ - -void initTestStream(BaseChannel *ts); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - diff --git a/simulator/simulator/global.h b/simulator/simulator/global.h index 6824e0508d..176901fabc 100644 --- a/simulator/simulator/global.h +++ b/simulator/simulator/global.h @@ -46,8 +46,6 @@ // project-wide default thread stack size #define UTILITY_THREAD_STACK_SIZE 1384 -extern BaseChannel serialAdapterInstance; - #define UNIT_TEST_BUSY_WAIT_CALLBACK() {} #ifdef __cplusplus diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index 3d6db250ce..968380dfe5 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -29,6 +29,7 @@ #include "map_averaging.h" #include "memstreams.h" #include +#include "rusefi_lua.h" #define DEFAULT_SIM_RPM 1200 #define DEFAULT_SNIFFER_THR 2500 @@ -102,7 +103,7 @@ void rusEfiFunctionalTest(void) { // todo: reduce code duplication with initEngineContoller - resetConfigurationExt(FORD_ESCORT_GT PASS_ENGINE_PARAMETER_SUFFIX); + resetConfigurationExt(MINIMAL_PINS PASS_ENGINE_PARAMETER_SUFFIX); enableTriggerStimulator(); commonInitEngineController(); @@ -112,12 +113,18 @@ void rusEfiFunctionalTest(void) { startStatusThreads(); + startLoggingProcessor(); + runChprintfTest(); initPeriodicEvents(PASS_ENGINE_PARAMETER_SIGNATURE); setTriggerEmulatorRPM(DEFAULT_SIM_RPM PASS_ENGINE_PARAMETER_SUFFIX); engineConfiguration->engineSnifferRpmThreshold = DEFAULT_SNIFFER_THR; + + startSerialChannels(); + + startLua(); } void printPendingMessages(void) { @@ -149,7 +156,3 @@ void logMsg(const char *format, ...) { // // fclose(fp); } - -BaseChannel * getConsoleChannel(void) { - return (BaseChannel *)TS_PRIMARY_SERIAL; -}