getsecs.c revision 1.8
11.8Stsutsui/*	$NetBSD: getsecs.c,v 1.8 2009/01/12 11:04:00 tsutsui Exp $	*/
21.5Sperry
31.1Scgd#include <sys/param.h>
41.6Sthorpej
51.6Sthorpej#include <netinet/in.h>
61.6Sthorpej#include <netinet/in_systm.h>
71.6Sthorpej
81.6Sthorpej#include <lib/libsa/stand.h>
91.6Sthorpej#include <lib/libsa/net.h>
101.6Sthorpej
111.1Scgd#include "include/prom.h"
121.1Scgd#include "include/rpb.h"
131.1Scgd
141.7Sdogcowtime_t
151.6Sthorpejgetsecs(void)
161.1Scgd{
171.8Stsutsui	static uint64_t tnsec;
181.8Stsutsui	static uint64_t lastpcc, wrapsecs;
191.8Stsutsui	uint64_t curpcc;
201.1Scgd
211.1Scgd	if (tnsec == 0) {
221.3Scgd		tnsec = 1;
231.1Scgd		lastpcc = alpha_rpcc() & 0xffffffff;
241.1Scgd		wrapsecs = (0xffffffff /
251.1Scgd		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1;
261.1Scgd
271.2Scgd#if 0
281.8Stsutsui		printf("getsecs: cc freq = %lu, time to wrap = %lu\n",
291.1Scgd		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs);
301.2Scgd#endif
311.1Scgd	}
321.1Scgd
331.1Scgd	curpcc = alpha_rpcc() & 0xffffffff;
341.1Scgd	if (curpcc < lastpcc)
351.1Scgd		curpcc += 0x100000000;
361.1Scgd
371.1Scgd	tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
381.1Scgd	lastpcc = curpcc;
391.1Scgd
401.1Scgd	return (tnsec / 1000000000);
411.1Scgd}
42