a11245590dd1368cf7a8fd7d85902bc4a190888e
[AROS.git] / arch / m68k-amiga / timer / getsystime.c
bloba11245590dd1368cf7a8fd7d85902bc4a190888e
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: GetSysTime() - Find out what time it is.
6 Lang: english
7 */
8 #include <proto/exec.h>
10 #define DEBUG 0
11 #include <aros/debug.h>
13 #include <timer_intern.h>
15 /*****************************************************************************
17 NAME */
18 #include <devices/timer.h>
19 #include <proto/timer.h>
21 AROS_LH1(void, GetSysTime,
23 /* SYNOPSIS */
24 AROS_LHA(struct timeval *, dest, A0),
26 /* LOCATION */
27 struct Device *, TimerBase, 11, Timer)
29 /* FUNCTION
30 GetSysTime() will fill in the supplied timeval with the current
31 system time.
33 INPUTS
34 dest - A pointer to the timeval you want the time stored in.
36 RESULT
37 The timeval "dest" will be filled with the current system time.
39 NOTES
40 This function is safe to call from interrupts.
42 EXAMPLE
44 BUGS
46 SEE ALSO
47 TR_GETSYSTIME, TR_SETSYSTIME
49 INTERNALS
51 HISTORY
52 18-02-1997 iaint Implemented.
54 *****************************************************************************/
56 AROS_LIBFUNC_INIT
58 struct TimerBase *timerBase = (struct TimerBase *)TimerBase;
59 ULONG tb_eclock_to_usec;
61 Disable();
62 tb_eclock_to_usec = timerBase->tb_eclock_to_usec + GetEClock(timerBase);
63 Enable();
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;
68 } else {
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;
77 dest->tv_secs++;
79 D(bug("systime=%d/%d\n", dest->tv_secs, dest->tv_micro));
81 AROS_LIBFUNC_EXIT
82 } /* GetSysTime */