Skip to content

Commit

Permalink
cli: Remove dependencies on UART implementation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
CJKay authored and jimqui01 committed Sep 8, 2020
1 parent 4a1283d commit abfa166
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 196 deletions.
46 changes: 0 additions & 46 deletions debugger/include/cli_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ void cli_platform_delay_ms(uint32_t ms);
/* CLI Platform-Specific UART Functions */
/*****************************************************************************/

/*
* 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
Expand All @@ -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_ */
60 changes: 23 additions & 37 deletions debugger/src/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cli_fifo.h>
#include <cli_platform.h>

#include <fwk_io.h>
#include <fwk_list.h>
#include <fwk_mm.h>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions debugger/src/cli/cli_commands_checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cli.h>
#include <cli_platform.h>

#include <fwk_io.h>
#include <fwk_status.h>

#include <stdint.h>
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions debugger/src/cli/cli_commands_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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>
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion module/debugger_cli/src/mod_debugger_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void alarm_callback(uintptr_t module_idx)
struct fwk_event *event;

/* Get the pending character (if any) from the UART without blocking */
status = cli_platform_uart_get(&ch, false);
status = fwk_io_getch(fwk_io_stdin, &ch);

if (status == FWK_SUCCESS) {
/* Ctrl-E has been pressed */
Expand Down
7 changes: 0 additions & 7 deletions module/pl011/include/mod_pl011.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ struct mod_pl011_element_cfg {
#endif
};

/*!
* \brief Set the baud rate of the PL011 device
*
* \param[in] cfg The desired device configuration.
*/
void mod_pl011_set_baud_rate(const struct mod_pl011_element_cfg *cfg);

/*!
* \}
*/
Expand Down
4 changes: 0 additions & 4 deletions module/pl011/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@
BS_LIB_NAME := "PL011"
BS_LIB_SOURCES = mod_pl011.c

ifeq ($(BUILD_HAS_DEBUGGER),yes)
BS_LIB_SOURCES += debug_uart.c
endif

include $(BS_DIR)/lib.mk
93 changes: 0 additions & 93 deletions module/pl011/src/debug_uart.c

This file was deleted.

2 changes: 1 addition & 1 deletion module/pl011/src/mod_pl011.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static int mod_pl011_init_ctx(struct mod_pl011_ctx *ctx)
return FWK_SUCCESS;
}

void mod_pl011_set_baud_rate(const struct mod_pl011_element_cfg *cfg)
static void mod_pl011_set_baud_rate(const struct mod_pl011_element_cfg *cfg)
{
struct pl011_reg *reg = (void *)cfg->reg_base;

Expand Down

0 comments on commit abfa166

Please sign in to comment.