示例#1
0
void main(void) {
#else
int main(void) {
#endif
    /* Ensure that the Watchdog is not running. */
    wdt_disable();
    
	/* Initialize system. */
	if (true != avr_init()) {
		error_handler();
	} else if (true != eep_init()) {
        eep_deinit();
        error_handler();
    } else if (true != cmd_if_init()) {
        cmd_if_deinit();
        error_handler();
    }
	
    /* Disable modules that are not needed any more. */
    eep_deinit();
    
    LED_ORANGE_ON();
        
    /* Enable interrupts. */
    sei();
    
	/* Endless application loop. */
	for(;;) {
        /* Dispatch events from the event queue. */
		vrt_dispatch_event();
        
        /* Poll modules that require this. */
        vrt_timer_task();
        usb_task();
        air_capture_task();
        cmd_if_task();
	}
}
void main(void) {
#else
int main(void) {
#endif
    /* Ensure that the watchdog is not running. */
    wdt_disable();
        
    /* Initialize AVR peripheral modules. */
    (bool)avr_init();
    
    /* Check if the RX and TX pins are shorted. If they are shorted, the RZUSBSTICK
     * shall start the bootloader. If not, continue to verify if the application
     * requested to enter the bootloader.
     */
    
    /* Check if the application has requested to enter the bootloader. */
    if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) {
        /* Check that RX goes high when TX is pulled high. */
        BOOT_PORT |= (1 << BOOT_TX);
        
        nop();
        nop();
        nop();
        nop();
        
        if ((BOOT_PIN & (1 << BOOT_RX)) != (1 << BOOT_RX)) {
            start_application();
        }
    } else {
        /* Check if the application has requested to enter the bootloader. */
        uint8_t volatile magic_value = 0xAA;
        EEGET(magic_value, EE_BOOT_MAGIC_ADR);
   
        if (EE_BOOT_MAGIC_VALUE != magic_value) {
            start_application();
        } else {
            EEPUT(EE_BOOT_MAGIC_ADR, 0xFF);
        }
    }
    
    /* Set the interrupt vectors to the bootloader, initialize the LEDs and the
     * VRT kernel.
     */
    ENTER_CRITICAL_REGION();
    uint8_t temp_mcucr = MCUCR;
    MCUCR = (1 << IVCE);
    MCUCR = (1 << IVSEL);
    MCUCR = temp_mcucr;
    LEAVE_CRITICAL_REGION();

    LED_INIT();
    vrt_init();
    
    if (true != eep_init()) {
        error_handler();
    } else if (true != cmd_if_init()) {
        error_handler();
    }
    
    LED_ORANGE_ON();
    
    /* Enable Interrupts. */
    sei();
    
    /* Enter the endless application loop. */
    for (;;) {
        vrt_dispatch_event();
        usb_task();
    }
}