xref: /netbsd-src/share/man/man9/todr.9 (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1.\" $NetBSD: todr.9,v 1.6 2003/04/16 13:35:34 wiz Exp $
2.\"
3.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Paul Kranenburg.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd July 22, 2000
38.Dt TODR 9
39.Os
40.Sh NAME
41.Nm todr_gettime
42.Nm todr_settime
43.Nm todr_getcal
44.Nm todr_setcal
45.Nm clock_ymdhms_to_secs
46.Nm clock_secs_to_ymdhms
47.Nd time-of-day clock support
48.Sh SYNOPSIS
49.In dev/clock_subr.h
50.Ft int
51.Fn todr_gettime "todr_chip_handle_t" "struct timeval *"
52.Ft int
53.Fn todr_settime "todr_chip_handle_t" "struct timeval *"
54.Ft int
55.Fn todr_getcal "todr_chip_handle_t" "int *"
56.Ft int
57.Fn todr_setcal "todr_chip_handle_t" "int"
58.Ft void
59.Fn clock_secs_to_ymdhms "int" "struct clock_ymdhms *"
60.Ft time_t
61.Fn clock_ymdhms_to_secs "struct clock_ymdhms *"
62.Sh DESCRIPTION
63The
64.Fn todr_*
65functions provide an interface to read, set and control
66.Ql time-of-day
67devices.
68The
69.Fa todr_chip_handle_t
70should be obtained from a driver for a particular hardware device that
71implements this interface.
72Examples of such drivers currently include
73.Xr mk48txx 4
74and
75.Xr intersil7170 4 .
76.Pp
77The
78.Fn todr_gettime
79retrieves the current data and time from the TODR device and returns it
80in the
81.Fa struct timeval
82storage provided by the caller.
83.Fn todr_settime
84sets the date and time in the TODR device represented by
85.Fa todr_chip_handle_t
86according to the
87.Fa struct timeval
88argument.
89.Pp
90.Fn todr_setcal
91specifies a calibration value in PPM units to be programmed in the TODR
92device.
93Positive values shall speed up the TODR clock, negative values
94shall slow it down.
95If the device in not capable of handling calibration,
96this function shall return
97.Va EOPNOTSUPP .
98The measurement and calculations necessary to use this method is
99expected to be provided by higher-level software modules.
100.Fn todr_getcal
101returns the current calibration (in PPM units) in effect on the TODR device.
102.Pp
103The utilities
104.Fn clock_secs_to_ymdhms
105and
106.Fn clock_ymdhms_to_secs
107are provided to convert a time value in seconds to and from a structure
108representing the date and time as a
109.Aq year,month,day,weekday,hour,minute,seconds
110tuple.
111This structure is defined as follows:
112.Bd -literal
113struct clock_ymdhms {
114	u_short dt_year;	/* Year */
115	u_char dt_mon;		/* Month (1-12) */
116	u_char dt_day;		/* Day (0-365) */
117	u_char dt_wday;		/* Day of week (0-6) */
118	u_char dt_hour;		/* Hour (0-23) */
119	u_char dt_min;		/* Minute (0-59) */
120	u_char dt_sec;		/* Second (0-59) */
121};
122.Ed
123.Pp
124Note: leap years are recognised by these conversion routines.
125.Sh RETURN VALUES
126The
127.Fn todr_*
128functions return 0 if the requested operation was successful;
129otherwise an error code from
130.Aq Pa sys/errno.h
131shall be returned.
132However, behaviour is undefined if an invalid
133.Fa todr_chip_handle_t
134is passed to any of these functions.
135The
136.Fn clock_secs_to_ymdhms
137and
138.Fn clock_ymdhms_to_secs
139functions never fail.
140.Sh SEE ALSO
141.Xr inittodr 9 ,
142.Xr resettodr 9 ,
143.Xr time 9
144