Skip to content

Commit

Permalink
reduce wait time in DebugWIRE before disable interrupt
Browse files Browse the repository at this point in the history
In previous implementaion, the DebugWIRE func waited 2ms to for all USB transactions to complete. Now it waits 100us, if there is USB transactions, it waits for another 100us.

If there is no USB transactions for 100us, the function will proceeed.
  • Loading branch information
DeqingSun committed Nov 10, 2018
1 parent 86be876 commit a0d1b6f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion usbtiny/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,15 @@ int main(void) {
// bit flag, and is arranged so that sending a 33 (send break and read pulse widths)
// will abort a pending wait.

if (dwState & 0x34) {_delay_ms(2);} // Allow USB transfer to complete before
if (dwState & 0x34) {
uchar usbInterruptCountPrev, usbInterruptCountNow;
usbInterruptCountNow = usbInterruptCount; //usbInterruptCount got increased in every USB interrupt
do {
usbInterruptCountPrev=usbInterruptCountNow;
_delay_us(100);
usbInterruptCountNow = usbInterruptCount;
} while( usbInterruptCountPrev!= usbInterruptCountNow);
} // Allow USB transfer to complete before
// any action that may disable interrupts

if (dwState & 0x01) {cbi(PORTB, 5); sbi(DDRB, 5); _delay_ms(100);}
Expand Down
3 changes: 3 additions & 0 deletions usbtiny/usbdrv/asmcommon.inc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ doReturn:
sbrc YL, USB_INTR_PENDING_BIT;[50] check whether data is already arriving
rjmp waitForJ ;[51] save the pops and pushes -- a new interrupt is already pending
sofError:
lds YL, usbInterruptCount ;POP_RETI restore YL & SREG
inc YL
sts usbInterruptCount, YL
POP_RETI ;macro call
reti

Expand Down
1 change: 1 addition & 0 deletions usbtiny/usbdrv/usbdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ uchar usbCurrentTok; /* last token received or endpoint number for la
uchar usbRxToken; /* token for data we received; or endpont number for last OUT */
volatile uchar usbTxLen = USBPID_NAK; /* number of bytes to transmit with next IN token or handshake token */
uchar usbTxBuf[USB_BUFSIZE];/* data to transmit with next IN, free if usbTxLen contains handshake token */
volatile uchar usbInterruptCount; /* incremented by assembler module every USB interrupt */
#if USB_COUNT_SOF
volatile uchar usbSofCount; /* incremented by assembler module every SOF */
#endif
Expand Down
3 changes: 3 additions & 0 deletions usbtiny/usbdrv/usbdrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ extern uchar usbConfiguration;
* You may want to reflect the "configured" status with a LED on the device or
* switch on high power parts of the circuit only if the device is configured.
*/
extern volatile uchar usbInterruptCount;
/* This variable is incremented on every USB interrupt.
*/
#if USB_COUNT_SOF
extern volatile uchar usbSofCount;
/* This variable is incremented on every SOF packet. It is only available if
Expand Down

0 comments on commit a0d1b6f

Please sign in to comment.