MCPcopy Create free account
hub / github.com/apache/nuttx / sim_usbdev_epread

Function sim_usbdev_epread

arch/sim/src/sim/sim_usbdev.c:527–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525 ****************************************************************************/
526
527static int sim_usbdev_epread(uint16_t addr, uint8_t *data, uint16_t len)
528{
529 struct sim_usbdev_s *priv = &g_sim_usbdev;
530 struct sim_ep_s *privep;
531 struct sim_req_s *privreq;
532 uint8_t *dest;
533 uint8_t epno;
534 int readlen;
535
536 /* Get the unadorned endpoint number */
537
538 epno = USB_EPNO(addr);
539 privep = &priv->eps[epno];
540
541 usbtrace(TRACE_READ(USB_EPNO(privep->ep.eplog)), len);
542
543 /* We get here when an IN endpoint interrupt occurs. So now we know that
544 * there is no TX transfer in progress.
545 */
546
547 while (privep->epstate == SIM_EPSTATE_IDLE && len > 0)
548 {
549 /* Check the request from the head of the endpoint request queue */
550
551 privreq = sim_rqpeek(&privep->reqq);
552 if (!privreq)
553 {
554 return -ENOENT;
555 }
556
557 /* Get the source and destination transfer addresses */
558
559 dest = privreq->req.buf + privreq->req.xfrd;
560
561 /* Get the number of bytes to read from packet memory */
562
563 readlen = MIN(privreq->req.len - privreq->req.xfrd, len);
564
565 /* Receive the next packet */
566
567 memcpy(dest, data, readlen);
568
569 /* If the receive buffer is full or this is a partial packet,
570 * then we are finished with the request buffer).
571 */
572
573 privreq->req.xfrd += readlen;
574 len -= readlen;
575 data += readlen;
576
577 if (len < privep->ep.maxpacket ||
578 privreq->req.xfrd >= privreq->req.len)
579 {
580 /* Return the read request to the class driver. */
581
582 usbtrace(TRACE_COMPLETE(epno), privreq->req.xfrd);
583 sim_reqcomplete(privep, OK);
584 }

Callers 1

sim_usbdev_workFunction · 0.85

Calls 3

usbtraceFunction · 0.85
sim_reqcompleteFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected