[comp.sys.nsc.32k] /dev/rtc

kls@ditka.UUCP (Karl Swartz) (09/13/90)

Johan Myreen <jem@cs.hut.fi> writes:

> I myself have written something that also might interest you out
> there: a driver for the real time clock. You talk to it through the
> special file /dev/rtc

That would be very nice indeed.  If I can ever manage to get the
sources I'll enhance the date command to use this.  What will your
driver do if there's no clock installed?  It would be nice to have
some automagic way of detecting that so you wouldn't have to diddle
with a kernel option to use the thing.

> but I have no net access at home

I'm about ready to take a look at the dialer part of uucp; currently
I just have ditka (my 3B1) poll halas (my pc532) on a regular basis.
Once the uucp dialer code is working anybody with a pc532, a phone,
and a modem should be able to have direct net access.

--
Karl Swartz			 |UUCP	uunet!apple!zygot!ditka!kls
1-408/223-1308			 |INet	zygot!ditka!kls@apple.com
"I never let my schooling get in |BIX	kswartz
the way of my education."(Twain) |Snail	1738 Deer Creek Ct., San Jose CA 95148

culberts@hplwbc.hpl.hp.com (Bruce Culbertson) (09/13/90)

> Karl Swartz writes:
> 
> Johan Myreen <jem@cs.hut.fi> writes:
> 
> > I myself have written something that also might interest you out
> > there: a driver for the real time clock. You talk to it through the
> > special file /dev/rtc
> 
> That would be very nice indeed.  If I can ever manage to get the
> sources I'll enhance the date command to use this.  What will your
> driver do if there's no clock installed?  It would be nice to have
> some automagic way of detecting that so you wouldn't have to diddle
> with a kernel option to use the thing.

What about putting something like this in /etc/rc:

	# set system date
	if (test -c /dev/rtc)
	then
	  # read date from hardware real time clock
	  date_formatter < /dev/rtc | date -q
	else
	  # prompt user for date
	  date -q
	fi

Date_formatter (to be written, but trivial) converts the eight bytes
from the real time clock chip into the mmddyyhhmmss format which
the date command likes.  The date command would be unchanged.  Also,
we would remove the RTC code which I supplied from the kernel.
If you have an RTC, you mknod /etc/rtc; if not, you do not mknod
/dev/rtc.  The kernel would have a new device driver but otherwise
would not know about the RTC.

I think this is clean -- what do you think?

Bruce

kls@halas.UUCP (Karl Swartz) (09/14/90)

I just installed Johan's /dev/rtc code and it works just fine.
A couple of missing pieces did crop up along the way though:

    /usr/src/minix/Makefile

	Add -DRTC to CFLAGS to enable RTC code.

    /usr/src/minix/h/com.h

	Minor device numbers for the new devices need to be
	added after the define for NULL_DEV:

	    #define NULL_DEV	3
	    #define RTC_DEV	4
	    #define ROM_DEV	5

I also discovered in the process of seeing if the code worked
that the -x option to od does not work properly.  Rather than
displaying each word in hex, it displays the lower word of each
*double* word in hex.  Sounds like the pointer is declared to
be an (int *) when it should be a (short *).  And when you use
od -o, don't forget that the RTC values are BCD.  That got me
confused for a minute or two.

Anyway, I plan on modifying the date command to read and write
/dev/rtc if it's found, and to do what makes sense at boot time.
(BTW, it appears that the system is on PST -- Pacific Standard
Time -- and not PDT.  Probably doesn't understand other zones
but I haven't looked at this one yet.)

Thanks for writing /dev/rtc and /dev/rom, Johan!

 -- Karl