From a42c8f6c418ff0bb1928befbf3ec4dcae0b05966 Mon Sep 17 00:00:00 2001 From: Wojciech Zajac Date: Mon, 2 Jun 2014 16:09:05 +0200 Subject: [PATCH] Error checking for USB interrupt transfer --- drivers/usbd/README.txt | 7 +++++-- drivers/usbd/hcd/hcd.c | 11 +++++++---- drivers/usbd/hcd/musb/musb_core.c | 14 ++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/usbd/README.txt b/drivers/usbd/README.txt index e18565bf9..c36055855 100755 --- a/drivers/usbd/README.txt +++ b/drivers/usbd/README.txt @@ -3,7 +3,7 @@ ------------------------------------------------------------------------------- README file for "USBD" USB host controller driver. -created march-may 2014, JPEmbedded (info@jpembedded.eu) +created march-june 2014, JPEmbedded (info@jpembedded.eu) ------------------------------------------------------------------------------- * KNOWN LIMITATIONS: * @@ -13,4 +13,7 @@ created march-may 2014, JPEmbedded (info@jpembedded.eu) - DDEKit does not implement resource deallocation for corresponding thread creation (see ddekit_thread_terminate, ddekit_thread_create) thus resources are spilled -- Driver assumes that there is no preemption for DDEKit threading \ No newline at end of file +- Driver assumes that there is no preemption for DDEKit threading +- URBs are enqueued in DDEKit but not in USBD itself +- DDEKit way of handling interface numbers is not explicitly defined, bitmask + formatting for it, is therefore hardcoded into USBD diff --git a/drivers/usbd/hcd/hcd.c b/drivers/usbd/hcd/hcd.c index fcb2edf24..216eaa528 100755 --- a/drivers/usbd/hcd/hcd.c +++ b/drivers/usbd/hcd/hcd.c @@ -804,8 +804,10 @@ hcd_data_transfer(hcd_device_state * this_device, hcd_datarequest * request) request->data += transfer_len; /* Total length shall not become negative */ - USB_ASSERT(request->size >= 0, - "Invalid amount of data received"); + if (request->size < 0) { + USB_MSG("Invalid amount of data received"); + return EXIT_FAILURE; + } #ifdef DEBUG /* TODO: REMOVEME (dumping of data transfer) */ @@ -813,7 +815,8 @@ hcd_data_transfer(hcd_device_state * this_device, hcd_datarequest * request) int i; USB_MSG("RECEIVED: %d", transfer_len); for (i = 0; i < transfer_len; i++) - USB_MSG("%c", + USB_MSG("0x%02X: %c", + (request->data-transfer_len)[i], (request->data-transfer_len)[i]); } #endif @@ -835,7 +838,7 @@ hcd_data_transfer(hcd_device_state * this_device, hcd_datarequest * request) /* Total length shall not become negative */ USB_ASSERT(request->size >= 0, - "Invalid amount of data received"); + "Invalid amount of transfer data calculated"); /* Start actual data transfer */ d->tx_stage(d->private_data, &temp_req); diff --git a/drivers/usbd/hcd/musb/musb_core.c b/drivers/usbd/hcd/musb/musb_core.c index 0c36e6ae3..854d4769d 100755 --- a/drivers/usbd/hcd/musb/musb_core.c +++ b/drivers/usbd/hcd/musb/musb_core.c @@ -795,13 +795,17 @@ musb_check_error(void * cfg, hcd_transfer transfer, hcd_direction dir) DEBUG_DUMP; + /* TODO: ISO transfer */ + USB_ASSERT(HCD_TRANSFER_ISOCHRONOUS != transfer, + "ISO transfer not supported"); + r = ((musb_core_config *)cfg)->regs; /* Set EP and device address to be used in this command */ musb_set_state((musb_core_config *)cfg); - /* TODO: In MUSB only EP0 is allowed to handle control transfers - * so there is no EP checking in this function */ + /* TODO: More than one control EP? */ + /* In MUSB EP0 has it's own registers for error handling */ if (HCD_TRANSFER_CONTROL == transfer) { /* Get control status register */ host_csr = HCD_RD2(r, MUSB_REG_HOST_CSR0); @@ -831,7 +835,9 @@ musb_check_error(void * cfg, hcd_transfer transfer, hcd_direction dir) return EXIT_SUCCESS; } - if ((HCD_TRANSFER_BULK == transfer) && (HCD_DIRECTION_OUT == dir)) { + /* Non-control transfer error check, + * is based on transfer direction */ + if (HCD_DIRECTION_OUT == dir) { /* Get RX status register */ host_csr = HCD_RD2(r, MUSB_REG_HOST_TXCSR); @@ -860,7 +866,7 @@ musb_check_error(void * cfg, hcd_transfer transfer, hcd_direction dir) return EXIT_SUCCESS; } - if ((HCD_TRANSFER_BULK == transfer) && (HCD_DIRECTION_IN == dir)) { + if (HCD_DIRECTION_IN == dir) { /* Get RX status register */ host_csr = HCD_RD2(r, MUSB_REG_HOST_RXCSR); -- 2.44.0