diff options
author | Atish Patra <atish.patra@wdc.com> | 2019-02-28 04:42:17 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2019-03-05 11:35:12 +0300 |
commit | 86cc9b8633bea3bc6fbda145424f871ea553af9e (patch) | |
tree | dd63e0eee35ed225059db03f36405842715792bb | |
parent | 05602e2bf4812533adcb7acb1a67e43726c0e7bb (diff) | |
download | opensbi-86cc9b8633bea3bc6fbda145424f871ea553af9e.tar.xz |
lib:platform: Fix sbi_getc return type.
As per the current SBI specification, sbi_getc should return
an int instead of char.
In case of FIFO is empty, return -1 as per the specification.
Reported-by: Sergi Granell <xerpi.g.12@gmail.com>
Suggested-by:Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
-rw-r--r-- | include/sbi/sbi_console.h | 2 | ||||
-rw-r--r-- | include/sbi/sbi_platform.h | 6 | ||||
-rw-r--r-- | lib/sbi_console.c | 9 | ||||
-rw-r--r-- | platform/common/include/plat/serial/sifive-uart.h | 2 | ||||
-rw-r--r-- | platform/common/include/plat/serial/uart8250.h | 2 | ||||
-rw-r--r-- | platform/common/serial/sifive-uart.c | 4 | ||||
-rw-r--r-- | platform/common/serial/uart8250.c | 4 | ||||
-rw-r--r-- | platform/kendryte/k210/platform.c | 2 | ||||
-rw-r--r-- | platform/kendryte/k210/uarths.c | 4 | ||||
-rw-r--r-- | platform/kendryte/k210/uarths.h | 2 | ||||
-rw-r--r-- | platform/template/platform.c | 2 |
11 files changed, 20 insertions, 19 deletions
diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index 8069669..0fd58e7 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -16,7 +16,7 @@ bool sbi_isprintable(char ch); -char sbi_getc(void); +int sbi_getc(void); void sbi_putc(char ch); diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 8f4f44b..fe04c2f 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -77,7 +77,7 @@ struct sbi_platform { /** Write a character to the platform console output */ void (*console_putc)(char ch); /** Read a character from the platform console input */ - char (*console_getc)(void); + int (*console_getc)(void); /** Initialize the platform console */ int (*console_init)(void); @@ -283,11 +283,11 @@ static inline void sbi_platform_console_putc(struct sbi_platform *plat, * * @return character read from console input */ -static inline char sbi_platform_console_getc(struct sbi_platform *plat) +static inline int sbi_platform_console_getc(struct sbi_platform *plat) { if (plat && plat->console_getc) return plat->console_getc(); - return 0; + return -1; } /** diff --git a/lib/sbi_console.c b/lib/sbi_console.c index bc8f952..527748f 100644 --- a/lib/sbi_console.c +++ b/lib/sbi_console.c @@ -26,7 +26,7 @@ bool sbi_isprintable(char c) return FALSE; } -char sbi_getc(void) +int sbi_getc(void) { return sbi_platform_console_getc(console_plat); } @@ -50,10 +50,11 @@ void sbi_puts(const char *str) void sbi_gets(char *s, int maxwidth, char endchar) { - char ch, *retval = s; + int ch; + char *retval = s; - while ((ch = sbi_getc()) != endchar && maxwidth > 1) { - *retval = ch; + while ((ch = sbi_getc()) != endchar && ch >= 0 && maxwidth > 1) { + *retval = (char) ch; retval++; maxwidth--; } diff --git a/platform/common/include/plat/serial/sifive-uart.h b/platform/common/include/plat/serial/sifive-uart.h index 2c4e7f3..6a64595 100644 --- a/platform/common/include/plat/serial/sifive-uart.h +++ b/platform/common/include/plat/serial/sifive-uart.h @@ -14,7 +14,7 @@ void sifive_uart_putc(char ch); -char sifive_uart_getc(void); +int sifive_uart_getc(void); int sifive_uart_init(unsigned long base, u32 in_freq, u32 baudrate); diff --git a/platform/common/include/plat/serial/uart8250.h b/platform/common/include/plat/serial/uart8250.h index c1ffc0d..3d58050 100644 --- a/platform/common/include/plat/serial/uart8250.h +++ b/platform/common/include/plat/serial/uart8250.h @@ -14,7 +14,7 @@ void uart8250_putc(char ch); -char uart8250_getc(void); +int uart8250_getc(void); int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, diff --git a/platform/common/serial/sifive-uart.c b/platform/common/serial/sifive-uart.c index 2c0e1f1..08cc485 100644 --- a/platform/common/serial/sifive-uart.c +++ b/platform/common/serial/sifive-uart.c @@ -69,12 +69,12 @@ void sifive_uart_putc(char ch) set_reg(UART_REG_TXFIFO, ch); } -char sifive_uart_getc(void) +int sifive_uart_getc(void) { u32 ret = get_reg(UART_REG_RXFIFO); if (!(ret & UART_RXFIFO_EMPTY)) return ret & UART_RXFIFO_DATA; - return 0; + return -1; } int sifive_uart_init(unsigned long base, diff --git a/platform/common/serial/uart8250.c b/platform/common/serial/uart8250.c index 02eabbe..ce0f4ca 100644 --- a/platform/common/serial/uart8250.c +++ b/platform/common/serial/uart8250.c @@ -71,11 +71,11 @@ void uart8250_putc(char ch) set_reg(UART_THR_OFFSET, ch); } -char uart8250_getc(void) +int uart8250_getc(void) { if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR) return get_reg(UART_RBR_OFFSET); - return 0; + return -1; } int uart8250_init(unsigned long base, diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index f1e19b7..104edcc 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -31,7 +31,7 @@ static void k210_console_putc(char c) uarths_putc(c); } -static char k210_console_getc(void) +static int k210_console_getc(void) { return uarths_getc(); } diff --git a/platform/kendryte/k210/uarths.c b/platform/kendryte/k210/uarths.c index f8f4974..34fcf39 100644 --- a/platform/kendryte/k210/uarths.c +++ b/platform/kendryte/k210/uarths.c @@ -48,12 +48,12 @@ void uarths_putc(char c) uarths->txdata.data = (u8)c; } -char uarths_getc(void) +int uarths_getc(void) { struct uarths_rxdata rx = uarths->rxdata; if (rx.empty) - return '\0'; + return -1; return rx.data; } diff --git a/platform/kendryte/k210/uarths.h b/platform/kendryte/k210/uarths.h index dd0433c..f247a63 100644 --- a/platform/kendryte/k210/uarths.h +++ b/platform/kendryte/k210/uarths.h @@ -161,6 +161,6 @@ enum uarths_stopbit { void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit); void uarths_putc(char c); -char uarths_getc(void); +int uarths_getc(void); #endif /* _K210_UARTHS_H_ */ diff --git a/platform/template/platform.c b/platform/template/platform.c index e7a70aa..c14398f 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -73,7 +73,7 @@ static void platform_console_putc(char ch) /* * Read a character from the platform console input. */ -static char platform_console_getc(void) +static int platform_console_getc(void) { return uart8250_getc(); } |