KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Real-Time Clock

Real-Time Clock (RTC) Management More...

Files

file  rtc.h
 Low-level real-time clock functionality.
 
file  rtc.h
 Low-level real-time clock functionality.
 

Functions

static time_t rtc_unix_secs (void)
 Get the current date/time.
 
static int rtc_set_unix_secs (time_t time)
 Set the current date/time.
 
static time_t rtc_boot_time (void)
 Get the time since the system was booted.
 

Detailed Description

Real-Time Clock (RTC) Management

Provides an API for fetching and managing the date/time using the hardware real-time clock (RTC). All timestamps are in standard Unix format, with an epoch of January 1, 1970. Due to the fact that there is no time zone data on the RTC, all times are expected to be in the local time zone.

Note
For reading the current date/time, you should favor the standard C, C++, or POSIX functions, as they are platform-indpendent and are calculating current time based on a cached boot time plus a delta that is maintained by the timer subsystem, rather than actually having to requery the RTC, so they are faster.
See also
Watchdog Timer, Timer Unit, Performance Counters

Function Documentation

◆ rtc_boot_time()

static time_t rtc_boot_time ( void )
inlinestatic

Get the time since the system was booted.

This function retrieves the cached RTC value from when KallistiOS was started. As with rtc_unix_secs(), this is a UNIX-style timestamp in local time.

Returns
The boot time as a UNIX-style timestamp.

◆ rtc_set_unix_secs()

static int rtc_set_unix_secs ( time_t time)
inlinestatic

Set the current date/time.

This function sets the current RTC value as a standard UNIX timestamp (with an epoch of January 1, 1970 00:00). This is assumed to be in the timezone of the user (as the RTC does not support timezones).

Warning
This function may fail! Since time_t is typically 64-bit while the RTC uses a 32-bit timestamp (which also has a different epoch), not all time_t values can be represented within the RTC!
Parameters
timeUnix timestamp to set the current time to
Returns
0 for success or -1 for failure (with errno set appropriately).
Exceptions
EINVALtime was an invalid timestamp or could not be represented on the hardware RTC.
EPERMFailed to set and successfully read back time from the RTC.
See also
rtc_unix_secs()

Referenced by main().

◆ rtc_unix_secs()

static time_t rtc_unix_secs ( void )
inlinestatic

Get the current date/time.

This function retrieves the current RTC value as a standard UNIX timestamp (with an epoch of January 1, 1970 00:00). This is assumed to be in the timezone of the user (as the RTC does not support timezones).

Returns
The current UNIX-style timestamp (local time).
See also
rtc_set_unix_secs()

Referenced by main().