bool sbi_isprintable(char ch);
-char sbi_getc(void);
+int sbi_getc(void);
void sbi_putc(char ch);
/** 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);
*
* @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;
}
/**
return FALSE;
}
-char sbi_getc(void)
+int sbi_getc(void)
{
return sbi_platform_console_getc(console_plat);
}
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--;
}
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);
void uart8250_putc(char ch);
-char uart8250_getc(void);
+int uart8250_getc(void);
int uart8250_init(unsigned long base,
u32 in_freq, u32 baudrate,
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,
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,
uarths_putc(c);
}
-static char k210_console_getc(void)
+static int k210_console_getc(void)
{
return uarths_getc();
}
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;
}
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_ */
/*
* Read a character from the platform console input.
*/
-static char platform_console_getc(void)
+static int platform_console_getc(void)
{
return uart8250_getc();
}