summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Burnicki <martin.burnicki@meinberg.de>2011-10-06 12:00:00 +0200
committerMartin Burnicki <martin.burnicki@meinberg.de>2011-10-06 12:00:00 +0200
commit014f1d176c48687acca32199f653ae78a861beab (patch)
tree2da4e6bcad9ace3cd7d19d5adea2ee47f4547df1
parent9fc4a73b3b75b4e9b68397d3d79e539366ff530e (diff)
downloadmbgtools-fbsd-014f1d176c48687acca32199f653ae78a861beab.tar.gz
mbgtools-fbsd-014f1d176c48687acca32199f653ae78a861beab.zip
Update files and cleanupmbgtools-fbsd-dev-2011-10-06
Update files to current versions. Add mbgsvcd start script. Use mbgversion.h file.
-rwxr-xr-xMakefile4
-rwxr-xr-xREADME41
-rwxr-xr-xmbgclock/Makefile5
-rwxr-xr-xmbgclock/mbgclock_main.c36
-rwxr-xr-xmbgctrl/Makefile8
-rwxr-xr-xmbgctrl/mbgctrl.c325
-rwxr-xr-xmbgfasttstamp/mbgfasttstamp.c33
-rwxr-xr-xmbggpscap/Makefile6
-rwxr-xr-xmbggpscap/mbggpscap.c69
-rwxr-xr-xmbghrtime/Makefile6
-rwxr-xr-xmbghrtime/mbghrtime.c50
-rwxr-xr-xmbgirigcfg/Makefile6
-rwxr-xr-xmbgirigcfg/mbgirigcfg.c309
-rwxr-xr-xmbglib/common/cfg_hlp.h115
-rwxr-xr-xmbglib/common/ctry.h15
-rwxr-xr-xmbglib/common/deviohlp.c260
-rwxr-xr-xmbglib/common/deviohlp.h156
-rwxr-xr-xmbglib/common/extiohlp.c119
-rwxr-xr-xmbglib/common/extiohlp.h114
-rwxr-xr-xmbglib/common/gpsdefs.h459
-rwxr-xr-xmbglib/common/lan_util.c442
-rwxr-xr-xmbglib/common/lan_util.h192
-rwxr-xr-xmbglib/common/macioctl.h1883
-rwxr-xr-xmbglib/common/mbg_arch.h11
-rwxr-xr-xmbglib/common/mbg_tgt.h38
-rwxr-xr-xmbglib/common/mbgdevio.c739
-rwxr-xr-xmbglib/common/mbgdevio.h545
-rwxr-xr-xmbglib/common/mbgerror.h2
-rwxr-xr-xmbglib/common/mbggenio.h10
-rwxr-xr-xmbglib/common/mbggeo.h14
-rwxr-xr-xmbglib/common/mbgioctl.h342
-rwxr-xr-xmbglib/common/mbgmutex.h40
-rwxr-xr-xmbglib/common/mbgpccyc.h302
-rwxr-xr-xmbglib/common/mbgtime.h2
-rwxr-xr-xmbglib/common/mbgutil.c4
-rwxr-xr-xmbglib/common/mbgutil.h15
-rwxr-xr-xmbglib/common/pci_asic.h43
-rwxr-xr-xmbglib/common/pcpsdefs.h415
-rwxr-xr-xmbglib/common/pcpsdev.h600
-rwxr-xr-xmbglib/common/pcpsdrvr.c365
-rwxr-xr-xmbglib/common/pcpsdrvr.h144
-rwxr-xr-xmbglib/common/pcpsirq.h6
-rwxr-xr-xmbglib/common/pcpslstr.h26
-rwxr-xr-xmbglib/common/pcpsutil.c6
-rwxr-xr-xmbglib/common/toolutil.c136
-rwxr-xr-xmbglib/common/toolutil.h53
-rwxr-xr-xmbglib/common/usbdefs.h11
-rwxr-xr-xmbglib/common/words.h17
-rwxr-xr-xmbgsetsystime/Makefile6
-rwxr-xr-xmbgsetsystime/mbgsetsystime.c15
-rwxr-xr-xmbgshowsignal/Makefile6
-rwxr-xr-xmbgshowsignal/mbgshowsignal.c46
-rwxr-xr-xmbgstatus/Makefile7
-rwxr-xr-xmbgstatus/mbgstatus.c174
-rwxr-xr-xmbgsvcd/Makefile6
-rwxr-xr-xmbgsvcd/mbgsvcd.c460
-rwxr-xr-xmbgversion.h29
-rwxr-xr-xmbgxhrtime/Makefile4
-rwxr-xr-xmbgxhrtime/mbgxhrtime.c20
-rwxr-xr-xscripts/mbgsvcd26
60 files changed, 6215 insertions, 3123 deletions
diff --git a/Makefile b/Makefile
index 271b44e..bdc67a9 100755
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,14 @@
#########################################################################
#
-# $Id: Makefile 1.1.1.6 2011/03/25 11:05:55 martin TRASH martin $
+# $Id: Makefile 1.1.1.7 2011/07/06 13:25:06 martin TEST $
#
# Description:
# Makefile for mbgtools which recurses into the subdirectories.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.1.1.7 2011/07/06 13:25:06 martin
# Revision 1.1.1.6 2011/03/25 11:05:55 martin
# Optional parameter USE_TIMESPEC.
# Revision 1.1.1.5 2011/03/21 16:24:12 martin
@@ -226,6 +227,7 @@ CFLAGS += -Wall
.endif
CFLAGS += -I.
+CFLAGS += -I$(BASEDIR)
CFLAGS += $(foreach dir,$(MBGLIB_DIRS),-I$(MBGLIB)/$(dir))
#########
CFLAGS += -I$(BASEDIR)/mbglib/common
diff --git a/README b/README
index 9067192..be98f6d 100755
--- a/README
+++ b/README
@@ -1,9 +1,48 @@
-$Id: README 1.1.1.1 2011/02/09 11:47:11 martin TRASH martin $
+$Id: README 1.1.1.2 2011/07/06 13:24:57 martin TEST $
This is the README file for mbgtools-fbsd-dev-2011-02-04
--------------------------------------------------------
+-----------------------------------------------------------------------------
+Oh, that's usually in /boot/loader.conf
+
+From the loader.conf(5) manual page:
+
+ *_load If set to ``YES'', that module will be loaded. If no name
+ is defined (see below), the module's name is taken to be
+ the same as the prefix.
+
+
+So, mbgclock_load="YES" in /boot/loader.conf ought to work.
+
+-----------------------------------------------------------------------------
+
+
+/boot/loader.conf:
+mbgclock_load="YES"
+
+/etc/rc.conf:
+mbgsvcd_enable="YES"
+
+cat /boot/loader.conf | sed -e "s/[SUCHPATTERN]/[ERSETZEN]/g" > /boot/loader.new
+
+grep "mbgclock_load=" && IS_THERE=YES || IS_THERE=NO
+
+grep -v "mbgclock_load=" > /boot/loader.new
+
+
+-----------------------------------------------------------------------------
+
+copy mbgsvcd script to /etc/rc.d/
+
+-----------------------------------------------------------------------------
+
+
+
+
+
+
Please send comments and required modifications to
Meinberg support <support@meinberg.de>
diff --git a/mbgclock/Makefile b/mbgclock/Makefile
index 51475e0..e7362bc 100755
--- a/mbgclock/Makefile
+++ b/mbgclock/Makefile
@@ -1,7 +1,7 @@
#########################################################################
#
-# $Id: Makefile 1.1.1.5 2011/05/06 14:12:02 martin TRASH $
+# $Id: Makefile 1.1.1.6 2011/07/06 13:24:29 martin TEST $
#
# Description:
# Makefile for mbgclock driver to support Meinberg bus level
@@ -9,6 +9,7 @@
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.1.1.6 2011/07/06 13:24:29 martin
# Revision 1.1.1.5 2011/05/06 14:12:02 martin
# Revision 1.1.1.4 2011/02/03 14:10:39 martin
# Revision 1.1.1.3 2011/01/26 17:38:58 martin
@@ -30,7 +31,7 @@ MBGLIB_BSD= $(MBGLIB)/bsd
.PATH: $(MBGLIB_COMMON) $(MBGLIB_BSD)
-CFLAGS= -I$(MBGLIB_COMMON) -I$(MBGLIB_BSD)
+CFLAGS= -I.. -I$(MBGLIB_COMMON) -I$(MBGLIB_BSD)
.ifdef DEBUG
CFLAGS+= -D DEBUG=$(DEBUG)
diff --git a/mbgclock/mbgclock_main.c b/mbgclock/mbgclock_main.c
index 584b303..5bfe8c7 100755
--- a/mbgclock/mbgclock_main.c
+++ b/mbgclock/mbgclock_main.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgclock_main.c 1.1.1.11.1.3 2011/03/25 11:06:27 martin TRASH martin $
+ * $Id: mbgclock_main.c 1.1.1.12 2011/10/05 10:38:06 martin TEST $
*
* Description:
* Main file for for mbgclock driver to support Meinberg bus level
@@ -14,12 +14,11 @@
*
* -----------------------------------------------------------------------
* $Log: mbgclock_main.c $
- * Revision 1.1.1.11.1.3 2011/03/25 11:06:27 martin
- * Fixed typo.
- * Revision 1.1.1.11.1.2 2011/03/23 16:49:53 martin
- * Syntax fix.
- * Revision 1.1.1.11.1.1 2011/03/22 12:09:16 martin
- * Started to support NetBSD.
+ * Revision 1.1.1.12 2011/10/05 10:38:06 martin
+ * Unified handling of program version information.
+ * Started to support privilege checking for IOCTL.
+ * Fixed sign of returned error codes.
+ * Free resources on dealloc.
* Revision 1.1.1.11 2011/02/04 14:44:19 martin
* Revision 1.1.1.10 2011/02/02 12:33:52 martin
* Revision 1.1.1.9 2011/02/01 17:11:38 martin
@@ -44,6 +43,7 @@
#include <pcpsdrvr.h>
#include <mbgddmsg.h>
+#include <mbgversion.h>
#include <sys/param.h> /* defines used in kernel.h */
#include <sys/module.h>
@@ -62,24 +62,21 @@
-#if 1 //##++ move this elsewhere!
+#define MBG_MICRO_VERSION_CODE 0
-#define REV_NUM 0x100
-#define REV_NUM_STR "1.00"
+#define MBG_COPYRIGHT "(c) Meinberg 2010-" MBG_CURRENT_COPYRIGHT_YEAR_STR
-#define MBG_COPYRIGHT "(c) Meinberg 2011"
#define MBG_DRVR_NAME "mbgclock"
-#define MBGCLK_NAME "mbgclk"
-#define MBGNTP_NAME "mbgntp"
-
const char pcps_driver_name[] = MBG_DRVR_NAME;
+
static MBG_DBG_DATA mbg_dbg_data;
static MBG_DBG_PORT mbg_dbg_port = 0x378 + 0; //##++
static PCPS_IO_ADDR_MAPPED mbg_dbg_port_mapped; //##++
-static PCPS_DRVR_INFO drvr_info = { REV_NUM, 0, MBG_DRVR_NAME " radio clock driver" };
+static PCPS_DRVR_INFO drvr_info = { MBG_VERSION_CODE( MBG_MICRO_VERSION_CODE ),
+ 0, MBG_DRVR_NAME " radio clock driver" };
#if defined( DEBUG )
int debug = DEBUG;
@@ -89,8 +86,6 @@ MALLOC_DEFINE( M_MBGCLOCK, "short desc", "long desc" );
#include <macioctl.h>
-#endif
-
/* The softc holds our per-instance data. */
@@ -214,7 +209,7 @@ mbgclock_write( struct cdev *dev, struct uio *uio, int ioflag )
int
mbgclock_ioctl( struct cdev *dev, u_long cmd, caddr_t data,
- int32_t flag, struct thread *td )
+ int32_t flag, struct thread *td ) // credentials in thread
{
struct mbgclock_softc *psc = dev->si_drv1;
PCPS_DDEV *pddev = psc->pddev;
@@ -247,6 +242,7 @@ mbgclock_ioctl( struct cdev *dev, u_long cmd, caddr_t data,
pcps_driver_name, dev, cmd, _pcps_ddev_type_name( pddev ), _pcps_ddev_sernum( pddev ) );
return EPERM;
}
+ //##+++++ !capable(CAP_SYS_ADMIN) is also used in FreeBSD's xfs_ioctl.c
#endif
break;
@@ -278,14 +274,14 @@ mbgclock_ioctl( struct cdev *dev, u_long cmd, caddr_t data,
_mbgddmsg_6( MBG_DBG_WARN, "%s: %p ioctl 0x%02lX: invalid cmd %04lX, dev %s_%s",
pcps_driver_name, dev, cmd, IOCBASECMD( cmd ),
_pcps_ddev_type_name( pddev ), _pcps_ddev_sernum( pddev ) );
- rc = EINVAL;
+ rc = ENOIOCTL;
break;
case MBG_ERR_NOT_SUPP_BY_DEV:
_mbgddmsg_5( MBG_DBG_WARN, "%s: %p ioctl 0x%02lX: not supported by dev %s_%s",
pcps_driver_name, dev, cmd, _pcps_ddev_type_name( pddev ), _pcps_ddev_sernum( pddev ) );
- rc = EIO;
+ rc = EINVAL;
break;
diff --git a/mbgctrl/Makefile b/mbgctrl/Makefile
index 01e3abf..e26af30 100755
--- a/mbgctrl/Makefile
+++ b/mbgctrl/Makefile
@@ -1,17 +1,16 @@
#########################################################################
#
-# $Id: Makefile 1.7.1.2.1.2 2011/04/20 09:34:06 martin TRASH $
+# $Id: Makefile 1.7.1.3 2011/09/26 15:50:00 martin TEST $
#
# Description:
# Makefile for mbgctrl.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
-# Revision 1.7.1.2.1.2 2011/04/20 09:34:06 martin
-# Added module lan_util.
-# Revision 1.7.1.2.1.1 2010/09/20 12:06:15 stefan
+# Revision 1.7.1.3 2011/09/26 15:50:00 martin
# Updated for use with latest base Makefile.
+# Added modules devio_hlp and lan_util.
# Revision 1.7.1.2 2010/08/30 09:05:22 martin
# Revision 1.7.1.1 2010/08/30 08:20:54 martin
# Revision 1.7 2009/07/24 10:31:16 martin
@@ -39,6 +38,7 @@ MBGDEVIO_SIMPLE = 0
OBJS = $(TARGET).o
OBJS += mbgdevio.o
+OBJS += deviohlp.o
OBJS += toolutil.o
OBJS += gpsutils.o
OBJS += pcpsutil.o
diff --git a/mbgctrl/mbgctrl.c b/mbgctrl/mbgctrl.c
index f13fc15..aba17f5 100755
--- a/mbgctrl/mbgctrl.c
+++ b/mbgctrl/mbgctrl.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgctrl.c 1.22.1.7.1.15 2011/05/04 14:53:18 martin TRASH $
+ * $Id: mbgctrl.c 1.22.1.8 2011/09/26 15:58:58 martin TEST martin $
*
* Description:
* Main file for mbgctrl program which sends commands and
@@ -9,23 +9,13 @@
*
* -----------------------------------------------------------------------
* $Log: mbgctrl.c $
- * Revision 1.22.1.7.1.15 2011/05/04 14:53:18 martin
- * Fixed compiler warning.
- * Revision 1.22.1.7.1.14 2011/05/03 15:43:12 martin
- * Revision 1.22.1.7.1.13 2011/04/21 11:09:42 martin
- * Revision 1.22.1.7.1.12 2011/04/21 10:16:03 martin
- * Revision 1.22.1.7.1.11 2011/04/21 08:49:09 martin
- * Revision 1.22.1.7.1.10 2011/04/21 08:40:19 martin
- * Revision 1.22.1.7.1.9 2011/04/21 07:51:05 martin
- * Revision 1.22.1.7.1.8 2011/04/20 16:07:41 martin
- * Revision 1.22.1.7.1.7 2011/04/20 14:49:31 martin
- * Revision 1.22.1.7.1.6 2011/04/20 14:43:00 martin
- * Revision 1.22.1.7.1.5 2011/04/20 14:13:36 martin
- * Revision 1.22.1.7.1.4 2011/04/20 13:32:52 martin
- * Revision 1.22.1.7.1.3 2011/04/20 11:34:28 martin
- * Revision 1.22.1.7.1.2 2011/04/20 11:32:36 martin
- * Revision 1.22.1.7.1.1 2011/04/19 15:31:31 martin
- * Started modifications for PTP unicast master cfg.
+ * Revision 1.22.1.8 2011/09/26 15:58:58 martin
+ * Started modifications for PTP unicast master configuration.
+ * Warn if trying to handle serial port cfg but no serial port is supported.
+ * Modified program version handling.
+ * Use O_RDWR flag when opening a device.
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
* Revision 1.22.1.7 2011/04/19 10:02:37 martin
* Syntax fix.
* Revision 1.22.1.6 2011/04/19 09:57:00 martin
@@ -110,6 +100,7 @@
// include Meinberg headers
#include <mbgdevio.h>
+#include <deviohlp.h>
#include <pcpsmktm.h>
#include <pcpsutil.h>
#include <parmpcps.h>
@@ -128,9 +119,13 @@
#include <ctype.h>
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbgctrl";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2001-2009";
+
+#define SIM_PTP_CFG ( 0 && DEBUG ) //##+++
static char *dev_name;
@@ -163,6 +158,136 @@ static const char no_lan_intf[] = "does not provide a LAN interface";
static const char no_ptp[] = "does not provide PTP";
static const char no_cab_len[] = "does not support antenna signal delay compensation";
+#define N_SUPP_UNICAST_MASTER 1
+
+
+#define DEFAULT_MC_SYNC_INTV_MIN -6 // [log2 s]
+#define DEFAULT_MC_SYNC_INTV_MAX 6 // [log2 s]
+
+#define DEFAULT_MC_ANN_INTV_MIN -6 // [log2 s]
+#define DEFAULT_MC_ANN_INTV_MAX 6 // [log2 s]
+
+#define DEFAULT_MC_DELAY_REQ_INTV_MIN -6 // [log2 s]
+#define DEFAULT_MC_DELAY_REQ_INTV_MAX 6 // [log2 s]
+
+
+#define DEFAULT_UC_SYNC_INTV_MIN -6 // [log2 s]
+#define DEFAULT_UC_SYNC_INTV_MAX 6 // [log2 s]
+
+#define DEFAULT_UC_ANN_INTV_MIN -6 // [log2 s]
+#define DEFAULT_UC_ANN_INTV_MAX 6 // [log2 s]
+
+#define DEFAULT_UC_DELAY_REQ_INTV_MIN -6 // [log2 s]
+#define DEFAULT_UC_DELAY_REQ_INTV_MAX 6 // [log2 s]
+
+
+
+#define DEFAULT_MC_SYNC_INTV 0 // [log2 s]
+#define DEFAULT_MC_ANN_INTV 1 // [log2 s]
+#define DEFAULT_MC_DELAY_REQ_INTV 3 // [log2 s]
+
+#define DEFAULT_UC_SYNC_INTV 0 // [log2 s]
+#define DEFAULT_UC_ANN_INTV 1 // [log2 s]
+#define DEFAULT_UC_DELAY_REQ_INTV 3 // [log2 s]
+#define DEFAULT_UC_MSG_DURATION 300 // [s]
+
+
+
+#define DEFAULT_PTP_CFG_SETTINGS \
+{ \
+ PTP_NW_PROT_BIT_UDP_IPV4, /* nw_prot */ \
+ 0, /* profile */ \
+ 0, /* domain_number */ \
+ PTP_DELAY_MECH_BIT_E2E, /* delay_mech */ \
+ PTP_ROLE_MULTICAST_SLAVE, /* ptp_role */ \
+ 128, /* priority_1 */ \
+ 128, /* priority_2 */ \
+ 52, /* dflt_clk_class_unsync_cold */ \
+ 7, /* dflt_clk_class_unsync_warm */ \
+ 6, /* dflt_clk_class_sync_cold */ \
+ 6, /* dflt_clk_class_sync_warm */ \
+ 0, /* reserved_1 */ \
+ 0, /* reserved_2 */ \
+ DEFAULT_MC_SYNC_INTV, /* sync_intv [log2 s]*/ \
+ DEFAULT_MC_ANN_INTV, /* ann_intv [log2 s] */ \
+ DEFAULT_MC_DELAY_REQ_INTV, /* delay_req_intv [log2 s] */ \
+ 0, /* upper_bound, not used */ \
+ 0, /* lower_bound, not used */ \
+ 0, /* reserved_3 */ \
+ 0 /* flags */ \
+}
+
+//##++++++++++
+#define DEFAULT_PTP_SLAVE_SUPP_FLAGS 0
+#define DEFAULT_PTP_SLAVE_SUPP_NW_PROT 0
+#define DEFAULT_PTP_SLAVE_SUPP_PROFILES 0
+#define DEFAULT_PTP_SLAVE_SUPP_DELAY_MECH 0
+
+#define DEFAULT_PTP_CFG_INFO_SLAVE \
+{ \
+ DEFAULT_PTP_CFG_SETTINGS, /* ptp_cfg_settings */ \
+ 2, /* ptp_proto_version */ \
+ 0, /* reserved_1 */ \
+ 0, /* reserved_2 */ \
+ DEFAULT_MC_SYNC_INTV_MIN, /* sync_intv_min */ \
+ DEFAULT_MC_SYNC_INTV_MAX, /* sync_intv_max */ \
+ DEFAULT_MC_ANN_INTV_MIN, /* ann_intv_min */ \
+ DEFAULT_MC_ANN_INTV_MIN, /* ann_intv_max */ \
+ DEFAULT_MC_DELAY_REQ_INTV_MIN, /* delay_req_intv_min */ \
+ DEFAULT_MC_DELAY_REQ_INTV_MIN, /* delay_req_intv_max */ \
+ DEFAULT_PTP_SLAVE_SUPP_FLAGS, /* supp_flags */ \
+ DEFAULT_PTP_SLAVE_SUPP_NW_PROT, /* supp_nw_prot */ \
+ DEFAULT_PTP_SLAVE_SUPP_PROFILES, /* supp_profiles */ \
+ DEFAULT_PTP_SLAVE_SUPP_DELAY_MECH /* supp_delay_mech */ \
+}
+
+#define DEFAULT_PTP_UC_MASTER_CFG_LIMITS \
+{ \
+ 1, /* n_supp_master */ \
+ -6, /* sync_intv_min */ \
+ 6, /* sync_intv_max */ \
+ -6, /* ann_intv_min */ \
+ 6, /* ann_intv_max */ \
+ -6, /* delay_req_intv_min */ \
+ 6, /* delay_req_intv_max */ \
+ 0, /* reserved_0 */ \
+ 0, /* supp_flags */ \
+ 0 /* reserved_1 */ \
+}
+
+
+#define DEFAULT_PTP_UC_MASTER_SETTINGS \
+{ \
+ "0.0.0.0", /* gm_host */ \
+ PTP_CLOCK_ID_WILDCARD, /* gm_clock_id */ \
+ PTP_PORT_ID_WILDCARD, /* gm_port_id */ \
+ DEFAULT_UC_SYNC_INTV, /* sync_intv [log2 s] */ \
+ DEFAULT_UC_ANN_INTV, /* ann_intv [log2 s] */ \
+ DEFAULT_UC_DELAY_REQ_INTV, /* delay_req_intv [log2 s] */ \
+ 0, /* fix_offset, [ns] */ \
+ DEFAULT_UC_MSG_DURATION, /* message_duration [s] */ \
+ 0, /* reserved_1 */ \
+ 0 /* flags */ \
+}
+
+
+#define DEFAULT_PTP_UC_MASTER_INFO \
+{ \
+ DEFAULT_PTP_UC_MASTER_SETTINGS, /* settings */ \
+ 0, /* reserved */ \
+ 0 /* flags */ \
+}
+
+
+
+#if SIM_PTP_CFG
+ static PTP_CFG_INFO sim_ptp_cfg_info = DEFAULT_PTP_CFG_INFO_SLAVE;
+ static PTP_UC_MASTER_CFG_LIMITS sim_ptp_uc_master_cfg_limits = DEFAULT_PTP_UC_MASTER_CFG_LIMITS;
+ static PTP_UC_MASTER_INFO sim_ptp_uc_master_info[N_SUPP_UNICAST_MASTER] = { DEFAULT_PTP_UC_MASTER_INFO };
+#endif
+
+
+
typedef struct
{
const char *name;
@@ -197,18 +322,18 @@ static const char ptp_name_v1[] = "HW";
static const char ptp_name_role[] = "ROLE";
-static const char ptp_name_gm_ip[] = "GMIP";
-static const char ptp_name_gm_id[] = "GMID";
-static const char ptp_name_tp_id[] = "PID";
+static const char ptp_name_gmip[] = "GMIP";
+static const char ptp_name_gmid[] = "GMID";
+static const char ptp_name_pid[] = "PID";
+static const char ptp_name_smi[] = "SMI";
+static const char ptp_name_ami[] = "AMI";
+static const char ptp_name_dri[] = "DRI";
static const char ptp_name_dur[] = "DUR";
-static const char ptp_name_sr[] = "SR";
-static const char ptp_name_ar[] = "AR";
-static const char ptp_name_dr[] = "DR";
//##+++++
static const char *delay_mech[] = PTP_DELAY_MECH_NAMES;
-static const char *network_prot[] = PTP_NW_PROT_STRS;
-static const char *network_prot_short[] = PTP_NW_PROT_STRS_SHORT;
+static const char *nw_prot[] = PTP_NW_PROT_STRS;
+static const char *nw_prot_short[] = PTP_NW_PROT_STRS_SHORT;
static const char *ptp_roles[] = PTP_ROLE_STRS;
static const char *ptp_roles_short[] = PTP_ROLE_STRS_SHORT;
@@ -391,59 +516,6 @@ int show_lan_intf( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info )
-//##+++++++++++++++
-typedef struct
-{
- PTP_CFG_INFO ptp_cfg_info;
- PTP_UC_MASTER_CFG_LIMITS ptp_uc_master_cfg_limits;
- ALL_PTP_UC_MASTER_INFO all_ptp_uc_master_info;
-} ALL_PTP_CFG_INFO;
-
-
-
-static /*HDR*/
-int mbg_get_all_ptp_cfg_info( MBG_DEV_HANDLE dh, ALL_PTP_CFG_INFO *p )
-{
- int rc;
-
- memset( p, 0, sizeof( *p ) );
-
- rc = mbg_get_ptp_cfg_info( dh, &p->ptp_cfg_info );
-
- if ( mbg_ioctl_err( rc, "mbg_get_ptp_cfg_info" ) )
- goto ret;
-
-
- if ( p->ptp_cfg_info.supp_flags & PTP_CFG_MSK_SUPPORT_PTP_UNICAST )
- {
- rc = mbg_get_ptp_uc_master_cfg_limits( dh, &p->ptp_uc_master_cfg_limits );
-
- if ( mbg_ioctl_err( rc, "mbg_get_ptp_uc_master_cfg_limits" ) )
- goto ret;
-
-
- if ( p->ptp_uc_master_cfg_limits.n_supp_master > MAX_PARM_PTP_UC_MASTER )
- {
- printf( "The number of PTP unicast masters supported by this device (%i)\n"
- "exceeds the number of unicast masters supporterd by this driver (%i)\n",
- p->ptp_uc_master_cfg_limits.n_supp_master, MAX_PARM_PTP_UC_MASTER );
- rc = MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP;
- }
-
-
- rc = mbg_get_all_ptp_uc_master_info( dh, p->all_ptp_uc_master_info, &p->ptp_uc_master_cfg_limits );
-
- if ( mbg_ioctl_err( rc, "mbg_get_all_ptp_uc_master_info" ) )
- goto ret;
- }
-
-ret:
- return rc;
-
-} // mbg_get_all_ptp_cfg_info
-
-
-
static /*HDR*/
int show_ptp_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info )
{
@@ -454,7 +526,7 @@ int show_ptp_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info )
int rc = mbg_get_all_ptp_cfg_info( dh, &all_ptp_cfg_info );
- if ( rc < 0 )
+ if ( mbg_ioctl_err( rc, "mbg_get_all_ptp_cfg_info" ) )
return rc;
unicast_supported = ( all_ptp_cfg_info.ptp_cfg_info.supp_flags & PTP_CFG_MSK_SUPPORT_PTP_UNICAST ) != 0;
@@ -464,8 +536,8 @@ int show_ptp_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *info )
idx = all_ptp_cfg_info.ptp_cfg_info.settings.ptp_role;
printf( " PTP Role : %s (%s)\n", _ptp_role_name_short( idx ), _ptp_role_name( idx ) );
- idx = all_ptp_cfg_info.ptp_cfg_info.settings.network_protocol;
- printf( " Network Protocol: %s (%s)\n", network_prot_short[idx], network_prot[idx] );
+ idx = all_ptp_cfg_info.ptp_cfg_info.settings.nw_prot;
+ printf( " Network Protocol: %s (%s)\n", nw_prot_short[idx], nw_prot[idx] );
printf( " Delay Mechanism : %s\n", delay_mech[all_ptp_cfg_info.ptp_cfg_info.settings.delay_mech] );
printf( " Domain Number : %d\n", all_ptp_cfg_info.ptp_cfg_info.settings.domain_number );
@@ -720,10 +792,10 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// Network protocol
- idx = chk_tbl_parm( arg, ptp_name_net, network_prot_short, N_PTP_NW_PROT, p_info->supp_network_prot, "network protocol type" );
+ idx = chk_tbl_parm( arg, ptp_name_net, nw_prot_short, N_PTP_NW_PROT, p_info->supp_nw_prot, "network protocol type" );
if ( idx >= 0 ) // valid parameter found
- p_settings->network_protocol = idx;
+ p_settings->nw_prot = idx;
else
if ( idx < -1 )
goto fail;
@@ -799,7 +871,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// GM Host
- idx = chk_parm_name( arg, ptp_name_gm_ip, &cp );
+ idx = chk_parm_name( arg, ptp_name_gmip, &cp );
if ( idx < 0 ) // parameter error
goto fail;
@@ -827,7 +899,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// GM Clock ID
- idx = chk_parm_name( arg, ptp_name_gm_id, &cp );
+ idx = chk_parm_name( arg, ptp_name_gmid, &cp );
if ( idx < 0 ) // parameter error
goto fail;
@@ -838,12 +910,12 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
err_unicast_nsupp = 1;
else
{
- PTP_CLOCK_IDENTITY gm_clock_id;
+ PTP_CLOCK_ID gm_clock_id;
idx = str_to_octets( gm_clock_id.b, sizeof( gm_clock_id.b ), cp );
if ( idx != sizeof( gm_clock_id ) )
{
- printf( "Syntax error in specified GM Clock ID\n" );
+ printf( "Syntax error in specified GM clock ID\n" );
goto fail;
}
else
@@ -859,7 +931,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// GM Target Port ID
- idx = chk_parm_name( arg, ptp_name_tp_id, &cp );
+ idx = chk_parm_name( arg, ptp_name_pid, &cp );
if ( idx < 0 ) // parameter error
goto fail;
@@ -877,7 +949,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// Sync Message Rate
- idx = chk_int16_parm( arg, ptp_name_sr, &p_uc_settings->sync_intv,
+ idx = chk_int16_parm( arg, ptp_name_smi, &p_uc_settings->sync_intv,
p_uc_limits->sync_intv_min, p_uc_limits->sync_intv_max,
unicast_supported, "sync intv." );
if ( idx < 0 )
@@ -885,7 +957,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// Announce Message Rate
- idx = chk_int16_parm( arg, ptp_name_ar, &p_uc_settings->ann_intv,
+ idx = chk_int16_parm( arg, ptp_name_ami, &p_uc_settings->ann_intv,
p_uc_limits->ann_intv_min, p_uc_limits->ann_intv_max,
unicast_supported, "ann. intv." );
if ( idx < 0 )
@@ -893,7 +965,7 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
// Delay Message Rate
- idx = chk_int16_parm( arg, ptp_name_dr, &p_uc_settings->delay_req_intv,
+ idx = chk_int16_parm( arg, ptp_name_dri, &p_uc_settings->delay_req_intv,
p_uc_limits->delay_req_intv_min, p_uc_limits->delay_req_intv_max,
unicast_supported, "delay req. intv." );
if ( idx < 0 )
@@ -929,7 +1001,12 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
#endif
+#if SIM_PTP_CFG
+ sim_ptp_cfg_info.settings = *p_settings;
+ rc = 0;
+#else
rc = mbg_set_ptp_cfg_settings( dh, p_settings );
+#endif
if ( mbg_ioctl_err( rc, "mbg_set_ptp_cfg_settings" ) )
return rc;
@@ -938,8 +1015,12 @@ int set_ptp_cfg( MBG_DEV_HANDLE dh, const char *arg, const PCPS_DEV *p_dev )
#if 0 //##+++++++++
if ( unicast_supported )
{
+ #if SIM_PTP_CFG
+ #error test
+ rc = MBG_SUCCESS;
+ #else
rc = mbg_set_ptp_unicast_cfg_settings( dh, &ptp_unicast_settings );
-
+ #endif
if ( mbg_ioctl_err( rc, "mbg_set_ptp_unicast_cfg_settings" ) )
return rc;
}
@@ -1738,7 +1819,7 @@ int set_event_time( MBG_DEV_HANDLE dh, const char *s )
if ( mbg_ioctl_err( rc, "mbg_set_event_time" ) )
return rc;
- mbg_snprint_hr_tstamp( ws, sizeof( ws ), &event_ts );
+ mbg_snprint_hr_tstamp( ws, sizeof( ws ), &event_ts, 0 ); // raw timestamp?
printf( "Event time set to UTC %s\n", ws );
return MBG_SUCCESS;
@@ -1986,22 +2067,23 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri,
" DM:P2P specifies peer-to-peer delay mechanism\n"
" DO:0 specifies PTP domain number [0..255]\n"
" HW:1 specifies if the \"v1 hardware compatibility flag\" shall be set ('1') or disabled ('0')\n"
+ " (this is usually not required)\n"
"\n"
);
- printf( " If the PTP device supports unicast mode then the following\n"
- " additional parameters can be set:\n"
- " PTP=ROLE:<rl>[,GMIP:<ip>][,GMID:<id>][,PID:<po>][,SR:<sr>][,AR:<ar>][,DR:<dr>][,DUR:<du>] set PTP unicast parameters\n"
+ printf( " If the PTP device supports unicast slave mode then the following parameters\n"
+ " can be specified to configure a unicast master to be queried:\n"
+ " PTP=ROLE:<rl>[,GMIP:<ip>][,GMID:<id>][,PID:<po>][,SMI:<sr>][,AMI:<ar>][,DMI:<dr>][,DUR:<du>] set PTP unicast parameters\n"
"\n"
" where, e.g.:\n"
" ROLE:MCS specifies \"Multicast Slave\" PTP role\n"
" ROLE:UCS specifies \"Unicast Slave\" PTP role\n"
" GMIP:192.168.1.115 specifies the IP address of the grandmaster\n"
- " GMID:FF:FF:FF:FF:FF:FF:FF:FF specifies the Clock ID of the grandmaster or FF:FF:... as wildcard\n"
- " PID:1 specifies the target port id of the grandmaster port to be used or 65535 as wildcard\n"
- " SR:0 specifies the Sync message rate requested from the grandmaster in 2^x seconds [-6..6]\n"
- " AR:1 specifies the Announce message rate requested from the grandmaster in 2^x seconds [-6..6]\n"
- " DR:1 specifies the DelayRequest message rate requested from the grandmaster in 2^x seconds [-6..6]\n"
+ " GMID:FF:FF:FF:FF:FF:FF:FF:FF specifies the Clock ID of the grandmaster, or '*' as wildcard for all FF\n"
+ " PID:1 specifies the target port ID of the grandmaster port to be used, or '*' for wildcard\n"
+ " SMI:0 specifies the Sync message interval requested from the grandmaster in 2^x seconds [-6..6]\n"
+ " AMI:1 specifies the Announce message interval requested from the grandmaster in 2^x seconds [-6..6]\n"
+ " DMI:1 specifies the DelayRequest message interval requested from the grandmaster in 2^x seconds [-6..6]\n"
" DUR:300 specifies the duration in seconds how long the master shall send messages to the slave until a timeout or renewal occurs\n"
"\n"
);
@@ -2025,7 +2107,7 @@ void usage( MBG_DEV_HANDLE dh, PCPS_DEV *p_dev, RECEIVER_INFO *p_ri,
static /*HDR*/
-const char *str_parm_p(const char *s, const char *keyword )
+const char *str_parm_p( const char *s, const char *keyword )
{
char *match = strstr( s, keyword );
@@ -2133,16 +2215,21 @@ int check_cmd_line( int argc, char *argv[], MBG_DEV_HANDLE dh, const PCPS_DEV *p
if ( p_dev )
{
check_setup_receiver_info( dh, p_dev, p_ri );
- check_get_receiver_port_cfg( dh, p_rpcfg, p_dev, p_ri );
-
- if ( *cp != 0 )
+ if ( p_ri->n_com_ports )
{
- printf( "** Invalid parameter: %s\n", argv[i] );
- must_print_usage = 1;
- continue;
- }
+ check_get_receiver_port_cfg( dh, p_rpcfg, p_dev, p_ri );
+
+ if ( *cp != 0 )
+ {
+ printf( "** Invalid parameter: %s\n", argv[i] );
+ must_print_usage = 1;
+ continue;
+ }
- show_serial_settings( dh, p_rpcfg, p_ri );
+ show_serial_settings( dh, p_rpcfg, p_ri );
+ }
+ else
+ printf( "** This device does not provide a configurable COM port.\n" );
}
continue;
@@ -2451,7 +2538,7 @@ int main( int argc, char *argv[] )
MBG_DEV_HANDLE dh = MBG_INVALID_DEV_HANDLE;
int rc;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// If no arguments have been given, just print usage.
if ( argc < 2 )
@@ -2462,12 +2549,16 @@ int main( int argc, char *argv[] )
check_cmd_line( argc, argv, dh, NULL, &ri, &rpcfg );
if ( dev_name )
- dh = open( dev_name, 0 ); // open specific device
+ dh = open( dev_name, O_RDWR ); // open specific device
else
dh = mbg_open_device( 0 ); // open first device found
if ( dh == MBG_INVALID_DEV_HANDLE )
{
+ //##++++++++++++++++++++++
+ if ( dev_name )
+ fprintf( stderr, "%s: ", dev_name );
+
perror( "Unable to open device" );
goto fail;
}
@@ -2481,6 +2572,10 @@ int main( int argc, char *argv[] )
pdev = &dev;
+ #if SIM_PTP_CFG
+ pdev->cfg.features |= PCPS_HAS_PTP;
+ #endif
+
rc = check_cmd_line( argc, argv, dh, pdev, &ri, &rpcfg );
if ( rc < 0 )
diff --git a/mbgfasttstamp/mbgfasttstamp.c b/mbgfasttstamp/mbgfasttstamp.c
index 35bad13..4388591 100755
--- a/mbgfasttstamp/mbgfasttstamp.c
+++ b/mbgfasttstamp/mbgfasttstamp.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgfasttstamp.c 1.6.1.3 2011/01/28 12:04:07 martin TEST $
+ * $Id: mbgfasttstamp.c 1.6.1.4 2011/09/26 16:00:51 martin TEST $
*
* Description:
* Main file for mbgfasttstamp program which demonstrates how to access
@@ -9,6 +9,11 @@
*
* -----------------------------------------------------------------------
* $Log: mbgfasttstamp.c $
+ * Revision 1.6.1.4 2011/09/26 16:00:51 martin
+ * Modified program version handling.
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
+ * Started to support signal handler to catch CTRL-C.
* Revision 1.6.1.3 2011/01/28 12:04:07 martin
* Revision 1.6.1.2 2011/01/28 11:51:13 martin
* Revision 1.6.1.1 2011/01/28 11:17:00 martin
@@ -46,9 +51,11 @@
#include <unistd.h>
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2007
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbgfasttstamp";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2007-2009";
#define MAX_TS_BURST 1000
@@ -56,6 +63,20 @@ static const char *pcopyright = "(c) Meinberg 2007-2009";
static int loops;
static int burst_read;
static int read_raw;
+static int exit_requested;
+
+
+
+static /*HDR*/
+void sighandler( int sig )
+{
+ #if defined( DEBUG )
+ printf( "Caught signal %i, exiting.\n", sig );
+ #endif
+
+ exit_requested = 1;
+
+} // sighandler
@@ -79,7 +100,7 @@ int show_fast_hr_timestamp( MBG_DEV_HANDLE dh )
if ( mbg_ioctl_err( rc, "mbg_get_fast_hr_timestamp..." ) )
goto fail;
- mbg_print_hr_timestamp( &ts, hns_latency, NULL, read_raw );
+ mbg_print_hr_timestamp( &ts, hns_latency, NULL, read_raw, 0 ); // raw timestamp?
if ( this_loops > 0 )
this_loops--;
@@ -139,7 +160,7 @@ int show_fast_hr_timestamp_burst( MBG_DEV_HANDLE dh )
for ( i = 0; i < this_loops; i++ )
{
PCPS_TIME_STAMP *p_prv_ts = i ? &ts[i - 1] : NULL;
- mbg_print_hr_timestamp( &ts[i], hns_latency[i], p_prv_ts, read_raw );
+ mbg_print_hr_timestamp( &ts[i], hns_latency[i], p_prv_ts, read_raw, 0 ); // raw timestamp?
}
return 0;
@@ -207,7 +228,7 @@ int main( int argc, char *argv[] )
int rc;
int c;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "bcn:rh?" ) ) != -1 )
diff --git a/mbggpscap/Makefile b/mbggpscap/Makefile
index 6564761..390b4cd 100755
--- a/mbggpscap/Makefile
+++ b/mbggpscap/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.7.1.2 2010/08/30 09:05:23 martin TEST $
+# $Id: Makefile 1.7.1.3 2011/09/26 16:01:46 martin TEST $
#
# Description:
# Makefile for mbggpscap.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.7.1.3 2011/09/26 16:01:46 martin
+# Updated for use with latest base Makefile.
# Revision 1.7.1.2 2010/08/30 09:05:23 martin
# Revision 1.7.1.1 2010/08/30 08:21:32 martin
# Revision 1.7 2009/07/24 10:31:16 martin
@@ -28,7 +30,7 @@
#########################################################################
TARGET = mbggpscap
-INST_DIR = /usr/local/bin
+INST_TO_BIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbggpscap/mbggpscap.c b/mbggpscap/mbggpscap.c
index bfa8804..c619bd3 100755
--- a/mbggpscap/mbggpscap.c
+++ b/mbggpscap/mbggpscap.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbggpscap.c 1.10.1.2 2010/11/12 12:27:17 martin TEST $
+ * $Id: mbggpscap.c 1.10.1.6 2011/09/09 08:28:22 martin TEST $
*
* Description:
* Main file for mbggpscap program which demonstrates how to access
@@ -13,6 +13,16 @@
*
* -----------------------------------------------------------------------
* $Log: mbggpscap.c $
+ * Revision 1.10.1.6 2011/09/09 08:28:22 martin
+ * Revision 1.10.1.5 2011/09/07 15:12:33 martin
+ * New option -r which displays raw timestamps and raw status.
+ * New option -o which forces usage of old API.
+ * Fixed a bug when displaying the capture event status. TTM and PCPS_HR_TIME
+ * are using different sets of status flags.
+ * Revision 1.10.1.4 2011/07/05 15:35:54 martin
+ * Modified version handling.
+ * Revision 1.10.1.3 2011/07/05 14:35:18 martin
+ * New way to maintain version information.
* Revision 1.10.1.2 2010/11/12 12:27:17 martin
* Improved reading capture events arriving at a high rate.
* Support validation of capture signals arriving at a constant rate.
@@ -61,14 +71,19 @@
#define USLEEP_INTV 10000 // [microseconds]
+
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbggpscap";
-static const char *pversion = "v3.4.1";
-static const char *pcopyright = "(c) Meinberg 2001-2010";
static int continuous;
static double nom_cap_intv; // nominal capture interval to check [s]
static double max_cap_jitter; // max allowed jitter [s]
+static int raw;
+static int force_old_api;
static int has_been_called;
static int must_check_intv;
@@ -76,20 +91,6 @@ static ulong err_cnt;
static PCPS_HR_TIME prv_ucap;
-static /*HDR*/
-void show_ucap_status( ulong status )
-{
- // status bit definitions can be found in pcpsdefs.h.
-
- if ( status & PCPS_UCAP_OVERRUN ) // capture events have occurred too fast
- printf( " << CAP OVR" );
-
- if ( status & PCPS_UCAP_BUFFER_FULL ) // capture buffer has been full, events lost
- printf( " << BUF OVR" );
-
-} // show_ucap_status
-
-
static /*HDR*/
void show_ucap_event( const PCPS_HR_TIME *ucap )
@@ -97,7 +98,7 @@ void show_ucap_event( const PCPS_HR_TIME *ucap )
char ws[80];
// Print converted date and time to a string:
- mbg_snprint_hr_time( ws, sizeof( ws ), ucap );
+ mbg_snprint_hr_time( ws, sizeof( ws ), ucap, raw );
// Print the time stamp, ucap->signal contains the channel number:
printf( "New capture: CH%i: %s", ucap->signal, ws );
@@ -122,7 +123,16 @@ void show_ucap_event( const PCPS_HR_TIME *ucap )
printf( " ** %lu", err_cnt );
}
- show_ucap_status( ucap->status );
+ // status bit definitions can be found in pcpsdefs.h.
+
+ if ( raw )
+ printf( ", st: 0x%04X", ucap->status );
+
+ if ( ucap->status & PCPS_UCAP_OVERRUN ) // capture events have occurred too fast
+ printf( " << CAP OVR" );
+
+ if ( ucap->status & PCPS_UCAP_BUFFER_FULL ) // capture buffer has been full, events lost
+ printf( " << BUF OVR" );
prv_ucap = *ucap;
has_been_called = 1;
@@ -151,7 +161,8 @@ void show_gps_ucap( const TTM *ucap )
(ulong) ucap->tm.frac
);
- show_ucap_status( ucap->tm.status );
+ if ( raw )
+ printf( ", st: 0x%04lX", (ulong) ucap->tm.status );
printf( "\n" );
@@ -226,7 +237,7 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
// The new API calls are supported by all supported by all newer boards which
// provide user capture inputs, and also for older boards with a firmware update.
- if ( _pcps_has_ucap( p_dev ) ) // check if the new API is supported
+ if ( !force_old_api && _pcps_has_ucap( p_dev ) ) // check if the new API is supported
{
// The new API provides the following functions:
// mbg_clr_ucap_buff() clear the on-board FIFO buffer
@@ -289,7 +300,7 @@ int do_mbggpscap( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
}
else // use the old API
{
- printf( "Checking for capture events:\n" );
+ printf( "Checking for capture events using the old API:\n" );
for (;;)
{
@@ -336,6 +347,8 @@ void usage( void )
mbg_print_opt_info( "-c", "run continuously" );
mbg_print_opt_info( "-i val", "check interval between captures events [s]" );
mbg_print_opt_info( "-j val", "max allowed jitter of capture interval [s]" );
+ mbg_print_opt_info( "-r", "show raw (hex) timestamp and status)" );
+ mbg_print_opt_info( "-o", "force usage of old API (for testing only)" );
mbg_print_device_options();
puts( "" );
@@ -348,10 +361,10 @@ int main( int argc, char *argv[] )
int rc;
int c;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
- while ( ( c = getopt( argc, argv, "ci:j:h?" ) ) != -1 )
+ while ( ( c = getopt( argc, argv, "ci:j:roh?" ) ) != -1 )
{
switch ( c )
{
@@ -367,6 +380,14 @@ int main( int argc, char *argv[] )
max_cap_jitter = atof( optarg );
break;
+ case 'r':
+ raw = 1;
+ break;
+
+ case 'o':
+ force_old_api = 1;
+ break;
+
case 'h':
case '?':
default:
diff --git a/mbghrtime/Makefile b/mbghrtime/Makefile
index e332204..0c8dc30 100755
--- a/mbghrtime/Makefile
+++ b/mbghrtime/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.7.1.2 2010/08/30 09:05:23 martin TEST $
+# $Id: Makefile 1.7.1.3 2011/09/26 16:02:55 martin TEST $
#
# Description:
# Makefile for mbghrtime.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.7.1.3 2011/09/26 16:02:55 martin
+# Updated for use with latest base Makefile.
# Revision 1.7.1.2 2010/08/30 09:05:23 martin
# Revision 1.7.1.1 2010/08/30 08:21:39 martin
# Revision 1.7 2009/07/24 10:31:16 martin
@@ -28,7 +30,7 @@
#########################################################################
TARGET = mbghrtime
-INST_DIR = /usr/local/bin
+INST_TO_BIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbghrtime/mbghrtime.c b/mbghrtime/mbghrtime.c
index 86214a2..9ff82d0 100755
--- a/mbghrtime/mbghrtime.c
+++ b/mbghrtime/mbghrtime.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbghrtime.c 1.11.1.4 2011/01/28 12:04:08 martin TEST $
+ * $Id: mbghrtime.c 1.11.1.8 2011/09/29 16:28:34 martin TEST martin $
*
* Description:
* Main file for mbghrtime program which demonstrates how to access
@@ -10,6 +10,16 @@
*
* -----------------------------------------------------------------------
* $Log: mbghrtime.c $
+ * Revision 1.11.1.8 2011/09/29 16:28:34 martin
+ * New options -s, -u, -v.
+ * Print time using new function mbg_print_hr_time().
+ * Revision 1.11.1.7 2011/09/07 15:08:55 martin
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
+ * Revision 1.11.1.6 2011/07/05 15:35:54 martin
+ * Modified version handling.
+ * Revision 1.11.1.5 2011/07/05 14:35:18 martin
+ * New way to maintain version information.
* Revision 1.11.1.4 2011/01/28 12:04:08 martin
* Revision 1.11.1.3 2011/01/28 11:52:51 martin
* Revision 1.11.1.2 2011/01/28 11:51:13 martin
@@ -61,9 +71,11 @@
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbghrtime";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2001-2009";
#define MAX_TS_BURST 1000
@@ -71,6 +83,9 @@ static const char *pcopyright = "(c) Meinberg 2001-2009";
static int loops;
static int burst_read;
static int read_raw;
+static long sleep_secs;
+static long sleep_usecs;
+static int verbose;
@@ -96,7 +111,7 @@ int show_hr_timestamp( MBG_DEV_HANDLE dh )
if ( mbg_ioctl_err( rc, "mbg_get_hr_time_..." ) )
goto fail;
- mbg_print_hr_timestamp( &ht.tstamp, hns_latency, p, read_raw );
+ mbg_print_hr_time( &ht, hns_latency, p, read_raw, verbose, verbose );
prv_ht = ht;
p = &prv_ht.tstamp;
@@ -107,6 +122,12 @@ int show_hr_timestamp( MBG_DEV_HANDLE dh )
if ( this_loops == 0 )
break;
+ if ( sleep_secs )
+ sleep( sleep_secs );
+ else
+ if ( sleep_usecs )
+ usleep( sleep_usecs );
+
// if this_loops is < 0 then loop forever
}
@@ -159,7 +180,7 @@ int show_hr_timestamp_burst( MBG_DEV_HANDLE dh )
for ( i = 0; i < this_loops; i++ )
{
PCPS_HR_TIME *p_prv_ht = i ? &ht[i - 1] : NULL;
- mbg_print_hr_timestamp( &ht[i].tstamp, hns_latency[i], &p_prv_ht->tstamp, read_raw );
+ mbg_print_hr_time( &ht[i], hns_latency[i], &p_prv_ht->tstamp, read_raw, verbose, verbose );
}
return 0;
@@ -214,6 +235,9 @@ void usage( void )
mbg_print_opt_info( "-n num", "run num loops" );
mbg_print_opt_info( "-b", "burst read" );
mbg_print_opt_info( "-r", "read raw time stamps, no cycles" );
+ mbg_print_opt_info( "-s num", "sleep num seconds between calls" );
+ mbg_print_opt_info( "-u num", "sleep num microseconds between calls" );
+ mbg_print_opt_info( "-v", "increase verbosity" );
mbg_print_device_options();
puts( "" );
@@ -226,10 +250,10 @@ int main( int argc, char *argv[] )
int rc;
int c;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
- while ( ( c = getopt( argc, argv, "bcn:rh?" ) ) != -1 )
+ while ( ( c = getopt( argc, argv, "bcn:rs:u:vh?" ) ) != -1 )
{
switch ( c )
{
@@ -249,6 +273,18 @@ int main( int argc, char *argv[] )
read_raw = 1;
break;
+ case 's':
+ sleep_secs = atoi( optarg );
+ break;
+
+ case 'u':
+ sleep_usecs = atoi( optarg );
+ break;
+
+ case 'v':
+ verbose++;
+ break;
+
case 'h':
case '?':
default:
diff --git a/mbgirigcfg/Makefile b/mbgirigcfg/Makefile
index fbeb4b5..7779939 100755
--- a/mbgirigcfg/Makefile
+++ b/mbgirigcfg/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.5.1.2 2010/08/30 09:05:23 martin TEST $
+# $Id: Makefile 1.5.1.3 2011/09/26 16:04:01 martin TEST $
#
# Description:
# Makefile for mbgirigcfg.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.5.1.3 2011/09/26 16:04:01 martin
+# Updated for use with latest base Makefile.
# Revision 1.5.1.2 2010/08/30 09:05:23 martin
# Revision 1.5.1.1 2010/08/30 08:21:45 martin
# Revision 1.5 2009/07/24 10:31:17 martin
@@ -24,7 +26,7 @@
#########################################################################
TARGET = mbgirigcfg
-INST_DIR = /usr/local/sbin
+INST_TO_SBIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbgirigcfg/mbgirigcfg.c b/mbgirigcfg/mbgirigcfg.c
index cd3993b..9751a4b 100755
--- a/mbgirigcfg/mbgirigcfg.c
+++ b/mbgirigcfg/mbgirigcfg.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgirigcfg.c 1.10.1.4 2011/02/02 12:28:44 martin TEST martin $
+ * $Id: mbgirigcfg.c 1.10.1.12 2011/07/19 12:59:06 martin TEST $
*
* Description:
* Main file for the mbgirigcfg program which can be used to configure
@@ -10,6 +10,20 @@
*
* -----------------------------------------------------------------------
* $Log: mbgirigcfg.c $
+ * Revision 1.10.1.12 2011/07/19 12:59:06 martin
+ * Revision 1.10.1.11 2011/07/07 15:08:35 martin
+ * Removed obsolete code.
+ * Revision 1.10.1.10 2011/07/06 14:53:50 martin
+ * Revision 1.10.1.9 2011/07/05 15:35:54 martin
+ * Modified version handling.
+ * Revision 1.10.1.8 2011/07/05 14:35:18 martin
+ * New way to maintain version information.
+ * Revision 1.10.1.7 2011/07/05 12:24:58 martin
+ * Revision 1.10.1.6 2011/07/04 10:30:29 martin
+ * Use getopt() for option processing.
+ * Support multiple devices.
+ * Revision 1.10.1.5 2011/07/01 13:49:47 martin
+ * bug fixes.
* Revision 1.10.1.4 2011/02/02 12:28:44 martin
* Revision 1.10.1.3 2010/08/30 08:22:24 martin
* Revision 1.10.1.2 2010/08/19 13:57:42 martin
@@ -60,11 +74,18 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <unistd.h>
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2003
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char pname[] = "mbgirigcfg";
-static const char pversion[] = "v3.4.0";
-static const char pcopyright[] = "(c) Meinberg 2003-2009";
+
+
+static int glb_argc;
+static char **glb_argv;
static const char str_yes[] = "YES";
static const char str_no[] = "NO";
@@ -80,9 +101,14 @@ static IRIG_INFO irig_tx_info;
static MBG_REF_OFFS ref_offs;
static MBG_OPT_INFO opt_info;
-static int cfg_err;
+static int cfg_err_rx;
+static int cfg_err_tx;
static int changed_cfg_rx;
static int changed_cfg_tx;
+static int warned_no_rx;
+static int warned_no_tx;
+
+static int must_print_help_info;
static const char *icode_rx_names[N_ICODE_RX] = DEFAULT_ICODE_RX_NAMES;
static const char *icode_rx_descr[N_ICODE_RX] = DEFAULT_ICODE_RX_DESCRIPTIONS_ENG;
@@ -94,7 +120,7 @@ static int max_ref_offs_h = MBG_REF_OFFS_MAX / MINS_PER_HOUR;
static /*HDR*/
-int get_cfg( MBG_DEV_HANDLE dh, PCPS_DEV *pdev )
+int get_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev )
{
int rc_rx = MBG_SUCCESS;
int rc_tx = MBG_SUCCESS;
@@ -132,7 +158,7 @@ int get_cfg( MBG_DEV_HANDLE dh, PCPS_DEV *pdev )
static /*HDR*/
-int save_cfg( MBG_DEV_HANDLE dh, PCPS_DEV *pdev )
+int save_cfg( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev )
{
int rc_rx = MBG_SUCCESS;
int rc_tx = MBG_SUCCESS;
@@ -174,7 +200,7 @@ void print_cfg_rx( const char *info, const char *msg )
int idx = irig_rx_info.settings.icode;
int ref_offs_h = ref_offs / MINS_PER_HOUR;
- printf( "%s %s:\n", info, msg );
+ printf( "%s %s configuration:\n", info, msg );
printf( " " DEFAULT_STR_IRIG_FMT_EN ": %s, %s\n",
icode_rx_names[idx],
@@ -206,7 +232,7 @@ void print_cfg_tx( const char *info, const char *msg )
{
int idx = irig_tx_info.settings.icode;
- printf( "%s %s:\n", info, msg );
+ printf( "%s %s configuration:\n", info, msg );
printf( " " DEFAULT_STR_IRIG_FMT_EN ": %s, %s\n",
icode_tx_names[idx],
@@ -227,15 +253,6 @@ void print_cfg_tx( const char *info, const char *msg )
static /*HDR*/
-void err_msg( PCPS_DEV *pdev, const char *msg )
-{
- printf( "The clock device %s %s.\n", _pcps_type_name( pdev ), msg );
-
-} // err_msg
-
-
-
-static /*HDR*/
void set_new_icode_rx( char *s )
{
int idx = atoi( s );
@@ -244,7 +261,7 @@ void set_new_icode_rx( char *s )
{
printf( "** IRIG RX code index %i is out of range (0..%i).\n",
idx, N_ICODE_RX - 1 );
- cfg_err = 1;
+ cfg_err_rx = 1;
return;
}
@@ -257,7 +274,7 @@ void set_new_icode_rx( char *s )
{
printf( "** IRIG RX code \"%s\" not supported by this device.\n",
icode_rx_names[idx] );
- cfg_err = 1;
+ cfg_err_rx = 1;
}
} // set_new_icode_rx
@@ -275,7 +292,7 @@ void set_new_ref_offs( char *s )
{
printf( "** New IRIG time offset %ih exceeds range (%+ih..%+ih).\n",
new_ref_offs_h, -max_ref_offs_h, max_ref_offs_h );
- cfg_err = 1;
+ cfg_err_rx = 1;
}
else
{
@@ -307,7 +324,7 @@ void set_new_str_utc( char *s )
this_cfg_err = 1;
if ( this_cfg_err )
- cfg_err = 1;
+ cfg_err_rx = 1;
else
changed_cfg_rx = 1;
@@ -324,7 +341,7 @@ void set_new_icode_tx( char *s )
{
printf( "** IRIG TX code index %i is out of range (0..%i).\n",
idx, N_ICODE_TX - 1 );
- cfg_err = 1;
+ cfg_err_tx = 1;
return;
}
@@ -337,7 +354,7 @@ void set_new_icode_tx( char *s )
{
printf( "** IRIG TX code \"%s\" not supported by this device.\n",
icode_tx_names[idx] );
- cfg_err = 1;
+ cfg_err_tx = 1;
}
} // set_new_icode_tx
@@ -358,7 +375,7 @@ void set_new_irig_tx_local( char *s )
this_cfg_err = 1;
if ( this_cfg_err )
- cfg_err = 1;
+ cfg_err_tx = 1;
else
changed_cfg_tx = 1;
@@ -367,7 +384,7 @@ void set_new_irig_tx_local( char *s )
static /*HDR*/
-void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag )
+void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag, int *err_flag )
{
if ( !(_idx_bit( p->icode ) & MSK_ICODE_TX_HAS_TFOM ) )
return; // not supported
@@ -379,7 +396,10 @@ void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag )
if ( strcmp( s, "0" ) == 0 )
p->flags &= ~IFLAGS_DISABLE_TFOM;
else
- cfg_err = 1;
+ {
+ *err_flag = 1;
+ return;
+ }
*changed_flag = 1;
@@ -390,14 +410,21 @@ void set_new_tfom_flag( char *s, IRIG_SETTINGS *p, int *changed_flag )
static /*HDR*/
int chk_dev_rx( const PCPS_DEV *pdev )
{
- if ( !_pcps_is_irig_rx( pdev ) )
+ if ( pdev )
{
- printf( "** This device is no IRIG receiver.\n" );
- cfg_err = 1;
- return 0;
+ if ( _pcps_is_irig_rx( pdev ) )
+ return 1;
+
+ if ( !warned_no_rx )
+ {
+ printf( "** This device does not provide an IRIG input.\n" );
+ warned_no_rx = 1;
+ }
+
+ cfg_err_rx = 1;
}
- return 1;
+ return 0;
} // chk_dev_rx
@@ -406,14 +433,21 @@ int chk_dev_rx( const PCPS_DEV *pdev )
static /*HDR*/
int chk_dev_tx( const PCPS_DEV *pdev )
{
- if ( !_pcps_has_irig_tx( pdev ) )
+ if ( pdev )
{
- printf( "** This device has no IRIG transmitter.\n" );
- cfg_err = 1;
- return 0;
+ if ( _pcps_has_irig_tx( pdev ) )
+ return 1;
+
+ if ( !warned_no_tx )
+ {
+ printf( "** This device does not provide an IRIG output.\n" );
+ warned_no_tx = 1;
+ }
+
+ cfg_err_tx = 1;
}
- return 1;
+ return 0;
} // chk_dev_tx
@@ -422,90 +456,62 @@ int chk_dev_tx( const PCPS_DEV *pdev )
static /*HDR*/
void check_cmd_line( int argc, char *argv[], const PCPS_DEV *pdev )
{
- int i;
+ int c;
+
+ // force checking all parameters since this may be called several times
+ optind = 1;
- for ( i = 1; i < argc; i++ )
+ while ( ( c = getopt( argc, argv, "h?" "r:o:u:i:" "t:l:s:" ) ) != -1 )
{
- if ( strcmp( argv[i], "-?" ) == 0 )
+ switch ( c )
{
- must_print_usage = 1;
- continue;
- }
+ case '?':
+ case 'h':
+ must_print_usage = 1;
+ break;
- if ( strcmp( argv[i], "-h" ) == 0 )
- {
- must_print_usage = 1;
- continue;
- }
- if ( strcmp( argv[i], "--help" ) == 0 )
- {
- must_print_usage = 1;
- continue;
- }
+ // IRIG receiver options
- if ( strcmp( argv[i], "-r" ) == 0 ) // IRIG RX code frame
- {
- if ( ++i < argc )
+ case 'r': // IRIG RX code frame
if ( chk_dev_rx( pdev ) )
- set_new_icode_rx( argv[i] );
-
- continue;
- }
+ set_new_icode_rx( optarg );
+ break;
- if ( strcmp( argv[i], "-o" ) == 0 ) // IRIG time offset from UTC
- {
- if ( ++i < argc )
+ case 'o': // incoming time offset from UTC
if ( chk_dev_rx( pdev ) )
- set_new_ref_offs( argv[i] );
-
- continue;
- }
+ set_new_ref_offs( optarg );
+ break;
- if ( strcmp( argv[i], "-u" ) == 0 ) // Option flag: serial output always UTC
- {
- if ( ++i < argc )
+ case 'u': // option flag: serial output is always UTC
if ( chk_dev_rx( pdev ) )
- set_new_str_utc( argv[i] );
+ set_new_str_utc( optarg );
+ break;
- continue;
- }
+ case 'i': // option flag: ignore incoming TFOM flag, alway sync
+ if ( chk_dev_rx( pdev ) )
+ set_new_tfom_flag( optarg, &irig_rx_info.settings, &changed_cfg_rx, &cfg_err_rx );
+ break;
- if ( strcmp( argv[i], "-t" ) == 0 ) // IRIG TX code frame
- {
- if ( ++i < argc )
- if ( chk_dev_tx( pdev ) )
- set_new_icode_tx( argv[i] );
- continue;
- }
+ // IRIG output options
- if ( strcmp( argv[i], "-l" ) == 0 ) // Option flag: transmit local time, not UTC
- {
- if ( ++i < argc )
+ case 't': // IRIG TX code frame
if ( chk_dev_tx( pdev ) )
- set_new_irig_tx_local( argv[i] );
+ set_new_icode_tx( optarg );
+ break;
- continue;
- }
-
- if ( strcmp( argv[i], "-s" ) == 0 ) // Option flag: send TFOM as always "sync"
- {
- if ( ++i < argc )
+ case 'l': // option flag: transmit local time, not UTC
if ( chk_dev_tx( pdev ) )
- set_new_tfom_flag( argv[i], &irig_tx_info.settings, &changed_cfg_tx );
-
- continue;
- }
+ set_new_irig_tx_local( optarg );
+ break;
- if ( strcmp( argv[i], "-i" ) == 0 ) // Option flag: ignore incoming TFOM flag, alway sync
- {
- if ( ++i < argc )
- if ( chk_dev_rx( pdev ) )
- set_new_tfom_flag( argv[i], &irig_rx_info.settings, &changed_cfg_rx );
+ case 's': // option flag: send TFOM as always "sync"
+ if ( chk_dev_tx( pdev ) )
+ set_new_tfom_flag( optarg, &irig_tx_info.settings, &changed_cfg_tx, &cfg_err_tx );
+ break;
- continue;
- }
+ } // switch
}
@@ -526,7 +532,7 @@ void usage( void )
);
printf(
- " -h or --help prints this info\n"
+ " -h or -? prints this info\n"
"\n"
);
@@ -562,6 +568,13 @@ void usage( void )
"\n"
);
+ printf(
+ " -i flag If \"flag\" is set to \"1\" then the TFOM qualifier in the\n"
+ " incoming IRIG signal is ignored, i.e. the receiver even synchronizes\n"
+ " to an input signal if the TFOM codes says the generator is freewheeling.\n"
+ " Please note that most IRIG codes do not support a TFOM qualifier.\n"
+ "\n"
+ );
printf(
"Options supported by IRIG transmitters:\n"
@@ -604,65 +617,30 @@ void usage( void )
static /*HDR*/
-void help_info( void )
-{
- printf( "\nFor help type \"%s -h\"\n", pname );
-
-} // help_info
-
-
-
-static /*HDR*/
int do_mbgirigcfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
{
- const char *no_irig = "is not an IRIG code receiver";
- PCPS_DEV dev = { { 0 } };
- int exit_code = 0;
- int rc = 0;
+ int rc = MBG_SUCCESS;
- {
- // if success, read the current IRIG configuration
- if ( rc == MBG_SUCCESS )
- rc = get_cfg( dh, &dev );
- }
-
-
-// check_cmd_line( argc, argv, &dev );
+ cfg_err_rx = 0;
+ cfg_err_tx = 0;
+ changed_cfg_rx = 0;
+ changed_cfg_tx = 0;
+ warned_no_rx = 0;
+ warned_no_tx = 0;
+ rc = get_cfg( dh, p_dev );
- if ( cfg_err )
+ if ( !_pcps_has_irig( p_dev ) )
{
- help_info();
- exit_code = 1;
- goto done;
+ printf( "** This device does not provide an IRIG input or output.\n" );
+ must_print_help_info = 1;
+ return rc;
}
+ check_cmd_line( glb_argc, glb_argv, p_dev );
- // At this point we shall either report or modify the current
- // configuration. If there has been an error accessing the
- // device, or the device is not an IRIG receiver, then we must
- // print a message.
-
- if ( dh == MBG_INVALID_DEV_HANDLE )
- {
- printf( "** Error opening the device.\n" );
- exit_code = 3;
- goto done;
- }
-
- if ( rc != MBG_SUCCESS )
- {
- exit_code = 3;
- goto done;
- }
-
- if ( !_pcps_has_irig( &dev ) )
- {
- err_msg( &dev, no_irig );
- exit_code = 2;
- goto done;
- }
-
+ if ( cfg_err_rx || cfg_err_tx )
+ must_print_help_info = 1;
if ( changed_cfg_rx || changed_cfg_tx )
{
@@ -673,29 +651,24 @@ int do_mbgirigcfg( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
if ( changed_cfg_tx )
print_cfg_tx( info_new, msg_tx );
- rc = save_cfg( dh, &dev );
+ rc = save_cfg( dh, p_dev );
if ( mbg_ioctl_err( rc, "save IRIG configuration" ) )
- exit_code = 3;
+ goto done;
}
else
{
- if ( _pcps_is_irig_rx( &dev ) )
+ if ( _pcps_is_irig_rx( p_dev ) )
print_cfg_rx( info_curr, msg_rx );
- if ( _pcps_has_irig_tx( &dev ) )
+ if ( _pcps_has_irig_tx( p_dev ) )
print_cfg_tx( info_curr, msg_tx );
- help_info();
+ must_print_help_info = 1;
}
done:
- printf( "\n" );
-
- if ( dh != MBG_INVALID_DEV_HANDLE )
- mbg_close_device( &dh );
-
- return exit_code;
+ return rc;
} // do_mbgirigcfg
@@ -705,7 +678,7 @@ int main( int argc, char *argv[] )
{
int rc;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
check_cmd_line( argc, argv, NULL );
@@ -716,13 +689,19 @@ int main( int argc, char *argv[] )
}
+ glb_argc = argc;
+ glb_argv = argv;
+
+
// The function below checks which devices have been specified
// on the command, and for each device
// - tries to open the device
// - shows basic device info
// - calls the function passed as last parameter
- //##+++++++++++ rc = mbg_check_devices( argc, argv, optind, do_mbgirigcfg );
- rc = mbg_check_devices( argc, argv, 0, do_mbgirigcfg );
+ rc = mbg_check_devices( glb_argc, glb_argv, optind, do_mbgirigcfg );
+
+ if ( must_print_help_info )
+ printf( "For help type \"%s -h\"\n\n", pname );
return abs( rc );
}
diff --git a/mbglib/common/cfg_hlp.h b/mbglib/common/cfg_hlp.h
new file mode 100755
index 0000000..9706dba
--- /dev/null
+++ b/mbglib/common/cfg_hlp.h
@@ -0,0 +1,115 @@
+
+/**************************************************************************
+ *
+ * $Id: cfg_hlp.h 1.1 2011/09/21 15:59:59 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Definitions and prototypes for configuration programs.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: cfg_hlp.h $
+ * Revision 1.1 2011/09/21 15:59:59 martin
+ * Initial revision.
+ *
+ **************************************************************************/
+
+#ifndef _CFG_HLP_H
+#define _CFG_HLP_H
+
+
+/* Other headers to be included */
+
+#include <gpsdefs.h>
+
+
+#ifdef _CFG_HLP
+ #define _ext
+ #define _DO_INIT
+#else
+ #define _ext extern
+#endif
+
+
+/* Start of header body */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*
+ * The definitions and types below are used to collect
+ * all configuration parameters of a clock's serial ports
+ * that can be handled by this library:
+ */
+
+
+/*
+ * The maximum number of clocks' serial ports and string types
+ * that can be handled by the configuration programs.
+ * WARNING: Changing these constants affects the size of the
+ * structures ALL_PORT_INFO ALL_STR_TYPE_INFO
+ */
+#define MAX_PARM_PORT 4
+#define MAX_PARM_STR_TYPE 20
+
+typedef PORT_INFO_IDX ALL_PORT_INFO[MAX_PARM_PORT];
+typedef STR_TYPE_INFO_IDX ALL_STR_TYPE_INFO[MAX_PARM_STR_TYPE];
+
+typedef struct
+{
+ ALL_PORT_INFO pii;
+ ALL_STR_TYPE_INFO stii;
+ PORT_PARM tmp_pp;
+
+} RECEIVER_PORT_CFG;
+
+
+/*
+ * The definitions and types below are used to collect
+ * all configuration parameters of a clock's programmable
+ * pulse outputs that can be handled by this library:
+ */
+
+#define MAX_PARM_POUT 4
+
+typedef POUT_INFO_IDX ALL_POUT_INFO[MAX_PARM_POUT];
+
+
+
+/*
+ * The definitions and types below are used to collect
+ * all configuration parameters of PTP device's unicast
+ * master specification:
+ */
+
+#define MAX_PARM_PTP_UC_MASTER 3
+
+typedef PTP_UC_MASTER_INFO_IDX ALL_PTP_UC_MASTER_INFO[MAX_PARM_PTP_UC_MASTER];
+
+
+
+
+/* function prototypes: */
+
+/* ----- function prototypes begin ----- */
+
+/* This section was generated automatically */
+/* by MAKEHDR, do not remove the comments. */
+
+
+/* ----- function prototypes end ----- */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* End of header body */
+
+#undef _ext
+#undef _DO_INIT
+
+#endif /* _CFG_HLP_H */
diff --git a/mbglib/common/ctry.h b/mbglib/common/ctry.h
index 9c39a28..189d1a5 100755
--- a/mbglib/common/ctry.h
+++ b/mbglib/common/ctry.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: ctry.h 1.11 2010/07/15 08:33:41 martin REL_M $
+ * $Id: ctry.h 1.12 2011/06/22 07:37:57 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,12 +10,13 @@
*
* -----------------------------------------------------------------------
* $Log: ctry.h $
+ * Revision 1.12 2011/06/22 07:37:57 martin
+ * Cleaned up handling of pragma pack().
* Revision 1.11 2010/07/15 08:33:41 martin
* Added some macros implemented by Stefan.
* Updated function prototypes.
* Revision 1.10 2007/03/29 12:21:10 martin
* Updated function prototypes.
- * Revision 1.1 2010/06/01 07:57:04 philipp
* Revision 1.9 2004/10/26 07:38:50Z martin
* Redefined interface data types using C99 fixed-size definitions.
* Updated function prototypes.
@@ -76,8 +77,9 @@
/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
#endif
@@ -220,8 +222,9 @@ extern CTRY ctry;
#endif
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/deviohlp.c b/mbglib/common/deviohlp.c
new file mode 100755
index 0000000..b101460
--- /dev/null
+++ b/mbglib/common/deviohlp.c
@@ -0,0 +1,260 @@
+
+/**************************************************************************
+ *
+ * $Id: deviohlp.c 1.1.1.4 2011/09/21 14:45:24 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Device configuration helper functions. This is an extension to
+ * mbgdevio.c providing useful functions to simplify reading/writing
+ * complex device configuration structure sets.
+ *
+ * Warning:
+ * These functions should not be implemented in a DLL / shared library
+ * since the parameter sizes might vary with different versions
+ * of the API calls, which which would make different versions of
+ * precompiled libraries incompatible to each other.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: deviohlp.c $
+ * Revision 1.1.1.4 2011/09/21 14:45:24 martin
+ * Moved mbgextio support functions to new module extiohlp.c.
+ * Revision 1.1.1.3 2011/09/20 15:36:02 marvin
+ * new functions:
+ * mbg_get_serial_settings
+ * mbg_set_serial_settings
+ * include mbgextio.h
+ * Revision 1.1.1.2 2011/08/05 10:30:28 martin
+ * Revision 1.1.1.1 2011/08/05 09:55:52 martin
+ * Revision 1.1 2011/08/03 15:37:00Z martin
+ * Initial revision with functions moved here from mbgdevio.
+ *
+ **************************************************************************/
+
+#define _DEVIOHLP
+ #include <deviohlp.h>
+#undef _DEVIOHLP
+
+#include <parmpcps.h>
+#include <parmgps.h>
+
+
+
+/*HDR*/
+/**
+ Read all serial port settings and supported configuration parameters.
+
+ The functions mbg_get_device_info() and mbg_setup_receiver_info()
+ must have been called before, and the returned ::PCPS_DEV and
+ ::RECEIVER_INFO structures must be passed to this function.
+
+ The complementary function mbg_save_serial_settings() should be used
+ to write the modified serial port configuration back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pdev Pointer to a ::PCPS_DEV structure.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+ @see mbg_save_serial_settings()
+*/
+int mbg_get_serial_settings( MBG_DEV_HANDLE dh,
+ const PCPS_DEV *pdev,
+ RECEIVER_PORT_CFG *pcfg,
+ const RECEIVER_INFO *p_ri )
+{
+ int rc;
+ int i;
+
+ memset( pcfg, 0, sizeof( *pcfg ) );
+
+ if ( _pcps_has_receiver_info( pdev ) )
+ {
+ rc = mbg_get_gps_all_port_info( dh, pcfg->pii, p_ri );
+ if ( rc != MBG_SUCCESS )
+ goto error;
+
+ rc = mbg_get_gps_all_str_type_info( dh, pcfg->stii, p_ri );
+ if ( rc != MBG_SUCCESS )
+ goto error;
+ }
+ else
+ {
+ if ( _pcps_is_gps( pdev ) )
+ {
+ rc = mbg_get_gps_port_parm( dh, &pcfg->tmp_pp );
+ if ( rc != MBG_SUCCESS )
+ goto error;
+
+ for ( i = 0; i < p_ri->n_com_ports; i++ )
+ {
+ PORT_INFO_IDX *p_pii = &pcfg->pii[i];
+ PORT_INFO *p_pi = &p_pii->port_info;
+
+ p_pii->idx = i;
+ port_settings_from_port_parm( &p_pi->port_settings,
+ i, &pcfg->tmp_pp, 1 );
+
+ p_pi->supp_baud_rates = DEFAULT_GPS_BAUD_RATES_C166;
+ p_pi->supp_framings = DEFAULT_GPS_FRAMINGS_C166;
+ p_pi->supp_str_types = DEFAULT_SUPP_STR_TYPES_GPS;
+ }
+ }
+ else
+ if ( _pcps_has_serial ( pdev ) ) // Not all non-GPS clocks have a serial port!
+ {
+ PCPS_SERIAL ser_code;
+
+ rc = mbg_get_serial( dh, &ser_code );
+ if ( rc != MBG_SUCCESS )
+ goto error;
+
+
+ port_info_from_pcps_serial( pcfg->pii, ser_code,
+ _pcps_has_serial_hs( pdev ) ?
+ DEFAULT_BAUD_RATES_DCF_HS :
+ DEFAULT_BAUD_RATES_DCF
+ );
+ }
+
+ for ( i = 0; i < p_ri->n_str_type; i++ )
+ {
+ STR_TYPE_INFO_IDX *stip = &pcfg->stii[i];
+ stip->idx = i;
+ stip->str_type_info = default_str_type_info[i];
+ }
+ }
+
+ return MBG_SUCCESS;
+
+
+error:
+ return rc;
+
+} // mbg_get_serial_settings
+
+
+
+/*HDR*/
+/**
+ Write the configuration settings for a single serial port to the board.
+
+ Modifications to the serial port configuration should be made only
+ after mbg_get_serial_settings() had been called to read all serial port
+ settings and supported configuration parameters.
+ This function has finally to be called once for every serial port
+ the configuration of which has been modified.
+
+ As also required by mbg_get_serial_settings(), the functions
+ mbg_get_device_info() and mbg_setup_receiver_info() must have been
+ called before, and the returned ::PCPS_DEV and ::RECEIVER_INFO structures
+ must be passed to this function.
+
+ @param dh Valid handle to a Meinberg device
+ @param *pdev Pointer to a ::PCPS_DEV structure
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
+ @param port_num Index of the ::serial port to be saved
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_serial_settings()
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+*/
+int mbg_save_serial_settings( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev,
+ RECEIVER_PORT_CFG *pcfg, int port_num )
+{
+ int rc;
+
+ if ( _pcps_has_receiver_info( pdev ) )
+ {
+ rc = mbg_set_gps_port_settings( dh, &pcfg->pii[port_num].port_info.port_settings, port_num );
+ }
+ else
+ {
+ if ( _pcps_is_gps( pdev ) )
+ {
+ port_parm_from_port_settings( &pcfg->tmp_pp, port_num,
+ &pcfg->pii[port_num].port_info.port_settings, 1 );
+
+ rc = mbg_set_gps_port_parm( dh, &pcfg->tmp_pp );
+ }
+ else
+ {
+ PCPS_SERIAL ser_code;
+
+ pcps_serial_from_port_info( &ser_code, pcfg->pii );
+
+ rc = mbg_set_serial( dh, &ser_code );
+ }
+ }
+
+ return rc;
+
+} // mbg_save_serial_settings
+
+
+
+/*HDR*/
+/**
+ Read all serial port settings and supported configuration parameters.
+
+ The functions mbg_get_device_info() and mbg_setup_receiver_info()
+ must have been called before, and the returned ::PCPS_DEV and
+ ::RECEIVER_INFO structures must be passed to this function.
+
+ The complementary function mbg_save_serial_settings() should be used
+ to write the modified serial port configuration back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pdev Pointer to a ::PCPS_DEV structure.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+ @see mbg_save_serial_settings()
+*/
+int mbg_get_all_ptp_cfg_info( MBG_DEV_HANDLE dh, ALL_PTP_CFG_INFO *p )
+{
+ int rc = MBG_SUCCESS;
+
+ memset( p, 0, sizeof( *p ) );
+
+ rc = mbg_get_ptp_cfg_info( dh, &p->ptp_cfg_info );
+
+ if ( rc < 0 )
+ return rc;
+
+ if ( p->ptp_cfg_info.supp_flags & PTP_CFG_MSK_SUPPORT_PTP_UNICAST )
+ {
+ rc = mbg_get_ptp_uc_master_cfg_limits( dh, &p->ptp_uc_master_cfg_limits );
+
+ if ( rc < 0 )
+ return rc;
+
+ if ( p->ptp_uc_master_cfg_limits.n_supp_master > MAX_PARM_PTP_UC_MASTER )
+ {
+ // The number of PTP unicast masters supported by this device
+ // exceeds the number of unicast masters supporterd by this driver.
+ return MBG_ERR_N_UC_MSTR_EXCEEDS_SUPP;
+ }
+
+ rc = mbg_get_all_ptp_uc_master_info( dh, p->all_ptp_uc_master_info,
+ &p->ptp_uc_master_cfg_limits );
+ if ( rc < 0 )
+ return rc;
+ }
+
+ return MBG_SUCCESS;
+
+} // mbg_get_all_ptp_cfg_info
+
+
diff --git a/mbglib/common/deviohlp.h b/mbglib/common/deviohlp.h
new file mode 100755
index 0000000..158f549
--- /dev/null
+++ b/mbglib/common/deviohlp.h
@@ -0,0 +1,156 @@
+
+/**************************************************************************
+ *
+ * $Id: deviohlp.h 1.1.1.5 2011/09/21 16:00:22 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Definitions and prototypes for deviohlp.c.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: deviohlp.h $
+ * Revision 1.1.1.5 2011/09/21 16:00:22 martin
+ * Revision 1.1.1.4 2011/09/21 14:44:50 martin
+ * Updated function prototypes.
+ * Revision 1.1.1.3 2011/09/20 15:36:03 marvin
+ * new functions:
+ * mbg_get_serial_settings
+ * mbg_set_serial_settings
+ * include mbgextio.h
+ * Revision 1.1.1.2 2011/08/05 10:30:28 martin
+ * Revision 1.1.1.1 2011/08/05 09:55:58 martin
+ * Revision 1.1 2011/08/03 15:36:44Z martin
+ * Initial revision with functions moved here from mbgdevio.
+ *
+ **************************************************************************/
+
+#ifndef _DEVIOHLP_H
+#define _DEVIOHLP_H
+
+
+/* Other headers to be included */
+
+#include <mbgdevio.h>
+#include <cfg_hlp.h>
+
+
+#ifdef _DEVIOHLP
+ #define _ext
+ #define _DO_INIT
+#else
+ #define _ext extern
+#endif
+
+
+/* Start of header body */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct
+{
+ PTP_CFG_INFO ptp_cfg_info;
+ PTP_UC_MASTER_CFG_LIMITS ptp_uc_master_cfg_limits;
+ ALL_PTP_UC_MASTER_INFO all_ptp_uc_master_info;
+
+} ALL_PTP_CFG_INFO;
+
+
+
+/* function prototypes: */
+
+/* ----- function prototypes begin ----- */
+
+/* This section was generated automatically */
+/* by MAKEHDR, do not remove the comments. */
+
+ /**
+ Read all serial port settings and supported configuration parameters.
+
+ The functions mbg_get_device_info() and mbg_setup_receiver_info()
+ must have been called before, and the returned ::PCPS_DEV and
+ ::RECEIVER_INFO structures must be passed to this function.
+
+ The complementary function mbg_save_serial_settings() should be used
+ to write the modified serial port configuration back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pdev Pointer to a ::PCPS_DEV structure.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+ @see mbg_save_serial_settings()
+*/
+ int mbg_get_serial_settings( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, RECEIVER_PORT_CFG *pcfg, const RECEIVER_INFO *p_ri ) ;
+
+ /**
+ Write the configuration settings for a single serial port to the board.
+
+ Modifications to the serial port configuration should be made only
+ after mbg_get_serial_settings() had been called to read all serial port
+ settings and supported configuration parameters.
+ This function has finally to be called once for every serial port
+ the configuration of which has been modified.
+
+ As also required by mbg_get_serial_settings(), the functions
+ mbg_get_device_info() and mbg_setup_receiver_info() must have been
+ called before, and the returned ::PCPS_DEV and ::RECEIVER_INFO structures
+ must be passed to this function.
+
+ @param dh Valid handle to a Meinberg device
+ @param *pdev Pointer to a ::PCPS_DEV structure
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
+ @param port_num Index of the ::serial port to be saved
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_serial_settings()
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+*/
+ int mbg_save_serial_settings( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, RECEIVER_PORT_CFG *pcfg, int port_num ) ;
+
+ /**
+ Read all serial port settings and supported configuration parameters.
+
+ The functions mbg_get_device_info() and mbg_setup_receiver_info()
+ must have been called before, and the returned ::PCPS_DEV and
+ ::RECEIVER_INFO structures must be passed to this function.
+
+ The complementary function mbg_save_serial_settings() should be used
+ to write the modified serial port configuration back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pdev Pointer to a ::PCPS_DEV structure.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_get_device_info()
+ @see mbg_setup_receiver_info()
+ @see mbg_save_serial_settings()
+*/
+ int mbg_get_all_ptp_cfg_info( MBG_DEV_HANDLE dh, ALL_PTP_CFG_INFO *p ) ;
+
+
+/* ----- function prototypes end ----- */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* End of header body */
+
+#undef _ext
+#undef _DO_INIT
+
+#endif /* _DEVIOHLP_H */
diff --git a/mbglib/common/extiohlp.c b/mbglib/common/extiohlp.c
new file mode 100755
index 0000000..ffcd1e2
--- /dev/null
+++ b/mbglib/common/extiohlp.c
@@ -0,0 +1,119 @@
+
+/**************************************************************************
+ *
+ * $Id: extiohlp.c 1.1 2011/09/21 15:59:59 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Device configuration helper functions. This is an extension to
+ * mbgextio.c providing useful functions to simplify reading/writing
+ * complex device configuration structure sets.
+ *
+ * Warning:
+ * These functions should not be implemented in a DLL / shared library
+ * since the parameter sizes might vary with different versions
+ * of the API calls, which which would make different versions of
+ * precompiled libraries incompatible to each other.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: extiohlp.c $
+ * Revision 1.1 2011/09/21 15:59:59 martin
+ * Initial revision.
+ *
+ **************************************************************************/
+
+#define _EXTIOHLP
+ #include <extiohlp.h>
+#undef _EXTIOHLP
+
+#include <mbgerror.h> //##++ Do we need this ??
+
+/*HDR*/
+/**
+ Read all serial port settings and supported configuration parameters.
+ from a non bus level device
+
+ The function mbgextio_get_receiver_info()
+ must have been called before, and the returned ::RECEIVER_INFO
+ structures must be passed to this function.
+
+ The complementary function mbgextio_save_serial_settings() should be used
+ to write the modified serial port configuration via serial connection back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbgextio_get_receiver_info()
+ @see mbgextio_save_serial_settings()
+*/
+int mbgextio_get_serial_settings( MBG_MSG_CTL *dh, RECEIVER_PORT_CFG *pcfg, const RECEIVER_INFO *p_ri )
+{
+ int rc;
+ uint16_t i;
+
+ memset( pcfg, 0, sizeof( *pcfg ) );
+
+ for ( i = 0; i < p_ri->n_com_ports; i++ )
+ {
+ rc = mbgextio_get_port_info_idx( dh, &pcfg->pii[i], i );
+ if ( rc < 0 )
+ return rc;
+ }
+ for ( i = 0; i < p_ri->n_str_type; i++ )
+ {
+ rc = mbgextio_get_str_type_info_idx( dh, &pcfg->stii[i], i );
+ if ( rc < 0 )
+ return rc;
+ }
+
+ return TR_COMPLETE; // success -> mbgextio -> TR_COMPLETE = 2 //##+++++ marvin
+}
+
+
+
+/*HDR*/
+/**
+ Write the configuration settings for a single serial port via serial connection to the board.
+
+ Modifications to the serial port configuration should be made only
+ after mbgextio_get_serial_settings() had been called to read all serial port
+ settings and supported configuration parameters.
+ This function has finally to be called once for every serial port
+ the configuration of which has been modified.
+
+ As also required by mbgextio_get_serial_settings(), the function
+ mbgextio_get_receiver_info() must have been
+ called before, and the returned ::RECEIVER_INFO structure
+ must be passed to this function.
+
+ @param dh Valid handle to a Meinberg device via serial connection
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
+ @param port_num Index of the ::serial port to be saved
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbgextio_get_serial_settings()
+ @see mbgextio_get_receiver_info()
+*/
+int mbgextio_save_serial_settings( MBG_MSG_CTL *dh, RECEIVER_PORT_CFG *pcfg, int port_num )
+{
+ int rc;
+
+ rc = mbgextio_set_port_settings_idx( dh, &pcfg->pii[port_num].port_info.port_settings, port_num );
+
+ if ( rc != 0 ) //##++++++++++++++++++
+ return !MBG_SUCCESS;
+
+/* rc = mbgextio_get_str_type_info_idx( dh, &pcfg->stii[i], i );
+ if(rc != 0)
+ return !MBG_SUCCESS;
+ */
+
+ return 0; // success
+
+} //mbgextio_save_serial_settings
+
diff --git a/mbglib/common/extiohlp.h b/mbglib/common/extiohlp.h
new file mode 100755
index 0000000..c0c707a
--- /dev/null
+++ b/mbglib/common/extiohlp.h
@@ -0,0 +1,114 @@
+
+/**************************************************************************
+ *
+ * $Id: extiohlp.h 1.1 2011/09/21 15:59:59 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Definitions and prototypes for extiohlp.c.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: extiohlp.h $
+ * Revision 1.1 2011/09/21 15:59:59 martin
+ * Initial revision.
+ *
+ **************************************************************************/
+
+#ifndef _EXTIOHLP_H
+#define _EXTIOHLP_H
+
+
+/* Other headers to be included */
+
+#include <mbgextio.h>
+
+#include <cfg_hlp.h>
+
+
+#ifdef _EXTIOHLP
+ #define _ext
+ #define _DO_INIT
+#else
+ #define _ext extern
+#endif
+
+
+/* Start of header body */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+
+/* function prototypes: */
+
+/* ----- function prototypes begin ----- */
+
+/* This section was generated automatically */
+/* by MAKEHDR, do not remove the comments. */
+
+ /**
+ Read all serial port settings and supported configuration parameters.
+ from a non bus level device
+
+ The function mbgextio_get_receiver_info()
+ must have been called before, and the returned ::RECEIVER_INFO
+ structures must be passed to this function.
+
+ The complementary function mbgextio_save_serial_settings() should be used
+ to write the modified serial port configuration via serial connection back to the board.
+
+ @param dh Valid handle to a Meinberg device.
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbgextio_get_receiver_info()
+ @see mbgextio_save_serial_settings()
+*/
+ int mbgextio_get_serial_settings( MBG_MSG_CTL *dh, RECEIVER_PORT_CFG *pcfg, const RECEIVER_INFO *p_ri ) ;
+
+ /**
+ Write the configuration settings for a single serial port via serial connection to the board.
+
+ Modifications to the serial port configuration should be made only
+ after mbgextio_get_serial_settings() had been called to read all serial port
+ settings and supported configuration parameters.
+ This function has finally to be called once for every serial port
+ the configuration of which has been modified.
+
+ As also required by mbgextio_get_serial_settings(), the function
+ mbgextio_get_receiver_info() must have been
+ called before, and the returned ::RECEIVER_INFO structure
+ must be passed to this function.
+
+ @param dh Valid handle to a Meinberg device via serial connection
+ @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
+ @param port_num Index of the ::serial port to be saved
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbgextio_get_serial_settings()
+ @see mbgextio_get_receiver_info()
+*/
+ int mbgextio_save_serial_settings( MBG_MSG_CTL *dh, RECEIVER_PORT_CFG *pcfg, int port_num ) ;
+
+
+/* ----- function prototypes end ----- */
+
+#ifdef __cplusplus
+}
+#endif
+
+
+/* End of header body */
+
+#undef _ext
+#undef _DO_INIT
+
+#endif /* _EXTIOHLP_H */
diff --git a/mbglib/common/gpsdefs.h b/mbglib/common/gpsdefs.h
index 75510c5..77797c3 100755
--- a/mbglib/common/gpsdefs.h
+++ b/mbglib/common/gpsdefs.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: gpsdefs.h 1.91.1.19.1.10 2011/05/06 13:47:37 martin TRASH $
+ * $Id: gpsdefs.h 1.95 2011/10/04 09:35:41 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -13,57 +13,37 @@
*
* -----------------------------------------------------------------------
* $Log: gpsdefs.h $
- * Revision 1.91.1.19.1.10 2011/05/06 13:47:37 martin
- * Support PZF600PEX.
- * Revision 1.91.1.19.1.9 2011/04/21 15:01:35 martin
- * Revision 1.91.1.19.1.8 2011/04/21 12:29:14 martin
- * Revision 1.91.1.19.1.7 2011/04/21 11:30:11 martin
- * Revision 1.91.1.19.1.6 2011/04/21 11:09:43 martin
- * Revision 1.91.1.19.1.5 2011/04/20 16:08:42 martin
- * Revision 1.91.1.19.1.4 2011/04/19 15:26:03 martin
- * Cleanup.
- * Revision 1.91.1.19.1.3 2011/04/19 15:05:44 martin
- * PTP unicast cfg stuff ...
- * Revision 1.91.1.19.1.2 2011/04/19 13:08:32 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.91.1.19.1.1 2011/04/18 15:30:28 martin
- * Started PTP unicast
- * Revision 1.91.1.19 2011/04/18 13:43:57 martin
- * Doxygen changes.
- * Revision 1.91.1.18 2011/04/18 13:00:33 martin
- * Merged some modified comments from an older branch.
- * Revision 1.91.1.17 2011/04/13 15:34:07 martin
- * Added lots of comments in doxygen style.
- * Revision 1.91.1.16 2011/04/11 09:15:00 andre
- * Revision 1.91.1.15 2011/04/08 08:29:18Z andre
- * Revision 1.91.1.14 2011/04/08 08:10:31Z martin
- * Renamed .._INST_.. to .._INSTC_..
- * Moved flags XMRS_..._IS_EXTERNAL and XMRS_..._INSTC_EXCEEDED
- * to definitions for XMULTI_REF_STATUS::status.
- * Revision 1.91.1.13 2011/04/07 15:50:16 martin
- * Introduced XMULTI_REF_INSTANCES:
- * Converted some comments to Doxygen style.
- * Revision 1.91.1.12 2011/04/07 13:52:04 martin
- * Revision 1.91.1.11 2011/04/07 13:23:41 martin
- * Started to add GPIO support and configuration stuff.
- * Revision 1.91.1.10 2011/04/07 10:38:43 martin
- * Modified default string for PTP layer 2 protocol.
- * Revision 1.91.1.9 2011/04/07 10:29:36 martin
+ * Revision 1.95 2011/10/04 09:35:41 martin
+ * Added support for ESI180.
+ * Changed RECEIVER_INFO::flags bit GPS_10MHZ_DISBD to a RECEIVER_INFO::features bit.
+ * Support MULTI_REF_INTERNAL, MULTI_REF_LWR and MULTI_REF_PZF.
+ * Added MBG_GPIO_BITS structure and associated definitions.
+ * Revision 1.94 2011/08/25 07:42:43Z martin
+ * Fixed a bug in macro _mbg_swab_pout_settings() where the 16 bit timeout
+ * field was swapped using a macro for 32 bit types.
+ * Use shorter names for some PTP unicast master default values.
+ * Revision 1.93 2011/08/10 08:19:38Z martin
+ * New PORT_INFO and PORT_SETTINGS flag PORT_FLAG_PORT_INVISIBLE.
+ * Revision 1.92 2011/07/29 09:49:35 martin
+ * Support PZF180PEX, MGR180, MSF600, WWVB600, JJY600,
+ * GPS180HS, and GPS180AMC.
+ * Added receiver info features GPS_FEAT_PTP_UNICAST
+ * and GPS_FEAT_XMRS_MULT_INSTC.
+ * Added receiver info flag bit GPS_10MHZ_DISBD.
* Added initializers for PTP timescale names.
- * Revision 1.91.1.8 2011/02/23 15:11:23 martin
* New PTP_STATE flags bit PTP_FLAG_MSK_IS_UNICAST.
- * Revision 1.91.1.7 2011/02/23 15:05:54 martin
* Made unused PTP_STATE fields num_clients and num_masters reserved.
- * Revision 1.91.1.6 2011/02/23 14:47:22 martin
- * Removed trailing whitespace and hard tabs.
- * Revision 1.91.1.5 2011/02/23 13:17:06 daniel
- * Revision 1.91.1.4 2011/02/17 14:39:13Z daniel
* Account for different PTP roles.
- * Revision 1.91.1.3 2011/02/15 14:24:53 martin
- * Revision 1.91.1.2 2011/02/15 11:30:56 martin
- * New feature GPS_FEAT_PTP_UNICAST.
- * Revision 1.91.1.1 2011/02/15 10:54:28 daniel
- * Started to support configuration for PTP unicast.
+ * Added / renamed some definitions for PTP.
+ * Modified default string for PTP layer 2 protocol.
+ * Support PTP unicast configuration.
+ * Support GPIO configuration.
+ * Introduced XMULTI_REF_INSTANCES.
+ * Moved flags XMRS_..._IS_EXTERNAL and XMRS_..._INSTC_EXCEEDED
+ * to definitions for XMULTI_REF_STATUS::status.
+ * Some comments added, updated, and converted to doxygen style.
+ * Cleaned up handling of pragma pack().
+ * Removed trailing whitespace and hard tabs.
* Revision 1.91 2011/01/31 11:23:56Z martin
* Added model type name definitions for GPS180PEX and TCR180PEX.
* Introduced synthesizer mode for programmable outputs.
@@ -379,12 +359,13 @@
#endif
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
-#endif
+/* Start of header body */
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
+#endif
-/* Start of header body */
/* "magic" number */
#define MEINBERG_MAGIC 0x6AAC
@@ -611,7 +592,14 @@ enum
GPS_MODEL_GLN170,
GPS_MODEL_GPS180PEX,
GPS_MODEL_TCR180PEX,
- GPS_MODEL_PZF600PEX,
+ GPS_MODEL_PZF180PEX,
+ GPS_MODEL_MGR180,
+ GPS_MODEL_MSF600,
+ GPS_MODEL_WWVB600,
+ GPS_MODEL_JJY600,
+ GPS_MODEL_GPS180HS,
+ GPS_MODEL_GPS180AMC,
+ GPS_MODEL_ESI180,
N_GPS_MODEL
/* If new model codes are added then care must be taken
* to update the associated string initializers below
@@ -660,7 +648,14 @@ enum
#define GPS_MODEL_NAME_GLN170 "GLN170"
#define GPS_MODEL_NAME_GPS180PEX "GPS180PEX"
#define GPS_MODEL_NAME_TCR180PEX "TCR180PEX"
-#define GPS_MODEL_NAME_PZF600PEX "PZF600PEX"
+#define GPS_MODEL_NAME_PZF180PEX "PZF180PEX"
+#define GPS_MODEL_NAME_MGR180 "MGR180"
+#define GPS_MODEL_NAME_MSF600 "MSF600"
+#define GPS_MODEL_NAME_WWVB600 "WWVB600"
+#define GPS_MODEL_NAME_JJY600 "JJY600"
+#define GPS_MODEL_NAME_GPS180HS "GPS180HS"
+#define GPS_MODEL_NAME_GPS180AMC "GPS180AMC"
+#define GPS_MODEL_NAME_ESI180 "ESI180"
/*
@@ -705,7 +700,14 @@ enum
GPS_MODEL_NAME_GLN170, \
GPS_MODEL_NAME_GPS180PEX, \
GPS_MODEL_NAME_TCR180PEX, \
- GPS_MODEL_NAME_PZF600PEX \
+ GPS_MODEL_NAME_PZF180PEX, \
+ GPS_MODEL_NAME_MGR180, \
+ GPS_MODEL_NAME_MSF600, \
+ GPS_MODEL_NAME_WWVB600, \
+ GPS_MODEL_NAME_JJY600, \
+ GPS_MODEL_NAME_GPS180HS, \
+ GPS_MODEL_NAME_GPS180AMC, \
+ GPS_MODEL_NAME_ESI180 \
}
@@ -870,20 +872,24 @@ enum
GPS_FEAT_IRIG_RX, /**< has on-board IRIG input */
GPS_FEAT_LAN_IP4, /**< has LAN IPv4 interface */
GPS_FEAT_MULTI_REF, /**< has multiple input sources with priorities */
+
GPS_FEAT_RCV_TIMEOUT, /**< timeout after GPS reception has stopped */
- GPS_FEAT_IGNORE_LOCK, /**< supports "ignore lock", alternatively */
- /**< MBG_OPT_BIT_EMU_SYNC may be supported */
+ GPS_FEAT_IGNORE_LOCK, /**< supports "ignore lock", MBG_OPT_BIT_EMU_SYNC can be set alternatively */
GPS_FEAT_5_MHZ, /**< output 5 MHz rather than 100 kHz */
GPS_FEAT_XMULTI_REF, /**< has extended multiple input source configuration */
GPS_FEAT_OPT_SETTINGS, /**< supports MBG_OPT_SETTINGS */
GPS_FEAT_TIME_SCALE, /**< supports configurable time scale (UTC, TAI, GPS, ...) */
GPS_FEAT_IRIG_CTRL_BITS, /**< supports IRIG control bits */
GPS_FEAT_PTP, /**< has PTP support */
+
GPS_FEAT_NAV_ENGINE_SETTINGS, /**< supports navigation engine configuration */
GPS_FEAT_RAW_IRIG_DATA, /**< supports reading raw IRIG input data */
GPS_FEAT_RAW_IRIG_TIME, /**< supports reading decoded IRIG time */
GPS_FEAT_PTP_UNICAST, /**< has PTP Unicast support */
GPS_FEAT_GPIO, /**< has general purpose in/outputs */
+ GPS_FEAT_XMRS_MULT_INSTC, /**< multiple XMRS instances of the same ref type supported, @see XMRSF_BIT_MULT_INSTC_SUPP */
+ GPS_FEAT_10MHZ_DISBD, /**< 10 MHz output is always disabled */
+
N_GPS_FEATURE /**< the number of valid features */
};
@@ -910,7 +916,9 @@ enum
"Raw IRIG Data", \
"Raw IRIG Time", \
"PTP/IEEE1588 Unicast", \
- "General Purpose I/O" \
+ "General Purpose I/O", \
+ "Multiple XMRS instances", \
+ "10 MHz Output Disabled" \
}
@@ -939,6 +947,8 @@ enum
#define GPS_HAS_RAW_IRIG_TIME ( 1UL << GPS_FEAT_RAW_IRIG_TIME )
#define GPS_HAS_PTP_UNICAST ( 1UL << GPS_FEAT_PTP_UNICAST )
#define GPS_HAS_GPIO ( 1UL << GPS_FEAT_GPIO )
+#define GPS_HAS_XMRS_MULT_INSTC ( 1UL << GPS_FEAT_XMRS_MULT_INSTC )
+#define GPS_HAS_10MHZ_DISBD ( 1UL << GPS_FEAT_10MHZ_DISBD )
#define GPS_HAS_REF_OFFS GPS_HAS_IRIG_RX
@@ -964,6 +974,7 @@ enum
#define GPS_HAS_FPGA 0x0004 // device provides on-board FPGA
+
/*
* If the GPS_HAS_FPGA flag is set in RECEIVER_INFO::flags then the card
* provides an FPGA and the following information about the FPGA is available:
@@ -1621,7 +1632,7 @@ enum
/*
* The bit masks below can be used to determine which baud rates
* are supported by a serial port. This may vary between
- * different ports of the same radio clock since different
+ * different ports of the same device since different
* types of UART are used which must not necessarily support
* each baud rate:
*/
@@ -1674,7 +1685,7 @@ enum
/*
* The bit masks below can be used to determine which framings
* are supported by a serial port. This may vary between
- * different ports of the same radio clock since different
+ * different ports of the same device since different
* types of UART are used which must not necessarily support
* each framing type:
*/
@@ -1853,6 +1864,19 @@ typedef struct
}
+/**
+ * @brief Flags used with PORT_SETTINGS::flags and PORT_INFO::flags
+ */
+enum
+{
+ PORT_FLAG_BIT_PORT_INVISIBLE, /**< this port is used internally and should not be displayed by config apps */
+ N_PORT_FLAGS /**< the number of defined bits */
+};
+
+#define PORT_FLAG_PORT_INVISIBLE ( 1UL << PORT_FLAG_BIT_PORT_INVISIBLE )
+
+
+
/*
* The structure below adds an index number to the structure
* above to allow addressing of several instances:
@@ -2943,7 +2967,7 @@ typedef struct
int i; \
_mbg_swab16( &(_p)->mode ); \
_mbg_swab16( &(_p)->pulse_len ); \
- _mbg_swab32( &(_p)->timeout ); \
+ _mbg_swab16( &(_p)->timeout ); \
_mbg_swab16( &(_p)->flags ); \
\
for ( i = 0; i < N_POUT_TIMES; i++ ) \
@@ -3191,6 +3215,9 @@ enum
MULTI_REF_FREQ, /**< fixed frequency */
MULTI_REF_PPS_STRING, /**< PPS in addition to string */
MULTI_REF_GPIO, /**< variable input signal via GPIO */
+ MULTI_REF_INTERNAL, /**< reserved, used internally by firmware only */
+ MULTI_REF_PZF, /**< DCF77 PZF providing much more accuracy than a standard LWR */
+ MULTI_REF_LWR, /**< long wave receiver. e.g. DCF77 AM, WWVB, MSF, JJY */
N_MULTI_REF /**< the number of defined sources, can not exceed bit number of uint32_t - 1 */
};
@@ -3210,7 +3237,10 @@ enum
"PTP over E1", \
"Fixed Freq. in", \
"PPS plus string", \
- "Var. freq. via GPIO" \
+ "Var. freq. via GPIO", \
+ "(reserved)", \
+ "DCF77 PZF Receiver", \
+ "Long Wave Receiver" \
}
@@ -3225,9 +3255,13 @@ enum
#define HAS_MULTI_REF_NTP ( 1UL << MULTI_REF_NTP )
#define HAS_MULTI_REF_PTP ( 1UL << MULTI_REF_PTP )
#define HAS_MULTI_REF_PTP_E1 ( 1UL << MULTI_REF_PTP_E1 )
+
#define HAS_MULTI_REF_FREQ ( 1UL << MULTI_REF_FREQ )
#define HAS_MULTI_REF_PPS_STRING ( 1UL << MULTI_REF_PPS_STRING )
#define HAS_MULTI_REF_GPIO ( 1UL << MULTI_REF_GPIO )
+#define HAS_MULTI_REF_INTERNAL ( 1UL << MULTI_REF_INTERNAL )
+#define HAS_MULTI_REF_PZF ( 1UL << MULTI_REF_PZF )
+#define HAS_MULTI_REF_LWR ( 1UL << MULTI_REF_LWR )
/*
@@ -3408,8 +3442,9 @@ typedef struct
XMULTI_REF_ID id; /**< time source identifier */
uint16_t status; /**< flag bits as defined below */
NANO_TIME offset; /**< time offset from main time base */
- uint32_t flags; /**< see flags specidied below */
-
+ uint16_t flags; /**< see flags specified below */
+ uint8_t ssm; /**< synchronization status message ( if supported by src. )*/
+ uint8_t soc; /**< signal outage counter ( updt. on loss of signal ) */
} XMULTI_REF_STATUS;
@@ -3504,7 +3539,6 @@ typedef struct
uint16_t n_xmr_settings; /**< number of configurable multi ref settings */
uint16_t reserved; /**< number of configurable multi ref settings */
uint8_t n_inst[32]; /**< N_MULTI_REF entries used, but can not exceed bit number of uint32_t - 1 */
-
} XMULTI_REF_INSTANCES;
/** @} group_xmr_cfg */
@@ -3530,16 +3564,36 @@ typedef struct
/**
- * @brief A structure used to specify a frequency
+ * @brief A structure used to specify a variable frequency
*/
typedef struct
{
- uint32_t hz; /**< integral number, HZ */
+ uint32_t hz; /**< integral number, Hz */
uint32_t frac; /**< fractional part, binary */
} MBG_GPIO_FREQ;
+/**
+ * @brief A structure used to specify a fixed frequency
+ */
+typedef struct
+{
+ uint32_t frq_bit; /**< fixed freq. bit mask ( see enum ) */
+ uint32_t reserved; /**< reserved */
+
+} MBG_GPIO_FIXED_FREQ;
+
+
+/**
+ * @brief A structure used to specify a framed datastream
+ */
+typedef struct
+{
+ uint32_t format; /**< format bit mask ( see enum and bit mask ! ) */
+ uint32_t reserved; /**< reserved */
+
+} MBG_GPIO_BITS;
/**
* @brief A structure used to configure a GPIO as frequency output
@@ -3555,19 +3609,64 @@ typedef struct
} MBG_GPIO_FREQ_OUT_SETTINGS;
+/**
+ * @brief A structure used to configure a GPIO as frequency output
+ */
+
+typedef struct
+{
+ MBG_GPIO_FREQ freq; /**< frequency */
+ uint32_t csc_limit; /**< max. cycle slip [1/1000 cycle units] */
+ uint32_t type; /**< sine, rectangle, etc. */ //##++++++++++++++
+ uint32_t reserved; /**< currently always 0 */
+ uint32_t flags; /**< currently always 0 */
+
+} MBG_GPIO_FREQ_IN_SETTINGS;
+
+
/**
- * @brief A structure used to specify the supported features of a GPIO frequency output
+ * @brief A structure used to configure a GPIO as fixed frequency output
*/
typedef struct
{
- MBG_GPIO_FREQ max_freq; /** maximum frequency */
- uint32_t reserved; /**< currently always 0 */
- uint32_t flags; /**< currently always 0 */
+ MBG_GPIO_FIXED_FREQ freq; /**< frequency */
+ uint32_t reserved_0; /**< supported frequencies bit mask, see enum */
+ uint32_t type; /**< sine, rectangle, etc. */ //##++++++++++++++
+ uint32_t reserved_1; /**< currently always 0 */
+ uint32_t flags; /**< currently always 0 */
-} MBG_GPIO_FREQ_OUT_INFO;
+} MBG_GPIO_FIXED_FREQ_OUT_SETTINGS;
+/**
+ * @brief A structure used to configure a GPIO as BITS module
+ */
+
+typedef struct {
+ MBG_GPIO_BITS bits; /**< DS Settings for building integrated timing supply */
+ uint32_t csc_limit; /**< max. cycle slip [1/1000 cycle units] */
+
+ union {
+ struct {
+ uint8_t ssm; /**< minimum E1 SSM ( 0...15 ) for acceptance */
+ uint8_t sa_bits; /**< Sa Bits group ( 4...8 ) carrying SSM */
+ uint16_t reserve;
+ } e1;
+
+ struct {
+ uint8_t min_boc;
+ uint8_t reserve_0;
+ uint16_t reserve_1;
+ } t1;
+
+ uint32_t u32;
+ } quality;
+
+ uint32_t err_msk; /**< error mask msk, see enum */
+ uint32_t flags; /**< currently always 0 */
+} MBG_GPIO_BITS_IN_SETTINGS;
+
/**
* @brief A structure used to configure a GPIO port
@@ -3580,12 +3679,37 @@ typedef struct
union
{
- MBG_GPIO_FREQ_OUT_SETTINGS frequ_out; /** if type is frequency output */
+ MBG_GPIO_FREQ_OUT_SETTINGS freq_out; /** if type is frequency output */
+ MBG_GPIO_FREQ_IN_SETTINGS freq_in; /** if type is frequency input */
+ MBG_GPIO_FIXED_FREQ_OUT_SETTINGS ff_out; /** if type is fixed frequency output */
+ MBG_GPIO_BITS_IN_SETTINGS bits_in; /** if type is framed ds. in */
} u;
} MBG_GPIO_SETTINGS;
+/**
+ * @brief A structure used to describe a GPIO ports limiting values
+ */
+typedef struct
+{
+ uint32_t supp_modes; /**< supported modes */
+ uint32_t reserved;
+ uint32_t supp_flags; /**< supported flags */
+
+ union
+ {
+ MBG_GPIO_FREQ_OUT_SETTINGS freq_out; /** max. freq. values for output */
+ MBG_GPIO_FREQ_IN_SETTINGS freq_in; /** max. freq. values for input */
+ MBG_GPIO_FIXED_FREQ_OUT_SETTINGS ff_out; /** max. ff values for output */
+ MBG_GPIO_BITS_IN_SETTINGS bits_in; /** if type is framed ds. in */
+ } u;
+
+} MBG_GPIO_LIMITS;
+
+
+
+
/**
* @brief A structure used to configure a specific GPIO port
@@ -3605,14 +3729,7 @@ typedef struct
typedef struct
{
MBG_GPIO_SETTINGS settings; /**< current configuration */
- uint32_t supp_modes; /**< bit mask of supported modes */
- uint32_t supp_flags; /**< bit mask of flags recognized by the device */
-
- union
- {
- MBG_GPIO_FREQ_OUT_INFO frequ_out; /** < capabilities in frequency output mode */
- } u;
-
+ MBG_GPIO_LIMITS limits; /**< supp. and max. values */
} MBG_GPIO_INFO;
@@ -3633,10 +3750,77 @@ typedef struct
*/
enum
{
- MBG_GPIO_SIGNAL_TYPE_FREQ_OUT, /**< frequency output */
- N_MBG_GPIO_SIGNAL_TYPES /**< number of known modes */
+ MBG_GPIO_SIGNAL_TYPE_FREQ_OUT, /**< variable frequency output */
+ MBG_GPIO_SIGNAL_TYPE_FREQ_IN, /**< variable frequency inputs */
+ MBG_GPIO_SIGNAL_TYPE_FIXED_FREQ_OUT, /**< fixed frequency outputs */
+ MBG_GPIO_SIGNAL_TYPE_FIXED_FREQ_IN, /**< fixed frequency input */
+ MBG_GPIO_SIGNAL_TYPE_BITS_OUT, /**< framed data stream output */
+ MBG_GPIO_SIGNAL_TYPE_BITS_IN, /**< framed data stream input */
+ N_MBG_GPIO_SIGNAL_TYPES /**< number of known modes */
+};
+
+
+
+/**
+ * @brief Definitions for MBG_GPIO_FF_OUT_SETTINGS::frq_bit
+ */
+enum
+{
+ MBG_GPIO_FIXED_FREQ_8kHz, /**< 8kHz */
+ MBG_GPIO_FIXED_FREQ_48kHz, /**< 48kHz */
+ MBG_GPIO_FIXED_FREQ_1MHz, /**< 1MHz */
+ MBG_GPIO_FIXED_FREQ_1544kHz, /**< 1.544MHz */
+ MBG_GPIO_FIXED_FREQ_2048kHz, /**< 2.048MHz */
+ MBG_GPIO_FIXED_FREQ_5MHz, /**< 5MHz */
+ MBG_GPIO_FIXED_FREQ_10MHz, /**< 10MHz */
+ MBG_GPIO_FIXED_FREQ_19440kHz, /**< 19.44MHz */
+ N_MBG_GPIO_FIXED_FREQ /**< number of known frequencies */
};
+/**< Bit Masks to be used with MBG_GPIO_FF_OUT_SETTINGS::frq_bit */
+#define MSK_MBG_GPIO_FIXED_FREQ_8kHz ( 1UL << MBG_GPIO_FIXED_FREQ_8kHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_48kHz ( 1UL << MBG_GPIO_FIXED_FREQ_48kHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_1MHz ( 1UL << MBG_GPIO_FIXED_FREQ_1MHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_1544kHz ( 1UL << MBG_GPIO_FIXED_FREQ_1544kHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_2048kHz ( 1UL << MBG_GPIO_FIXED_FREQ_2048kHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_5MHz ( 1UL << MBG_GPIO_FIXED_FREQ_5MHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_10MHz ( 1UL << MBG_GPIO_FIXED_FREQ_10MHz )
+#define MSK_MBG_GPIO_FIXED_FREQ_19440kHz ( 1UL << MBG_GPIO_FIXED_FREQ_19440kHz )
+
+
+
+/**
+ * @brief Definitions for MBG_GPIO_BITS::format
+ */
+enum
+{
+ MBG_GPIO_BITS_E1_FRAMED, /**< 2.048MBit */
+ MBG_GPIO_BITS_T1_FRAMED, /**< 1.544MBit */
+ MBG_GPIO_BITS_E1_TIMING, /**< 2.048MHz */
+ MBG_GPIO_BITS_T1_TIMING, /**< 2.048MHz */
+ N_MBG_GPIO_BITS /**< number of formats */
+};
+
+#define MSK_MBG_GPIO_BITS_E1_FRAMED ( 1UL << MBG_GPIO_BITS_E1_FRAMED )
+#define MSK_MBG_GPIO_BITS_T1_FRAMED ( 1UL << MBG_GPIO_BITS_T1_FRAMED )
+#define MSK_MBG_GPIO_BITS_E1_TIMING ( 1UL << MBG_GPIO_BITS_E1_TIMING )
+#define MSK_MBG_GPIO_BITS_T1_TIMING ( 1UL << MBG_GPIO_BITS_T1_TIMING )
+
+
+/**
+ * @brief Definitions for MBG_GPIO_BITS_IN_SETTINGS::quality.err
+ */
+enum
+{
+ MBG_GPIO_BITS_ERR_LOS, /**< loss of signal error */
+ MBG_GPIO_BITS_ERR_LOF, /**< loss of frame */
+ N_MBG_GPIO_BITS_ERR /**< number of formats */
+};
+
+#define MSK_MBG_GPIO_BITS_ERR_LOS ( 1UL << MBG_GPIO_BITS_ERR_LOS )
+#define MSK_MBG_GPIO_BITS_ERR_LOF ( 1UL << MBG_GPIO_BITS_ERR_LOF )
+
+
/** @} group_gpio */
@@ -4372,15 +4556,29 @@ enum
* @brief A PTP clock identity
*
* @note This usually consists of a 6 byte MAC address with
- * 2 fixed bytes inserted.
+ * 2 fixed bytes inserted, or all ones as wildcard.
*/
typedef struct
{
uint8_t b[8];
-} PTP_CLOCK_IDENTITY;
+} PTP_CLOCK_ID;
-#define _mbg_swab_ptp_clock_identity( _p ) _nop_macro_fnc() // nothing to swap
+#define _mbg_swab_ptp_clock_id( _p ) _nop_macro_fnc() // nothing to swap
+#define PTP_CLOCK_ID_WILDCARD { { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }
+
+
+/**
+ * @brief A PTP port ID
+ *
+ * @note This usually consists of a 6 byte MAC address with
+ * 2 fixed bytes inserted, or all ones as wildcard.
+ */
+typedef uint16_t PTP_PORT_ID;
+
+#define _mbg_swab_ptp_port_id( _p ) _mbg_swab16( _p )
+
+#define PTP_PORT_ID_WILDCARD 0xFFFF
/**
@@ -4437,8 +4635,8 @@ enum
typedef struct
{
//##++++ Do we need a port identifier ??
- uint16_t network_protocol; /**< one of the enumerated protocols (@see N_PTP_NW_PROT) */
- uint8_t ptp_proto_version; /**< PTP protocol version, 1, or 2, usually 2 for v2 */
+ uint16_t nw_prot; /**< one of the enumerated protocols (@see N_PTP_NW_PROT) */
+ uint8_t ptp_prot_version; /**< PTP protocol version, 1, or 2, usually 2 for v2 */
uint8_t port_state; /**< one of the enumerated port states (@see N_PTP_PORT_STATE ) */
uint32_t flags; /**< bit masks as defined below */
NANO_TIME offset; /**< estimated time offset from the upstream time source */
@@ -4446,7 +4644,7 @@ typedef struct
NANO_TIME mean_path_delay;
NANO_TIME delay_asymmetry;
- PTP_CLOCK_IDENTITY gm_identity; /**< identifier ot the upstream time source */
+ PTP_CLOCK_ID gm_id; /**< identifier ot the upstream time source */
uint16_t clock_offset_scaled_log_variance;
uint8_t clock_class;
@@ -4458,7 +4656,7 @@ typedef struct
uint8_t domain_number; /**< the PTP clock domain number, 0:3 */
uint8_t time_source; /**< one of the defined codes PTP_TIME_SOURCE_... */
uint8_t delay_mech; /**< PTP_DELAY_MECH_BIT_E2E or PTP_DELAY_MECH_BIT_P2P */
- int8_t log_delay_req_intv;
+ int8_t log_delay_req_intv;
int16_t utc_offset; /**< UTC offset observed against TAI */
DAC_VAL osc_dac_cal; /**< disiplination value of the oscillator */
@@ -4469,13 +4667,13 @@ typedef struct
#define _mbg_swab_ptp_state( _p ) \
{ \
- _mbg_swab16( &(_p)->network_protocol ); \
+ _mbg_swab16( &(_p)->nw_prot ); \
_mbg_swab32( &(_p)->flags ); \
_mbg_swab_nano_time( &(_p)->offset ); \
_mbg_swab_nano_time( &(_p)->path_delay ); \
_mbg_swab_nano_time( &(_p)->mean_path_delay ); \
_mbg_swab_nano_time( &(_p)->delay_asymmetry ); \
- _mbg_swab_ptp_clock_identity( &(_p)->gm_identity ); \
+ _mbg_swab_ptp_clock_id( &(_p)->gm_id ); \
_mbg_swab16( &(_p)->clock_offset_scaled_log_variance ); \
_mbg_swab32( &(_p)->reserved_1 ); \
_mbg_swab32( &(_p)->reserved_2 ); \
@@ -4514,14 +4712,14 @@ enum
#define PTP_DELAY_REQ_INTERVAL_MIN -6
#define PTP_DELAY_REQ_INTERVAL_MAX 6
-#define PTP_DEFAULT_UNICAST_SYNC_INTERVAL_MIN -4
-#define PTP_DEFAULT_UNICAST_SYNC_INTERVAL_MAX 4
+#define PTP_DEFAULT_UC_SYNC_INTV_MIN -4
+#define PTP_DEFAULT_UC_SYNC_INTV_MAX 4
-#define PTP_DEFAULT_UNICAST_DELAY_REQ_INTERVAL_MIN -4
-#define PTP_DEFAULT_UNICAST_DELAY_REQ_INTERVAL_MAX 4
+#define PTP_DEFAULT_UC_DLY_REQ_INTV_MIN -4
+#define PTP_DEFAULT_UC_DLY_REQ_INTV_MAX 4
-#define PTP_DEFAULT_UNICAST_ANNOUNCE_INTERVAL_MIN -4
-#define PTP_DEFAULT_UNICAST_ANNOUNCE_INTERVAL_MAX 4
+#define PTP_DEFAULT_UC_ANN_INTV_MIN -4
+#define PTP_DEFAULT_UC_ANN_INTV_MAX 4
/**
* @defgroup group_ptp_uc_msg_duration_limits Unicast PTP masters send messages
@@ -4545,7 +4743,7 @@ enum
typedef struct
{
//##++++ Do we need a port identifier ??
- uint16_t network_protocol; /**< one of the enumerated and supported protocols (@see N_PTP_NW_PROT) */
+ uint16_t nw_prot; /**< one of the enumerated and supported protocols (@see N_PTP_NW_PROT) */
uint8_t profile; /**< PTP profile, currently only 0 = default */
uint8_t domain_number; /**< the PTP clock domain number, 0:3 */
@@ -4576,7 +4774,7 @@ typedef struct
#define _mbg_swab_ptp_cfg_settings( _p ) \
{ \
- _mbg_swab16( &(_p)->network_protocol ); \
+ _mbg_swab16( &(_p)->nw_prot ); \
_mbg_swab16( &(_p)->sync_intv ); \
_mbg_swab16( &(_p)->ann_intv ); \
_mbg_swab16( &(_p)->delay_req_intv ); \
@@ -4607,7 +4805,7 @@ typedef struct
int16_t delay_req_intv_max; /**< log2 of maximum delay request interval [s] */
uint32_t supp_flags; /**< a bit mask of supported features (see below) */
- uint32_t supp_network_prot; /**< a bit mask of supported network protocols */
+ uint32_t supp_nw_prot; /**< a bit mask of supported network protocols */
uint32_t supp_profiles; /**< a bit mask of supported profiles */
uint32_t supp_delay_mech; /**< a bit mask of supported delay mechanisms */
@@ -4624,9 +4822,9 @@ typedef struct
_mbg_swab16( &(_p)->delay_req_intv_min ); \
_mbg_swab16( &(_p)->delay_req_intv_max ); \
_mbg_swab32( &(_p)->supp_flags ); \
- _mbg_swab32( &(_p)->supp_network_protocols ); \
+ _mbg_swab32( &(_p)->supp_nw_prot ); \
_mbg_swab32( &(_p)->supp_profiles ); \
- _mbg_swab32( &(_p)->supp_delay_mechanisms ); \
+ _mbg_swab32( &(_p)->supp_delay_mech ); \
}
@@ -4726,32 +4924,32 @@ typedef struct
*/
typedef struct
{
- MBG_HOSTNAME gm_host; /**< grandmaster's hostname or IP address */
- PTP_CLOCK_IDENTITY gm_clock_id; /**< use clock ID of master port, or FF:FF:FF:FF:FF:FF:FF:FF as wildcard */
- uint16_t gm_port_id; /**< use target port ID of master port (e.g. '1') or 0xFFFF as wildcard */
- int16_t sync_intv; /**< log2 of sync interval [s] */
- int16_t ann_intv; /**< log2 of announce interval [s] */
- int16_t delay_req_intv; /**< log2 of delay request interval [s]*/
- int32_t fix_offset; /**< constant time offset to be compensated [ns] */
- uint16_t message_duration; /**< time period until master stops sending messages [s] */
- uint16_t reserved_0; /**< reserved, currently always 0 */
- uint32_t reserved_1; /**< reserved, currently always 0 */
- uint32_t flags; /**< bit masks as specified below */
+ MBG_HOSTNAME gm_host; /**< grandmaster's hostname or IP address */
+ PTP_CLOCK_ID gm_clock_id; /**< use clock ID of master port, or PTP_CLOCK_ID_WILDCARD */
+ PTP_PORT_ID gm_port_id; /**< use target port ID of master port (e.g. 135) or PTP_PORT_ID_WILDCARD */
+ int16_t sync_intv; /**< sync interval [log2 s] */
+ int16_t ann_intv; /**< announce interval [log2 s] */
+ int16_t delay_req_intv; /**< delay request interval [log2 s]*/
+ int32_t fix_offset; /**< constant time offset to be compensated [ns] */
+ uint16_t message_duration; /**< time period until master stops sending messages [s] */
+ uint16_t reserved_0; /**< reserved, currently always 0 */
+ uint32_t reserved_1; /**< reserved, currently always 0 */
+ uint32_t flags; /**< bit masks as specified below */
} PTP_UC_MASTER_SETTINGS;
-#define _mbg_swab_ptp_uc_master_settings( _p ) \
-{ \
- _mbg_swab_ptp_clock_identity( &(_p)->gm_clock_id ); \
- _mbg_swab16( &(_p)->gm_port_id ); \
- _mbg_swab16( &(_p)->sync_intv ); \
- _mbg_swab16( &(_p)->ann_intv ); \
- _mbg_swab16( &(_p)->delay_req_intv ); \
- _mbg_swab32( &(_p)->fix_offset ); \
- _mbg_swab16( &(_p)->message_duration ); \
- _mbg_swab16( &(_p)->reserved_0 ); \
- _mbg_swab32( &(_p)->reserved_1 ); \
- _mbg_swab32( &(_p)->flags ); \
+#define _mbg_swab_ptp_uc_master_settings( _p ) \
+{ \
+ _mbg_swab_ptp_clock_id( &(_p)->gm_clock_id ); \
+ _mbg_swab_ptp_port_id( &(_p)->gm_port_id ); \
+ _mbg_swab16( &(_p)->sync_intv ); \
+ _mbg_swab16( &(_p)->ann_intv ); \
+ _mbg_swab16( &(_p)->delay_req_intv ); \
+ _mbg_swab32( &(_p)->fix_offset ); \
+ _mbg_swab16( &(_p)->message_duration ); \
+ _mbg_swab16( &(_p)->reserved_0 ); \
+ _mbg_swab32( &(_p)->reserved_1 ); \
+ _mbg_swab32( &(_p)->flags ); \
}
@@ -5036,12 +5234,11 @@ typedef struct
} NAV_ENGINE_SETTINGS;
-/* End of header body */
-
-
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
+/* End of header body */
#endif /* _GPSDEFS_H */
diff --git a/mbglib/common/lan_util.c b/mbglib/common/lan_util.c
index c9c221f..8d31493 100755
--- a/mbglib/common/lan_util.c
+++ b/mbglib/common/lan_util.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: lan_util.c 1.1.1.2 2011/04/20 16:08:55 martin TRASH martin $
+ * $Id: lan_util.c 1.1.1.13 2011/09/20 16:14:03 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,29 @@
*
* -----------------------------------------------------------------------
* $Log: lan_util.c $
- * Revision 1.1.1.2 2011/04/20 16:08:55 martin
+ * Revision 1.1.1.13 2011/09/20 16:14:03 martin
+ * Fix for old Linux ethtool headers.
+ * Revision 1.1.1.12 2011/09/14 13:50:48 martin
+ * Rewrote some functions sharing common code.
+ * Use predefined return values for those functions.
+ * Renamed some functions to more appropriate names.
+ * Revision 1.1.1.11 2011/09/08 10:37:36 udo
+ * Revision 1.1.1.10 2011/08/27 14:26:47 udo
+ * new get_port_ip4_addr() and get_port_ip4_netm()
+ * Revision 1.1.1.9 2011/08/27 13:34:57 udo
+ * new get_port_ip4_addr() and get_port_ip4_netm()
+ * Revision 1.1.1.8 2011/08/25 20:39:36 martin
+ * Added new functions to deal with MAC addresses.
+ * Revision 1.1.1.7 2011/08/09 08:13:19 philipp
+ * proper return code evaluating
+ * Revision 1.1.1.6 2011/08/08 16:12:08 martin
+ * Revision 1.1.1.5 2011/08/08 16:02:28 martin
+ * Revision 1.1.1.4 2011/08/04 13:46:12 philipp
+ * Linux implementation of function check_port_link
+ * which performs a link detection test for a specific, given interface
+ * Revision 1.1.1.3 2011/06/21 15:23:30 martin
+ * Fixed build under DOS.
+ * Revision 1.1.1.2 2011/04/20 16:08:55Z martin
* Revision 1.1.1.1 2011/03/04 10:33:22 martin
* Implemented dummy snprintf() function for environments
* which don't provide this.
@@ -24,14 +46,54 @@
#undef _LAN_UTIL
#include <stdio.h>
+#include <string.h>
+
+#if defined ( MBG_TGT_UNIX )
+
+ #if defined ( MBG_TGT_LINUX )
+
+ #include <linux/types.h>
+
+ // Some older versions of linux/types.h don't define u8..u64
+ // for user space applications. However, if they do they also
+ // define BITS_PER_LONG, so we use this symbol to figure out
+ // if we need to define u8..u64 by ourselves.
+ #if !defined( BITS_PER_LONG )
+ typedef uint8_t u8;
+ typedef uint16_t u16;
+ typedef uint32_t u32;
+ typedef uint64_t u64;
+ #endif
+
+ #include <linux/sockios.h>
+ #include <linux/ethtool.h>
+
+ #endif
+
+ #include <sys/ioctl.h>
+ #include <unistd.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+
+#endif
+
+
+// Maximum size of an IPv4 address string in dotted quad format,
+// including a terminating 0, and thus the required minimum size
+// for a buffer to take such a string. i.e. "aaa.bbb.ccc.ddd\0".
+#define MAX_IP4_ADDR_STR_SIZE 16
+
#if defined( __BORLANDC__ ) \
&& ( __BORLANDC__ <= 0x410 ) // BC3.1 defines 0x410 !
-
#include <stdarg.h>
+// Declare a snprintf() function if not provided by the
+// build environment, though this implementation actually
+// does not check the string length ...
+
static /*HDR*/
int snprintf( char *s, size_t max_len, const char *fmt, ... )
{
@@ -52,6 +114,83 @@ int snprintf( char *s, size_t max_len, const char *fmt, ... )
/*HDR*/
/**
+ * @brief Print an IPv4 address to a dotted quad format string.
+ *
+ * @param s The string buffer into which to print
+ * @param max_len Maximum length of the string, i.e. size of the buffer
+ * @param addr The IPv4 address
+ * @param info An optional string which is prepended to the string, or NULL
+ *
+ * @return The overall number of characters printed to the string
+ */
+int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *addr, const char *info )
+{
+ int n = 0;
+
+ if ( info )
+ n += snprintf( s, max_len, "%s", info );
+
+ // Don't use byte pointers here since this is not safe
+ // for both little and big endian targets.
+ n += snprintf( &s[n], max_len - n, "%i.%i.%i.%i",
+ ( (*addr) >> 24 ) & 0xFF,
+ ( (*addr) >> 16 ) & 0xFF,
+ ( (*addr) >> 8 ) & 0xFF,
+ ( (*addr) ) & 0xFF
+ );
+ return n;
+
+} // snprint_ip4_addr
+
+
+
+/*HDR*/
+/**
+ * @brief Convert a string to an IP4_ADDR.
+ *
+ * @param p Pointer to the IP4_ADDR variable, or NULL, in which case this
+ * function can be used to check if the string is formally correct.
+ * @param s The string to be converted
+ *
+ * @return >= 0 on success, number of characters evaluated from the input string
+ * -1 if invalid number found in string
+ * -2 if separator is not a dot '.'
+ */
+int str_to_ip4_addr( IP4_ADDR *p, const char *s )
+{
+ IP4_ADDR tmp_ip4_addr = 0;
+ char *cp;
+ int i;
+
+ for ( i = 0, cp = (char *) s; ; )
+ {
+ unsigned long ul = strtoul( cp, &cp, 10 );
+
+ if ( ul > 255 ) // invalid number
+ return -1;
+
+ tmp_ip4_addr |= ul << ( 8 * (3 - i) );
+
+ if ( ++i >= 4 )
+ break; // done
+
+ if ( *cp != '.' )
+ return -2; // invalid string format, dot expected
+
+ cp++; // skip dot
+ }
+
+ if ( p )
+ *p = tmp_ip4_addr;
+
+ return cp - (char *) s; // success
+
+} // str_to_ip4_addr
+
+
+
+/*HDR*/
+/**
* @brief Print a MAC ID or similar array of octets to a string.
*
* @param s The string buffer into which to print
@@ -61,7 +200,7 @@ int snprintf( char *s, size_t max_len, const char *fmt, ... )
* @param sep The separator printed between the bytes, or 0
* @param info An optional string which is prepended to the output, or NULL
*
- * @return The overall number of characters printed to the string
+ * @return The overall number of characters printed to the string
*/
int snprint_octets( char *s, size_t max_len, const uint8_t *octets,
int num_octets, char sep, const char *info )
@@ -88,13 +227,31 @@ int snprint_octets( char *s, size_t max_len, const uint8_t *octets,
/*HDR*/
/**
- * @brief Set a MAC ID or a similar array of bytes from a string.
+ * @brief Print a MAC address to a string.
+ *
+ * @param s The string buffer into which to print
+ * @param max_len Maximum length of the string, i.e. size of the buffer
+ * @param p_mac_addr The MAC address to be printed
+ *
+ * @return The overall number of characters printed to the string
+ */
+int snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr )
+{
+ return snprint_octets( s, max_len, p_mac_addr->b, sizeof( *p_mac_addr ), MAC_SEP_CHAR, NULL );
+
+} // snprint_mac_addr
+
+
+
+/*HDR*/
+/**
+ * @brief Set a MAC ID or a similar array of octets from a string.
*
* @param octets An array of octets to be set up
* @param num_octets The number of octets which can be stored
* @param s The string to be converted
*
- * @return The overall number of octets decoded from the string
+ * @return The overall number of octets decoded from the string
*/
int str_to_octets( uint8_t *octets, int num_octets, const char *s )
{
@@ -124,74 +281,259 @@ int str_to_octets( uint8_t *octets, int num_octets, const char *s )
/*HDR*/
/**
- * @brief Print an IPv4 address to a dotted quad format string.
+ * @brief Check if an array of octets is valid, i.e. != 0
*
- * @param s The string buffer into which to print
- * @param max_len Maximum length of the string, i.e. size of the buffer
- * @param addr The IPv4 address
- * @param info An optional string which is prepended to the string, or NULL
+ * @param octets Pointer to the array of octets
+ * @param num_octets Number of octets
*
- * @return The overall number of characters printed to the string
+ * @return MBG_LU_SUCCESS octets are valid, i.e. not all 0
+ * MBG_LU_ERR_NOT_SET octets are invalid, i.e. all 0
*/
-int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *addr, const char *info )
+int check_octets_not_all_zero( const uint8_t *octets, int num_octets )
{
- int n = 0;
+ int i;
- if ( info )
- n += snprintf( s, max_len, "%s", info );
+ // check if any of the MAC adddress bytes is != 0
+ for ( i = 0; i < num_octets; i++ )
+ if ( octets[i] != 0 )
+ break;
- n += snprintf( &s[n], max_len - n, "%i.%i.%i.%i",
- BYTE_OF( *addr, 3 ),
- BYTE_OF( *addr, 2 ),
- BYTE_OF( *addr, 1 ),
- BYTE_OF( *addr, 0 )
- );
- return n;
+ if ( i == num_octets ) // *all* bytes are 0
+ return MBG_LU_ERR_NOT_SET;
+
+ return 0;
+
+} // check_octets_not_all_zero
-} // snprint_ip4_addr
+#if defined( MBG_TGT_UNIX )
/*HDR*/
/**
- * @brief Convert a string to an IP4_ADDR.
+ * @brief Do a SIOCGxxx IOCTL call to read specific information from a LAN interface
*
- * @param p Pointer to the IP4_ADDR variable, or NULL, in which case this
- * function can be used to check if the string is formally correct.
- * @param s The string to be converted
+ * @param if_name Name of the interface
+ * @param ioctl_code One of the predefined system SIOCGxxx IOCTL codes
+ * @param p_ifreq Pointer to a request buffer
*
- * @return >= 0 on success, number of characters evaluated from the input string
- * -1 if invalid number found in string
- * -2 if separator is not a dot '.'
+ * @return one of the MBG_LU_xxx codes
*/
-int str_to_ip4_addr( IP4_ADDR *p, const char *s )
+int do_siocg_ioctl( const char *if_name, int ioctl_code, struct ifreq *p_ifreq )
{
- IP4_ADDR tmp_ip4_addr = 0;
- char *cp;
- int i;
+ int fd;
+ int rc;
- for ( i = 0, cp = (char *) s; ; )
- {
- unsigned long ul = strtoul( cp, &cp, 10 );
+ if ( strlen( if_name ) > ( IFNAMSIZ - 1 ) )
+ return MBG_LU_ERR_PORT_NAME;
- if ( ul > 255 ) // invalid number
- return -1;
+ fd = socket( AF_INET, SOCK_DGRAM, 0 );
- tmp_ip4_addr |= ul << ( 8 * (3 - i) );
+ if ( fd < 0 )
+ return MBG_LU_ERR_SOCKET;
- if ( ++i >= 4 )
- break; // done
+ strcpy( p_ifreq->ifr_name, if_name );
- if ( *cp != '.' )
- return -2; // invalid string format, dot expected
+ rc = ioctl( fd, ioctl_code, p_ifreq );
- cp++; // skip dot
+ if ( rc < 0 )
+ rc = MBG_LU_ERR_IOCTL;
+
+ close( fd );
+
+ return MBG_LU_SUCCESS;
+
+} // do_siocg_ioctl
+
+#endif // defined( MBG_TGT_UNIX )
+
+
+
+/*HDR*/
+/**
+ * @brief Retrieve the MAC address of a network interface
+ *
+ * @param if_name Name of the interface
+ * @param p_mac_addr Pointer to the MAC address buffer to be filled up
+ *
+ * @return one of the MBG_LU_xxx codes
+ * on error the MAC addr is set to all 0
+ */
+int get_port_mac_addr( const char *if_name, MBG_MAC_ADDR *p_mac_addr )
+{
+ int rc = MBG_LU_ERR_NSUPP;
+
+ #if defined( MBG_TGT_LINUX )
+ struct ifreq ifr = { { { 0 } } };
+
+ rc = do_siocg_ioctl( if_name, SIOCGIFHWADDR, &ifr );
+
+ if ( rc != MBG_LU_SUCCESS )
+ goto fail;
+
+ memcpy( p_mac_addr, ifr.ifr_hwaddr.sa_data, sizeof( *p_mac_addr ) );
+
+ return rc;
+
+fail:
+ #endif
+
+ memset( p_mac_addr, 0, sizeof( *p_mac_addr ) );
+
+ return rc;
+
+} // get_port_mac_addr
+
+
+
+/*HDR*/
+/**
+ * @brief Retrieve and check the MAC address of a network interface
+ *
+ * @param if_name Name of the interface
+ * @param p_mac_addr Pointer to the MAC address buffer to be filled up
+ *
+ * @return one of the MBG_LU_xxx codes
+ * on error the MAC addr is set to all 0
+ */
+int get_port_mac_addr_check( const char *if_name, MBG_MAC_ADDR *p_mac_addr )
+{
+ int rc = get_port_mac_addr( if_name, p_mac_addr );
+
+ if ( rc == MBG_LU_SUCCESS )
+ {
+ if ( !check_octets_not_all_zero( p_mac_addr->b, sizeof( *p_mac_addr ) ) )
+ rc = MBG_LU_ERR_NOT_SET;
}
- if ( p )
- *p = tmp_ip4_addr;
+ return rc;
- return cp - s; // success
+} // get_port_mac_addr_check
+
+
+
+/*HDR*/
+/**
+ * @brief Check the link state of a network interface
+ *
+ * @param ifname Name of the interface
+ *
+ * @return 1 link detected on port
+ * 0 no link detected on port
+ * one of the MBG_LU_xxx codes in case of an error
+ */
+int check_port_link( const char *if_name )
+{
+ #if defined( MBG_TGT_LINUX )
+ struct ifreq ifr = { { { 0 } } };
+ struct ethtool_value edata = { 0 };
+ int rc;
+
+ edata.cmd = ETHTOOL_GLINK; // defined in ethtool.h
+ ifr.ifr_data = (caddr_t) &edata;
+
+ rc = do_siocg_ioctl( if_name, SIOCETHTOOL, &ifr );
+
+ if ( rc == MBG_LU_SUCCESS )
+ rc = edata.data != 0;
+
+ return rc;
+
+ #else
+
+ return MBG_LU_ERR_NSUPP;
+
+ #endif
+
+} // check_port_link
+
+
+
+/*HDR*/
+/**
+ * @brief Retrieve the IPv4 address of a network interface as string
+ *
+ * @param if_name Name of the interface
+ * @param p_addr_buf Pointer to the string buffer to be filled up
+ * @param buf_size size of the string buffer
+ *
+ * @return one of the MBG_LU_xxx codes
+ */
+int get_port_ip4_addr_str( const char *if_name, char *p_addr_buf, int buf_size )
+{
+ int rc = MBG_LU_ERR_NSUPP;
+
+ #if defined( MBG_TGT_LINUX )
+ struct ifreq ifr = { { { 0 } } };
+
+ rc = do_siocg_ioctl( if_name, SIOCGIFADDR, &ifr );
+
+ if ( rc != MBG_LU_SUCCESS )
+ goto fail;
+
+
+ if ( buf_size < MAX_IP4_ADDR_STR_SIZE ) //###+++
+ {
+ rc = MBG_LU_ERR_BUFF_SZ;
+ goto fail;
+ }
+
+ strncpy( p_addr_buf, inet_ntoa( ( (struct sockaddr_in *) &ifr.ifr_addr )->sin_addr ), buf_size - 1 );
+ p_addr_buf[buf_size-1] = 0; // force terminating 0
+
+ return rc;
+
+fail:
+ #endif
+
+ *p_addr_buf = 0; // make empty string
+
+ return rc;
+
+} // get_port_ip4_addr_str
+
+
+
+/*HDR*/
+/**
+ * @brief Retrieve the IPv4 net mask of a network interface as string
+ *
+ * @param if_name Name of the interface
+ * @param p_addr_buf Pointer to the string buffer to be filled up
+ * @param buf_size size of the string buffer
+ *
+ * @return one of the MBG_LU_xxx codes
+ */
+int get_port_ip4_netmask_str( const char *if_name, char *p_addr_buf, int buf_size )
+{
+ int rc = MBG_LU_ERR_NSUPP;
+
+ #if defined( MBG_TGT_LINUX )
+ struct ifreq ifr = { { { 0 } } };
+
+ rc = do_siocg_ioctl( if_name, SIOCGIFNETMASK, &ifr );
+
+ if ( rc != MBG_LU_SUCCESS )
+ goto fail;
+
+ if ( buf_size < MAX_IP4_ADDR_STR_SIZE ) //###++++
+ {
+ rc = MBG_LU_ERR_BUFF_SZ;
+ goto fail;
+ }
+
+ strncpy( p_addr_buf, inet_ntoa( ( (struct sockaddr_in *) &ifr.ifr_netmask )->sin_addr ), buf_size - 1 );
+ p_addr_buf[buf_size-1] = 0; // force terminating 0
+
+ return rc;
+
+fail:
+ #endif
+
+ *p_addr_buf = 0; // make empty string
+
+ return rc;
+
+} // get_port_ip4_netmask_str
-} // str_to_ip4_addr
diff --git a/mbglib/common/lan_util.h b/mbglib/common/lan_util.h
index d7ee5e3..3b480d5 100755
--- a/mbglib/common/lan_util.h
+++ b/mbglib/common/lan_util.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: lan_util.h 1.1.1.1 2011/04/20 16:09:02 martin TRASH martin $
+ * $Id: lan_util.h 1.1.1.7 2011/09/14 13:51:58 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,20 @@
*
* -----------------------------------------------------------------------
* $Log: lan_util.h $
+ * Revision 1.1.1.7 2011/09/14 13:51:58 martin
+ * Defined some common return codes.
+ * Updated function prototypes.
+ * Revision 1.1.1.6 2011/08/27 14:26:47 udo
+ * new get_port_ip4_addr() and get_port_ip4_netm()
+ * Revision 1.1.1.5 2011/08/27 13:35:05 udo
+ * new get_port_ip4_addr() and get_port_ip4_netm()
+ * Revision 1.1.1.4 2011/08/25 20:39:14 martin
+ * Defined MBG_MAC_ADDR.
+ * Updated function prototypes
+ * Revision 1.1.1.3 2011/08/04 13:44:55 philipp
+ * prototype for function: check_port_link
+ * Revision 1.1.1.2 2011/06/22 07:47:48 martin
+ * Cleaned up handling of pragma pack().
* Revision 1.1.1.1 2011/04/20 16:09:02 martin
* Revision 1.1 2011/03/04 10:01:32 martin
* Initial revision.
@@ -22,10 +36,23 @@
/* Other headers to be included */
+#include <mbg_tgt.h>
#include <gpsdefs.h>
#include <stdlib.h>
+#if defined( MBG_TGT_UNIX )
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <net/if.h>
+#else
+ // A dummy declaration to prevent from warnings due to usage
+ // of this type with function prototypes.
+ struct ifreq
+ {
+ int dummy;
+ };
+#endif
#ifdef _LAN_UTIL
#define _ext
@@ -37,8 +64,13 @@
/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
+#endif
+
+#ifdef __cplusplus
+extern "C" {
#endif
@@ -50,13 +82,27 @@
#define MAC_SEP_CHAR_ALT '-' // alternate character
#endif
+#if !defined( IFHWADDRLEN )
+ #define IFHWADDRLEN 6 //##+++++ usually defined in net/if.h
+#endif
+#define MBG_LU_SUCCESS 0 // success
+#define MBG_LU_ERR_NSUPP -1 // function not supported
+#define MBG_LU_ERR_PORT_NAME -2 // port name exceeds max length
+#define MBG_LU_ERR_SOCKET -3 // failed to open socket
+#define MBG_LU_ERR_IOCTL -4 // IOCTL call failed
+#define MBG_LU_ERR_NOT_SET -5 // octets are all 0
+#define MBG_LU_ERR_BUFF_SZ -6 // buffer size too small
-/* function prototypes: */
-#ifdef __cplusplus
-extern "C" {
-#endif
+typedef struct
+{
+ uint8_t b[IFHWADDRLEN];
+} MBG_MAC_ADDR;
+
+
+
+/* function prototypes: */
/* ----- function prototypes begin ----- */
@@ -64,6 +110,31 @@ extern "C" {
/* by MAKEHDR, do not remove the comments. */
/**
+ * @brief Print an IPv4 address to a dotted quad format string.
+ *
+ * @param s The string buffer into which to print
+ * @param max_len Maximum length of the string, i.e. size of the buffer
+ * @param addr The IPv4 address
+ * @param info An optional string which is prepended to the string, or NULL
+ *
+ * @return The overall number of characters printed to the string
+ */
+ int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *addr, const char *info ) ;
+
+ /**
+ * @brief Convert a string to an IP4_ADDR.
+ *
+ * @param p Pointer to the IP4_ADDR variable, or NULL, in which case this
+ * function can be used to check if the string is formally correct.
+ * @param s The string to be converted
+ *
+ * @return >= 0 on success, number of characters evaluated from the input string
+ * -1 if invalid number found in string
+ * -2 if separator is not a dot '.'
+ */
+ int str_to_ip4_addr( IP4_ADDR *p, const char *s ) ;
+
+ /**
* @brief Print a MAC ID or similar array of octets to a string.
*
* @param s The string buffer into which to print
@@ -73,45 +144,108 @@ extern "C" {
* @param sep The separator printed between the bytes, or 0
* @param info An optional string which is prepended to the output, or NULL
*
- * @return The overall number of characters printed to the string
+ * @return The overall number of characters printed to the string
*/
int snprint_octets( char *s, size_t max_len, const uint8_t *octets, int num_octets, char sep, const char *info ) ;
/**
- * @brief Set a MAC ID or a similar array of bytes from a string.
+ * @brief Print a MAC address to a string.
+ *
+ * @param s The string buffer into which to print
+ * @param max_len Maximum length of the string, i.e. size of the buffer
+ * @param p_mac_addr The MAC address to be printed
+ *
+ * @return The overall number of characters printed to the string
+ */
+ int snprint_mac_addr( char *s, size_t max_len, const MBG_MAC_ADDR *p_mac_addr ) ;
+
+ /**
+ * @brief Set a MAC ID or a similar array of octets from a string.
*
* @param octets An array of octets to be set up
* @param num_octets The number of octets which can be stored
* @param s The string to be converted
*
- * @return The overall number of octets decoded from the string
+ * @return The overall number of octets decoded from the string
*/
int str_to_octets( uint8_t *octets, int num_octets, const char *s ) ;
/**
- * @brief Print an IPv4 address to a dotted quad format string.
+ * @brief Check if an array of octets is valid, i.e. != 0
*
- * @param s The string buffer into which to print
- * @param max_len Maximum length of the string, i.e. size of the buffer
- * @param addr The IPv4 address
- * @param info An optional string which is prepended to the string, or NULL
+ * @param octets Pointer to the array of octets
+ * @param num_octets Number of octets
*
- * @return The overall number of characters printed to the string
+ * @return MBG_LU_SUCCESS octets are valid, i.e. not all 0
+ * MBG_LU_ERR_NOT_SET octets are invalid, i.e. all 0
*/
- int snprint_ip4_addr( char *s, size_t max_len, const IP4_ADDR *addr, const char *info ) ;
+ int check_octets_not_all_zero( const uint8_t *octets, int num_octets ) ;
/**
- * @brief Convert a string to an IP4_ADDR.
+ * @brief Do a SIOCGxxx IOCTL call to read specific information from a LAN interface
*
- * @param p Pointer to the IP4_ADDR variable, or NULL, in which case this
- * function can be used to check if the string is formally correct.
- * @param s The string to be converted
+ * @param if_name Name of the interface
+ * @param ioctl_code One of the predefined system SIOCGxxx IOCTL codes
+ * @param p_ifreq Pointer to a request buffer
*
- * @return >= 0 on success, number of characters evaluated from the input string
- * -1 if invalid number found in string
- * -2 if separator is not a dot '.'
+ * @return one of the MBG_LU_xxx codes
*/
- int str_to_ip4_addr( IP4_ADDR *p, const char *s ) ;
+ int do_siocg_ioctl( const char *if_name, int ioctl_code, struct ifreq *p_ifreq ) ;
+
+ /**
+ * @brief Retrieve the MAC address of a network interface
+ *
+ * @param if_name Name of the interface
+ * @param p_mac_addr Pointer to the MAC address buffer to be filled up
+ *
+ * @return one of the MBG_LU_xxx codes
+ * on error the MAC addr is set to all 0
+ */
+ int get_port_mac_addr( const char *if_name, MBG_MAC_ADDR *p_mac_addr ) ;
+
+ /**
+ * @brief Retrieve and check the MAC address of a network interface
+ *
+ * @param if_name Name of the interface
+ * @param p_mac_addr Pointer to the MAC address buffer to be filled up
+ *
+ * @return one of the MBG_LU_xxx codes
+ * on error the MAC addr is set to all 0
+ */
+ int get_port_mac_addr_check( const char *if_name, MBG_MAC_ADDR *p_mac_addr ) ;
+
+ /**
+ * @brief Check the link state of a network interface
+ *
+ * @param ifname Name of the interface
+ *
+ * @return 1 link detected on port
+ * 0 no link detected on port
+ * one of the MBG_LU_xxx codes in case of an error
+ */
+ int check_port_link( const char *if_name ) ;
+
+ /**
+ * @brief Retrieve the IPv4 address of a network interface as string
+ *
+ * @param if_name Name of the interface
+ * @param p_addr_buf Pointer to the string buffer to be filled up
+ * @param buf_size size of the string buffer
+ *
+ * @return one of the MBG_LU_xxx codes
+ */
+ int get_port_ip4_addr_str( const char *if_name, char *p_addr_buf, int buf_size ) ;
+
+ /**
+ * @brief Retrieve the IPv4 net mask of a network interface as string
+ *
+ * @param if_name Name of the interface
+ * @param p_addr_buf Pointer to the string buffer to be filled up
+ * @param buf_size size of the string buffer
+ *
+ * @return one of the MBG_LU_xxx codes
+ */
+ int get_port_ip4_netmask_str( const char *if_name, char *p_addr_buf, int buf_size ) ;
/* ----- function prototypes end ----- */
@@ -121,11 +255,9 @@ extern "C" {
#endif
-
-
-
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/macioctl.h b/mbglib/common/macioctl.h
index 03cfa9d..994f7ff 100755
--- a/mbglib/common/macioctl.h
+++ b/mbglib/common/macioctl.h
@@ -1,28 +1,49 @@
/**************************************************************************
*
- * $Id: macioctl.h 1.33.1.17.1.3 2011/04/19 15:05:44 martin TRASH martin $
+ * $Id: macioctl.h 1.33.1.28 2011/10/05 09:00:14 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
* Description:
* Macros used inside the IOCTL handlers of device drivers
- * for Meinberg radio clocks.
+ * for Meinberg PCI and USB devices.
*
* -----------------------------------------------------------------------
* $Log: macioctl.h $
- * Revision 1.33.1.17.1.3 2011/04/19 15:05:44 martin
- * PTP unicast cfg stuff ...
- * Revision 1.33.1.17.1.2 2011/04/19 13:08:33 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.33.1.17.1.1 2011/04/19 09:58:38 martin
- * Started PTP unicast
+ * Revision 1.33.1.28 2011/10/05 09:00:14 martin
+ * Made inline functions static.
+ * Revision 1.33.1.27 2011/09/21 16:01:54 martin
+ * Include cfg_hlp.h.
+ * Revision 1.33.1.26 2011/09/08 13:17:54 martin
+ * Always read receiver info directly from the device.
+ * Revision 1.33.1.25 2011/07/20 15:48:22 martin
+ * Conditionally use older IOCTL request buffer structures.
+ * Revision 1.33.1.24 2011/07/19 12:52:05 martin
+ * Revision 1.33.1.23 2011/07/14 14:53:58 martin
+ * Modified generic IOCTL handling such that for calls requiring variable sizes
+ * a fixed request block containing input and output buffer pointers and sizes is
+ * passed down to the kernel driver. This simplifies implementation under *BSD
+ * and also works for other target systems.
+ * Revision 1.33.1.22 2011/07/06 11:19:19 martin
+ * Support reading CORR_INFO, and reading/writing TR_DISTANCE.
+ * Revision 1.33.1.21 2011/06/29 10:51:16 martin
+ * Support IOCTL_DEV_HAS_PZF.
+ * Revision 1.33.1.20 2011/05/18 10:08:13 martin
+ * Re-ordered IOCTL evaluation to match ioctl_get_required_privilege()
+ * which also makes sure calls requiring lowest latency are handled first.
+ * Revision 1.33.1.19 2011/05/17 16:05:06 martin
+ * Use a single union type buffer instead of a large number of local
+ * variables in ioctl_switch().
+ * The accumulated size of all local variables required much stack
+ * space which led to problems under Windows.
+ * Revision 1.33.1.18 2011/05/17 09:37:31 martin
+ * Support PTP unicast configuration.
+ * Account for some IOCTL codes renamed to follow common naming conventions.
* Revision 1.33.1.17 2011/04/12 15:28:54 martin
* Use common mutex primitives from mbgmutex.h.
* Revision 1.33.1.16 2011/03/31 10:57:00 martin
* Revision 1.33.1.15 2011/03/31 07:32:09 martin
- *
- * --- Added comments --- martin [2011/03/31 10:41:58Z]
* This version is the same as 1.33.1.12.
* Revision 1.33.1.14 2011/03/31 07:16:34 martin
* Changes by Frank Kardel: Don't require copyin/copyout under NetBSD.
@@ -111,7 +132,7 @@
* Support mapped I/O resources.
* Revision 1.22 2008/01/17 09:28:49 daniel
* Support for memory mapped I/O under Linux and Windows.
- * Added macros _io_get_mapped_mem_address(),
+ * Added macros _io_get_mapped_mem_address(),
* _io_unmap_mapped_mem_address().
* Account for IOCTL_GET_PCI_ASIC_FEATURES
* Cleanup for PCI ASIC version.
@@ -193,8 +214,9 @@
#ifndef _MACIOCTL_H
#define _MACIOCTL_H
-#include <pcpsdrvr.h>
#include <mbgioctl.h>
+#include <cfg_hlp.h>
+#include <pcpsdrvr.h>
#include <pci_asic.h>
#include <mbgddmsg.h>
@@ -214,32 +236,26 @@ typedef struct
} XYZs;
-#define USE_DEBUG_PORT !defined( MBG_ARCH_ARM )
-
-// OS dependent definitions
+// OS dependent primitives
#if defined( MBG_TGT_LINUX )
- #define _pcps_iob( _type, _s ) _type _s
- #define _pcps_iob_arr( _type, _s, n ) _type _s[_n]
-
- #define _pcps_iob_to_pout_size( _type, _iob, _pout, _size ) \
- if ( copy_to_user( (_type *)(_pout), &(_iob), _size ) ) \
+ #define _iob_to_pout( _piob, _pout, _size ) \
+ if ( copy_to_user( _pout, _piob, _size ) ) \
goto err_to_user;
- #define _pcps_iob_from_pin_size( _type, _iob, _pin, _size ) \
- if ( copy_from_user( &(_iob), (_type *) (_pin), _size ) ) \
+ #define _iob_from_pin( _piob, _pin, _size ) \
+ if ( copy_from_user( _piob, _pin, _size ) ) \
goto err_from_user;
#define _io_wait_pcps_sec_change( _pddev, _cmd, _type, _pout ) \
goto err_inval
- #define _io_get_mapped_mem_address( _pddev, _pout ) \
- { \
- _pcps_iob( PCPS_MAPPED_MEM, _s ); \
- _s.pfn_offset = ( pddev->rsrc_info.mem[0].start & ~PAGE_MASK ) + sizeof( PCI_ASIC ); \
- _s.len = pddev->rsrc_info.mem[0].len - sizeof( PCI_ASIC ); \
- _pcps_iob_to_pout_size( PCPS_MAPPED_MEM, _s, _pout, sizeof( PCPS_MAPPED_MEM ) ); \
+ #define _io_get_mapped_mem_address( _pddev, _pout ) \
+ { \
+ iob.mapped_mem.pfn_offset = ( pddev->rsrc_info.mem[0].start & ~PAGE_MASK ) + sizeof( PCI_ASIC ); \
+ iob.mapped_mem.len = pddev->rsrc_info.mem[0].len - sizeof( PCI_ASIC ); \
+ _iob_to_pout_var( iob.mapped_mem, _pout ); \
}
#define _io_unmap_mapped_mem_address( _pddev, _pin ) \
@@ -251,14 +267,17 @@ typedef struct
#include <sys/malloc.h>
- #define _pcps_iob( _type, _s ) _type _s
- #define _pcps_iob_arr( _type, _s, n ) _type _s[_n]
+ #define _iob_to_pout( _piob, _pout, _size ) \
+ memcpy( _pout, _piob, _size )
+
+ #define _iob_from_pin( _piob, _pin, _size ) \
+ memcpy( _piob, _pin, _size )
- #define _pcps_iob_to_pout_size( _type, _iob, _pout, _size ) \
- memcpy( (_type *)(_pout), &(_iob), _size )
+ #define _frc_iob_to_pout( _piob, _pout, _size ) \
+ copyout( _piob, _pout, _size )
- #define _pcps_iob_from_pin_size( _type, _iob, _pin, _size ) \
- memcpy( &(_iob), (_type *) (_pin), _size )
+ #define _frc_iob_from_pin( _piob, _pin, _size ) \
+ copyin( _pin, _piob, _size )
#define _io_wait_pcps_sec_change( _pddev, _cmd, _type, _pout ) \
goto err_inval
@@ -271,17 +290,14 @@ typedef struct
#elif defined( MBG_TGT_WIN32 )
- #define _pcps_iob( _type, _s ) _type _s
- #define _pcps_iob_arr( _type, _s, n ) _type _s[_n]
-
- #define _pcps_iob_to_pout_size( _type, _iob, _pout, _size ) \
- { \
- RtlCopyMemory( _pout, &_iob, _size ); \
- *ret_size = _size; \
+ #define _iob_to_pout( _piob, _pout, _size ) \
+ { \
+ RtlCopyMemory( _pout, _piob, _size ); \
+ *ret_size = _size; \
}
- #define _pcps_iob_from_pin_size( _type, _iob, _pin, _size ) \
- RtlCopyMemory( &_iob, _pin, _size );
+ #define _iob_from_pin( _piob, _pin, _size ) \
+ RtlCopyMemory( _piob, _pin, _size );
// The following macros are defined in the OS dependent code:
//
@@ -295,15 +311,25 @@ typedef struct
-#define _pcps_iob_to_pout( _type, _iob, _pout ) \
- _pcps_iob_to_pout_size( _type, _iob, _pout, sizeof( _iob ) )
+#if !defined( _frc_iob_to_pout )
+ #define _frc_iob_to_pout _iob_to_pout
+#endif
+
+#if !defined( _frc_iob_from_pin )
+ #define _frc_iob_from_pin _iob_from_pin
+#endif
+
+
+#define _iob_to_pout_var( _iob, _pout ) \
+ _iob_to_pout( &(_iob), _pout, sizeof( _iob ) )
+
+#define _iob_from_pin_var( _iob, _pin ) \
+ _iob_from_pin( &(_iob), _pin, sizeof( _iob ) )
-#define _pcps_iob_from_pin( _type, _iob, _pin ) \
- _pcps_iob_from_pin_size( _type, _iob, _pin, sizeof( _iob ) )
-// For some cards it may be unsafe to access the card while
-// interrups are enabled for the card since IRQs may during
+// For some cards it may be unsafe to access the card while
+// interrups are enabled for the card since IRQs may during
// access may mess up the interface. The macro below checks
// whether this is the case.
#define _pcps_access_is_unsafe( _pddev ) \
@@ -315,11 +341,12 @@ typedef struct
// preventing the card from being accessed from IRQ handler.
#if defined( MBG_TGT_WIN32 )
- // Under Windows.we need to save a pointer to the current
+ // Under Windows we need to save a pointer to the current
// IRP by default.
#define _pcps_sem_inc_safe( _pddev ) \
if ( _pcps_access_is_unsafe( _pddev ) ) \
goto err_busy_unsafe; \
+ \
_pcps_sem_inc( _pddev ); \
(_pddev)->irp = pIrp
@@ -331,6 +358,7 @@ typedef struct
#define _pcps_sem_inc_safe_no_irp( _pddev ) \
if ( _pcps_access_is_unsafe( _pddev ) ) \
goto err_busy_unsafe; \
+ \
_pcps_sem_inc( _pddev ); \
(_pddev)->irp = NULL
@@ -341,6 +369,7 @@ typedef struct
#define _pcps_sem_inc_safe( _pddev ) \
if ( _pcps_access_is_unsafe( _pddev ) ) \
goto err_busy_unsafe; \
+ \
_pcps_sem_inc( _pddev ); \
#endif
@@ -348,145 +377,131 @@ typedef struct
+// Check a condition and go to an error handler
+// if the condition is not true.
+#define _io_chk_cond( _cond ) \
+ if ( !(_cond) ) \
+ goto err_support;
+
+
-// Read a data structure from a clock device.
+// Read a data structure from a device.
// Check the return code and if no error occurred,
// copy the data to the caller's memory space.
-#define _io_read_var( _pddev, _cmd, _type, _pout ) \
-{ \
- _pcps_iob( _type, _s ); \
- \
- _pcps_sem_inc_safe( _pddev ); \
- rc = _pcps_read_var( _pddev, _cmd, _s ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
- \
- _pcps_iob_to_pout( _type, _s, _pout ); \
+#define _io_read_var( _pddev, _cmd, _fld, _pout ) \
+{ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = _pcps_read_var( _pddev, _cmd, iob._fld ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
+ \
+ _iob_to_pout_var( iob._fld, _pout ); \
}
// Retrieve a data structure from the caller's
-// memory space, write it to a clock device and
+// memory space, write it to the device and
// check the return code.
-#define _io_write_var( _pddev, _cmd, _type, _pin ) \
-{ \
- _pcps_iob( _type, _s ); \
- \
- _pcps_iob_from_pin( _type, _s, _pin ); \
- \
- _pcps_sem_inc_safe( _pddev ); \
- rc = _pcps_write_var( _pddev, _cmd, _s ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
+#define _io_write_var( _pddev, _cmd, _fld, _pin ) \
+{ \
+ _iob_from_pin_var( iob._fld, _pin ); \
+ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = _pcps_write_var( _pddev, _cmd, iob._fld ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
}
-// Retrieve a data structure from the caller's
-// memory space, write it to a clock device and
+// Write a command byte to the device and
// check the return code.
-#define _io_write_cmd( _pddev, _cmd ) \
-{ \
- _pcps_sem_inc_safe( _pddev ); \
- rc = _pcps_write_byte( _pddev, _cmd ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
+#define _io_write_cmd( _pddev, _cmd ) \
+{ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = _pcps_write_byte( _pddev, _cmd ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
}
-// Check if a clock is a GPS device. If it is,
-// read GPS data with variable size from the device.
+// Check if a device supports large (GPS) data structures.
+// If it does, read GPS data of given size from the device.
// Check the return code and if no error occurred,
// copy the data to the caller's memory space.
-#define _io_read_gps( _pddev, _cmd, _type, _pout, _size ) \
-{ \
- _pcps_iob( _type, _s ); \
- \
- if ( !_pcps_ddev_has_gps_data( _pddev ) ) \
- goto err_support; \
- \
- _pcps_sem_inc_safe( _pddev ); \
- rc = pcps_read_gps( _pddev, _cmd, (uchar FAR *) &_s, _size ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
- \
- _pcps_iob_to_pout_size( _type, _s, _pout, _size ); \
+#define _io_read_gps( _pddev, _cmd, _fld, _pout, _size ) \
+{ \
+ _io_chk_cond( _pcps_ddev_has_gps_data( _pddev ) ); \
+ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = pcps_read_gps( _pddev, _cmd, (uchar FAR *) &iob._fld, _size ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
+ \
+ _iob_to_pout( &iob._fld, _pout, _size ); \
}
-// Check if a clock is a GPS device. If it is,
-// read a GPS data structure from the device.
+// Check if a device supports large (GPS) data structures.
+// If it does, read a GPS data structure from the device.
// Check the return code and if no error occurred,
// copy the data to the caller's memory space.
-#define _io_read_gps_var( _pddev, _cmd, _type, _pout ) \
-{ \
- _pcps_iob( _type, _s ); \
- \
- if ( !_pcps_ddev_has_gps_data( _pddev ) ) \
- goto err_support; \
- \
- _pcps_sem_inc_safe( _pddev ); \
- rc = _pcps_read_gps_var( _pddev, _cmd, _s ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
- \
- _pcps_iob_to_pout( _type, _s, _pout ); \
+#define _io_read_gps_var( _pddev, _cmd, _fld, _pout ) \
+{ \
+ _io_chk_cond( _pcps_ddev_has_gps_data( _pddev ) ); \
+ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = _pcps_read_gps_var( _pddev, _cmd, iob._fld ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
+ \
+ _iob_to_pout_var( iob._fld, _pout ); \
}
-// Check if a clock is a GPS device. If it is,
-// retrieve a data structure from the caller's
-// memory space, write it to the clock device and
-// check the return code.
-#define _io_write_gps_var( _pddev, _cmd, _type, _pin ) \
-{ \
- _pcps_iob( _type, _s ); \
- \
- if ( !_pcps_ddev_has_gps_data( _pddev ) ) \
- goto err_support; \
- \
- _pcps_iob_from_pin( _type, _s, _pin ); \
- \
- _pcps_sem_inc_safe( _pddev ); \
- rc = _pcps_write_gps_var( _pddev, _cmd, _s ); \
- _pcps_sem_dec( _pddev ); \
- \
- if ( rc != MBG_SUCCESS ) \
- goto err_access; \
+// Check if a device supports large (GPS) data structures.
+// If it does, retrieve a data structure from the caller's
+// memory space, write it to the device and check
+// the return code.
+#define _io_write_gps_var( _pddev, _cmd, _fld, _pin ) \
+{ \
+ _io_chk_cond( _pcps_ddev_has_gps_data( _pddev ) ); \
+ \
+ _iob_from_pin_var( iob._fld, _pin ); \
+ \
+ _pcps_sem_inc_safe( _pddev ); \
+ rc = _pcps_write_gps_var( _pddev, _cmd, iob._fld ); \
+ _pcps_sem_dec( _pddev ); \
+ \
+ if ( rc != MBG_SUCCESS ) \
+ goto err_access; \
}
-// Check a condition an go to an error handler
-// if the condition is not true.
-#define _io_chk_cond( _cond ) \
- if ( !(_cond) ) \
- goto err_support;
-
-
// The macros below are similar to those defined above except
// that they check if a condition is true before they really
// do anything. This is used for IOCTL calls which may not
-// be supported with any type of clock device.
-#define _io_read_var_chk( _pddev, _cmd, _type, _pout, _cond ) \
-{ \
- _io_chk_cond( _cond ); \
- _io_read_var( _pddev, _cmd, _type, _pout ); \
+// be supported by every device.
+#define _io_read_var_chk( _pddev, _cmd, _fld, _pout, _cond ) \
+{ \
+ _io_chk_cond( _cond ); \
+ _io_read_var( _pddev, _cmd, _fld, _pout ); \
}
-#define _io_write_var_chk( _pddev, _cmd, _type, _pin, _cond ) \
-{ \
- _io_chk_cond( _cond ); \
- _io_write_var( _pddev, _cmd, _type, _pin ); \
+#define _io_write_var_chk( _pddev, _cmd, _fld, _pin, _cond ) \
+{ \
+ _io_chk_cond( _cond ); \
+ _io_write_var( _pddev, _cmd, _fld, _pin ); \
}
#define _io_write_cmd_chk( _pddev, _cmd, _cond ) \
@@ -495,48 +510,48 @@ typedef struct
_io_write_cmd( _pddev, _cmd ); \
}
-#define _io_read_gps_chk( _pddev, _cmd, _type, _pout, _size, _cond ) \
+#define _io_read_gps_chk( _pddev, _cmd, _fld, _pout, _size, _cond ) \
{ \
_io_chk_cond( _cond ); \
- _io_read_gps( _pddev, _cmd, _type, _pout, _size ); \
+ _io_read_gps( _pddev, _cmd, _fld, _pout, _size ); \
}
-#define _io_read_gps_var_chk( _pddev, _cmd, _type, _pout, _cond ) \
-{ \
- _io_chk_cond( _cond ); \
- _io_read_gps_var( _pddev, _cmd, _type, _pout ); \
+#define _io_read_gps_var_chk( _pddev, _cmd, _fld, _pout, _cond ) \
+{ \
+ _io_chk_cond( _cond ); \
+ _io_read_gps_var( _pddev, _cmd, _fld, _pout ); \
}
-#define _io_write_gps_var_chk( _pddev, _cmd, _type, _pin, _cond ) \
-{ \
- _io_chk_cond( _cond ); \
- _io_write_gps_var( _pddev, _cmd, _type, _pin ); \
+#define _io_write_gps_var_chk( _pddev, _cmd, _fld, _pin, _cond ) \
+{ \
+ _io_chk_cond( _cond ); \
+ _io_write_gps_var( _pddev, _cmd, _fld, _pin ); \
}
-#define _report_cond( _cond, _pout ) \
-{ \
- int retval = _cond; \
- _pcps_iob_to_pout( int, retval, _pout ); \
+#define _report_cond( _cond, _pout ) \
+{ \
+ iob.i = _cond; \
+ _iob_to_pout_var( iob.i, _pout ); \
}
-#define _mbg_dbg_set_bit( _d, _v ) \
-{ \
- mbg_dbg_data |= (_v); \
+#define _mbg_dbg_set_bit( _d, _v ) \
+{ \
+ mbg_dbg_data |= (_v); \
_mbg_outp8( (_d), 0, mbg_dbg_port_mapped, mbg_dbg_data ); \
}
-#define _mbg_dbg_clr_bit( _d, _v ) \
-{ \
- mbg_dbg_data &= ~(_v); \
+#define _mbg_dbg_clr_bit( _d, _v ) \
+{ \
+ mbg_dbg_data &= ~(_v); \
_mbg_outp8( (_d), 0, mbg_dbg_port_mapped, mbg_dbg_data ); \
}
-#define _mbg_dbg_clr_all( _d ) \
-{ \
- mbg_dbg_data = 0; \
+#define _mbg_dbg_clr_all( _d ) \
+{ \
+ mbg_dbg_data = 0; \
_mbg_outp8( (_d), 0, mbg_dbg_port_mapped, mbg_dbg_data ); \
}
@@ -551,13 +566,90 @@ typedef struct
#endif
+typedef union
+{
+ PCPS_STATUS_PORT pcps_status_port;
+ PCPS_TIME pcps_time;
+ PCPS_STIME pcps_stime;
+ PCPS_HR_TIME pcps_hr_time;
+ PCPS_TIME_STAMP pcps_time_stamp;
+ PCPS_SERIAL pcps_serial;
+ PCPS_TZCODE pcps_tzcode;
+ PCPS_TZDL pcps_tzdl;
+ MBG_REF_OFFS mbg_ref_offs;
+ MBG_OPT_INFO mbg_opt_info;
+ MBG_OPT_SETTINGS mbg_opt_settings;
+ IRIG_INFO irig_info;
+ IRIG_SETTINGS irig_settings;
+ PCPS_UCAP_ENTRIES pcps_ucap_entries;
+ TZDL tzdl;
+ SW_REV sw_rev;
+ BVAR_STAT bvar_stat;
+ TTM ttm;
+ PORT_PARM port_parm;
+ ANT_INFO ant_info;
+ ENABLE_FLAGS enable_flags;
+ STAT_INFO stat_info;
+ RECEIVER_INFO receiver_info;
+ GPS_CMD gps_cmd;
+ IDENT ident;
+ POS pos;
+ XYZs xyzs;
+ LLAs llas;
+ ANT_CABLE_LEN ant_cable_len;
+ PORT_SETTINGS_IDX port_settings_idx;
+ SYNTH synth;
+ SYNTH_STATE synth_state;
+ ALL_POUT_INFO all_pout_info;
+ POUT_SETTINGS_IDX pout_settings_idx;
+ ALL_STR_TYPE_INFO all_str_type_info;
+ ALL_PORT_INFO all_port_info;
+ ALL_PTP_UC_MASTER_INFO all_ptp_uc_master_info;
+ MBG_TIME_SCALE_INFO mbg_time_scale_info;
+ MBG_TIME_SCALE_SETTINGS mbg_time_scale_settings;
+ UTC utc;
+ MBG_IRIG_CTRL_BITS mbg_irig_ctrl_bits;
+ LAN_IF_INFO lan_if_info;
+ IP4_SETTINGS ip4_settings;
+ PTP_STATE ptp_state;
+ PTP_CFG_INFO ptp_cfg_info;
+ PTP_CFG_SETTINGS ptp_cfg_settings;
+ PCPS_IRIG_TIME pcps_irig_time;
+ MBG_RAW_IRIG_DATA mbg_raw_irig_data;
+ PTP_UC_MASTER_CFG_LIMITS ptp_uc_master_cfg_limits;
+ PTP_UC_MASTER_SETTINGS_IDX ptp_uc_master_settings_idx;
+ PCPS_TIME_CYCLES pcps_time_cycles;
+ PCPS_HR_TIME_CYCLES pcps_hr_time_cycles;
+ MBG_DBG_PORT mbg_dbg_port;
+ MBG_DBG_DATA mbg_dbg_data;
+ MBG_PC_CYCLES_FREQUENCY mbg_pc_cycles_frequency;
+ PCPS_TIME_STAMP_CYCLES pcps_time_stamp_cycles;
+ MBG_TIME_INFO_HRT mbg_time_info_hrt;
+ MBG_TIME_INFO_TSTAMP mbg_time_info_tstamp;
+ CORR_INFO corr_info;
+ TR_DISTANCE tr_distance;
+
+ PCPS_MAPPED_MEM mapped_mem;
+
+ #if USE_IOCTL_GENERIC_REQ
+ IOCTL_GENERIC_REQ req;
+ #else
+ IOCTL_GENERIC_CTL ctl;
+ #endif
+
+ int i;
+
+} IOCTL_BUFFER;
+
+
+
#if defined( __GNUC__ )
// Avoid "no previous prototype" with some gcc versions.
-__mbg_inline
+static __mbg_inline
void swap_tstamp( PCPS_TIME_STAMP *p_ts ) __attribute__((always_inline));
#endif
-__mbg_inline
+static __mbg_inline
void swap_tstamp( PCPS_TIME_STAMP *p_ts )
{
uint32_t tmp = p_ts->sec;
@@ -570,12 +662,12 @@ void swap_tstamp( PCPS_TIME_STAMP *p_ts )
#if defined( __GNUC__ )
// Avoid "no previous prototype" with some gcc versions.
-__mbg_inline
+static __mbg_inline
void do_get_fast_hr_timestamp_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP *p_ts ) __attribute__((always_inline));
#endif
-__mbg_inline
+static __mbg_inline
void do_get_fast_hr_timestamp_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP *p_ts )
{
#if TEST_MM_ACCESS_64
@@ -666,11 +758,11 @@ void do_get_fast_hr_timestamp_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP *p_ts )
#if defined( __GNUC__ )
// Avoid "no previous prototype" with some gcc versions.
-__mbg_inline
+static __mbg_inline
void do_get_fast_hr_timestamp_cycles_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP_CYCLES *p_ts_cyc ) __attribute__((always_inline));
#endif
-__mbg_inline
+static __mbg_inline
void do_get_fast_hr_timestamp_cycles_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP_CYCLES *p_ts_cyc )
{
volatile uint32_t *p = (volatile uint32_t *) pddev->mm_tstamp_addr;
@@ -684,1163 +776,1234 @@ void do_get_fast_hr_timestamp_cycles_safe( PCPS_DDEV *pddev, PCPS_TIME_STAMP_CYC
} // do_get_fast_hr_timestamp_cycles_safe
-
#if defined( __GNUC__ )
// Avoid "no previous prototype" with some gcc versions.
-__mbg_inline
-int ioctl_switch( PCPS_DDEV *pddev, int ioctl_code,
+static __mbg_inline
+int ioctl_switch( PCPS_DDEV *pddev, unsigned int ioctl_code,
#if defined( MBG_TGT_WIN32 )
IRP *pIrp, int *ret_size, uint16_t pout_size,
#endif
void *pin, void *pout ) __attribute__((always_inline));
#endif
-__mbg_inline
-int ioctl_switch( PCPS_DDEV *pddev, int ioctl_code,
+/**
+ * @brief Decode an handle IOCTL commands.
+ *
+ * This function is called from the OS dependent IOCTL handlers.
+ *
+ * @param pddev Pointer to the device structure
+ * @param ioctl_code The IOCTL code to be handled
+#if defined( MBG_TGT_WIN32 )
+ * @param pIrp The IRP associated to the IOCTL call
+ * @param ret_size The number of bytes to be returned
+ * @param pout_size The size of the output buffer
+#endif
+ * @param pin The input buffer
+ * @param pout The output buffer
+ *
+ * @return MBG_SUCCESS or one of the Meinberg error codes which need to be translated
+ * by the calling function to the OS dependent error code.
+ * @return -1 for unknown IOCTL codes
+ */
+static __mbg_inline
+int ioctl_switch( PCPS_DDEV *pddev, unsigned int ioctl_code,
#if defined( MBG_TGT_WIN32 )
IRP *pIrp, int *ret_size, uint16_t pout_size,
#endif
void *pin, void *pout )
{
+ #if USE_DEBUG_PORT
+ MBG_PC_CYCLES cyc;
+ #endif
+ IOCTL_BUFFER iob;
+ #if USE_IOCTL_GENERIC_REQ
+ void *p_buff_in;
+ void *p_buff_out;
+ #else
+ IOCTL_GENERIC_BUFFER *p_buff;
+ int buffer_size;
+ #endif
+ uint8_t pcps_cmd;
int rc = MBG_SUCCESS;
+ // To provide best maintainability the sequence of cases here should match
+ // the sequence in ioctl_get_required_privilege(), which also makes sure
+ // commands requiring lowest latency are handled first.
+
switch ( ioctl_code )
{
- case IOCTL_GET_PCPS_DRVR_INFO:
- _pcps_iob_to_pout( PCPS_DRVR_INFO,
- drvr_info, pout );
- break;
+ // Commands requiring lowest latency
-
- case IOCTL_GET_PCPS_DEV:
- _pcps_iob_to_pout( PCPS_DEV, pddev->dev, pout );
+ case IOCTL_GET_FAST_HR_TIMESTAMP:
+ _io_chk_cond( _pcps_ddev_has_fast_hr_timestamp( pddev ) );
+ do_get_fast_hr_timestamp_safe( pddev, &iob.pcps_time_stamp );
+ _iob_to_pout_var( iob.pcps_time_stamp, pout );
+ rc = MBG_SUCCESS;
break;
- #if !defined( OMIT_STATUS_PORT )
- case IOCTL_GET_PCPS_STATUS_PORT:
- {
- if ( _pcps_ddev_is_usb( pddev ) )
- {
- _io_read_var( pddev, PCPS_GET_STATUS_PORT,
- PCPS_STATUS_PORT, pout );
-
- }
- else
- {
- PCPS_STATUS_PORT status =
- _pcps_ddev_read_status_port( pddev );
- _pcps_iob_to_pout( PCPS_STATUS_PORT, status, pout );
- }
+ case IOCTL_GET_PCPS_HR_TIME:
+ _io_read_var_chk( pddev, PCPS_GIVE_HR_TIME, pcps_hr_time, pout,
+ _pcps_ddev_has_hr_time( pddev ) );
break;
- }
- #endif
- case IOCTL_PCPS_GENERIC_READ:
- {
- IOCTL_GENERIC_CTL ctl;
- IOCTL_GENERIC_BUFFER *p_buff;
- int buffer_size;
-
- _pcps_iob_from_pin( IOCTL_GENERIC_CTL, ctl, pin );
- buffer_size = sizeof( ctl ) + ctl.data_size_out;
- p_buff = _pcps_kmalloc( buffer_size );
+ case IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES:
+ _io_chk_cond( _pcps_ddev_has_fast_hr_timestamp( pddev ) );
+ do_get_fast_hr_timestamp_cycles_safe( pddev, &iob.pcps_time_stamp_cycles );
+ _iob_to_pout_var( iob.pcps_time_stamp_cycles, pout );
+ rc = MBG_SUCCESS;
+ break;
- if ( p_buff == NULL )
- goto err_no_mem;
+ case IOCTL_GET_PCPS_HR_TIME_CYCLES:
_pcps_sem_inc_safe( pddev );
- rc = _pcps_read( pddev, (uint8_t) ctl.info,
- p_buff->data,
- (uint8_t) ctl.data_size_out );
+ rc = _pcps_read_var( pddev, PCPS_GIVE_HR_TIME, iob.pcps_hr_time_cycles.t );
+ iob.pcps_hr_time_cycles.cycles = pddev->acc_cycles;
_pcps_sem_dec( pddev );
- if ( rc == MBG_SUCCESS )
- {
- p_buff->ctl = ctl;
- _pcps_iob_to_pout_size( uint8_t, *p_buff, pout,
- buffer_size );
- }
-
- _pcps_kfree( p_buff, buffer_size );
-
if ( rc != MBG_SUCCESS )
goto err_access;
+ _iob_to_pout_var( iob.pcps_hr_time_cycles, pout );
break;
- }
- case IOCTL_PCPS_GENERIC_WRITE:
- {
- IOCTL_GENERIC_CTL ctl;
- IOCTL_GENERIC_BUFFER *p_buff;
- int buffer_size;
+ case IOCTL_GET_PCPS_UCAP_EVENT:
+ _io_read_var_chk( pddev, PCPS_GIVE_UCAP_EVENT, pcps_hr_time,
+ pout, _pcps_ddev_has_ucap( pddev ) );
+ break;
- _pcps_iob_from_pin( IOCTL_GENERIC_CTL, ctl, pin );
- buffer_size = sizeof( ctl ) + ctl.data_size_in;
- p_buff = _pcps_kmalloc( buffer_size );
- if ( p_buff == NULL )
- goto err_no_mem;
+ // Other low latency commands
+
+ case IOCTL_GET_PCPS_TIME:
+ _io_read_var( pddev, PCPS_GIVE_TIME_NOCLEAR, pcps_time, pout );
+ break;
- _pcps_iob_from_pin_size( uint8_t, *p_buff, pin,
- buffer_size );
+ case IOCTL_GET_PCPS_TIME_CYCLES:
_pcps_sem_inc_safe( pddev );
- rc = pcps_write( pddev, (uint8_t) ctl.info,
- p_buff->data,
- (uint8_t) ctl.data_size_in );
+ rc = _pcps_read_var( pddev, PCPS_GIVE_TIME_NOCLEAR, iob.pcps_time_cycles.t );
+ if ( _pcps_ddev_is_usb( pddev ) )
+ iob.pcps_time_cycles.cycles = pddev->acc_cycles;
+ else
+ mbg_get_pc_cycles( &iob.pcps_time_cycles.cycles );
_pcps_sem_dec( pddev );
- _pcps_kfree( p_buff, buffer_size );
-
if ( rc != MBG_SUCCESS )
goto err_access;
+ _iob_to_pout_var( iob.pcps_time_cycles, pout );
break;
- }
-
-
- case IOCTL_PCPS_GENERIC_READ_GPS:
- {
- IOCTL_GENERIC_CTL ctl;
- IOCTL_GENERIC_BUFFER *p_buff;
- int buffer_size;
- _pcps_iob_from_pin( IOCTL_GENERIC_CTL, ctl, pin );
- buffer_size = sizeof( ctl ) + ctl.data_size_out;
- p_buff = _pcps_kmalloc( buffer_size );
-
- if ( p_buff == NULL )
- goto err_no_mem;
- _pcps_sem_inc_safe( pddev );
- rc = pcps_read_gps( pddev, (uint8_t) ctl.info,
- p_buff->data,
- (uint16_t) ctl.data_size_out );
- _pcps_sem_dec( pddev );
-
- if ( rc == MBG_SUCCESS )
+ #if !defined( OMIT_STATUS_PORT )
+ case IOCTL_GET_PCPS_STATUS_PORT:
+ if ( _pcps_ddev_is_usb( pddev ) )
{
- p_buff->ctl = ctl;
- _pcps_iob_to_pout_size( uint8_t, *p_buff, pout,
- buffer_size );
+ _io_read_var( pddev, PCPS_GET_STATUS_PORT, pcps_status_port, pout );
}
+ else
+ {
+ iob.pcps_status_port = _pcps_ddev_read_status_port( pddev );
+ _iob_to_pout_var( iob.pcps_status_port, pout );
+ }
+ break;
+ #endif
- _pcps_kfree( p_buff, buffer_size );
- if ( rc != MBG_SUCCESS )
- goto err_access;
+ case IOCTL_GET_PCPS_TIME_SEC_CHANGE:
+ _io_wait_pcps_sec_change( pddev, PCPS_GIVE_TIME, PCPS_TIME, pout );
+ break;
+
+ case IOCTL_GET_GPS_TIME:
+ _io_read_gps_var( pddev, PC_GPS_TIME, ttm, pout );
break;
- }
- case IOCTL_PCPS_GENERIC_WRITE_GPS:
- {
- IOCTL_GENERIC_CTL ctl;
- IOCTL_GENERIC_BUFFER *p_buff;
- int buffer_size;
+ case IOCTL_GET_GPS_UCAP:
+ _io_read_gps_var( pddev, PC_GPS_UCAP, ttm, pout );
+ break;
- _pcps_iob_from_pin( IOCTL_GENERIC_CTL, ctl, pin );
- buffer_size = sizeof( ctl ) + ctl.data_size_in;
- p_buff = _pcps_kmalloc( buffer_size );
- if ( p_buff == NULL )
- goto err_no_mem;
+ case IOCTL_GET_TIME_INFO_HRT:
+ _io_chk_cond( _pcps_ddev_has_hr_time( pddev ) );
- _pcps_iob_from_pin_size( uint8_t, *p_buff, pin,
- buffer_size );
+ mbg_get_pc_cycles( &iob.mbg_time_info_hrt.sys_time_cycles.cyc_before );
+ mbg_get_sys_time( &iob.mbg_time_info_hrt.sys_time_cycles.sys_time );
+ mbg_get_pc_cycles( &iob.mbg_time_info_hrt.sys_time_cycles.cyc_after );
_pcps_sem_inc_safe( pddev );
- rc = pcps_write_gps( pddev, (uint8_t) ctl.info,
- p_buff->data,
- (uint8_t) ctl.data_size_in );
+ rc = _pcps_read_var( pddev, PCPS_GIVE_HR_TIME, iob.mbg_time_info_hrt.ref_hr_time_cycles.t );
+ iob.mbg_time_info_hrt.ref_hr_time_cycles.cycles = pddev->acc_cycles;
_pcps_sem_dec( pddev );
- _pcps_kfree( p_buff, buffer_size );
-
if ( rc != MBG_SUCCESS )
goto err_access;
+ _iob_to_pout_var( iob.mbg_time_info_hrt, pout );
break;
- }
- case IOCTL_GET_PCPS_TIME:
- _io_read_var( pddev, PCPS_GIVE_TIME_NOCLEAR,
- PCPS_TIME, pout );
- break;
+ case IOCTL_GET_TIME_INFO_TSTAMP:
+ _io_chk_cond( _pcps_ddev_has_fast_hr_timestamp( pddev ) );
+ mbg_get_pc_cycles( &iob.mbg_time_info_tstamp.sys_time_cycles.cyc_before );
+ mbg_get_sys_time( &iob.mbg_time_info_tstamp.sys_time_cycles.sys_time );
+ mbg_get_pc_cycles( &iob.mbg_time_info_tstamp.sys_time_cycles.cyc_after );
- case IOCTL_SET_PCPS_TIME:
- _io_write_var_chk( pddev, PCPS_SET_TIME,
- PCPS_STIME, pin,
- _pcps_ddev_can_set_time( pddev ) );
+ do_get_fast_hr_timestamp_cycles_safe( pddev, &iob.mbg_time_info_tstamp.ref_tstamp_cycles );
+ rc = MBG_SUCCESS;
+
+ _iob_to_pout_var( iob.mbg_time_info_tstamp, pout );
break;
- case IOCTL_GET_PCPS_SYNC_TIME:
- _io_read_var_chk( pddev, PCPS_GIVE_SYNC_TIME,
- PCPS_TIME, pout,
- _pcps_ddev_has_sync_time( pddev ) );
+ // Commands returning public status information
+
+ case IOCTL_GET_PCPS_DRVR_INFO:
+ _iob_to_pout_var( drvr_info, pout );
break;
- case IOCTL_GET_PCPS_TIME_SEC_CHANGE:
- _io_wait_pcps_sec_change( pddev, PCPS_GIVE_TIME,
- PCPS_TIME, pout );
+ case IOCTL_GET_PCPS_DEV:
+ _iob_to_pout_var( pddev->dev, pout );
break;
- case IOCTL_GET_PCPS_HR_TIME:
- _io_read_var_chk( pddev, PCPS_GIVE_HR_TIME,
- PCPS_HR_TIME, pout,
- _pcps_ddev_has_hr_time( pddev ) );
+ case IOCTL_GET_PCPS_SYNC_TIME:
+ _io_read_var_chk( pddev, PCPS_GIVE_SYNC_TIME, pcps_time,
+ pout, _pcps_ddev_has_sync_time( pddev ) );
break;
- case IOCTL_SET_PCPS_EVENT_TIME:
- _io_write_var_chk( pddev, PCPS_SET_EVENT_TIME,
- PCPS_TIME_STAMP, pin,
- _pcps_ddev_has_event_time( pddev ) );
+ case IOCTL_GET_GPS_SW_REV:
+ _io_read_gps_var( pddev, PC_GPS_SW_REV, sw_rev, pout );
break;
- case IOCTL_GET_PCPS_SERIAL:
- _io_read_var( pddev, PCPS_GET_SERIAL,
- PCPS_SERIAL, pout );
+ case IOCTL_GET_GPS_BVAR_STAT:
+ _io_read_gps_var( pddev, PC_GPS_BVAR_STAT, bvar_stat, pout );
break;
- case IOCTL_SET_PCPS_SERIAL:
- _io_write_var( pddev, PCPS_SET_SERIAL,
- PCPS_SERIAL, pin );
+ case IOCTL_GET_GPS_ANT_INFO:
+ _io_read_gps_var( pddev, PC_GPS_ANT_INFO, ant_info, pout );
break;
- case IOCTL_GET_PCPS_TZCODE:
- _io_read_var_chk( pddev, PCPS_GET_TZCODE,
- PCPS_TZCODE, pout,
- _pcps_ddev_has_tzcode( pddev ) );
+ case IOCTL_GET_GPS_STAT_INFO:
+ _io_read_gps_var( pddev, PC_GPS_STAT_INFO, stat_info, pout );
break;
- case IOCTL_SET_PCPS_TZCODE:
- _io_write_var_chk( pddev, PCPS_SET_TZCODE,
- PCPS_TZCODE, pin,
- _pcps_ddev_has_tzcode( pddev ) );
+ case IOCTL_GET_GPS_IDENT:
+ _io_read_gps_var( pddev, PC_GPS_IDENT, ident, pout );
break;
- case IOCTL_GET_PCPS_TZDL:
- _io_read_var_chk( pddev, PCPS_GET_PCPS_TZDL,
- PCPS_TZDL, pout,
- _pcps_ddev_has_pcps_tzdl( pddev ) );
+ case IOCTL_GET_GPS_RECEIVER_INFO:
+ // Always read the receiver info directly from the device. Never
+ // just return a previous copy which has been read earlier since
+ // something may just have been changed by a configuration API call.
+ _io_read_gps_var_chk( pddev, PC_GPS_RECEIVER_INFO,
+ receiver_info, pout,
+ _pcps_ddev_has_receiver_info( pddev ) );
break;
- case IOCTL_SET_PCPS_TZDL:
- _io_write_var_chk( pddev, PCPS_SET_PCPS_TZDL,
- PCPS_TZDL, pin,
- _pcps_ddev_has_pcps_tzdl( pddev ) );
+ case IOCTL_GET_PCI_ASIC_VERSION:
+ _io_chk_cond( _pcps_ddev_has_asic_version( pddev ) );
+ _iob_to_pout_var( pddev->raw_asic_version, pout );
+ rc = MBG_SUCCESS;
break;
- case IOCTL_GET_REF_OFFS:
- _io_read_var_chk( pddev, PCPS_GET_REF_OFFS,
- MBG_REF_OFFS, pout,
- _pcps_ddev_has_ref_offs( pddev ) );
+ case IOCTL_GET_SYNTH_STATE:
+ _io_read_var_chk( pddev, PCPS_GET_SYNTH_STATE, synth_state,
+ pout, _pcps_ddev_has_synth( pddev ) );
break;
- case IOCTL_SET_REF_OFFS:
- _io_write_var_chk( pddev, PCPS_SET_REF_OFFS,
- MBG_REF_OFFS, pin,
- _pcps_ddev_has_ref_offs( pddev ) );
+ case IOCTL_GET_PCPS_UCAP_ENTRIES:
+ _io_read_var_chk( pddev, PCPS_GIVE_UCAP_ENTRIES, pcps_ucap_entries,
+ pout, _pcps_ddev_has_ucap( pddev ) );
break;
- case IOCTL_GET_MBG_OPT_INFO:
- _io_read_var_chk( pddev, PCPS_GET_OPT_INFO,
- MBG_OPT_INFO, pout,
- _pcps_ddev_has_opt_flags( pddev ) );
+ case IOCTL_GET_PCI_ASIC_FEATURES:
+ _io_chk_cond( _pcps_ddev_has_asic_features( pddev ) );
+ _iob_to_pout_var( pddev->asic_features, pout );
+ rc = MBG_SUCCESS;
break;
- case IOCTL_SET_MBG_OPT_SETTINGS:
- _io_write_var_chk( pddev, PCPS_SET_OPT_SETTINGS,
- MBG_OPT_SETTINGS, pin,
- _pcps_ddev_has_opt_flags( pddev ) );
+ case IOCTL_GET_IRQ_STAT_INFO:
+ _iob_to_pout_var( pddev->irq_stat_info, pout );
+ rc = MBG_SUCCESS;
break;
- case IOCTL_GET_PCPS_IRIG_RX_INFO:
- _io_read_var_chk( pddev, PCPS_GET_IRIG_RX_INFO,
- IRIG_INFO, pout,
- _pcps_ddev_is_irig_rx( pddev ) );
+ case IOCTL_GET_CYCLES_FREQUENCY:
+ mbg_get_pc_cycles_frequency( &iob.mbg_pc_cycles_frequency );
+ _iob_to_pout_var( iob.mbg_pc_cycles_frequency, pout );
+ rc = MBG_SUCCESS;
break;
- case IOCTL_SET_PCPS_IRIG_RX_SETTINGS:
- _io_write_var_chk( pddev, PCPS_SET_IRIG_RX_SETTINGS,
- IRIG_SETTINGS, pin,
- _pcps_ddev_is_irig_rx( pddev ) );
+ case IOCTL_GET_IRIG_CTRL_BITS:
+ _io_read_var_chk( pddev, PCPS_GET_IRIG_CTRL_BITS, mbg_irig_ctrl_bits,
+ pout, _pcps_ddev_has_irig_ctrl_bits( pddev ) );
break;
- case IOCTL_PCPS_CLR_UCAP_BUFF:
- _io_write_cmd_chk( pddev, PCPS_CLR_UCAP_BUFF,
- _pcps_ddev_can_clr_ucap_buff( pddev ) );
+ case IOCTL_GET_IP4_STATE:
+ _io_read_gps_var_chk( pddev, PC_GPS_IP4_STATE, ip4_settings,
+ pout, _pcps_ddev_has_lan_intf( pddev ) );
break;
- case IOCTL_GET_PCPS_UCAP_ENTRIES:
- _io_read_var_chk( pddev, PCPS_GIVE_UCAP_ENTRIES,
- PCPS_UCAP_ENTRIES, pout,
- _pcps_ddev_has_ucap( pddev ) );
+ case IOCTL_GET_PTP_STATE:
+ _io_read_gps_var_chk( pddev, PC_GPS_PTP_STATE, ptp_state,
+ pout, _pcps_ddev_has_ptp( pddev ) );
break;
- case IOCTL_GET_PCPS_UCAP_EVENT:
- _io_read_var_chk( pddev, PCPS_GIVE_UCAP_EVENT,
- PCPS_HR_TIME, pout,
- _pcps_ddev_has_ucap( pddev ) );
+ case IOCTL_GET_CORR_INFO:
+ _io_read_var_chk( pddev, PCPS_GET_CORR_INFO, corr_info,
+ pout, _pcps_ddev_has_corr_info( pddev ) );
break;
- /* slow read/write operations with GPS data */
+ // Commands returning device capabilities and features
- case IOCTL_GET_GPS_TZDL:
- _io_read_gps_var( pddev, PC_GPS_TZDL, TZDL, pout );
+ case IOCTL_DEV_IS_GPS:
+ _report_cond( _pcps_ddev_is_gps( pddev ), pout );
break;
- case IOCTL_SET_GPS_TZDL:
- _io_write_gps_var( pddev, PC_GPS_TZDL, TZDL, pin );
+ case IOCTL_DEV_IS_DCF:
+ _report_cond( _pcps_ddev_is_dcf( pddev ), pout );
break;
- case IOCTL_GET_GPS_SW_REV:
- _io_read_gps_var( pddev, PC_GPS_SW_REV,
- SW_REV, pout );
+ case IOCTL_DEV_IS_MSF:
+ _report_cond( _pcps_ddev_is_msf( pddev ), pout );
break;
- case IOCTL_GET_GPS_BVAR_STAT:
- _io_read_gps_var( pddev, PC_GPS_BVAR_STAT,
- BVAR_STAT, pout );
+ case IOCTL_DEV_IS_WWVB:
+ _report_cond( _pcps_ddev_is_wwvb( pddev ), pout );
break;
- case IOCTL_GET_GPS_TIME:
- _io_read_gps_var( pddev, PC_GPS_TIME, TTM, pout );
+ case IOCTL_DEV_IS_LWR:
+ _report_cond( _pcps_ddev_is_lwr( pddev ), pout );
break;
- case IOCTL_SET_GPS_TIME:
- _io_write_gps_var( pddev, PC_GPS_TIME, TTM, pin );
+ case IOCTL_DEV_IS_IRIG_RX:
+ _report_cond( _pcps_ddev_is_irig_rx( pddev ), pout );
break;
- case IOCTL_GET_GPS_PORT_PARM:
- _io_read_gps_var( pddev, PC_GPS_PORT_PARM,
- PORT_PARM, pout );
+ case IOCTL_DEV_HAS_HR_TIME:
+ _report_cond( _pcps_ddev_has_hr_time( pddev ), pout );
break;
- case IOCTL_SET_GPS_PORT_PARM:
- _io_write_gps_var( pddev, PC_GPS_PORT_PARM,
- PORT_PARM, pin );
+ case IOCTL_DEV_HAS_CAB_LEN:
+ _report_cond( _pcps_ddev_has_cab_len( pddev ), pout );
break;
- case IOCTL_GET_GPS_ANT_INFO:
- _io_read_gps_var( pddev, PC_GPS_ANT_INFO,
- ANT_INFO, pout );
+ case IOCTL_DEV_HAS_TZDL:
+ _report_cond( _pcps_ddev_has_tzdl( pddev ), pout );
break;
- case IOCTL_GET_GPS_UCAP:
- _io_read_gps_var( pddev, PC_GPS_UCAP, TTM, pout );
+ case IOCTL_DEV_HAS_PCPS_TZDL:
+ _report_cond( _pcps_ddev_has_pcps_tzdl( pddev ), pout );
break;
- case IOCTL_GET_GPS_ENABLE_FLAGS:
- _io_read_gps_var( pddev, PC_GPS_ENABLE_FLAGS,
- ENABLE_FLAGS, pout );
+ case IOCTL_DEV_HAS_TZCODE:
+ _report_cond( _pcps_ddev_has_tzcode( pddev ), pout );
break;
- case IOCTL_SET_GPS_ENABLE_FLAGS:
- _io_write_gps_var( pddev, PC_GPS_ENABLE_FLAGS,
- ENABLE_FLAGS, pin );
+ case IOCTL_DEV_HAS_TZ:
+ _report_cond( _pcps_ddev_has_tz( pddev ), pout );
break;
- case IOCTL_GET_GPS_STAT_INFO:
- _io_read_gps_var( pddev, PC_GPS_STAT_INFO,
- STAT_INFO, pout );
+ case IOCTL_DEV_HAS_EVENT_TIME:
+ _report_cond( _pcps_ddev_has_event_time( pddev ), pout );
break;
- case IOCTL_SET_GPS_CMD:
- _io_write_gps_var( pddev, PC_GPS_CMD,
- GPS_CMD, pin );
+ case IOCTL_DEV_HAS_RECEIVER_INFO:
+ _report_cond( _pcps_ddev_has_receiver_info( pddev ), pout );
break;
- case IOCTL_GET_GPS_IDENT:
- _io_read_gps_var( pddev, PC_GPS_IDENT,
- IDENT, pout );
+ case IOCTL_DEV_CAN_CLR_UCAP_BUFF:
+ _report_cond( _pcps_ddev_can_clr_ucap_buff( pddev ), pout );
break;
- case IOCTL_GET_GPS_POS:
- _io_read_gps_var( pddev, PC_GPS_POS,
- POS, pout );
+ case IOCTL_DEV_HAS_UCAP:
+ _report_cond( _pcps_ddev_has_ucap( pddev ), pout );
break;
- case IOCTL_SET_GPS_POS_XYZ:
- _io_write_gps_var( pddev, PC_GPS_POS_XYZ,
- XYZs, pin );
+ case IOCTL_DEV_HAS_IRIG_TX:
+ _report_cond( _pcps_ddev_has_irig_tx( pddev ), pout );
break;
- case IOCTL_SET_GPS_POS_LLA:
- _io_write_gps_var( pddev, PC_GPS_POS_LLA,
- LLAs, pin );
+ case IOCTL_DEV_HAS_SERIAL_HS:
+ _report_cond( _pcps_ddev_has_serial_hs( pddev ), pout );
break;
- case IOCTL_GET_GPS_ANT_CABLE_LEN:
- _io_read_gps_var_chk( pddev, PC_GPS_ANT_CABLE_LEN,
- ANT_CABLE_LEN, pout,
- _pcps_ddev_has_cab_len( pddev ) );
+ case IOCTL_DEV_HAS_SIGNAL:
+ _report_cond( _pcps_ddev_has_signal( pddev ), pout );
break;
- case IOCTL_SET_GPS_ANT_CABLE_LEN:
- _io_write_gps_var_chk( pddev, PC_GPS_ANT_CABLE_LEN,
- ANT_CABLE_LEN, pin,
- _pcps_ddev_has_cab_len( pddev ) );
+ case IOCTL_DEV_HAS_MOD:
+ _report_cond( _pcps_ddev_has_mod( pddev ), pout );
break;
- case IOCTL_GET_GPS_RECEIVER_INFO:
- _io_chk_cond( _pcps_ddev_has_receiver_info( pddev ) );
- // Just copy the saved RECEIVER_INFO ...
- _pcps_iob_to_pout_size( RECEIVER_INFO, pddev->ri, pout,
- sizeof( RECEIVER_INFO ) );
+ case IOCTL_DEV_HAS_IRIG:
+ _report_cond( _pcps_ddev_has_irig( pddev ), pout );
break;
- #if _MBG_SUPP_VAR_ACC_SIZE
- case IOCTL_GET_GPS_ALL_STR_TYPE_INFO:
- _io_read_gps_chk( pddev, PC_GPS_ALL_STR_TYPE_INFO,
- ALL_STR_TYPE_INFO, pout, pout_size,
- _pcps_ddev_has_receiver_info( pddev ) );
+ case IOCTL_DEV_HAS_REF_OFFS:
+ _report_cond( _pcps_ddev_has_ref_offs( pddev ), pout );
break;
- #endif
- #if _MBG_SUPP_VAR_ACC_SIZE
- case IOCTL_GET_GPS_ALL_PORT_INFO:
- _io_read_gps_chk( pddev, PC_GPS_ALL_PORT_INFO,
- ALL_PORT_INFO, pout, pout_size,
- _pcps_ddev_has_receiver_info( pddev ) );
+ case IOCTL_DEV_HAS_OPT_FLAGS:
+ _report_cond( _pcps_ddev_has_opt_flags( pddev ), pout );
break;
- #endif
- case IOCTL_SET_GPS_PORT_SETTINGS_IDX:
- _io_write_gps_var_chk( pddev, PC_GPS_PORT_SETTINGS_IDX,
- PORT_SETTINGS_IDX, pin,
- _pcps_ddev_has_receiver_info( pddev ) );
+ case IOCTL_DEV_HAS_GPS_DATA:
+ _report_cond( _pcps_ddev_has_gps_data( pddev ), pout );
break;
- case IOCTL_GET_PCI_ASIC_VERSION:
- _io_chk_cond( _pcps_ddev_has_asic_version( pddev ) );
- {
- _pcps_iob( PCI_ASIC_VERSION, _s );
+ case IOCTL_DEV_HAS_SYNTH:
+ _report_cond( _pcps_ddev_has_synth( pddev ), pout );
+ break;
- _s = pddev->raw_asic_version;
- rc = MBG_SUCCESS;
- _pcps_iob_to_pout( PCI_ASIC_VERSION, _s, pout );
- }
+ case IOCTL_DEV_HAS_GENERIC_IO:
+ _report_cond( _pcps_ddev_has_generic_io( pddev ), pout );
break;
- case IOCTL_GET_PCPS_TIME_CYCLES:
- {
- _pcps_iob( PCPS_TIME_CYCLES, _s );
-
- _pcps_sem_inc_safe( pddev );
- rc = _pcps_read_var( pddev, PCPS_GIVE_TIME_NOCLEAR,
- _s.t );
- if ( _pcps_ddev_is_usb( pddev ) )
- _s.cycles =(pddev)->acc_cycles;
- else
- mbg_get_pc_cycles( &(_s).cycles );
- _pcps_sem_dec( pddev );
+ case IOCTL_DEV_HAS_PCI_ASIC_FEATURES:
+ _report_cond( _pcps_ddev_has_asic_features( pddev ), pout );
+ break;
- if ( rc != MBG_SUCCESS )
- goto err_access;
- _pcps_iob_to_pout( PCPS_TIME_CYCLES, _s, pout );
- }
+ case IOCTL_DEV_HAS_PCI_ASIC_VERSION:
+ _report_cond( _pcps_ddev_has_asic_version( pddev ), pout );
break;
- case IOCTL_GET_PCPS_HR_TIME_CYCLES:
- {
- _pcps_iob( PCPS_HR_TIME_CYCLES, _s );
-
- _pcps_sem_inc_safe( pddev );
- rc = _pcps_read_var( pddev, PCPS_GIVE_HR_TIME,
- _s.t );
- _s.cycles =(pddev)->acc_cycles;
- _pcps_sem_dec( pddev );
+ case IOCTL_DEV_HAS_FAST_HR_TIMESTAMP:
+ _report_cond( _pcps_ddev_has_fast_hr_timestamp( pddev ), pout );
+ break;
- if ( rc != MBG_SUCCESS )
- goto err_access;
- _pcps_iob_to_pout( PCPS_HR_TIME_CYCLES, _s, pout );
- }
+ case IOCTL_DEV_HAS_GPS_TIME_SCALE:
+ _report_cond( _pcps_ddev_has_time_scale( pddev ), pout );
break;
- case IOCTL_GET_PCPS_IRIG_TX_INFO:
- {
- /* This is a workaround for GPS169PCIs with early */
- /* firmware versions. See RCS log for details. */
- uint8_t pcps_cmd = PCPS_GET_IRIG_TX_INFO;
+ case IOCTL_DEV_HAS_GPS_UTC_PARM:
+ _report_cond( _pcps_ddev_has_utc_parm( pddev ), pout );
+ break;
- if ( _pcps_ddev_requires_irig_workaround( pddev ) )
- {
- pcps_cmd = PCPS_GET_IRIG_RX_INFO;
- _mbgddmsg_1( MBG_DBG_INFO,
- "%s: workaround for GPS169PCI \"get IRIG TX cfg\"",
- pcps_driver_name );
- }
- _io_read_var_chk( pddev, pcps_cmd, IRIG_INFO, pout,
- _pcps_ddev_has_irig_tx( pddev ) );
- }
+ case IOCTL_DEV_HAS_IRIG_CTRL_BITS:
+ _report_cond( _pcps_ddev_has_irig_ctrl_bits( pddev ), pout );
break;
- case IOCTL_SET_PCPS_IRIG_TX_SETTINGS:
- {
- /* This is a workaround for GPS169PCIs with early */
- /* firmware versions. See RCS log for details. */
- uint8_t pcps_cmd = PCPS_SET_IRIG_TX_SETTINGS;
+ case IOCTL_DEV_HAS_LAN_INTF:
+ _report_cond( _pcps_ddev_has_lan_intf( pddev ), pout );
+ break;
- if ( _pcps_ddev_requires_irig_workaround( pddev ) )
- {
- pcps_cmd = PCPS_SET_IRIG_RX_SETTINGS;
- _mbgddmsg_1( MBG_DBG_INFO,
- "%s: workaround for GPS169PCI \"set IRIG TX cfg\"",
- pcps_driver_name );
- }
- _io_write_var_chk( pddev, pcps_cmd,
- IRIG_SETTINGS, pin,
- _pcps_ddev_has_irig_tx( pddev ) );
- }
+ case IOCTL_DEV_IS_PTP:
+ _report_cond( _pcps_ddev_is_ptp( pddev ), pout );
break;
- case IOCTL_GET_SYNTH:
- _io_read_var_chk( pddev, PCPS_GET_SYNTH,
- SYNTH, pout,
- _pcps_ddev_has_synth( pddev ) );
+ case IOCTL_DEV_HAS_PTP:
+ _report_cond( _pcps_ddev_has_ptp( pddev ), pout );
break;
- case IOCTL_SET_SYNTH:
- _io_write_var_chk( pddev, PCPS_SET_SYNTH,
- SYNTH, pin,
- _pcps_ddev_has_synth( pddev ) );
+ case IOCTL_DEV_HAS_IRIG_TIME:
+ _report_cond( _pcps_ddev_has_irig_time( pddev ), pout );
break;
- case IOCTL_DEV_IS_GPS:
- _report_cond( _pcps_ddev_is_gps( pddev ), pout );
+ case IOCTL_DEV_HAS_RAW_IRIG_DATA:
+ _report_cond( _pcps_ddev_has_raw_irig_data( pddev ), pout );
break;
- case IOCTL_DEV_IS_DCF:
- _report_cond( _pcps_ddev_is_dcf( pddev ), pout );
+ case IOCTL_DEV_HAS_PTP_UNICAST:
+ _report_cond( _pcps_ddev_has_ptp_unicast( pddev ), pout );
break;
- case IOCTL_DEV_IS_IRIG_RX:
- _report_cond( _pcps_ddev_is_irig_rx( pddev ), pout );
+ case IOCTL_DEV_HAS_PZF:
+ _report_cond( _pcps_ddev_has_pzf( pddev ), pout );
break;
- case IOCTL_DEV_HAS_HR_TIME:
- _report_cond( _pcps_ddev_has_hr_time( pddev ), pout );
+ case IOCTL_DEV_HAS_CORR_INFO:
+ _report_cond( _pcps_ddev_has_corr_info( pddev ), pout );
break;
- case IOCTL_DEV_HAS_CAB_LEN:
- _report_cond( _pcps_ddev_has_cab_len( pddev ), pout );
+ case IOCTL_DEV_HAS_TR_DISTANCE:
+ _report_cond( _pcps_ddev_has_tr_distance( pddev ), pout );
break;
- case IOCTL_DEV_HAS_TZDL:
- _report_cond( _pcps_ddev_has_tzdl( pddev ), pout );
+ // The next codes are somewhat special since they change something
+ // on the board but do not affect basic operation
+
+ case IOCTL_PCPS_CLR_UCAP_BUFF:
+ _io_write_cmd_chk( pddev, PCPS_CLR_UCAP_BUFF,
+ _pcps_ddev_can_clr_ucap_buff( pddev ) );
break;
- case IOCTL_DEV_HAS_PCPS_TZDL:
- _report_cond( _pcps_ddev_has_pcps_tzdl( pddev ), pout );
+ case IOCTL_SET_PCPS_EVENT_TIME:
+ _io_write_var_chk( pddev, PCPS_SET_EVENT_TIME,
+ pcps_time_stamp, pin,
+ _pcps_ddev_has_event_time( pddev ) );
break;
- case IOCTL_DEV_HAS_TZCODE:
- _report_cond( _pcps_ddev_has_tzcode( pddev ), pout );
+ // Status information which may not be available for everybody
+
+ case IOCTL_GET_GPS_POS:
+ _io_read_gps_var( pddev, PC_GPS_POS, pos, pout );
break;
- case IOCTL_DEV_HAS_TZ:
- _report_cond( _pcps_ddev_has_tz( pddev ), pout );
+ // Codes reading device configuration
+
+ case IOCTL_GET_PCPS_SERIAL:
+ _io_read_var( pddev, PCPS_GET_SERIAL, pcps_serial, pout );
break;
- case IOCTL_DEV_HAS_EVENT_TIME:
- _report_cond( _pcps_ddev_has_event_time( pddev ), pout );
+ case IOCTL_GET_PCPS_TZCODE:
+ _io_read_var_chk( pddev, PCPS_GET_TZCODE, pcps_tzcode, pout,
+ _pcps_ddev_has_tzcode( pddev ) );
break;
- case IOCTL_DEV_HAS_RECEIVER_INFO:
- _report_cond( _pcps_ddev_has_receiver_info( pddev ), pout );
+ case IOCTL_GET_PCPS_TZDL:
+ _io_read_var_chk( pddev, PCPS_GET_PCPS_TZDL, pcps_tzdl, pout,
+ _pcps_ddev_has_pcps_tzdl( pddev ) );
break;
- case IOCTL_DEV_CAN_CLR_UCAP_BUFF:
- _report_cond( _pcps_ddev_can_clr_ucap_buff( pddev ), pout );
+ case IOCTL_GET_REF_OFFS:
+ _io_read_var_chk( pddev, PCPS_GET_REF_OFFS, mbg_ref_offs, pout,
+ _pcps_ddev_has_ref_offs( pddev ) );
break;
- case IOCTL_DEV_HAS_UCAP:
- _report_cond( _pcps_ddev_has_ucap( pddev ), pout );
+ case IOCTL_GET_MBG_OPT_INFO:
+ _io_read_var_chk( pddev, PCPS_GET_OPT_INFO, mbg_opt_info, pout,
+ _pcps_ddev_has_opt_flags( pddev ) );
break;
- case IOCTL_DEV_HAS_IRIG_TX:
- _report_cond( _pcps_ddev_has_irig_tx( pddev ), pout );
+ case IOCTL_GET_PCPS_IRIG_RX_INFO:
+ _io_read_var_chk( pddev, PCPS_GET_IRIG_RX_INFO, irig_info, pout,
+ _pcps_ddev_is_irig_rx( pddev ) );
break;
- case IOCTL_DEV_HAS_SERIAL_HS:
- _report_cond( _pcps_ddev_has_serial_hs( pddev ), pout );
+ case IOCTL_GET_GPS_TZDL:
+ _io_read_gps_var( pddev, PC_GPS_TZDL, tzdl, pout );
break;
- case IOCTL_DEV_HAS_SIGNAL:
- _report_cond( _pcps_ddev_has_signal( pddev ), pout );
+ case IOCTL_GET_GPS_PORT_PARM:
+ _io_read_gps_var( pddev, PC_GPS_PORT_PARM, port_parm, pout );
break;
- case IOCTL_DEV_HAS_MOD:
- _report_cond( _pcps_ddev_has_mod( pddev ), pout );
+ case IOCTL_GET_GPS_ENABLE_FLAGS:
+ _io_read_gps_var( pddev, PC_GPS_ENABLE_FLAGS, enable_flags, pout );
break;
- case IOCTL_DEV_HAS_IRIG:
- _report_cond( _pcps_ddev_has_irig( pddev ), pout );
+ case IOCTL_GET_GPS_ANT_CABLE_LEN:
+ _io_read_gps_var_chk( pddev, PC_GPS_ANT_CABLE_LEN, ant_cable_len, pout,
+ _pcps_ddev_has_cab_len( pddev ) );
break;
- case IOCTL_DEV_HAS_REF_OFFS:
- _report_cond( _pcps_ddev_has_ref_offs( pddev ), pout );
- break;
+ case IOCTL_GET_PCPS_IRIG_TX_INFO:
+ /* This is a workaround for GPS169PCIs with early */
+ /* firmware versions. See RCS log for details. */
+ pcps_cmd = PCPS_GET_IRIG_TX_INFO;
+ if ( _pcps_ddev_requires_irig_workaround( pddev ) )
+ {
+ pcps_cmd = PCPS_GET_IRIG_RX_INFO;
+ _mbgddmsg_1( MBG_DBG_INFO, "%s: workaround for GPS169PCI \"get IRIG TX cfg\"",
+ pcps_driver_name );
+ }
- case IOCTL_DEV_HAS_OPT_FLAGS:
- _report_cond( _pcps_ddev_has_opt_flags( pddev ), pout );
+ _io_read_var_chk( pddev, pcps_cmd, irig_info, pout,
+ _pcps_ddev_has_irig_tx( pddev ) );
break;
- case IOCTL_DEV_HAS_GPS_DATA:
- _report_cond( _pcps_ddev_has_gps_data( pddev ), pout );
+ case IOCTL_GET_SYNTH:
+ _io_read_var_chk( pddev, PCPS_GET_SYNTH, synth, pout,
+ _pcps_ddev_has_synth( pddev ) );
break;
- case IOCTL_DEV_HAS_SYNTH:
- _report_cond( _pcps_ddev_has_synth( pddev ), pout );
+ case IOCTL_GET_GPS_TIME_SCALE_INFO:
+ _io_read_gps_var_chk( pddev, PC_GPS_TIME_SCALE, mbg_time_scale_info,
+ pout, _pcps_ddev_has_time_scale( pddev ) );
break;
- case IOCTL_DEV_HAS_GENERIC_IO:
- _report_cond( _pcps_ddev_has_generic_io( pddev ), pout );
+ case IOCTL_GET_GPS_UTC_PARM:
+ _io_read_gps_var_chk( pddev, PC_GPS_UTC, utc, pout,
+ _pcps_ddev_has_utc_parm( pddev ) );
break;
- case IOCTL_PCPS_GENERIC_IO:
- {
- IOCTL_GENERIC_CTL ctl;
- IOCTL_GENERIC_BUFFER *p_buff;
- int buffer_size;
+ case IOCTL_GET_LAN_IF_INFO:
+ _io_read_gps_var_chk( pddev, PC_GPS_LAN_IF_INFO, lan_if_info,
+ pout, _pcps_ddev_has_lan_intf( pddev ) );
+ break;
- _io_chk_cond( _pcps_ddev_has_generic_io( pddev ) );
- _pcps_iob_from_pin( IOCTL_GENERIC_CTL, ctl, pin );
- buffer_size = sizeof( ctl ) +
- ( ( ctl.data_size_in > ctl.data_size_out ) ?
- ctl.data_size_in : ctl.data_size_out );
- p_buff = _pcps_kmalloc( buffer_size );
+ case IOCTL_GET_IP4_SETTINGS:
+ _io_read_gps_var_chk( pddev, PC_GPS_IP4_SETTINGS, ip4_settings,
+ pout, _pcps_ddev_has_lan_intf( pddev ) );
+ break;
- if ( p_buff == NULL )
- goto err_no_mem;
- _pcps_iob_from_pin_size( uint8_t, *p_buff, pin,
- sizeof( p_buff->ctl ) + ctl.data_size_in );
+ case IOCTL_GET_PTP_CFG_INFO:
+ _io_read_gps_var_chk( pddev, PC_GPS_PTP_CFG, ptp_cfg_info,
+ pout, _pcps_ddev_has_ptp( pddev ) );
+ break;
- _pcps_sem_inc_safe( pddev );
- rc = pcps_generic_io( pddev, (uint8_t) ctl.info,
- p_buff->data,
- (uint8_t) ctl.data_size_in,
- p_buff->data,
- (uint8_t) ctl.data_size_out );
- _pcps_sem_dec( pddev );
- if ( rc == MBG_SUCCESS )
- {
- p_buff->ctl = ctl;
- _pcps_iob_to_pout_size( uint8_t, *p_buff, pout,
- sizeof( p_buff->ctl ) + ctl.data_size_out );
- }
+ case IOCTL_GET_IRIG_TIME:
+ _io_read_var_chk( pddev, PCPS_GIVE_IRIG_TIME, pcps_irig_time,
+ pout, _pcps_ddev_has_irig_time( pddev ) );
+ break;
- _pcps_kfree( p_buff, buffer_size );
- if ( rc != MBG_SUCCESS )
- goto err_access;
+ case IOCTL_GET_RAW_IRIG_DATA:
+ _io_read_var_chk( pddev, PCPS_GET_RAW_IRIG_DATA, mbg_raw_irig_data,
+ pout, _pcps_ddev_has_raw_irig_data( pddev ) );
+ break;
+
+ case IOCTL_PTP_UC_MASTER_CFG_LIMITS:
+ _io_read_gps_var_chk( pddev, PC_GPS_PTP_UC_MASTER_CFG_LIMITS, ptp_uc_master_cfg_limits,
+ pout, _pcps_ddev_has_ptp_unicast( pddev ) );
break;
- }
- case IOCTL_GET_SYNTH_STATE:
- _io_read_var_chk( pddev, PCPS_GET_SYNTH_STATE,
- SYNTH_STATE, pout,
- _pcps_ddev_has_synth( pddev ) );
+ case IOCTL_GET_TR_DISTANCE:
+ _io_read_var_chk( pddev, PCPS_GET_TR_DISTANCE, tr_distance,
+ pout, _pcps_ddev_has_tr_distance( pddev ) );
break;
#if _MBG_SUPP_VAR_ACC_SIZE
- case IOCTL_GET_GPS_ALL_POUT_INFO:
- _io_read_gps_chk( pddev, PC_GPS_ALL_POUT_INFO,
- ALL_POUT_INFO, pout, pout_size,
- _pcps_ddev_has_receiver_info( pddev ) );
+
+ // These codes are only supported on target systems where a variable size of
+ // the IOCTL buffer can be specified in the IOCTL call. On other systems the
+ // generic IOCTL functions are used instead.
+
+ case IOCTL_GET_GPS_ALL_STR_TYPE_INFO:
+ _io_read_gps_chk( pddev, PC_GPS_ALL_STR_TYPE_INFO, all_str_type_info, pout,
+ pout_size, _pcps_ddev_has_receiver_info( pddev ) );
break;
- #endif
- case IOCTL_SET_GPS_POUT_SETTINGS_IDX:
- _io_write_gps_var_chk( pddev, PC_GPS_POUT_SETTINGS_IDX,
- POUT_SETTINGS_IDX, pin,
- _pcps_ddev_has_receiver_info( pddev ) );
+ case IOCTL_GET_GPS_ALL_PORT_INFO:
+ _io_read_gps_chk( pddev, PC_GPS_ALL_PORT_INFO, all_port_info, pout,
+ pout_size, _pcps_ddev_has_receiver_info( pddev ) );
break;
-#if USE_DEBUG_PORT
- case IOCTL_MBG_DBG_GET_PORT_ADDR:
- {
- _pcps_iob( MBG_DBG_PORT, _s );
- _s = mbg_dbg_port;
- _pcps_iob_to_pout( MBG_DBG_PORT, _s, pout );
+ case IOCTL_GET_GPS_ALL_POUT_INFO:
+ _io_read_gps_chk( pddev, PC_GPS_ALL_POUT_INFO, all_pout_info, pout,
+ pout_size, _pcps_ddev_has_receiver_info( pddev ) );
+ break;
+
- rc = MBG_SUCCESS;
- }
+ case IOCTL_GET_ALL_PTP_UC_MASTER_INFO:
+ _io_read_gps_chk( pddev, PC_GPS_ALL_PTP_UC_MASTER_INFO, all_ptp_uc_master_info,
+ pout, pout_size, _pcps_ddev_has_ptp_unicast( pddev ) );
break;
+ #endif // _MBG_SUPP_VAR_ACC_SIZE
- case IOCTL_MBG_DBG_SET_PORT_ADDR:
- {
- _pcps_iob( MBG_DBG_PORT, _s );
- _pcps_iob_from_pin( MBG_DBG_PORT, _s, pin );
- mbg_dbg_port = _s;
- mbg_dbg_port_mapped = _pcps_ioremap( mbg_dbg_port, sizeof( mbg_dbg_port ) );
+ // Codes writing device configuration
- rc = MBG_SUCCESS;
- }
+ case IOCTL_SET_PCPS_SERIAL:
+ _io_write_var( pddev, PCPS_SET_SERIAL, pcps_serial, pin );
break;
-#endif // USE_DEBUG_PORT
- case IOCTL_GET_MAPPED_MEM_ADDR:
- {
- _io_chk_cond( ( pddev->asic_features & PCI_ASIC_HAS_MM_IO ) );
- _io_get_mapped_mem_address( pddev, pout );
- }
+ case IOCTL_SET_PCPS_TZCODE:
+ _io_write_var_chk( pddev, PCPS_SET_TZCODE, pcps_tzcode, pin,
+ _pcps_ddev_has_tzcode( pddev ) );
break;
- case IOCTL_UNMAP_MAPPED_MEM:
- {
- _io_chk_cond( ( pddev->asic_features & PCI_ASIC_HAS_MM_IO ) );
- _io_unmap_mapped_mem_address( pddev, pin );
- }
+ case IOCTL_SET_PCPS_TZDL:
+ _io_write_var_chk( pddev, PCPS_SET_PCPS_TZDL, pcps_tzdl, pin,
+ _pcps_ddev_has_pcps_tzdl( pddev ) );
break;
- case IOCTL_GET_PCI_ASIC_FEATURES:
- _io_chk_cond( _pcps_ddev_has_asic_features( pddev ) );
- {
- _pcps_iob( PCI_ASIC_FEATURES, _s );
+ case IOCTL_SET_REF_OFFS:
+ _io_write_var_chk( pddev, PCPS_SET_REF_OFFS, mbg_ref_offs, pin,
+ _pcps_ddev_has_ref_offs( pddev ) );
+ break;
- _s = pddev->asic_features;
- rc = MBG_SUCCESS;
- _pcps_iob_to_pout( PCI_ASIC_FEATURES, _s, pout );
- }
+ case IOCTL_SET_MBG_OPT_SETTINGS:
+ _io_write_var_chk( pddev, PCPS_SET_OPT_SETTINGS, mbg_opt_settings,
+ pin, _pcps_ddev_has_opt_flags( pddev ) );
break;
- case IOCTL_DEV_HAS_PCI_ASIC_FEATURES:
- _report_cond( _pcps_ddev_has_asic_features( pddev ), pout );
+ case IOCTL_SET_PCPS_IRIG_RX_SETTINGS:
+ _io_write_var_chk( pddev, PCPS_SET_IRIG_RX_SETTINGS,
+ irig_settings, pin,
+ _pcps_ddev_is_irig_rx( pddev ) );
break;
- case IOCTL_DEV_HAS_PCI_ASIC_VERSION:
- _report_cond( _pcps_ddev_has_asic_version( pddev ), pout );
+ case IOCTL_SET_GPS_TZDL:
+ _io_write_gps_var( pddev, PC_GPS_TZDL, tzdl, pin );
break;
- case IOCTL_DEV_IS_MSF:
- _report_cond( _pcps_ddev_is_msf( pddev ), pout );
+ case IOCTL_SET_GPS_PORT_PARM:
+ _io_write_gps_var( pddev, PC_GPS_PORT_PARM, port_parm, pin );
break;
- case IOCTL_DEV_IS_WWVB:
- _report_cond( _pcps_ddev_is_wwvb( pddev ), pout );
+ case IOCTL_SET_GPS_ENABLE_FLAGS:
+ _io_write_gps_var( pddev, PC_GPS_ENABLE_FLAGS, enable_flags, pin );
break;
- case IOCTL_DEV_IS_LWR:
- _report_cond( _pcps_ddev_is_lwr( pddev ), pout );
+ case IOCTL_SET_GPS_ANT_CABLE_LEN:
+ _io_write_gps_var_chk( pddev, PC_GPS_ANT_CABLE_LEN, ant_cable_len,
+ pin, _pcps_ddev_has_cab_len( pddev ) );
break;
- case IOCTL_GET_IRQ_STAT_INFO:
- {
- _pcps_iob( PCPS_IRQ_STAT_INFO, _s );
+ case IOCTL_SET_GPS_PORT_SETTINGS_IDX:
+ _io_write_gps_var_chk( pddev, PC_GPS_PORT_SETTINGS_IDX, port_settings_idx,
+ pin, _pcps_ddev_has_receiver_info( pddev ) );
+ break;
- _s = pddev->irq_stat_info;
- rc = MBG_SUCCESS;
- _pcps_iob_to_pout( PCPS_IRQ_STAT_INFO, _s, pout );
+ case IOCTL_SET_PCPS_IRIG_TX_SETTINGS:
+ /* This is a workaround for GPS169PCIs with early */
+ /* firmware versions. See RCS log for details. */
+ pcps_cmd = PCPS_SET_IRIG_TX_SETTINGS;
+
+ if ( _pcps_ddev_requires_irig_workaround( pddev ) )
+ {
+ pcps_cmd = PCPS_SET_IRIG_RX_SETTINGS;
+ _mbgddmsg_1( MBG_DBG_INFO, "%s: workaround for GPS169PCI \"set IRIG TX cfg\"",
+ pcps_driver_name );
}
+
+ _io_write_var_chk( pddev, pcps_cmd, irig_settings, pin,
+ _pcps_ddev_has_irig_tx( pddev ) );
break;
- case IOCTL_GET_CYCLES_FREQUENCY:
- {
- _pcps_iob( MBG_PC_CYCLES_FREQUENCY, _s );
+ case IOCTL_SET_SYNTH:
+ _io_write_var_chk( pddev, PCPS_SET_SYNTH, synth, pin,
+ _pcps_ddev_has_synth( pddev ) );
+ break;
- mbg_get_pc_cycles_frequency( &(_s) );
- rc = MBG_SUCCESS;
- _pcps_iob_to_pout( MBG_PC_CYCLES_FREQUENCY, _s, pout );
- }
+ case IOCTL_SET_GPS_POUT_SETTINGS_IDX:
+ _io_write_gps_var_chk( pddev, PC_GPS_POUT_SETTINGS_IDX, pout_settings_idx,
+ pin, _pcps_ddev_has_receiver_info( pddev ) );
break;
- case IOCTL_DEV_HAS_FAST_HR_TIMESTAMP:
- _report_cond( _pcps_ddev_has_fast_hr_timestamp( pddev ), pout );
+ case IOCTL_SET_IP4_SETTINGS:
+ _io_write_gps_var_chk( pddev, PC_GPS_IP4_SETTINGS, ip4_settings,
+ pin, _pcps_ddev_has_lan_intf( pddev ) );
break;
- case IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES:
- {
- _pcps_iob( PCPS_TIME_STAMP_CYCLES, _s );
+ case IOCTL_SET_PTP_CFG_SETTINGS:
+ _io_write_gps_var_chk( pddev, PC_GPS_PTP_CFG, ptp_cfg_settings,
+ pin, _pcps_ddev_has_ptp( pddev ) );
+ break;
- if ( !_pcps_ddev_has_fast_hr_timestamp( pddev ) )
- goto err_support;
- do_get_fast_hr_timestamp_cycles_safe( pddev, &_s );
- rc = MBG_SUCCESS;
+ case IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX:
+ _io_write_gps_var_chk( pddev, PC_GPS_PTP_UC_MASTER_SETTINGS_IDX,
+ ptp_uc_master_settings_idx, pin,
+ _pcps_ddev_has_ptp_unicast( pddev ) );
+ break;
- _pcps_iob_to_pout( PCPS_TIME_STAMP_CYCLES, _s, pout );
- }
+
+ case IOCTL_SET_TR_DISTANCE:
+ _io_write_var_chk( pddev, PCPS_SET_TR_DISTANCE, tr_distance,
+ pin, _pcps_ddev_has_tr_distance( pddev ) );
break;
- case IOCTL_GET_FAST_HR_TIMESTAMP:
- {
- _pcps_iob( PCPS_TIME_STAMP, _s );
+ // Operations which may severely affect system operation
- if ( !_pcps_ddev_has_fast_hr_timestamp( pddev ) )
- goto err_support;
+ case IOCTL_SET_PCPS_TIME:
+ _io_write_var_chk( pddev, PCPS_SET_TIME, pcps_stime, pin,
+ _pcps_ddev_can_set_time( pddev ) );
+ break;
- do_get_fast_hr_timestamp_safe( pddev, &_s );
- rc = MBG_SUCCESS;
- _pcps_iob_to_pout( PCPS_TIME_STAMP, _s, pout );
- }
+ case IOCTL_SET_GPS_TIME:
+ _io_write_gps_var( pddev, PC_GPS_TIME, ttm, pin );
break;
- case IOCTL_DEV_HAS_GPS_TIME_SCALE:
- _report_cond( _pcps_ddev_has_time_scale( pddev ), pout );
+ case IOCTL_SET_GPS_POS_XYZ:
+ _io_write_gps_var( pddev, PC_GPS_POS_XYZ, xyzs, pin );
break;
- case IOCTL_GET_GPS_TIME_SCALE_INFO:
- _io_read_gps_var_chk( pddev, PC_GPS_TIME_SCALE,
- MBG_TIME_SCALE_INFO, pout,
- _pcps_ddev_has_time_scale( pddev ) );
+ case IOCTL_SET_GPS_POS_LLA:
+ _io_write_gps_var( pddev, PC_GPS_POS_LLA, llas, pin );
break;
case IOCTL_SET_GPS_TIME_SCALE_SETTINGS:
- _io_write_gps_var_chk( pddev, PC_GPS_TIME_SCALE,
- MBG_TIME_SCALE_SETTINGS, pin,
- _pcps_ddev_has_time_scale( pddev ) );
+ _io_write_gps_var_chk( pddev, PC_GPS_TIME_SCALE, mbg_time_scale_settings,
+ pin, _pcps_ddev_has_time_scale( pddev ) );
break;
- case IOCTL_DEV_HAS_GPS_UTC_PARM:
- _report_cond( _pcps_ddev_has_utc_parm( pddev ), pout );
+ case IOCTL_SET_GPS_UTC_PARM:
+ _io_write_gps_var_chk( pddev, PC_GPS_UTC, utc, pin,
+ _pcps_ddev_has_utc_parm( pddev ) );
break;
- case IOCTL_GET_GPS_UTC_PARM:
- _io_read_gps_var_chk( pddev, PC_GPS_UTC,
- UTC, pout,
- _pcps_ddev_has_utc_parm( pddev ) );
+ case IOCTL_SET_GPS_CMD:
+ _io_write_gps_var( pddev, PC_GPS_CMD, gps_cmd, pin );
break;
- case IOCTL_SET_GPS_UTC_PARM:
- _io_write_gps_var_chk( pddev, PC_GPS_UTC,
- UTC, pin,
- _pcps_ddev_has_utc_parm( pddev ) );
- break;
+ // Generic read/write operations which can do anything
+ case IOCTL_PCPS_GENERIC_READ:
+ #if USE_IOCTL_GENERIC_REQ
+ _iob_from_pin_var( iob.req, pin );
+ p_buff_out = _pcps_kmalloc( iob.req.out_sz );
- case IOCTL_DEV_HAS_IRIG_CTRL_BITS:
- _report_cond( _pcps_ddev_has_irig_ctrl_bits( pddev ), pout );
- break;
+ if ( p_buff_out == NULL )
+ {
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for %s, cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.out_sz,
+ "IOCTL_PCPS_GENERIC_READ", (ulong) iob.req.info );
+ goto err_no_mem;
+ }
+ _pcps_sem_inc_safe( pddev );
+ rc = _pcps_read( pddev, (uint8_t) iob.req.info, p_buff_out,
+ (uint8_t) iob.req.out_sz );
+ _pcps_sem_dec( pddev );
- case IOCTL_GET_IRIG_CTRL_BITS:
- _io_read_var_chk( pddev, PCPS_GET_IRIG_CTRL_BITS,
- MBG_IRIG_CTRL_BITS, pout,
- _pcps_ddev_has_irig_ctrl_bits( pddev ) );
- break;
+ if ( rc == MBG_SUCCESS )
+ _frc_iob_to_pout( p_buff_out, iob.req.out_p, iob.req.out_sz );
+ _pcps_kfree( p_buff_out, iob.req.out_sz );
- case IOCTL_DEV_HAS_LAN_INTF:
- _report_cond( _pcps_ddev_has_lan_intf( pddev ), pout );
- break;
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+ #else
- case IOCTL_GET_LAN_IF_INFO:
- _io_read_gps_var_chk( pddev, PC_GPS_LAN_IF_INFO,
- LAN_IF_INFO, pout,
- _pcps_ddev_has_lan_intf( pddev ) );
- break;
+ _iob_from_pin_var( iob.ctl, pin );
+ buffer_size = sizeof( iob.ctl ) + iob.ctl.data_size_out;
+ p_buff = _pcps_kmalloc( buffer_size );
+ if ( p_buff == NULL )
+ goto err_no_mem;
- case IOCTL_GET_IP4_STATE:
- _io_read_gps_var_chk( pddev, PC_GPS_IP4_STATE,
- IP4_SETTINGS, pout,
- _pcps_ddev_has_lan_intf( pddev ) );
- break;
+ _pcps_sem_inc_safe( pddev );
+ rc = _pcps_read( pddev, (uint8_t) iob.ctl.info, p_buff->data,
+ (uint8_t) iob.ctl.data_size_out );
+ _pcps_sem_dec( pddev );
+
+ if ( rc == MBG_SUCCESS )
+ {
+ p_buff->ctl = iob.ctl;
+ _iob_to_pout( p_buff, pout, buffer_size ); //##+++++++ need to check this !!
+ }
+ _pcps_kfree( p_buff, buffer_size );
- case IOCTL_GET_IP4_SETTINGS:
- _io_read_gps_var_chk( pddev, PC_GPS_IP4_SETTINGS,
- IP4_SETTINGS, pout,
- _pcps_ddev_has_lan_intf( pddev ) );
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+
+ #endif
break;
- case IOCTL_SET_IP4_SETTINGS:
- _io_write_gps_var_chk( pddev, PC_GPS_IP4_SETTINGS,
- IP4_SETTINGS, pin,
- _pcps_ddev_has_lan_intf( pddev ) );
- break;
+ case IOCTL_PCPS_GENERIC_WRITE:
+ #if USE_IOCTL_GENERIC_REQ
+ _iob_from_pin_var( iob.req, pin );
+ p_buff_in = _pcps_kmalloc( iob.req.in_sz );
+ if ( p_buff_in == NULL )
+ {
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for %s, cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.in_sz,
+ "IOCTL_PCPS_GENERIC_WRITE", (ulong) iob.req.info );
+ goto err_no_mem;
+ }
- case IOCTL_DEV_IS_PTP:
- _report_cond( _pcps_ddev_is_ptp( pddev ), pout );
- break;
+ _frc_iob_from_pin( p_buff_in, pin, iob.req.in_sz );
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_write( pddev, (uint8_t) iob.req.info, p_buff_in,
+ (uint8_t) iob.req.in_sz );
+ _pcps_sem_dec( pddev );
- case IOCTL_DEV_HAS_PTP:
- _report_cond( _pcps_ddev_has_ptp( pddev ), pout );
- break;
+ _pcps_kfree( p_buff_in, iob.req.in_sz );
+
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+ #else
- case IOCTL_GET_PTP_STATE:
- _io_read_gps_var_chk( pddev, PC_GPS_PTP_STATE,
- PTP_STATE, pout,
- _pcps_ddev_has_ptp( pddev ) );
- break;
+ _iob_from_pin_var( iob.ctl, pin );
+ buffer_size = sizeof( iob.ctl ) + iob.ctl.data_size_in;
+ p_buff = _pcps_kmalloc( buffer_size );
+ if ( p_buff == NULL )
+ goto err_no_mem;
- case IOCTL_GET_PTP_CFG_INFO:
- _io_read_gps_var_chk( pddev, PC_GPS_PTP_CFG,
- PTP_CFG_INFO, pout,
- _pcps_ddev_has_ptp( pddev ) );
- break;
+ _iob_from_pin( p_buff, pin, buffer_size );
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_write( pddev, (uint8_t) iob.ctl.info, p_buff->data,
+ (uint8_t) iob.ctl.data_size_in );
+ _pcps_sem_dec( pddev );
- case IOCTL_SET_PTP_CFG_SETTINGS:
- _io_write_gps_var_chk( pddev, PC_GPS_PTP_CFG,
- PTP_CFG_SETTINGS, pin,
- _pcps_ddev_has_ptp( pddev ) );
- break;
+ _pcps_kfree( p_buff, buffer_size );
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
- case IOCTL_DEV_HAS_IRIG_TIME:
- _report_cond( _pcps_ddev_has_irig_time( pddev ), pout );
+ #endif
break;
- case IOCTL_GET_IRIG_TIME:
- _io_read_var_chk( pddev, PCPS_GIVE_IRIG_TIME,
- PCPS_IRIG_TIME, pout,
- _pcps_ddev_has_irig_time( pddev ) );
- break;
+ case IOCTL_PCPS_GENERIC_READ_GPS:
+ #if USE_IOCTL_GENERIC_REQ
+ _iob_from_pin_var( iob.req, pin );
+ p_buff_out = _pcps_kmalloc( iob.req.out_sz );
+
+ if ( p_buff_out == NULL )
+ {
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for %s, GPS cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.out_sz,
+ "IOCTL_PCPS_GENERIC_READ_GPS", (ulong) iob.req.info );
+ goto err_no_mem;
+ }
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_read_gps( pddev, (uint8_t) iob.req.info, p_buff_out,
+ (uint16_t) iob.req.out_sz );
+ _pcps_sem_dec( pddev );
- case IOCTL_GET_RAW_IRIG_DATA:
- _io_read_var_chk( pddev, PCPS_GET_RAW_IRIG_DATA,
- MBG_RAW_IRIG_DATA, pout,
- _pcps_ddev_has_raw_irig_data( pddev ) );
- break;
+ if ( rc == MBG_SUCCESS )
+ _frc_iob_to_pout( p_buff_out, iob.req.out_p, iob.req.out_sz );
+ _pcps_kfree( p_buff_out, iob.req.out_sz );
- case IOCTL_DEV_HAS_PTP_UNICAST:
- _report_cond( _pcps_ddev_has_ptp_unicast( pddev ), pout );
- break;
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+ #else
- case IOCTL_PTP_UC_MASTER_CFG_LIMITS:
- _io_read_gps_var_chk( pddev, PC_GPS_PTP_UC_MASTER_CFG_LIMITS,
- PTP_UC_MASTER_CFG_LIMITS, pout,
- _pcps_ddev_has_ptp_unicast( pddev ) );
- break;
+ _iob_from_pin_var( iob.ctl, pin );
+ buffer_size = sizeof( iob.ctl ) + iob.ctl.data_size_out;
+ p_buff = _pcps_kmalloc( buffer_size );
+ if ( p_buff == NULL )
+ goto err_no_mem;
- #if _MBG_SUPP_VAR_ACC_SIZE
- case IOCTL_GET_ALL_PTP_UC_MASTER_INFO:
- _io_read_gps_var_chk( pddev, PC_GPS_ALL_PTP_UC_MASTER_INFO,
- ALL_PTP_UC_MASTER_INFO, pout,
- _pcps_ddev_has_ptp_unicast( pddev ) );
- break;
- #endif
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_read_gps( pddev, (uint8_t) iob.ctl.info, p_buff->data,
+ (uint16_t) iob.ctl.data_size_out );
+ _pcps_sem_dec( pddev );
+ if ( rc == MBG_SUCCESS )
+ {
+ p_buff->ctl = iob.ctl;
+ _iob_to_pout( p_buff, pout, buffer_size ); //##+++++++ need to check this !!
+ }
- case IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX:
- _io_write_gps_var_chk( pddev, PC_GPS_PTP_UC_MASTER_SETTINGS_IDX,
- PTP_UC_MASTER_SETTINGS_IDX, pin,
- _pcps_ddev_has_ptp_unicast( pddev ) );
+ _pcps_kfree( p_buff, buffer_size );
+
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+
+ #endif
break;
- case IOCTL_GET_TIME_INFO_HRT:
+ case IOCTL_PCPS_GENERIC_WRITE_GPS:
+ #if USE_IOCTL_GENERIC_REQ
+ _iob_from_pin_var( iob.req, pin );
+ p_buff_in = _pcps_kmalloc( iob.req.in_sz );
+
+ if ( p_buff_in == NULL )
{
- _pcps_iob( MBG_TIME_INFO_HRT, _s );
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for %s, cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.in_sz,
+ "IOCTL_PCPS_GENERIC_WRITE_GPS", (ulong) iob.req.info );
+ goto err_no_mem;
+ }
- if ( !_pcps_ddev_has_hr_time( pddev ) )
- goto err_support;
+ _frc_iob_from_pin( p_buff_in, pin, iob.req.in_sz );
- mbg_get_pc_cycles( &_s.sys_time_cycles.cyc_before );
- mbg_get_sys_time( &_s.sys_time_cycles.sys_time );
- mbg_get_pc_cycles( &_s.sys_time_cycles.cyc_after );
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_write_gps( pddev, (uint8_t) iob.req.info, p_buff_in,
+ (uint16_t) iob.req.in_sz );
+ _pcps_sem_dec( pddev );
- _pcps_sem_inc_safe( pddev );
- rc = _pcps_read_var( pddev, PCPS_GIVE_HR_TIME, _s.ref_hr_time_cycles.t );
- _s.ref_hr_time_cycles.cycles =(pddev)->acc_cycles;
- _pcps_sem_dec( pddev );
+ _pcps_kfree( p_buff_in, iob.req.in_sz );
- if ( rc != MBG_SUCCESS )
- goto err_access;
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
- _pcps_iob_to_pout( MBG_TIME_INFO_HRT, _s, pout );
- }
+ #else
+
+ _iob_from_pin_var( iob.ctl, pin );
+ buffer_size = sizeof( iob.ctl ) + iob.ctl.data_size_in;
+ p_buff = _pcps_kmalloc( buffer_size );
+
+ if ( p_buff == NULL )
+ goto err_no_mem;
+
+ _iob_from_pin( p_buff, pin, buffer_size );
+
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_write_gps( pddev, (uint8_t) iob.ctl.info, p_buff->data,
+ (uint8_t) iob.ctl.data_size_in );
+ _pcps_sem_dec( pddev );
+
+ _pcps_kfree( p_buff, buffer_size );
+
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+
+ #endif
break;
- case IOCTL_GET_TIME_INFO_TSTAMP:
+ case IOCTL_PCPS_GENERIC_IO:
+ #if USE_IOCTL_GENERIC_REQ
+ _io_chk_cond( _pcps_ddev_has_generic_io( pddev ) );
+ _iob_from_pin_var( iob.req, pin );
+
+ if ( iob.req.in_p && iob.req.in_sz )
{
- _pcps_iob( MBG_TIME_INFO_TSTAMP, _s );
+ p_buff_in = _pcps_kmalloc( iob.req.in_sz );
- if ( !_pcps_ddev_has_fast_hr_timestamp( pddev ) )
- goto err_support;
+ if ( p_buff_in == NULL )
+ {
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for input in %s, cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.in_sz,
+ "IOCTL_PCPS_GENERIC_IO", (ulong) iob.req.info );
+ goto err_no_mem;
+ }
- mbg_get_pc_cycles( &_s.sys_time_cycles.cyc_before );
- mbg_get_sys_time( &_s.sys_time_cycles.sys_time );
- mbg_get_pc_cycles( &_s.sys_time_cycles.cyc_after );
+ _frc_iob_from_pin( p_buff_in, pin, iob.req.in_sz );
+ }
+ else
+ {
+ p_buff_in = NULL;
+ iob.req.in_sz = 0; // just to be sure
+ }
- do_get_fast_hr_timestamp_cycles_safe( pddev, &(_s).ref_tstamp_cycles );
+ if ( iob.req.out_p && iob.req.out_sz )
+ {
+ p_buff_out = _pcps_kmalloc( iob.req.out_sz );
- rc = MBG_SUCCESS;
+ if ( p_buff_out == NULL )
+ {
+ _mbgddmsg_4( MBG_DBG_INFO, "%s: unable to alloc %lu bytes for output in %s, cmd: %02lX",
+ pcps_driver_name, (ulong) iob.req.in_sz,
+ "IOCTL_PCPS_GENERIC_IO", (ulong) iob.req.info );
- _pcps_iob_to_pout( MBG_TIME_INFO_TSTAMP, _s, pout );
+ // free the input buffer we already have allocated
+ _pcps_kfree( p_buff_in, iob.req.in_sz );
+ goto err_no_mem;
+ }
}
- break;
-
-#if USE_DEBUG_PORT
- case IOCTL_MBG_DBG_SET_BIT:
+ else
{
- _pcps_iob( MBG_DBG_DATA, _s );
- _pcps_iob( MBG_PC_CYCLES, _c );
+ p_buff_out = NULL;
+ iob.req.out_sz = 0; // just to be sure
+ }
- _pcps_iob_from_pin( MBG_DBG_DATA, _s, pin );
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_generic_io( pddev, (uint8_t) iob.req.info,
+ p_buff_in, (uint8_t) iob.req.in_sz,
+ p_buff_out, (uint8_t) iob.req.out_sz );
+ _pcps_sem_dec( pddev );
- _mbg_dbg_set_bit( pddev, _s );
- mbg_get_pc_cycles( &(_c) );
+ if ( rc == MBG_SUCCESS )
+ _frc_iob_to_pout( p_buff_out, iob.req.out_p, iob.req.out_sz );
+
+ if ( p_buff_in )
+ _pcps_kfree( p_buff_in, iob.req.in_sz );
+
+ if ( p_buff_out )
+ _pcps_kfree( p_buff_out, iob.req.out_sz );
+
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+
+ #else
+
+ _io_chk_cond( _pcps_ddev_has_generic_io( pddev ) );
+
+ _iob_from_pin_var( iob.ctl, pin );
+ buffer_size = sizeof( iob.ctl ) +
+ ( ( iob.ctl.data_size_in > iob.ctl.data_size_out ) ?
+ iob.ctl.data_size_in : iob.ctl.data_size_out );
+ p_buff = _pcps_kmalloc( buffer_size );
- _pcps_iob_to_pout( MBG_PC_CYCLES, _c, pout );
+ if ( p_buff == NULL )
+ goto err_no_mem;
+
+ _iob_from_pin( p_buff, pin, sizeof( p_buff->ctl ) + iob.ctl.data_size_in );
+
+ _pcps_sem_inc_safe( pddev );
+ rc = pcps_generic_io( pddev, (uint8_t) iob.ctl.info,
+ p_buff->data, (uint8_t) iob.ctl.data_size_in,
+ p_buff->data, (uint8_t) iob.ctl.data_size_out );
+ _pcps_sem_dec( pddev );
+
+ if ( rc == MBG_SUCCESS )
+ {
+ p_buff->ctl = iob.ctl;
+ _iob_to_pout( p_buff, pout, sizeof( p_buff->ctl ) + iob.ctl.data_size_out ); //##+++++++ need to check this !!
}
+
+ _pcps_kfree( p_buff, buffer_size );
+
+ if ( rc != MBG_SUCCESS )
+ goto err_access;
+
+ #endif
break;
- case IOCTL_MBG_DBG_CLR_BIT:
- {
- _pcps_iob( MBG_DBG_DATA, _s );
- _pcps_iob( MBG_PC_CYCLES, _c );
+ // The next codes are somewhat special and normally
+ // not used by the driver software:
- _pcps_iob_from_pin( MBG_DBG_DATA, _s, pin );
+ case IOCTL_GET_MAPPED_MEM_ADDR:
+ _io_chk_cond( ( pddev->asic_features & PCI_ASIC_HAS_MM_IO ) );
+ _io_get_mapped_mem_address( pddev, pout );
+ break;
- _mbg_dbg_clr_bit( pddev, _s );
- mbg_get_pc_cycles( &(_c) );
- _pcps_iob_to_pout( MBG_PC_CYCLES, _c, pout );
- }
+ case IOCTL_UNMAP_MAPPED_MEM:
+ _io_chk_cond( ( pddev->asic_features & PCI_ASIC_HAS_MM_IO ) );
+ _io_unmap_mapped_mem_address( pddev, pin );
break;
- case IOCTL_MBG_DBG_CLR_ALL:
- {
- _pcps_iob( MBG_PC_CYCLES, _c );
- _mbg_dbg_clr_all( pddev );
- mbg_get_pc_cycles( &(_c) );
+ #if USE_DEBUG_PORT
+ // The codes below are used for debugging only.
+ // Unrestricted usage may cause system malfunction !!
- _pcps_iob_to_pout( MBG_PC_CYCLES, _c, pout );
- }
+ case IOCTL_MBG_DBG_GET_PORT_ADDR:
+ _iob_to_pout_var( mbg_dbg_port, pout );
+ rc = MBG_SUCCESS;
+ break;
+
+
+ case IOCTL_MBG_DBG_SET_PORT_ADDR:
+ _iob_from_pin_var( mbg_dbg_port, pin );
+ mbg_dbg_port_mapped = _pcps_ioremap( mbg_dbg_port, sizeof( mbg_dbg_port ) );
+ rc = MBG_SUCCESS;
+ break;
+
+
+ case IOCTL_MBG_DBG_SET_BIT:
+ _iob_from_pin_var( iob.mbg_dbg_data, pin );
+ _mbg_dbg_set_bit( pddev, iob.mbg_dbg_data );
+ mbg_get_pc_cycles( &cyc );
+ _iob_to_pout_var( cyc, pout );
+ break;
+
+
+ case IOCTL_MBG_DBG_CLR_BIT:
+ _iob_from_pin_var( iob.mbg_dbg_data, pin );
+ _mbg_dbg_clr_bit( pddev, iob.mbg_dbg_data );
+ mbg_get_pc_cycles( &cyc );
+ _iob_to_pout_var( cyc, pout );
break;
-#endif
+
+
+ case IOCTL_MBG_DBG_CLR_ALL:
+ _mbg_dbg_clr_all( pddev );
+ mbg_get_pc_cycles( &cyc );
+ _iob_to_pout_var( cyc, pout );
+ break;
+
+ #endif // USE_DEBUG_PORT
default:
goto err_inval;
-
}
return rc;
diff --git a/mbglib/common/mbg_arch.h b/mbglib/common/mbg_arch.h
index 4878922..7bb9a3b 100755
--- a/mbglib/common/mbg_arch.h
+++ b/mbglib/common/mbg_arch.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbg_arch.h 1.3.1.3 2011/04/12 12:55:28 martin TRASH $
+ * $Id: mbg_arch.h 1.3.1.4 2011/06/27 16:12:59 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,7 @@
*
* -----------------------------------------------------------------------
* $Log: mbg_arch.h $
+ * Revision 1.3.1.4 2011/06/27 16:12:59 martin
* Revision 1.3.1.3 2011/04/12 12:55:28 martin
* Include words.h.
* Revision 1.3.1.2 2011/02/09 15:46:48 martin
@@ -64,12 +65,12 @@
// define some default macros assuming no special handling is required
// to access unaligned data.
-#if !defined( _pcps_put_unaligned )
- #define _pcps_put_unaligned( _v, _p ) ((void)( *(_p) = (_v) ))
+#if !defined( _mbg_put_unaligned )
+ #define _mbg_put_unaligned( _v, _p ) ((void)( *(_p) = (_v) ))
#endif
-#if !defined( _pcps_get_unaligned )
- #define _pcps_get_unaligned( _p ) (*(_p))
+#if !defined( _mbg_get_unaligned )
+ #define _mbg_get_unaligned( _p ) (*(_p))
#endif
diff --git a/mbglib/common/mbg_tgt.h b/mbglib/common/mbg_tgt.h
index 95d1111..f5ede60 100755
--- a/mbglib/common/mbg_tgt.h
+++ b/mbglib/common/mbg_tgt.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbg_tgt.h 1.22.2.12 2011/04/12 15:36:00 martin TRASH $
+ * $Id: mbg_tgt.h 1.24 2011/08/23 10:21:23 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -11,27 +11,18 @@
*
* -----------------------------------------------------------------------
* $Log: mbg_tgt.h $
- * Revision 1.22.2.12 2011/04/12 15:36:00 martin
- * Revision 1.22.2.11 2011/03/22 10:25:26Z martin
- * Fixed typo in comment.
- * Revision 1.22.2.10 2011/02/09 15:46:48 martin
- * Revision 1.22.2.9 2011/02/09 15:27:10 martin
- * Revision 1.22.2.8 2011/02/04 10:15:54Z martin
- * Revision 1.22.2.7 2011/02/01 17:11:54 martin
- * Revision 1.22.2.6 2011/01/27 16:16:28 martin
- * Support wchar_t for BSD.
- * Revision 1.22.2.5 2011/01/24 17:08:40 martin
- * Fixed build under FreeBSD.
- * Revision 1.22.2.4 2010/12/14 11:04:02 martin
- * Revision 1.22.2.3 2010/05/25 14:42:32Z martin
- * Don't use MM I/O on IA64 platform.
- * Revision 1.22.2.2 2010/05/21 13:09:35 martin
- * Initial support for IA64 platform.
- * Revision 1.22.2.1 2010/04/22 09:35:56 martin
+ * Revision 1.24 2011/08/23 10:21:23 martin
+ * New symbol _NO_MBG_API_ATTR which can be used with functions
+ * which are going to be exported by a DLL, but actually aren't, yet.
+ * Revision 1.23 2011/08/19 10:47:00 martin
+ * Don't include stddef.h.
* Distinguish between different gcc target platforms.
+ * Initial support for IA64 platform.
+ * Support wchar_t for BSD.
+ * Defined _NO_USE_PACK_INTF for Sparc and IA64.
+ * Fixed typo in comment.
* Revision 1.22 2009/10/01 08:20:50 martin
* Fixed inline code support with different BC versions.
- * Revision 1.1 2009/11/20 12:24:05 philipp
* Revision 1.21 2009/09/01 10:34:23Z martin
* Don't define __mbg_inline for CVI and undefined targets.
* Revision 1.20 2009/08/18 15:14:26 martin
@@ -232,11 +223,15 @@
#define MBG_ARCH_IA64
+ #define _NO_USE_PACK_INTF
+
#elif defined( __sparc__ )
#define MBG_ARCH_SPARC
#define MBG_USE_MM_IO_FOR_PCI 1
+ #define _NO_USE_PACK_INTF
+
#elif defined( __arm__ )
#define MBG_ARCH_ARM
@@ -369,6 +364,10 @@
#define _MBG_API_ATTR
#endif
+#if !defined( _NO_MBG_API_ATTR )
+ #define _NO_MBG_API_ATTR
+#endif
+
#if !defined( MBG_INVALID_PORT_HANDLE )
#define MBG_INVALID_PORT_HANDLE MBG_INVALID_HANDLE
#endif
@@ -442,4 +441,3 @@ extern "C" {
#endif /* _MBG_TGT_H */
-
diff --git a/mbglib/common/mbgdevio.c b/mbglib/common/mbgdevio.c
index f23f394..fa5b6b2 100755
--- a/mbglib/common/mbgdevio.c
+++ b/mbglib/common/mbgdevio.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgdevio.c 1.35.1.17.1.4 2011/04/19 15:05:45 martin TRASH martin $
+ * $Id: mbgdevio.c 1.35.1.26 2011/09/26 13:58:54 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,14 +10,40 @@
*
* -----------------------------------------------------------------------
* $Log: mbgdevio.c $
- * Revision 1.35.1.17.1.4 2011/04/19 15:05:45 martin
- * PTP unicast cfg stuff ...
- * Revision 1.35.1.17.1.3 2011/04/19 13:08:34 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.35.1.17.1.2 2011/04/19 09:59:09 martin
- * More PTP unicast cfg ...
- * Revision 1.35.1.17.1.1 2011/04/18 15:30:42 martin
- * Started PTP unicast
+ * Revision 1.35.1.26 2011/09/26 13:58:54 martin
+ * Added a workaround to make mbgmon (BC) build under Windows.
+ * In mbg_get_serial_settings() return an error if the number of provided
+ * serial ports or supported string types exceeds the numbers supported
+ * by the driver.
+ * Moved mbg_get_serial_settings() and mbg_save_serial_settings()
+ * to an extra file. These functions expect parameters the sizes of
+ * which might change in future API versions, which would make
+ * functions exported by shared libraries incompatible across versions.
+ * Made functions mbg_get_gps_all_port_info() and
+ * mbg_get_gps_all_str_type_info() non-static so they are now exported
+ * by the shared libraries built from this module.
+ * Include cfg_hlp.h.
+ * Revision 1.35.1.25 2011/07/20 15:50:51Z martin
+ * Conditionally use older IOCTL request buffer structures.
+ * Moved some macros etc. to the .h file.
+ * Modified some macros.
+ * Revision 1.35.1.24 2011/07/14 14:54:00 martin
+ * Modified generic IOCTL handling such that for calls requiring variable sizes
+ * a fixed request block containing input and output buffer pointers and sizes is
+ * passed down to the kernel driver. This simplifies implementation under *BSD
+ * and also works for other target systems.
+ * Revision 1.35.1.23 2011/07/08 10:11:00 martin
+ * Fixes for DOS.
+ * Revision 1.35.1.22 2011/07/06 11:19:20Z martin
+ * Support reading CORR_INFO, and reading/writing TR_DISTANCE.
+ * Revision 1.35.1.21 2011/06/29 11:09:55 martin
+ * Added mbg_dev_has_pzf() function.
+ * Revision 1.35.1.20 2011/06/27 13:02:50 martin
+ * Use O_RDWR flag when opening a device.
+ * Revision 1.35.1.19 2011/06/24 11:13:36 martin
+ * Revision 1.35.1.18 2011/06/22 10:05:45 martin
+ * Support PTP unicast configuration.
+ * Account for some IOCTL codes renamed to follow common naming conventions.
* Revision 1.35.1.17 2011/04/12 12:56:20 martin
* Renamed mutex stuff to critical sections.
* Revision 1.35.1.16 2011/03/31 13:18:46 martin
@@ -257,16 +283,13 @@
#include <parmgps.h>
#include <gpsutils.h>
#include <mbgerror.h>
+#include <cfg_hlp.h>
#if defined( MBG_TGT_DOS_PM )
#include <mbg_dpmi.h>
#endif
-#if defined( MBG_USE_KERNEL_DRIVER )
-
- #include <mbgioctl.h>
-
-#else
+#if !defined( MBG_USE_KERNEL_DRIVER )
#include <pcpsdrvr.h>
#include <pci_asic.h>
@@ -304,60 +327,14 @@ typedef struct
#include <tchar.h>
#include <stdio.h>
- #define _mbgdevio_vars() \
- DWORD rc
-
- #define _mbgdevio_ret_val \
- rc
-
- #define _do_mbgdevio_io( _dh, _ioctl, _p, _insz, _outsz ) \
- rc = do_mbgdevio_io( _dh, _ioctl, (LPVOID) _p, _insz, _outsz )
-
- static __mbg_inline
- DWORD do_mbgdevio_io( MBG_DEV_HANDLE dh, int ioctl_code,
- LPVOID p, int in_sz, int out_sz )
- {
- DWORD ReturnedLength;
-
- if ( !DeviceIoControl( dh, ioctl_code,
- p, in_sz, p, out_sz,
- &ReturnedLength,
- NULL
- ) )
- {
- DWORD rc = GetLastError();
-
- // do not report a USB device timeout error
- if ( rc != _mbg_err_to_os( MBG_ERR_USB_ACCESS ) )
- mbgsvctl_log_mbgdevio_error( ioctl_code, rc );
-
- return rc;
- }
-
- return MBG_SUCCESS;
-
- } // do_mbgdevio_io
-
#elif defined( MBG_TGT_UNIX )
- #include <mbgioctl.h>
-
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h> // sprintf()
- #include <sys/ioctl.h>
#include <sys/mman.h>
- #define _mbgdevio_vars() \
- int rc
-
- #define _mbgdevio_ret_val \
- ( ( rc < 0 ) ? rc : MBG_SUCCESS )
-
- #define _do_mbgdevio_io( _dh, _ioctl, _p, _insz, _outsz ) \
- rc = ioctl( _dh, _ioctl, _p )
-
#else // other target OSs which access the hardware directly
#if defined( MBG_TGT_QNX_NTO )
@@ -380,12 +357,6 @@ typedef struct
#define _pcps_write_gps_var_safe _pcps_write_gps_var
#endif
- #define _mbgdevio_vars() \
- int rc
-
- #define _mbgdevio_ret_val \
- rc
-
#define _mbgdevio_chk_cond( _cond ) \
{ \
if ( !(_cond) ) \
@@ -406,189 +377,53 @@ typedef struct
#if !defined( _mbgdevio_chk_cond )
// If the macro has not been defined previously then
- // it is not be required for the target environment and
+ // it may not be required for the target environment and
// is defined as empty string.
- #define _mbgdevio_chk_cond( _cond );
+ #define _mbgdevio_chk_cond( _cond ) _nop_macro_fnc()
#endif
-// The code below depends on whether the target device is accessed via
-// IOCTLs to a device driver, or the hardware is accessed directly.
-
-#if defined( _MBGIOCTL_H ) // using IOCTL to access device driver
-
- #define _mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ) \
- _do_mbgdevio_io( _dh, _ioctl, _p, 0, _sz )
-
- #define _mbgdevio_write( _dh, _cmd, _ioctl, _p, _sz ) \
- _do_mbgdevio_io( _dh, _ioctl, _p, _sz, 0 )
-
- #define _mbgdevio_read_gps _mbgdevio_read
-
- #define _mbgdevio_write_gps _mbgdevio_write
-
-
- #define _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ) \
- _mbgdevio_read( _dh, _cmd, _ioctl, _p, sizeof( *(_p) ) )
-
- #define _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ) \
- _mbgdevio_write( _dh, _cmd, _ioctl, _p, sizeof( *(_p) ) )
-
- #define _mbgdevio_write_cmd( _dh, _cmd, _ioctl ) \
- _mbgdevio_write( _dh, _cmd, _ioctl, NULL, 0 )
-
- #define _mbgdevio_read_gps_var _mbgdevio_read_var
-
- #define _mbgdevio_write_gps_var _mbgdevio_write_var
-
-
- #define _mbgdevio_gen_read( _dh, _cmd, _p, _sz ) \
- rc = mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_READ, NULL, 0, _p, _sz )
-
- #define _mbgdevio_gen_write( _dh, _cmd, _p, _sz ) \
- rc = mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_WRITE, _p, _sz, NULL, 0 )
-
- #define _mbgdevio_gen_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz ) \
- rc = mbgdevio_do_gen_io( _dh, _type, IOCTL_PCPS_GENERIC_IO, _in_p, _in_sz, _out_p, _out_sz )
-
- #define _mbgdevio_gen_read_gps( _dh, _cmd, _p, _sz ) \
- rc = mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_READ_GPS, NULL, 0, _p, _sz )
-
- #define _mbgdevio_gen_write_gps( _dh, _cmd, _p, _sz ) \
- rc = mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_WRITE_GPS, _p, _sz, NULL, 0 )
-
-
- static __mbg_inline
- int mbgdevio_do_gen_io( MBG_DEV_HANDLE dh, int info, int ioctl_code,
- const void *in_p, int in_sz,
- void *out_p, int out_sz )
- {
- IOCTL_GENERIC_BUFFER *p_buff;
- int buff_size = sizeof( p_buff->ctl )
- + ( ( in_sz > out_sz ) ? in_sz : out_sz );
- int rc;
-
- p_buff = (IOCTL_GENERIC_BUFFER *) malloc( buff_size );
-
- if ( p_buff == NULL )
- return _mbg_err_to_os( MBG_ERR_NO_MEM );
-
- p_buff->ctl.info = info;
- p_buff->ctl.data_size_in = in_sz;
- p_buff->ctl.data_size_out = out_sz;
-
- if ( in_p )
- memcpy( p_buff->data, in_p, in_sz );
-
- _do_mbgdevio_io( dh, ioctl_code,
- p_buff,
- sizeof( IOCTL_GENERIC_CTL ) + in_sz,
- sizeof( IOCTL_GENERIC_CTL ) + out_sz );
-
- if ( out_p && ( rc == MBG_SUCCESS ) )
- memcpy( out_p, p_buff->data, out_sz );
-
- free( p_buff );
-
- return rc;
-
- } // mbgdevio_do_gen_io
-
-#else // accessing hardware device directly
-
- #define _mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ) \
- rc = pcps_read_safe( _dh, _cmd, _p, _sz )
-
- #define _mbgdevio_write( _dh, _cmd, _ioctl, _p, _sz ) \
- rc = pcps_write_safe( _dh, _cmd, _p, _sz )
-
- #define _mbgdevio_read_gps( _dh, _cmd, _ioctl, _p, _sz ) \
- rc = pcps_read_gps_safe( _dh, _cmd, _p, _sz )
-
- #define _mbgdevio_write_gps( _dh, _cmd, _ioctl, _p, _sz ) \
- rc = pcps_write_gps_safe( _dh, _cmd, _p, _sz )
-
-
- #define _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ) \
- rc = _pcps_read_var_safe( _dh, _cmd, *(_p) )
-
- #define _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ) \
- rc = _pcps_write_var_safe( _dh, _cmd, *(_p) )
-
- #define _mbgdevio_write_cmd( _dh, _cmd, _ioctl ) \
- rc = _pcps_write_byte_safe( _dh, _cmd );
-
- #define _mbgdevio_read_gps_var( _dh, _cmd, _ioctl, _p ) \
- rc = _pcps_read_gps_var_safe( _dh, _cmd, *(_p) )
-
- #define _mbgdevio_write_gps_var( _dh, _cmd, _ioctl, _p ) \
- rc = _pcps_write_gps_var_safe( _dh, _cmd, *(_p) )
-
-
- #define _mbgdevio_gen_read( _dh, _cmd, _p, _sz ) \
- _mbgdevio_read( _dh, _cmd, -1, _p, _sz )
-
- #define _mbgdevio_gen_write( _dh, _cmd, _p, _sz ) \
- _mbgdevio_write( _dh, _cmd, -1, _p, _sz )
-
- #define _mbgdevio_gen_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz ); \
- { \
- _mbgdevio_chk_cond( _pcps_ddev_has_generic_io( _dh ) ); \
- rc = pcps_generic_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz ); \
- }
-
- #define _mbgdevio_gen_read_gps( _dh, _cmd, _p, _sz ) \
- _mbgdevio_read_gps( _dh, _cmd, -1, _p, _sz )
-
- #define _mbgdevio_gen_write_gps( _dh, _cmd, _p, _sz ) \
- _mbgdevio_write_gps( _dh, _cmd, -1, _p, _sz )
-
-#endif
-
-
-
-
#define _mbgdevio_read_chk( _dh, _cmd, _ioctl, _p, _sz, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ); \
+ rc = _do_mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ); \
}
#define _mbgdevio_read_var_chk( _dh, _cmd, _ioctl, _p, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ); \
+ rc = _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ); \
}
#define _mbgdevio_write_var_chk( _dh, _cmd, _ioctl, _p, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ); \
+ rc = _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ); \
}
#define _mbgdevio_write_cmd_chk( _dh, _cmd, _ioctl, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_write_cmd( _dh, _cmd, _ioctl ); \
+ rc = _mbgdevio_write_cmd( _dh, _cmd, _ioctl ); \
}
#define _mbgdevio_read_gps_chk( _dh, _cmd, _ioctl, _p, _sz, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_read_gps( _dh, _cmd, _ioctl, _p, _sz ); \
+ rc = _do_mbgdevio_read_gps( _dh, _cmd, _ioctl, _p, _sz ); \
}
#define _mbgdevio_read_gps_var_chk( _dh, _cmd, _ioctl, _p, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_read_gps_var( _dh, _cmd, _ioctl, _p ); \
+ rc = _mbgdevio_read_gps_var( _dh, _cmd, _ioctl, _p ); \
}
#define _mbgdevio_write_gps_var_chk( _dh, _cmd, _ioctl, _p, _cond ) \
{ \
_mbgdevio_chk_cond( _cond ); \
- _mbgdevio_write_gps_var( _dh, _cmd, _ioctl, _p ); \
+ rc = _mbgdevio_write_gps_var( _dh, _cmd, _ioctl, _p ); \
}
@@ -597,7 +432,7 @@ typedef struct
#define _mbgdevio_query_cond( _dh, _cond, _ioctl, _p ) \
{ \
_mbgdevio_vars(); \
- _mbgdevio_read_var( _dh, -1, _ioctl, _p ); \
+ rc = _mbgdevio_read_var( _dh, -1, _ioctl, _p ); \
return _mbgdevio_ret_val; \
}
@@ -606,7 +441,7 @@ typedef struct
#define _mbgdevio_query_cond( _dh, _cond, _ioctl, _p ) \
{ \
*p = _cond( _dh ); \
- return MBG_SUCCESS; \
+ return MBG_SUCCESS; \
}
#define _mbgdevio_query_ri_cond( _dh, _cond, _ioctl, _p ) \
@@ -622,7 +457,6 @@ static MBG_DEVICE_INFO device_info_list[MBG_MAX_DEVICES];
-
static /*HDR*/ //##++ make this public ?
int mbg_comp_hr_latency( PCPS_TIME_STAMP *ts,
const MBG_PC_CYCLES *p_cyc_ts,
@@ -821,7 +655,7 @@ fail:
sprintf( dev_fn, "/dev/mbgclock%d", device_index ); //##++
- dh = open( dev_fn, 0 );
+ dh = open( dev_fn, O_RDWR );
return ( dh < 0 ) ? MBG_INVALID_DEV_HANDLE : dh;
@@ -877,7 +711,7 @@ fail:
MBG_DEV_HANDLE dh = -1;
if ( strlen( hw_id ) > 0 )
- dh = open( hw_id, 0 );
+ dh = open( hw_id, O_RDWR );
return ( dh < 0 ) ? MBG_INVALID_DEV_HANDLE : dh;
@@ -1404,7 +1238,7 @@ fail:
#elif defined ( MBG_TGT_UNIX )
if ( hw_id[0] != '\0' )
- dh = open( hw_id, 0 );
+ dh = open( hw_id, O_RDWR );
else
goto fail;
@@ -1462,7 +1296,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_drvr_info( MBG_DEV_HANDLE dh, PCPS_DRVR_INFO
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_DRVR_INFO, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_DRVR_INFO, p );
return _mbgdevio_ret_val;
#else
#if defined( __BORLANDC__ )
@@ -1490,7 +1324,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_device_info( MBG_DEV_HANDLE dh, PCPS_DEV *p )
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_DEV, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_DEV, p );
// Endianess is converted inside the kernel driver, if necessary.
return _mbgdevio_ret_val;
#else
@@ -1517,7 +1351,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_status_port( MBG_DEV_HANDLE dh, PCPS_STATUS_P
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_STATUS_PORT, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_STATUS_PORT, p );
// No endianess conversion required.
return _mbgdevio_ret_val;
#else
@@ -1555,7 +1389,7 @@ _MBG_API_ATTR int _MBG_API mbg_generic_read( MBG_DEV_HANDLE dh, int cmd,
void *p, int size )
{
_mbgdevio_vars();
- _mbgdevio_gen_read( dh, cmd, p, size );
+ rc = _mbgdevio_gen_read( dh, cmd, p, size );
// No type information available, so endianess must be
// converted by the caller, if required.
return _mbgdevio_ret_val;
@@ -1592,7 +1426,7 @@ _MBG_API_ATTR int _MBG_API mbg_generic_read_gps( MBG_DEV_HANDLE dh, int cmd,
void *p, int size )
{
_mbgdevio_vars();
- _mbgdevio_gen_read_gps( dh, cmd, p, size );
+ rc = _mbgdevio_gen_read_gps( dh, cmd, p, size );
// No type information available, so endianess must be
// converted by the caller, if required.
return _mbgdevio_ret_val;
@@ -1628,7 +1462,7 @@ _MBG_API_ATTR int _MBG_API mbg_generic_write( MBG_DEV_HANDLE dh, int cmd,
_mbgdevio_vars();
// No type information available, so endianess must be
// converted by the caller, if required.
- _mbgdevio_gen_write( dh, cmd, p, size );
+ rc = _mbgdevio_gen_write( dh, cmd, p, size );
return _mbgdevio_ret_val;
} // mbg_generic_write
@@ -1665,7 +1499,7 @@ _MBG_API_ATTR int _MBG_API mbg_generic_write_gps( MBG_DEV_HANDLE dh, int cmd,
_mbgdevio_vars();
// No type information available, so endianess must be
// converted by the caller, if required.
- _mbgdevio_gen_write_gps( dh, cmd, p, size );
+ rc = _mbgdevio_gen_write_gps( dh, cmd, p, size );
return _mbgdevio_ret_val;
} // mbg_generic_write_gps
@@ -1693,9 +1527,16 @@ _MBG_API_ATTR int _MBG_API mbg_generic_io( MBG_DEV_HANDLE dh, int type,
void *out_p, int out_sz )
{
_mbgdevio_vars();
+
+ #if !defined( _MBGIOCTL_H )
+ // The hardware is accessed directly, so we must check
+ // here if this call is supported.
+ _mbgdevio_chk_cond( _pcps_ddev_has_generic_io( dh ) );
+ #endif
+
// No type information available, so endianess must be
// converted by the caller, if required.
- _mbgdevio_gen_io( dh, type, in_p, in_sz, out_p, out_sz );
+ rc = _mbgdevio_gen_io( dh, type, in_p, in_sz, out_p, out_sz );
return _mbgdevio_ret_val;
} // mbg_generic_io
@@ -1724,7 +1565,7 @@ _MBG_API_ATTR int _MBG_API mbg_generic_io( MBG_DEV_HANDLE dh, int type,
_MBG_API_ATTR int _MBG_API mbg_get_time( MBG_DEV_HANDLE dh, PCPS_TIME *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GIVE_TIME, IOCTL_GET_PCPS_TIME, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GIVE_TIME, IOCTL_GET_PCPS_TIME, p );
// No endianess conversion required.
return _mbgdevio_ret_val;
@@ -1812,7 +1653,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_time_sec_change( MBG_DEV_HANDLE dh, PCPS_TIME
{
#if defined( MBG_TGT_WIN32 )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_TIME_SEC_CHANGE, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCPS_TIME_SEC_CHANGE, p );
// No endianess conversion required.
return _mbgdevio_ret_val;
#else
@@ -1914,7 +1755,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_event_time( MBG_DEV_HANDLE dh, const PCPS_TIM
_MBG_API_ATTR int _MBG_API mbg_get_serial( MBG_DEV_HANDLE dh, PCPS_SERIAL *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GET_SERIAL, IOCTL_GET_PCPS_SERIAL, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GET_SERIAL, IOCTL_GET_PCPS_SERIAL, p );
// No endianess conversion required.
return _mbgdevio_ret_val;
@@ -1944,7 +1785,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_serial( MBG_DEV_HANDLE dh, const PCPS_SERIAL
{
_mbgdevio_vars();
// No endianess conversion required.
- _mbgdevio_write_var( dh, PCPS_SET_SERIAL, IOCTL_SET_PCPS_SERIAL, p );
+ rc = _mbgdevio_write_var( dh, PCPS_SET_SERIAL, IOCTL_SET_PCPS_SERIAL, p );
return _mbgdevio_ret_val;
} // mbg_set_serial
@@ -2315,7 +2156,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_irig_ctrl_bits( MBG_DEV_HANDLE dh,
MBG_IRIG_CTRL_BITS *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GET_IRIG_CTRL_BITS, IOCTL_GET_IRIG_CTRL_BITS, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GET_IRIG_CTRL_BITS, IOCTL_GET_IRIG_CTRL_BITS, p );
_mbg_swab_irig_ctrl_bits( p );
return _mbgdevio_ret_val;
@@ -2335,7 +2176,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_irig_ctrl_bits( MBG_DEV_HANDLE dh,
@see mbg_get_raw_irig_data()
@see mbg_get_raw_irig_data_on_sec_change()
*/
-_MBG_API_ATTR int _MBG_API mbg_dev_has_raw_irig_data( MBG_DEV_HANDLE dh, int *p)
+_MBG_API_ATTR int _MBG_API mbg_dev_has_raw_irig_data( MBG_DEV_HANDLE dh, int *p )
{
_mbgdevio_query_cond( dh, _pcps_ddev_has_raw_irig_data, IOCTL_DEV_HAS_RAW_IRIG_DATA, p );
@@ -2362,7 +2203,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_raw_irig_data( MBG_DEV_HANDLE dh,
MBG_RAW_IRIG_DATA *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GET_RAW_IRIG_DATA, IOCTL_GET_RAW_IRIG_DATA, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GET_RAW_IRIG_DATA, IOCTL_GET_RAW_IRIG_DATA, p );
// No endianess conversion required.
return _mbgdevio_ret_val;
@@ -2391,17 +2232,13 @@ _MBG_API_ATTR int _MBG_API mbg_get_raw_irig_data( MBG_DEV_HANDLE dh,
_MBG_API_ATTR int _MBG_API mbg_get_raw_irig_data_on_sec_change( MBG_DEV_HANDLE dh,
MBG_RAW_IRIG_DATA *p )
{
-
PCPS_TIME t;
-
_mbgdevio_vars();
- rc = mbg_get_time_sec_change( dh, &t);
+ rc = mbg_get_time_sec_change( dh, &t );
if ( rc == MBG_SUCCESS )
rc = mbg_get_raw_irig_data( dh, p );
- else
- return rc;
return _mbgdevio_ret_val;
@@ -2448,7 +2285,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_irig_time( MBG_DEV_HANDLE dh,
PCPS_IRIG_TIME *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GIVE_IRIG_TIME, IOCTL_GET_IRIG_TIME, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GIVE_IRIG_TIME, IOCTL_GET_IRIG_TIME, p );
_mbg_swab_pcps_irig_time( p );
return _mbgdevio_ret_val;
@@ -2571,7 +2408,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_ucap_event( MBG_DEV_HANDLE dh, PCPS_HR_TIME *
_MBG_API_ATTR int _MBG_API mbg_get_gps_tzdl( MBG_DEV_HANDLE dh, TZDL *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_TZDL, IOCTL_GET_GPS_TZDL, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_TZDL, IOCTL_GET_GPS_TZDL, p );
_mbg_swab_tzdl( p );
return _mbgdevio_ret_val;
@@ -2609,7 +2446,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_tzdl( MBG_DEV_HANDLE dh, const TZDL *p )
_mbg_swab_tzdl( &tmp );
p = &tmp;
#endif
- _mbgdevio_write_gps_var( dh, PC_GPS_TZDL, IOCTL_SET_GPS_TZDL, p );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_TZDL, IOCTL_SET_GPS_TZDL, p );
return _mbgdevio_ret_val;
} // mbg_set_gps_tzdl
@@ -2638,7 +2475,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_tzdl( MBG_DEV_HANDLE dh, const TZDL *p )
_MBG_API_ATTR int _MBG_API mbg_get_gps_sw_rev( MBG_DEV_HANDLE dh, SW_REV *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_SW_REV, IOCTL_GET_GPS_SW_REV, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_SW_REV, IOCTL_GET_GPS_SW_REV, p );
_mbg_swab_sw_rev( p );
return _mbgdevio_ret_val;
@@ -2662,7 +2499,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_sw_rev( MBG_DEV_HANDLE dh, SW_REV *p )
_MBG_API_ATTR int _MBG_API mbg_get_gps_bvar_stat( MBG_DEV_HANDLE dh, BVAR_STAT *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_BVAR_STAT, IOCTL_GET_GPS_BVAR_STAT, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_BVAR_STAT, IOCTL_GET_GPS_BVAR_STAT, p );
_mbg_swab_bvar_stat( p );
return _mbgdevio_ret_val;
@@ -2687,7 +2524,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_bvar_stat( MBG_DEV_HANDLE dh, BVAR_STAT *
_MBG_API_ATTR int _MBG_API mbg_get_gps_time( MBG_DEV_HANDLE dh, TTM *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_TIME, IOCTL_GET_GPS_TIME, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_TIME, IOCTL_GET_GPS_TIME, p );
_mbg_swab_ttm( p );
return _mbgdevio_ret_val;
@@ -2715,7 +2552,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_time( MBG_DEV_HANDLE dh, const TTM *p )
_mbg_swab_ttm( &tmp );
p = &tmp;
#endif
- _mbgdevio_write_gps_var( dh, PC_GPS_TIME, IOCTL_SET_GPS_TIME, p );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_TIME, IOCTL_SET_GPS_TIME, p );
return _mbgdevio_ret_val;
} // mbg_set_gps_time
@@ -2744,7 +2581,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_time( MBG_DEV_HANDLE dh, const TTM *p )
_MBG_API_ATTR int _MBG_API mbg_get_gps_port_parm( MBG_DEV_HANDLE dh, PORT_PARM *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_PORT_PARM, IOCTL_GET_GPS_PORT_PARM, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_PORT_PARM, IOCTL_GET_GPS_PORT_PARM, p );
_mbg_swab_port_parm( p );
return _mbgdevio_ret_val;
@@ -2779,7 +2616,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_port_parm( MBG_DEV_HANDLE dh, const PORT_
_mbg_swab_port_parm( &tmp );
p = &tmp;
#endif
- _mbgdevio_write_gps_var( dh, PC_GPS_PORT_PARM, IOCTL_SET_GPS_PORT_PARM, p );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_PORT_PARM, IOCTL_SET_GPS_PORT_PARM, p );
return _mbgdevio_ret_val;
} // mbg_set_gps_port_parm
@@ -2804,7 +2641,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_port_parm( MBG_DEV_HANDLE dh, const PORT_
_MBG_API_ATTR int _MBG_API mbg_get_gps_ant_info( MBG_DEV_HANDLE dh, ANT_INFO *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_ANT_INFO, IOCTL_GET_GPS_ANT_INFO, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_ANT_INFO, IOCTL_GET_GPS_ANT_INFO, p );
_mbg_swab_ant_info( p );
return _mbgdevio_ret_val;
@@ -2835,7 +2672,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_ant_info( MBG_DEV_HANDLE dh, ANT_INFO *p
_MBG_API_ATTR int _MBG_API mbg_get_gps_ucap( MBG_DEV_HANDLE dh, TTM *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_UCAP, IOCTL_GET_GPS_UCAP, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_UCAP, IOCTL_GET_GPS_UCAP, p );
_mbg_swab_ttm( p );
return _mbgdevio_ret_val;
@@ -2865,7 +2702,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_ucap( MBG_DEV_HANDLE dh, TTM *p )
_MBG_API_ATTR int _MBG_API mbg_get_gps_enable_flags( MBG_DEV_HANDLE dh, ENABLE_FLAGS *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_ENABLE_FLAGS,
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_ENABLE_FLAGS,
IOCTL_GET_GPS_ENABLE_FLAGS, p );
_mbg_swab_enable_flags( p );
return _mbgdevio_ret_val;
@@ -2902,7 +2739,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_enable_flags( MBG_DEV_HANDLE dh,
_mbg_swab_enable_flags( &tmp );
p = &tmp;
#endif
- _mbgdevio_write_gps_var( dh, PC_GPS_ENABLE_FLAGS,
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_ENABLE_FLAGS,
IOCTL_SET_GPS_ENABLE_FLAGS, p );
return _mbgdevio_ret_val;
@@ -2928,7 +2765,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_enable_flags( MBG_DEV_HANDLE dh,
_MBG_API_ATTR int _MBG_API mbg_get_gps_stat_info( MBG_DEV_HANDLE dh, STAT_INFO *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_STAT_INFO, IOCTL_GET_GPS_STAT_INFO, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_STAT_INFO, IOCTL_GET_GPS_STAT_INFO, p );
_mbg_swab_stat_info( p );
return _mbgdevio_ret_val;
@@ -2957,7 +2794,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_cmd( MBG_DEV_HANDLE dh, const GPS_CMD *p
_mbg_swab_gps_cmd( &tmp );
p = &tmp;
#endif
- _mbgdevio_write_gps_var( dh, PC_GPS_CMD, IOCTL_SET_GPS_CMD, p );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_CMD, IOCTL_SET_GPS_CMD, p );
return _mbgdevio_ret_val;
} // mbg_set_gps_cmd
@@ -2981,7 +2818,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_cmd( MBG_DEV_HANDLE dh, const GPS_CMD *p
_MBG_API_ATTR int _MBG_API mbg_get_gps_pos( MBG_DEV_HANDLE dh, POS *p )
{
_mbgdevio_vars();
- _mbgdevio_read_gps_var( dh, PC_GPS_POS, IOCTL_GET_GPS_POS, p );
+ rc = _mbgdevio_read_gps_var( dh, PC_GPS_POS, IOCTL_GET_GPS_POS, p );
swap_pos_doubles( p );
_mbg_swab_pos( p );
return _mbgdevio_ret_val;
@@ -3018,7 +2855,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_pos_xyz( MBG_DEV_HANDLE dh, const XYZ p )
_mbg_swab_double( &xyz[i] );
}
- _mbgdevio_write_gps_var( dh, PC_GPS_POS_XYZ, IOCTL_SET_GPS_POS_XYZ, xyz );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_POS_XYZ, IOCTL_SET_GPS_POS_XYZ, xyz );
return _mbgdevio_ret_val;
} // mbg_set_gps_pos_xyz
@@ -3053,7 +2890,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_gps_pos_lla( MBG_DEV_HANDLE dh, const LLA p )
_mbg_swab_double( &lla[i] );
}
- _mbgdevio_write_gps_var( dh, PC_GPS_POS_LLA, IOCTL_SET_GPS_POS_LLA, lla );
+ rc = _mbgdevio_write_gps_var( dh, PC_GPS_POS_LLA, IOCTL_SET_GPS_POS_LLA, lla );
return _mbgdevio_ret_val;
} // mbg_set_gps_pos_lla
@@ -3154,14 +2991,14 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_receiver_info( MBG_DEV_HANDLE dh, RECEIVE
#if !MBGDEVIO_SIMPLE
-static /*HDR*/
-/* (Intentionally excluded from Doxygen)
- Read a ::STR_TYPE_INFO_IDX array of supported string types.
+/*HDR*/
+/**
+ Read a ::STR_TYPE_INFO_IDX array of supported string types.
The function mbg_setup_receiver_info() must have been called before,
and the returned ::RECEIVER_INFO structure passed to this function.
- <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
- to get retrieve the cuurrent port settings and configuration options.
+ <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
+ to get retrieve the current port settings and configuration options.
@param dh Valid handle to a Meinberg device.
@param stii Pointer to a an array of string type information to be filled up
@@ -3173,9 +3010,9 @@ static /*HDR*/
@see mbg_get_gps_all_port_info()
@see mbg_get_serial_settings()
*/
-int _MBG_API mbg_get_gps_all_str_type_info( MBG_DEV_HANDLE dh,
- STR_TYPE_INFO_IDX stii[],
- const RECEIVER_INFO *p_ri )
+_MBG_API_ATTR int _MBG_API mbg_get_gps_all_str_type_info( MBG_DEV_HANDLE dh,
+ STR_TYPE_INFO_IDX stii[],
+ const RECEIVER_INFO *p_ri )
{
_mbgdevio_vars();
@@ -3189,8 +3026,8 @@ int _MBG_API mbg_get_gps_all_str_type_info( MBG_DEV_HANDLE dh,
// has been read from a device which really supports it, or
// a dummy structure has been setup.
if ( p_ri && ( p_ri->model_code != GPS_MODEL_UNKNOWN ) )
- _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_STR_TYPE_INFO, stii,
- p_ri->n_str_type * sizeof( stii[0] ) );
+ rc = _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_STR_TYPE_INFO, stii,
+ p_ri->n_str_type * sizeof( stii[0] ) );
else
return _mbg_err_to_os( MBG_ERR_NOT_SUPP_BY_DEV );
#endif
@@ -3213,14 +3050,14 @@ int _MBG_API mbg_get_gps_all_str_type_info( MBG_DEV_HANDLE dh,
-static /*HDR*/
-/* (Intentionally excluded from Doxygen)
- Read a ::PORT_INFO_IDX array of supported serial port configurations.
+/*HDR*/
+/**
+ Read a ::PORT_INFO_IDX array of supported serial port configurations.
The function mbg_setup_receiver_info() must have been called before,
and the returned ::RECEIVER_INFO structure passed to this function.
- <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
- to get retrieve the cuurrent port settings and configuration options.
+ <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
+ to get retrieve the current port settings and configuration options.
@param dh Valid handle to a Meinberg device.
@param pii Pointer to a an array of port configuration information to be filled up
@@ -3232,9 +3069,9 @@ static /*HDR*/
@see mbg_get_gps_all_str_type_info()
@see mbg_get_serial_settings()
*/
-int _MBG_API mbg_get_gps_all_port_info( MBG_DEV_HANDLE dh,
- PORT_INFO_IDX pii[],
- const RECEIVER_INFO *p_ri )
+_MBG_API_ATTR int _MBG_API mbg_get_gps_all_port_info( MBG_DEV_HANDLE dh,
+ PORT_INFO_IDX pii[],
+ const RECEIVER_INFO *p_ri )
{
_mbgdevio_vars();
@@ -3246,10 +3083,10 @@ int _MBG_API mbg_get_gps_all_port_info( MBG_DEV_HANDLE dh,
#else
// We check the model_code to see whether the receiver info
// has been read from a device which really supports it, or
- // a dummy structure has been setup.
+ // a dummy structure has been set up.
if ( p_ri && ( p_ri->model_code != GPS_MODEL_UNKNOWN ) )
- _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_PORT_INFO, pii,
- p_ri->n_com_ports * sizeof( pii[0] ) );
+ rc = _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_PORT_INFO, pii,
+ p_ri->n_com_ports * sizeof( pii[0] ) );
else
return _mbg_err_to_os( MBG_ERR_NOT_SUPP_BY_DEV );
#endif
@@ -3274,7 +3111,7 @@ int _MBG_API mbg_get_gps_all_port_info( MBG_DEV_HANDLE dh,
/*HDR*/
/**
- Write the configuration for a single serial port using the ::PORT_SETTINGS_IDX
+ Write the configuration for a single serial port using the ::PORT_SETTINGS_IDX
structure which contains both the ::PORT_SETTINGS and the port index value.
Except for the parameter types, this call is equivalent to mbg_set_gps_port_settings().
The macro _pcps_has_receiver_info() or the API call mbg_dev_has_receiver_info()
@@ -3406,176 +3243,6 @@ check:
-#if !MBGDEVIO_SIMPLE
-
-// The functions below can conditionally be excluded from build
-// for simple applications which don't do complex card configuration.
-// This reduces the number of modules needed to be linked to the
-// application.
-
-/*HDR*/
-/**
- Read all serial port settings and supported configuration parameters.
-
- The functions mbg_get_device_info() and mbg_setup_receiver_info()
- must have been called before, and the returned ::PCPS_DEV and
- ::RECEIVER_INFO structures must be passed to this function.
-
- The complementary function mbg_save_serial_settings() should be used
- to write the modified serial port configuration back to the board.
-
- @param dh Valid handle to a Meinberg device.
- @param *pdev Pointer to a ::PCPS_DEV structure.
- @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
- @param *p_ri Pointer to a ::RECEIVER_INFO structure.
-
- @return ::MBG_SUCCESS or error code returned by device I/O control function.
-
- @see mbg_get_device_info()
- @see mbg_setup_receiver_info()
- @see mbg_save_serial_settings()
-*/
-_MBG_API_ATTR int _MBG_API mbg_get_serial_settings( MBG_DEV_HANDLE dh,
- const PCPS_DEV *pdev,
- RECEIVER_PORT_CFG *pcfg,
- const RECEIVER_INFO *p_ri )
-{
- int rc;
- int i;
-
- memset( pcfg, 0, sizeof( *pcfg ) );
-
- if ( _pcps_has_receiver_info( pdev ) )
- {
- rc = mbg_get_gps_all_port_info( dh, pcfg->pii, p_ri );
- if ( rc != MBG_SUCCESS )
- goto error;
-
- rc = mbg_get_gps_all_str_type_info( dh, pcfg->stii, p_ri );
- if ( rc != MBG_SUCCESS )
- goto error;
- }
- else
- {
- if ( _pcps_is_gps( pdev ) )
- {
- rc = mbg_get_gps_port_parm( dh, &pcfg->tmp_pp );
- if ( rc != MBG_SUCCESS )
- goto error;
-
- for ( i = 0; i < p_ri->n_com_ports; i++ )
- {
- PORT_INFO_IDX *p_pii = &pcfg->pii[i];
- PORT_INFO *p_pi = &p_pii->port_info;
-
- p_pii->idx = i;
- port_settings_from_port_parm( &p_pi->port_settings,
- i, &pcfg->tmp_pp, 1 );
-
- p_pi->supp_baud_rates = DEFAULT_GPS_BAUD_RATES_C166;
- p_pi->supp_framings = DEFAULT_GPS_FRAMINGS_C166;
- p_pi->supp_str_types = DEFAULT_SUPP_STR_TYPES_GPS;
- }
- }
- else
- if ( _pcps_has_serial ( pdev ) ) // Not all non-GPS clocks have a serial port!
- {
- PCPS_SERIAL ser_code;
-
- rc = mbg_get_serial( dh, &ser_code );
- if ( rc != MBG_SUCCESS )
- goto error;
-
-
- port_info_from_pcps_serial( pcfg->pii, ser_code,
- _pcps_has_serial_hs( pdev ) ?
- DEFAULT_BAUD_RATES_DCF_HS :
- DEFAULT_BAUD_RATES_DCF
- );
- }
-
- for ( i = 0; i < p_ri->n_str_type; i++ )
- {
- STR_TYPE_INFO_IDX *stip = &pcfg->stii[i];
- stip->idx = i;
- stip->str_type_info = default_str_type_info[i];
- }
- }
-
- return MBG_SUCCESS;
-
-
-error:
- return rc;
-
-} // mbg_get_serial_settings
-
-
-
-/*HDR*/
-/**
- Write the configuration settings for a single serial port to the board.
-
- Modifications to the serial port configuration should be made only
- after mbg_get_serial_settings() had been called to read all serial port
- settings and supported configuration parameters.
- This function has finally to be called once for every serial port
- the configuration of which has been modified.
-
- As also required by mbg_get_serial_settings(), the functions
- mbg_get_device_info() and mbg_setup_receiver_info() must have been
- called before, and the returned ::PCPS_DEV and ::RECEIVER_INFO structures
- must be passed to this function.
-
- @param dh Valid handle to a Meinberg device
- @param *pdev Pointer to a ::PCPS_DEV structure
- @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
- @param port_num Index of the ::serial port to be saved
-
- @return ::MBG_SUCCESS or error code returned by device I/O control function.
-
- @see mbg_get_serial_settings()
- @see mbg_get_device_info()
- @see mbg_setup_receiver_info()
-*/
-_MBG_API_ATTR int _MBG_API mbg_save_serial_settings( MBG_DEV_HANDLE dh,
- const PCPS_DEV *pdev,
- RECEIVER_PORT_CFG *pcfg,
- int port_num )
-{
- int rc;
-
- if ( _pcps_has_receiver_info( pdev ) )
- {
- rc = mbg_set_gps_port_settings( dh, &pcfg->pii[port_num].port_info.port_settings, port_num );
- }
- else
- {
- if ( _pcps_is_gps( pdev ) )
- {
- port_parm_from_port_settings( &pcfg->tmp_pp, port_num,
- &pcfg->pii[port_num].port_info.port_settings, 1 );
-
- rc = mbg_set_gps_port_parm( dh, &pcfg->tmp_pp );
- }
- else
- {
- PCPS_SERIAL ser_code;
-
- pcps_serial_from_port_info( &ser_code, pcfg->pii );
-
- rc = mbg_set_serial( dh, &ser_code );
- }
- }
-
- return rc;
-
-} // mbg_save_serial_settings
-
-#endif // !MBGDEVIO_SIMPLE
-
-
-
/*HDR*/
/**
Read the version code of the on-board PCI/PCIe interface ASIC.
@@ -3594,7 +3261,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_asic_version( MBG_DEV_HANDLE dh, PCI_ASIC_VER
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCI_ASIC_VERSION, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCI_ASIC_VERSION, p );
return _mbgdevio_ret_val;
#else
if ( !_pcps_ddev_has_asic_version( dh ) )
@@ -3629,7 +3296,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_asic_features( MBG_DEV_HANDLE dh,
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_PCI_ASIC_FEATURES, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_PCI_ASIC_FEATURES, p );
return _mbgdevio_ret_val;
#else
if ( !_pcps_ddev_has_asic_features( dh ) )
@@ -3871,7 +3538,7 @@ _MBG_API_ATTR int _MBG_API mbg_set_utc_parm( MBG_DEV_HANDLE dh, UTC *p )
_MBG_API_ATTR int _MBG_API mbg_get_time_cycles( MBG_DEV_HANDLE dh, PCPS_TIME_CYCLES *p )
{
_mbgdevio_vars();
- _mbgdevio_read_var( dh, PCPS_GIVE_TIME, IOCTL_GET_PCPS_TIME_CYCLES, p );
+ rc = _mbgdevio_read_var( dh, PCPS_GIVE_TIME, IOCTL_GET_PCPS_TIME_CYCLES, p );
// No endianess conversion required.
#if !defined( _MBGIOCTL_H )
// only if not using IOCTLs
@@ -4218,7 +3885,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_fast_hr_timestamp_cycles( MBG_DEV_HANDLE dh,
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES, p );
// native endianess, no need to swap bytes
return _mbgdevio_ret_val;
#else
@@ -4296,7 +3963,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_fast_hr_timestamp( MBG_DEV_HANDLE dh,
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_FAST_HR_TIMESTAMP, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_FAST_HR_TIMESTAMP, p );
// native endianess, no need to swap bytes
return _mbgdevio_ret_val;
#else
@@ -4920,8 +4587,8 @@ _MBG_API_ATTR int _MBG_API mbg_get_gps_all_pout_info( MBG_DEV_HANDLE dh,
// has been read from a device which really supports it, or
// a dummy structure has been setup.
if ( p_ri && ( p_ri->model_code != GPS_MODEL_UNKNOWN ) )
- _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_POUT_INFO, pii,
- p_ri->n_prg_out * sizeof( pii[0] ) );
+ rc = _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_POUT_INFO, pii,
+ p_ri->n_prg_out * sizeof( pii[0] ) );
else
return _mbg_err_to_os( MBG_ERR_NOT_SUPP_BY_DEV );
#endif
@@ -5029,7 +4696,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_irq_stat_info( MBG_DEV_HANDLE dh, PCPS_IRQ_ST
{
#if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_IRQ_STAT_INFO, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_IRQ_STAT_INFO, p );
// native endianess, no need to swap bytes
return _mbgdevio_ret_val;
#else
@@ -5377,8 +5044,8 @@ _MBG_API_ATTR int _MBG_API mbg_get_all_ptp_uc_master_info( MBG_DEV_HANDLE dh,
_pcps_ddev_has_ptp_unicast( dh ) );
#else
if ( p_umsl && p_umsl->n_supp_master )
- _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_PTP_UC_MASTER_INFO, pii,
- p_umsl->n_supp_master * sizeof( pii[0] ) );
+ rc = _mbgdevio_gen_read_gps( dh, PC_GPS_ALL_PTP_UC_MASTER_INFO, pii,
+ p_umsl->n_supp_master * sizeof( pii[0] ) );
else
return _mbg_err_to_os( MBG_ERR_NOT_SUPP_BY_DEV );
#endif
@@ -5509,6 +5176,158 @@ _MBG_API_ATTR int _MBG_API mbg_get_time_info_tstamp( MBG_DEV_HANDLE dh, MBG_TIME
/*HDR*/
/**
+ Check if a specific device supports demodulation of the DCF77 PZF code.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_corr_info()
+ @see mbg_dev_has_tr_distance()
+*/
+_MBG_API_ATTR int _MBG_API mbg_dev_has_pzf( MBG_DEV_HANDLE dh, int *p )
+{
+ _mbgdevio_query_cond( dh, _pcps_ddev_has_pzf, IOCTL_DEV_HAS_PZF, p );
+
+} // mbg_dev_has_pzf
+
+
+
+/*HDR*/
+/**
+ Check if a specific device supports reading correlation info.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_get_corr_info()
+*/
+_MBG_API_ATTR int _MBG_API mbg_dev_has_corr_info( MBG_DEV_HANDLE dh, int *p )
+{
+ _mbgdevio_query_cond( dh, _pcps_ddev_has_corr_info, IOCTL_DEV_HAS_CORR_INFO, p );
+
+} // mbg_dev_has_corr_info
+
+
+
+/*HDR*/
+/**
+ Check if a specific device supports configurable distance from transmitter
+ used to compensate RF propagation delay.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_get_tr_distance()
+ @see mbg_set_tr_distance()
+*/
+_MBG_API_ATTR int _MBG_API mbg_dev_has_tr_distance( MBG_DEV_HANDLE dh, int *p )
+{
+ _mbgdevio_query_cond( dh, _pcps_ddev_has_tr_distance, IOCTL_DEV_HAS_TR_DISTANCE, p );
+
+} // mbg_dev_has_tr_distance
+
+
+
+/*HDR*/
+/**
+ Read PZF correlation info from a card which supports this.
+ The macro _pcps_has_corr_info() or the API call mbg_dev_has_corr_info()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::CORR_INFO variable to be filled up
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_corr_info()
+ */
+_MBG_API_ATTR int _MBG_API mbg_get_corr_info( MBG_DEV_HANDLE dh, CORR_INFO *p )
+{
+ _mbgdevio_vars();
+ _mbgdevio_read_var_chk( dh, PCPS_GET_CORR_INFO,
+ IOCTL_GET_CORR_INFO, p,
+ _pcps_ddev_has_corr_info( dh ) );
+ _mbg_swab_corr_info( p );
+ return _mbgdevio_ret_val;
+
+} // mbg_get_corr_info
+
+
+
+/*HDR*/
+/**
+ Read configurable "distance from transmitter" parameter from a card
+ which supports this. The parameter is used to compensate the RF signal
+ propagation delay.
+ The macro _pcps_has_tr_distance() or the API call mbg_dev_has_tr_distance()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::TR_DISTANCE variable to be filled up
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_tr_distance()
+ @see mbg_set_tr_distance()
+ */
+_MBG_API_ATTR int _MBG_API mbg_get_tr_distance( MBG_DEV_HANDLE dh, TR_DISTANCE *p )
+{
+ _mbgdevio_vars();
+ _mbgdevio_read_var_chk( dh, PCPS_GET_TR_DISTANCE,
+ IOCTL_GET_TR_DISTANCE, p,
+ _pcps_ddev_has_tr_distance( dh ) );
+ _mbg_swab_tr_distance( p );
+ return _mbgdevio_ret_val;
+
+} // mbg_get_tr_distance
+
+
+
+/*HDR*/
+/**
+ Write configurable "distance from transmitter" parameter to a card
+ which supports this. The parameter is used to compensate the RF signal
+ propagation delay.
+ The macro _pcps_has_tr_distance() or the API call mbg_dev_has_tr_distance()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::TR_DISTANCE variable to be written
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_tr_distance()
+ @see mbg_get_tr_distance()
+ */
+_MBG_API_ATTR int _MBG_API mbg_set_tr_distance( MBG_DEV_HANDLE dh, const TR_DISTANCE *p )
+{
+ _mbgdevio_vars();
+ #if defined( MBG_ARCH_BIG_ENDIAN )
+ TR_DISTANCE tmp = *p;
+ _mbg_swab_tr_distance( &tmp );
+ p = &tmp;
+ #endif
+ _mbgdevio_write_var_chk( dh, PCPS_SET_TR_DISTANCE, IOCTL_SET_TR_DISTANCE,
+ p, _pcps_ddev_has_tr_distance( dh ) );
+ return _mbgdevio_ret_val;
+
+} // mbg_set_tr_distance
+
+
+
+/*HDR*/
+/**
Read the CPU affinity of a process, i.e. on which of the available
CPUs the process can be executed.
@@ -6125,9 +5944,9 @@ _MBG_API_ATTR int _MBG_API mbg_get_xhrt_cycles_frequency( MBG_XHRT_INFO *p, MBG_
*/
_MBG_API_ATTR int _MBG_API mbg_get_default_cycles_frequency_from_dev( MBG_DEV_HANDLE dh, MBG_PC_CYCLES_FREQUENCY *p )
{
- #if defined( _MBGIOCTL_H ) && defined( MBG_PC_CYCLES_SUPPORTED )
+ #if defined( _MBGIOCTL_H )
_mbgdevio_vars();
- _mbgdevio_read_var( dh, -1, IOCTL_GET_CYCLES_FREQUENCY, p );
+ rc = _mbgdevio_read_var( dh, -1, IOCTL_GET_CYCLES_FREQUENCY, p );
// native endianess, no need to swap bytes
if ( rc != MBG_SUCCESS )
*p = 0;
@@ -6142,7 +5961,7 @@ _MBG_API_ATTR int _MBG_API mbg_get_default_cycles_frequency_from_dev( MBG_DEV_HA
if ( rc != MBG_SUCCESS )
goto done;
- if ( ( rc == MBG_SUCCESS ) && has_hr_time )
+ if ( has_hr_time )
{
PCPS_HR_TIME_CYCLES htc1;
PCPS_HR_TIME_CYCLES htc2;
diff --git a/mbglib/common/mbgdevio.h b/mbglib/common/mbgdevio.h
index 568c7c4..e192114 100755
--- a/mbglib/common/mbgdevio.h
+++ b/mbglib/common/mbgdevio.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgdevio.h 1.39.1.15.1.4 2011/04/19 15:05:47 martin TRASH martin $
+ * $Id: mbgdevio.h 1.39.1.21 2011/09/26 14:03:21 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,14 +10,24 @@
*
* -----------------------------------------------------------------------
* $Log: mbgdevio.h $
- * Revision 1.39.1.15.1.4 2011/04/19 15:05:47 martin
- * PTP unicast cfg stuff ...
- * Revision 1.39.1.15.1.3 2011/04/19 13:08:36 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.39.1.15.1.2 2011/04/19 10:00:08 martin
- * More PTP unicast cfg ...
- * Revision 1.39.1.15.1.1 2011/04/18 15:30:52 martin
- * Started PTP unicast
+ * Revision 1.39.1.21 2011/09/26 14:03:21 martin
+ * Workaround to make mbgmon (BC) build under Windows.
+ * See diff for details.
+ * Cleaned up CPU set support under Linux.
+ * Updated function prototypes.
+ * Revision 1.39.1.20 2011/07/20 15:52:22Z martin
+ * Conditionally use older IOCTL request buffer structures.
+ * Moved some macros here so they can be used by other modules.
+ * Modified some macros and definitions.
+ * Revision 1.39.1.19 2011/07/19 15:46:39 martin
+ * Revision 1.39.1.18 2011/07/06 11:19:24 martin
+ * Support reading CORR_INFO, and reading/writing TR_DISTANCE.
+ * Revision 1.39.1.17 2011/06/29 11:10:19 martin
+ * Updated function prototypes.
+ * Revision 1.39.1.16 2011/06/22 10:16:22 martin
+ * Cleaned up handling of pragma pack().
+ * Cleaned up inclusion of header files.
+ * Updated function prototypes.
* Revision 1.39.1.15 2011/04/12 12:57:53 martin
* Moved mutex definitions to new mbgmutex.h.
* Renamed mutex stuff to critical sections.
@@ -187,7 +197,6 @@
#include <mbgerror.h>
#include <mbggeo.h>
#include <pcpsdev.h>
-#include <pcpsutil.h>
#include <pci_asic.h>
#include <use_pack.h>
#include <time.h>
@@ -216,6 +225,9 @@
#define MBG_USE_KERNEL_DRIVER 1
#include <windows.h>
+ #define MBGDEVIO_RET_VAL DWORD
+ #define _mbgdevio_cnv_ret_val( _v ) (_v)
+
#elif defined( MBG_TGT_LINUX )
#if !defined( MBGDEVIO_XHRT_API )
@@ -230,11 +242,18 @@
// as per default.
#define MBG_USE_KERNEL_DRIVER 1
+ #include <sys/ioctl.h>
#include <fcntl.h>
+ #include <sched.h>
+
+ #if MBGDEVIO_USE_THREAD_API
+ #include <pthread.h>
+ #endif
#elif defined( MBG_TGT_BSD )
#define MBG_USE_KERNEL_DRIVER 1
+ #include <sys/ioctl.h>
#include <fcntl.h>
#elif defined( MBG_TGT_OS2 )
@@ -256,6 +275,16 @@
#endif
+#if defined( MBG_USE_KERNEL_DRIVER )
+
+ #include <mbgioctl.h>
+
+ #include <stdlib.h>
+ #include <string.h>
+
+#endif
+
+
#if !defined( MBGDEVIO_XHRT_API )
#define MBGDEVIO_XHRT_API 0
#endif
@@ -277,8 +306,9 @@
/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
#endif
@@ -306,6 +336,24 @@
#endif
+#if !defined( MBGDEVIO_RET_VAL )
+ #define MBGDEVIO_RET_VAL int
+#endif
+
+
+#if !defined( _mbgdevio_cnv_ret_val )
+ #define _mbgdevio_cnv_ret_val( _v ) \
+ ( ( (_v) < 0 ) ? (_v) : MBG_SUCCESS )
+#endif
+
+
+#define _mbgdevio_vars() \
+ MBGDEVIO_RET_VAL rc
+
+#define _mbgdevio_ret_val \
+ _mbgdevio_cnv_ret_val( rc )
+
+
/**
The type below is used to store a unique ID for a device which
@@ -316,29 +364,25 @@ typedef char MBG_HW_NAME[PCPS_CLOCK_NAME_SZ + PCPS_SN_SIZE + 1];
-#if defined( MBG_TGT_LINUX ) && !defined( MBG_ARCH_ARM )
-
- #include <sched.h>
+#if defined( MBG_TGT_LINUX )
#define MBG_PROCESS_ID pid_t
#define _mbg_get_current_process() 0
- #define MBG_CPU_SET cpu_set_t
- #define MBG_CPU_SET_SIZE CPU_SETSIZE
- #define _mbg_cpu_clear( _ps ) CPU_ZERO( (_ps) )
- #define _mbg_cpu_set( _i, _ps ) CPU_SET( (_i), (_ps) )
- #define _mbg_cpu_isset( _i, _ps ) CPU_ISSET( (_i), (_ps) )
+ #if defined( __cpu_set_t_defined )
+ #define MBG_CPU_SET cpu_set_t
+ #define MBG_CPU_SET_SIZE CPU_SETSIZE
+ #define _mbg_cpu_clear( _ps ) CPU_ZERO( (_ps) )
+ #define _mbg_cpu_set( _i, _ps ) CPU_SET( (_i), (_ps) )
+ #define _mbg_cpu_isset( _i, _ps ) CPU_ISSET( (_i), (_ps) )
+ #endif
#if MBGDEVIO_USE_THREAD_API
-
- #include <pthread.h>
-
- #define MBG_THREAD_ID pthread_t
- #define _mbg_get_current_thread() 0
- #define MBG_THREAD_FNC_ATTR // empty
- #define MBG_THREAD_FNC_RET_VAL void *
- #define _mbg_thread_exit( _v ) return (void *) (_v)
-
+ #define MBG_THREAD_ID pthread_t
+ #define _mbg_get_current_thread() 0
+ #define MBG_THREAD_FNC_ATTR // empty
+ #define MBG_THREAD_FNC_RET_VAL void *
+ #define _mbg_thread_exit( _v ) return (void *) (_v)
#endif
#elif defined( MBG_TGT_WIN32 )
@@ -484,20 +528,6 @@ typedef struct _MBG_DEVICENAME_LIST
-#define _mbg_generic_read_var( _dh, _cmd, _s ) \
- mbg_generic_read( _dh, _cmd, &(_s), sizeof( (_s) ) )
-
-#define _mbg_generic_write_var( _dh, _cmd, _s ) \
- mbg_generic_write( _dh, _cmd, &(_s), sizeof( (_s) ) )
-
-#define _mbg_generic_read_gps_var( _dh, _cmd, _s ) \
- mbg_generic_read_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
-
-#define _mbg_generic_write_gps_var( _dh, _cmd, _s ) \
- mbg_generic_write_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
-
-
-
/* function prototypes: */
#ifdef __cplusplus
@@ -1157,7 +1187,7 @@ extern "C" {
@see mbg_get_raw_irig_data()
@see mbg_get_raw_irig_data_on_sec_change()
*/
- _MBG_API_ATTR int _MBG_API mbg_dev_has_raw_irig_data( MBG_DEV_HANDLE dh, int *p) ;
+ _MBG_API_ATTR int _MBG_API mbg_dev_has_raw_irig_data( MBG_DEV_HANDLE dh, int *p ) ;
/**
Read a ::MBG_RAW_IRIG_DATA type which contains all data
@@ -1633,7 +1663,47 @@ extern "C" {
_MBG_API_ATTR int _MBG_API mbg_get_gps_receiver_info( MBG_DEV_HANDLE dh, RECEIVER_INFO *p ) ;
/**
- Write the configuration for a single serial port using the ::PORT_SETTINGS_IDX
+ Read a ::STR_TYPE_INFO_IDX array of supported string types.
+ The function mbg_setup_receiver_info() must have been called before,
+ and the returned ::RECEIVER_INFO structure passed to this function.
+
+ <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
+ to get retrieve the current port settings and configuration options.
+
+ @param dh Valid handle to a Meinberg device.
+ @param stii Pointer to a an array of string type information to be filled up
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure returned by mbg_setup_receiver_info()
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_setup_receiver_info()
+ @see mbg_get_gps_all_port_info()
+ @see mbg_get_serial_settings()
+*/
+ _MBG_API_ATTR int _MBG_API mbg_get_gps_all_str_type_info( MBG_DEV_HANDLE dh, STR_TYPE_INFO_IDX stii[], const RECEIVER_INFO *p_ri ) ;
+
+ /**
+ Read a ::PORT_INFO_IDX array of supported serial port configurations.
+ The function mbg_setup_receiver_info() must have been called before,
+ and the returned ::RECEIVER_INFO structure passed to this function.
+
+ <b>Note:</b> The function mbg_get_serial_settings() should be used preferably
+ to get retrieve the current port settings and configuration options.
+
+ @param dh Valid handle to a Meinberg device.
+ @param pii Pointer to a an array of port configuration information to be filled up
+ @param *p_ri Pointer to a ::RECEIVER_INFO structure returned by mbg_setup_receiver_info()
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_setup_receiver_info()
+ @see mbg_get_gps_all_str_type_info()
+ @see mbg_get_serial_settings()
+*/
+ _MBG_API_ATTR int _MBG_API mbg_get_gps_all_port_info( MBG_DEV_HANDLE dh, PORT_INFO_IDX pii[], const RECEIVER_INFO *p_ri ) ;
+
+ /**
+ Write the configuration for a single serial port using the ::PORT_SETTINGS_IDX
structure which contains both the ::PORT_SETTINGS and the port index value.
Except for the parameter types, this call is equivalent to mbg_set_gps_port_settings().
The macro _pcps_has_receiver_info() or the API call mbg_dev_has_receiver_info()
@@ -1695,56 +1765,6 @@ extern "C" {
_MBG_API_ATTR int _MBG_API mbg_setup_receiver_info( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, RECEIVER_INFO *p ) ;
/**
- Read all serial port settings and supported configuration parameters.
-
- The functions mbg_get_device_info() and mbg_setup_receiver_info()
- must have been called before, and the returned ::PCPS_DEV and
- ::RECEIVER_INFO structures must be passed to this function.
-
- The complementary function mbg_save_serial_settings() should be used
- to write the modified serial port configuration back to the board.
-
- @param dh Valid handle to a Meinberg device.
- @param *pdev Pointer to a ::PCPS_DEV structure.
- @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure to be filled up.
- @param *p_ri Pointer to a ::RECEIVER_INFO structure.
-
- @return ::MBG_SUCCESS or error code returned by device I/O control function.
-
- @see mbg_get_device_info()
- @see mbg_setup_receiver_info()
- @see mbg_save_serial_settings()
-*/
- _MBG_API_ATTR int _MBG_API mbg_get_serial_settings( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, RECEIVER_PORT_CFG *pcfg, const RECEIVER_INFO *p_ri ) ;
-
- /**
- Write the configuration settings for a single serial port to the board.
-
- Modifications to the serial port configuration should be made only
- after mbg_get_serial_settings() had been called to read all serial port
- settings and supported configuration parameters.
- This function has finally to be called once for every serial port
- the configuration of which has been modified.
-
- As also required by mbg_get_serial_settings(), the functions
- mbg_get_device_info() and mbg_setup_receiver_info() must have been
- called before, and the returned ::PCPS_DEV and ::RECEIVER_INFO structures
- must be passed to this function.
-
- @param dh Valid handle to a Meinberg device
- @param *pdev Pointer to a ::PCPS_DEV structure
- @param *pcfg Pointer to a ::RECEIVER_PORT_CFG structure
- @param port_num Index of the ::serial port to be saved
-
- @return ::MBG_SUCCESS or error code returned by device I/O control function.
-
- @see mbg_get_serial_settings()
- @see mbg_get_device_info()
- @see mbg_setup_receiver_info()
-*/
- _MBG_API_ATTR int _MBG_API mbg_save_serial_settings( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, RECEIVER_PORT_CFG *pcfg, int port_num ) ;
-
- /**
Read the version code of the on-board PCI/PCIe interface ASIC.
The macro _pcps_has_asic_version() or the API call mbg_dev_has_asic_version()
check whether this call is supported by a specific card.
@@ -2846,6 +2866,98 @@ extern "C" {
_MBG_API_ATTR int _MBG_API mbg_get_time_info_tstamp( MBG_DEV_HANDLE dh, MBG_TIME_INFO_TSTAMP *p ) ;
/**
+ Check if a specific device supports demodulation of the DCF77 PZF code.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_corr_info()
+ @see mbg_dev_has_tr_distance()
+*/
+ _MBG_API_ATTR int _MBG_API mbg_dev_has_pzf( MBG_DEV_HANDLE dh, int *p ) ;
+
+ /**
+ Check if a specific device supports reading correlation info.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_get_corr_info()
+*/
+ _MBG_API_ATTR int _MBG_API mbg_dev_has_corr_info( MBG_DEV_HANDLE dh, int *p ) ;
+
+ /**
+ Check if a specific device supports configurable distance from transmitter
+ used to compensate RF propagation delay.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to an int which is set 0 or != 0 unless the call fails.
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_get_tr_distance()
+ @see mbg_set_tr_distance()
+*/
+ _MBG_API_ATTR int _MBG_API mbg_dev_has_tr_distance( MBG_DEV_HANDLE dh, int *p ) ;
+
+ /**
+ Read PZF correlation info from a card which supports this.
+ The macro _pcps_has_corr_info() or the API call mbg_dev_has_corr_info()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::CORR_INFO variable to be filled up
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_corr_info()
+ */
+ _MBG_API_ATTR int _MBG_API mbg_get_corr_info( MBG_DEV_HANDLE dh, CORR_INFO *p ) ;
+
+ /**
+ Read configurable "distance from transmitter" parameter from a card
+ which supports this. The parameter is used to compensate the RF signal
+ propagation delay.
+ The macro _pcps_has_tr_distance() or the API call mbg_dev_has_tr_distance()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::TR_DISTANCE variable to be filled up
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_tr_distance()
+ @see mbg_set_tr_distance()
+ */
+ _MBG_API_ATTR int _MBG_API mbg_get_tr_distance( MBG_DEV_HANDLE dh, TR_DISTANCE *p ) ;
+
+ /**
+ Write configurable "distance from transmitter" parameter to a card
+ which supports this. The parameter is used to compensate the RF signal
+ propagation delay.
+ The macro _pcps_has_tr_distance() or the API call mbg_dev_has_tr_distance()
+ check whether this call is supported by a specific card.
+
+ @param dh Valid handle to a Meinberg device
+ @param *p Pointer to a ::TR_DISTANCE variable to be written
+
+ @return ::MBG_SUCCESS or error code returned by device I/O control function.
+
+ @see mbg_dev_has_pzf()
+ @see mbg_dev_has_tr_distance()
+ @see mbg_get_tr_distance()
+ */
+ _MBG_API_ATTR int _MBG_API mbg_set_tr_distance( MBG_DEV_HANDLE dh, const TR_DISTANCE *p ) ;
+
+ /**
Read the CPU affinity of a process, i.e. on which of the available
CPUs the process can be executed.
@@ -3081,6 +3193,243 @@ extern "C" {
#endif
+#if defined( MBG_TGT_WIN32 )
+
+static __mbg_inline
+MBGDEVIO_RET_VAL do_mbg_ioctl( MBG_DEV_HANDLE dh, int ioctl_code,
+ const void *in_p, int in_sz, void *out_p, int out_sz )
+{
+ DWORD ReturnedLength;
+
+ if ( !DeviceIoControl( dh, ioctl_code,
+ (LPVOID) in_p, in_sz, out_p, out_sz,
+ &ReturnedLength,
+ NULL
+ ) )
+ {
+ DWORD rc = GetLastError();
+
+#if 0 //##++++++++++++++++++++++++
+// We can't call mbgsvctl_log_mbgdevio_error() here (for now).
+// Is is defined in mbgsvctl.h, and including mbgsvc.h here,
+// or copying the prototype here results in DLL import/export
+// mismatch errors.
+
+ // do not report a USB device timeout error
+ if ( rc != _mbg_err_to_os( MBG_ERR_USB_ACCESS ) )
+ mbgsvctl_log_mbgdevio_error( ioctl_code, rc );
+#endif
+
+ return rc;
+ }
+
+ return MBG_SUCCESS;
+
+} // do_mbg_ioctl
+
+ #define _do_mbg_ioctl( _dh, _ioctl, _p, _in_sz, _out_sz ) \
+ do_mbg_ioctl( _dh, _ioctl, (LPVOID) _p, _in_sz, (LPVOID) _p, _out_sz )
+
+#elif defined( MBG_TGT_UNIX )
+
+ #define _do_mbg_ioctl( _dh, _ioctl, _p, _in_sz, _out_sz ) \
+ ioctl( _dh, _ioctl, _p )
+
+#endif
+
+
+
+// The code below depends on whether the target device is accessed via
+// IOCTLs to a device driver, or the hardware is accessed directly.
+
+#if defined( _MBGIOCTL_H ) // using IOCTL to access device driver
+
+ static __mbg_inline
+ int mbgdevio_do_gen_io( MBG_DEV_HANDLE dh, int info, unsigned int ioctl_code,
+ const void *in_p, int in_sz,
+ void *out_p, int out_sz )
+ {
+ _mbgdevio_vars();
+
+ #if _MBG_SUPP_VAR_ACC_SIZE
+ info; // avoid "unused" warning
+
+ rc = do_mbg_ioctl( dh, ioctl_code, in_p, in_sz, out_p, out_sz ); //##++++ in_p / out_p vs. _do_mbg_ioctl()
+
+ #elif USE_IOCTL_GENERIC_REQ
+
+ IOCTL_GENERIC_REQ req = { 0 };
+
+ req.info = info;
+ req.in_p = in_p;
+ req.in_sz = in_sz;
+ req.out_p = out_p;
+ req.out_sz = out_sz;
+
+ rc = _do_mbg_ioctl( dh, ioctl_code, &req, sizeof( req ), 0 );
+
+ #else
+
+ IOCTL_GENERIC_BUFFER *p_buff;
+ int buff_size = sizeof( p_buff->ctl )
+ + ( ( in_sz > out_sz ) ? in_sz : out_sz );
+
+ p_buff = (IOCTL_GENERIC_BUFFER *) malloc( buff_size );
+
+ if ( p_buff == NULL )
+ return _mbg_err_to_os( MBG_ERR_NO_MEM );
+
+ p_buff->ctl.info = info;
+ p_buff->ctl.data_size_in = in_sz;
+ p_buff->ctl.data_size_out = out_sz;
+
+ if ( in_p )
+ memcpy( p_buff->data, in_p, in_sz );
+
+ rc = _do_mbg_ioctl( dh, ioctl_code, p_buff,
+ sizeof( IOCTL_GENERIC_CTL ) + in_sz,
+ sizeof( IOCTL_GENERIC_CTL ) + out_sz );
+
+ if ( out_p && ( rc == MBG_SUCCESS ) )
+ memcpy( out_p, p_buff->data, out_sz );
+
+ free( p_buff );
+
+ #endif
+
+ return _mbgdevio_ret_val;
+
+ } // mbgdevio_do_gen_io
+
+
+
+ #define _do_mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ) \
+ _do_mbg_ioctl( _dh, _ioctl, _p, 0, _sz )
+
+ #define _do_mbgdevio_write( _dh, _cmd, _ioctl, _p, _sz ) \
+ _do_mbg_ioctl( _dh, _ioctl, _p, _sz, 0 )
+
+ #define _do_mbgdevio_read_gps _do_mbgdevio_read
+
+ #define _do_mbgdevio_write_gps _do_mbgdevio_write
+
+
+
+ #define _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ) \
+ _do_mbgdevio_read( _dh, _cmd, _ioctl, _p, sizeof( *(_p) ) )
+
+ #define _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ) \
+ _do_mbgdevio_write( _dh, _cmd, _ioctl, _p, sizeof( *(_p) ) )
+
+ #define _mbgdevio_write_cmd( _dh, _cmd, _ioctl ) \
+ _do_mbgdevio_write( _dh, _cmd, _ioctl, NULL, 0 )
+
+ #define _mbgdevio_read_gps_var _mbgdevio_read_var
+
+ #define _mbgdevio_write_gps_var _mbgdevio_write_var
+
+
+ #define _mbgdevio_gen_read( _dh, _cmd, _p, _sz ) \
+ mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_READ, NULL, 0, _p, _sz )
+
+ #define _mbgdevio_gen_write( _dh, _cmd, _p, _sz ) \
+ mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_WRITE, _p, _sz, NULL, 0 )
+
+ #define _mbgdevio_gen_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz ) \
+ mbgdevio_do_gen_io( _dh, _type, IOCTL_PCPS_GENERIC_IO, _in_p, _in_sz, _out_p, _out_sz )
+
+ #define _mbgdevio_gen_read_gps( _dh, _cmd, _p, _sz ) \
+ mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_READ_GPS, NULL, 0, _p, _sz )
+
+ #define _mbgdevio_gen_write_gps( _dh, _cmd, _p, _sz ) \
+ mbgdevio_do_gen_io( _dh, _cmd, IOCTL_PCPS_GENERIC_WRITE_GPS, _p, _sz, NULL, 0 )
+
+
+#else // accessing hardware device directly
+
+ #define _mbgdevio_chk_cond( _cond ) \
+ { \
+ if ( !(_cond) ) \
+ return _mbg_err_to_os( MBG_ERR_NOT_SUPP_BY_DEV ); \
+ }
+
+ #define _mbgdevio_read( _dh, _cmd, _ioctl, _p, _sz ) \
+ pcps_read_safe( _dh, _cmd, _p, _sz )
+
+ #define _mbgdevio_write( _dh, _cmd, _ioctl, _p, _sz ) \
+ pcps_write_safe( _dh, _cmd, _p, _sz )
+
+ #define _do_mbgdevio_read_gps( _dh, _cmd, _ioctl, _p, _sz ) \
+ pcps_read_gps_safe( _dh, _cmd, _p, _sz )
+
+ #define _mbgdevio_write_gps( _dh, _cmd, _ioctl, _p, _sz ) \
+ pcps_write_gps_safe( _dh, _cmd, _p, _sz )
+
+
+
+//##+++++++++++++++++++
+ #define _mbgdevio_read_var( _dh, _cmd, _ioctl, _p ) \
+ _pcps_read_var_safe( _dh, _cmd, *(_p) )
+
+ #define _mbgdevio_write_var( _dh, _cmd, _ioctl, _p ) \
+ _pcps_write_var_safe( _dh, _cmd, *(_p) )
+
+ #define _mbgdevio_write_cmd( _dh, _cmd, _ioctl ) \
+ _pcps_write_byte_safe( _dh, _cmd );
+
+ #define _mbgdevio_read_gps_var( _dh, _cmd, _ioctl, _p ) \
+ _pcps_read_gps_var_safe( _dh, _cmd, *(_p) )
+
+ #define _mbgdevio_write_gps_var( _dh, _cmd, _ioctl, _p ) \
+ _pcps_write_gps_var_safe( _dh, _cmd, *(_p) )
+
+
+ #define _mbgdevio_gen_read( _dh, _cmd, _p, _sz ) \
+ _mbgdevio_read( _dh, _cmd, -1, _p, _sz )
+
+ #define _mbgdevio_gen_write( _dh, _cmd, _p, _sz ) \
+ _mbgdevio_write( _dh, _cmd, -1, _p, _sz )
+
+ #define _mbgdevio_gen_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz ) \
+ pcps_generic_io( _dh, _type, _in_p, _in_sz, _out_p, _out_sz );
+
+ #define _mbgdevio_gen_read_gps( _dh, _cmd, _p, _sz ) \
+ _do_mbgdevio_read_gps( _dh, _cmd, -1, _p, _sz )
+
+ #define _mbgdevio_gen_write_gps( _dh, _cmd, _p, _sz ) \
+ _mbgdevio_write_gps( _dh, _cmd, -1, _p, _sz )
+
+#endif
+
+
+
+#define _mbg_generic_read_var( _dh, _cmd, _s ) \
+ mbg_generic_read( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbg_generic_write_var( _dh, _cmd, _s ) \
+ mbg_generic_write( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbg_generic_read_gps_var( _dh, _cmd, _s ) \
+ mbg_generic_read_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbg_generic_write_gps_var( _dh, _cmd, _s ) \
+ mbg_generic_write_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+
+
+#define _mbgdevio_gen_read_var( _dh, _cmd, _s ) \
+ _mbgdevio_gen_read( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbgdevio_gen_write_var( _dh, _cmd, _s ) \
+ _mbgdevio_gen_write( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbgdevio_gen_read_gps_var( _dh, _cmd, _s ) \
+ _mbgdevio_gen_read_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+#define _mbgdevio_gen_write_gps_var( _dh, _cmd, _s ) \
+ _mbgdevio_gen_write_gps( _dh, _cmd, &(_s), sizeof( (_s) ) )
+
+
#if defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_UNIX )
@@ -3149,9 +3498,9 @@ void uint64_to_pcps_time_stamp( PCPS_TIME_STAMP *ts, uint64_t n )
#endif
-
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/mbgerror.h b/mbglib/common/mbgerror.h
index 714dd45..f6c41e4 100755
--- a/mbglib/common/mbgerror.h
+++ b/mbglib/common/mbgerror.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgerror.h 1.5.1.1 2011/04/20 16:09:19 martin TRASH martin $
+ * $Id: mbgerror.h 1.5.1.1 2011/04/20 16:09:19 martin TEST $
* $Name: $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
diff --git a/mbglib/common/mbggenio.h b/mbglib/common/mbggenio.h
index 0d6c1ef..dece56b 100755
--- a/mbglib/common/mbggenio.h
+++ b/mbglib/common/mbggenio.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbggenio.h 1.5.1.3 2011/02/09 17:08:30 martin TRASH $
+ * $Id: mbggenio.h 1.5.1.4 2011/10/05 08:57:20 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,8 @@
*
* -----------------------------------------------------------------------
* $Log: mbggenio.h $
+ * Revision 1.5.1.4 2011/10/05 08:57:20 martin
+ * Fixed includes for NetBSD.
* Revision 1.5.1.3 2011/02/09 17:08:30 martin
* Specify I/O range number when calling port I/O macros
* so they can be used for different ranges under BSD.
@@ -72,10 +74,12 @@ extern "C" {
#endif
#elif defined( MBG_TGT_BSD )
-
+ #include <sys/param.h>
#include <sys/types.h>
#include <sys/bus.h>
- #include <machine/bus.h>
+ #if !defined(__NetBSD_Version__) || __NetBSD_Version__ < 599005500
+ #include <machine/bus.h>
+ #endif
#define _mbg_inp8( _d, _i, _p ) ( (uint8_t) bus_space_read_1( ( (_d)->rsrc_info.port[_i].bsd.bst ), \
( (_d)->rsrc_info.port[_i].bsd.bsh ), (_p) ) )
diff --git a/mbglib/common/mbggeo.h b/mbglib/common/mbggeo.h
index c375570..9ffaebe 100755
--- a/mbglib/common/mbggeo.h
+++ b/mbglib/common/mbggeo.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbggeo.h 1.10 2008/09/03 14:54:28 martin REL_M $
+ * $Id: mbggeo.h 1.11 2011/06/22 10:18:10 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -22,6 +22,8 @@
*
* -----------------------------------------------------------------------
* $Log: mbggeo.h $
+ * Revision 1.11 2011/06/22 10:18:10 martin
+ * Cleaned up handling of pragma pack().
* Revision 1.10 2008/09/03 14:54:28 martin
* Added macros to swap endianess of structures.
* Revision 1.9 2008/01/17 09:31:33 daniel
@@ -62,8 +64,9 @@
/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
#endif
@@ -284,8 +287,9 @@ extern "C" {
#endif
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/mbgioctl.h b/mbglib/common/mbgioctl.h
index 1c7718e..566c846 100755
--- a/mbglib/common/mbgioctl.h
+++ b/mbglib/common/mbgioctl.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgioctl.h 1.24.1.2.1.4 2011/04/19 15:28:46 martin TRASH martin $
+ * $Id: mbgioctl.h 1.24.1.10 2011/07/20 15:49:00 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,14 +10,30 @@
*
* -----------------------------------------------------------------------
* $Log: mbgioctl.h $
- * Revision 1.24.1.2.1.4 2011/04/19 15:28:46 martin
- * Cleanup.
- * Revision 1.24.1.2.1.3 2011/04/19 15:05:48 martin
- * PTP unicast cfg stuff ...
- * Revision 1.24.1.2.1.2 2011/04/19 13:08:37 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.24.1.2.1.1 2011/04/18 15:30:59 martin
- * Started PTP unicast
+ * Revision 1.24.1.10 2011/07/20 15:49:00 martin
+ * Conditionally use older IOCTL request buffer structures.
+ * Revision 1.24.1.9 2011/07/19 12:31:59 martin
+ * Relaxed required priority level for generic read functions.
+ * Revision 1.24.1.8 2011/07/18 10:18:49 martin
+ * Revision 1.24.1.7 2011/07/15 14:50:11 martin
+ * Revision 1.24.1.6 2011/07/14 14:54:01 martin
+ * Modified generic IOCTL handling such that for calls requiring variable sizes
+ * a fixed request block containing input and output buffer pointers and sizes is
+ * passed down to the kernel driver. This simplifies implementation under *BSD
+ * and also works for other target systems.
+ * Revision 1.24.1.5 2011/07/06 11:19:28 martin
+ * Support reading CORR_INFO, and reading/writing TR_DISTANCE.
+ * Revision 1.24.1.4 2011/06/29 10:52:00 martin
+ * New code IOCTL_DEV_HAS_PZF.
+ * Revision 1.24.1.3 2011/06/21 15:03:29 martin
+ * Support PTP unicast configuration.
+ * Changed the names of a few IOCTL codes to follow general naming conventions.
+ * Added definitions to support privilege level requirements for IOCTLs.
+ * Use native alignment to avoid problems on Sparc and IA64.
+ * Added definitions to set up a table of all known
+ * IOCTL codes and names.
+ * Use MBG_TGT_KERNEL instead of _KDD_.
+ * Fixed a typo.
* Revision 1.24.1.2 2011/03/22 11:19:46 martin
* Use IOTYPE 'Z' under *BSD since this means passthrough on NetBSD.
* Revision 1.24.1.1 2011/02/15 11:21:21 daniel
@@ -113,9 +129,13 @@
/* Other headers to be included */
#include <mbg_tgt.h>
-#include <pcpsdev.h>
#include <mbggeo.h>
-#include <use_pack.h>
+#include <pcpsdev.h>
+#include <pci_asic.h>
+
+
+#define USE_DEBUG_PORT defined( MBG_ARCH_X86 )
+
#if defined( MBG_TGT_LINUX )
@@ -151,7 +171,7 @@
#define _MBG_SUPP_VAR_ACC_SIZE 1
#endif
- #ifndef _KDD_ // must be defined in the KDDs' SOURCES file
+ #if !defined( MBG_TGT_KERNEL )
#include <windows.h>
#include <winioctl.h>
#endif
@@ -209,23 +229,74 @@
#endif
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+/* Start of header body */
+
+// We must use native alignment here!
+
+
+// The structure below is used by the IOCTL_PCPS_GENERIC_... calls.
+
+#if defined( MBG_TGT_LINUX )
+ #if defined( MBG_ARCH_ARM ) || defined( MBG_ARCH_SPARC )
+ #define USE_IOCTL_GENERIC_REQ 0
+ #endif
+#endif
+
+#if !defined( USE_IOCTL_GENERIC_REQ )
+ #define USE_IOCTL_GENERIC_REQ 1
+#endif
+
+
+#if USE_IOCTL_GENERIC_REQ
+
+// This does not yet work properly under Linux/Sparc where the kernel may be 64 bit
+// while user space is 32 bit, which leads to different sizes for pointers and size_t.
+
+typedef struct
+{
+ ulong info;
+ const void *in_p;
+ size_t in_sz;
+ void *out_p;
+ size_t out_sz;
+
+} IOCTL_GENERIC_REQ;
+
+#define _MBG_IOG( _t, _n, _s ) _MBG_IOW( _t, _n, _s )
+
+#else
+
+// The structure below is used by the IOCTL_PCPS_GENERIC_... calls.
+typedef struct
+{
+ uint32_t info;
+ uint32_t data_size_in;
+ uint32_t data_size_out;
+} IOCTL_GENERIC_CTL;
+
+typedef struct
+{
+ IOCTL_GENERIC_CTL ctl;
+ uint8_t data[1];
+} IOCTL_GENERIC_BUFFER;
+
+#define _MBG_IOG( _t, _n, _s ) _MBG_IO( _t, _n )
+
#endif
-/* Start of header body */
// read general driver info, device info, and status port
#define IOCTL_GET_PCPS_DRVR_INFO _MBG_IOR( IOTYPE, 0x00, PCPS_DRVR_INFO )
#define IOCTL_GET_PCPS_DEV _MBG_IOR( IOTYPE, 0x01, PCPS_DEV )
#define IOCTL_GET_PCPS_STATUS_PORT _MBG_IOR( IOTYPE, 0x02, PCPS_STATUS_PORT )
-// generic read/write operations (preliminary)
-#define IOCTL_PCPS_GENERIC_READ _MBG_IO( IOTYPE, 0x03 )
-#define IOCTL_PCPS_GENERIC_WRITE _MBG_IO( IOTYPE, 0x04 )
-#define IOCTL_PCPS_GENERIC_READ_GPS _MBG_IO( IOTYPE, 0x05 )
-#define IOCTL_PCPS_GENERIC_WRITE_GPS _MBG_IO( IOTYPE, 0x06 )
+// Generic read/write operations. We define _MBG_IOW codes since these calls
+// eventually pass a generic request structure IOCTL_GENERIC_REQ to the driver.
+#define IOCTL_PCPS_GENERIC_READ _MBG_IOG( IOTYPE, 0x03, IOCTL_GENERIC_REQ )
+#define IOCTL_PCPS_GENERIC_WRITE _MBG_IOG( IOTYPE, 0x04, IOCTL_GENERIC_REQ )
+#define IOCTL_PCPS_GENERIC_READ_GPS _MBG_IOG( IOTYPE, 0x05, IOCTL_GENERIC_REQ )
+#define IOCTL_PCPS_GENERIC_WRITE_GPS _MBG_IOG( IOTYPE, 0x06, IOCTL_GENERIC_REQ )
// normal direct read/write operations
#define IOCTL_GET_PCPS_TIME _MBG_IOR( IOTYPE, 0x10, PCPS_TIME )
@@ -297,8 +368,8 @@
#define IOCTL_SET_GPS_ANT_CABLE_LEN _MBG_IOW( IOTYPE, 0x38, ANT_CABLE_LEN )
#define IOCTL_GET_GPS_RECEIVER_INFO _MBG_IOR( IOTYPE, 0x39, RECEIVER_INFO )
-#define IOCTL_GET_GPS_ALL_STR_TYPE_INFO _MBG_IO( IOTYPE, 0x3A ) // variable size
-#define IOCTL_GET_GPS_ALL_PORT_INFO _MBG_IO( IOTYPE, 0x3B ) // variable size
+#define IOCTL_GET_GPS_ALL_STR_TYPE_INFO _MBG_IOG( IOTYPE, 0x3A, IOCTL_GENERIC_REQ ) // variable size
+#define IOCTL_GET_GPS_ALL_PORT_INFO _MBG_IOG( IOTYPE, 0x3B, IOCTL_GENERIC_REQ ) // variable size
#define IOCTL_SET_GPS_PORT_SETTINGS_IDX _MBG_IOW( IOTYPE, 0x3C, PORT_SETTINGS_IDX )
@@ -339,11 +410,11 @@
#define IOCTL_DEV_HAS_SYNTH _MBG_IOR( IOTYPE, 0x59, int )
#define IOCTL_DEV_HAS_GENERIC_IO _MBG_IOR( IOTYPE, 0x5A, int )
-#define IOCTL_PCPS_GENERIC_IO _MBG_IO( IOTYPE, 0x5B )
+#define IOCTL_PCPS_GENERIC_IO _MBG_IOG( IOTYPE, 0x5B, IOCTL_GENERIC_REQ )
#define IOCTL_GET_SYNTH_STATE _MBG_IOR( IOTYPE, 0x5C, SYNTH_STATE )
-#define IOCTL_GET_GPS_ALL_POUT_INFO _MBG_IO( IOTYPE, 0x5D ) // variable size
+#define IOCTL_GET_GPS_ALL_POUT_INFO _MBG_IOG( IOTYPE, 0x5D, IOCTL_GENERIC_REQ ) // variable size
#define IOCTL_SET_GPS_POUT_SETTINGS_IDX _MBG_IOW( IOTYPE, 0x5E, POUT_SETTINGS_IDX )
#define IOCTL_GET_MAPPED_MEM_ADDR _MBG_IOR( IOTYPE, 0x5F, PCPS_MAPPED_MEM )
@@ -399,9 +470,15 @@
#define IOCTL_DEV_HAS_PTP_UNICAST _MBG_IOR( IOTYPE, 0x84, int )
#define IOCTL_PTP_UC_MASTER_CFG_LIMITS _MBG_IOR( IOTYPE, 0x85, PTP_UC_MASTER_CFG_LIMITS )
-#define IOCTL_GET_ALL_PTP_UC_MASTER_INFO _MBG_IO( IOTYPE, 0x86 ) // variable size
+#define IOCTL_GET_ALL_PTP_UC_MASTER_INFO _MBG_IOG( IOTYPE, 0x86, IOCTL_GENERIC_REQ ) // variable size
#define IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX _MBG_IOW( IOTYPE, 0x87, PTP_UC_MASTER_SETTINGS_IDX )
+#define IOCTL_DEV_HAS_PZF _MBG_IOR( IOTYPE, 0x88, int )
+#define IOCTL_DEV_HAS_CORR_INFO _MBG_IOR( IOTYPE, 0x89, int )
+#define IOCTL_DEV_HAS_TR_DISTANCE _MBG_IOR( IOTYPE, 0x8A, int )
+#define IOCTL_GET_CORR_INFO _MBG_IOR( IOTYPE, 0x8B, CORR_INFO )
+#define IOCTL_GET_TR_DISTANCE _MBG_IOR( IOTYPE, 0x8C, TR_DISTANCE )
+#define IOCTL_SET_TR_DISTANCE _MBG_IOW( IOTYPE, 0x8D, TR_DISTANCE )
// The codes below are subject to changes without notice. They may be supported
// by some kernel drivers, but usage is restricted to Meinberg software development.
@@ -413,11 +490,162 @@
#define IOCTL_MBG_DBG_CLR_ALL _MBG_IO( IOTYPE, 0xF4 )
+
+/**
+ * @brief An initializer for a table of IOCTL codes and associated names.
+ *
+ * This can e.g. be assigned to an array of MBG_CODE_NAME_TABLE_ENTRY elements
+ * and may be helpful when debugging.
+ */
+#define MBG_IOCTL_CODE_TABLE \
+{ \
+ { IOCTL_GET_PCPS_DRVR_INFO, "IOCTL_GET_PCPS_DRVR_INFO" }, \
+ { IOCTL_GET_PCPS_DEV, "IOCTL_GET_PCPS_DEV" }, \
+ { IOCTL_GET_PCPS_STATUS_PORT, "IOCTL_GET_PCPS_STATUS_PORT" }, \
+ { IOCTL_PCPS_GENERIC_READ, "IOCTL_PCPS_GENERIC_READ" }, \
+ { IOCTL_PCPS_GENERIC_WRITE, "IOCTL_PCPS_GENERIC_WRITE" }, \
+ { IOCTL_PCPS_GENERIC_READ_GPS, "IOCTL_PCPS_GENERIC_READ_GPS" }, \
+ { IOCTL_PCPS_GENERIC_WRITE_GPS, "IOCTL_PCPS_GENERIC_WRITE_GPS" }, \
+ { IOCTL_GET_PCPS_TIME, "IOCTL_GET_PCPS_TIME" }, \
+ { IOCTL_SET_PCPS_TIME, "IOCTL_SET_PCPS_TIME" }, \
+ { IOCTL_GET_PCPS_SYNC_TIME, "IOCTL_GET_PCPS_SYNC_TIME" }, \
+ { IOCTL_GET_PCPS_TIME_SEC_CHANGE, "IOCTL_GET_PCPS_TIME_SEC_CHANGE" }, \
+ { IOCTL_GET_PCPS_HR_TIME, "IOCTL_GET_PCPS_HR_TIME" }, \
+ { IOCTL_SET_PCPS_EVENT_TIME, "IOCTL_SET_PCPS_EVENT_TIME" }, \
+ { IOCTL_GET_PCPS_SERIAL, "IOCTL_GET_PCPS_SERIAL" }, \
+ { IOCTL_SET_PCPS_SERIAL, "IOCTL_SET_PCPS_SERIAL" }, \
+ { IOCTL_GET_PCPS_TZCODE, "IOCTL_GET_PCPS_TZCODE" }, \
+ { IOCTL_SET_PCPS_TZCODE, "IOCTL_SET_PCPS_TZCODE" }, \
+ { IOCTL_GET_PCPS_TZDL, "IOCTL_GET_PCPS_TZDL" }, \
+ { IOCTL_SET_PCPS_TZDL, "IOCTL_SET_PCPS_TZDL" }, \
+ { IOCTL_GET_REF_OFFS, "IOCTL_GET_REF_OFFS" }, \
+ { IOCTL_SET_REF_OFFS, "IOCTL_SET_REF_OFFS" }, \
+ { IOCTL_GET_MBG_OPT_INFO, "IOCTL_GET_MBG_OPT_INFO" }, \
+ { IOCTL_SET_MBG_OPT_SETTINGS, "IOCTL_SET_MBG_OPT_SETTINGS" }, \
+ { IOCTL_GET_PCPS_IRIG_RX_INFO, "IOCTL_GET_PCPS_IRIG_RX_INFO" }, \
+ { IOCTL_SET_PCPS_IRIG_RX_SETTINGS, "IOCTL_SET_PCPS_IRIG_RX_SETTINGS" }, \
+ { IOCTL_PCPS_CLR_UCAP_BUFF, "IOCTL_PCPS_CLR_UCAP_BUFF" }, \
+ { IOCTL_GET_PCPS_UCAP_ENTRIES, "IOCTL_GET_PCPS_UCAP_ENTRIES" }, \
+ { IOCTL_GET_PCPS_UCAP_EVENT, "IOCTL_GET_PCPS_UCAP_EVENT" }, \
+ { IOCTL_GET_GPS_TZDL, "IOCTL_GET_GPS_TZDL" }, \
+ { IOCTL_SET_GPS_TZDL, "IOCTL_SET_GPS_TZDL" }, \
+ { IOCTL_GET_GPS_SW_REV, "IOCTL_GET_GPS_SW_REV" }, \
+ { IOCTL_GET_GPS_BVAR_STAT, "IOCTL_GET_GPS_BVAR_STAT" }, \
+ { IOCTL_GET_GPS_TIME, "IOCTL_GET_GPS_TIME" }, \
+ { IOCTL_SET_GPS_TIME, "IOCTL_SET_GPS_TIME" }, \
+ { IOCTL_GET_GPS_PORT_PARM, "IOCTL_GET_GPS_PORT_PARM" }, \
+ { IOCTL_SET_GPS_PORT_PARM, "IOCTL_SET_GPS_PORT_PARM" }, \
+ { IOCTL_GET_GPS_ANT_INFO, "IOCTL_GET_GPS_ANT_INFO" }, \
+ { IOCTL_GET_GPS_UCAP, "IOCTL_GET_GPS_UCAP" }, \
+ { IOCTL_GET_GPS_ENABLE_FLAGS, "IOCTL_GET_GPS_ENABLE_FLAGS" }, \
+ { IOCTL_SET_GPS_ENABLE_FLAGS, "IOCTL_SET_GPS_ENABLE_FLAGS" }, \
+ { IOCTL_GET_GPS_STAT_INFO, "IOCTL_GET_GPS_STAT_INFO" }, \
+ { IOCTL_SET_GPS_CMD, "IOCTL_SET_GPS_CMD" }, \
+ { IOCTL_GET_GPS_IDENT, "IOCTL_GET_GPS_IDENT" }, \
+ { IOCTL_GET_GPS_POS, "IOCTL_GET_GPS_POS" }, \
+ { IOCTL_SET_GPS_POS_XYZ, "IOCTL_SET_GPS_POS_XYZ" }, \
+ { IOCTL_SET_GPS_POS_LLA, "IOCTL_SET_GPS_POS_LLA" }, \
+ { IOCTL_GET_GPS_ANT_CABLE_LEN, "IOCTL_GET_GPS_ANT_CABLE_LEN" }, \
+ { IOCTL_SET_GPS_ANT_CABLE_LEN, "IOCTL_SET_GPS_ANT_CABLE_LEN" }, \
+ { IOCTL_GET_GPS_RECEIVER_INFO, "IOCTL_GET_GPS_RECEIVER_INFO" }, \
+ { IOCTL_GET_GPS_ALL_STR_TYPE_INFO, "IOCTL_GET_GPS_ALL_STR_TYPE_INFO" }, \
+ { IOCTL_GET_GPS_ALL_PORT_INFO, "IOCTL_GET_GPS_ALL_PORT_INFO" }, \
+ { IOCTL_SET_GPS_PORT_SETTINGS_IDX, "IOCTL_SET_GPS_PORT_SETTINGS_IDX" }, \
+ { IOCTL_GET_PCI_ASIC_VERSION, "IOCTL_GET_PCI_ASIC_VERSION" }, \
+ { IOCTL_GET_PCPS_TIME_CYCLES, "IOCTL_GET_PCPS_TIME_CYCLES" }, \
+ { IOCTL_GET_PCPS_HR_TIME_CYCLES, "IOCTL_GET_PCPS_HR_TIME_CYCLES" }, \
+ { IOCTL_GET_PCPS_IRIG_TX_INFO, "IOCTL_GET_PCPS_IRIG_TX_INFO" }, \
+ { IOCTL_SET_PCPS_IRIG_TX_SETTINGS, "IOCTL_SET_PCPS_IRIG_TX_SETTINGS" }, \
+ { IOCTL_GET_SYNTH, "IOCTL_GET_SYNTH" }, \
+ { IOCTL_SET_SYNTH, "IOCTL_SET_SYNTH" }, \
+ { IOCTL_DEV_IS_GPS, "IOCTL_DEV_IS_GPS" }, \
+ { IOCTL_DEV_IS_DCF, "IOCTL_DEV_IS_DCF" }, \
+ { IOCTL_DEV_IS_IRIG_RX, "IOCTL_DEV_IS_IRIG_RX" }, \
+ { IOCTL_DEV_HAS_HR_TIME, "IOCTL_DEV_HAS_HR_TIME" }, \
+ { IOCTL_DEV_HAS_CAB_LEN, "IOCTL_DEV_HAS_CAB_LEN" }, \
+ { IOCTL_DEV_HAS_TZDL, "IOCTL_DEV_HAS_TZDL" }, \
+ { IOCTL_DEV_HAS_PCPS_TZDL, "IOCTL_DEV_HAS_PCPS_TZDL" }, \
+ { IOCTL_DEV_HAS_TZCODE, "IOCTL_DEV_HAS_TZCODE" }, \
+ { IOCTL_DEV_HAS_TZ, "IOCTL_DEV_HAS_TZ" }, \
+ { IOCTL_DEV_HAS_EVENT_TIME, "IOCTL_DEV_HAS_EVENT_TIME" }, \
+ { IOCTL_DEV_HAS_RECEIVER_INFO, "IOCTL_DEV_HAS_RECEIVER_INFO" }, \
+ { IOCTL_DEV_CAN_CLR_UCAP_BUFF, "IOCTL_DEV_CAN_CLR_UCAP_BUFF" }, \
+ { IOCTL_DEV_HAS_UCAP, "IOCTL_DEV_HAS_UCAP" }, \
+ { IOCTL_DEV_HAS_IRIG_TX, "IOCTL_DEV_HAS_IRIG_TX" }, \
+ { IOCTL_DEV_HAS_SERIAL_HS, "IOCTL_DEV_HAS_SERIAL_HS" }, \
+ { IOCTL_DEV_HAS_SIGNAL, "IOCTL_DEV_HAS_SIGNAL" }, \
+ { IOCTL_DEV_HAS_MOD, "IOCTL_DEV_HAS_MOD" }, \
+ { IOCTL_DEV_HAS_IRIG, "IOCTL_DEV_HAS_IRIG" }, \
+ { IOCTL_DEV_HAS_REF_OFFS, "IOCTL_DEV_HAS_REF_OFFS" }, \
+ { IOCTL_DEV_HAS_OPT_FLAGS, "IOCTL_DEV_HAS_OPT_FLAGS" }, \
+ { IOCTL_DEV_HAS_GPS_DATA, "IOCTL_DEV_HAS_GPS_DATA" }, \
+ { IOCTL_DEV_HAS_SYNTH, "IOCTL_DEV_HAS_SYNTH" }, \
+ { IOCTL_DEV_HAS_GENERIC_IO, "IOCTL_DEV_HAS_GENERIC_IO" }, \
+ { IOCTL_PCPS_GENERIC_IO, "IOCTL_PCPS_GENERIC_IO" }, \
+ { IOCTL_GET_SYNTH_STATE, "IOCTL_GET_SYNTH_STATE" }, \
+ { IOCTL_GET_GPS_ALL_POUT_INFO, "IOCTL_GET_GPS_ALL_POUT_INFO" }, \
+ { IOCTL_SET_GPS_POUT_SETTINGS_IDX, "IOCTL_SET_GPS_POUT_SETTINGS_IDX" }, \
+ { IOCTL_GET_MAPPED_MEM_ADDR, "IOCTL_GET_MAPPED_MEM_ADDR" }, \
+ { IOCTL_UNMAP_MAPPED_MEM, "IOCTL_UNMAP_MAPPED_MEM" }, \
+ { IOCTL_GET_PCI_ASIC_FEATURES, "IOCTL_GET_PCI_ASIC_FEATURES" }, \
+ { IOCTL_DEV_HAS_PCI_ASIC_FEATURES, "IOCTL_DEV_HAS_PCI_ASIC_FEATURES" }, \
+ { IOCTL_DEV_HAS_PCI_ASIC_VERSION, "IOCTL_DEV_HAS_PCI_ASIC_VERSION" }, \
+ { IOCTL_DEV_IS_MSF, "IOCTL_DEV_IS_MSF" }, \
+ { IOCTL_DEV_IS_LWR, "IOCTL_DEV_IS_LWR" }, \
+ { IOCTL_DEV_IS_WWVB, "IOCTL_DEV_IS_WWVB" }, \
+ { IOCTL_GET_IRQ_STAT_INFO, "IOCTL_GET_IRQ_STAT_INFO" }, \
+ { IOCTL_GET_CYCLES_FREQUENCY, "IOCTL_GET_CYCLES_FREQUENCY" }, \
+ { IOCTL_DEV_HAS_FAST_HR_TIMESTAMP, "IOCTL_DEV_HAS_FAST_HR_TIMESTAMP" }, \
+ { IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES, "IOCTL_GET_FAST_HR_TIMESTAMP_CYCLES" }, \
+ { IOCTL_GET_FAST_HR_TIMESTAMP, "IOCTL_GET_FAST_HR_TIMESTAMP" }, \
+ { IOCTL_DEV_HAS_GPS_TIME_SCALE, "IOCTL_DEV_HAS_GPS_TIME_SCALE" }, \
+ { IOCTL_GET_GPS_TIME_SCALE_INFO, "IOCTL_GET_GPS_TIME_SCALE_INFO" }, \
+ { IOCTL_SET_GPS_TIME_SCALE_SETTINGS, "IOCTL_SET_GPS_TIME_SCALE_SETTINGS" }, \
+ { IOCTL_DEV_HAS_GPS_UTC_PARM, "IOCTL_DEV_HAS_GPS_UTC_PARM" }, \
+ { IOCTL_GET_GPS_UTC_PARM, "IOCTL_GET_GPS_UTC_PARM" }, \
+ { IOCTL_SET_GPS_UTC_PARM, "IOCTL_SET_GPS_UTC_PARM" }, \
+ { IOCTL_DEV_HAS_IRIG_CTRL_BITS, "IOCTL_DEV_HAS_IRIG_CTRL_BITS" }, \
+ { IOCTL_GET_IRIG_CTRL_BITS, "IOCTL_GET_IRIG_CTRL_BITS" }, \
+ { IOCTL_DEV_HAS_LAN_INTF, "IOCTL_DEV_HAS_LAN_INTF" }, \
+ { IOCTL_GET_LAN_IF_INFO, "IOCTL_GET_LAN_IF_INFO" }, \
+ { IOCTL_GET_IP4_STATE, "IOCTL_GET_IP4_STATE" }, \
+ { IOCTL_GET_IP4_SETTINGS, "IOCTL_GET_IP4_SETTINGS" }, \
+ { IOCTL_SET_IP4_SETTINGS, "IOCTL_SET_IP4_SETTINGS" }, \
+ { IOCTL_DEV_IS_PTP, "IOCTL_DEV_IS_PTP" }, \
+ { IOCTL_DEV_HAS_PTP, "IOCTL_DEV_HAS_PTP" }, \
+ { IOCTL_GET_PTP_STATE, "IOCTL_GET_PTP_STATE" }, \
+ { IOCTL_GET_PTP_CFG_INFO, "IOCTL_GET_PTP_CFG_INFO" }, \
+ { IOCTL_SET_PTP_CFG_SETTINGS, "IOCTL_SET_PTP_CFG_SETTINGS" }, \
+ { IOCTL_DEV_HAS_IRIG_TIME, "IOCTL_DEV_HAS_IRIG_TIME" }, \
+ { IOCTL_GET_IRIG_TIME, "IOCTL_GET_IRIG_TIME" }, \
+ { IOCTL_GET_TIME_INFO_HRT, "IOCTL_GET_TIME_INFO_HRT" }, \
+ { IOCTL_GET_TIME_INFO_TSTAMP, "IOCTL_GET_TIME_INFO_TSTAMP" }, \
+ { IOCTL_DEV_HAS_RAW_IRIG_DATA, "IOCTL_DEV_HAS_RAW_IRIG_DATA" }, \
+ { IOCTL_GET_RAW_IRIG_DATA, "IOCTL_GET_RAW_IRIG_DATA" }, \
+ { IOCTL_DEV_HAS_PTP_UNICAST, "IOCTL_DEV_HAS_PTP_UNICAST" }, \
+ { IOCTL_PTP_UC_MASTER_CFG_LIMITS, "IOCTL_PTP_UC_MASTER_CFG_LIMITS" }, \
+ { IOCTL_GET_ALL_PTP_UC_MASTER_INFO, "IOCTL_GET_ALL_PTP_UC_MASTER_INFO" }, \
+ { IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX, "IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX" }, \
+ { IOCTL_DEV_HAS_PZF, "IOCTL_DEV_HAS_PZF" }, \
+ { IOCTL_DEV_HAS_CORR_INFO, "IOCTL_DEV_HAS_CORR_INFO" }, \
+ { IOCTL_DEV_HAS_TR_DISTANCE, "IOCTL_DEV_HAS_TR_DISTANCE" }, \
+ { IOCTL_GET_CORR_INFO, "IOCTL_GET_CORR_INFO" }, \
+ { IOCTL_GET_TR_DISTANCE, "IOCTL_GET_TR_DISTANCE" }, \
+ { IOCTL_SET_TR_DISTANCE, "IOCTL_SET_TR_DISTANCE" }, \
+ { IOCTL_MBG_DBG_GET_PORT_ADDR, "IOCTL_MBG_DBG_GET_PORT_ADDR" }, \
+ { IOCTL_MBG_DBG_SET_PORT_ADDR, "IOCTL_MBG_DBG_SET_PORT_ADDR" }, \
+ { IOCTL_MBG_DBG_SET_BIT, "IOCTL_MBG_DBG_SET_BIT" }, \
+ { IOCTL_MBG_DBG_CLR_BIT, "IOCTL_MBG_DBG_CLR_BIT" }, \
+ { 0, NULL } \
+}
+
+
#if !defined( _cmd_from_ioctl_code )
#define _cmd_from_ioctl_code( _ioctl_code ) _ioctl_code
#endif
+
/**
* @brief Privilege levels for IOCTL codes.
*
@@ -450,7 +678,7 @@ enum
#if defined( __GNUC__ )
// Avoid "no previous prototype" with some gcc versions.
-__mbg_inline
+static __mbg_inline
int ioctl_get_required_privilege( ulong ioctl_code ) __attribute__((always_inline));
#endif
@@ -462,9 +690,13 @@ int ioctl_get_required_privilege( ulong ioctl_code ) __attribute__((always_inlin
* @return One of the enumerated privilege levels
* @return -1 for unknown IOCTL codes
*/
-__mbg_inline
+static __mbg_inline
int ioctl_get_required_privilege( ulong ioctl_code )
{
+ // To provide best maintainability the sequence of cases in ioctl_switch()
+ // should match the sequence of the cases here, which also makes sure
+ // commands requiring lowest latency are handled first.
+
switch ( ioctl_code )
{
// Commands requiring lowest latency:
@@ -503,14 +735,15 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_GET_IRIG_CTRL_BITS:
case IOCTL_GET_IP4_STATE:
case IOCTL_GET_PTP_STATE:
+ case IOCTL_GET_CORR_INFO:
return MBG_REQ_PRIVL_NONE;
// Commands returning device capabilities and features:
case IOCTL_DEV_IS_GPS:
case IOCTL_DEV_IS_DCF:
case IOCTL_DEV_IS_MSF:
- case IOCTL_DEV_IS_LWR:
case IOCTL_DEV_IS_WWVB:
+ case IOCTL_DEV_IS_LWR:
case IOCTL_DEV_IS_IRIG_RX:
case IOCTL_DEV_HAS_HR_TIME:
case IOCTL_DEV_HAS_CAB_LEN:
@@ -544,9 +777,12 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_DEV_HAS_IRIG_TIME:
case IOCTL_DEV_HAS_RAW_IRIG_DATA:
case IOCTL_DEV_HAS_PTP_UNICAST:
+ case IOCTL_DEV_HAS_PZF:
+ case IOCTL_DEV_HAS_CORR_INFO:
+ case IOCTL_DEV_HAS_TR_DISTANCE:
return MBG_REQ_PRIVL_NONE;
- // This ones are somewhat special since they change something
+ // The next codes are somewhat special since they change something
// on the board but do not affect basic operation:
case IOCTL_PCPS_CLR_UCAP_BUFF:
case IOCTL_SET_PCPS_EVENT_TIME: // supported by some customized firmware only
@@ -567,11 +803,8 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_GET_GPS_PORT_PARM:
case IOCTL_GET_GPS_ENABLE_FLAGS:
case IOCTL_GET_GPS_ANT_CABLE_LEN:
- case IOCTL_GET_GPS_ALL_STR_TYPE_INFO:
- case IOCTL_GET_GPS_ALL_PORT_INFO:
case IOCTL_GET_PCPS_IRIG_TX_INFO:
case IOCTL_GET_SYNTH:
- case IOCTL_GET_GPS_ALL_POUT_INFO:
case IOCTL_GET_GPS_TIME_SCALE_INFO:
case IOCTL_GET_GPS_UTC_PARM:
case IOCTL_GET_LAN_IF_INFO:
@@ -580,7 +813,19 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_GET_IRIG_TIME:
case IOCTL_GET_RAW_IRIG_DATA:
case IOCTL_PTP_UC_MASTER_CFG_LIMITS:
+ case IOCTL_GET_TR_DISTANCE:
+ // generic read functions
+ case IOCTL_PCPS_GENERIC_READ:
+ case IOCTL_PCPS_GENERIC_READ_GPS:
+ #if _MBG_SUPP_VAR_ACC_SIZE
+ // These codes are only supported on target systems where a variable size of
+ // the IOCTL buffer can be specified in the IOCTL call. On other systems the
+ // generic IOCTL functions are used instead.
+ case IOCTL_GET_GPS_ALL_STR_TYPE_INFO:
+ case IOCTL_GET_GPS_ALL_PORT_INFO:
+ case IOCTL_GET_GPS_ALL_POUT_INFO:
case IOCTL_GET_ALL_PTP_UC_MASTER_INFO:
+ #endif
return MBG_REQ_PRIVL_CFG_READ;
// Writing device configuration:
@@ -601,9 +846,10 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_SET_IP4_SETTINGS:
case IOCTL_SET_PTP_CFG_SETTINGS:
case IOCTL_SET_PTP_UC_MASTER_SETTINGS_IDX:
+ case IOCTL_SET_TR_DISTANCE:
return MBG_REQ_PRIVL_CFG_WRITE;
- // Operations which may affect system operation:
+ // Operations which may severely affect system operation:
case IOCTL_SET_PCPS_TIME:
case IOCTL_SET_GPS_TIME:
case IOCTL_SET_GPS_POS_XYZ:
@@ -611,20 +857,19 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_SET_GPS_TIME_SCALE_SETTINGS:
case IOCTL_SET_GPS_UTC_PARM:
case IOCTL_SET_GPS_CMD:
- // generic read/write operations can do anything
- case IOCTL_PCPS_GENERIC_READ:
+ // generic write operations can do anything
case IOCTL_PCPS_GENERIC_WRITE:
- case IOCTL_PCPS_GENERIC_READ_GPS:
case IOCTL_PCPS_GENERIC_WRITE_GPS:
case IOCTL_PCPS_GENERIC_IO:
return MBG_REQ_PRIVL_SYSTEM;
- // These codes are somewhat special and normally
+ // The next codes are somewhat special and normally
// not used by the driver software:
case IOCTL_GET_MAPPED_MEM_ADDR:
case IOCTL_UNMAP_MAPPED_MEM:
return MBG_REQ_PRIVL_SYSTEM;
+ #if USE_DEBUG_PORT
// The codes below are used for debugging only.
// Unrestricted usage may cause system malfunction !!
case IOCTL_MBG_DBG_GET_PORT_ADDR:
@@ -633,7 +878,7 @@ int ioctl_get_required_privilege( ulong ioctl_code )
case IOCTL_MBG_DBG_CLR_BIT:
case IOCTL_MBG_DBG_CLR_ALL:
return MBG_REQ_PRIVL_SYSTEM;
-
+ #endif
} // switch
return -1; // unsupported code, should always be denied
@@ -642,23 +887,6 @@ int ioctl_get_required_privilege( ulong ioctl_code )
-// The structure below is used by the IOCTL_PCPS_GENERIC_... calls.
-typedef struct
-{
- uint32_t info;
- uint32_t data_size_in;
- uint32_t data_size_out;
-} IOCTL_GENERIC_CTL;
-
-
-typedef struct
-{
- IOCTL_GENERIC_CTL ctl;
- uint8_t data[1];
-} IOCTL_GENERIC_BUFFER;
-
-
-
/* End of header body */
#undef _ext
@@ -685,8 +913,4 @@ extern "C" {
#endif
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack()
-#endif
-
#endif /* _MBGIOCTL_H */
diff --git a/mbglib/common/mbgmutex.h b/mbglib/common/mbgmutex.h
index e079914..67b048a 100755
--- a/mbglib/common/mbgmutex.h
+++ b/mbglib/common/mbgmutex.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgmutex.h 1.1.1.4 2011/05/06 09:11:16 martin TRASH $
+ * $Id: mbgmutex.h 1.1.1.6 2011/05/31 14:19:55 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -11,7 +11,11 @@
*
* -----------------------------------------------------------------------
* $Log: mbgmutex.h $
- * Revision 1.1.1.4 2011/05/06 09:11:16 martin
+ * Revision 1.1.1.6 2011/05/31 14:19:55 martin
+ * Revision 1.1.1.5 2011/05/16 17:39:41 martin
+ * Don't define macros for semaphore destroy functions
+ * if not required/supported on the target OS.
+ * Revision 1.1.1.4 2011/05/06 09:11:16Z martin
* Fix for DOS.
* Revision 1.1.1.3 2011/05/04 09:24:18Z martin
* Revision 1.1.1.2 2011/05/04 08:57:23 martin
@@ -48,16 +52,16 @@
typedef KSPIN_LOCK MBG_SPINLOCK;
#define _mbg_spin_lock_init( _spl ) KeInitializeSpinLock( _spl )
- #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc()
+ // _mbg_spin_lock_destroy is not supported
#define _mbg_spin_lock_acquire( _spl ) KeAcquireSpinLockAtDpcLevel( _spl )
#define _mbg_spin_lock_release( _spl ) KeReleaseSpinLockFromDpcLevel( _spl )
- #define MBG_SPINLOCK_DEFINED 1
+ #define _MBG_SPINLOCK_DEFINED 1
typedef FAST_MUTEX MBG_MUTEX;
#define _mbg_mutex_init( _pmtx ) ExInitializeFastMutex( _pmtx )
- #define _mbg_mutex_destroy( _pmtx ) _nop_macro_fnc()
+ // _mbg_mutex_destroy( _pmtx ) is not supported
#define _mbg_mutex_acquire( _pmtx ) ExAcquireFastMutex( _pmtx )
#define _mbg_mutex_release( _pmtx ) ExReleaseFastMutex( _pmtx )
@@ -76,16 +80,16 @@
typedef spinlock_t MBG_SPINLOCK;
#define _mbg_spin_lock_init( _spl ) spin_lock_init( _spl )
- #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc()
+ // _mbg_spin_lock_destroy is not supported
#define _mbg_spin_lock_acquire( _spl ) spin_lock( _spl )
#define _mbg_spin_lock_release( _spl ) spin_unlock( _spl )
- #define MBG_SPINLOCK_DEFINED 1
+ #define _MBG_SPINLOCK_DEFINED 1
typedef struct semaphore MBG_MUTEX;
#define _mbg_mutex_init( _pmtx ) sema_init( _pmtx, 1 )
- #define _mbg_mutex_destroy( _pmtx ) _nop_macro_fnc()
+ // _mbg_mutex_destroy( _pmtx ) is not supported
#define _mbg_mutex_acquire( _pmtx ) down_interruptible( _pmtx )
#define _mbg_mutex_release( _pmtx ) up( _pmtx )
@@ -102,7 +106,7 @@
#define _mbg_spin_lock_acquire( _spl ) mtx_lock_spin( _spl )
#define _mbg_spin_lock_release( _spl ) mtx_unlock_spin( _spl )
- #define MBG_SPINLOCK_DEFINED 1
+ #define _MBG_SPINLOCK_DEFINED 1
typedef struct mtx MBG_MUTEX;
@@ -126,7 +130,7 @@
#define _mbg_spin_lock_acquire( _spl ) mutex_spin_enter( _spl )
#define _mbg_spin_lock_release( _spl ) mutex_spin_exit( _spl )
- #define MBG_SPINLOCK_DEFINED 1
+ #define _MBG_SPINLOCK_DEFINED 1
typedef kmutex_t MBG_MUTEX;
@@ -192,10 +196,10 @@
#endif
-#if !defined( MBG_SPINLOCK_DEFINED )
+#if !defined( _MBG_SPINLOCK_DEFINED )
#define _mbg_spin_lock_init( _spl ) _nop_macro_fnc()
- #define _mbg_spin_lock_destroy( _spl ) _nop_macro_fnc()
+ // _mbg_spin_lock_destroy is not supported
#define _mbg_spin_lock_acquire( _spl ) _nop_macro_fnc()
#define _mbg_spin_lock_release( _spl ) _nop_macro_fnc()
@@ -209,7 +213,7 @@
typedef MBG_CRIT_SECT MBG_MUTEX;
#define _mbg_mutex_init( _pm ) _nop_macro_fnc()
- #define _mbg_mutex_destroy( _pm ) _nop_macro_fnc()
+ // _mbg_mutex_destroy( _pmtx ) is not supported
#define _mbg_mutex_acquire( _pm ) _nop_macro_fnc()
#define _mbg_mutex_release( _pm ) _nop_macro_fnc()
@@ -223,10 +227,12 @@
#define _MBG_CRIT_SECT_DEFINED 1
typedef MBG_MUTEX MBG_CRIT_SECT;
- #define _mbg_crit_sect_init _mbg_mutex_init
- #define _mbg_crit_sect_destroy _mbg_mutex_destroy
- #define _mbg_crit_sect_enter _mbg_mutex_acquire
- #define _mbg_crit_sect_leave _mbg_mutex_release
+ #define _mbg_crit_sect_init _mbg_mutex_init
+ #if defined( _mbg_mutex_destroy )
+ #define _mbg_crit_sect_destroy _mbg_mutex_destroy
+ #endif
+ #define _mbg_crit_sect_enter _mbg_mutex_acquire
+ #define _mbg_crit_sect_leave _mbg_mutex_release
#endif
diff --git a/mbglib/common/mbgpccyc.h b/mbglib/common/mbgpccyc.h
new file mode 100755
index 0000000..a6563e9
--- /dev/null
+++ b/mbglib/common/mbgpccyc.h
@@ -0,0 +1,302 @@
+
+/**************************************************************************
+ *
+ * $Id: mbgpccyc.h 1.1.1.5 2011/09/21 14:25:39 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Portable macros to get a machine's current cycle count.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: mbgpccyc.h $
+ * Revision 1.1.1.5 2011/09/21 14:25:39 martin
+ * Use get_cycles() in Linux kernel mode if no special cycles support
+ * is provided for the given hardware platform.
+ * Revision 1.1.1.4 2011/07/20 15:58:53 martin
+ * Support cycles on IA64 only in kernel space.
+ * Revision 1.1.1.3 2011/07/13 09:44:49 martin
+ * Moved IA64 includes from pcpsdev.h to mbgpccyc.h.
+ * Revision 1.1.1.2 2011/07/06 13:23:36 martin
+ * Revision 1.1.1.1 2011/07/05 12:25:08 martin
+ * Revision 1.1 2011/06/23 15:36:07 martin
+ * Initial revision.
+ *
+ **************************************************************************/
+
+#ifndef _MBGPCCYC_H
+#define _MBGPCCYC_H
+
+
+/* Other headers to be included */
+
+#include <mbg_tgt.h>
+#include <words.h>
+
+#if defined( MBG_TGT_NETBSD )
+ #if defined( MBG_TGT_KERNEL )
+ #include <machine/cpu.h>
+ #include <machine/cpu_counter.h> /* for cycle counter abstraction */
+ #endif
+#endif
+
+#if defined( MBG_TGT_FREEBSD )
+ #if defined( MBG_TGT_KERNEL )
+ #if defined( MBG_ARCH_X86 )
+ #include <machine/clock.h> /* for symbol 'tsc_freq' */
+ #endif
+ #endif
+#endif
+
+#if defined( MBG_TGT_LINUX )
+ #if defined( MBG_ARCH_IA64 ) && defined( MBG_TGT_KERNEL )
+ #include <asm/ia64regs.h>
+ #include <asm/intel_intrin.h>
+ #endif
+#endif
+
+
+#ifdef _MBGPCCYC
+ #define _ext
+ #define _DO_INIT
+#else
+ #define _ext extern
+#endif
+
+
+/* Start of header body */
+
+/**
+ * @brief Generic types to hold PC cycle counter values.
+ *
+ * The cycle counter value is usually derived from the PC CPU's TSC or some other
+ * timer hardware on the mainboard.
+ */
+#if defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_UNIX )
+
+ typedef int64_t MBG_PC_CYCLES;
+ typedef uint64_t MBG_PC_CYCLES_FREQUENCY;
+
+#else
+
+ typedef uint32_t MBG_PC_CYCLES;
+ typedef uint32_t MBG_PC_CYCLES_FREQUENCY;
+
+#endif
+
+
+// MBG_PC_CYCLES and MBG_PC_CYCLES_FREQUENCY are always read in native
+// machine endianess, so no endianess conversion is required.
+#define _mbg_swab_mbg_pc_cycles( _p ) \
+ _nop_macro_fnc()
+
+#define _mbg_swab_mbg_pc_cycles_frequency( _p ) \
+ _nop_macro_fnc()
+
+
+
+#if ( defined( MBG_TGT_LINUX ) || defined( MBG_TGT_BSD ) ) && defined( MBG_ARCH_X86 )
+
+ static __mbg_inline unsigned long long int mbg_rdtscll( void )
+ {
+ // The code below is a hack to get around issues with
+ // different versions of gcc.
+ //
+ // Normally the inline asm code could look similar to:
+ //
+ // __asm__ volatile ( "rdtsc" : "=A" (x) )
+ //
+ // which would copy the output regs edx:eax as a 64 bit
+ // number to a variable x.
+ //
+ // The "=A" expression should implicitely tell the compiler
+ // the edx and eax registers have been clobbered. However,
+ // this does not seem to work properly at least with gcc 4.1.2
+ // shipped with Centos 5.
+ //
+ // If optimization level 1 or higher is used then function
+ // parameters are also passed in registers. If the inline
+ // code above is used inside a function then the edx register
+ // is clobbered but the gcc 4.1.2 is not aware of this and
+ // assumes edx is unchanged, which may yield faulty results
+ // or even lead to segmentation faults.
+ //
+ // A possible workaround could be to mark edx explicitely as
+ // being clobbered in the asm inline code, but unfortunately
+ // other gcc versions report an error if a register which is
+ // implicitely (by "=A") known to be clobbered is also listed
+ // explicitely to be clobbered.
+ //
+ // So the code below is a workaround which tells the compiler
+ // implicitely that the eax ("=a") and edx ("=d") registers
+ // are being used and thus clobbered.
+
+ union
+ {
+ struct
+ {
+ uint32_t lo;
+ uint32_t hi;
+ } u32;
+
+ uint64_t u64;
+
+ } tsc_val;
+
+ __asm__ __volatile__( "rdtsc" : "=a" (tsc_val.u32.lo), "=d" (tsc_val.u32.hi) );
+
+ return tsc_val.u64;
+
+ } // mbg_rdtscll
+
+#endif
+
+
+
+static __mbg_inline
+void mbg_get_pc_cycles( MBG_PC_CYCLES *p )
+{
+ #if defined( MBG_TGT_WIN32 )
+
+ #if defined( MBG_TGT_KERNEL ) // kernel space
+ *p = (MBG_PC_CYCLES) KeQueryPerformanceCounter( NULL ).QuadPart;
+ #else // user space
+ QueryPerformanceCounter( (LARGE_INTEGER *) p );
+ #endif
+
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_X86 )
+
+ *p = mbg_rdtscll();
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_IA64 ) && defined( MBG_TGT_KERNEL )
+
+ unsigned long result = ia64_getreg( _IA64_REG_AR_ITC );
+ ia64_barrier();
+
+ #ifdef CONFIG_ITANIUM
+ while (unlikely((__s32) result == -1)) {
+ result = ia64_getreg(_IA64_REG_AR_ITC);
+ ia64_barrier();
+ }
+ #endif
+
+ *p = result;
+
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #elif defined( MBG_TGT_LINUX ) && defined( MBG_TGT_KERNEL )
+
+ *p = get_cycles();
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #elif defined( MBG_TGT_FREEBSD ) && defined( MBG_ARCH_X86 )
+
+ *p = mbg_rdtscll();
+
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #elif defined( MBG_TGT_NETBSD ) && defined ( MBG_TGT_KERNEL )
+
+ *p = cpu_counter(); //##++ or cpu_counter_serializing()
+
+ #define MBG_PC_CYCLES_SUPPORTED 1
+
+ #else
+
+ *p = 0;
+
+ #endif
+
+} // mbg_get_pc_cycles
+
+
+
+static __mbg_inline
+void mbg_get_pc_cycles_frequency( MBG_PC_CYCLES_FREQUENCY *p )
+{
+ #if defined( MBG_TGT_WIN32 )
+ LARGE_INTEGER li;
+
+ #if defined( MBG_TGT_KERNEL ) // kernel space
+ KeQueryPerformanceCounter( &li );
+ #else // user space
+ QueryPerformanceFrequency( &li );
+ #endif
+
+ *p = li.QuadPart;
+
+ #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_X86 ) && defined( MBG_TGT_KERNEL )
+
+ *p = ( cpu_khz * 1000 );
+
+ #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_IA64 )
+
+ // we probably can use
+ // ia64_sal_freq_base(unsigned long which, unsigned long *ticks_per_second,
+ // unsigned long *drift_info)
+ // However, this is not tested.
+
+ *p = 0;
+
+ #elif defined( MBG_TGT_FREEBSD ) && defined( MBG_ARCH_X86 ) && defined( MBG_TGT_KERNEL )
+
+ *p = tsc_freq;
+
+ #elif defined( MBG_TGT_NETBSD ) && defined( MBG_TGT_KERNEL )
+
+ *p = cpu_frequency( curcpu() );
+
+ #else
+
+ *p = 0;
+
+ #endif
+
+} // mbg_get_pc_cycles_frequency
+
+
+
+static __mbg_inline
+MBG_PC_CYCLES mbg_delta_pc_cycles( const MBG_PC_CYCLES *p1, const MBG_PC_CYCLES *p2 )
+{
+#if 0 && !defined( MBG_PC_CYCLES_SUPPORTED ) //##+++++++++++++++++
+ // Cycle counts not supported on this target platform.
+ // Under SPARC this may even result in bus errors
+ // due to alignment of the underlying data structures.
+ return 0;
+#else
+ return *p1 - *p2;
+#endif
+
+} // mbg_delta_pc_cycles
+
+
+
+/* function prototypes: */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ----- function prototypes begin ----- */
+
+/* This section was generated automatically */
+/* by MAKEHDR, do not remove the comments. */
+
+/* (no header definitions found) */
+
+/* ----- function prototypes end ----- */
+
+#ifdef __cplusplus
+}
+#endif
+
+/* End of header body */
+
+#undef _ext
+#undef _DO_INIT
+
+#endif /* _MBGPCCYC */
diff --git a/mbglib/common/mbgtime.h b/mbglib/common/mbgtime.h
index ba6900f..d1ae02b 100755
--- a/mbglib/common/mbgtime.h
+++ b/mbglib/common/mbgtime.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgtime.h 1.17.1.6 2011/05/06 09:03:12 martin TRASH $
+ * $Id: mbgtime.h 1.17.1.6 2011/05/06 09:03:12 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
diff --git a/mbglib/common/mbgutil.c b/mbglib/common/mbgutil.c
index 1a4156e..8ae735d 100755
--- a/mbglib/common/mbgutil.c
+++ b/mbglib/common/mbgutil.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgutil.c 1.5.2.1 2010/07/15 13:06:59 martin TEST $
+ * $Id: mbgutil.c 1.5.2.2 2011/09/21 16:01:18 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,7 @@
*
* -----------------------------------------------------------------------
* $Log: mbgutil.c $
+ * Revision 1.5.2.2 2011/09/21 16:01:18 martin
* Revision 1.5.2.1 2010/07/15 13:06:59 martin
* Revision 1.5 2009/03/19 09:09:55Z daniel
* Fixed ambiguous syntax in mbg_str_dev_name().
@@ -34,7 +35,6 @@
#include <pcpsutil.h>
#include <pcpslstr.h>
-//#include <gpsutils.h>
#include <pcpsdev.h>
#include <stdio.h>
diff --git a/mbglib/common/mbgutil.h b/mbglib/common/mbgutil.h
index 9d26c62..e78f27c 100755
--- a/mbglib/common/mbgutil.h
+++ b/mbglib/common/mbgutil.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgutil.h 1.16.1.1 2011/02/09 15:27:23 martin TRASH $
+ * $Id: mbgutil.h 1.16.1.2 2011/06/22 10:21:57 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,10 @@
*
* -----------------------------------------------------------------------
* $Log: mbgutil.h $
+ * Revision 1.16.1.2 2011/06/22 10:21:57 martin
+ * Cleaned up handling of pragma pack().
* Revision 1.16.1.1 2011/02/09 15:27:23 martin
+ * Include stdlib.h.
* Revision 1.16 2009/08/14 10:11:53Z daniel
* New version code 306, compatibility version still 110.
* Revision 1.15 2009/06/09 08:57:47Z daniel
@@ -95,8 +98,9 @@
/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
#endif
@@ -169,8 +173,9 @@ extern "C" {
#endif
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/pci_asic.h b/mbglib/common/pci_asic.h
index b641e51..66afe3e 100755
--- a/mbglib/common/pci_asic.h
+++ b/mbglib/common/pci_asic.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: pci_asic.h 1.18.1.1 2011/05/06 13:47:48 martin TRASH $
+ * $Id: pci_asic.h 1.22 2011/10/05 09:46:12 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,15 @@
*
* -----------------------------------------------------------------------
* $Log: pci_asic.h $
- * Revision 1.18.1.1 2011/05/06 13:47:48 martin
+ * Revision 1.22 2011/10/05 09:46:12 martin
+ * Updated version info for GPS180PEX.
+ * Revision 1.21 2011/09/13 07:36:21Z martin
+ * Updated version info for GPS180PEX.
+ * Revision 1.20 2011/06/30 13:52:26Z martin
+ * Updated version info for GPS180PEX.
+ * Revision 1.19 2011/06/29 08:58:32Z martin
+ * Support PZF180PEX.
+ * Cleaned up handling of pragma pack().
* Revision 1.18 2011/04/06 12:31:48 martin
* Updated minor versions for PTP270PEX and GPS180PEX.
* Revision 1.17 2010/09/10 14:03:25Z martin
@@ -73,11 +81,6 @@
#include <words.h>
#include <use_pack.h>
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
-#endif
-
-
#ifdef _PCI_ASIC
#define _ext
#define _DO_INIT
@@ -88,6 +91,11 @@
/* Start of header body */
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
+#endif
+
typedef struct
{
@@ -271,7 +279,7 @@ enum
PCI_ASIC_MAJOR_TCR170PEX, // PEX EPLD for TCR170PEX
PCI_ASIC_MAJOR_GPS180PEX, // PEX EPLD for GPS180PEX
PCI_ASIC_MAJOR_TCR180PEX, // PEX EPLD for TCR180PEX
- PCI_ASIC_MAJOR_PZF600PEX, // PEX EPLD for PZF600PEX
+ PCI_ASIC_MAJOR_PZF180PEX, // PEX EPLD for PZF180PEX
N_PCI_ASIC_MAJOR // the number of known codes
};
@@ -311,15 +319,19 @@ enum
#define PCI_ASIC_FIX_EE_ACCESS_TCR170PEX 0x02 // fixes EE access problem after reset
#define PCI_ASIC_FIX_FO_IN_LEVEL_TCR170PEX 0x03 // correct polarity for fiber optic input
-#define PCI_ASIC_CURRENT_MINOR_GPS180PEX 0x01
+#define PCI_ASIC_CURRENT_MINOR_GPS180PEX 0x05
#define PCI_ASIC_REQUIRED_MINOR_GPS180PEX 0x01
-// 0x01 // updated VHDL compiler and associated primitives
+// 0x01 // updated VHDL compiler and associated PCI primitives
+// 0x02 // I/O using 3.3V LVTTL
+// 0x03 // GPS TIC pulse len now 1 sample clock
+// 0x04 // Enabled PCI IRQ line which had unintentionally been disabled earlier
+// 0x05 // Increased accuracy of synthesizer output
#define PCI_ASIC_CURRENT_MINOR_TCR180PEX 0x00
#define PCI_ASIC_REQUIRED_MINOR_TCR180PEX 0x00
-#define PCI_ASIC_CURRENT_MINOR_PZF600PEX 0x00
-#define PCI_ASIC_REQUIRED_MINOR_PZF600PEX 0x00
+#define PCI_ASIC_CURRENT_MINOR_PZF180PEX 0x00
+#define PCI_ASIC_REQUIRED_MINOR_PZF180PEX 0x00
typedef struct
@@ -340,7 +352,7 @@ typedef struct
{ PCPS_TYPE_TCR170PEX, PCI_ASIC_MAJOR_TCR170PEX, PCI_ASIC_CURRENT_MINOR_TCR170PEX, PCI_ASIC_REQUIRED_MINOR_TCR170PEX }, \
{ PCPS_TYPE_GPS180PEX, PCI_ASIC_MAJOR_GPS180PEX, PCI_ASIC_CURRENT_MINOR_GPS180PEX, PCI_ASIC_REQUIRED_MINOR_GPS180PEX }, \
{ PCPS_TYPE_TCR180PEX, PCI_ASIC_MAJOR_TCR180PEX, PCI_ASIC_CURRENT_MINOR_TCR180PEX, PCI_ASIC_REQUIRED_MINOR_TCR180PEX }, \
- { PCPS_TYPE_PZF600PEX, PCI_ASIC_MAJOR_PZF600PEX, PCI_ASIC_CURRENT_MINOR_PZF600PEX, PCI_ASIC_REQUIRED_MINOR_PZF600PEX }, \
+ { PCPS_TYPE_PZF180PEX, PCI_ASIC_MAJOR_PZF180PEX, PCI_ASIC_CURRENT_MINOR_PZF180PEX, PCI_ASIC_REQUIRED_MINOR_PZF180PEX }, \
{ 0 } \
}
@@ -365,8 +377,9 @@ extern "C" {
#endif
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/pcpsdefs.h b/mbglib/common/pcpsdefs.h
index 53fa6a3..094ff03 100755
--- a/mbglib/common/pcpsdefs.h
+++ b/mbglib/common/pcpsdefs.h
@@ -1,30 +1,43 @@
/**************************************************************************
*
- * $Id: pcpsdefs.h 1.46.1.3.1.7 2011/05/06 13:47:38 martin TRASH $
+ * $Id: pcpsdefs.h 1.46.1.13 2011/10/05 15:10:31 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
* Description:
- * General definitions for Meinberg plug-in radio clocks
+ * General definitions for Meinberg plug-in devices.
*
* -----------------------------------------------------------------------
* $Log: pcpsdefs.h $
- * Revision 1.46.1.3.1.7 2011/05/06 13:47:38 martin
+ * Revision 1.46.1.13 2011/10/05 15:10:31 martin
+ * Added string initializers for PZF correlation state.
+ * Revision 1.46.1.12 2011/08/05 11:03:21 martin
+ * Fixed typos.
+ * Revision 1.46.1.11 2011/07/18 10:19:28 martin
+ * Added an initializer for a table of GPS command code/names.
+ * Revision 1.46.1.10 2011/07/06 11:21:38 martin
+ * Added commands to read CORR_INFO, and read/write TR_DISTANCE.
+ * Added swab macros for CORR_INFO and TR_DISTANCE.
+ * Modified some comments.
+ * Revision 1.46.1.9 2011/07/05 08:27:00 martin
+ * Comments only.
+ * Revision 1.46.1.8 2011/07/04 15:27:52 martin
+ * Made command group codes obsolete. They are still supported
+ * when building firmware, though.
+ * Revision 1.46.1.7 2011/07/04 14:53:46 martin
+ * Added definitions MBG_PCPS_FMT_STATUS and PCPS_SYNC_PZF.
+ * Modified some comments.
+ * Revision 1.46.1.6 2011/06/29 14:08:28 martin
+ * Updated some comments.
+ * Revision 1.46.1.5 2011/06/29 09:10:25 martin
+ * Renamed PZF600PEX to PZF180PEX.
+ * Revision 1.46.1.4 2011/06/21 13:45:14 martin
* Support PZF600PEX.
- * Revision 1.46.1.3.1.6 2011/04/21 12:31:00 martin
* Renamed *_GPIO_CFG_INFO to *_GPIO_CFG_LIMITS
* to follow common naming conventions.
- * Revision 1.46.1.3.1.5 2011/04/19 15:14:19 martin
- * Cleanup.
- * Revision 1.46.1.3.1.4 2011/04/19 15:05:48 martin
- * PTP unicast cfg stuff ...
- * Revision 1.46.1.3.1.3 2011/04/19 13:08:37 martin
- * Modified naming conventions for PTP unicast master configuration.
- * Revision 1.46.1.3.1.2 2011/04/19 09:59:11 martin
- * More PTP unicast cfg ...
- * Revision 1.46.1.3.1.1 2011/04/18 15:31:05 martin
- * Started PTP unicast
+ * Support PTP unicast configuration.
+ * Modified handling of pragma pack().
* Revision 1.46.1.3 2011/04/18 13:29:39 martin
* Doxygen changes.
* Revision 1.46.1.2 2011/04/07 15:56:25 martin
@@ -230,16 +243,16 @@
#include <use_pack.h>
-/* Start of header body */
+/* Start of header body */
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+#if defined( _USE_PACK )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
#endif
/**
- * The following codes enumerate the ref time sources
- * from which the clocks receive the reference time.
+ * @brief Enumeration of the ref time signal sources used by Meinberg devices
*/
enum
{
@@ -248,7 +261,7 @@ enum
PCPS_REF_GPS, /**< see http://www.meinberg.de/english/info/gps.htm */
PCPS_REF_IRIG, /**< see http://www.meinberg.de/english/info/irig.htm */
PCPS_REF_MSF, /**< MSF Receiver (UK) */
- PCPS_REF_PTP, /**< PTP Timestamp card */
+ PCPS_REF_PTP, /**< PTP/IEEE1588 network protocol */
PCPS_REF_FRC, /**< Free Running Clock */
PCPS_REF_WWVB, /**< WWVB Receiver (US) */
PCPS_REF_JJY, /**< JJY Receiver (Japan) */
@@ -299,9 +312,9 @@ enum
-/**
- PCI vendor ID number (assigned by PCI SIG)
-*/
+/**
+ * @brief Meinberg PCI vendor ID (assigned by PCI SIG)
+ */
#define PCI_VENDOR_MEINBERG 0x1360
/* PCI device ID numbers (assigned by Meinberg) *
@@ -313,7 +326,7 @@ enum
#define PCI_DEV_PCI510 ( ( PCPS_REF_DCF << 8 ) | 0x03 )
#define PCI_DEV_PCI511 ( ( PCPS_REF_DCF << 8 ) | 0x04 )
#define PCI_DEV_PEX511 ( ( PCPS_REF_DCF << 8 ) | 0x05 )
-#define PCI_DEV_PZF600PEX ( ( PCPS_REF_DCF << 8 ) | 0x06 ) //##+++++ Should we use a new ref type for PZF reception?
+#define PCI_DEV_PZF180PEX ( ( PCPS_REF_DCF << 8 ) | 0x06 )
#define PCI_DEV_GPS167PCI ( ( PCPS_REF_GPS << 8 ) | 0x01 )
#define PCI_DEV_GPS168PCI ( ( PCPS_REF_GPS << 8 ) | 0x02 )
@@ -339,21 +352,22 @@ enum
// (not to be intermixed with PCPS_TIME_STATUS)
typedef uint8_t PCPS_STATUS_PORT; /**< see @ref group_status_port "Bitmask" */
-/** @defgroup group_status_port Bit masks of PCPS_STATUS_PORT
-
- Bit definitions used with the #PCPS_STATUS_PORT register.
-
- The flags #PCPS_ST_SEC and #PCPS_ST_MIN are cleared whenever the clock
- is read, so they are not very reliable in multitasking environments.
-
- <b>NOTE</b>: The PCPS_ST_IRQF flag originates from old ISA cards.
- Some PCI cards also support this, but in case of PCI cards the
- associated flag of the PCI interface chip should be checked to see
- if a certain card has generated an IRQ on the PC bus.
-
- The macro _pcps_ddev_has_gen_irq() cares about this and should be used
- to determine in a portable way whether a card has generated an IRQ.
-
+/**
+ * @defgroup group_status_port Bit masks of PCPS_STATUS_PORT
+ *
+ * Bit definitions used with the #PCPS_STATUS_PORT register.
+ *
+ * The flags #PCPS_ST_SEC and #PCPS_ST_MIN are cleared whenever the clock
+ * is read, so they are not very reliable in multitasking environments.
+ *
+ * @note The PCPS_ST_IRQF flag originates from old ISA cards.
+ * Some PCI cards also support this, but in case of PCI cards the
+ * associated flag of the PCI interface chip should be checked to see
+ * if a certain card has generated an IRQ on the PC bus.
+ *
+ * The macro _pcps_ddev_has_gen_irq() cares about this and should be used
+ * to determine in a portable way whether a card has generated an IRQ.
+ *
* @{ */
#define PCPS_ST_BUSY 0x01 /**< the clock is busy filling the output FIFO */
@@ -364,19 +378,24 @@ typedef uint8_t PCPS_STATUS_PORT; /**< see @ref group_status_port "Bitmask" */
/** @} group_status_port */
+/**
+ * A format string to be used with snprintb() which is available on some Unix
+ * systems to print information held in a bit coded variable.
+ */
+#define MBG_PCPS_FMT_STATUS \
+ "\177\20b\0FREER\0b\1DL_ENB\0b\2SYNCD\0b\3DL_ANN\0b\4UTC\0b\5LS_ANN\0b\6IFTM\0b\7INVT" \
+ "\0b\x08LS_ENB\0b\11ANT_FAIL\0b\x0aLS_ANN_NEG\0b\x0bSCALE_GPS\0b\x0cSCALE_TAI\0\0"
+
/** @defgroup group_cmd_bytes Command bytes used to access the device
- The commands described below can be used to access the Meinberg
- computer peripherals. However, some of the commands have not been
- implemented with older clock models, or firmware versions.
+ The commands described below are used to access computer peripherals
+ manufactured by Meinberg.
- The device driver library contains functions which detect the clocks
- and check which features are supported by a given clock model/firmware
The header files pcpsdev.h and pcpsdrvr.h contain macros which can be
- used to query whether a detected clock supports a feature.
- If checking is required, the name of the macro is given in the
+ used to check if a detected device supports a certain feature or command.
+ If checking is required then the name of the macro is given in the
comments below.
Some commands expect parameters to be passed to the board. In that
@@ -588,16 +607,34 @@ typedef uint8_t PCPS_STATUS_PORT; /**< see @ref group_status_port "Bitmask" */
available then the structure is filled with 0s.
_pcps_has_ucap() checks whether supported.
+ - #PCPS_GET_CORR_INFO<br>
+ Read PZF correlation info using a CORR_INFO
+ structure.
+ _pcps_has_pzf() checks whether supported.
+
+ - #PCPS_GET_TR_DISTANCE<br>
+ #PCPS_SET_TR_DISTANCE<br>
+ Read or write distance from the RF transmitter.
+ This is used to compensate the RF propagation delay
+ for PZF receivers.
+ _pcps_has_tr_distance() checks whether supported.
+
- #PCPS_FORCE_RESET<br>
- Resets the microprocessor on the radio clock
- board. This is for debug purposes only and
- should not be used by standard applications.
+ Resets the microprocessor on the device. This is
+ for special test scenarios only and should not be
+ used by standard applications since this may lock up
+ the PC.
The command codes listed above are defined below. The commands are
grouped for bytes having the same high nibble:
@{ */
+
+#if _IS_MBG_FIRMWARE //##++
+
+// These group codes are obsolete and should be removed.
+// The explicite command codes defined below should be used instead.
#define PCPS_GIVE_TIME_GROUP 0x00
#define PCPS_SET_TIME_GROUP 0x10
#define PCPS_IRQ_GROUP 0x20
@@ -607,44 +644,39 @@ typedef uint8_t PCPS_STATUS_PORT; /**< see @ref group_status_port "Bitmask" */
#define PCPS_CTRL_GROUP 0x60
#define PCPS_CFG2_GROUP 0x70
+#endif
+
-/* PCPS_GIVE_TIME_GROUP */
-#define PCPS_GIVE_TIME ( PCPS_GIVE_TIME_GROUP | 0x0 )
-#define PCPS_GIVE_TIME_NOCLEAR ( PCPS_GIVE_TIME_GROUP | 0x1 )
-#define PCPS_GIVE_SYNC_TIME ( PCPS_GIVE_TIME_GROUP | 0x2 ) // only supported if _pcps_has_sync_time()
-#define PCPS_GIVE_HR_TIME ( PCPS_GIVE_TIME_GROUP | 0x3 ) // only supported if _pcps_has_hr_time()
-#define PCPS_GIVE_IRIG_TIME ( PCPS_GIVE_TIME_GROUP | 0x4 ) // only supported if _pcps_has_irig_time()
+#define PCPS_GIVE_TIME 0x00
+#define PCPS_GIVE_TIME_NOCLEAR 0x01
+#define PCPS_GIVE_SYNC_TIME 0x02 // only supported if _pcps_has_sync_time()
+#define PCPS_GIVE_HR_TIME 0x03 // only supported if _pcps_has_hr_time()
+#define PCPS_GIVE_IRIG_TIME 0x04 // only supported if _pcps_has_irig_time()
-/* PCPS_SET_TIME_GROUP */
-#define PCPS_SET_TIME ( PCPS_SET_TIME_GROUP | 0x0 )
+#define PCPS_SET_TIME 0x10
/* on error, return PCPS_ERR_STIME */
/* Attention: The code below can be used EXCLUSIVELY */
/* with a GPS167PCI with customized CERN firmware !! */
/* _pcps_has_event_time() checks whether supported. */
-#define PCPS_SET_EVENT_TIME ( PCPS_SET_TIME_GROUP | 0x4 )
-
+#define PCPS_SET_EVENT_TIME 0x14
-/* PCPS_IRQ_GROUP */
-#define PCPS_IRQ_NONE ( PCPS_IRQ_GROUP | 0x0 )
-#define PCPS_IRQ_1_SEC ( PCPS_IRQ_GROUP | 0x1 )
-#define PCPS_IRQ_1_MIN ( PCPS_IRQ_GROUP | 0x2 )
-#define PCPS_IRQ_10_MIN ( PCPS_IRQ_GROUP | 0x4 )
-#define PCPS_IRQ_30_MIN ( PCPS_IRQ_GROUP | 0x8 )
+#define PCPS_IRQ_NONE 0x20
+#define PCPS_IRQ_1_SEC 0x21
+#define PCPS_IRQ_1_MIN 0x22
+#define PCPS_IRQ_10_MIN 0x24
+#define PCPS_IRQ_30_MIN 0x28
-
-/* PCPS_CFG_GROUP */
-
-#define PCPS_GET_SERIAL ( PCPS_CFG_GROUP | 0x0 )
-#define PCPS_SET_SERIAL ( PCPS_CFG_GROUP | 0x1 )
+#define PCPS_GET_SERIAL 0x30
+#define PCPS_SET_SERIAL 0x31
/* on error, return PCPS_ERR_CFG */
typedef uint8_t PCPS_SERIAL;
-#define PCPS_GET_TZCODE ( PCPS_CFG_GROUP | 0x2 )
-#define PCPS_SET_TZCODE ( PCPS_CFG_GROUP | 0x3 )
+#define PCPS_GET_TZCODE 0x32
+#define PCPS_SET_TZCODE 0x33
/* on error, return PCPS_ERR_CFG */
typedef uint8_t PCPS_TZCODE;
@@ -665,8 +697,8 @@ enum
#define PCPS_TZCODE_OEZ PCPS_TZCODE_EET_EEST
-#define PCPS_GET_PCPS_TZDL ( PCPS_CFG_GROUP | 0x4 )
-#define PCPS_SET_PCPS_TZDL ( PCPS_CFG_GROUP | 0x5 )
+#define PCPS_GET_PCPS_TZDL 0x34
+#define PCPS_SET_PCPS_TZDL 0x35
/* on error, return PCPS_ERR_CFG */
@@ -720,68 +752,63 @@ typedef struct
-#define PCPS_GET_REF_OFFS ( PCPS_CFG_GROUP | 0x6 )
-#define PCPS_SET_REF_OFFS ( PCPS_CFG_GROUP | 0x7 )
+#define PCPS_GET_REF_OFFS 0x36
+#define PCPS_SET_REF_OFFS 0x37
/* on error, return PCPS_ERR_CFG */
/* The associated type MBG_REF_OFFS is defined in gpsdefs.h. */
-#define PCPS_GET_OPT_INFO ( PCPS_CFG_GROUP | 0x8 )
-#define PCPS_SET_OPT_SETTINGS ( PCPS_CFG_GROUP | 0x9 )
+#define PCPS_GET_OPT_INFO 0x38
+#define PCPS_SET_OPT_SETTINGS 0x39
/* on error, return PCPS_ERR_CFG */
/* The associated structures MBG_OPT_INFO and MBG_OPT_SETTINGS
are defined in gpsdefs.h. */
-#define PCPS_GET_IRIG_RX_INFO ( PCPS_CFG_GROUP | 0xA )
-#define PCPS_SET_IRIG_RX_SETTINGS ( PCPS_CFG_GROUP | 0xB )
+#define PCPS_GET_IRIG_RX_INFO 0x3A
+#define PCPS_SET_IRIG_RX_SETTINGS 0x3B
/* on error, return PCPS_ERR_CFG */
-#define PCPS_GET_IRIG_TX_INFO ( PCPS_CFG_GROUP | 0xC )
-#define PCPS_SET_IRIG_TX_SETTINGS ( PCPS_CFG_GROUP | 0xD )
+#define PCPS_GET_IRIG_TX_INFO 0x3C
+#define PCPS_SET_IRIG_TX_SETTINGS 0x3D
/* on error, return PCPS_ERR_CFG */
/* The associated structures IRIG_INFO and IRIG_SETTINGS
are defined in gpsdefs.h. */
-#define PCPS_GET_SYNTH ( PCPS_CFG_GROUP | 0xE )
-#define PCPS_SET_SYNTH ( PCPS_CFG_GROUP | 0xF )
+#define PCPS_GET_SYNTH 0x3E
+#define PCPS_SET_SYNTH 0x3F
/* on error, return PCPS_ERR_CFG */
/* The associated structure SYNTH is defined in gpsdefs.h. */
-
-/* PCPS_GIVE_DATA_GROUP */
-#define PCPS_GIVE_FW_ID_1 ( PCPS_GIVE_DATA_GROUP | 0x0 )
-#define PCPS_GIVE_FW_ID_2 ( PCPS_GIVE_DATA_GROUP | 0x1 )
-#define PCPS_GIVE_SERNUM ( PCPS_GIVE_DATA_GROUP | 0x2 )
-#define PCPS_GENERIC_IO ( PCPS_GIVE_DATA_GROUP | 0x3 )
-#define PCPS_GET_SYNTH_STATE ( PCPS_GIVE_DATA_GROUP | 0x4 )
-#define PCPS_GET_IRIG_CTRL_BITS ( PCPS_GIVE_DATA_GROUP | 0x5 )
-#define PCPS_GET_RAW_IRIG_DATA ( PCPS_GIVE_DATA_GROUP | 0x6 )
+#define PCPS_GIVE_FW_ID_1 0x40
+#define PCPS_GIVE_FW_ID_2 0x41
+#define PCPS_GIVE_SERNUM 0x42
+#define PCPS_GENERIC_IO 0x43
+#define PCPS_GET_SYNTH_STATE 0x44
+#define PCPS_GET_IRIG_CTRL_BITS 0x45
+#define PCPS_GET_RAW_IRIG_DATA 0x46
-#define PCPS_GET_STATUS_PORT ( PCPS_GIVE_DATA_GROUP | 0xB )
-#define PCPS_GET_DEBUG_STATUS ( PCPS_GIVE_DATA_GROUP | 0xC )
+#define PCPS_GET_STATUS_PORT 0x4B
+#define PCPS_GET_DEBUG_STATUS 0x4C
// expects sizeof( MBG_DEBUG_STATUS ) chars
-// PCPS_GIVE_DATA_GROUP codes 0x0D, 0x0E, and 0x0F are reserved.
+// Command codes 0x4D, 0x4E, and 0x4F are reserved.
-/* PCPS_GPS_DATA_GROUP */
-#define PCPS_READ_GPS_DATA ( PCPS_GPS_DATA_GROUP | 0x0 )
-#define PCPS_WRITE_GPS_DATA ( PCPS_GPS_DATA_GROUP | 0x1 )
+#define PCPS_READ_GPS_DATA 0x50
+#define PCPS_WRITE_GPS_DATA 0x51
-
-/* PCPS_CTRL_GROUP */
-#define PCPS_CLR_UCAP_BUFF ( PCPS_CTRL_GROUP | 0x0 )
-#define PCPS_GIVE_UCAP_ENTRIES ( PCPS_CTRL_GROUP | 0x1 )
-#define PCPS_GIVE_UCAP_EVENT ( PCPS_CTRL_GROUP | 0x2 )
+#define PCPS_CLR_UCAP_BUFF 0x60
+#define PCPS_GIVE_UCAP_ENTRIES 0x61
+#define PCPS_GIVE_UCAP_EVENT 0x62
typedef struct
{
@@ -797,11 +824,19 @@ typedef struct
+#define PCPS_GET_CORR_INFO 0x63 // read CORR_INFO structure, only if _pcps_has_pzf()
+#define PCPS_GET_TR_DISTANCE 0x64 // read TR_DISTANCE, only if _pcps_has_tr_distance()
+#define PCPS_SET_TR_DISTANCE 0x65 // write TR_DISTANCE, only if _pcps_has_tr_distance()
+
+
+
/**
special -- use with care !
*/
#define PCPS_FORCE_RESET 0x80
+// Command codes 0xF0 through 0xFF are reserved.
+
/** @} group_cmd_bytes */
@@ -809,7 +844,7 @@ typedef struct
/* to the board */
#define PCPS_SUCCESS 0 /**< OK, no error */
#define PCPS_ERR_STIME -1 /**< invalid date/time/status passed */
-#define PCPS_ERR_CFG -2 /**< invalid parms with a PCPS_CFG_GROUP cmd */
+#define PCPS_ERR_CFG -2 /**< invalid parms for a cmd writing config parameters */
@@ -818,7 +853,7 @@ typedef struct
#endif
-/** The size of the plug-in radio clock's on-board FIFO: */
+/** The size of the plug-in card's on-board FIFO */
#define PCPS_FIFO_SIZE 16
typedef int8_t PCPS_BUFF[PCPS_FIFO_SIZE];
@@ -1013,8 +1048,9 @@ typedef struct PCPS_IRIG_TIME_s
-/* Bit masks used with both PCPS_TIME_STATUS and PCPS_TIME_STATUS_X */
-
+/**
+ * Bit masks used with both PCPS_TIME_STATUS and PCPS_TIME_STATUS_X
+ */
#define PCPS_FREER 0x01 /**< DCF77 clock running on xtal */
/**< GPS receiver has not verified its position */
@@ -1035,20 +1071,29 @@ typedef struct PCPS_IRIG_TIME_s
#define PCPS_INVT 0x80 /**< invalid time because battery was disconn'd */
-/* Bit masks used only with PCPS_TIME_STATUS_X */
-
+/**
+ * Bit masks used only with PCPS_TIME_STATUS_X
+ */
#define PCPS_LS_ENB 0x0100 /**< current second is leap second */
#define PCPS_ANT_FAIL 0x0200 /**< antenna failure */
-#define PCPS_LS_ANN_NEG 0x0400 /**< announced leap second is negative */
+#define PCPS_LS_ANN_NEG 0x0400 /**< announced leap second is negative */
#define PCPS_SCALE_GPS 0x0800 /**< time stamp is GPS scale */
#define PCPS_SCALE_TAI 0x1000 /**< time stamp is TAI scale */
-/* The next two bits are used only if the structure */
-/* PCPS_HR_TIME contains a user capture event */
+/**
+ * Bit masks used only with time stamps representing user capture events
+ */
#define PCPS_UCAP_OVERRUN 0x2000 /**< events interval too short */
#define PCPS_UCAP_BUFFER_FULL 0x4000 /**< events read too slow */
/**
+ * Bit masks used only with time stamps representing the current board time.
+ * A DCF77 PZF receiver can set this bit if it is actually synchronized
+ * using PZF correlation and thus provides higher accuracy than AM receivers.
+ */
+#define PCPS_SYNC_PZF 0x2000 /**< same code as PCPS_UCAP_OVERRUN */
+
+/**
* Immediately after a clock has been accessed, subsequent accesses
* are blocked for up to 1.5 msec to give the clock's microprocessor
* some time to decode the incoming time signal.
@@ -1060,9 +1105,9 @@ typedef struct PCPS_IRIG_TIME_s
*/
#define PCPS_IO_BLOCKED 0x8000
-/**
- This bit mask can be used to extract the time scale information out
- of a PCPS_TIME_STATUS_X value.
+/**
+ * This bit mask can be used to extract the time scale information out
+ * of a PCPS_TIME_STATUS_X value.
*/
#define PCPS_SCALE_MASK ( PCPS_SCALE_TAI | PCPS_SCALE_GPS )
@@ -1152,41 +1197,6 @@ enum
#define PCPS_MOD_SHIFT ( PCPS_BD_BITS + PCPS_FR_BITS )
/* num of bits to shift left */
-/**
- * The fixed-length standard time string being sent on the serial
- * output is described below:
- *
- * \<STX\>D:dd.mm.yy;T:d;U:hh.mm.ss;uvwx\<ETX\>
- *
- * where \<STX\> and \<ETX\> represent the ASCII codes 0x02 and 0x03,
- * 'dd.mm.yy' is the format of the current date, 'd' is the current
- * day of week (1..7, 1 == Monday ) and 'hh.mm.ss' is the format of
- * the current time. The characters 'uvwx' reflect the clock's status:
- *
- * u clock status character:
- * '#' clock has not synchronized after reset
- * ' ' (space, 20h) clock has synchronized after reset
- *
- * v clock status character, different for DCF77 or GPS receivers:
- * '*' DCF77 clock currently runs on XTAL
- * GPS receiver has not checked its position
- * ' ' (space, 20h):
- * DCF77 clock is syncronized with transmitter
- * GPS receiver has determined its position
- *
- * x time zone indicator:
- * 'U' UTC Universal Time, Coordinated
- * ' ' MEZ European Standard Time, daylight saving disabled
- * 'S' MESZ European Summertime, daylight saving enabled
- *
- * y anouncement of discontinuity of time, enabled during last hour
- * before discontinuity comes in effect:
- * '!' announcement of start or end of daylight saving
- * 'A' announcement of leap second insertion
- * ' ' (space, 20h): nothing announced
- */
-
-
/**
* Some definitions used with PZF receivers
@@ -1195,6 +1205,11 @@ enum
/* receiver distance from transmitter [km] */
typedef uint16_t TR_DISTANCE;
+#define _mbg_swab_tr_distance( _p ) \
+ _mbg_swab16( _p )
+
+
+
/* correlation status info */
typedef struct
{
@@ -1204,6 +1219,10 @@ typedef struct
uint8_t signal; /**< signal level, may always be 0 for devices which do not support this */
} CORR_INFO;
+#define _mbg_swab_corr_info( _p ) \
+ _nop_macro_fnc()
+
+
/** Codes used with CORR_INFO::status: */
enum
{
@@ -1214,17 +1233,43 @@ enum
};
+#define PZF_CORR_STATE_NAME_RAW_ENG "Searching"
+#define PZF_CORR_STATE_NAME_CHECK_ENG "Checking"
+#define PZF_CORR_STATE_NAME_FINE_ENG "Synchronized"
+
+#define PZF_CORR_STATE_NAME_RAW_GER "suchen"
+#define PZF_CORR_STATE_NAME_CHECK_GER "eingerastet"
+#define PZF_CORR_STATE_NAME_FINE_GER "synchron"
+
+
+#define PZF_CORR_STATE_NAMES_ENG \
+{ \
+ PZF_CORR_STATE_NAME_RAW_ENG, \
+ PZF_CORR_STATE_NAME_CHECK_ENG, \
+ PZF_CORR_STATE_NAME_FINE_ENG \
+}
+
+
+#define PZF_CORR_STATE_NAMES_LSTR \
+{ \
+ { PZF_CORR_STATE_NAME_RAW_ENG, PZF_CORR_STATE_NAME_RAW_GER }, \
+ { PZF_CORR_STATE_NAME_CHECK_ENG, PZF_CORR_STATE_NAME_CHECK_GER }, \
+ { PZF_CORR_STATE_NAME_FINE_ENG, PZF_CORR_STATE_NAME_FINE_GER } \
+}
+
+
+
/** @defgroup group_gps_cmds_bus GPS commands passed via the system bus
This enumeration defines the various types of data that can be read
from or written to Meinberg bus level devices which support this.
Access should be done using the functions ::pcps_read_gps_data()
and ::pcps_write_gps_data() since the size of some of the structures
- exceeds the size of the devices's I/O buffer and must therefore be
- accessed in several portions.
+ exceeds the size of the device's I/O buffer and must therefore be
+ accessed in several blocks.
The structures to be used are defined in gpsdefs.h. Not all structures
- are supportet, yet. Check the R/W indicators for details.
+ are supported, yet. Check the R/W indicators for details.
* @{ */
enum
@@ -1274,6 +1319,61 @@ enum
PC_GPS_ASCII_MSG // -/- ASCII_MSG the GPS ASCII message
};
+/** @} group_gps_cmds_bus */
+
+
+
+/**
+ * @brief An initializer for a table of code/name entries of GPS commands.
+ *
+ * This can e.g. be assigned to an array of MBG_CODE_NAME_TABLE_ENTRY elements
+ * and may be helpful when debugging.
+ */
+#define MBG_PC_GPS_CMD_TABLE \
+{ \
+ { PC_GPS_TZDL, "PC_GPS_TZDL" }, \
+ { PC_GPS_SW_REV, "PC_GPS_SW_REV" }, \
+ { PC_GPS_BVAR_STAT, "PC_GPS_BVAR_STAT" }, \
+ { PC_GPS_TIME, "PC_GPS_TIME" }, \
+ { PC_GPS_POS_XYZ, "PC_GPS_POS_XYZ" }, \
+ { PC_GPS_POS_LLA, "PC_GPS_POS_LLA" }, \
+ { PC_GPS_PORT_PARM, "PC_GPS_PORT_PARM" }, \
+ { PC_GPS_ANT_INFO, "PC_GPS_ANT_INFO" }, \
+ { PC_GPS_UCAP, "PC_GPS_UCAP" }, \
+ { PC_GPS_ENABLE_FLAGS, "PC_GPS_ENABLE_FLAGS" }, \
+ { PC_GPS_STAT_INFO, "PC_GPS_STAT_INFO" }, \
+ { PC_GPS_CMD, "PC_GPS_CMD" }, \
+ { PC_GPS_IDENT, "PC_GPS_IDENT" }, \
+ { PC_GPS_POS, "PC_GPS_POS" }, \
+ { PC_GPS_ANT_CABLE_LEN, "PC_GPS_ANT_CABLE_LEN" }, \
+ { PC_GPS_RECEIVER_INFO, "PC_GPS_RECEIVER_INFO" }, \
+ { PC_GPS_ALL_STR_TYPE_INFO, "PC_GPS_ALL_STR_TYPE_INFO" }, \
+ { PC_GPS_ALL_PORT_INFO, "PC_GPS_ALL_PORT_INFO" }, \
+ { PC_GPS_PORT_SETTINGS_IDX, "PC_GPS_PORT_SETTINGS_IDX" }, \
+ { PC_GPS_ALL_POUT_INFO, "PC_GPS_ALL_POUT_INFO" }, \
+ { PC_GPS_POUT_SETTINGS_IDX, "PC_GPS_POUT_SETTINGS_IDX" }, \
+ { PC_GPS_TIME_SCALE, "PC_GPS_TIME_SCALE" }, \
+ { PC_GPS_LAN_IF_INFO, "PC_GPS_LAN_IF_INFO" }, \
+ { PC_GPS_IP4_STATE, "PC_GPS_IP4_STATE" }, \
+ { PC_GPS_IP4_SETTINGS, "PC_GPS_IP4_SETTINGS" }, \
+ { PC_GPS_PTP_STATE, "PC_GPS_PTP_STATE" }, \
+ { PC_GPS_PTP_CFG, "PC_GPS_PTP_CFG" }, \
+ { PC_GPS_PTP_UC_MASTER_CFG_LIMITS, "PC_GPS_PTP_UC_MASTER_CFG_LIMITS" }, \
+ { PC_GPS_ALL_PTP_UC_MASTER_INFO, "PC_GPS_ALL_PTP_UC_MASTER_INFO" }, \
+ { PC_GPS_PTP_UC_MASTER_SETTINGS_IDX, "PC_GPS_PTP_UC_MASTER_SETTINGS_IDX" }, \
+ { PC_GPS_GPIO_CFG_LIMITS, "PC_GPS_GPIO_CFG_LIMITS" }, \
+ { PC_GPS_ALL_GPIO_INFO, "PC_GPS_ALL_GPIO_INFO" }, \
+ { PC_GPS_GPIO_SETTINGS_IDX, "PC_GPS_GPIO_SETTINGS_IDX" }, \
+ { PC_GPS_CFGH, "PC_GPS_CFGH" }, \
+ { PC_GPS_ALM, "PC_GPS_ALM" }, \
+ { PC_GPS_EPH, "PC_GPS_EPH" }, \
+ { PC_GPS_UTC, "PC_GPS_UTC" }, \
+ { PC_GPS_IONO, "PC_GPS_IONO" }, \
+ { PC_GPS_ASCII_MSG, "PC_GPS_ASCII_MSG" }, \
+ { 0, NULL } \
+}
+
+
/** codes used with PC_GPS_CMD */
enum
@@ -1285,7 +1385,6 @@ enum
N_PC_GPS_CMD /**< no command, just the number of known commands */
};
-/** @} group_gps_cmds_bus */
// The type below can be used to store an unambiguous command code.
@@ -1296,8 +1395,10 @@ enum
// the associated PC_GPS_... type code.
typedef uint16_t PCPS_CMD_INFO;
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/pcpsdev.h b/mbglib/common/pcpsdev.h
index e83958b..63c5ce7 100755
--- a/mbglib/common/pcpsdev.h
+++ b/mbglib/common/pcpsdev.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: pcpsdev.h 1.49.1.36 2011/05/06 13:47:38 martin TRASH $
+ * $Id: pcpsdev.h 1.49.1.57 2011/09/21 16:03:04 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -17,7 +17,45 @@
*
* -----------------------------------------------------------------------
* $Log: pcpsdev.h $
- * Revision 1.49.1.36 2011/05/06 13:47:38 martin
+ * Revision 1.49.1.57 2011/09/21 16:03:04 martin
+ * Moved some definitions useful for configuration tools to new file cfg_hlp.h.
+ * Revision 1.49.1.56 2011/09/20 08:31:22 martin
+ * Modified default features for PZF180PEX.
+ * Revision 1.49.1.55 2011/09/12 12:32:38Z martin
+ * Revision 1.49.1.54 2011/09/12 09:45:12 martin
+ * Fixed a typo (missing comma).
+ * Revision 1.49.1.53 2011/08/05 11:02:28 martin
+ * Revision 1.49.1.52 2011/07/19 10:41:48 martin
+ * Revision 1.49.1.51 2011/07/14 13:29:14 martin
+ * Revision 1.49.1.50 2011/07/13 09:44:53 martin
+ * Moved IA64 includes from pcpsdev.h to mbgpccyc.h.
+ * Revision 1.49.1.49 2011/07/06 13:23:24 martin
+ * Revision 1.49.1.48 2011/07/06 11:22:50 martin
+ * Added macros _pcps_has_corr_info() and _pcps_has_tr_distance().
+ * Revision 1.49.1.47 2011/07/05 12:25:19 martin
+ * Revision 1.49.1.46 2011/07/04 10:29:44 martin
+ * Modified a comment.
+ * Revision 1.49.1.45 2011/06/29 14:06:08 martin
+ * Added support for TCR600USB, MSF600USB, and WVB600USB.
+ * Extended bus flag for USB v2 and macro _pcps_is_usb_v2().
+ * New feature ..._HAS_PZF and macro _pcps_has_pzf().
+ * Revision 1.49.1.44 2011/06/29 09:10:26 martin
+ * Renamed PZF600PEX to PZF180PEX.
+ * Revision 1.49.1.43 2011/06/24 10:26:52 martin
+ * Fixed warning under DOS.
+ * Revision 1.49.1.42 2011/06/24 08:07:03Z martin
+ * Moved PC cycles stuff to an new extra header.
+ * Revision 1.49.1.41 2011/06/21 15:17:36 martin
+ * Fixed build under DOS.
+ * Revision 1.49.1.40 2011/06/21 14:23:59Z martin
+ * Cleaned up handling of pragma pack().
+ * Introduced generic MBG_SYS_TIME with nanosecond resolution.
+ * Support struct timespec under Linux, if available.
+ * Revision 1.49.1.39 2011/06/01 09:29:09 martin
+ * Revision 1.49.1.38 2011/05/31 14:20:54 martin
+ * Revision 1.49.1.37 2011/05/16 13:18:38 martin
+ * Use MBG_TGT_KERNEL instead of _KDD_.
+ * Revision 1.49.1.36 2011/05/06 13:47:38Z martin
* Support PZF600PEX.
* Revision 1.49.1.35 2011/04/19 15:06:24 martin
* Added PTP unicast master configuration stuff.
@@ -260,71 +298,75 @@
#ifndef _PCPSDEV_H
#define _PCPSDEV_H
+#include <mbg_tgt.h>
+#include <mbgtime.h>
+#include <mbgpccyc.h>
#include <pcpsdefs.h>
#include <gpsdefs.h>
#include <usbdefs.h>
-#include <mbg_tgt.h>
-#include <mbgtime.h>
#include <use_pack.h>
#if defined( MBG_TGT_LINUX )
- #if !defined( USE_TIMESPEC )
- #define USE_TIMESPEC 0
- #endif
-
#if defined( MBG_TGT_KERNEL )
#include <linux/delay.h>
#include <linux/time.h>
#else
#include <unistd.h>
+ #include <time.h>
#include <sys/time.h>
#include <sys/sysinfo.h>
#endif
- #if defined( MBG_ARCH_IA64 )
- #include <asm/ia64regs.h>
- #include <asm/intel_intrin.h>
- #endif
-
-#endif
-
-#if defined( MBG_TGT_BSD )
+#elif defined( MBG_TGT_FREEBSD )
- #if !defined( USE_TIMESPEC )
- #define USE_TIMESPEC 1
+ #if defined( MBG_TGT_KERNEL )
+ #include <sys/sysproto.h>
+ #include <sys/pcpu.h>
+ #else
+ #include <sys/time.h>
#endif
- #if defined( MBG_TGT_FREEBSD ) && defined( MBG_ARCH_X86 ) && defined( MBG_TGT_KERNEL )
- #include <machine/clock.h> /* for symbol 'tsc_freq' */
- #endif
+#elif defined( MBG_TGT_NETBSD )
- #if defined( MBG_TGT_NETBSD ) && defined( MBG_TGT_KERNEL )
- #include <machine/cpu.h>
- #include <machine/cpu_counter.h> /* for cycle counter abstraction */
+ #if !defined( MBG_TGT_KERNEL )
+ #include <sys/time.h>
#endif
-#endif
+#elif defined( MBG_TGT_DOS )
-#if defined( MBG_TGT_DOS )
#include <dos.h> // for delay()
-#endif
+#endif
/* Start of header body */
-#if defined( MBG_ARCH_SPARC ) || defined( MBG_ARCH_IA64 )
- #undef _USE_PACK // don't pack interface structures
+#if defined( _USE_PACK )
+ #if !defined( _NO_USE_PACK_INTF )
+ #pragma pack( 1 ) // set byte alignment
+ #define _USING_BYTE_ALIGNMENT
+ #endif
#endif
-#if defined( _USE_PACK ) // set byte alignment
- #pragma pack( 1 )
+
+#if defined( MBG_TGT_UNIX )
+ #define USE_GENERIC_SYS_TIME 1
+#else
+ #define USE_GENERIC_SYS_TIME 0
#endif
-#if !defined( USE_TIMESPEC )
- #define USE_TIMESPEC 0
+#if USE_GENERIC_SYS_TIME
+
+ typedef struct
+ {
+ uint64_t sec;
+ uint64_t nsec;
+ } NANO_TIME_64;
+
+ typedef NANO_TIME_64 MBG_SYS_TIME;
+
#endif
@@ -341,10 +383,6 @@
#define MBG_TGT_SUPP_MEM_ACC 1
- // used with QueryPerformanceCounter()
- typedef int64_t MBG_PC_CYCLES;
- typedef uint64_t MBG_PC_CYCLES_FREQUENCY;
-
typedef int64_t MBG_SYS_UPTIME; // [s]
typedef LARGE_INTEGER MBG_SYS_TIME;
@@ -353,35 +391,14 @@
#define MBG_TGT_SUPP_MEM_ACC 1
- typedef uint64_t MBG_PC_CYCLES;
- typedef uint64_t MBG_PC_CYCLES_FREQUENCY;
-
typedef int64_t MBG_SYS_UPTIME; // [s]
- typedef struct timeval MBG_SYS_TIME;
-
#elif defined( MBG_TGT_BSD )
#define MBG_TGT_SUPP_MEM_ACC 1
- typedef uint64_t MBG_PC_CYCLES;
- typedef uint64_t MBG_PC_CYCLES_FREQUENCY;
-
typedef int64_t MBG_SYS_UPTIME; // [s]
- #if USE_TIMESPEC
- typedef struct timespec MBG_SYS_TIME;
- #else
- typedef struct timeval MBG_SYS_TIME;
- #endif
-
- #if defined( MBG_TGT_FREEBSD ) && defined( MBG_TGT_KERNEL )
- #include <sys/sysproto.h>
- #include <sys/pcpu.h>
- #else
- #include <sys/time.h>
- #endif
-
#if defined( MBG_TGT_NETBSD )
#ifdef __LP64__
#define MBG_MEM_ADDR uint64_t
@@ -392,17 +409,12 @@
#elif defined( MBG_TGT_OS2 )
- typedef uint32_t MBG_PC_CYCLES; //##++ should differentiate more
- typedef uint32_t MBG_PC_CYCLES_FREQUENCY;
-
typedef long MBG_SYS_UPTIME; //## dummy
typedef uint32_t MBG_SYS_TIME; //## dummy
#elif defined( MBG_TGT_DOS )
- typedef uint32_t MBG_PC_CYCLES; //##++ should differentiate more
- typedef uint32_t MBG_PC_CYCLES_FREQUENCY;
#define MBG_MEM_ADDR uint32_t // 64 bit not supported, nor required.
typedef long MBG_SYS_UPTIME; //## dummy
@@ -411,9 +423,6 @@
#else // other target OSs which access the hardware directly
- typedef uint32_t MBG_PC_CYCLES; //##++ should differentiate more
- typedef uint32_t MBG_PC_CYCLES_FREQUENCY;
-
typedef long MBG_SYS_UPTIME; //## dummy
typedef uint32_t MBG_SYS_TIME; //## dummy
@@ -426,14 +435,8 @@
#endif
-// MBG_PC_CYCLES, MBG_PC_CYCLES_FREQUENCY, and MBG_SYS_TIME are always read
-// in native machine endianess, so no endianess conversion is required.
-#define _mbg_swab_mbg_pc_cycles( _p ) \
- _nop_macro_fnc()
-
-#define _mbg_swab_mbg_pc_cycles_frequency( _p ) \
- _nop_macro_fnc()
-
+// MBG_SYS_TIME is always read in native machine endianess,
+// so no endianess conversion is required.
#define _mbg_swab_mbg_sys_time( _p ) \
_nop_macro_fnc()
@@ -465,253 +468,76 @@ typedef struct
-#if ( defined( MBG_TGT_LINUX ) || defined( MBG_TGT_BSD ) ) && defined( MBG_ARCH_X86 )
-
- static __mbg_inline unsigned long long int mbg_rdtscll( void )
- {
- // The code below is a hack to get around issues with
- // different versions of gcc.
- //
- // Normally the inline asm code could look similar to:
- //
- // __asm__ volatile ( "rdtsc" : "=A" (x) )
- //
- // which would copy the output regs edx:eax as a 64 bit
- // number to a variable x.
- //
- // The "=A" expression should implicitely tell the compiler
- // the edx and eax registers have been clobbered. However,
- // this does not seem to work properly at least with gcc 4.1.2
- // shipped with Centos 5.
- //
- // If optimization level 1 or higher is used then function
- // parameters are also passed in registers. If the inline
- // code above is used inside a function then the edx register
- // is clobbered but the gcc 4.1.2 is not aware of this and
- // assumes edx is unchanged, which may yield faulty results
- // or even lead to segmentation faults.
- //
- // A possible workaround could be to mark edx explicitely as
- // being clobbered in the asm inline code, but unfortunately
- // other gcc versions report an error if a register which is
- // implicitely (by "=A") known to be clobbered is also listed
- // explicitely to be clobbered.
- //
- // So the code below is a workaround which tells the compiler
- // implicitely that the eax ("=a") and edx ("=d") registers
- // are being used and thus clobbered.
-
- union
- {
- struct
- {
- uint32_t lo;
- uint32_t hi;
- } u32;
-
- uint64_t u64;
-
- } tsc_val;
-
- __asm__ __volatile__( "rdtsc" : "=a" (tsc_val.u32.lo), "=d" (tsc_val.u32.hi) );
-
- return tsc_val.u64;
-
- } // mbg_rdtscll
-
-#endif
-
-
-
static __mbg_inline
-void mbg_get_pc_cycles( MBG_PC_CYCLES *p )
+void mbg_get_sys_time( MBG_SYS_TIME *p )
{
#if defined( MBG_TGT_WIN32 )
- #if defined( _KDD_ ) // kernel space
- *p = (MBG_PC_CYCLES) KeQueryPerformanceCounter( NULL ).QuadPart;
- #else // user space
- QueryPerformanceCounter( (LARGE_INTEGER *) p );
- #endif
-
- #define MBG_PC_CYCLES_SUPPORTED 1
-
- #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_X86 )
-
- #if 0 && ( defined( CONFIG_X86_TSC ) || defined( CONFIG_M586TSC ) ) //##++++
- #define _pcps_get_cycles( _c ) \
- _c = get_cycles()
- #else
- *p = mbg_rdtscll();
+ #if defined( MBG_TGT_KERNEL ) // kernel space
+ KeQuerySystemTime( p );
+ #else // user space
+ {
+ FILETIME ft;
+ GetSystemTimeAsFileTime( &ft );
+ p->LowPart = ft.dwLowDateTime;
+ p->HighPart = ft.dwHighDateTime;
+ }
#endif
- #define MBG_PC_CYCLES_SUPPORTED 1
-
- #elif defined( MBG_TGT_NETBSD ) && defined ( MBG_TGT_KERNEL )
-
- *p = cpu_counter(); //##++ or cpu_counter_serializing()
-
- #define MBG_PC_CYCLES_SUPPORTED 1
-
- #elif defined( MBG_TGT_BSD ) && defined( MBG_ARCH_X86 )
-
- *p = mbg_rdtscll();
+ #elif defined( MBG_TGT_LINUX )
- #define MBG_PC_CYCLES_SUPPORTED 1
+ #if defined( MBG_TGT_KERNEL )
- #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_IA64 )
+ #if ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 22 ) ) //##+++++++++++++
+ {
+ // getnstimeofday() supported
+ struct timespec ts;
- unsigned long result = ia64_getreg( _IA64_REG_AR_ITC );
- ia64_barrier();
+ getnstimeofday( &ts );
- #ifdef CONFIG_ITANIUM
- while (unlikely((__s32) result == -1)) {
- result = ia64_getreg(_IA64_REG_AR_ITC);
- ia64_barrier();
+ p->sec = ts.tv_sec;
+ p->nsec = ts.tv_nsec;
}
- #endif
-
- *p = result;
-
- #define MBG_PC_CYCLES_SUPPORTED 1
-
- #else
-
- *p = 0;
-
- #endif
-
-} // mbg_get_pc_cycles
-
-
-
-static __mbg_inline
-void mbg_get_pc_cycles_frequency( MBG_PC_CYCLES_FREQUENCY *p )
-{
- #if defined( MBG_TGT_WIN32 )
- LARGE_INTEGER li;
-
- #if defined( _KDD_ ) // kernel space
- KeQueryPerformanceCounter( &li );
- #else // user space
- QueryPerformanceFrequency( &li );
- #endif
-
- *p = li.QuadPart;
-
- #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_X86 )
+ #else
+ {
+ // getnstimeofday() *not* supported
+ struct timeval tv;
- #if defined( MBG_TGT_KERNEL )
+ do_gettimeofday( &tv );
- *p = ( cpu_khz * 1000 );
+ p->sec = tv.tv_sec;
+ p->nsec = tv.tv_usec * 1000;
+ }
+ #endif
- #else
+ #else // Linux user space
+ {
+ struct timespec ts;
- *p = 0;
+ clock_gettime( CLOCK_REALTIME, &ts );
+ p->sec = ts.tv_sec;
+ p->nsec = ts.tv_nsec;
+ }
#endif
- #elif defined( MBG_TGT_LINUX ) && defined( MBG_ARCH_IA64 )
-
- #error A way to get cycles frequency needs to be defined for Linux/IA64.
-
- // we probably can use
- // ia64_sal_freq_base(unsigned long which, unsigned long *ticks_per_second,
- // unsigned long *drift_info)
- // However, this is not tested.
-
#elif defined( MBG_TGT_BSD )
- #if defined( MBG_TGT_FREEBSD ) && defined( MBG_ARCH_X86 ) && defined( MBG_TGT_KERNEL )
-
- *p = tsc_freq;
-
- #elif defined( MBG_TGT_NETBSD ) && defined( MBG_TGT_KERNEL )
-
- *p = cpu_frequency( curcpu() );
-
- #else
-
- *p = 0;
-
- #endif
-
- #else
-
- #if MBG_PC_CYCLES_SUPPORTED
-
- #error A way to get cycles frequency needs to be defined for this target.
-
- #else
- *p = 0;
- #endif
-
- #endif
-
-} // mbg_get_pc_cycles_frequency
-
-
-
-static __mbg_inline
-MBG_PC_CYCLES mbg_delta_pc_cycles( const MBG_PC_CYCLES *p1, const MBG_PC_CYCLES *p2 )
-{
-#if !defined( MBG_PC_CYCLES_SUPPORTED )
- // Cycle counts not supported on this target platform.
- // Under SPARC this may even result in bus errors
- // due to alignment of the underlying data structures.
- return 0;
-#else
- return *p1 - *p2;
-#endif
-
-} // mbg_delta_pc_cycles
-
-
-
-static __mbg_inline
-void mbg_get_sys_time( MBG_SYS_TIME *p )
-{
- #if defined( MBG_TGT_WIN32 )
-
- #if defined( _KDD_ ) // kernel space
- KeQuerySystemTime( p );
- #else // user space
- {
- FILETIME ft;
- GetSystemTimeAsFileTime( &ft );
- p->LowPart = ft.dwLowDateTime;
- p->HighPart = ft.dwHighDateTime;
- }
- #endif
-
- #elif defined( MBG_TGT_LINUX )
+ struct timespec ts;
#if defined( MBG_TGT_KERNEL )
- do_gettimeofday( p );
+ nanotime( &ts );
#else
- gettimeofday( p, NULL );
- #endif
-
- #elif defined( MBG_TGT_BSD )
-
- #if USE_TIMESPEC // use struct timespec
- #if defined( MBG_TGT_KERNEL )
- nanotime( p );
- #else
- #if defined( MBG_TGT_FREEBSD )
- clock_gettime( CLOCK_REALTIME_PRECISE, p );
- #else // MBG_TGT_NETBSD, ...
- clock_gettime( CLOCK_REALTIME, p );
- #endif
- #endif
- #else // use struct timeval
- #if defined( MBG_TGT_KERNEL )
- microtime( p );
- #else
- gettimeofday( p, NULL );
+ #if defined( MBG_TGT_FREEBSD )
+ clock_gettime( CLOCK_REALTIME_PRECISE, &ts );
+ #else // MBG_TGT_NETBSD, ...
+ clock_gettime( CLOCK_REALTIME, &ts );
#endif
#endif
+ p->sec = ts.tv_sec;
+ p->nsec = ts.tv_nsec;
+
#else
*p = 0;
@@ -727,7 +553,7 @@ void mbg_get_sys_uptime( MBG_SYS_UPTIME *p )
{
#if defined( MBG_TGT_WIN32 )
- #if defined( _KDD_ ) // kernel space
+ #if defined( MBG_TGT_KERNEL ) // kernel space
ULONGLONG time_increment = KeQueryTimeIncrement();
LARGE_INTEGER tick_count;
@@ -738,7 +564,7 @@ void mbg_get_sys_uptime( MBG_SYS_UPTIME *p )
// but we need seconds
*p = ( tick_count.QuadPart * time_increment ) / HNS_PER_SEC;
- #else // user space
+ #else // user space
DWORD tickCount;
DWORD timeAdjustment;
@@ -818,7 +644,7 @@ void mbg_sleep_sec( long sec )
{
#if defined( MBG_TGT_WIN32 )
- #if defined( _KDD_ ) // kernel space
+ #if defined( MBG_TGT_KERNEL ) // kernel space
LARGE_INTEGER delay;
// we need to pass a negative value to KeDelayExecutionThread()
@@ -827,7 +653,7 @@ void mbg_sleep_sec( long sec )
delay.QuadPart = (LONGLONG) sec * HNS_PER_SEC;
KeDelayExecutionThread( KernelMode, FALSE, &delay );
- #else // user space
+ #else // user space
// Sleep() expects milliseconds
Sleep( sec * 1000 );
#endif
@@ -855,7 +681,7 @@ void mbg_sleep_sec( long sec )
#elif defined( MBG_TGT_DOS )
- delay( sec * 1000 );
+ delay( (unsigned) ( sec * 1000 ) );
#else
@@ -887,26 +713,18 @@ typedef uint16_t MBG_DBG_PORT;
#define PCPS_BUS_PCI 0x0004 // PCI
#define PCPS_BUS_USB 0x0008 // USB
+
// The flags below are or'ed to the PC_BUS_PCI code
// in order to indicate which PCI interface chip is used
// on a PCI card. If no flag is set then the S5933 chip is
// installed which has been used for the first generation
// of Meinberg PCI cards.
+#define PCPS_BUS_PCI_CHIP_S5920 0x8000 // S5920 PCI interface chip.
+#define PCPS_BUS_PCI_CHIP_ASIC 0x4000 // Meinberg's own PCI interface chip.
+#define PCPS_BUS_PCI_CHIP_PEX8311 0x2000 // PEX8311 PCI Express interface chip
+#define PCPS_BUS_PCI_CHIP_MBGPEX 0x1000 // Meinberg's own PCI Express interface chip
-// S5920 PCI interface chip.
-#define PCPS_BUS_PCI_CHIP_S5920 0x8000
-
-// Meinberg's own PCI interface chip.
-#define PCPS_BUS_PCI_CHIP_ASIC 0x4000
-
-// PEX8311 PCI Express interface chip
-#define PCPS_BUS_PCI_CHIP_PEX8311 0x2000
-
-// Meinberg's own PCI Express interface chip
-#define PCPS_BUS_PCI_CHIP_MBGPEX 0x1000
-
-
-// The constant below combines the PCI bus flags.
+// The constants below combine the PCI bus flags:
#define PCPS_BUS_PCI_S5933 ( PCPS_BUS_PCI )
#define PCPS_BUS_PCI_S5920 ( PCPS_BUS_PCI | PCPS_BUS_PCI_CHIP_S5920 )
#define PCPS_BUS_PCI_ASIC ( PCPS_BUS_PCI | PCPS_BUS_PCI_CHIP_ASIC )
@@ -914,6 +732,16 @@ typedef uint16_t MBG_DBG_PORT;
#define PCPS_BUS_PCI_MBGPEX ( PCPS_BUS_PCI | PCPS_BUS_PCI_CHIP_MBGPEX )
+// The flags below are or'ed to the PCPS_BUS_USB code
+// in order to indicate which USB protocol version
+// is supported by the device. If no additional flag is set
+// then the device has a USB v1 interface.
+#define PCPS_BUS_USB_FLAG_V2 0x8000
+
+// The constant below combines the PCI bus flags:
+#define PCPS_BUS_USB_V2 ( PCPS_BUS_USB | PCPS_BUS_USB_FLAG_V2 )
+
+
/** A list of known radio clocks. */
enum PCPS_TYPES
@@ -947,7 +775,10 @@ enum PCPS_TYPES
PCPS_TYPE_GPS180PEX,
PCPS_TYPE_TCR180PEX,
PCPS_TYPE_DCF600USB,
- PCPS_TYPE_PZF600PEX,
+ PCPS_TYPE_PZF180PEX,
+ PCPS_TYPE_TCR600USB,
+ PCPS_TYPE_MSF600USB,
+ PCPS_TYPE_WVB600USB,
N_PCPS_DEV_TYPE
};
@@ -975,10 +806,10 @@ typedef struct
-#if !defined( MBG_TGT_LINUX ) || defined( MBG_ARCH_X86 )
+#if !defined( MBG_TGT_UNIX ) || defined( MBG_ARCH_X86 )
typedef uint16_t PCPS_PORT_ADDR;
#else
- typedef ulong PCPS_PORT_ADDR;
+ typedef uint64_t PCPS_PORT_ADDR;
#endif
@@ -1001,9 +832,11 @@ typedef struct
typedef struct
{
MBG_MEM_ADDR user_virtual_address;
- ulong len;
#if defined( MBG_TGT_LINUX )
- uint32_t pfn_offset;
+ uint64_t len;
+ uint64_t pfn_offset;
+ #else
+ ulong len;
#endif
} PCPS_MAPPED_MEM;
@@ -1069,6 +902,7 @@ enum
PCPS_BIT_HAS_UTC_OFFS,
PCPS_BIT_HAS_HR_TIME,
PCPS_BIT_HAS_SERNUM,
+
PCPS_BIT_HAS_TZCODE,
PCPS_BIT_HAS_CABLE_LEN,
PCPS_BIT_HAS_EVENT_TIME, // custom GPS firmware only
@@ -1077,6 +911,7 @@ enum
PCPS_BIT_HAS_PCPS_TZDL,
PCPS_BIT_HAS_UCAP,
PCPS_BIT_HAS_IRIG_TX,
+
PCPS_BIT_HAS_GPS_DATA_16, // use 16 bit size specifiers
PCPS_BIT_HAS_SYNTH,
PCPS_BIT_HAS_GENERIC_IO,
@@ -1085,10 +920,13 @@ enum
PCPS_BIT_HAS_IRIG_CTRL_BITS,
PCPS_BIT_HAS_LAN_INTF,
PCPS_BIT_HAS_PTP,
+
PCPS_BIT_HAS_IRIG_TIME,
PCPS_BIT_HAS_FAST_HR_TSTAMP,
PCPS_BIT_HAS_RAW_IRIG_DATA,
- N_PCPS_FEATURE
+ PCPS_BIT_HAS_PZF, // can also demodulate DCF77 PZF
+
+ N_PCPS_FEATURE // must not exceed 32 !!
};
@@ -1119,6 +957,7 @@ enum
#define PCPS_HAS_IRIG_TIME ( 1UL << PCPS_BIT_HAS_IRIG_TIME )
#define PCPS_HAS_FAST_HR_TSTAMP ( 1UL << PCPS_BIT_HAS_FAST_HR_TSTAMP )
#define PCPS_HAS_RAW_IRIG_DATA ( 1UL << PCPS_BIT_HAS_RAW_IRIG_DATA )
+#define PCPS_HAS_PZF ( 1UL << PCPS_BIT_HAS_PZF )
@@ -1150,7 +989,8 @@ enum
"PCPS_HAS_PTP", \
"PCPS_HAS_IRIG_TIME", \
"PCPS_HAS_FAST_HR_TSTAMP", \
- "PCPS_HAS_RAW_IRIG_DATA" \
+ "PCPS_HAS_RAW_IRIG_DATA", \
+ "PCPS_HAS_PZF" \
}
/** @} */
@@ -1276,9 +1116,29 @@ enum
#define PCPS_FEAT_DCF600USB ( PCPS_FEAT_USB5131 )
-#define PCPS_FEAT_PZF600PEX ( PCPS_FEAT_PEX511 ) //##++++++ PZF reception as feature ??
+#define PCPS_FEAT_PZF180PEX ( PCPS_FEAT_LVL2 \
+ | PCPS_HAS_TZDL \
+ | PCPS_HAS_HR_TIME \
+ | PCPS_HAS_SERNUM \
+ | PCPS_HAS_RECEIVER_INFO \
+ | PCPS_CAN_CLR_UCAP_BUFF \
+ | PCPS_HAS_UCAP \
+ | PCPS_HAS_GPS_DATA_16 \
+ | PCPS_HAS_GENERIC_IO \
+ | PCPS_HAS_TIME_SCALE \
+ | PCPS_HAS_UTC_PARM \
+ | PCPS_HAS_PZF )
+
+#define PCPS_FEAT_TCR600USB ( PCPS_FEAT_TCR51USB \
+ | PCPS_HAS_IRIG_CTRL_BITS \
+ | PCPS_HAS_IRIG_TIME \
+ | PCPS_HAS_RAW_IRIG_DATA )
+
+#define PCPS_FEAT_MSF600USB ( PCPS_FEAT_MSF51USB )
-// Some features of the API used to access Meinberg plug-in radio clocks
+#define PCPS_FEAT_WVB600USB ( PCPS_FEAT_WWVB51USB )
+
+// Some features of the API used to access Meinberg plug-in devices
// have been implemented starting with the special firmware revision
// numbers defined below.
//
@@ -1367,7 +1227,7 @@ enum
/* command PCPS_GIVE_TIME_NOCLEAR: */
// This is supported by all clocks but PC31/PS31 with
-// firmware versions before v3.0. If such a card shall
+// firmware versions before v3.0. If such a card shall
// be used then the firmware should be updated to the
// last recent version.
@@ -1409,11 +1269,14 @@ typedef struct
#define _pcps_is_lwr( _d ) ( _pcps_is_dcf( _d ) || _pcps_is_msf( _d ) || _pcps_is_wwvb( _d ) )
+// Generic bus types:
#define _pcps_is_isa( _d ) ( _pcps_bus_flags( _d ) & PCPS_BUS_ISA )
#define _pcps_is_mca( _d ) ( _pcps_bus_flags( _d ) & PCPS_BUS_MCA )
#define _pcps_is_pci( _d ) ( _pcps_bus_flags( _d ) & PCPS_BUS_PCI )
#define _pcps_is_usb( _d ) ( _pcps_bus_flags( _d ) & PCPS_BUS_USB )
+// Special bus types:
+#define _pcps_is_usb_v2( _d ) ( _pcps_bus_flags( _d ) == PCPS_BUS_USB_V2 )
#define _pcps_is_pci_s5933( _d ) ( _pcps_bus_flags( _d ) == PCPS_BUS_PCI_S5933 )
#define _pcps_is_pci_s5920( _d ) ( _pcps_bus_flags( _d ) == PCPS_BUS_PCI_S5920 )
#define _pcps_is_pci_amcc( _d ) ( _pcps_is_pci_s5920( _d ) || _pcps_is_pci_s5933( _d ) )
@@ -1423,8 +1286,8 @@ typedef struct
// Access device configuration information:
-#define _pcps_bus_num( _d ) ( (_d)->cfg.bus_num )
-#define _pcps_slot_num( _d ) ( (_d)->cfg.slot_num )
+#define _pcps_bus_num( _d ) ( (_d)->cfg.bus_num )
+#define _pcps_slot_num( _d ) ( (_d)->cfg.slot_num )
#define _pcps_cfg_port_rsrc( _c, _n ) ( (_c)->port[_n] )
#define _pcps_port_rsrc( _d, _n ) _pcps_cfg_port_rsrc( &(_d)->cfg, (_n) )
@@ -1445,7 +1308,7 @@ typedef struct
#define _pcps_sernum( _d ) ( (_d)->cfg.sernum )
-// The macros below handle the clock device's err_flags.
+// The macros below handle the device's err_flags.
#define _pcps_err_flags( _d ) ( (_d)->cfg.err_flags )
#define _pcps_chk_err_flags( _d, _msk ) ( _pcps_err_flags( _d ) & (_msk) )
#define _pcps_set_err_flags( _d, _msk ) ( _pcps_err_flags( _d ) |= (_msk) )
@@ -1499,7 +1362,6 @@ typedef struct
#define _pcps_has_mod( _d ) \
( _pcps_is_dcf( _d ) || _pcps_is_msf( _d ) || _pcps_is_wwvb( _d ) )
-
#define _pcps_has_irig( _d ) \
( _pcps_is_irig_rx( _d ) || _pcps_has_irig_tx( _d ) )
@@ -1534,6 +1396,12 @@ typedef struct
#define _pcps_has_utc_parm( _d ) _pcps_has_feature( (_d), PCPS_HAS_UTC_PARM )
+#define _pcps_has_asic_version( _d ) ( _pcps_is_pci_asic( _d ) \
+ || _pcps_is_pci_pex8311( _d ) \
+ || _pcps_is_pci_mbgpex( _d ) )
+
+#define _pcps_has_asic_features( _d ) _pcps_has_asic_version( _d )
+
#define _pcps_has_fast_hr_timestamp( _d ) _pcps_has_feature( (_d), PCPS_HAS_FAST_HR_TSTAMP )
#define _pcps_has_lan_intf( _d ) _pcps_has_feature( (_d), PCPS_HAS_LAN_INTF )
@@ -1542,12 +1410,11 @@ typedef struct
#define _pcps_has_ri_ptp_unicast( _p_ri ) _pcps_has_ri_feature( (_p_ri), GPS_HAS_PTP_UNICAST )
-#define _pcps_has_asic_version( _d ) ( _pcps_is_pci_asic( _d ) \
- || _pcps_is_pci_pex8311( _d ) \
- || _pcps_is_pci_mbgpex( _d ) )
+#define _pcps_has_pzf( _d ) _pcps_has_feature( (_d), PCPS_HAS_PZF )
-#define _pcps_has_asic_features( _d ) _pcps_has_asic_version( _d )
+#define _pcps_has_corr_info( _d ) _pcps_has_pzf( _d )
+#define _pcps_has_tr_distance( _d ) _pcps_has_pzf( _d )
// There are some versions of IRIG receiver cards which ignore the TFOM code
@@ -1566,6 +1433,22 @@ typedef struct
|| ( ( _pcps_type_num( _d ) == PCPS_TYPE_TCR170PEX ) && ( _pcps_fw_rev_num( _d ) <= 0x103 ) ) )
+// Some Meinberg PCI Express cards have a PCIe interface chip with an extra
+// PCI bridge built into the chip. Unfortunately there are some mainboards out there
+// which do not handle PCI resources behind this PCI bridge correctly. The symptom is
+// usually that both I/O address ranges of these cards get the same base address
+// assigned by the BIOS, and the efeect is that in this case a card is not accessible
+// properly, since both I/O ranges try to respond to the same I/O addresses.
+// As a consequence data read from the card is usually garbage.
+// The only known fix for this is a BIOS update for the mainboard which makes the
+// BIOS handle the card's resources properly.
+
+// The macro below can be used to test if both port base addresses assigned to a card
+// are identical, and thus the BIOS is probably faulty::
+#define _pcps_pci_cfg_err( _d ) \
+ ( _pcps_is_pci( _d ) && ( _pcps_port_base( _d, 1 ) == _pcps_port_base( _d, 0 ) ) )
+
+
/**
The structure is used to return info
@@ -1579,54 +1462,6 @@ typedef struct
-/*
- * The definitions and types below are used to collect
- * all configuration parameters of a clock's serial ports
- * that can be handled by this library:
- */
-
-// The maximum number of clocks' serial ports and string types
-// that can be handled by the configuration programs:
-#define MAX_PARM_PORT 4
-#define MAX_PARM_STR_TYPE 20
-
-typedef PORT_INFO_IDX ALL_PORT_INFO[MAX_PARM_PORT];
-typedef STR_TYPE_INFO_IDX ALL_STR_TYPE_INFO[MAX_PARM_STR_TYPE];
-
-typedef struct
-{
- ALL_PORT_INFO pii;
- ALL_STR_TYPE_INFO stii;
- PORT_PARM tmp_pp;
-
-} RECEIVER_PORT_CFG;
-
-
-
-/*
- * The definitions and types below are used to collect
- * all configuration parameters of a clock's programmable
- * pulse outputs that can be handled by this library:
- */
-
-#define MAX_PARM_POUT 4
-
-typedef POUT_INFO_IDX ALL_POUT_INFO[MAX_PARM_POUT];
-
-
-
-/*
- * The definitions and types below are used to collect
- * all configuration parameters of PTP device's unicast
- * master specification:
- */
-
-#define MAX_PARM_PTP_UC_MASTER 4
-
-typedef PTP_UC_MASTER_INFO_IDX ALL_PTP_UC_MASTER_INFO[MAX_PARM_PTP_UC_MASTER];
-
-
-
// The macros below can be used to mark a PCPS_TIME variable
// as unread, i.e. its contents have not been read from the clock,
// and to check if such a variable is marked as unread.
@@ -1745,8 +1580,9 @@ typedef uint32_t PCPS_IRQ_STAT_INFO;
( (_v) & 0xFF )
-#if defined( _USE_PACK ) // set default alignment
- #pragma pack()
+#if defined( _USING_BYTE_ALIGNMENT )
+ #pragma pack() // set default alignment
+ #undef _USING_BYTE_ALIGNMENT
#endif
/* End of header body */
diff --git a/mbglib/common/pcpsdrvr.c b/mbglib/common/pcpsdrvr.c
index 7c2f754..ff71feb 100755
--- a/mbglib/common/pcpsdrvr.c
+++ b/mbglib/common/pcpsdrvr.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: pcpsdrvr.c 1.46.2.39 2011/05/06 13:47:39 martin TRASH $
+ * $Id: pcpsdrvr.c 1.46.2.53 2011/10/06 13:35:06 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -20,17 +20,19 @@
* under the different operating systems. If required, each of
* those symbols can be overridden by compiler arguments.
*
- * Basically the following radio clocks are supported:
- * USB: USB5131, TCR51USB, MSF51USB, WWVB51USB, DCF600USB
+ * Basically the following devices are supported:
+ * USB v2: DCF600USB, TCR600USB, MSF600USB, WVB600USB
+ * USB v1: USB5131, TCR51USB, MSF51USB, WWVB51USB
* PCI express: PEX511, TCR511PEX, GPS170PEX, PTP270PEX,
* FRC511PEX, TCR170PEX, GPS180PEX, TCR180PEX
+ * PZF180PEX
* PCI bus 5V/3.3V: PCI510, PCI511, GPS169PCI, GPS170PCI,
* TCR510PCI, TCR167PCI, TCR511PCI
* PCI bus 5V: PCI32, GPS167PCI, PCI509, GPS168PCI
* MCA bus: PS31
* ISA bus: PC31, PC32, GPS167PC
*
- * USB is not supported for some target environments, mainly because
+ * USB is not supported for some target environments, mainly because
* those operating systems don't provide full USB support.
*
* PCI support is possible in two different ways. The preferred
@@ -61,7 +63,42 @@
*
* -----------------------------------------------------------------------
* $Log: pcpsdrvr.c $
- * Revision 1.46.2.39 2011/05/06 13:47:39 martin
+ * Revision 1.46.2.53 2011/10/06 13:35:06 martin
+ * Revision 1.46.2.52 2011/10/06 13:29:13 martin
+ * Temp. don't delay for PTP270PEX under FreeBSD.
+ * Revision 1.46.2.51 2011/09/12 12:32:57 martin
+ * Revision 1.46.2.50 2011/09/09 08:28:57 martin
+ * Revision 1.46.2.49 2011/09/08 13:18:32 martin
+ * Always read the serial numbber directly from the device.
+ * Revision 1.46.2.48 2011/07/19 12:48:10 martin
+ * Unified low level functions and use 16 bit types for buffer sizes.
+ * Cleanup.
+ * Revision 1.46.2.47 2011/07/11 12:49:44 martin
+ * Revision 1.46.2.46 2011/07/11 11:00:42Z martin
+ * Modified some debug code.
+ * Revision 1.46.2.45 2011/07/05 10:44:22 martin
+ * Fixed build errors under Unix.
+ * Revision 1.46.2.44 2011/07/05 10:18:59 martin
+ * Fixed pcps_start_device() for USBv2 devices.
+ * Added warnings in case a device is not handled
+ * by chip setup or device feature check.
+ * Revision 1.46.2.43 2011/06/29 14:02:49Z martin
+ * Renamed PZF600PEX to PZF180PEX.
+ * Added support for TCR600USB, MSF600USB, and WVB600USB.
+ * Modified low level AMCC read functions for SPARC.
+ * Fixed handling of unaligned access for SPARC.
+ * Modified DEBUG_IO code.
+ * Added some debug messages.
+ * Updated some comments.
+ * Revision 1.46.2.42 2011/06/21 15:20:56 martin
+ * Fixed build under DOS.
+ * Revision 1.46.2.41 2011/06/20 16:53:34Z martin
+ * account for generic MBG_SYS_TIME with nanosecond resolution.
+ * Revision 1.46.2.40 2011/05/16 17:41:11 martin
+ * Initialize device semaphores only early at device initializition
+ * if required, otherwise later, since early initialization can lead
+ * to a trap e.g. under Windows.
+ * Revision 1.46.2.39 2011/05/06 13:47:39Z martin
* Support PZF600PEX.
* Revision 1.46.2.38 2011/04/19 15:06:56 martin
* Fixed build error on bigendian target.
@@ -370,7 +407,11 @@
#if !defined( DEBUG_IO )
- #define DEBUG_IO ( defined( DEBUG ) && ( DEBUG >= DEBUG_LVL_IO ) )
+ #if defined( MBG_TGT_NETBSD )
+ #define DEBUG_IO ( defined( MBG_DEBUG ) && ( MBG_DEBUG >= DEBUG_LVL_IO ) )
+ #else
+ #define DEBUG_IO ( defined( DEBUG ) && ( DEBUG >= DEBUG_LVL_IO ) )
+ #endif
#endif
#if !defined( DEBUG_PORTS )
@@ -462,15 +503,19 @@ extern const char pcps_driver_name[];
+#if !defined( MBG_TGT_FREEBSD )
+
static /*HDR*/
long mbg_delta_sys_time_ms( const MBG_SYS_TIME *t2, const MBG_SYS_TIME *t1 )
{
- #if defined( MBG_TGT_LINUX ) || defined( MBG_TGT_BSD )
- long dt = ( t2->tv_sec - t1->tv_sec ) * 1000;
- #if USE_TIMESPEC
- dt += ( t2->tv_nsec - t1->tv_nsec ) / 1000000;
+ #if USE_GENERIC_SYS_TIME
+ long dt = ( t2->sec - t1->sec ) * 1000;
+ #if defined ( MBG_TGT_LINUX ) && defined( MBG_TGT_KERNEL )
+ int64_t tmp64 = t2->nsec - t1->nsec;
+ do_div( tmp64, 1000000 );
+ dt += tmp64;
#else
- dt += ( t2->tv_usec - t1->tv_usec ) / 1000;
+ dt += ( t2->nsec - t1->nsec ) / 1000000;
#endif
return dt;
#elif defined( MBG_TGT_WIN32 )
@@ -562,6 +607,8 @@ void check_uptime( void )
} // check_uptime
+#endif
+
static /*HDR*/
@@ -719,7 +766,7 @@ int pcps_wait_busy( PCPS_DDEV *pddev )
* pcps_read_usb()
*
* Purpose: These functions are used for low level access
- * to Meinberg plug-in radio clocks. The function
+ * to Meinberg plug-in devices. The function
* to be used depends on the clock's bus type and
* interface chip.
*
@@ -737,9 +784,9 @@ int pcps_wait_busy( PCPS_DDEV *pddev )
// not properly initialized, in order to avoid I/O access
// on unspecified ports.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_null( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
return MBG_ERR_TIMEOUT;
@@ -751,10 +798,11 @@ short pcps_read_null( PCPS_DDEV *pddev, uint8_t cmd,
// The function below must be used to access a clock with
// standard ISA or micro channel bus.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_std( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
+ uint8_t FAR *p = (uint8_t FAR *) buffer;
PCPS_IO_ADDR_MAPPED port = _pcps_ddev_io_base_mapped( pddev, 0 );
int i;
_pcps_irq_flags
@@ -777,11 +825,13 @@ short pcps_read_std( PCPS_DDEV *pddev, uint8_t cmd,
// no timeout: read bytes from the board's FIFO
for ( i = 0; i < count; i++ )
{
- *buffer++ = _mbg_inp8( pddev, 0, port );
+ *p = _mbg_inp8( pddev, 0, port );
#if DEBUG_IO
- _mbgddmsg_1( MBG_DBG_DETAIL, "pcps_read_std: %02X", buffer[i] );
+ _mbgddmsg_1( MBG_DBG_DETAIL, "pcps_read_std: %02X", *p );
#endif
+
+ p++;
}
return MBG_SUCCESS;
@@ -795,10 +845,11 @@ short pcps_read_std( PCPS_DDEV *pddev, uint8_t cmd,
// The function below must be used to access a clock with
// PCI bus and AMCC S5933 interface chip.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_amcc_s5933( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
+ uint8_t FAR *p = (uint8_t FAR *) buffer;
PCPS_IO_ADDR_MAPPED port = _pcps_ddev_io_base_mapped( pddev, 0 );
int i;
_pcps_irq_flags
@@ -818,6 +869,9 @@ short pcps_read_amcc_s5933( PCPS_DDEV *pddev, uint8_t cmd,
mbg_get_pc_cycles( &pddev->acc_cycles );
// write the command byte
_mbg_outp8( pddev, 0, port + AMCC_OP_REG_OMB1, cmd );
+ #if defined( MBG_ARCH_SPARC )
+ udelay( 3 );
+ #endif
_pcps_local_irq_restore();
// wait until BUSY flag goes low or timeout
@@ -831,10 +885,13 @@ short pcps_read_amcc_s5933( PCPS_DDEV *pddev, uint8_t cmd,
if ( _mbg_inp16_to_cpu( pddev, 0, port + AMCC_OP_REG_MCSR ) & 0x20 )
return MBG_ERR_FIFO;
- buffer[i] = _mbg_inp8( pddev, 0, port + AMCC_OP_REG_FIFO + ( i % sizeof( uint32_t) ) );
+ p[i] = _mbg_inp8( pddev, 0, port + AMCC_OP_REG_FIFO + ( i % sizeof( uint32_t) ) );
#if DEBUG_IO
- _mbgddmsg_1( MBG_DBG_DETAIL, "pcps_read_amcc_s5933: %02X", buffer[i] );
+ if ( ( cmd == PCPS_GIVE_FW_ID_1 ) || ( cmd == PCPS_GIVE_FW_ID_2 ) )
+ _mbgddmsg_2( MBG_DBG_DETAIL, "pcps_read_amcc_s5933: %02X '%c'", p[i], p[i] );
+ else
+ _mbgddmsg_1( MBG_DBG_DETAIL, "pcps_read_amcc_s5933: %02X", p[i] );
#endif
}
@@ -851,11 +908,11 @@ short pcps_read_amcc_s5933( PCPS_DDEV *pddev, uint8_t cmd,
// The function below must be used to access a clock with
// PCI bus and AMCC S5920 interface chip.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_amcc_s5920( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
- uint8_t FAR *p = buffer;
+ uint8_t FAR *p = (uint8_t FAR *) buffer;
PCPS_IO_ADDR_MAPPED data_port = _pcps_ddev_io_base_mapped( pddev, 1 );
int i;
int dt_quot;
@@ -864,15 +921,18 @@ short pcps_read_amcc_s5920( PCPS_DDEV *pddev, uint8_t cmd,
#if DEBUG_IO
- _mbgddmsg_3( MBG_DBG_INIT_DEV, "pcps_read_amcc_s5920: cmd %02X, port: %04lX, data_port: %04lX",
+ _mbgddmsg_5( MBG_DBG_INIT_DEV, "pcps_read_amcc_s5920: cmd %02X, port: %04lX, data_port: %04lX, buffer: %p, count: %u",
cmd, (ulong) _pcps_ddev_io_base_mapped( pddev, 0 ) + AMCC_OP_REG_OMB,
- (ulong) data_port );
+ (ulong) data_port, buffer, count );
#endif
_pcps_disb_local_irq_save();
mbg_get_pc_cycles( &pddev->acc_cycles );
// write the command byte
_mbg_outp8( pddev, 0, _pcps_ddev_io_base_mapped( pddev, 0 ) + AMCC_OP_REG_OMB, cmd );
+ #if defined( MBG_ARCH_SPARC )
+ udelay( 3 );
+ #endif
_pcps_local_irq_restore();
dt_quot = count / 4;
@@ -894,9 +954,15 @@ short pcps_read_amcc_s5920( PCPS_DDEV *pddev, uint8_t cmd,
{
ul = _mbg_inp32_to_cpu( pddev, 1, data_port );
#if DEBUG_IO
- _mbgddmsg_1( MBG_DBG_INIT_DEV, "pcps_read_amcc_s5920: %08X", ul );
+ if ( ( cmd == PCPS_GIVE_FW_ID_1 ) || ( cmd == PCPS_GIVE_FW_ID_2 ) )
+ {
+ _mbgddmsg_5( MBG_DBG_INIT_DEV, "pcps_read_amcc_s5920: %08X \"%c%c%c%c\"", ul,
+ BYTE_OF( ul, 0 ), BYTE_OF( ul, 1 ), BYTE_OF( ul, 2 ), BYTE_OF( ul, 3 ) );
+ }
+ else
+ _mbgddmsg_1( MBG_DBG_INIT_DEV, "pcps_read_amcc_s5920: %08X", ul );
#endif
- _pcps_put_unaligned( ul, (uint32_t FAR *) p );
+ _mbg_put_unaligned( ul, (uint32_t FAR *) p );
p += sizeof( ul );
}
@@ -931,11 +997,11 @@ short pcps_read_amcc_s5920( PCPS_DDEV *pddev, uint8_t cmd,
// The function below must be used to access a clock with
// PCI bus and Meinberg PCI interface ASIC.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_asic( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
- uint8_t FAR *p = buffer;
+ uint8_t FAR *p = (uint8_t FAR *) buffer;
PCPS_IO_ADDR_MAPPED data_port;
PCI_ASIC_REG ar;
int i;
@@ -975,7 +1041,7 @@ short pcps_read_asic( PCPS_DDEV *pddev, uint8_t cmd,
#if DEBUG_IO
_mbgddmsg_1( MBG_DBG_INIT_DEV, "pcps_read_asic: %08X", ar.ul );
#endif
- _pcps_put_unaligned( ar.ul, (uint32_t FAR *) p );
+ _mbg_put_unaligned( ar.ul, (uint32_t FAR *) p );
p += sizeof( ar.ul );
data_port += sizeof( ar.ul );
}
@@ -1005,12 +1071,11 @@ short pcps_read_asic( PCPS_DDEV *pddev, uint8_t cmd,
#if _PCPS_USE_USB
-// The function below must be used to access a clock
-// connected via USB bus.
+// The function below must be used to access a device connected via USB.
-static /*HDR*/ /* type: PCPS_READ_FNC */
+static /*HDR*/ /* PCPS_READ_FNC */
short pcps_read_usb( PCPS_DDEV *pddev, uint8_t cmd,
- uint8_t FAR *buffer, uint8_t count )
+ void FAR *buffer, uint16_t count )
{
int actual_count = 0;
short rc;
@@ -1069,8 +1134,9 @@ short pcps_read_usb( PCPS_DDEV *pddev, uint8_t cmd,
else
usb_latency_cycles = cycles_diff - ( ( FrameNumberDiff - 1 ) * frame_length_cycles );
- #if DBG
- swprintf( pddev->wcs_msg, L"FD %d CD %I64u l %I64u fl %I64u", FrameNumberDiff, cycles_diff, usb_latency_cycles, frame_length_cycles );
+ #if defined( DEBUG )
+ swprintf( pddev->wcs_msg, L"FD %d CD %I64u l %I64u fl %I64u", FrameNumberDiff,
+ cycles_diff, usb_latency_cycles, frame_length_cycles );
_dbg_evt_msg( GlbDriverObject, pddev->wcs_msg );
#endif
}
@@ -1091,7 +1157,7 @@ short pcps_read_usb( PCPS_DDEV *pddev, uint8_t cmd,
/*--------------------------------------------------------------
* Name: pcps_write()
*
- * Purpose: Write data to the radio clock.
+ * Purpose: Write data to a device.
*
* Input: pddev pointer to the device information
* cmd the address of buffer holding the
@@ -1109,9 +1175,9 @@ short pcps_read_usb( PCPS_DDEV *pddev, uint8_t cmd,
* has been invalid
*-------------------------------------------------------------*/
-/*HDR*/
+/*HDR*/ /* PCPS_WRITE_FNC */
short pcps_write( PCPS_DDEV *pddev, uint8_t cmd,
- const void FAR *buffer, uint8_t count )
+ const void FAR *buffer, uint16_t count )
{
short rc;
@@ -1212,7 +1278,7 @@ done:
/*--------------------------------------------------------------
* Name: pcps_generic_io()
*
- * Purpose: Write data to the radio clock.
+ * Purpose: Write data to and/or read data from a device.
*
* Input: pddev pointer to the device information
* cmd the address of buffer holding the
@@ -1450,7 +1516,7 @@ short pcps_read_gps_block( PCPS_DDEV *pddev,
* MBG_ERR_NBYTES
*-------------------------------------------------------------*/
-/*HDR*/
+/*HDR*/ /* PCPS_READ_FNC */
short pcps_read_gps( PCPS_DDEV *pddev,
uint8_t data_type,
void FAR *buffer,
@@ -1521,7 +1587,7 @@ done:
* MBG_ERR_NBYTES
*-------------------------------------------------------------*/
-/*HDR*/
+/*HDR*/ /* PCPS_WRITE_FNC */
short pcps_write_gps( PCPS_DDEV *pddev,
uint8_t data_type,
const void FAR *buffer,
@@ -1771,48 +1837,60 @@ int pcps_read_sernum( PCPS_DDEV *pddev )
memset( pddev->dev.cfg.sernum, 0, sizeof( pddev->dev.cfg.sernum ) );
- // There are different ways to read the clock's S/N.
- // Check which way is supported by the clock, and
- // read the S/N,
-
+ // There are different ways to read the clock's S/N. Check which
+ // way is supported, and read the S/N from the device.
+ //
+ // Never just return a previous copy of the serial number which
+ // has been read earlier since the S/N may just have been set
+ // by a configuration API call.
- // The S/N is part of the RECEIVER_INFO structure. If this
- // structure is supported by the device then it should have
- // already been set up, so we can simply copy the serial number.
- if ( _pcps_ddev_has_receiver_info( pddev ) )
+ // Read directly. This is supported by newer devices.
+ if ( _pcps_ddev_has_sernum( pddev ) )
{
#if DEBUG_SERNUM
- _mbgddmsg_0( MBG_DBG_DETAIL, "copying S/N from receiver info" );
+ _mbgddmsg_0( MBG_DBG_DETAIL, "getting S/N via PCPS_GIVE_SERNUM cmd" );
#endif
- strncpy( pddev->dev.cfg.sernum, pddev->ri.sernum,
- sizeof( pddev->dev.cfg.sernum ) );
+ rc = _pcps_read( pddev, PCPS_GIVE_SERNUM, pddev->dev.cfg.sernum, PCPS_FIFO_SIZE );
+
+ if ( rc != MBG_SUCCESS )
+ {
+ _mbgddmsg_2( MBG_DBG_INIT_DEV, "PCPS read SERNUM %X: rc = %i",
+ _pcps_ddev_dev_id( pddev ), rc );
+ goto fail;
+ }
+
goto check;
}
- // Read directly. This is supported by newer DCF77 clocks.
- if ( _pcps_ddev_has_sernum( pddev ) )
+ // The S/N is part of the RECEIVER_INFO structure,
+ // so use that one, if supported.
+ if ( _pcps_ddev_has_receiver_info( pddev ) )
{
#if DEBUG_SERNUM
- _mbgddmsg_0( MBG_DBG_DETAIL, "getting S/N via PCPS_GIVE_SERNUM cmd" );
+ _mbgddmsg_0( MBG_DBG_DETAIL, "getting S/N from receiver info" );
#endif
- rc = _pcps_read( pddev, PCPS_GIVE_SERNUM, pddev->dev.cfg.sernum, PCPS_FIFO_SIZE );
+ rc = _pcps_read_gps_var( pddev, PC_GPS_RECEIVER_INFO, pddev->ri );
if ( rc != MBG_SUCCESS )
{
- _mbgddmsg_2( MBG_DBG_INIT_DEV, "PCPS read SERNUM %X: rc = %i",
+ _mbgddmsg_2( MBG_DBG_INIT_DEV, "PCPS read GPS receiver info %X: rc = %i",
_pcps_ddev_dev_id( pddev ), rc );
goto fail;
}
+ _mbg_swab_receiver_info( &pddev->ri );
+
+ strncpy( pddev->dev.cfg.sernum, pddev->ri.sernum,
+ sizeof( pddev->dev.cfg.sernum ) );
goto check;
}
// Older GPS clocks store the S/N in an IDENT structure
- // which must be decoded to get the S/N.
+ // which needs to be decoded to get the S/N.
if ( _pcps_ddev_has_ident( pddev ) )
{
static_wc IDENT ident = { { 0 } };
@@ -1834,7 +1912,7 @@ int pcps_read_sernum( PCPS_DDEV *pddev )
goto fail;
}
- // The ident union must never be swapped due to endianess since we are
+ // The ident union must never be swapped due to endianess since we are
// using it only as an array of characters.
#if DEBUG_SERNUM
@@ -1872,8 +1950,8 @@ fail:
goto done;
#else
- // Remove trailing spaces which may unfortunately
- // be returned by some devices.
+ // Remove trailing spaces or 'F' characters which may
+ // unfortunately be returned by some devices.
for ( i = strlen( pddev->dev.cfg.sernum ); ; )
{
if ( i == 0 )
@@ -1881,8 +1959,8 @@ fail:
--i;
cp = &pddev->dev.cfg.sernum[i];
- if ( *cp > ' ' ) // not a trailing space, done
- break;
+ if ( ( *cp > ' ' ) && ( *cp != 'F' ) )
+ break; // done
*cp = 0;
}
@@ -1892,7 +1970,7 @@ fail:
fail:
- // No valid serial number has been found, though the device
+ // No valid serial number has been found, though the device
// should have one. In order to distinguish from devices which
// don't even support a serial number we return a number of '?'
// rather than "N/A".
@@ -2182,9 +2260,20 @@ PCPS_DDEV *pcps_alloc_ddev( void )
{
memset( pddev, 0, sizeof( *pddev ) );
- _mbg_mutex_init( &pddev->dev_mutex );
- _mbg_spin_lock_init( &pddev->mm_lock );
- _mbg_spin_lock_init( &pddev->irq_lock );
+ // If mutexes or spinlocks need to be destroyed on the target OS
+ // when the driver shuts down then they are initialized now and
+ // destroyed in the complementary function pcps_free_ddev().
+ // However, there are target OSs where those semaphores don't need
+ // to be destroyed, and sometimes even *must not* be initialized
+ // at this early point of driver initialization, e.g. under Windows,
+ // in which case the semaphores will be initialized later.
+ #if defined( _mbg_mutex_destroy )
+ _mbg_mutex_init( &pddev->dev_mutex );
+ #endif
+ #if defined( _mbg_spin_lock_destroy )
+ _mbg_spin_lock_init( &pddev->mm_lock );
+ _mbg_spin_lock_init( &pddev->irq_lock );
+ #endif
}
return pddev;
@@ -2196,25 +2285,25 @@ PCPS_DDEV *pcps_alloc_ddev( void )
/*HDR*/
void pcps_free_ddev( PCPS_DDEV *pddev )
{
- #if !_PCPS_STATIC_DEV_LIST
- if ( pddev )
- {
+ if ( pddev )
+ {
+ #if defined( _mbg_mutex_destroy )
_mbg_mutex_destroy( &pddev->dev_mutex );
+ #endif
+ #if defined( _mbg_spin_lock_destroy )
_mbg_spin_lock_destroy( &pddev->mm_lock );
_mbg_spin_lock_destroy( &pddev->irq_lock );
+ #endif
+ #if !_PCPS_STATIC_DEV_LIST
_pcps_kfree( pddev, sizeof( *pddev ) );
- }
- #else
- _mbg_mutex_destroy( &pddev->dev_mutex );
- _mbg_spin_lock_destroy( &pddev->mm_lock );
- _mbg_spin_lock_destroy( &pddev->irq_lock );
-
- memset( pddev, 0, sizeof( *pddev ) );
+ #else
+ memset( pddev, 0, sizeof( *pddev ) );
- if ( n_ddevs )
- n_ddevs--;
- #endif
+ if ( n_ddevs )
+ n_ddevs--;
+ #endif
+ }
} // pcps_free_ddev
@@ -2425,14 +2514,34 @@ int pcps_start_device( PCPS_DDEV *pddev,
goto fail;
}
- // mutexes / spinlocks have already been initialized
- // when the *pddef has been allocated.
+
+ // If mutexes or spinlocks need to be destroyed on the target OS
+ // when the driver shuts down then they have already been initialized
+ // in the device allocation routine and will be destroyed in the
+ // complementary device deallocation routine.
+ // However, there are target OSs where those semaphores don't need
+ // to be destroyed, and sometimes even *must not* be initialized
+ // when the device structure is allocated (e.g under Windows),
+ // in which case the semaphores need to be initialized now.
+ #if !defined( _mbg_mutex_destroy )
+ #if defined( _mbg_mutex_init )
+ _mbg_mutex_init( &pddev->dev_mutex );
+ #endif
+ #endif
+ #if !defined( _mbg_spin_lock_destroy )
+ #if defined( _mbg_spin_lock_init )
+ _mbg_spin_lock_init( &pddev->mm_lock );
+ _mbg_spin_lock_init( &pddev->irq_lock );
+ #endif
+ #endif
+
switch ( _pcps_ddev_bus_flags( pddev ) )
{
#if _PCPS_USE_USB
case PCPS_BUS_USB:
- // No direct port I/O required.
+ case PCPS_BUS_USB_V2:
+ // No direct port I/O possible.
pddev->read = pcps_read_usb;
// In case of an USB device, do some additional
@@ -2552,6 +2661,20 @@ int pcps_start_device( PCPS_DDEV *pddev,
pddev->read = pcps_read_std;
break;
+ default:
+ #if defined( MBG_TGT_LINUX )
+ printk( KERN_ERR "%s: unhandled bus flags %04X for device %s\n",
+ pcps_driver_name, _pcps_ddev_bus_flags( pddev ), _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_BSD )
+ printf( "%s: unhandled bus flags %04X for device %s\n",
+ pcps_driver_name, _pcps_ddev_bus_flags( pddev ), _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_WIN32 )
+ swprintf( pddev->wcs_msg, L"unhandled bus flags %04X for device %S",
+ _pcps_ddev_bus_flags( pddev ), _pcps_ddev_type_name( pddev ) );
+ _evt_msg( GlbDriverObject, pddev->wcs_msg );
+ #endif
+ goto fail;
+
} // switch ( _pcps_ddev_bus_flags( pddev ) )
@@ -2656,7 +2779,7 @@ chip_setup_done:
pddev->status_port = _pcps_ddev_io_base_mapped( pddev, 0 ) + status_port_offs;
// Set up the resource list in pddev->dev.cfg which
- // isn't real required anymore, but just informational:
+ // isn't really required anymore, but just informational:
for ( i = 0; i < N_PCPS_PORT_RSRC; i++ )
{
@@ -2710,9 +2833,29 @@ chip_setup_done:
}
#endif
- // Make sure a PTP270PEX card has finished booting.
- if ( _pcps_ddev_dev_id( pddev ) == PCI_DEV_PTP270PEX )
+ // There are some BIOSs out there which don't configure some PEX cards
+ // properly, and thus the cards can not be accessed properly.
+ // See note near the definition of _pcps_pci_cfg_err() for details.
+ if ( _pcps_ddev_pci_cfg_err( pddev ) )
+ {
+ #if defined( MBG_TGT_LINUX )
+ printk( KERN_WARNING "%s: duplicate base address 0x%04lX, device %s will not work properly (BIOS faulty)\n",
+ pcps_driver_name, (ulong) _pcps_ddev_port_base( pddev, 0 ), _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_BSD )
+ printf( "%s: duplicate base address 0x%04lX, device %s will not work properly (BIOS faulty)\n",
+ pcps_driver_name, (ulong) _pcps_ddev_port_base( pddev, 0 ), _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_WIN32 )
+ swprintf( pddev->wcs_msg, L"duplicate base address 0x%04lX, device %s will not work properly (BIOS faulty)",
+ (ulong) _pcps_ddev_port_base( pddev, 0 ), _pcps_ddev_type_name( pddev ) );
+ _evt_msg( GlbDriverObject, pddev->wcs_msg );
+ #endif
+ }
+
+#if !defined( MBG_TGT_FREEBSD ) // need to check how to delay execution
+ // Make sure a PTP270PEX card has finished booting.
+ if ( _pcps_ddev_is_pci( pddev ) && ( _pcps_ddev_dev_id( pddev ) == PCI_DEV_PTP270PEX ) )
check_uptime();
+#endif
// try to read EPROM ID
rc = pcps_get_fw_id( pddev, pddev->dev.cfg.fw_id );
@@ -2946,10 +3089,36 @@ chip_setup_done:
pddev->dev.cfg.features = PCPS_FEAT_DCF600USB;
break;
- case PCPS_TYPE_PZF600PEX:
- pddev->dev.cfg.features = PCPS_FEAT_PZF600PEX;
+ case PCPS_TYPE_PZF180PEX:
+ pddev->dev.cfg.features = PCPS_FEAT_PZF180PEX;
+ break;
+
+ case PCPS_TYPE_TCR600USB:
+ pddev->dev.cfg.features = PCPS_FEAT_TCR600USB;
+ break;
+
+ case PCPS_TYPE_MSF600USB:
+ pddev->dev.cfg.features = PCPS_FEAT_MSF600USB;
+ break;
+
+ case PCPS_TYPE_WVB600USB:
+ pddev->dev.cfg.features = PCPS_FEAT_WVB600USB;
break;
+ default:
+ #if defined( MBG_TGT_LINUX )
+ printk( KERN_WARNING "%s: no feature detection for device %s\n",
+ pcps_driver_name, _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_BSD )
+ printf( "%s: no feature detection for device %s\n",
+ pcps_driver_name, _pcps_ddev_type_name( pddev ) );
+ #elif defined( MBG_TGT_WIN32 )
+ swprintf( pddev->wcs_msg, L"no feature detection for device %S",
+ _pcps_ddev_type_name( pddev ) );
+ _evt_msg( GlbDriverObject, pddev->wcs_msg );
+ #endif
+ goto fail_with_cleanup;
+
} // switch
@@ -2960,8 +3129,15 @@ chip_setup_done:
if ( rc == MBG_SUCCESS )
{
_mbg_swab_receiver_info( &pddev->ri );
+ _mbgddmsg_1( MBG_DBG_INIT_DEV, "Successfully read receiver info from dev %X",
+ _pcps_ddev_dev_id( pddev ) );
+
goto check;
}
+
+ _mbgddmsg_1( MBG_DBG_INIT_DEV, "Failed to read receiver info from dev %X",
+ _pcps_ddev_dev_id( pddev ) );
+
}
_mbgddmsg_1( MBG_DBG_INIT_DEV, "Setting up default receiver info for dev %X",
@@ -3031,7 +3207,7 @@ check:
check_ri_feature( pddev, &pddev->ri, GPS_HAS_LAN_IP4, PCPS_HAS_LAN_INTF );
check_ri_feature( pddev, &pddev->ri, GPS_HAS_PTP, PCPS_HAS_PTP );
- check_ri_feature( pddev, &pddev->ri, GPS_HAS_PTP_UNICAST, 0 ); // no equivalent in PCPS_DDEV features
+ // check_ri_feature( pddev, &pddev->ri, GPS_HAS_PTP_UNICAST, 0 ); // no equivalent in PCPS_DDEV features
#if !defined( MBG_TGT_OS2 ) && !defined( MBG_TGT_BSD )
// Function strstr may not be supported at kernel level,
@@ -3043,6 +3219,7 @@ check:
#if DEBUG_IO && defined( MBG_TGT_LINUX )
{
PCPS_TIME t = { 0 };
+ printk( KERN_INFO "reading current time as test:\n" );
rc = _pcps_read( pddev, PCPS_GIVE_TIME, &t, sizeof( t ) );
printk( KERN_INFO "read time, sz: %lu, returned %i\n", (ulong) sizeof( t ), rc );
printk( KERN_INFO " sec100 %02X, sec %02X, min %02X hour %02X\n",
@@ -3438,7 +3615,7 @@ void pcps_detect_isa_clocks( PCPS_DDEV_ALLOC_FNC alloc_fnc,
#if !_PCPS_USE_PNP
/*--------------------------------------------------------------
- * Try to detect any plug-in radio clock. If a DOS TSR is
+ * Try to detect any plug-in device. If a DOS TSR is
* installed, be sure it is disabled (BUSY flag set) when
* this function is called.
*-------------------------------------------------------------*/
diff --git a/mbglib/common/pcpsdrvr.h b/mbglib/common/pcpsdrvr.h
index 13e0e4a..77ce4b0 100755
--- a/mbglib/common/pcpsdrvr.h
+++ b/mbglib/common/pcpsdrvr.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: pcpsdrvr.h 1.41.1.27 2011/05/06 13:47:40 martin TRASH $
+ * $Id: pcpsdrvr.h 1.41.1.35 2011/09/09 12:47:13 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,26 @@
*
* -----------------------------------------------------------------------
* $Log: pcpsdrvr.h $
- * Revision 1.41.1.27 2011/05/06 13:47:40 martin
+ * Revision 1.41.1.35 2011/09/09 12:47:13 martin
+ * Fixes for DOS.
+ * Revision 1.41.1.34 2011/07/19 12:48:39Z martin
+ * Updated function prototypes.
+ * Code cleanup.
+ * Revision 1.41.1.33 2011/07/06 11:23:09 martin
+ * Added macros _pcps_ddev_has_corr_info() and _pcps_ddev_has_tr_distance().
+ * Revision 1.41.1.32 2011/07/04 10:29:44 martin
+ * Modified a comment.
+ * Revision 1.41.1.31 2011/06/29 14:01:32 martin
+ * Renamed PZF600PEX to PZF180PEX.
+ * Added support for TCR600USB, MSF600USB, and WVB600USB.
+ * New macros _pcps_ddev_is_usb_v2() and _pcps_ddev_has_pcf().
+ * Updated some comments.
+ * Revision 1.41.1.30 2011/06/29 09:10:27 martin
+ * Renamed PZF600PEX to PZF180PEX.
+ * Revision 1.41.1.29 2011/05/31 14:24:18 martin
+ * Revision 1.41.1.28 2011/05/16 16:39:20 martin
+ * Allocate non-paged memory under Windows.
+ * Revision 1.41.1.27 2011/05/06 13:47:40Z martin
* Support PZF600PEX.
* Revision 1.41.1.26 2011/04/12 15:50:57 martin
* Revision 1.41.1.25 2011/04/12 15:26:10Z martin
@@ -465,6 +484,10 @@
// We use native alignment for structures which are not accessed across system boundaries.
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// Define some OS-specific primitives to alloc / free memory and handle
// mutexes and spinlocks in kernel space.
@@ -513,9 +536,20 @@
#elif defined( MBG_TGT_WIN32 )
- #define _pcps_kmalloc( _sz ) ExAllocatePool( PagedPool, _sz )
+ #define _pcps_kmalloc( _sz ) ExAllocatePool( NonPagedPool, _sz )
#define _pcps_kfree( _p, _sz ) ExFreePool( _p )
+#elif defined( MBG_TGT_DOS )
+
+ // No multitasking, no device driver,
+ // so we don't need this.
+
+ #define _pcps_sem_inc( _pddev ) \
+ _nop_macro_fnc()
+
+ #define _pcps_sem_dec( _pddev ) \
+ _nop_macro_fnc()
+
#endif
@@ -744,15 +778,21 @@ typedef union
} PCPS_MM_LAYOUT;
+struct PCPS_DDEV_s;
+
+typedef short (*PCPS_READ_FNC)( struct PCPS_DDEV_s *pddev, uint8_t cmd, void FAR *buffer, uint16_t count );
+typedef short (*PCPS_WRITE_FNC)( struct PCPS_DDEV_s *pddev, uint8_t cmd, const void FAR *buffer, uint16_t count );
+typedef struct PCPS_DDEV_s *(*PCPS_DDEV_ALLOC_FNC)( void );
+typedef void (*PCPS_DDEV_CLEANUP_FNC)( struct PCPS_DDEV_s * );
+typedef int (*PCPS_DDEV_REGISTER_FNC)( struct PCPS_DDEV_s * );
+
typedef struct PCPS_DDEV_s
{
// the device info data
PCPS_DEV dev;
- // the read function to be used to access the clock
- short (*read)( struct PCPS_DDEV_s *pddev, uchar cmd,
- uchar FAR *buffer, uchar count );
+ PCPS_READ_FNC read;
PCPS_IO_ADDR_MAPPED status_port;
PCPS_IO_ADDR_MAPPED irq_enb_disb_port;
@@ -777,7 +817,7 @@ typedef struct PCPS_DDEV_s
PCPS_MM_LAYOUT FAR *mm_addr;
volatile PCPS_TIME_STAMP FAR *mm_tstamp_addr;
- #if defined( MBG_SPINLOCK_DEFINED )
+ #if defined( _MBG_SPINLOCK_DEFINED )
MBG_SPINLOCK mm_lock;
MBG_SPINLOCK irq_lock;
#endif
@@ -900,7 +940,7 @@ typedef struct PCPS_DDEV_s
_ext PCPS_DEV_TYPE pcps_dev_type[N_PCPS_DEV_TYPE]
#ifdef _DO_INIT
-= {
+= { // attention, the name is limited to PCPS_CLOCK_NAME_SZ, including terminating 0
{ PCPS_TYPE_PC31, "PC31", 0, PCPS_REF_DCF, PCPS_BUS_ISA },
{ PCPS_TYPE_PS31_OLD, "PS31", MCA_ID_PS31_OLD, PCPS_REF_DCF, PCPS_BUS_MCA },
{ PCPS_TYPE_PS31, "PS31", MCA_ID_PS31, PCPS_REF_DCF, PCPS_BUS_MCA },
@@ -929,8 +969,11 @@ _ext PCPS_DEV_TYPE pcps_dev_type[N_PCPS_DEV_TYPE]
{ PCPS_TYPE_WWVB51USB, "WWVB51USB", USB_DEV_WWVB51USB, PCPS_REF_WWVB, PCPS_BUS_USB },
{ PCPS_TYPE_GPS180PEX, "GPS180PEX", PCI_DEV_GPS180PEX, PCPS_REF_GPS, PCPS_BUS_PCI_MBGPEX },
{ PCPS_TYPE_TCR180PEX, "TCR180PEX", PCI_DEV_TCR180PEX, PCPS_REF_IRIG, PCPS_BUS_PCI_MBGPEX },
- { PCPS_TYPE_DCF600USB, "DCF600USB", USB_DEV_DCF600USB, PCPS_REF_DCF, PCPS_BUS_USB },
- { PCPS_TYPE_PZF600PEX, "PZF600PEX", PCI_DEV_PZF600PEX, PCPS_REF_DCF, PCPS_BUS_PCI_MBGPEX } //##+++++ Should we encode PZF reception in ref?
+ { PCPS_TYPE_DCF600USB, "DCF600USB", USB_DEV_DCF600USB, PCPS_REF_DCF, PCPS_BUS_USB_V2 },
+ { PCPS_TYPE_PZF180PEX, "PZF180PEX", PCI_DEV_PZF180PEX, PCPS_REF_DCF, PCPS_BUS_PCI_MBGPEX },
+ { PCPS_TYPE_TCR600USB, "TCR600USB", USB_DEV_TCR600USB, PCPS_REF_IRIG, PCPS_BUS_USB_V2 },
+ { PCPS_TYPE_MSF600USB, "MSF600USB", USB_DEV_MSF600USB, PCPS_REF_MSF, PCPS_BUS_USB_V2 },
+ { PCPS_TYPE_WVB600USB, "WVB600USB", USB_DEV_WVB600USB, PCPS_REF_WWVB, PCPS_BUS_USB_V2 }
// If a new device is added here, don't forget to add it also
// to the Windows .inf file of supported PCI an USB devices,
@@ -975,9 +1018,10 @@ _ext const char *fw_id_ref[]
"TCR", // TCR510PCI, TCR167PCI, TCR511PCI, TCR511PEX, TCR51USB, TCR170PEX, TCR180PEX
"PEX", // PEX511
"USB", // USB5131
- "MSF", // MSF51USB
- "WWVB", // WWVB51USB
+ "MSF", // MSF51USB, MSF600USB
+ "WWVB", // WWVB51USB, WVB600USB
"DCF", // DCF600USB
+ "PZF", // PZF180PEX
NULL
}
#endif
@@ -1012,11 +1056,14 @@ _ext const char *fw_id_ref[]
#define _pcps_ddev_is_lwr( _p ) _pcps_is_lwr( &(_p)->dev )
+// Generic bus types:
#define _pcps_ddev_is_isa( _p ) _pcps_is_isa( &(_p)->dev )
#define _pcps_ddev_is_mca( _p ) _pcps_is_mca( &(_p)->dev )
#define _pcps_ddev_is_pci( _p ) _pcps_is_pci( &(_p)->dev )
#define _pcps_ddev_is_usb( _p ) _pcps_is_usb( &(_p)->dev )
+// Special bus types:
+#define _pcps_ddev_is_usb_v2( _p ) _pcps_is_usb_v2( &(_p)->dev )
#define _pcps_ddev_is_pci_s5933( _p ) _pcps_is_pci_s5933( &(_p)->dev )
#define _pcps_ddev_is_pci_s5920( _p ) _pcps_is_pci_s5920( &(_p)->dev )
#define _pcps_ddev_is_pci_amcc( _p ) _pcps_is_pci_amcc( &(_p)->dev )
@@ -1040,22 +1087,24 @@ _ext const char *fw_id_ref[]
#define _pcps_ddev_features( _p ) _pcps_features( &(_p)->dev )
#define _pcps_ddev_fw_id( _p ) _pcps_fw_id( &(_p)->dev )
#define _pcps_ddev_sernum( _p ) _pcps_sernum( &(_p)->dev )
+
#define _pcps_ddev_raw_asic_version( _p ) ( (_p)->raw_asic_version )
#define _pcps_ddev_asic_version( _p ) ( (_p)->asic_version )
-// The macros below handle the clock device's err_flags.
+// The macros below handle the device's err_flags.
+#define _pcps_ddev_chk_err_flags( _p, _msk ) \
+ _pcps_chk_err_flags( &(_p)->dev, _msk )
+
#define _pcps_ddev_set_err_flags( _p, _msk ) \
_pcps_set_err_flags( &(_p)->dev, _msk )
#define _pcps_ddev_clr_err_flags( _p, _msk ) \
_pcps_clr_err_flags( &(_p)->dev, _msk )
-#define _pcps_ddev_chk_err_flags( _p, _msk ) \
- _pcps_chk_err_flags( &(_p)->dev, _msk )
-
// Query whether a special feature is supported:
#define _pcps_ddev_has_feature( _p, _f ) _pcps_has_feature( &(_p)->dev, _f )
+
#define _pcps_ddev_can_set_time( _p ) _pcps_can_set_time( &(_p)->dev )
#define _pcps_ddev_has_serial( _p ) _pcps_has_serial( &(_p)->dev )
#define _pcps_ddev_has_sync_time( _p ) _pcps_has_sync_time( &(_p)->dev )
@@ -1087,7 +1136,6 @@ _ext const char *fw_id_ref[]
#define _pcps_ddev_has_mod( _p ) \
_pcps_has_mod( &(_p)->dev )
-
#define _pcps_ddev_has_irig( _p ) \
_pcps_has_irig( &(_p)->dev )
@@ -1106,12 +1154,12 @@ _ext const char *fw_id_ref[]
#define _pcps_ddev_has_opt_flags( _p ) \
_pcps_has_opt_flags( &(_p)->dev )
-#define _pcps_ddev_has_gps_data( _p ) \
- _pcps_has_gps_data( &(_p)->dev )
-
#define _pcps_ddev_has_gps_data_16( _p ) \
_pcps_has_gps_data_16( &(_p)->dev )
+#define _pcps_ddev_has_gps_data( _p ) \
+ _pcps_has_gps_data( &(_p)->dev )
+
#define _pcps_ddev_has_synth( _p ) \
_pcps_has_synth( &(_p)->dev )
@@ -1142,6 +1190,21 @@ _ext const char *fw_id_ref[]
#define _pcps_ddev_has_ptp_unicast( _p ) \
_pcps_has_ri_ptp_unicast( &(_p)->ri )
+#define _pcps_ddev_has_pzf( _p ) \
+ _pcps_has_pzf( &(_p)->dev )
+
+#define _pcps_ddev_has_corr_info( _p ) \
+ _pcps_has_corr_info( &(_p)->dev )
+
+#define _pcps_ddev_has_tr_distance( _p ) \
+ _pcps_has_tr_distance( &(_p)->dev )
+
+#define _pcps_ddev_incoming_tfom_ignored( _p ) \
+ _pcps_incoming_tfom_ignored( &(_p)->dev )
+
+#define _pcps_ddev_pci_cfg_err( _p ) \
+ _pcps_pci_cfg_err( &(_p)->dev )
+
// The macros below simplify read/write access to the clocks.
@@ -1152,14 +1215,14 @@ _ext const char *fw_id_ref[]
( (_pddev)->read( _pddev, (_cmd), (uchar FAR *)(_p), (_n) ) )
#endif
-// Write a byte _b to the radio clock device. This is typically
-// done by just writing the command byte from inside the read function.
+// Write a byte _b to a device. This is typically done by just writing
+// the command byte from inside the read function.
#if !defined( _pcps_write_byte )
#define _pcps_write_byte( _pddev, _b ) \
_pcps_read( (_pddev), (_b), NULL, 0 )
#endif
-// write a command plus the contents of a data buffer to the device.
+// write a command plus the contents of a data buffer to a device.
// This is typically implemented as a function which uses the
// _pcps_write_byte() macro repeatedly.
#if !defined( _pcps_write )
@@ -1184,13 +1247,13 @@ _ext const char *fw_id_ref[]
// The macros below simplify reading/writing typed variables by
// determining the size automatically from the type of the variable.
-// Read data from the radio clock board to variable _s.
+// Read data from a device to variable _s.
// The number of bytes to read is determined by the size
// of _s. The accepted type of _s depends on the _cmd code.
#define _pcps_read_var( _pddev, _cmd, _s ) \
_pcps_read( (_pddev), (_cmd), &(_s), sizeof( (_s) ) )
-// Write data from variable _s to the radio clock board .
+// Write data from variable _s to a device.
// The number of bytes to write is determined by the size
// of _s. The accepted type of _s depends on the _cmd code.
#define _pcps_write_var( _pddev, _cmd, _s ) \
@@ -1210,16 +1273,16 @@ _ext const char *fw_id_ref[]
_pcps_write_gps( (_pddev), (_cmd), &(_s), sizeof( (_s) ) )
-// Generate a hardware reset on the radio clock board. This
-// macro should be used VERY carefully and should be avoided
-// if possible.
+// Generate a hardware reset on a device. This macro should be used
+// VERY carefully and should be avoided, if possible, since resetting
+// a device could lock up the PC.
#define _pcps_force_reset( _pddev ) \
_pcps_write_byte( (_pddev), PCPS_FORCE_RESET )
-// The macro below reads a radio clock's status port which
-// includes the BUSY flag and the modulation signal of DCF77
-// clocks. The macro takes a (PCPS_DDEV *) as argument.
+// The macro below reads a device's status port which includes
+// the BUSY flag and the modulation signal of DCF77 receivers.
+// The macro takes a (PCPS_DDEV *) as argument.
#define _pcps_ddev_read_status_port( _d ) \
_mbg_inp8( (_d), 0, (_d)->status_port )
@@ -1341,26 +1404,21 @@ _ext const char *fw_id_ref[]
-
-/* function prototypes: */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef PCPS_DDEV *(*PCPS_DDEV_ALLOC_FNC)( void );
-typedef void (*PCPS_DDEV_CLEANUP_FNC)( PCPS_DDEV * );
-typedef int (*PCPS_DDEV_REGISTER_FNC)( PCPS_DDEV * );
-
/* ----- function prototypes begin ----- */
/* This section was generated automatically */
/* by MAKEHDR, do not remove the comments. */
- short pcps_write( PCPS_DDEV *pddev, uint8_t cmd, const void FAR *buffer, uint8_t count ) ;
+/* PCPS_WRITE_FNC */
+ short pcps_write( PCPS_DDEV *pddev, uint8_t cmd, const void FAR *buffer, uint16_t count ) ;
+
short pcps_generic_io( PCPS_DDEV *pddev, uint8_t type, const void FAR *in_buff, uint8_t in_cnt, void FAR *out_buff, uint8_t out_cnt ) ;
+/* PCPS_READ_FNC */
short pcps_read_gps( PCPS_DDEV *pddev, uint8_t data_type, void FAR *buffer, uint16_t buffer_size ) ;
+
+/* PCPS_WRITE_FNC */
short pcps_write_gps( PCPS_DDEV *pddev, uint8_t data_type, const void FAR *buffer, uint16_t buffer_size ) ;
+
short pcps_get_fw_id( PCPS_DDEV *pddev, PCPS_ID_STR FAR fw_id ) ;
short pcps_check_id( PCPS_DDEV *pddev, const char FAR *ref ) ;
short pcps_get_rev_num( char FAR *idstr ) ;
diff --git a/mbglib/common/pcpsirq.h b/mbglib/common/pcpsirq.h
index 21c5bc5..d2c2853 100755
--- a/mbglib/common/pcpsirq.h
+++ b/mbglib/common/pcpsirq.h
@@ -1,16 +1,18 @@
/**************************************************************************
*
- * $Id: pcpsirq.h 1.7.1.1 2011/02/09 17:22:36 martin TRASH $
+ * $Id: pcpsirq.h 1.7.1.2 2011/06/29 11:03:28 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
* Description:
* OS independent definitions used to handle interrupts from
- * Meinberg radio clock devices.
+ * Meinberg PCI devices.
*
* -----------------------------------------------------------------------
* $Log: pcpsirq.h $
+ * Revision 1.7.1.2 2011/06/29 11:03:28 martin
+ * Updated a comment.
* Revision 1.7.1.1 2011/02/09 17:22:36 martin
* Revision 1.7 2008/12/05 12:20:36 martin
* Protect HW access to enable/disable IRQ by mutex.
diff --git a/mbglib/common/pcpslstr.h b/mbglib/common/pcpslstr.h
index adf4b5e..2993aa0 100755
--- a/mbglib/common/pcpslstr.h
+++ b/mbglib/common/pcpslstr.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: pcpslstr.h 1.27.1.5 2011/02/16 09:34:23 martin TRASH $
+ * $Id: pcpslstr.h 1.27.1.6 2011/10/04 10:41:39 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,7 +10,11 @@
*
* -----------------------------------------------------------------------
* $Log: pcpslstr.h $
- * Revision 1.27.1.5 2011/02/16 09:34:23 martin
+ * Revision 1.27.1.6 2011/10/04 10:41:39 martin
+ * Made all declarations extern C.
+ * Include cfg_hlp.h.
+ * Added DEFAULT_OPT_NAME_TR_DISTANCE.
+ * Revision 1.27.1.5 2011/02/16 09:34:23Z martin
* Added menu titles for PTP and PTP Unicast configuration.
* Revision 1.27.1.4 2011/02/09 14:43:42Z martin
* Revision 1.27.1.3 2011/01/28 09:34:38 martin
@@ -109,6 +113,7 @@
/* Other headers to be included */
#include <mbg_tgt.h>
+#include <cfg_hlp.h>
#include <parmpcps.h>
#include <ctrydttm.h>
#include <cnv_wday.h>
@@ -127,6 +132,10 @@
/* Start of header body */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
// upper case 'A' umlaut
#define ANSI_UC_A_UML '\xC4' // single char
#define ANSI_US_A_UML "\xC4" // string
@@ -568,6 +577,15 @@ typedef struct
}
+// menu option: setup distance from transmitter
+
+#define DEFAULT_OPT_NAME_TR_DISTANCE \
+{ \
+ "Distance from Transmitter", \
+ "Senderentfernung" \
+}
+
+
// menu option: setup IRIG config
#define DEFAULT_OPT_NAME_IRIG_TX_EN "IRIG Output"
@@ -1001,10 +1019,6 @@ _ext const char *short_mode_name[N_STR_MODE]
;
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/* ----- function prototypes begin ----- */
/* This section was generated automatically */
diff --git a/mbglib/common/pcpsutil.c b/mbglib/common/pcpsutil.c
index e35ea25..d2813d2 100755
--- a/mbglib/common/pcpsutil.c
+++ b/mbglib/common/pcpsutil.c
@@ -1,15 +1,17 @@
/**************************************************************************
*
- * $Id: pcpsutil.c 1.13 2009/03/09 13:39:45 martin REL_M $
+ * $Id: pcpsutil.c 1.14 2011/06/29 11:03:44 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
* Description:
- * Utility functions used with programs for Meinberg radio clocks.
+ * Utility functions used with programs for Meinberg devices.
*
* -----------------------------------------------------------------------
* $Log: pcpsutil.c $
+ * Revision 1.14 2011/06/29 11:03:44 martin
+ * Updated a comment.
* Revision 1.13 2009/03/09 13:39:45 martin
* Made pcps_exp_year() an inline function.
* Revision 1.12 2008/12/10 19:59:48 martin
diff --git a/mbglib/common/toolutil.c b/mbglib/common/toolutil.c
index 50a4ad8..535a485 100755
--- a/mbglib/common/toolutil.c
+++ b/mbglib/common/toolutil.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: toolutil.c 1.3.2.1 2010/11/05 12:56:02 martin TEST $
+ * $Id: toolutil.c 1.3.2.10 2011/10/05 15:08:28 martin TEST $
*
* Description:
* Common functions which can be used with Meinberg command line
@@ -9,6 +9,22 @@
*
* -----------------------------------------------------------------------
* $Log: toolutil.c $
+ * Revision 1.3.2.10 2011/10/05 15:08:28 martin
+ * Added function to show PZF correlation.
+ * Revision 1.3.2.9 2011/09/29 16:31:53 martin
+ * New function mbg_print_hr_time() which optionally prints hex status.
+ * Revision 1.3.2.8 2011/09/20 16:14:13 martin
+ * Revision 1.3.2.7 2011/09/07 15:05:04 martin
+ * Let th display functions for HR timestamps optionally show
+ * the raw (hex) timestamps.
+ * Revision 1.3.2.6 2011/07/08 11:39:00 martin
+ * Revision 1.3.2.5 2011/07/06 07:55:32 martin
+ * Revision 1.3.2.4 2011/07/05 15:35:56 martin
+ * Modified version handling.
+ * Revision 1.3.2.3 2011/07/05 14:36:47 martin
+ * New way to maintain version information.
+ * Revision 1.3.2.2 2011/06/27 13:02:11 martin
+ * Open device with O_RDWR flag.
* Revision 1.3.2.1 2010/11/05 12:56:02 martin
* Revision 1.3 2009/06/19 12:12:14 martin
* Added function mbg_print_hr_timestamp().
@@ -35,9 +51,38 @@
/*HDR*/
-void mbg_print_program_info( const char *pname, const char *pversion, const char *pcopyright )
+int mbg_program_info_str( char *s, size_t max_len, const char *pname,
+ int micro_version, int first_year, int last_year )
{
- printf( "\n%s %s %s\n\n", pname, pversion, pcopyright );
+ int n;
+
+ if ( last_year == 0 )
+ last_year = MBG_CURRENT_COPYRIGHT_YEAR;
+
+ n = snprintf( s, max_len, "%s v%i.%i.%i Copyright Meinberg ", pname,
+ MBG_MAJOR_VERSION_CODE, MBG_MINOR_VERSION_CODE, micro_version );
+
+ if ( first_year != last_year )
+ n += snprintf( &s[n], max_len - n, "%04i-", first_year );
+
+ n += snprintf( &s[n], max_len - n, "%04i", last_year );
+
+ return n;
+
+} // mbg_program_info_str
+
+
+
+/*HDR*/
+void mbg_print_program_info( const char *pname, int micro_version, int first_year, int last_year )
+{
+ char ws[256];
+ #if defined( MBG_MICRO_VERSION_CODE_DEV )
+ micro_version = MBG_MICRO_VERSION_CODE_DEV;
+ #endif
+ mbg_program_info_str( ws, sizeof( ws ), pname, micro_version, first_year, last_year );
+
+ printf( "\n%s\n\n", ws );
} // mbg_print_program_info
@@ -268,7 +313,7 @@ int mbg_check_devices( int argc, char *argv[], int optind, int (*fnc)( MBG_DEV_H
// shall be displayed.
const char *fn = ( num_devices > 1 ) ? argv[i] : NULL;
- dh = open( argv[i], 0 );
+ dh = open( argv[i], O_RDWR );
ret_val = mbg_check_device( dh, fn, fnc );
if ( ret_val )
@@ -283,7 +328,7 @@ int mbg_check_devices( int argc, char *argv[], int optind, int (*fnc)( MBG_DEV_H
/*HDR*/
-int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p )
+int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p, int show_raw )
{
int n = 0;
@@ -296,11 +341,10 @@ int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p )
// settings, we always use the gmtime() function for conversion:
struct tm *tmp = gmtime( &t );
- #if defined( DEBUG )
- n += snprintf( s + n, len_s - n, "raw: %08lX.%08lX, ",
+ if ( show_raw )
+ n += snprintf( s + n, len_s - n, "raw: 0x%08lX.%08lX, ",
(ulong) p->sec,
(ulong) p->frac );
- #endif
n += snprintf( s + n, len_s - n, "%04i-%02i-%02i %02i:%02i:%02i." PCPS_HRT_FRAC_SCALE_FMT,
tmp->tm_year + 1900,
@@ -319,7 +363,7 @@ int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p )
/*HDR*/
-int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p )
+int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p, int show_raw )
{
char ws[80];
PCPS_TIME_STAMP ts = p->tstamp;
@@ -351,7 +395,7 @@ int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p )
// Convert the local time stamp to calendar date and time.
- n = mbg_snprint_hr_tstamp( s, len_s, &ts );
+ n = mbg_snprint_hr_tstamp( s, len_s, &ts, show_raw );
// By default the time stamp represents UTC plus an optional local time offset.
time_scale_name = "UTC";
@@ -372,12 +416,13 @@ int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p )
/*HDR*/
-void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int raw )
+void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts,
+ int no_latency, int show_raw )
{
char ws[80];
- mbg_snprint_hr_tstamp( ws, sizeof( ws ), p_ts );
- printf( "Fast HR time %s", ws );
+ mbg_snprint_hr_tstamp( ws, sizeof( ws ), p_ts, show_raw );
+ printf( "HR time %s", ws );
if ( p_prv_ts )
{
@@ -390,7 +435,7 @@ void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TI
printf( " (%+.1f us)", delta_t );
}
- if ( !raw )
+ if ( !no_latency )
printf( ", latency: %.1f us", ( (double) hns_latency ) / 10 );
puts( "" );
@@ -399,3 +444,66 @@ void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TI
+/*HDR*/
+void mbg_print_hr_time( PCPS_HR_TIME *p_ht, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts,
+ int no_latency, int show_raw, int verbose )
+{
+ char ws[80];
+
+ mbg_snprint_hr_time( ws, sizeof( ws ), p_ht, show_raw );
+ printf( "HR time %s", ws );
+
+ if ( p_prv_ts )
+ {
+ // print the difference between the current and the previous time stamp
+ uint64_t ts = pcps_time_stamp_to_uint64( &p_ht->tstamp );
+ uint64_t prv_ts = pcps_time_stamp_to_uint64( p_prv_ts );
+ // we divide by PCPS_HRT_BIN_FRAC_SCALE to get the correct fractions
+ // and we multiply by 1E6 to get the result in microseconds
+ double delta_t = (double) ( ts - prv_ts ) * 1E6 / PCPS_HRT_BIN_FRAC_SCALE;
+ printf( " (%+.1f us)", delta_t );
+ }
+
+ if ( !no_latency )
+ printf( ", latency: %.1f us", ( (double) hns_latency ) / 10 );
+
+ if ( verbose )
+ printf( ", st: 0x%04lX", (ulong) p_ht->status );
+
+ puts( "" );
+
+} // mbg_print_hr_time
+
+
+
+/*HDR*/
+int mbg_show_pzf_corr_info( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int show_corr_step )
+{
+ CORR_INFO ci;
+ char ws[80];
+ const char *cp;
+
+ int rc = mbg_get_corr_info( dh, &ci );
+
+ if ( mbg_ioctl_err( rc, "mbg_get_corr_info" ) )
+ return rc;
+
+
+ if ( ci.status < N_PZF_CORR_STATE )
+ cp = pzf_corr_state_name[ci.status];
+ else
+ {
+ snprintf( ws, sizeof( ws ) - 1, "(unknown, code: 0x%02X)", ci.status );
+ ws[sizeof( ws ) - 1] = 0; // force terminating 0
+ cp = ws;
+ }
+
+ printf( "PZF correlation: %u%%, status: %s", ci.val, cp );
+
+ if ( show_corr_step )
+ printf( " %c", ci.corr_dir );
+
+ return MBG_SUCCESS;
+
+} // mbg_show_pzf_corr_info
+
diff --git a/mbglib/common/toolutil.h b/mbglib/common/toolutil.h
index 7c69e84..d47cca2 100755
--- a/mbglib/common/toolutil.h
+++ b/mbglib/common/toolutil.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: toolutil.h 1.2 2009/06/19 12:11:35 martin REL_M $
+ * $Id: toolutil.h 1.2.1.5 2011/10/05 15:10:08 martin TEST $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,16 @@
*
* -----------------------------------------------------------------------
* $Log: toolutil.h $
+ * Revision 1.2.1.5 2011/10/05 15:10:08 martin
+ * Updated function prototypes.
+ * Revision 1.2.1.4 2011/09/29 16:30:58 martin
+ * Updated function prototypes.
+ * Revision 1.2.1.3 2011/09/07 15:03:36 martin
+ * Updated function prototypes.
+ * Revision 1.2.1.2 2011/07/05 15:35:56 martin
+ * Modified version handling.
+ * Revision 1.2.1.1 2011/07/05 14:36:42 martin
+ * New way to maintain version information.
* Revision 1.2 2009/06/19 12:11:35 martin
* Updated function prototypes.
* Revision 1.1 2008/12/17 10:45:14 martin
@@ -26,6 +36,7 @@
/* Other headers to be included */
#include <mbgdevio.h>
+#include <mbgversion.h>
@@ -39,32 +50,40 @@
/* Start of header body */
-_ext int must_print_usage;
-
-
#ifdef __cplusplus
extern "C" {
#endif
+_ext int must_print_usage;
+
+_ext const char *pzf_corr_state_name[N_PZF_CORR_STATE]
+#ifdef _DO_INIT
+ = PZF_CORR_STATE_NAMES_ENG
+#endif
+;
+
/* ----- function prototypes begin ----- */
/* This section was generated automatically */
/* by MAKEHDR, do not remove the comments. */
-void mbg_print_program_info( const char *pname, const char *pversion, const char *pcopyright );
-void mbg_print_usage_intro( const char *pname, const char *info );
-void mbg_print_help_options( void );
-void mbg_print_opt_info( const char *opt_name, const char *opt_info );
-void mbg_print_device_options( void );
-void mbg_print_default_usage( const char *pname, const char *prog_info );
-int mbg_ioctl_err( int rc, const char *descr ) ;
-int mbg_get_show_dev_info( MBG_DEV_HANDLE dh, const char *dev_name, PCPS_DEV *p_dev );
-int mbg_check_device( MBG_DEV_HANDLE dh, const char *dev_name, int (*fnc)( MBG_DEV_HANDLE, const PCPS_DEV *) );
-int mbg_check_devices( int argc, char *argv[], int optind, int (*fnc)( MBG_DEV_HANDLE, const PCPS_DEV *) );
-int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p );
-int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p );
-void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int raw );
+ int mbg_program_info_str( char *s, size_t max_len, const char *pname, int micro_version, int first_year, int last_year ) ;
+ void mbg_print_program_info( const char *pname, int micro_version, int first_year, int last_year ) ;
+ void mbg_print_usage_intro( const char *pname, const char *info ) ;
+ void mbg_print_help_options( void ) ;
+ void mbg_print_opt_info( const char *opt_name, const char *opt_info ) ;
+ void mbg_print_device_options( void ) ;
+ void mbg_print_default_usage( const char *pname, const char *prog_info ) ;
+ int mbg_ioctl_err( int rc, const char *descr ) ;
+ int mbg_get_show_dev_info( MBG_DEV_HANDLE dh, const char *dev_name, PCPS_DEV *p_dev ) ;
+ int mbg_check_device( MBG_DEV_HANDLE dh, const char *dev_name, int (*fnc)( MBG_DEV_HANDLE, const PCPS_DEV *) ) ;
+ int mbg_check_devices( int argc, char *argv[], int optind, int (*fnc)( MBG_DEV_HANDLE, const PCPS_DEV *) ) ;
+ int mbg_snprint_hr_tstamp( char *s, int len_s, const PCPS_TIME_STAMP *p, int show_raw ) ;
+ int mbg_snprint_hr_time( char *s, int len_s, const PCPS_HR_TIME *p, int show_raw ) ;
+ void mbg_print_hr_timestamp( PCPS_TIME_STAMP *p_ts, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw ) ;
+ void mbg_print_hr_time( PCPS_HR_TIME *p_ht, int32_t hns_latency, PCPS_TIME_STAMP *p_prv_ts, int no_latency, int show_raw, int verbose ) ;
+ int mbg_show_pzf_corr_info( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, int show_corr_step ) ;
/* ----- function prototypes end ----- */
diff --git a/mbglib/common/usbdefs.h b/mbglib/common/usbdefs.h
index c557c86..32b0dba 100755
--- a/mbglib/common/usbdefs.h
+++ b/mbglib/common/usbdefs.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: usbdefs.h 1.11 2011/04/13 07:59:11 daniel TRASH $
+ * $Id: usbdefs.h 1.13 2011/06/29 14:11:23 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,10 @@
*
* -----------------------------------------------------------------------
* $Log: usbdefs.h $
+ * Revision 1.13 2011/06/29 14:11:23 martin
+ * Added device IDs for TCR600USB, MSF600USB, and WVB600USB.
+ * Revision 1.12 2011/05/11 07:20:37 daniel
+ * New class code and device id for fan control unit
* Revision 1.11 2011/04/13 07:59:11 daniel
* New class code and device id for external
* synchronization interface device.
@@ -70,6 +74,7 @@ enum
MBG_USB_CLASS_WWVB, // WWVB Radio Clock
MBG_USB_CLASS_SCU, // Meinberg Signal Changeover Unit
MBG_USB_CLASS_ESI, // External Synchronization Interface
+ MBG_USB_CLASS_FCU, // Fan Control Unit
N_MBG_USB_CLASS // number of known device class codes
};
@@ -89,15 +94,19 @@ enum
#define USB_DEV_CMC ( ( MBG_USB_CLASS_CMC << 8 ) | 0x01 )
#define USB_DEV_TCR51USB ( ( MBG_USB_CLASS_TCR << 8 ) | 0x01 )
+#define USB_DEV_TCR600USB ( ( MBG_USB_CLASS_TCR << 8 ) | 0x02 )
#define USB_DEV_MSF51USB ( ( MBG_USB_CLASS_MSF << 8 ) | 0x01 )
+#define USB_DEV_MSF600USB ( ( MBG_USB_CLASS_MSF << 8 ) | 0x02 )
#define USB_DEV_WWVB51USB ( ( MBG_USB_CLASS_WWVB << 8 ) | 0x01 )
+#define USB_DEV_WVB600USB ( ( MBG_USB_CLASS_WWVB << 8 ) | 0x02 )
#define USB_DEV_SCU_USB ( ( MBG_USB_CLASS_SCU << 8 ) | 0x01 )
#define USB_DEV_ESI_01 ( ( MBG_USB_CLASS_ESI << 8 ) | 0x01 )
+#define USB_DEV_FCU_01 ( ( MBG_USB_CLASS_FCU << 8 ) | 0x01 )
enum
{
diff --git a/mbglib/common/words.h b/mbglib/common/words.h
index 4216e17..5aa10e5 100755
--- a/mbglib/common/words.h
+++ b/mbglib/common/words.h
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: words.h 1.26 2011/04/06 10:23:03 martin REL_M $
+ * $Id: words.h 1.27 2011/07/18 10:21:38 martin REL_M $
*
* Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
*
@@ -10,6 +10,9 @@
*
* -----------------------------------------------------------------------
* $Log: words.h $
+ * Revision 1.27 2011/07/18 10:21:38 martin
+ * Added definition for MBG_CODE_NAME_TABLE_ENTRY which can
+ * be used to define tables assigning strings to numeric codes.
* Revision 1.26 2011/04/06 10:23:03 martin
* Added FBYTE_OF() and FWORD_OF() macros.
* Modifications required for *BSD.
@@ -332,6 +335,18 @@ typedef unsigned long dword;
#define _hilo_32( _x ) (_x)
#endif
+
+/**
+ * @brief A table entry which can be used to map codes to names.
+ */
+typedef struct
+{
+ ulong code;
+ const char *name;
+} MBG_CODE_NAME_TABLE_ENTRY;
+
+
+
/* End of header body */
#undef _ext
diff --git a/mbgsetsystime/Makefile b/mbgsetsystime/Makefile
index 07ec4e4..c68401c 100755
--- a/mbgsetsystime/Makefile
+++ b/mbgsetsystime/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.8.1.2 2010/08/30 09:05:23 martin TEST $
+# $Id: Makefile 1.8.1.3 2011/09/26 16:07:30 martin TEST $
#
# Description:
# Makefile for mbgsetsystime.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.8.1.3 2011/09/26 16:07:30 martin
+# Updated for use with latest base Makefile.
# Revision 1.8.1.2 2010/08/30 09:05:23 martin
# Revision 1.8.1.1 2010/08/30 08:21:54 martin
# Revision 1.8 2009/07/24 10:31:17 martin
@@ -30,7 +32,7 @@
#########################################################################
TARGET = mbgsetsystime
-INST_DIR = /usr/local/sbin
+INST_TO_SBIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbgsetsystime/mbgsetsystime.c b/mbgsetsystime/mbgsetsystime.c
index 6015f12..334b431 100755
--- a/mbgsetsystime/mbgsetsystime.c
+++ b/mbgsetsystime/mbgsetsystime.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgsetsystime.c 1.8 2009/09/29 15:02:15 martin REL_M $
+ * $Id: mbgsetsystime.c 1.8.1.2 2011/07/05 15:35:55 martin TEST $
*
* Description:
* Main file for mbgsetsystime program which reads the current date
@@ -14,6 +14,10 @@
*
* -----------------------------------------------------------------------
* $Log: mbgsetsystime.c $
+ * Revision 1.8.1.2 2011/07/05 15:35:55 martin
+ * Modified version handling.
+ * Revision 1.8.1.1 2011/07/05 14:36:01 martin
+ * New way to maintain version information.
* Revision 1.8 2009/09/29 15:02:15 martin
* Updated version number to 3.4.0.
* Revision 1.7 2009/07/24 09:50:09 martin
@@ -52,10 +56,11 @@
#include <sys/types.h>
-static const char *pname = "mbgsetsystime";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2001-2009";
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+static const char *pname = "mbgsetsystime";
@@ -142,7 +147,7 @@ int main( int argc, char *argv[] )
int c;
int rc;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "h?" ) ) != -1 )
diff --git a/mbgshowsignal/Makefile b/mbgshowsignal/Makefile
index c10b915..16120bb 100755
--- a/mbgshowsignal/Makefile
+++ b/mbgshowsignal/Makefile
@@ -1,13 +1,15 @@
#########################################################################
#
-# $Id: Makefile 1.7.1.2 2010/08/30 09:05:23 martin TEST $
+# $Id: Makefile 1.7.1.3 2011/09/26 16:07:30 martin TEST $
#
# Description:
# Makefile for mbgshowsignal.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
+# Revision 1.7.1.3 2011/09/26 16:07:30 martin
+# Updated for use with latest base Makefile.
# Revision 1.7.1.2 2010/08/30 09:05:23 martin
# Revision 1.7.1.1 2010/08/30 08:22:00 martin
# Revision 1.7 2009/07/24 10:31:17 martin
@@ -28,7 +30,7 @@
#########################################################################
TARGET = mbgshowsignal
-INST_DIR = /usr/local/bin
+INST_TO_BIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbgshowsignal/mbgshowsignal.c b/mbgshowsignal/mbgshowsignal.c
index 308fec8..73f66a5 100755
--- a/mbgshowsignal/mbgshowsignal.c
+++ b/mbgshowsignal/mbgshowsignal.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgshowsignal.c 1.8 2009/09/29 15:02:15 martin REL_M $
+ * $Id: mbgshowsignal.c 1.8.1.4 2011/10/05 15:10:56 martin TEST $
*
* Description:
* Main file for mbgshowsignal program which demonstrates how to
@@ -10,6 +10,14 @@
*
* -----------------------------------------------------------------------
* $Log: mbgshowsignal.c $
+ * Revision 1.8.1.4 2011/10/05 15:10:56 martin
+ * Show PZF correlation state.
+ * Revision 1.8.1.3 2011/07/05 15:35:55 martin
+ * Modified version handling.
+ * Revision 1.8.1.2 2011/07/05 14:35:19 martin
+ * New way to maintain version information.
+ * Revision 1.8.1.1 2011/07/04 13:19:04 martin
+ * Update modulation status continuously.
* Revision 1.8 2009/09/29 15:02:15 martin
* Updated version number to 3.4.0.
* Revision 1.7 2009/07/24 09:50:09 martin
@@ -47,18 +55,20 @@
#include <time.h>
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbgshowsignal";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2001-2009";
static /*HDR*/
-int show_modulation( MBG_DEV_HANDLE dh )
+int show_modulation( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
{
static time_t prv_sys_t;
time_t sys_t;
- uchar status_port; // current value of the clock's status port
+ PCPS_STATUS_PORT status_port; // current value of the clock's status port
PCPS_TIME t;
int signal;
int rc = mbg_get_status_port( dh, &status_port ); // read status port
@@ -69,16 +79,15 @@ int show_modulation( MBG_DEV_HANDLE dh )
// show signal only once per second
sys_t = time( NULL );
- if ( sys_t == prv_sys_t )
- return 0;
-
- prv_sys_t = sys_t;
-
- rc = mbg_get_time( dh, &t );
+ if ( sys_t != prv_sys_t )
+ {
+ rc = mbg_get_time( dh, &t );
- if ( mbg_ioctl_err( rc, "mbg_get_time" ) )
- return -1;
+ if ( mbg_ioctl_err( rc, "mbg_get_time" ) )
+ return -1;
+ prv_sys_t = sys_t;
+ }
// The current value of the modulation (second mark) is returned
// in a single bit of the status port, so ignore the other bits.
@@ -92,7 +101,12 @@ int show_modulation( MBG_DEV_HANDLE dh )
if ( signal > PCPS_SIG_MAX )
signal = PCPS_SIG_MAX;
- printf( " Signal: %u%% ", signal * 100 / PCPS_SIG_MAX );
+ printf( " Signal: %u%% ", signal * 100 / PCPS_SIG_MAX );
+
+ if ( _pcps_has_pzf( p_dev ) )
+ mbg_show_pzf_corr_info( dh, p_dev, 1 );
+
+ printf( " " );
return 0;
@@ -118,7 +132,7 @@ int do_mbgshowsignal( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
printf( "\nMonitoring signal modulation:\n" );
for (;;)
- if ( show_modulation( dh ) < 0 )
+ if ( show_modulation( dh, p_dev ) < 0 )
goto fail;
done:
@@ -151,7 +165,7 @@ int main( int argc, char *argv[] )
int c;
int rc;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "h?" ) ) != -1 )
diff --git a/mbgstatus/Makefile b/mbgstatus/Makefile
index 3d86873..11d0742 100755
--- a/mbgstatus/Makefile
+++ b/mbgstatus/Makefile
@@ -1,17 +1,16 @@
#########################################################################
#
-# $Id: Makefile 1.7.1.4.1.2 2011/04/20 09:34:06 martin TRASH $
+# $Id: Makefile 1.7.1.5 2011/09/26 16:07:50 martin TEST $
#
# Description:
# Makefile for mbgstatus.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
-# Revision 1.7.1.4.1.2 2011/04/20 09:34:06 martin
-# Added module lan_util.
-# Revision 1.7.1.4.1.1 2010/09/20 12:07:06 stefan
+# Revision 1.7.1.5 2011/09/26 16:07:50 martin
# Updated for use with latest base Makefile.
+# Added module lan_util.
# Revision 1.7.1.4 2010/08/30 09:05:24 martin
# Revision 1.7.1.3 2010/08/30 08:20:32 martin
# Revision 1.7.1.2 2010/08/24 08:35:11 martin
diff --git a/mbgstatus/mbgstatus.c b/mbgstatus/mbgstatus.c
index e0e7c47..a78cdcb 100755
--- a/mbgstatus/mbgstatus.c
+++ b/mbgstatus/mbgstatus.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgstatus.c 1.13.1.9 2011/04/20 16:08:27 martin TRASH $
+ * $Id: mbgstatus.c 1.13.1.17 2011/10/05 15:10:56 martin TEST $
*
* Description:
* Main file for mbgstatus program which demonstrates how to
@@ -10,6 +10,23 @@
*
* -----------------------------------------------------------------------
* $Log: mbgstatus.c $
+ * Revision 1.13.1.17 2011/10/05 15:10:56 martin
+ * Show PZF correlation state.
+ * Revision 1.13.1.16 2011/10/05 13:03:34 martin
+ * Adapted PZF correlation/signal/status display.
+ * Revision 1.13.1.15 2011/10/05 11:57:42 martin
+ * Revision 1.13.1.14 2011/09/29 16:30:03 martin
+ * Started to support PZF.
+ * Optionally show hex status.
+ * Changed what is displayed in certain levels of verbosity.
+ * Revision 1.13.1.13 2011/09/07 15:08:55 martin
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
+ * Revision 1.13.1.12 2011/07/08 11:02:47 martin
+ * Revision 1.13.1.11 2011/07/05 15:35:55 martin
+ * Modified version handling.
+ * Revision 1.13.1.10 2011/07/05 14:35:19 martin
+ * New way to maintain version information.
* Revision 1.13.1.9 2011/04/20 16:08:27 martin
* Use snprint_ip4_addr() from module lan_util.
* Revision 1.13.1.8 2011/03/03 10:01:23 daniel
@@ -86,9 +103,12 @@
#include <unistd.h>
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2001
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use current year by default
+
static const char *pname = "mbgstatus";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2001-2009";
+
static unsigned int verbose;
@@ -116,7 +136,7 @@ void print_pcps_time( const char *s, const PCPS_TIME *tp, const char *tail )
printf( fmt, pcps_date_time_str( ws, tp, year_limit, pcps_tz_name( tp, PCPS_TZ_NAME_FORCE_UTC_OFFS, 0 ) ) );
- if ( verbose > 1 )
+ if ( ( verbose > 0 ) && _pcps_time_is_read( tp ) )
printf( ", st: 0x%02lX", (ulong) tp->status );
if ( tail )
@@ -180,49 +200,10 @@ void print_position( const char *s, const POS *p, const char *tail )
static /*HDR*/
-void show_time_and_status( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, const char *tail )
+void show_signal( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, int signal )
{
- const char *status_fmt = "Status info: %s%s\n";
- const char *status_err = "*** ";
- const char *status_ok = "";
- PCPS_TIME t;
- PCPS_STATUS_STRS strs;
- int signal;
int ref_type;
- int i;
- int rc = mbg_get_time( dh, &t );
- if ( mbg_ioctl_err( rc, "mbg_get_time" ) )
- return;
-
-
- print_pcps_time( "Date/time: ", &t, tail );
-
- if ( ( verbose > 0 ) && _pcps_has_hr_time( pdev ) )
- {
- PCPS_HR_TIME ht;
- char ws[80];
-
- rc = mbg_get_hr_time( dh, &ht );
-
- if ( mbg_ioctl_err( rc, "mbg_get_hr_time" ) )
- return;
-
- mbg_snprint_hr_time( ws, sizeof( ws ), &ht );
- printf( "Local HR time: %s", ws );
-
- if ( verbose > 1 )
- printf( ", st: 0x%04lX", (ulong) ht.status );
-
- printf( "%s", tail );
- }
-
- signal = t.signal - PCPS_SIG_BIAS;
-
- if ( signal < 0 )
- signal = 0;
- else
- if ( signal > PCPS_SIG_MAX )
- signal = PCPS_SIG_MAX;
+ int rc;
ref_type = _pcps_ref_type( pdev );
@@ -266,8 +247,68 @@ void show_time_and_status( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, const char *
}
}
}
+ else
+ if ( _pcps_has_pzf( pdev ) )
+ printf( "/PZF" );
+
+ printf( ")\n" );
+
+} // show_signal
+
+
+
+static /*HDR*/
+void show_time_and_status( MBG_DEV_HANDLE dh, const PCPS_DEV *pdev, const char *tail )
+{
+ const char *status_fmt = "Status info: %s%s\n";
+ const char *status_err = "*** ";
+ const char *status_ok = "";
+ PCPS_TIME t;
+ PCPS_STATUS_STRS strs;
+ int signal;
+ int i;
+ int rc = mbg_get_time( dh, &t );
+ if ( mbg_ioctl_err( rc, "mbg_get_time" ) )
+ return;
+
+
+ print_pcps_time( "Date/time: ", &t, tail );
+
+ if ( ( verbose > 0 ) && _pcps_has_hr_time( pdev ) )
+ {
+ PCPS_HR_TIME ht;
+ char ws[80];
+
+ rc = mbg_get_hr_time( dh, &ht );
+
+ if ( mbg_ioctl_err( rc, "mbg_get_hr_time" ) )
+ return;
+
+ mbg_snprint_hr_time( ws, sizeof( ws ), &ht, 0 ); // raw timestamp?
+ printf( "Local HR time: %s", ws );
+
+ if ( verbose > 0 )
+ printf( ", st: 0x%04lX", (ulong) ht.status );
+
+ printf( "%s", tail );
+ }
+
+ signal = t.signal - PCPS_SIG_BIAS;
+
+ if ( signal < 0 )
+ signal = 0;
+ else
+ if ( signal > PCPS_SIG_MAX )
+ signal = PCPS_SIG_MAX;
- puts( ")" );
+ if ( _pcps_has_signal( pdev ) )
+ show_signal( dh, pdev, signal );
+
+ if ( _pcps_has_pzf( pdev ) )
+ {
+ mbg_show_pzf_corr_info( dh, pdev, 0 );
+ printf( "\n" );
+ }
if ( _pcps_has_irig_time( pdev ) )
{
@@ -342,14 +383,14 @@ void show_ext_stat_info( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *t
if ( mbg_ioctl_err( rc, "mbg_get_gps_stat_info" ) )
return;
+ rc = mbg_get_gps_stat_info( dh, &si );
- if ( _pcps_is_gps( p_dev ) )
- {
- rc = mbg_get_gps_stat_info( dh, &si );
+ if ( mbg_ioctl_err( rc, "mbg_get_gps_stat_info" ) )
+ return;
- if ( mbg_ioctl_err( rc, "mbg_get_gps_stat_info" ) )
- return;
+ if ( _pcps_is_gps( p_dev ) )
+ {
switch ( si.mode )
{
case AUTO_166: mode_name = "Normal Operation"; break;
@@ -365,16 +406,16 @@ void show_ext_stat_info( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev, const char *t
printf( "%s, %i sats in view, %i sats used\n", mode_name, si.svs_in_view, si.good_svs );
}
- printf( "Osc type: %s", osc_name[( ri.osc_type < N_GPS_OSC ) ? ri.osc_type : GPS_OSC_UNKNOWN] );
-
- if ( _pcps_is_gps( p_dev ) )
+ if ( verbose )
{
+ printf( "Osc type: %s", osc_name[( ri.osc_type < N_GPS_OSC ) ? ri.osc_type : GPS_OSC_UNKNOWN] );
+
printf( ", DAC cal: %+i, fine: %+i",
- (int) ( si.dac_cal - OSC_DAC_BIAS ),
- (int) ( si.dac_val - OSC_DAC_BIAS ) );
- }
+ (int) ( si.dac_cal - OSC_DAC_BIAS ),
+ (int) ( si.dac_val - OSC_DAC_BIAS ) );
- puts( "" );
+ puts( "" );
+ }
if ( tail )
printf( fmt, tail );
@@ -613,13 +654,14 @@ void show_ptp_state( MBG_DEV_HANDLE dh )
cp = ptp_state_available ? ws : str_not_avail;
+//##++++++++++
snprintf( ws, sizeof( ws ), "%02X-%02X-%02X-%02X-%02X-%02X",
- ptp_state.gm_identity.b[0],
- ptp_state.gm_identity.b[1],
- ptp_state.gm_identity.b[2],
- ptp_state.gm_identity.b[5],
- ptp_state.gm_identity.b[6],
- ptp_state.gm_identity.b[7]
+ ptp_state.gm_id.b[0],
+ ptp_state.gm_id.b[1],
+ ptp_state.gm_id.b[2],
+ ptp_state.gm_id.b[5],
+ ptp_state.gm_id.b[6],
+ ptp_state.gm_id.b[7]
);
printf( " Grandmaster MAC: %s\n", cp );
@@ -712,7 +754,7 @@ int do_mbgstatus( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
if ( _pcps_is_gps( p_dev ) )
show_gps_pos( dh, "\n" );
- if ( _pcps_has_utc_parm( p_dev ) )
+ if ( _pcps_has_utc_parm( p_dev ) && ( _pcps_is_gps( p_dev ) || ( verbose > 0 ) ) )
show_utc_info( dh, p_dev );
if ( _pcps_has_irig_ctrl_bits( p_dev ) )
@@ -762,7 +804,7 @@ int main( int argc, char *argv[] )
ctry.dt_fmt = DT_FMT_YYYYMMDD;
ctry.dt_sep = '-';
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "vh?" ) ) != -1 )
diff --git a/mbgsvcd/Makefile b/mbgsvcd/Makefile
index d8a8fe8..0da8003 100755
--- a/mbgsvcd/Makefile
+++ b/mbgsvcd/Makefile
@@ -1,14 +1,14 @@
#########################################################################
#
-# $Id: Makefile 1.1.1.2.1.1 2010/09/20 12:07:10 stefan TEST $
+# $Id: Makefile 1.1.1.3 2011/09/26 16:07:31 martin TEST martin $
#
# Description:
# Makefile for mbgsvcd.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
-# Revision 1.1.1.2.1.1 2010/09/20 12:07:10 stefan
+# Revision 1.1.1.3 2011/09/26 16:07:31 martin
# Updated for use with latest base Makefile.
# Revision 1.1.1.2 2010/08/30 09:05:24 martin
# Revision 1.1.1.1 2010/08/30 08:22:06 martin
@@ -18,7 +18,7 @@
#########################################################################
TARGET = mbgsvcd
-INST_TO_BIN = 1
+INST_TO_SBIN = 1
OBJS = $(TARGET).o
OBJS += mbgdevio.o
diff --git a/mbgsvcd/mbgsvcd.c b/mbgsvcd/mbgsvcd.c
index 1a4921e..d58c95b 100755
--- a/mbgsvcd/mbgsvcd.c
+++ b/mbgsvcd/mbgsvcd.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgsvcd.c 1.3.1.3 2011/03/25 11:05:24 martin TRASH $
+ * $Id: mbgsvcd.c 1.3.1.13 2011/10/06 13:03:46 martin TEST $
*
* Description:
* Main file for mbgsvcd which compares the system time to a PCI card's
@@ -9,6 +9,30 @@
*
* -----------------------------------------------------------------------
* $Log: mbgsvcd.c $
+ * Revision 1.3.1.13 2011/10/06 13:03:46 martin
+ * Combined printf() and syslog() to mbg_log().
+ * Cleanup.
+ * Revision 1.3.1.12 2011/10/05 15:11:50 martin
+ * Log reasons for error if function calls fail.
+ * Revision 1.3.1.11 2011/09/07 15:08:56 martin
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
+ * Revision 1.3.1.10 2011/07/14 13:30:57 martin
+ * Code cleanup.
+ * Eliminated some potential warnings due to ignored function return values.
+ * Revision 1.3.1.9 2011/07/05 15:35:55 martin
+ * Modified version handling.
+ * Revision 1.3.1.8 2011/07/05 14:35:19 martin
+ * New way to maintain version information.
+ * Revision 1.3.1.7 2011/06/23 15:35:40 martin
+ * Skip devices which don't support HR time immediately at startup.
+ * Revision 1.3.1.6 2011/06/23 15:02:55 martin
+ * Compute execution time limit in cycles instead of us so this can also
+ * be done if the cycle counter clock rate can not be determined.
+ * Revision 1.3.1.5 2011/06/23 12:45:37 martin
+ * Workaround in case cycle frequency can not be determined.
+ * Revision 1.3.1.4 2011/06/20 15:10:22 martin
+ * Using generic MBG_SYS_TIME with nanosecond resolution.
* Revision 1.3.1.3 2011/03/25 11:05:24 martin
* Optionally support timespec for sys time.
* Cleanup.
@@ -44,36 +68,88 @@
#include <fcntl.h>
#include <signal.h>
#include <syslog.h>
+#include <stdarg.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#define NTPD_BASE 0x4e545030 /* "NTP0" */
-#define SHM_UNIT 0 /* SHM driver unit number (0..3) */
-#define MAX_SHM_REFCLOCKS 4
+#define NTPD_BASE 0x4e545030 /* "NTP0" */
+#define MAX_SHM_REFCLOCKS 4
-#define RUNNING_DIR "/var/run"
-#define LOCK_FILE "mbgsvcd.pid"
+#define RUNNING_DIR "/var/run"
+#define LOCK_FILE "mbgsvcd.pid"
-#define EXEC_TIME_SAMPLES 20
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2010
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
static const char *pname = "mbgsvcd";
-static const char *pversion = "v1.2";
-static const char *pcopyright = "(c) Meinberg 2010-2011";
static int sleep_intv = 1;
static int pretend_sync;
+
+#define MAX_FILTER_ENTRIES 32
+
+typedef struct
+{
+ MBG_PC_CYCLES cyc[MAX_FILTER_ENTRIES];
+ MBG_PC_CYCLES sum;
+ int entries;
+ int index;
+} FILTER;
+
+static FILTER filter;
+
+
+
+static /*HDR*/
+void mbg_log( int lvl, const char *fmt, ... )
+{
+ char ws[256];
+ va_list ap;
+
+ va_start( ap, fmt );
+ vsnprintf( ws, sizeof( ws ), fmt, ap );
+ va_end( ap );
+
+ syslog( lvl, ws );
+ fprintf( stdout, "%s\n", ws );
+
+} // mbg_log
+
+
+
+static /*HDR*/
+MBG_PC_CYCLES do_filter( FILTER *p, MBG_PC_CYCLES cyc )
+{
+ if ( p->entries < MAX_FILTER_ENTRIES )
+ p->entries++;
+
+ if ( ++( p->index ) >= MAX_FILTER_ENTRIES )
+ p->index = 0;
+
+ // update the sum of filter entries
+ p->sum -= p->cyc[p->index]; // subtract oldest sample
+ p->cyc[p->index] = cyc; // save new sample
+ p->sum += cyc; // add new sample
+
+ return p->sum / p->entries; // return mean value
+
+} /* do_filter */
+
+
+
struct shmTime {
int mode; /* 0 - if valid set
- * use values,
+ * use values,
* clear valid
- * 1 - if valid set
- * if count before and after read of
+ * 1 - if valid set
+ * if count before and after read of
* values is equal,
- * use values
+ * use values
* clear valid
*/
int count;
@@ -85,78 +161,71 @@ struct shmTime {
int precision;
int nsamples;
int valid;
- int dummy[10];
+ int dummy[10];
};
-struct shmTime *shmTime[MAX_SHM_REFCLOCKS];
+static struct shmTime *shmTime[MAX_SHM_REFCLOCKS];
-static
-struct shmTime *getShmTime(int unit)
+static
+struct shmTime *getShmTime( int unit )
{
+ struct shmTime *p;
+
int shmid = shmget( (key_t) ( NTPD_BASE + unit ),
- sizeof( struct shmTime ), IPC_CREAT | 0644 );
+ sizeof( struct shmTime ), IPC_CREAT | 0644 );
- if ( shmid == -1 )
+ if ( shmid == -1 )
{
- syslog(LOG_ERR, "shmget failed\n");
+ mbg_log( LOG_ERR, "shmget %i failed: %s", unit, strerror( errno ) );
return NULL;
}
- else
- {
- struct shmTime *p = ( struct shmTime * ) shmat( shmid, 0, 0);
-
- if ( (int) (long) p == -1 )
- {
- syslog(LOG_ERR, "shmat failed\n" );
- return NULL;
- }
-
- syslog(LOG_INFO, "shmat(%d,0,0) succeeded\n", shmid);
- return p;
- }
-}
+ p = (struct shmTime *) shmat( shmid, 0, 0 );
-static /*HDR*/
-void ntpshm_init( void )
-{
- int i = 0;
-
- syslog(LOG_INFO, "Initializing shared memory for ntpd");
+ if ( (long) p == -1L )
+ {
+ mbg_log( LOG_ERR, "shmat %i failed: %s", unit, strerror( errno ) );
+ return NULL;
+ }
- for ( i = 0; i< MAX_SHM_REFCLOCKS; i++ )
- shmTime[i] = getShmTime( i );
+ return p;
-} // ntpshm_init
+} // getShmTime
static /*HDR*/
-int ntpshm_alloc( void )
+int ntpshm_init( int n_units )
{
int i;
+ int ret_val = 0;
- for ( i = 0; i< MAX_SHM_REFCLOCKS; i++)
+ for ( i = 0; i < n_units; i++ )
{
- struct shmTime *p = shmTime[i];
+ struct shmTime *p = getShmTime( i );
+ shmTime[i] = p;
- if ( p )
+ if ( p == NULL )
{
- memset( p, 0, sizeof( *p ) );
+ mbg_log( LOG_WARNING, "** Failed to initialize NTP SHM unit %i", i );
+ ret_val = -1;
+ continue;
+ }
- p->mode = 1;
- p->precision = -5; /* initially 0.5 sec */
- p->nsamples = 3; /* stages of median filter */
+ memset( p, 0, sizeof( *p ) );
- printf( "Shared memory %d initialized\n", i );
- }
+ p->mode = 1;
+ p->precision = -5; /* initially 0.5 sec */
+ p->nsamples = 3; /* stages of median filter */
+
+ mbg_log( LOG_INFO, "NTP SHM unit %i initialized successfully", i );
}
- return 0;
+ return ret_val;
-} // ntpshm_alloc
+} // ntpshm_init
@@ -172,70 +241,84 @@ int do_mbgsvctasks( void )
double d_ref;
double d_sys;
int rc = 0;
- int n_devices = 0;
- MBG_DEV_HANDLE dhs[4];
- PCPS_DEV devs[4];
- int i,excnt;
- double exec_limit = 30.0;
- double exec_times[EXEC_TIME_SAMPLES];
+ int n_devices_found;
+ int n_devices;
+ MBG_DEV_HANDLE dhs[MAX_SHM_REFCLOCKS];
+ PCPS_DEV devs[MAX_SHM_REFCLOCKS];
+ int i;
- n_devices = mbg_find_devices();
+ n_devices_found = mbg_find_devices();
- i = excnt = 0;
+ for ( i = 0, n_devices = 0; i < n_devices_found; i++ )
+ {
+ MBG_DEV_HANDLE dh = mbg_open_device( i );
+ PCPS_DEV dev_info;
+
+ rc = mbg_get_device_info( dh, &dev_info );
+
+ if ( rc < 0 )
+ {
+ mbg_log( LOG_WARNING, "Failed to read device info from device #%i.", i );
+ mbg_close_device( &dh );
+ continue;
+ }
+
+ if ( !_pcps_has_hr_time( &dev_info ) )
+ {
+ mbg_log( LOG_WARNING, "Device %s does not support HR time stamps.",
+ _pcps_type_name( &dev_info ) );
+ mbg_close_device( &dh );
+ continue;
+ }
+
+ dhs[n_devices] = dh;
+ devs[n_devices] = dev_info;
+
+ if ( ++n_devices >= MAX_SHM_REFCLOCKS )
+ break;
+ }
if ( n_devices == 0 )
{
- printf("No devices found!\n");
+ mbg_log( LOG_WARNING, "No usable device found!" );
goto done;
}
+
// Search for devices up to the maximum of supported NTP SHM refclocks
if ( n_devices > MAX_SHM_REFCLOCKS )
n_devices = MAX_SHM_REFCLOCKS;
- syslog(LOG_INFO, "Found %d devices for NTPD", n_devices);
-
- for ( i = 0; i < n_devices; i++ )
- {
- dhs[i] = mbg_open_device(i);
- mbg_get_device_info( dhs[i], &devs[i] );
- }
+ mbg_log( LOG_INFO, "Found %d devices usable for the NTP daemon", n_devices ); //##++++
rc = mbg_get_default_cycles_frequency_from_dev( dhs[0], &cyc_freq );
if ( mbg_ioctl_err( rc, "mbg_get_default_cycles_frequency_from_dev" ) )
goto done;
- printf( "PC cycles counter clock frequency: %Lu Hz\n",
- (unsigned long long) cyc_freq );
+
+ mbg_log( LOG_INFO, "%sPC cycles counter clock frequency: %Lu Hz",
+ ( cyc_freq == 0 ) ? "*** Warning: " : "",
+ (unsigned long long) cyc_freq );
// Initialize NTP shared memory area
- ntpshm_init();
- ntpshm_alloc();
+ ntpshm_init( n_devices );
for (;;)
{
for ( i = 0; i < n_devices; i++ )
{
- double ltcy_us;
- double exec_us;
double ltcy_sec;
- double exec_sec;
double d_ref_comp;
MBG_PC_CYCLES ltcy_cyc;
MBG_PC_CYCLES exec_cyc;
+ MBG_PC_CYCLES exec_cyc_limit;
+ MBG_PC_CYCLES tmp;
const char *cp;
- if ( !_pcps_has_hr_time( &devs[i] ) )
- {
- printf( "This device does not support HR time stamps.\n" );
- continue;
- }
-
-
rc = mbg_get_time_info_hrt( dhs[i], &hrti );
- if ( mbg_ioctl_err( rc, "mbg_get_time_info_..." ) )
+ if ( mbg_ioctl_err( rc, "mbg_get_time_info_hrt" ) )
continue;
@@ -244,93 +327,98 @@ int do_mbgsvctasks( void )
p_sys_tic = &hrti.sys_time_cycles;
d_ref = (double) p_ref_ts->sec + ( (double) p_ref_ts->frac ) / (double) PCPS_HRT_BIN_FRAC_SCALE;
-
- d_sys = (double) p_sys_tic->sys_time.tv_sec;
- #if USE_TIMESPEC // use struct timespec
- d_sys += (double) p_sys_tic->sys_time.tv_nsec / 1e9;
- #else // use struct timeval
- d_sys += (double) p_sys_tic->sys_time.tv_usec / 1e6;
- #endif
+ d_sys = (double) p_sys_tic->sys_time.sec + (double) p_sys_tic->sys_time.nsec / 1e9;
ltcy_cyc = mbg_delta_pc_cycles( p_ref_cyc, &p_sys_tic->cyc_after );
exec_cyc = mbg_delta_pc_cycles( &p_sys_tic->cyc_after, &p_sys_tic->cyc_before );
- ltcy_sec = ( (double) ltcy_cyc ) / (double) cyc_freq;
- exec_sec = ( (double) exec_cyc ) / (double) cyc_freq;
+ ltcy_sec = cyc_freq ? ( ( (double) ltcy_cyc ) / (double) cyc_freq ) : 0.0;
- // compensate latencies between time stamps ->
+ // Compensate latencies between time stamps ->
// normalize ref time to system time stamp
d_ref_comp = d_ref - ltcy_sec;
- ltcy_us = ltcy_sec * 1e6;
- exec_us = exec_sec * 1e6;
+ exec_cyc_limit = do_filter( &filter, exec_cyc );
- exec_times[excnt++] = exec_us;
+ // Try to set the limit to 1.7 of the mean execution cycles.
+ tmp = ( 7 * exec_cyc_limit ) / 10;
- if ( excnt == EXEC_TIME_SAMPLES )
- {
- exec_limit = 0;
-
- for ( excnt = 0; excnt < EXEC_TIME_SAMPLES; excnt++ )
- exec_limit += exec_times[excnt];
-
- exec_limit /= ( (double) EXEC_TIME_SAMPLES );
- exec_limit *= 1.7;
- excnt = 0;
- }
+ // If execution takes only a few cycles make sure the limit
+ // is above the mean number of cycles.
+ if ( tmp == 0 )
+ tmp++;
+ exec_cyc_limit += tmp;
cp = "";
// check if refclock is sync and if exec time of the system time call was fast enough
- if ( pretend_sync || ( ( ( hrti.ref_hr_time_cycles.t.status & PCPS_FREER ) == 0 )
- && ( ( hrti.ref_hr_time_cycles.t.status & PCPS_SYNCD ) != 0 )
- && ( exec_us < exec_limit ) ) )
+ if ( ( exec_cyc <= exec_cyc_limit ) && ( pretend_sync || (
+ ( ( hrti.ref_hr_time_cycles.t.status & PCPS_FREER ) == 0 ) &&
+ ( ( hrti.ref_hr_time_cycles.t.status & PCPS_SYNCD ) != 0 ) ) ) )
{
struct shmTime *p = shmTime[i];
- cp = " *";
-
- // fill SHM structure
- p->count++;
- p->clockTimeStampSec = (time_t) d_ref_comp;
- p->clockTimeStampUSec = (int) ( ( d_ref_comp - p->clockTimeStampSec ) * 1e6 ); // get µs from d_ref
- p->receiveTimeStampSec = (time_t) p_sys_tic->sys_time.tv_sec;
- #if USE_TIMESPEC // use struct timespec
- p->receiveTimeStampUSec = (int) ( p_sys_tic->sys_time.tv_nsec / 1000 );
- #else // use struct timeval
- p->receiveTimeStampUSec = (int) p_sys_tic->sys_time.tv_usec;
- #endif
-
- // patch precision value according to the ref time accuracy
- if ( _pcps_is_lwr( &devs[i] ) )
- p->precision = -8;
- else if (_pcps_is_irig_rx( &devs[i] ) )
+ if ( p )
{
- if ( _pcps_is_usb( &devs[i] ) )
- p->precision = -10;
+ cp = " *";
+
+ // fill SHM structure
+ p->count++;
+ p->clockTimeStampSec = (time_t) d_ref_comp;
+ p->clockTimeStampUSec = (int) ( ( d_ref_comp - p->clockTimeStampSec ) * 1e6 ); // get µs from d_ref
+ p->receiveTimeStampSec = (time_t) p_sys_tic->sys_time.sec;
+ p->receiveTimeStampUSec = (int) ( p_sys_tic->sys_time.nsec / 1000 );
+
+ // patch precision value according to the ref time accuracy
+ if ( _pcps_is_lwr( &devs[i] ) )
+ p->precision = -8;
else
- p->precision = -18;
+ {
+ if ( _pcps_is_irig_rx( &devs[i] ) )
+ {
+ if ( _pcps_is_usb( &devs[i] ) )
+ p->precision = -10;
+ else
+ p->precision = -18;
+ }
+ else
+ p->precision = -20;
+ }
+
+ p->count++;
+ p->valid = 1;
}
- else
- p->precision = -20;
-
- p->count++;
- p->valid = 1;
}
- mbg_snprint_hr_tstamp( ws, sizeof( ws ), p_ref_ts );
+ mbg_snprint_hr_tstamp( ws, sizeof( ws ), p_ref_ts, 0 ); // raw timestamp?
- printf( "%-9s: %s: %.7f-%.7f: %+.7f %+.7f, "
- "ltcy: %.2f us, exec: %.2f us, limit: %.2f us%s\n",
+ printf( "%-9s: %s: %.7f-%.7f: %+.7f %+.7f, ltcy: ",
_pcps_type_name( &devs[i] ), ws, d_ref, d_sys,
- d_ref - d_sys, d_ref_comp - d_sys,
- ltcy_us, exec_us, exec_limit, cp );
+ d_ref - d_sys, d_ref_comp - d_sys );
+
+ if ( cyc_freq != 0 ) // print latency and execution time in microseconds
+ {
+ double exec_sec = (double) exec_cyc / (double) cyc_freq;
+ double exec_sec_limit = (double) exec_cyc_limit / (double) cyc_freq;
+
+ printf( "%.2f us, exec: %.2f us, limit: %.2f us",
+ ltcy_sec * 1e6, exec_sec * 1e6, exec_sec_limit * 1e6 );
+ }
+ else // print latency and execution time in cycles only
+ {
+ printf( "%lli cyc, exec: %lli cyc, limit: %lli cyc",
+ (long long) ltcy_cyc, (long long) exec_cyc,
+ (long long) exec_cyc_limit );
+ }
+
+ printf( "%s\n", cp );
usleep( 10 );
}
- printf("\n");
+ if ( n_devices > 1 )
+ printf( "\n" );
if ( sleep_intv )
sleep( sleep_intv );
@@ -350,10 +438,12 @@ static /*HDR*/
void usage( void )
{
mbg_print_usage_intro( pname,
- "This deamon reads a time stamp from every refclock together.\n"
- "with an associated system time stamp and transfers it to the SHM\n"
- "refclock driver of NTP.\n"
- "This works only with cards which support high resolution time stamps."
+ "This program periodically reads a reference time stamp and an associated\n"
+ "system time stamp from every mbgclock device, and feeds the time stamp pairs\n"
+ "to the NTP daemon's shared memory refclock driver.\n"
+ "It usually runs as daemon but can also be run in the foreground to monitor the\n"
+ "time stamps and offsets.\n"
+ "This works only for cards supporting high resolution time stamps.\n"
);
mbg_print_help_options();
mbg_print_opt_info( "-f", "run program in foreground" );
@@ -369,51 +459,58 @@ void usage( void )
static /*HDR*/
void startup_daemon( void )
{
- int i,lfp;
+ int i;
+ int lfp;
+ int rc;
char str[1024];
- if (getppid()==1)
+ if ( getppid() == 1 )
return; /* already a daemon */
- printf ("Daemon mode, backgrounding ... \n");
- i=fork();
+ mbg_log( LOG_INFO, "Daemon mode, backgrounding" );
+ i = fork();
+
+ if ( i < 0 )
+ exit( 1 ); /* fork error */
- if (i<0)
- exit(1); /* fork error */
+ if ( i > 0 )
+ exit( 0 ); /* parent exits */
- if (i>0)
- exit(0); /* parent exits */
/* child (daemon) continues */
setsid(); /* obtain a new process group */
- for (i=getdtablesize(); i>=0; --i)
- close(i); /* close all descriptors */
- i=open("/dev/null",O_RDWR); dup(i); dup(i); /* handle standart I/O */
+ for ( i = getdtablesize(); i >= 0; --i )
+ close( i ); /* close all descriptors */
- umask(027); /* set newly created file permissions */
- chdir(RUNNING_DIR); /* change running directory */
+ /* handle standard I/O */
+ i = open( "/dev/null", O_RDWR );
+ rc = dup( i );
+ rc = dup( i );
- lfp = open(LOCK_FILE,O_RDWR|O_CREAT,0640);
+ umask( 027 ); /* set newly created file permissions */
+ rc = chdir( RUNNING_DIR ); /* change running directory */
- if (lfp<0)
- exit(1); /* can not open */
+ lfp = open( LOCK_FILE, O_RDWR | O_CREAT, 0640 );
- if (lockf(lfp,F_TLOCK,0)<0)
+ if ( lfp < 0 )
+ exit( 1 ); /* unable to open lock file */
+
+ if ( lockf( lfp, F_TLOCK, 0 ) < 0 )
{
- syslog(LOG_ERR, "Lock file already exists, another instance of this daemon seems to be running");
+ mbg_log( LOG_ERR, "Lock file already exists, another instance of this daemon seems to be running" );
closelog();
- exit(0); /* can not lock */
+ exit( 0 ); /* can not lock */
}
/* first instance continues */
- sprintf(str,"%d\n",getpid());
- write(lfp,str,strlen(str)); /* record pid to lockfile */
+ snprintf( str, sizeof( str ), "%d\n", getpid() );
+ rc = write( lfp, str, strlen( str ) ); /* record pid to lockfile */
- signal(SIGCHLD,SIG_IGN); /* ignore child */
- signal(SIGTSTP,SIG_IGN); /* ignore tty signals */
- signal(SIGTTOU,SIG_IGN);
- signal(SIGTTIN,SIG_IGN);
+ signal( SIGCHLD, SIG_IGN ); /* ignore child */
+ signal( SIGTSTP, SIG_IGN ); /* ignore tty signals */
+ signal( SIGTTOU, SIG_IGN );
+ signal( SIGTTIN, SIG_IGN );
} // startup_daemon
@@ -425,11 +522,7 @@ int main( int argc, char *argv[] )
int c;
int foreground = 0;
- mbg_print_program_info( pname, pversion, pcopyright );
-
- #if ( USE_TIMESPEC )
- printf( "(using nanosecond resolution)\n\n" );
- #endif
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "fps:h?" ) ) != -1 )
@@ -462,9 +555,16 @@ int main( int argc, char *argv[] )
}
if ( foreground == 0 )
- startup_daemon();
+ {
+ char ws[256];
+
+ mbg_program_info_str( ws, sizeof( ws ), pname, MBG_MICRO_VERSION,
+ MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
+
+ mbg_log( LOG_INFO, "Starting Meinberg Service Daemon %s", ws );
- syslog( LOG_INFO, "Starting Meinberg Service Daemon %s %s %s", pname, pversion, pcopyright );
+ startup_daemon();
+ }
rc = do_mbgsvctasks();
diff --git a/mbgversion.h b/mbgversion.h
new file mode 100755
index 0000000..55d4d8d
--- /dev/null
+++ b/mbgversion.h
@@ -0,0 +1,29 @@
+
+/**************************************************************************
+ *
+ * $Id: mbgversion.h 1.1 2011/07/06 13:24:48 martin TEST $
+ *
+ * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
+ *
+ * Description:
+ * Program version definitions for package mbgtools-fbsd.
+ *
+ * -----------------------------------------------------------------------
+ * $Log: mbgversion.h $
+ * Revision 1.1 2011/07/06 13:24:48 martin
+ * Initial revision.
+ *
+ **************************************************************************/
+
+#define MBG_CURRENT_COPYRIGHT_YEAR 2011
+#define MBG_CURRENT_COPYRIGHT_YEAR_STR "2011"
+
+#define MBG_MAJOR_VERSION_CODE 0
+#define MBG_MINOR_VERSION_CODE 99
+
+#define MBG_MAIN_VERSION_STR "0.99"
+
+
+#define MBG_MAIN_VERSION_CODE ( ( MBG_MAJOR_VERSION_CODE << 8 ) | MBG_MINOR_VERSION_CODE )
+
+#define MBG_VERSION_CODE( _micro ) ( (uint16_t) ( ( MBG_MAIN_VERSION_CODE << 8 ) | (_micro) ) )
diff --git a/mbgxhrtime/Makefile b/mbgxhrtime/Makefile
index 75d6673..4162670 100755
--- a/mbgxhrtime/Makefile
+++ b/mbgxhrtime/Makefile
@@ -1,14 +1,14 @@
#########################################################################
#
-# $Id: Makefile 1.2.1.2.1.1 2010/09/20 12:07:14 stefan TEST $
+# $Id: Makefile 1.2.1.3 2011/09/26 16:07:31 martin TEST $
#
# Description:
# Makefile for mbgxhrtime.
#
# -----------------------------------------------------------------------
# $Log: Makefile $
-# Revision 1.2.1.2.1.1 2010/09/20 12:07:14 stefan
+# Revision 1.2.1.3 2011/09/26 16:07:31 martin
# Updated for use with latest base Makefile.
# Revision 1.2.1.2 2010/08/30 09:05:24 martin
# Revision 1.2.1.1 2010/08/30 08:22:11 martin
diff --git a/mbgxhrtime/mbgxhrtime.c b/mbgxhrtime/mbgxhrtime.c
index bceb331..863ba08 100755
--- a/mbgxhrtime/mbgxhrtime.c
+++ b/mbgxhrtime/mbgxhrtime.c
@@ -1,7 +1,7 @@
/**************************************************************************
*
- * $Id: mbgxhrtime.c 1.5 2009/09/29 14:25:07 martin REL_M $
+ * $Id: mbgxhrtime.c 1.5.1.3 2011/09/07 15:08:56 martin TEST martin $
*
* Description:
* Main file for mbgxhrtime program which demonstrates how to retrieve
@@ -41,6 +41,13 @@
*
* -----------------------------------------------------------------------
* $Log: mbgxhrtime.c $
+ * Revision 1.5.1.3 2011/09/07 15:08:56 martin
+ * Account for modified library functions which can now
+ * optionally print the raw (hex) HR time stamp.
+ * Revision 1.5.1.2 2011/07/05 15:35:56 martin
+ * Modified version handling.
+ * Revision 1.5.1.1 2011/07/05 14:36:11 martin
+ * New way to maintain version information.
* Revision 1.5 2009/09/29 14:25:07 martin
* Display measured and default PC cycles frequency.
* Updated version number to 3.4.0.
@@ -79,9 +86,12 @@
#endif
+#define MBG_MICRO_VERSION 0
+#define MBG_FIRST_COPYRIGHT_YEAR 2008
+#define MBG_LAST_COPYRIGHT_YEAR 0 // use default
+
static const char *pname = "mbgxhrtime";
-static const char *pversion = "v3.4.0";
-static const char *pcopyright = "(c) Meinberg 2008-2009";
+
static int loops;
@@ -232,7 +242,7 @@ int do_mbgxhrtime( MBG_DEV_HANDLE dh, const PCPS_DEV *p_dev )
latency = ( (double) cyc_2 - (double) cyc_1 ) / (double) freq_hz * 1E6;
// convert to human readable date and time
- mbg_snprint_hr_time( ws, sizeof( ws ), &hrt );
+ mbg_snprint_hr_time( ws, sizeof( ws ), &hrt, 0 ); // raw timestamp?
printf( "t: %s (%.3f us)\n", ws, latency );
if ( this_loops > 0 )
@@ -290,7 +300,7 @@ int main( int argc, char *argv[] )
int rc;
int c;
- mbg_print_program_info( pname, pversion, pcopyright );
+ mbg_print_program_info( pname, MBG_MICRO_VERSION, MBG_FIRST_COPYRIGHT_YEAR, MBG_LAST_COPYRIGHT_YEAR );
// check command line parameters
while ( ( c = getopt( argc, argv, "cn:h?" ) ) != -1 )
diff --git a/scripts/mbgsvcd b/scripts/mbgsvcd
new file mode 100755
index 0000000..ed3b2f8
--- /dev/null
+++ b/scripts/mbgsvcd
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# $Id: mbgsvcd 1.1 2011/07/06 13:26:01 martin TEST $
+#
+# PROVIDE: mbgsvcd
+# REQUIRE: DAEMON
+# KEYWORD: shutdown
+
+. /etc/rc.subr
+
+name="mbgsvcd"
+rcvar=`set_rcvar`
+command="/usr/local/sbin/${name}"
+
+load_rc_config $name
+
+#
+# DO NOT CHANGE THESE DEFAULT VALUES HERE
+# SET THEM IN THE /etc/rc.conf FILE
+#
+## utility_enable=${utility_enable-"NO"}
+## utility_pidfile=${utility_pidfile-"/var/run/utility.pid"}
+
+## pidfile="${utility_pidfile}"
+
+run_rc_command "$1"