Common functions to access the wall-clock / real time clock.
More...
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
|
| 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.
|
| |
◆ walltime_alarm_cb_t
| typedef void(* walltime_alarm_cb_t) (void *arg) |
Signature for alarm Callback.
- Parameters
-
| [in] | arg | optional 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] | ctx | User supplied context |
| [in] | diff_sec | seconds portion of the time change |
| [in] | diff_ms | millisecond portion of the time change |
Definition at line 43 of file walltime.h.
◆ walltime_change_subscribe()
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] | sub | The time change notify subscription to add |
◆ walltime_change_unsubscribe()
Remove a time change notification subscription.
- Parameters
-
| [in] | sub | The time change notify subscription to remove |
- Return values
-
| true | The subscription was removed |
| false | The subscription could not be found |
◆ walltime_get()
| int walltime_get |
( |
struct tm * | time, |
|
|
uint16_t * | ms ) |
Get the system date / time.
- Parameters
-
| [out] | time | current time output |
| [out] | ms | current 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] | time | Pointer to structure to receive alarm time |
- Return values
-
| 0 | success |
| -EINVAL | no alarm is configured |
| <0 | other 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] | ms | current 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] | ms | current 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] | time | Pointer to structure to receive alarm time |
- Return values
-
| 0 | success |
| -EINVAL | no alarm is configured |
| <0 | other error (negative errno code to indicate cause) |
◆ walltime_impl_alarm_set()
Backend implementation to set the alarm.
- Note
- The
time value is normalized by the upper layer.
- Parameters
-
| [in] | time | The value to trigger an alarm when hit. |
| [in] | cb | Callback executed when alarm is hit. Set this to NULL to clear the alarm. |
| [in] | arg | Argument passed to callback when alarm is hit. |
- Return values
-
| 0 | success |
| -EINVAL | time was invalid (e.g. in the past, out of range) |
| <0 | other 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] | time | current time output |
| [out] | ms | current 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] | time | The current data / time to set |
- Returns
- 0 on success
◆ walltime_set()
| int walltime_set |
( |
struct tm * | time | ) |
|
Set the system date / time.
- Parameters
-
| [in] | time | The current data / time to set |
- Returns
- 0 on success
-
-ERANGE if the difference to the current time is too large
◆ walltime_set_alarm()
Set an alarm for RTC to the specified value.
- Note
- Any already set alarm will be overwritten.
- Parameters
-
| [in] | time | The value to trigger an alarm when hit. |
| [in] | cb | Callback executed when alarm is hit. Set this to NULL to clear the alarm. |
| [in] | arg | Argument passed to callback when alarm is hit. |
- Return values
-
| 0 | success |
| -EINVAL | time was invalid (e.g. in the past, out of range) |
| <0 | other 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] | full | set to false to get seconds since last (warm) boot / wake-up set to true to get seconds since last cold boot / full reset |