See Quick start guide for RTC driver.
This is a driver implementation for the XMEGA RTC.
If current time is close to a time unit roll over, there is a risk to miss this when using a value of 0.
A safe use of this can be in an alarm callback.
Macros | |
#define | CONFIG_RTC_COMPARE_INT_LEVEL |
Configuration symbol for interrupt level to use on alarm. More... | |
#define | CONFIG_RTC_OVERFLOW_INT_LEVEL |
Configuration symbol for interrupt level to use on overflow. More... | |
#define | CONFIG_RTC_PRESCALER |
Configuration symbol for prescaler to use. More... | |
Typedefs | |
typedef void(* | rtc_callback_t )(uint32_t time) |
Callback definition for alarm callback. More... | |
Functions | |
bool | rtc_alarm_has_triggered (void) |
Check if pending alarm have triggered. More... | |
static void | rtc_disable_correction (void) |
Disable correction of RTC clock. More... | |
static void | rtc_enable_correction (void) |
Enable correction of RTC clock. More... | |
uint32_t | rtc_get_time (void) |
Get current time. More... | |
void | rtc_init (void) |
Initialize the RTC. More... | |
void | rtc_load_calibration (uint8_t error_value, uint8_t sign) |
Load Error value to RTC Calibration register with sign bit. More... | |
void | rtc_set_alarm (uint32_t time) |
Set alarm time. More... | |
static void | rtc_set_alarm_relative (uint32_t offset) |
Set alarm relative to current time. More... | |
void | rtc_set_callback (rtc_callback_t callback) |
Set callback to call on alarm. More... | |
void | rtc_set_time (uint32_t time) |
Set current time. More... | |
#define CONFIG_RTC_COMPARE_INT_LEVEL |
Configuration symbol for interrupt level to use on alarm.
Possible values:
#define CONFIG_RTC_OVERFLOW_INT_LEVEL |
Configuration symbol for interrupt level to use on overflow.
Possible values:
#define CONFIG_RTC_PRESCALER |
Configuration symbol for prescaler to use.
Possible values:
typedef void(* rtc_callback_t)(uint32_t time) |
Callback definition for alarm callback.
time | The time of the alarm |
bool rtc_alarm_has_triggered | ( | void | ) |
Check if pending alarm have triggered.
true | Alarm have triggered |
false | Alarm is pending |
References RTC_COMPARE_INT_LEVEL.
|
inlinestatic |
Disable correction of RTC clock.
|
inlinestatic |
Enable correction of RTC clock.
uint32_t rtc_get_time | ( | void | ) |
Get current time.
References rtc_data_struct::counter_high, cpu_irq_restore(), cpu_irq_save(), rtc_data, and rtc_is_busy().
Referenced by rtc_set_alarm_relative().
void rtc_init | ( | void | ) |
Initialize the RTC.
Start up the RTC and start counting from 0
References CONFIG_RTC_PRESCALER, RTC_OVERFLOW_INT_LEVEL, sleepmgr_lock_mode(), SLEEPMGR_PSAVE, sysclk_enable_module(), SYSCLK_PORT_GEN, and SYSCLK_RTC.
Referenced by main().
void rtc_load_calibration | ( | uint8_t | error_value, |
uint8_t | sign | ||
) |
Load Error value to RTC Calibration register with sign bit.
error_value | Error value for correction operation of RTC |
sign | Direction of correction or sign of correction. If this bit is LOW then the RTC counter will be slowed down by adding clocks. If this bit is HIGH, then the RTC counter will be speeded up by removing clocks |
References Assert.
void rtc_set_alarm | ( | uint32_t | time | ) |
Set alarm time.
Will set absolute alarm time that will call the callback specified by rtc_set_callback on completion. Or possibly use rtc_alarm_has_triggered to check for it.
Any pending alarm will be overwritten with this function.
time | Absolute time value. See also Minimum allowed alarm time |
References rtc_data_struct::alarm_high, rtc_data_struct::alarm_low, RTC_COMPARE_INT_LEVEL, rtc_data, rtc_is_busy(), and RTC_OVERFLOW_INT_LEVEL.
Referenced by alarm(), and rtc_set_alarm_relative().
|
inlinestatic |
Set alarm relative to current time.
offset | Offset to current time. This is minimum value, so the alarm might happen at up to one time unit later. See also Minimum allowed alarm time |
References rtc_get_time(), and rtc_set_alarm().
Referenced by main().
void rtc_set_callback | ( | rtc_callback_t | callback | ) |
Set callback to call on alarm.
callback | Callback function pointer |
References rtc_data_struct::callback, and rtc_data.
Referenced by main().
void rtc_set_time | ( | uint32_t | time | ) |
Set current time.
time | Time value to set |
References CONFIG_RTC_PRESCALER, rtc_data_struct::counter_high, rtc_data, and rtc_is_busy().