diff options
author | Chris Kay <chris.kay@arm.com> | 2020-08-07 15:58:17 +0100 |
---|---|---|
committer | jimqui01 <54316584+jimqui01@users.noreply.github.com> | 2020-09-08 11:37:54 +0100 |
commit | abfa1661623d92fae4aa32e6b966d559c3d0e8be (patch) | |
tree | 19f399ea38e512798653959e73f90ef8478b35d7 /debugger | |
parent | 4a1283d07b8c1760a49ea8585b1c00ae776ae721 (diff) |
cli: Remove dependencies on UART implementation
With the introduction of the I/O framework component, the CLI can now
refer to a standard output configured by the firmware for sending and
receiving UART data. This patch therefore moves any CLI-specific UART
platform interfaces to the I/O component with the standard input and
output streams.
Change-Id: Iac55f592b438a603193da568e16eaf39fca115cf
Signed-off-by: Chris Kay <chris.kay@arm.com>
Diffstat (limited to 'debugger')
-rw-r--r-- | debugger/include/cli_platform.h | 46 | ||||
-rw-r--r-- | debugger/src/cli/cli.c | 60 | ||||
-rw-r--r-- | debugger/src/cli/cli_commands_checkpoint.c | 5 | ||||
-rw-r--r-- | debugger/src/cli/cli_commands_core.c | 9 |
4 files changed, 30 insertions, 90 deletions
diff --git a/debugger/include/cli_platform.h b/debugger/include/cli_platform.h index f9ae03f7..2b983eba 100644 --- a/debugger/include/cli_platform.h +++ b/debugger/include/cli_platform.h @@ -65,15 +65,6 @@ void cli_platform_delay_ms(uint32_t ms); /*****************************************************************************/ /* - * cli_platform_uart_init - * Description - * Initializes the necessary hardware to send and receive characters. - * Return - * cli_ret_et: success if it works, something else if it fails. - */ -uint32_t cli_platform_uart_init(void); - -/* * cli_platform_uid_notify * Description * If system has a UID light, this function notifies it of activity on @@ -83,41 +74,4 @@ uint32_t cli_platform_uart_init(void); */ uint32_t cli_platform_uid_notify(void); -/* - * cli_platform_uart_get - * Description - * Receives a single character from the UART. Must support blocking and - * non-blocking receive operations. - * Parameters - * char *c - * Pointer to a char in which to place the received character. - * bool block - * If true, this function must not return until a character is - * received or the UART generates an error. If false, this function - * returns immediately regardless of whether or not a character was - * received. - * Return - * cli_ret_et: success if a character is read with no errors, error_empty - * if block==true and no characters are available, or some other error - * from the UART. - */ -uint32_t cli_platform_uart_get(char *c, bool block); - -/* - * cli_platform_uart_put - * Description - * Sends a single character on the UART. This function is blocking. - * Parameters - * char *c - * Pointer to character to send. - * bool block - * If true, this function must not return until a character is - * output or the UART generates an error. If false, this function - * returns immediately regardless of whether or not a character was - * output. - * Return - * cli_ret_et: success if it works, some other error if it doesn't. - */ -uint32_t cli_platform_uart_put(const char *c, bool block); - #endif /* _CLI_PLATFORM_H_ */ diff --git a/debugger/src/cli/cli.c b/debugger/src/cli/cli.c index aab034c6..3e5235d0 100644 --- a/debugger/src/cli/cli.c +++ b/debugger/src/cli/cli.c @@ -10,6 +10,7 @@ #include <cli_fifo.h> #include <cli_platform.h> +#include <fwk_io.h> #include <fwk_list.h> #include <fwk_mm.h> @@ -354,11 +355,6 @@ uint32_t cli_init(void) strncpy(cli_prompt, prompt, CLI_CONFIG_PROMPT_BUF_SIZE); cli_prompt_size = strlen(prompt); - /* Initializing platform UART. */ - status = cli_platform_uart_init(); - if (status != FWK_SUCCESS) - return status; - /* Initialize print buffer FIFO. */ status = fifo_init( &cli_print_fifo, cli_print_fifo_buffer, CLI_CONFIG_PRINT_BUFFER_SIZE); @@ -528,7 +524,7 @@ uint32_t cli_print(const char *string) int32_t status = FWK_SUCCESS; for (index = 0; string[index] != 0; index++) { - status = cli_platform_uart_put(&string[index], true); + status = fwk_io_putch(fwk_io_stdout, string[index]); if (status != FWK_SUCCESS) return status; } @@ -579,13 +575,14 @@ uint32_t cli_getline( /* * Loop will terminate when the user presses enter or when an error is - * generated. If your cli_platform_uart_get is thread friendly (and it - * should be if implemented correctly), this loop will have negligible - * impact on system performance. + * generated. This loop will have negligible impact on system performance. */ while (1) { /* Grab a character from the UART. */ - status = cli_platform_uart_get(&c, true); + do { + status = fwk_io_getch(fwk_io_stdin, &c); + } while (status == FWK_PENDING); + if (status != FWK_SUCCESS) return status; @@ -630,7 +627,10 @@ uint32_t cli_getline( } /* Echo received character to console. */ - status = cli_platform_uart_put(&c, true); + do { + status = fwk_io_putch(fwk_io_stdout, c); + } while (status == FWK_PENDING); + if (status != FWK_SUCCESS) return status; @@ -943,7 +943,10 @@ static uint32_t cli_get_command( while (1) { /* Get character from UART. */ - status = cli_platform_uart_get(&c, true); + do { + status = fwk_io_getch(fwk_io_stdin, &c); + } while (status == FWK_PENDING); + if (status != FWK_SUCCESS) return status; @@ -1006,8 +1009,8 @@ static uint32_t cli_get_command( /* Printing history command to screen. */ while (buffer[index] != 0) { - status = cli_platform_uart_put(&buffer[index], - true); + status = + fwk_io_putch(fwk_io_stdout, buffer[index]); if (status != FWK_SUCCESS) return status; index = index + 1; @@ -1044,8 +1047,8 @@ static uint32_t cli_get_command( /* Printing history command to screen. */ while (buffer[index] != 0) { - status = cli_platform_uart_put(&buffer[index], - true); + status = + fwk_io_putch(fwk_io_stdout, buffer[index]); if (status != FWK_SUCCESS) return status; @@ -1096,7 +1099,7 @@ static uint32_t cli_get_command( } /* Printing received character to console. */ - status = cli_platform_uart_put(&c, true); + status = fwk_io_putch(fwk_io_stdout, c); if (status != FWK_SUCCESS) return status; @@ -1299,7 +1302,7 @@ static uint32_t cli_debug_output(void) "press Ctrl+C.\n"); while (1) { /* Looking for Ctrl+C press. */ - if (cli_platform_uart_get((char *)&c, false) == FWK_SUCCESS) { + if (fwk_io_getch(fwk_io_stdin, &c) == FWK_SUCCESS) { if (c == '\x03') { cli_printf( 0, @@ -1313,7 +1316,7 @@ static uint32_t cli_debug_output(void) fifo_status = fifo_get(&cli_print_fifo, &c); if (fifo_status == FWK_SUCCESS) { overflow = false; - cli_platform_uart_put((char *)&c, true); + fwk_io_putch(fwk_io_stdout, c); } else /* If no characters are available, let other stuff run. */ cli_platform_delay_ms(0); @@ -1325,24 +1328,7 @@ static void cli_error_handler(uint32_t status) if (status == FWK_SUCCESS) return; - cli_printf(NONE, "CONSOLE ERROR: "); - switch (status) { - case FWK_E_NOMEM: - cli_print("Buffer size.\n"); - break; - case FWK_E_PARAM: - cli_print("Bad argument.\n"); - break; - case FWK_E_SUPPORT: - cli_print("Not found.\n"); - break; - case FWK_E_DATA: - cli_print("No data available.\n"); - break; - default: - cli_print("Unknown error.\n"); - return; - } + cli_printf(NONE, "CONSOLE ERROR: %s\n", fwk_status_str(status)); } static void cli_val2str( diff --git a/debugger/src/cli/cli_commands_checkpoint.c b/debugger/src/cli/cli_commands_checkpoint.c index 12b7eb23..29620230 100644 --- a/debugger/src/cli/cli_commands_checkpoint.c +++ b/debugger/src/cli/cli_commands_checkpoint.c @@ -9,6 +9,7 @@ #include <cli.h> #include <cli_platform.h> +#include <fwk_io.h> #include <fwk_status.h> #include <stdint.h> @@ -109,12 +110,12 @@ void checkpoint_boot_state(uint32_t timeout_s) char c = 0; /* Make sure nothing is waiting in UART buffer. */ - while (cli_platform_uart_get(&c, false) == FWK_SUCCESS) + while (fwk_io_getch(fwk_io_stdin, &c) == FWK_SUCCESS) ; cli_print("Press any key to enable checkpoints before boot... "); while (timeout_s != 0) { - if (cli_platform_uart_get(&c, false) == FWK_SUCCESS) { + if (fwk_io_getch(fwk_io_stdin, &c) == FWK_SUCCESS) { cli_print("\nCheckpoints enabled.\n"); checkpoint_enable_all(); return; diff --git a/debugger/src/cli/cli_commands_core.c b/debugger/src/cli/cli_commands_core.c index 04d4f5ae..c7d6b088 100644 --- a/debugger/src/cli/cli_commands_core.c +++ b/debugger/src/cli/cli_commands_core.c @@ -41,9 +41,6 @@ /* cli_getline */ /* Retrieves a line of user input from the console, see cli_module.h for */ /* full description. */ -/* cli_platform_uart_get and cli_platform_uart_put */ -/* Direct access to the UART hardware, using these is not recommended */ -/* but shouldn't hurt anything. */ /* cli_snprintf */ /* Takes the place of snprintf and it's derivatives, a bit rudimentary */ /* but has no heap dependence, see cli_module.h for full descriptions. */ @@ -59,6 +56,8 @@ #include <cli_fifo.h> #include <cli_platform.h> +#include <fwk_io.h> + #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -109,10 +108,10 @@ static int32_t dump_memory_f(int32_t argc, char **argv) for (j = 0; j < NUM_BYTES_PER_LINE; j++) { if ((bytes[j] >= 0x20) && (bytes[j] <= 0x7E)) /* Character is printing. */ - cli_platform_uart_put((const char *)&bytes[j], true); + fwk_io_putch(fwk_io_stdout, bytes[j]); else /* Character is non-printing so put a period. */ - cli_platform_uart_put(".", true); + fwk_io_putch(fwk_io_stdout, '.'); } cli_print("\"\n"); } |