1.\" $NetBSD: todr.9,v 1.8 2003/08/07 09:41:14 wiz Exp $ 2.\" 3.\" Copyright (c) 2000, 2003 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 18, 2003 38.Dt TODR 9 39.Os 40.Sh NAME 41.Nm todr_attach , 42.Nm todr_gettime , 43.Nm todr_settime , 44.Nm todr_getcal , 45.Nm todr_setcal , 46.Nm clock_ymdhms_to_secs , 47.Nm clock_secs_to_ymdhms 48.Nd time-of-day clock support 49.Sh SYNOPSIS 50.In dev/clock_subr.h 51.Ft void 52.Fn todr_attach "todr_chip_handle_t" 53.Ft int 54.Fn todr_gettime "todr_chip_handle_t" "struct timeval *" 55.Ft int 56.Fn todr_settime "todr_chip_handle_t" "struct timeval *" 57.Ft int 58.Fn todr_getcal "todr_chip_handle_t" "int *" 59.Ft int 60.Fn todr_setcal "todr_chip_handle_t" "int" 61.Ft void 62.Fn clock_secs_to_ymdhms "int" "struct clock_ymdhms *" 63.Ft time_t 64.Fn clock_ymdhms_to_secs "struct clock_ymdhms *" 65.Sh DESCRIPTION 66The 67.Fn todr_* 68functions provide an interface to read, set and control 69.Ql time-of-day 70devices. 71A driver for a 72.Ql time-of-day 73device registers its 74.Fa todr_chip_handle_t 75with machine-dependent code using the 76.Fn todr_attach 77function. 78Alternatively, a machine-dependent front-end to a 79.Ql time-of-day 80device driver may obtain the 81.Fa todr_chip_handle_t 82directly. 83.Pp 84The 85.Fn todr_gettime 86retrieves the current data and time from the TODR device and returns it 87in the 88.Fa struct timeval 89storage provided by the caller. 90.Fn todr_settime 91sets the date and time in the TODR device represented by 92.Fa todr_chip_handle_t 93according to the 94.Fa struct timeval 95argument. 96.Pp 97.Fn todr_setcal 98specifies a calibration value in PPM units to be programmed in the TODR 99device. 100Positive values shall speed up the TODR clock, negative values 101shall slow it down. 102If the device in not capable of handling calibration, 103this function shall return 104.Va EOPNOTSUPP . 105The measurement and calculations necessary to use this method is 106expected to be provided by higher-level software modules. 107.Fn todr_getcal 108returns the current calibration (in PPM units) in effect on the TODR device. 109.Pp 110The utilities 111.Fn clock_secs_to_ymdhms 112and 113.Fn clock_ymdhms_to_secs 114are provided to convert a time value in seconds to and from a structure 115representing the date and time as a 116.Aq year,month,day,weekday,hour,minute,seconds 117tuple. 118This structure is defined as follows: 119.Bd -literal 120struct clock_ymdhms { 121 u_short dt_year; /* Year */ 122 u_char dt_mon; /* Month (1-12) */ 123 u_char dt_day; /* Day (0-365) */ 124 u_char dt_wday; /* Day of week (0-6) */ 125 u_char dt_hour; /* Hour (0-23) */ 126 u_char dt_min; /* Minute (0-59) */ 127 u_char dt_sec; /* Second (0-59) */ 128}; 129.Ed 130.Pp 131Note: leap years are recognised by these conversion routines. 132.Sh RETURN VALUES 133The 134.Fn todr_* 135functions return 0 if the requested operation was successful; 136otherwise an error code from 137.Aq Pa sys/errno.h 138shall be returned. 139However, behaviour is undefined if an invalid 140.Fa todr_chip_handle_t 141is passed to any of these functions. 142The 143.Fn clock_secs_to_ymdhms 144and 145.Fn clock_ymdhms_to_secs 146functions never fail. 147.Sh SEE ALSO 148.Xr intersil7170 4 , 149.Xr mk48txx 4 , 150.Xr inittodr 9 , 151.Xr resettodr 9 , 152.Xr time 9 153