コード例 #1
0
ファイル: main.c プロジェクト: agural/Photuris
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();
}
コード例 #2
0
ファイル: main.c プロジェクト: Wolfman-F16/usbBootloader
uchar   usbFunctionSetup(uchar data[8])
{
    uchar len = 0;
    
    if (data[1] == USBBOOT_FUNC_LEAVE_BOOT) {
      leaveBootloader();
    } else if (data[1] == USBBOOT_FUNC_WRITE_PAGE) {

      state = STATE_WRITE_PAGE;

      page_address = (data[3] << 8) | data[2]; /* page address */
      page_offset = 0;

      eeprom_busy_wait();
      cli();
      boot_page_erase(page_address); /* erase page */
      sei();
      boot_spm_busy_wait(); /* wait until page is erased */

      len = 0xff; /* multiple out */

    } else if (data[1] == USBBOOT_FUNC_GET_PAGESIZE) {

      replyBuffer[0] = SPM_PAGESIZE >> 8;
      replyBuffer[1] = SPM_PAGESIZE & 0xff;
      len = 2;

    }
コード例 #3
0
ファイル: main.c プロジェクト: ejholmes/openfocus
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();
}
コード例 #4
0
ファイル: main.c プロジェクト: esrijan/ddk-software
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();
}
コード例 #5
0
ファイル: main.c プロジェクト: Bluebie/USBaspLoader-tiny85
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();
}
コード例 #6
0
ファイル: main.c プロジェクト: vimes79/micronucleus-t85
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();
}
コード例 #7
0
ファイル: main.c プロジェクト: fabiobaltieri/rf-synthesizer
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();
}
コード例 #8
0
ファイル: main.c プロジェクト: gblargg/micronucleus
int main( void )
{
	// TODO: default implementation is bloated
	//clock_prescale_set( clock_div_1 );
	
	// Allow user to see registers before any disruption
	bootLoaderInit();
	
	initHardware(); // gives time for jumper pull-ups to stabilize
	
	while ( bootLoaderCondition() )
	{
		// Run USB until we have some action to take and that transaction is complete
		uchar prevTxLen;
		do {
			prevTxLen = usbTxLen;
			wait_usb_interrupt();
		}
		while ( !(prevCommand != cmd_info &&
				usbTxLen == USBPID_NAK && prevTxLen != USBPID_NAK) );
		
		// Stops once we have a command and we've just transmitted the final reply
		// back to host
		
		// Now we can ignore USB until our host program makes another request
		
		if ( prevCommand == cmd_erase )
			erase_flash();
		else if ( prevCommand == cmd_write )
			write_flash();
		else
			break;
	}
	
	leaveBootloader();
}
コード例 #9
0
ファイル: main.c プロジェクト: jbowes/button-firmware
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();
}