xref: /csrg-svn/sys/pmax/pmax/clockreg.h (revision 63218)
152119Smckusick /*
252119Smckusick  * Copyright (c) 1988 University of Utah.
3*63218Sbostic  * Copyright (c) 1992, 1993
4*63218Sbostic  *	The Regents of the University of California.  All rights reserved.
552119Smckusick  *
652119Smckusick  * This code is derived from software contributed to Berkeley by
752119Smckusick  * the Systems Programming Group of the University of Utah Computer
852119Smckusick  * Science Department and Ralph Campbell.
952119Smckusick  *
1052119Smckusick  * %sccs.include.redist.c%
1152119Smckusick  *
1252119Smckusick  * from: Utah $Hdr: clockreg.h 1.14 91/01/18$
1352119Smckusick  *
14*63218Sbostic  *	@(#)clockreg.h	8.1 (Berkeley) 06/10/93
1552119Smckusick  */
1652119Smckusick 
1752119Smckusick /*
1852119Smckusick  * This file contains definitions for the MC 146818 real-time clock.
1952119Smckusick  *
2052119Smckusick  * For a detailed explanation of the chip, see the "PMAX Desktop
2152119Smckusick  * Workstation Functional Specification, Revision 1.1" pages 62-66.
2252119Smckusick  */
2352119Smckusick #define	SECMIN	((unsigned)60)			/* seconds per minute */
2452119Smckusick #define	SECHOUR	((unsigned)(60*SECMIN))		/* seconds per hour */
2552119Smckusick #define	SECDAY	((unsigned)(24*SECHOUR))	/* seconds per day */
2652119Smckusick #define	SECYR	((unsigned)(365*SECDAY))	/* seconds per common year */
2752119Smckusick 
2852119Smckusick #define	YRREF		1970
2952119Smckusick #define	LEAPYEAR(year)	(((year) % 4) == 0)
3052119Smckusick 
3152119Smckusick /*
3252119Smckusick  * Definitions for MC146818 real time clock
3352119Smckusick  */
3452119Smckusick struct chiptime {
3552119Smckusick 	u_char	sec;		/* current seconds */
3652119Smckusick 	char	dummy0[3];
3752119Smckusick 	u_char	alarm_sec;	/* alarm seconds */
3852119Smckusick 	char	dummy1[3];
3952119Smckusick 	u_char	min;		/* current minutes */
4052119Smckusick 	char	dummy2[3];
4152119Smckusick 	u_char	alarm_min;	/* alarm minutes */
4252119Smckusick 	char	dummy3[3];
4352119Smckusick 	u_char	hour;		/* current hours */
4452119Smckusick 	char	dummy4[3];
4552119Smckusick 	u_char	alarm_hour;	/* alarm hours */
4652119Smckusick 	char	dummy5[3];
4752119Smckusick 	u_char	dayw;		/* day of the week */
4852119Smckusick 	char	dummy6[3];
4952119Smckusick 	u_char	day;		/* day of the month */
5052119Smckusick 	char	dummy7[3];
5152119Smckusick 	u_char	mon;		/* month */
5252119Smckusick 	char	dummy8[3];
5352119Smckusick 	u_char	year;		/* year */
5452119Smckusick 	char	dummy9[3];
5552119Smckusick 	u_char	rega;		/* register a */
5652119Smckusick 	char	dummy10[3];
5752119Smckusick 	u_char	regb;		/* register b */
5852119Smckusick 	char	dummy11[3];
5952119Smckusick 	u_char	regc;		/* register c */
6052119Smckusick 	char	dummy12[3];
6152119Smckusick 	u_char	regd;		/* register d */
6252119Smckusick 	char	dummy13[3];
6352119Smckusick 	u_char	nvram[50*4];	/* battery backed-up ram */
6452119Smckusick };
6552119Smckusick 
6652119Smckusick /*
6752119Smckusick  * Control register A fields.
6852119Smckusick  */
6952119Smckusick #define REGA_UIP		0x80
7052119Smckusick #define REGA_TIME_DIV		0x70
7152119Smckusick #define REGA_RATE_SELECT	0x0F
7252119Smckusick 
7352119Smckusick /*
7452119Smckusick  * Time base to use in the REGA_TIME_DIV field.
7552119Smckusick  */
7652119Smckusick #define REGA_TIME_BASE		0x20
7752119Smckusick 
7852119Smckusick /*
7952119Smckusick  * Set the interval at 15.625 ms.
8052119Smckusick  */
8152119Smckusick #define SELECTED_RATE		0xA
8252119Smckusick 
8352119Smckusick /*
8452119Smckusick  * Control register B fields.
8552119Smckusick  */
8652119Smckusick #define REGB_SET_TIME		0x80
8752119Smckusick #define REGB_PER_INT_ENA	0x40
8852119Smckusick #define REGB_UPDATE_INT_ENA	0x10
8952119Smckusick #define REGB_DATA_MODE		0x04
9052119Smckusick #define REGB_HOURS_FORMAT	0x02
9152119Smckusick 
9252119Smckusick /*
9352119Smckusick  * Control register C fields.
9452119Smckusick  */
9552119Smckusick #define REGC_INT_PENDING	0x80
9652119Smckusick #define REGC_PER_INT_PENDING	0x40
9752119Smckusick #define REGC_UPDATE_INT_PENDING	0x10
9852119Smckusick 
9952119Smckusick /*
10052119Smckusick  * Control register D fields.
10152119Smckusick  */
10252119Smckusick #define REGD_VALID_TIME		0x80
10352119Smckusick 
10452119Smckusick /*
10552119Smckusick  * The RTC registers can only be accessed one byte at a time.
10652119Smckusick  * This routine is used to write words into the non-volatile storage.
10752119Smckusick  */
10852119Smckusick 
10952119Smckusick #define BYTECOPY(a,b,num) { \
11052119Smckusick 	int i; \
11152119Smckusick 	for (i = 0; i < (num); i++) \
11252119Smckusick 		((char *) (b))[i] = ((char *) (a))[i]; \
11352119Smckusick }
114