Stabilize USB control firmware
This commit is contained in:
@ -97,6 +97,14 @@ typedef struct app_context_t {
|
||||
/* Written by app_uart_protocol_feed_byte() and reset helpers. Read by UART IRQ path and timeout logic. Purpose: incremental UART parser state. */
|
||||
app_uart_protocol_parser_t parser;
|
||||
|
||||
/*
|
||||
* Written by USART IRQ after a complete packet is parsed.
|
||||
* Consumed by app_run_once() so device, SPI, delay, and SD-card work
|
||||
* stays out of interrupt context.
|
||||
*/
|
||||
volatile uint8_t pending_uart_packet_ready;
|
||||
app_packet_t pending_uart_packet;
|
||||
|
||||
/* Written by app_capture_live_frame() and telemetry helpers. Read by telemetry finalisation/serialisation. Purpose: canonical structured telemetry snapshot. */
|
||||
telemetry_frame_t telemetry;
|
||||
|
||||
@ -157,6 +165,7 @@ static void app_handle_ad9102_wave_control_packet(const app_packet_t *packet);
|
||||
static void app_handle_ad9102_wave_data_packet(const app_packet_t *packet);
|
||||
static void app_handle_profile_save_data_packet(const app_packet_t *packet);
|
||||
static void app_process_work_mode(void);
|
||||
static void app_handle_pending_uart_packet(void);
|
||||
static void app_flush_tx_request(void);
|
||||
static void app_check_uart_timeout(void);
|
||||
static void app_handle_pending_event(void);
|
||||
@ -197,6 +206,7 @@ static void app_reset_runtime_state(bool reset_ticks)
|
||||
|
||||
telemetry_reset(&g_app.telemetry);
|
||||
app_uart_protocol_reset(&g_app.parser);
|
||||
g_app.pending_uart_packet_ready = 0u;
|
||||
uart_transport_reset();
|
||||
|
||||
if (reset_ticks)
|
||||
@ -633,6 +643,12 @@ static bool app_handle_profile_boot(void)
|
||||
FILINFO profile_index_info;
|
||||
FRESULT profile_index_result;
|
||||
|
||||
/* Legacy behaviour: saved SD startup data is used only without USB. */
|
||||
if (board_io_is_usb_connected())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
app_set_boot_diag(APP_BOOT_DIAG_STARTED);
|
||||
|
||||
if (!storage_sd_is_available())
|
||||
@ -1224,6 +1240,31 @@ static void app_process_work_mode(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void app_handle_pending_uart_packet(void)
|
||||
{
|
||||
app_packet_t packet;
|
||||
uint8_t packet_ready = 0u;
|
||||
|
||||
if (g_app.pending_uart_packet_ready == 0u)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
__disable_irq();
|
||||
if (g_app.pending_uart_packet_ready != 0u)
|
||||
{
|
||||
packet = g_app.pending_uart_packet;
|
||||
g_app.pending_uart_packet_ready = 0u;
|
||||
packet_ready = 1u;
|
||||
}
|
||||
__enable_irq();
|
||||
|
||||
if (packet_ready != 0u)
|
||||
{
|
||||
app_handle_packet(&packet);
|
||||
}
|
||||
}
|
||||
|
||||
static void app_flush_tx_request(void)
|
||||
{
|
||||
switch (g_app.tx_request)
|
||||
@ -1304,7 +1345,10 @@ void app_init(void)
|
||||
|
||||
app_initialise_default_configuration();
|
||||
app_reset_runtime_state(true);
|
||||
ui_status_init();
|
||||
if (!board_io_is_usb_connected())
|
||||
{
|
||||
ui_status_init();
|
||||
}
|
||||
app_set_mode(APP_MODE_IDLE);
|
||||
g_app.resume_mode = APP_MODE_IDLE;
|
||||
app_set_boot_diag(APP_BOOT_DIAG_NONE);
|
||||
@ -1330,9 +1374,16 @@ void app_run_once(void)
|
||||
app_event_t ui_event;
|
||||
|
||||
app_ensure_uart_rx_enabled();
|
||||
|
||||
if (g_app.mode == APP_MODE_WORK)
|
||||
{
|
||||
app_process_work_mode();
|
||||
}
|
||||
|
||||
ui_event = ui_status_poll_event(g_app.tick_10ms);
|
||||
app_post_event(ui_event);
|
||||
|
||||
app_handle_pending_uart_packet();
|
||||
app_handle_pending_event();
|
||||
|
||||
switch (g_app.mode)
|
||||
@ -1389,7 +1440,15 @@ void app_on_uart_byte(uint8_t byte)
|
||||
}
|
||||
else if (result == APP_PROTOCOL_FEED_PACKET_READY)
|
||||
{
|
||||
app_handle_packet(&packet);
|
||||
if (g_app.pending_uart_packet_ready == 0u)
|
||||
{
|
||||
g_app.pending_uart_packet = packet;
|
||||
g_app.pending_uart_packet_ready = 1u;
|
||||
}
|
||||
else
|
||||
{
|
||||
app_set_error(APP_STATUS_FLAG_UART_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user