refactoring connectivity
This commit is contained in:
parent
e57fbcb24b
commit
2a64b6eb1a
|
@ -289,6 +289,7 @@
|
||||||
*/
|
*/
|
||||||
#define TS_UART_DMA_MODE FALSE
|
#define TS_UART_DMA_MODE FALSE
|
||||||
#define TS_UART_MODE TRUE
|
#define TS_UART_MODE TRUE
|
||||||
|
#define PRIMARY_UART_DMA_MODE FALSE
|
||||||
|
|
||||||
#define TS_UART_DEVICE (&UARTD2)
|
#define TS_UART_DEVICE (&UARTD2)
|
||||||
#undef TS_SERIAL_DEVICE
|
#undef TS_SERIAL_DEVICE
|
||||||
|
|
|
@ -308,6 +308,8 @@
|
||||||
*/
|
*/
|
||||||
#define TS_UART_DMA_MODE FALSE
|
#define TS_UART_DMA_MODE FALSE
|
||||||
|
|
||||||
|
#define PRIMARY_UART_DMA_MODE FALSE
|
||||||
|
|
||||||
//#define TS_UART_DEVICE (&UARTD3)
|
//#define TS_UART_DEVICE (&UARTD3)
|
||||||
#define TS_SERIAL_DEVICE (&SD3)
|
#define TS_SERIAL_DEVICE (&SD3)
|
||||||
|
|
||||||
|
|
|
@ -343,6 +343,7 @@
|
||||||
* in mcuconf.h
|
* in mcuconf.h
|
||||||
*/
|
*/
|
||||||
#define TS_UART_DMA_MODE FALSE
|
#define TS_UART_DMA_MODE FALSE
|
||||||
|
#define PRIMARY_UART_DMA_MODE FALSE
|
||||||
|
|
||||||
//#define TS_UART_DEVICE (&UARTD3)
|
//#define TS_UART_DEVICE (&UARTD3)
|
||||||
#define TS_SERIAL_DEVICE (&SD3)
|
#define TS_SERIAL_DEVICE (&SD3)
|
||||||
|
|
|
@ -83,6 +83,7 @@
|
||||||
// todo: our "DMA-half" ChibiOS patch not implemented for USARTv2/STM32F7
|
// todo: our "DMA-half" ChibiOS patch not implemented for USARTv2/STM32F7
|
||||||
#undef TS_UART_DMA_MODE
|
#undef TS_UART_DMA_MODE
|
||||||
#define TS_UART_DMA_MODE FALSE
|
#define TS_UART_DMA_MODE FALSE
|
||||||
|
#define PRIMARY_UART_DMA_MODE FALSE
|
||||||
|
|
||||||
#undef TS_UART_DEVICE
|
#undef TS_UART_DEVICE
|
||||||
//#define TS_UART_DEVICE (&UARTD3)
|
//#define TS_UART_DEVICE (&UARTD3)
|
||||||
|
|
|
@ -28,49 +28,6 @@ extern SerialUSBDriver SDU1;
|
||||||
#endif /* HAL_USE_SERIAL_USB */
|
#endif /* HAL_USE_SERIAL_USB */
|
||||||
|
|
||||||
#if TS_UART_DMA_MODE
|
#if TS_UART_DMA_MODE
|
||||||
// Async. FIFO buffer takes some RAM...
|
|
||||||
static uart_dma_s tsUartDma;
|
|
||||||
|
|
||||||
/* Common function for all DMA-UART IRQ handlers. */
|
|
||||||
static void tsCopyDataFromDMA() {
|
|
||||||
chSysLockFromISR();
|
|
||||||
// get 0-based DMA buffer position
|
|
||||||
int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_UART_DEVICE->dmarx);
|
|
||||||
// if the position is wrapped (circular DMA-mode enabled)
|
|
||||||
if (dmaPos < tsUartDma.readPos)
|
|
||||||
dmaPos += TS_DMA_BUFFER_SIZE;
|
|
||||||
// we need to update the current readPos
|
|
||||||
int newReadPos = tsUartDma.readPos;
|
|
||||||
for (int i = newReadPos; i < dmaPos; ) {
|
|
||||||
if (iqPutI(&tsUartDma.fifoRxQueue, tsUartDma.dmaBuffer[newReadPos]) != Q_OK) {
|
|
||||||
break; // todo: ignore overflow?
|
|
||||||
}
|
|
||||||
// the read position should always stay inside the buffer range
|
|
||||||
newReadPos = (++i) & (TS_DMA_BUFFER_SIZE - 1);
|
|
||||||
}
|
|
||||||
tsUartDma.readPos = newReadPos;
|
|
||||||
chSysUnlockFromISR();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We use the same handler code for both halves. */
|
|
||||||
static void tsRxIRQHalfHandler(UARTDriver *uartp, uartflags_t full) {
|
|
||||||
UNUSED(uartp);
|
|
||||||
UNUSED(full);
|
|
||||||
tsCopyDataFromDMA();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This handler is called right after the UART receiver has finished its work. */
|
|
||||||
static void tsRxIRQIdleHandler(UARTDriver *uartp) {
|
|
||||||
UNUSED(uartp);
|
|
||||||
tsCopyDataFromDMA();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Note: This structure is modified from the default ChibiOS layout! */
|
|
||||||
static UARTConfig tsDmaUartConfig = {
|
|
||||||
.txend1_cb = NULL, .txend2_cb = NULL, .rxend_cb = NULL, .rxchar_cb = NULL, .rxerr_cb = NULL,
|
|
||||||
.speed = 0, .cr1 = 0, .cr2 = 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN, .cr3 = 0,
|
|
||||||
.timeout_cb = tsRxIRQIdleHandler, .rxhalf_cb = tsRxIRQHalfHandler
|
|
||||||
};
|
|
||||||
#elif TS_UART_MODE
|
#elif TS_UART_MODE
|
||||||
/* Note: This structure is modified from the default ChibiOS layout! */
|
/* Note: This structure is modified from the default ChibiOS layout! */
|
||||||
static UARTConfig tsUartConfig = {
|
static UARTConfig tsUartConfig = {
|
||||||
|
@ -114,17 +71,8 @@ void startTsPort(ts_channel_s *tsChannel) {
|
||||||
efiSetPadMode("tunerstudio tx", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
|
efiSetPadMode("tunerstudio tx", engineConfiguration->binarySerialTxPin, PAL_MODE_ALTERNATE(TS_SERIAL_AF));
|
||||||
|
|
||||||
#if TS_UART_DMA_MODE
|
#if TS_UART_DMA_MODE
|
||||||
print("Using UART-DMA mode");
|
tsChannel->uartp = TS_UART_DEVICE;
|
||||||
// init FIFO queue
|
startUartDmaConnector(tsChannel->uartp PASS_CONFIG_PARAMETER_SUFFIX);
|
||||||
iqObjectInit(&tsUartDma.fifoRxQueue, tsUartDma.buffer, sizeof(tsUartDma.buffer), NULL, NULL);
|
|
||||||
|
|
||||||
// start DMA driver
|
|
||||||
tsDmaUartConfig.speed = CONFIG(tunerStudioSerialSpeed);
|
|
||||||
uartStart(TS_UART_DEVICE, &tsDmaUartConfig);
|
|
||||||
|
|
||||||
// start continuous DMA transfer using our circular buffer
|
|
||||||
tsUartDma.readPos = 0;
|
|
||||||
uartStartReceive(TS_UART_DEVICE, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer);
|
|
||||||
#elif TS_UART_MODE
|
#elif TS_UART_MODE
|
||||||
print("Using UART mode");
|
print("Using UART mode");
|
||||||
// start DMA driver
|
// start DMA driver
|
||||||
|
@ -209,9 +157,15 @@ void sr5WriteData(ts_channel_s *tsChannel, const 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) {
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
#if TS_UART_DMA_MODE
|
#if TS_UART_DMA_MODE
|
||||||
UNUSED(tsChannel);
|
|
||||||
return (int)iqReadTimeout(&tsUartDma.fifoRxQueue, (uint8_t * )buffer, (size_t)size, timeout);
|
|
||||||
#elif TS_UART_MODE
|
#elif TS_UART_MODE
|
||||||
UNUSED(tsChannel);
|
UNUSED(tsChannel);
|
||||||
size_t received = (size_t)size;
|
size_t received = (size_t)size;
|
||||||
|
|
|
@ -22,14 +22,18 @@ typedef enum {
|
||||||
TS_CRC = 1
|
TS_CRC = 1
|
||||||
} ts_response_format_e;
|
} ts_response_format_e;
|
||||||
|
|
||||||
typedef struct {
|
struct ts_channel_s {
|
||||||
BaseChannel * channel;
|
BaseChannel * channel;
|
||||||
uint8_t writeBuffer[7]; // size(2 bytes) + response(1 byte) + crc32 (4 bytes)
|
uint8_t writeBuffer[7]; // size(2 bytes) + response(1 byte) + crc32 (4 bytes)
|
||||||
/**
|
/**
|
||||||
* See 'blockingFactor' in rusefi.ini
|
* See 'blockingFactor' in rusefi.ini
|
||||||
*/
|
*/
|
||||||
char crcReadBuffer[BLOCKING_FACTOR + 30];
|
char crcReadBuffer[BLOCKING_FACTOR + 30];
|
||||||
} ts_channel_s;
|
|
||||||
|
#if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
||||||
|
UARTDriver *uartp = nullptr;
|
||||||
|
#endif // TS_UART_DMA_MODE
|
||||||
|
};
|
||||||
|
|
||||||
// These commands are used exclusively by the rusEfi console
|
// These commands are used exclusively by the rusEfi console
|
||||||
#define TS_TEST_COMMAND 't' // 0x74
|
#define TS_TEST_COMMAND 't' // 0x74
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* @file connector_uart_dma.cpp
|
||||||
|
*
|
||||||
|
* @date Jun 21, 2020
|
||||||
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
||||||
|
|
||||||
|
// Async. FIFO buffer takes some RAM...
|
||||||
|
uart_dma_s tsUartDma;
|
||||||
|
|
||||||
|
/* Common function for all DMA-UART IRQ handlers. */
|
||||||
|
static void tsCopyDataFromDMA() {
|
||||||
|
chSysLockFromISR();
|
||||||
|
// get 0-based DMA buffer position
|
||||||
|
int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_UART_DEVICE->dmarx);
|
||||||
|
// if the position is wrapped (circular DMA-mode enabled)
|
||||||
|
if (dmaPos < tsUartDma.readPos)
|
||||||
|
dmaPos += TS_DMA_BUFFER_SIZE;
|
||||||
|
// we need to update the current readPos
|
||||||
|
int newReadPos = tsUartDma.readPos;
|
||||||
|
for (int i = newReadPos; i < dmaPos; ) {
|
||||||
|
if (iqPutI(&tsUartDma.fifoRxQueue, tsUartDma.dmaBuffer[newReadPos]) != Q_OK) {
|
||||||
|
break; // todo: ignore overflow?
|
||||||
|
}
|
||||||
|
// the read position should always stay inside the buffer range
|
||||||
|
newReadPos = (++i) & (TS_DMA_BUFFER_SIZE - 1);
|
||||||
|
}
|
||||||
|
tsUartDma.readPos = newReadPos;
|
||||||
|
chSysUnlockFromISR();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We use the same handler code for both halves. */
|
||||||
|
static void tsRxIRQHalfHandler(UARTDriver *uartp, uartflags_t full) {
|
||||||
|
UNUSED(uartp);
|
||||||
|
UNUSED(full);
|
||||||
|
tsCopyDataFromDMA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This handler is called right after the UART receiver has finished its work. */
|
||||||
|
static void tsRxIRQIdleHandler(UARTDriver *uartp) {
|
||||||
|
UNUSED(uartp);
|
||||||
|
tsCopyDataFromDMA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Note: This structure is modified from the default ChibiOS layout! */
|
||||||
|
static UARTConfig tsDmaUartConfig = {
|
||||||
|
.txend1_cb = NULL, .txend2_cb = NULL, .rxend_cb = NULL, .rxchar_cb = NULL, .rxerr_cb = NULL,
|
||||||
|
.speed = 0, .cr1 = 0, .cr2 = 0/*USART_CR2_STOP1_BITS*/ | USART_CR2_LINEN, .cr3 = 0,
|
||||||
|
.timeout_cb = tsRxIRQIdleHandler, .rxhalf_cb = tsRxIRQHalfHandler
|
||||||
|
};
|
||||||
|
|
||||||
|
void startUartDmaConnector(UARTDriver *uartp DECLARE_CONFIG_PARAMETER_SUFFIX) {
|
||||||
|
print("Using UART-DMA mode");
|
||||||
|
// init FIFO queue
|
||||||
|
iqObjectInit(&tsUartDma.fifoRxQueue, tsUartDma.buffer, sizeof(tsUartDma.buffer), NULL, NULL);
|
||||||
|
|
||||||
|
// start DMA driver
|
||||||
|
tsDmaUartConfig.speed = CONFIG(tunerStudioSerialSpeed);
|
||||||
|
uartStart(TS_UART_DEVICE, &tsDmaUartConfig);
|
||||||
|
|
||||||
|
// start continuous DMA transfer using our circular buffer
|
||||||
|
tsUartDma.readPos = 0;
|
||||||
|
uartStartReceive(uartp, sizeof(tsUartDma.dmaBuffer), tsUartDma.dmaBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
|
@ -24,3 +24,9 @@ typedef struct {
|
||||||
// input FIFO Rx queue
|
// input FIFO Rx queue
|
||||||
input_queue_t fifoRxQueue;
|
input_queue_t fifoRxQueue;
|
||||||
} uart_dma_s;
|
} uart_dma_s;
|
||||||
|
|
||||||
|
#if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
||||||
|
void startUartDmaConnector(UARTDriver *uartp DECLARE_CONFIG_PARAMETER_SUFFIX);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ CONSOLESRC =
|
||||||
CONSOLE_SRC_CPP = $(PROJECT_DIR)/console/status_loop.cpp \
|
CONSOLE_SRC_CPP = $(PROJECT_DIR)/console/status_loop.cpp \
|
||||||
$(PROJECT_DIR)/console/console_io.cpp \
|
$(PROJECT_DIR)/console/console_io.cpp \
|
||||||
$(PROJECT_DIR)/console/eficonsole.cpp \
|
$(PROJECT_DIR)/console/eficonsole.cpp \
|
||||||
|
$(PROJECT_DIR)/console/connector_uart_dma.cpp \
|
||||||
$(PROJECT_DIR)/console/binary_log/tooth_logger.cpp \
|
$(PROJECT_DIR)/console/binary_log/tooth_logger.cpp \
|
||||||
$(PROJECT_DIR)/console/binary_log/log_field.cpp \
|
$(PROJECT_DIR)/console/binary_log/log_field.cpp \
|
||||||
$(PROJECT_DIR)/console/binary_log/binary_logging.cpp \
|
$(PROJECT_DIR)/console/binary_log/binary_logging.cpp \
|
||||||
|
|
|
@ -276,6 +276,13 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
|
||||||
logger = sharedLogger;
|
logger = sharedLogger;
|
||||||
console_line_callback = console_line_callback_p;
|
console_line_callback = console_line_callback_p;
|
||||||
|
|
||||||
|
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) || defined(EFI_CONSOLE_UART_DEVICE)) && ! EFI_SIMULATOR
|
||||||
|
efiSetPadMode("console RX", EFI_CONSOLE_RX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
||||||
|
efiSetPadMode("console TX", EFI_CONSOLE_TX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
||||||
|
isSerialConsoleStarted = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR)
|
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR)
|
||||||
/*
|
/*
|
||||||
* Activates the serial
|
* Activates the serial
|
||||||
|
@ -284,20 +291,10 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
|
||||||
serialConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
|
serialConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
|
||||||
sdStart(EFI_CONSOLE_SERIAL_DEVICE, &serialConfig);
|
sdStart(EFI_CONSOLE_SERIAL_DEVICE, &serialConfig);
|
||||||
|
|
||||||
efiSetPadMode("console RX", EFI_CONSOLE_RX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
|
||||||
efiSetPadMode("console TX", EFI_CONSOLE_TX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
|
||||||
|
|
||||||
isSerialConsoleStarted = true;
|
|
||||||
|
|
||||||
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_SERIAL_DEVICE), &consoleEventListener, 1);
|
chEvtRegisterMask((event_source_t *) chnGetEventSource(EFI_CONSOLE_SERIAL_DEVICE), &consoleEventListener, 1);
|
||||||
#elif (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR)
|
#elif (defined(EFI_CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR)
|
||||||
uartConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
|
uartConfig.speed = engineConfiguration->uartConsoleSerialSpeed;
|
||||||
uartStart(EFI_CONSOLE_UART_DEVICE, &uartConfig);
|
uartStart(EFI_CONSOLE_UART_DEVICE, &uartConfig);
|
||||||
|
|
||||||
efiSetPadMode("console RX", EFI_CONSOLE_RX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
|
||||||
efiSetPadMode("console TX", EFI_CONSOLE_TX_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_CONSOLE_AF));
|
|
||||||
|
|
||||||
isSerialConsoleStarted = true;
|
|
||||||
#endif /* EFI_CONSOLE_SERIAL_DEVICE || EFI_CONSOLE_UART_DEVICE */
|
#endif /* EFI_CONSOLE_SERIAL_DEVICE || EFI_CONSOLE_UART_DEVICE */
|
||||||
|
|
||||||
#if !defined(EFI_CONSOLE_NO_THREAD)
|
#if !defined(EFI_CONSOLE_NO_THREAD)
|
||||||
|
|
Loading…
Reference in New Issue