new sa.timer!
This commit is contained in:
parent
c16517bee9
commit
707dd54c54
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: gmtime.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#define dysize(A) (((A)%4)? 365: 366)
|
||||
#include <time.h>
|
||||
|
||||
struct tm *gmtime();
|
||||
|
||||
static char cbuf[26];
|
||||
static int dmsize[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
struct tm *
|
||||
gmtime(tim)
|
||||
const long *tim;
|
||||
{
|
||||
register int d0, d1;
|
||||
long hms, day;
|
||||
static struct tm xtime;
|
||||
|
||||
/*
|
||||
* break initial number into days
|
||||
*/
|
||||
hms = *tim % 86400L;
|
||||
day = *tim / 86400L;
|
||||
if(hms < 0) {
|
||||
hms += 86400L;
|
||||
day -= 1;
|
||||
}
|
||||
/*
|
||||
* generate hours:minutes:seconds
|
||||
*/
|
||||
xtime.tm_sec = hms % 60;
|
||||
d1 = hms / 60;
|
||||
xtime.tm_min = d1 % 60;
|
||||
d1 /= 60;
|
||||
xtime.tm_hour = d1;
|
||||
|
||||
/*
|
||||
* day is the day number.
|
||||
* generate day of the week.
|
||||
* The addend is 4 mod 7 (1/1/1970 was Thursday)
|
||||
*/
|
||||
|
||||
xtime.tm_wday = (day + 7340036L) % 7;
|
||||
|
||||
/*
|
||||
* year number
|
||||
*/
|
||||
if(day >= 0)
|
||||
for(d1=70; day >= dysize(d1); d1++)
|
||||
day -= dysize(d1);
|
||||
else
|
||||
for(d1=70; day < 0; d1--)
|
||||
day += dysize(d1-1);
|
||||
xtime.tm_year = d1;
|
||||
xtime.tm_yday = d0 = day;
|
||||
|
||||
/*
|
||||
* generate month
|
||||
*/
|
||||
|
||||
if(dysize(d1) == 366)
|
||||
dmsize[1] = 29;
|
||||
for(d1=0; d0 >= dmsize[d1]; d1++)
|
||||
d0 -= dmsize[d1];
|
||||
dmsize[1] = 28;
|
||||
xtime.tm_mday = d0+1;
|
||||
xtime.tm_mon = d1;
|
||||
xtime.tm_isdst = 0;
|
||||
return(&xtime);
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: rtc72421.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include "rtc72421.h"
|
||||
|
||||
void wrnibble();
|
||||
void wrbyte();
|
||||
int rdnibble();
|
||||
int rdbyte();
|
||||
extern long timegm();
|
||||
extern struct tm *gmtime();
|
||||
|
||||
|
||||
int
|
||||
rtc72421_init()
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
rtc72421_set(time)
|
||||
long time;
|
||||
{
|
||||
struct tm *clktime;
|
||||
|
||||
clktime = gmtime(&time);
|
||||
if(clktime->tm_year > 100)
|
||||
clktime->tm_year -= 100;
|
||||
clktime->tm_mon++;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
rtc72421_start()
|
||||
{
|
||||
}
|
||||
|
||||
long
|
||||
rtc72421_get()
|
||||
{
|
||||
long time;
|
||||
struct tm *clktime;
|
||||
clktime->tm_year = 0;
|
||||
clktime->tm_mday = 0;
|
||||
clktime->tm_mon = 0;
|
||||
while ((clktime->tm_sec = 0) == 59);
|
||||
clktime->tm_min = 0;
|
||||
clktime->tm_hour = 0;
|
||||
|
||||
time = timegm(clktime);
|
||||
|
||||
return(time);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wrnibble(addr,nibble)
|
||||
unsigned addr;
|
||||
int nibble;
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
wrbyte(addr1,addr2,byte)
|
||||
unsigned addr1;
|
||||
unsigned addr2;
|
||||
int byte;
|
||||
{
|
||||
wrnibble(addr1,byte/10);
|
||||
wrnibble(addr2,byte%10);
|
||||
}
|
||||
|
||||
int
|
||||
rdnibble(addr)
|
||||
unsigned addr;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
int
|
||||
rdbyte(addr1,addr2)
|
||||
unsigned addr1;
|
||||
unsigned addr2;
|
||||
{
|
||||
return(rdnibble(addr1) + rdnibble(addr2)*10);
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: rtc72421.h,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#ifndef R421_H
|
||||
#define R421_H 1
|
||||
|
||||
#define STR_R421 0xc0
|
||||
|
||||
#define R421BASE 0xfde1 /* base address */
|
||||
#define R421YYx1 0xfdf5 /* 1-year digit register */
|
||||
#define R421YY1x 0xfdf7 /* 10-year digit register */
|
||||
#define R421DDx1 0xfded /* 1-day digit register */
|
||||
#define R421DD1x 0xfdef /* 10-day digit register */
|
||||
#define R421MMx1 0xfdf1 /* 1-month digit register */
|
||||
#define R421MM1x 0xfdf3 /* 10-month digit register */
|
||||
#define R421SSx1 0xfde1 /* 1-second digit register */
|
||||
#define R421SS1x 0xfde3 /* 10-second digit register */
|
||||
#define R421HHx1 0xfde9 /* 1-hour digit register */
|
||||
#define R421HH1x 0xfdeb /* 10-hour digit register */
|
||||
#define R421MIx1 0xfde5 /* 1-minute digit register */
|
||||
#define R421MI1x 0xfde7 /* 10-minute digit register */
|
||||
#define R421DOW 0xfdfa /* not used */
|
||||
#define R421REGD 0xfdfb /* 30-s ADJ, IRQ Flag, BUSY, HOLD */
|
||||
#define R421REGE 0xfdfd /* t1, t0, ITRPT/STND, MASK */
|
||||
#define R421REGF 0xfdff /* TEST, 24/12, STOP, RESET */
|
||||
|
||||
/* register F */
|
||||
#define R421RST 0x01
|
||||
#define R421STOP 0x02
|
||||
#define R4212412 0x04
|
||||
#define R421TEST 0x08
|
||||
|
||||
/* register D */
|
||||
#define R421HOLD 0x01
|
||||
#define R421BUSY 0x02
|
||||
#define R421IRQF 0x04
|
||||
#define R421ADJ 0x08
|
||||
|
||||
int rtc72421_init();
|
||||
long rtc72421_get();
|
||||
int rtc72421_set();
|
||||
void rtc72421_start();
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: timegm.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
extern struct tm *gmtime();
|
||||
|
||||
long
|
||||
timegm(clktime)
|
||||
struct tm *clktime;
|
||||
{
|
||||
register long time;
|
||||
register i;
|
||||
static int dmsize[] = /* Tage/Monat (kumulierend) */
|
||||
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
|
||||
|
||||
time = 0;
|
||||
if (clktime->tm_mday > 31 || clktime->tm_mon > 12)
|
||||
return(time);
|
||||
i = dmsize[clktime->tm_mon];
|
||||
if (clktime->tm_year%4 == 0 && clktime->tm_mon > 2) i++;
|
||||
if (clktime->tm_year > 137) return(time);
|
||||
time = (clktime->tm_year-69)/4;
|
||||
time += 365*(clktime->tm_year-70)+i;
|
||||
time += clktime->tm_mday - 1;
|
||||
|
||||
if (clktime->tm_sec > 59 || clktime->tm_min > 59 || clktime->tm_hour > 23)
|
||||
return(time);
|
||||
time = 24*time + clktime->tm_hour;
|
||||
time = 60*time + clktime->tm_min;
|
||||
time = 60*time + clktime->tm_sec;
|
||||
return(time);
|
||||
}
|
||||
|
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: u130.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include "u130.h"
|
||||
|
||||
int rdvalue();
|
||||
int invalue();
|
||||
void outvalue();
|
||||
extern long timegm();
|
||||
extern struct tm *gmtime();
|
||||
|
||||
|
||||
int
|
||||
u130_init()
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
u130_set(time)
|
||||
long time;
|
||||
{
|
||||
struct tm *clktime;
|
||||
|
||||
clktime = gmtime(&time);
|
||||
if(clktime->tm_year > 100)
|
||||
clktime->tm_year -= 100;
|
||||
clktime->tm_mon++;
|
||||
|
||||
outvalue(0x02); /* Datum einstellen */
|
||||
outvalue(0x03); /* Korrektur Monat */
|
||||
outvalue(0x00);
|
||||
while ((invalue(U130MMx1,1) + invalue(U130MM1x,1)*10) != clktime->tm_mon)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Zehnerstelle Tag */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130DD1x,1) != clktime->tm_mday/10)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Einerstelle Tag */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130DDx1,1) != clktime->tm_mday%10)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Zehnerstelle Jahr */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130YY1x,1) != clktime->tm_year/10)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Einerstelle Jahr */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130YYx1,1) != clktime->tm_year%10)
|
||||
;
|
||||
outvalue(0x02); /* Korrektur Ende */
|
||||
outvalue(0x00);
|
||||
|
||||
outvalue(0x01); /* Zeit stellen */
|
||||
outvalue(0x00);
|
||||
outvalue(0x02); /* Sekunden auf Null */
|
||||
outvalue(0x00);
|
||||
outvalue(0x01);
|
||||
outvalue(0x00);
|
||||
outvalue(0x01); /* Korrektur Stunden */
|
||||
outvalue(0x00);
|
||||
while ((invalue(U130HHx1,1) + invalue(U130HH1x,1)*10) != clktime->tm_hour)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Zehner-Minuten */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130MI1x,1) != clktime->tm_min/10)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Einer-Minuten */
|
||||
outvalue(0x00);
|
||||
while (invalue(U130MIx1,1) != clktime->tm_min%10)
|
||||
;
|
||||
outvalue(0x01); /* Korrektur Stop */
|
||||
outvalue(0x00);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void
|
||||
u130_start()
|
||||
{
|
||||
outvalue(0x01); /* Start der Zeit */
|
||||
outvalue(0x00);
|
||||
}
|
||||
|
||||
long
|
||||
u130_get()
|
||||
{
|
||||
long time;
|
||||
struct tm *clktime;
|
||||
outvalue(0x02); /* Umschalten auf Datum */
|
||||
clktime->tm_year = rdvalue(U130YYx1);
|
||||
clktime->tm_mday = rdvalue(U130DDx1);
|
||||
clktime->tm_mon = rdvalue(U130MMx1);
|
||||
outvalue(0x00);
|
||||
clktime->tm_sec = inb(U130MM1x) & 0x28; /* Umschalten auf Zeit */
|
||||
if (clktime->tm_sec == 0x08 || clktime->tm_sec == 0x20) {
|
||||
outvalue(0x02);
|
||||
outvalue(0x00);
|
||||
}
|
||||
while ((clktime->tm_sec = rdvalue(U130SSx1)) == 59);
|
||||
clktime->tm_min = rdvalue(U130MIx1);
|
||||
clktime->tm_hour = rdvalue(U130HHx1);
|
||||
|
||||
time = timegm(clktime);
|
||||
|
||||
return(time);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
outvalue(t)
|
||||
register t;
|
||||
{
|
||||
outb(U130BASE, t);
|
||||
t = 10000;
|
||||
while (t--)
|
||||
;
|
||||
}
|
||||
|
||||
int
|
||||
invalue(addr, flag)
|
||||
register addr;
|
||||
register flag;
|
||||
{
|
||||
register seg7, takt;
|
||||
|
||||
seg7 = inb(addr);
|
||||
if (seg7 != inb(addr))
|
||||
seg7 = inb(addr);
|
||||
takt = seg7 & 0x80; /* nur gueltig bei 6. Stelle */
|
||||
if (seg7 & 0x20)
|
||||
seg7 = ~seg7;
|
||||
if (addr == 0xfeff) /* 6.Stelle */
|
||||
seg7 &= 0x07;
|
||||
seg7 &= 0x1f;
|
||||
if (seg7 == 0x0f)
|
||||
return(0);
|
||||
if (seg7 == 0x00) {
|
||||
if (flag == 0)
|
||||
return(0);
|
||||
if (addr == 0xfeff && takt)
|
||||
return(0);
|
||||
}
|
||||
if (seg7 == 0x02)
|
||||
return(1);
|
||||
if (seg7 == 0x17 || seg7 == 0x05)
|
||||
return(2);
|
||||
if (seg7 == 0x13)
|
||||
return(3);
|
||||
if (seg7 == 0x1a)
|
||||
return(4);
|
||||
if (seg7 == 0x19)
|
||||
return(5);
|
||||
if (seg7 == 0x1d)
|
||||
return(6);
|
||||
if (seg7 == 0x03)
|
||||
return(7);
|
||||
if (seg7 == 0x1f)
|
||||
return(8);
|
||||
if (seg7 == 0x1b)
|
||||
return(9);
|
||||
return(0xff);
|
||||
}
|
||||
|
||||
int
|
||||
rdvalue(addr)
|
||||
unsigned addr;
|
||||
{
|
||||
return(invalue(addr,0) + invalue(addr+2,0)*10);
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: u130.h,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#ifndef U130_H
|
||||
#define U130_H 1
|
||||
|
||||
#define STR_U130 0xbf
|
||||
|
||||
#define U130BASE 0xfef1 /* base address */
|
||||
#define U130YYx1 0xfef5 /* 1-year digit register */
|
||||
#define U130YY1x 0xfef7 /* 10-year digit register */
|
||||
#define U130DDx1 0xfef9 /* 1-day digit register */
|
||||
#define U130DD1x 0xfefb /* 10-day digit register */
|
||||
#define U130MMx1 0xfefd /* 1-month digit register */
|
||||
#define U130MM1x 0xfeff /* 10-month digit register */
|
||||
#define U130SSx1 0xfef5 /* 1-second digit register */
|
||||
#define U130SS1x 0xfef7 /* 10-second digit register */
|
||||
#define U130HHx1 0xfefd /* 1-hour digit register */
|
||||
#define U130HH1x 0xfeff /* 10-hour digit register */
|
||||
#define U130MIx1 0xfef9 /* 1-minute digit register */
|
||||
#define U130MI1x 0xfefb /* 10-minute digit register */
|
||||
|
||||
int u130_init();
|
||||
long u130_get();
|
||||
int u130_set();
|
||||
void u130_start();
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2009 Oliver Lehmann <oliver@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: sa.timer.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "u130.h"
|
||||
#include "rtc72421.h"
|
||||
|
||||
extern long timegm();
|
||||
extern struct tm *gmtime();
|
||||
|
||||
char estring[20];
|
||||
|
||||
main()
|
||||
{
|
||||
register long time;
|
||||
|
||||
if (inb(U130BASE) != STR_U130) { /* Uhrmodul vorhanden ? */
|
||||
printf("Timer not available\n");
|
||||
exit(1);
|
||||
}
|
||||
time = u130_get(); /* Uhrenmodul lesen */
|
||||
outtime(time); /* Datum/Zeit ausgeben */
|
||||
settimer(); /* Uhrenmodul neu programmieren */
|
||||
time = u130_get(); /* Uhrenmodul lesen */
|
||||
outtime(time); /* Datum/Zeit ausgeben */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
getdat(k)
|
||||
register k;
|
||||
{
|
||||
register i, c, n;
|
||||
|
||||
n = 0;
|
||||
for (i = 0; c = estring[i]; i++) {
|
||||
if (k-1 == 0) {
|
||||
if (c == '/' || c== ':') return(n);
|
||||
if (c < '0' || c > '9') return(-1);
|
||||
n = n*10 + (c-'0');
|
||||
} else
|
||||
if (c == '/' || c == ':') k--;
|
||||
}
|
||||
return(n);
|
||||
}
|
||||
|
||||
outtime(time)
|
||||
long time;
|
||||
{
|
||||
struct tm *clktime;
|
||||
|
||||
clktime = gmtime(&time);
|
||||
|
||||
clktime->tm_year += 1900;
|
||||
clktime->tm_mon++;
|
||||
|
||||
printf("Date is: %d/%d/%d\n", clktime->tm_mon, clktime->tm_mday, clktime->tm_year);
|
||||
printf("Time is: %d:%d:%d GMT\n", clktime->tm_hour, clktime->tm_min, clktime->tm_sec);
|
||||
}
|
||||
|
||||
settimer()
|
||||
{
|
||||
struct tm *clktime;
|
||||
long time;
|
||||
int i;
|
||||
loop1:
|
||||
printf("Enter new Date (MM/DD/YY) : ");
|
||||
gets(estring, sizeof estring);
|
||||
if (estring[0] == 0)
|
||||
goto loop2;
|
||||
clktime->tm_mon = getdat(1)-1;
|
||||
clktime->tm_mday = getdat(2);
|
||||
clktime->tm_year = getdat(3);
|
||||
if (clktime->tm_year < 70 )
|
||||
clktime->tm_year += 100;
|
||||
|
||||
if (clktime->tm_mon<1 || clktime->tm_mon>12 || clktime->tm_mday<1 || clktime->tm_mday>31)
|
||||
goto loop1;
|
||||
|
||||
loop2:
|
||||
printf("Enter new Time in GMT (HH:MM) : ");
|
||||
gets(estring, sizeof estring);
|
||||
if (estring[0] == 0)
|
||||
return;
|
||||
clktime->tm_hour = getdat(1);
|
||||
clktime->tm_min = getdat(2);
|
||||
clktime->tm_sec = 0;
|
||||
if (clktime->tm_min<0 || clktime->tm_min>59 || clktime->tm_hour<0 || clktime->tm_hour>23)
|
||||
goto loop2;
|
||||
|
||||
time = timegm(clktime);
|
||||
u130_set(time);
|
||||
printf("Enter Return to start time : ");
|
||||
gets(estring, 1);
|
||||
u130_start();
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue