SAM XOSC32K Runtime Failure Detector Application.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include "conf_example.h"
Macros | |
#define | CRYSTAL_FAIL_CYCLES (CRYSTAL_RESET_CYCLES * 2) |
Number of cycles on the OSC32K before assuming a XOSC32K failure. More... | |
#define | CRYSTAL_RESET_CYCLES 200 |
Number of cycles on the XOSC32K before resetting the reference timer. More... | |
#define | ENABLE_CPU_CLOCK_OUT true |
If true , the CPU clock will be routed out to GPIO pin. More... | |
#define | GCLK_GENERATOR_OSC32K GCLK_GENERATOR_1 |
Generator index configured to source from the internal OSC32K oscillator. More... | |
#define | GCLK_GENERATOR_XOSC32K GCLK_GENERATOR_2 |
Generator index configured to source from the XOSC32K crystal. More... | |
Functions | |
static void | init_dfll (const enum system_clock_source source_generator) |
Configures and starts the DFLL in closed loop mode with the given reference generator. More... | |
static void | init_osc32k (void) |
Configures and starts the OSC32K internal clock. More... | |
static void | init_xosc32k (void) |
Configures and starts the XOSC32K external crystal. More... | |
static void | init_xosc32k_fail_detector (const tc_callback_t ok_callback, const tc_callback_t fail_callback) |
Initializes the XOSC32K crystal failure detector, and starts it. More... | |
int | main (void) |
Main application entry point. More... | |
static void | xosc32k_fail_callback (struct tc_module *instance) |
Callback run when a XOSC32K crystal failure is detected. More... | |
static void | xosc32k_ok_callback (struct tc_module *instance) |
Callback run when a XOSC32K crystal operation is detected. More... | |
Variables | |
static struct tc_module | tc_osc32k |
Software instance of the OSC32K timer. More... | |
static struct tc_module | tc_xosc32k |
Software instance of the XOSC32K timer. More... | |
#define CRYSTAL_FAIL_CYCLES (CRYSTAL_RESET_CYCLES * 2) |
Number of cycles on the OSC32K before assuming a XOSC32K failure.
Referenced by init_xosc32k_fail_detector().
#define CRYSTAL_RESET_CYCLES 200 |
Number of cycles on the XOSC32K before resetting the reference timer.
Referenced by init_xosc32k_fail_detector().
#define ENABLE_CPU_CLOCK_OUT true |
If true
, the CPU clock will be routed out to GPIO pin.
Referenced by init_dfll().
#define GCLK_GENERATOR_OSC32K GCLK_GENERATOR_1 |
Generator index configured to source from the internal OSC32K oscillator.
Referenced by init_xosc32k_fail_detector(), and xosc32k_fail_callback().
#define GCLK_GENERATOR_XOSC32K GCLK_GENERATOR_2 |
Generator index configured to source from the XOSC32K crystal.
Referenced by init_xosc32k_fail_detector(), and xosc32k_ok_callback().
|
static |
Configures and starts the DFLL in closed loop mode with the given reference generator.
[in] | source_generator | Reference generator to use for the DFLL |
References ENABLE_CPU_CLOCK_OUT, GCLK_GENERATOR_0, system_clock_source_dfll_config::loop_mode, system_clock_source_dfll_config::multiply_factor, system_clock_source_dfll_config::on_demand, system_gclk_gen_config::output_enable, system_gclk_gen_config::source_clock, SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED, SYSTEM_CLOCK_SOURCE_DFLL, system_clock_source_dfll_get_config_defaults(), system_clock_source_dfll_set_config(), system_clock_source_disable(), system_clock_source_enable(), system_clock_source_is_ready(), SYSTEM_CLOCK_SOURCE_OSC16M, system_gclk_chan_enable(), system_gclk_chan_get_hz(), system_gclk_gen_get_config_defaults(), and system_gclk_gen_set_config().
Referenced by xosc32k_fail_callback(), and xosc32k_ok_callback().
|
static |
Configures and starts the OSC32K internal clock.
References system_clock_source_enable(), SYSTEM_CLOCK_SOURCE_OSC32K, system_clock_source_osc32k_get_config_defaults(), and system_clock_source_osc32k_set_config().
Referenced by main().
|
static |
Configures and starts the XOSC32K external crystal.
References system_clock_source_xosc32k_config::on_demand, system_clock_source_enable(), system_clock_source_is_ready(), SYSTEM_CLOCK_SOURCE_XOSC32K, system_clock_source_xosc32k_get_config_defaults(), and system_clock_source_xosc32k_set_config().
Referenced by main().
|
static |
Initializes the XOSC32K crystal failure detector, and starts it.
[in] | ok_callback | Callback function to run upon XOSC32K operational |
[in] | fail_callback | Callback function to run upon XOSC32K failure |
References _tc_get_inst_index(), Abs, Assert, tc_config::clock_source, tc_16bit_config::compare_capture_channel, tc_config::counter_16_bit, CRYSTAL_FAIL_CYCLES, CRYSTAL_RESET_CYCLES, events_config::edge_detect, tc_events::event_action, events_allocate(), events_attach_user(), EVENTS_EDGE_DETECT_NONE, events_get_config_defaults(), EVENTS_PATH_ASYNCHRONOUS, GCLK_GENERATOR_0, GCLK_GENERATOR_OSC32K, GCLK_GENERATOR_XOSC32K, tc_events::generate_event_on_overflow, events_config::generator, tc_events::on_event_perform_action, events_config::path, system_gclk_gen_config::source_clock, SYSTEM_CLOCK_SOURCE_OSC32K, SYSTEM_CLOCK_SOURCE_XOSC32K, system_gclk_gen_enable(), system_gclk_gen_get_config_defaults(), system_gclk_gen_set_config(), TC_CALLBACK_CC_CHANNEL0, tc_enable(), tc_enable_callback(), tc_enable_events(), TC_EVENT_ACTION_RETRIGGER, tc_get_config_defaults(), tc_init(), tc_osc32k, tc_register_callback(), TC_WAVE_GENERATION_MATCH_FREQ, tc_xosc32k, and tc_config::wave_generation.
Referenced by main().
int main | ( | void | ) |
Main application entry point.
References system_pinmux_config::direction, init_osc32k(), init_xosc32k(), init_xosc32k_fail_detector(), system_pinmux_config::mux_position, port_pin_get_input_level(), system_clock_source_disable(), system_clock_source_enable(), system_clock_source_is_ready(), SYSTEM_CLOCK_SOURCE_XOSC32K, system_flash_set_waitstates(), system_init(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_OUTPUT, system_pinmux_pin_set_config(), xosc32k_fail_callback(), and xosc32k_ok_callback().
|
static |
Callback run when a XOSC32K crystal failure is detected.
[in] | instance | Timer instance that triggered the failure (CONF_TC_OSC32K) |
References GCLK_GENERATOR_OSC32K, init_dfll(), port_pin_set_output_level(), TC_CALLBACK_CC_CHANNEL0, tc_disable_callback(), tc_enable_callback(), tc_osc32k, and tc_xosc32k.
Referenced by main().
|
static |
Callback run when a XOSC32K crystal operation is detected.
[in] | instance | Timer instance that triggered the operation (CONF_TC_XOSC32K) |
References GCLK_GENERATOR_XOSC32K, init_dfll(), port_pin_set_output_level(), TC_CALLBACK_CC_CHANNEL0, tc_disable_callback(), tc_enable_callback(), tc_osc32k, and tc_xosc32k.
Referenced by main().
|
static |
Software instance of the OSC32K timer.
Referenced by init_xosc32k_fail_detector(), xosc32k_fail_callback(), and xosc32k_ok_callback().
|
static |
Software instance of the XOSC32K timer.
Referenced by init_xosc32k_fail_detector(), xosc32k_fail_callback(), and xosc32k_ok_callback().