SceRtc

From Vita Development Wiki
Jump to navigation Jump to search

Real Time Clock.

Module

Version World Privilege
1.69-3.60 Non-secure Kernel

Libraries

Known NIDs

Version Name World Visibility NID
1.69-3.60 SceRtcForDriver Non-secure Kernel 0x0351D827
1.69-3.60 SceRtc Non-secure User 0x3503487E

Types

typedef struct SceRtcTickBase { // size is 0x28-bytes
	SceRtcTick tick_src_0;
	SceRtcTick tick_dst_0;
	int unk_0x10;
	int unk_0x14;
	int tick_flags_0;
	int unk_0x1C;
	int unk_0x20;
	int unk_0x24;
} SceRtcTickBase;

// internal use. From SceRtc_data + 0x38
typedef struct SceRtcTickContext { // size is 0x140-bytes
	SceRtcTickBase current_secure_tick;
	SceRtcTickBase current_retained_network_tick;
	SceRtcTickBase current_tool_secure_tick;
	SceRtcTickBase current_gps_tick;
	SceRtcTickBase current_debug_network_tick;
	SceRtcTickBase unk_tick_5;
	SceRtcTickBase unk_tick_6;
	SceRtcTickBase unk_tick_7;
} SceRtcTickContext;

Information

If some ticks in rtc are lower than the constant set in SceRtc, those ticks are set to 0.

constant list per fw.

Version date
1.00 - 1.67 2011/08/01
1.80 2012/06/01
2.00 - 2.xx 2012/09/01
2.50 - 3.00 2013/01/01
3.30 2014/01/01
3.50 - 3.74 2015/01/01

SceRtcForDriver

sceRtcConvertLocalTimeToUtcForDriver

Version NID
3.60 0xAD2F3544

sceRtcConvertUtcToLocalTimeForDriver

Version NID
3.60 0xC6E03DD4

sceRtcFormatRFC2822ForDriver

Version NID
3.60 0xBA3415F8

sceRtcFormatRFC2822LocalTimeForDriver

Version NID
3.60 0x1F7FC209

sceRtcFormatRFC3339ForDriver

Version NID
3.60 0xD32AC698
int sceRtcFormatRFC3339ForDriver(char *pszDateTime, const SceRtcTick *utc, int iTimeZoneMinutes);

sceRtcFormatRFC3339LocalTimeForDriver

Version NID
3.60 0x35925318

sceRtcGetAccumulativeTimeForDriver

Version NID
3.60 0x0A86FB04

sceRtcGetAlarmTickForDriver

Version NID
3.60 0xC838275A

sceRtcGetCurrentAdNetworkTickForDriver

Version NID
3.60 0x3E3C09A0

sceRtcGetCurrentClockForDriver

Version NID
3.60 0xA930CD1A

sceRtcGetCurrentClockLocalTimeForDriver

Version NID
3.60 0x7DC0DF93

sceRtcGetCurrentDebugNetworkTickForDriver

Version NID
3.60 0xC141632A

sceRtcGetCurrentGpsTickForDriver

Version NID
3.60 0xF69B610F

sceRtcGetCurrentNetworkTickForDriver

Version NID
3.60 0xF1517B38

If the current NetworkTick is less than 2015/01/01, the system will ignore the registry setting and update the NetworkTick from the internet.

int sceRtcGetCurrentNetworkTickForDriver(SceRtcTick *tick);

sceRtcGetCurrentRetainedNetworkTickForDriver

Version NID
3.60 0x40B4BCFF

sceRtcGetCurrentTickForDriver

Version NID
3.60 0xDEC408D4

sceRtcGetCurrentSecureTickForDriver

Version NID
1.03-3.60 0x401C0954

If the current SecureTick is less than 2015/01/01, it sets 0xDDDEF8B3A14000(1980/01/01 00:00:00 UTC) to the Secure Tick and returns error code 0x80251002.

int sceRtcGetCurrentSecureTickForDriver(SceRtcTick *tick);

sceRtcConvertTickToDateTimeForDriver

Version NID
1.03-3.60 0x42A0DFCB

This is a guessed name.

Used with the result of sceRtcGetCurrentSecureTickForDriver. Used by SceCoredump, SceSblGcAuthMgr.

int sceRtcConvertTickToDateTimeForDriver(SceDateTime *dst, SceRtcTick *src);

sceRtcConvertDateTimeToUnixTimeForDriver

Version NID
3.60 0x497B5DC9

This is a guessed name.

Used by SceCoredump.

int sceRtcConvertDateTimeToUnixTimeForDriver(const SceDateTime *src, SceUInt64 *dst);

SceRtcForDriver_A7236656

Version NID
3.60 0xA7236656
int SceRtcForDriver_A7236656(SceRtcTick *tick);

sceRtcGetLastAdjustedTickForDriver

Version NID
3.60 0x8A987573

sceRtcGetLastReincarnatedTickForDriver

Version NID
3.60 0x3D614A9A

sceRtcGetSecureAlarmTickForDriver

Version NID
3.60 0xBD53731C

sceRtcSynchronizeForDriver

Version NID
3.60-3.74 0xA2D280B4

Initializes SceRtc internal flags.

int sceRtcSynchronizeForDriver(void);

SceRtcForDriver_ABA035B7

Version NID
3.60 0xABA035B7

Reset all SceRtc internal flags to 0.

Returns 0.

int SceRtcForDriver_ABA035B7(void);

sceRtcGetCurrentToolSecureTickForDriver

Version NID
0.990-3.60 0xA0D7899A

This is a guessed name.

Used on Tool only. Used when checking DevKit activation license expire date.

Creates a tick using SceKernelThreadMgr#sceKernelGetSystemTimeWideForDriver.

int sceRtcGetCurrentToolSecureTickForDriver(SceRtcTick *pTick);

sceRtcIsAlarmedForDriver

Version NID
3.60 0xCD295F0C

sceRtcIsSecureAlarmedForDriver

Version NID
3.60 0xE39F2ABE

sceRtcRegisterCallbackForDriver

Version NID
3.60 0x5220870D

sceRtcRegisterSecureAlarmCallbackForDriver

Version NID
3.60 0xCF84DFC0

sceRtcSetAlarmTickForDriver

Version NID
3.60 0xD610C646

sceRtcSetConfForDriver

Version NID
3.60 0xACFE5A9F

sceRtcSetCurrentDebugNetworkTickForDriver

Version NID
3.60 0xAAB6053F

sceRtcSetCurrentNetworkTickForDriver

Version NID
3.60 0x162E486E

sceRtcSetCurrentSecureTickForDriver

Version NID
3.60 0x7D431C87

sceRtcSetCurrentTickForDriver

Version NID
3.60 0x70A78CD2

sceRtcSetSecureAlarmTickForDriver

Version NID
3.60 0x8333790D

sceRtcUnregisterCallbackForDriver

Version NID
3.60 0x9546C68B

sceRtcUnregisterSecureAlarmCallbackForDriver

Version NID
3.60 0xEDDC2325

SceRtcForDriver_9C8AF264

Version NID
0.931-3.60 0x9C8AF264

Adds time (in second) to a time structure (in nanosecond).

typedef struct SceRtcSomeTime {
    SceUInt32 time_minor; // in nanosecond
    SceUInt32 time_major; // in nanosecond
} SceRtcSomeTime;

int SceRtcForDriver_9C8AF264(SceRtcSomeTime *pDst, SceRtcSomeTime *pSrc, SceUInt32 time_minor_sec, SceUInt32 time_major_sec);

SceRtcForDriver_CE51C2A1

Version NID
0.931-3.60 0xCE51C2A1

Adds time (in microseconds) to a time structure (in nanosecond).

typedef struct SceRtcSomeTime {
    SceUInt32 time_minor; // in nanosecond
    SceUInt32 time_major; // in nanosecond
} SceRtcSomeTime;

int SceRtcForDriver_CE51C2A1(SceRtcSomeTime *pDst, SceRtcSomeTime *pSrc, SceUInt32 time_minor_usec, SceUInt32 time_major_usec);

SceRtcForDriver_0CB72FAF

Version NID
3.60 0x0CB72FAF

Used by SceCompat#sceCompatSetUpdateState.

SceRtcForDriver_FFD7A04F

Version NID
3.60 0xFFD7A04F

Used indirectly by SceProcessmgr#sceKernelLibcTime.

SceRtc

_sceRtcGetCurrentNetworkTick

Version NID
1.69-3.60 0x06F734FE

_sceRtcConvertLocalTimeToUtc

Version NID
1.69-3.60 0x0FC8AC41

_sceRtcConvertUtcToLocalTime

Version NID
1.69-3.60 0x1E61DDA4

_sceRtcGetCurrentTick

Version NID
1.69-3.60 0x247EE33B

_sceRtcGetCurrentClock

Version NID
1.69-3.60 0x24947354

sceRtcGetAccumulativeTime

Version NID
1.69-3.60 0x258BE8EC

_sceRtcFormatRFC2822

Version NID
1.69-3.60 0x2CD6AC86

_sceRtcGetCurrentGpsTick

Version NID
1.69-3.60 0x3BA820E5

_sceRtcGetCurrentClockLocalTime

Version NID
1.69-3.60 0x41A6C861

_sceRtcFormatRFC3339LocalTime

Version NID
1.69-3.60 0x4836474D

_sceRtcFormatRFC2822LocalTime

Version NID
1.69-3.60 0x4C7ED349

_sceRtcFormatRFC3339

Version NID
1.69-3.60 0x7EE2CBEF

_sceRtcGetCurrentRetainedNetworkTick

Version NID
1.69-3.60 0xC17EA809

_sceRtcGetLastReincarnatedTick

Version NID
1.69-3.60 0xE13D0FE5

_sceRtcGetLastAdjustedTick

Version NID
1.69-3.60 0xEA157EC5

_sceRtcGetCurrentAdNetworkTick

Version NID
3.60 0x76EFA8FE

_sceRtcGetCurrentDebugNetworkTick

Version NID
3.60 0xBF639B21

How to get current time and date

Getting the current time and date involves Syscon scratchpad and Syscon command 0x11. Syscon command 0x11 that returns twice the number of seconds the Syscon has been running since its power on. Syscon scratchpad at offset 0x10 contains the timestamp when syscon "started" running. It is stored in the following format: microseconds since 01/01/0001 and divided by 2^19. By adding those values together the OS obtains the current time.

In pseudocode:

last_reincarnated_tick = syscon_read_scratchpad(offset=0x10, size=5)
up_time_half_seconds = syscon_cmd_read(cmd=0x11, size=4)
UTC = timedelta(microseconds=last_reincarnated_tick * (1<<19)) + datetime(1, 1, 1) + timedelta(seconds=up_time_half_seconds*2)