Exemplo n.º 1
0
Arquivo: devrtc.c Projeto: 8l/inferno
static long	 
rtcwrite(Chan *c, void *buf, long n, vlong offset)
{
	Rtc rtc;
	ulong secs;
	char *cp, sbuf[32];

	switch((ulong)c->qid.path){
	case Qrtc:
		/*
		 *  read the time
		 */
		if(offset != 0 || n >= sizeof(sbuf)-1)
			error(Ebadarg);
		memmove(sbuf, buf, n);
		sbuf[n] = '\0';
		cp = sbuf;
		while(*cp){
			if(*cp>='0' && *cp<='9')
				break;
			cp++;
		}
		secs = strtoul(cp, 0, 0);
		/*
		 *  convert to bcd
		 */
		sec2rtc(secs, &rtc);
		/*
		 * write it
		 */
		qlock(&rtclock);
		setrtc(&rtc);
		qunlock(&rtclock);
		return n;
	case Qnvram:
		if(offset > NVWRITE)
			return 0;
		if(n > NVWRITE - offset)
			n = NVWRITE - offset;
		qlock(&rtclock);
		memmove(nvr.ram+offset, buf, n);
		*nvr.cksum = rtcgencksum();
		qunlock(&rtclock);
		return n;
	}
	error(Egreg);
	return 0;		/* not reached */
}
Exemplo n.º 2
0
static long	 
rtcwrite(Chan* c, void* buf, long n, vlong off)
{
	Rtc rtc;
	ulong secs;
	char *cp, *ep;
	ulong offset = off;

	if(offset!=0)
		error(Ebadarg);

	switch((ulong)c->qid.path){
	case Qrtc:
		/*
		 *  read the time
		 */
		cp = ep = buf;
		ep += n;
		while(cp < ep){
			if(*cp>='0' && *cp<='9')
				break;
			cp++;
		}
		secs = strtoul(cp, 0, 0);
	
		/*
		 *  convert to rtc
		 */
		sec2rtc(secs, &rtc);

		/*
		 *  write the clock
		 */
		ilock(&rtclock);
		outb(Paddr, Seconds);	outb(Pdata, rtc.sec);
		outb(Paddr, Minutes);	outb(Pdata, rtc.min);
		outb(Paddr, Hours);		outb(Pdata, rtc.hour);
		outb(Paddr, Mday);		outb(Pdata, rtc.mday);
		outb(Paddr, Month);		outb(Pdata, rtc.mon);
		outb(Paddr, Year);		outb(Pdata, rtc.year % 100);
		iunlock(&rtclock);
		return n;
	}
	error(Ebadarg);
	return 0;
}
Exemplo n.º 3
0
Arquivo: devrtc.c Projeto: 8l/inferno
static long	 
rtcwrite(Chan* c, void* buf, long n, vlong off)
{
	int t;
	char *a, *start;
	Rtc rtc;
	ulong secs;
	uchar bcdclock[Nbcd];
	char *cp, *ep;
	ulong offset = off;

	if(offset!=0)
		error(Ebadarg);


	switch((ulong)c->qid.path){
	case Qrtc:
		/*
		 *  read the time
		 */
		cp = ep = buf;
		ep += n;
		while(cp < ep){
			if(*cp>='0' && *cp<='9')
				break;
			cp++;
		}
		secs = strtoul(cp, 0, 0);
	
		/*
		 *  convert to bcd
		 */
		sec2rtc(secs, &rtc);
		PUTBCD(rtc.sec, 0);
		PUTBCD(rtc.min, 1);
		PUTBCD(rtc.hour, 2);
		PUTBCD(rtc.mday, 3);
		PUTBCD(rtc.mon, 4);
		PUTBCD(rtc.year, 5);

		/*
		 *  write the clock
		 */
		ilock(&nvrtlock);
		outb(Paddr, Seconds);	outb(Pdata, bcdclock[0]);
		outb(Paddr, Minutes);	outb(Pdata, bcdclock[1]);
		outb(Paddr, Hours);	outb(Pdata, bcdclock[2]);
		outb(Paddr, Mday);	outb(Pdata, bcdclock[3]);
		outb(Paddr, Month);	outb(Pdata, bcdclock[4]);
		outb(Paddr, Year);	outb(Pdata, bcdclock[5]);
		iunlock(&nvrtlock);
		return n;
	case Qnvram:
		if(n == 0)
			return 0;
		if(n > Nvsize)
			n = Nvsize;
	
		start = a = smalloc(n);
		if(waserror()){
			free(start);
			nexterror();
		}
		memmove(a, buf, n);
		poperror();

		ilock(&nvrtlock);
		for(t = offset; t < offset + n; t++){
			if(t >= Nvsize)
				break;
			outb(Paddr, Nvoff+t);
			outb(Pdata, *a++);
		}
		iunlock(&nvrtlock);

		free(start);
		return t - offset;
	}
	error(Ebadarg);
	return 0;
}