From c5aba879c18ea838176578a0d9b2fb086ed92f03 Mon Sep 17 00:00:00 2001 From: Henry Gabryjelski Date: Mon, 23 Dec 2024 16:59:11 -0800 Subject: [PATCH] Fix statusbar corruption --- src/commands/global/cls.c | 3 ++- src/pirate.c | 4 ++-- src/ui/ui_config.c | 4 +++- src/ui/ui_statusbar.c | 8 +++++++- src/ui/ui_statusbar.h | 6 ++++-- src/usb_tx.c | 25 +------------------------ 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/commands/global/cls.c b/src/commands/global/cls.c index b1f7b112..82a094cd 100644 --- a/src/commands/global/cls.c +++ b/src/commands/global/cls.c @@ -17,6 +17,7 @@ static const char* const usage[] = { static const struct ui_help_options options[] = {}; void ui_display_clear(struct command_result* res) { + BP_ASSERT_CORE0(); if (ui_help_show(res->help_flag, usage, count_of(usage), &options[0], count_of(options))) { return; } @@ -30,6 +31,6 @@ void ui_display_clear(struct command_result* res) { ui_term_init(); // Initialize VT100 if ANSI terminal if (system_config.terminal_ansi_color && system_config.terminal_ansi_statusbar) { ui_statusbar_init(); - ui_statusbar_update(UI_UPDATE_ALL); + ui_statusbar_update_blocking(); } } diff --git a/src/pirate.c b/src/pirate.c index 9208f956..14659276 100644 --- a/src/pirate.c +++ b/src/pirate.c @@ -522,7 +522,7 @@ static void core0_infinite_loop(void) { // and does the initial painting of the full statusbar if (system_config.terminal_ansi_statusbar) { ui_statusbar_init(); - ui_statusbar_update(UI_UPDATE_ALL); + ui_statusbar_update_blocking(); } break; default: @@ -768,7 +768,7 @@ static void core1_infinite_loop(void) { system_config.terminal_ansi_statusbar && system_config.terminal_ansi_statusbar_update && !system_config.terminal_ansi_statusbar_pause) { - ui_statusbar_update(update_flags); + ui_statusbar_update_from_core1(update_flags); } #if (BP_VER == 5 && BP_REV <= 9) diff --git a/src/ui/ui_config.c b/src/ui/ui_config.c index 05600412..c37eb913 100644 --- a/src/ui/ui_config.c +++ b/src/ui/ui_config.c @@ -153,6 +153,8 @@ uint32_t ui_config_action_ansi_color(uint32_t a, uint32_t b) { } uint32_t ui_config_action_ansi_toolbar(uint32_t a, uint32_t b) { + BP_ASSERT_CORE0(); + // NOTE: `b` is treated as a boolean value b = !!b; @@ -164,7 +166,7 @@ uint32_t ui_config_action_ansi_toolbar(uint32_t a, uint32_t b) { } ui_term_detect(); // Do we detect a VT100 ANSI terminal? what is the size? ui_term_init(); // Initialize VT100 if ANSI terminal - ui_statusbar_update(UI_UPDATE_ALL); + ui_statusbar_update_blocking(); } } diff --git a/src/ui/ui_statusbar.c b/src/ui/ui_statusbar.c index 8801447c..760750e4 100644 --- a/src/ui/ui_statusbar.c +++ b/src/ui/ui_statusbar.c @@ -11,6 +11,7 @@ #include "ui/ui_flags.h" #include "system_monitor.h" #include "display/scope.h" +#include "pirate/intercore_helpers.h" uint32_t ui_statusbar_info(char* buf, size_t buffLen) { uint32_t len = 0; @@ -209,8 +210,13 @@ uint32_t ui_statusbar_value(char* buf, size_t buffLen) { return (do_update ? len : 0); } +void ui_statusbar_update_blocking() { + BP_ASSERT_CORE0(); // if called from core1, this will deadlock + icm_core0_send_message_synchronous(BP_ICM_FORCE_LCD_UPDATE); +} +void ui_statusbar_update_from_core1(uint32_t update_flags) { + BP_ASSERT_CORE1(); -void ui_statusbar_update(uint32_t update_flags) { uint32_t len = 0; size_t buffLen = sizeof(tx_sb_buf); diff --git a/src/ui/ui_statusbar.h b/src/ui/ui_statusbar.h index 4ab0f71f..5a6980f4 100644 --- a/src/ui/ui_statusbar.h +++ b/src/ui/ui_statusbar.h @@ -1,3 +1,5 @@ -void ui_statusbar_update(uint32_t update_flags); +#pragma once +void ui_statusbar_update_blocking(); +void ui_statusbar_update_from_core1(uint32_t update_flags); void ui_statusbar_init(void); -void ui_statusbar_deinit(void); \ No newline at end of file +void ui_statusbar_deinit(void); diff --git a/src/usb_tx.c b/src/usb_tx.c index 216ac5a7..a628fd6a 100644 --- a/src/usb_tx.c +++ b/src/usb_tx.c @@ -45,30 +45,7 @@ void tx_fifo_init(void) { void tx_sb_start(uint32_t valid_characters_in_status_bar) { - // BUGBUG -- This is currently called from both cores. - // This means the buffer is being updated from both cores ... - // and there is no lock / protection on the buffer. - - // // Something updated the status bar buffer. - // // Which core is this on? - // static uint prior_core = 0xFFFFu; - // uint core = get_core_num(); - // if (prior_core == 0xFFFFu) { - // prior_core = core; - // } else if (prior_core > 2) { - // --prior_core; - // } else if (prior_core == 2) { - // prior_core = core; - // } - - // if ((prior_core < 2) && (prior_core != core)) { - // BP_DEBUG_PRINT(BP_DEBUG_LEVEL_FATAL, BP_DEBUG_CAT_CATCHALL, - // "tx_sb_start() is called from multiple cores\n" - // ); - // // prior_core = 10; // limit how often we see this message - // prior_core = core; // show this every time it changes - // } - + BP_ASSERT_CORE1(); BP_ASSERT(valid_characters_in_status_bar <= MAXIMUM_STATUS_BAR_BUFFER_BYTES); tx_sb_buf_cnt = valid_characters_in_status_bar; tx_sb_buf_ready = true;