4 * - clock driver for hopf 6039 PCI board (GPS or DCF77)
5 * Bernd Altmeier altmeier@atlsoft.de
7 * latest source and further information can be found at:
8 * http://www.ATLSoft.de/ntp
10 * In order to run this driver you have to install and test
11 * the PCI-board driver for your system first.
15 * The driver attempts to open the device /dev/hopf6039 .
16 * The device entry will be made by the installation process of
17 * the kernel module for the PCI-bus board. The driver sources
18 * belongs to the delivery equipment of the PCI-board.
22 * The driver attempts to open the device by calling the function
23 * "OpenHopfDevice()". This function will be installed by the
24 * Device Driver for the PCI-bus board. The driver belongs to the
25 * delivery equipment of the PCI-board.
28 * Start 21.03.2000 Revision: 01.20
29 * changes 22.12.2000 Revision: 01.40 flag1 = 1 sync even if Quarz
37 #if defined(REFCLOCK) && defined(CLOCK_HOPF_PCI)
41 #include "ntp_refclock.h"
42 #include "ntp_unixtime.h"
43 #include "ntp_stdlib.h"
51 # include <sys/ioctl.h>
55 # include "hopf6039.h"
57 # include "hopf_PCI_io.h"
61 * hopfpci interface definitions
63 #define PRECISION (-10) /* precision assumed (1 ms) */
64 #define REFID "hopf" /* reference ID */
65 #define DESCRIPTION "hopf Elektronik PCI radio board"
67 #define NSAMPLES 3 /* stages of median filter */
69 # define DEVICE "/dev/hopf6039" /* device name inode*/
71 # define DEVICE "hopf6039" /* device name WinNT */
74 #define LEWAPWAR 0x20 /* leap second warning bit */
76 #define HOPF_OPMODE 0xC0 /* operation mode mask */
77 #define HOPF_INVALID 0x00 /* no time code available */
78 #define HOPF_INTERNAL 0x40 /* internal clock */
79 #define HOPF_RADIO 0x80 /* radio clock */
80 #define HOPF_RADIOHP 0xC0 /* high precision radio clock */
84 * hopfclock unit control structure.
86 struct hopfclock_unit {
87 short unit; /* NTP refclock unit number */
88 char leap_status; /* leap second flag */
90 int fd; /* file descr. */
95 static int hopfpci_start (int, struct peer *);
96 static void hopfpci_shutdown (int, struct peer *);
97 static void hopfpci_poll (int unit, struct peer *);
102 struct refclock refclock_hopfpci = {
103 hopfpci_start, /* start up driver */
104 hopfpci_shutdown, /* shut down driver */
105 hopfpci_poll, /* transmit poll message */
106 noentry, /* not used */
107 noentry, /* initialize driver (not used) */
108 noentry, /* not used */
109 NOFLAGS /* not used */
113 * hopfpci_start - attach to hopf PCI board 6039
121 struct refclockproc *pp;
122 struct hopfclock_unit *up;
125 * Allocate and initialize unit structure
127 up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit));
130 msyslog(LOG_ERR, "hopfPCIClock(%d) emalloc: %m",unit);
132 printf("hopfPCIClock(%d) emalloc\n",unit);
136 memset((char *)up, 0, sizeof(struct hopfclock_unit));
140 fd = open(DEVICE,O_RDWR); /* try to open hopf clock device */
143 if (!OpenHopfDevice()){
144 msyslog(LOG_ERR,"Start: %s unit: %d failed!",DEVICE,unit);
150 pp->io.clock_recv = noentry;
151 pp->io.srcclock = (caddr_t)peer;
153 pp->io.fd = INVALID_SOCKET;
154 pp->unitptr = (caddr_t)up;
156 get_systime(&pp->lastrec);
159 * Initialize miscellaneous peer variables
161 if (pp->unitptr!=0) {
162 memcpy((char *)&pp->refid, REFID, 4);
163 peer->precision = PRECISION;
164 pp->clockdesc = DESCRIPTION;
166 up->unit = (short) unit;
176 * hopfpci_shutdown - shut down the clock
194 * hopfpci_poll - called by the transmit procedure
202 struct refclockproc *pp;
208 ioctl(fd,HOPF_CLOCK_GET_UTC,&m_time);
210 GetHopfSystemTime(&m_time);
214 pp->day = ymd2yd(m_time.wYear,m_time.wMonth,m_time.wDay);
215 pp->hour = m_time.wHour;
216 pp->minute = m_time.wMinute;
217 pp->second = m_time.wSecond;
218 pp->nsec = m_time.wMilliseconds * 1000000;
219 if (m_time.wStatus & LEWAPWAR)
220 pp->leap = LEAP_ADDSECOND;
222 pp->leap = LEAP_NOWARNING;
224 sprintf(pp->a_lastcode,"ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
225 m_time.wStatus, pp->hour, pp->minute, pp->second,
226 pp->nsec / 1000000, m_time.wDay, m_time.wMonth, m_time.wYear);
227 pp->lencode = (u_short)strlen(pp->a_lastcode);
229 get_systime(&pp->lastrec);
232 * If clock has no valid status then report error and exit
234 if ((m_time.wStatus & HOPF_OPMODE) == HOPF_INVALID) { /* time ok? */
235 refclock_report(peer, CEVNT_BADTIME);
236 pp->leap = LEAP_NOTINSYNC;
241 * Test if time is running on internal quarz
242 * if CLK_FLAG1 is set, sychronize even if no radio operation
245 if ((m_time.wStatus & HOPF_OPMODE) == HOPF_INTERNAL){
246 if ((pp->sloppyclockflag & CLK_FLAG1) == 0) {
247 refclock_report(peer, CEVNT_BADTIME);
248 pp->leap = LEAP_NOTINSYNC;
253 if (!refclock_process(pp)) {
254 refclock_report(peer, CEVNT_BADTIME);
257 pp->lastref = pp->lastrec;
258 refclock_receive(peer);
259 record_clock_stats(&peer->srcadr, pp->a_lastcode);
264 int refclock_hopfpci_bs;
265 #endif /* REFCLOCK */