00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include <ubixos/types.h>
00031 #include <ubixos/time.h>
00032 #include <ubixos/vitals.h>
00033 #include <lib/kprintf.h>
00034 #include <assert.h>
00035 
00036 static int month[12] = {
00037         0,
00038         DAY*(31),
00039         DAY*(31+29),
00040         DAY*(31+29+31),
00041         DAY*(31+29+31+30),
00042         DAY*(31+29+31+30+31),
00043         DAY*(31+29+31+30+31+30),
00044         DAY*(31+29+31+30+31+30+31),
00045         DAY*(31+29+31+30+31+30+31+31),
00046         DAY*(31+29+31+30+31+30+31+31+30),
00047         DAY*(31+29+31+30+31+30+31+31+30+31),
00048         DAY*(31+29+31+30+31+30+31+31+30+31+30)
00049 };
00050 
00051 static int timeCmosRead(int addr) {
00052   outportByteP(0x70,addr);
00053   return((int)inportByte(0x71));
00054   }
00055 
00056 int time_init() {
00057   int i;
00058   struct timeStruct time;
00059  
00060   for (i = 0 ; i < 1000000 ; i++) {
00061     if (!(timeCmosRead(10) & 0x80)) {
00062       break;
00063       }
00064     }
00065 
00066   do {
00067     time.sec = timeCmosRead(0);
00068     time.min = timeCmosRead(2);
00069     time.hour = timeCmosRead(4);
00070     time.day = timeCmosRead(7);
00071     time.mon = timeCmosRead(8);
00072     time.year = timeCmosRead(9);
00073     } while (time.sec != timeCmosRead(0));
00074 
00075   BCD_TO_BIN(time.sec);
00076   BCD_TO_BIN(time.min);
00077   BCD_TO_BIN(time.hour);
00078   BCD_TO_BIN(time.day);
00079   BCD_TO_BIN(time.mon);
00080   BCD_TO_BIN(time.year);
00081 
00082   
00083   systemVitals->timeStart = timeMake(&time);
00084 
00085   kprintf("%i/%i/%i %i:%i.%i\n",time.mon,time.day,time.year,time.hour,time.min,time.sec);
00086 
00087   
00088   
00089   return(0x0);
00090   }
00091 
00092 uInt32 timeMake(struct timeStruct *time) {
00093   uInt32 res;
00094   int year;
00095 
00096   year = (time->year+100) - 70;
00097   
00098   res = YEAR*year + DAY*((year+1)/4);
00099   res += month[time->mon];
00100   
00101   if (time->mon>1 && ((year+2)%4))
00102     res -= DAY;
00103   res += DAY*(time->day-1);
00104   res += HOUR*time->hour;
00105   res += MINUTE*time->min;
00106   res += time->sec;
00107   return(res);
00108   }
00109 
00110 int gettimeofday(struct timeval *tp,struct timezone *tzp) {
00111   
00112   tp->tv_sec    = 0x0;
00113   tp->tv_usec = 0x0;
00114   return(0x0);
00115   }
00116 
00117 
00118 
00119 
00120