2014-06-25 00:38:34 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2018-09-26 00:14:10 +02:00
|
|
|
#include "sys_event.h"
|
|
|
|
|
|
2015-06-19 17:49:38 +02:00
|
|
|
#include "Utilities/Thread.h"
|
2018-09-26 00:14:10 +02:00
|
|
|
#include "Emu/Memory/vm_ptr.h"
|
|
|
|
|
|
2015-06-19 17:49:38 +02:00
|
|
|
|
2015-03-08 16:25:31 +01:00
|
|
|
// Timer State
|
|
|
|
|
enum : u32
|
2014-06-25 00:38:34 +02:00
|
|
|
{
|
2015-03-08 16:25:31 +01:00
|
|
|
SYS_TIMER_STATE_STOP = 0,
|
|
|
|
|
SYS_TIMER_STATE_RUN = 1,
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sys_timer_information_t
|
|
|
|
|
{
|
2017-02-04 15:00:02 +01:00
|
|
|
be_t<s64> next_expire;
|
2015-03-08 16:25:31 +01:00
|
|
|
be_t<u64> period;
|
|
|
|
|
be_t<u32> timer_state;
|
|
|
|
|
be_t<u32> pad;
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-11 00:17:19 +02:00
|
|
|
struct lv2_timer_context : lv2_obj
|
2014-06-25 00:38:34 +02:00
|
|
|
{
|
2017-01-25 18:50:30 +01:00
|
|
|
static const u32 id_base = 0x11000000;
|
|
|
|
|
|
2018-10-11 00:17:19 +02:00
|
|
|
void operator()();
|
2015-11-26 09:06:29 +01:00
|
|
|
|
2018-11-26 16:55:22 +01:00
|
|
|
shared_mutex mutex;
|
2017-07-22 01:03:27 +02:00
|
|
|
atomic_t<u32> state{SYS_TIMER_STATE_STOP};
|
2015-11-26 09:06:29 +01:00
|
|
|
|
2017-02-04 15:00:02 +01:00
|
|
|
std::weak_ptr<lv2_event_queue> port;
|
|
|
|
|
u64 source;
|
|
|
|
|
u64 data1;
|
|
|
|
|
u64 data2;
|
2018-02-09 15:49:37 +01:00
|
|
|
|
2017-02-04 15:00:02 +01:00
|
|
|
atomic_t<u64> expire{0}; // Next expiration time
|
|
|
|
|
atomic_t<u64> period{0}; // Period (oneshot if 0)
|
2020-06-09 17:35:14 +02:00
|
|
|
|
|
|
|
|
void get_information(sys_timer_information_t& info)
|
|
|
|
|
{
|
2020-11-05 16:59:01 +01:00
|
|
|
reader_lock lock(mutex);
|
2020-06-09 17:35:14 +02:00
|
|
|
|
|
|
|
|
if (state == SYS_TIMER_STATE_RUN)
|
|
|
|
|
{
|
|
|
|
|
info.timer_state = SYS_TIMER_STATE_RUN;
|
|
|
|
|
info.next_expire = expire;
|
|
|
|
|
info.period = period;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
info.timer_state = SYS_TIMER_STATE_STOP;
|
|
|
|
|
info.next_expire = 0;
|
|
|
|
|
info.period = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-25 00:38:34 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-11 00:17:19 +02:00
|
|
|
using lv2_timer = named_thread<lv2_timer_context>;
|
|
|
|
|
|
2017-02-05 13:48:11 +01:00
|
|
|
class ppu_thread;
|
|
|
|
|
|
2017-02-04 15:00:02 +01:00
|
|
|
// Syscalls
|
|
|
|
|
|
2019-07-14 17:21:56 +02:00
|
|
|
error_code sys_timer_create(ppu_thread&, vm::ptr<u32> timer_id);
|
|
|
|
|
error_code sys_timer_destroy(ppu_thread&, u32 timer_id);
|
|
|
|
|
error_code sys_timer_get_information(ppu_thread&, u32 timer_id, vm::ptr<sys_timer_information_t> info);
|
|
|
|
|
error_code _sys_timer_start(ppu_thread&, u32 timer_id, u64 basetime, u64 period); // basetime type changed from s64
|
|
|
|
|
error_code sys_timer_stop(ppu_thread&, u32 timer_id);
|
|
|
|
|
error_code sys_timer_connect_event_queue(ppu_thread&, u32 timer_id, u32 queue_id, u64 name, u64 data1, u64 data2);
|
|
|
|
|
error_code sys_timer_disconnect_event_queue(ppu_thread&, u32 timer_id);
|
2017-02-05 13:48:11 +01:00
|
|
|
error_code sys_timer_sleep(ppu_thread&, u32 sleep_time);
|
|
|
|
|
error_code sys_timer_usleep(ppu_thread&, u64 sleep_time);
|