AT11378

Code

Copy-paste the following code to your user application:
/* Check if the RESET is caused by external wakeup pin */
if (system_get_reset_cause() == SYSTEM_RESET_CAUSE_BACKUP
    && system_get_backup_exit_source() == SYSTEM_RESET_BACKKUP_EXIT_EXTWAKE
    && (system_get_pin_wakeup_cause() & (1 << CONF_EXT_WAKEUP_PIN))){
    system_init();
    delay_init();
    config_clock_output_and_extwake_pin();
    /* Now GCLK0/GCLK1 are running at 4MHz , using LED0 ON/OFF as an indication */
    led_toggle_indication(4);
    port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
    while(1);
}


/* Disable I/O retention*/
system_io_retension_disable();

system_init();
delay_init();

port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);

/* Config GCLK0/GCLK1 output pin and extwakeup pin */
config_clock_output_and_extwake_pin();

/* Config external interrupt for wakeup system from standby mode*/
configure_extint_channel();
delay_s(1);

/* Turn off LED0 before enter standby mode */
port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);

/* Set and enter standby mode, using default stanby config */
system_set_sleepmode(SYSTEM_SLEEPMODE_STANDBY);
system_sleep();

/* Detect BUTTON pressed and system  wakeup from standby mode,
    turn on led */
port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);

/* Disable external interrupt to avoid any impact */
extint_chan_disable_callback(BUTTON_0_EIC_LINE,
            EXTINT_CALLBACK_TYPE_DETECT);
extint_chan_clear_detected(BUTTON_0_EIC_LINE);

/* Switch GCLK0 to 48MHz */
performance_level_switch_test();

/* GCLK0 is runing at 48MHz and GCLK1 is running at 4MHz ,
    use led ON/OFF as an indication */
led_toggle_indication(2);


/* Set external wakeup pin polarity */
system_set_pin_wakeup_polarity_low(1<<CONF_EXT_WAKEUP_PIN);

/* Set external wakeup detector */
system_enable_pin_wakeup(1<<CONF_EXT_WAKEUP_PIN);
system_set_pin_wakeup_debounce_counter(SYSTEM_WAKEUP_DEBOUNCE_2CK32);

/* Enter BACKUP mode */
system_set_sleepmode(SYSTEM_SLEEPMODE_BACKUP);
system_sleep();

/* Now system is in BACKUP mode and wait for extwakeup pin to low */