aboutsummaryrefslogtreecommitdiff
path: root/nuttx/drivers/serial/serial.c
diff options
context:
space:
mode:
authorpx4dev <px4@purgatory.org>2013-01-03 00:33:22 -0800
committerpx4dev <px4@purgatory.org>2013-01-03 00:33:22 -0800
commite787fa5bce52e10179cae33df56caa765bfa75e2 (patch)
tree938ffd5c828f1bbd09391d611a3a0743bbf90477 /nuttx/drivers/serial/serial.c
parentc08135ffefcb171fd518e210b88e7e993361fd81 (diff)
downloadpx4-firmware-e787fa5bce52e10179cae33df56caa765bfa75e2.tar.gz
px4-firmware-e787fa5bce52e10179cae33df56caa765bfa75e2.tar.bz2
px4-firmware-e787fa5bce52e10179cae33df56caa765bfa75e2.zip
Add FIONWRITE to allow applications to sniff the amount of writable space on a descriptor. Implement this for serial devices only.
Diffstat (limited to 'nuttx/drivers/serial/serial.c')
-rw-r--r--nuttx/drivers/serial/serial.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/nuttx/drivers/serial/serial.c b/nuttx/drivers/serial/serial.c
index c650da5db..24744524f 100644
--- a/nuttx/drivers/serial/serial.c
+++ b/nuttx/drivers/serial/serial.c
@@ -688,6 +688,27 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
*(int *)arg = count;
}
+ case FIONWRITE:
+ {
+ int count;
+ irqstate_t state = irqsave();
+
+ /* determine the number of bytes free in the buffer */
+
+ if (dev->xmit.head <= dev->xmit.tail)
+ {
+ count = dev->xmit.tail - dev->xmit.head - 1;
+ }
+ else
+ {
+ count = dev->xmit.size - (dev->xmit.head - dev->xmit.tail) - 1;
+ }
+
+ irqrestore(state);
+
+ *(int *)arg = count;
+ }
+
#ifdef CONFIG_SERIAL_TERMIOS
case TCGETS:
{