From 01059da8494a372f094c3b718c4114549810b6a3 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 17 Nov 2021 13:00:14 +0100 Subject: [PATCH] Fixed serial passthrough exit when pulling USB cable --- radio/src/cli.cpp | 48 +++++++++++++++++---------------------- radio/src/pulses/pulses.h | 3 ++- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index bfafee823..8c1b13865 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -46,18 +46,8 @@ static StaticStreamBuffer_t cliRxBufferStatic; // CLI receive stream buffer static StreamBufferHandle_t cliRxBuffer; -static void cliDefaultRx(uint8_t* buf, uint32_t len) -{ - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - - xStreamBufferSendFromISR(cliRxBuffer, buf, len, &xHigherPriorityTaskWoken); - xTaskNotifyFromISR(cliTaskId.rtos_handle, 0, eNoAction, - &xHigherPriorityTaskWoken); - - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); -} - -void (*cliReceiveCallBack)(uint8_t* buf, uint32_t len) = cliDefaultRx; +// CLI receive call back +void (*cliReceiveCallBack)(uint8_t* buf, uint32_t len) = nullptr; uint8_t cliTracesEnabled = true; char cliLastLine[CLI_COMMAND_MAX_LEN+1]; @@ -921,13 +911,7 @@ int cliSerialPassthrough(const char **argv) // stop pulses watchdogSuspend(200/*2s*/); - pausePulses(); -#if defined(HARDWARE_INTERNAL_MODULE) - stopPulsesInternalModule(); -#endif -#if defined(HARDWARE_EXTERNAL_MODULE) - stopPulsesExternalModule(); -#endif + stopPulses(); // suspend RTOS scheduler vTaskSuspendAll(); @@ -936,13 +920,15 @@ int cliSerialPassthrough(const char **argv) if (port_n == INTERNAL_MODULE) { // setup serial com - // TODO: - // - '8n1' param + + // TODO: '8n1' param etx_serial_init params; params.baudrate = baudrate; params.rx_enable = true; - intmoduleSerialStart(¶ms); + + // backup and swap CLI input + auto backupCB = cliReceiveCallBack; cliReceiveCallBack = spInternalModuleTx; // loop until cable disconnected @@ -959,23 +945,21 @@ int cliSerialPassthrough(const char **argv) usbSerialPutc(data); } - // RTOS_WAIT_MS(200); - // keep us up & running WDG_RESET(); } + // restore CLI input + cliReceiveCallBack = backupCB; intmoduleStop(); - // TODO: reset cli rx callback } #endif // TODO: // - external module (S.PORT?) - // - how to exit this mode ??? USB exit ? watchdogSuspend(200/*2s*/); - resumePulses(); + startPulses(); // suspend RTOS scheduler xTaskResumeAll(); @@ -1584,6 +1568,13 @@ void cliReceiveData(uint8_t* buf, uint32_t len) cliReceiveCallBack(buf, len); } +static void cliDefaultRx(uint8_t *buf, uint32_t len) +{ + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + xStreamBufferSendFromISR(cliRxBuffer, buf, len, &xHigherPriorityTaskWoken); + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); +} + void cliStart() { // Init stream buffer @@ -1592,6 +1583,9 @@ void cliStart() xStreamBufferCreateStatic(sizeof(cliRxBufferStorage), xTriggerLevel, cliRxBufferStorage, &cliRxBufferStatic); + // Setup consumer callback + cliReceiveCallBack = cliDefaultRx; + RTOS_CREATE_TASK(cliTaskId, cliTask, "CLI", cliStack, CLI_STACK_SIZE, CLI_TASK_PRIO); } diff --git a/radio/src/pulses/pulses.h b/radio/src/pulses/pulses.h index 1b25c353c..c4a8a053f 100644 --- a/radio/src/pulses/pulses.h +++ b/radio/src/pulses/pulses.h @@ -317,7 +317,8 @@ enum ChannelsProtocols { inline void stopPulses() { s_pulses_paused = true; - moduleState[0].protocol = PROTOCOL_CHANNELS_UNINITIALIZED; + for (uint8_t i = 0; i < NUM_MODULES; i++) + moduleState[i].protocol = PROTOCOL_CHANNELS_UNINITIALIZED; } inline bool pulsesStarted()