diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-03-19 18:02:57 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-03-19 18:02:57 -0600 |
commit | 35392d553c92ad96c944800bbb50defb4ca66f13 (patch) | |
tree | 955c81492ba666290c72f103458f6b2be617a3c3 | |
parent | 1f24c23a017b71d07459194f47adda9f26df8753 (diff) | |
download | nuttx-35392d553c92ad96c944800bbb50defb4ca66f13.tar.gz nuttx-35392d553c92ad96c944800bbb50defb4ca66f13.tar.bz2 nuttx-35392d553c92ad96c944800bbb50defb4ca66f13.zip |
SAM4E UDP: Fix errors associated with OUT packet size handling and bank interrupt bit handling
-rwxr-xr-x | nuttx/arch/arm/src/sam34/chip/sam_udp.h | 4 | ||||
-rw-r--r-- | nuttx/arch/arm/src/sam34/sam_udp.c | 96 |
2 files changed, 36 insertions, 64 deletions
diff --git a/nuttx/arch/arm/src/sam34/chip/sam_udp.h b/nuttx/arch/arm/src/sam34/chip/sam_udp.h index fd0230f65..267bcc43a 100755 --- a/nuttx/arch/arm/src/sam34/chip/sam_udp.h +++ b/nuttx/arch/arm/src/sam34/chip/sam_udp.h @@ -234,8 +234,8 @@ # define UDPEP_CSR_EPTYPE_INTIN (7 << UDPEP_CSR_EPTYPE_SHIFT) /* Interrupt IN */ #define UDPEP_CSR_DTGLE (1 << 11) /* Bit 11: Data Toggle */ #define UDPEP_CSR_EPEDS (1 << 15) /* Bit 15: Endpoint Enable Disable */ -#define UDPEP_CSR_RXBYTECNT_SHIFT (24) /* Bits 24-26: Number of Bytes Available in the FIFO */ -#define UDPEP_CSR_RXBYTECNT_MASK (7 << UDPEP_CSR_RXBYTECNT_SHIFT) +#define UDPEP_CSR_RXBYTECNT_SHIFT (16) /* Bits 16-26: Number of Bytes Available in the FIFO */ +#define UDPEP_CSR_RXBYTECNT_MASK (0x7ff << UDPEP_CSR_RXBYTECNT_SHIFT) /* Endpoint FIFO Data Registers */ diff --git a/nuttx/arch/arm/src/sam34/sam_udp.c b/nuttx/arch/arm/src/sam34/sam_udp.c index 4021516b1..b2546687c 100644 --- a/nuttx/arch/arm/src/sam34/sam_udp.c +++ b/nuttx/arch/arm/src/sam34/sam_udp.c @@ -380,9 +380,6 @@ static void sam_req_wrsetup(struct sam_usbdev_s *priv, struct sam_ep_s *privep, struct sam_req_s *privreq); static int sam_req_write(struct sam_usbdev_s *priv, struct sam_ep_s *privep); -static void sam_req_rddone(struct sam_usbdev_s *priv, - struct sam_ep_s *privep, struct sam_req_s *privreq, - uint16_t recvsize); static int sam_req_read(struct sam_usbdev_s *priv, struct sam_ep_s *privep, uint16_t recvsize); static void sam_req_cancel(struct sam_ep_s *privep, int16_t status); @@ -1100,53 +1097,6 @@ static int sam_req_write(struct sam_usbdev_s *priv, struct sam_ep_s *privep) } /**************************************************************************** - * Name: sam_req_rddone - * - * Description: - * The last OUT transfer has completed. Read 'recvsize' bytes from the - * FIFO into the read request buffer. - * - ****************************************************************************/ - -static void sam_req_rddone(struct sam_usbdev_s *priv, - struct sam_ep_s *privep, - struct sam_req_s *privreq, uint16_t recvsize) -{ - volatile uint32_t *fifo; - uint8_t *dest; - int remaining; - int readlen; - int epno; - - /* Get the number of bytes that can be received. This is the size of the - * user-provided request buffer, minus the number of bytes already - * transferred to the user-buffer. - */ - - remaining = privreq->req.len - privreq->req.xfrd; - - /* Read the smaller of the number of bytes available in FIFO and the - * size remaining in the request buffer provided by the caller. - */ - - readlen = MIN(remaining, recvsize); - privreq->req.xfrd += readlen; - - /* Get the source and destination transfer addresses */ - - epno = USB_EPNO(privep->ep.eplog); - fifo = (volatile uint32_t *)SAM_UDPEP_FDR(epno); - dest = privreq->req.buf + privreq->req.xfrd; - - /* Retrieve packet from the FIFO */ - - for (; readlen > 0; readlen--) - { - *dest++ = (uint8_t)(*fifo); - } -} - -/**************************************************************************** * Name: sam_req_read * * Description: @@ -1178,7 +1128,11 @@ static int sam_req_read(struct sam_usbdev_s *priv, struct sam_ep_s *privep, uint16_t recvsize) { struct sam_req_s *privreq; - uint8_t epno; + volatile const uint32_t *fifo; + uint8_t *dest; + int remaining; + int readlen; + int epno; DEBUGASSERT(priv && privep && privep->epstate == UDP_EPSTATE_IDLE); @@ -1213,18 +1167,36 @@ static int sam_req_read(struct sam_usbdev_s *priv, struct sam_ep_s *privep, usbtrace(TRACE_READ(USB_EPNO(privep->ep.eplog)), recvsize); - /* Update the number of bytes transferred with the received size */ + /* Get the number of bytes that can be received. This is the size + * of the user-provided request buffer, minus the number of bytes + * already transferred to the user-buffer. + */ - privreq->req.xfrd += recvsize; - privreq->inflight = 0; + remaining = privreq->req.len - privreq->req.xfrd; - /* Read the incoming data from the FIFO */ + /* Read the smaller of the number of bytes available in FIFO and the + * size remaining in the request buffer provided by the caller. + */ - sam_req_rddone(priv, privep, privreq, recvsize); + readlen = MIN(remaining, recvsize); + recvsize = 0; - /* In case we go through the loop again */ + /* Get the source and destination transfer addresses */ - recvsize = 0; + fifo = (volatile const uint32_t *)SAM_UDPEP_FDR(epno); + dest = privreq->req.buf + privreq->req.xfrd; + + /* Update the total number of bytes transferred */ + + privreq->req.xfrd += readlen; + privreq->inflight = 0; + + /* Retrieve packet from the endpoint FIFO */ + + for (; readlen > 0; readlen--) + { + *dest++ = (uint8_t)(*fifo); + } /* If nothing has yet be transferred into the read request, then * indicate that we are in the RECEIVING state. @@ -1285,11 +1257,11 @@ static void sam_req_cancel(struct sam_ep_s *privep, int16_t result) static void sam_ep0_read(uint8_t *buffer, size_t buflen) { - volatile uint32_t *fifo; + volatile const uint32_t *fifo; /* Retrieve packet from the FIFO */ - fifo = (volatile uint32_t *)SAM_UDPEP_FDR(EP0); + fifo = (volatile const uint32_t *)SAM_UDPEP_FDR(EP0); for (; buflen > 0; buflen--) { *buffer++ = (uint8_t)*fifo; @@ -2041,7 +2013,7 @@ static void sam_ep_interrupt(struct sam_usbdev_s *priv, int epno) /* Acknowledge the RX Data Bank 0 interrupt */ - sam_csr_setbits(epno, UDPEP_CSR_RXDATABK0); + sam_csr_clrbits(epno, UDPEP_CSR_RXDATABK0); } /* OUT packet received in data bank 1 */ @@ -2056,7 +2028,7 @@ static void sam_ep_interrupt(struct sam_usbdev_s *priv, int epno) /* Acknowledge the RX Data Bank 1 interrupt */ - sam_csr_setbits(epno, UDPEP_CSR_RXDATABK1); + sam_csr_clrbits(epno, UDPEP_CSR_RXDATABK1); } /* STALL sent */ |