From b1ac5161757a2d97579a7a24507b87737c847d39 Mon Sep 17 00:00:00 2001
From: "Andrew J. Kroll"
Date: Thu, 22 May 2014 01:33:01 -0400
Subject: [PATCH 1/4] Better/smaller EndpointXtract method, Removes
buggy/unused/dead block of code.
---
masstorage.cpp | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/masstorage.cpp b/masstorage.cpp
index 19da7b19..90f76b3c 100644
--- a/masstorage.cpp
+++ b/masstorage.cpp
@@ -532,6 +532,20 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t
uint8_t index;
+#if 1
+ if((pep->bmAttributes & 0x02) == 2) {
+ index = ((pep->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex;
+ // Fill in the endpoint info structure
+ epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
+ epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
+ epInfo[index].epAttribs = 0;
+
+ bNumEP++;
+
+ PrintEndpointDescriptor(pep);
+
+ }
+#else
if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80)
index = epInterruptInIndex;
else
@@ -548,6 +562,7 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t
bNumEP++;
PrintEndpointDescriptor(pep);
+#endif
}
/**
From d56ed57495a9c8d01c4cd94653c5ea3d28ba60c6 Mon Sep 17 00:00:00 2001
From: "Andrew J. Kroll"
Date: Thu, 22 May 2014 23:36:33 -0400
Subject: [PATCH 2/4] Fix 1 month rollover bug -- Lei Shi found this one in one
place, I found the problem all over the library and patched them all.
---
BTD.cpp | 2 +-
Usb.cpp | 10 +-
Wii.cpp | 4 +-
examples/hub_demo/hub_demo.ino | 2 +-
examples/pl2303/pl2303_gps/pl2303_gps.ino | 109 ++++++------
examples/testusbhostFAT/testusbhostFAT.ino | 182 ++++++++++-----------
hidboot.h | 2 +-
hiduniversal.cpp | 2 +-
masstorage.cpp | 2 +-
usbhub.cpp | 2 +-
10 files changed, 155 insertions(+), 162 deletions(-)
diff --git a/BTD.cpp b/BTD.cpp
index 4de668d9..1812f391 100755
--- a/BTD.cpp
+++ b/BTD.cpp
@@ -371,7 +371,7 @@ uint8_t BTD::Release() {
uint8_t BTD::Poll() {
if(!bPollEnable)
return 0;
- if(qNextPollTime <= millis()) { // Don't poll if shorter than polling interval
+ if((long)(millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval
qNextPollTime = millis() + pollInterval; // Set new poll time
HCI_event_task(); // Poll the HCI event pipe
HCI_task(); // HCI state machine
diff --git a/Usb.cpp b/Usb.cpp
index e21ca1fe..d75149d8 100644
--- a/Usb.cpp
+++ b/Usb.cpp
@@ -327,7 +327,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
rcode = (regRd(rHRSL) & 0x0f);
- while(rcode && (timeout > millis())) {
+ while(rcode && ((long)(millis() - timeout) >= 0L)) {
switch(rcode) {
case hrNAK:
nak_count++;
@@ -380,11 +380,11 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
uint8_t retry_count = 0;
uint16_t nak_count = 0;
- while(timeout > millis()) {
+ while((long)(millis() - timeout) >= 0L) {
regWr(rHXFR, (token | ep)); //launch the transfer
rcode = USB_ERROR_TRANSFER_TIMEOUT;
- while(timeout > millis()) //wait for transfer completion
+ while((long)(millis() - timeout) >= 0L) //wait for transfer completion
{
tmpdata = regRd(rHIRQ);
@@ -475,7 +475,7 @@ void USB::Task(void) //USB state machine
case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
break;
case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device
- if(delay < millis())
+ if((long)(millis() - delay) >= 0L)
usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
else break; // don't fall through
case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
@@ -502,7 +502,7 @@ void USB::Task(void) //USB state machine
}
break;
case USB_ATTACHED_SUBSTATE_WAIT_RESET:
- if(delay < millis()) usb_task_state = USB_STATE_CONFIGURING;
+ if((long)(millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING;
else break; // don't fall through
case USB_STATE_CONFIGURING:
diff --git a/Wii.cpp b/Wii.cpp
index 62af423a..8106666b 100755
--- a/Wii.cpp
+++ b/Wii.cpp
@@ -657,7 +657,7 @@ void WII::L2CAP_task() {
/* The next states are in run() */
case L2CAP_INTERRUPT_DISCONNECT:
- if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && millis() > timer) {
+ if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((long)(millis() - timer) >= 0L)) {
#ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
#endif
@@ -682,7 +682,7 @@ void WII::L2CAP_task() {
}
void WII::Run() {
- if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && millis() > timer)
+ if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((long)(millis() - timer) >= 0L))
L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough
switch(l2cap_state) {
diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino
index 466ae4d7..bede0f4b 100644
--- a/examples/hub_demo/hub_demo.ino
+++ b/examples/hub_demo/hub_demo.ino
@@ -97,7 +97,7 @@ void loop()
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
- if (millis() >= next_time)
+ if ((next_time - millis()) >= 0L)
{
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses);
diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino
index 9f33766a..908763c4 100644
--- a/examples/pl2303/pl2303_gps/pl2303_gps.ino
+++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino
@@ -10,80 +10,75 @@
#include
#endif
-class PLAsyncOper : public CDCAsyncOper
-{
+class PLAsyncOper : public CDCAsyncOper {
public:
- virtual uint8_t OnInit(ACM *pacm);
+ virtual uint8_t OnInit(ACM *pacm);
};
-uint8_t PLAsyncOper::OnInit(ACM *pacm)
-{
- uint8_t rcode;
+uint8_t PLAsyncOper::OnInit(ACM *pacm) {
+ uint8_t rcode;
- // Set DTR = 1
- rcode = pacm->SetControlLineState(1);
+ // Set DTR = 1
+ rcode = pacm->SetControlLineState(1);
+
+ if(rcode) {
+ ErrorMessage(PSTR("SetControlLineState"), rcode);
+ return rcode;
+ }
+
+ LINE_CODING lc;
+ lc.dwDTERate = 4800; //default serial speed of GPS unit
+ lc.bCharFormat = 0;
+ lc.bParityType = 0;
+ lc.bDataBits = 8;
+
+ rcode = pacm->SetLineCoding(&lc);
+
+ if(rcode)
+ ErrorMessage(PSTR("SetLineCoding"), rcode);
- if (rcode)
- {
- ErrorMessage(PSTR("SetControlLineState"), rcode);
return rcode;
- }
-
- LINE_CODING lc;
- lc.dwDTERate = 4800; //default serial speed of GPS unit
- lc.bCharFormat = 0;
- lc.bParityType = 0;
- lc.bDataBits = 8;
-
- rcode = pacm->SetLineCoding(&lc);
-
- if (rcode)
- ErrorMessage(PSTR("SetLineCoding"), rcode);
-
- return rcode;
}
-USB Usb;
-USBHub Hub(&Usb);
-PLAsyncOper AsyncOper;
-PL2303 Pl(&Usb, &AsyncOper);
+USB Usb;
+USBHub Hub(&Usb);
+PLAsyncOper AsyncOper;
+PL2303 Pl(&Usb, &AsyncOper);
uint32_t read_delay;
#define READ_DELAY 100
-void setup()
-{
- Serial.begin( 115200 );
- while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
- Serial.println("Start");
+void setup() {
+ Serial.begin(115200);
+ while(!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+ Serial.println("Start");
- if (Usb.Init() == -1)
- Serial.println("OSCOKIRQ failed to assert");
+ if(Usb.Init() == -1)
+ Serial.println("OSCOKIRQ failed to assert");
- delay( 200 );
+ delay(200);
}
-void loop()
-{
-uint8_t rcode;
-uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
-uint16_t rcvd = 64;
+void loop() {
+ uint8_t rcode;
+ uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
+ uint16_t rcvd = 64;
- Usb.Task();
+ Usb.Task();
- if( Pl.isReady()) {
- /* reading the GPS */
- if( read_delay < millis() ){
- read_delay += READ_DELAY;
- rcode = Pl.RcvData(&rcvd, buf);
- if ( rcode && rcode != hrNAK )
- ErrorMessage(PSTR("Ret"), rcode);
- if( rcvd ) { //more than zero bytes received
- for( uint16_t i=0; i < rcvd; i++ ) {
- Serial.print((char)buf[i]); //printing on the screen
- }//for( uint16_t i=0; i < rcvd; i++...
- }//if( rcvd
- }//if( read_delay > millis()...
- }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
+ if(Pl.isReady()) {
+ /* reading the GPS */
+ if((long)(millis() - read_delay) >= 0L) {
+ read_delay += READ_DELAY;
+ rcode = Pl.RcvData(&rcvd, buf);
+ if(rcode && rcode != hrNAK)
+ ErrorMessage(PSTR("Ret"), rcode);
+ if(rcvd) { //more than zero bytes received
+ for(uint16_t i = 0; i < rcvd; i++) {
+ Serial.print((char)buf[i]); //printing on the screen
+ }//for( uint16_t i=0; i < rcvd; i++...
+ }//if( rcvd
+ }//if( read_delay > millis()...
+ }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}
diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino
index f316a49b..c7110632 100644
--- a/examples/testusbhostFAT/testusbhostFAT.ino
+++ b/examples/testusbhostFAT/testusbhostFAT.ino
@@ -126,7 +126,7 @@ static int tty_std_putc(char c, FILE *t) {
}
static int tty_std_getc(FILE *t) {
- while (!Serial.available());
+ while(!Serial.available());
return Serial.read();
}
@@ -140,18 +140,18 @@ extern "C" {
int _write(int fd, const char *ptr, int len) {
int j;
- for (j = 0; j < len; j++) {
- if (fd == 1)
+ for(j = 0; j < len; j++) {
+ if(fd == 1)
Serial.write(*ptr++);
- else if (fd == 2)
+ else if(fd == 2)
USB_HOST_SERIAL.write(*ptr++);
}
return len;
}
int _read(int fd, char *ptr, int len) {
- if (len > 0 && fd == 0) {
- while (!Serial.available());
+ if(len > 0 && fd == 0) {
+ while(!Serial.available());
*ptr = Serial.read();
return 1;
}
@@ -175,7 +175,7 @@ extern "C" {
void setup() {
boolean serr = false;
- for (int i = 0; i < _VOLUMES; i++) {
+ for(int i = 0; i < _VOLUMES; i++) {
Fats[i] = NULL;
sto[i].private_data = new pvt_t;
((pvt_t *)sto[i].private_data)->B = 255; // impossible
@@ -193,7 +193,7 @@ void setup() {
// Initialize 'debug' serial port
USB_HOST_SERIAL.begin(115200);
// Do not start primary Serial port if already started.
- if (bit_is_clear(UCSR0B, TXEN0)) {
+ if(bit_is_clear(UCSR0B, TXEN0)) {
Serial.begin(115200);
serr = true;
}
@@ -220,7 +220,7 @@ void setup() {
analogWrite(LED_BUILTIN, 0);
delay(500);
#else
- while (!Serial);
+ while(!Serial);
#endif
printf_P(PSTR("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStart\r\n"));
@@ -236,7 +236,7 @@ void setup() {
"Disabled"
#endif
"\r\n"));
- if (serr) {
+ if(serr) {
fprintf_P(stderr, PSTR("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStart\r\n"));
fprintf_P(stderr, PSTR("Current UsbDEBUGlvl %02x\r\n"), UsbDEBUGlvl);
fprintf_P(stderr, PSTR("Long filename support: "
@@ -274,7 +274,7 @@ void setup() {
// I want to be able to have slightly more control.
// Besides, it is easier to initialize stuff...
#if WANT_HUB_TEST
- for (int i = 0; i < MAX_HUBS; i++) {
+ for(int i = 0; i < MAX_HUBS; i++) {
Hubs[i] = new USBHub(&Usb);
#if defined(AVR)
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
@@ -284,7 +284,7 @@ void setup() {
// Initialize generic storage. This must be done before USB starts.
InitStorage();
- while (Usb.Init(1000) == -1) {
+ while(Usb.Init(1000) == -1) {
printf_P(PSTR("No USB HOST Shield?\r\n"));
Notify(PSTR("OSC did not start."), 0x40);
}
@@ -316,7 +316,7 @@ void setup() {
//printf("SPI_CTAR0 = %8.8X\r\n", ctar);
uint32_t mcr = SPI0_MCR;
- if (mcr & SPI_MCR_MDIS) {
+ if(mcr & SPI_MCR_MDIS) {
SPI0_CTAR0 = ctar;
} else {
SPI0_MCR = mcr | SPI_MCR_MDIS | SPI_MCR_HALT;
@@ -334,23 +334,23 @@ void serialEvent() {
// . to increase by 16, , to decrease by 16
// e to flick VBUS
// * to report debug level
- if (Serial.available()) {
+ if(Serial.available()) {
int inByte = Serial.read();
- switch (inByte) {
+ switch(inByte) {
case '+':
- if (UsbDEBUGlvl < 0xff) UsbDEBUGlvl++;
+ if(UsbDEBUGlvl < 0xff) UsbDEBUGlvl++;
reportlvl = true;
break;
case '-':
- if (UsbDEBUGlvl > 0x00) UsbDEBUGlvl--;
+ if(UsbDEBUGlvl > 0x00) UsbDEBUGlvl--;
reportlvl = true;
break;
case '.':
- if (UsbDEBUGlvl < 0xf0) UsbDEBUGlvl += 16;
+ if(UsbDEBUGlvl < 0xf0) UsbDEBUGlvl += 16;
reportlvl = true;
break;
case ',':
- if (UsbDEBUGlvl > 0x0f) UsbDEBUGlvl -= 16;
+ if(UsbDEBUGlvl > 0x0f) UsbDEBUGlvl -= 16;
reportlvl = true;
break;
case '*':
@@ -370,7 +370,7 @@ void serialEvent() {
#if defined(AVR)
ISR(TIMER3_COMPA_vect) {
- if (millis() >= LEDnext_time) {
+ if(millis() >= LEDnext_time) {
LEDnext_time = millis() + 30;
// set the brightness of LED
@@ -380,11 +380,11 @@ ISR(TIMER3_COMPA_vect) {
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
- if (brightness <= 0) {
+ if(brightness <= 0) {
brightness = 0;
fadeAmount = -fadeAmount;
}
- if (brightness >= 255) {
+ if(brightness >= 255) {
brightness = 255;
fadeAmount = -fadeAmount;
}
@@ -406,8 +406,8 @@ void loop() {
#if defined(AVR)
// Print a heap status report about every 10 seconds.
- if (millis() >= HEAPnext_time) {
- if (UsbDEBUGlvl > 0x50) {
+ if(millis() >= HEAPnext_time) {
+ if(UsbDEBUGlvl > 0x50) {
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
}
HEAPnext_time = millis() + 10000;
@@ -419,14 +419,14 @@ void loop() {
#endif
// Horrid! This sort of thing really belongs in an ISR, not here!
// We also will be needing to test each hub port, we don't do this yet!
- if (!change && !usbon && millis() >= usbon_time) {
+ if(!change && !usbon && millis() >= usbon_time) {
change = true;
usbon = true;
}
- if (change) {
+ if(change) {
change = false;
- if (usbon) {
+ if(usbon) {
Usb.vbusPower(vbus_on);
printf_P(PSTR("VBUS on\r\n"));
} else {
@@ -436,21 +436,21 @@ void loop() {
}
Usb.Task();
current_state = Usb.getUsbTaskState();
- if (current_state != last_state) {
- if (UsbDEBUGlvl > 0x50)
+ if(current_state != last_state) {
+ if(UsbDEBUGlvl > 0x50)
printf_P(PSTR("USB state = %x\r\n"), current_state);
#if defined(AVR)
- if (current_state == USB_STATE_RUNNING) {
+ if(current_state == USB_STATE_RUNNING) {
fadeAmount = 30;
}
#endif
- if (current_state == USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE) {
+ if(current_state == USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE) {
#if defined(AVR)
fadeAmount = 80;
#endif
partsready = false;
- for (int i = 0; i < cpart; i++) {
- if (Fats[i] != NULL)
+ for(int i = 0; i < cpart; i++) {
+ if(Fats[i] != NULL)
delete Fats[i];
Fats[i] = NULL;
}
@@ -462,28 +462,27 @@ void loop() {
}
// only do any of this if usb is on
- if (usbon) {
- if (partsready && !fatready) {
- if (cpart > 0) fatready = true;
+ if(usbon) {
+ if(partsready && !fatready) {
+ if(cpart > 0) fatready = true;
}
// This is horrible, and needs to be moved elsewhere!
- for (int B = 0; B < MAX_USB_MS_DRIVERS; B++) {
- if (!partsready && (Bulk[B]->GetAddress() != NULL)) {
+ for(int B = 0; B < MAX_USB_MS_DRIVERS; B++) {
+ if(!partsready && (Bulk[B]->GetAddress() != NULL)) {
// Build a list.
int ML = Bulk[B]->GetbMaxLUN();
//printf("MAXLUN = %i\r\n", ML);
ML++;
- for (int i = 0; i < ML; i++) {
- if (Bulk[B]->LUNIsGood(i)) {
+ for(int i = 0; i < ML; i++) {
+ if(Bulk[B]->LUNIsGood(i)) {
partsready = true;
((pvt_t *)(sto[i].private_data))->lun = i;
((pvt_t *)(sto[i].private_data))->B = B;
- sto[i].Read = *PRead;
- sto[i].Write = *PWrite;
sto[i].Reads = *PReads;
sto[i].Writes = *PWrites;
sto[i].Status = *PStatus;
+ sto[i].Commit = *UHS_USB_BulkOnly_Commit;
sto[i].TotalSectors = Bulk[B]->GetCapacity(i);
sto[i].SectorSize = Bulk[B]->GetSectorSize(i);
printf_P(PSTR("LUN:\t\t%u\r\n"), i);
@@ -492,18 +491,18 @@ void loop() {
// get the partition data...
PT = new PCPartition;
- if (!PT->Init(&sto[i])) {
+ if(!PT->Init(&sto[i])) {
part_t *apart;
- for (int j = 0; j < 4; j++) {
+ for(int j = 0; j < 4; j++) {
apart = PT->GetPart(j);
- if (apart != NULL && apart->type != 0x00) {
+ if(apart != NULL && apart->type != 0x00) {
memcpy(&(parts[cpart]), apart, sizeof (part_t));
printf_P(PSTR("Partition %u type %#02x\r\n"), j, parts[cpart].type);
// for now
- if (isfat(parts[cpart].type)) {
+ if(isfat(parts[cpart].type)) {
Fats[cpart] = new PFAT(&sto[i], cpart, parts[cpart].firstSector);
//int r = Fats[cpart]->Good();
- if (Fats[cpart]->MountStatus()) {
+ if(Fats[cpart]->MountStatus()) {
delete Fats[cpart];
Fats[cpart] = NULL;
} else cpart++;
@@ -514,7 +513,7 @@ void loop() {
// try superblock
Fats[cpart] = new PFAT(&sto[i], cpart, 0);
//int r = Fats[cpart]->Good();
- if (Fats[cpart]->MountStatus()) {
+ if(Fats[cpart]->MountStatus()) {
//printf_P(PSTR("Superblock error %x\r\n"), r);
delete Fats[cpart];
Fats[cpart] = NULL;
@@ -535,18 +534,18 @@ void loop() {
}
}
- if (fatready) {
- if (Fats[0] != NULL) {
+ if(fatready) {
+ if(Fats[0] != NULL) {
struct Pvt * p;
p = ((struct Pvt *)(Fats[0]->storage->private_data));
- if (!Bulk[p->B]->LUNIsGood(p->lun)) {
+ if(!Bulk[p->B]->LUNIsGood(p->lun)) {
// media change
#if defined(AVR)
fadeAmount = 80;
#endif
partsready = false;
- for (int i = 0; i < cpart; i++) {
- if (Fats[i] != NULL)
+ for(int i = 0; i < cpart; i++) {
+ if(Fats[i] != NULL)
delete Fats[i];
Fats[cpart] = NULL;
}
@@ -557,62 +556,61 @@ void loop() {
}
}
- if (fatready) {
+ if(fatready) {
FRESULT rc; /* Result code */
UINT bw, br, i;
- if (!notified) {
+ if(!notified) {
#if defined(AVR)
fadeAmount = 5;
#endif
notified = true;
printf_P(PSTR("\r\nOpen an existing file (message.txt).\r\n"));
rc = f_open(&My_File_Object_x, "0:/MESSAGE.TXT", FA_READ);
- if (rc) printf_P(PSTR("Error %i, message.txt not found.\r\n"), rc);
+ if(rc) printf_P(PSTR("Error %i, message.txt not found.\r\n"), rc);
else {
printf_P(PSTR("\r\nType the file content.\r\n"));
- for (;;) {
+ for(;;) {
rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &br); /* Read a chunk of file */
- if (rc || !br) break; /* Error or end of file */
- for (i = 0; i < br; i++) {
+ if(rc || !br) break; /* Error or end of file */
+ for(i = 0; i < br; i++) {
/* Type the data */
- if (My_Buff_x[i] == '\n')
+ if(My_Buff_x[i] == '\n')
Serial.write('\r');
- if (My_Buff_x[i] != '\r')
+ if(My_Buff_x[i] != '\r')
Serial.write(My_Buff_x[i]);
Serial.flush();
}
}
- if (rc) {
+ if(rc) {
f_close(&My_File_Object_x);
goto out;
}
printf_P(PSTR("\r\nClose the file.\r\n"));
rc = f_close(&My_File_Object_x);
- if (rc) goto out;
+ if(rc) goto out;
}
printf_P(PSTR("\r\nCreate a new file (hello.txt).\r\n"));
rc = f_open(&My_File_Object_x, "0:/Hello.TxT", FA_WRITE | FA_CREATE_ALWAYS);
- if (rc) {
+ if(rc) {
die(rc);
goto outdir;
}
printf_P(PSTR("\r\nWrite a text data. (Hello world!)\r\n"));
rc = f_write(&My_File_Object_x, "Hello world!\r\n", 14, &bw);
- if (rc) {
+ if(rc) {
goto out;
}
printf_P(PSTR("%u bytes written.\r\n"), bw);
printf_P(PSTR("\r\nClose the file.\r\n"));
rc = f_close(&My_File_Object_x);
- if (rc) {
+ if(rc) {
die(rc);
goto out;
}
-outdir:
- {
+outdir:{
#if _USE_LFN
char lfn[_MAX_LFN + 1];
FILINFO My_File_Info_Object_x; /* File information object */
@@ -621,7 +619,7 @@ outdir:
DIR My_Dir_Object_x; /* Directory object */
printf_P(PSTR("\r\nOpen root directory.\r\n"));
rc = f_opendir(&My_Dir_Object_x, "0:/");
- if (rc) {
+ if(rc) {
die(rc);
goto out;
}
@@ -630,46 +628,46 @@ outdir:
#if defined(AVR)
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
#endif
- for (;;) {
+ for(;;) {
#if _USE_LFN
My_File_Info_Object_x.lfsize = _MAX_LFN;
#endif
rc = f_readdir(&My_Dir_Object_x, &My_File_Info_Object_x); /* Read a directory item */
- if (rc || !My_File_Info_Object_x.fname[0]) break; /* Error or end of dir */
+ if(rc || !My_File_Info_Object_x.fname[0]) break; /* Error or end of dir */
- if (My_File_Info_Object_x.fattrib & AM_DIR) {
+ if(My_File_Info_Object_x.fattrib & AM_DIR) {
Serial.write('d');
} else {
Serial.write('-');
}
Serial.write('r');
- if (My_File_Info_Object_x.fattrib & AM_RDO) {
+ if(My_File_Info_Object_x.fattrib & AM_RDO) {
Serial.write('-');
} else {
Serial.write('w');
}
- if (My_File_Info_Object_x.fattrib & AM_HID) {
+ if(My_File_Info_Object_x.fattrib & AM_HID) {
Serial.write('h');
} else {
Serial.write('-');
}
- if (My_File_Info_Object_x.fattrib & AM_SYS) {
+ if(My_File_Info_Object_x.fattrib & AM_SYS) {
Serial.write('s');
} else {
Serial.write('-');
}
- if (My_File_Info_Object_x.fattrib & AM_ARC) {
+ if(My_File_Info_Object_x.fattrib & AM_ARC) {
Serial.write('a');
} else {
Serial.write('-');
}
#if _USE_LFN
- if (*My_File_Info_Object_x.lfname)
+ if(*My_File_Info_Object_x.lfname)
printf_P(PSTR(" %8lu %s (%s)\r\n"), My_File_Info_Object_x.fsize, My_File_Info_Object_x.fname, My_File_Info_Object_x.lfname);
else
#endif
@@ -677,48 +675,48 @@ outdir:
}
}
out:
- if (rc) die(rc);
+ if(rc) die(rc);
printf_P(PSTR("\r\nTest completed.\r\n"));
}
- if (runtest) {
+ if(runtest) {
ULONG ii, wt, rt, start, end;
runtest = false;
f_unlink("0:/10MB.bin");
printf_P(PSTR("\r\nCreate a new 10MB test file (10MB.bin).\r\n"));
rc = f_open(&My_File_Object_x, "0:/10MB.bin", FA_WRITE | FA_CREATE_ALWAYS);
- if (rc) goto failed;
- for (bw = 0; bw < mbxs; bw++) My_Buff_x[bw] = bw & 0xff;
+ if(rc) goto failed;
+ for(bw = 0; bw < mbxs; bw++) My_Buff_x[bw] = bw & 0xff;
fflush(stdout);
start = millis();
- while (start == millis());
- for (ii = 10485760LU / mbxs; ii > 0LU; ii--) {
+ while(start == millis());
+ for(ii = 10485760LU / mbxs; ii > 0LU; ii--) {
rc = f_write(&My_File_Object_x, My_Buff_x, mbxs, &bw);
- if (rc || !bw) goto failed;
+ if(rc || !bw) goto failed;
}
rc = f_close(&My_File_Object_x);
- if (rc) goto failed;
+ if(rc) goto failed;
end = millis();
wt = (end - start) - 1;
printf_P(PSTR("Time to write 10485760 bytes: %lu ms (%lu sec) \r\n"), wt, (500 + wt) / 1000UL);
rc = f_open(&My_File_Object_x, "0:/10MB.bin", FA_READ);
fflush(stdout);
start = millis();
- while (start == millis());
- if (rc) goto failed;
- for (;;) {
+ while(start == millis());
+ if(rc) goto failed;
+ for(;;) {
rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &bw); /* Read a chunk of file */
- if (rc || !bw) break; /* Error or end of file */
+ if(rc || !bw) break; /* Error or end of file */
}
end = millis();
- if (rc) goto failed;
+ if(rc) goto failed;
rc = f_close(&My_File_Object_x);
- if (rc) goto failed;
+ if(rc) goto failed;
rt = (end - start) - 1;
printf_P(PSTR("Time to read 10485760 bytes: %lu ms (%lu sec)\r\nDelete test file\r\n"), rt, (500 + rt) / 1000UL);
failed:
- if (rc) die(rc);
+ if(rc) die(rc);
printf_P(PSTR("10MB timing test finished.\r\n"));
}
}
diff --git a/hidboot.h b/hidboot.h
index 2218eb9e..0326bf25 100644
--- a/hidboot.h
+++ b/hidboot.h
@@ -536,7 +536,7 @@ template
uint8_t HIDBoot::Poll() {
uint8_t rcode = 0;
- if(bPollEnable && qNextPollTime <= millis()) {
+ if(bPollEnable && ((long)(millis() - qNextPollTime) >= 0L)) {
// To-do: optimize manually, using the for loop only if needed.
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
diff --git a/hiduniversal.cpp b/hiduniversal.cpp
index c2f33533..acc1b00c 100644
--- a/hiduniversal.cpp
+++ b/hiduniversal.cpp
@@ -370,7 +370,7 @@ uint8_t HIDUniversal::Poll() {
if(!bPollEnable)
return 0;
- if(qNextPollTime <= millis()) {
+ if((long)(millis() - qNextPollTime) >= 0L) {
qNextPollTime = millis() + pollInterval;
uint8_t buf[constBuffLen];
diff --git a/masstorage.cpp b/masstorage.cpp
index 3c014f89..ab9ad4ff 100644
--- a/masstorage.cpp
+++ b/masstorage.cpp
@@ -671,7 +671,7 @@ uint8_t BulkOnly::Poll() {
if(!bPollEnable)
return 0;
- if(qNextPollTime <= millis()) {
+ if((long)(millis() - qNextPollTime) >= 0L) {
CheckMedia();
}
//rcode = 0;
diff --git a/usbhub.cpp b/usbhub.cpp
index 82fc30f5..a3ab21eb 100644
--- a/usbhub.cpp
+++ b/usbhub.cpp
@@ -230,7 +230,7 @@ uint8_t USBHub::Poll() {
if(!bPollEnable)
return 0;
- if(qNextPollTime <= millis()) {
+ if(((long)(millis() - qNextPollTime) >= 0L)) {
rcode = CheckHubStatus();
qNextPollTime = millis() + 100;
}
From a50baa8aecdc62fe23f212e92a2f29e75fe6cf74 Mon Sep 17 00:00:00 2001
From: "Andrew J. Kroll"
Date: Fri, 23 May 2014 00:12:55 -0400
Subject: [PATCH 3/4] Merge in masters
---
examples/testusbhostFAT/Arduino_Makefile_master | 2 +-
examples/testusbhostFAT/RTClib | 2 +-
examples/testusbhostFAT/generic_storage | 2 +-
examples/testusbhostFAT/xmem2 | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master
index 1cacea4e..d35bb955 160000
--- a/examples/testusbhostFAT/Arduino_Makefile_master
+++ b/examples/testusbhostFAT/Arduino_Makefile_master
@@ -1 +1 @@
-Subproject commit 1cacea4e8933b37b9f98528b2a831031f69905de
+Subproject commit d35bb955e3818f0c14e47c8a1998003da8dc1b5a
diff --git a/examples/testusbhostFAT/RTClib b/examples/testusbhostFAT/RTClib
index 9108effe..7fd6a306 160000
--- a/examples/testusbhostFAT/RTClib
+++ b/examples/testusbhostFAT/RTClib
@@ -1 +1 @@
-Subproject commit 9108effe4d4e556198e3e7b95365d1c898680dae
+Subproject commit 7fd6a306ca53d08bf53b2bbfc1b80eb056f2c55b
diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage
index ab85718a..0b8e3076 160000
--- a/examples/testusbhostFAT/generic_storage
+++ b/examples/testusbhostFAT/generic_storage
@@ -1 +1 @@
-Subproject commit ab85718a917094391762b79140d8e3a03af136a4
+Subproject commit 0b8e3076b5a072251e01cfc6e6333b364d4e71e7
diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2
index dd85091a..2bf8f633 160000
--- a/examples/testusbhostFAT/xmem2
+++ b/examples/testusbhostFAT/xmem2
@@ -1 +1 @@
-Subproject commit dd85091abaca7cc6055ff515a5e42f32198380d2
+Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e
From f6244bbe59c46a176251125f07bca1b92daf4d6a Mon Sep 17 00:00:00 2001
From: "Andrew J. Kroll"
Date: Sat, 24 May 2014 00:31:26 -0400
Subject: [PATCH 4/4] bugfix
---
Usb.cpp | 6 +++---
examples/hub_demo/hub_demo.ino | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/Usb.cpp b/Usb.cpp
index d75149d8..ca81cf99 100644
--- a/Usb.cpp
+++ b/Usb.cpp
@@ -327,7 +327,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
rcode = (regRd(rHRSL) & 0x0f);
- while(rcode && ((long)(millis() - timeout) >= 0L)) {
+ while(rcode && ((long)(millis() - timeout) < 0L)) {
switch(rcode) {
case hrNAK:
nak_count++;
@@ -380,11 +380,11 @@ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) {
uint8_t retry_count = 0;
uint16_t nak_count = 0;
- while((long)(millis() - timeout) >= 0L) {
+ while((long)(millis() - timeout) < 0L) {
regWr(rHXFR, (token | ep)); //launch the transfer
rcode = USB_ERROR_TRANSFER_TIMEOUT;
- while((long)(millis() - timeout) >= 0L) //wait for transfer completion
+ while((long)(millis() - timeout) < 0L) //wait for transfer completion
{
tmpdata = regRd(rHIRQ);
diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino
index bede0f4b..329c6230 100644
--- a/examples/hub_demo/hub_demo.ino
+++ b/examples/hub_demo/hub_demo.ino
@@ -97,7 +97,7 @@ void loop()
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
{
- if ((next_time - millis()) >= 0L)
+ if ((millis() - next_time) >= 0L)
{
Usb.ForEachUsbDevice(&PrintAllDescriptors);
Usb.ForEachUsbDevice(&PrintAllAddresses);