getsecs.c revision 1.10
1/*	$NetBSD: getsecs.c,v 1.10 2013/01/10 10:36:41 he Exp $	*/
2
3#include <sys/param.h>
4
5#include <machine/cpu.h>
6#include <netinet/in.h>
7#include <netinet/in_systm.h>
8
9#include <lib/libsa/stand.h>
10#include <lib/libsa/net.h>
11
12#include "include/prom.h"
13#include "include/rpb.h"
14
15satime_t
16getsecs(void)
17{
18	static uint64_t tnsec;
19	static uint64_t lastpcc, wrapsecs;
20	uint64_t curpcc;
21
22	if (tnsec == 0) {
23		tnsec = 1;
24		lastpcc = alpha_rpcc() & 0xffffffff;
25		wrapsecs = (0xffffffff /
26		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1;
27
28#if 0
29		printf("getsecs: cc freq = %lu, time to wrap = %lu\n",
30		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs);
31#endif
32	}
33
34	curpcc = alpha_rpcc() & 0xffffffff;
35	if (curpcc < lastpcc)
36		curpcc += 0x100000000;
37
38	tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
39	lastpcc = curpcc;
40
41	return (tnsec / 1000000000);
42}
43