Home | History | Annotate | Line # | Download | only in lib
getsecs.c revision 1.1
      1  1.1  perry /*	$NetBSD: getsecs.c,v 1.1 1997/03/14 02:40:32 perry Exp $	*/
      2  1.1  perry 
      3  1.1  perry /* extracted from netbsd:sys/arch/i386/netboot/misc.c */
      4  1.1  perry 
      5  1.1  perry #include <sys/types.h>
      6  1.1  perry 
      7  1.1  perry #include <lib/libsa/stand.h>
      8  1.1  perry 
      9  1.1  perry #include "libi386.h"
     10  1.1  perry 
     11  1.1  perry extern int biosgetrtc __P((u_long*));
     12  1.1  perry 
     13  1.1  perry static inline u_long
     14  1.1  perry bcd2dec(arg)
     15  1.1  perry u_long arg;
     16  1.1  perry {
     17  1.1  perry   return((arg >> 4) * 10 + (arg & 0x0f));
     18  1.1  perry }
     19  1.1  perry 
     20  1.1  perry time_t
     21  1.1  perry getsecs() {
     22  1.1  perry   /*
     23  1.1  perry    * Return the current time in seconds
     24  1.1  perry    */
     25  1.1  perry 
     26  1.1  perry   u_long t;
     27  1.1  perry   time_t sec;
     28  1.1  perry 
     29  1.1  perry   if(biosgetrtc(&t))
     30  1.1  perry       panic("RTC invalid");
     31  1.1  perry 
     32  1.1  perry   sec = bcd2dec(t & 0xff);
     33  1.1  perry   sec *= 60;
     34  1.1  perry   t >>= 8;
     35  1.1  perry   sec += bcd2dec(t & 0xff);
     36  1.1  perry   sec *= 60;
     37  1.1  perry   t >>= 8;
     38  1.1  perry   sec += bcd2dec(t & 0xff);
     39  1.1  perry 
     40  1.1  perry   return(sec);
     41  1.1  perry }
     42