예제 #1
0
bool stopTsPort(ts_channel_s *tsChannel) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
	if (isCommandLineConsoleOverTTL()) {
#if 0
		usb_serial_stop();
#endif
		// don't stop USB!
		return false;
	} else
#endif
	{
		if (CONFIGB(useSerialPort)) {
			// todo: disable Rx/Tx pads?
#if TS_UART_DMA_MODE
			uartStop(TS_DMA_UART_DEVICE);
#else
			sdStop(TS_SERIAL_UART_DEVICE);
#endif /* TS_UART_DMA_MODE */
		}
	}

	tsChannel->channel = (BaseChannel *) NULL;
	return true;
#else  /* EFI_PROD_CODE */
	// don't stop simulator!
	return false;
#endif /* EFI_PROD_CODE */
}
예제 #2
0
void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p) {
	logger = sharedLogger;
	console_line_callback = console_line_callback_p;

#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__)

	palSetPadMode(CONSOLE_MODE_SWITCH_PORT, CONSOLE_MODE_SWITCH_PIN, PAL_MODE_INPUT_PULLUP);

	b_isCommandLineConsoleOverTTL = GET_CONSOLE_MODE_VALUE() == EFI_USE_UART_FOR_CONSOLE;

	if (isCommandLineConsoleOverTTL()) {
		/*
		 * Activates the serial
		 * it is important to set 'NONE' as flow control! in terminal application on the PC
		 */
		serialConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
		sdStart(EFI_CONSOLE_UART_DEVICE, &serialConfig);

// cannot use pin repository here because pin repository prints to console
		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;

		chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1);
	}
#else
	b_isCommandLineConsoleOverTTL = false;
#endif /* EFI_PROD_CODE */

	chThdCreateStatic(consoleThreadStack, sizeof(consoleThreadStack), NORMALPRIO, (tfunc_t)consoleThreadThreadEntryPoint, NULL);
	addConsoleAction(SWITCH_TO_BINARY_COMMAND, switchToBinaryProtocol);
}
예제 #3
0
bool isCommandLineConsoleReady(void) {
	if (isCommandLineConsoleOverTTL()) {
		return isSerialConsoleStarted;
	} else {
		return is_usb_serial_ready();
	}
}
예제 #4
0
BaseChannel * getTsSerialDevice(void) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
	if (isCommandLineConsoleOverTTL()) {
		// if console uses UART then TS uses USB
		return (BaseChannel *) &SDU1;
	} else {
		return (BaseChannel *) TS_SERIAL_UART_DEVICE;
	}
#else
	return (BaseChannel *) TS_SIMULATOR_PORT;
#endif
}
예제 #5
0
bool sr5IsReady(bool isConsoleRedirect) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
	if (isCommandLineConsoleOverTTL() ^ isConsoleRedirect) {
		// TS uses USB when console uses serial
		return is_usb_serial_ready();
	} else {
		// TS uses serial when console uses USB
		return true;
	}
#else
	return true;
#endif
}
예제 #6
0
BaseChannel * getConsoleChannel(void) {
#if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__)
	if (isCommandLineConsoleOverTTL()) {
		return (BaseChannel *) EFI_CONSOLE_UART_DEVICE;
	}
#endif /* EFI_CONSOLE_UART_DEVICE */

#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
	return (BaseChannel *) &SDU1;
#else
	return NULL;
#endif /* HAL_USE_SERIAL_USB */
}
예제 #7
0
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 */
}
예제 #8
0
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);
}
예제 #9
0
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);
		}
	}
}
예제 #10
0
/**
 * @brief   Reads a whole line from the input channel.
 *
 * @param[in] chp       pointer to a @p BaseChannel object
 * @param[in] line      pointer to the line buffer
 * @param[in] size      buffer maximum length
 * @return              The operation status.
 * @retval TRUE         the channel was reset or CTRL-D pressed.
 * @retval FALSE        operation successful.
 */
static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size) {
	char *p = line;

	while (true) {
		if (!isCommandLineConsoleReady()) {
			// we better do not read from USB serial before it is ready
			chThdSleepMilliseconds(10);
			continue;
		}

		short c = (short) streamGet(chp);
		onDataArrived();

#if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__)
		if (isCommandLineConsoleOverTTL()) {
			uint32_t flags;
			chSysLock()
			;

			flags = chEvtGetAndClearFlagsI(&consoleEventListener);
			chSysUnlock()
			;
			if (flags & SD_OVERRUN_ERROR) {
//				firmwareError(OBD_PCM_Processor_Fault, "serial overrun");
			}
		}
#endif

#if EFI_UART_ECHO_TEST_MODE
		/**
		 * That's test code - let's test connectivity
		 */
		consolePutChar((uint8_t) c);
		continue;
#endif

		if (c < 0 || c == 4) {
			return true;
		}
		if (c == 8) {
			if (p != line) {
				// backspace
				consolePutChar((uint8_t) c);
				consolePutChar(0x20);
				consolePutChar((uint8_t) c);
				p--;
			}
			continue;
		}
		if (c == '\r') {
			consolePutChar('\r');
			consolePutChar('\n');
			*p = 0;
			return false;
		}
		if (c == '\n') {
			consolePutChar('\n');
			*p = 0;
			return false;
		}
		if (c < 0x20) {
			continue;
		}
		if (p < line + size - 1) {
			consolePutChar((uint8_t) c);
			*p++ = (char) c;
		}
	}
}