Subject: Re: [linuxsh-dev] Dreamcast RTC
To: M. R. Brown <marcusb@uwm.edu>
From: Philipp Rumpf <prumpf@parcelfarce.linux.theplanet.co.uk>
List: port-sh3
Date: 12/01/2000 13:45:19
On Thu, Nov 30, 2000 at 06:34:51PM -0600, M. R. Brown wrote:
> The Dreamcast RTC is a 32-bit seconds counter at 0xa0710000 and 0xa0710004
> (32-bit registers).  a0710000 contains the high 16-bits in its LSW and
> a0710004 contains the low 16-bits.  The epoch or zero value (i.e. when the
> RTC starts counting) is January 1, 1950 00:00.

Are the counters latched when you read the first register ?  Otherwise you
might want to use the standard trick of doing

	do {
		val1 = (ctrl_inl(high word)<<16) + (ctrl_inl(low word)&0xffff);
		val2 = (ctrl_inl(high word)<<16) + (ctrl_inl(low word)&0xffff);
	} while(val1 != val2);

> I'm currently working on host-tools and I have a patch to newlib for
> gettimeofday (simply adds 20 years to the RTC val to get the Unix epoch of
> Jan. 1, 1970).  I'll post the code when I get to my workstation, tommorow.

subtract, I hope.

so arch/sh/kernel/time.c: get_rtc_time would look like this;

static unsigned long get_rtc_time(void)
{
	unsigned long val1, val2;

	do {
		val1 = (ctrl_inl(high word)<<16) + (ctrl_inl(low word)&0xffff);
		val2 = (ctrl_inl(high word)<<16) + (ctrl_inl(low word)&0xffff);
	} while(val1 != val2);

	/* should be date -d 'jan 1 0000 1950' '+%s'. */
	val1 -= 631152000;

	return val1;
}