2 Copyright © 1995-2013, 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 #include <devices/timer.h>
16 #include <proto/timer.h>
18 /* See rom/timer/getsystime.c for documentation */
20 AROS_LH1(void, GetSysTime
,
21 AROS_LHA(struct timeval
*, dest
, A0
),
22 struct Device
*, TimerBase
, 11, Timer
)
26 struct TimerBase
*timerBase
= (struct TimerBase
*)TimerBase
;
27 ULONG tb_eclock_to_usec
;
30 tb_eclock_to_usec
= timerBase
->tb_eclock_to_usec
+ GetEClock(timerBase
);
32 dest
->tv_secs
= timerBase
->tb_CurrentTime
.tv_secs
;
33 dest
->tv_micro
= (ULONG
)(((long long)tb_eclock_to_usec
* timerBase
->tb_eclock_micro_mult
) >> 16);
34 if (dest
->tv_micro
> timerBase
->tb_lastsystime
.tv_secs
+ timerBase
->lastsystimetweak
) {
35 timerBase
->lastsystimetweak
= 0;
37 timerBase
->lastsystimetweak
++;
39 timerBase
->tb_lastsystime
.tv_secs
= dest
->tv_secs
;
40 timerBase
->tb_lastsystime
.tv_micro
= dest
->tv_micro
;
41 dest
->tv_micro
+= timerBase
->lastsystimetweak
;
42 // can only overflow once, e-clock interrupts happen more than once a second
43 if (dest
->tv_micro
>= 1000000) {
44 dest
->tv_micro
-= 1000000;
47 D(bug("systime=%d/%d\n", dest
->tv_secs
, dest
->tv_micro
));