From c1badf86eac0ce2ed29f5762ce688f6230edd680 Mon Sep 17 00:00:00 2001 From: Oliver Lehmann Date: Tue, 11 Aug 2009 19:18:03 +0000 Subject: [PATCH] works - pressign enter to re-take the old date in settimer() does not work yet --- .../cmd/standalone/sa.timer/common/rtc72421.c | 8 +- .../cmd/standalone/sa.timer/common/rtc72421.h | 4 +- .../cmd/standalone/sa.timer/common/timer.h | 16 +++- .../src/cmd/standalone/sa.timer/common/u130.c | 7 +- .../cmd/standalone/sa.timer/kernel/makefile | 4 +- WEGA/src/cmd/standalone/sa.timer/makefile | 4 +- .../standalone/sa.timer/standalone/makefile | 4 +- .../standalone/sa.timer/standalone/sa.timer.c | 82 +++++++++++++------ 8 files changed, 85 insertions(+), 44 deletions(-) diff --git a/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.c b/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.c index 85af5c9..cc32a9c 100644 --- a/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.c +++ b/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: rtc72421.c,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $ + * $Id: rtc72421.c,v 1.3 2009/08/11 19:18:03 olivleh1 Exp $ */ #include @@ -37,7 +37,6 @@ extern long timegm(); extern struct tm *gmtime(); -#ifdef NOTYET int rtc72421_init() { @@ -45,7 +44,7 @@ rtc72421_init() } -int +void rtc72421_set(time) long time; { @@ -55,8 +54,6 @@ long time; if(clktime->tm_year > 100) clktime->tm_year -= 100; clktime->tm_mon++; - - return(0); } void @@ -112,4 +109,3 @@ unsigned addr2; { return(rdnibble(addr1) + rdnibble(addr2)*10); } -#endif diff --git a/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.h b/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.h index c5e4420..144ef38 100644 --- a/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.h +++ b/WEGA/src/cmd/standalone/sa.timer/common/rtc72421.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: rtc72421.h,v 1.2 2009/08/07 20:02:59 olivleh1 Exp $ + * $Id: rtc72421.h,v 1.3 2009/08/11 19:18:03 olivleh1 Exp $ */ #ifndef R421_H @@ -64,7 +64,7 @@ int rtc72421_init(); long rtc72421_get(); -int rtc72421_set(); +void rtc72421_set(); void rtc72421_start(); #endif diff --git a/WEGA/src/cmd/standalone/sa.timer/common/timer.h b/WEGA/src/cmd/standalone/sa.timer/common/timer.h index c56dc7b..37ce8bd 100644 --- a/WEGA/src/cmd/standalone/sa.timer/common/timer.h +++ b/WEGA/src/cmd/standalone/sa.timer/common/timer.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: timer.h,v 1.1 2009/08/07 20:08:59 olivleh1 Exp $ + * $Id: timer.h,v 1.2 2009/08/11 19:18:03 olivleh1 Exp $ */ #ifndef TIMER_H @@ -34,15 +34,23 @@ struct clock_type { int clock_det_msk; int clock_det_str; char *clock_name; + int (*time_init)(); + long (*time_get)(); + void (*time_set)(); + void (*time_start)(); }; char estring[20]; static struct clock_type clock_devs[] = { { U130BASE, MSK_U130, STR_U130, - "RFT U130X RTC" }, - { R421BASE, MSK_R421, STR_R421, - "Seiko Epson RTC-72421" }, + "RFT U130X RTC", + u130_init, u130_get, u130_set, u130_start + }, + { R421BASE, MSK_R421, STR_R421, + "Seiko Epson RTC-72421", + rtc72421_init, rtc72421_get, rtc72421_set, rtc72421_start + }, }; #endif diff --git a/WEGA/src/cmd/standalone/sa.timer/common/u130.c b/WEGA/src/cmd/standalone/sa.timer/common/u130.c index da1cb8c..f603d7b 100644 --- a/WEGA/src/cmd/standalone/sa.timer/common/u130.c +++ b/WEGA/src/cmd/standalone/sa.timer/common/u130.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: u130.c,v 1.5 2009/08/11 05:14:26 olivleh1 Exp $ + * $Id: u130.c,v 1.6 2009/08/11 19:18:03 olivleh1 Exp $ */ #include @@ -113,6 +113,8 @@ u130_get() { long time; struct tm *clktime; +long time1,time2; + outvalue(0x02); /* Umschalten auf Datum */ clktime->tm_year = rdvalue(U130YYx1); if (clktime->tm_year < 70) @@ -131,6 +133,9 @@ u130_get() clktime->tm_hour = rdvalue(U130HHx1); time = timegm(clktime); +time1 = time/100000L; +time2 = time%100000L; +printf("time: %d-%d-%d-%d\n",(int)(time1/100L),(int)(time1%100L),(int)(time2/100L),(int)(time2%100L)); return(time); } diff --git a/WEGA/src/cmd/standalone/sa.timer/kernel/makefile b/WEGA/src/cmd/standalone/sa.timer/kernel/makefile index 4b2e3d1..bfedfdf 100644 --- a/WEGA/src/cmd/standalone/sa.timer/kernel/makefile +++ b/WEGA/src/cmd/standalone/sa.timer/kernel/makefile @@ -1,7 +1,7 @@ -OBJ= sa.timer.o libb.a u130.o gmtime.o timegm.o +OBJ= sa.timer.o libb.a u130.o rtc72421.o gmtime.o timegm.o CC= cc LD= ld -DEBUG= +DEBUG= CFLAGS= -O $(DEBUG) all: sa.timer diff --git a/WEGA/src/cmd/standalone/sa.timer/makefile b/WEGA/src/cmd/standalone/sa.timer/makefile index 4b2e3d1..bfedfdf 100644 --- a/WEGA/src/cmd/standalone/sa.timer/makefile +++ b/WEGA/src/cmd/standalone/sa.timer/makefile @@ -1,7 +1,7 @@ -OBJ= sa.timer.o libb.a u130.o gmtime.o timegm.o +OBJ= sa.timer.o libb.a u130.o rtc72421.o gmtime.o timegm.o CC= cc LD= ld -DEBUG= +DEBUG= CFLAGS= -O $(DEBUG) all: sa.timer diff --git a/WEGA/src/cmd/standalone/sa.timer/standalone/makefile b/WEGA/src/cmd/standalone/sa.timer/standalone/makefile index 4b2e3d1..bfedfdf 100644 --- a/WEGA/src/cmd/standalone/sa.timer/standalone/makefile +++ b/WEGA/src/cmd/standalone/sa.timer/standalone/makefile @@ -1,7 +1,7 @@ -OBJ= sa.timer.o libb.a u130.o gmtime.o timegm.o +OBJ= sa.timer.o libb.a u130.o rtc72421.o gmtime.o timegm.o CC= cc LD= ld -DEBUG= +DEBUG= CFLAGS= -O $(DEBUG) all: sa.timer diff --git a/WEGA/src/cmd/standalone/sa.timer/standalone/sa.timer.c b/WEGA/src/cmd/standalone/sa.timer/standalone/sa.timer.c index bc9a7b3..f0e43b1 100644 --- a/WEGA/src/cmd/standalone/sa.timer/standalone/sa.timer.c +++ b/WEGA/src/cmd/standalone/sa.timer/standalone/sa.timer.c @@ -23,14 +23,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sa.timer.c,v 1.4 2009/08/11 05:14:26 olivleh1 Exp $ + * $Id: sa.timer.c,v 1.5 2009/08/11 19:18:03 olivleh1 Exp $ */ -char estring[20]; -long u130_get(); - -#define dysize(A) (((A)%4)? 365: 366) #include "time.h" #include "u130.h" #include "rtc72421.h" @@ -38,35 +34,55 @@ long u130_get(); long timegm(); struct tm *gmtime(); +long u130_get(); + +int (*time_init)(); +long (*time_get)(); +void (*time_set)(); +void (*time_start)(); main() { - long time; - register i,timer_found; + register long time; + register i; struct clock_type *t; + int a,b; +long time1,time2; + t = clock_devs; -#ifdef foo + 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) { + a = inb(t->clock_addr)&~t->clock_det_msk; + b = t->clock_det_str; + if(a == b) { printf("%s found\n",t->clock_name); - timer_found=1; - /* function pointers here */ + time_init = t->time_init; + time_get = t->time_get; + time_set = t->time_set; + time_start = t->time_start; break; } } -#else - timer_found=1; -#endif - if (timer_found != 1) { /* Uhrmodul vorhanden ? */ + + if (time_init > 0) { /* function pointer assigned? */ + time_init(); /* init RTC */ + time = time_get(); /* Uhrenmodul lesen */ +time1 = time/100000L; +time2 = time%100000L; +printf("time: %d-%d-%d-%d\n",(int)(time1/100L),(int)(time1%100L),(int)(time2/100L),(int)(time2%100L)); + outtime(time); /* Datum/Zeit ausgeben */ +time1 = time/100000L; +time2 = time%100000L; +printf("time: %d-%d-%d-%d\n",(int)(time1/100L),(int)(time1%100L),(int)(time2/100L),(int)(time2%100L)); + settimer(time); /* Uhrenmodul neu programmieren */ + time = time_get(); /* Uhrenmodul lesen */ + outtime(time); /* Datum/Zeit ausgeben */ + exit(0); + } else { 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) @@ -102,11 +118,19 @@ long time; printf("Time is: %d:%d:%d GMT\n", clktime->tm_hour, clktime->tm_min, clktime->tm_sec); } -settimer() +settimer(time) +long time; { struct tm *clktime; - long time; + long time,time2; register i; + + time2=time; + + clktime = gmtime(&time2); + if(clktime->tm_year > 100) + clktime->tm_year -= 100; + clktime->tm_mon ++; loop1: printf("Enter new Date (MM/DD/YY) : "); gets(estring, sizeof estring); @@ -132,9 +156,17 @@ loop2: if (clktime->tm_min<0 || clktime->tm_min>59 || clktime->tm_hour<0 || clktime->tm_hour>23) goto loop2; + 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); + + time = 0; time = timegm(clktime); - u130_set(time); + time_set(time); printf("Enter Return to start time : "); gets(estring, 1); - u130_start(); + time_start(); }