diff options
author | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2015-07-15 19:21:26 +0000 |
commit | 2a25cee78ab1d37e7d2bc40ae675646974d99f56 (patch) | |
tree | b0302ac4be59e104f4e1e54014561a1389397192 /contrib/ntp/ntpd/refclock_leitch.c | |
parent | a0741a75537b2e0514472ac3b28afc55a7846c30 (diff) | |
download | FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.zip FreeBSD-src-2a25cee78ab1d37e7d2bc40ae675646974d99f56.tar.gz |
MFC r280849,280915-280916,281015-281016,282097,282408,282415,283542,
284864,285169-285170,285435:
ntp 4.2.8p3.
Relnotes: yes
Approved by: re (?)
Diffstat (limited to 'contrib/ntp/ntpd/refclock_leitch.c')
-rw-r--r-- | contrib/ntp/ntpd/refclock_leitch.c | 100 |
1 files changed, 37 insertions, 63 deletions
diff --git a/contrib/ntp/ntpd/refclock_leitch.c b/contrib/ntp/ntpd/refclock_leitch.c index e1ba0c4..69ffdc5 100644 --- a/contrib/ntp/ntpd/refclock_leitch.c +++ b/contrib/ntp/ntpd/refclock_leitch.c @@ -6,23 +6,17 @@ # include <config.h> #endif -#if defined(REFCLOCK) && defined(CLOCK_LEITCH) +#include "ntp_types.h" -#include "ntpd.h" -#include "ntp_io.h" -#include "ntp_refclock.h" -#include "ntp_unixtime.h" +#if defined(REFCLOCK) && defined(CLOCK_LEITCH) #include <stdio.h> #include <ctype.h> -#ifdef STREAM -#include <stropts.h> -#if defined(LEITCHCLK) -#include <sys/clkdefs.h> -#endif /* LEITCHCLK */ -#endif /* STREAM */ - +#include "ntpd.h" +#include "ntp_io.h" +#include "ntp_refclock.h" +#include "timevalops.h" #include "ntp_stdlib.h" @@ -43,6 +37,7 @@ * STATUS: G (good), D (diag fail), T (time not provided) or * P (last phone update failed) */ +#define PRECISION (-20) /* 1x10-8 */ #define MAXUNITS 1 /* max number of LEITCH units */ #define LEITCHREFID "ATOM" /* reference id */ #define LEITCH_DESCRIPTION "Leitch: CSD 5300 Master Clock System Driver" @@ -96,20 +91,20 @@ struct leitchunit { /* * Function prototypes */ -static void leitch_init P((void)); -static int leitch_start P((int, struct peer *)); -static void leitch_shutdown P((int, struct peer *)); -static void leitch_poll P((int, struct peer *)); -static void leitch_control P((int, struct refclockstat *, struct refclockstat *, struct peer *)); +static void leitch_init (void); +static int leitch_start (int, struct peer *); +static void leitch_shutdown (int, struct peer *); +static void leitch_poll (int, struct peer *); +static void leitch_control (int, const struct refclockstat *, struct refclockstat *, struct peer *); #define leitch_buginfo noentry -static void leitch_receive P((struct recvbuf *)); -static void leitch_process P((struct leitchunit *)); +static void leitch_receive (struct recvbuf *); +static void leitch_process (struct leitchunit *); #if 0 -static void leitch_timeout P((struct peer *)); +static void leitch_timeout (struct peer *); #endif -static int leitch_get_date P((struct recvbuf *, struct leitchunit *)); -static int leitch_get_time P((struct recvbuf *, struct leitchunit *, int)); -static int days_per_year P((int)); +static int leitch_get_date (struct recvbuf *, struct leitchunit *); +static int leitch_get_time (struct recvbuf *, struct leitchunit *, int); +static int days_per_year (int); static struct leitchunit leitchunits[MAXUNITS]; static u_char unitinuse[MAXUNITS]; @@ -149,9 +144,17 @@ leitch_shutdown( struct peer *peer ) { + struct leitchunit *leitch; + + if (unit >= MAXUNITS) { + return; + } + leitch = &leitchunits[unit]; + if (-1 != leitch->leitchio.fd) + io_closeclock(&leitch->leitchio); #ifdef DEBUG if (debug) - fprintf(stderr, "leitch_shutdown()\n"); + fprintf(stderr, "leitch_shutdown()\n"); #endif } @@ -192,7 +195,7 @@ leitch_poll( static void leitch_control( int unit, - struct refclockstat *in, + const struct refclockstat *in, struct refclockstat *out, struct peer *passed_peer ) @@ -257,7 +260,7 @@ leitch_start( /* * Open serial port. */ - (void) sprintf(leitchdev, LEITCH232, unit); + snprintf(leitchdev, sizeof(leitchdev), LEITCH232, unit); fd232 = open(leitchdev, O_RDWR, 0777); if (fd232 == -1) { msyslog(LOG_ERR, @@ -266,7 +269,7 @@ leitch_start( } leitch = &leitchunits[unit]; - memset((char*)leitch, 0, sizeof(*leitch)); + memset(leitch, 0, sizeof(*leitch)); #if defined(HAVE_SYSV_TTYS) /* @@ -294,9 +297,6 @@ leitch_start( #if defined(HAVE_TERMIOS) /* * POSIX serial line parameters (termios interface) - * - * The LEITCHCLK option provides timestamping at the driver level. - * It requires the tty_clk streams module. */ { struct termios ttyb, *ttyp; @@ -323,27 +323,12 @@ leitch_start( } } #endif /* HAVE_TERMIOS */ -#ifdef STREAM -#if defined(LEITCHCLK) - if (ioctl(fd232, I_PUSH, "clk") < 0) - msyslog(LOG_ERR, - "leitch_start: ioctl(%s, I_PUSH, clk): %m", leitchdev); - if (ioctl(fd232, CLK_SETSTR, "\n") < 0) - msyslog(LOG_ERR, - "leitch_start: ioctl(%s, CLK_SETSTR): %m", leitchdev); -#endif /* LEITCHCLK */ -#endif /* STREAM */ #if defined(HAVE_BSD_TTYS) /* * 4.3bsd serial line parameters (sgttyb interface) - * - * The LEITCHCLK option provides timestamping at the driver level. - * It requires the tty_clk line discipline and 4.3bsd or later. */ - { struct sgttyb ttyb; -#if defined(LEITCHCLK) - int ldisc = CLKLDISC; -#endif /* LEITCHCLK */ + { + struct sgttyb ttyb; if (ioctl(fd232, TIOCGETP, &ttyb) < 0) { msyslog(LOG_ERR, @@ -351,25 +336,13 @@ leitch_start( goto screwed; } ttyb.sg_ispeed = ttyb.sg_ospeed = SPEED232; -#if defined(LEITCHCLK) - ttyb.sg_erase = ttyb.sg_kill = '\r'; - ttyb.sg_flags = RAW; -#else ttyb.sg_erase = ttyb.sg_kill = '\0'; ttyb.sg_flags = EVENP|ODDP|CRMOD; -#endif /* LEITCHCLK */ if (ioctl(fd232, TIOCSETP, &ttyb) < 0) { msyslog(LOG_ERR, "leitch_start: ioctl(%s, TIOCSETP): %m", leitchdev); goto screwed; } -#if defined(LEITCHCLK) - if (ioctl(fd232, TIOCSETD, &ldisc) < 0) { - msyslog(LOG_ERR, - "leitch_start: ioctl(%s, TIOCSETD): %m",leitchdev); - goto screwed; - } -#endif /* LEITCHCLK */ } #endif /* HAVE_BSD_TTYS */ @@ -382,10 +355,11 @@ leitch_start( leitch->fudge1 = 15; /* 15ms */ leitch->leitchio.clock_recv = leitch_receive; - leitch->leitchio.srcclock = (caddr_t) leitch; + leitch->leitchio.srcclock = peer; leitch->leitchio.datalen = 0; leitch->leitchio.fd = fd232; if (!io_addclock(&leitch->leitchio)) { + leitch->leitchio.fd = -1; goto screwed; } @@ -393,7 +367,7 @@ leitch_start( * All done. Initialize a few random peer variables, then * return success. */ - peer->precision = 0; + peer->precision = PRECISION; peer->stratum = stratumtouse[unit]; peer->refid = refid[unit]; unitinuse[unit] = 1; @@ -416,7 +390,7 @@ leitch_receive( struct recvbuf *rbufp ) { - struct leitchunit *leitch = (struct leitchunit *)rbufp->recv_srcclock; + struct leitchunit *leitch = rbufp->recv_peer->procptr->unitptr; #ifdef DEBUG if (debug) @@ -622,5 +596,5 @@ leitch_get_time( } #else -int refclock_leitch_bs; +NONEMPTY_TRANSLATION_UNIT #endif /* REFCLOCK */ |