2018-07-24 10:03:24 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project / 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2+
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-06-04 23:52:42 +00:00
|
|
|
#include <chrono>
|
2018-07-24 10:03:24 +00:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2019-02-12 17:32:15 +00:00
|
|
|
namespace Core::Timing {
|
2018-07-24 10:03:24 +00:00
|
|
|
|
|
|
|
// The below clock rate is based on Switch's clockspeed being widely known as 1.020GHz
|
|
|
|
// The exact value used is of course unverified.
|
|
|
|
constexpr u64 BASE_CLOCK_RATE = 1019215872; // Switch clock speed is 1020MHz un/docked
|
2019-02-16 00:04:11 +00:00
|
|
|
constexpr u64 CNTFREQ = 19200000; // Value from fusee.
|
2018-07-24 10:03:24 +00:00
|
|
|
|
2019-06-04 23:52:42 +00:00
|
|
|
s64 msToCycles(std::chrono::milliseconds ms);
|
|
|
|
s64 usToCycles(std::chrono::microseconds us);
|
|
|
|
s64 nsToCycles(std::chrono::nanoseconds ns);
|
2018-07-24 10:03:24 +00:00
|
|
|
|
2019-06-04 23:52:42 +00:00
|
|
|
inline std::chrono::milliseconds cyclesToMs(s64 cycles) {
|
|
|
|
return std::chrono::milliseconds(cycles * 1000 / BASE_CLOCK_RATE);
|
2018-07-24 10:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 23:52:42 +00:00
|
|
|
inline std::chrono::nanoseconds cyclesToNs(s64 cycles) {
|
|
|
|
return std::chrono::nanoseconds(cycles * 1000000000 / BASE_CLOCK_RATE);
|
2018-07-24 10:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 23:52:42 +00:00
|
|
|
inline std::chrono::microseconds cyclesToUs(s64 cycles) {
|
|
|
|
return std::chrono::microseconds(cycles * 1000000 / BASE_CLOCK_RATE);
|
2018-07-24 10:03:24 +00:00
|
|
|
}
|
|
|
|
|
2019-02-15 17:15:28 +00:00
|
|
|
u64 CpuCyclesToClockCycles(u64 ticks);
|
|
|
|
|
2019-02-12 17:32:15 +00:00
|
|
|
} // namespace Core::Timing
|