clock.h revision 162954
1139826Simp/*-
253541Sshin * Copyright (c) 1996 The NetBSD Foundation, Inc.
353541Sshin * All rights reserved.
453541Sshin *
553541Sshin * This code is derived from software contributed to The NetBSD Foundation
653541Sshin * by Gordon W. Ross
753541Sshin *
853541Sshin * Redistribution and use in source and binary forms, with or without
953541Sshin * modification, are permitted provided that the following conditions
1053541Sshin * are met:
1153541Sshin * 1. Redistributions of source code must retain the above copyright
1253541Sshin *    notice, this list of conditions and the following disclaimer.
1353541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1453541Sshin *    notice, this list of conditions and the following disclaimer in the
1553541Sshin *    documentation and/or other materials provided with the distribution.
1653541Sshin * 3. All advertising materials mentioning features or use of this software
1753541Sshin *    must display the following acknowledgement:
1853541Sshin *        This product includes software developed by the NetBSD
1953541Sshin *        Foundation, Inc. and its contributors.
2053541Sshin * 4. Neither the name of The NetBSD Foundation nor the names of its
2153541Sshin *    contributors may be used to endorse or promote products derived
2253541Sshin *    from this software without specific prior written permission.
2353541Sshin *
2453541Sshin * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2553541Sshin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2653541Sshin * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2753541Sshin * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28174510Sobrien * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29174510Sobrien * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3053541Sshin * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3153541Sshin * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32174510Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33174510Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34174510Sobrien * POSSIBILITY OF SUCH DAMAGE.
3562587Sitojun *
3662587Sitojun *	$NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $
37254889Smarkj *
3862587Sitojun * $FreeBSD: head/sys/sys/clock.h 162954 2006-10-02 12:59:59Z phk $
3953541Sshin */
4053541Sshin
4178064Sume#ifndef _SYS_CLOCK_H_
4253541Sshin#define _SYS_CLOCK_H_
4353541Sshin
4453541Sshin#ifdef _KERNEL		/* No user serviceable parts */
4553541Sshin
4653541Sshin/*
4753541Sshin * Kernel to clock driver interface.
4862587Sitojun */
4953541Sshinvoid	inittodr(time_t base);
5053541Sshinvoid	resettodr(void);
51186119Sqinglivoid	startrtclock(void);
52186119Sqingliextern int	wall_cmos_clock;
5353541Sshinextern int	adjkerntz;
54254889Smarkjextern int	disable_rtc_set;
5578064Sume
5653541Sshin/*
5753541Sshin * Timezone info from settimeofday(2), usually not used
58121283Sume */
5953541Sshinextern int tz_minuteswest;
6053541Sshinextern int tz_dsttime;
61120049Smdodd
6293920Smdodd/*
6353541Sshin * Structure to hold the values typically reported by time-of-day clocks.
64185571Sbz * This can be passed to the generic conversion functions to be converted
6553541Sshin * to a struct timespec.
6653541Sshin */
67254889Smarkjstruct clocktime {
68186119Sqingli	int	year;			/* year (4 digit year) */
69186119Sqingli	int	mon;			/* month (1 - 12) */
7053541Sshin	int	day;			/* day (1 - 31) */
7153541Sshin	int	hour;			/* hour (0 - 23) */
7262587Sitojun	int	min;			/* minute (0 - 59) */
7353541Sshin	int	sec;			/* second (0 - 59) */
74148385Sume	int	dow;			/* day of week (0 - 6; 0 = Sunday) */
7553541Sshin	long	nsec;			/* nano seconds */
76197138Shrs};
7762587Sitojun
78211501Sanchieint clock_ct_to_ts(struct clocktime *, struct timespec *);
7953541Sshinvoid clock_ts_to_ct(struct timespec *, struct clocktime *);
80151539Ssuzvoid clock_register(device_t, long);
81151539Ssuz
82163606Srwatson/*
83163606Srwatson * BCD to decimal and decimal to BCD.
8462587Sitojun */
8562587Sitojun#define	FROMBCD(x)	bcd2bin(x)
8653541Sshin#define	TOBCD(x)	bin2bcd(x)
87249925Sglebius
8853541Sshin/* Some handy constants. */
89207369Sbz#define SECDAY		(24 * 60 * 60)
90207369Sbz#define SECYR		(SECDAY * 365)
91207369Sbz
92207369Sbz/* Traditional POSIX base year */
93207369Sbz#define	POSIX_BASE_YEAR	1970
94207369Sbz
95207369Sbz#endif /* _KERNEL */
96207369Sbz
97207369Sbz#endif /* !_SYS_CLOCK_H_ */
9853541Sshin