From owner-freebsd-hackers Thu Oct 22 13:58:37 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA29190 for freebsd-hackers-outgoing; Thu, 22 Oct 1998 13:58:37 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from alcanet.com.au (border.alcanet.com.au [203.62.196.10]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA29171 for ; Thu, 22 Oct 1998 13:58:29 -0700 (PDT) (envelope-from peter.jeremy@auss2.alcatel.com.au) Received: by border.alcanet.com.au id <40321>; Fri, 23 Oct 1998 06:57:20 +1000 Date: Fri, 23 Oct 1998 06:57:50 +1000 From: Peter Jeremy Subject: Re: Reading CMOS date values To: hackers@FreeBSD.ORG Message-Id: <98Oct23.065720est.40321@border.alcanet.com.au> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, 21 Oct 1998 12:02:37 +0200 (CEST), Reinier Bezuidenhout wrote: >I'd like to read the CMOS values for the day, hour and minutes. Note that the CMOS clock will normally be kept in UTC, so the HMS that you read will not be local time. Also, the CMOS clock can drift WRT the system clock (especially if you use adjtime), so the time you read from the CMOS clock may be different to the kernel TOD clock. >I'd like to get the day of the week, hour and minutes without >having to call microtime and then convert the values. Assuming you want UTC, this is all quite simple - just some divisions and modulos. The difficulties come when you want local time and/or year/month/day or day of year. The following code fragment should work: extern volatile struct timeval time; int sec, minute, hour; int dow; /* 0[Sunday] .. 6[Saturday] */ { long now = time.tv_sec; sec = now % 60; now /= 60; min = now % 60; now /= 60; hour = now % 24; now /= 24; dow = (now + 4) % 7; /* 1970-JAN-01 is Thursday == 4 */ } Note that the above code is likely to be _faster_ than reading the RTC on most systems (because the RTC is sitting on the abyssmally slow ISA bus and needs 2 I/O instructions per field). >Has anyone done this before ?? Some time ago, I wrote a device driver that provided access to the CMOS clock and RAM. I can dig it out over the weekend if there's sufficient interest. Peter -- Peter Jeremy (VK2PJ) peter.jeremy@alcatel.com.au Alcatel Australia Limited 41 Mandible St Phone: +61 2 9690 5019 ALEXANDRIA NSW 2015 Fax: +61 2 9690 5247 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message