check if USB is idle

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
kefeer

check if USB is idle

Post by kefeer » Tue Sep 26, 2017 10:49 am

Is there a way to know that there is no pending transfers are going on USB?

Specifically, i want to know that we already ACK'ed STATUS of my current SETUP.

I am calling SPM to erase/flash pages and this causes a significant enough delay to cause URB to error on a host side.


Thanks!

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: check if USB is idle

Post by ulao » Fri Sep 29, 2017 1:54 pm

Been going down this road all month....

Do you use any control transfers? If so things get twice as hard.

Assuming you have a normal interrupt based USB poll every 8-10ms you can tie everything to the usbpoll. Somewhere in your code you should have a line like so.
while (!usbInterruptIsReady()) usbPoll(); usbSetInterrupt( reportBuffer, 8);
//add code here..

If you do your pages at this point you have 8 ms of free time to play. Now if you are using a control transfer to tell the driver to do page writes, things get a bit more complicated. I set a global bit that I turn on after the control transfer completes them check for that bit where I added the comment above and do the work. This will worked for any software written in c or c++ but forget about c#.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: check if USB is idle

Post by ulao » Fri Nov 10, 2017 6:38 pm

check for the arrest


usbPoll(); //issue at least one for the check below
if (USB_INTR_PENDING & (1<<USB_INTR_PENDING_BIT)) // Usbpoll() collided with data packet
{
uint8_t ctr;

// loop takes 5 cycles
asm volatile(
" ldi %0,%1 \n\t"
"loop%=: sbis %2,%3 \n\t"
" ldi %0,%1 \n\t"
" subi %0,1 \n\t"
" brne loop%= \n\t"
: "=&d" (ctr)
: "M" ((uint8_t)(8.8f*(F_CPU/1.0e6f)/5.0f+0.5)), "I" (_SFR_IO_ADDR(USBIN)), "M" (USB_CFG_DMINUS_BIT)
);
USB_INTR_PENDING = 1<<USB_INTR_PENDING_BIT;
}

Post Reply