diff --git a/firmware/console/console.mk b/firmware/console/console.mk index 3b9184efcd..a6e93c4ff3 100644 --- a/firmware/console/console.mk +++ b/firmware/console/console.mk @@ -1,6 +1,7 @@ -CONSOLESRC = $(PROJECT_DIR)/console/console_io.c +CONSOLESRC = CONSOLE_SRC_CPP = $(PROJECT_DIR)/console/status_loop.cpp \ + $(PROJECT_DIR)/console/console_io.cpp \ $(PROJECT_DIR)/console/eficonsole.cpp diff --git a/firmware/console/console_io.c b/firmware/console/console_io.cpp similarity index 95% rename from firmware/console/console_io.c rename to firmware/console/console_io.cpp index ba867035d6..eabf8a12ce 100644 --- a/firmware/console/console_io.c +++ b/firmware/console/console_io.cpp @@ -194,7 +194,14 @@ void consoleOutputBuffer(const uint8_t *buf, int size) { #endif /* EFI_UART_ECHO_TEST_MODE */ } -void startConsole(void (*console_line_callback_p)(char *)) { +static Logging *logger; + +static void switchToBinaryProtocol(void) { + scheduleMsg(logger, "switching to binary protocol"); +} + +void startConsole(Logging *sharedLogger, void (*console_line_callback_p)(char *)) { + logger = sharedLogger; console_line_callback = console_line_callback_p; #if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__) @@ -223,6 +230,7 @@ void startConsole(void (*console_line_callback_p)(char *)) { #endif /* EFI_PROD_CODE */ chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, consoleThreadThreadEntryPoint, NULL); + addConsoleAction("~", switchToBinaryProtocol); } /** diff --git a/firmware/console/console_io.h b/firmware/console/console_io.h index 5afe2bc430..f7aa7711e5 100644 --- a/firmware/console/console_io.h +++ b/firmware/console/console_io.h @@ -19,6 +19,7 @@ #endif #include "efifeatures.h" +#include "datalogging.h" #define GET_CONSOLE_MODE_VALUE() palReadPad(CONSOLE_MODE_SWITCH_PORT, CONSOLE_MODE_SWITCH_PIN) #define SHOULD_INGORE_FLASH() (palReadPad(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN) == 0) @@ -32,7 +33,7 @@ SerialDriver * getConsoleChannel(void); void consolePutChar(int x); void consoleOutputBuffer(const uint8_t *buf, int size); -void startConsole(void (*console_line_callback_p)(char *)); +void startConsole(Logging *sharedLogger, void (*console_line_callback_p)(char *)); bool isSerialOverUart(void); #if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index ac007215c4..ceca50c657 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -83,7 +83,6 @@ static void sayHello(void) { printMsg(&logger, "STM32_PCLK2=%d", STM32_PCLK2); #endif - printMsg(&logger, "PORT_IDLE_THREAD_STACK_SIZE=%d", PORT_IDLE_THREAD_STACK_SIZE); printMsg(&logger, "CH_DBG_ENABLE_ASSERTS=%d", CH_DBG_ENABLE_ASSERTS); @@ -118,7 +117,6 @@ static void sayHello(void) { // printSimpleMsg(&logger, "", ); // printSimpleMsg(&logger, "", ); - /** * Time to finish output. This is needed to avoid mix-up of this methods output and console command confirmation */ @@ -136,11 +134,10 @@ static void cmd_threads(void) { print(" addr stack prio refs state time\r\n"); tp = chRegFirstThread(); do { - print("%.8lx [%.8lx] %4lu %4lu %9s %lu %s\r\n", (uint32_t) tp, 0, - (uint32_t) tp->p_prio, (uint32_t) (tp->p_refs - 1), - states[tp->p_state], (uint32_t) tp->p_time, tp->p_name); + print("%.8lx [%.8lx] %4lu %4lu %9s %lu %s\r\n", (uint32_t) tp, 0, (uint32_t) tp->p_prio, + (uint32_t) (tp->p_refs - 1), states[tp->p_state], (uint32_t) tp->p_time, tp->p_name); tp = chRegNextThread(tp); - } while (tp != NULL ); + } while (tp != NULL); #endif } @@ -149,12 +146,12 @@ static void cmd_threads(void) { */ void print(const char *format, ...) { #if !EFI_UART_ECHO_TEST_MODE - if (!isConsoleReady()) { + if (!isConsoleReady()) { return; - } + } va_list ap; va_start(ap, format); - chvprintf((BaseSequentialStream*)getConsoleChannel(), format, ap); + chvprintf((BaseSequentialStream*) getConsoleChannel(), format, ap); va_end(ap); #endif /* EFI_UART_ECHO_TEST_MODE */ } @@ -163,7 +160,7 @@ void initializeConsole(Logging *sharedLogger) { initIntermediateLoggingBuffer(); initConsoleLogic(sharedLogger); - startConsole(&handleConsoleLine); + startConsole(sharedLogger, &handleConsoleLine); sayHello(); addConsoleAction("test", sayNothing); diff --git a/firmware/console/tunerstudio/tunerstudio.cpp b/firmware/console/tunerstudio/tunerstudio.cpp index 8a357d9c9d..eaeb9337e1 100644 --- a/firmware/console/tunerstudio/tunerstudio.cpp +++ b/firmware/console/tunerstudio/tunerstudio.cpp @@ -363,14 +363,7 @@ static bool isKnownCommand(char command) { static uint8_t firstByte; static uint8_t secondByte; -static msg_t tsThreadEntryPoint(void *arg) { - (void) arg; - chRegSetThreadName("tunerstudio thread"); - -#if EFI_PROD_CODE || defined(__DOXYGEN__) - startTsPort(); -#endif - +void runBinaryProtocolLoop(void) { int wasReady = false; while (true) { int isReady = ts_serial_ready(); @@ -461,6 +454,18 @@ static msg_t tsThreadEntryPoint(void *arg) { print("got unexpected TunerStudio command %x:%c\r\n", command, command); } +} + +static msg_t tsThreadEntryPoint(void *arg) { + (void) arg; + chRegSetThreadName("tunerstudio thread"); + +#if EFI_PROD_CODE || defined(__DOXYGEN__) + startTsPort(); +#endif + + runBinaryProtocolLoop(); + #if defined __GNUC__ return 0; #endif