Skip to content

Commit

Permalink
char/cadence_uart: Fix can_receive logic
Browse files Browse the repository at this point in the history
The can_receive logic was only taking into account the RxFIFO
occupancy. RxFIFO population is only used for the echo and normal modes
however. Improve the logic to correctly return the true number of
receivable characters based on the current mode:

Normal mode: RxFIFO vacancy.
Remote loopback: TxFIFO vacancy.
Echo mode: The min of the TxFIFO and RxFIFO vacancies.
Local Loopback: Return non-zero (to implement droppage)

Signed-off-by: Peter Crosthwaite <[email protected]>
Message-id: 36a58440c9ca5080151e95765c2c81342de8a8df.1388626249.git.peter.crosthwaite@xilinx.com
Signed-off-by: Peter Maydell <[email protected]>
  • Loading branch information
pete128 authored and pm215 committed Jan 8, 2014
1 parent 2152e08 commit d0ac820
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion hw/char/cadence_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,16 @@ static void uart_parameters_setup(UartState *s)
static int uart_can_receive(void *opaque)
{
UartState *s = (UartState *)opaque;
int ret = MAX(RX_FIFO_SIZE, TX_FIFO_SIZE);
uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;

return RX_FIFO_SIZE - s->rx_count;
if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
ret = MIN(ret, RX_FIFO_SIZE - s->rx_count);
}
if (ch_mode == REMOTE_LOOPBACK || ch_mode == ECHO_MODE) {
ret = MIN(ret, TX_FIFO_SIZE - s->tx_count);
}
return ret;
}

static void uart_ctrl_update(UartState *s)
Expand Down

0 comments on commit d0ac820

Please sign in to comment.