Fixed serial passthrough exit when pulling USB cable

This commit is contained in:
Raphael Coeffic
2021-11-21 11:18:35 +01:00
committed by Raphael Coeffic
parent aa7b0143bd
commit 01059da849
2 changed files with 23 additions and 28 deletions
+21 -27
View File
@@ -46,18 +46,8 @@ static StaticStreamBuffer_t cliRxBufferStatic;
// CLI receive stream buffer // CLI receive stream buffer
static StreamBufferHandle_t cliRxBuffer; static StreamBufferHandle_t cliRxBuffer;
static void cliDefaultRx(uint8_t* buf, uint32_t len) // CLI receive call back
{ void (*cliReceiveCallBack)(uint8_t* buf, uint32_t len) = nullptr;
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;
uint8_t cliTracesEnabled = true; uint8_t cliTracesEnabled = true;
char cliLastLine[CLI_COMMAND_MAX_LEN+1]; char cliLastLine[CLI_COMMAND_MAX_LEN+1];
@@ -921,13 +911,7 @@ int cliSerialPassthrough(const char **argv)
// stop pulses // stop pulses
watchdogSuspend(200/*2s*/); watchdogSuspend(200/*2s*/);
pausePulses(); stopPulses();
#if defined(HARDWARE_INTERNAL_MODULE)
stopPulsesInternalModule();
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
stopPulsesExternalModule();
#endif
// suspend RTOS scheduler // suspend RTOS scheduler
vTaskSuspendAll(); vTaskSuspendAll();
@@ -936,13 +920,15 @@ int cliSerialPassthrough(const char **argv)
if (port_n == INTERNAL_MODULE) { if (port_n == INTERNAL_MODULE) {
// setup serial com // setup serial com
// TODO:
// - '8n1' param // TODO: '8n1' param
etx_serial_init params; etx_serial_init params;
params.baudrate = baudrate; params.baudrate = baudrate;
params.rx_enable = true; params.rx_enable = true;
intmoduleSerialStart(&params); intmoduleSerialStart(&params);
// backup and swap CLI input
auto backupCB = cliReceiveCallBack;
cliReceiveCallBack = spInternalModuleTx; cliReceiveCallBack = spInternalModuleTx;
// loop until cable disconnected // loop until cable disconnected
@@ -959,23 +945,21 @@ int cliSerialPassthrough(const char **argv)
usbSerialPutc(data); usbSerialPutc(data);
} }
// RTOS_WAIT_MS(200);
// keep us up & running // keep us up & running
WDG_RESET(); WDG_RESET();
} }
// restore CLI input
cliReceiveCallBack = backupCB;
intmoduleStop(); intmoduleStop();
// TODO: reset cli rx callback
} }
#endif #endif
// TODO: // TODO:
// - external module (S.PORT?) // - external module (S.PORT?)
// - how to exit this mode ??? USB exit ?
watchdogSuspend(200/*2s*/); watchdogSuspend(200/*2s*/);
resumePulses(); startPulses();
// suspend RTOS scheduler // suspend RTOS scheduler
xTaskResumeAll(); xTaskResumeAll();
@@ -1584,6 +1568,13 @@ void cliReceiveData(uint8_t* buf, uint32_t len)
cliReceiveCallBack(buf, 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() void cliStart()
{ {
// Init stream buffer // Init stream buffer
@@ -1592,6 +1583,9 @@ void cliStart()
xStreamBufferCreateStatic(sizeof(cliRxBufferStorage), xTriggerLevel, xStreamBufferCreateStatic(sizeof(cliRxBufferStorage), xTriggerLevel,
cliRxBufferStorage, &cliRxBufferStatic); cliRxBufferStorage, &cliRxBufferStatic);
// Setup consumer callback
cliReceiveCallBack = cliDefaultRx;
RTOS_CREATE_TASK(cliTaskId, cliTask, "CLI", cliStack, CLI_STACK_SIZE, RTOS_CREATE_TASK(cliTaskId, cliTask, "CLI", cliStack, CLI_STACK_SIZE,
CLI_TASK_PRIO); CLI_TASK_PRIO);
} }
+2 -1
View File
@@ -317,7 +317,8 @@ enum ChannelsProtocols {
inline void stopPulses() inline void stopPulses()
{ {
s_pulses_paused = true; 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() inline bool pulsesStarted()