summaryrefslogtreecommitdiff
path: root/nuttx/drivers
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2013-07-25 21:56:14 +1000
committerAndrew Tridgell <tridge@samba.org>2013-07-25 21:58:57 +1000
commitd544e4b11fa79001995c06acbb874f2880acd42d (patch)
treeedbc9e7e6637f0695bb3c51d4a930d70d4b076f7 /nuttx/drivers
parentdcfc43c3bbe754884f1256551c057536b864ca1a (diff)
downloadpx4-nuttx-d544e4b11fa79001995c06acbb874f2880acd42d.tar.gz
px4-nuttx-d544e4b11fa79001995c06acbb874f2880acd42d.tar.bz2
px4-nuttx-d544e4b11fa79001995c06acbb874f2880acd42d.zip
cdcacm: added FIONREAD and FIONWRITE to cdcacm driver
based on serial.c implementation
Diffstat (limited to 'nuttx/drivers')
-rw-r--r--nuttx/drivers/usbdev/cdcacm.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/nuttx/drivers/usbdev/cdcacm.c b/nuttx/drivers/usbdev/cdcacm.c
index ec3dcd333..2584ce428 100644
--- a/nuttx/drivers/usbdev/cdcacm.c
+++ b/nuttx/drivers/usbdev/cdcacm.c
@@ -1939,6 +1939,54 @@ 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 = -ENOSYS;