sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
delaythread.c
Go to the documentation of this file.
1
/*
2
# _____ ___ ____ ___ ____
3
# ____| | ____| | | |____|
4
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5
#-----------------------------------------------------------------------
6
# Copyright ps2dev - http://www.ps2dev.org
7
# Licenced under Academic Free License version 2.0
8
# Review ps2sdk README & LICENSE files for further details.
9
*/
10
15
16
#include <
kernel.h
>
17
#include <
timer.h
>
18
#include <
timer_alarm.h
>
19
#include <
delaythread.h
>
20
#include <
mipscopaccess.h
>
21
22
static
u64 DelayThreadWakeup_callback(s32 alarm_id, u64 scheduled_time, u64 actual_time,
void
*arg,
void
*pc_value)
23
{
24
(void)alarm_id;
25
(void)scheduled_time;
26
(void)actual_time;
27
(void)pc_value;
28
29
iSignalSema((s32)arg);
30
ExitHandler();
31
return
0;
32
}
33
34
s32 DelayThread(s32 microseconds)
35
{
36
u32 eie;
37
s32 sema_id;
38
s32 timer_alarm_id;
39
ee_sema_t sema;
40
41
eie = get_mips_cop_reg(0,
COP0_REG_Status
);
42
if
((eie & 0x10000) == 0)
43
{
44
return
0x80008008;
// ECPUDI
45
}
46
sema.max_count = 1;
47
sema.option = (u32)
"DelayThread"
;
48
sema.init_count = 0;
49
sema_id = CreateSema(&sema);
50
if
(sema_id < 0)
51
{
52
return
0x80008003;
// ESEMAPHORE
53
}
54
timer_alarm_id =
SetTimerAlarm
(TimerUSec2BusClock(0, microseconds), DelayThreadWakeup_callback, (
void
*)sema_id);
55
if
(timer_alarm_id < 0)
56
{
57
DeleteSema(sema_id);
58
return
timer_alarm_id;
59
}
60
WaitSema(sema_id);
61
DeleteSema(sema_id);
62
return
0;
63
}
delaythread.h
kernel.h
mipscopaccess.h
COP0_REG_Status
#define COP0_REG_Status
Definition
mipscopaccess.h:35
timer.h
timer_alarm.h
SetTimerAlarm
s32 SetTimerAlarm(u64 clock_cycles, timer_alarm_handler_t callback_handler, void *arg)
Definition
timer_alarm.c:120
core
kernel
src
delaythread.c
Generated by
1.18.0