mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Add extra yield for Espressif. Helps with WTD.
This commit is contained in:
parent
ed08df7e68
commit
5c303ed62c
2 changed files with 36 additions and 17 deletions
51
Usb.cpp
51
Usb.cpp
|
@ -1,18 +1,11 @@
|
||||||
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
|
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This software may be distributed and modified under the terms of the GNU
|
||||||
it under the terms of the GNU General Public License as published by
|
General Public License version 2 (GPL2) as published by the Free Software
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
Foundation and appearing in the file GPL2.TXT included in the packaging of
|
||||||
(at your option) any later version.
|
this file. Please note that GPL2 Section 2[b] requires that all works based
|
||||||
|
on this software must also be made publicly available under the terms of
|
||||||
This program is distributed in the hope that it will be useful,
|
the GPL2 ("Copyleft").
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
|
|
||||||
Contact information
|
Contact information
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -171,6 +164,9 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
|
||||||
|
|
||||||
while(left) {
|
while(left) {
|
||||||
// Bytes read into buffer
|
// Bytes read into buffer
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
uint16_t read = nbytes;
|
uint16_t read = nbytes;
|
||||||
//uint16_t read = (left<nbytes) ? left : nbytes;
|
//uint16_t read = (left<nbytes) ? left : nbytes;
|
||||||
|
|
||||||
|
@ -238,6 +234,9 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
|
||||||
|
|
||||||
// use a 'break' to exit this loop
|
// use a 'break' to exit this loop
|
||||||
while(1) {
|
while(1) {
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS.
|
rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS.
|
||||||
if(rcode == hrTOGERR) {
|
if(rcode == hrTOGERR) {
|
||||||
// yes, we flip it wrong here so that next time it is actually correct!
|
// yes, we flip it wrong here so that next time it is actually correct!
|
||||||
|
@ -249,8 +248,12 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
|
||||||
//printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
|
//printf(">>>>>>>> Problem! dispatchPkt %2.2x\r\n", rcode);
|
||||||
break; //should be 0, indicating ACK. Else return error code.
|
break; //should be 0, indicating ACK. Else return error code.
|
||||||
}
|
}
|
||||||
/* check for RCVDAVIRQ and generate error if not present */
|
/* check for RCVDAVIRQ and generate error if not present
|
||||||
/* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred. Need to add handling for that */
|
* the only case when absence of RCVDAVIRQ makes sense is when toggle error occurred.
|
||||||
|
* Need to add handling for that
|
||||||
|
*
|
||||||
|
* NOTE: I've seen this happen with SPI corruption -- xxxajk
|
||||||
|
*/
|
||||||
if((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
|
if((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
|
||||||
//printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
|
//printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
|
||||||
rcode = 0xf0; //receive error
|
rcode = 0xf0; //receive error
|
||||||
|
@ -325,17 +328,27 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
|
||||||
regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
|
regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value
|
||||||
|
|
||||||
while(bytes_left) {
|
while(bytes_left) {
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
retry_count = 0;
|
retry_count = 0;
|
||||||
nak_count = 0;
|
nak_count = 0;
|
||||||
bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
|
bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
|
||||||
bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
|
bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
|
||||||
regWr(rSNDBC, bytes_tosend); //set number of bytes
|
regWr(rSNDBC, bytes_tosend); //set number of bytes
|
||||||
regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
|
regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
|
||||||
while(!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
|
while(!(regRd(rHIRQ) & bmHXFRDNIRQ)){
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
|
} //wait for the completion IRQ
|
||||||
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
|
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
|
||||||
rcode = (regRd(rHRSL) & 0x0f);
|
rcode = (regRd(rHRSL) & 0x0f);
|
||||||
|
|
||||||
while(rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) {
|
while(rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) {
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
switch(rcode) {
|
switch(rcode) {
|
||||||
case hrNAK:
|
case hrNAK:
|
||||||
nak_count++;
|
nak_count++;
|
||||||
|
@ -363,7 +376,11 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8
|
||||||
regWr(rSNDFIFO, *data_p);
|
regWr(rSNDFIFO, *data_p);
|
||||||
regWr(rSNDBC, bytes_tosend);
|
regWr(rSNDBC, bytes_tosend);
|
||||||
regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
|
regWr(rHXFR, (tokOUT | pep->epAddr)); //dispatch packet
|
||||||
while(!(regRd(rHIRQ) & bmHXFRDNIRQ)); //wait for the completion IRQ
|
while(!(regRd(rHIRQ) & bmHXFRDNIRQ)){
|
||||||
|
#if defined(ESP8266) || defined(ESP32)
|
||||||
|
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||||
|
#endif
|
||||||
|
} //wait for the completion IRQ
|
||||||
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
|
regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ
|
||||||
rcode = (regRd(rHRSL) & 0x0f);
|
rcode = (regRd(rHRSL) & 0x0f);
|
||||||
}//while( rcode && ....
|
}//while( rcode && ....
|
||||||
|
|
|
@ -242,6 +242,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t*
|
||||||
HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
|
HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
|
||||||
data_p += nbytes;
|
data_p += nbytes;
|
||||||
#elif !defined(SPDR) // ESP8266, ESP32
|
#elif !defined(SPDR) // ESP8266, ESP32
|
||||||
|
yield();
|
||||||
USB_SPI.transfer(reg | 0x02);
|
USB_SPI.transfer(reg | 0x02);
|
||||||
while(nbytes) {
|
while(nbytes) {
|
||||||
USB_SPI.transfer(*data_p);
|
USB_SPI.transfer(*data_p);
|
||||||
|
@ -345,6 +346,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t*
|
||||||
HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
|
HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
|
||||||
data_p += nbytes;
|
data_p += nbytes;
|
||||||
#elif !defined(SPDR) // ESP8266, ESP32
|
#elif !defined(SPDR) // ESP8266, ESP32
|
||||||
|
yield();
|
||||||
USB_SPI.transfer(reg);
|
USB_SPI.transfer(reg);
|
||||||
while(nbytes) {
|
while(nbytes) {
|
||||||
*data_p++ = USB_SPI.transfer(0);
|
*data_p++ = USB_SPI.transfer(0);
|
||||||
|
|
Loading…
Reference in a new issue