From 38b278426356247e81ada3171c3b4cc020d49d7c Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 7 Dec 2014 18:03:14 -0600 Subject: [PATCH] auto-sync --- firmware/console/console_io.c | 56 +++++++++++--------- firmware/console/status_loop.cpp | 22 +++++++- firmware/console/tunerstudio/tunerstudio.cpp | 37 ++++++------- firmware/hw_layer/io_pins.c | 18 ------- firmware/hw_layer/pin_repository.c | 2 +- firmware/svnversion.h | 4 +- 6 files changed, 74 insertions(+), 65 deletions(-) diff --git a/firmware/console/console_io.c b/firmware/console/console_io.c index b272fbbeb0..c07aad3360 100644 --- a/firmware/console/console_io.c +++ b/firmware/console/console_io.c @@ -120,26 +120,6 @@ bool isSerialOverUart(void) { return is_serial_over_uart; } -static THD_WORKING_AREA(consoleThreadStack, 2 * UTILITY_THREAD_STACK_SIZE); -static msg_t consoleThreadThreadEntryPoint(void *arg) { - (void) arg; - chRegSetThreadName("console thread"); - - while (TRUE) { - efiAssert(getRemainingStack(chThdSelf()) > 256, "lowstck#9e", 0); - bool end = getConsoleLine((BaseSequentialStream*) getConsoleChannel(), consoleInput, sizeof(consoleInput)); - if (end) { - // firmware simulator is the only case when this happens - continue; - } - - (console_line_callback)(consoleInput); - } -#if defined __GNUC__ - return false; -#endif -} - #if EFI_PROD_CODE static SerialConfig serialConfig = { SERIAL_SPEED, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 }; @@ -162,6 +142,35 @@ bool isConsoleReady(void) { #endif /* EFI_PROD_CODE */ +static THD_WORKING_AREA(consoleThreadStack, 2 * UTILITY_THREAD_STACK_SIZE); +static msg_t consoleThreadThreadEntryPoint(void *arg) { + (void) arg; + chRegSetThreadName("console thread"); + +#if EFI_PROD_CODE + if (!isSerialOverUart()) { + /** + * This method contains a long delay, that's the reason why this is not done on the main thread + */ + usb_serial_start(); + } +#endif /* EFI_PROD_CODE */ + + while (true) { + efiAssert(getRemainingStack(chThdSelf()) > 256, "lowstck#9e", 0); + bool end = getConsoleLine((BaseSequentialStream*) getConsoleChannel(), consoleInput, sizeof(consoleInput)); + if (end) { + // firmware simulator is the only case when this happens + continue; + } + + (console_line_callback)(consoleInput); + } +#if defined __GNUC__ + return false; +#endif +} + void consolePutChar(int x) { chSequentialStreamPut(getConsoleChannel(), (uint8_t )(x)); } @@ -198,18 +207,15 @@ void startConsole(void (*console_line_callback_p)(char *)) { palSetPadMode(EFI_CONSOLE_RX_PORT, EFI_CONSOLE_RX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF)); palSetPadMode(EFI_CONSOLE_TX_PORT, EFI_CONSOLE_TX_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF)); - isSerialConsoleStarted = TRUE; + isSerialConsoleStarted = true; chEvtRegisterMask((EventSource *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1); - } else { - usb_serial_start(); } #endif /* EFI_PROD_CODE */ + chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, consoleThreadThreadEntryPoint, NULL); } -extern cnt_t dbg_isr_cnt; - /** * @return TRUE if already in locked context */ diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 6ee5bff2fc..2d2a803d67 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -345,6 +345,23 @@ static THD_WORKING_AREA(lcdThreadStack, UTILITY_THREAD_STACK_SIZE); */ static THD_WORKING_AREA(comBlinkingStack, UTILITY_THREAD_STACK_SIZE); +static io_pin_e leds[] = { LED_WARNING, LED_RUNNING, LED_ERROR, LED_COMMUNICATION_1, LED_DEBUG, LED_EXT_1, + LED_CHECK_ENGINE }; + +/** + * This method would blink all the LEDs just to test them + */ +static void initialLedsBlink(void) { + int size = sizeof(leds) / sizeof(leds[0]); + for (int i = 0; i < size; i++) + setOutputPinValue(leds[i], 1); + + chThdSleepMilliseconds(100); + + for (int i = 0; i < size; i++) + setOutputPinValue(leds[i], 0); +} + /** * error thread to show error condition (blinking LED means non-fatal error) */ @@ -354,7 +371,10 @@ static THD_WORKING_AREA(errBlinkingStack, UTILITY_THREAD_STACK_SIZE); static void comBlinkingThread(void *arg) { (void) arg; chRegSetThreadName("communication blinking"); - while (TRUE) { + + initialLedsBlink(); + + while (true) { int delay; if (getNeedToWriteConfiguration()) { diff --git a/firmware/console/tunerstudio/tunerstudio.cpp b/firmware/console/tunerstudio/tunerstudio.cpp index 12709952ed..f38f54d9ac 100644 --- a/firmware/console/tunerstudio/tunerstudio.cpp +++ b/firmware/console/tunerstudio/tunerstudio.cpp @@ -372,13 +372,29 @@ static uint8_t secondByte; static uint8_t crcIoBuffer[300]; - - - static msg_t tsThreadEntryPoint(void *arg) { (void) arg; chRegSetThreadName("tunerstudio thread"); +#if EFI_PROD_CODE + if (isSerialOverUart()) { + print("TunerStudio over USB serial"); + /** + * This method contains a long delay, that's the reason why this is not done on the main thread + */ + usb_serial_start(); + } else { + + print("TunerStudio over USART"); + mySetPadMode("tunerstudio rx", TS_SERIAL_RX_PORT, TS_SERIAL_RX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); + mySetPadMode("tunerstudio tx", TS_SERIAL_TX_PORT, TS_SERIAL_TX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); + + tsSerialConfig.speed = boardConfiguration->tunerStudioSerialSpeed; + + sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); + } +#endif /* EFI_PROD_CODE */ + int wasReady = false; while (true) { int isReady = ts_serial_ready(); @@ -506,21 +522,6 @@ void startTunerStudioConnectivity(void) { firmwareError("TS outputs size mismatch: %d/%d", sizeof(TunerStudioOutputChannels), TS_OUTPUT_SIZE); memset(&tsState, 0, sizeof(tsState)); -#if EFI_PROD_CODE - if (isSerialOverUart()) { - print("TunerStudio over USB serial"); - usb_serial_start(); - } else { - - print("TunerStudio over USART"); - mySetPadMode("tunerstudio rx", TS_SERIAL_RX_PORT, TS_SERIAL_RX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); - mySetPadMode("tunerstudio tx", TS_SERIAL_TX_PORT, TS_SERIAL_TX_PIN, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); - - tsSerialConfig.speed = boardConfiguration->tunerStudioSerialSpeed; - - sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); - } -#endif /* EFI_PROD_CODE */ syncTunerStudioCopy(); addConsoleAction("tsinfo", printStats); diff --git a/firmware/hw_layer/io_pins.c b/firmware/hw_layer/io_pins.c index 6b19ff8190..6fcfe37fe4 100644 --- a/firmware/hw_layer/io_pins.c +++ b/firmware/hw_layer/io_pins.c @@ -27,8 +27,6 @@ static Logging logger; extern pin_output_mode_e *pinDefaultState[IO_PIN_COUNT]; extern OutputPin outputs[IO_PIN_COUNT]; -static io_pin_e leds[] = { LED_WARNING, LED_RUNNING, LED_ERROR, LED_COMMUNICATION_1, LED_DEBUG, LED_EXT_1, - LED_CHECK_ENGINE }; static GPIO_TypeDef *PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH }; @@ -96,20 +94,6 @@ void outputPinRegister(const char *msg, io_pin_e ioPin, GPIO_TypeDef *port, uint outputPinRegisterExt(msg, ioPin, port, pin, &DEFAULT_OUTPUT); } -/** - * This method would blink all the LEDs just to test them - */ -static void initialLedsBlink(void) { - int size = sizeof(leds) / sizeof(leds[0]); - for (int i = 0; i < size; i++) - setOutputPinValue(leds[i], 1); - - chThdSleepMilliseconds(100); - - for (int i = 0; i < size; i++) - setOutputPinValue(leds[i], 0); -} - void initPrimaryPins(void) { outputPinRegister("LED_ERROR", LED_ERROR, LED_ERROR_PORT, LED_ERROR_PIN); } @@ -158,8 +142,6 @@ void initOutputPins(void) { outputPinRegisterExt2("trg_err", LED_TRIGGER_ERROR, boardConfiguration->triggerErrorPin, &boardConfiguration->triggerErrorPinMode); outputPinRegisterExt2("A/C relay", AC_RELAY, boardConfiguration->acRelayPin, &boardConfiguration->acRelayPinMode); - initialLedsBlink(); - // digit 1 /* ledRegister(LED_HUGE_0, GPIOB, 2); diff --git a/firmware/hw_layer/pin_repository.c b/firmware/hw_layer/pin_repository.c index 1705668ced..41a265c70f 100644 --- a/firmware/hw_layer/pin_repository.c +++ b/firmware/hw_layer/pin_repository.c @@ -127,7 +127,7 @@ void initPinRepository(void) { for (int i = 0; i < PIN_REPO_SIZE; i++) PIN_USED[i] = 0; - initialized = TRUE; + initialized = true; addConsoleAction("pins", reportPins); } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index f0169a4d90..6b3778de59 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Sat Nov 29 23:31:29 EST 2014 +// Sun Dec 07 18:26:23 EST 2014 #ifndef VCS_VERSION -#define VCS_VERSION "5638" +#define VCS_VERSION "5721" #endif