The Big Refactoring of 2019: console vs TS vs CONSOLE_MODE_SWITCH_PIN vs text protocol #725

sweet progress!
This commit is contained in:
rusefi 2019-04-01 14:18:21 -04:00
parent e2883a9166
commit aaf6fcdf6a
7 changed files with 29 additions and 38 deletions

View File

@ -461,11 +461,11 @@ static bool isKnownCommand(char command) {
}
// this function runs indefinitely
void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
int wasReady = false;
while (true) {
int isReady = sr5IsReady(isConsoleRedirect);
int isReady = sr5IsReady(tsChannel);
if (!isReady) {
chThdSleepMilliseconds(10);
wasReady = false;
@ -586,7 +586,7 @@ static THD_FUNCTION(tsThreadEntryPoint, arg) {
startTsPort(&tsChannel);
runBinaryProtocolLoop(&tsChannel, false);
runBinaryProtocolLoop(&tsChannel);
}
void syncTunerStudioCopy(void) {

View File

@ -66,7 +66,7 @@ void requestBurn(void);
void startTunerStudioConnectivity(void);
void syncTunerStudioCopy(void);
void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect);
void runBinaryProtocolLoop(ts_channel_s *tsChannel);
#if defined __GNUC__
// GCC

View File

@ -23,8 +23,7 @@ extern LoggingWithStorage tsLogger;
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
extern SerialUSBDriver SDU1;
#define CONSOLE_USB_DEVICE &SDU1
#endif
#endif /* HAL_USE_SERIAL_USB */
#if TS_UART_DMA_MODE
// Async. FIFO buffer takes some RAM...
@ -85,14 +84,14 @@ static SerialConfig tsSerialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LI
void startTsPort(ts_channel_s *tsChannel) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
if (isCommandLineConsoleOverTTL()) {
if (true) {
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;
tsChannel->channel = (BaseChannel *) &CONSOLE_USB_DEVICE;
} else
#endif
{
@ -138,7 +137,7 @@ void startTsPort(ts_channel_s *tsChannel) {
bool stopTsPort(ts_channel_s *tsChannel) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
if (isCommandLineConsoleOverTTL()) {
if (true) {
#if 0
usb_serial_stop();
#endif
@ -257,17 +256,13 @@ void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const u
}
}
bool sr5IsReady(bool isConsoleRedirect) {
#if EFI_PROD_CODE || defined(__DOXYGEN__)
if (isCommandLineConsoleOverTTL() ^ isConsoleRedirect) {
bool sr5IsReady(ts_channel_s *tsChannel) {
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
if (isUsbSerial(tsChannel->channel)) {
// TS uses USB when console uses serial
return is_usb_serial_ready();
} else {
// TS uses serial when console uses USB
return true;
}
#else
#endif /* EFI_USB_SERIAL */
return true;
#endif
}

View File

@ -85,6 +85,9 @@ typedef struct {
// todo: double-check this
#define CRC_WRAPPING_SIZE (CRC_VALUE_SIZE + 3)
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
#define CONSOLE_USB_DEVICE SDU1
#endif /* HAL_USE_SERIAL_USB */
void startTsPort(ts_channel_s *tsChannel);
bool stopTsPort(ts_channel_s *tsChannel);
@ -100,6 +103,6 @@ void sr5WriteCrcPacket(ts_channel_s *tsChannel, const uint8_t responseCode, cons
void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const uint8_t * buffer, int size);
int sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size);
int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout);
bool sr5IsReady(bool isConsoleRedirect);
bool sr5IsReady(ts_channel_s *tsChannel);
#endif /* CONSOLE_TUNERSTUDIO_TUNERSTUDIO_IO_H_ */

View File

@ -132,23 +132,27 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
CommandHandler console_line_callback;
bool isCommandLineConsoleOverTTL(void) {
return true;
}
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR ) || defined(__DOXYGEN__)
static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
#endif
#if EFI_PROD_CODE || EFI_EGT || defined(__DOXYGEN__)
bool isUsbSerial(BaseChannel * channel) {
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
return channel == (BaseChannel *) &CONSOLE_USB_DEVICE;
#else
return false;
#endif
}
BaseChannel * getConsoleChannel(void) {
#if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__)
return (BaseChannel *) EFI_CONSOLE_UART_DEVICE;
#endif /* EFI_CONSOLE_UART_DEVICE */
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
return (BaseChannel *) &SDU1;
return (BaseChannel *) &CONSOLE_USB_DEVICE;
#else
return NULL;
#endif /* HAL_USE_SERIAL_USB */
@ -168,20 +172,10 @@ 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) {
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
runBinaryProtocolLoop(&binaryConsole, true);
runBinaryProtocolLoop(&binaryConsole);
#endif /* EFI_TUNER_STUDIO */
}
}
@ -211,8 +205,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
console_line_callback = console_line_callback_p;
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__)
if (isCommandLineConsoleOverTTL()) {
/*
* Activates the serial
* it is important to set 'NONE' as flow control! in terminal application on the PC
@ -227,7 +219,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
isSerialConsoleStarted = true;
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1);
}
#endif /* EFI_PROD_CODE */
#if !defined(EFI_CONSOLE_NO_THREAD) || defined(__DOXYGEN__)

View File

@ -32,8 +32,8 @@ BaseChannel * getConsoleChannel(void);
void consolePutChar(int x);
void consoleOutputBuffer(const uint8_t *buf, int size);
void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p);
bool isCommandLineConsoleOverTTL(void);
void onDataArrived(void);
bool isUsbSerial(BaseChannel * channel);
#if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT
bool isCommandLineConsoleReady(void);

View File

@ -24,6 +24,8 @@
#define TS_UART_MODE FALSE
#define EFI_USB_SERIAL FALSE
#define EFI_CDM_INTEGRATION FALSE
#define EFI_BLUETOOTH_SETUP FALSE