Skip to content

Commit

Permalink
Fix statusbar corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
henrygab committed Dec 24, 2024
1 parent e50764b commit c5aba87
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/commands/global/cls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/pirate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/ui/ui_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/ui/ui_statusbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions src/ui/ui_statusbar.h
Original file line number Diff line number Diff line change
@@ -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);
void ui_statusbar_deinit(void);
25 changes: 1 addition & 24 deletions src/usb_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c5aba87

Please sign in to comment.