int __attribute__((noreturn)) main(void) { /* initialize hardware */ bootLoaderInit(); odDebugInit(); DBG1(0x00, 0, 0); /* jump to application if jumper is set */ if(bootLoaderCondition()) { uchar i = 0, j = 0; #ifndef TEST_MODE GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (1 << IVSEL); /* move interrupts to boot flash section */ #endif initForUsbConnectivity(); do { /* main event loop */ wdt_reset(); usbPoll(); #if BOOTLOADER_CAN_EXIT if(exitMainloop) { #if F_CPU == 12800000 break; /* memory is tight at 12.8 MHz, save exit delay below */ #endif if(--i == 0) { if(--j == 0) break; } } #endif } while(bootLoaderCondition()); } leaveBootloader(); }
int __attribute__((noreturn)) main(void) { bootLoaderInit(); initStatusLed(); if (bootLoaderCondition()) { if (eeprom_read_stay_in_bootloader() != 0) eeprom_clear_stay_in_bootloader(); statusLedOn(); uchar i = 0, j = 0; GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (1 << IVSEL); /* move interrupts to boot flash section */ initForUsbConnectivity(); for (;;) { /* main event loop */ wdt_reset(); usbPoll(); #if BOOTLOADER_CAN_EXIT if (exitMainloop) { if (--i == 0) { if (--j == 0) break; } } #endif } } leaveBootloader(); }
int main(void) { bool suspended = false; #if USB_COUNT_SOF uint16_t last_timer = timer_read(); #endif #if !defined(__AVR_ATmega32__) CLKPR = 0x80, CLKPR = 0; #endif #ifndef PS2_USE_USART uart_init(UART_BAUD_RATE); #endif keyboard_init(); host_set_driver(vusb_driver()); debug("initForUsbConnectivity()\n"); initForUsbConnectivity(); debug("main loop\n"); while (1) { #if USB_COUNT_SOF if (usbSofCount != 0) { suspended = false; usbSofCount = 0; last_timer = timer_read(); } else { // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) if (timer_elapsed(last_timer) > 5) { suspended = true; /* uart_putchar('S'); _delay_ms(1); cli(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); sleep_bod_disable(); sei(); sleep_cpu(); sleep_disable(); _delay_ms(10); uart_putchar('W'); */ } } #endif if (!suspended) { usbPoll(); // TODO: configuration process is incosistent. it sometime fails. // To prevent failing to configure NOT scan keyboard during configuration if (usbConfiguration && usbInterruptIsReady()) { keyboard_task(); } vusb_transfer_keyboard(); } } }
int __attribute__((noreturn)) main(void) { unsigned int blink_cnt = 0; /* initialize hardware */ bootLoaderInit(); /* * Calling the function below for it to get included in the bootloader. * Also, making sure that it actually doesn't do anything. And hence, * passing an unaligned address 0x0001, for the function to fail. */ #if (FLASHEND) > 0xFFFF flash_write_block(0x00000001, NULL); #else flash_write_block(0x0001, NULL); #endif odDebugInit(); DBG1(0x00, 0, 0); /* jump to application if jumper is set */ if(bootLoaderCondition()){ #ifndef TEST_MODE uint8_t gicr; gicr = GICR; GICR = gicr | (1 << IVCE); /* enable change of interrupt vectors */ GICR = gicr | (1 << IVSEL); /* move interrupts to boot flash section */ #endif DBG1(0x02, 0, 0); initForUsbConnectivity(); do{ /* main event loop */ //DBG2(0x03, 0, 0); wdt_reset(); usbPoll(); /* The following piece of code indicates being in bootloader */ if (++blink_cnt == 60000) { blink_cnt = 0; toggleLED(); //DBG2(0x04, 0, 0); } //DBG2(0x05, 0, 0); #if BOOTLOADER_CAN_EXIT if(exitMainloop){ break; } #endif }while(1); } leaveBootloader(); }
int __attribute__((noreturn)) main(void) { uint16_t idlePolls = 0; #ifdef APPCHECKSUM int validApp = 0; #endif /* initialize */ wdt_disable(); /* main app may have enabled watchdog */ #ifdef TINY85MODE tiny85FlashInit(); #endif bootLoaderInit(); odDebugInit(); DBG1(0x00, 0, 0); #ifdef APPCHECKSUM validApp = testForValidApplication(); #endif #ifndef TINY85MODE # ifndef NO_FLASH_WRITE GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (1 << IVSEL); /* move interrupts to boot flash section */ # endif #endif if(bootLoaderCondition()){ initForUsbConnectivity(); do{ usbPoll(); _delay_us(100); idlePolls++; #ifdef TINY85MODE tiny85FlashWrites(); #endif #if BOOTLOADER_CAN_EXIT // exit if requested by the programming app, or if we timeout waiting for the pc with a valid app if(requestBootLoaderExit || AUTO_EXIT_CONDITION()){ _delay_ms(10); break; } #endif }while(bootLoaderCondition()); /* main event loop */ } leaveBootloader(); }
int __attribute__((noreturn)) main(void) { uint16_t idlePolls = 0; /* initialize */ wdt_disable(); /* main app may have enabled watchdog */ tiny85FlashInit(); bootLoaderInit(); if (bootLoaderCondition()) { initForUsbConnectivity(); do { usbPoll(); _delay_us(100); idlePolls++; if (events) idlePolls = 0; // these next two freeze the chip for ~ 4.5ms, breaking usb protocol // and usually both of these will activate in the same loop, so host // needs to wait > 9ms before next usb request if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites(); if (isEvent(EVENT_FINISH)) { // || AUTO_EXIT_CONDITION()) { tiny85FinishWriting(); # if BOOTLOADER_CAN_EXIT _delay_ms(10); // removing delay causes USB errors break; # endif } // # if BOOTLOADER_CAN_EXIT // // exit if requested by the programming app, or if we timeout waiting for the pc with a valid app // if (isEvent(EVENT_EXIT_BOOTLOADER) || AUTO_EXIT_CONDITION()) { // //_delay_ms(10); // break; // } // # endif clearEvents(); } while(bootLoaderCondition()); /* main event loop */ } leaveBootloader(); }
int main(void) { bool suspended = false; #if USB_COUNT_SOF uint16_t last_timer = timer_read(); #endif CLKPR = 0x80, CLKPR = 0; #ifndef NO_UART uart_init(UART_BAUD_RATE); #endif keyboard_init(); host_set_driver(vusb_driver()); debug("initForUsbConnectivity()\n"); initForUsbConnectivity(); debug("main loop\n"); while (1) { #if USB_COUNT_SOF if (usbSofCount != 0) { suspended = false; usbSofCount = 0; last_timer = timer_read(); } else { // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1) if (timer_elapsed(last_timer) > 5) { suspended = true; } } #endif if (!suspended) { usbPoll(); // TODO: configuration process is incosistent. it sometime fails. // To prevent failing to configure NOT scan keyboard during configuration if (usbConfiguration && usbInterruptIsReady()) { keyboard_task(); } vusb_transfer_keyboard(); } else if (suspend_wakeup_condition()) { usb_remote_wakeup(); } } }
int __attribute__((noreturn)) main(void) { uint16_t blink = 0; volatile int zero = 0; loop = 0; odDebugInit(); DBG1(0x00, 0, 0); uchar i = 0, j = 0; #ifndef TEST_MODE GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (1 << IVSEL); /* move interrupts to boot flash section */ #endif LED_DDR |= LED; initForUsbConnectivity(); do{ /* main event loop */ wdt_reset(); usbPoll(); #if BOOTLOADER_CAN_EXIT if(exitMainloop){ #if F_CPU == 12800000 break; /* memory is tight at 12.8 MHz, save exit delay below */ #endif if(--i == 0){ if(--j == 0) break; } } #endif if (blink++ == 0) { LED_PORT ^= LED; if (loop++ > 10 && (pgm_read_byte(zero) != 0xff)) exitMainloop = 1; } } while (1); LED_DDR &= ~LED; LED_PORT &= ~LED; leaveBootloader(); }
int main(void) { /* initialize */ #ifdef RESTORE_OSCCAL uint8_t osccal_default = OSCCAL; #endif #if (!SET_CLOCK_PRESCALER) && LOW_POWER_MODE uint8_t prescaler_default = CLKPR; #endif wdt_disable(); /* main app may have enabled watchdog */ tiny85FlashInit(); bootLoaderInit(); if (bootLoaderStartCondition()) { #if LOW_POWER_MODE // turn off clock prescalling - chip must run at full speed for usb // if you might run chip at lower voltages, detect that in bootLoaderStartCondition CLKPR = 1 << CLKPCE; CLKPR = 0; #endif initForUsbConnectivity(); do { usbPoll(); _delay_us(100); idlePolls++; // these next two freeze the chip for ~ 4.5ms, breaking usb protocol // and usually both of these will activate in the same loop, so host // needs to wait > 9ms before next usb request if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication(); if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites(); # if BOOTLOADER_CAN_EXIT if (isEvent(EVENT_EXECUTE)) { // when host requests device run uploaded program break; } # endif clearEvents(); } while(bootLoaderCondition()); /* main event loop runs so long as bootLoaderCondition remains truthy */ } // set clock prescaler to desired clock speed (changing from clkdiv8, or no division, depending on fuses) #if LOW_POWER_MODE #ifdef SET_CLOCK_PRESCALER CLKPR = 1 << CLKPCE; CLKPR = SET_CLOCK_PRESCALER; #else CLKPR = 1 << CLKPCE; CLKPR = prescaler_default; #endif #endif // slowly bring down OSCCAL to it's original value before launching in to user program #ifdef RESTORE_OSCCAL while (OSCCAL > osccal_default) { OSCCAL -= 1; } #endif leaveBootloader(); }