Merge pull request #4400 from wwylele/core-timing-global

CoreTiming: wrap into class
This commit is contained in:
Weiyi Wang
2018-11-06 20:04:56 -05:00
committed by GitHub
34 changed files with 413 additions and 413 deletions

View File

@@ -8,6 +8,7 @@
#include <unordered_map>
#include "common/assert.h"
#include "common/common_types.h"
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/applets/applet.h"
#include "core/hle/applets/erreula.h"
@@ -38,7 +39,7 @@ namespace Applets {
static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
/// The CoreTiming event identifier for the Applet update callback.
static CoreTiming::EventType* applet_update_event = nullptr;
static Core::TimingEventType* applet_update_event = nullptr;
/// The interval at which the Applet update callback will be called, 16.6ms
static const u64 applet_update_interval_us = 16666;
@@ -88,8 +89,8 @@ static void AppletUpdateEvent(u64 applet_id, s64 cycles_late) {
// If the applet is still running after the last update, reschedule the event
if (applet->IsRunning()) {
CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us) - cycles_late,
applet_update_event, applet_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us) - cycles_late, applet_update_event, applet_id);
} else {
// Otherwise the applet has terminated, in which case we should clean it up
applets[id] = nullptr;
@@ -101,8 +102,8 @@ ResultCode Applet::Start(const Service::APT::AppletStartupParameter& parameter)
if (result.IsError())
return result;
// Schedule the update event
CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us), applet_update_event,
static_cast<u64>(id));
Core::System::GetInstance().CoreTiming().ScheduleEvent(
usToCycles(applet_update_interval_us), applet_update_event, static_cast<u64>(id));
return result;
}
@@ -128,11 +129,12 @@ bool IsLibraryAppletRunning() {
void Init() {
// Register the applet update callback
applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent);
applet_update_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
"HLE Applet Update Event", AppletUpdateEvent);
}
void Shutdown() {
CoreTiming::RemoveEvent(applet_update_event);
Core::System::GetInstance().CoreTiming().RemoveEvent(applet_update_event);
}
} // namespace Applets
} // namespace HLE

View File

@@ -4,6 +4,7 @@
#include <chrono>
#include <cstring>
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/kernel/shared_page.h"
#include "core/hle/service/ptm/ptm.h"
@@ -53,9 +54,9 @@ Handler::Handler() {
init_time = GetInitTime();
using namespace std::placeholders;
update_time_event = CoreTiming::RegisterEvent(
update_time_event = Core::System::GetInstance().CoreTiming().RegisterEvent(
"SharedPage::UpdateTimeCallback", std::bind(&Handler::UpdateTimeCallback, this, _1, _2));
CoreTiming::ScheduleEvent(0, update_time_event);
Core::System::GetInstance().CoreTiming().ScheduleEvent(0, update_time_event);
float slidestate =
Settings::values.toggle_3d ? (float_le)Settings::values.factor_3d / 100 : 0.0f;
@@ -65,8 +66,8 @@ Handler::Handler() {
/// Gets system time in 3DS format. The epoch is Jan 1900, and the unit is millisecond.
u64 Handler::GetSystemTime() const {
std::chrono::milliseconds now =
init_time +
std::chrono::duration_cast<std::chrono::milliseconds>(CoreTiming::GetGlobalTimeUs());
init_time + std::chrono::duration_cast<std::chrono::milliseconds>(
Core::System::GetInstance().CoreTiming().GetGlobalTimeUs());
// 3DS system does't allow user to set a time before Jan 1 2000,
// so we use it as an auxiliary epoch to calculate the console time.
@@ -97,14 +98,15 @@ void Handler::UpdateTimeCallback(u64 userdata, int cycles_late) {
shared_page.date_time_counter % 2 ? shared_page.date_time_0 : shared_page.date_time_1;
date_time.date_time = GetSystemTime();
date_time.update_tick = CoreTiming::GetTicks();
date_time.update_tick = Core::System::GetInstance().CoreTiming().GetTicks();
date_time.tick_to_second_coefficient = BASE_CLOCK_RATE_ARM11;
date_time.tick_offset = 0;
++shared_page.date_time_counter;
// system time is updated hourly
CoreTiming::ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late, update_time_event);
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(60 * 60 * 1000) - cycles_late,
update_time_event);
}
void Handler::SetMacAddress(const MacAddress& addr) {

View File

@@ -21,8 +21,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
}
namespace SharedPage {
@@ -96,7 +96,7 @@ public:
private:
u64 GetSystemTime() const;
void UpdateTimeCallback(u64 userdata, int cycles_late);
CoreTiming::EventType* update_time_event;
Core::TimingEventType* update_time_event;
std::chrono::seconds init_time;
SharedPageDef shared_page;

View File

@@ -1107,9 +1107,10 @@ static void SleepThread(s64 nanoseconds) {
/// This returns the total CPU ticks elapsed since the CPU was powered-on
static s64 GetSystemTick() {
s64 result = CoreTiming::GetTicks();
s64 result = Core::System::GetInstance().CoreTiming().GetTicks();
// Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end.
CoreTiming::AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
// Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b
Core::System::GetInstance().CoreTiming().AddTicks(150);
return result;
}

View File

@@ -48,7 +48,8 @@ Thread* ThreadManager::GetCurrentThread() const {
void Thread::Stop() {
// Cancel any outstanding wakeup events for this thread
CoreTiming::UnscheduleEvent(thread_manager.ThreadWakeupEventType, thread_id);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(thread_manager.ThreadWakeupEventType,
thread_id);
thread_manager.wakeup_callback_table.erase(thread_id);
// Clean up thread from ready queue
@@ -80,9 +81,11 @@ void Thread::Stop() {
void ThreadManager::SwitchContext(Thread* new_thread) {
Thread* previous_thread = GetCurrentThread();
Core::Timing& timing = Core::System::GetInstance().CoreTiming();
// Save context for previous thread
if (previous_thread) {
previous_thread->last_running_ticks = CoreTiming::GetTicks();
previous_thread->last_running_ticks = timing.GetTicks();
Core::CPU().SaveContext(previous_thread->context);
if (previous_thread->status == ThreadStatus::Running) {
@@ -99,7 +102,7 @@ void ThreadManager::SwitchContext(Thread* new_thread) {
"Thread must be ready to become running.");
// Cancel any outstanding wakeup events for this thread
CoreTiming::UnscheduleEvent(ThreadWakeupEventType, new_thread->thread_id);
timing.UnscheduleEvent(ThreadWakeupEventType, new_thread->thread_id);
auto previous_process = Core::System::GetInstance().Kernel().GetCurrentProcess();
@@ -182,8 +185,8 @@ void Thread::WakeAfterDelay(s64 nanoseconds) {
if (nanoseconds == -1)
return;
CoreTiming::ScheduleEvent(nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType,
thread_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(nanoseconds), thread_manager.ThreadWakeupEventType, thread_id);
}
void Thread::ResumeFromWait() {
@@ -316,7 +319,7 @@ ResultVal<SharedPtr<Thread>> KernelSystem::CreateThread(std::string name, VAddr
thread->entry_point = entry_point;
thread->stack_top = stack_top;
thread->nominal_priority = thread->current_priority = priority;
thread->last_running_ticks = CoreTiming::GetTicks();
thread->last_running_ticks = Core::System::GetInstance().CoreTiming().GetTicks();
thread->processor_id = processor_id;
thread->wait_objects.clear();
thread->wait_address = 0;
@@ -459,10 +462,9 @@ VAddr Thread::GetCommandBufferAddress() const {
}
ThreadManager::ThreadManager() {
ThreadWakeupEventType =
CoreTiming::RegisterEvent("ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) {
ThreadWakeupCallback(thread_id, cycle_late);
});
ThreadWakeupEventType = Core::System::GetInstance().CoreTiming().RegisterEvent(
"ThreadWakeupCallback",
[this](u64 thread_id, s64 cycle_late) { ThreadWakeupCallback(thread_id, cycle_late); });
}
ThreadManager::~ThreadManager() {

View File

@@ -127,7 +127,7 @@ private:
std::unordered_map<u64, Thread*> wakeup_callback_table;
/// Event type for the thread wake up event
CoreTiming::EventType* ThreadWakeupEventType = nullptr;
Core::TimingEventType* ThreadWakeupEventType = nullptr;
// Lists all threadsthat aren't deleted.
std::vector<SharedPtr<Thread>> thread_list;

View File

@@ -6,6 +6,7 @@
#include <unordered_map>
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/thread.h"
@@ -55,13 +56,14 @@ void Timer::Set(s64 initial, s64 interval) {
// Immediately invoke the callback
Signal(0);
} else {
CoreTiming::ScheduleEvent(nsToCycles(initial), timer_manager.timer_callback_event_type,
callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(initial), timer_manager.timer_callback_event_type, callback_id);
}
}
void Timer::Cancel() {
CoreTiming::UnscheduleEvent(timer_manager.timer_callback_event_type, callback_id);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(
timer_manager.timer_callback_event_type, callback_id);
}
void Timer::Clear() {
@@ -85,8 +87,9 @@ void Timer::Signal(s64 cycles_late) {
if (interval_delay != 0) {
// Reschedule the timer with the interval delay
CoreTiming::ScheduleEvent(nsToCycles(interval_delay) - cycles_late,
timer_manager.timer_callback_event_type, callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
nsToCycles(interval_delay) - cycles_late, timer_manager.timer_callback_event_type,
callback_id);
}
}
@@ -103,10 +106,9 @@ void TimerManager::TimerCallback(u64 callback_id, s64 cycles_late) {
}
TimerManager::TimerManager() {
timer_callback_event_type =
CoreTiming::RegisterEvent("TimerCallback", [this](u64 thread_id, s64 cycle_late) {
TimerCallback(thread_id, cycle_late);
});
timer_callback_event_type = Core::System::GetInstance().CoreTiming().RegisterEvent(
"TimerCallback",
[this](u64 thread_id, s64 cycle_late) { TimerCallback(thread_id, cycle_late); });
}
} // namespace Kernel

View File

@@ -20,7 +20,7 @@ private:
void TimerCallback(u64 callback_id, s64 cycles_late);
/// The event type of the generic timer callback event
CoreTiming::EventType* timer_callback_event_type = nullptr;
Core::TimingEventType* timer_callback_event_type = nullptr;
u64 next_timer_callback_id = 0;
std::unordered_map<u64, Timer*> timer_callback_table;

View File

@@ -151,7 +151,7 @@ void Module::StartReceiving(int port_id) {
// schedules a completion event according to the frame rate. The event will block on the
// capture task if it is not finished within the expected time
CoreTiming::ScheduleEvent(
system.CoreTiming().ScheduleEvent(
msToCycles(LATENCY_BY_FRAME_RATE[static_cast<int>(camera.frame_rate)]),
completion_event_callback, port_id);
}
@@ -160,7 +160,7 @@ void Module::CancelReceiving(int port_id) {
if (!ports[port_id].is_receiving)
return;
LOG_WARNING(Service_CAM, "tries to cancel an ongoing receiving process.");
CoreTiming::UnscheduleEvent(completion_event_callback, port_id);
system.CoreTiming().UnscheduleEvent(completion_event_callback, port_id);
ports[port_id].capture_result.wait();
ports[port_id].is_receiving = false;
}
@@ -1019,7 +1019,7 @@ void Module::Interface::DriverFinalize(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_CAM, "called");
}
Module::Module(Core::System& system) {
Module::Module(Core::System& system) : system(system) {
using namespace Kernel;
for (PortConfig& port : ports) {
port.completion_event =
@@ -1029,7 +1029,7 @@ Module::Module(Core::System& system) {
port.vsync_interrupt_event =
system.Kernel().CreateEvent(ResetType::OneShot, "CAM::vsync_interrupt_event");
}
completion_event_callback = CoreTiming::RegisterEvent(
completion_event_callback = system.CoreTiming().RegisterEvent(
"CAM::CompletionEventCallBack",
[this](u64 userdata, s64 cycles_late) { CompletionEventCallBack(userdata, cycles_late); });
}

View File

@@ -21,8 +21,8 @@ namespace Camera {
class CameraInterface;
}
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
}
namespace Kernel {
@@ -779,9 +779,10 @@ private:
void LoadCameraImplementation(CameraConfig& camera, int camera_id);
Core::System& system;
std::array<CameraConfig, NumCameras> cameras;
std::array<PortConfig, 2> ports;
CoreTiming::EventType* completion_event_callback;
Core::TimingEventType* completion_event_callback;
std::atomic<bool> is_camera_reload_pending{false};
};

View File

@@ -128,7 +128,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->pad.index == 0) {
mem->pad.index_reset_ticks_previous = mem->pad.index_reset_ticks;
mem->pad.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->pad.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
mem->touch.index = next_touch_index;
@@ -152,7 +152,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->touch.index == 0) {
mem->touch.index_reset_ticks_previous = mem->touch.index_reset_ticks;
mem->touch.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->touch.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
// Signal both handles when there's an update to Pad or touch
@@ -160,7 +160,7 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
event_pad_or_touch_2->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
system.CoreTiming().ScheduleEvent(pad_update_ticks - cycles_late, pad_update_event);
}
void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
@@ -198,13 +198,14 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->accelerometer.index == 0) {
mem->accelerometer.index_reset_ticks_previous = mem->accelerometer.index_reset_ticks;
mem->accelerometer.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->accelerometer.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
event_accelerometer->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(accelerometer_update_ticks - cycles_late, accelerometer_update_event);
system.CoreTiming().ScheduleEvent(accelerometer_update_ticks - cycles_late,
accelerometer_update_event);
}
void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
@@ -233,13 +234,13 @@ void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->gyroscope.index == 0) {
mem->gyroscope.index_reset_ticks_previous = mem->gyroscope.index_reset_ticks;
mem->gyroscope.index_reset_ticks = (s64)CoreTiming::GetTicks();
mem->gyroscope.index_reset_ticks = (s64)system.CoreTiming().GetTicks();
}
event_gyroscope->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(gyroscope_update_ticks - cycles_late, gyroscope_update_event);
system.CoreTiming().ScheduleEvent(gyroscope_update_ticks - cycles_late, gyroscope_update_event);
}
void Module::Interface::GetIPCHandles(Kernel::HLERequestContext& ctx) {
@@ -257,7 +258,8 @@ void Module::Interface::EnableAccelerometer(Kernel::HLERequestContext& ctx) {
// Schedules the accelerometer update event if the accelerometer was just enabled
if (hid->enable_accelerometer_count == 1) {
CoreTiming::ScheduleEvent(accelerometer_update_ticks, hid->accelerometer_update_event);
hid->system.CoreTiming().ScheduleEvent(accelerometer_update_ticks,
hid->accelerometer_update_event);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@@ -273,7 +275,7 @@ void Module::Interface::DisableAccelerometer(Kernel::HLERequestContext& ctx) {
// Unschedules the accelerometer update event if the accelerometer was just disabled
if (hid->enable_accelerometer_count == 0) {
CoreTiming::UnscheduleEvent(hid->accelerometer_update_event, 0);
hid->system.CoreTiming().UnscheduleEvent(hid->accelerometer_update_event, 0);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@@ -289,7 +291,7 @@ void Module::Interface::EnableGyroscopeLow(Kernel::HLERequestContext& ctx) {
// Schedules the gyroscope update event if the gyroscope was just enabled
if (hid->enable_gyroscope_count == 1) {
CoreTiming::ScheduleEvent(gyroscope_update_ticks, hid->gyroscope_update_event);
hid->system.CoreTiming().ScheduleEvent(gyroscope_update_ticks, hid->gyroscope_update_event);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@@ -305,7 +307,7 @@ void Module::Interface::DisableGyroscopeLow(Kernel::HLERequestContext& ctx) {
// Unschedules the gyroscope update event if the gyroscope was just disabled
if (hid->enable_gyroscope_count == 0) {
CoreTiming::UnscheduleEvent(hid->gyroscope_update_event, 0);
hid->system.CoreTiming().UnscheduleEvent(hid->gyroscope_update_event, 0);
}
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@@ -371,19 +373,21 @@ Module::Module(Core::System& system) : system(system) {
event_debug_pad = system.Kernel().CreateEvent(ResetType::OneShot, "HID:EventDebugPad");
// Register update callbacks
Core::Timing& timing = system.CoreTiming();
pad_update_event =
CoreTiming::RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
timing.RegisterEvent("HID::UpdatePadCallback", [this](u64 userdata, s64 cycles_late) {
UpdatePadCallback(userdata, cycles_late);
});
accelerometer_update_event = CoreTiming::RegisterEvent(
accelerometer_update_event = timing.RegisterEvent(
"HID::UpdateAccelerometerCallback", [this](u64 userdata, s64 cycles_late) {
UpdateAccelerometerCallback(userdata, cycles_late);
});
gyroscope_update_event = CoreTiming::RegisterEvent(
"HID::UpdateGyroscopeCallback",
[this](u64 userdata, s64 cycles_late) { UpdateGyroscopeCallback(userdata, cycles_late); });
gyroscope_update_event =
timing.RegisterEvent("HID::UpdateGyroscopeCallback", [this](u64 userdata, s64 cycles_late) {
UpdateGyroscopeCallback(userdata, cycles_late);
});
CoreTiming::ScheduleEvent(pad_update_ticks, pad_update_event);
timing.ScheduleEvent(pad_update_ticks, pad_update_event);
}
void Module::ReloadInputDevices() {

View File

@@ -27,8 +27,8 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
};
namespace Service::HID {
@@ -325,9 +325,9 @@ private:
int enable_accelerometer_count = 0; // positive means enabled
int enable_gyroscope_count = 0; // positive means enabled
CoreTiming::EventType* pad_update_event;
CoreTiming::EventType* accelerometer_update_event;
CoreTiming::EventType* gyroscope_update_event;
Core::TimingEventType* pad_update_event;
Core::TimingEventType* accelerometer_update_event;
Core::TimingEventType* gyroscope_update_event;
std::atomic<bool> is_device_reload_pending{true};
std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>

View File

@@ -4,6 +4,7 @@
#include "common/alignment.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/core_timing.h"
#include "core/hle/service/ir/extra_hid.h"
#include "core/movie.h"
@@ -144,11 +145,11 @@ ExtraHID::ExtraHID(SendFunc send_func) : IRDevice(send_func) {
0x65,
}};
hid_polling_callback_id =
CoreTiming::RegisterEvent("ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) {
hid_polling_callback_id = Core::System::GetInstance().CoreTiming().RegisterEvent(
"ExtraHID::SendHIDStatus", [this](u64, s64 cycles_late) {
SendHIDStatus();
CoreTiming::ScheduleEvent(msToCycles(hid_period) - cycles_late,
hid_polling_callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(
msToCycles(hid_period) - cycles_late, hid_polling_callback_id);
});
}
@@ -159,7 +160,7 @@ ExtraHID::~ExtraHID() {
void ExtraHID::OnConnect() {}
void ExtraHID::OnDisconnect() {
CoreTiming::UnscheduleEvent(hid_polling_callback_id, 0);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0);
}
void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request) {
@@ -170,9 +171,10 @@ void ExtraHID::HandleConfigureHIDPollingRequest(const std::vector<u8>& request)
}
// Change HID input polling interval
CoreTiming::UnscheduleEvent(hid_polling_callback_id, 0);
Core::System::GetInstance().CoreTiming().UnscheduleEvent(hid_polling_callback_id, 0);
hid_period = request[1];
CoreTiming::ScheduleEvent(msToCycles(hid_period), hid_polling_callback_id);
Core::System::GetInstance().CoreTiming().ScheduleEvent(msToCycles(hid_period),
hid_polling_callback_id);
}
void ExtraHID::HandleReadCalibrationDataRequest(const std::vector<u8>& request_buf) {

View File

@@ -11,9 +11,9 @@
#include "core/frontend/input.h"
#include "core/hle/service/ir/ir_user.h"
namespace CoreTiming {
struct EventType;
} // namespace CoreTiming
namespace Core {
struct TimingEventType;
} // namespace Core
namespace Service::IR {
@@ -57,7 +57,7 @@ private:
void LoadInputDevices();
u8 hid_period;
CoreTiming::EventType* hid_polling_callback_id;
Core::TimingEventType* hid_polling_callback_id;
std::array<u8, 0x40> calibration_data;
std::unique_ptr<Input::ButtonDevice> zl;
std::unique_ptr<Input::ButtonDevice> zr;

View File

@@ -100,13 +100,13 @@ void IR_RST::UpdateCallback(u64 userdata, s64 cycles_late) {
// If we just updated index 0, provide a new timestamp
if (mem->index == 0) {
mem->index_reset_ticks_previous = mem->index_reset_ticks;
mem->index_reset_ticks = CoreTiming::GetTicks();
mem->index_reset_ticks = system.CoreTiming().GetTicks();
}
update_event->Signal();
// Reschedule recurrent event
CoreTiming::ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
system.CoreTiming().ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
}
void IR_RST::GetHandles(Kernel::HLERequestContext& ctx) {
@@ -126,7 +126,7 @@ void IR_RST::Initialize(Kernel::HLERequestContext& ctx) {
next_pad_index = 0;
is_device_reload_pending.store(true);
CoreTiming::ScheduleEvent(msToCycles(update_period), update_callback_id);
system.CoreTiming().ScheduleEvent(msToCycles(update_period), update_callback_id);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS);
@@ -137,7 +137,7 @@ void IR_RST::Initialize(Kernel::HLERequestContext& ctx) {
void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x03, 0, 0);
CoreTiming::UnscheduleEvent(update_callback_id, 0);
system.CoreTiming().UnscheduleEvent(update_callback_id, 0);
UnloadInputDevices();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
@@ -145,7 +145,7 @@ void IR_RST::Shutdown(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_IR, "called");
}
IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1) {
IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1), system(system) {
using namespace Kernel;
// Note: these two kernel objects are even available before Initialize service function is
// called.
@@ -154,10 +154,9 @@ IR_RST::IR_RST(Core::System& system) : ServiceFramework("ir:rst", 1) {
MemoryRegion::BASE, "IRRST:SharedMemory");
update_event = system.Kernel().CreateEvent(ResetType::OneShot, "IRRST:UpdateEvent");
update_callback_id =
CoreTiming::RegisterEvent("IRRST:UpdateCallBack", [this](u64 userdata, s64 cycles_late) {
UpdateCallback(userdata, cycles_late);
});
update_callback_id = system.CoreTiming().RegisterEvent(
"IRRST:UpdateCallBack",
[this](u64 userdata, s64 cycles_late) { UpdateCallback(userdata, cycles_late); });
static const FunctionInfo functions[] = {
{0x00010000, &IR_RST::GetHandles, "GetHandles"},

View File

@@ -18,8 +18,8 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
namespace Core {
struct TimingEventType;
};
namespace Service::IR {
@@ -77,10 +77,11 @@ private:
void UnloadInputDevices();
void UpdateCallback(u64 userdata, s64 cycles_late);
Core::System& system;
Kernel::SharedPtr<Kernel::Event> update_event;
Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
u32 next_pad_index{0};
CoreTiming::EventType* update_callback_id;
Core::TimingEventType* update_callback_id;
std::unique_ptr<Input::ButtonDevice> zl_button;
std::unique_ptr<Input::ButtonDevice> zr_button;
std::unique_ptr<Input::AnalogDevice> c_stick;

View File

@@ -14,10 +14,6 @@ class Event;
class SharedMemory;
} // namespace Kernel
namespace CoreTiming {
struct EventType;
};
namespace Service::IR {
class BufferManager;

View File

@@ -88,7 +88,7 @@ struct Node {
static std::map<MacAddress, Node> node_map;
// Event that will generate and send the 802.11 beacon frames.
static CoreTiming::EventType* beacon_broadcast_event;
static Core::TimingEventType* beacon_broadcast_event;
// Callback identifier for the OnWifiPacketReceived event.
static Network::RoomMember::CallbackHandle<Network::WifiPacket> wifi_packet_received;
@@ -955,8 +955,8 @@ void NWM_UDS::BeginHostingNetwork(Kernel::HLERequestContext& ctx) {
connection_status_event->Signal();
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU),
beacon_broadcast_event, 0);
system.CoreTiming().ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU),
beacon_broadcast_event, 0);
LOG_DEBUG(Service_NWM, "An UDS network has been created.");
@@ -976,7 +976,7 @@ void NWM_UDS::DestroyNetwork(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x08, 0, 0);
// Unschedule the beacon broadcast event.
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0);
// Only a host can destroy
std::lock_guard<std::mutex> lock(connection_status_mutex);
@@ -1336,7 +1336,7 @@ void NWM_UDS::DecryptBeaconData(Kernel::HLERequestContext& ctx) {
}
// Sends a 802.11 beacon frame with information about the current network.
static void BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
void NWM_UDS::BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
// Don't do anything if we're not actually hosting a network
if (connection_status.status != static_cast<u32>(NetworkStatus::ConnectedAsHost))
return;
@@ -1353,8 +1353,9 @@ static void BeaconBroadcastCallback(u64 userdata, s64 cycles_late) {
SendPacket(packet);
// Start broadcasting the network, send a beacon frame every 102.4ms.
CoreTiming::ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) - cycles_late,
beacon_broadcast_event, 0);
system.CoreTiming().ScheduleEvent(msToCycles(DefaultBeaconInterval * MillisecondsPerTU) -
cycles_late,
beacon_broadcast_event, 0);
}
NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(system) {
@@ -1394,8 +1395,9 @@ NWM_UDS::NWM_UDS(Core::System& system) : ServiceFramework("nwm::UDS"), system(sy
RegisterHandlers(functions);
beacon_broadcast_event =
CoreTiming::RegisterEvent("UDS::BeaconBroadcastCallback", BeaconBroadcastCallback);
beacon_broadcast_event = system.CoreTiming().RegisterEvent(
"UDS::BeaconBroadcastCallback",
[this](u64 userdata, s64 cycles_late) { BeaconBroadcastCallback(userdata, cycles_late); });
CryptoPP::AutoSeededRandomPool rng;
auto mac = SharedPage::DefaultMac;
@@ -1428,7 +1430,7 @@ NWM_UDS::~NWM_UDS() {
if (auto room_member = Network::GetRoomMember().lock())
room_member->Unbind(wifi_packet_received);
CoreTiming::UnscheduleEvent(beacon_broadcast_event, 0);
system.CoreTiming().UnscheduleEvent(beacon_broadcast_event, 0);
}
} // namespace Service::NWM

View File

@@ -352,6 +352,8 @@ private:
* 2, 3: output buffer return descriptor & ptr
*/
void DecryptBeaconData(Kernel::HLERequestContext& ctx);
void BeaconBroadcastCallback(u64 userdata, s64 cycles_late);
};
} // namespace Service::NWM