20.7.1.1.3 Workflow
- Switch performance level to PL2.
static
void
performance_level_switch_test(
void
)
{
struct
system_gclk_gen_config gclk_conf;
/* Switch to PL2 */
system_switch_performance_level(SYSTEM_PERFORMANCE_LEVEL_2);
system_flash_set_waitstates(2);
/* Switch GCLK0 to 48MHz */
system_gclk_gen_get_config_defaults(&gclk_conf);
gclk_conf.source_clock = SYSTEM_CLOCK_SOURCE_DFLL;
gclk_conf.division_factor = 1;
gclk_conf.run_in_standby =
false
;
gclk_conf.output_enable =
true
;
system_gclk_gen_set_config(GCLK_GENERATOR_0, &gclk_conf);
}
- Configure GCLK0/GCLK1 output pin and extwakeup pin.
static
void
config_clock_output_and_extwake_pin(
void
)
{
struct
system_pinmux_config pin_conf;
system_pinmux_get_config_defaults(&pin_conf);
pin_conf.mux_position = CONF_GCLK0_OUTPUT_PINMUX;
pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_OUTPUT;
system_pinmux_pin_set_config(CONF_GCLK0_OUTPUT_PIN, &pin_conf);
pin_conf.mux_position = CONF_GCLK1_OUTPUT_PINMUX;
system_pinmux_pin_set_config(CONF_GCLK1_OUTPUT_PIN, &pin_conf);
#if SAML21
pin_conf.direction = SYSTEM_PINMUX_PIN_DIR_INPUT;
pin_conf.input_pull = SYSTEM_PINMUX_PIN_PULL_UP;
pin_conf.mux_position = CONF_EXT_WAKEUP_PINMUX;
system_pinmux_pin_set_config(CONF_EXT_WAKEUP_PIN, &pin_conf);
#endif
}
- Config external interrupt.
static
void
configure_extint_channel(
void
)
{
struct
extint_chan_conf config_extint_chan;
extint_chan_get_config_defaults(&config_extint_chan);
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
extint_chan_enable_callback(BUTTON_0_EIC_LINE,EXTINT_CALLBACK_TYPE_DETECT);
system_interrupt_enable_global();
while
(extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
extint_chan_clear_detected(BUTTON_0_EIC_LINE);
}
}