Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SAM RTC Count (RTC COUNT) Driver

This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Real Time Clock functionality in Count operating mode, for the configuration and retrieval of the current RTC counter value.

The following driver API modes are covered by this manual:

The following peripheral is used by this module:

The following devices can use this module:

The outline of this documentation is as follows:

Prerequisites

There are no prerequisites for this module.

Module Overview

The RTC module in the SAM devices is a 32-bit counter, with a 10-bit programmable prescaler. Typically, the RTC clock is run continuously, including in the device's low-power sleep modes, to track the current time and date information. The RTC can be used as a source to wake up the system at a scheduled time or periodically using the alarm functions.

In this driver, the RTC is operated in Count mode. This allows for an easy integration of an asynchronous counter into a user application, which is capable of operating while the device is in sleep mode.

Whilst operating in Count mode, the RTC features:

Driver Feature Macro Definition

Driver Feature Macro Supported devices
FEATURE_RTC_PERIODIC_INT SAM L21/L22/C20/C21/R30
FEATURE_RTC_PRESCALER_OFF SAM L21/L22/C20/C21/R30
FEATURE_RTC_CLOCK_SELECTION SAM L21/L22/C20/C21/R30
FEATURE_RTC_GENERAL_PURPOSE_REG SAM L21/L22/R30
FEATURE_RTC_CONTINUOUSLY_UPDATED SAM D20, SAM D21, SAM R21, SAM D10, SAM D11, SAM DA1, SAM HA1
FEATURE_RTC_TAMPER_DETECTION SAM L22
Note
The specific features are only available in the driver when the selected device supports those features.

Compare and Overflow

The RTC can be used with up to 4/6 compare values (depending on selected operation mode). These compare values will trigger on match with the current RTC counter value, and can be set up to trigger an interrupt, event, or both. The RTC can also be configured to clear the counter value on compare match in 32-bit mode, resetting the count value back to zero.

If the RTC is operated without the Clear on Match option enabled, or in 16-bit mode, the RTC counter value will instead be cleared on overflow once the maximum count value has been reached:

\[ COUNT_{MAX} = 2^{32}-1 \]

for 32-bit counter mode, and

\[ COUNT_{MAX} = 2^{16}-1 \]

for 16-bit counter mode.

When running in 16-bit mode, the overflow value is selectable with a period value. The counter overflow will then occur when the counter value reaches the specified period value.

Periodic Events

The RTC can generate events at periodic intervals, allowing for direct peripheral actions without CPU intervention. The periodic events can be generated on the upper eight bits of the RTC prescaler, and will be generated on the rising edge transition of the specified bit. The resulting periodic frequency can be calculated by the following formula:

\[ f_{PERIODIC}=\frac{f_{ASY}}{2^{n+3}} \]

Where \(f_{ASY}\) refers to the asynchronous clock is set up in the RTC module configuration. The n parameter is the event source generator index of the RTC module. If the asynchronous clock is operated at the recommended frequency of 1KHz, the formula results in the values shown in the table below.

RTC Event Frequencies for Each Prescaler Bit Using a 1KHz Clock
n Periodic event
7 1Hz
6 2Hz
5 4Hz
4 8Hz
3 16Hz
2 32Hz
1 64Hz
0 128Hz
Note
The connection of events between modules requires the use of the SAM Event System (EVENTS) Driver to route output event of one module to the the input event of another. For more information on event routing, refer to the event driver documentation.

Digital Frequency Correction

The RTC module contains Digital Frequency Correction logic to compensate for inaccurate source clock frequencies which would otherwise result in skewed time measurements. The correction scheme requires that at least two bits in the RTC module prescaler are reserved by the correction logic. As a result of this implementation, frequency correction is only available when the RTC is running from a 1Hz reference clock.

The correction procedure is implemented by subtracting or adding a single cycle from the RTC prescaler every 1024 RTC GCLK cycles. The adjustment is applied the specified number of time (maximum 127) over 976 of these periods. The corresponding correction in PPM will be given by:

\[ Correction(PPM) = \frac{VALUE}{999424}10^6 \]

The RTC clock will tick faster if provided with a positive correction value, and slower when given a negative correction value.

RTC Tamper Detect

see RTC Tamper Detect

Special Considerations

Clock Setup

SAM D20/D21/R21/D10/D11/DA1/HA1 Clock Setup

The RTC is typically clocked by a specialized GCLK generator that has a smaller prescaler than the others. By default the RTC clock is on, selected to use the internal 32KHz RC-oscillator with a prescaler of 32, giving a resulting clock frequency of 1KHz to the RTC. When the internal RTC prescaler is set to 1024, this yields an end-frequency of 1Hz.

The implementer also has the option to set other end-frequencies. The table below lists the available RTC frequencies for each possible GCLK and RTC input prescaler options.

RTC Output Frequencies from Allowable Input Clocks
End-frequency GCLK prescaler RTC prescaler
32KHz 1 1
1KHz 32 1
1Hz 32 1024

The overall RTC module clocking scheme is shown in the figure below.

SAM L21/C20/C21/R30 Clock Setup

The RTC clock can be selected from OSC32K, XOSC32K, or OSCULP32K, and a 32KHz or 1KHz oscillator clock frequency is required. This clock must be configured and enabled in the 32KHz oscillator controller before using the RTC.

The table below lists the available RTC clock asfdoc_sam0_rtc_count_rtc_clk.

RTC Clocks Source
RTC clock frequency Clock source Description
1.024KHz ULP1K 1.024KHz from 32KHz internal ULP oscillator
32.768KHz ULP32K 32.768KHz from 32KHz internal ULP oscillator
1.024KHz OSC1K 1.024KHz from 32KHz internal oscillator
32.768KHz OSC32K 32.768KHz from 32KHz internal oscillator
1.024KHz XOSC1K 1.024KHz from 32KHz internal oscillator
32.768KHz XOSC32K 32.768KHz from 32KHz external crystal oscillator

Extra Information

For extra information, see Extra Information for RTC COUNT Driver. This includes:

Examples

For a list of examples related to this driver, see Examples for RTC (COUNT) Driver.

API Overview

Modules

 

Data Structures

struct  rtc_count_config
 RTC Count configuration structure. More...
 
struct  rtc_count_events
 RTC Count event enable/disable structure. 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...
 

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...
 

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)
 
void rtc_count_enable (struct rtc_module *const module)
 
void rtc_count_disable (struct rtc_module *const module)
 
enum status_code rtc_count_init (struct rtc_module *const module, Rtc *const hw, const struct rtc_count_config *const config)
 
enum status_code rtc_count_frequency_correction (struct rtc_module *const module, const int8_t value)
 

Count and Compare Value Management

enum status_code rtc_count_set_count (struct rtc_module *const module, const uint32_t count_value)
 
uint32_t rtc_count_get_count (struct rtc_module *const module)
 
enum status_code rtc_count_set_compare (struct rtc_module *const module, const uint32_t comp_value, const enum rtc_count_compare comp_index)
 
enum status_code rtc_count_get_compare (struct rtc_module *const module, uint32_t *const comp_value, const enum rtc_count_compare comp_index)
 
enum status_code rtc_count_set_period (struct rtc_module *const module, uint16_t period_value)
 
enum status_code rtc_count_get_period (struct rtc_module *const module, uint16_t *const period_value)
 

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)
 
enum status_code rtc_count_clear_compare_match (struct rtc_module *const module, const enum rtc_count_compare comp_index)
 

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...
 

Callbacks

enum status_code rtc_count_register_callback (struct rtc_module *const module, rtc_count_callback_t callback, enum rtc_count_callback callback_type)
 
enum status_code rtc_count_unregister_callback (struct rtc_module *const module, enum rtc_count_callback callback_type)
 
void rtc_count_enable_callback (struct rtc_module *const module, enum rtc_count_callback callback_type)
 
void rtc_count_disable_callback (struct rtc_module *const module, enum rtc_count_callback callback_type)
 

#define FEATURE_RTC_CLOCK_SELECTION

RTC clock selection.

#define FEATURE_RTC_GENERAL_PURPOSE_REG

General purpose registers.

#define FEATURE_RTC_PERIODIC_INT

RTC periodic interval interrupt.

#define FEATURE_RTC_PRESCALER_OFF

RTC prescaler is off.

#define FEATURE_RTC_TAMPER_DETECTION

RTC tamper detection.

Available clock source for RTC.

RTC clock source.

Enumerator
RTC_CLOCK_SELECTION_ULP1K 

1.024kHz from 32KHz internal ULP oscillator

RTC_CLOCK_SELECTION_ULP32K 

32.768kHz from 32KHz internal ULP oscillator

RTC_CLOCK_SELECTION_OSC1K 

1.024kHz from 32KHz internal oscillator

RTC_CLOCK_SELECTION_OSC32K 

32.768kHz from 32KHz internal oscillator

RTC_CLOCK_SELECTION_XOSC1K 

1.024kHz from 32KHz internal oscillator

RTC_CLOCK_SELECTION_XOSC32K 

32.768kHz from 32.768kHz external crystal oscillator

RTC_CLOCK_SELECTION_ULP1K 

1.024KHz from 32KHz internal ULP oscillator

RTC_CLOCK_SELECTION_ULP32K 

32.768KHz from 32KHz internal ULP oscillator

RTC_CLOCK_SELECTION_OSC1K 

1.024KHz from 32KHz internal oscillator

RTC_CLOCK_SELECTION_OSC32K 

32.768KHz from 32KHz internal oscillator

RTC_CLOCK_SELECTION_XOSC1K 

1.024KHz from 32KHz external oscillator

RTC_CLOCK_SELECTION_XOSC32K 

32.768KHz from 32.768KHz external crystal oscillator

Callback types.

The available callback types for the RTC count module.

Enumerator
RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_0 

Callback for Periodic Interval 0 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_1 

Callback for Periodic Interval 1 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_2 

Callback for Periodic Interval 2 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_3 

Callback for Periodic Interval 3 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_4 

Callback for Periodic Interval 4 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_5 

Callback for Periodic Interval 5 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_6 

Callback for Periodic Interval 6 Interrupt.

RTC_COUNT_CALLBACK_PERIODIC_INTERVAL_7 

Callback for Periodic Interval 7 Interrupt.

RTC_COUNT_CALLBACK_COMPARE_0 

Callback for compare channel 0.

RTC_COUNT_CALLBACK_COMPARE_1 

Callback for compare channel 1.

RTC_COUNT_CALLBACK_COMPARE_2 

Callback for compare channel 2.

RTC_COUNT_CALLBACK_COMPARE_3 

Callback for compare channel 3.

RTC_COUNT_CALLBACK_COMPARE_4 

Callback for compare channel 4.

RTC_COUNT_CALLBACK_COMPARE_5 

Callback for compare channel 5.

RTC_COUNT_CALLBACK_TAMPER 

Callback for tamper.

RTC_COUNT_CALLBACK_OVERFLOW 

Callback for overflow.

Available compare channels.

Note
Not all compare channels are available in all devices and modes.
Enumerator
RTC_COUNT_COMPARE_0 

Compare channel 0.

RTC_COUNT_COMPARE_1 

Compare channel 1.

RTC_COUNT_COMPARE_2 

Compare channel 2.

RTC_COUNT_COMPARE_3 

Compare channel 3.

RTC_COUNT_COMPARE_4 

Compare channel 4.

RTC_COUNT_COMPARE_5 

Compare channel 5.

Available operation modes for the RTC.

RTC Count operating modes, to select the counting width and associated module operation.

Enumerator
RTC_COUNT_MODE_16BIT 

RTC Count module operates in 16-bit mode.

RTC_COUNT_MODE_32BIT 

RTC Count module operates in 32-bit mode.

Available periodic interval source.

Enumerator
RTC_COUNT_PERIODIC_INTERVAL_0 

Periodic interval 0.

RTC_COUNT_PERIODIC_INTERVAL_1 

Periodic interval 1.

RTC_COUNT_PERIODIC_INTERVAL_2 

Periodic interval 2.

RTC_COUNT_PERIODIC_INTERVAL_3 

Periodic interval 3.

RTC_COUNT_PERIODIC_INTERVAL_4 

Periodic interval 4.

RTC_COUNT_PERIODIC_INTERVAL_5 

Periodic interval 5.

RTC_COUNT_PERIODIC_INTERVAL_6 

Periodic interval 6.

RTC_COUNT_PERIODIC_INTERVAL_7 

Periodic interval 7.

RTC input clock prescaler settings.

The available input clock prescaler values for the RTC count module.

Enumerator
RTC_COUNT_PRESCALER_OFF 

RTC prescaler is off, and the input clock frequency is prescaled by a factor of 1.

RTC_COUNT_PRESCALER_DIV_1 

RTC input clock frequency is prescaled by a factor of 1.

RTC_COUNT_PRESCALER_DIV_2 

RTC input clock frequency is prescaled by a factor of 2.

RTC_COUNT_PRESCALER_DIV_4 

RTC input clock frequency is prescaled by a factor of 4.

RTC_COUNT_PRESCALER_DIV_8 

RTC input clock frequency is prescaled by a factor of 8.

RTC_COUNT_PRESCALER_DIV_16 

RTC input clock frequency is prescaled by a factor of 16.

RTC_COUNT_PRESCALER_DIV_32 

RTC input clock frequency is prescaled by a factor of 32.

RTC_COUNT_PRESCALER_DIV_64 

RTC input clock frequency is prescaled by a factor of 64.

RTC_COUNT_PRESCALER_DIV_128 

RTC input clock frequency is prescaled by a factor of 128.

RTC_COUNT_PRESCALER_DIV_256 

RTC input clock frequency is prescaled by a factor of 256.

RTC_COUNT_PRESCALER_DIV_512 

RTC input clock frequency is prescaled by a factor of 512.

RTC_COUNT_PRESCALER_DIV_1024 

RTC input clock frequency is prescaled by a factor of 1024.

enum status_code rtc_count_clear_compare_match ( struct rtc_module *const  module,
const enum rtc_count_compare  comp_index 
)
static void rtc_count_clear_overflow ( struct rtc_module *const  module)
inlinestatic

Clears the RTC overflow flag.

Clears the RTC module counter overflow flag, so that new overflow conditions can be detected.

Parameters
[in,out]moduleRTC hardware module

References Assert.

Referenced by run_rtc_count_test().

static void rtc_count_clear_periodic_interval ( struct rtc_module *const  module,
enum rtc_count_periodic_interval  n 
)
inlinestatic

Clears the RTC periodic interval flag.

Clears the RTC module counter periodic interval flag, so that new periodic interval conditions can be detected.

Parameters
[in,out]moduleRTC hardware module
[in]nRTC periodic interval interrupt

References Assert.

void rtc_count_disable_callback ( struct rtc_module *const  module,
enum rtc_count_callback  callback_type 
)
static void rtc_count_disable_events ( struct rtc_module *const  module,
struct rtc_count_events *const  events 
)
inlinestatic

Disables an RTC event output.

Disabled one or more output events from the RTC module. See rtc_count_events for a list of events this module supports.

Note
Events cannot be altered while the module is enabled.
Parameters
[in,out]moduleRTC hardware module
[in]eventsStruct containing flags of events to disable

References Assert, rtc_count_events::generate_event_on_compare, rtc_count_events::generate_event_on_overflow, rtc_count_events::generate_event_on_periodic, rtc_count_events::generate_event_on_tamper, i, and rtc_count_events::on_event_to_tamper.

void rtc_count_enable_callback ( struct rtc_module *const  module,
enum rtc_count_callback  callback_type 
)
static void rtc_count_enable_events ( struct rtc_module *const  module,
struct rtc_count_events *const  events 
)
inlinestatic

Enables an RTC event output.

Enables one or more output events from the RTC module. See rtc_count_events for a list of events this module supports.

Note
Events cannot be altered while the module is enabled.
Parameters
[in,out]moduleRTC hardware module
[in]eventsStruct containing flags of events to enable

References Assert, rtc_count_events::generate_event_on_compare, rtc_count_events::generate_event_on_overflow, rtc_count_events::generate_event_on_periodic, rtc_count_events::generate_event_on_tamper, i, and rtc_count_events::on_event_to_tamper.

Referenced by rtc_setup(), and test_event_gen_user_init().

enum status_code rtc_count_frequency_correction ( struct rtc_module *const  module,
const int8_t  value 
)
enum status_code rtc_count_get_compare ( struct rtc_module *const  module,
uint32_t *const  comp_value,
const enum rtc_count_compare  comp_index 
)

Referenced by run_rtc_count_test().

static void rtc_count_get_config_defaults ( struct rtc_count_config *const  config)
inlinestatic

Gets the RTC default configurations.

Initializes the configuration structure to default values. This function should be called at the start of any RTC initialization.

The default configuration is:

  • Input clock divided by a factor of 1024
  • RTC in 32-bit mode
  • Clear on compare match off
  • Continuously sync count register off
  • No event source on
  • All compare values equal 0
  • Count read synchronization is enabled for SAM L22
Parameters
[out]configConfiguration structure to be initialized to default values

References Assert, rtc_count_config::clear_on_match, rtc_count_config::compare_values, i, rtc_count_config::mode, rtc_count_config::prescaler, RTC_COUNT_MODE_32BIT, and RTC_COUNT_PRESCALER_DIV_1024.

Referenced by configure_rtc_count(), rtc_setup(), run_rtc_count_test(), and test_event_gen_user_init().

uint32_t rtc_count_get_count ( struct rtc_module *const  module)
enum status_code rtc_count_get_period ( struct rtc_module *const  module,
uint16_t *const  period_value 
)

Referenced by run_rtc_count_test().

enum status_code rtc_count_init ( struct rtc_module *const  module,
Rtc *const  hw,
const struct rtc_count_config *const  config 
)
bool rtc_count_is_compare_match ( struct rtc_module *const  module,
const enum rtc_count_compare  comp_index 
)

Referenced by main(), and run_rtc_count_test().

static bool rtc_count_is_overflow ( struct rtc_module *const  module)
inlinestatic

Check if an RTC overflow has occurred.

Checks the overflow flag in the RTC. The flag is set when there is an overflow in the clock.

Parameters
[in,out]moduleRTC hardware module
Returns
Overflow state of the RTC module.
Return values
trueIf the RTC count value has overflowed
falseIf the RTC count value has not overflowed

References Assert.

Referenced by run_rtc_count_test().

static bool rtc_count_is_periodic_interval ( struct rtc_module *const  module,
enum rtc_count_periodic_interval  n 
)
inlinestatic

Check if an RTC periodic interval interrupt has occurred.

Checks the periodic interval flag in the RTC.

Parameters
[in,out]moduleRTC hardware module
[in]nRTC periodic interval interrupt
Returns
Periodic interval interrupt state of the RTC module.
Return values
trueRTC periodic interval interrupt occurs
falseRTC periodic interval interrupt doesn't occur

References Assert.

enum status_code rtc_count_register_callback ( struct rtc_module *const  module,
rtc_count_callback_t  callback,
enum rtc_count_callback  callback_type 
)
void rtc_count_reset ( struct rtc_module *const  module)
enum status_code rtc_count_set_compare ( struct rtc_module *const  module,
const uint32_t  comp_value,
const enum rtc_count_compare  comp_index 
)
enum status_code rtc_count_set_count ( struct rtc_module *const  module,
const uint32_t  count_value 
)
enum status_code rtc_count_set_period ( struct rtc_module *const  module,
uint16_t  period_value 
)
enum status_code rtc_count_unregister_callback ( struct rtc_module *const  module,
enum rtc_count_callback  callback_type 
)
static uint32_t rtc_read_general_purpose_reg ( struct rtc_module *const  module,
const uint8_t  index 
)
inlinestatic

Read the value from general purpose register.

Parameters
[in]modulePointer to the software instance struct
[in]indexGeneral purpose register index (0..3)
Returns
Value of general purpose register.

References Assert.

uint32_t rtc_tamper_get_stamp ( struct rtc_module *const  module)

Get the tamper stamp value.

Parameters
[in,out]modulePointer to the software instance struct
Returns
The current tamper stamp value as a 32-bit unsigned integer.
static void rtc_write_general_purpose_reg ( struct rtc_module *const  module,
const uint8_t  index,
uint32_t  value 
)
inlinestatic

Write a value into general purpose register.

Parameters
[in]modulePointer to the software instance struct
[in]nGeneral purpose type
[in]indexGeneral purpose register index (0..3)

References Assert.