X-Git-Url: http://git.linex4red.de/pub/USBaspLoader.git/blobdiff_plain/5546d9fccf53bd10d2b185da2da00e7047cec7e1..c2df4584d6bc82ef8c793eaaffc0acead7f8410c:/firmware/main.c?ds=inline diff --git a/firmware/main.c b/firmware/main.c index fda58a2..8012e20 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -386,10 +386,33 @@ uchar i; static void initForUsbConnectivity(void) { +#if HAVE_UNPRECISEWAIT + /* (0.25s*F_CPU)/(4 cycles per loop) ~ (65536*waitloopcnt) + * F_CPU/(16*65536) ~ waitloopcnt + * F_CPU / 1048576 ~ waitloopcnt + */ + uint8_t waitloopcnt = 1 + (F_CPU/1048576); +#endif usbInit(); /* enforce USB re-enumerate: */ usbDeviceDisconnect(); /* do this while interrupts are disabled */ +#if HAVE_UNPRECISEWAIT + asm volatile ( + /*we really don't care what value Z has... + * ...if we loop 65536/F_CPU more or less... + * ...unimportant - just save some opcodes + */ +"initForUsbConnectivity_sleeploop: \n\t" + "sbiw r30, 1 \n\t" + "sbci %0, 0 \n\t" + "brne initForUsbConnectivity_sleeploop \n\t" + : "+d" (waitloopcnt) + : + : "r30","r31" + ); +#else _delay_ms(260); /* fake USB disconnect for > 250 ms */ +#endif usbDeviceConnect(); sei(); }