xref: /original-bsd/sys/luna68k/luna68k/clockreg.h (revision 3b3772fe)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1992 OMRON Corporation.
4  * Copyright (c) 1982, 1990, 1992 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * %sccs.include.redist.c%
12  *
13  * from: Utah $Hdr: clockreg.h 1.14 91/01/18$
14  * OMRON: $Id: clockreg.h,v 1.1 92/05/27 14:24:52 moti Exp $
15  *
16  * from: hp300/hp300/clockreg.h	7.3 (Berkeley) 5/7/91
17  *
18  *	@(#)clockreg.h	7.2 (Berkeley) 10/11/92
19  */
20 
21 /*
22  *  LUNA system clock defines
23  */
24 #define	CLOCK_REG	0x63000000	/* system clock address */
25 
26 #define	CLK_INT		0x7		/* system clock intr flag */
27 #define	CLK_CLR		0x1		/* system clock intr clear */
28 
29 /*
30  * LUNA battery-backed clock
31  */
32 
33 /* only use software */
34 struct bbc_tm {
35 	int	tm_sec;
36 	int	tm_min;
37 	int	tm_hour;
38 	int	tm_mday;
39 	int	tm_mon;
40 	int	tm_year;
41 };
42 
43 #define FEBRUARY	2
44 #define	STARTOFTIME	1970
45 #define SECDAY		86400L
46 #define SECYR		(SECDAY * 365)
47 
48 #define	leapyear(year)		((year) % 4 == 0)
49 #define	range_test(n, l, h)	if ((n) < (l) || (n) > (h)) return(0)
50 #define	days_in_year(a) 	(leapyear(a) ? 366 : 365)
51 #define	days_in_month(a) 	(month_days[(a) - 1])
52 
53 /*
54  * TIME KEEPER RAM -- (MK48T02/12(B)-12/15/20/25)
55  */
56 
57 #include <luna68k/dev/nvram.h>
58 
59 struct bbc {
60     struct nvram 	nvram;	       	/* non-volatile RAM area */
61     unsigned char    	cal_ctl;       	/* calender control resistor */
62     unsigned char	cal_sec;       	/* secons resistor */
63     unsigned char	cal_min;       	/* minutes resistor */
64     unsigned char	cal_hour;      	/* hours resitor */
65     unsigned char	cal_dow;       	/* day of the weeks */
66     unsigned char	cal_day;       	/* days resistor */
67     unsigned char	cal_mon;       	/* months resistor */
68     unsigned char	cal_year;      	/* years resistor */
69 };
70 
71 #define	BBC_ADDR	0x45000000	/* battery backuped clock address */
72 
73 #define	BBC_FRQ		0x40		/* Frequency test (in day) */
74 #define	BBC_KICK	0x80		/* Kick start (in hour) */
75 #define	BBC_STOP	0x80		/* Stop bit (in seconds) */
76 #define	BBC_WRT		0x80		/* Write bit (in control) */
77 #define	BBC_RD		0x40		/* Read bit (in control) */
78 #define	BBC_SGN		0x20		/* Sign bit (in control) */
79 #define	BBC_DELAY	180		/* delay time */
80 
81 #define	binary_to_bcd(i)	(((i) / 10) << 4 | ((i) % 10))
82 #define	bcd_to_binary(i)	(((i) >> 4) *10 + ((i) & 0x0F))
83