Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.naic.edu/~phil/hardware/vertex/sharemegsvertex/floppy_bckup/lcuv2_2/LCU_ver2.2/BC630.LST
Дата изменения: Mon Mar 5 21:23:32 2001
Дата индексирования: Thu Jan 15 11:16:56 2009
Кодировка:

Поисковые слова: total solar eclipse


CP581 PAGE 1
bc630 03-05-:1
14:23:32

Line# Source Line Microsoft C Compiler Version 6.00A

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include "prog.h"
7 #include "extern.c"
8 /*
9 *modification history
10 *31dec99 - updated to check hours,min,secs.
11 * - also changed rtc_error to tell where it failed
12 * 1- first loop,
13 * 2- 2nd loop .. etc
14 */
15 void bc630(void)
16 {
17 int ii,rdyflg;
18 unsigned char tin[3];
19 unsigned int timer;
20 long int rtc_offs;
21 unsigned long int sub_msec;
22 int sec1,sec10,min1,min10,hour1,hour10,hour;
23 int badTmRd; /* true if we read a bad tm*/
24 int badDelta; /* true if we computes a bad delta*/
25
26 timer = 30000;
27 outp(0x20e,0x83); /* request sub second data */
28 do{
29 for(ii=100;ii!=0;ii--); /*don't read reg faster then 500kh
z*/
30 rdyflg = inp(0x20e);
31 } while((rdyflg != 0x3) && --timer); /* wait for ready flag of 3 */
32 if(!timer) {
33 rtc_error = 1;
34 goto tmouterr;
35 }
36 /*
37 * read in sub second data.
38 * don't bother with last 8 bits since we only need millisec not micro
sec
39 * resolution.
40 */
41 rtc_offs = inp(0x200);
42 rtc_offs = rtc_offs + inp(0x201)*0x100L;
43 rtc_offs = rtc_offs - 33920L;/* 2E6 mod 0xffff = 33920 for sync crysta
ls */
44 /*
45 * request time (seconds,minutes,hours)
46 */
47 timer = 30000;
48 outp(0x20e,0x80);
49 do{
50 for(ii=100;ii!=0;ii--); /* don't check stat faster than every 2 usec
s*/
51 rdyflg = inp(0x20e);
52 } while((rdyflg != 0) && --timer);


CP581 PAGE 2
bc630 03-05-:1
14:23:32

Line# Source Line Microsoft C Compiler Version 6.00A

53 if(!timer) {
54 rtc_error = 2;
55 goto tmouterr;
56 }
57 /*
58 * input the data
59 * adr b7-4 b3-0
60 * 200 10sec 1sec tin[1]
61 * 201 10min 1min tin[2]
62 * 202 10hour 1hour tin[3]
63 */
64 tin[0] =(unsigned char)(inp(0x200) & 0xff); /* 10sec , 1 sec */

65 tin[1] =(unsigned char)(inp(0x201) & 0xff); /* 10min , 1 min*/
66 tin[2] =(unsigned char)(inp(0x202) & 0xff); /* 10hr , 1 hr */
67 /*
68 * move to separate variables for data validity checking
69 */
70 sec1 = tin[0]&0xf;
71 sec10 =(tin[0]>>4) & 0xf;
72 min1 = tin[1]&0xf;
73 min10 =(tin[1]>>4) & 0xf;
74 hour1 = tin[2]&0xf;
75 hour10=(tin[2]>>4) & 0xf;
76 hour =hour1+10*hour10;
77 badTmRd=(sec1 > 9) || (sec10>5) || (min1>9)||(min10>5)||(hour1>9)||
78 (hour10>2) || (hour > 23);
79 /*
80 * the brd has a .5 micros sec counter that counts between each irig 1
sec
81 * transmission. The counter value gives us the sub second resolution.

82 * This counter is driven from the local board oscilator (not the irig
).
83 * rtc_offs is measured (i think every sec) telling how far off this
84 * counter is from the expected 2e6. It is then used to correct for th
e
85 * drift in the local board oscilator.
86 * Note:we have 1e3L rather than 1e6l since we want millisecs not micr
osecs
87 * c20-c0 21 bits .5 usec units.
88 * adr data
89 * 204 xxxc20 c19-c16 first byte
90 * 206 c15-8
91 * 207 c7-c0 not input...
92 */
93 sub_msec =(((inp(0x204)&0x1f)*0x10000L + inp(0x206)*0x100L)/
94 (2E6L+rtc_offs))* 1e3L + .5;
***** bc630.c(94) : warning C4051: type conversion - possible loss of data
95 /*
96 * convert to secs, then milliseconds, then add on sub_ms
97 * below assumes that compiler will promote an int to long before
98 * doing (int + long) or (long*int)
99 */
100 time_ms=(sec1 + 10L*sec10 + 60L*(min1+10L*min10 + 60L*(hour)))*1000L +


CP581 PAGE 3
bc630 03-05-:1
14:23:32

Line# Source Line Microsoft C Compiler Version 6.00A


101 sub_msec;
102 /*
103 * -compute time interval since last call to this routine.
104 * -allow midnite crossing +/- 1 second about midnight
105 */
106 if ((time_ms <= 1000) && (time_ms >=0) &&
107 (timeold1 >= 86399000) && (timeold1 < 86400000)){
108 dtime= 86400000-timeold1 + time_ms;
109 } else {
110 dtime = time_ms-timeold1;
111 }
112 if ((badDelta=((dtime > 2000) || (dtime < 0)))) {
113 dtime1 = time_ms; /* debug variables output in schreib call */
114 dtime2 = timeold1;
115 dtime = 0;
116 }
117
118 if ((stat1[12]&0x0040) == 0x0040) { /* reset flag with ch local only*/

119 dtime1 = 0;
120 dtime2 = 0;
121 }
122 /*
123 * if we had an error, stuff it in the error variables for output to
124 * the vme (but don't stuff it if we haven't output the last error..
125 * this is controlled by logFlag)
126 * If badInput, then set time_ms to last time+10mhz
127 * Don't do this for badDeltas since a bad oldTime1 would stay
128 * leave us stuck with a bad time forever.
129 */
130 rtc_error=(badTmRd)?3:(badDelta)?4:0;
131 if (badTmRd||badDelta) {
132 if (!badTm.logFlag){ /* nothing in badTm, ok to load it*/
133 badTm.inp[0]=tin[0];
134 badTm.inp[1]=tin[1];
135 badTm.inp[2]=tin[2];
136 badTm.time_ms = time_ms;
137 dreh4((char*)&badTm.time_ms); /* big endian*/
138 badTm.timelast_ms= timeold1;
139 dreh4((char*)&badTm.timelast_ms);/* big endian*/
140 badTm.logFlag =(unsigned char)rtc_error;
141 }
142 if (badTmRd) time_ms=timeold1 + 20;/*20ms after last time*/
143 }
144 timeold1 = time_ms;
145 if ((time_ms - timeold) >= 1000 || time_ms < timeold) {
146 timeold = time_ms;
147 dreh4((char*)&time_ms);
148 schreib(1);
149 } else {
150 dreh4((char*)&time_ms);
151 }
152 return;
153 /*
154 * timed out talking to bc630 .. just return rtc_error


CP581 PAGE 4
bc630 03-05-:1
14:23:32

Line# Source Line Microsoft C Compiler Version 6.00A

155 */
156 tmouterr:
157 if (!badTm.logFlag){ /* nothing in badTm, ok to load it*/
158 memset(&badTm,0,sizeof(badTm));
159 badTm.logFlag =(unsigned char)rtc_error;
160 }
161 return;
162 }


bc630 Local Symbols

Name Class Type Size Offset Register

hour1 . . . . . . . . . . auto -0024
hour10. . . . . . . . . . auto -0022
hour. . . . . . . . . . . auto -0020
badTmRd . . . . . . . . . auto -001e
sec1. . . . . . . . . . . auto -001c
sec10 . . . . . . . . . . auto -001a
tin . . . . . . . . . . . auto -0018
rdyflg. . . . . . . . . . auto -0014
rtc_offs. . . . . . . . . auto -0012
min1. . . . . . . . . . . auto -000e
min10 . . . . . . . . . . auto -000c
ii. . . . . . . . . . . . auto -000a
timer . . . . . . . . . . auto -0008
sub_msec. . . . . . . . . auto -0006
badDelta. . . . . . . . . auto -0002


Global Symbols

Name Class Type Size Offset

badTm . . . . . . . . . . extern struct/array 12 ***
bc630 . . . . . . . . . . global far function *** 0000
dreh4 . . . . . . . . . . extern far function *** ***
dtime . . . . . . . . . . extern long 4 ***
dtime1. . . . . . . . . . extern long 4 ***
dtime2. . . . . . . . . . extern long 4 ***
rtc_error . . . . . . . . extern int 2 ***
schreib . . . . . . . . . extern far function *** ***
stat1 . . . . . . . . . . extern struct/array 36 ***
time_ms . . . . . . . . . extern long 4 ***
timeold . . . . . . . . . extern long 4 ***
timeold1. . . . . . . . . extern long 4 ***

Code size = 04d2 (1234)
Data size = 0030 (48)
Bss size = 0000 (0)

No errors detected