Skip to content

Commit

Permalink
serial: improve robustness when trying to stop or restart serial
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JamieDriver committed Nov 12, 2024
1 parent d493c9b commit 8c7f550
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions main/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ static bool serial_init_internal(void)
}
#endif // IDF_TARGET_ESP32

// The tasks run while this flag is set
serial_is_enabled = true;

BaseType_t retval = xTaskCreatePinnedToCore(&serial_reader, "serial_reader", reader_stack_size, NULL,
JADE_TASK_PRIO_READER, &serial_reader_handle, JADE_CORE_SECONDARY);

Expand All @@ -294,6 +297,7 @@ static bool serial_init_internal(void)
p_serial_writer_handle, JADE_CORE_SECONDARY);
JADE_ASSERT_MSG(
retval == pdPASS, "Failed to create serial_writer task, xTaskCreatePinnedToCore() returned %d", retval);

return true;
}

Expand All @@ -315,29 +319,25 @@ bool serial_init(TaskHandle_t* serial_handle)
full_serial_data_in[0] = SOURCE_SERIAL;
serial_data_out = JADE_MALLOC_PREFER_SPIRAM(MAX_OUTPUT_MSG_SIZE);
p_serial_writer_handle = serial_handle;
serial_is_enabled = true;
return serial_init_internal();
}

bool serial_enabled(void) { return serial_is_enabled; }

void serial_start(void)
{
// JADE_ASSERT(!serial_is_enabled);
if (serial_is_enabled) {
return;
}
serial_is_enabled = true;
const bool res = serial_init_internal();
JADE_ASSERT(res);
serial_init_internal();
}

void serial_stop(void)
{
// JADE_ASSERT(serial_is_enabled);
if (!serial_is_enabled) {
return;
}

// flag tasks to die
serial_is_enabled = false;

Expand Down

0 comments on commit 8c7f550

Please sign in to comment.