Loading...
Searching...
No Matches
Wall-Clock Time Helper Functions

Common functions to access the wall-clock / real time clock. More...

Detailed Description

Common functions to access the wall-clock / real time clock.

         Use these functions to access system time, don't directly use the
         `periph_rtc` API.
         This allows to write applications that are independent of the RTC
         peripheral and allows the implementation of on-time change callbacks.
Note
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

Files

file  walltime.h
 

Data Structures

struct  walltime_change_sub_t
 Time change notification subscription. More...
 

Typedefs

typedef void(* walltime_change_cb_t) (void *ctx, int32_t diff_sec, int16_t diff_ms)
 Time change notification callback.
 
typedef void(* walltime_alarm_cb_t) (void *arg)
 Signature for alarm Callback.
 

Functions

void walltime_change_subscribe (walltime_change_sub_t *sub)
 Add a time change notification subscription This will be called whenever the system time changes.
 
bool walltime_change_unsubscribe (walltime_change_sub_t *sub)
 Remove a time change notification subscription.
 
int walltime_set (struct tm *time)
 Set the system date / time.
 
int walltime_get (struct tm *time, uint16_t *ms)
 Get the system date / time.
 
uint32_t walltime_get_riot (uint16_t *ms)
 Get the current system time in seconds since RIOT_EPOCH.
 
time_t walltime_get_unix (uint16_t *ms)
 Get the current system time in seconds since 01.01.1970.
 
int walltime_set_alarm (struct tm *time, walltime_alarm_cb_t cb, void *arg)
 Set an alarm for RTC to the specified value.
 
int walltime_get_alarm (struct tm *time)
 Gets the current alarm setting.
 
uint32_t walltime_uptime (bool full)
 Get seconds elapsed since last reset.
 
void walltime_impl_init (void)
 Backend implementation init, only implement when necessary.
 
int walltime_impl_set (struct tm *time)
 Backend implementation to set the system time.
 
int walltime_impl_get (struct tm *time, uint16_t *ms)
 Backend implementation to get the system time.
 
int walltime_impl_alarm_set (struct tm *time, walltime_alarm_cb_t cb, void *arg)
 Backend implementation to set the alarm.
 
int walltime_impl_alarm_get (struct tm *time)
 Gets the current alarm setting.
 

Typedef Documentation

◆ walltime_alarm_cb_t

typedef void(* walltime_alarm_cb_t) (void *arg)

Signature for alarm Callback.

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

Definition at line 50 of file walltime.h.

◆ walltime_change_cb_t

typedef void(* walltime_change_cb_t) (void *ctx, int32_t diff_sec, int16_t diff_ms)

Time change notification callback.

Parameters
[in,out]ctxUser supplied context
[in]diff_secseconds portion of the time change
[in]diff_msmillisecond portion of the time change

Definition at line 43 of file walltime.h.

Function Documentation

◆ walltime_change_subscribe()

void walltime_change_subscribe ( walltime_change_sub_t * sub)

Add a time change notification subscription This will be called whenever the system time changes.

Note
sub must remain valid as long as the subscription is active.
Parameters
[in]subThe time change notify subscription to add

◆ walltime_change_unsubscribe()

bool walltime_change_unsubscribe ( walltime_change_sub_t * sub)

Remove a time change notification subscription.

Parameters
[in]subThe time change notify subscription to remove
Return values
trueThe subscription was removed
falseThe subscription could not be found

◆ walltime_get()

int walltime_get ( struct tm * time,
uint16_t * ms )

Get the system date / time.

Parameters
[out]timecurrent time output
[out]mscurrent milliseconds output, may be NULL always returns 0 if the backend supports no millisecond resolution
Returns
0 on success
-ERANGE if the difference to the current time is too large

◆ walltime_get_alarm()

int walltime_get_alarm ( struct tm * time)

Gets the current alarm setting.

Parameters
[out]timePointer to structure to receive alarm time
Return values
0success
-EINVALno alarm is configured
<0other error (negative errno code to indicate cause)

◆ walltime_get_riot()

uint32_t walltime_get_riot ( uint16_t * ms)

Get the current system time in seconds since RIOT_EPOCH.

Parameters
[out]mscurrent milliseconds output, may be NULL always returns 0 if the backend supports no millisecond resolution
Returns
seconds since RIOT_EPOCH

◆ walltime_get_unix()

time_t walltime_get_unix ( uint16_t * ms)

Get the current system time in seconds since 01.01.1970.

Parameters
[out]mscurrent milliseconds output, may be NULL always returns 0 if the backend supports no millisecond resolution
Returns
seconds since 01.01.1970

◆ walltime_impl_alarm_get()

int walltime_impl_alarm_get ( struct tm * time)

Gets the current alarm setting.

Parameters
[out]timePointer to structure to receive alarm time
Return values
0success
-EINVALno alarm is configured
<0other error (negative errno code to indicate cause)

◆ walltime_impl_alarm_set()

int walltime_impl_alarm_set ( struct tm * time,
walltime_alarm_cb_t cb,
void * arg )

Backend implementation to set the alarm.

Note
The time value is normalized by the upper layer.
Parameters
[in]timeThe value to trigger an alarm when hit.
[in]cbCallback executed when alarm is hit. Set this to NULL to clear the alarm.
[in]argArgument passed to callback when alarm is hit.
Return values
0success
-EINVALtime was invalid (e.g. in the past, out of range)
<0other error (negative errno code to indicate cause)

◆ walltime_impl_get()

int walltime_impl_get ( struct tm * time,
uint16_t * ms )

Backend implementation to get the system time.

Parameters
[out]timecurrent time output
[out]mscurrent milliseconds output (will never be NULL)
Returns
0 on success

◆ walltime_impl_set()

int walltime_impl_set ( struct tm * time)

Backend implementation to set the system time.

Parameters
[in]timeThe current data / time to set
Returns
0 on success

◆ walltime_set()

int walltime_set ( struct tm * time)

Set the system date / time.

Parameters
[in]timeThe current data / time to set
Returns
0 on success
-ERANGE if the difference to the current time is too large

◆ walltime_set_alarm()

int walltime_set_alarm ( struct tm * time,
walltime_alarm_cb_t cb,
void * arg )

Set an alarm for RTC to the specified value.

Note
Any already set alarm will be overwritten.
Parameters
[in]timeThe value to trigger an alarm when hit.
[in]cbCallback executed when alarm is hit. Set this to NULL to clear the alarm.
[in]argArgument passed to callback when alarm is hit.
Return values
0success
-EINVALtime was invalid (e.g. in the past, out of range)
<0other error (negative errno code to indicate cause)

◆ walltime_uptime()

uint32_t walltime_uptime ( bool full)

Get seconds elapsed since last reset.

Note
The full option will only have an effect if BACKUP_RAM is available.
Parameters
[in]fullset to false to get seconds since last (warm) boot / wake-up set to true to get seconds since last cold boot / full reset