| 1 |
/*************************************************************************** |
| 2 |
|
| 3 |
timer.c |
| 4 |
|
| 5 |
Functions needed to generate timing and synchronization between several |
| 6 |
CPUs. |
| 7 |
|
| 8 |
***************************************************************************/ |
| 9 |
|
| 10 |
#ifndef __TIMER_H__ |
| 11 |
#define __TIMER_H__ |
| 12 |
|
| 13 |
#ifdef __cplusplus |
| 14 |
extern "C" { |
| 15 |
#endif |
| 16 |
|
| 17 |
extern double cycles_to_sec[]; |
| 18 |
extern double sec_to_cycles[]; |
| 19 |
|
| 20 |
#define TIME_IN_HZ(hz) (1.0 / (double)(hz)) |
| 21 |
#define TIME_IN_CYCLES(c,cpu) ((double)(c) * cycles_to_sec[cpu]) |
| 22 |
#define TIME_IN_SEC(s) ((double)(s)) |
| 23 |
#define TIME_IN_MSEC(ms) ((double)(ms) * (1.0 / 1000.0)) |
| 24 |
#define TIME_IN_USEC(us) ((double)(us) * (1.0 / 1000000.0)) |
| 25 |
#define TIME_IN_NSEC(us) ((double)(us) * (1.0 / 1000000000.0)) |
| 26 |
|
| 27 |
#define TIME_NOW (0.0) |
| 28 |
#define TIME_NEVER (1.0e30) |
| 29 |
|
| 30 |
#define TIME_TO_CYCLES(cpu,t) ((int)((t) * sec_to_cycles[cpu])) |
| 31 |
|
| 32 |
|
| 33 |
#define SUSPEND_REASON_HALT 0x0001 |
| 34 |
#define SUSPEND_REASON_RESET 0x0002 |
| 35 |
#define SUSPEND_REASON_SPIN 0x0004 |
| 36 |
#define SUSPEND_REASON_TRIGGER 0x0008 |
| 37 |
#define SUSPEND_REASON_DISABLE 0x0010 |
| 38 |
#define SUSPEND_ANY_REASON ((UINT32)-1) |
| 39 |
|
| 40 |
|
| 41 |
void timer_init(void); |
| 42 |
void timer_free(void); |
| 43 |
void *timer_alloc(void (*callback)(int)); |
| 44 |
void timer_adjust(void *which, double duration, int param, double period); |
| 45 |
void timer_pulse(double period, int param, void (*callback)(int)); |
| 46 |
void timer_set(double duration, int param, void (*callback)(int)); |
| 47 |
void timer_reset(void *which, double duration); |
| 48 |
void timer_remove(void *which); |
| 49 |
int timer_enable(void *which, int enable); |
| 50 |
double timer_timeelapsed(void *which); |
| 51 |
double timer_timeleft(void *which); |
| 52 |
double timer_get_time(void); |
| 53 |
double timer_starttime(void *which); |
| 54 |
double timer_firetime(void *which); |
| 55 |
int timer_schedule_cpu(int *cpu, int *cycles); |
| 56 |
void timer_update_cpu(int cpu, int ran); |
| 57 |
void timer_suspendcpu(int cpu, int suspend, int reason); |
| 58 |
void timer_holdcpu(int cpu, int hold, int reason); |
| 59 |
int timer_iscpususpended(int cpu, int reason); |
| 60 |
int timer_iscpuheld(int cpunum, int reason); |
| 61 |
void timer_suspendcpu_trigger(int cpu, int trigger); |
| 62 |
void timer_holdcpu_trigger(int cpu, int trigger); |
| 63 |
void timer_trigger(int trigger); |
| 64 |
double timer_get_overclock(int cpunum); |
| 65 |
void timer_set_overclock(int cpunum, double overclock); |
| 66 |
|
| 67 |
#ifdef __cplusplus |
| 68 |
} |
| 69 |
#endif |
| 70 |
|
| 71 |
#endif |