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