mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
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>
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
bool sbi_isprintable(char ch);
|
bool sbi_isprintable(char ch);
|
||||||
|
|
||||||
char sbi_getc(void);
|
int sbi_getc(void);
|
||||||
|
|
||||||
void sbi_putc(char ch);
|
void sbi_putc(char ch);
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ struct sbi_platform {
|
|||||||
/** Write a character to the platform console output */
|
/** Write a character to the platform console output */
|
||||||
void (*console_putc)(char ch);
|
void (*console_putc)(char ch);
|
||||||
/** Read a character from the platform console input */
|
/** Read a character from the platform console input */
|
||||||
char (*console_getc)(void);
|
int (*console_getc)(void);
|
||||||
/** Initialize the platform console */
|
/** Initialize the platform console */
|
||||||
int (*console_init)(void);
|
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
|
* @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)
|
if (plat && plat->console_getc)
|
||||||
return plat->console_getc();
|
return plat->console_getc();
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,7 +26,7 @@ bool sbi_isprintable(char c)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char sbi_getc(void)
|
int sbi_getc(void)
|
||||||
{
|
{
|
||||||
return sbi_platform_console_getc(console_plat);
|
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)
|
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) {
|
while ((ch = sbi_getc()) != endchar && ch >= 0 && maxwidth > 1) {
|
||||||
*retval = ch;
|
*retval = (char) ch;
|
||||||
retval++;
|
retval++;
|
||||||
maxwidth--;
|
maxwidth--;
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
void sifive_uart_putc(char ch);
|
void sifive_uart_putc(char ch);
|
||||||
|
|
||||||
char sifive_uart_getc(void);
|
int sifive_uart_getc(void);
|
||||||
|
|
||||||
int sifive_uart_init(unsigned long base,
|
int sifive_uart_init(unsigned long base,
|
||||||
u32 in_freq, u32 baudrate);
|
u32 in_freq, u32 baudrate);
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
void uart8250_putc(char ch);
|
void uart8250_putc(char ch);
|
||||||
|
|
||||||
char uart8250_getc(void);
|
int uart8250_getc(void);
|
||||||
|
|
||||||
int uart8250_init(unsigned long base,
|
int uart8250_init(unsigned long base,
|
||||||
u32 in_freq, u32 baudrate,
|
u32 in_freq, u32 baudrate,
|
||||||
|
@@ -69,12 +69,12 @@ void sifive_uart_putc(char ch)
|
|||||||
set_reg(UART_REG_TXFIFO, ch);
|
set_reg(UART_REG_TXFIFO, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
char sifive_uart_getc(void)
|
int sifive_uart_getc(void)
|
||||||
{
|
{
|
||||||
u32 ret = get_reg(UART_REG_RXFIFO);
|
u32 ret = get_reg(UART_REG_RXFIFO);
|
||||||
if (!(ret & UART_RXFIFO_EMPTY))
|
if (!(ret & UART_RXFIFO_EMPTY))
|
||||||
return ret & UART_RXFIFO_DATA;
|
return ret & UART_RXFIFO_DATA;
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sifive_uart_init(unsigned long base,
|
int sifive_uart_init(unsigned long base,
|
||||||
|
@@ -71,11 +71,11 @@ void uart8250_putc(char ch)
|
|||||||
set_reg(UART_THR_OFFSET, ch);
|
set_reg(UART_THR_OFFSET, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
char uart8250_getc(void)
|
int uart8250_getc(void)
|
||||||
{
|
{
|
||||||
if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
|
if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR)
|
||||||
return get_reg(UART_RBR_OFFSET);
|
return get_reg(UART_RBR_OFFSET);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uart8250_init(unsigned long base,
|
int uart8250_init(unsigned long base,
|
||||||
|
@@ -31,7 +31,7 @@ static void k210_console_putc(char c)
|
|||||||
uarths_putc(c);
|
uarths_putc(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char k210_console_getc(void)
|
static int k210_console_getc(void)
|
||||||
{
|
{
|
||||||
return uarths_getc();
|
return uarths_getc();
|
||||||
}
|
}
|
||||||
|
@@ -48,12 +48,12 @@ void uarths_putc(char c)
|
|||||||
uarths->txdata.data = (u8)c;
|
uarths->txdata.data = (u8)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
char uarths_getc(void)
|
int uarths_getc(void)
|
||||||
{
|
{
|
||||||
struct uarths_rxdata rx = uarths->rxdata;
|
struct uarths_rxdata rx = uarths->rxdata;
|
||||||
|
|
||||||
if (rx.empty)
|
if (rx.empty)
|
||||||
return '\0';
|
return -1;
|
||||||
|
|
||||||
return rx.data;
|
return rx.data;
|
||||||
}
|
}
|
||||||
|
@@ -161,6 +161,6 @@ enum uarths_stopbit {
|
|||||||
|
|
||||||
void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit);
|
void uarths_init(u32 baud_rate, enum uarths_stopbit stopbit);
|
||||||
void uarths_putc(char c);
|
void uarths_putc(char c);
|
||||||
char uarths_getc(void);
|
int uarths_getc(void);
|
||||||
|
|
||||||
#endif /* _K210_UARTHS_H_ */
|
#endif /* _K210_UARTHS_H_ */
|
||||||
|
@@ -73,7 +73,7 @@ static void platform_console_putc(char ch)
|
|||||||
/*
|
/*
|
||||||
* Read a character from the platform console input.
|
* Read a character from the platform console input.
|
||||||
*/
|
*/
|
||||||
static char platform_console_getc(void)
|
static int platform_console_getc(void)
|
||||||
{
|
{
|
||||||
return uart8250_getc();
|
return uart8250_getc();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user