mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
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.
This commit is contained in:
parent
0acad810b2
commit
d56ed57495
10 changed files with 155 additions and 162 deletions
2
BTD.cpp
2
BTD.cpp
|
@ -371,7 +371,7 @@ uint8_t BTD::Release() {
|
||||||
uint8_t BTD::Poll() {
|
uint8_t BTD::Poll() {
|
||||||
if(!bPollEnable)
|
if(!bPollEnable)
|
||||||
return 0;
|
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
|
qNextPollTime = millis() + pollInterval; // Set new poll time
|
||||||
HCI_event_task(); // Poll the HCI event pipe
|
HCI_event_task(); // Poll the HCI event pipe
|
||||||
HCI_task(); // HCI state machine
|
HCI_task(); // HCI state machine
|
||||||
|
|
10
Usb.cpp
10
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
|
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
|
||||||
rcode = (regRd(rHRSL) & 0x0f);
|
rcode = (regRd(rHRSL) & 0x0f);
|
||||||
|
|
||||||
while(rcode && (timeout > millis())) {
|
while(rcode && ((long)(millis() - timeout) >= 0L)) {
|
||||||
switch(rcode) {
|
switch(rcode) {
|
||||||
case hrNAK:
|
case hrNAK:
|
||||||
nak_count++;
|
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;
|
uint8_t retry_count = 0;
|
||||||
uint16_t nak_count = 0;
|
uint16_t nak_count = 0;
|
||||||
|
|
||||||
while(timeout > millis()) {
|
while((long)(millis() - timeout) >= 0L) {
|
||||||
regWr(rHXFR, (token | ep)); //launch the transfer
|
regWr(rHXFR, (token | ep)); //launch the transfer
|
||||||
rcode = USB_ERROR_TRANSFER_TIMEOUT;
|
rcode = USB_ERROR_TRANSFER_TIMEOUT;
|
||||||
|
|
||||||
while(timeout > millis()) //wait for transfer completion
|
while((long)(millis() - timeout) >= 0L) //wait for transfer completion
|
||||||
{
|
{
|
||||||
tmpdata = regRd(rHIRQ);
|
tmpdata = regRd(rHIRQ);
|
||||||
|
|
||||||
|
@ -475,7 +475,7 @@ void USB::Task(void) //USB state machine
|
||||||
case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
|
case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here
|
||||||
break;
|
break;
|
||||||
case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device
|
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;
|
usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE;
|
||||||
else break; // don't fall through
|
else break; // don't fall through
|
||||||
case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
|
case USB_ATTACHED_SUBSTATE_RESET_DEVICE:
|
||||||
|
@ -502,7 +502,7 @@ void USB::Task(void) //USB state machine
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case USB_ATTACHED_SUBSTATE_WAIT_RESET:
|
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
|
else break; // don't fall through
|
||||||
case USB_STATE_CONFIGURING:
|
case USB_STATE_CONFIGURING:
|
||||||
|
|
||||||
|
|
4
Wii.cpp
4
Wii.cpp
|
@ -657,7 +657,7 @@ void WII::L2CAP_task() {
|
||||||
/* The next states are in run() */
|
/* The next states are in run() */
|
||||||
|
|
||||||
case L2CAP_INTERRUPT_DISCONNECT:
|
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
|
#ifdef DEBUG_USB_HOST
|
||||||
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
|
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
|
||||||
#endif
|
#endif
|
||||||
|
@ -682,7 +682,7 @@ void WII::L2CAP_task() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WII::Run() {
|
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
|
L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough
|
||||||
|
|
||||||
switch(l2cap_state) {
|
switch(l2cap_state) {
|
||||||
|
|
|
@ -97,7 +97,7 @@ void loop()
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
if (millis() >= next_time)
|
if ((next_time - millis()) >= 0L)
|
||||||
{
|
{
|
||||||
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
||||||
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
||||||
|
|
|
@ -10,21 +10,18 @@
|
||||||
#include <spi4teensy3.h>
|
#include <spi4teensy3.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class PLAsyncOper : public CDCAsyncOper
|
class PLAsyncOper : public CDCAsyncOper {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual uint8_t OnInit(ACM *pacm);
|
virtual uint8_t OnInit(ACM *pacm);
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t PLAsyncOper::OnInit(ACM *pacm)
|
uint8_t PLAsyncOper::OnInit(ACM *pacm) {
|
||||||
{
|
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
|
|
||||||
// Set DTR = 1
|
// Set DTR = 1
|
||||||
rcode = pacm->SetControlLineState(1);
|
rcode = pacm->SetControlLineState(1);
|
||||||
|
|
||||||
if (rcode)
|
if(rcode) {
|
||||||
{
|
|
||||||
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
|
ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
@ -50,8 +47,7 @@ PL2303 Pl(&Usb, &AsyncOper);
|
||||||
uint32_t read_delay;
|
uint32_t read_delay;
|
||||||
#define READ_DELAY 100
|
#define READ_DELAY 100
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
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
|
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");
|
Serial.println("Start");
|
||||||
|
@ -62,8 +58,7 @@ void setup()
|
||||||
delay(200);
|
delay(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
|
uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
|
||||||
uint16_t rcvd = 64;
|
uint16_t rcvd = 64;
|
||||||
|
@ -72,7 +67,7 @@ uint16_t rcvd = 64;
|
||||||
|
|
||||||
if(Pl.isReady()) {
|
if(Pl.isReady()) {
|
||||||
/* reading the GPS */
|
/* reading the GPS */
|
||||||
if( read_delay < millis() ){
|
if((long)(millis() - read_delay) >= 0L) {
|
||||||
read_delay += READ_DELAY;
|
read_delay += READ_DELAY;
|
||||||
rcode = Pl.RcvData(&rcvd, buf);
|
rcode = Pl.RcvData(&rcvd, buf);
|
||||||
if(rcode && rcode != hrNAK)
|
if(rcode && rcode != hrNAK)
|
||||||
|
|
|
@ -479,11 +479,10 @@ void loop() {
|
||||||
partsready = true;
|
partsready = true;
|
||||||
((pvt_t *)(sto[i].private_data))->lun = i;
|
((pvt_t *)(sto[i].private_data))->lun = i;
|
||||||
((pvt_t *)(sto[i].private_data))->B = B;
|
((pvt_t *)(sto[i].private_data))->B = B;
|
||||||
sto[i].Read = *PRead;
|
|
||||||
sto[i].Write = *PWrite;
|
|
||||||
sto[i].Reads = *PReads;
|
sto[i].Reads = *PReads;
|
||||||
sto[i].Writes = *PWrites;
|
sto[i].Writes = *PWrites;
|
||||||
sto[i].Status = *PStatus;
|
sto[i].Status = *PStatus;
|
||||||
|
sto[i].Commit = *UHS_USB_BulkOnly_Commit;
|
||||||
sto[i].TotalSectors = Bulk[B]->GetCapacity(i);
|
sto[i].TotalSectors = Bulk[B]->GetCapacity(i);
|
||||||
sto[i].SectorSize = Bulk[B]->GetSectorSize(i);
|
sto[i].SectorSize = Bulk[B]->GetSectorSize(i);
|
||||||
printf_P(PSTR("LUN:\t\t%u\r\n"), i);
|
printf_P(PSTR("LUN:\t\t%u\r\n"), i);
|
||||||
|
@ -611,8 +610,7 @@ void loop() {
|
||||||
die(rc);
|
die(rc);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
outdir:
|
outdir:{
|
||||||
{
|
|
||||||
#if _USE_LFN
|
#if _USE_LFN
|
||||||
char lfn[_MAX_LFN + 1];
|
char lfn[_MAX_LFN + 1];
|
||||||
FILINFO My_File_Info_Object_x; /* File information object */
|
FILINFO My_File_Info_Object_x; /* File information object */
|
||||||
|
|
|
@ -536,7 +536,7 @@ template <const uint8_t BOOT_PROTOCOL>
|
||||||
uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
|
uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
|
||||||
uint8_t rcode = 0;
|
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.
|
// To-do: optimize manually, using the for loop only if needed.
|
||||||
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
|
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
|
||||||
|
|
|
@ -370,7 +370,7 @@ uint8_t HIDUniversal::Poll() {
|
||||||
if(!bPollEnable)
|
if(!bPollEnable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(qNextPollTime <= millis()) {
|
if((long)(millis() - qNextPollTime) >= 0L) {
|
||||||
qNextPollTime = millis() + pollInterval;
|
qNextPollTime = millis() + pollInterval;
|
||||||
|
|
||||||
uint8_t buf[constBuffLen];
|
uint8_t buf[constBuffLen];
|
||||||
|
|
|
@ -671,7 +671,7 @@ uint8_t BulkOnly::Poll() {
|
||||||
if(!bPollEnable)
|
if(!bPollEnable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(qNextPollTime <= millis()) {
|
if((long)(millis() - qNextPollTime) >= 0L) {
|
||||||
CheckMedia();
|
CheckMedia();
|
||||||
}
|
}
|
||||||
//rcode = 0;
|
//rcode = 0;
|
||||||
|
|
|
@ -230,7 +230,7 @@ uint8_t USBHub::Poll() {
|
||||||
if(!bPollEnable)
|
if(!bPollEnable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(qNextPollTime <= millis()) {
|
if(((long)(millis() - qNextPollTime) >= 0L)) {
|
||||||
rcode = CheckHubStatus();
|
rcode = CheckHubStatus();
|
||||||
qNextPollTime = millis() + 100;
|
qNextPollTime = millis() + 100;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue