Add option to used different request buffer sizes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1019 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2008-10-09 21:47:45 +00:00
parent 4371d7c822
commit 08b3a8917e
+39 -22
View File
@@ -98,10 +98,14 @@
# define CONFIG_USBSER_EPBULKIN 3 # define CONFIG_USBSER_EPBULKIN 3
#endif #endif
/* Packet and request buffer sizes */
#ifndef CONFIG_USBSER_EP0MAXPACKET #ifndef CONFIG_USBSER_EP0MAXPACKET
# define CONFIG_USBSER_EP0MAXPACKET 64 # define CONFIG_USBSER_EP0MAXPACKET 64
#endif #endif
#undef CONFIG_USBSER_BULKREQLEN
/* Vendor and product IDs and strings */ /* Vendor and product IDs and strings */
#ifndef CONFIG_USBSER_VENDORID #ifndef CONFIG_USBSER_VENDORID
@@ -289,11 +293,11 @@ struct usbser_alloc_s
/* Transfer helpers *********************************************************/ /* Transfer helpers *********************************************************/
static uint16 usbclass_fillpacket(FAR struct usbser_dev_s *priv, static uint16 usbclass_fillrequest(FAR struct usbser_dev_s *priv,
char *packet, uint16 size); char *reqbuf, uint16 reqlen);
static int usbclass_sndpacket(FAR struct usbser_dev_s *priv); static int usbclass_sndpacket(FAR struct usbser_dev_s *priv);
static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv, static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv,
char *packet, uint16 size); char *reqbuf, uint16 reqlen);
/* Request helpers *********************************************************/ /* Request helpers *********************************************************/
@@ -477,10 +481,10 @@ static const struct usb_qualdesc_s g_qualdesc =
****************************************************************************/ ****************************************************************************/
/************************************************************************************ /************************************************************************************
* Name: usbclass_fillpacket * Name: usbclass_fillrequest
* *
* Description: * Description:
* If there is data to send, a packet is built in the given buffer. Called either * If there is data to send it is copied to the given buffer. Called either
* to initiate the first write operation, or from the completion interrupt handler * to initiate the first write operation, or from the completion interrupt handler
* service consecutive write operations. * service consecutive write operations.
* *
@@ -492,7 +496,7 @@ static const struct usb_qualdesc_s g_qualdesc =
* *
************************************************************************************/ ************************************************************************************/
static uint16 usbclass_fillpacket(FAR struct usbser_dev_s *priv, char *packet, uint16 size) static uint16 usbclass_fillrequest(FAR struct usbser_dev_s *priv, char *reqbuf, uint16 reqlen)
{ {
FAR uart_dev_t *serdev = &priv->serdev; FAR uart_dev_t *serdev = &priv->serdev;
FAR struct uart_buffer_s *xmit = &serdev->xmit; FAR struct uart_buffer_s *xmit = &serdev->xmit;
@@ -503,11 +507,11 @@ static uint16 usbclass_fillpacket(FAR struct usbser_dev_s *priv, char *packet, u
flags = irqsave(); flags = irqsave();
/* Transfer bytes while we have bytes available and there is room in the packet */ /* Transfer bytes while we have bytes available and there is room in the request */
while (xmit->head != xmit->tail && nbytes < size) while (xmit->head != xmit->tail && nbytes < reqlen)
{ {
*packet++ = xmit->buffer[xmit->tail]; *reqbuf++ = xmit->buffer[xmit->tail];
nbytes++; nbytes++;
/* Increment the tail pointer */ /* Increment the tail pointer */
@@ -543,8 +547,8 @@ static uint16 usbclass_fillpacket(FAR struct usbser_dev_s *priv, char *packet, u
* Name: usbclass_sndpacket * Name: usbclass_sndpacket
* *
* Description: * Description:
* This function obtains write requests, transfers the TX data into the packet, * This function obtains write requests, transfers the TX data into the request,
* and submits the packets to the USB controller. This continues untils either * and submits the requests to the USB controller. This continues untils either
* (1) there are no further packets available, or (2) thre is not further data * (1) there are no further packets available, or (2) thre is not further data
* to send. * to send.
* *
@@ -573,8 +577,8 @@ static int usbclass_sndpacket(FAR struct usbser_dev_s *priv)
ep = priv->epbulkin; ep = priv->epbulkin;
/* Loop until either (1) we run out or write requests, or (2) usbclass_fillpacket() /* Loop until either (1) we run out or write requests, or (2) usbclass_fillrequest()
* is unable to fill the packet with data (i.e., untilthere is no more data * is unable to fill the request with data (i.e., untilthere is no more data
* to be sent). * to be sent).
*/ */
@@ -589,9 +593,9 @@ static int usbclass_sndpacket(FAR struct usbser_dev_s *priv)
reqcontainer = (struct usbser_req_s *)sq_peek(&priv->reqlist); reqcontainer = (struct usbser_req_s *)sq_peek(&priv->reqlist);
req = reqcontainer->req; req = reqcontainer->req;
/* Fill the packet with serial TX data */ /* Fill the request with serial TX data */
len = usbclass_fillpacket(priv, req->buf, ep->maxpacket); len = usbclass_fillrequest(priv, req->buf, req->len);
if (len > 0) if (len > 0)
{ {
/* Remove the empty contained from the request list */ /* Remove the empty contained from the request list */
@@ -634,7 +638,7 @@ static int usbclass_sndpacket(FAR struct usbser_dev_s *priv)
************************************************************************************/ ************************************************************************************/
static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv, static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv,
char *packet, uint16 size) char *reqbuf, uint16 reqlen)
{ {
FAR uart_dev_t *serdev = &priv->serdev; FAR uart_dev_t *serdev = &priv->serdev;
FAR struct uart_buffer_s *recv = &serdev->recv; FAR struct uart_buffer_s *recv = &serdev->recv;
@@ -662,7 +666,7 @@ static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv,
* then we have overrun the serial driver and data will be lost. * then we have overrun the serial driver and data will be lost.
*/ */
while (nexthead != recv->tail && size > 0) while (nexthead != recv->tail && reqlen > 0)
{ {
/* Pre-increment the head index and check for wrap around. We need to do this /* Pre-increment the head index and check for wrap around. We need to do this
* so that we can determine if the circular buffer will overrun BEFORE we * so that we can determine if the circular buffer will overrun BEFORE we
@@ -677,12 +681,12 @@ static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv,
/* Copy one byte to the head of the circular RX buffer */ /* Copy one byte to the head of the circular RX buffer */
recv->buffer[currhead] = *packet++; recv->buffer[currhead] = *reqbuf++;
/* Update counts and indices */ /* Update counts and indices */
currhead = nexthead; currhead = nexthead;
size--; reqlen--;
/* Wake up the serial driver if it is waiting for incoming data. If we /* Wake up the serial driver if it is waiting for incoming data. If we
* are running in an interrupt handler, then the serial driver will * are running in an interrupt handler, then the serial driver will
@@ -714,7 +718,7 @@ static inline int usbclass_recvpacket(FAR struct usbser_dev_s *priv,
/* Return an error if the entire packet could not be transferred */ /* Return an error if the entire packet could not be transferred */
if (size > 0) if (reqlen > 0)
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RXOVERRUN), 0); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RXOVERRUN), 0);
return -ENOSPC; return -ENOSPC;
@@ -1244,6 +1248,7 @@ static int usbclass_bind(FAR struct usbdev_s *dev, FAR struct usbdevclass_driver
FAR struct usbser_dev_s *priv = ((struct usbser_driver_s*)driver)->dev; FAR struct usbser_dev_s *priv = ((struct usbser_driver_s*)driver)->dev;
FAR struct usbser_req_s *reqcontainer; FAR struct usbser_req_s *reqcontainer;
irqstate_t flags; irqstate_t flags;
uint16 reqlen;
int ret; int ret;
int i; int i;
@@ -1307,10 +1312,16 @@ static int usbclass_bind(FAR struct usbdev_s *dev, FAR struct usbdevclass_driver
/* Pre-allocate read requests */ /* Pre-allocate read requests */
#ifdef CONFIG_USBSER_BULKREQLEN
reqlen = max(CONFIG_USBSER_BULKREQLEN, priv->epbulkout->maxpacket);
#else
reqlen =priv->epbulkout->maxpacket;
#endif
for (i = 0; i < CONFIG_USBSER_NRDREQS; i++) for (i = 0; i < CONFIG_USBSER_NRDREQS; i++)
{ {
reqcontainer = &priv->rdreqs[i]; reqcontainer = &priv->rdreqs[i];
reqcontainer->req = usbclass_allocreq(priv->epbulkout, priv->epbulkout->maxpacket); reqcontainer->req = usbclass_allocreq(priv->epbulkout, reqlen);
if (reqcontainer->req == NULL) if (reqcontainer->req == NULL)
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDALLOCREQ), (uint16)-ret); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_RDALLOCREQ), (uint16)-ret);
@@ -1323,10 +1334,16 @@ static int usbclass_bind(FAR struct usbdev_s *dev, FAR struct usbdevclass_driver
/* Pre-allocate write request containers and put in a free list */ /* Pre-allocate write request containers and put in a free list */
#ifdef CONFIG_USBSER_BULKREQLEN
reqlen = max(CONFIG_USBSER_BULKREQLEN, priv->epbulkin->maxpacket);
#else
reqlen = priv->epbulkin->maxpacket;
#endif
for (i = 0; i < CONFIG_USBSER_NWRREQS; i++) for (i = 0; i < CONFIG_USBSER_NWRREQS; i++)
{ {
reqcontainer = &priv->wrreqs[i]; reqcontainer = &priv->wrreqs[i];
reqcontainer->req = usbclass_allocreq(priv->epbulkin, priv->epbulkin->maxpacket); reqcontainer->req = usbclass_allocreq(priv->epbulkin, reqlen);
if (reqcontainer->req == NULL) if (reqcontainer->req == NULL)
{ {
usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_WRALLOCREQ), (uint16)-ret); usbtrace(TRACE_CLSERROR(USBSER_TRACEERR_WRALLOCREQ), (uint16)-ret);