diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2009-01-21 12:33:00 +0100 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2009-01-21 12:33:00 +0100 |
commit | 7936c9bd1d3a209af0ebc2a2b0b325ec8586c1a6 (patch) | |
tree | 68bf3238c67c21dfaa2bc18797de77aab32570c9 | |
parent | d578cd1b41510aabd394e785ed2b04ad5e050f8a (diff) | |
download | mbgsdk-win-7936c9bd1d3a209af0ebc2a2b0b325ec8586c1a6.tar.gz mbgsdk-win-7936c9bd1d3a209af0ebc2a2b0b325ec8586c1a6.zip |
Update some mbglib source files
-rw-r--r-- | c/mbglib/include/mbg_tgt.h | 232 | ||||
-rw-r--r-- | c/mbglib/include/mbgsvcio.h | 93 | ||||
-rw-r--r-- | c/mbglib/include/pcpsdefs.h | 904 | ||||
-rw-r--r-- | c/mbglib/include/use_pack.h | 2 | ||||
-rw-r--r-- | c/mbglib/include/words.h | 192 |
5 files changed, 1088 insertions, 335 deletions
diff --git a/c/mbglib/include/mbg_tgt.h b/c/mbglib/include/mbg_tgt.h index 2bca823..6bd9919 100644 --- a/c/mbglib/include/mbg_tgt.h +++ b/c/mbglib/include/mbg_tgt.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_tgt.h 1.5 2003/12/17 16:11:41Z martin TEST $ + * $Id: mbg_tgt.h 1.16 2008/12/08 16:42:30Z martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,6 +11,43 @@ * * ----------------------------------------------------------------------- * $Log: mbg_tgt.h $ + * Revision 1.16 2008/12/08 16:42:30Z martin + * Defined _GNU_SOURCE for Linux. + * Revision 1.15 2008/11/19 15:31:49 martin + * Added symbol MBG_ARCH_I386. + * Revision 1.14 2008/09/03 15:06:04 martin + * Support DOS protected mode target. + * Support SUN SPARC architecture. + * Specified handle types for common host environments. + * Added macro MBG_USE_MM_IO_FOR_PCI. + * Added macro _nop_macro_fnc(). + * Revision 1.13 2008/01/30 15:52:22 martin + * Modified checking for availability of wchar_t. + * Revision 1.13 2008/01/29 15:18:07Z martin + * Recognize DOS target under Watcom compilers. + * Flag Watcom C always supports wchar_t. + * Revision 1.12 2008/01/17 09:38:50Z daniel + * Added macros to determine whether C language extensions + * (e.g. C94, C99) are supported by the target environment. + * Added macro to check whether wchar_t and friends are + * supported, and some compatibility stuff. + * Revision 1.11 2007/10/31 16:58:03 martin + * Fixed __mbg_inline for Borland C (DOS). + * Revision 1.10 2007/09/25 08:10:27Z martin + * Support CVI target environment. + * Added MBG_PORT_HANDLE type for serial ports. + * Added macros for unified inline code syntax. + * Revision 1.9 2006/12/08 12:45:54Z martin + * Under Windows include ntddk.h rather than windows.h + * if building kernel driver . + * Revision 1.8 2006/10/25 12:20:45Z martin + * Initial support for FreeBSD, NetBSD, and OpenBSD. + * Added definitions for generic handle types. + * Revision 1.7 2006/08/23 13:43:55 martin + * Added definition for MBG_TGT_UNIX. + * Minor syntax fixes. + * Revision 1.6 2006/01/25 14:37:06 martin + * Added definitions for 64 bit Windows environments. * Revision 1.5 2003/12/17 16:11:41Z martin * Split API modifiers into _MBG_API and _MBG_API_ATTR. * Revision 1.4 2003/06/19 08:20:22Z martin @@ -30,6 +67,8 @@ /* Other headers to be included */ +#include <stddef.h> + #ifdef _MBG_TGT #define _ext #else @@ -39,7 +78,11 @@ /* Start of header body */ -#if defined( _WIN32_WINNT ) +#if defined( _CVI ) + + #define MBG_TGT_CVI + +#elif defined( _WIN32_WINNT ) // MS platform SDK // WinNT 4.0 and above @@ -74,6 +117,11 @@ // MS Visual C++ #define MBG_TGT_WIN32 +#elif defined( __WINDOWS_386__ ) + + // Watcom C/C++ for target Win32 + #define MBG_TGT_WIN32 + #elif defined( __NETWARE_386__ ) // Watcom C/C++ for target NetWare @@ -88,6 +136,22 @@ // GCC for target Linux #define MBG_TGT_LINUX + #define _GNU_SOURCE 1 + +#elif defined( __FreeBSD__ ) + + // GCC for target FreeBSD + #define MBG_TGT_FREEBSD + +#elif defined( __NetBSD__ ) + + // GCC for target NetBSD + #define MBG_TGT_NETBSD + +#elif defined( __OpenBSD__ ) + + // GCC for target FreeBSD + #define MBG_TGT_OPENBSD #elif defined( __QNX__ ) @@ -99,33 +163,191 @@ #define MBG_TGT_QNX_NTO #endif -#elif defined( __MSDOS__ ) +#elif defined( __MSDOS__ ) || defined( __DOS__ ) // any compiler for target DOS #define MBG_TGT_DOS + #if defined( __WATCOMC__ ) && defined( __386__ ) + + #define MBG_TGT_DOS_PM // protected mode DOS + + #endif + +#endif + +// Some definitions which depend on the type of compiler ... + +#if defined( __GNUC__ ) + + #define __mbg_inline __inline__ + + #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + + #if defined( __sparc__ ) + #define MBG_ARCH_SPARC + #endif + +#elif defined( _MSC_VER ) + + #define __mbg_inline __forceinline + + #define MBG_TGT_HAS_WCHAR_T 1 + +#elif defined( _CVI ) + + #define __mbg_inline //##++++ + + #define MBG_TGT_HAS_WCHAR_T 0 + +#elif defined( __BORLANDC__ ) + + #if defined( __cplusplus ) + #define __mbg_inline inline + #endif + + #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + +#elif defined( __WATCOMC__ ) + + #define __mbg_inline _inline + + #define MBG_TGT_HAS_WCHAR_T defined( MBG_TGT_WIN32 ) + +#endif + + + +// Currently we support only Sparc and i386/x86_64 architectures, +// so unless we have explicitely found sparc we assume i386. + +#if !defined MBG_ARCH_SPARC + #define MBG_ARCH_I386 +#endif + + +#if !defined( __mbg_inline ) + + #define __mbg_inline + #endif +#if defined( MBG_TGT_FREEBSD ) \ + || defined( MBG_TGT_NETBSD ) \ + || defined( MBG_TGT_OPENBSD ) + #define MBG_TGT_BSD +#endif + +#if defined( MBG_TGT_LINUX ) \ + || defined( MBG_TGT_BSD ) \ + || defined( MBG_TGT_QNX_NTO ) + #define MBG_TGT_UNIX +#endif + + + +#if defined( MBG_TGT_CVI ) + + #include <windows.h> + #include <utility.h> -#if defined MBG_TGT_WIN32 + #define MBG_HANDLE HANDLE + #define MBG_PORT_HANDLE int + + #define MBG_INVALID_HANDLE -1 + +#elif defined( MBG_TGT_WIN32 ) + + #if defined( _AMD64_ ) + // This is used for AMD64 architecture and for + // Intel XEON CPUs with 64 bit extension. + #define MBG_TGT_WIN32_PNP_X64 + #define WIN32_FLAVOR "x64" + #elif defined( _IA64_ ) + #define MBG_TGT_WIN32_PNP_IA64 + #define WIN32_FLAVOR "ia64" + #endif + + #if defined( _KDD_ ) + #include <ntddk.h> + #else + // This must not be used for kernel drivers. + #include <windows.h> + typedef HANDLE MBG_HANDLE; + typedef HANDLE MBG_PORT_HANDLE; + + #define MBG_INVALID_HANDLE INVALID_HANDLE_VALUE + + #endif #define _MBG_API WINAPI - #if defined MBG_LIB_EXPORT + #if defined( MBG_LIB_EXPORT ) #define _MBG_API_ATTR __declspec( dllexport ) #else #define _MBG_API_ATTR __declspec( dllimport ) #endif +#elif defined( MBG_TGT_UNIX ) + + typedef int MBG_HANDLE; + typedef int MBG_PORT_HANDLE; + + #define MBG_INVALID_HANDLE -1 + #else + typedef int MBG_HANDLE; + typedef int MBG_PORT_HANDLE; + + #define MBG_INVALID_HANDLE -1 + +#endif + + +#if !defined( _MBG_API ) #define _MBG_API +#endif + +#if !defined( _MBG_API_ATTR ) #define _MBG_API_ATTR +#endif + +#if !defined( MBG_USE_MM_IO_FOR_PCI ) + #define MBG_USE_MM_IO_FOR_PCI ( 0 || defined( MBG_ARCH_SPARC ) ) #endif +#if !defined( _nop_macro_fnc ) + #define _nop_macro_fnc() do {} while (0) +#endif + + +// The macros below are defined in order to be able to check if +// certain C language extensions are available on the target system: +#define MBG_TGT_C94 ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199409L ) ) +#define MBG_TGT_C99 ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) ) + +// Check if wchar_t is supported +#if !defined( MBG_TGT_HAS_WCHAR_T ) + #define MBG_TGT_HAS_WCHAR_T ( MBG_TGT_C94 || defined( WCHAR_MAX ) ) +#endif + +#if !MBG_TGT_HAS_WCHAR_T + // Even if wchar_t is not natively supported by the target platform + // there may already be a compatibility define (e.g. BC3.1) + // However, some functions may be missing (e.g. snwprintf()). + #if !defined( _WCHAR_T ) /* BC3.1 */ \ + && !defined( _WCHAR_T_DEFINED_ ) /* WC11 */ + //##++ #define _WCHAR_T + #define wchar_t char + #endif +#endif + + + /* End of header body */ #undef _ext diff --git a/c/mbglib/include/mbgsvcio.h b/c/mbglib/include/mbgsvcio.h index e489c48..c22ba5d 100644 --- a/c/mbglib/include/mbgsvcio.h +++ b/c/mbglib/include/mbgsvcio.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgsvcio.h 1.1 2004/07/01 10:00:51Z martin TEST $ + * $Id: mbgsvcio.h 1.13 2009/01/12 09:40:18Z daniel REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,32 @@ * * ----------------------------------------------------------------------- * $Log: mbgsvcio.h $ + * Revision 1.13 2009/01/12 09:40:18Z daniel + * New version code 303, compatibility version code still 200. + * Added comments in doxygen format. + * Revision 1.12 2008/01/17 10:14:41Z daniel + * New version code 302, compatibility version code still 200. + * Revision 1.11 2007/10/16 10:16:27Z daniel + * New version code 301, compatibility version code still 200. + * Revision 1.10 2007/09/24 15:28:17Z martin + * New version code 300, compatibility version code still 200. + * Revision 1.9 2007/03/22 09:52:18Z martin + * New version code 219, compatibility version code still 200. + * Removed obsolete headers. + * Revision 1.8 2006/08/09 13:38:02Z martin + * New version code 218, compatibility version still 200. + * Revision 1.7 2006/06/08 12:23:54Z martin + * New version code 217, compatibility version still 200. + * Revision 1.6 2006/05/02 12:52:17Z martin + * New version code 216, compatibility version still 200. + * Revision 1.5 2006/01/11 12:04:32Z martin + * New version code 215, compatibility version still 200. + * Revision 1.4 2005/12/15 09:16:38Z martin + * New version code 214, compatibility version still 200. + * Revision 1.3 2005/07/20 07:38:39Z martin + * New version code 213. + * Revision 1.2 2005/02/16 15:34:40Z martin + * New version 2.12. * Revision 1.1 2004/07/01 10:00:51Z martin * **************************************************************************/ @@ -22,8 +48,6 @@ #include <mbg_tgt.h> -#include <windows.h> -#include <stdio.h> //##++ #ifdef _MBGSVCIO @@ -39,7 +63,7 @@ #pragma pack( 1 ) #endif -#define MBGSVCIO_VERSION 0x0200 +#define MBGSVCIO_VERSION 0x0303 #define MBGSVCIO_COMPAT_VERSION 0x0200 @@ -53,12 +77,73 @@ extern "C" { /* This section was generated automatically */ /* by MAKEHDR, do not remove the comments. */ + /** + Get the version number of the compiled mbgsvcio library. + If the mbgsvcio library is built as a DLL then + the version number of the compiled library may differ from + the version number of the import library and header files + which have been used to build an application. + + @return The version number + + @see ::MBGSVCIO_VERSION defined in mbgsvcio.h. +*/ _MBG_API_ATTR int _MBG_API mbgsvcio_get_version( void ) ; + + /** + Check if the version of the compiled mbgsvcio library is compatible + with a certain version which is passed as parameter. + + @param header_version Version number to be checked, should be ::MBGSVCIO_VERSION + defined in mbgsvcio.h. + + @return ::MBG_SUCCESS if compatible, ::MBG_WINERR_LIB_NOT_COMPATIBLE if not. + + @see ::MBGSVCIO_VERSION defined in mbgsvcio.h. + */ _MBG_API_ATTR int _MBG_API mbgsvcio_check_version( int header_version ) ; + + /** + Query the status of the Meinberg time adjustment service "mbgadjtm.exe" + + @return 1, if the service has the state "SERVICE_RUNNING", otherwise 0. +*/ _MBG_API_ATTR int _MBG_API mbg_time_adjustment_active( void ) ; + + /** + Check if the time of the reference clock is accessible. + + @return 1: The reference clock is accessible and delivers a valid time.<br> + 0: The reference time is invalid or inaccessible.<br> + -1: The shared memory area which provides information from the + service is not accessible.<br> +*/ _MBG_API_ATTR int _MBG_API mbg_ref_time_accessible( void ) ; + + /** + Return the current state of the reference clock. + + @return ::PCPS_TIME_STATUS_X.<br><br> + The status information can be extracted by using the + following bit masks:<br> + <ul><li>::PCPS_FREER</li> + <li>::PCPS_DL_ENB</li> + <li>::PCPS_SYNCD</li> + <li>::PCPS_DL_ANN</li> + <li>::PCPS_UTC</li> + <li>::PCPS_LS_ANN</li> + <li>::PCPS_IFTM</li> + <li>::PCPS_INVT</li> + <li>::PCPS_LS_ENB</li> + <li>::PCPS_ANT_FAIL</li> + <li>::PCPS_UCAP_OVERRUN</li> + <li>::PCPS_UCAP_BUFFER_FULL</li> + <li>::PCPS_IO_BLOCKED</li> + </ul> +*/ _MBG_API_ATTR int _MBG_API mbg_get_ref_time_status( void ) ; + /* ----- function prototypes end ----- */ #ifdef __cplusplus diff --git a/c/mbglib/include/pcpsdefs.h b/c/mbglib/include/pcpsdefs.h index 10d8320..bff5eef 100644 --- a/c/mbglib/include/pcpsdefs.h +++ b/c/mbglib/include/pcpsdefs.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: pcpsdefs.h 1.19 2004/06/16 12:46:33Z martin REL_M $ + * $Id: pcpsdefs.h 1.37 2008/12/05 16:01:37Z martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,72 @@ * * ----------------------------------------------------------------------- * $Log: pcpsdefs.h $ + * Revision 1.37 2008/12/05 16:01:37Z martin + * Added ref types PTP, FRC, and WWVB. + * Added ref names MSF, PTP, FRC, and WWVB. + * Added device codes TCR170PEX, PTP270PEX, and FRC511PEX. + * Added macros to convert the endianess of structures. + * Moved definitions of PCPS_HRT_FRAC_SCALE and + * PCPS_HRT_FRAC_SCALE_FMT here. + * Added definitions of PCPS_HRT_FRAC_CONVERSION_TYPE + * and PCPS_HRT_BIN_FRAC_SCALE. + * Escaped '<' and '>' characters for doxygen. + * Modified comments for PCPS_TZDL. + * Removed trailing spaces and obsolete comments. + * Revision 1.36 2008/01/17 09:20:25Z daniel + * Added new REF type PCPS_REF_MSF. + * Revision 1.35 2008/01/17 09:18:46Z daniel + * Made comments compatible for doxygen parser. + * No sourcecode changes. + * Revision 1.34 2007/07/17 08:22:47Z martin + * Added support for TCR511PEX and GPS170PEX. + * Revision 1.33 2007/05/20 21:39:51Z martin + * Added support for PEX511. + * Added PCPS_GET_STATUS_PORT cmd code for devices + * that do not support a hardware status port. + * Revision 1.32 2007/03/29 12:57:32Z martin + * Renamed some TZCODE numbers for unique naming conventions. + * Added definitions of the older symbols for compatibility. + * Revision 1.31 2007/03/26 15:42:31Z martin + * Replaced PCPS_REF_OFFS and associated definitions by MBG_REF_OFFS, etc., + * which are defined in gpsdefs.h. + * Added PCPS_GET_DEBUG_STATUS code. + * Revision 1.30 2006/06/29 10:13:13 martin + * Added some descriptive comments. + * Revision 1.29 2006/06/14 12:59:12Z martin + * Added support for TCR511PCI. + * Revision 1.28 2006/05/18 09:45:16 martin + * Added data types used with PZF receivers. + * Revision 1.27 2006/05/03 10:19:14Z martin + * Added initializers for reference source names. + * Revision 1.26 2006/03/10 10:24:45Z martin + * New definitions for PCI511. + * Added command codes to configure programmable pulse outputs. + * Revision 1.25 2005/11/03 15:05:16Z martin + * New definitions for GPS170PCI. + * New types PCPS_TIME_STATUS and PCPS_TIME_STATUS_X. + * Removed obsolete enumeration of PCPS_TIME fields. + * Revision 1.24 2005/05/03 07:56:55Z martin + * Added command PCPS_GET_SYNTH_STATE. + * Revision 1.23 2005/03/29 12:51:10Z martin + * New cmd code PCPS_GENERIC_IO. + * Revision 1.22 2004/12/09 11:03:37Z martin + * Support configuration of on-board frequency synthesizer. + * Revision 1.21 2004/11/09 12:55:32Z martin + * Redefined interface data types using C99 fixed-size definitions. + * Added workaround macros for some structure sizes because the C166 + * compiler always reports an even structure size even if the structure + * size is in fact odd, which might lead to different sizes in C166 and + * other environments. + * Modifications were required in order to be able to configure IRIG + * settings of cards which provide both IRIG input and output. + * The existing codes have been renamed with .._RX.. and are used to + * configure the IRIG receiver (input). New codes have been defined + * used to configure the IRIG transmitter. + * Renamed PC_GPS_STAT to PC_GPS_BVAR_STAT. + * Use more specific data types than generic types. + * Revision 1.20 2004/10/14 15:01:23 martin + * Added support for TCR167PCI. * Revision 1.19 2004/06/16 12:46:33Z martin * Moved OPT_SETTINGS related definitions to gpsdefs.h, * and renamed symbols from PCPS_.. to to MBG_... @@ -125,21 +191,67 @@ #endif -/* +/** * The following codes enumerate the ref time sources * from which the clocks receive the reference time. */ enum { - PCPS_REF_NONE, // (unknown or not defined) - PCPS_REF_DCF, // see http://www.meinberg.de/english/info/dcf77.htm - PCPS_REF_GPS, // see http://www.meinberg.de/english/info/gps.htm - PCPS_REF_IRIG, // see http://www.meinberg.de/english/info/irig.htm - N_PCPS_REF // number of valid ref time sources + PCPS_REF_NONE, /**< (unknown or not defined) */ + PCPS_REF_DCF, /**< see http://www.meinberg.de/english/info/dcf77.htm */ + 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_FRC, /**< Free Running Clock */ + PCPS_REF_WWVB, /**< WWVB Receiver (US) */ + N_PCPS_REF /**< number of valid ref time sources */ }; -/* PCI vendor ID number (assigned by PCI SIG) */ +/* Initializers for the reference source names */ + +#define PCPS_REF_NAME_NONE_ENG "unknown" +#define PCPS_REF_NAME_NONE_GER "nicht bekannt" +#define PCPS_REF_NAME_DCF "DCF77" +#define PCPS_REF_NAME_GPS "GPS" +#define PCPS_REF_NAME_IRIG "IRIG" +#define PCPS_REF_NAME_MSF "MSF" +#define PCPS_REF_NAME_PTP "PTP" +#define PCPS_REF_NAME_FRC "FRC" +#define PCPS_REF_NAME_WWVB "WWVB" + + +#define PCPS_REF_NAMES_ENG \ +{ \ + PCPS_REF_NAME_NONE_ENG, \ + PCPS_REF_NAME_DCF, \ + PCPS_REF_NAME_GPS, \ + PCPS_REF_NAME_IRIG, \ + PCPS_REF_NAME_MSF, \ + PCPS_REF_NAME_PTP, \ + PCPS_REF_NAME_FRC, \ + PCPS_REF_NAME_WWVB \ +} + + +#define PCPS_REF_NAMES_LSTR \ +{ \ + { PCPS_REF_NAME_NONE_ENG, PCPS_REF_NAME_NONE_GER }, \ + { PCPS_REF_NAME_DCF, NULL }, \ + { PCPS_REF_NAME_GPS, NULL }, \ + { PCPS_REF_NAME_IRIG, NULL }, \ + { PCPS_REF_NAME_MSF, NULL }, \ + { PCPS_REF_NAME_PTP, NULL }, \ + { PCPS_REF_NAME_FRC, NULL }, \ + { PCPS_REF_NAME_WWVB, NULL } \ +} + + + +/** + PCI vendor ID number (assigned by PCI SIG) +*/ #define PCI_VENDOR_MEINBERG 0x1360 /* PCI device ID numbers (assigned by Meinberg) * @@ -149,170 +261,241 @@ enum #define PCI_DEV_PCI32 ( ( PCPS_REF_DCF << 8 ) | 0x01 ) #define PCI_DEV_PCI509 ( ( PCPS_REF_DCF << 8 ) | 0x02 ) #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_GPS167PCI ( ( PCPS_REF_GPS << 8 ) | 0x01 ) #define PCI_DEV_GPS168PCI ( ( PCPS_REF_GPS << 8 ) | 0x02 ) #define PCI_DEV_GPS169PCI ( ( PCPS_REF_GPS << 8 ) | 0x03 ) +#define PCI_DEV_GPS170PCI ( ( PCPS_REF_GPS << 8 ) | 0x04 ) +#define PCI_DEV_GPS170PEX ( ( PCPS_REF_GPS << 8 ) | 0x05 ) #define PCI_DEV_TCR510PCI ( ( PCPS_REF_IRIG << 8 ) | 0x01 ) - - -/* - * Command bytes used to access the board - * - * The commands described below can be used to access the Meinberg - * plug-in radio clocks. However, some of the commands have not been - * implemented with older clock models, or firmware versions. - * - * 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 - * comments below. - * - * Some commands expect parameters to be passed to the board. In that - * case, the board returns the number of parameter bytes expected when - * the command code is passed. Every parameter byte has to be supplied - * to the board exactly like a command byte. - * Refer to function pcps_write_data() and the macro _pcps_write_var() - * for details. - * - * PCPS_GIVE_TIME Return a PCPS_TIME structure with current date, - * time and status. Supported by all clocks. - * - * PCPS_GIVE_TIME_NOCLEAR Same as PCPS_GIVE_TIME but the bits PCPS_ST_SEC - * and PCPS_ST_MIN (see pcpsdev.h) of the status - * port are not cleared. - * Supported by all clocks except PC31/PS31 with - * firmware version older than v3.0. - * This is mainly used by the DOS TSR and should - * not be used in other environments. - * - * PCPS_GIVE_SYNC_TIME Return a PCPS_TIME structure with date and time - * of last synchronization of the clock or - * the last time set via the interface. - * _pcps_has_sync_time() checks whether supported. - * - * PCPS_GIVE_HR_TIME Return a PCPS_HR_TIME structure with current - * date, time and status. This command should be - * used to read the clock with higher resolution. - * _pcps_has_hr_time() checks whether supported. - * - * PCPS_SET_TIME Set the board date, time and status. This - * command expects sizeof( PCPS_TIME_SET ) parameter - * bytes. - * _pcps_can_set_time() checks whether supported. - * - * PCPS_SET_EVENT_TIME Send a high resolution time stamp to the clock to - * configure a UTC time when the clock shall generate - * some event. This command expects a PCPS_TIME_STAMP - * parameter. - * _pcps_has_event_time() checks whether supported. - * (requires custom GPS CERN firmware) - * - * PCPS_IRQ_NONE Disable the board's hardware IRQ - * PCPS_IRQ_1_SEC Enable hardware IRQs once per second - * PCPS_IRQ_1_MIN Enable hardware IRQs once per minute - * PCPS_IRQ_10_MIN Enable hardware IRQs once per 10 minutes - * PCPS_IRQ_30_MIN Enable hardware IRQs once per 30 minutes - * - * PCPS_GET_SERIAL These commands read or set the configuration - * PCPS_SET_SERIAL of a clock's serial port COM0. The commands - * expect PCPS_SERIAL_BYTES parameter bytes and - * should be used preferably with the DCF77 - * clocks which have only one COM port. - * _pcps_has_serial() checks whether supported. - * Recent GPS clocks' COM ports should be cfg'd - * using the structures RECEIVER_INFO, PORT_INFO, - * and STR_TYPE_INFO. - * _pcps_has_receiver_info() checks whether - * these are supported. If they are not, then - * the code PC_GPS_PORT_PARM together with the - * PCPS_READ_GPS_DATA and PCPS_WRITE_GPS_DATA - * commands should be used. - * - * PCPS_GET_TZCODE These commands read or set a DCF77 clock's - * PCPS_SET_TZCODE time zone code and should be used preferably - * with the newer DCF77 clocks which have limited - * support of different time zones. - * _pcps_has_tzcode() checks whether supported. - * A GPS clock's time zone must be cfg'd using - * the code PC_GPS_TZDL together with the - * PCPS_READ_GPS_DATA and PCPS_WRITE_GPS_DATA - * commands. - * - * PCPS_GET_PCPS_TZDL These commands read or set a DCF77 clock's - * PCPS_SET_PCPS_TZDL time zone / daylight saving configuration. - * _pcps_has_pcps_tzdl() checks whether supported. - * A GPS clock's time zone must be cfg'd using - * the code PC_GPS_TZDL together with the - * PCPS_READ_GPS_DATA and PCPS_WRITE_GPS_DATA - * commands. - * - * PCPS_GET_REF_OFFS These commands can be used to configure the - * PCPS_SET_REF_OFFS reference time offset from UTC for clocks - * which can't determine the offset automatically, - * e.g. from an IRIG input signal. - * _pcps_has_ref_offs() checks whether supported. - * - * PCPS_GET_OPT_INFO These commands can be used to configure some - * PCPS_SET_OPT_SETTINGS optional settings, controlled by flags. - * When reading, the clock returns a MBG_OPT_INFO - * structure which contains the supported values, - * plus the current settings. - * When writing, clocks accepts a MBG_OPT_SETTINGS - * structure only which contain the desired settings - * of the supported flags only. - * _pcps_has_opt_flags() checks whether supported. - * - * PCPS_GET_IRIG_INFO These commands can be used to configure IRIG - * PCPS_SET_IRIG_SETTINGS formats. When reading, the clock returns an - * IRIG_INFO structure which contains the supported - * values, plus the current settings. When writing, - * clocks accepts an IRIG_SETTINGS structure only - * which contain the desired settings only. - * _pcps_is_irig_rx() checks whether supported. - * - * PCPS_GIVE_FW_ID_1 Returns the first/second block of PCPS_FIFO_SIZE - * PCPS_GIVE_FW_ID_2 characters of the firmware ID string. These - * commands can be used to check if the board - * responds properly. This is done by the clock - * detection functions. - * - * PCPS_GIVE_SERNUM Returns PCPS_FIFO_SIZE characters of the - * clock's serial number. - * _pcps_has_sernum() checks whether supported. - * - * PCPS_READ_GPS_DATA These commands are used by the functions - * PCPS_WRITE_GPS_DATA pcps_read_gps_data() and pcps_write_gps_data() - * to read or write large data structures to - * Meinberg GPS plug-in clocks. - * _pcps_is_gps() checks whether supported. - * - * PCPS_CLR_UCAP_BUFF Clear a clock's time capture buffer. - * _pcps_can_clr_ucap_buff() checks whether - * supported. - * - * PCPS_GIVE_UCAP_ENTRIES Read a PCPS_UCAP_ENTRIES structure which - * reports the max number of entries and the - * currently used number of entries in the - * user capture buffer. - * _pcps_has_ucap() checks whether supported. - * - * PCPS_GIVE_UCAP_EVENT Read capture events using a PCPS_HR_TIME - * structure. This is faster than reading using the - * GPS command PC_GPS_UCAP. If no capture event is - * available then the structure is filled with 0s. - * _pcps_has_ucap() checks whether supported. - * - * PCPS_FORCE_RESET Resets the microprocessor on the radio clock - * board. This is for debug purposes only and - * should not be used by standard applications. - * - * The command codes listed above are defined below. The commands are - * grouped for bytes having the same high nibble: - */ +#define PCI_DEV_TCR167PCI ( ( PCPS_REF_IRIG << 8 ) | 0x02 ) +#define PCI_DEV_TCR511PCI ( ( PCPS_REF_IRIG << 8 ) | 0x03 ) +#define PCI_DEV_TCR511PEX ( ( PCPS_REF_IRIG << 8 ) | 0x04 ) +#define PCI_DEV_TCR170PEX ( ( PCPS_REF_IRIG << 8 ) | 0x05 ) + +#define PCI_DEV_PTP270PEX ( ( PCPS_REF_PTP << 8 ) | 0x01 ) + +#define PCI_DEV_FRC511PEX ( ( PCPS_REF_FRC << 8 ) | 0x01 ) + +/** @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 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 + comments below. + + Some commands expect parameters to be passed to the board. In that + case, the board returns the number of parameter bytes expected when + the command code is passed. Every parameter byte has to be supplied + to the board exactly like a command byte. + Refer to function pcps_write_data() and the macro _pcps_write_var() + for details. + + + - #PCPS_GIVE_TIME<br> + Return a PCPS_TIME structure with current date, + time and status. Supported by all clocks. + + - #PCPS_GIVE_TIME_NOCLEAR<br> + Same as #PCPS_GIVE_TIME but the bits #PCPS_ST_SEC + and #PCPS_ST_MIN (see pcpsdev.h) of the status + port are not cleared. + Supported by all clocks except PC31/PS31 with + firmware version older than v3.0. + This is mainly used by the DOS TSR and should + not be used in other environments. + + - #PCPS_GIVE_SYNC_TIME<br> + Return a ::PCPS_TIME structure with date and time + of last synchronization of the clock or + the last time set via the interface. + _pcps_has_sync_time() checks whether supported. + + - #PCPS_GIVE_HR_TIME<br> + Return a PCPS_HR_TIME structure with current + date, time and status. This command should be + used to read the clock with higher resolution. + _pcps_has_hr_time() checks whether supported. + + - #PCPS_SET_TIME<br> + Set the board date, time and status. This + command expects sizeof( ::PCPS_STIME ) parameter + bytes. + _pcps_can_set_time() checks whether supported. + + - #PCPS_SET_EVENT_TIME<br> + Send a high resolution time stamp to the clock to + configure a UTC time when the clock shall generate + some event. This command expects a PCPS_TIME_STAMP + parameter. + _pcps_has_event_time() checks whether supported. + (requires custom GPS CERN firmware) + + - #PCPS_IRQ_NONE<br> + Disable the board's hardware IRQ<br> + - #PCPS_IRQ_1_SEC<br> + Enable hardware IRQs once per second<br> + - #PCPS_IRQ_1_MIN<br> + Enable hardware IRQs once per minute<br> + - #PCPS_IRQ_10_MIN<br> + Enable hardware IRQs once per 10 minutes<br> + - #PCPS_IRQ_30_MIN<br> + Enable hardware IRQs once per 30 minutes<br> + + - #PCPS_GET_SERIAL<br> + #PCPS_SET_SERIAL<br> + These commands read or set the configuration + of a clock's serial port COM0. The commands + expect PCPS_SERIAL_BYTES parameter bytes and + should be used preferably with the DCF77 + clocks which have only one COM port. + _pcps_has_serial() checks whether supported. + Recent GPS clocks' COM ports should be cfg'd + using the structures RECEIVER_INFO, PORT_INFO, + and STR_TYPE_INFO. + _pcps_has_receiver_info() checks whether + these are supported. If they are not, then + the code #PC_GPS_PORT_PARM together with the + #PCPS_READ_GPS_DATA and #PCPS_WRITE_GPS_DATA + commands should be used. + + - #PCPS_GET_TZCODE<br> + #PCPS_SET_TZCODE<br> + These commands read or set a DCF77 clock's + time zone code and should be used preferably + with the newer DCF77 clocks which have limited + support of different time zones. + _pcps_has_tzcode() checks whether supported. + A GPS clock's time zone must be cfg'd using + the code #PC_GPS_TZDL together with the + #PCPS_READ_GPS_DATA and #PCPS_WRITE_GPS_DATA + commands. + + - #PCPS_GET_PCPS_TZDL<br> + #PCPS_SET_PCPS_TZDL<br> + These commands read or set a DCF77 clock's + time zone / daylight saving configuration. + _pcps_has_pcps_tzdl() checks whether supported. + A GPS clock's time zone must be cfg'd using + the code #PC_GPS_TZDL together with the + #PCPS_READ_GPS_DATA and #PCPS_WRITE_GPS_DATA + commands. + + - #PCPS_GET_REF_OFFS<br> + #PCPS_SET_REF_OFFS<br> + These commands can be used to configure the + reference time offset from UTC for clocks + which can't determine the offset automatically, + e.g. from an IRIG input signal. + _pcps_has_ref_offs() checks whether supported. + + - #PCPS_GET_OPT_INFO<br> + #PCPS_SET_OPT_SETTINGS<br> + These commands can be used to configure some + optional settings, controlled by flags. + When reading, the clock returns a MBG_OPT_INFO + structure which contains the supported values, + plus the current settings. + When writing, clocks accepts a MBG_OPT_SETTINGS + structure only which contain the desired settings + of the supported flags only. + _pcps_has_opt_flags() checks whether supported. + + - #PCPS_GET_IRIG_RX_INFO<br> + #PCPS_SET_IRIG_RX_SETTINGS<br> + #PCPS_GET_IRIG_TX_INFO<br> + #PCPS_SET_IRIG_TX_SETTINGS<br> + These commands can be used to configure IRIG + inputs and outputs.<br> + When reading, the clock returns an IRIG_INFO + structure which contains the supported values, + plus the current settings.<br> + When writing, clocks accepts an IRIG_SETTINGS + structure only which contain the desired settings + only. _pcps_is_irig_rx() and _pcps_is_irig_tx() + check whether supported. + + - #PCPS_GET_SYNTH<br> + #PCPS_SET_SYNTH<br> + #PCPS_GET_SYNTH_STATE<br> + These commands can be used to configure an on-board + frequency synthesizer and query the synthesizer + status. The commands are only supported if the board + supports the RECEIVER_INFO structure and the flag + #GPS_HAS_SYNTH is set in the RECEIVER_INFO::features. + _pcps_has_synth() checks whether supported. + The structures SYNTH and SYNTH_STATE used with these + commands are defined in gpsdefs.h. + + - #PCPS_GIVE_FW_ID_1<br> + #PCPS_GIVE_FW_ID_2<br> + Returns the first/second block of PCPS_FIFO_SIZE + characters of the firmware ID string. These + commands can be used to check if the board + responds properly. This is done by the clock + detection functions. + + - #PCPS_GIVE_SERNUM<br> + Returns PCPS_FIFO_SIZE characters of the + clock's serial number. + _pcps_has_sernum() checks whether supported. + + - #PCPS_GENERIC_IO<br> + Generic I/O read and write. Can be used to query + specific data, e.g. a selected element of an array. + _pcps_has_generic_io() checks whether supported. + + - #PCPS_GET_DEBUG_STATUS<br> + This command reads a MBG_DEBUG_STATUS structure + which represents the internal status of the + IRIG decoder and some additional debug info. + _pcps_has_debug_status() checks whether supported. + + - #PCPS_READ_GPS_DATA<br> + #PCPS_WRITE_GPS_DATA<br> + These commands are used by the functions + pcps_read_gps_data() and pcps_write_gps_data() + to read or write large data structures to + Meinberg GPS plug-in clocks. + _pcps_is_gps() checks whether supported. + + - #PCPS_CLR_UCAP_BUFF<br> + Clear a clock's time capture buffer. + _pcps_can_clr_ucap_buff() checks whether + supported. + + - #PCPS_GIVE_UCAP_ENTRIES<br> + Read a PCPS_UCAP_ENTRIES structure which + reports the max number of entries and the + currently used number of entries in the + user capture buffer. + _pcps_has_ucap() checks whether supported. + + - #PCPS_GIVE_UCAP_EVENT<br> + Read capture events using a PCPS_HR_TIME + structure. This is faster than reading using the + GPS command #PC_GPS_UCAP. If no capture event is + available then the structure is filled with 0s. + _pcps_has_ucap() 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. + + The command codes listed above are defined below. The commands are + grouped for bytes having the same high nibble: + @{ +*/ #define PCPS_GIVE_TIME_GROUP 0x00 #define PCPS_SET_TIME_GROUP 0x10 #define PCPS_IRQ_GROUP 0x20 @@ -320,6 +503,7 @@ enum #define PCPS_GIVE_DATA_GROUP 0x40 #define PCPS_GPS_DATA_GROUP 0x50 #define PCPS_CTRL_GROUP 0x60 +#define PCPS_CFG2_GROUP 0x70 /* PCPS_GIVE_TIME_GROUP */ @@ -353,48 +537,57 @@ enum #define PCPS_SET_SERIAL ( PCPS_CFG_GROUP | 0x1 ) /* on error, return PCPS_ERR_CFG */ -typedef uchar PCPS_SERIAL; +typedef uint8_t PCPS_SERIAL; #define PCPS_GET_TZCODE ( PCPS_CFG_GROUP | 0x2 ) #define PCPS_SET_TZCODE ( PCPS_CFG_GROUP | 0x3 ) /* on error, return PCPS_ERR_CFG */ -typedef uchar PCPS_TZCODE; +typedef uint8_t PCPS_TZCODE; /* the following codes are used with the PCPS_TZCODE parameter: */ enum { - PCPS_TZCODE_MEZMESZ, /* default as broadcasted by DCF77 (UTC+1h/UTC+2h) */ - PCPS_TZCODE_MEZ, /* always MEZ (UTC+1h), discard DST */ + PCPS_TZCODE_CET_CEST, /* default as broadcasted by DCF77 (UTC+1h/UTC+2h) */ + PCPS_TZCODE_CET, /* always CET (UTC+1h), discard DST */ PCPS_TZCODE_UTC, /* always UTC */ - PCPS_TZCODE_OEZ, /* Eastern European Time, MEZ/MESZ + 1h */ + PCPS_TZCODE_EET_EEST, /* East European Time, CET/CEST + 1h */ N_PCPS_TZCODE /* the number of valid codes */ }; +/* the definitions below are for compatibily only: */ +#define PCPS_TZCODE_MEZMESZ PCPS_TZCODE_CET_CEST +#define PCPS_TZCODE_MEZ PCPS_TZCODE_CET +#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 ) /* on error, return PCPS_ERR_CFG */ -/* +/** * The structures below can be used to configure a clock's * time zone/daylight saving setting. This structure is shorter * than the TZDL structure used with GPS clocks. */ typedef struct { - ushort year_or_wday; // contents depends on MSB flag; see below - uchar month; - uchar mday; - uchar hour; - uchar min; + // The year_or_wday field below contains the full year number + // or 0..6 == Sun..Sat if the DL_AUTO_FLAG is set; see below. + uint16_t year_or_wday; + uint8_t month; + uint8_t mday; + uint8_t hour; + uint8_t min; } PCPS_DL_ONOFF; -// char wday; /* 0..6 == Sun..Sat */ -// char wday; /* 1..7 == Mon..Sun */ +#define _mbg_swab_pcps_dl_onoff( _p ) \ +{ \ + _mbg_swab16( &(_p)->year_or_wday ); \ +} -/* +/** * If the field year_or_wday is or'ed with the constant DL_AUTO_FLAG * defined below then this means that start and end of daylight saving * time shall be computed automatically for each year. In this case @@ -407,23 +600,27 @@ typedef struct typedef struct { - short offs; // offset from UTC to local time [min] - short offs_dl; // additional offset if DST enabled [min] - PCPS_DL_ONOFF tm_on; // date/time when daylight saving starts - PCPS_DL_ONOFF tm_off; // date/time when daylight saving ends + int16_t offs; /**< offset from UTC to local time [min] */ + int16_t offs_dl; /**< additional offset if DST enabled [min] */ + PCPS_DL_ONOFF tm_on; /**< date/time when daylight saving starts */ + PCPS_DL_ONOFF tm_off; /**< date/time when daylight saving ends */ } PCPS_TZDL; +#define _mbg_swab_pcps_tzdl( _p ) \ +{ \ + _mbg_swab16( &(_p)->offs ); \ + _mbg_swab16( &(_p)->offs_dl ); \ + _mbg_swab_pcps_dl_onoff( &(_p)->tm_on ); \ + _mbg_swab_pcps_dl_onoff( &(_p)->tm_off ); \ +} + #define PCPS_GET_REF_OFFS ( PCPS_CFG_GROUP | 0x6 ) #define PCPS_SET_REF_OFFS ( PCPS_CFG_GROUP | 0x7 ) /* on error, return PCPS_ERR_CFG */ -typedef short PCPS_REF_OFFS; // -PCPS_REF_OFFS_MAX..PCPS_REF_OFFS_MAX - -/* the maximum allowed positive / negative offset */ -#define PCPS_REF_OFFS_MAX ( ( 12L * 60 ) + 30 ) // [minutes] - +/* The associated type MBG_REF_OFFS is defined in gpsdefs.h. */ #define PCPS_GET_OPT_INFO ( PCPS_CFG_GROUP | 0x8 ) @@ -434,18 +631,38 @@ typedef short PCPS_REF_OFFS; // -PCPS_REF_OFFS_MAX..PCPS_REF_OFFS_MAX are defined in gpsdefs.h. */ -#define PCPS_GET_IRIG_INFO ( PCPS_CFG_GROUP | 0xA ) -#define PCPS_SET_IRIG_SETTINGS ( PCPS_CFG_GROUP | 0xB ) +#define PCPS_GET_IRIG_RX_INFO ( PCPS_CFG_GROUP | 0xA ) +#define PCPS_SET_IRIG_RX_SETTINGS ( PCPS_CFG_GROUP | 0xB ) +/* 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 ) /* 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 ) +/* 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_STATUS_PORT ( PCPS_GIVE_DATA_GROUP | 0xB ) +#define PCPS_GET_DEBUG_STATUS ( PCPS_GIVE_DATA_GROUP | 0xC ) +// expects sizeof( MBG_DEBUG_STATUS ) chars + + /* PCPS_GPS_DATA_GROUP */ @@ -460,20 +677,30 @@ typedef short PCPS_REF_OFFS; // -PCPS_REF_OFFS_MAX..PCPS_REF_OFFS_MAX typedef struct { - ulong used; /* the number of saved capture events */ - ulong max; /* capture buffer size */ + uint32_t used; /**< the number of saved capture events */ + uint32_t max; /**< capture buffer size */ } PCPS_UCAP_ENTRIES; +#define _mbg_swab_pcps_ucap_entries( _p ) \ +{ \ + _mbg_swab32( &(_p)->used ); \ + _mbg_swab32( &(_p)->max ); \ +} + + -/* special -- use with care */ +/** + special -- use with care ! +*/ #define PCPS_FORCE_RESET 0x80 +/** @} */ /* Codes returned when commands with parameters have been passed */ /* 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_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 */ @@ -482,40 +709,85 @@ typedef struct #endif -/* the size of the plug-in radio clock's on-board FIFO: */ +/** The size of the plug-in radio clock's on-board FIFO: */ #define PCPS_FIFO_SIZE 16 -typedef char PCPS_BUFF[PCPS_FIFO_SIZE]; +typedef int8_t PCPS_BUFF[PCPS_FIFO_SIZE]; -#define PCPS_ID_SIZE ( 2 * PCPS_FIFO_SIZE + 1 ) /* ASCIIZ string */ +#define PCPS_ID_SIZE ( 2 * PCPS_FIFO_SIZE + 1 ) /**< ASCIIZ string */ typedef char PCPS_ID_STR[PCPS_ID_SIZE]; -#define PCPS_SN_SIZE ( PCPS_FIFO_SIZE + 1 ) /* ASCIIZ string */ +#define PCPS_SN_SIZE ( PCPS_FIFO_SIZE + 1 ) /**< ASCIIZ string */ typedef char PCPS_SN_STR[PCPS_SN_SIZE]; -/* - * The structure below has been introduced to be able to handle +/** + * The structure has been introduced to be able to handle * high resolution time stamps. */ typedef struct { - ulong sec; /* seconds since 1970 (UTC) */ - ulong frac; /* fractions of second ( 0xFFFFFFFF == 0.9999.. sec) */ + uint32_t sec; /**< seconds since 1970 (UTC) */ + uint32_t frac; /**< fractions of second ( 0xFFFFFFFF == 0.9999.. sec) */ } PCPS_TIME_STAMP; +#define _mbg_swab_pcps_time_stamp( _p ) \ +{ \ + _mbg_swab32( &(_p)->sec ); \ + _mbg_swab32( &(_p)->frac ); \ +} + + + +// Depending on the target environment define a data type +// which can be used to convert binary fractions without +// range overflow. +#if defined( MBG_TGT_UNIX ) + #define PCPS_HRT_FRAC_CONVERSION_TYPE int64_t +#elif defined( MBG_TGT_WIN32 ) + #define PCPS_HRT_FRAC_CONVERSION_TYPE int64_t +#elif defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 ) + #define PCPS_HRT_FRAC_CONVERSION_TYPE int64_t +#else + #define PCPS_HRT_FRAC_CONVERSION_TYPE double +#endif -/* - * The structure below has been introduced to be able to read the +// Max value of PCPS_TIME_STAMP::frac + 1 used for scaling +#define PCPS_HRT_BIN_FRAC_SCALE ( (PCPS_HRT_FRAC_CONVERSION_TYPE) 4294967296.0 ) // == 0x100000000 + + +// The scale and format to be used to print the fractions +// of a second as returned in the PCPS_TIME_STAMP structure. +// The function frac_sec_from_bin() can be used for +// the conversion. +#ifndef PCPS_HRT_FRAC_SCALE + #define PCPS_HRT_FRAC_SCALE 10000000UL +#endif + +#ifndef PCPS_HRT_FRAC_SCALE_FMT + #define PCPS_HRT_FRAC_SCALE_FMT "%07lu" +#endif + + + + + +typedef uint16_t PCPS_TIME_STATUS_X; /**< extended status */ + +#define _mbg_swab_pcps_time_status_x( _p ) _mbg_swab16( _p ) + + +/** + * The structure has been introduced to be able to read the * current time with higher resolution of fractions of seconds and * more detailed information on the time zone and status. - * The structure is returned if the new command PCPS_GIVE_HR_TIME + * The structure is returned if the new command #PCPS_GIVE_HR_TIME * is written to the board. * _pcps_has_hr_time() checks whether supported. * - * Newer GPS boards also accept the PCPS_GIVE_UCAP_EVENT command + * Newer GPS boards also accept the #PCPS_GIVE_UCAP_EVENT command * to return user capture event times using this format. In this * case, the "signal" field contains the number of the capture * input line, e.g. 0 or 1. @@ -523,49 +795,73 @@ typedef struct */ typedef struct { - PCPS_TIME_STAMP tstamp; - long utc_offs; /* UTC offs [sec] (loc_time = UTC + utc_offs) */ - ushort status; /* status flags as defined below */ - uchar signal; /* for normal time, the relative RF signal level */ - /* for ucap, the channel number */ -} PCPS_HR_TIME; /* "high resolution time" */ - - -/* the standard structure used to read times from the board */ + PCPS_TIME_STAMP tstamp; /**< High resolution time stamp (UTC) */ + int32_t utc_offs; /**< UTC offs [sec] (loc_time = UTC + utc_offs) */ + PCPS_TIME_STATUS_X status; /**< status flags as defined below */ + uint8_t signal; /**< for normal time, the relative RF signal level, for ucap, the channel number */ +} PCPS_HR_TIME; + +#define _mbg_swab_pcps_hr_time( _p ) \ +{ \ + _mbg_swab_pcps_time_stamp( &(_p)->tstamp ); \ + _mbg_swab32( &(_p)->utc_offs ); \ + _mbg_swab_pcps_time_status_x( &(_p)->status ); \ +} + + +typedef uint8_t PCPS_TIME_STATUS; + +/** + The standard structure used to read times from the board. + The time has a resultion of 10 ms. +*/ typedef struct PCPS_TIME_s { - uchar sec100; - uchar sec; - uchar min; - uchar hour; - - uchar mday; - uchar wday; - uchar month; - uchar year; - - uchar status; - uchar signal; - char offs_utc; /* [hours], 0 if !_pcps_has_utc_offs() */ + uint8_t sec100; /**< hundredths of seconds, 0..99 */ + uint8_t sec; /**< seconds, 0..59, or 60 if leap second */ + uint8_t min; /**< minutes, 0..59 */ + uint8_t hour; /**< hours, 0..23 */ + + uint8_t mday; /**< day of month, 0..31 */ + uint8_t wday; /**< day of week, 1..7, 1 = Monday */ + uint8_t month; /**< month, 1..12 */ + uint8_t year; /**< year of the century, 0..99 */ + + PCPS_TIME_STATUS status; /**< status bits, see below */ + uint8_t signal; /**< relative signal strength, range depends on device type */ + int8_t offs_utc; /**< [hours], 0 if !_pcps_has_utc_offs() */ } PCPS_TIME; -/* the structure below is passed as parameter with the PCPS_SET_TIME cmd */ +/** + The structure is passed as parameter with the PCPS_SET_TIME cmd +*/ typedef struct PCPS_STIME_s { - uchar sec100; - uchar sec; - uchar min; - uchar hour; + uint8_t sec100; /**< hundredths of seconds, 0..99 */ + uint8_t sec; /**< seconds, 0..59, or 60 if leap second */ + uint8_t min; /**< minutes, 0..59 */ + uint8_t hour; /**< hours, 0..23 */ - uchar mday; - uchar wday; - uchar month; - uchar year; + uint8_t mday; /**< day of month, 0..31 */ + uint8_t wday; /**< day of week, 1..7, 1 = Monday */ + uint8_t month; /**< month, 1..12 */ + uint8_t year; /**< year of the century, 0..99 */ - uchar status; + PCPS_TIME_STATUS status; /**< status bits, see below */ } PCPS_STIME; +#ifdef _C166 + // This is a workaround to specify some structure sizes. The C166 compiler + // always reports an even structure size although the structure size may + // be odd due to the number of bytes. This might lead to errors between + // the C166 and other build environments. + #define sizeof_PCPS_TIME ( sizeof( PCPS_TIME ) - 1 ) + #define sizeof_PCPS_STIME ( sizeof( PCPS_STIME ) - 1 ) +#else + #define sizeof_PCPS_TIME sizeof( PCPS_TIME ) + #define sizeof_PCPS_STIME sizeof( PCPS_STIME ) +#endif typedef union { @@ -574,61 +870,40 @@ typedef union } PCPS_TIME_UNION; -/* - * The enumeration below is useful if a PCPS_TIME structure - * must be accessed as an array of bytes. Be sure the order of - * fields matches: - */ -enum -{ - PCPS_SEC100, - PCPS_SEC, - PCPS_MIN, - PCPS_HOUR, - PCPS_MDAY, - PCPS_WDAY, - PCPS_MONTH, - PCPS_YEAR, - PCPS_STATUS, - PCPS_SIGNAL, - PCPS_OFFS_UTC -}; +/* 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 */ -/* Bit masks used with both PCPS_TIME.status and PCPS_HR_TIME.status */ +#define PCPS_DL_ENB 0x02 /**< daylight saving enabled */ -#define PCPS_FREER 0x01 /* DCF77 clock running on xtal */ - /* GPS receiver has not verified its position */ +#define PCPS_SYNCD 0x04 /**< clock has sync'ed at least once after pwr up */ -#define PCPS_DL_ENB 0x02 /* daylight saving enabled */ +#define PCPS_DL_ANN 0x08 /**< a change in daylight saving is announced */ -#define PCPS_SYNCD 0x04 /* clock has sync'ed at least once after pwr up */ +#define PCPS_UTC 0x10 /**< a special UTC firmware is installed */ -#define PCPS_DL_ANN 0x08 /* a change in daylight saving is announced */ +#define PCPS_LS_ANN 0x20 /**< leap second announced */ + /**< (requires firmware rev. REV_PCPS_LS_ANN_...) */ -#define PCPS_UTC 0x10 /* a special UTC firmware is installed */ +#define PCPS_IFTM 0x40 /**< the current time was set via PC */ + /**< (requires firmware rev. REV_PCPS_IFTM_...) */ -#define PCPS_LS_ANN 0x20 /* leap second announced */ - /* (requires firmware rev. REV_PCPS_LS_ANN_...) */ +#define PCPS_INVT 0x80 /**< invalid time because battery was disconn'd */ -#define PCPS_IFTM 0x40 /* the current time was set via PC */ - /* (requires firmware rev. REV_PCPS_IFTM_...) */ -#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_HR_TIME.status */ - -#define PCPS_LS_ENB 0x0100 /* current second is leap second */ -#define PCPS_ANT_FAIL 0x0200 /* antenna failure */ +#define PCPS_LS_ENB 0x0100 /**< current second is leap second */ +#define PCPS_ANT_FAIL 0x0200 /**< antenna failure */ /* The next two bits are used only if the structure */ /* PCPS_HR_TIME contains a user capture event */ -#define PCPS_UCAP_OVERRUN 0x2000 /* events interval too short */ -#define PCPS_UCAP_BUFFER_FULL 0x4000 /* events read too slow */ +#define PCPS_UCAP_OVERRUN 0x2000 /**< events interval too short */ +#define PCPS_UCAP_BUFFER_FULL 0x4000 /**< events read too slow */ -/* +/** * 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. @@ -640,7 +915,7 @@ enum */ #define PCPS_IO_BLOCKED 0x8000 -/* +/** * Some DCF77 clocks have a serial interface that can be controlled * using the commands PCPS_SET_SERIAL and PCPS_GET_SERIAL. Both commands * use a parameter byte describing transmission speed, framing and mode @@ -653,7 +928,7 @@ enum * command. */ -/* +/** * Baud rate indices. The values below are obsolete and should * be replaced by the codes named MBG_BAUD_RATE_... which are * defined in gpsdefs.h. The resulting index numbers, however, @@ -680,7 +955,7 @@ enum */ -/* +/** * Unfortunately, the framing codes below can not simply be * replaced by the newer MBG_FRAMING_... definitions since * the order of indices does not match. @@ -704,8 +979,9 @@ enum * codes to unify handling inside the edit functions. */ -/* modes of operation */ -/* +/** + Modes of operation + * Indices for modes of operation. The values below are obsolete * and should be replaced by the codes named STR_... which are * defined in gpsdefs.h. The resulting index numbers, however, @@ -724,13 +1000,13 @@ 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> + * \<STX\>D:dd.mm.yy;T:d;U:hh.mm.ss;uvwx\<ETX\> * - * where <STX> and <ETX> represent the ASCII codes 0x02 and 0x03, + * 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: @@ -759,7 +1035,35 @@ enum */ -/* The enumeration below defines the various types of data that can be + +/** + * Some definitions used with PZF receivers + */ + +/* receiver distance from transmitter [km] */ +typedef uint16_t TR_DISTANCE; + +/* correlation status info */ +typedef struct +{ + uint8_t val; /**< correlation value */ + uint8_t status; /**< status codes, see below */ + char corr_dir; /**< space, '<', or '>' */ + uint8_t flags; /**< reserved, currently always 0 */ +} CORR_INFO; + +/** Codes used with CORR_INFO::status: */ +enum +{ + PZF_CORR_RAW, + PZF_CORR_CHECK, + PZF_CORR_FINE, + N_PZF_CORR_STATE +}; + + +/** + * The enumeration below defines the various types of data that can be * read from or written to a Meinberg GPS plug-in clock. Access should be * done using the functions pcps_read_gps_data() and pcps_write_gps_data() * in file pcpsio.c because the size of some of the structures exceeds @@ -769,13 +1073,12 @@ enum * The structures to be used are defined in gpsdefs.h. Not all structures * are supportet, yet. Check the R/W indicators for details. */ - enum { // R/W data type description // system data ----------------------------------------------- PC_GPS_TZDL = 0, // R/W TZDL time zone / daylight saving PC_GPS_SW_REV, // R/- SW_REV software revision - PC_GPS_STAT, // R/- ushort status of buffered variables + PC_GPS_BVAR_STAT, // R/- BVAR_STAT status of buffered variables PC_GPS_TIME, // R/W TTM curr. time PC_GPS_POS_XYZ, // -/W XYZ curr. pos. in ECEF coords PC_GPS_POS_LLA, // -/W LLA curr. pos. in geogr. coords @@ -784,15 +1087,17 @@ enum PC_GPS_UCAP, // R/- TTM user capture PC_GPS_ENABLE_FLAGS, // R/W ENABLE_FLAGS controls when to enable outp. PC_GPS_STAT_INFO, // R/- GPS_STAT_INFO - PC_GPS_CMD, // -/W ushort commands as described below + PC_GPS_CMD, // -/W GPS_CMD commands as described below PC_GPS_IDENT, // R/- GPS_IDENT serial number PC_GPS_POS, // R/- POS position XYZ, LLA, and DMS - PC_GPS_ANT_CABLE_LEN, // R/W ushort used to compensate delay + PC_GPS_ANT_CABLE_LEN, // R/W ANT_CABLE_LEN used to compensate delay // The codes below are supported by new GPS receiver boards: PC_GPS_RECEIVER_INFO, // R/- RECEIVER_INFO rcvr model info PC_GPS_ALL_STR_TYPE_INFO, // R/- n*STR_TYPE_INFO_IDX all string types PC_GPS_ALL_PORT_INFO, // R/- n*PORT_INFO_IDX all port info PC_GPS_PORT_SETTINGS_IDX, // -/W PORT_SETTINGS_IDX port settings only + PC_GPS_ALL_POUT_INFO, // R/- n*POUT_INFO_IDX all pout info + PC_GPS_POUT_SETTINGS_IDX, // -/W POUT_SETTINGS_IDX pout settings only // GPS data PC_GPS_CFGH = 0x80, // -/- CFGH SVs' config. and health codes @@ -804,15 +1109,14 @@ enum }; -/* codes used with PC_GPS_CMD: */ - +/** codes used with PC_GPS_CMD */ enum { - PC_GPS_CMD_BOOT = 1, /* force the clock to boot mode */ - PC_GPS_CMD_INIT_SYS, /* let the clock clear its system variables */ - PC_GPS_CMD_INIT_USER, /* reset the clock's user parameters to defaults */ - PC_GPS_CMD_INIT_DAC, /* initialize the oscillator disciplining values */ - N_PC_GPS_CMD /* no command, just the number of known commands */ + PC_GPS_CMD_BOOT = 1, /**< force the clock to boot mode */ + PC_GPS_CMD_INIT_SYS, /**< let the clock clear its system variables */ + PC_GPS_CMD_INIT_USER, /**< reset the clock's user parameters to defaults */ + PC_GPS_CMD_INIT_DAC, /**< initialize the oscillator disciplining values */ + N_PC_GPS_CMD /**< no command, just the number of known commands */ }; diff --git a/c/mbglib/include/use_pack.h b/c/mbglib/include/use_pack.h index b48ecd6..b162014 100644 --- a/c/mbglib/include/use_pack.h +++ b/c/mbglib/include/use_pack.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: use_pack.h 1.2 2002/02/25 08:50:33Z Andre TRASH $ + * $Id: use_pack.h 1.2 2002/02/25 08:50:33Z Andre REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * diff --git a/c/mbglib/include/words.h b/c/mbglib/include/words.h index 9597b8a..ab77508 100644 --- a/c/mbglib/include/words.h +++ b/c/mbglib/include/words.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: words.h 1.9 2003/02/07 11:36:54Z MARTIN TRASH $ + * $Id: words.h 1.16 2008/12/05 12:05:41Z martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,7 +10,27 @@ * * ----------------------------------------------------------------------- * $Log: words.h $ - * Revision 1.9 2003/02/07 11:36:54Z MARTIN + * Revision 1.16 2008/12/05 12:05:41Z martin + * Define dummy int64_t/uint64_t types for targets + * which don't support 64 bit data types. + * Revision 1.15 2008/07/14 14:44:00Z martin + * Use fixed size C99 types which come with GCC and newer Borland compilers. + * Revision 1.14 2008/01/30 10:27:50Z martin + * Moved some macro definitions here. + * Revision 1.13 2007/03/08 15:00:30Z martin + * Fixed incompatibility of macro _IS_MBG_FIRMWARE. + * Added a workaround for _IS_MBG_FIRMWARE under CVI. + * Support for BSD. + * Revision 1.12 2006/12/15 10:45:46 martin + * Added macro _IS_MBG_FIRMWARE. + * Cleanup for Linux, QNX, and Watcom C. + * Include mbg_tgt.h for non-firmware targets. + * Revision 1.11 2004/11/10 10:45:34 martin + * Added C99 fixed-type handling for QNX. + * Revision 1.10 2004/11/09 13:12:56 martin + * Redefined C99 integer types with fixed sizes as standard types + * if required, depending on the environment. + * Revision 1.9 2003/02/07 11:36:54 MARTIN * New macros _hilo_16() and _hilo_32() for endian conversion. * Revision 1.8 2002/05/28 10:09:54 MARTIN * Added new macros _var_bswap16() and _var_bswap32(). @@ -36,6 +56,30 @@ /* Other headers to be included */ + +#if defined( _CVI ) + // This is a hack for CVI which seems to be unable + // to handle recursive preprocessor symbols. + #define _IS_MBG_FIRMWARE 0 +#endif + +#if !defined( _IS_MBG_FIRMWARE ) + + #define _IS_MBG_FIRMWARE \ + ( \ + defined( _C166 ) || \ + defined( _CC51 ) || \ + defined( __ARM ) \ + ) + + +#endif + +#if !_IS_MBG_FIRMWARE + #include <mbg_tgt.h> +#endif + + #ifdef _WORDS #define _ext #else @@ -45,15 +89,125 @@ /* Start of header body */ -typedef unsigned char uchar; -#if defined( __linux ) - #ifdef __KERNEL__ +// Check whether the target system supports C99 fixed-size types. + +#if defined( MBG_TGT_LINUX ) // any Linux target + + #if defined( __KERNEL__ ) #include <linux/types.h> #else + #include <stdint.h> #include <sys/types.h> #endif + + #define _C99_BIT_TYPES_DEFINED 1 + +#elif defined( MBG_TGT_BSD ) + + #include <sys/types.h> + + #define _C99_BIT_TYPES_DEFINED 1 + +#elif defined( MBG_TGT_QNX ) // QNX 4.x or QNX 6.x + + #if defined( MBG_TGT_QNX_NTO ) // QNX 6.x (Neutrino) with gcc + #include <stdint.h> + #else // QNX 4.x with Watcom C 10.6 + #include <sys/types.h> // 64 bit types not supported + #endif + + #define _C99_BIT_TYPES_DEFINED 1 + +#endif + + +// If it's not yet clear whether fixed-size types are supported, +// check the build environment which may be multi-platform. + +#if !defined( _C99_BIT_TYPES_DEFINED ) + + #if defined( __WATCOMC__ ) + #if __WATCOMC__ > 1230 // Open Watcom C 1.3 and above + #include <stdint.h> + #define _C99_BIT_TYPES_DEFINED 1 + #elif defined( __WATCOM_INT64__ ) // Watcom C 11, non-QNX + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; + + #define _C99_BIT_TYPES_DEFINED 1 + #endif + #endif + + #if defined( __BORLANDC__ ) + #if ( __BORLANDC__ >= 0x570 ) // at least Borland Developer Studio 2006 + #define _C99_BIT_TYPES_DEFINED 1 + #endif + #endif + + #if defined( __GNUC__ ) + #include <stdint.h> + #define _C99_BIT_TYPES_DEFINED 1 + #endif + +#endif + + +// If neither the target system nor the build environment define C99 fixed-size +// types define those types based on standard types with the proper sizes +// commonly used in 16/32 bit environments. + +#if defined( _C99_BIT_TYPES_DEFINED ) + + #define MBG_TGT_HAS_64BIT_TYPES 1 + #else + + typedef char int8_t; + typedef unsigned char uint8_t; + + typedef short int16_t; + typedef unsigned short uint16_t; + + typedef long int32_t; + typedef unsigned long uint32_t; + + + #if defined( MBG_TGT_WIN32 ) + + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; + + #define MBG_TGT_HAS_64BIT_TYPES 1 + + #else + // The types below are required to avoid build errors + // if these types are formally used in function prototypes. + // We explicitely use abnormal data types to hopefully + // cause compiler errors in case these types are + // unexpectedly used to generate real code for a target + // platform which does not support 64 bit types. + typedef void *int64_t; + typedef void *uint64_t; + #endif + +#endif + + + +#if !defined( MBG_TGT_HAS_64BIT_TYPES ) + + #define MBG_TGT_HAS_64BIT_TYPES 0 + +#endif + + + +// Some commonly used types + +typedef unsigned char uchar; + +#if !defined( MBG_TGT_LINUX ) typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; @@ -67,25 +221,15 @@ typedef unsigned long longword; typedef unsigned long dword; -#if !defined( __OS2__ ) && !defined( _Windows ) && \ - !defined( _WIN32 ) && !defined( __WIN32__ ) +#define HI_BYTE( _x ) ( (_x) >> 8 ) +#define LO_BYTE( _x ) ( (_x) & 0xFF ) - #ifndef BYTE - #define BYTE unsigned char - #endif +#define HI_WORD( _x ) ( (_x) >> 16 ) +#define LO_WORD( _x ) ( (_x) & 0xFFFF ) - #ifndef WORD - #define WORD unsigned short - #endif - - #ifndef LONG - #define LONG unsigned long - #endif - - #ifndef LONGWORD - #define LONGWORD longword - #endif -#endif +// the macros below assume little endianess +#define BYTE_OF( _x, _n ) *( ( (uint8_t *) &(_x) ) + (_n) ) +#define WORD_OF( _x, _n ) *( ( (uint16_t *) &(_x) ) + (_n) ) // a macro to swap the byte order of a 16 bit value @@ -114,7 +258,7 @@ typedef unsigned long dword; // little-endian, so we must use macros to adjust the // byte order if the C51 is used. -#if defined _CC51 +#if defined( _CC51 ) #define _hilo_16( _x ) _bswap16( _x ) #define _hilo_32( _x ) _bswap32( _x ) #else @@ -122,8 +266,6 @@ typedef unsigned long dword; #define _hilo_32( _x ) (_x) #endif - - /* End of header body */ #undef _ext |