diff options
author | px4dev <px4@purgatory.org> | 2013-01-03 00:33:22 -0800 |
---|---|---|
committer | px4dev <px4@purgatory.org> | 2013-01-03 00:33:22 -0800 |
commit | e787fa5bce52e10179cae33df56caa765bfa75e2 (patch) | |
tree | 938ffd5c828f1bbd09391d611a3a0743bbf90477 /nuttx/drivers/serial/serial.c | |
parent | c08135ffefcb171fd518e210b88e7e993361fd81 (diff) | |
download | px4-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.c | 21 |
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: { |