From e7bb5fafb1656807510f10b19a56814233636a36 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Jul 2015 19:17:12 +0200 Subject: [PATCH] Add delay between multiple calls to dispatchpkt inside InTransfer Fixes: #167 --- BTD.cpp | 4 ++-- Usb.cpp | 9 +++++---- UsbCore.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index bcfba14b..1bad3099 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -388,7 +388,7 @@ void BTD::disconnect() { void BTD::HCI_event_task() { uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this - uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf); // Input on endpoint 1 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf, pollInterval); // Input on endpoint 1 if(!rcode || rcode == hrNAK) { // Check for errors switch(hcibuf[0]) { // Switch on event type @@ -900,7 +900,7 @@ void BTD::HCI_task() { void BTD::ACL_event_task() { uint16_t length = BULK_MAXPKTSIZE; - uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf, pollInterval); // Input on endpoint 2 if(!rcode) { // Check for errors if(length > 0) { // Check if any data was read diff --git a/Usb.cpp b/Usb.cpp index 14272588..2703c034 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -203,7 +203,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque /* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, fe USB xfer timeout */ -uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data) { +uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { EpInfo *pep = NULL; uint16_t nak_limit = 0; @@ -215,10 +215,10 @@ uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* USBTRACE3("(USB::InTransfer) ep requested ", ep, 0x81); return rcode; } - return InTransfer(pep, nak_limit, nbytesptr, data); + return InTransfer(pep, nak_limit, nbytesptr, data, bInterval); } -uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data) { +uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { uint8_t rcode = 0; uint8_t pktsize; @@ -280,7 +280,8 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui //printf("\r\n"); rcode = 0; break; - } // if + } else if(bInterval > 0) + delay(bInterval); // Delay according to polling interval } //while( 1 ) return ( rcode); } diff --git a/UsbCore.h b/UsbCore.h index 5c6c7710..fdec87b0 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -245,7 +245,7 @@ public: /**/ uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr, bool direction); uint8_t ctrlStatus(uint8_t ep, bool direction, uint16_t nak_limit); - uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data); + uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval = 0); uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data); uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit); @@ -262,7 +262,7 @@ private: void init(); uint8_t SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_limit); uint8_t OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data); - uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data); + uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval = 0); uint8_t AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed); };