Microchip® Advanced Software Framework

xosc32k_failure_detector.c File Reference

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 void init_osc32k ( void  )
static
static void xosc32k_fail_callback ( struct tc_module instance)
static

Callback run when a XOSC32K crystal failure is detected.

Parameters
[in]instanceTimer instance that triggered the failure (CONF_TC_OSC32K)

References GCLK_GENERATOR_OSC32K, init_dfll(), LED_0_INACTIVE, LED_0_PIN, port_pin_set_output_level(), TC_CALLBACK_CC_CHANNEL0, tc_disable_callback(), tc_enable_callback(), tc_osc32k, and tc_xosc32k.

Referenced by main().

static void xosc32k_ok_callback ( struct tc_module instance)
static

Callback run when a XOSC32K crystal operation is detected.

Parameters
[in]instanceTimer instance that triggered the operation (CONF_TC_XOSC32K)

References GCLK_GENERATOR_XOSC32K, init_dfll(), LED_0_ACTIVE, LED_0_PIN, port_pin_set_output_level(), TC_CALLBACK_CC_CHANNEL0, tc_disable_callback(), tc_enable_callback(), tc_osc32k, and tc_xosc32k.

Referenced by main().

struct tc_module tc_osc32k
static

Software instance of the OSC32K timer.

Referenced by init_xosc32k_fail_detector(), xosc32k_fail_callback(), and xosc32k_ok_callback().

struct tc_module tc_xosc32k
static

Software instance of the XOSC32K timer.

Referenced by init_xosc32k_fail_detector(), xosc32k_fail_callback(), and xosc32k_ok_callback().