plan 9 kernel history: overview | file list | diff list

1997/0401/carrera/devrtc.c (diff list | history)

1997/0401/sys/src/9/carrera/devrtc.c:35,421997/0403/sys/src/9/carrera/devrtc.c:35,47 (short | long | prev | next)
1993/0916    
	Month=		0x08, 
	Year=		0x09, 
	Status=		0x0A, 
1997/0403    
	StatusB=	0x0B, 
	StatusC=	0x0C, 
	StatusD=	0x0D, 
1993/0916    
 
	Nvsize = 4096, 
1997/0403    
 
	Nclock=		6, 
1993/0916    
}; 
 
Dirtab rtcdir[]={ 
1997/0401/sys/src/9/carrera/devrtc.c:47,551997/0403/sys/src/9/carrera/devrtc.c:52,82
1997/0327    
static ulong rtc2sec(Rtc*); 
static void sec2rtc(ulong, Rtc*); 
1993/0916    
 
1997/0403    
static uchar statusB; 
 
static void 
getstatusB(void) 
{ 
	int i, x; 
	uchar r; 
 
	for(i = 0; i < 10000; i++){ 
		x = (*(uchar*)Rtcindex)&~0x7f; 
		*(uchar*)Rtcindex = x|Status; 
		r = *(uchar*)Rtcdata; 
		if(r & 0x80) 
			continue; 
 
		*(uchar*)Rtcindex = x|StatusB; 
		statusB = *(uchar*)Rtcdata; 
		break; 
	} 
} 
 
1997/0327    
static Chan* 
1993/0916    
rtcattach(char *spec) 
{ 
1997/0403    
	getstatusB(); 
1993/0916    
	return devattach('r', spec); 
} 
 
1997/0401/sys/src/9/carrera/devrtc.c:98,1331997/0403/sys/src/9/carrera/devrtc.c:125,226
1993/0916    
	return (x&0xf) + 10*(x>>4); 
} 
 
1997/0403    
#define GETBCD(o) ((clock[o]&0xf) + 10*(clock[o]>>4)) 
 
static void 
dumprtcstatus(void) 
{ 
	int i, x; 
	uchar status[4], r; 
 
	for(i = 0; i < 10000; i++){ 
		x = (*(uchar*)Rtcindex)&~0x7f; 
		*(uchar*)Rtcindex = x|Status; 
		r = *(uchar*)Rtcdata; 
		if(r & 0x80) 
			continue; 
 
		status[0] = r; 
		*(uchar*)Rtcindex = x|StatusB; 
		status[1] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|StatusC; 
		status[2] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|StatusD; 
		status[3] = *(uchar*)Rtcdata; 
 
		*(uchar*)Rtcindex = x|Status; 
		r = *(uchar*)Rtcdata; 
		if((r & 0x80) == 0) 
			break; 
	} 
 
	print("RTC: %uX %uX %uX %uX\n", status[0], status[1], status[2], status[3]); 
} 
 
1997/0401    
static long	  
_rtctime(void) 
1993/0916    
{ 
	Rtc rtc; 
1997/0401    
	int i, x; 
1997/0403    
	uchar clock[Nclock], r; 
	int busy; 
1993/0916    
 
1997/0403    
	/* don't do the read until the clock is no longer busy */ 
	busy = 0; 
1997/0401    
	for(i = 0; i < 10000; i++){ 
		x = (*(uchar*)Rtcindex)&~0x7f; 
		*(uchar*)Rtcindex = x|Status; 
		x = *(uchar*)Rtcdata; 
		if(x & 0x80) 
1997/0403    
		r = *(uchar*)Rtcdata; 
		if(r & 0x80){ 
			busy++; 
1997/0401    
			continue; 
1997/0403    
		} 
1993/0916    
 
1997/0401    
		/* 
		 *  read and convert from bcd 
		 */ 
		rtc.sec = bcd2binary(Seconds); 
		rtc.min = bcd2binary(Minutes); 
		rtc.hour = bcd2binary(Hours); 
		rtc.mday = bcd2binary(Mday); 
		rtc.mon = bcd2binary(Month); 
		rtc.year = bcd2binary(Year)+1970; 
1997/0403    
		/* read clock values */ 
		*(uchar*)Rtcindex = x|Seconds; 
		clock[0] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|Minutes; 
		clock[1] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|Hours; 
		clock[2] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|Mday; 
		clock[3] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|Month; 
		clock[4] = *(uchar*)Rtcdata; 
		*(uchar*)Rtcindex = x|Year; 
		clock[5] = *(uchar*)Rtcdata; 
1997/0401    
 
		x = (*(uchar*)Rtcindex)&~0x7f; 
		*(uchar*)Rtcindex = x|Status; 
		x = *(uchar*)Rtcdata; 
		if((x & 0x80) == 0) 
1997/0403    
		r = *(uchar*)Rtcdata; 
		if((r & 0x80) == 0) 
1997/0401    
			break; 
	} 
 
1997/0403    
	if(statusB & 0x04){ 
		rtc.sec = clock[0]; 
		rtc.min = clock[1]; 
		rtc.hour = clock[2]; 
		rtc.mday = clock[3]; 
		rtc.mon = clock[4]; 
		rtc.year = clock[5]; 
	} 
	else{ 
		/* 
		 *  convert from BCD 
		 */ 
		rtc.sec = GETBCD(0); 
		rtc.min = GETBCD(1); 
		rtc.hour = GETBCD(2); 
		rtc.mday = GETBCD(3); 
		rtc.mon = GETBCD(4); 
		rtc.year = GETBCD(5); 
	} 
 
	/* 
	 *  the world starts jan 1 1970 
	 */ 
	rtc.year += 1970; 
 
1993/0916    
	return rtc2sec(&rtc); 
} 
 
1997/0401/sys/src/9/carrera/devrtc.c:136,1411997/0403/sys/src/9/carrera/devrtc.c:229,236
1997/0401    
long 
rtctime(void) 
{ 
1997/0403    
#define notdef 
#ifdef notdef 
1997/0401    
	int i; 
	long t, ot; 
 
1997/0401/sys/src/9/carrera/devrtc.c:149,1591997/0403/sys/src/9/carrera/devrtc.c:244,259
1997/0401    
		if(ot == t) 
			break; 
	} 
	if(i == 100) print("we are boofheads\n"); 
                 
	iunlock(&rtlock); 
 
1997/0403    
	if(i == 100) print("we are boofheads\n"); 
 
1997/0401    
	return t; 
1997/0403    
#else 
	extern ulong boottime; 
 
	return boottime+TK2SEC(MACHP(0)->ticks); 
#endif /* notdef */ 
1997/0401    
} 
 
1997/0327    
static long	  
1997/0401/sys/src/9/carrera/devrtc.c:169,1741997/0403/sys/src/9/carrera/devrtc.c:269,275
1993/0916    
	case Qrtc: 
1997/0401    
		qlock(&rtclock); 
1993/0916    
		t = rtctime(); 
1997/0403    
dumprtcstatus(); 
1997/0401    
		qunlock(&rtclock); 
1993/0916    
		n = readnum(offset, buf, n, t, 12); 
		return n; 
1997/0401/sys/src/9/carrera/devrtc.c:192,2001997/0403/sys/src/9/carrera/devrtc.c:293,305
1993/0916    
binary2bcd(int reg, uchar val) 
{ 
	uchar x; 
1997/0403    
 
1993/0916    
	x = (*(uchar*)Rtcindex)&~0x7f; 
	*(uchar*)Rtcindex = x|reg; 
	*(uchar*)Rtcdata = (val % 10) | (((val / 10) % 10)<<4); 
1997/0403    
	if(statusB & 0x04) 
		*(uchar*)Rtcdata = val; 
	else 
		*(uchar*)Rtcdata = (val % 10) | (((val / 10) % 10)<<4); 
1993/0916    
} 
 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)