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.
 

Functions

time_t rtc_unix_secs (void)
 Get the current date/time.
 
int rtc_set_unix_secs (time_t time)
 Set the current date/time.
 
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 Dreamcast's real-time clock. 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
The RTC that is used by the DC is located on the AICA rather than SH4, presumably for power-efficiency reasons. Because of this, accessing it requires a trip over the G2 BUS, which is notoriously slow.
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 over the G2 BUS, so they are faster.
Warning
Internally, the RTC's date/time is maintained using a 32-bit counter with an epoch of January 1, 1950 00:00. Because of this, the Dreamcast's Y2K and the last timestamp it can represent before rolling over is February 06 2086 06:28:15.
See also
Watchdog Timer, Timer Unit, Performance Counters

Function Documentation

◆ rtc_boot_time()

time_t rtc_boot_time ( void )

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()

int rtc_set_unix_secs ( time_t time)

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 AICA's RTC.
EPERMFailed to set and successfully read back time from the RTC.
See also
rtc_unix_secs()

◆ rtc_unix_secs()

time_t rtc_unix_secs ( void )

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()