Low-level RTC (Real Time Clock) peripheral driver. More...

Detailed Description

Low-level RTC (Real Time Clock) peripheral driver.

The values used for setting and getting the time/alarm should conform to the struct tm specification. Compare: http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html

(Low-) Power Implications

After the RTC has been initialized (i.e. after calling rtc_init()), the RTC should be powered on and running. The RTC can then be powered off manually at a later point in time by calling the rtc_poweroff() function. When the RTC is powered back on using the rtc_poweron() function, it should transparently continue its previously configured operation.

On many CPUs, certain power states might need to be blocked in rtc_init(), so that it is ensured that the RTC will function properly while it is enabled.


file  rtc.h
 Low-level RTC peripheral driver interface definitions.


typedef void(* rtc_alarm_cb_t) (void *arg)
 Signature for alarm Callback. More...


void rtc_init (void)
 Initialize RTC module.
int rtc_set_time (struct tm *time)
 Set RTC to given time. More...
int rtc_get_time (struct tm *time)
 Get current RTC time. More...
int rtc_set_alarm (struct tm *time, rtc_alarm_cb_t cb, void *arg)
 Set an alarm for RTC to the specified value. More...
int rtc_get_alarm (struct tm *time)
 Gets the current alarm setting. More...
void rtc_clear_alarm (void)
 Clear any set alarm, do nothing if nothing set.
void rtc_poweron (void)
 Turns the RTC hardware module on.
void rtc_poweroff (void)
 Turns the RTC hardware module off.
void rtc_tm_normalize (struct tm *time)
 Normalize the time struct. More...
int rtc_tm_compare (const struct tm *a, const struct tm *b)
 Compare two time structs. More...

Typedef Documentation

◆ rtc_alarm_cb_t

typedef void(* rtc_alarm_cb_t) (void *arg)

Signature for alarm Callback.

[in]argoptional argument to put the callback in the right context

Definition at line 52 of file rtc.h.

Function Documentation

◆ rtc_get_alarm()

int rtc_get_alarm ( struct tm time)

Gets the current alarm setting.

[out]timePointer to structure to receive alarm time
0 for success
-1 an error occurred

◆ rtc_get_time()

int rtc_get_time ( struct tm time)

Get current RTC time.

[out]timePointer to the struct to write the time to.
0 for success
-1 an error occurred

◆ rtc_set_alarm()

int rtc_set_alarm ( struct tm time,
rtc_alarm_cb_t  cb,
void *  arg 

Set an alarm for RTC to the specified value.

Any already set alarm will be overwritten.
[in]timeThe value to trigger an alarm when hit.
[in]cbCallback executed when alarm is hit.
[in]argArgument passed to callback when alarm is hit.
0 for success
-2 invalid time parameter
-1 other errors

◆ rtc_set_time()

int rtc_set_time ( struct tm time)

Set RTC to given time.

[in]timePointer to the struct holding the time to set.
0 for success
-1 an error occurred

◆ rtc_tm_compare()

int rtc_tm_compare ( const struct tm a,
const struct tm b 

Compare two time structs.

The time structs a and b are assumed to be normalized. Use rtc_tm_normalize to normalize a struct tm that has been manually edited.
[in]aThe first time struct.
[in]bThe second time struct.
an integer < 0 if a is earlier than b
an integer > 0 if a is later than b
0 if a and b are equal

◆ rtc_tm_normalize()

void rtc_tm_normalize ( struct tm time)

Normalize the time struct.

The function modifies the fields of the tm structure as follows: If structure members are outside their valid interval, they will be normalized. So that, for example, 40 October is changed into 9 November.

If RTC_NORMALIZE_COMPAT is 1 tm_wday and tm_yday are set to values determined from the contents of the other fields.

timePointer to the struct to normalize.