void startTunerStudioConnectivity(void) { initLogging(&logger, "tuner studio"); if (sizeof(engine_configuration_s) != getTunerStudioPageSize(0)) firmwareError("TS page size mismatch: %d/%d", sizeof(engine_configuration_s), getTunerStudioPageSize(0)); if (sizeof(TunerStudioOutputChannels) != TS_OUTPUT_SIZE) 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)); sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); } #endif /* EFI_PROD_CODE */ syncTunerStudioCopy(); addConsoleAction("tsinfo", printStats); chThdCreateStatic(TS_WORKING_AREA, sizeof(TS_WORKING_AREA), NORMALPRIO, tsThreadEntryPoint, NULL); }
void startTsPort(ts_channel_s *tsChannel) { #if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_USB_SERIAL || defined(__DOXYGEN__) if (isCommandLineConsoleOverTTL()) { 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(); // if console uses UART then TS uses USB tsChannel->channel = (BaseChannel *) CONSOLE_USB_DEVICE; } else #endif { if (CONFIGB(useSerialPort)) { print("TunerStudio over USART"); efiSetPadMode("tunerstudio rx", engineConfiguration->binarySerialRxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); efiSetPadMode("tunerstudio tx", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); #if TS_UART_DMA_MODE print("Using UART-DMA mode"); // init FIFO queue iqObjectInit(&tsUartDma.fifoRxQueue, tsUartDma.buffer, sizeof(tsUartDma.buffer), NULL, NULL); // start DMA driver tsDmaUartConfig.speed = CONFIGB(tunerStudioSerialSpeed); uartStart(TS_DMA_UART_DEVICE, &tsDmaUartConfig); // start continuous DMA transfer using our circular buffer tsUartDma.readPos = 0; uartStartReceive(TS_DMA_UART_DEVICE, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer); #else print("Using Serial mode"); tsSerialConfig.speed = CONFIGB(tunerStudioSerialSpeed); sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); tsChannel->channel = (BaseChannel *) TS_SERIAL_UART_DEVICE; #endif /* TS_UART_DMA_MODE */ } else tsChannel->channel = (BaseChannel *) NULL; // actually not used } #else /* EFI_PROD_CODE */ tsChannel->channel = (BaseChannel *) TS_SIMULATOR_PORT; #endif /* EFI_PROD_CODE */ }
static THD_FUNCTION(consoleThreadThreadEntryPoint, arg) { (void) arg; chRegSetThreadName("console thread"); #if (EFI_PROD_CODE && EFI_USB_SERIAL) || defined(__DOXYGEN__) if (!isCommandLineConsoleOverTTL()) { /** * 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 */ binaryConsole.channel = (BaseChannel *) getConsoleChannel(); if (binaryConsole.channel != NULL) runConsoleLoop(&binaryConsole); }
static msg_t consoleThreadThreadEntryPoint(void *arg) { (void) arg; chRegSetThreadName("console thread"); #if (EFI_PROD_CODE && EFI_USB_SERIAL) || defined(__DOXYGEN__) 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 */ binaryConsole.channel = (BaseChannel *) getConsoleChannel(); 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; } char *trimmed = efiTrim(consoleInput); (console_line_callback)(trimmed); if (consoleInBinaryMode) { #if EFI_SIMULATOR || defined(__DOXYGEN__) logMsg("Switching to binary mode\r\n"); #endif // switch to binary protocol runBinaryProtocolLoop(&binaryConsole, true); } } #if defined __GNUC__ return false; #endif }
void startTsPort(void) { #if EFI_USB_SERIAL || defined(__DOXYGEN__) if (isCommandLineConsoleOverTTL()) { 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 #endif { if (boardConfiguration->useSerialPort) { print("TunerStudio over USART"); mySetPadMode2("tunerstudio rx", engineConfiguration->binarySerialRxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); mySetPadMode2("tunerstudio tx", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF)); tsSerialConfig.speed = boardConfiguration->tunerStudioSerialSpeed; sdStart(TS_SERIAL_UART_DEVICE, &tsSerialConfig); } } }