diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-08-10 19:21:39 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-08-10 19:21:39 -0600 |
commit | 0e6621387a1b415e377fca1b60d70d25366e1680 (patch) | |
tree | 2249f0eee7dcc0b1c5b51d8c2675131811822fec /nuttx/drivers/usbdev | |
parent | 3c5fcd7ca22c13071fc85c89036adf43f92ebaf2 (diff) | |
download | px4-nuttx-0e6621387a1b415e377fca1b60d70d25366e1680.tar.gz px4-nuttx-0e6621387a1b415e377fca1b60d70d25366e1680.tar.bz2 px4-nuttx-0e6621387a1b415e377fca1b60d70d25366e1680.zip |
Added FIONREAD and FIONWRITE to CDC/ACM driver. From Lorenz Meier
Diffstat (limited to 'nuttx/drivers/usbdev')
-rw-r--r-- | nuttx/drivers/usbdev/cdcacm.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nuttx/drivers/usbdev/cdcacm.c b/nuttx/drivers/usbdev/cdcacm.c index 441ac907e..dcd5b9aa1 100644 --- a/nuttx/drivers/usbdev/cdcacm.c +++ b/nuttx/drivers/usbdev/cdcacm.c @@ -1937,6 +1937,52 @@ static int cdcuart_ioctl(FAR struct file *filep,int cmd,unsigned long arg) break; #endif + case FIONREAD: + { + int count; + irqstate_t state = irqsave(); + + /* Determine the number of bytes available in the buffer. */ + + if (serdev->recv.tail <= serdev->recv.head) + { + count = serdev->recv.head - serdev->recv.tail; + } + else + { + count = serdev->recv.size - (serdev->recv.tail - serdev->recv.head); + } + + irqrestore(state); + + *(int *)arg = count; + ret = 0; + } + break; + + case FIONWRITE: + { + int count; + irqstate_t state = irqsave(); + + /* Determine the number of bytes free in the buffer. */ + + if (serdev->xmit.head < serdev->xmit.tail) + { + count = serdev->xmit.tail - serdev->xmit.head - 1; + } + else + { + count = serdev->xmit.size - (serdev->xmit.head - serdev->xmit.tail) - 1; + } + + irqrestore(state); + + *(int *)arg = count; + ret = 0; + } + break; + default: ret = -ENOTTY; break; |