refactoring connectivity
This commit is contained in:
parent
997c723920
commit
57239f6001
|
@ -5,16 +5,20 @@
|
|||
* @author Andrey Belomutskiy, (c) 2012-2020
|
||||
*/
|
||||
|
||||
#include "connector_uart_dma.h"
|
||||
|
||||
#if TS_UART_DMA_MODE || PRIMARY_UART_DMA_MODE
|
||||
|
||||
EXTERN_CONFIG;
|
||||
|
||||
// Async. FIFO buffer takes some RAM...
|
||||
uart_dma_s tsUartDma;
|
||||
|
||||
/* Common function for all DMA-UART IRQ handlers. */
|
||||
static void tsCopyDataFromDMA() {
|
||||
static void tsCopyDataFromDMA(UARTDriver *uartp) {
|
||||
chSysLockFromISR();
|
||||
// get 0-based DMA buffer position
|
||||
int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(TS_UART_DEVICE->dmarx);
|
||||
int dmaPos = TS_DMA_BUFFER_SIZE - dmaStreamGetTransactionSize(uartp->dmarx);
|
||||
// if the position is wrapped (circular DMA-mode enabled)
|
||||
if (dmaPos < tsUartDma.readPos)
|
||||
dmaPos += TS_DMA_BUFFER_SIZE;
|
||||
|
@ -35,13 +39,13 @@ static void tsCopyDataFromDMA() {
|
|||
static void tsRxIRQHalfHandler(UARTDriver *uartp, uartflags_t full) {
|
||||
UNUSED(uartp);
|
||||
UNUSED(full);
|
||||
tsCopyDataFromDMA();
|
||||
tsCopyDataFromDMA(uartp);
|
||||
}
|
||||
|
||||
/* This handler is called right after the UART receiver has finished its work. */
|
||||
static void tsRxIRQIdleHandler(UARTDriver *uartp) {
|
||||
UNUSED(uartp);
|
||||
tsCopyDataFromDMA();
|
||||
tsCopyDataFromDMA(uartp);
|
||||
}
|
||||
|
||||
/* Note: This structure is modified from the default ChibiOS layout! */
|
||||
|
@ -58,7 +62,7 @@ void startUartDmaConnector(UARTDriver *uartp DECLARE_CONFIG_PARAMETER_SUFFIX) {
|
|||
|
||||
// start DMA driver
|
||||
tsDmaUartConfig.speed = CONFIG(tunerStudioSerialSpeed);
|
||||
uartStart(TS_UART_DEVICE, &tsDmaUartConfig);
|
||||
uartStart(uartp, &tsDmaUartConfig);
|
||||
|
||||
// start continuous DMA transfer using our circular buffer
|
||||
tsUartDma.readPos = 0;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "global.h"
|
||||
#include "engine_configuration.h"
|
||||
|
||||
// See uart_dma_s
|
||||
#define TS_FIFO_BUFFER_SIZE (BLOCKING_FACTOR + 30)
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "console_io.h"
|
||||
#include "os_util.h"
|
||||
#include "tunerstudio.h"
|
||||
#include "connector_uart_dma.h"
|
||||
|
||||
#if EFI_SIMULATOR
|
||||
#include "rusEfiFunctionalTest.h"
|
||||
|
@ -232,7 +233,7 @@ BaseChannel * getConsoleChannel(void) {
|
|||
#if HAL_USE_SERIAL_USB
|
||||
return (BaseChannel *) &CONSOLE_USB_DEVICE;
|
||||
#else
|
||||
return NULL;
|
||||
return nullptr;
|
||||
#endif /* HAL_USE_SERIAL_USB */
|
||||
}
|
||||
|
||||
|
@ -250,7 +251,10 @@ static THD_FUNCTION(consoleThreadEntryPoint, arg) {
|
|||
(void) arg;
|
||||
chRegSetThreadName("console thread");
|
||||
|
||||
#if !PRIMARY_UART_DMA_MODE
|
||||
primaryChannel.channel = (BaseChannel *) getConsoleChannel();
|
||||
#endif
|
||||
|
||||
if (primaryChannel.channel != NULL) {
|
||||
#if EFI_TUNER_STUDIO
|
||||
runBinaryProtocolLoop(&primaryChannel);
|
||||
|
@ -283,7 +287,11 @@ void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p)
|
|||
#endif
|
||||
|
||||
|
||||
#if (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR)
|
||||
#if (defined(CONSOLE_UART_DEVICE) && ! EFI_SIMULATOR)
|
||||
primaryChannel.uartp = CONSOLE_UART_DEVICE;
|
||||
startUartDmaConnector(primaryChannel.uartp PASS_CONFIG_PARAMETER_SUFFIX);
|
||||
|
||||
#elif (defined(EFI_CONSOLE_SERIAL_DEVICE) && ! EFI_SIMULATOR)
|
||||
/*
|
||||
* Activates the serial
|
||||
* it is important to set 'NONE' as flow control! in terminal application on the PC
|
||||
|
|
|
@ -169,9 +169,13 @@ void print(const char *format, ...) {
|
|||
if (!isCommandLineConsoleReady()) {
|
||||
return;
|
||||
}
|
||||
BaseSequentialStream * channel = (BaseSequentialStream*) getConsoleChannel();
|
||||
if (channel == nullptr) {
|
||||
return;
|
||||
}
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
chvprintf((BaseSequentialStream*) getConsoleChannel(), format, ap);
|
||||
chvprintf(channel, format, ap);
|
||||
va_end(ap);
|
||||
#else
|
||||
UNUSED(format);
|
||||
|
|
Loading…
Reference in New Issue