Microchip® Advanced Software Framework

rtc_count.h File Reference

SAM RTC Driver (Count Mode)

Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <conf_clocks.h>
#include <system_interrupt.h>
#include "rtc_tamper.h"

Data Structures

struct  rtc_count_config
 RTC Count configuration structure. More...
 
struct  rtc_count_events
 RTC Count event enable/disable structure. More...
 

Macros

Driver Feature Definition

Define port features set according to different device family.

#define FEATURE_RTC_PERIODIC_INT
 RTC periodic interval interrupt. More...
 
#define FEATURE_RTC_PRESCALER_OFF
 RTC prescaler is off. More...
 
#define FEATURE_RTC_CLOCK_SELECTION
 RTC clock selection. More...
 
#define FEATURE_RTC_GENERAL_PURPOSE_REG
 General purpose registers. More...
 
#define FEATURE_RTC_TAMPER_DETECTION
 RTC tamper detection. More...
 

Enumerations

enum  rtc_clock_sel {
  RTC_CLOCK_SELECTION_ULP1K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP1K_Val,
  RTC_CLOCK_SELECTION_ULP32K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP32K_Val,
  RTC_CLOCK_SELECTION_OSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC1K_Val,
  RTC_CLOCK_SELECTION_OSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC32K_Val,
  RTC_CLOCK_SELECTION_XOSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC1K_Val,
  RTC_CLOCK_SELECTION_XOSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC32K_Val,
  RTC_CLOCK_SELECTION_ULP1K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP1K_Val,
  RTC_CLOCK_SELECTION_ULP32K = OSC32KCTRL_RTCCTRL_RTCSEL_ULP32K_Val,
  RTC_CLOCK_SELECTION_OSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC1K_Val,
  RTC_CLOCK_SELECTION_OSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_OSC32K_Val,
  RTC_CLOCK_SELECTION_XOSC1K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC1K_Val,
  RTC_CLOCK_SELECTION_XOSC32K = OSC32KCTRL_RTCCTRL_RTCSEL_XOSC32K_Val
}
 Available clock source for RTC. More...
 
enum  rtc_count_callback {
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_0 = 0,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_1,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_2,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_3,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_4,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_5,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_6,
  RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_7,
  RTC_COUNT_CALLBACK_COMPARE_0,
  RTC_COUNT_CALLBACK_COMPARE_1,
  RTC_COUNT_CALLBACK_COMPARE_2,
  RTC_COUNT_CALLBACK_COMPARE_3,
  RTC_COUNT_CALLBACK_COMPARE_4,
  RTC_COUNT_CALLBACK_COMPARE_5,
  RTC_COUNT_CALLBACK_TAMPER,
  RTC_COUNT_CALLBACK_OVERFLOW
}
 Callback types. More...
 
enum  rtc_count_compare {
  RTC_COUNT_COMPARE_0 = 0,
  RTC_COUNT_COMPARE_1 = 1,
  RTC_COUNT_COMPARE_2 = 2,
  RTC_COUNT_COMPARE_3 = 3,
  RTC_COUNT_COMPARE_4 = 4,
  RTC_COUNT_COMPARE_5 = 5
}
 Available compare channels. More...
 
enum  rtc_count_mode {
  RTC_COUNT_MODE_16BIT = 0,
  RTC_COUNT_MODE_32BIT = 1
}
 Available operation modes for the RTC. More...
 
enum  rtc_count_periodic_interval {
  RTC_COUNT_PERIODIC_INTERVAL_0 = 0,
  RTC_COUNT_PERIODIC_INTERVAL_1 = 1,
  RTC_COUNT_PERIODIC_INTERVAL_2 = 2,
  RTC_COUNT_PERIODIC_INTERVAL_3 = 3,
  RTC_COUNT_PERIODIC_INTERVAL_4 = 4,
  RTC_COUNT_PERIODIC_INTERVAL_5 = 5,
  RTC_COUNT_PERIODIC_INTERVAL_6 = 6,
  RTC_COUNT_PERIODIC_INTERVAL_7 = 7
}
 Available periodic interval source. More...
 
enum  rtc_count_prescaler {
  RTC_COUNT_PRESCALER_OFF = RTC_MODE0_CTRLA_PRESCALER_OFF,
  RTC_COUNT_PRESCALER_DIV_1 = RTC_MODE0_CTRLA_PRESCALER_DIV1,
  RTC_COUNT_PRESCALER_DIV_2 = RTC_MODE0_CTRLA_PRESCALER_DIV2,
  RTC_COUNT_PRESCALER_DIV_4 = RTC_MODE0_CTRLA_PRESCALER_DIV4,
  RTC_COUNT_PRESCALER_DIV_8 = RTC_MODE0_CTRLA_PRESCALER_DIV8,
  RTC_COUNT_PRESCALER_DIV_16 = RTC_MODE0_CTRLA_PRESCALER_DIV16,
  RTC_COUNT_PRESCALER_DIV_32 = RTC_MODE0_CTRLA_PRESCALER_DIV32,
  RTC_COUNT_PRESCALER_DIV_64 = RTC_MODE0_CTRLA_PRESCALER_DIV64,
  RTC_COUNT_PRESCALER_DIV_128 = RTC_MODE0_CTRLA_PRESCALER_DIV128,
  RTC_COUNT_PRESCALER_DIV_256 = RTC_MODE0_CTRLA_PRESCALER_DIV256,
  RTC_COUNT_PRESCALER_DIV_512 = RTC_MODE0_CTRLA_PRESCALER_DIV512,
  RTC_COUNT_PRESCALER_DIV_1024 = RTC_MODE0_CTRLA_PRESCALER_DIV1024
}
 RTC input clock prescaler settings. More...
 

Functions

uint32_t rtc_tamper_get_stamp (struct rtc_module *const module)
 Get the tamper stamp value. More...
 
Configuration and Initialization
static void rtc_count_get_config_defaults (struct rtc_count_config *const config)
 Gets the RTC default configurations. More...
 
void rtc_count_reset (struct rtc_module *const module)
 Resets the RTC module. More...
 
void rtc_count_enable (struct rtc_module *const module)
 Enables the RTC module. More...
 
void rtc_count_disable (struct rtc_module *const module)
 Disables the RTC module. More...
 
enum status_code rtc_count_init (struct rtc_module *const module, Rtc *const hw, const struct rtc_count_config *const config)
 Initializes the RTC module with given configurations. More...
 
enum status_code rtc_count_frequency_correction (struct rtc_module *const module, const int8_t value)
 Calibrate for too-slow or too-fast oscillator. More...
 
Count and Compare Value Management
enum status_code rtc_count_set_count (struct rtc_module *const module, const uint32_t count_value)
 Set the current count value to desired value. More...
 
uint32_t rtc_count_get_count (struct rtc_module *const module)
 Get the current count value. More...
 
enum status_code rtc_count_set_compare (struct rtc_module *const module, const uint32_t comp_value, const enum rtc_count_compare comp_index)
 Set the compare value for the specified compare. More...
 
enum status_code rtc_count_get_compare (struct rtc_module *const module, uint32_t *const comp_value, const enum rtc_count_compare comp_index)
 Get the current compare value of specified compare. More...
 
enum status_code rtc_count_set_period (struct rtc_module *const module, uint16_t period_value)
 Set the given value to the period. More...
 
enum status_code rtc_count_get_period (struct rtc_module *const module, uint16_t *const period_value)
 Retrieves the value of period. More...
 
Status Management
static bool rtc_count_is_overflow (struct rtc_module *const module)
 Check if an RTC overflow has occurred. More...
 
static void rtc_count_clear_overflow (struct rtc_module *const module)
 Clears the RTC overflow flag. More...
 
static bool rtc_count_is_periodic_interval (struct rtc_module *const module, enum rtc_count_periodic_interval n)
 Check if an RTC periodic interval interrupt has occurred. More...
 
static void rtc_count_clear_periodic_interval (struct rtc_module *const module, enum rtc_count_periodic_interval n)
 Clears the RTC periodic interval flag. More...
 
bool rtc_count_is_compare_match (struct rtc_module *const module, const enum rtc_count_compare comp_index)
 Check if RTC compare match has occurred. More...
 
enum status_code rtc_count_clear_compare_match (struct rtc_module *const module, const enum rtc_count_compare comp_index)
 Clears RTC compare match flag. More...
 
Event Management
static void rtc_count_enable_events (struct rtc_module *const module, struct rtc_count_events *const events)
 Enables an RTC event output. More...
 
static void rtc_count_disable_events (struct rtc_module *const module, struct rtc_count_events *const events)
 Disables an RTC event output. More...
 
RTC General Purpose Registers
static void rtc_write_general_purpose_reg (struct rtc_module *const module, const uint8_t index, uint32_t value)
 Write a value into general purpose register. More...
 
static uint32_t rtc_read_general_purpose_reg (struct rtc_module *const module, const uint8_t index)
 Read the value from general purpose register. More...