Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/simonb-timecounters]: src/sys/dev/ic Adapt for timecounters and newer PP...



details:   https://anonhg.NetBSD.org/src/rev/db9e3a6ab149
branches:  simonb-timecounters
changeset: 587798:db9e3a6ab149
user:      simonb <simonb%NetBSD.org@localhost>
date:      Sat Feb 04 14:00:40 2006 +0000

description:
Adapt for timecounters and newer PPS API.

diffstat:

 sys/dev/ic/com.c      |  49 ++++++++++++++++++++++++++++++++++++++++-
 sys/dev/ic/comvar.h   |   6 ++++-
 sys/dev/ic/z8530tty.c |  59 ++++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 104 insertions(+), 10 deletions(-)

diffs (300 lines):

diff -r 88dcdc26cd9b -r db9e3a6ab149 sys/dev/ic/com.c
--- a/sys/dev/ic/com.c  Sat Feb 04 13:55:05 2006 +0000
+++ b/sys/dev/ic/com.c  Sat Feb 04 14:00:40 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: com.c,v 1.240 2006/01/08 22:19:59 dsl Exp $    */
+/*     $NetBSD: com.c,v 1.240.4.1 2006/02/04 14:00:40 simonb Exp $     */
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.240 2006/01/08 22:19:59 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.240.4.1 2006/02/04 14:00:40 simonb Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -218,11 +218,13 @@
 static tcflag_t comconscflag;
 static struct cnm_state com_cnm_state;
 
+#ifndef __HAVE_TIMECOUNTER
 static int ppscap =
        PPS_TSFMT_TSPEC |
        PPS_CAPTUREASSERT |
        PPS_CAPTURECLEAR |
        PPS_OFFSETASSERT | PPS_OFFSETCLEAR;
+#endif /* !__HAVE_TIMECOUNTER */
 
 #ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
 #ifdef __NO_SOFT_SERIAL_INTERRUPT
@@ -751,9 +753,11 @@
        /* Clear any break condition set with TIOCSBRK. */
        com_break(sc, 0);
 
+#ifndef __HAVE_TIMECOUNTER
        /* Turn off PPS capture on last close. */
        sc->sc_ppsmask = 0;
        sc->ppsparam.mode = 0;
+#endif /* !__HAVE_TIMECOUNTER */
 
        /*
         * Hang up if necessary.  Wait a bit, so the other side has time to
@@ -868,8 +872,14 @@
                sc->sc_msr = bus_space_read_1(sc->sc_iot, sc->sc_ioh, com_msr);
 
                /* Clear PPS capture state on first open. */
+#ifdef __HAVE_TIMECOUNTER
+               memset(&sc->sc_pps_state, 0, sizeof(sc->sc_pps_state));
+               sc->sc_pps_state.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
+               pps_init(&sc->sc_pps_state);
+#else /* !__HAVE_TIMECOUNTER */
                sc->sc_ppsmask = 0;
                sc->ppsparam.mode = 0;
+#endif /* !__HAVE_TIMECOUNTER */
 
                COM_UNLOCK(sc);
                splx(s2);
@@ -1089,6 +1099,19 @@
                *(int *)data = com_to_tiocm(sc);
                break;
 
+#ifdef __HAVE_TIMECOUNTER
+       case PPS_IOC_CREATE:
+       case PPS_IOC_DESTROY:
+       case PPS_IOC_GETPARAMS:
+       case PPS_IOC_SETPARAMS:
+       case PPS_IOC_GETCAP:
+       case PPS_IOC_FETCH:
+#ifdef PPS_SYNC
+       case PPS_IOC_KCBIND:
+#endif
+               error = pps_ioctl(cmd, data, &sc->sc_pps_state);
+               break;
+#else /* !__HAVE_TIMECOUNTER */
        case PPS_IOC_CREATE:
                break;
 
@@ -1181,8 +1204,18 @@
                break;
        }
 #endif /* PPS_SYNC */
+#endif /* !__HAVE_TIMECOUNTER */
 
        case TIOCDCDTIMESTAMP:  /* XXX old, overloaded  API used by xntpd v3 */
+#ifdef __HAVE_TIMECOUNTER
+#ifndef PPS_TRAILING_EDGE
+               TIMESPEC_TO_TIMEVAL((struct timeval *)data,
+                   &sc->sc_pps_state.ppsinfo.assert_timestamp);
+#else
+               TIMESPEC_TO_TIMEVAL((struct timeval *)data,
+                   &sc->sc_pps_state.ppsinfo.clear_timestamp);
+#endif
+#else /* !__HAVE_TIMECOUNTER */
                /*
                 * Some GPS clocks models use the falling rather than
                 * rising edge as the on-the-second signal.
@@ -1200,6 +1233,7 @@
                TIMESPEC_TO_TIMEVAL((struct timeval *)data,
                    &sc->ppsinfo.clear_timestamp);
 #endif
+#endif /* !__HAVE_TIMECOUNTER */
                break;
 
        default:
@@ -2141,6 +2175,16 @@
                msr = bus_space_read_1(iot, ioh, com_msr);
                delta = msr ^ sc->sc_msr;
                sc->sc_msr = msr;
+#ifdef __HAVE_TIMECOUNTER
+               if ((sc->sc_pps_state.ppsparam.mode & PPS_CAPTUREBOTH) &&
+                   (delta & MSR_DCD)) {
+                       pps_capture(&sc->sc_pps_state);
+                       pps_event(&sc->sc_pps_state,
+                           (msr & MSR_DCD) ?
+                           PPS_CAPTUREASSERT :
+                           PPS_CAPTURECLEAR);
+               }
+#else /* !__HAVE_TIMECOUNTER */
                /*
                 * Pulse-per-second (PSS) signals on edge of DCD?
                 * Process these even if line discipline is ignoring DCD.
@@ -2188,6 +2232,7 @@
                                sc->ppsinfo.current_mode = sc->ppsparam.mode;
                        }
                }
+#endif /* !__HAVE_TIMECOUNTER */
 
                /*
                 * Process normal status changes
diff -r 88dcdc26cd9b -r db9e3a6ab149 sys/dev/ic/comvar.h
--- a/sys/dev/ic/comvar.h       Sat Feb 04 13:55:05 2006 +0000
+++ b/sys/dev/ic/comvar.h       Sat Feb 04 14:00:40 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: comvar.h,v 1.50 2005/12/27 00:46:38 chs Exp $  */
+/*     $NetBSD: comvar.h,v 1.50.6.1 2006/02/04 14:00:40 simonb Exp $   */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -137,12 +137,16 @@
        void (*disable)(struct com_softc *);
        int enabled;
 
+#ifdef __HAVE_TIMECOUNTER
+       struct pps_state sc_pps_state;  /* pps state */
+#else /* !__HAVE_TIMECOUNTER */
        /* PPS signal on DCD, with or without inkernel clock disciplining */
        u_char  sc_ppsmask;                     /* pps signal mask */
        u_char  sc_ppsassert;                   /* pps leading edge */
        u_char  sc_ppsclear;                    /* pps trailing edge */
        pps_info_t ppsinfo;
        pps_params_t ppsparam;
+#endif /* !__HAVE_TIMECOUNTER */
 
 #if NRND > 0 && defined(RND_COM)
        rndsource_element_t  rnd_source;
diff -r 88dcdc26cd9b -r db9e3a6ab149 sys/dev/ic/z8530tty.c
--- a/sys/dev/ic/z8530tty.c     Sat Feb 04 13:55:05 2006 +0000
+++ b/sys/dev/ic/z8530tty.c     Sat Feb 04 14:00:40 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: z8530tty.c,v 1.102 2005/12/27 17:20:54 chs Exp $       */
+/*     $NetBSD: z8530tty.c,v 1.102.6.1 2006/02/04 14:00:40 simonb Exp $        */
 
 /*-
  * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999
@@ -137,7 +137,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.102 2005/12/27 17:20:54 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.102.6.1 2006/02/04 14:00:40 simonb Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_ntp.h"
@@ -236,10 +236,14 @@
 
        /* PPS signal on DCD, with or without inkernel clock disciplining */
        u_char  zst_ppsmask;                    /* pps signal mask */
+#ifdef __HAVE_TIMECOUNTER
+       struct pps_state zst_pps_state;
+#else /* !__HAVE_TIMECOUNTER */
        u_char  zst_ppsassert;                  /* pps leading edge */
        u_char  zst_ppsclear;                   /* pps trailing edge */
        pps_info_t ppsinfo;
        pps_params_t ppsparam;
+#endif /* !__HAVE_TIMECOUNTER */
 };
 
 /* Macros to clear/set/test flags. */
@@ -506,9 +510,11 @@
        /* Clear any break condition set with TIOCSBRK. */
        zs_break(cs, 0);
 
+#ifndef __HAVE_TIMECOUNTER
        /* Turn off PPS capture on last close. */
        zst->zst_ppsmask = 0;
        zst->ppsparam.mode = 0;
+#endif /* __HAVE_TIMECOUNTER */
 
        /*
         * Hang up if necessary.  Wait a bit, so the other side has time to
@@ -634,7 +640,13 @@
 
                /* Clear PPS capture state on first open. */
                zst->zst_ppsmask = 0;
+#ifdef __HAVE_TIMECOUNTER
+               memset(&sc->sc_pps_state, 0, sizeof(sc->sc_pps_state));
+               sc->sc_pps_state.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
+               pps_init(&zst->zst_pps_state);
+#else /* !__HAVE_TIMECOUNTER */
                zst->ppsparam.mode = 0;
+#endif /* !__HAVE_TIMECOUNTER */
 
                simple_unlock(&cs->cs_lock);
                splx(s2);
@@ -850,6 +862,23 @@
                *(int *)data = zs_to_tiocm(zst);
                break;
 
+#ifdef __HAVE_TIMECOUNTER
+       case PPS_IOC_CREATE:
+       case PPS_IOC_DESTROY:
+       case PPS_IOC_GETPARAMS:
+       case PPS_IOC_SETPARAMS:
+       case PPS_IOC_GETCAP:
+       case PPS_IOC_FETCH:
+#ifdef PPS_SYNC
+       case PPS_IOC_KCBIND:
+#endif
+               error = pps_ioctl(cmd, data, &zst->zst_pps_state);
+               if (zst->zst_pps_state.ppsparm.mode & PPS_CAPTUREBOTH)
+                       zst->zst_ppsmask = ZSRR0_DCD;
+               else
+                       zst->zst_ppsmask = 0;
+               break;
+#else /* !__HAVE_TIMECOUNTER */
        case PPS_IOC_CREATE:
                break;
 
@@ -964,17 +993,22 @@
                break;
        }
 #endif /* PPS_SYNC */
+#endif /* !__HAVE_TIMECOUNTER */
 
        case TIOCDCDTIMESTAMP:  /* XXX old, overloaded  API used by xntpd v3 */
                if (cs->cs_rr0_pps == 0) {
                        error = EINVAL;
                        break;
                }
-               /*
-                * Some GPS clocks models use the falling rather than
-                * rising edge as the on-the-second signal.
-                * The old API has no way to specify PPS polarity.
-                */
+#ifdef __HAVE_TIMECOUNTER
+#ifndef PPS_TRAILING_EDGE
+               TIMESPEC_TO_TIMEVAL((struct timeval *)data,
+                   &sc->sc_pps_state.ppsinfo.assert_timestamp);
+#else
+               TIMESPEC_TO_TIMEVAL((struct timeval *)data,
+                   &sc->sc_pps_state.ppsinfo.clear_timestamp);
+#endif
+#else /* !__HAVE_TIMECOUNTER */
                zst->zst_ppsmask = ZSRR0_DCD;
 #ifndef        PPS_TRAILING_EDGE
                zst->zst_ppsassert = ZSRR0_DCD;
@@ -987,6 +1021,7 @@
                TIMESPEC_TO_TIMEVAL((struct timeval *)data,
                        &zst->ppsinfo.clear_timestamp);
 #endif
+#endif /* !__HAVE_TIMECOUNTER */
                /*
                 * Now update interrupts.
                 */
@@ -1656,6 +1691,15 @@
                 * Pulse-per-second clock signal on edge of DCD?
                 */
                if (ISSET(delta, zst->zst_ppsmask)) {
+#ifdef __HAVE_TIMECOUNTER
+                       if (zst->sc_pps_state.ppsparam.mode & PPS_CAPTUREBOTH) {
+                               pps_capture(&zst->sc_pps_state);
+                               pps_event(&zst->sc_pps_state,
+                                   (ISSET(cs->cs_rr0, zst->zst_ppsmask))
+                                   ? PPS_CAPTUREASSERT
+                                   : PPS_CAPTURECLEAR);
+                       }
+#else /* !__HAVE_TIMECOUNTER */
                        struct timeval tv;
                        if (ISSET(rr0, zst->zst_ppsmask) == zst->zst_ppsassert) {
                                /* XXX nanotime() */
@@ -1697,6 +1741,7 @@
                                zst->ppsinfo.clear_sequence++;
                                zst->ppsinfo.current_mode = zst->ppsparam.mode;
                        }
+#endif /* !__HAVE_TIMECOUNTER */
                }
 
                /*



Home | Main Index | Thread Index | Old Index