1.\" $NetBSD: todr.9,v 1.3 2002/02/13 08:18:52 ross 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.Fd #include \*[Lt]dev/clock_subr.h\*[Gt] 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. The 68.Fa todr_chip_handle_t 69should be obtained from a driver for a particular hardware device that 70implements this interface. Examples of such drivers currently include 71.Xr mk48txx 4 72and 73.Xr intersil7170 4 . 74.Pp 75The 76.Fn todr_gettime 77retrieves the current data and time from the TODR device and returns it 78in the 79.Fa struct timeval 80storage provided by the caller. 81.Fn todr_settime 82sets the date and time in the TODR device represented by 83.Fa todr_chip_handle_t 84according to the 85.Fa struct timeval 86argument. 87.Pp 88.Fn todr_setcal 89specifies a calibration value in PPM units to be programmed in the TODR 90device. Positive values shall speed up the TODR clock, negative values 91shall slow it down. If the device in not capable of handling calibration, 92this function shall return 93.Va EOPNOTSUPP . 94The measurement and calculations necessary to utilize this method is 95expected to be provided by higher-level software modules. 96.Fn todr_getcal 97returns the current calibration (in PPM units) in effect on the TODR device. 98.Pp 99The utilities 100.Fn clock_secs_to_ymdhms 101and 102.Fn clock_ymdhms_to_secs 103are provided to convert a time value in seconds to and from a structure 104representing the date and time as a 105.Aq year,month,day,weekday,hour,minute,seconds 106tuple. This structure is defined as follows: 107.Bd -literal 108struct clock_ymdhms { 109 u_short dt_year; /* Year */ 110 u_char dt_mon; /* Month (1-12) */ 111 u_char dt_day; /* Day (0-365) */ 112 u_char dt_wday; /* Day of week (0-6) */ 113 u_char dt_hour; /* Hour (0-23) */ 114 u_char dt_min; /* Minute (0-59) */ 115 u_char dt_sec; /* Second (0-59) */ 116}; 117.Ed 118.Pp 119Note: leap years are recognised by these conversion routines. 120.Sh RETURN VALUES 121The 122.Fn todr_* 123functions return 0 if the requested operation was successful; 124otherwise an error code from 125.Aq Pa sys/errno.h 126shall be returned. However, behaviour is undefined if an invalid 127.Fa todr_chip_handle_t 128is passed to any of these functions. 129The 130.Fn clock_secs_to_ymdhms 131and 132.Fn clock_ymdhms_to_secs 133functions never fail. 134.Sh SEE ALSO 135.Xr inittodr 9 , 136.Xr resettodr 9 , 137.Xr time 9 138