- Add a uart_rxready() and corresponding device-specific implementations

that can be used to check whether receive data is ready, i.e. whether
  the subsequent call of uart_poll() should return a char, and unlike
  uart_poll() doesn't actually receive data.
- Remove the device-specific implementations of uart_poll() and implement
  uart_poll() in terms of uart_getc() and the newly added uart_rxready()
  in order to minimize code duplication.
- In sunkbd(4) take advantage of uart_rxready() and use it to implement
  the polled mode part of sunkbd_check() so we don't need to buffer a
  potentially read char in the softc.
- Fix some mis-indentation in sunkbd_read_char().

Discussed with:	marcel
This commit is contained in:
marius 2007-01-18 22:01:19 +00:00
parent 6f6da4e54a
commit 545a381d5f
7 changed files with 45 additions and 48 deletions

View File

@ -94,7 +94,7 @@ static int at91_usart_probe(struct uart_bas *bas);
static void at91_usart_init(struct uart_bas *bas, int, int, int, int);
static void at91_usart_term(struct uart_bas *bas);
static void at91_usart_putc(struct uart_bas *bas, int);
static int at91_usart_poll(struct uart_bas *bas);
static int at91_usart_rxready(struct uart_bas *bas);
static int at91_usart_getc(struct uart_bas *bas, struct mtx *mtx);
extern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
@ -201,7 +201,7 @@ struct uart_ops at91_usart_ops = {
.init = at91_usart_init,
.term = at91_usart_term,
.putc = at91_usart_putc,
.poll = at91_usart_poll,
.rxready = at91_usart_rxready,
.getc = at91_usart_getc,
};
@ -252,15 +252,13 @@ at91_usart_putc(struct uart_bas *bas, int c)
}
/*
* Poll for a character available
* Check for a character available.
*/
static int
at91_usart_poll(struct uart_bas *bas)
at91_usart_rxready(struct uart_bas *bas)
{
if (!(RD4(bas, USART_CSR) & USART_CSR_RXRDY))
return (-1);
return (RD4(bas, USART_RHR) & 0xff);
return ((RD4(bas, USART_CSR) & USART_CSR_RXRDY) != 0 ? 1 : 0);
}
/*

View File

@ -52,7 +52,7 @@ static int sa1110_probe(struct uart_bas *bas);
static void sa1110_init(struct uart_bas *bas, int, int, int, int);
static void sa1110_term(struct uart_bas *bas);
static void sa1110_putc(struct uart_bas *bas, int);
static int sa1110_poll(struct uart_bas *bas);
static int sa1110_rxready(struct uart_bas *bas);
static int sa1110_getc(struct uart_bas *bas, struct mtx *mtx);
extern SLIST_HEAD(uart_devinfo_list, uart_devinfo) uart_sysdevs;
@ -62,7 +62,7 @@ struct uart_ops uart_sa1110_ops = {
.init = sa1110_init,
.term = sa1110_term,
.putc = sa1110_putc,
.poll = sa1110_poll,
.rxready = sa1110_rxready,
.getc = sa1110_getc,
};
@ -102,11 +102,10 @@ sa1110_putc(struct uart_bas *bas, int c)
}
static int
sa1110_poll(struct uart_bas *bas)
sa1110_rxready(struct uart_bas *bas)
{
if (!(uart_getreg(bas, SACOM_SR1) & SR1_RNE))
return (-1);
return (uart_getreg(bas, SACOM_DR) & 0xff);
return ((uart_getreg(bas, SACOM_SR1) & SR1_RNE) != 0 ? 1 : 0);
}
static int

View File

@ -41,7 +41,7 @@ struct uart_ops {
void (*init)(struct uart_bas *, int, int, int, int);
void (*term)(struct uart_bas *);
void (*putc)(struct uart_bas *, int);
int (*poll)(struct uart_bas *);
int (*rxready)(struct uart_bas *);
int (*getc)(struct uart_bas *, struct mtx *);
};
@ -136,13 +136,27 @@ uart_putc(struct uart_devinfo *di, int c)
uart_unlock(di->hwmtx);
}
static __inline int
uart_rxready(struct uart_devinfo *di)
{
int res;
uart_lock(di->hwmtx);
res = di->ops.rxready(&di->bas);
uart_unlock(di->hwmtx);
return (res);
}
static __inline int
uart_poll(struct uart_devinfo *di)
{
int res;
uart_lock(di->hwmtx);
res = di->ops.poll(&di->bas);
if (di->ops.rxready(&di->bas))
res = di->ops.getc(&di->bas, NULL);
else
res = -1;
uart_unlock(di->hwmtx);
return (res);
}

View File

@ -217,7 +217,7 @@ static int ns8250_probe(struct uart_bas *bas);
static void ns8250_init(struct uart_bas *bas, int, int, int, int);
static void ns8250_term(struct uart_bas *bas);
static void ns8250_putc(struct uart_bas *bas, int);
static int ns8250_poll(struct uart_bas *bas);
static int ns8250_rxready(struct uart_bas *bas);
static int ns8250_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_ns8250_ops = {
@ -225,7 +225,7 @@ struct uart_ops uart_ns8250_ops = {
.init = ns8250_init,
.term = ns8250_term,
.putc = ns8250_putc,
.poll = ns8250_poll,
.rxready = ns8250_rxready,
.getc = ns8250_getc,
};
@ -299,12 +299,10 @@ ns8250_putc(struct uart_bas *bas, int c)
}
static int
ns8250_poll(struct uart_bas *bas)
ns8250_rxready(struct uart_bas *bas)
{
if (uart_getreg(bas, REG_LSR) & LSR_RXRDY)
return (uart_getreg(bas, REG_DATA));
return (-1);
return ((uart_getreg(bas, REG_LSR) & LSR_RXRDY) != 0 ? 1 : 0);
}
static int

View File

@ -173,7 +173,7 @@ static int sab82532_probe(struct uart_bas *bas);
static void sab82532_init(struct uart_bas *bas, int, int, int, int);
static void sab82532_term(struct uart_bas *bas);
static void sab82532_putc(struct uart_bas *bas, int);
static int sab82532_poll(struct uart_bas *bas);
static int sab82532_rxready(struct uart_bas *bas);
static int sab82532_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_sab82532_ops = {
@ -181,7 +181,7 @@ struct uart_ops uart_sab82532_ops = {
.init = sab82532_init,
.term = sab82532_term,
.putc = sab82532_putc,
.poll = sab82532_poll,
.rxready = sab82532_rxready,
.getc = sab82532_getc,
};
@ -303,12 +303,10 @@ sab82532_putc(struct uart_bas *bas, int c)
}
static int
sab82532_poll(struct uart_bas *bas)
sab82532_rxready(struct uart_bas *bas)
{
if (uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE)
return (sab82532_getc(bas, NULL));
return (-1);
return ((uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE) != 0 ? 1 : 0);
}
static int

View File

@ -192,7 +192,7 @@ static int z8530_probe(struct uart_bas *bas);
static void z8530_init(struct uart_bas *bas, int, int, int, int);
static void z8530_term(struct uart_bas *bas);
static void z8530_putc(struct uart_bas *bas, int);
static int z8530_poll(struct uart_bas *bas);
static int z8530_rxready(struct uart_bas *bas);
static int z8530_getc(struct uart_bas *bas, struct mtx *);
struct uart_ops uart_z8530_ops = {
@ -200,7 +200,7 @@ struct uart_ops uart_z8530_ops = {
.init = z8530_init,
.term = z8530_term,
.putc = z8530_putc,
.poll = z8530_poll,
.rxready = z8530_rxready,
.getc = z8530_getc,
};
@ -235,12 +235,10 @@ z8530_putc(struct uart_bas *bas, int c)
}
static int
z8530_poll(struct uart_bas *bas)
z8530_rxready(struct uart_bas *bas)
{
if (!(uart_getreg(bas, REG_CTRL) & BES_RXA))
return (-1);
return (uart_getreg(bas, REG_DATA));
return ((uart_getreg(bas, REG_CTRL) & BES_RXA) != 0 ? 1 : 0);
}
static int

View File

@ -72,8 +72,6 @@ struct sunkbd_softc {
struct uart_softc *sc_uart;
struct uart_devinfo *sc_sysdev;
int sc_checked_key;
struct callout sc_repeat_callout;
int sc_repeat_key;
@ -403,7 +401,7 @@ sunkbd_check(keyboard_t *kbd)
return (TRUE);
if (sc->sc_polling != 0 && sc->sc_sysdev != NULL &&
(sc->sc_checked_key = uart_poll(sc->sc_sysdev)) != -1)
uart_rxready(sc->sc_sysdev))
return (TRUE);
return (FALSE);
@ -441,12 +439,6 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
goto process_code;
}
if (sc->sc_checked_key != -1) {
suncode = sc->sc_checked_key;
sc->sc_checked_key = -1;
goto process_code;
}
for (;;) {
next_code:
if (!(sc->sc_flags & KPCOMPOSE) && (sc->sc_composed_char > 0)) {
@ -472,7 +464,6 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
case SKBD_RSP_IDLE:
break;
default:
process_code:
++kbd->kb_count;
key = SKBD_KEY_CHAR(suncode);
@ -565,10 +556,12 @@ sunkbd_read_char(keyboard_t *kbd, int wait)
if (key == 0x13) { /* left alt (KP compose key) */
#endif
if (release != 0) {
if (sc->sc_flags & KPCOMPOSE) {
sc->sc_flags &= ~KPCOMPOSE;
if (sc->sc_composed_char > UCHAR_MAX)
sc->sc_composed_char = 0;
if (sc->sc_flags & KPCOMPOSE) {
sc->sc_flags &= ~KPCOMPOSE;
if (sc->sc_composed_char >
UCHAR_MAX)
sc->sc_composed_char =
0;
}
} else {
if (!(sc->sc_flags & KPCOMPOSE)) {
@ -768,7 +761,6 @@ sunkbd_clear_state(keyboard_t *kbd)
struct sunkbd_softc *sc;
sc = (struct sunkbd_softc *)kbd;
sc->sc_checked_key = -1;
sc->sc_repeat_key = -1;
sc->sc_accents = 0;
sc->sc_composed_char = 0;