mirror of https://github.com/rusefi/rusefi-1.git
The Big Refactoring of 2019: console vs TS vs CONSOLE_MODE_SWITCH_PIN vs text protocol #725
sweet progress!
This commit is contained in:
parent
e2883a9166
commit
aaf6fcdf6a
|
@ -461,11 +461,11 @@ static bool isKnownCommand(char command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function runs indefinitely
|
// this function runs indefinitely
|
||||||
void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
|
void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
||||||
int wasReady = false;
|
int wasReady = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int isReady = sr5IsReady(isConsoleRedirect);
|
int isReady = sr5IsReady(tsChannel);
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
wasReady = false;
|
wasReady = false;
|
||||||
|
@ -586,7 +586,7 @@ static THD_FUNCTION(tsThreadEntryPoint, arg) {
|
||||||
|
|
||||||
startTsPort(&tsChannel);
|
startTsPort(&tsChannel);
|
||||||
|
|
||||||
runBinaryProtocolLoop(&tsChannel, false);
|
runBinaryProtocolLoop(&tsChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncTunerStudioCopy(void) {
|
void syncTunerStudioCopy(void) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ void requestBurn(void);
|
||||||
|
|
||||||
void startTunerStudioConnectivity(void);
|
void startTunerStudioConnectivity(void);
|
||||||
void syncTunerStudioCopy(void);
|
void syncTunerStudioCopy(void);
|
||||||
void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect);
|
void runBinaryProtocolLoop(ts_channel_s *tsChannel);
|
||||||
|
|
||||||
#if defined __GNUC__
|
#if defined __GNUC__
|
||||||
// GCC
|
// GCC
|
||||||
|
|
|
@ -23,8 +23,7 @@ extern LoggingWithStorage tsLogger;
|
||||||
|
|
||||||
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
|
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
|
||||||
extern SerialUSBDriver SDU1;
|
extern SerialUSBDriver SDU1;
|
||||||
#define CONSOLE_USB_DEVICE &SDU1
|
#endif /* HAL_USE_SERIAL_USB */
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TS_UART_DMA_MODE
|
#if TS_UART_DMA_MODE
|
||||||
// Async. FIFO buffer takes some RAM...
|
// 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) {
|
void startTsPort(ts_channel_s *tsChannel) {
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
|
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
|
||||||
if (isCommandLineConsoleOverTTL()) {
|
if (true) {
|
||||||
print("TunerStudio over USB serial");
|
print("TunerStudio over USB serial");
|
||||||
/**
|
/**
|
||||||
* This method contains a long delay, that's the reason why this is not done on the main thread
|
* This method contains a long delay, that's the reason why this is not done on the main thread
|
||||||
*/
|
*/
|
||||||
usb_serial_start();
|
usb_serial_start();
|
||||||
// if console uses UART then TS uses USB
|
// if console uses UART then TS uses USB
|
||||||
tsChannel->channel = (BaseChannel *) CONSOLE_USB_DEVICE;
|
tsChannel->channel = (BaseChannel *) &CONSOLE_USB_DEVICE;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -138,7 +137,7 @@ void startTsPort(ts_channel_s *tsChannel) {
|
||||||
bool stopTsPort(ts_channel_s *tsChannel) {
|
bool stopTsPort(ts_channel_s *tsChannel) {
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
||||||
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
|
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
|
||||||
if (isCommandLineConsoleOverTTL()) {
|
if (true) {
|
||||||
#if 0
|
#if 0
|
||||||
usb_serial_stop();
|
usb_serial_stop();
|
||||||
#endif
|
#endif
|
||||||
|
@ -257,17 +256,13 @@ void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sr5IsReady(bool isConsoleRedirect) {
|
bool sr5IsReady(ts_channel_s *tsChannel) {
|
||||||
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
#if EFI_USB_SERIAL || defined(__DOXYGEN__)
|
||||||
if (isCommandLineConsoleOverTTL() ^ isConsoleRedirect) {
|
if (isUsbSerial(tsChannel->channel)) {
|
||||||
// TS uses USB when console uses serial
|
// TS uses USB when console uses serial
|
||||||
return is_usb_serial_ready();
|
return is_usb_serial_ready();
|
||||||
} else {
|
|
||||||
// TS uses serial when console uses USB
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
#else
|
#endif /* EFI_USB_SERIAL */
|
||||||
return true;
|
return true;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,9 @@ typedef struct {
|
||||||
// todo: double-check this
|
// todo: double-check this
|
||||||
#define CRC_WRAPPING_SIZE (CRC_VALUE_SIZE + 3)
|
#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);
|
void startTsPort(ts_channel_s *tsChannel);
|
||||||
bool stopTsPort(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);
|
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 sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size);
|
||||||
int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout);
|
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_ */
|
#endif /* CONSOLE_TUNERSTUDIO_TUNERSTUDIO_IO_H_ */
|
||||||
|
|
|
@ -132,23 +132,27 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
|
||||||
|
|
||||||
CommandHandler console_line_callback;
|
CommandHandler console_line_callback;
|
||||||
|
|
||||||
bool isCommandLineConsoleOverTTL(void) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR ) || defined(__DOXYGEN__)
|
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR ) || defined(__DOXYGEN__)
|
||||||
static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
|
static SerialConfig serialConfig = { 0, 0, USART_CR2_STOP1_BITS | USART_CR2_LINEN, 0 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if EFI_PROD_CODE || EFI_EGT || defined(__DOXYGEN__)
|
#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) {
|
BaseChannel * getConsoleChannel(void) {
|
||||||
#if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__)
|
#if defined(EFI_CONSOLE_UART_DEVICE) || defined(__DOXYGEN__)
|
||||||
return (BaseChannel *) EFI_CONSOLE_UART_DEVICE;
|
return (BaseChannel *) EFI_CONSOLE_UART_DEVICE;
|
||||||
#endif /* EFI_CONSOLE_UART_DEVICE */
|
#endif /* EFI_CONSOLE_UART_DEVICE */
|
||||||
|
|
||||||
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
|
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
|
||||||
return (BaseChannel *) &SDU1;
|
return (BaseChannel *) &CONSOLE_USB_DEVICE;
|
||||||
#else
|
#else
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif /* HAL_USE_SERIAL_USB */
|
#endif /* HAL_USE_SERIAL_USB */
|
||||||
|
@ -168,20 +172,10 @@ static THD_FUNCTION(consoleThreadThreadEntryPoint, arg) {
|
||||||
(void) arg;
|
(void) arg;
|
||||||
chRegSetThreadName("console thread");
|
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();
|
binaryConsole.channel = (BaseChannel *) getConsoleChannel();
|
||||||
if (binaryConsole.channel != NULL) {
|
if (binaryConsole.channel != NULL) {
|
||||||
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
#if EFI_TUNER_STUDIO || defined(__DOXYGEN__)
|
||||||
runBinaryProtocolLoop(&binaryConsole, true);
|
runBinaryProtocolLoop(&binaryConsole);
|
||||||
#endif /* EFI_TUNER_STUDIO */
|
#endif /* EFI_TUNER_STUDIO */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,8 +205,6 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
|
||||||
console_line_callback = console_line_callback_p;
|
console_line_callback = console_line_callback_p;
|
||||||
|
|
||||||
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__)
|
#if (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR) || defined(__DOXYGEN__)
|
||||||
|
|
||||||
if (isCommandLineConsoleOverTTL()) {
|
|
||||||
/*
|
/*
|
||||||
* Activates the serial
|
* Activates the serial
|
||||||
* it is important to set 'NONE' as flow control! in terminal application on the PC
|
* 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;
|
isSerialConsoleStarted = true;
|
||||||
|
|
||||||
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1);
|
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_UART_DEVICE), &consoleEventListener, 1);
|
||||||
}
|
|
||||||
#endif /* EFI_PROD_CODE */
|
#endif /* EFI_PROD_CODE */
|
||||||
|
|
||||||
#if !defined(EFI_CONSOLE_NO_THREAD) || defined(__DOXYGEN__)
|
#if !defined(EFI_CONSOLE_NO_THREAD) || defined(__DOXYGEN__)
|
||||||
|
|
|
@ -32,8 +32,8 @@ BaseChannel * getConsoleChannel(void);
|
||||||
void consolePutChar(int x);
|
void consolePutChar(int x);
|
||||||
void consoleOutputBuffer(const uint8_t *buf, int size);
|
void consoleOutputBuffer(const uint8_t *buf, int size);
|
||||||
void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p);
|
void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p);
|
||||||
bool isCommandLineConsoleOverTTL(void);
|
|
||||||
void onDataArrived(void);
|
void onDataArrived(void);
|
||||||
|
bool isUsbSerial(BaseChannel * channel);
|
||||||
|
|
||||||
#if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT
|
#if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT
|
||||||
bool isCommandLineConsoleReady(void);
|
bool isCommandLineConsoleReady(void);
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#define TS_UART_MODE FALSE
|
#define TS_UART_MODE FALSE
|
||||||
|
|
||||||
|
#define EFI_USB_SERIAL FALSE
|
||||||
|
|
||||||
#define EFI_CDM_INTEGRATION FALSE
|
#define EFI_CDM_INTEGRATION FALSE
|
||||||
|
|
||||||
#define EFI_BLUETOOTH_SETUP FALSE
|
#define EFI_BLUETOOTH_SETUP FALSE
|
||||||
|
|
Loading…
Reference in New Issue