summaryrefslogtreecommitdiffstats
path: root/firmware/main.c
diff options
context:
space:
mode:
authorcpldcpu <cpldcpu@gmail.com>2013-11-27 19:56:01 +0100
committercpldcpu <cpldcpu@gmail.com>2013-11-27 19:56:01 +0100
commit6b890afca8dcf7b470dd10a2fd76c5dc97fa6061 (patch)
tree57454454d05fefb3cdd452288598c35900a71662 /firmware/main.c
parent64153397eef3bc5ed0c13435d1cbee5ec022fed9 (diff)
downloadmicronucleus-6b890afca8dcf7b470dd10a2fd76c5dc97fa6061.tar.gz
micronucleus-6b890afca8dcf7b470dd10a2fd76c5dc97fa6061.tar.bz2
micronucleus-6b890afca8dcf7b470dd10a2fd76c5dc97fa6061.zip
Move Usbinit, using wdt now
make micronucleus more similar to littlewire
Diffstat (limited to 'firmware/main.c')
-rw-r--r--firmware/main.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/firmware/main.c b/firmware/main.c
index 57987e1..f03484d 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -325,11 +325,12 @@ void PushMagicWord (void) {
/* ------------------------------------------------------------------------ */
static inline void initForUsbConnectivity(void) {
- usbInit();
+
/* enforce USB re-enumerate: */
usbDeviceDisconnect(); /* do this while interrupts are disabled */
_delay_ms(300); // reduced to 300ms from 500ms to allow faster resetting when no usb connected
usbDeviceConnect();
+ usbInit(); // Initialize INT settings after reconnect
sei();
}
@@ -371,6 +372,8 @@ static inline void leaveBootloader(void) {
bootLoaderExit();
cli();
usbDeviceDisconnect(); /* Disconnect micronucleus */
+
+ wdt_disable(); /* Disable watchdog */
USB_INTR_ENABLE = 0;
USB_INTR_CFG = 0; /* also reset config bits */
@@ -403,7 +406,8 @@ int main(void) {
#endif
// MCUSR=0; /* clean wdt reset bit if reset occured due to wdt */
- wdt_disable(); /* main app may have enabled watchdog */
+ // wdt_disable();
+ wdt_enable(WDTO_1S); /* enable watchdog and set to 500ms. */
tiny85FlashInit();
bootLoaderInit();
@@ -424,10 +428,12 @@ int main(void) {
# endif
initForUsbConnectivity();
-
+
+
do {
usbPoll();
+ wdt_reset();
_delay_us(100);
// these next two freeze the chip for ~ 4.5ms, breaking usb protocol