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.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
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
|
||||
This software may be distributed and modified under the terms of the GNU
|
||||
General Public License version 2 (GPL2) as published by the Free Software
|
||||
Foundation and appearing in the file GPL2.TXT included in the packaging of
|
||||
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
|
||||
the GPL2 ("Copyleft").
|
||||
|
||||
Contact information
|
||||
-------------------
|
||||
|
@ -171,6 +164,9 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque
|
|||
|
||||
while(left) {
|
||||
// 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 = (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
|
||||
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.
|
||||
if(rcode == hrTOGERR) {
|
||||
// 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);
|
||||
break; //should be 0, indicating ACK. Else return error code.
|
||||
}
|
||||
/* 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 */
|
||||
/* 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
|
||||
*
|
||||
* NOTE: I've seen this happen with SPI corruption -- xxxajk
|
||||
*/
|
||||
if((regRd(rHIRQ) & bmRCVDAVIRQ) == 0) {
|
||||
//printf(">>>>>>>> Problem! NO RCVDAVIRQ!\r\n");
|
||||
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
|
||||
|
||||
while(bytes_left) {
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
yield(); // needed in order to reset the watchdog timer on the ESP8266
|
||||
#endif
|
||||
retry_count = 0;
|
||||
nak_count = 0;
|
||||
bytes_tosend = (bytes_left >= maxpktsize) ? maxpktsize : bytes_left;
|
||||
bytesWr(rSNDFIFO, bytes_tosend, data_p); //filling output FIFO
|
||||
regWr(rSNDBC, bytes_tosend); //set number of bytes
|
||||
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
|
||||
rcode = (regRd(rHRSL) & 0x0f);
|
||||
|
||||
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) {
|
||||
case hrNAK:
|
||||
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(rSNDBC, bytes_tosend);
|
||||
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
|
||||
rcode = (regRd(rHRSL) & 0x0f);
|
||||
}//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);
|
||||
data_p += nbytes;
|
||||
#elif !defined(SPDR) // ESP8266, ESP32
|
||||
yield();
|
||||
USB_SPI.transfer(reg | 0x02);
|
||||
while(nbytes) {
|
||||
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);
|
||||
data_p += nbytes;
|
||||
#elif !defined(SPDR) // ESP8266, ESP32
|
||||
yield();
|
||||
USB_SPI.transfer(reg);
|
||||
while(nbytes) {
|
||||
*data_p++ = USB_SPI.transfer(0);
|
||||
|
|
Loading…
Reference in a new issue