mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-05 03:04:16 +01:00
Improve time conversion macros.
This commit is contained in:
parent
23c56959b3
commit
2b165bf887
@ -16,12 +16,13 @@ typedef struct OSSystemInfo OSSystemInfo;
|
||||
|
||||
struct OSSystemInfo
|
||||
{
|
||||
uint32_t clockSpeed;
|
||||
UNKNOWN(0x4);
|
||||
uint32_t busClockSpeed;
|
||||
uint32_t coreClockSpeed;
|
||||
OSTime baseTime;
|
||||
UNKNOWN(0x10);
|
||||
};
|
||||
CHECK_OFFSET(OSSystemInfo, 0x0, clockSpeed);
|
||||
CHECK_OFFSET(OSSystemInfo, 0x0, busClockSpeed);
|
||||
CHECK_OFFSET(OSSystemInfo, 0x4, coreClockSpeed);
|
||||
CHECK_OFFSET(OSSystemInfo, 0x8, baseTime);
|
||||
CHECK_SIZE(OSSystemInfo, 0x20);
|
||||
|
||||
|
@ -42,11 +42,17 @@ CHECK_OFFSET(OSCalendarTime, 0x20, tm_msec);
|
||||
CHECK_OFFSET(OSCalendarTime, 0x24, tm_usec);
|
||||
CHECK_SIZE(OSCalendarTime, 0x28);
|
||||
|
||||
#define OSOneSecond ((OSGetSystemInfo()->clockSpeed) / 4)
|
||||
#define OSSeconds(val) (((uint64_t)(val)) * (uint64_t)(OSOneSecond))
|
||||
#define OSMilliseconds(val) ((((uint64_t)(val)) * (uint64_t)(OSOneSecond)) / 1000ull)
|
||||
#define OSMicroseconds(val) ((((uint64_t)(val)) * (uint64_t)(OSOneSecond)) / 1000000ull)
|
||||
#define OSNanoseconds(val) ((((uint64_t)(val)) * (uint64_t)(OSOneSecond)) / 1000000000ull)
|
||||
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
|
||||
|
||||
#define OSSecondsToTicks(val) ((uint64_t)(val) * (uint64_t)OSTimerClockSpeed)
|
||||
#define OSMillisecondsToTicks(val) (((uint64_t)(val) * (uint64_t)OSTimerClockSpeed) / 1000ull)
|
||||
#define OSMicrosecondsToTicks(val) (((uint64_t)(val) * (uint64_t)OSTimerClockSpeed) / 1000000ull)
|
||||
#define OSNanosecondsToTicks(val) (((uint64_t)(val) * ((uint64_t)OSTimerClockSpeed) / 31250ull) / 32000ull)
|
||||
|
||||
#define OSTicksToSeconds(val) ((uint64_t)(val) / (uint64_t)OSTimerClockSpeed)
|
||||
#define OSTicksToMilliseconds(val) (((uint64_t)(val) * 1000ull) / (uint64_t)OSTimerClockSpeed)
|
||||
#define OSTicksToMicroseconds(val) (((uint64_t)(val) * 1000000ull) / (uint64_t)OSTimerClockSpeed)
|
||||
#define OSTicksToNanoseconds(val) (((uint64_t)(val) * 32000ull) / ((uint64_t)OSTimerClockSpeed / 31250ull))
|
||||
|
||||
OSTime
|
||||
OSGetTime();
|
||||
|
@ -180,7 +180,7 @@ getRegisters(OSContext *context)
|
||||
writeRegister("\n--Per-core OSContext runtime ----\n");
|
||||
for (i = 0; i < 3; ++i) {
|
||||
writeRegister("coretime[%d] = 0x%016llX ticks, %lld second(s) elapsed\n",
|
||||
i, context->coretime[i], context->coretime[i] / OSOneSecond);
|
||||
i, context->coretime[i], OSTicksToSeconds(context->coretime[i]));
|
||||
}
|
||||
|
||||
writeRegister("\n--FPRs----------\n");
|
||||
|
@ -75,7 +75,7 @@ __wut_cond_timedwait(OSCondition *cond, OSMutex *mutex,
|
||||
OSAlarm alarm;
|
||||
OSCreateAlarm(&alarm);
|
||||
OSSetAlarmUserData(&alarm, &data);
|
||||
OSSetAlarm(&alarm, OSNanoseconds(duration.count()),
|
||||
OSSetAlarm(&alarm, OSNanosecondsToTicks(duration.count()),
|
||||
&__wut_cond_timedwait_alarm_callback);
|
||||
|
||||
// Wait on the condition
|
||||
|
@ -22,12 +22,12 @@ main(int argc, char **argv)
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
OSSleepTicks(OSMillisecondsToTicks(1000));
|
||||
}
|
||||
|
||||
WHBLogPrintf("Exiting... good bye.");
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
OSSleepTicks(OSMillisecondsToTicks(1000));
|
||||
|
||||
WHBLogConsoleFree();
|
||||
WHBProcShutdown();
|
||||
|
@ -21,12 +21,12 @@ hello_thread()
|
||||
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
OSSleepTicks(OSMillisecondsToTicks(1000));
|
||||
}
|
||||
|
||||
WHBLogPrintf("Exiting... good bye.");
|
||||
WHBLogConsoleDraw();
|
||||
OSSleepTicks(OSMilliseconds(1000));
|
||||
OSSleepTicks(OSMillisecondsToTicks(1000));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user