diff options
author | px4dev <px4@purgatory.org> | 2013-01-03 00:33:22 -0800 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2013-01-03 19:35:44 +1100 |
commit | 3916230d8fc7185a7eefcc1640a68bacf3eac72b (patch) | |
tree | 3aef2a3b7d064ff3a683c414edde850bd336aca9 /nuttx | |
parent | 8ffba227718f6f7897abb5a1fd77f770f1f3db1f (diff) | |
download | px4-firmware-3916230d8fc7185a7eefcc1640a68bacf3eac72b.tar.gz px4-firmware-3916230d8fc7185a7eefcc1640a68bacf3eac72b.tar.bz2 px4-firmware-3916230d8fc7185a7eefcc1640a68bacf3eac72b.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')
-rw-r--r-- | nuttx/drivers/serial/serial.c | 21 | ||||
-rw-r--r-- | nuttx/include/nuttx/fs/ioctl.h | 4 |
2 files changed, 25 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: { diff --git a/nuttx/include/nuttx/fs/ioctl.h b/nuttx/include/nuttx/fs/ioctl.h index 08f62e164..6d60c2ee9 100644 --- a/nuttx/include/nuttx/fs/ioctl.h +++ b/nuttx/include/nuttx/fs/ioctl.h @@ -110,6 +110,10 @@ * OUT: Bytes readable from this fd */ +#define FIONWRITE _FIOC(0x0005) /* IN: Location to return value (int *) + * OUT: Bytes writable to this fd + */ + /* NuttX file system ioctl definitions **************************************/ #define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE) |