Code in for loop outside of if (usbInterruptIsReady()) {...}

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
yardleydobon
Posts: 2
Joined: Sat Jun 11, 2011 8:25 am

Code in for loop outside of if (usbInterruptIsReady()) {...}

Post by yardleydobon » Mon Jun 27, 2011 8:17 am

Is it not OK to do work in the for loop outside of the if (usbInterruptIsReady()) code block?
I have code between wdt_reset() and usbPoll(). Sometimes the device enumerates correctly
but usually not. Why doesn't this work or why shouldn't I do this? Does the amount of
work done there matter? Do I need to call wdt_reset() multiple times?

Code: Select all

        for(;;)
        {
                wdt_reset();

                //doing some work here
                foo = froobulate(foo, bar, baz);

                usbPoll();
                if (usbInterruptIsReady())
                {
                        my_report.foo = foo;
                        usbSetInterrupt((void *)&my_report, sizeof(my_report));
                }
        }

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

Re: Code in for loop outside of if (usbInterruptIsReady()) {...}

Post by ulao » Wed Jun 29, 2011 10:43 pm

Use the code below, this may help a little.

When ( ! usbInterruptIsReady() ) , You are limited to a very small amount of code space before the next pull must be done. I have tried using that section of code to preform a check on the d- line. My need was for a line Low for x amount of time. I realized there was little room to do anything. The amount of time is much less for Win7 then XP. Almost no time at all!. I added a cli and sli to try to get more room but still was not enough. I would like to know how to cheet this, as thus far I have not had much luck.


Code: Select all

//You can put anything here you want but you still have a limit from what I know. 
// i have never hit it and its well over a second.

while (!usbInterruptIsReady()){   /*  limited to a short amount of time.   */  usbPoll();} 

//You can put anything here you want but you still have a limit from what I know. 
//i have never hit it and its well over a second.

Post Reply