Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/arduino/Arduino.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@arduino.cc>2017-01-04 20:40:13 +0300
committerCristian Maglie <c.maglie@bug.st>2017-03-16 20:35:47 +0300
commit3c0f26d6a89e249a16eb469774add5aa4487bb3f (patch)
tree9750dc4c5ea72a331247747444347fde98f2809b /hardware
parenta707f0ba4deb4e217a6a1dd8067f21692a2c9be7 (diff)
[AVR] USB send ZLP when needed
See #5732 #4864 #4138 #3946
Diffstat (limited to 'hardware')
-rw-r--r--hardware/arduino/avr/cores/arduino/USBCore.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp
index efac25ed6..e85c6131b 100644
--- a/hardware/arduino/avr/cores/arduino/USBCore.cpp
+++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp
@@ -273,7 +273,9 @@ int USB_Send(u8 ep, const void* d, int len)
int r = len;
const u8* data = (const u8*)d;
u8 timeout = 250; // 250ms timeout on send? TODO
- while (len)
+ bool sendZlp = false;
+
+ while (len || sendZlp)
{
u8 n = USB_SendSpace(ep);
if (n == 0)
@@ -284,13 +286,16 @@ int USB_Send(u8 ep, const void* d, int len)
continue;
}
- if (n > len)
+ if (n > len) {
n = len;
+ }
+
{
LockEP lock(ep);
// Frame may have been released by the SOF interrupt handler
if (!ReadWriteAllowed())
continue;
+
len -= n;
if (ep & TRANSFER_ZERO)
{
@@ -307,8 +312,17 @@ int USB_Send(u8 ep, const void* d, int len)
while (n--)
Send8(*data++);
}
- if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
+
+ if (sendZlp) {
+ ReleaseTX();
+ sendZlp = false;
+ } else if (!ReadWriteAllowed()) { // ...release if buffer is full...
ReleaseTX();
+ if (len == 0) sendZlp = true;
+ } else if ((len == 0) && (ep & TRANSFER_RELEASE)) { // ...or if forced with TRANSFER_RELEASE
+ // XXX: TRANSFER_RELEASE is never used can be removed?
+ ReleaseTX();
+ }
}
}
TXLED1; // light the TX LED
@@ -473,7 +487,7 @@ static
bool SendConfiguration(int maxlen)
{
// Count and measure interfaces
- InitControl(0);
+ InitControl(0);
u8 interfaces = SendInterfaces();
ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);