This commit is contained in:
Oliver Lehmann 2009-08-07 20:02:59 +00:00
parent 48ddc0fcff
commit 77313cae4b
9 changed files with 98 additions and 19 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: gmtime.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $ * $Id: gmtime.c,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#define dysize(A) (((A)%4)? 365: 366) #define dysize(A) (((A)%4)? 365: 366)
@ -36,7 +36,7 @@ static int dmsize[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct tm * struct tm *
gmtime(tim) gmtime(tim)
const long *tim; long *tim;
{ {
register int d0, d1; register int d0, d1;
long hms, day; long hms, day;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: rtc72421.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $ * $Id: rtc72421.c,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#include <time.h> #include <time.h>
@ -37,6 +37,7 @@ extern long timegm();
extern struct tm *gmtime(); extern struct tm *gmtime();
#ifdef NOTYET
int int
rtc72421_init() rtc72421_init()
{ {
@ -111,3 +112,4 @@ unsigned addr2;
{ {
return(rdnibble(addr1) + rdnibble(addr2)*10); return(rdnibble(addr1) + rdnibble(addr2)*10);
} }
#endif

View File

@ -23,13 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: rtc72421.h,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $ * $Id: rtc72421.h,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#ifndef R421_H #ifndef R421_H
#define R421_H 1 #define R421_H 1
#define STR_R421 0xc0 #define STR_R421 0xc
#define MSK_R421 0xf0
#define R421BASE 0xfde1 /* base address */ #define R421BASE 0xfde1 /* base address */
#define R421YYx1 0xfdf5 /* 1-year digit register */ #define R421YYx1 0xfdf5 /* 1-year digit register */

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: u130.c,v 1.2 2009/08/07 13:55:55 olivleh1 Exp $ * $Id: u130.c,v 1.3 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#include <time.h> #include <time.h>
@ -52,7 +52,7 @@ long time;
clktime = gmtime(&time); clktime = gmtime(&time);
if(clktime->tm_year > 100) if(clktime->tm_year > 100)
clktime->tm_year -= 100; clktime->tm_year -= 100;
clktime->tm_mon++; clktime->tm_mon ++;
outvalue(0x02); /* Datum einstellen */ outvalue(0x02); /* Datum einstellen */
outvalue(0x03); /* Korrektur Monat */ outvalue(0x03); /* Korrektur Monat */
@ -115,8 +115,11 @@ u130_get()
struct tm *clktime; struct tm *clktime;
outvalue(0x02); /* Umschalten auf Datum */ outvalue(0x02); /* Umschalten auf Datum */
clktime->tm_year = rdvalue(U130YYx1); clktime->tm_year = rdvalue(U130YYx1);
if (clktime->tm_year < 70)
clktime->tm_year+=100;
clktime->tm_mday = rdvalue(U130DDx1); clktime->tm_mday = rdvalue(U130DDx1);
clktime->tm_mon = rdvalue(U130MMx1); clktime->tm_mon = rdvalue(U130MMx1);
clktime->tm_mon --;
outvalue(0x00); outvalue(0x00);
clktime->tm_sec = inb(U130MM1x) & 0x28; /* Umschalten auf Zeit */ clktime->tm_sec = inb(U130MM1x) & 0x28; /* Umschalten auf Zeit */
if (clktime->tm_sec == 0x08 || clktime->tm_sec == 0x20) { if (clktime->tm_sec == 0x08 || clktime->tm_sec == 0x20) {
@ -126,7 +129,15 @@ u130_get()
while ((clktime->tm_sec = rdvalue(U130SSx1)) == 59); while ((clktime->tm_sec = rdvalue(U130SSx1)) == 59);
clktime->tm_min = rdvalue(U130MIx1); clktime->tm_min = rdvalue(U130MIx1);
clktime->tm_hour = rdvalue(U130HHx1); clktime->tm_hour = rdvalue(U130HHx1);
#ifdef DEBUG
printf("u130_get\n");
printf("year %d\n",clktime->tm_year);
printf("month %d\n",clktime->tm_mon);
printf("day %d\n",clktime->tm_mday);
printf("hour %d\n",clktime->tm_hour);
printf("min %d\n",clktime->tm_min);
printf("sec %d\n",clktime->tm_sec);
#endif
time = timegm(clktime); time = timegm(clktime);
return(time); return(time);

View File

@ -23,13 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: u130.h,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $ * $Id: u130.h,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#ifndef U130_H #ifndef U130_H
#define U130_H 1 #define U130_H 1
#define STR_U130 0xbf #define STR_U130 0xbf
#define MSK_U130 0x00
#define U130BASE 0xfef1 /* base address */ #define U130BASE 0xfef1 /* base address */
#define U130YYx1 0xfef5 /* 1-year digit register */ #define U130YYx1 0xfef5 /* 1-year digit register */

View File

@ -0,0 +1,12 @@
OBJ= sa.timer.o u130.o rtc72421.o gmtime.o timegm.o libb.a
CC= cc
LD= ld
DEBUG=
CFLAGS= -O $(DEBUG)
all: sa.timer
sa.timer.o:
$(CC) -c $(DEBUG) sa.timer.c
sa.timer: $(OBJ)
$(LD) -s -o $@ $(OBJ)
chmod 400 $@

View File

@ -0,0 +1,12 @@
OBJ= sa.timer.o u130.o rtc72421.o gmtime.o timegm.o libb.a
CC= cc
LD= ld
DEBUG=
CFLAGS= -O $(DEBUG)
all: sa.timer
sa.timer.o:
$(CC) -c $(DEBUG) sa.timer.c
sa.timer: $(OBJ)
$(LD) -s -o $@ $(OBJ)
chmod 400 $@

View File

@ -0,0 +1,12 @@
OBJ= sa.timer.o u130.o rtc72421.o gmtime.o timegm.o libb.a
CC= cc
LD= ld
DEBUG=
CFLAGS= -O $(DEBUG)
all: sa.timer
sa.timer.o:
$(CC) -c $(DEBUG) sa.timer.c
sa.timer: $(OBJ)
$(LD) -s -o $@ $(OBJ)
chmod 400 $@

View File

@ -23,25 +23,36 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: sa.timer.c,v 1.1 2009/08/07 13:53:20 olivleh1 Exp $ * $Id: sa.timer.c,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h> #include <time.h>
#include "u130.h" #include "u130.h"
#include "rtc72421.h" #include "rtc72421.h"
#include "timer.h"
extern long timegm(); extern long timegm();
extern struct tm *gmtime(); extern struct tm *gmtime();
char estring[20];
main() main()
{ {
register long time; register long time;
register i,timer_found;
struct clock_type *t;
int a;
if (inb(U130BASE) != STR_U130) { /* Uhrmodul vorhanden ? */ t = clock_devs;
for( i = 0 ; i < sizeof(clock_devs) / sizeof(clock_devs[0]); i++, t++) {
if((inb(t->clock_addr)&~t->clock_det_msk) == t->clock_det_str) {
printf("%s found\n",t->clock_name);
timer_found=1;
/* function pointers here */
break;
}
}
if (timer_found != 1) { /* Uhrmodul vorhanden ? */
printf("Timer not available\n"); printf("Timer not available\n");
exit(1); exit(1);
} }
@ -77,11 +88,13 @@ long time;
clktime = gmtime(&time); clktime = gmtime(&time);
clktime->tm_year += 1900; #ifdef DEBUG
print_tm("outtime",clktime);
#endif
(clktime->tm_year) += 1900;
clktime->tm_mon++; clktime->tm_mon++;
printf("Date is: %d/%d/%d\n", clktime->tm_mon, clktime->tm_mday, clktime->tm_year);
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);
printf("Time is: %d:%d:%d GMT\n", clktime->tm_hour, clktime->tm_min, clktime->tm_sec);
} }
settimer() settimer()
@ -100,7 +113,7 @@ loop1:
if (clktime->tm_year < 70 ) if (clktime->tm_year < 70 )
clktime->tm_year += 100; clktime->tm_year += 100;
if (clktime->tm_mon<1 || clktime->tm_mon>12 || clktime->tm_mday<1 || clktime->tm_mday>31) if (clktime->tm_mon<0 || clktime->tm_mon>11 || clktime->tm_mday<1 || clktime->tm_mday>31)
goto loop1; goto loop1;
loop2: loop2:
@ -121,3 +134,18 @@ loop2:
u130_start(); u130_start();
} }
#ifdef DEBUG
print_tm(func,clktime)
char *func;
struct tm *clktime;
{
printf("%s\n", func);
printf("year %d\n",clktime->tm_year);
printf("month %d\n",clktime->tm_mon);
printf("day %d\n",clktime->tm_mday);
printf("hour %d\n",clktime->tm_hour);
printf("min %d\n",clktime->tm_min);
printf("sec %d\n",clktime->tm_sec);
}
#endif