summaryrefslogtreecommitdiffstats
path: root/sys/dev/ppbus/pps.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1999-03-11 15:09:51 +0000
committerphk <phk@FreeBSD.org>1999-03-11 15:09:51 +0000
commit1542a4a4974b31d78a2115e37a802c377265be93 (patch)
tree59c54f6ab6826395ea6c20a6d0d12cb2be4bc943 /sys/dev/ppbus/pps.c
parent9c47f49734c0ff3b3d666a5a7a2bb329444223f1 (diff)
downloadFreeBSD-src-1542a4a4974b31d78a2115e37a802c377265be93.zip
FreeBSD-src-1542a4a4974b31d78a2115e37a802c377265be93.tar.gz
Make even more of the PPSAPI implementations generic.
FLL support in hardpps() Various magic shuffles and improved comments Style fixes from Bruce.
Diffstat (limited to 'sys/dev/ppbus/pps.c')
-rw-r--r--sys/dev/ppbus/pps.c75
1 files changed, 22 insertions, 53 deletions
diff --git a/sys/dev/ppbus/pps.c b/sys/dev/ppbus/pps.c
index 24be094..f507143 100644
--- a/sys/dev/ppbus/pps.c
+++ b/sys/dev/ppbus/pps.c
@@ -6,7 +6,7 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
- * $Id: pps.c,v 1.12 1998/12/07 21:58:16 archie Exp $
+ * $Id: pps.c,v 1.13 1999/01/30 15:35:39 nsouch Exp $
*
* This driver implements a draft-mogul-pps-api-02.txt PPS source.
*
@@ -16,7 +16,6 @@
*/
#include "opt_devfs.h"
-#include "opt_ntp.h"
#include <sys/param.h>
#include <sys/kernel.h>
@@ -36,20 +35,11 @@
static struct pps_data {
int pps_unit;
struct ppb_device pps_dev;
- pps_params_t ppsparam;
- pps_info_t ppsinfo;
+ struct pps_state pps;
} *softc[NPPS];
-static int ppscap =
- PPS_CAPTUREASSERT |
-#ifdef PPS_SYNC
- PPS_HARDPPSONASSERT |
-#endif /* PPS_SYNC */
- PPS_OFFSETASSERT |
- PPS_ECHOASSERT |
- PPS_TSFMT_TSPEC;
-
static int npps;
+static pps_devsw_installed = 0;
/*
* Make ourselves visible as a ppbus driver
@@ -77,6 +67,7 @@ static struct cdevsw pps_cdevsw =
seltrue, nommap, nostrat, PPS_NAME,
NULL, -1 };
+
static struct ppb_device *
ppsprobe(struct ppb_data *ppb)
{
@@ -99,12 +90,16 @@ ppsprobe(struct ppb_data *ppb)
sc->pps_dev.name = ppsdriver.name;
sc->pps_dev.intr = ppsintr;
+ sc->pps.ppscap = PPS_CAPTUREASSERT | PPS_ECHOASSERT;
+ pps_init(&sc->pps);
return (&sc->pps_dev);
}
static int
ppsattach(struct ppb_device *dev)
{
+ dev_t devt;
+
/*
* Report ourselves
*/
@@ -116,7 +111,11 @@ ppsattach(struct ppb_device *dev)
dev->id_unit, DV_CHR,
UID_ROOT, GID_WHEEL, 0600, PPS_NAME "%d", dev->id_unit);
#endif
-
+ if( ! pps_devsw_installed ) {
+ devt = makedev(CDEV_MAJOR, 0);
+ cdevsw_add(&devt, &pps_cdevsw, NULL);
+ pps_devsw_installed = 1;
+ }
return (1);
}
@@ -145,7 +144,7 @@ ppsclose(dev_t dev, int flags, int fmt, struct proc *p)
{
struct pps_data *sc = softc[minor(dev)];
- sc->ppsparam.mode = 0;
+ sc->pps.ppsparam.mode = 0; /* PHK ??? */
ppb_wdtr(&sc->pps_dev, 0);
ppb_wctr(&sc->pps_dev, 0);
@@ -158,32 +157,17 @@ static void
ppsintr(int unit)
{
struct pps_data *sc = softc[unit];
- struct timespec tc;
+ struct timecounter *tc;
+ unsigned count;
- nanotime(&tc);
+ tc = timecounter;
+ count = timecounter->tc_get_timecount(tc);
if (!(ppb_rstr(&sc->pps_dev) & nACK))
return;
- if (sc->ppsparam.mode & PPS_ECHOASSERT)
+ if (sc->pps.ppsparam.mode & PPS_ECHOASSERT)
ppb_wctr(&sc->pps_dev, IRQENABLE | AUTOFEED);
- if (sc->ppsparam.mode & PPS_OFFSETASSERT) {
- timespecadd(&tc, &sc->ppsparam.assert_offset);
- if (tc.tv_nsec < 0) {
- tc.tv_sec--;
- tc.tv_nsec += 1000000000;
- }
- }
- sc->ppsinfo.assert_timestamp = tc;
- sc->ppsinfo.assert_sequence++;
-#ifdef PPS_SYNC
- if (sc->ppsparam.mode & PPS_HARDPPSONASSERT) {
- struct timeval tv;
-
- tv.tv_sec = tc.tv_sec;
- tv.tv_usec = tc.tv_nsec / 1000;
- hardpps(&tv, tv.tv_usec);
- }
-#endif /* PPS_SYNC */
- if (sc->ppsparam.mode & PPS_ECHOASSERT)
+ pps_event(&sc->pps, tc, count, PPS_CAPTUREASSERT);
+ if (sc->pps.ppsparam.mode & PPS_ECHOASSERT)
ppb_wctr(&sc->pps_dev, IRQENABLE);
}
@@ -192,21 +176,6 @@ ppsioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
{
struct pps_data *sc = softc[minor(dev)];
- return (std_pps_ioctl(cmd, data, &sc->ppsparam, &sc->ppsinfo, ppscap));
-}
-
-static pps_devsw_installed = 0;
-
-static void
-pps_drvinit(void *unused)
-{
- dev_t dev;
-
- if( ! pps_devsw_installed ) {
- dev = makedev(CDEV_MAJOR, 0);
- cdevsw_add(&dev, &pps_cdevsw, NULL);
- pps_devsw_installed = 1;
- }
+ return (pps_ioctl(cmd, data, &sc->pps));
}
-SYSINIT(ppsdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,pps_drvinit,NULL)
OpenPOWER on IntegriCloud