2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file tunerstudio_io.cpp
|
|
|
|
*
|
|
|
|
* @date Mar 8, 2015
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2020-03-23 06:00:57 -07:00
|
|
|
#include "engine.h"
|
2019-07-03 18:48:04 -07:00
|
|
|
#include "os_access.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "tunerstudio_io.h"
|
|
|
|
#include "console_io.h"
|
2020-06-21 12:50:21 -07:00
|
|
|
#include "connector_uart_dma.h"
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "rusEfiFunctionalTest.h"
|
2020-06-21 18:47:51 -07:00
|
|
|
#endif // EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
|
|
|
extern LoggingWithStorage tsLogger;
|
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_PROD_CODE
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "pin_repository.h"
|
2017-05-02 10:34:01 -07:00
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if HAL_USE_SERIAL_USB
|
2020-08-21 11:12:28 -07:00
|
|
|
// Assert that the USB tx/rx buffers are large enough to fit one full packet
|
|
|
|
static_assert(SERIAL_USB_BUFFERS_SIZE >= BLOCKING_FACTOR + 10);
|
2020-09-11 02:50:48 -07:00
|
|
|
#define SERIAL_USB_DRIVER SerialUSBDriver
|
|
|
|
#define TS_USB_DEVICE EFI_CONSOLE_USB_DEVICE // SDU1
|
2019-04-01 11:18:21 -07:00
|
|
|
#endif /* HAL_USE_SERIAL_USB */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-09-11 02:50:48 -07:00
|
|
|
#ifdef TS_USB_DEVICE
|
|
|
|
extern SERIAL_USB_DRIVER TS_USB_DEVICE;
|
|
|
|
#endif /* TS_USB_DEVICE */
|
|
|
|
|
|
|
|
#ifdef TS_CAN_DEVICE
|
2020-09-23 11:06:22 -07:00
|
|
|
#include "serial_can.h"
|
2020-09-11 02:50:48 -07:00
|
|
|
#endif /* TS_CAN_DEVICE */
|
|
|
|
|
|
|
|
|
2017-05-23 10:10:43 -07:00
|
|
|
#if TS_UART_DMA_MODE
|
2019-03-29 07:29:01 -07:00
|
|
|
#elif TS_UART_MODE
|
|
|
|
/* Note: This structure is modified from the default ChibiOS layout! */
|
|
|
|
static UARTConfig tsUartConfig = {
|
2021-01-19 12:20:35 -08:00
|
|
|
.txend1_cb = NULL,
|
|
|
|
.txend2_cb = NULL,
|
|
|
|
.rxend_cb = NULL,
|
|
|
|
.rxchar_cb = NULL,
|
|
|
|
.rxerr_cb = NULL,
|
|
|
|
.timeout_cb = NULL,
|
|
|
|
.speed = 0,
|
|
|
|
.cr1 = 0,
|
|
|
|
.cr2 = 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN,
|
|
|
|
.cr3 = 0,
|
|
|
|
.rxhalf_cb = NULL
|
2019-03-29 07:29:01 -07:00
|
|
|
};
|
2020-09-11 02:50:48 -07:00
|
|
|
#elif defined(TS_SERIAL_DEVICE)
|
2019-04-15 05:40:12 -07:00
|
|
|
static SerialConfig tsSerialConfig = { .speed = 0, .cr1 = 0, .cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN, .cr3 = 0 };
|
2020-09-11 02:50:48 -07:00
|
|
|
#elif defined(TS_CAN_DEVICE)
|
|
|
|
static CANConfig tsCanConfig = { CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, CAN_BTR_500 };
|
2017-05-23 10:10:43 -07:00
|
|
|
#endif /* TS_UART_DMA_MODE */
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-05-23 10:10:43 -07:00
|
|
|
|
|
|
|
void startTsPort(ts_channel_s *tsChannel) {
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_PROD_CODE
|
2020-11-15 08:55:26 -08:00
|
|
|
tsChannel->channel = (BaseChannel *) NULL;
|
2020-09-11 02:50:48 -07:00
|
|
|
#if defined(TS_USB_DEVICE)
|
2020-05-04 17:52:32 -07:00
|
|
|
#if defined(TS_UART_DEVICE)
|
2020-09-11 02:54:21 -07:00
|
|
|
#error "cannot have TS_UART_DEVICE and TS_USB_DEVICE"
|
2020-05-04 17:52:32 -07:00
|
|
|
#endif
|
2019-04-01 14:39:07 -07:00
|
|
|
print("TunerStudio over USB serial");
|
|
|
|
/**
|
|
|
|
* This method contains a long delay, that's the reason why this is not done on the main thread
|
2019-04-21 11:00:19 -07:00
|
|
|
* TODO: actually now with some refactoring this IS on the main thread :(
|
2019-04-01 14:39:07 -07:00
|
|
|
*/
|
|
|
|
usb_serial_start();
|
|
|
|
// if console uses UART then TS uses USB
|
2020-09-11 02:50:48 -07:00
|
|
|
tsChannel->channel = (BaseChannel *) &TS_USB_DEVICE;
|
2019-04-01 14:39:07 -07:00
|
|
|
return;
|
2020-09-11 02:50:48 -07:00
|
|
|
#endif /* TS_USB_DEVICE */
|
2019-04-01 14:39:07 -07:00
|
|
|
#if defined(TS_UART_DEVICE) || defined(TS_SERIAL_DEVICE)
|
2019-12-11 14:48:55 -08:00
|
|
|
if (CONFIG(useSerialPort)) {
|
2019-04-01 14:39:07 -07:00
|
|
|
|
|
|
|
print("TunerStudio over USART");
|
2019-12-07 18:22:09 -08:00
|
|
|
/**
|
|
|
|
* We have hard-coded USB serial console so that it would be clear how to connect to each specific board,
|
|
|
|
* but for UART serial we allow users to change settings.
|
|
|
|
*/
|
2019-04-01 14:39:07 -07:00
|
|
|
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
|
2020-06-21 13:37:33 -07:00
|
|
|
tsChannel->uartp = TS_UART_DEVICE;
|
|
|
|
startUartDmaConnector(tsChannel->uartp PASS_CONFIG_PARAMETER_SUFFIX);
|
2019-04-01 14:39:07 -07:00
|
|
|
#elif TS_UART_MODE
|
|
|
|
print("Using UART mode");
|
|
|
|
// start DMA driver
|
2019-12-11 14:48:55 -08:00
|
|
|
tsUartConfig.speed = CONFIG(tunerStudioSerialSpeed);
|
2019-04-01 14:39:07 -07:00
|
|
|
uartStart(TS_UART_DEVICE, &tsUartConfig);
|
|
|
|
#elif defined(TS_SERIAL_DEVICE)
|
|
|
|
print("Using Serial mode");
|
2019-12-11 14:48:55 -08:00
|
|
|
tsSerialConfig.speed = CONFIG(tunerStudioSerialSpeed);
|
2019-04-01 14:39:07 -07:00
|
|
|
|
|
|
|
sdStart(TS_SERIAL_DEVICE, &tsSerialConfig);
|
|
|
|
|
|
|
|
tsChannel->channel = (BaseChannel *) TS_SERIAL_DEVICE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* TS_UART_DMA_MODE || TS_UART_MODE */
|
2020-09-11 02:50:48 -07:00
|
|
|
#if defined(TS_CAN_DEVICE)
|
|
|
|
/*if (CONFIG(useCanForTs))*/ {
|
|
|
|
print("TunerStudio over CAN");
|
2020-09-11 02:54:21 -07:00
|
|
|
|
2020-09-11 02:50:48 -07:00
|
|
|
efiSetPadMode("ts can rx", GPIOG_13/*CONFIG(canRxPin)*/, PAL_MODE_ALTERNATE(TS_CAN_AF)); // CAN2_RX2_0
|
|
|
|
efiSetPadMode("ts can tx", GPIOG_14/*CONFIG(canTxPin)*/, PAL_MODE_ALTERNATE(TS_CAN_AF)); // CAN2_TX2_0
|
|
|
|
|
|
|
|
canStart(&TS_CAN_DEVICE, &tsCanConfig);
|
|
|
|
canInit(&TS_CAN_DEVICE);
|
2020-09-11 02:54:21 -07:00
|
|
|
|
2020-09-11 02:50:48 -07:00
|
|
|
//tsChannel->channel = (BaseChannel *) &TS_CAN_DEVICE;
|
|
|
|
}
|
|
|
|
#endif /* TS_CAN_DEVICE */
|
2020-11-15 08:55:26 -08:00
|
|
|
#elif EFI_SIMULATOR /* EFI_PROD_CODE */
|
2019-04-01 14:39:07 -07:00
|
|
|
tsChannel->channel = (BaseChannel *) TS_SIMULATOR_PORT;
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-06-04 05:48:53 -07:00
|
|
|
bool stopTsPort(ts_channel_s *tsChannel) {
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_PROD_CODE
|
|
|
|
#if EFI_USB_SERIAL
|
2019-04-01 14:39:07 -07:00
|
|
|
// don't stop USB!
|
|
|
|
//usb_serial_stop();
|
|
|
|
return false;
|
|
|
|
#endif
|
2019-12-11 14:48:55 -08:00
|
|
|
if (CONFIG(useSerialPort)) {
|
2017-06-04 05:48:53 -07:00
|
|
|
// todo: disable Rx/Tx pads?
|
2019-04-01 14:39:07 -07:00
|
|
|
#if (TS_UART_DMA_MODE || TS_UART_MODE)
|
|
|
|
uartStop(TS_UART_DEVICE);
|
|
|
|
#endif /* TS_UART_DMA_MODE || TS_UART_MODE */
|
|
|
|
#ifdef TS_SERIAL_DEVICE
|
|
|
|
sdStop(TS_SERIAL_DEVICE);
|
|
|
|
#endif /* TS_SERIAL_DEVICE */
|
2017-06-04 05:48:53 -07:00
|
|
|
}
|
2020-09-11 02:50:48 -07:00
|
|
|
#if defined(TS_CAN_DEVICE)
|
|
|
|
/*if (CONFIG(useCanForTs))*/ {
|
|
|
|
canStop(&TS_CAN_DEVICE);
|
|
|
|
}
|
|
|
|
#endif /* TS_CAN_DEVICE */
|
2019-04-01 14:39:07 -07:00
|
|
|
tsChannel->channel = (BaseChannel *) NULL;
|
|
|
|
return true;
|
|
|
|
#else /* EFI_PROD_CODE */
|
|
|
|
// don't stop simulator!
|
|
|
|
return false;
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2017-06-04 05:48:53 -07:00
|
|
|
}
|
|
|
|
|
2020-11-15 08:55:26 -08:00
|
|
|
#if EFI_UNIT_TEST
|
2020-11-15 09:27:47 -08:00
|
|
|
int sr5TestWriteDataIndex = 0;
|
|
|
|
uint8_t st5TestBuffer[16000];
|
2020-11-15 08:55:26 -08:00
|
|
|
|
2020-11-15 09:27:47 -08:00
|
|
|
void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size) {
|
|
|
|
memcpy(&st5TestBuffer[sr5TestWriteDataIndex], buffer, size);
|
|
|
|
sr5TestWriteDataIndex += size;
|
2020-11-15 08:55:26 -08:00
|
|
|
}
|
|
|
|
#endif // EFI_UNIT_TEST
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2017-05-23 11:37:03 -07:00
|
|
|
void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size) {
|
2019-02-23 09:33:49 -08:00
|
|
|
efiAssertVoid(CUSTOM_ERR_6570, getCurrentRemainingStack() > 64, "tunerStudioWriteData");
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
logMsg("chSequentialStreamWrite [%d]\r\n", size);
|
|
|
|
#endif
|
2017-05-23 10:10:43 -07:00
|
|
|
|
2020-06-21 18:47:51 -07:00
|
|
|
#if (PRIMARY_UART_DMA_MODE || TS_UART_DMA_MODE || TS_UART_MODE) && EFI_PROD_CODE
|
|
|
|
if (tsChannel->uartp != nullptr) {
|
2020-09-11 02:54:21 -07:00
|
|
|
int transferred = size;
|
|
|
|
uartSendTimeout(tsChannel->uartp, (size_t *)&transferred, buffer, BINARY_IO_TIMEOUT);
|
|
|
|
return;
|
2020-06-21 18:47:51 -07:00
|
|
|
}
|
2020-09-11 02:50:48 -07:00
|
|
|
#elif defined(TS_CAN_DEVICE)
|
|
|
|
UNUSED(tsChannel);
|
|
|
|
int transferred = size;
|
|
|
|
canAddToTxStreamTimeout(&TS_CAN_DEVICE, (size_t *)&transferred, buffer, BINARY_IO_TIMEOUT);
|
2020-09-11 04:05:32 -07:00
|
|
|
#endif
|
2020-01-20 22:47:58 -08:00
|
|
|
if (tsChannel->channel == nullptr)
|
2017-05-23 10:10:43 -07:00
|
|
|
return;
|
2018-01-24 18:34:05 -08:00
|
|
|
|
|
|
|
// int transferred = chnWriteTimeout(tsChannel->channel, buffer, size, BINARY_IO_TIMEOUT);
|
|
|
|
// temporary attempt to work around #553
|
|
|
|
// instead of one huge packet let's try sending a few smaller packets
|
|
|
|
int transferred = 0;
|
|
|
|
int stillToTransfer = size;
|
|
|
|
while (stillToTransfer > 0) {
|
2018-01-25 06:46:31 -08:00
|
|
|
int thisTransferSize = minI(stillToTransfer, 768);
|
2018-01-24 18:34:05 -08:00
|
|
|
transferred += chnWriteTimeout(tsChannel->channel, buffer, thisTransferSize, BINARY_IO_TIMEOUT);
|
|
|
|
buffer += thisTransferSize;
|
|
|
|
stillToTransfer -= thisTransferSize;
|
|
|
|
}
|
|
|
|
|
2017-05-23 10:10:43 -07:00
|
|
|
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
logMsg("transferred [%d]\r\n", transferred);
|
|
|
|
#endif
|
|
|
|
if (transferred != size) {
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
logMsg("!!! NOT ACCEPTED %d out of %d !!!", transferred, size);
|
2017-05-23 14:39:47 -07:00
|
|
|
#endif /* EFI_SIMULATOR */
|
2015-07-10 06:01:56 -07:00
|
|
|
scheduleMsg(&tsLogger, "!!! NOT ACCEPTED %d out of %d !!!", transferred, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 11:08:12 -07:00
|
|
|
int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout) {
|
2020-06-21 13:37:33 -07:00
|
|
|
#if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
|
|
|
if (tsChannel->uartp!= NULL) {
|
|
|
|
extern uart_dma_s tsUartDma;
|
|
|
|
return (int)iqReadTimeout(&tsUartDma.fifoRxQueue, (uint8_t * )buffer, (size_t)size, timeout);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-08-28 18:03:01 -07:00
|
|
|
#if TS_UART_DMA_MODE
|
|
|
|
#elif TS_UART_MODE
|
2019-03-29 07:29:01 -07:00
|
|
|
UNUSED(tsChannel);
|
|
|
|
size_t received = (size_t)size;
|
|
|
|
uartReceiveTimeout(TS_UART_DEVICE, &received, buffer, timeout);
|
|
|
|
return (int)received;
|
2020-09-11 02:50:48 -07:00
|
|
|
#elif defined(TS_CAN_DEVICE)
|
|
|
|
UNUSED(tsChannel);
|
|
|
|
size_t received = (size_t)size;
|
|
|
|
canStreamReceiveTimeout(&TS_CAN_DEVICE, &received, buffer, timeout);
|
|
|
|
return (int)received;
|
2017-05-23 14:39:47 -07:00
|
|
|
#else /* TS_UART_DMA_MODE */
|
2020-01-20 22:47:58 -08:00
|
|
|
if (tsChannel->channel == nullptr)
|
2017-05-23 10:10:43 -07:00
|
|
|
return 0;
|
2017-05-30 11:08:12 -07:00
|
|
|
return chnReadTimeout(tsChannel->channel, (uint8_t * )buffer, size, timeout);
|
2017-05-23 14:39:47 -07:00
|
|
|
#endif /* TS_UART_DMA_MODE */
|
2020-06-21 18:17:48 -07:00
|
|
|
firmwareError(CUSTOM_ERR_6126, "Unexpected channel situation");
|
|
|
|
return 0;
|
2017-05-23 10:10:43 -07:00
|
|
|
}
|
|
|
|
|
2017-05-30 11:08:12 -07:00
|
|
|
int sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size) {
|
|
|
|
return sr5ReadDataTimeout(tsChannel, buffer, size, SR5_READ_TIMEOUT);
|
|
|
|
}
|
2020-11-15 08:55:26 -08:00
|
|
|
#endif // EFI_PROD_CODE || EFI_SIMULATOR
|
2017-05-30 11:08:12 -07:00
|
|
|
|
2020-11-15 09:36:07 -08:00
|
|
|
void sr5WriteCrcPacketSmall(ts_channel_s* tsChannel, uint8_t responseCode, const uint8_t* buf, size_t size) {
|
2020-11-15 07:28:23 -08:00
|
|
|
auto scratchBuffer = tsChannel->scratchBuffer;
|
|
|
|
|
|
|
|
// don't transmit too large a buffer
|
|
|
|
efiAssertVoid(OBD_PCM_Processor_Fault, size <= BLOCKING_FACTOR + 7, "sr5WriteCrcPacket tried to transmit too large a packet")
|
|
|
|
|
|
|
|
// If transmitting data, copy it in to place in the scratch buffer
|
|
|
|
// We want to prevent the data changing itself (higher priority threads could write
|
|
|
|
// tsOutputChannels) during the CRC computation. Instead compute the CRC on our
|
|
|
|
// local buffer that nobody else will write.
|
|
|
|
if (size) {
|
|
|
|
memcpy(scratchBuffer + 3, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Index 0/1 = packet size (big endian)
|
|
|
|
*(uint16_t*)scratchBuffer = SWAP_UINT16(size + 1);
|
|
|
|
// Index 2 = response code
|
|
|
|
scratchBuffer[2] = responseCode;
|
|
|
|
|
|
|
|
// CRC is computed on the responseCode and payload but not length
|
|
|
|
uint32_t crc = crc32(&scratchBuffer[2], size + 1); // command part of CRC
|
|
|
|
|
|
|
|
// Place the CRC at the end
|
|
|
|
*reinterpret_cast<uint32_t*>(&scratchBuffer[size + 3]) = SWAP_UINT32(crc);
|
|
|
|
|
|
|
|
// Write to the underlying stream
|
|
|
|
sr5WriteData(tsChannel, reinterpret_cast<uint8_t*>(scratchBuffer), size + 7);
|
|
|
|
}
|
|
|
|
|
2020-11-15 09:36:07 -08:00
|
|
|
void sr5WriteCrcPacketLarge(ts_channel_s* tsChannel, uint8_t responseCode, const uint8_t* buf, size_t size) {
|
2020-11-15 07:28:23 -08:00
|
|
|
uint8_t headerBuffer[3];
|
|
|
|
uint8_t crcBuffer[4];
|
|
|
|
|
|
|
|
*(uint16_t*)headerBuffer = SWAP_UINT16(size + 1);
|
|
|
|
*(uint8_t*)(headerBuffer + 2) = responseCode;
|
|
|
|
|
|
|
|
// Command part of CRC
|
|
|
|
uint32_t crc = crc32((void*)(headerBuffer + 2), 1);
|
|
|
|
// Data part of CRC
|
|
|
|
crc = crc32inc((void*)buf, crc, size);
|
|
|
|
*(uint32_t*)crcBuffer = SWAP_UINT32(crc);
|
|
|
|
|
|
|
|
// Write header
|
|
|
|
sr5WriteData(tsChannel, headerBuffer, sizeof(headerBuffer));
|
|
|
|
|
|
|
|
// If data, write that
|
|
|
|
if (size) {
|
|
|
|
sr5WriteData(tsChannel, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lastly the CRC footer
|
|
|
|
sr5WriteData(tsChannel, crcBuffer, sizeof(crcBuffer));
|
|
|
|
}
|
2020-11-15 04:14:50 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
|
|
|
|
*/
|
|
|
|
void sr5WriteCrcPacket(ts_channel_s *tsChannel, uint8_t responseCode, const uint8_t* buf, size_t size) {
|
2020-11-15 07:28:23 -08:00
|
|
|
// don't transmit a null buffer...
|
|
|
|
if (!buf) {
|
|
|
|
size = 0;
|
|
|
|
}
|
2020-11-15 04:14:50 -08:00
|
|
|
|
|
|
|
#if defined(TS_CAN_DEVICE) && defined(TS_CAN_DEVICE_SHORT_PACKETS_IN_ONE_FRAME)
|
|
|
|
// a special case for short packets: we can sent them in 1 frame, without CRC & size,
|
|
|
|
// because the CAN protocol is already protected by its own checksum.
|
|
|
|
if ((size + 1) <= 7) {
|
|
|
|
sr5WriteData(tsChannel, &responseCode, 1); // header without size
|
|
|
|
if (size > 0) {
|
|
|
|
sr5WriteData(tsChannel, (const uint8_t*)buf, size); // body
|
|
|
|
}
|
|
|
|
sr5FlushData(tsChannel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* TS_CAN_DEVICE */
|
2020-11-15 07:28:23 -08:00
|
|
|
if (size <= BLOCKING_FACTOR + 7) {
|
|
|
|
// small packets use small packet optimization
|
|
|
|
sr5WriteCrcPacketSmall(tsChannel, responseCode, buf, size);
|
|
|
|
} else {
|
|
|
|
sr5WriteCrcPacketLarge(tsChannel, responseCode, buf, size);
|
2020-11-15 07:02:40 -08:00
|
|
|
}
|
2020-11-17 20:47:35 -08:00
|
|
|
|
2020-09-11 02:50:48 -07:00
|
|
|
sr5FlushData(tsChannel);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-23 11:37:03 -07:00
|
|
|
void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const uint8_t * buffer, int size) {
|
2015-07-10 06:01:56 -07:00
|
|
|
if (mode == TS_CRC) {
|
2017-05-23 11:37:03 -07:00
|
|
|
sr5WriteCrcPacket(tsChannel, TS_RESPONSE_OK, buffer, size);
|
2015-07-10 06:01:56 -07:00
|
|
|
} else {
|
2020-09-11 02:50:48 -07:00
|
|
|
if (size > 0) {
|
2017-05-23 11:37:03 -07:00
|
|
|
sr5WriteData(tsChannel, buffer, size);
|
2020-09-11 02:50:48 -07:00
|
|
|
sr5FlushData(tsChannel);
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 11:18:21 -07:00
|
|
|
bool sr5IsReady(ts_channel_s *tsChannel) {
|
2019-04-12 19:10:57 -07:00
|
|
|
#if EFI_USB_SERIAL
|
2019-04-01 11:18:21 -07:00
|
|
|
if (isUsbSerial(tsChannel->channel)) {
|
2017-05-23 10:10:43 -07:00
|
|
|
// TS uses USB when console uses serial
|
|
|
|
return is_usb_serial_ready();
|
|
|
|
}
|
2019-04-01 11:18:21 -07:00
|
|
|
#endif /* EFI_USB_SERIAL */
|
2017-05-23 10:10:43 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-11 02:50:48 -07:00
|
|
|
void sr5FlushData(ts_channel_s *tsChannel) {
|
|
|
|
#if defined(TS_CAN_DEVICE)
|
|
|
|
UNUSED(tsChannel);
|
|
|
|
canFlushTxStream(&TS_CAN_DEVICE);
|
2020-11-14 16:21:29 -08:00
|
|
|
#else
|
|
|
|
UNUSED(tsChannel);
|
2020-09-11 02:50:48 -07:00
|
|
|
#endif /* TS_CAN_DEVICE */
|
|
|
|
}
|
|
|
|
|