USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
Diff: USBHost/USBHost.cpp
- Revision:
- 16:981c3104f6c0
- Parent:
- 12:b91fdea8c0a7
- Child:
- 18:61554f238584
--- a/USBHost/USBHost.cpp Fri Jun 13 01:52:44 2014 +0000 +++ b/USBHost/USBHost.cpp Mon Jun 23 20:30:04 2014 +0900 @@ -1,6 +1,4 @@ -// Simple USBHost for FRDM-KL46Z #include "USBHost.h" -#include <algorithm> USBHost* USBHost::inst = NULL; @@ -252,22 +250,12 @@ USB_DBG("setup %02x", LastStatus); return -1; } - int read_len = 0; - while(read_len < size) { - int size2 = std::min(size-read_len, ep->getSize()); - int result = token_in(ep, data+read_len, size2); - //USB_DBG("token_in result=%d %02x", result, LastStatus); - if (result < 0) { - USB_DBG("token_in %d/%d %02x", read_len, size, LastStatus); - return result; - } - read_len += result; - if (result < ep->getSize()) { - break; - } - } + int read_len = multi_token_in(ep, data, size); + if (read_len < 0) { + return -1; + } ep->setData01(DATA1); - int result = token_out(ep); // status stage + int result = multi_token_out(ep); // status stage if (result < 0) { USB_DBG("status token_out %02x", LastStatus); if (LastStatus == STALL) { @@ -292,13 +280,13 @@ } int write_len = 0; if (data != NULL) { - write_len = token_out(ep, data, size); + write_len = multi_token_out(ep, data, size); if (write_len < 0) { return -1; } } ep->setData01(DATA1); - int result = token_in(ep); // status stage + int result = multi_token_in(ep); // status stage if (result < 0) { USB_DBG("result=%d %02x", result, LastStatus); //return result; @@ -314,25 +302,10 @@ USB_TEST_ASSERT(dev); setAddr(dev->getAddress(), dev->getSpeed()); setEndpoint(); - const int retryLimit = 0; - int read_len = 0; - for(int n = 0; read_len < size; n++) { - int size2 = std::min(size-read_len, ep->getSize()); - int result = token_in(ep, data+read_len, size2, retryLimit); - if (result < 0) { - if (LastStatus == NAK) { - if (n == 0) { - return -1; - } - break; - } - //USB_DBG("token_in result=%d %02x", result, LastStatus); - return result; - } - read_len += result; - if (result < ep->getSize()) { - break; - } + const bool block = false; + int read_len = multi_token_in(ep, data, size, block); + if (read_len < 0) { + return -1; } ep->setLengthTransferred(read_len); return read_len; @@ -345,25 +318,10 @@ USB_TEST_ASSERT(dev); setAddr(dev->getAddress(), dev->getSpeed()); setEndpoint(); - const int retryLimit = 0; - int transferred_len = 0; - for(int n = 0; transferred_len < size; n++) { - int size2 = std::min(size-transferred_len, ep->getSize()); - int result = token_out(ep, data+transferred_len, size2, retryLimit); - if (result < 0) { - if (LastStatus == NAK) { - if (n == 0) { - return -1; - } - break; - } - //USB_DBG("token_in result=%d %02x", result, LastStatus); - return result; - } - transferred_len += result; - if (result < ep->getSize()) { - break; - } + const bool block = true; + int transferred_len = multi_token_out(ep, data, size, block); + if (transferred_len < 0) { + return -1; } ep->setLengthTransferred(transferred_len); return transferred_len; @@ -380,30 +338,10 @@ USB_TEST_ASSERT(dev); setAddr(dev->getAddress()); setEndpoint(); - int retryLimit = (timeout_ms == 0) ? 0 : 10; - int read_len = 0; - Timer t; - for(int n = 0; read_len < size; n++) { - int size2 = std::min(size-read_len, ep->getSize()); - int result = token_in(ep, data+read_len, size2, retryLimit); - if (result < 0) { - if (LastStatus == NAK) { - if (n == 0) { - return -1; - } - break; - } - //USB_DBG("token_in result=%d %02x", result, LastStatus); - return result; - } - read_len += result; - if (result < ep->getSize()) { - break; - } - if (timeout_ms > 0 && t.read_ms() > timeout_ms) { - USB_DBG("timeout_ms: %d", timeout_ms); - break; - } + bool block = (timeout_ms != 0); + int read_len = multi_token_in(ep, data, size, block); + if (read_len < 0) { + return -1; } ep->setLengthTransferred(read_len); return read_len; @@ -415,24 +353,9 @@ USB_TEST_ASSERT(dev); setAddr(dev->getAddress()); setEndpoint(); - int write_len = 0; - for(int n = 0; write_len < size; n++) { - int size2 = std::min(size-write_len, ep->getSize()); - int result = token_out(ep, data+write_len, size2); - if (result < 0) { - if (LastStatus == NAK) { - if (n == 0) { - return -1; - } - break; - } - USB_DBG("token_out result=%d %02x", result, LastStatus); - return result; - } - write_len += result; - if (result < ep->getSize()) { - break; - } + int write_len = multi_token_out(ep, data, size); + if (write_len < 0) { + return -1; } ep->setLengthTransferred(write_len); return write_len;