193835Stmm/*-
293835Stmm * Copyright (c) 1996 The NetBSD Foundation, Inc.
393835Stmm * All rights reserved.
493835Stmm *
593835Stmm * This code is derived from software contributed to The NetBSD Foundation
693835Stmm * by Gordon W. Ross
793835Stmm *
893835Stmm * Redistribution and use in source and binary forms, with or without
993835Stmm * modification, are permitted provided that the following conditions
1093835Stmm * are met:
1193835Stmm * 1. Redistributions of source code must retain the above copyright
1293835Stmm *    notice, this list of conditions and the following disclaimer.
1393835Stmm * 2. Redistributions in binary form must reproduce the above copyright
1493835Stmm *    notice, this list of conditions and the following disclaimer in the
1593835Stmm *    documentation and/or other materials provided with the distribution.
1693835Stmm *
1793835Stmm * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1893835Stmm * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1993835Stmm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2093835Stmm * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2193835Stmm * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2293835Stmm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2393835Stmm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2493835Stmm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2593835Stmm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2693835Stmm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2793835Stmm * POSSIBILITY OF SUCH DAMAGE.
2893835Stmm *
2993835Stmm *	$NetBSD: clock_subr.h,v 1.7 2000/10/03 13:41:07 tsutsui Exp $
3093835Stmm *
31178429Sphk *
32178429Sphk * This file is the central clearing-house for calendrical issues.
33178429Sphk *
34178429Sphk * In general the kernel does not know about minutes, hours, days, timezones,
35178429Sphk * daylight savings time, leap-years and such.  All that is theoretically a
36178429Sphk * matter for userland only.
37178429Sphk *
38178429Sphk * Parts of kernel code does however care: badly designed filesystems store
39178429Sphk * timestamps in local time and RTC chips sometimes track time in a local
40178429Sphk * timezone instead of UTC and so on.
41178429Sphk *
42178429Sphk * All that code should go here for service.
43178429Sphk *
4493835Stmm * $FreeBSD$
4593835Stmm */
4693835Stmm
4793835Stmm#ifndef _SYS_CLOCK_H_
4893835Stmm#define _SYS_CLOCK_H_
4993835Stmm
50162954Sphk#ifdef _KERNEL		/* No user serviceable parts */
51162954Sphk
5293835Stmm/*
53162954Sphk * Timezone info from settimeofday(2), usually not used
54162954Sphk */
55162954Sphkextern int tz_minuteswest;
56162954Sphkextern int tz_dsttime;
57162954Sphk
58162962Sphkint utc_offset(void);
59162962Sphk
60162954Sphk/*
6193835Stmm * Structure to hold the values typically reported by time-of-day clocks.
6293835Stmm * This can be passed to the generic conversion functions to be converted
6393835Stmm * to a struct timespec.
6493835Stmm */
6593835Stmmstruct clocktime {
66157084Simp	int	year;			/* year (4 digit year) */
6793835Stmm	int	mon;			/* month (1 - 12) */
6893835Stmm	int	day;			/* day (1 - 31) */
6993835Stmm	int	hour;			/* hour (0 - 23) */
7093835Stmm	int	min;			/* minute (0 - 59) */
7193835Stmm	int	sec;			/* second (0 - 59) */
7293835Stmm	int	dow;			/* day of week (0 - 6; 0 = Sunday) */
7393835Stmm	long	nsec;			/* nano seconds */
7493835Stmm};
7593835Stmm
7693835Stmmint clock_ct_to_ts(struct clocktime *, struct timespec *);
7793835Stmmvoid clock_ts_to_ct(struct timespec *, struct clocktime *);
7893835Stmmvoid clock_register(device_t, long);
7993835Stmm
8093835Stmm/*
8193835Stmm * BCD to decimal and decimal to BCD.
8293835Stmm */
83162954Sphk#define	FROMBCD(x)	bcd2bin(x)
84162954Sphk#define	TOBCD(x)	bin2bcd(x)
8593835Stmm
8693835Stmm/* Some handy constants. */
8793835Stmm#define SECDAY		(24 * 60 * 60)
8893835Stmm#define SECYR		(SECDAY * 365)
8993835Stmm
9093835Stmm/* Traditional POSIX base year */
9193835Stmm#define	POSIX_BASE_YEAR	1970
9293835Stmm
93163646Sphkvoid timespec2fattime(struct timespec *tsp, int utc, u_int16_t *ddp, u_int16_t *dtp, u_int8_t *dhp);
94163646Sphkvoid fattime2timespec(unsigned dd, unsigned dt, unsigned dh, int utc, struct timespec *tsp);
95163611Sphk
96162954Sphk#endif /* _KERNEL */
97162954Sphk
9893835Stmm#endif /* !_SYS_CLOCK_H_ */
99