Added FIONREAD and FIONWRITE to CDC/ACM driver. From Lorenz Meier

This commit is contained in:
Gregory Nutt 2013-08-10 19:21:39 -06:00
parent 82b528e0c8
commit 0f20d4581b
2 changed files with 49 additions and 0 deletions

View File

@ -5347,3 +5347,6 @@
added TERMIOS input / output processing support for UART and CDCACM
serial ports. Implemented by Mike Smith, Andrew Tridgell and Lorenz
Meier (2013-8-10).
* drivers/usbdev/cdcacm.c: Added FIONREAD and FIONWRITE to CDC/ACM
driver based on serial.c implementation. From Lorenz Meier
(2013-8-10).

View File

@ -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;