1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * the Systems Programming Group of the University of Utah Computer 8 * Science Department and Ralph Campbell. 9 * 10 * %sccs.include.redist.c% 11 * 12 * from: Utah $Hdr: clockreg.h 1.14 91/01/18$ 13 * 14 * @(#)clockreg.h 8.1 (Berkeley) 06/10/93 15 */ 16 17 /* 18 * This file contains definitions for the MC 146818 real-time clock. 19 * 20 * For a detailed explanation of the chip, see the "PMAX Desktop 21 * Workstation Functional Specification, Revision 1.1" pages 62-66. 22 */ 23 #define SECMIN ((unsigned)60) /* seconds per minute */ 24 #define SECHOUR ((unsigned)(60*SECMIN)) /* seconds per hour */ 25 #define SECDAY ((unsigned)(24*SECHOUR)) /* seconds per day */ 26 #define SECYR ((unsigned)(365*SECDAY)) /* seconds per common year */ 27 28 #define YRREF 1970 29 #define LEAPYEAR(year) (((year) % 4) == 0) 30 31 /* 32 * Definitions for MC146818 real time clock 33 */ 34 struct chiptime { 35 u_char sec; /* current seconds */ 36 char dummy0[3]; 37 u_char alarm_sec; /* alarm seconds */ 38 char dummy1[3]; 39 u_char min; /* current minutes */ 40 char dummy2[3]; 41 u_char alarm_min; /* alarm minutes */ 42 char dummy3[3]; 43 u_char hour; /* current hours */ 44 char dummy4[3]; 45 u_char alarm_hour; /* alarm hours */ 46 char dummy5[3]; 47 u_char dayw; /* day of the week */ 48 char dummy6[3]; 49 u_char day; /* day of the month */ 50 char dummy7[3]; 51 u_char mon; /* month */ 52 char dummy8[3]; 53 u_char year; /* year */ 54 char dummy9[3]; 55 u_char rega; /* register a */ 56 char dummy10[3]; 57 u_char regb; /* register b */ 58 char dummy11[3]; 59 u_char regc; /* register c */ 60 char dummy12[3]; 61 u_char regd; /* register d */ 62 char dummy13[3]; 63 u_char nvram[50*4]; /* battery backed-up ram */ 64 }; 65 66 /* 67 * Control register A fields. 68 */ 69 #define REGA_UIP 0x80 70 #define REGA_TIME_DIV 0x70 71 #define REGA_RATE_SELECT 0x0F 72 73 /* 74 * Time base to use in the REGA_TIME_DIV field. 75 */ 76 #define REGA_TIME_BASE 0x20 77 78 /* 79 * Set the interval at 15.625 ms. 80 */ 81 #define SELECTED_RATE 0xA 82 83 /* 84 * Control register B fields. 85 */ 86 #define REGB_SET_TIME 0x80 87 #define REGB_PER_INT_ENA 0x40 88 #define REGB_UPDATE_INT_ENA 0x10 89 #define REGB_DATA_MODE 0x04 90 #define REGB_HOURS_FORMAT 0x02 91 92 /* 93 * Control register C fields. 94 */ 95 #define REGC_INT_PENDING 0x80 96 #define REGC_PER_INT_PENDING 0x40 97 #define REGC_UPDATE_INT_PENDING 0x10 98 99 /* 100 * Control register D fields. 101 */ 102 #define REGD_VALID_TIME 0x80 103 104 /* 105 * The RTC registers can only be accessed one byte at a time. 106 * This routine is used to write words into the non-volatile storage. 107 */ 108 109 #define BYTECOPY(a,b,num) { \ 110 int i; \ 111 for (i = 0; i < (num); i++) \ 112 ((char *) (b))[i] = ((char *) (a))[i]; \ 113 } 114