1999-12-09 13:01:21 +00:00
|
|
|
/* refclock_bancomm.c - clock driver for the Datum/Bancomm bc635VME
|
|
|
|
* Time and Frequency Processor. It requires the BANCOMM bc635VME/
|
|
|
|
* bc350VXI Time and Frequency Processor Module Driver for SunOS4.x
|
|
|
|
* and SunOS5.x UNIX Systems. It has been tested on a UltraSparc
|
|
|
|
* IIi-cEngine running Solaris 2.6.
|
|
|
|
*
|
|
|
|
* Author(s): Ganesh Ramasivan & Gary Cliff, Computing Devices Canada,
|
|
|
|
* Ottawa, Canada
|
|
|
|
*
|
|
|
|
* Date: July 1999
|
|
|
|
*
|
|
|
|
* Note(s): The refclock type has been defined as 16.
|
|
|
|
*
|
|
|
|
* This program has been modelled after the Bancomm driver
|
|
|
|
* originally written by R. Schmidt of Time Service, U.S.
|
|
|
|
* Naval Observatory for a HP-UX machine. Since the original
|
|
|
|
* authors no longer plan to maintain this code, all
|
|
|
|
* references to the HP-UX vme2 driver subsystem bave been
|
|
|
|
* removed. Functions vme_report_event(), vme_receive(),
|
|
|
|
* vme_control() and vme_buginfo() have been deleted because
|
|
|
|
* they are no longer being used.
|
|
|
|
*
|
2008-08-18 14:26:05 +00:00
|
|
|
* 04/28/2005 Rob Neal
|
|
|
|
* Modified to add support for Symmetricom bc637PCI-U Time &
|
|
|
|
* Frequency Processor.
|
2013-12-04 21:33:17 +00:00
|
|
|
* 2/21/2007 Ali Ghorashi
|
|
|
|
* Modified to add support for Symmetricom bc637PCI-U Time &
|
|
|
|
* Frequency Processor on Solaris.
|
|
|
|
* Tested on Solaris 10 with a bc635 card.
|
|
|
|
*
|
2008-08-18 14:26:05 +00:00
|
|
|
* Card bus type (VME/VXI or PCI) and environment are specified via the
|
|
|
|
* "mode" keyword on the server command in ntp.conf.
|
2013-12-04 21:33:17 +00:00
|
|
|
* server 127.127.16.u prefer mode M
|
|
|
|
* where u is the id (usually 0) of the entry in /dev (/dev/stfp0)
|
|
|
|
*
|
|
|
|
* and M is one of the following modes:
|
2008-08-18 14:26:05 +00:00
|
|
|
* 1 : FreeBSD PCI 635/637.
|
|
|
|
* 2 : Linux or Windows PCI 635/637.
|
2013-12-04 21:33:17 +00:00
|
|
|
* 3 : Solaris PCI 635/637
|
2008-08-18 14:26:05 +00:00
|
|
|
* not specified, or other number:
|
|
|
|
* : Assumed to be VME/VXI legacy Bancomm card on Solaris.
|
|
|
|
* Linux and Windows platforms require Symmetricoms' proprietary driver
|
2013-12-04 21:33:17 +00:00
|
|
|
* for the TFP card.
|
|
|
|
* Solaris requires Symmetricom's driver and its header file (freely distributed) to
|
|
|
|
* be installed and running.
|
1999-12-09 13:01:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(REFCLOCK) && defined(CLOCK_BANC)
|
|
|
|
|
|
|
|
#include "ntpd.h"
|
|
|
|
#include "ntp_io.h"
|
|
|
|
#include "ntp_refclock.h"
|
|
|
|
#include "ntp_unixtime.h"
|
|
|
|
#include "ntp_stdlib.h"
|
|
|
|
|
2001-08-29 14:35:15 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
1999-12-09 13:01:21 +00:00
|
|
|
struct btfp_time /* Structure for reading 5 time words */
|
|
|
|
/* in one ioctl(2) operation. */
|
|
|
|
{
|
|
|
|
unsigned short btfp_time[5]; /* Time words 0,1,2,3, and 4. (16bit)*/
|
|
|
|
};
|
|
|
|
/* SunOS5 ioctl commands definitions.*/
|
|
|
|
#define BTFPIOC ( 'b'<< 8 )
|
|
|
|
#define IOCIO( l, n ) ( BTFPIOC | n )
|
|
|
|
#define IOCIOR( l, n, s ) ( BTFPIOC | n )
|
|
|
|
#define IOCIORN( l, n, s ) ( BTFPIOC | n )
|
|
|
|
#define IOCIOWN( l, n, s ) ( BTFPIOC | n )
|
|
|
|
|
|
|
|
/***** Simple ioctl commands *****/
|
|
|
|
#define RUNLOCK IOCIOR(b, 19, int ) /* Release Capture Lockout */
|
|
|
|
#define RCR0 IOCIOR(b, 22, int ) /* Read control register zero.*/
|
|
|
|
#define WCR0 IOCIOWN(b, 23, int) /* Write control register zero*/
|
|
|
|
/***** Compound ioctl commands *****/
|
|
|
|
|
|
|
|
/* Read all 5 time words in one call. */
|
|
|
|
#define READTIME IOCIORN(b, 32, sizeof( struct btfp_time ))
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#undef READTIME
|
|
|
|
#define READTIME _IOR('u', 5, struct btfp_time )
|
|
|
|
#endif
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
/* Solaris specific section */
|
|
|
|
struct stfp_tm {
|
|
|
|
int32_t tm_sec;
|
|
|
|
int32_t tm_min;
|
|
|
|
int32_t tm_hour;
|
|
|
|
int32_t tm_mday;
|
|
|
|
int32_t tm_mon;
|
|
|
|
int32_t tm_year;
|
|
|
|
int32_t tm_wday;
|
|
|
|
int32_t tm_yday;
|
|
|
|
int32_t tm_isdst;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct stfp_time {
|
|
|
|
struct stfp_tm tm;
|
|
|
|
int32_t usec; /* usec 0 - 999999 */
|
|
|
|
int32_t hnsec; /* hnsec 0 - 9 (hundreds of nsecs) */
|
|
|
|
int32_t status;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SELTIMEFORMAT 2
|
|
|
|
# define TIME_DECIMAL 0
|
|
|
|
# define TIME_BINARY 1
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
#if defined(__sun__)
|
|
|
|
#undef READTIME
|
|
|
|
#define READTIME 9
|
|
|
|
#endif /** __sun___ **/
|
|
|
|
/* end solaris specific section */
|
|
|
|
|
|
|
|
struct vmedate { /* structure returned by get_vmetime.c */
|
1999-12-09 13:01:21 +00:00
|
|
|
unsigned short year;
|
|
|
|
unsigned short day;
|
|
|
|
unsigned short hr;
|
|
|
|
unsigned short mn;
|
|
|
|
unsigned short sec;
|
2008-08-18 14:26:05 +00:00
|
|
|
long frac;
|
1999-12-09 13:01:21 +00:00
|
|
|
unsigned short status;
|
|
|
|
};
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
typedef void *SYMMT_PCI_HANDLE;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VME interface parameters.
|
|
|
|
*/
|
|
|
|
#define VMEPRECISION (-21) /* precision assumed (1 us) */
|
|
|
|
#define USNOREFID "BTFP" /* or whatever */
|
|
|
|
#define VMEREFID "BTFP" /* reference id */
|
|
|
|
#define VMEDESCRIPTION "Bancomm bc635 TFP" /* who we are */
|
|
|
|
#define VMEHSREFID 0x7f7f1000 /* 127.127.16.00 refid hi strata */
|
|
|
|
/* clock type 16 is used here */
|
|
|
|
#define GMT 0 /* hour offset from Greenwich */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Imported from ntp_timer module
|
|
|
|
*/
|
|
|
|
extern u_long current_time; /* current time(s) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VME unit control structure.
|
|
|
|
* Changes made to vmeunit structure. Most members are now available in the
|
|
|
|
* new refclockproc structure in ntp_refclock.h - 07/99 - Ganesh Ramasivan
|
|
|
|
*/
|
|
|
|
struct vmeunit {
|
|
|
|
struct vmedate vmedata; /* data returned from vme read */
|
|
|
|
u_long lasttime; /* last time clock heard from */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function prototypes
|
|
|
|
*/
|
|
|
|
static int vme_start (int, struct peer *);
|
|
|
|
static void vme_shutdown (int, struct peer *);
|
|
|
|
static void vme_receive (struct recvbuf *);
|
|
|
|
static void vme_poll (int unit, struct peer *);
|
2008-08-18 14:26:05 +00:00
|
|
|
struct vmedate *get_datumtime(struct vmedate *);
|
2013-12-04 21:33:17 +00:00
|
|
|
void tvme_fill(struct vmedate *, uint32_t btm[2]);
|
|
|
|
void stfp_time2tvme(struct vmedate *time_vme, struct stfp_time *stfp);
|
|
|
|
inline const char *DEVICE_NAME(int n);
|
|
|
|
|
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/*
|
|
|
|
* Define the bc*() functions as weak so we can compile/link without them.
|
|
|
|
* Only clients with the card will have the proprietary vendor device driver
|
|
|
|
* and interface library needed for use on Linux/Windows platforms.
|
|
|
|
*/
|
|
|
|
extern uint32_t __attribute__ ((weak)) bcReadBinTime(SYMMT_PCI_HANDLE, uint32_t *, uint32_t*, uint8_t*);
|
|
|
|
extern SYMMT_PCI_HANDLE __attribute__ ((weak)) bcStartPci(void);
|
|
|
|
extern void __attribute__ ((weak)) bcStopPci(SYMMT_PCI_HANDLE);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer vector
|
|
|
|
*/
|
|
|
|
struct refclock refclock_bancomm = {
|
2001-08-29 14:35:15 +00:00
|
|
|
vme_start, /* start up driver */
|
|
|
|
vme_shutdown, /* shut down driver */
|
|
|
|
vme_poll, /* transmit poll message */
|
|
|
|
noentry, /* not used (old vme_control) */
|
|
|
|
noentry, /* initialize driver */
|
|
|
|
noentry, /* not used (old vme_buginfo) */
|
|
|
|
NOFLAGS /* not used */
|
1999-12-09 13:01:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int fd_vme; /* file descriptor for ioctls */
|
|
|
|
int regvalue;
|
2008-08-18 14:26:05 +00:00
|
|
|
int tfp_type; /* mode selector, indicate platform and driver interface */
|
|
|
|
SYMMT_PCI_HANDLE stfp_handle;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
/**
|
|
|
|
* this macro returns the device name based on
|
|
|
|
* the platform we are running on and the device number
|
|
|
|
*/
|
|
|
|
#if defined(__sun__)
|
|
|
|
inline const char *DEVICE_NAME(int n) {static char s[20]={0}; snprintf(s,19,"/dev/stfp%d",n);return s;}
|
|
|
|
#else
|
|
|
|
inline const char* DEVICE_NAME(int n) {static char s[20]={0}; snprintf(s,19,"/dev/btfp%d",n);return s;}
|
|
|
|
#endif /**__sun__**/
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* vme_start - open the VME device and initialize data for processing
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
vme_start(
|
|
|
|
int unit,
|
|
|
|
struct peer *peer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
register struct vmeunit *vme;
|
|
|
|
struct refclockproc *pp;
|
|
|
|
int dummy;
|
|
|
|
char vmedev[20];
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
tfp_type = (int)(peer->ttl);
|
|
|
|
switch (tfp_type) {
|
|
|
|
case 1:
|
2013-12-04 21:33:17 +00:00
|
|
|
case 3:
|
2008-08-18 14:26:05 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
stfp_handle = bcStartPci(); /* init the card in lin/win */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* Open VME device
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
printf("Opening DATUM DEVICE %s\n",DEVICE_NAME(peer->refclkunit));
|
1999-12-09 13:01:21 +00:00
|
|
|
#endif
|
2013-12-04 21:33:17 +00:00
|
|
|
if ( (fd_vme = open(DEVICE_NAME(peer->refclkunit), O_RDWR)) < 0) {
|
1999-12-09 13:01:21 +00:00
|
|
|
msyslog(LOG_ERR, "vme_start: failed open of %s: %m", vmedev);
|
|
|
|
return (0);
|
|
|
|
}
|
2008-08-18 14:26:05 +00:00
|
|
|
else {
|
|
|
|
switch (tfp_type) {
|
|
|
|
case 1: break;
|
|
|
|
case 2: break;
|
2013-12-04 21:33:17 +00:00
|
|
|
case 3:break;
|
2008-08-18 14:26:05 +00:00
|
|
|
default:
|
|
|
|
/* Release capture lockout in case it was set before. */
|
|
|
|
if( ioctl( fd_vme, RUNLOCK, &dummy ) )
|
|
|
|
msyslog(LOG_ERR, "vme_start: RUNLOCK failed %m");
|
|
|
|
|
|
|
|
regvalue = 0; /* More esoteric stuff to do... */
|
|
|
|
if( ioctl( fd_vme, WCR0, ®value ) )
|
|
|
|
msyslog(LOG_ERR, "vme_start: WCR0 failed %m");
|
|
|
|
break;
|
|
|
|
}
|
1999-12-09 13:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate unit structure
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
vme = emalloc_zero(sizeof(struct vmeunit));
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the structures
|
|
|
|
*/
|
|
|
|
pp = peer->procptr;
|
2014-12-20 22:52:39 +00:00
|
|
|
pp->unitptr = vme;
|
1999-12-09 13:01:21 +00:00
|
|
|
pp->timestarted = current_time;
|
|
|
|
|
|
|
|
pp->io.clock_recv = vme_receive;
|
2014-12-20 22:52:39 +00:00
|
|
|
pp->io.srcclock = peer;
|
1999-12-09 13:01:21 +00:00
|
|
|
pp->io.datalen = 0;
|
|
|
|
pp->io.fd = fd_vme;
|
2014-12-20 22:52:39 +00:00
|
|
|
/* shouldn't there be an io_addclock() call? */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All done. Initialize a few random peer variables, then
|
|
|
|
* return success. Note that root delay and root dispersion are
|
|
|
|
* always zero for this clock.
|
|
|
|
*/
|
|
|
|
peer->precision = VMEPRECISION;
|
2001-08-29 14:35:15 +00:00
|
|
|
memcpy(&pp->refid, USNOREFID,4);
|
1999-12-09 13:01:21 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vme_shutdown - shut down a VME clock
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vme_shutdown(
|
|
|
|
int unit,
|
|
|
|
struct peer *peer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
register struct vmeunit *vme;
|
|
|
|
struct refclockproc *pp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the I/O module to turn us off. We're history.
|
|
|
|
*/
|
2001-08-29 14:35:15 +00:00
|
|
|
pp = peer->procptr;
|
2014-12-20 22:52:39 +00:00
|
|
|
vme = pp->unitptr;
|
1999-12-09 13:01:21 +00:00
|
|
|
io_closeclock(&pp->io);
|
|
|
|
pp->unitptr = NULL;
|
2013-12-04 21:33:17 +00:00
|
|
|
if (NULL != vme)
|
|
|
|
free(vme);
|
|
|
|
if (tfp_type == 2)
|
|
|
|
bcStopPci(stfp_handle);
|
1999-12-09 13:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vme_receive - receive data from the VME device.
|
|
|
|
*
|
|
|
|
* Note: This interface would be interrupt-driven. We don't use that
|
|
|
|
* now, but include a dummy routine for possible future adventures.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vme_receive(
|
|
|
|
struct recvbuf *rbufp
|
|
|
|
)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vme_poll - called by the transmit procedure
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
vme_poll(
|
|
|
|
int unit,
|
|
|
|
struct peer *peer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct vmedate *tptr;
|
|
|
|
struct vmeunit *vme;
|
|
|
|
struct refclockproc *pp;
|
|
|
|
time_t tloc;
|
|
|
|
struct tm *tadr;
|
|
|
|
|
|
|
|
pp = peer->procptr;
|
2014-12-20 22:52:39 +00:00
|
|
|
vme = pp->unitptr; /* Here is the structure */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
tptr = &vme->vmedata;
|
|
|
|
if ((tptr = get_datumtime(tptr)) == NULL ) {
|
|
|
|
refclock_report(peer, CEVNT_BADREPLY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_systime(&pp->lastrec);
|
|
|
|
pp->polls++;
|
|
|
|
vme->lasttime = current_time;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get VME time and convert to timestamp format.
|
|
|
|
* The year must come from the system clock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
time(&tloc);
|
|
|
|
tadr = gmtime(&tloc);
|
|
|
|
tptr->year = (unsigned short)(tadr->tm_year + 1900);
|
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(pp->a_lastcode,
|
|
|
|
sizeof(pp->a_lastcode),
|
|
|
|
"%3.3d %2.2d:%2.2d:%2.2d.%.6ld %1d",
|
|
|
|
tptr->day,
|
|
|
|
tptr->hr,
|
|
|
|
tptr->mn,
|
|
|
|
tptr->sec,
|
|
|
|
tptr->frac,
|
|
|
|
tptr->status);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
pp->lencode = (u_short) strlen(pp->a_lastcode);
|
|
|
|
|
|
|
|
pp->day = tptr->day;
|
|
|
|
pp->hour = tptr->hr;
|
|
|
|
pp->minute = tptr->mn;
|
|
|
|
pp->second = tptr->sec;
|
2008-08-18 14:26:05 +00:00
|
|
|
pp->nsec = tptr->frac;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug)
|
|
|
|
printf("pp: %3d %02d:%02d:%02d.%06ld %1x\n",
|
|
|
|
pp->day, pp->hour, pp->minute, pp->second,
|
2008-08-18 14:26:05 +00:00
|
|
|
pp->nsec, tptr->status);
|
1999-12-09 13:01:21 +00:00
|
|
|
#endif
|
|
|
|
if (tptr->status ) { /* Status 0 is locked to ref., 1 is not */
|
|
|
|
refclock_report(peer, CEVNT_BADREPLY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, compute the reference time value. Use the heavy
|
|
|
|
* machinery for the seconds and the millisecond field for the
|
|
|
|
* fraction when present. If an error in conversion to internal
|
|
|
|
* format is found, the program declares bad data and exits.
|
|
|
|
* Note that this code does not yet know how to do the years and
|
|
|
|
* relies on the clock-calendar chip for sanity.
|
|
|
|
*/
|
|
|
|
if (!refclock_process(pp)) {
|
|
|
|
refclock_report(peer, CEVNT_BADTIME);
|
|
|
|
return;
|
|
|
|
}
|
2004-07-20 15:01:56 +00:00
|
|
|
pp->lastref = pp->lastrec;
|
1999-12-09 13:01:21 +00:00
|
|
|
refclock_receive(peer);
|
2004-07-20 15:01:56 +00:00
|
|
|
record_clock_stats(&peer->srcadr, pp->a_lastcode);
|
1999-12-09 13:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct vmedate *
|
|
|
|
get_datumtime(struct vmedate *time_vme)
|
|
|
|
{
|
|
|
|
char cbuf[7];
|
|
|
|
struct btfp_time vts;
|
2008-08-18 14:26:05 +00:00
|
|
|
uint32_t btm[2];
|
|
|
|
uint8_t dmy;
|
2013-12-04 21:33:17 +00:00
|
|
|
struct stfp_time stfpm;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
if (time_vme == NULL)
|
|
|
|
time_vme = emalloc(sizeof(*time_vme));
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
switch (tfp_type) {
|
|
|
|
case 1: /* BSD, PCI, 2 32bit time words */
|
|
|
|
if (ioctl(fd_vme, READTIME, &btm)) {
|
|
|
|
msyslog(LOG_ERR, "get_bc63x error: %m");
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
tvme_fill(time_vme, btm);
|
|
|
|
break;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
case 2: /* Linux/Windows, PCI, 2 32bit time words */
|
|
|
|
if (bcReadBinTime(stfp_handle, &btm[1], &btm[0], &dmy) == 0) {
|
|
|
|
msyslog(LOG_ERR, "get_datumtime error: %m");
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
tvme_fill(time_vme, btm);
|
|
|
|
break;
|
2013-12-04 21:33:17 +00:00
|
|
|
|
|
|
|
case 3: /** solaris **/
|
|
|
|
memset(&stfpm,0,sizeof(stfpm));
|
|
|
|
|
|
|
|
/* we need the time in decimal format */
|
|
|
|
/* Here we rudely assume that we are the only user of the driver.
|
|
|
|
* Other programs will have to set their own time format before reading
|
|
|
|
* the time.
|
|
|
|
*/
|
|
|
|
if(ioctl (fd_vme, SELTIMEFORMAT, TIME_DECIMAL)){
|
2014-12-20 22:52:39 +00:00
|
|
|
msyslog(LOG_ERR, "Could not set time format");
|
2013-12-04 21:33:17 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/* read the time */
|
|
|
|
if (ioctl(fd_vme, READTIME, &stfpm)) {
|
|
|
|
msyslog(LOG_ERR, "ioctl error: %m");
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
stfp_time2tvme(time_vme, &stfpm);
|
|
|
|
break;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
default: /* legacy bancomm card */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (ioctl(fd_vme, READTIME, &vts)) {
|
2013-12-04 21:33:17 +00:00
|
|
|
msyslog(LOG_ERR,
|
|
|
|
"get_datumtime error: %m");
|
2008-08-18 14:26:05 +00:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
/* Get day */
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(cbuf, sizeof(cbuf), "%3.3x",
|
|
|
|
((vts.btfp_time[ 0 ] & 0x000f) << 8) +
|
|
|
|
((vts.btfp_time[ 1 ] & 0xff00) >> 8));
|
2008-08-18 14:26:05 +00:00
|
|
|
time_vme->day = (unsigned short)atoi(cbuf);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Get hour */
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(cbuf, sizeof(cbuf), "%2.2x",
|
|
|
|
vts.btfp_time[ 1 ] & 0x00ff);
|
2008-08-18 14:26:05 +00:00
|
|
|
time_vme->hr = (unsigned short)atoi(cbuf);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Get minutes */
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(cbuf, sizeof(cbuf), "%2.2x",
|
|
|
|
(vts.btfp_time[ 2 ] & 0xff00) >> 8);
|
2008-08-18 14:26:05 +00:00
|
|
|
time_vme->mn = (unsigned short)atoi(cbuf);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Get seconds */
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(cbuf, sizeof(cbuf), "%2.2x",
|
|
|
|
vts.btfp_time[ 2 ] & 0x00ff);
|
2008-08-18 14:26:05 +00:00
|
|
|
time_vme->sec = (unsigned short)atoi(cbuf);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so
|
|
|
|
we can use the TVTOTSF function later on...*/
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
snprintf(cbuf, sizeof(cbuf), "%4.4x%2.2x",
|
|
|
|
vts.btfp_time[ 3 ],
|
|
|
|
vts.btfp_time[ 4 ] >> 8);
|
2008-08-18 14:26:05 +00:00
|
|
|
time_vme->frac = (u_long) atoi(cbuf);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Get status bit */
|
2013-12-04 21:33:17 +00:00
|
|
|
time_vme->status = (vts.btfp_time[0] & 0x0010) >> 4;
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
if (time_vme->status)
|
1999-12-09 13:01:21 +00:00
|
|
|
return ((void *)NULL);
|
|
|
|
else
|
|
|
|
return (time_vme);
|
|
|
|
}
|
2008-08-18 14:26:05 +00:00
|
|
|
/* Assign values to time_vme struct. Mostly for readability */
|
|
|
|
void
|
|
|
|
tvme_fill(struct vmedate *time_vme, uint32_t btm[2])
|
|
|
|
{
|
|
|
|
struct tm maj;
|
|
|
|
uint32_t dmaj, dmin;
|
|
|
|
|
|
|
|
dmaj = btm[1]; /* syntax sugar */
|
|
|
|
dmin = btm[0];
|
|
|
|
|
|
|
|
gmtime_r(&dmaj, &maj);
|
|
|
|
time_vme->day = maj.tm_yday+1;
|
|
|
|
time_vme->hr = maj.tm_hour;
|
|
|
|
time_vme->mn = maj.tm_min;
|
|
|
|
time_vme->sec = maj.tm_sec;
|
|
|
|
time_vme->frac = (dmin & 0x000fffff) * 1000;
|
|
|
|
time_vme->frac += ((dmin & 0x00f00000) >> 20) * 100;
|
|
|
|
time_vme->status = (dmin & 0x01000000) >> 24;
|
|
|
|
return;
|
|
|
|
}
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
|
|
|
|
/* Assign values to time_vme struct. Mostly for readability */
|
|
|
|
void
|
|
|
|
stfp_time2tvme(struct vmedate *time_vme, struct stfp_time *stfp)
|
|
|
|
{
|
|
|
|
|
|
|
|
time_vme->day = stfp->tm.tm_yday+1;
|
|
|
|
time_vme->hr = stfp->tm.tm_hour;
|
|
|
|
time_vme->mn = stfp->tm.tm_min;
|
|
|
|
time_vme->sec = stfp->tm.tm_sec;
|
|
|
|
time_vme->frac = stfp->usec*1000;
|
|
|
|
time_vme->frac += stfp->hnsec * 100;
|
|
|
|
time_vme->status = stfp->status;
|
|
|
|
return;
|
|
|
|
}
|
1999-12-09 13:01:21 +00:00
|
|
|
#else
|
|
|
|
int refclock_bancomm_bs;
|
|
|
|
#endif /* REFCLOCK */
|