Potential fix for 0-length usb packets seen on OSX

This commit is contained in:
Martin Holst Swende 2015-07-17 00:01:58 +02:00
parent 976627d5ba
commit 83f3f8ac40
3 changed files with 18 additions and 5 deletions

View file

@ -399,14 +399,10 @@ void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
#define OPEN_COIL() HIGH(GPIO_SSC_DOUT)
i = 0;
byte_t rx[sizeof(UsbCommand)]; // Storage for usb_read call in loop
for(;;) {
//wait until SSC_CLK goes HIGH
while(!(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_CLK)) {
// Craig Young - Adding a usb_read() here to avoid abort on empty UsbCommand
// My OS X client does this preventing simulation.
// Performance hit should be non-existent since the read is only performed if usb_poll is true
if(BUTTON_PRESS() || (usb_poll() && usb_read(rx,sizeof(UsbCommand)))) {
if(BUTTON_PRESS() || (usb_poll_validate_length() )) {
DbpString("Stopped");
return;
}

View file

@ -293,6 +293,22 @@ bool usb_poll()
return (pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank);
}
/**
In github PR #129, some users appears to get a false positive from
usb_poll, which returns true, but the usb_read operation
still returns 0.
This check is basically the same as above, but also checks
that the length available to read is non-zero, thus hopefully fixes the
bug.
**/
bool usb_poll_validate_length()
{
if (!usb_check()) return false;
if (!(pUdp->UDP_CSR[AT91C_EP_OUT] & btReceiveBank)) return false;
return (pUdp->UDP_CSR[AT91C_EP_OUT] >> 16) > 0;
}
//*----------------------------------------------------------------------------
//* \fn usb_read
//* \brief Read available data from Endpoint OUT

View file

@ -41,6 +41,7 @@ void usb_disable();
void usb_enable();
bool usb_check();
bool usb_poll();
bool usb_poll_validate_length();
uint32_t usb_read(byte_t* data, size_t len);
uint32_t usb_write(const byte_t* data, const size_t len);