mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-05 22:24:47 +08:00
Add FIONWRITE to allow applications to sniff the amount of writable space on a descriptor. Implement this for serial devices only.
This commit is contained in:
@@ -688,6 +688,27 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|||||||
*(int *)arg = count;
|
*(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
|
#ifdef CONFIG_SERIAL_TERMIOS
|
||||||
case TCGETS:
|
case TCGETS:
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,6 +110,10 @@
|
|||||||
* OUT: Bytes readable from this fd
|
* 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 **************************************/
|
/* NuttX file system ioctl definitions **************************************/
|
||||||
|
|
||||||
#define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE)
|
#define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE)
|
||||||
|
|||||||
Reference in New Issue
Block a user