a11245590dd1368cf7a8fd7d85902bc4a190888e
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: GetSysTime() - Find out what time it is.
8 #include <proto/exec.h>
11 #include <aros/debug.h>
13 #include <timer_intern.h>
15 /*****************************************************************************
18 #include <devices/timer.h>
19 #include <proto/timer.h>
21 AROS_LH1(void, GetSysTime
,
24 AROS_LHA(struct timeval
*, dest
, A0
),
27 struct Device
*, TimerBase
, 11, Timer
)
30 GetSysTime() will fill in the supplied timeval with the current
34 dest - A pointer to the timeval you want the time stored in.
37 The timeval "dest" will be filled with the current system time.
40 This function is safe to call from interrupts.
47 TR_GETSYSTIME, TR_SETSYSTIME
52 18-02-1997 iaint Implemented.
54 *****************************************************************************/
58 struct TimerBase
*timerBase
= (struct TimerBase
*)TimerBase
;
59 ULONG tb_eclock_to_usec
;
62 tb_eclock_to_usec
= timerBase
->tb_eclock_to_usec
+ GetEClock(timerBase
);
64 dest
->tv_secs
= timerBase
->tb_CurrentTime
.tv_secs
;
65 dest
->tv_micro
= (ULONG
)(((long long)tb_eclock_to_usec
* timerBase
->tb_eclock_micro_mult
) >> 16);
66 if (dest
->tv_micro
> timerBase
->tb_lastsystime
.tv_secs
+ timerBase
->lastsystimetweak
) {
67 timerBase
->lastsystimetweak
= 0;
69 timerBase
->lastsystimetweak
++;
71 timerBase
->tb_lastsystime
.tv_secs
= dest
->tv_secs
;
72 timerBase
->tb_lastsystime
.tv_micro
= dest
->tv_micro
;
73 dest
->tv_micro
+= timerBase
->lastsystimetweak
;
74 // can only overflow once, e-clock interrupts happen more than once a second
75 if (dest
->tv_micro
>= 1000000) {
76 dest
->tv_micro
-= 1000000;
79 D(bug("systime=%d/%d\n", dest
->tv_secs
, dest
->tv_micro
));