Skip to content

Commit 8c7f550

Browse files
author
Jamie C. Driver
committed
serial: improve robustness when trying to stop or restart serial
Do not abort if serial cannot be restarted, and improve when the serial-enabled flag is set so that it indicates the tasks are running so that trying to stop serial does not wait for tasks to exit that have not been started and are not actually running.
1 parent d493c9b commit 8c7f550

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

main/serial.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ static bool serial_init_internal(void)
284284
}
285285
#endif // IDF_TARGET_ESP32
286286

287+
// The tasks run while this flag is set
288+
serial_is_enabled = true;
289+
287290
BaseType_t retval = xTaskCreatePinnedToCore(&serial_reader, "serial_reader", reader_stack_size, NULL,
288291
JADE_TASK_PRIO_READER, &serial_reader_handle, JADE_CORE_SECONDARY);
289292

@@ -294,6 +297,7 @@ static bool serial_init_internal(void)
294297
p_serial_writer_handle, JADE_CORE_SECONDARY);
295298
JADE_ASSERT_MSG(
296299
retval == pdPASS, "Failed to create serial_writer task, xTaskCreatePinnedToCore() returned %d", retval);
300+
297301
return true;
298302
}
299303

@@ -315,29 +319,25 @@ bool serial_init(TaskHandle_t* serial_handle)
315319
full_serial_data_in[0] = SOURCE_SERIAL;
316320
serial_data_out = JADE_MALLOC_PREFER_SPIRAM(MAX_OUTPUT_MSG_SIZE);
317321
p_serial_writer_handle = serial_handle;
318-
serial_is_enabled = true;
319322
return serial_init_internal();
320323
}
321324

322325
bool serial_enabled(void) { return serial_is_enabled; }
323326

324327
void serial_start(void)
325328
{
326-
// JADE_ASSERT(!serial_is_enabled);
327329
if (serial_is_enabled) {
328330
return;
329331
}
330-
serial_is_enabled = true;
331-
const bool res = serial_init_internal();
332-
JADE_ASSERT(res);
332+
serial_init_internal();
333333
}
334334

335335
void serial_stop(void)
336336
{
337-
// JADE_ASSERT(serial_is_enabled);
338337
if (!serial_is_enabled) {
339338
return;
340339
}
340+
341341
// flag tasks to die
342342
serial_is_enabled = false;
343343

0 commit comments

Comments
 (0)