Serial RX Flow Control: Fix a bunch of compile problems introduced into unbuilt, conditioned out logic

This commit is contained in:
Gregory Nutt 2014-12-27 08:15:41 -06:00
parent 2fadd0da4b
commit 32fd858dc6
2 changed files with 38 additions and 35 deletions

View File

@ -521,20 +521,21 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer,
static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
{
FAR struct inode *inode = filep->f_inode;
FAR uart_dev_t *dev = inode->i_private;
FAR uart_dev_t *dev = inode->i_private;
FAR struct uart_buffer_s *rxbuf = &dev->recv;
#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS
unsigned int nbuffered;
unsigned int watermark;
unsigned int nbuffered;
unsigned int watermark;
#endif
irqstate_t flags;
ssize_t recvd = 0;
int16_t tail;
int ret;
char ch;
irqstate_t flags;
ssize_t recvd = 0;
int16_t tail;
char ch;
int ret;
/* Only one user can access dev->recv.tail at a time */
/* Only one user can access rxbuf->tail at a time */
ret = uart_takesem(&dev->recv.sem, true);
ret = uart_takesem(&rxbuf->sem, true);
if (ret < 0)
{
/* A signal received while waiting for access to the recv.tail will avort
@ -579,24 +580,24 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
* 8-bit accesses to obtain the 16-bit head index.
*/
tail = dev->recv.tail;
if (dev->recv.head != tail)
tail = rxbuf->tail;
if (rxbuf->head != tail)
{
/* Take the next character from the tail of the buffer */
ch = dev->recv.buffer[tail];
ch = rxbuf->buffer[tail];
/* Increment the tail index. Most operations are done using the
* local variable 'tail' so that the final dev->recv.tail update
* local variable 'tail' so that the final rxbuf->tail update
* is atomic.
*/
if (++tail >= dev->recv.size)
if (++tail >= rxbuf->size)
{
tail = 0;
}
dev->recv.tail = tail;
rxbuf->tail = tail;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do input processing if any is enabled */
@ -697,7 +698,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
* interrupts.
*/
if (dev->recv.head == dev->recv.tail)
if (rxbuf->head == rxbuf->tail)
{
/* Yes.. the buffer is still empty. Wait for some characters
* to be received into the buffer with the RX interrupt re-
@ -781,28 +782,29 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS
/* How many bytes are now buffered */
if (buf->head >= buf->tail)
rxbuf = &dev->recv;
if (rxbuf->head >= rxbuf->tail)
{
nbuffered = buf->head - buf->tail;
nbuffered = rxbuf->head - rxbuf->tail;
}
else
{
nbuffered = buf->size - buf->tail + buf->head;
nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head;
}
/* Is the level now below the watermark level that we need to report? */
watermark = (CONFIG_SERIAL_IFLOWCONTROL_LOWER_WATERMARK * buf->size) / 100
watermark = (CONFIG_SERIAL_IFLOWCONTROL_LOWER_WATERMARK * rxbuf->size) / 100;
if (nbuffered <= watermark)
{
/* Let the lower level driver know that the watermark level has been
* crossed.
*/
(void)uart_rxflowcontrol(dev, nubuffered, false))
(void)uart_rxflowcontrol(dev, nbuffered, false);
}
#else
if (dev->recv.head == dev->recv.tail)
if (rxbuf->head == rxbuf->tail)
{
/* We might leave Rx interrupt disabled if full recv buffer was read
* empty. Enable Rx interrupt to make sure that more input is received.

View File

@ -138,14 +138,15 @@ void uart_xmitchars(FAR uart_dev_t *dev)
void uart_recvchars(FAR uart_dev_t *dev)
{
FAR struct uart_buffer_s *rxbuf = &dev->recv;
#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS
unsigned int watermark;
#endif
unsigned int status;
int nexthead = dev->recv.head + 1;
int nexthead = rxbuf->head + 1;
uint16_t nbytes = 0;
if (nexthead >= dev->recv.size)
if (nexthead >= rxbuf->size)
{
nexthead = 0;
}
@ -153,7 +154,7 @@ void uart_recvchars(FAR uart_dev_t *dev)
#ifdef CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS
/* Pre-calcuate the watermark level that we will need to test against. */
watermark = (CONFIG_SERIAL_IFLOWCONTROL_UPPER_WATERMARK * buf->size) / 100
watermark = (CONFIG_SERIAL_IFLOWCONTROL_UPPER_WATERMARK * rxbuf->size) / 100;
#endif
/* Loop putting characters into the receive buffer until there are no further
@ -162,7 +163,7 @@ void uart_recvchars(FAR uart_dev_t *dev)
while (uart_rxavailable(dev))
{
bool is_full = (nexthead == dev->recv.tail);
bool is_full = (nexthead == rxbuf->tail);
char ch;
#ifdef CONFIG_SERIAL_IFLOWCONTROL
@ -171,13 +172,13 @@ void uart_recvchars(FAR uart_dev_t *dev)
/* How many bytes are buffered */
if (buf->head >= buf->tail)
if (rxbuf->head >= rxbuf->tail)
{
nbuffered = buf->head - buf->tail;
nbuffered = rxbuf->head - rxbuf->tail;
}
else
{
nbuffered = buf->size - buf->tail + buf->head;
nbuffered = rxbuf->size - rxbuf->tail + rxbuf->head;
}
/* Is the level now above the watermark level that we need to report? */
@ -188,7 +189,7 @@ void uart_recvchars(FAR uart_dev_t *dev)
* crossed.
*/
if (uart_rxflowcontrol(dev, nubuffered, true))
if (uart_rxflowcontrol(dev, nbuffered, true))
{
/* Low-level driver activated RX flow control, exit loop now. */
@ -202,7 +203,7 @@ void uart_recvchars(FAR uart_dev_t *dev)
if (is_full)
{
if (uart_rxflowcontrol(dev, buf->size, true))
if (uart_rxflowcontrol(dev, rxbuf->size, true))
{
/* Low-level driver activated RX flow control, exit loop now. */
@ -226,13 +227,13 @@ void uart_recvchars(FAR uart_dev_t *dev)
{
/* Add the character to the buffer */
dev->recv.buffer[dev->recv.head] = ch;
rxbuf->buffer[rxbuf->head] = ch;
nbytes++;
/* Increment the head index */
dev->recv.head = nexthead;
if (++nexthead >= dev->recv.size)
rxbuf->head = nexthead;
if (++nexthead >= rxbuf->size)
{
nexthead = 0;
}