MCPcopy Create free account
hub / github.com/devkitPro/libctru / osGetTime

Function osGetTime

libctru/source/os.c:67–89  ·  view source on GitHub ↗

---------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

65
66//---------------------------------------------------------------------------------
67u64 osGetTime(void) {
68//---------------------------------------------------------------------------------
69 // Read the latest time reference point published by PTM
70 osTimeRef_s tr = osGetTimeRef();
71
72 // Calculate the time elapsed since the reference point using the system clock
73 s64 elapsed_tick = svcGetSystemTick() - tr.value_tick;
74 s64 elapsed_ms = elapsed_tick * 1000 / tr.sysclock_hz;
75
76 // Apply the drift adjustment if present:
77 // Every time PTM publishes a new reference point it measures by how long the
78 // system clock has drifted with respect to the RTC. It also recalculates the
79 // system clock frequency using RTC data in order to minimize future drift.
80 // The idea behind the following logic is to reapply the inaccuracy to the
81 // calculated timestamp, but gradually reducing it to zero over the course of
82 // an hour. This ensures the monotonic growth of the returned time value.
83 const s64 hour_in_ms = 60*60*1000; // milliseconds in an hour
84 if (tr.drift_ms != 0 && elapsed_ms < hour_in_ms)
85 elapsed_ms += tr.drift_ms * (hour_in_ms - elapsed_ms) / hour_in_ms;
86
87 // Return the final timestamp
88 return tr.value_ms + elapsed_ms;
89}
90
91//---------------------------------------------------------------------------------
92double osTickCounterRead(const TickCounter* cnt) {

Callers 3

NEWS_AddNotificationFunction · 0.85
__SYSCALL(clock_gettime)Function · 0.85
__SYSCALL(gettod_r)Function · 0.85

Calls 1

osGetTimeRefFunction · 0.85

Tested by

no test coverage detected