diff --git a/drivers/serial/serial_io.c b/drivers/serial/serial_io.c index c88875a1342..9518fc4e302 100644 --- a/drivers/serial/serial_io.c +++ b/drivers/serial/serial_io.c @@ -166,7 +166,7 @@ void uart_recvchars(FAR uart_dev_t *dev) { int nexthead = rxbuf->head + 1 < rxbuf->size ? rxbuf->head + 1 : 0; bool is_full = (nexthead == rxbuf->tail); - FAR char *pbuf; + FAR char *pbuf = NULL; char ch; #ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS @@ -217,38 +217,52 @@ void uart_recvchars(FAR uart_dev_t *dev) /* Get this next character from the hardware */ - if (!is_full && dev->ops->recvbuf) + if (dev->ops->recvbuf) { ssize_t ret; - if (rxbuf->tail > rxbuf->head) + if (!is_full) { - nbytes = rxbuf->tail - rxbuf->head - 1; - } - else if (rxbuf->tail) - { - nbytes = rxbuf->size - rxbuf->head; + if (rxbuf->tail > rxbuf->head) + { + nbytes = rxbuf->tail - rxbuf->head - 1; + } + else if (rxbuf->tail) + { + nbytes = rxbuf->size - rxbuf->head; + } + else + { + nbytes = rxbuf->size - rxbuf->head - 1; + } + + pbuf = &rxbuf->buffer[rxbuf->head]; + ret = uart_recvbuf(dev, pbuf, nbytes); + if (ret <= 0) + { + continue; + } + + nbytes = ret; + rxbuf->head += nbytes; + if (rxbuf->head >= rxbuf->size) + { + rxbuf->head = 0; + } } else { - nbytes = rxbuf->size - rxbuf->head - 1; - } + pbuf = &ch; + nbytes = 1; - pbuf = &rxbuf->buffer[rxbuf->head]; - ret = uart_recvbuf(dev, pbuf, nbytes); - if (ret <= 0) - { - continue; - } - - nbytes = ret; - rxbuf->head += nbytes; - if (rxbuf->head >= rxbuf->size) - { - rxbuf->head = 0; + ret = uart_recvbuf(dev, pbuf, nbytes); + if (ret <= 0) + { + continue; + } } } - else + else if(dev->ops->receive) { unsigned int status;