/**************************************************************************/ #include /* set dos time */ #include #include #include #include #include #include void main() { struct dostime_t time; int i,byte,count,fifoflag,error=0; unsigned char ihour,imin,isec,ihsec; /* initialize the IRIG reader */ outp(0x200,0x00); /* select IRIG B */ outp(0x201,0x00); /* select channel 1, forward */ outp(0x202,0x00); /* low to high trigger */ outp(0x203,0x00); /* request time function */ inp(0x218); /* reset the reader */ _dos_gettime(&time); isec=time.second; if(isec>56) isec=0; wait: _dos_gettime(&time); if(time.second!=(isec+3)) goto wait; inp(0x210); /* clear the interrupt */ isec=time.second; if(isec>56) isec=0; again: _dos_gettime(&time); if(time.second!=(isec+3)) goto again; /* read the IRIG reader and set dos time */ outp(0x208,0x00); /* reset the IRIG FIFO memory */ retry: outp(0x214,0x00); /* request time transfer to the FIFO */ _dos_gettime(&time); ihsec=time.hsecond; if(ihsec>98) ihsec=0; delay: _dos_gettime(&time); if(time.hsecond>=(ihsec+1)) goto delay; for(i=0;i<11;i++) { fifoflag=(inp(0x20C)&0x01); for(count=0;((count<1000)&&(fifoflag!=0x01));count++) /* wait for FIFO empty flag to clear */ { fifoflag=(inp(0x20C)&0x01); } if(count>999) goto quit; /* timed out */ byte=inp(0x204); /* read a time byte */ if((byte&0xFF)==0xF1) { error++; if(error==5) goto quit; goto retry; } else if((byte&0xF0)==0x30) ihour = (byte&0x0F)*10; else if((byte&0xF0)==0x40) ihour = ihour + (byte&0x0F); else if((byte&0xF0)==0x50) imin = (byte&0x0F)*10; else if((byte&0xF0)==0x60) imin = imin + (byte&0x0F); else if((byte&0xF0)==0x70) isec = (byte&0x0F)*10; else if((byte&0xF0)==0x80) isec = isec + (byte&0x0F); else if((byte&0xF0)==0x90) ihsec = (byte&0x0F)*10; else if((byte&0xF0)==0xA0) ihsec = ihsec + (byte&0x0F); } time.hour = ihour; time.minute = imin; time.second = isec; time.hsecond = ihsec; _dos_settime(&time); printf("TIME IS SET"); quit:; } /**************************************************************************/