Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Oct 1998 06:57:50 +1000
From:      Peter Jeremy <peter.jeremy@auss2.alcatel.com.au>
To:        hackers@FreeBSD.ORG
Subject:   Re: Reading CMOS date values
Message-ID:  <98Oct23.065720est.40321@border.alcanet.com.au>

next in thread | raw e-mail | index | archive | help
On Wed, 21 Oct 1998 12:02:37 +0200 (CEST), Reinier Bezuidenhout <Reinier.Bezuidenhout@KryptoKom.DE> 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?98Oct23.065720est.40321>