From b371169dc96da74912a4b63d9a498ba5b5a72c80 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 20 Mar 2025 15:01:48 +0100 Subject: [PATCH] fixup! refactor(core/prodtest): make cli non-blocking, event-loop compatible --- core/embed/rtl/cli.c | 11 +++++++++-- core/embed/rtl/inc/rtl/cli.h | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/embed/rtl/cli.c b/core/embed/rtl/cli.c index 079b0b0a48..7a0348c0d1 100644 --- a/core/embed/rtl/cli.c +++ b/core/embed/rtl/cli.c @@ -541,6 +541,11 @@ bool cli_get_event(cli_t* cli, cli_event_t* event) { return false; } + if (cli->cmd_active) { + // Some command is already active or waiting for processing + return false; + } + // Read the next line int res = cli_process_char(cli); @@ -599,8 +604,7 @@ bool cli_get_event(cli_t* cli, cli_event_t* event) { event->type = CLI_EVENT_COMMAND_RECEIVED; event->data.command_received.command = cmd; - - cli_clear_line(cli); + cli->cmd_active = true; return true; cleanup: @@ -632,6 +636,9 @@ void cli_process_command(cli_t* cli, const cli_command_t* cmd) { // Print the prompt cli_printf(cli, "> "); } + + cli->cmd_active = false; + cli_clear_line(cli); } // Return position of the argument with the given name in diff --git a/core/embed/rtl/inc/rtl/cli.h b/core/embed/rtl/inc/rtl/cli.h index 0af359a733..1796c01318 100644 --- a/core/embed/rtl/inc/rtl/cli.h +++ b/core/embed/rtl/inc/rtl/cli.h @@ -98,6 +98,9 @@ struct cli { int hist_idx; int hist_prefix; + // Command active flag + bool cmd_active; // true if the command is pending or being processed + // Command name (pointer to the line buffer) const char* cmd_name; // Number of parsed arguments