summaryrefslogtreecommitdiff
path: root/sys/arch/mvme88k/dev/clock.c
blob: 77b458f2526e68af867734671752848cb84c84c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <machine/board.h>
#include <machine/bug.h>
#include <machine/pcctworeg.h>

extern u_int *pcc_io_base;
extern const u_int timer_reload;
void	setstatclockrate (int hzrate)
{
}       

resettodr()
{
}

int
hexdectodec(unsigned char n)
{

	return(((n>>4)&0x0F)*10 + (n&0x0F));
}

#define STARTOFTIME 1970
#define FEBRUARY 2
#define leapyear(year) (((year)%4==0) && ((year)%100) != 0 || ((year)%400) == 0)
#define days_in_year(year) (leapyear((year)) ? 366 : 365)
#define   days_in_month(a)    (month_days[(a) - 1])

static int month_days[12] = {
     31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
}; 


inittodr(time_t base)
{
	struct bugrtc rtc;
	u_long sec, min, hour, day, month, year;
	u_long i, tmp, timebuf;

	/* ignore suggested time, use realtime clock via bug */
	bugrtcrd(&rtc);
	sec	= hexdectodec(rtc.s);
	min	= hexdectodec(rtc.m);
	hour	= hexdectodec(rtc.H);
	day	= hexdectodec(rtc.D);
	month	= hexdectodec(rtc.M);
	year	= hexdectodec(rtc.Y) + 1900;

	tmp = 0;
	for (i = STARTOFTIME; i < year; i++) {
		tmp += days_in_year(i);
	}
	for (i = 1; i < month; i++) {
		tmp += days_in_month(i);
	}
	if (leapyear(year) && month > FEBRUARY) {
		tmp++;
	}
	printf("date yy mm dd hh mm.ss:%02d %02d %02d %02d %02d.%02d:",
		year,month,day,hour,min, sec);
	tmp += (day -1);
	timebuf = (((tmp * 24 + hour) * 60 + min) * 60 + sec);
	printf(" epochsec %d\n",timebuf);
	time.tv_sec = timebuf;
	time.tv_usec = 0;
}

clkread()
{
}

cpu_initclocks()
{
#if 0
	u_int *io_base;
	io_base = 0xfffe1000; /* should really be return of virtmem alloc */
	/*
	io_base = pcc_io_base;
	*/
	/* timer 2 setup */
	PCC_TIMER2_PRE(io_base) = timer_reload;
	PCC_TIMER2_CTR(io_base) = 0x7;
	PCC_TIMER2_ICR(io_base) = 0x8e;
#endif
}

/*
 * Clock interrupts.
 */
int
clockintr(cap)
	void *cap;
{
#if 0
	volatile register unsigned char icr;
	/* clear clock interrupt */
	asm ("ld.b %0,%1" : "=r" (icr) : "" (TIMER2ICR));
	icr |= ICLR;
	asm ("st.b %0,%1" : "=r" (icr) : "" (TIMER2ICR));

	/* read the limit register to clear the interrupt */
#endif /* 0 */
	hardclock((struct clockframe *)cap);

	return (1);
}