Serial pass-through

This commit is contained in:
Raphael Coeffic
2021-11-21 11:18:35 +01:00
committed by Raphael Coeffic
parent 1f0480532d
commit c8a4a80ffd
6 changed files with 138 additions and 4 deletions
+118 -3
View File
@@ -808,12 +808,13 @@ int cliSet(const char **argv)
t.tm_hour = hour; t.tm_hour = hour;
t.tm_min = minute; t.tm_min = minute;
t.tm_sec = second; t.tm_sec = second;
g_rtcTime = // update local timestamp and get wday calculated
gmktime(&t); // update local timestamp and get wday calculated g_rtcTime = gmktime(&t);
rtcSetTime(&t); rtcSetTime(&t);
} else { } else {
serialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1], serialPrint("%s: Invalid arguments \"%s\" \"%s\"", argv[0], argv[1],
argv[2]); argv[2]);
return -1;
} }
} }
#if !defined(SOFTWARE_VOLUME) #if !defined(SOFTWARE_VOLUME)
@@ -824,13 +825,123 @@ int cliSet(const char **argv)
} else { } else {
serialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1], serialPrint("%s: Invalid argument \"%s\" \"%s\"", argv[0], argv[1],
argv[2]); argv[2]);
return -1;
} }
return 0;
} }
#endif #endif
#if defined(INTMODULE_BOOTCMD_GPIO)
else if (!strcmp(argv[1], "bootpin")) {
int level = 0;
if (toInt(argv, 2, &level) < 0) {
serialPrint("%s: invalid level argument '%s'", argv[0], argv[2]);
return -1;
}
if (level)
GPIO_SetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
else
GPIO_ResetBits(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_GPIO_PIN);
}
#endif
return 0; return 0;
} }
#if defined(ENABLE_SERIAL_PASSTHROUGH)
int cliSerialPassthrough(const char **argv)
{
const char* port_type = argv[1];
const char* port_num = argv[2];
const char* rate_str = argv[3];
if (!port_type || !port_num || !rate_str) {
serialPrint("%s: missing argument", argv[0]);
return -1;
}
int port_n = 0;
int err = toInt(argv, 2, &port_n);
if (err == -1) return err;
if (err == 0) {
serialPrint("%s: missing port #", argv[0]);
return -1;
}
int baudrate = 0;
err = toInt(argv, 2, &baudrate);
if (err == -1) return err;
if (err == 0) {
serialPrint("%s: missing baudrate", argv[0]);
return -1;
}
if (!strcmp("rfmod", port_type)) {
if (port_n >= NUM_MODULES
// only internal module supported for now
&& port_n != INTERNAL_MODULE) {
serialPrint("%s: invalid port # '%s'", port_num);
return -1;
}
// stop pulses
watchdogSuspend(200/*2s*/);
pausePulses();
#if defined(HARDWARE_INTERNAL_MODULE)
stopPulsesInternalModule();
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
stopPulsesExternalModule();
#endif
#if defined(HARDWARE_INTERNAL_MODULE)
if (port_n == INTERNAL_MODULE) {
// TODO: check the stack level so we don't crash it
uint8_t tmpBuf[256];
// setup serial com
// TODO:
// - '8n1' param
intmoduleSerialStart(baudrate, true, USART_Parity_No, USART_StopBits_1,
USART_WordLength_8b);
for (;;) {
/* Block for max 10ms. */
const TickType_t xTimeout = 10 / RTOS_MS_PER_TICK;
size_t xReceivedBytes =
xStreamBufferReceive(cliRxBuffer, tmpBuf, sizeof(tmpBuf), xTimeout);
// keep us up & running
WDG_RESET();
if (xReceivedBytes) {
// TODO: wait for previous buffer flushed
intmoduleWaitForTxCompleted();
intmoduleSendBuffer(tmpBuf, xReceivedBytes);
}
// Let's hope this does not starve the other side
uint8_t inData;
while(intmoduleFifo.pop(inData)) {
serialPutc(inData);
}
}
}
#endif
// TODO:
// - external module (S.PORT?)
// - how to exit this mode ??? USB exit ?
} else {
serialPrint("%s: invalid port type '%s'", port_type);
return -1;
}
return 0;
}
#endif
#if defined(DEBUG_INTERRUPTS) #if defined(DEBUG_INTERRUPTS)
void printInterrupts() void printInterrupts()
{ {
@@ -1268,6 +1379,9 @@ const CliCommand cliCommands[] = {
{ "play", cliPlay, "<filename>" }, { "play", cliPlay, "<filename>" },
{ "reboot", cliReboot, "[wdt]" }, { "reboot", cliReboot, "[wdt]" },
{ "set", cliSet, "<what> <value>" }, { "set", cliSet, "<what> <value>" },
#if defined(ENABLE_SERIAL_PASSTHROUGH)
{ "serialpassthrough", cliSerialPassthrough, "<port type> <port number>"},
#endif
#if defined(DEBUG) #if defined(DEBUG)
{ "print", cliDisplay, "<address> [<size>] | <what>" }, { "print", cliDisplay, "<address> [<size>] | <what>" },
{ "p", cliDisplay, "<address> [<size>] | <what>" }, { "p", cliDisplay, "<address> [<size>] | <what>" },
@@ -1395,6 +1509,7 @@ void cliTask(void * pdata)
// save new command // save new command
strcpy(cliLastLine, line); strcpy(cliLastLine, line);
} }
// TODO: check return value
cliExecLine(line); cliExecLine(line);
pos = 0; pos = 0;
cliPrompt(); cliPrompt();
@@ -1,6 +1,7 @@
set(TIMERS 3 CACHE STRING "Timers count (2 or 3)") set(TIMERS 3 CACHE STRING "Timers count (2 or 3)")
set_property(CACHE TIMERS PROPERTY STRINGS 2 3) set_property(CACHE TIMERS PROPERTY STRINGS 2 3)
option(CLI "Command Line Interface" OFF) option(CLI "Command Line Interface" OFF)
option(ENABLE_SERIAL_PASSTHROUGH "Enable serial passthrough" OFF)
option(DEBUG "Debug mode" OFF) option(DEBUG "Debug mode" OFF)
option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF) option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF)
option(LOG_BLUETOOTH "Bluetooth Logs on SD card" OFF) option(LOG_BLUETOOTH "Bluetooth Logs on SD card" OFF)
@@ -101,6 +102,10 @@ if(CLI OR DEBUG)
set(SRC ${SRC} dump.cpp) set(SRC ${SRC} dump.cpp)
endif() endif()
if(ENABLE_SERIAL_PASSTHROUGH)
add_definitions(-DENABLE_SERIAL_PASSTHROUGH)
endif()
if(DEBUG) if(DEBUG)
add_definitions(-DDEBUG) add_definitions(-DDEBUG)
endif() endif()
@@ -205,3 +205,15 @@ void intmoduleSendNextFrame()
#endif #endif
} }
} }
void intmoduleWaitForTxCompleted()
{
#if defined(INTMODULE_DMA_STREAM)
if (DMA_GetCmdStatus(INTMODULE_DMA_STREAM) == ENABLE) {
while(DMA_GetFlagStatus(INTMODULE_DMA_STREAM, INTMODULE_DMA_FLAG_TC) == RESET);
DMA_ClearFlag(INTMODULE_DMA_STREAM, INTMODULE_DMA_FLAG_TC);
}
#else
#error "intmoduleWaitForTC() not implemented for IRQ based transfer"
#endif
}
+1
View File
@@ -106,6 +106,7 @@ if (PCB STREQUAL X10)
set(AUX2_SERIAL ON) set(AUX2_SERIAL ON)
endif() endif()
set(INTERNAL_GPS_BAUDRATE "9600" CACHE STRING "Baud rate for internal GPS") set(INTERNAL_GPS_BAUDRATE "9600" CACHE STRING "Baud rate for internal GPS")
set(ENABLE_SERIAL_PASSTHROUGH ON CACHE BOOL "Enable serial passthrough")
set(CLI ON CACHE BOOL "Enable CLI") set(CLI ON CACHE BOOL "Enable CLI")
elseif (PCBREV STREQUAL T18) elseif (PCBREV STREQUAL T18)
set(FLAVOUR t18) set(FLAVOUR t18)
+1
View File
@@ -202,6 +202,7 @@ void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable, uint16_t parity,
void intmoduleSendByte(uint8_t byte); void intmoduleSendByte(uint8_t byte);
void intmoduleSendBuffer(const uint8_t * data, uint8_t size); void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
void intmoduleSendNextFrame(); void intmoduleSendNextFrame();
void intmoduleWaitForTxCompleted();
void extmoduleSerialStart(); void extmoduleSerialStart();
void extmoduleInvertedSerialStart(uint32_t baudrate); void extmoduleInvertedSerialStart(uint32_t baudrate);
+1 -1
View File
@@ -817,7 +817,7 @@
#define INTMODULE_DMA_STREAM DMA2_Stream7 #define INTMODULE_DMA_STREAM DMA2_Stream7
#define INTMODULE_DMA_STREAM_IRQ DMA2_Stream7_IRQn #define INTMODULE_DMA_STREAM_IRQ DMA2_Stream7_IRQn
#define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler #define INTMODULE_DMA_STREAM_IRQHandler DMA2_Stream7_IRQHandler
#define INTMODULE_DMA_FLAG_TC DMA_IT_TCIF7 #define INTMODULE_DMA_FLAG_TC DMA_FLAG_TCIF7
#define INTMODULE_DMA_CHANNEL DMA_Channel_4 #define INTMODULE_DMA_CHANNEL DMA_Channel_4
#if defined(PCBX12S) #if defined(PCBX12S)
#define INTMODULE_BOOTCMD_GPIO GPIOC #define INTMODULE_BOOTCMD_GPIO GPIOC