Reverted GX FIFO breakage.
[libogc.git] / gc / ogc / lwp_watchdog.h
blob912a1bb930c58cae847507d2a41859fe1864a88a
1 #ifndef __LWP_WATCHDOG_H__
2 #define __LWP_WATCHDOG_H__
4 #include <gctypes.h>
5 #include "lwp_queue.h"
6 #include <time.h>
8 #if defined(HW_RVL)
9 #define TB_BUS_CLOCK 243000000u
10 #define TB_CORE_CLOCK 729000000u
11 #elif defined(HW_DOL)
12 #define TB_BUS_CLOCK 162000000u
13 #define TB_CORE_CLOCK 486000000u
14 #endif
15 #define TB_TIMER_CLOCK (TB_BUS_CLOCK/4000) //4th of the bus frequency
17 #define TB_SECSPERMIN 60
18 #define TB_MINSPERHR 60
19 #define TB_MONSPERYR 12
20 #define TB_DAYSPERYR 365
21 #define TB_HRSPERDAY 24
22 #define TB_SECSPERDAY (TB_SECSPERMIN*TB_MINSPERHR*TB_HRSPERDAY)
23 #define TB_SECSPERNYR (365*TB_SECSPERDAY)
25 #define TB_MSPERSEC 1000
26 #define TB_USPERSEC 1000000
27 #define TB_NSPERSEC 1000000000
28 #define TB_NSPERMS 1000000
29 #define TB_NSPERUS 1000
30 #define TB_USPERTICK 10000
32 #define ticks_to_cycles(ticks) ((u32)(((u64)(ticks)*(u64)((TB_CORE_CLOCK*2)/TB_TIMER_CLOCK))/2))
33 #define ticks_to_secs(ticks) ((u32)((u64)(ticks)/(u64)(TB_TIMER_CLOCK*1000)))
34 #define ticks_to_millisecs(ticks) ((u32)((u64)(ticks)/(u64)(TB_TIMER_CLOCK)))
35 #define ticks_to_microsecs(ticks) ((u32)(((u64)(ticks)*8)/(u64)(TB_TIMER_CLOCK/125)))
36 #define ticks_to_nanosecs(ticks) ((u32)(((u64)(ticks)*8000)/(u64)(TB_TIMER_CLOCK/125)))
38 #define secs_to_ticks(sec) ((u64)(sec)*(TB_TIMER_CLOCK*1000))
39 #define millisecs_to_ticks(msec) ((u64)(msec)*(TB_TIMER_CLOCK))
40 #define microsecs_to_ticks(usec) (((u64)(usec)*(TB_TIMER_CLOCK/125))/8)
41 #define nanosecs_to_ticks(nsec) (((u64)(nsec)*(TB_TIMER_CLOCK/125))/8000)
43 #define diff_ticks(tick0,tick1) (((u64)(tick1)<(u64)(tick0))?((u64)-1-(u64)(tick0)+(u64)(tick1)):((u64)(tick1)-(u64)(tick0)))
45 #define LWP_WD_INACTIVE 0
46 #define LWP_WD_INSERTED 1
47 #define LWP_WD_ACTIVE 2
48 #define LWP_WD_REMOVE 3
50 #define LWP_WD_FORWARD 0
51 #define LWP_WD_BACKWARD 1
53 #define LWP_WD_NOTIMEOUT 0
55 #define LWP_WD_ABS(x) ((s64)(x)>0?(s64)(x):-((s64)(x)))
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
61 extern vu32 _wd_sync_level;
62 extern vu32 _wd_sync_count;
63 extern u32 _wd_ticks_since_boot;
65 extern lwp_queue _wd_ticks_queue;
67 extern u32 gettick();
68 extern u64 gettime();
69 extern void settime(u64);
71 u32 diff_sec(u64 start,u64 end);
72 u32 diff_msec(u64 start,u64 end);
73 u32 diff_usec(u64 start,u64 end);
74 u32 diff_nsec(u64 start,u64 end);
76 typedef void (*wd_service_routine)(void *);
78 typedef struct _wdcntrl {
79 lwp_node node;
80 u64 start;
81 u32 id;
82 u32 state;
83 u64 fire;
84 wd_service_routine routine;
85 void *usr_data;
86 } wd_cntrl;
88 void __lwp_watchdog_init();
89 void __lwp_watchdog_settimer(wd_cntrl *wd);
90 void __lwp_wd_insert(lwp_queue *header,wd_cntrl *wd);
91 u32 __lwp_wd_remove(lwp_queue *header,wd_cntrl *wd);
92 void __lwp_wd_tickle(lwp_queue *queue);
93 void __lwp_wd_adjust(lwp_queue *queue,u32 dir,s64 interval);
95 #ifdef LIBOGC_INTERNAL
96 #include <libogc/lwp_watchdog.inl>
97 #endif
99 #ifdef __cplusplus
101 #endif
103 #endif