Microchip® Advanced Software Framework

rtc_calendar.h File Reference

SAM RTC Driver (Calendar Mode)

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

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

Data Structures

struct  rtc_calendar_alarm_time
 Alarm structure. More...
 
struct  rtc_calendar_config
 RTC configuration structure. More...
 
struct  rtc_calendar_events
 RTC Calendar event enable/disable structure. More...
 
struct  rtc_calendar_time
 Time structure. More...
 

Macros

#define FEATURE_RTC_PERIODIC_INT
 Define port features set according to different device family. 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_calendar_alarm {
  RTC_CALENDAR_ALARM_0 = 0,
  RTC_CALENDAR_ALARM_1 = 1,
  RTC_CALENDAR_ALARM_2 = 2,
  RTC_CALENDAR_ALARM_3 = 3
}
 Available alarm channels. More...
 
enum  rtc_calendar_alarm_mask {
  RTC_CALENDAR_ALARM_MASK_DISABLED = RTC_MODE2_MASK_SEL_OFF,
  RTC_CALENDAR_ALARM_MASK_SEC = RTC_MODE2_MASK_SEL_SS,
  RTC_CALENDAR_ALARM_MASK_MIN = RTC_MODE2_MASK_SEL_MMSS,
  RTC_CALENDAR_ALARM_MASK_HOUR = RTC_MODE2_MASK_SEL_HHMMSS,
  RTC_CALENDAR_ALARM_MASK_DAY = RTC_MODE2_MASK_SEL_DDHHMMSS,
  RTC_CALENDAR_ALARM_MASK_MONTH = RTC_MODE2_MASK_SEL_MMDDHHMMSS,
  RTC_CALENDAR_ALARM_MASK_YEAR = RTC_MODE2_MASK_SEL_YYMMDDHHMMSS
}
 Available mask options for alarms. More...
 
enum  rtc_calendar_callback {
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_0 = 0,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_1,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_2,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_3,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_4,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_5,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_6,
  RTC_CALENDAR_CALLBACK_PERIODIC_INTERVAL_7,
  RTC_CALENDAR_CALLBACK_ALARM_0,
  RTC_CALENDAR_CALLBACK_ALARM_1,
  RTC_CALENDAR_CALLBACK_ALARM_2,
  RTC_CALENDAR_CALLBACK_ALARM_3,
  RTC_CALENDAR_CALLBACK_TAMPER,
  RTC_CALENDAR_CALLBACK_OVERFLOW
}
 Callback types. More...
 
enum  rtc_calendar_periodic_interval {
  RTC_CALENDAR_PERIODIC_INTERVAL_0 = 0,
  RTC_CALENDAR_PERIODIC_INTERVAL_1 = 1,
  RTC_CALENDAR_PERIODIC_INTERVAL_2 = 2,
  RTC_CALENDAR_PERIODIC_INTERVAL_3 = 3,
  RTC_CALENDAR_PERIODIC_INTERVAL_4 = 4,
  RTC_CALENDAR_PERIODIC_INTERVAL_5 = 5,
  RTC_CALENDAR_PERIODIC_INTERVAL_6 = 6,
  RTC_CALENDAR_PERIODIC_INTERVAL_7 = 7
}
 Available periodic interval source. More...
 
enum  rtc_calendar_prescaler {
  RTC_CALENDAR_PRESCALER_OFF = RTC_MODE2_CTRLA_PRESCALER_OFF,
  RTC_CALENDAR_PRESCALER_DIV_1 = RTC_MODE2_CTRLA_PRESCALER_DIV1,
  RTC_CALENDAR_PRESCALER_DIV_2 = RTC_MODE2_CTRLA_PRESCALER_DIV2,
  RTC_CALENDAR_PRESCALER_DIV_4 = RTC_MODE2_CTRLA_PRESCALER_DIV4,
  RTC_CALENDAR_PRESCALER_DIV_8 = RTC_MODE2_CTRLA_PRESCALER_DIV8,
  RTC_CALENDAR_PRESCALER_DIV_16 = RTC_MODE2_CTRLA_PRESCALER_DIV16,
  RTC_CALENDAR_PRESCALER_DIV_32 = RTC_MODE2_CTRLA_PRESCALER_DIV32,
  RTC_CALENDAR_PRESCALER_DIV_64 = RTC_MODE2_CTRLA_PRESCALER_DIV64,
  RTC_CALENDAR_PRESCALER_DIV_128 = RTC_MODE2_CTRLA_PRESCALER_DIV128,
  RTC_CALENDAR_PRESCALER_DIV_256 = RTC_MODE2_CTRLA_PRESCALER_DIV256,
  RTC_CALENDAR_PRESCALER_DIV_512 = RTC_MODE2_CTRLA_PRESCALER_DIV512,
  RTC_CALENDAR_PRESCALER_DIV_1024 = RTC_MODE2_CTRLA_PRESCALER_DIV1024
}
 RTC input clock prescaler settings. More...
 
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...
 

Functions

void rtc_tamper_get_stamp (struct rtc_module *const module, struct rtc_calendar_time *const time)
 Get the tamper stamp value. More...
 
Configuration and Initialization
static void rtc_calendar_get_time_defaults (struct rtc_calendar_time *const time)
 Initialize a time structure. More...
 
static void rtc_calendar_get_config_defaults (struct rtc_calendar_config *const config)
 Gets the RTC default settings. More...
 
void rtc_calendar_reset (struct rtc_module *const module)
 Resets the RTC module. More...
 
void rtc_calendar_enable (struct rtc_module *const module)
 Enables the RTC module. More...
 
void rtc_calendar_disable (struct rtc_module *const module)
 Disables the RTC module. More...
 
void rtc_calendar_init (struct rtc_module *const module, Rtc *const hw, const struct rtc_calendar_config *const config)
 Initializes the RTC module with given configurations. More...
 
void rtc_calendar_swap_time_mode (struct rtc_module *const module)
 Swaps between 12h and 24h clock mode. More...
 
enum status_code rtc_calendar_frequency_correction (struct rtc_module *const module, const int8_t value)
 Calibrate for too-slow or too-fast oscillator. More...
 
Time and Alarm Management
uint32_t rtc_calendar_time_to_register_value (struct rtc_module *const module, const struct rtc_calendar_time *const time)
 Convert time structure to register_value. More...
 
void rtc_calendar_register_value_to_time (struct rtc_module *const module, const uint32_t register_value, struct rtc_calendar_time *const time)
 Convert register_value to time structure. More...
 
void rtc_calendar_set_time (struct rtc_module *const module, const struct rtc_calendar_time *const time)
 Set the current calendar time to desired time. More...
 
void rtc_calendar_get_time (struct rtc_module *const module, struct rtc_calendar_time *const time)
 Get the current calendar value. More...
 
enum status_code rtc_calendar_set_alarm (struct rtc_module *const module, const struct rtc_calendar_alarm_time *const alarm, const enum rtc_calendar_alarm alarm_index)
 Set the alarm time for the specified alarm. More...
 
enum status_code rtc_calendar_get_alarm (struct rtc_module *const module, struct rtc_calendar_alarm_time *const alarm, const enum rtc_calendar_alarm alarm_index)
 Get the current alarm time of specified alarm. More...
 
Status Flag Management
static bool rtc_calendar_is_overflow (struct rtc_module *const module)
 Check if an RTC overflow has occurred. More...
 
static void rtc_calendar_clear_overflow (struct rtc_module *const module)
 Clears the RTC overflow flag. More...
 
static bool rtc_calendar_is_periodic_interval (struct rtc_module *const module, enum rtc_calendar_periodic_interval n)
 Check if an RTC periodic interval interrupt has occurred. More...
 
static void rtc_calendar_clear_periodic_interval (struct rtc_module *const module, enum rtc_calendar_periodic_interval n)
 Clears the RTC periodic interval flag. More...
 
static bool rtc_calendar_is_alarm_match (struct rtc_module *const module, const enum rtc_calendar_alarm alarm_index)
 Check the RTC alarm flag. More...
 
static enum status_code rtc_calendar_clear_alarm_match (struct rtc_module *const module, const enum rtc_calendar_alarm alarm_index)
 Clears the RTC alarm match flag. More...
 
Event Management
static void rtc_calendar_enable_events (struct rtc_module *const module, struct rtc_calendar_events *const events)
 Enables an RTC event output. More...
 
static void rtc_calendar_disable_events (struct rtc_module *const module, struct rtc_calendar_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...