diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 2002-04-26 20:24:28 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 2002-04-26 20:24:28 +0000 |
commit | 7bf758bff079c475d6bd99193fec252bbc4be8e8 (patch) | |
tree | 61c1590387f116655d9c80b8e7b3ced6030e81c9 /sys | |
parent | 79dea31b974f32b819bd4e808117f1bd98319e23 (diff) | |
download | src-7bf758bff079c475d6bd99193fec252bbc4be8e8.tar.gz src-7bf758bff079c475d6bd99193fec252bbc4be8e8.zip |
Simplify the RFC2783 and PPS_SYNC timestamp collection API.
Notes
Notes:
svn path=/head/; revision=95523
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ppbus/pps.c | 22 | ||||
-rw-r--r-- | sys/dev/sio/sio.c | 9 | ||||
-rw-r--r-- | sys/kern/kern_tc.c | 53 | ||||
-rw-r--r-- | sys/pc98/cbus/sio.c | 9 | ||||
-rw-r--r-- | sys/pc98/pc98/sio.c | 9 | ||||
-rw-r--r-- | sys/pci/xrpu.c | 10 | ||||
-rw-r--r-- | sys/sys/timepps.h | 20 |
7 files changed, 71 insertions, 61 deletions
diff --git a/sys/dev/ppbus/pps.c b/sys/dev/ppbus/pps.c index 2ba4429c96af..e8a233f14cd5 100644 --- a/sys/dev/ppbus/pps.c +++ b/sys/dev/ppbus/pps.c @@ -21,7 +21,6 @@ #include <sys/module.h> #include <sys/bus.h> #include <sys/conf.h> -#include <sys/timetc.h> #include <sys/timepps.h> #include <machine/bus.h> #include <machine/resource.h> @@ -258,8 +257,6 @@ ppshcpoll(void *arg) { struct pps_data *sc = arg; int i, j, k, l; - struct timecounter *tc; - unsigned count; if (!(sc->busy & ~1)) return; @@ -267,16 +264,14 @@ ppshcpoll(void *arg) i = ppb_rdtr(sc->ppbus); if (i == sc->lastdata) return; - tc = timecounter; - count = timecounter->tc_get_timecount(tc); l = sc->lastdata ^ i; k = 1; for (j = 1; j < 9; j ++) { - if (l & k) - pps_event(&sc->pps[j], tc, count, - i & k ? - PPS_CAPTUREASSERT : PPS_CAPTURECLEAR - ); + if (l & k) { + pps_capture(&sc->pps[j]); + pps_event(&sc->pps[j], + i & k ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR); + } k += k; } sc->lastdata = i; @@ -288,16 +283,13 @@ ppsintr(void *arg) device_t ppsdev = (device_t)arg; struct pps_data *sc = DEVTOSOFTC(ppsdev); device_t ppbus = sc->ppbus; - struct timecounter *tc; - unsigned count; - tc = timecounter; - count = timecounter->tc_get_timecount(tc); + pps_capture(&sc->pps[0]); if (!(ppb_rstr(ppbus) & nACK)) return; if (sc->pps[0].ppsparam.mode & PPS_ECHOASSERT) ppb_wctr(ppbus, IRQENABLE | AUTOFEED); - pps_event(&sc->pps[0], tc, count, PPS_CAPTUREASSERT); + pps_event(&sc->pps[0], PPS_CAPTUREASSERT); if (sc->pps[0].ppsparam.mode & PPS_ECHOASSERT) ppb_wctr(ppbus, IRQENABLE); } diff --git a/sys/dev/sio/sio.c b/sys/dev/sio/sio.c index 60be206577bc..642053700240 100644 --- a/sys/dev/sio/sio.c +++ b/sys/dev/sio/sio.c @@ -69,7 +69,6 @@ #include <machine/bus_pio.h> #include <machine/bus.h> #include <sys/rman.h> -#include <sys/timetc.h> #include <sys/timepps.h> #include <sys/uio.h> @@ -1725,8 +1724,6 @@ siointr1(com) u_char recv_data; u_char int_ctl; u_char int_ctl_new; - struct timecounter *tc; - u_int count; int_ctl = inb(com->intr_ctl_port); int_ctl_new = int_ctl; @@ -1735,10 +1732,8 @@ siointr1(com) if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) { modem_status = inb(com->modem_status_port); if ((modem_status ^ com->last_modem_status) & MSR_DCD) { - tc = timecounter; - count = tc->tc_get_timecount(tc); - pps_event(&com->pps, tc, count, - (modem_status & MSR_DCD) ? + pps_capture(&com->pps); + pps_event(&com->pps, (modem_status & MSR_DCD) ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR); } } diff --git a/sys/kern/kern_tc.c b/sys/kern/kern_tc.c index aee3eaa390b6..fe07aec9bc58 100644 --- a/sys/kern/kern_tc.c +++ b/sys/kern/kern_tc.c @@ -478,7 +478,18 @@ pps_init(struct pps_state *pps) } void -pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int event) +pps_capture(struct pps_state *pps) +{ + struct timecounter *tc; + + tc = timecounter; + pps->captc = tc; + pps->capgen = tc->tc_generation; + pps->capcount = tc->tc_get_timecount(tc); +} + +void +pps_event(struct pps_state *pps, int event) { struct timespec ts, *tsp, *osp; unsigned tcount, *pcount; @@ -486,6 +497,10 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve int foff, fhard; pps_seq_t *pseq; + /* If the timecounter were wound up, bail. */ + if (pps->capgen != pps->capgen) + return; + /* Things would be easier with arrays... */ if (event == PPS_CAPTUREASSERT) { tsp = &pps->ppsinfo.assert_timestamp; @@ -505,26 +520,32 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve /* The timecounter changed: bail */ if (!pps->ppstc || - pps->ppstc->tc_name != tc->tc_name || - tc->tc_name != timecounter->tc_name) { - pps->ppstc = tc; - *pcount = count; + pps->ppstc->tc_name != pps->captc->tc_name || + pps->captc->tc_name != timecounter->tc_name) { + pps->ppstc = pps->captc; + *pcount = pps->capcount; +#ifdef PPS_SYNC + pps->ppscount[2] = pps->capcount; +#endif return; } /* Nothing really happened */ - if (*pcount == count) + if (*pcount == pps->capcount) return; - *pcount = count; - /* Convert the count to timespec */ - tcount = count - tc->tc_offset_count; - tcount &= tc->tc_counter_mask; - bt = tc->tc_offset; - bintime_addx(&bt, tc->tc_scale * tcount); + tcount = pps->capcount - pps->captc->tc_offset_count; + tcount &= pps->captc->tc_counter_mask; + bt = pps->captc->tc_offset; + bintime_addx(&bt, pps->captc->tc_scale * tcount); bintime2timespec(&bt, &ts); + /* If the timecounter were wound up, bail. */ + if (pps->capgen != pps->capgen) + return; + + *pcount = pps->capcount; (*pseq)++; *tsp = ts; @@ -538,12 +559,12 @@ pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int eve #ifdef PPS_SYNC if (fhard) { /* magic, at its best... */ - tcount = count - pps->ppscount[2]; - pps->ppscount[2] = count; - tcount &= tc->tc_counter_mask; + tcount = pps->capcount - pps->ppscount[2]; + pps->ppscount[2] = pps->capcount; + tcount &= pps->captc->tc_counter_mask; bt.sec = 0; bt.frac = 0; - bintime_addx(&bt, tc->tc_scale * tcount); + bintime_addx(&bt, pps->captc->tc_scale * tcount); bintime2timespec(&bt, &ts); hardpps(tsp, ts.tv_nsec + 1000000000 * ts.tv_sec); } diff --git a/sys/pc98/cbus/sio.c b/sys/pc98/cbus/sio.c index 2295500b7065..7ff381681f7f 100644 --- a/sys/pc98/cbus/sio.c +++ b/sys/pc98/cbus/sio.c @@ -131,7 +131,6 @@ #include <sys/tty.h> #include <machine/bus.h> #include <sys/rman.h> -#include <sys/timetc.h> #include <sys/timepps.h> #include <sys/uio.h> @@ -2568,8 +2567,6 @@ siointr1(com) u_char recv_data; u_char int_ctl; u_char int_ctl_new; - struct timecounter *tc; - u_int count; #ifdef PC98 u_char tmp = 0; @@ -2611,10 +2608,8 @@ more_intr: if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) { modem_status = inb(com->modem_status_port); if ((modem_status ^ com->last_modem_status) & MSR_DCD) { - tc = timecounter; - count = tc->tc_get_timecount(tc); - pps_event(&com->pps, tc, count, - (modem_status & MSR_DCD) ? + pps_capture(&com->pps); + pps_event(&com->pps, (modem_status & MSR_DCD) ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR); } } diff --git a/sys/pc98/pc98/sio.c b/sys/pc98/pc98/sio.c index 2295500b7065..7ff381681f7f 100644 --- a/sys/pc98/pc98/sio.c +++ b/sys/pc98/pc98/sio.c @@ -131,7 +131,6 @@ #include <sys/tty.h> #include <machine/bus.h> #include <sys/rman.h> -#include <sys/timetc.h> #include <sys/timepps.h> #include <sys/uio.h> @@ -2568,8 +2567,6 @@ siointr1(com) u_char recv_data; u_char int_ctl; u_char int_ctl_new; - struct timecounter *tc; - u_int count; #ifdef PC98 u_char tmp = 0; @@ -2611,10 +2608,8 @@ more_intr: if (com->pps.ppsparam.mode & PPS_CAPTUREBOTH) { modem_status = inb(com->modem_status_port); if ((modem_status ^ com->last_modem_status) & MSR_DCD) { - tc = timecounter; - count = tc->tc_get_timecount(tc); - pps_event(&com->pps, tc, count, - (modem_status & MSR_DCD) ? + pps_capture(&com->pps); + pps_event(&com->pps, (modem_status & MSR_DCD) ? PPS_CAPTUREASSERT : PPS_CAPTURECLEAR); } } diff --git a/sys/pci/xrpu.c b/sys/pci/xrpu.c index 1cae322bf1d2..6a2f13cfa7e7 100644 --- a/sys/pci/xrpu.c +++ b/sys/pci/xrpu.c @@ -94,22 +94,28 @@ xrpu_poll_pps(struct timecounter *tc) for (i = 0; i < XRPU_MAX_PPS; i++) { if (sc->assert[i]) { + sc->pps[i].capgen = tc->tc_generation; ppscount = *(sc->assert[i]) & tc->tc_counter_mask; j = 0; do { count1 = ppscount; ppscount = *(sc->assert[i]) & tc->tc_counter_mask; } while (ppscount != count1 && ++j < 5); - pps_event(&sc->pps[i], tc, ppscount, PPS_CAPTUREASSERT); + sc->pps[i].captc = tc; + sc->pps[i].capcount = ppscount; + pps_event(&sc->pps[i], PPS_CAPTUREASSERT); } if (sc->clear[i]) { + sc->pps[i].capgen = tc->tc_generation; j = 0; ppscount = *(sc->clear[i]) & tc->tc_counter_mask; do { count1 = ppscount; ppscount = *(sc->clear[i]) & tc->tc_counter_mask; } while (ppscount != count1 && ++j < 5); - pps_event(&sc->pps[i], tc, ppscount, PPS_CAPTURECLEAR); + sc->pps[i].captc = tc; + sc->pps[i].capcount = ppscount; + pps_event(&sc->pps[i], PPS_CAPTURECLEAR); } } } diff --git a/sys/sys/timepps.h b/sys/sys/timepps.h index a48cc84b5dfc..24c9a1d0a497 100644 --- a/sys/sys/timepps.h +++ b/sys/sys/timepps.h @@ -104,15 +104,21 @@ struct pps_kcbind_args { #ifdef _KERNEL struct pps_state { - pps_params_t ppsparam; - pps_info_t ppsinfo; - int kcmode; - int ppscap; - struct timecounter *ppstc; - unsigned ppscount[3]; + /* capture information */ + struct timecounter *captc; + u_int capgen; + u_int capcount; + /* state information */ + pps_params_t ppsparam; + pps_info_t ppsinfo; + int kcmode; + int ppscap; + struct timecounter *ppstc; + unsigned ppscount[3]; }; -void pps_event(struct pps_state *pps, struct timecounter *tc, unsigned count, int event); +void pps_capture(struct pps_state *pps); +void pps_event(struct pps_state *pps, int event); void pps_init(struct pps_state *pps); int pps_ioctl(u_long cmd, caddr_t data, struct pps_state *pps); void hardpps(struct timespec *tsp, long nsec); |