Lines Matching +full:conv +full:- +full:period
1 /* refclock_ees - clock driver for the EES M201 receiver */
55 if (flags & CLK_FLAG2 && unitinuse) ees->leaphold = 0;
56 ees->dump_vals = flags & CLK_FLAG3;
57 ees->usealldata = flags & CLK_FLAG4;
60 bug->values[0] = (ees->lasttime) ? current_time - ees->lasttime : 0;
61 bug->values[1] = (ees->clocklastgood)?current_time-ees->clocklastgood:0;
62 bug->values[2] = (u_long)ees->status;
63 bug->values[3] = (u_long)ees->lastevent;
64 bug->values[4] = (u_long)ees->reason;
65 bug->values[5] = (u_long)ees->nsamples;
66 bug->values[6] = (u_long)ees->codestate;
67 bug->values[7] = (u_long)ees->day;
68 bug->values[8] = (u_long)ees->hour;
69 bug->values[9] = (u_long)ees->minute;
70 bug->values[10] = (u_long)ees->second;
71 bug->values[11] = (u_long)ees->tz;
72 bug->values[12] = ees->yearstart;
73 bug->values[13] = (ees->leaphold > current_time) ?
74 ees->leaphold - current_time : 0;
75 bug->values[14] = inherent_delay[unit].l_uf;
76 bug->values[15] = offset_fudge[unit].l_uf;
78 bug->times[0] = ees->reftime;
79 bug->times[1] = ees->arrvtime;
80 bug->times[2] = ees->lastsampletime;
81 bug->times[3] = ees->offset;
82 bug->times[4] = ees->lowoffset;
83 bug->times[5] = ees->highoffset;
84 bug->times[6] = inherent_delay[unit];
85 bug->times[8] = os_delay[unit];
86 bug->times[7] = fudgefactor[unit];
87 bug->times[9] = offset_fudge[unit];
88 bug->times[10]= ees->yearstart, 0;
101 * On the next minute it steps forward again :-(
102 * This is typically 16.5uS/S then 3975uS at the 4min re-sync,
103 * or 9.5uS/S then 3990.5uS at a 7min re-sync,
105 * I assume that the most accurate time is just AFTER the re-sync.
129 #define EESPRECISION (-10) /* what the heck - 2**-10 = 1ms */
153 (((((bits)*2 +1) << (FRACTION_PREC-SAFETY_SHIFT)) / (2*baud)) << SAFETY_SHIFT)
158 #define STREAM_PP1 "ppsclocd\0<-- patch space for module name1 -->"
161 #define STREAM_PP2 "ppsclock\0<-- patch space for module name2 -->"
166 * give offsets into ees->lastcode.
168 #define EESM_CSEC 0 /* centiseconds - always zero in our clock */
195 #define DEFOSTIME 0 /* Default OS delay -- passed by Make ? */
205 #define REDUCESHIFT (FULLSHIFT -1) /* SAMPLEREDUCE root 2 */
275 /* Fine tuning - compensate for 4 mS ramping .... */
281 int last_step_late; /* How late the last step was (0-59) */
285 int using_ramp; /* 1 -> noemal, -1 -> over stepped */
289 #define this_uisec ((ees->arrvtime).l_ui)
290 #define this_sfsec ((ees->arrvtime).l_f)
292 #define LAST_STEPS (sizeof ees->last_steps / sizeof ees->last_steps[0])
293 #define subms(x) ((((((x < 0) ? (-(x)) : (x)) % (1<<22))/2) * 625) / (1<<(22 -5)))
295 /* Bitmask for what methods to try to use -- currently only PPS enabled */
299 #define is_cbreak(x) ((x)->ttytype & T_CBREAK)
300 #define is_pps(x) ((x)->ttytype & T_PPS)
301 #define is_any(x) ((x)->ttytype)
321 static l_fp acceptable_slop; /* = { 0, 1 << (FRACTION_PREC -2) }; */
328 /* ees_reset - reset the count back to zero */
329 #define ees_reset(ees) (ees)->nsamples = 0; \
330 (ees)->codestate = EESCS_WAIT
332 /* ees_event - record and report an event */
333 #define ees_event(ees, evcode) if ((ees)->status != (u_char)(evcode)) \
385 if ((ptr - buff) > DUMP_BUF_SIZE) { in dump_buf()
389 snprintf(ptr, sizeof(buff) - (ptr - buff), in dump_buf()
395 /* msfees_init - initialize internal ees driver data */
405 acceptable_slop.l_uf = 1 << (FRACTION_PREC -2); in msfees_init()
427 /* msfees_start - open the EES devices and initialize data for processing */
436 int fd232 = -1; in msfees_start()
440 pp = peer->procptr; in msfees_start()
444 unit, MAXUNITS-1); in msfees_start()
457 if (fd232 == -1) { in msfees_start()
488 ttyp->c_iflag = IGNBRK|IGNPAR|ICRNL; in msfees_start()
489 ttyp->c_cflag = SPEED232|CS8|CLOCAL|CREAD; in msfees_start()
490 ttyp->c_oflag = 0; in msfees_start()
491 ttyp->c_lflag = ICANON; in msfees_start()
492 ttyp->c_cc[VERASE] = ttyp->c_cc[VKILL] = '\0'; in msfees_start()
525 } /* no spare -- make a new one */ in msfees_start()
532 ees->peer = peer; in msfees_start()
533 ees->unit = (u_char)unit; in msfees_start()
534 ees->timestarted= current_time; in msfees_start()
535 ees->ttytype = 0; in msfees_start()
536 ees->io.clock_recv= ees_receive; in msfees_start()
537 ees->io.srcclock= peer; in msfees_start()
538 ees->io.datalen = 0; in msfees_start()
539 ees->io.fd = fd232; in msfees_start()
564 ees->ttytype |= T_PPS; in msfees_start()
570 if (!io_addclock(&ees->io)) { in msfees_start()
579 peer->precision = sys_precision; in msfees_start()
580 peer->stratum = stratumtouse[unit]; in msfees_start()
582 memcpy((char *)&pp->refid, EESREFID, 4); in msfees_start()
584 ((char *)&pp->refid)[3] = '0' + unit; in msfees_start()
586 peer->refid = htonl(EESHSREFID); in msfees_start()
589 pp->unitptr = &eesunits[unit]; in msfees_start()
590 pp->clockdesc = EESDESCRIPTION; in msfees_start()
595 if (fd232 != -1) in msfees_start()
601 /* msfees_shutdown - shut down a EES clock */
624 io_closeclock(&ees->io); in msfees_shutdown()
629 /* ees_report_event - note the occurance of an event */
636 if (ees->status != (u_char)code) { in ees_report_event()
637 ees->status = (u_char)code; in ees_report_event()
639 ees->lastevent = (u_char)code; in ees_report_event()
647 /* ees_receive - receive data from the serial interface on an EES clock */
677 ees = (struct eesunit *)rbufp->recv_peer->procptr->unitptr; in ees_receive()
678 dpt = (u_char *)&rbufp->recv_space; in ees_receive()
679 dpend = dpt + rbufp->recv_length; in ees_receive()
680 if ((dbg & DB_LOG_AWAITMORE) && (rbufp->recv_length != LENEESCODE)) in ees_receive()
681 printf("[%d] ", rbufp->recv_length); in ees_receive()
684 switch (ees->codestate) { in ees_receive()
691 ees->arrvtime = rbufp->recv_time; in ees_receive()
692 ees->codestate = EESCS_GOTSOME; in ees_receive()
693 ees->lencode = 0; in ees_receive()
697 cp = &(ees->lastcode[ees->lencode]); in ees_receive()
702 ees->lencode++; in ees_receive()
703 /* Oh dear -- too many bytes .. */ in ees_receive()
704 if (ees->lencode > LENEESPRT) { in ees_receive()
708 ees->lencode, dpend - dpt, LENEESPRT, in ees_receive()
709 #define D(x) (ees->lastcode[x]) in ees_receive()
713 ees->badformat++; in ees_receive()
714 ees->reason = CODEREASON + 1; in ees_receive()
726 ees->unit, dpt, dpend); in ees_receive()
733 ees->badformat++; in ees_receive()
734 ees->reason = CODEREASON + 2; in ees_receive()
745 cp = ees->lastcode; in ees_receive()
750 ees->unit, ees->codestate); in ees_receive()
751 ees->reason = CODEREASON + 5; in ees_receive()
761 ees->codestate = EESCS_WAIT; in ees_receive()
762 ees->lasttime = current_time; in ees_receive()
763 if (ees->lencode != LENEESPRT) { in ees_receive()
764 ees->badformat++; in ees_receive()
765 ees->reason = CODEREASON + 6; in ees_receive()
771 cp = ees->lastcode; in ees_receive()
775 ees->baddata++; in ees_receive()
776 ees->reason = CODEREASON + 7; in ees_receive()
784 ees->badformat++; in ees_receive()
785 ees->reason = CODEREASON + 8; in ees_receive()
792 ees->badformat++; in ees_receive()
793 ees->reason = CODEREASON + 9; in ees_receive()
800 ees->badformat++; in ees_receive()
801 ees->reason = CODEREASON + 10; in ees_receive()
814 ees->second = bcdunpack(cp[EESM_SEC]); /* second */ in ees_receive()
815 ees->minute = bcdunpack(cp[EESM_MIN]); /* minute */ in ees_receive()
816 ees->hour = bcdunpack(cp[EESM_HOUR]); /* hour */ in ees_receive()
838 default: ees->baddata++; in ees_receive()
839 ees->reason = CODEREASON + 11; in ees_receive()
845 ees->day = day; in ees_receive()
849 * Currently -1 if BST flag set, 0 otherwise. This in ees_receive()
853 ees->tz = istrue(cp[EESM_BST]) ? -1 : 0; in ees_receive()
855 if (ees->day > 366 || ees->day < 1 || in ees_receive()
856 ees->hour > 23 || ees->minute > 59 || ees->second > 59) { in ees_receive()
857 ees->baddata++; in ees_receive()
858 ees->reason = CODEREASON + 12; in ees_receive()
864 n_sample = ees->nsamples; in ees_receive()
866 /* Now, compute the reference time value: text -> tmp.l_ui */ in ees_receive()
867 if (!clocktime(ees->day, ees->hour, ees->minute, ees->second, in ees_receive()
868 ees->tz, rbufp->recv_time.l_ui, &ees->yearstart, in ees_receive()
870 ees->baddata++; in ees_receive()
871 ees->reason = CODEREASON + 13; in ees_receive()
878 /* DON'T use ees->arrvtime -- it may be < reftime */ in ees_receive()
879 ees->lastsampletime = tmp; in ees_receive()
885 ees->reftime = tmp; in ees_receive()
886 ees->clocklastgood = current_time; in ees_receive()
893 ees->codeoffsets[n_sample].l_ui = tmp.l_ui; in ees_receive()
894 ees->codeoffsets[n_sample].l_uf = 0; in ees_receive()
897 sincelast = this_uisec - ees->last_step; in ees_receive()
901 rc = ioctl(ees->io.fd, request, (char *) &ppsclockev); in ees_receive()
904 DB_PRINT_EV, ees->unit, ees->io.fd, request, is_pps(ees), in ees_receive()
909 int conv = -1; in ees_receive() local
910 pps_step = ppsclockev.serial - ees->last_pps_no; in ees_receive()
913 if (pps_step == 2) msyslog(LOG_ERR, "pps step = 2 @ %02d", ees->second); in ees_receive()
914 if (pps_step == 2 && ees->second == 1) suspect_4ms_step |= 1; in ees_receive()
915 if (pps_step == 2 && ees->second == 2) suspect_4ms_step |= 4; in ees_receive()
920 ppsclockev.serial, ees->last_pps_no, pps_step); in ees_receive()
923 /* if ((ABS(time difference) - 0.25) < 0) in ees_receive()
928 conv = 0; in ees_receive()
929 L_SUB(&diff, &ees->arrvtime); in ees_receive()
931 printf("[%x] Have %lx.%08lx and %lx.%08lx -> %lx.%08lx @ %s", in ees_receive()
932 DB_PRINT_CDT, (long)ees->arrvtime.l_ui, (long)ees->arrvtime.l_uf, in ees_receive()
938 if (L_ISNEG(&diff)) { /* AOK -- pps_sample */ in ees_receive()
939 ees->arrvtime = pps_arrvstamp; in ees_receive()
940 conv++; in ees_receive()
944 else if (ees->second == 1) { in ees_receive()
947 L_SUB(&diff, &ees->arrvtime); in ees_receive()
950 msyslog(LOG_ERR, "Have sec==1 slip %ds a=%08x-p=%08x -> %x.%08x (u=%d) %s", in ees_receive()
951 pps_arrvstamp.l_ui - ees->arrvtime.l_ui, in ees_receive()
953 ees->arrvtime.l_uf, in ees_receive()
957 if (L_ISNEG(&diff)) { /* AOK -- pps_sample */ in ees_receive()
959 ees->arrvtime = pps_arrvstamp; in ees_receive()
960 L_ADD(&ees->arrvtime, &onesec); in ees_receive()
961 conv++; in ees_receive()
966 ees->last_pps_no = ppsclockev.serial; in ees_receive()
971 (long)pps_arrvstamp.l_uf, conv, ees->unit, in ees_receive()
982 delta.l_i = ees->arrvtime.l_i; in ees_receive()
983 delta.l_f = ees->arrvtime.l_f; in ees_receive()
985 L_SUB(&delta, &ees->last_l); in ees_receive()
987 if (delta_f_abs < 0) delta_f_abs = -delta_f_abs; in ees_receive()
992 if (/*0 <= ees->second && */ in ees_receive()
993 ees->second < COUNTOF(deltas)) in ees_receive()
994 deltas[ees->second] = delta_sfsec; in ees_receive()
996 if (ees->second == 1) { in ees_receive()
1006 msyslog(LOG_ERR, "Deltas: %d.%04d<->%d.%04d: %s", in ees_receive()
1007 msec(EES_STEP_F - EES_STEP_F_GRACE), subms(EES_STEP_F - EES_STEP_F_GRACE), in ees_receive()
1015 if ( ((EES_STEP_F - EES_STEP_F_GRACE) < delta_f_abs) && in ees_receive()
1017 (ees->second == 0 || ees->second == 1 || ees->second == 2) && in ees_receive()
1023 /* Yes -- so compute the ramp time */ in ees_receive()
1024 if (ees->last_step == 0) sincelast = 0; in ees_receive()
1027 /* First time in, just set "ees->last_step" */ in ees_receive()
1028 if(ees->last_step) { in ees_receive()
1032 int p_step = ees->this_step; in ees_receive()
1034 ees->last_steps[p_step] = this_step; in ees_receive()
1038 ees->this_step = p_step; in ees_receive()
1041 int this = ees->last_steps[p]; in ees_receive()
1046 this== (this_step -2) || in ees_receive()
1048 this== (this_step -1))) in ees_receive()
1051 int idelta = (this_step - other_step); in ees_receive()
1052 if (idelta < 0) idelta = - idelta; in ees_receive()
1056 this == (other_step -1) || in ees_receive()
1058 this == (this_step -1)) in ees_receive()
1068 p--; in ees_receive()
1072 …%d (%d), other=%d/%d, sum=%d, count=%d, pps_step=%d, suspect=%x", ees->unit, p, ees->last_steps[p]… in ees_receive()
1074 #define SV(x) (ees->last_steps[(x + p_step) % LAST_STEPS]) in ees_receive()
1076 ees->unit, suspect_4ms_step, p_step, SV(0), SV(1), SV(2), SV(3), SV(4), SV(5), SV(6), in ees_receive()
1079 ees->unit, p_step, SV(0), SV(1), SV(2), SV(3), SV(4), SV(5), SV(6), in ees_receive()
1082 ees->jump_fsecs = delta_sfsec; in ees_receive()
1083 ees->using_ramp = 1; in ees_receive()
1085 ees->last_step_late += sincelast - ((sum) ? sum : ees->last_step_secs); in ees_receive()
1086 else ees->last_step_late = 30; in ees_receive()
1087 if (ees->last_step_late < -60 || ees->last_step_late > 120) ees->last_step_late = 30; in ees_receive()
1088 if (ees->last_step_late < 0) ees->last_step_late = 0; in ees_receive()
1089 if (ees->last_step_late >= 60) ees->last_step_late = 59; in ees_receive()
1092 else { /* First time in -- just save info */ in ees_receive()
1093 ees->last_step_late = 30; in ees_receive()
1094 ees->jump_fsecs = delta_sfsec; in ees_receive()
1095 ees->using_ramp = 1; in ees_receive()
1098 ees->last_step = this_uisec; in ees_receive()
1100 ees->unit, (long)msec(delta_sfsec), (long)subms(delta_sfsec), in ees_receive()
1101 ees->second, old_sincelast, ees->last_step_late, count, sum, in ees_receive()
1102 ees->last_step_secs); in ees_receive()
1104 ees->unit, msec(delta_sfsec), subms(delta_sfsec), ees->second, in ees_receive()
1105 old_sincelast, ees->last_step_late, count, sum, ees->last_step_secs); in ees_receive()
1106 if (sum) ees->last_step_secs = sum; in ees_receive()
1112 ees->unit, suspect_4ms_step, msec(delta_sfsec), subms(delta_sfsec), in ees_receive()
1113 msec(EES_STEP_F - EES_STEP_F_GRACE), in ees_receive()
1114 subms(EES_STEP_F - EES_STEP_F_GRACE), in ees_receive()
1119 ees->second, in ees_receive()
1121 if ((delta_f_abs > EES_STEP_NOTE) && ees->last_l.l_i) { in ees_receive()
1124 ees_step_notes--; in ees_receive()
1126 ees->unit, (long)msec(delta_sfsec), (long)subms(delta_sfsec), in ees_receive()
1127 ees->second, sincelast, ees_step_notes ? "" : " -- NO MORE !"); in ees_receive()
1129 …ees->unit, msec(delta_sfsec), subms(delta_sfsec), ees->second, (ees->last_step) ? sincelast : -1, … in ees_receive()
1134 ees->last_l = ees->arrvtime; in ees_receive()
1137 * && it's within twice the expected ramp period in ees_receive()
1141 if (ees->using_ramp && in ees_receive()
1142 sincelast < (ees->last_step_secs)*2 && in ees_receive()
1143 ees->last_step_secs) in ees_receive()
1144 { long sec_of_ramp = sincelast + ees->last_step_late; in ees_receive()
1149 if (sec_of_ramp > (ees->last_step_secs + 120)) in ees_receive()
1150 sec_of_ramp = ees->last_step_secs; in ees_receive()
1152 /* sec_of_ramp * ees->jump_fsecs may overflow 2**32 */ in ees_receive()
1153 fsecs = sec_of_ramp * (ees->jump_fsecs / ees->last_step_secs); in ees_receive()
1156 "[%x] MSF%d: %3ld/%03d -> d=%11ld (%d|%ld)", in ees_receive()
1158 ees->unit, sec_of_ramp, ees->last_step_secs, fsecs, in ees_receive()
1161 "MSF%d: %3ld/%03d -> d=%11ld (%ld|%ld)\n", in ees_receive()
1162 ees->unit, sec_of_ramp, ees->last_step_secs, fsecs, in ees_receive()
1166 inc.l_i = (fsecs < 0) ? -1 : 0; in ees_receive()
1170 L_SUB(&ees->arrvtime, &inc); in ees_receive()
1174 L_ADD(&ees->arrvtime, &inc); in ees_receive()
1179 "[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x", in ees_receive()
1181 ees->unit, ees->using_ramp, in ees_receive()
1183 (ees->last_step_secs)*2, in ees_receive()
1184 ees->last_step_secs); in ees_receive()
1186 "[%x] MSF%d: ees->using_ramp=%d, sincelast=%x / %x, ees->last_step_secs=%x\n", in ees_receive()
1188 ees->unit, ees->using_ramp, in ees_receive()
1190 (ees->last_step_secs)*2, in ees_receive()
1191 ees->last_step_secs); in ees_receive()
1194 L_SUB(&ees->arrvtime, &offset_fudge[ees->unit]); in ees_receive()
1195 L_SUB(&pps_arrvstamp, &offset_fudge[ees->unit]); in ees_receive()
1198 /* Sigh -- it expects its args negated */ in ees_receive()
1209 L_SUB(&ees->codeoffsets[n_sample], &ees->arrvtime); in ees_receive()
1212 ees->unit, DB_LOG_DELTAS, n_sample, in ees_receive()
1213 ees->codeoffsets[n_sample].l_f, in ees_receive()
1214 ees->codeoffsets[n_sample].l_f / 4295, in ees_receive()
1219 if (ees->nsamples++ == NCODES-1) ees_process(ees); in ees_receive()
1225 /* offcompare - auxiliary comparison routine for offset sort */
1235 return(L_ISGEQ(a, b) ? (L_ISEQU(a, b) ? 0 : 1) : -1); in offcompare()
1239 /* ees_process - process a pile of samples from the clock */
1245 static int last_samples = -1; in ees_process()
1248 register l_fp *coffs = ees->codeoffsets; in ees_process()
1252 int samples = ees->nsamples; in ees_process()
1253 int samplelog = 0; /* keep "gcc -Wall" happy ! */ in ees_process()
1260 if (sloppyclockflag[ees->unit]) { in ees_process()
1270 ((samples != (last_samples-1)) || samples < 3)) { in ees_process()
1278 if (ees->dump_vals) in ees_process()
1286 while ((noff - i) > samplereduce) { in ees_process()
1291 * identity (c-b)-(b-a) == 2*b-a-c in ees_process()
1296 L_SUB(&tmp, &coffs[noff-1]); in ees_process()
1297 if (L_ISNEG(&tmp)) noff--; else i++; in ees_process()
1301 if (ees->dump_vals) dump_buf(coffs, i, noff, "Reduced to:"); in ees_process()
1307 if (sloppyclockflag[ees->unit]) { in ees_process()
1311 for (j = samplelog; j > 0; j--) in ees_process()
1322 tmp = coffs[noff-1]; in ees_process()
1332 (sloppyclockflag[ees->unit]) ? " by averaging" : "", in ees_process()
1339 noff-1, in ees_process()
1340 (coffs[noff-1].l_f) / 4295, in ees_process()
1341 (coffs[samples-1].l_f) / 4295); in ees_process()
1347 if (ees->usealldata && ees->offset.l_uf) { in ees_process()
1348 long diff = (long) (ees->offset.l_uf - offset.l_uf); in ees_process()
1351 if ((- FRACT_SEC(100)) < diff && diff < FRACT_SEC(100)) { in ees_process()
1355 new = offset.l_uf + ((diff * (samd -1)) / samd); in ees_process()
1357 /* Sign change -> need to fix up int part */ in ees_process()
1365 (new < 0) ? -1 : 1); in ees_process()
1366 offset.l_ui += (new < 0) ? -1 : 1; in ees_process()
1371 "I: [%x] Smooth data: %ld -> %ld, dispersion now %f", in ees_process()
1381 - FRACT_SEC(100), diff, FRACT_SEC(100)); in ees_process()
1387 ees->usealldata, ees->offset.l_f, ees->offset.l_uf, in ees_process()
1388 offset.l_f, ees->offset.l_f - offset.l_f); in ees_process()
1391 ees->offset = offset; in ees_process()
1392 ees->lowoffset = coffs[i]; in ees_process()
1393 ees->highoffset = coffs[noff-1]; in ees_process()
1407 lostsync = current_time - ees->clocklastgood > 300 ? 1 : 0; in ees_process()
1408 isinsync = (lostsync || ees->leaphold > current_time) ? 0 : 1; in ees_process()
1413 if (ees->fix_pending) { in ees_process()
1414 msyslog(LOG_ERR, "MSF%d: fix_pending=%d -> jump %x.%08x", in ees_process()
1415 ees->fix_pending, ees->unit, offset.l_i, offset.l_f); in ees_process()
1416 ees->fix_pending = 0; in ees_process()
1419 refclock_receive(ees->peer); in ees_process()
1423 /* msfees_poll - called by the transmit procedure */
1443 if ((current_time - eesunits[unit]->lasttime) > 150) in msfees_poll()