diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-02 01:50:34 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-02 01:50:34 +0000 |
commit | f1851b468b62b448a0d9ed343d4ca8b9987e0d53 (patch) | |
tree | f2535999bb1d5b2b3b0f914c6812f8c5d897e35b | |
parent | d456ef7910458353f84d1270f5a9061441a082bc (diff) | |
download | px4-nuttx-f1851b468b62b448a0d9ed343d4ca8b9987e0d53.tar.gz px4-nuttx-f1851b468b62b448a0d9ed343d4ca8b9987e0d53.tar.bz2 px4-nuttx-f1851b468b62b448a0d9ed343d4ca8b9987e0d53.zip |
A spurious checkin... I just want to improve some code structure
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5597 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/drivers/serial/serial.c | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c index 68f0f43a2..aaec71202 100644 --- a/nuttx/drivers/serial/serial.c +++ b/nuttx/drivers/serial/serial.c @@ -220,19 +220,23 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch) if (dev->disconnected) { - irqrestore(flags); - return -ENOTCONN; + ret = -ENOTCONN; } + else #endif - /* Wait for some characters to be sent from the buffer with the TX - * interrupt enabled. When the TX interrupt is enabled, uart_xmitchars - * should execute and remove some of the data from the TX buffer. - */ + { + /* Wait for some characters to be sent from the buffer with + * the TX interrupt enabled. When the TX interrupt is + * enabled, uart_xmitchars should execute and remove some + * of the data from the TX buffer. + */ + + dev->xmitwaiting = true; + uart_enabletxint(dev); + ret = uart_takesem(&dev->xmitsem, true); + uart_disabletxint(dev); + } - dev->xmitwaiting = true; - uart_enabletxint(dev); - ret = uart_takesem(&dev->xmitsem, true); - uart_disabletxint(dev); irqrestore(flags); #ifdef CONFIG_SERIAL_REMOVABLE @@ -397,7 +401,7 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t * interrupted by a signal (ret should be -EINTR), or (2) if * CONFIG_SERIAL_REMOVABLE is defined, then uart_putxmitchar() * might also return if the serial device was disconnected - * (wtih -ENOTCONN). + * (with -ENOTCONN). */ if (ret < 0) @@ -409,16 +413,16 @@ static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t if (buflen < nread) { - /* Some data was transferred. Return the number of bytes that were - * successfully transferred. + /* Some data was transferred. Return the number of bytes that + * were successfully transferred. */ nread -= buflen; } else { - /* No data was transferred. Return -EINTR. The VFS layer will - * set the errno value appropriately). + /* No data was transferred. Return the negated errno value. + * The VFS layer will set the errno value appropriately). */ nread = ret; @@ -586,29 +590,30 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen */ flags = irqsave(); + uart_enablerxint(dev); #ifdef CONFIG_SERIAL_REMOVABLE - /* Check if the removable device is no longer connected while - * we have interrupts off. We do not want the transition to - * occur as a race condition before we begin the wait. + /* Check again if the removable device is still connected + * while we have interrupts off. We do not want the transition + * to occur as a race condition before we begin the wait. */ if (dev->disconnected) - { - uart_enablerxint(dev); - irqrestore(flags); + { ret = -ENOTCONN; - break; } + else #endif - /* Now wait with the Rx interrupt re-enabled. NuttX will - * automatically re-enable global interrupts when this thread - * goes to sleep. - */ + { + /* Now wait with the Rx interrupt re-enabled. NuttX will + * automatically re-enable global interrupts when this + * thread goes to sleep. + */ + + dev->recvwaiting = true; + ret = uart_takesem(&dev->recvsem, true); + } - dev->recvwaiting = true; - uart_enablerxint(dev); - ret = uart_takesem(&dev->recvsem, true); irqrestore(flags); /* Was a signal received while waiting for data to be |