Page 1 of 1
check if USB is idle
Posted: Tue Sep 26, 2017 10:49 am
by kefeer
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!
Re: check if USB is idle
Posted: Fri Sep 29, 2017 1:54 pm
by ulao
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,
;
//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#.
Re: check if USB is idle
Posted: Fri Nov 10, 2017 6:38 pm
by ulao
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;
}