diff options
author | Martin Burnicki <martin.burnicki@meinberg.de> | 2017-09-06 12:00:00 +0200 |
---|---|---|
committer | Martin Burnicki <martin.burnicki@meinberg.de> | 2017-09-06 12:00:00 +0200 |
commit | c35b19c0c7b6467a0e949cce6077de97833231fa (patch) | |
tree | 6da58a31bbbdd4ed40a5f22b51deb72281b464f4 | |
parent | 0c91c96e055991b5cb83858a56a8133c01028e1c (diff) | |
download | ntptest-c35b19c0c7b6467a0e949cce6077de97833231fa.tar.gz ntptest-c35b19c0c7b6467a0e949cce6077de97833231fa.zip |
Print leap smear offset, control printing of packets1.7
Conditionally display dispersion and leap smear offset.
Distinguish flags which increase verbosity or print packets.
-rwxr-xr-x | mbglib/common/gpsdefs.h | 6145 | ||||
-rwxr-xr-x | mbglib/common/mbg_ntp_test_util.c | 38 | ||||
-rwxr-xr-x | mbglib/common/mbg_tgt.h | 180 | ||||
-rwxr-xr-x | mbglib/common/mbgerror.c | 141 | ||||
-rwxr-xr-x | mbglib/common/mbgerror.h | 153 | ||||
-rwxr-xr-x | mbglib/common/mbgntp.h | 74 | ||||
-rwxr-xr-x | mbglib/common/mbgtime.h | 731 | ||||
-rwxr-xr-x | mbglib/common/str_util.h | 8 | ||||
-rwxr-xr-x | mbglib/common/timeutil.c | 67 | ||||
-rwxr-xr-x | mbglib/common/timeutil.h | 28 | ||||
-rwxr-xr-x | mbglib/common/words.h | 118 | ||||
-rwxr-xr-x | ntptest.c | 47 |
12 files changed, 6338 insertions, 1392 deletions
diff --git a/mbglib/common/gpsdefs.h b/mbglib/common/gpsdefs.h index c40126c..32194a6 100755 --- a/mbglib/common/gpsdefs.h +++ b/mbglib/common/gpsdefs.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: gpsdefs.h 1.124.1.215 2016/11/21 12:22:44 thomas-b TRASH $ + * $Id: gpsdefs.h 1.125 2017/07/05 18:18:27 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -13,444 +13,75 @@ * * ----------------------------------------------------------------------- * $Log: gpsdefs.h $ - * Revision 1.124.1.215 2016/11/21 12:22:44 thomas-b - * Added enable flags as builtin feature for FDM180 - * Revision 1.124.1.214 2016/11/16 11:00:36 thomas-b - * Added core module type and revision to MBG_EXT_SYS_INFO - * Revision 1.124.1.213 2016/11/10 14:08:17 thomas-b - * Changed string name for GPS_MODEL_NAME_UNKNOWN - * Revision 1.124.1.212 2016/11/08 17:22:11 martin - * Doxygen fixes. - * Revision 1.124.1.211 2016/11/04 11:48:35 paul.kretz - * Support MDU312. - * Revision 1.124.1.210 2016/11/04 07:21:26Z thomas-b - * Added flag, mask, and idx for GPIO, which indicates that a GPIO configuration depends on another GPIO - * Revision 1.124.1.209 2016/11/02 11:54:57 paul.kretz - * added new xfeature MBG_XFEATURE_REQ_TTM - * Revision 1.124.1.208 2016/11/01 09:27:49Z thomas-b - * Added builtin feature for TZDL to FDM180 - * Revision 1.124.1.207 2016/11/01 09:24:12 martin - * *** empty log message *** - * Revision 1.124.1.206 2016/10/25 13:24:37 martin - * *** empty log message *** - * Revision 1.124.1.205 2016/10/25 08:56:40 martin - * Renamed MSK_ICODE_RX_HAS_SHORT_YEAR to MSK_ICODE_RX_HAS_SHORT_YEAR_AFTER_P5. - * New MSK_ICODE_RX_HAS_ANY_SHORT_YEAR which includes - * all codes providing a year number, either after P5 or after P6. - * Doxygen fixes. - * Changes to builtin feature definitions. - * Revision 1.124.1.204 2016/10/24 08:12:04 martin - * Support MDU180. - * Revision 1.124.1.203 2016/10/20 10:43:20 thomas-b - * Added builtin feature GPS_MODEL_IS_BUS_LVL_DEV - * Revision 1.124.1.202 2016/10/19 10:19:59 thomas-b - * Added define for default user capture network UDP port - * Revision 1.124.1.201 2016/10/19 09:07:28 thomas-b - * Added supported flags for MBG_UCAP_NET_GLB_INFO - * Revision 1.124.1.200 2016/10/13 07:30:10 paul.kretz - * Extended sysinfo proc and fpga types by SAM3s, STM32F4, Cyclone4GX15 and Cyclone4CE22 - * Revision 1.124.1.199 2016/10/10 10:36:35Z thomas-b - * Added transfer protocol for ucap network receivers and added destination port - * Revision 1.124.1.198 2016/10/10 10:17:37 thomas-b - * Removed _PRELIMINARY_CODE_AUDIO restrictions - * Added new extended feature and structure definitions for ucap via network - * Revision 1.124.1.197 2016/10/07 11:24:50 thomas-b - * Fixed swab makro for addr settings - * Revision 1.124.1.196 2016/10/05 08:26:36 andre.hartmann - * Revision 1.124.1.195 2016/09/29 11:56:43Z philipp - * Added documentation for MBG_TRANSACTION_TYPE_NETWORK - * Revision 1.124.1.194 2016/09/29 10:43:41 thomas-b - * Added define for MBG_ARPHRD_ETHER - * Revision 1.124.1.193 2016/09/29 06:13:07 philipp - * Added support for beginning / ending typed transactions - * Revision 1.124.1.192 2016/09/28 13:35:00 philipp - * Renamed flag field - * Revision 1.124.1.191 2016/09/28 13:29:22 thomas-b - * Added feature flags for MBG_NET_GLB_CFG_INFO - * Revision 1.124.1.190 2016/09/26 13:04:54 udo - * added missing comma in MBG_TLV_FEAT_TYPE_NAMES - * Revision 1.124.1.189 2016/09/26 10:08:14 udo - * added TLV Feature MBG_TLV_FEAT_TYPE_FILE_REQUEST to request a generic file from HPS - * Revision 1.124.1.188 2016/09/23 08:29:09 martin - * Fixed missing comma in string table initializer. - * Revision 1.124.1.187 2016/09/22 12:12:29 philipp - * Split ::MBG_NET_INTF_LINK_OPTS::MBG_NET_INTF_LINK_OPT_CAN_SYNCE up into SyncE In and SyncE Out option - * Revision 1.124.1.186 2016/09/15 14:54:30 martin - * Support GRC181PEX. - * Revision 1.124.1.185 2016/09/12 09:16:49 martin - * Fixed cascaded comment characters. - * Revision 1.124.1.184 2016/09/08 10:25:03 martin - * Fixed build for 16 bit targets. - * Revision 1.124.1.183 2016/09/05 13:23:04 paul.kretz - * Added ENABLE_FLAGS to BUILTIN_FEAT_VSG180 - * Revision 1.124.1.182 2016/08/25 14:37:16Z paul.kretz - * added new gpio video type PAL_M - * Revision 1.124.1.181 2016/08/23 15:47:04Z martin - * Moved macros _setup_default_receiver_info_dcf() and - * _setup_default_receiver_info_gps() here. - * Revision 1.124.1.180 2016/08/16 13:01:13 martin - * Syntax fix. - * Revision 1.124.1.179 2016/08/12 11:05:14 paul.kretz - * Added digital audio output as new gpio type which is only included - * if symbol _PRELIMINARY_CODE_AUDIO is defined. - * Revision 1.124.1.178 2016/08/11 11:34:06Z martin - * Modified MBG_REF_OFFS_NOT_CFGD to avoid compiler warning. - * Revision 1.124.1.177 2016/08/11 11:30:16 martin - * Moved time monitoring stuff to new file time_mon.h. - * Revision 1.124.1.176 2016/08/11 10:28:09 udo - * prepare extended data set for time monitor - * Revision 1.124.1.175 2016/08/10 05:17:08 udo - * added domain number to Time Monitor Target Settings - * Revision 1.124.1.174 2016/08/09 14:48:06 martin - * Revision 1.124.1.173 2016/08/03 08:05:11Z thomas-b - * Finished new network structures, definitions and relations - * Revision 1.124.1.172 2016/07/29 09:36:21 paul.kretz - * Added definitions for N2X180. - * Revision 1.124.1.171 2016/07/15 14:08:09Z martin - * Fixed a typo. - * Revision 1.124.1.170 2016/07/07 14:17:02 martin - * Cleaned up POUT API. - * Doxygen fixes. - * Revision 1.124.1.169 2016/07/07 09:57:10 andre.hartmann - * added mbg_clk_res_info - * Revision 1.124.1.168 2016/06/28 15:42:16Z martin - * *** empty log message *** - * Revision 1.124.1.167 2016/06/28 15:04:40 martin - * Added definitions for GRC181. - * Added missing definitions for GPS180CSM. - * Revision 1.124.1.166 2016/06/23 09:23:24 thomas-b - * Added num_dns_srvr and num_dns_srch_dom to MBG_NET_GLB_CFG_SETTINGS - * Revision 1.124.1.165 2016/06/22 06:58:37 udo - * added new parameters to MBG_TIME_MON_TARGET_STATUS - * Revision 1.124.1.164 2016/06/21 06:34:54 andre - * QL alarms now separated for TDEV and MTIE - * comment for QL hysteresis added - * Revision 1.124.1.163 2016/06/10 07:59:09Z philipp - * Extended sysinfo proc and fpga types by SAM3u and Cyclone5 - * Revision 1.124.1.162 2016/06/09 09:17:08 thomas-b - * Added builtin features TIME and TZDL for TCR cards - * Revision 1.124.1.161 2016/06/06 08:59:45 andre - * Revision 1.124.1.160 2016/06/02 13:36:11Z philipp - * Extended MBG_EXT_SYS_INFO proc and fpga types - * Revision 1.124.1.159 2016/06/02 10:57:51 philipp - * Added string initializers for MBG_EXT_SYS_INFO's proc and FPGA types - * Revision 1.124.1.158 2016/06/02 10:24:22 philipp - * Renaming all revision macros and helper functions - * Revision 1.124.1.157 2016/06/02 10:15:35 philipp - * Renaming all MBG_EXT_REV_INFO related stuff to MBG_EXT_SYS_INFO. - * Revision 1.124.1.156 2016/06/01 10:49:49 andre - * Revision 1.124.1.155 2016/06/01 09:51:26Z philipp - * Added structures and definitions for new type MBG_LICENSE to be queried via TLV_API. - * Revision 1.124.1.154 2016/06/01 06:59:00 andre - * Revision 1.124.1.153 2016/05/31 14:32:27Z andre - * Revision 1.124.1.152 2016/05/31 14:32:02Z andre - * Revision 1.124.1.151 2016/05/30 08:14:09Z thomas-b - * Added builtin feature GPS_MODEL_HAS_TIME to GPS receivers and N2x - * Revision 1.124.1.150 2016/05/27 06:32:12 philipp - * Changed XMR_HOLDOVER_STATUS_MODE_NAMES - * Revision 1.124.1.149 2016/05/26 08:01:16 andre - * Revision 1.124.1.148 2016/05/24 14:43:10Z andre - * Revision 1.124.1.147 2016/05/24 13:32:24Z philipp - * Added PTP Statistics - * Revision 1.124.1.146 2016/05/20 08:58:52 thomas-b - * New BUILTIN_FEATURE GPS_HAS_TZCODE for older PZF cards - * Revision 1.124.1.145 2016/05/20 06:41:42 thomas-b - * Added TZDL and ENABLE_FLAGS to BUILTIN_FEAT_N2X - * Revision 1.124.1.144 2016/05/19 13:12:32 paul - * renamed two video HD formats: - * 1080i29.97Hz to 1080i59.94Hz and 1080i25Hz to 1080i50Hz - * Revision 1.124.1.143 2016/05/11 13:20:20Z thomas-b - * Changed several fields and flags in NET_CFG structures - * Revision 1.124.1.142 2016/05/09 08:06:53 philipp - * New array string initializers for LED modes and colors - * Revision 1.124.1.141 2016/05/04 09:57:27 thomas-b - * Comment changed - * Revision 1.124.1.140 2016/04/26 09:17:41 thomas-b - * Changed structure MBG_NET_GLB_CFG_SETTINGS - * Revision 1.124.1.139 2016/04/26 08:51:47 philipp - * New multi reference input type SyncE - * Revision 1.124.1.138 2016/04/26 08:18:58 thomas-b - * Added typedefs for interface route structures if _PRELIMINARY_CODE is not defined - * Revision 1.124.1.137 2016/04/26 07:39:45 thomas-b - * Changed names and descriptions in net_cfg structures - * Relocated preliminary code areas in net_cfg and ntp definitions - * Revision 1.124.1.136 2016/04/26 06:05:44 philipp - * Removed space to fix compiler error on ARM GCC 4.9.3 - * Revision 1.124.1.135 2016/04/25 15:13:58 martin - * *** empty log message *** - * Revision 1.124.1.134 2016/04/25 14:34:46 martin - * *** empty log message *** - * Revision 1.124.1.133 2016/04/25 10:23:22Z martin - * TLV code isn't preliminary anymore. - * Enums with more than 16 entries are not supported by 16 bit compilers. - * Revision 1.124.1.132 2016/04/22 08:36:27 philipp - * Added String initializers for GPIO bit out flags - * Revision 1.124.1.131 2016/04/21 10:53:29 philipp - * Added GPIO bits format strings. - * Added T1 SSM quality levels. - * Revision 1.124.1.130 2016/04/20 14:43:29 udo - * use NANO_TIME instead of double - * Revision 1.124.1.129 2016/04/20 13:16:58 thomas-b - * Added typedefs for NTP_SRV_MODE_INFO and NTP_SRV_MODE_SETTINGS - * Revision 1.124.1.128 2016/04/20 09:26:05 philipp - * Moved all HPS-PTP related structures to gpspriv.h and removed related extended feature bit from gpsdefs.h. - * Also removed functions from mbgextio and xdevfeat since HPS-PTP handling needs a redesign concerning structures. - * Thus, handle everything explicitly for now! - * -> Redesing this A.S.A.P.!!! - * Revision 1.124.1.127 2016/04/18 12:37:02 thomas-b - * New network structures and definitions for bonding and routing - * Revision 1.124.1.126 2016/04/15 13:14:08 daniel - * Added PTP profile ITU-T. G. 8275.2 - * Revision 1.124.1.125 2016/04/15 09:22:16 udo - * fixed alignment problem in PTP_DEV_CFG_GLB - * Revision 1.124.1.124 2016/04/15 08:17:28 philipp - * New feature MBG_XFEATURE_EXT_PTP - * Revision 1.124.1.123 2016/04/15 07:31:46 andre - * Revision 1.124.1.122 2016/04/08 10:18:02Z daniel - * Fixed MBG_ENCODE_EXT_REV macro - * Revision 1.124.1.121 2016/04/08 10:16:29 martin - * *** empty log message *** - * Revision 1.124.1.120 2016/04/07 13:20:23 philipp - * Extended NTP definitions and added new structure MBG_EXT_REV_INFO including enums, masks, etc.. - * Revision 1.124.1.119 2016/04/05 13:29:25 daniel - * Adjust ptp cfg and state structures to take care of unified data type sizes and alignment - * Revision 1.124.1.118 2016/04/04 14:46:13 martin - * Added TLV feature type names. - * Revision 1.124.1.117 2016/03/24 14:08:47 martin - * *** empty log message *** - * Revision 1.124.1.116 2016/03/24 09:14:52 martin - * New extended feature MBG_XFEATURE_PWR_CTL_API. - * Revision 1.124.1.115 2016/03/18 11:21:52 martin - * *** empty log message *** - * Revision 1.124.1.114 2016/03/18 10:32:25 martin - * *** empty log message *** - * Revision 1.124.1.113 2016/03/17 09:21:01 martin - * *** empty log message *** - * Revision 1.124.1.112 2016/03/16 15:13:37 martin - * *** empty log message *** - * Revision 1.124.1.111 2016/03/16 08:29:13 martin - * Removed ..._MODEL_HAS_GNSS_MODE definitions, use ..._MODEL_IS_GNSS - * instead. - * Revision 1.124.1.110 2016/03/15 14:55:04 martin - * Modified LNE and LED API. - * Revision 1.124.1.109 2016/03/14 11:54:06 martin - * Fixed duplicate macro name. - * Revision 1.124.1.108 2016/03/11 15:12:08 martin - * Started to refactor LED and LNE API. - * Revision 1.124.1.107 2016/03/11 11:25:26 martin - * Made XMR_STATS::step_det_val a reserved, unused field. - * Cleanup. - * Revision 1.124.1.106 2016/03/11 10:09:44 andre - * Revision 1.124.1.105 2016/03/02 15:03:42Z daniel - * Updates for new PTP Utility profile and PTP statistics - * Revision 1.124.1.104 2016/02/29 15:51:31 andre - * added estimated holdover var to XMR_HOLDOVER_STATUS - * Revision 1.124.1.103 2016/02/25 08:47:32Z paul - * Added definitions for GTS180. - * Revision 1.124.1.102 2016/02/24 09:23:55Z gregoire - * change PTP_ANN_RCPT_TIMEOUT_MAX from 255 to 8 - * Revision 1.124.1.101 2016/02/19 12:11:21Z udo - * added MBG_LNE_INFO_EXT - * Revision 1.124.1.100 2016/02/18 14:56:37 daniel - * Added TLV FEAT_TYPE LICENSE UPGRADE - * Revision 1.124.1.99 2016/02/18 11:27:27 udo - * added MBG_LNE_LED_STATUS - * Revision 1.124.1.98 2016/02/16 08:38:50 gregoire - * added new initializer to MBG_XFEATURE_NAMES - * Revision 1.124.1.97 2016/02/11 12:02:39Z daniel - * Added two TLV_FEAT_TYPES - * Revision 1.124.1.96 2016/02/10 15:52:36 thomas-b - * Added enum MBG_IMS_FDM_FLAGS and appropriate masks enum - * Revision 1.124.1.95 2016/02/03 13:27:44 martin - * Added definitions for LNE180SFP. - * Revision 1.124.1.94 2016/02/03 09:41:32 martin - * Fixed build without _PRELIMINARY_CODE. - * Revision 1.124.1.93 2016/02/02 15:53:46Z martin - * Added definitions for CSM100. - * Revision 1.124.1.92 2016/01/29 09:06:32 udo - * Added time-protocol type to Time Monitor Target settings. - * Revision 1.124.1.91 2016/01/22 11:34:39 gregoire - * Added string initializers for XMR_STATS_FLAGS_BITS. - * Revision 1.124.1.90 2016/01/22 08:16:07Z gregoire - * Renamed DEFAULT_MULTI_REF_NAMES_SHORT strings. - * Revision 1.124.1.89 2016/01/21 08:59:03Z andre - * Added auto_bis field in XMR_STATS. - * Revision 1.124.1.88 2016/01/19 14:11:47Z udo - * Modified time monitor structures. - * Revision 1.124.1.87 2016/01/18 08:37:03 udo - * Added support for PTP Time Monitoring on TSU/HPS100. - * Revision 1.124.1.86 2016/01/15 11:30:14 martin - * New field 'timestamp' in XMR_STATS. - * Revision 1.124.1.85 2016/01/15 08:52:51 martin - * Some flag masks for XMR_STATS. - * Revision 1.124.1.84 2016/01/13 15:26:00 martin - * Removed obsolete code added in the previous version. - * Revision 1.124.1.83 2016/01/13 15:09:17 martin - * Support XMR_STATS. - * Revision 1.124.1.82 2015/12/14 13:03:09 lars - * Fixes / changes in IRIG TX / RX masks. - * Revision 1.124.1.81 2015/12/14 11:09:01Z lars - * *** preliminary *** - * Revision 1.124.1.80 2015/12/09 17:34:56Z martin - * *** empty log message *** - * Revision 1.124.1.79 2015/12/09 10:21:18 martin - * *** empty log message *** - * Revision 1.124.1.78 2015/12/09 08:28:36 martin - * New legacy model codes. - * Changed/Added some IRIG enums. - * Revision 1.124.1.77 2015/12/07 14:43:04 martin - * Doxygen fixes. - * Revision 1.124.1.76 2015/12/04 14:20:18 paul - * Fixed a typo in comment of video string initialzier. - * Added support for configurable epochs for video outputs. - * Revision 1.124.1.75 2015/12/02 16:51:19Z martin - * *** empty log message *** - * Revision 1.124.1.74 2015/12/02 16:35:32 martin - * *** empty log message *** - * Revision 1.124.1.73 2015/12/01 11:34:33 martin - * *** empty log message *** - * Revision 1.124.1.72 2015/11/30 16:51:12 martin - * *** empty log message *** - * Revision 1.124.1.71 2015/11/30 16:22:30 martin - * *** empty log message *** - * Revision 1.124.1.70 2015/11/30 09:02:47 philipp - * Added TLV feature MBG_TLV_CTX_FLAG_FW_ROLLBACK. - * Revision 1.124.1.69 2015/11/30 08:16:57 philipp - * Added MBG_TLV_INFO feature macros. - * Revision 1.124.1.68 2015/11/26 17:01:08 martin - * *** empty log message *** - * Revision 1.124.1.67 2015/11/26 08:32:54 martin - * *** empty log message *** - * Revision 1.124.1.66 2015/11/25 16:55:08 martin - * Started to implement extended features. - * Revision 1.124.1.65 2015/11/24 13:10:54 philipp - * TLV additions / partly redesign and feature inline functions. - * Revision 1.124.1.64 2015/11/23 10:23:47 philipp - * Added Doxygen documentation for TLV structures, flags and masks. - * Revision 1.124.1.63 2015/11/23 10:11:28 martin - * *** empty log message *** - * Revision 1.124.1.62 2015/11/23 08:27:32 gregoire - * Added initializers for MBG_IMS_FDM_LINE_FREQS. - * Revision 1.124.1.61 2015/11/20 09:16:39Z philipp - * Fixed macro _mbg_swab_tlv_announce. - * Revision 1.124.1.60 2015/11/20 08:14:29 philipp - * Added id member to struct MBG_TLV_ANNOUNCE. - * Revision 1.124.1.59 2015/11/20 07:26:29 philipp - * Moved TLV structures here. - * Revision 1.124.1.58 2015/11/18 13:51:50 philipp - * Added leapfile to NTP miscellaneous structures. - * Revision 1.124.1.57 2015/11/18 13:39:22 philipp - * Added NTP miscellaneous structures. - * Revision 1.124.1.56 2015/11/06 12:42:08 philipp - * Added NTP statistics structures. - * Revision 1.124.1.55 2015/11/06 11:25:22 philipp - * Removed member symlink in NTP_REFCLK_CFG_SPEC since it is implementation defined. - * Revision 1.124.1.54 2015/11/06 11:16:35 philipp - * Added NTP symmetric key structures. - * Revision 1.124.1.53 2015/11/06 09:17:40 philipp - * Added byte swap macros to NTP restriction and NTP refclock configuration structures. - * Revision 1.124.1.52 2015/11/05 12:20:12 martin - * New define MBG_MAX_HOSTNAME_LEN. - * Preliminary fix for TZDL initializers. - * Updated some comments. - * Revision 1.124.1.51 2015/11/05 09:07:56 philipp - * Added structures for NTP restriction and refclock configuration (preliminary code). - * Revision 1.124.1.50 2015/10/28 12:09:26 martin - * GPIO types for SCG not preliminary anymore. - * Added definitions for LUE180. - * Revision 1.124.1.49 2015/10/26 11:55:19 daniel - * Merged aligned PTP SMPTE and TELECOM PHASE profile structures from previous branch here. - * Revision 1.124.1.48 2015/10/26 11:24:04 daniel - * Support for PTP Preset 802.1AS - * Revision 1.124.1.47 2015/10/26 10:56:42 paul - * added a new flag for GPIO studio clock out - * Revision 1.124.1.46 2015/10/26 09:47:53Z paul - * added a missing GPIO studio clock scale string initializer - * Revision 1.124.1.45 2015/10/23 11:00:27Z paul - * Revision 1.124.1.44 2015/10/22 14:35:51Z paul - * fixed a typo - * Revision 1.124.1.43 2015/10/22 14:17:34Z martin - * *** empty log message *** - * Revision 1.124.1.42 2015/10/22 14:15:02 paul - * some changes in GPIO structs - * Revision 1.124.1.41 2015/10/21 14:36:32Z paul - * renamed stud_clk_out in studio_clk_out and vid_sync_out in video_sync_out - * Revision 1.124.1.40 2015/10/20 13:38:57Z paul - * renamed HD format in GPIO video type - * Revision 1.124.1.39 2015/10/20 12:11:36Z paul - * Revision 1.124.1.38 2015/10/20 10:58:01Z martin - * *** empty log message *** - * Revision 1.124.1.37 2015/10/20 10:43:39 paul - * Revision 1.124.1.36 2015/10/20 10:15:57Z paul - * added preliminary studio clock structs and defines - * Revision 1.124.1.35 2015/10/19 10:48:00Z gregoire - * Revision 1.124.1.34 2015/10/19 10:08:47Z gregoire - * Revision 1.124.1.33 2015/10/16 11:03:06Z martin - * *** empty log message *** - * Revision 1.124.1.32 2015/10/15 14:17:22 martin - * *** empty log message *** - * Revision 1.124.1.31 2015/10/15 08:40:37 paul - * added two new HD video formats - * Revision 1.124.1.30 2015/10/15 07:38:14Z gregoire - * AES67 Media Profile added - * Revision 1.124.1.29 2015/10/13 08:44:08Z gregoire - * smpte_jam_event added to PTP_DEV_CFG_GLB - * Revision 1.124.1.28 2015/10/12 10:01:59Z martin - * *** empty log message *** - * Revision 1.124.1.27 2015/10/09 11:09:13 martin - * *** empty log message *** - * Revision 1.124.1.26 2015/10/09 09:03:50 gregoire - * Revision 1.124.1.25 2015/10/09 07:18:49Z gregoire - * Builtin feature BUILTIN_FEAT_GNSS set for GRC models. - * Revision 1.124.1.24 2015/10/08 13:27:37Z martin - * *** empty log message *** - * Revision 1.124.1.23 2015/10/06 10:33:39 paul - * Changed GPIO names. - * Added two defines for GPIO_TYPE_VIDEO_SYNC. - * Revision 1.124.1.22 2015/10/06 07:55:11Z paul - * Changed names of GPIO types and structs. - * Revision 1.124.1.21 2015/10/02 13:07:11Z martin - * Doxygen fixes. - * Revision 1.124.1.20 2015/10/02 10:33:00 martin - * *** empty log message *** - * Revision 1.124.1.19 2015/10/01 10:51:32 martin - * *** empty log message *** - * Revision 1.124.1.18 2015/09/30 08:03:45 paul - * Bug fix in some GPIO structs. - * Added comments. - * Revision 1.124.1.17 2015/09/29 09:55:22Z paul - * added video output and sync output as two new GPIO types - * Revision 1.124.1.16 2015/09/28 09:34:56Z thomas-b - * Renamed td_max_limit in MBG_IMS_FDM_LIMITS to td_pos_limit - * Revision 1.124.1.15 2015/09/18 13:58:44 martin - * *** empty log message *** - * Revision 1.124.1.14 2015/09/17 14:56:57 thomas-b - * Renamed several variables in MBG_FDM_SETTINGS and MBG_FDM_LIMITS - * Revision 1.124.1.13 2015/09/15 13:15:01 martin + * Revision 1.125 2017/07/05 18:18:27 martin + * New models GPS_MODEL_CTC100, GPS_MODEL_TCR180, + * GPS_MODEL_LUE180, GPS_MODEL_CPC_01, GPS_MODEL_TSU_01, + * GPS_MODEL_CMC_01, GPS_MODEL_SCU_01, GPS_MODEL_FCU_01, + * GPS_MODEL_CSM100, GPS_MODEL_LNE180SFP, GPS_MODEL_GTS180, + * GPS_MODEL_GPS180CSM, GPS_MODEL_GRC181, GPS_MODEL_N2X180, + * GPS_MODEL_GNS181PEX, GPS_MODEL_MDU180, GPS_MODEL_MDU312, + * GPS_MODEL_GPS165, GPS_MODEL_GNS181_UC, GPS_MODEL_PSX_4GE, + * GPS_MODEL_RSC180RDU, GPS_MODEL_USYNCPWR, GPS_MODEL_FDM180M, + * GPS_MODEL_LSG180, GPS_MODEL_GPS190, GPS_MODEL_GNS181 and + * associated definitions. + * New GPS_BUILTIN_FEATURE_BITS and associated definitions. + * New macros _setup_default_receiver_info_dcf() and + * _setup_default_receiver_info_gps() as well as associated + * definitions which can be used to set up a RECEIVER_INFO + * structure for legacy devices which don't provide it. + * New Receiver_INO feature bit GPS_FEAT_XFEATURE which + * indicates that a new, extended feature set is supported. + * Defined a new st of extended features (MBG_XFEATURE_BITS) + * and associated definitions. * Moved definitions for NANO_TIME and NANO_TIME_64 to words.h. - * Revision 1.124.1.12 2015/09/15 11:08:22 martin - * Support new model TCR180. - * Added missing comma in DEFAULT_GPS_MODEL_NAMES. - * Revision 1.124.1.11 2015/09/07 09:19:21 martin - * Revision 1.124.1.10 2015/09/04 09:19:17 daniel - * Moved 2 additional TSU strcutures to PREMINARY_CODE block - * Revision 1.124.1.9 2015/09/03 09:17:41 martin - * Doxygen fixes. - * Revision 1.124.1.8 2015/09/02 16:42:17 martin - * Preliminary code which is only included if a preprocessor symbol - * _PRELIMINARY_CODE is defined in the project Makefile. - * Revision 1.124.1.7 2015/08/25 10:30:13 daniel - * Revision 1.124.1.6 2015/08/25 10:02:37 daniel - * Revision 1.124.1.5 2015/08/25 09:16:39 daniel - * Changed reserved member in PTP_STATE to include tsu_secs - * Revision 1.124.1.4 2015/08/10 07:37:09 daniel - * Added sync_e byte swab macros - * Revision 1.124.1.3 2015/08/07 10:51:10 daniel - * Fixed typo in CTC100 declaration - * Revision 1.124.1.2 2015/08/07 10:49:40 daniel - * RE-added temp. PTP structures PTP_DEV_CFG_GLB and PTP_DEV_CFG_NET - * Added new model CTC100 - * Revision 1.124.1.1 2015/07/29 07:40:55 daniel + * New IRIG TX codes ICODE_TX_A006_A136, ICODE_TX_A007_A137, + * and associated definitions. + * Renamed ICODE_RX_G142_G146 to ICODE_RX_G142, and + * ICODE_RX_G002_G006 to ICODE_RX_G002. + * New IRIG RX codes ICODE_RX_A136_A137, ICODE_RX_A006_A007, + * ICODE_RX_G146, ICODE_RX_G006, and associated definitions. + * New union POUT_DATA union used for varying configuration + * data in POUT_SETTINGS, depending on the output mode. + * New POUT_MODES POUT_PTTI_PPS, POUT_HAVEQUICK, and + * associated definitions. + * Definitions to support a configurable pulse shift + * of some programmable output signals. + * New multiref source MULTI_REF_SYNCE and associated + * definitions. + * Added a number of swab..() macros that were still missing. + * XMR statistics, XMR_QL and some other XMR stuff by andre. + * New GPIO types including video modes, and associated stuff. + * Renamed some structure fields and added some definitions + * related to FDM. + * Added some SCU_STAT_MASKS. + * New GNSS_TYPE_QZSS, and modified MBG_GNSS_MODE_INFO. + * New flag MBG_GNSS_FLAG_HAS_SV_STATUS, structure + * GNSS_SV_STATUS and associated definitions. + * A bunch of new structures and definitions for network + * configuration. + * Many new structures and definitions for NTP configuration. + * New structures and associated definitions used to send + * user capture events over the network (ext_ucap). + * New PTP_ROLES and associated stuff. + * Changed one of PTP_STATE's reserved fields to tsu_secs. + * Changed PTP_ANN_RCPT_TIMEOUT_MAX from 255 to 8. + * New PTP_CFG_FLAGS, PTP_OPT_EXTS flags, PTP_PRESETS_MASKS + * and associated definitions. + * Definitions for PTPv1 and v2 data sets, and PTP statistics. + * Preliminary definitions to support SMPTE and SDH. + * Definition for XBP addressing of devices. + * Definitions to support TLVs. + * Added LED and LNE API definitions. + * MBG_EXT_SYS_INFO_BITS and associated definitions for an + * extended sysinfo API. + * MBG_CLK_RES_INFO and associated stuff for clock resolution + * info. + * Definitions for configuration transaction handling. + * Definitions for a higher level I/O port API. + * Definitions for monitoring / notification. + * Definitions for USB locking. + * Preliminary licensing stuff. + * Defined macros in a safer way. * Revision 1.124 2015/07/14 14:22:46 martin * Doxygen fix. * Revision 1.123 2015/07/06 13:00:10 martin @@ -1019,10 +650,11 @@ typedef uint16_t IOD; ///< Issue-Of-Data code #ifndef _CSUM_DEFINED typedef uint16_t CSUM; ///< checksum used by some structures stored in non-volatile memory #define _CSUM_DEFINED - - #define _mbg_swab_csum( _p ) _mbg_swab16( _p ) #endif +#define _mbg_swab_csum( _p ) _mbg_swab16( _p ) + + /** * @brief The type of a GPS command code @@ -1052,9 +684,10 @@ typedef struct } SW_REV; #define _mbg_swab_sw_rev( _p ) \ +do \ { \ _mbg_swab16( &(_p)->code ); \ -} +} while ( 0 ) @@ -1164,10 +797,11 @@ typedef struct } FIXED_FREQ_INFO; #define _mbg_swab_fixed_freq_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->khz_val ); \ _mbg_swab16( &(_p)->range ); \ -} +} while ( 0 ) /** @@ -1204,6 +838,7 @@ typedef struct } RECEIVER_INFO; #define _mbg_swab_receiver_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->model_code ); \ _mbg_swab_sw_rev( &(_p)->sw_rev ); \ @@ -1211,7 +846,7 @@ typedef struct _mbg_swab32( &(_p)->features ); \ _mbg_swab_fixed_freq_info( &(_p)->fixed_freq ); \ _mbg_swab16( &(_p)->flags ); \ -} +} while ( 0 ) /** @@ -1303,9 +938,18 @@ enum GPS_MODEL_CODES GPS_MODEL_GPS180CSM, GPS_MODEL_GRC181, GPS_MODEL_N2X180, - GPS_MODEL_GRC181PEX, + GPS_MODEL_GNS181PEX, GPS_MODEL_MDU180, GPS_MODEL_MDU312, + GPS_MODEL_GPS165, + GPS_MODEL_GNS181_UC, + GPS_MODEL_PSX_4GE, + GPS_MODEL_RSC180RDU, + GPS_MODEL_USYNCPWR, + GPS_MODEL_FDM180M, + GPS_MODEL_LSG180, // Line Signal Generator + GPS_MODEL_GPS190, + GPS_MODEL_GNS181, N_GPS_MODEL /* If new model codes are added then care must be taken * to update the associated string initializers GPS_MODEL_NAMES @@ -1408,9 +1052,18 @@ enum GPS_MODEL_CODES #define GPS_MODEL_NAME_GPS180CSM "GPS180CSM" #define GPS_MODEL_NAME_GRC181 "GRC181" #define GPS_MODEL_NAME_N2X180 "N2X180" -#define GPS_MODEL_NAME_GRC181PEX "GRC181PEX" +#define GPS_MODEL_NAME_GNS181PEX "GNS181PEX" #define GPS_MODEL_NAME_MDU180 "MDU180" #define GPS_MODEL_NAME_MDU312 "MDU312" +#define GPS_MODEL_NAME_GPS165 "GPS165" +#define GPS_MODEL_NAME_GNS181_UC "GNS181_UC" +#define GPS_MODEL_NAME_PSX_4GE "PSX_4GE" +#define GPS_MODEL_NAME_RSC180RDU "RSC180RDU" +#define GPS_MODEL_NAME_USYNCPWR "MICROSYNC-PWR" +#define GPS_MODEL_NAME_FDM180M "FDM180M" +#define GPS_MODEL_NAME_LSG180 "LSG180" +#define GPS_MODEL_NAME_GPS190 "GPS190" +#define GPS_MODEL_NAME_GNS181 "GNS181" /** @} anchor GPS_MODEL_NAMES */ @@ -1511,13 +1164,23 @@ enum GPS_MODEL_CODES GPS_MODEL_NAME_GPS180CSM, \ GPS_MODEL_NAME_GRC181, \ GPS_MODEL_NAME_N2X180, \ - GPS_MODEL_NAME_GRC181PEX, \ + GPS_MODEL_NAME_GNS181PEX, \ GPS_MODEL_NAME_MDU180, \ - GPS_MODEL_NAME_MDU312 \ + GPS_MODEL_NAME_MDU312, \ + GPS_MODEL_NAME_GPS165, \ + GPS_MODEL_NAME_GNS181_UC, \ + GPS_MODEL_NAME_PSX_4GE, \ + GPS_MODEL_NAME_RSC180RDU, \ + GPS_MODEL_NAME_USYNCPWR, \ + GPS_MODEL_NAME_FDM180M, \ + GPS_MODEL_NAME_LSG180, \ + GPS_MODEL_NAME_GPS190, \ + GPS_MODEL_NAME_GNS181 \ } + /** * @brief Definitions used to classify devices and built-in features * @@ -1529,6 +1192,14 @@ enum GPS_MODEL_CODES /** + * @brief A data type to hold a mask of @ref GPS_BUILTIN_FEATURE_MASKS + * + * @see @ref GPS_BUILTIN_FEATURE_MASKS + */ +typedef uint32_t BUILTIN_FEATURE_MASK; + + +/** * @brief Enumeration of classifiers and built-in features * * @see ::GPS_MODEL_CODES @@ -1557,8 +1228,8 @@ enum GPS_BUILTIN_FEATURE_BITS GPS_BIT_MODEL_HAS_ENABLE_FLAGS, GPS_BIT_MODEL_HAS_STAT_INFO, GPS_BIT_MODEL_HAS_ANT_CABLE_LEN, - GPS_BIT_MODEL_HAS_GPS_IGNORE_LOCK, - + GPS_BIT_MODEL_HAS_SCU_STAT, + GPS_BIT_MODEL_HAS_SV_INFO, GPS_BIT_MODEL_HAS_XMR_HOLDOVER_INTV, @@ -1601,7 +1272,8 @@ enum GPS_BUILTIN_FEATURE_BITS #define GPS_MODEL_HAS_ENABLE_FLAGS ( 1UL << GPS_BIT_MODEL_HAS_ENABLE_FLAGS ) ///< see ::GPS_BIT_MODEL_HAS_ENABLE_FLAGS #define GPS_MODEL_HAS_STAT_INFO ( 1UL << GPS_BIT_MODEL_HAS_STAT_INFO ) ///< see ::GPS_BIT_MODEL_HAS_STAT_INFO #define GPS_MODEL_HAS_ANT_CABLE_LEN ( 1UL << GPS_BIT_MODEL_HAS_ANT_CABLE_LEN ) ///< see ::GPS_BIT_MODEL_HAS_ANT_CABLE_LEN -#define GPS_MODEL_HAS_GPS_IGNORE_LOCK ( 1UL << GPS_BIT_MODEL_HAS_GPS_IGNORE_LOCK ) ///< see ::GPS_BIT_MODEL_HAS_GPS_IGNORE_LOCK +#define GPS_MODEL_HAS_SCU_STAT ( 1UL << GPS_BIT_MODEL_HAS_SCU_STAT ) ///< see ::GPS_BIT_MODEL_HAS_SCU_STAT +#define GPS_MODEL_HAS_SV_INFO ( 1UL << GPS_BIT_MODEL_HAS_SV_INFO ) ///< see ::GPS_BIT_MODEL_HAS_SV_INFO #if 0 // ### TODO This has to be discussed #define GPS_MODEL_IS_LNO ( 1UL << GPS_BIT_MODEL_IS_LNO ) ///< see ::GPS_BIT_MODEL_IS_LNO @@ -1657,7 +1329,6 @@ enum GPS_BUILTIN_FEATURE_BITS #define GPS_MODEL_HAS_ROM_CSUM // ? #define GPS_MODEL_HAS_MULTI_REF_STATUS // ri ... #define GPS_MODEL_HAS_RCV_TIMEOUT // ri ... -#define GPS_MODEL_HAS_IGNORE_LOCK // ? #define GPS_MODEL_HAS_IRIG_RX_SETTINGS // ri ... #define GPS_MODEL_HAS_IRIG_RX_INFO // ri ... #define GPS_MODEL_HAS_REF_OFFS // ri ... @@ -1721,8 +1392,6 @@ enum GPS_BUILTIN_FEATURE_BITS #define GPS_MODEL_HAS_LAN_IF_INFO // #define GPS_MODEL_HAS_IP4_STATE // -#define GPS_MODEL_HAS_SCU_STAT // - #define GPS_MODEL_HAS_CRYPTED_PACKET // #define GPS_MODEL_HAS_CRYPTED_RAW_PACKET // @@ -1751,7 +1420,8 @@ enum GPS_BUILTIN_FEATURE_BITS GPS_MODEL_HAS_ANT_INFO | \ GPS_MODEL_HAS_ENABLE_FLAGS | \ GPS_MODEL_HAS_STAT_INFO | \ - GPS_MODEL_HAS_ANT_CABLE_LEN \ + GPS_MODEL_HAS_ANT_CABLE_LEN | \ + GPS_MODEL_HAS_SV_INFO \ ) @@ -2009,7 +1679,7 @@ enum GPS_BUILTIN_FEATURE_BITS #define BUILTIN_FEAT_BPE ( 0 ) #define BUILTIN_FEAT_GLN180PEX ( BUILTIN_FEAT_GNSS_BUS_LVL ) #define BUILTIN_FEAT_N2X ( BUILTIN_FEAT_COMM_N2X ) -#define BUILTIN_FEAT_RSC180 ( 0 ) +#define BUILTIN_FEAT_RSC180 ( GPS_MODEL_HAS_SCU_STAT ) #define BUILTIN_FEAT_LNE_GB ( 0 ) #define BUILTIN_FEAT_PPG180 ( 0 ) #define BUILTIN_FEAT_SCG ( 0 ) @@ -2020,7 +1690,7 @@ enum GPS_BUILTIN_FEATURE_BITS #define BUILTIN_FEAT_PZF180 ( BUILTIN_FEAT_DCF_PZF_2 ) #define BUILTIN_FEAT_REL1000 ( 0 ) #define BUILTIN_FEAT_HPS100 ( 0 ) -#define BUILTIN_FEAT_VSG180 ( GPS_MODEL_HAS_ENABLE_FLAGS ) +#define BUILTIN_FEAT_VSG180 ( 0 ) #define BUILTIN_FEAT_MSF180 ( BUILTIN_FEAT_MSF_2 ) #define BUILTIN_FEAT_WWVB180 ( BUILTIN_FEAT_WVB_2 ) #define BUILTIN_FEAT_CPC180 ( 0 ) @@ -2038,9 +1708,28 @@ enum GPS_BUILTIN_FEATURE_BITS #define BUILTIN_FEAT_GPS180CSM ( BUILTIN_FEAT_GPS ) #define BUILTIN_FEAT_GRC181 ( BUILTIN_FEAT_GNSS ) #define BUILTIN_FEAT_N2X180 ( BUILTIN_FEAT_COMM_N2X ) -#define BUILTIN_FEAT_GRC181PEX ( BUILTIN_FEAT_GNSS_BUS_LVL ) -#define BUILTIN_FEAT_MDU180 ( 0 ) +#define BUILTIN_FEAT_GNS181PEX ( BUILTIN_FEAT_GNSS_BUS_LVL ) +#define BUILTIN_FEAT_MDU180 ( GPS_MODEL_HAS_SCU_STAT ) #define BUILTIN_FEAT_MDU312 ( 0 ) +#define BUILTIN_FEAT_GPS165 ( BUILTIN_FEAT_GPS ) +#define BUILTIN_FEAT_GNS181_UC ( BUILTIN_FEAT_GNSS ) +#define BUILTIN_FEAT_PSX_4GE ( 0 ) +#define BUILTIN_FEAT_RSC180RDU ( GPS_MODEL_HAS_SCU_STAT ) +#define BUILTIN_FEAT_USYNCPWR ( 0 ) +#define BUILTIN_FEAT_FDM180M ( GPS_MODEL_HAS_TZDL | GPS_MODEL_HAS_ENABLE_FLAGS ) +#define BUILTIN_FEAT_LSG180 ( 0 ) +#define BUILTIN_FEAT_GPS190 ( BUILTIN_FEAT_GPS ) +#define BUILTIN_FEAT_GNS181 ( BUILTIN_FEAT_GNSS ) + +/** + * @brief Feature mask used for legacy devices + * + * This code is used to set builtin feature flags + * legacy devices not listed here, so we can simply + * search for ::BUILTIN_FEAT_UNDEFINED to identify + * such devices. The numeric value is just 0, though. + */ +#define BUILTIN_FEAT_UNDEFINED ( 0 ) /** @} anchor GPS_MODEL_BUILTIN_FEATURE_MASKS */ @@ -2136,10 +1825,18 @@ enum GPS_BUILTIN_FEATURE_BITS { GPS_MODEL_GPS180CSM, BUILTIN_FEAT_GPS180CSM }, \ { GPS_MODEL_GRC181, BUILTIN_FEAT_GRC181 }, \ { GPS_MODEL_N2X180, BUILTIN_FEAT_N2X180 }, \ - { GPS_MODEL_GRC181PEX, BUILTIN_FEAT_GRC181PEX }, \ - { GPS_MODEL_GRC181PEX, BUILTIN_FEAT_GRC181PEX }, \ + { GPS_MODEL_GNS181PEX, BUILTIN_FEAT_GNS181PEX }, \ { GPS_MODEL_MDU180, BUILTIN_FEAT_MDU180 }, \ { GPS_MODEL_MDU312, BUILTIN_FEAT_MDU312 }, \ + { GPS_MODEL_GPS165, BUILTIN_FEAT_GPS165 }, \ + { GPS_MODEL_GNS181_UC, BUILTIN_FEAT_GNS181_UC }, \ + { GPS_MODEL_PSX_4GE, BUILTIN_FEAT_PSX_4GE }, \ + { GPS_MODEL_RSC180RDU, BUILTIN_FEAT_RSC180RDU }, \ + { GPS_MODEL_USYNCPWR, BUILTIN_FEAT_USYNCPWR }, \ + { GPS_MODEL_FDM180M, BUILTIN_FEAT_FDM180M }, \ + { GPS_MODEL_LSG180, BUILTIN_FEAT_LSG180 }, \ + { GPS_MODEL_GPS190, BUILTIN_FEAT_GPS190 }, \ + { GPS_MODEL_GNS181, BUILTIN_FEAT_GNS181 }, \ { 0, 0 } \ } @@ -2544,6 +2241,10 @@ enum MBG_XFEATURE_BITS MBG_XFEATURE_CLK_RES_INFO, ///< Supports the ::GPS_CLK_RES_INFO command, see @ref group_clk_res_info MBG_XFEATURE_UCAP_NET, ///< Supports the ::GPS_UCAP_NET_GLB_INFO and ::GPS_UCAP_NET_RECV_INFO_IDX commands, see @ref group_ucap_net MBG_XFEATURE_REQ_TTM, ///< Supports TTM requests via GPS_TIME command + MBG_XFEATURE_IO_PORTS, ///< Supports I/O port structures, see @ref group_io_ports + MBG_XFEATURE_MONITORING, ///< Supports monitoring / notifications, see @ref group_monitoring + MBG_XFEATURE_XHE, ///< Supports XHE external rubidium unit I/O commands + MBG_XFEATURE_USB_LOCK, ///< Supports USB interrupt structures, see @ref group_usb_lock N_MBG_XFEATURE ///< Number of defined extended features // NOTE If new features are appended here then an appropriate feature // name string has to be appended to ::MBG_XFEATURE_NAMES, and care must @@ -2572,7 +2273,11 @@ enum MBG_XFEATURE_BITS "Reboot command", \ "Clock Resolution Info", \ "Extended User Captures", \ - "Request TTM" \ + "Request TTM", \ + "I/O Ports", \ + "Monitoring", \ + "XHE unit", \ + "USB lock" \ } @@ -2677,11 +2382,7 @@ typedef union { CSUM csum; uint32_t fsize; - #if _IS_MBG_FIRMWARE - uint32_t start_addr; - #else - uint8_t *start_addr; - #endif + uint32_t start_addr; char name[FPGA_NAME_SIZE]; } hdr; @@ -2738,11 +2439,12 @@ typedef struct } T_GPS; #define _mbg_swab_t_gps( _p ) \ +do \ { \ _mbg_swab16( &(_p)->wn ); \ _mbg_swab32( &(_p)->sec ); \ _mbg_swab32( &(_p)->tick ); \ -} +} while ( 0 ) /** @@ -2775,13 +2477,14 @@ typedef struct } TM_GPS; #define _mbg_swab_tm_gps( _p ) \ +do \ { \ _mbg_swab16( &(_p)->year ); \ _mbg_swab16( &(_p)->yday ); \ _mbg_swab32( &(_p)->frac ); \ _mbg_swab32( &(_p)->offs_from_utc ); \ _mbg_swab16( &(_p)->status ); \ -} +} while ( 0 ) /** @@ -2886,11 +2589,12 @@ typedef struct } TTM; #define _mbg_swab_ttm( _p ) \ +do \ { \ _mbg_swab16( &(_p)->channel ); \ _mbg_swab_t_gps( &(_p)->t ); \ _mbg_swab_tm_gps( &(_p)->tm ); \ -} +} while ( 0 ) @@ -3028,11 +2732,12 @@ typedef struct } SYNTH; #define _mbg_swab_synth( _p ) \ +do \ { \ _mbg_swab16( &(_p)->freq ); \ _mbg_swab16( &(_p)->range ); \ _mbg_swab16( &(_p)->phase ); \ -} +} while ( 0 ) /** @@ -3113,12 +2818,13 @@ typedef struct } TZDL; #define _mbg_swab_tzdl( _p ) \ +do \ { \ _mbg_swab32( &(_p)->offs ); \ _mbg_swab32( &(_p)->offs_dl ); \ _mbg_swab_tm_gps( &(_p)->tm_on ); \ _mbg_swab_tm_gps( &(_p)->tm_off ); \ -} +} while ( 0 ) /** @@ -3271,12 +2977,13 @@ typedef struct } ANT_INFO; #define _mbg_swab_ant_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->status ); \ _mbg_swab_tm_gps( &(_p)->tm_disconn ); \ _mbg_swab_tm_gps( &(_p)->tm_reconn ); \ _mbg_swab32( &(_p)->delta_t ); \ -} +} while ( 0 ) /** @@ -3312,12 +3019,13 @@ typedef struct } ENABLE_FLAGS; #define _mbg_swab_enable_flags( _p ) \ +do \ { \ _mbg_swab16( &(_p)->serial ); \ _mbg_swab16( &(_p)->pulses ); \ _mbg_swab16( &(_p)->freq ); \ _mbg_swab16( &(_p)->synth ); \ -} +} while ( 0 ) /** @@ -3375,10 +3083,11 @@ enum ENABLE_FLAGS_CODES #define _mbg_swab_baud_rate( _p ) _mbg_swab32( _p ) #define _mbg_swab_com_parm( _p ) \ +do \ { \ _mbg_swab_baud_rate( &(_p)->baud_rate ); \ _mbg_swab16( &(_p)->handshake ); \ -} +} while ( 0 ) /** @@ -3675,10 +3384,11 @@ typedef struct } PORT_SETTINGS; #define _mbg_swab_port_settings( _p ) \ +do \ { \ _mbg_swab_com_parm( &(_p)->parm ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** @@ -3759,10 +3469,11 @@ typedef struct } PORT_SETTINGS_IDX; #define _mbg_swab_port_settings_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_port_settings( &(_p)->port_settings ); \ -} +} while ( 0 ) /** @@ -3786,6 +3497,7 @@ typedef struct } PORT_INFO; #define _mbg_swab_port_info( _p ) \ +do \ { \ _mbg_swab_port_settings( &(_p)->port_settings ); \ _mbg_swab32( &(_p)->supp_baud_rates ); \ @@ -3793,7 +3505,7 @@ typedef struct _mbg_swab32( &(_p)->supp_str_types ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** @@ -3840,10 +3552,11 @@ typedef struct } PORT_INFO_IDX; #define _mbg_swab_port_info_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_port_info( &(_p)->port_info ); \ -} +} while ( 0 ) /** @@ -3868,10 +3581,11 @@ typedef struct } STR_TYPE_INFO; #define _mbg_swab_str_type_info( _p ) \ +do \ { \ _mbg_swab32( &(_p)->supp_modes ); \ _mbg_swab16( &(_p)->flags ); \ -} +} while ( 0 ) @@ -3894,10 +3608,11 @@ typedef struct } STR_TYPE_INFO_IDX; #define _mbg_swab_str_type_info_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_str_type_info( &(_p)->str_type_info ); \ -} +} while ( 0 ) /** @@ -4082,6 +3797,7 @@ typedef struct } PORT_PARM; #define _mbg_swab_port_parm( _p ) \ +do \ { \ int i; \ for ( i = 0; i < DEFAULT_N_COM; i++ ) \ @@ -4089,7 +3805,7 @@ typedef struct _mbg_swab_com_parm( &(_p)->com[i] ); \ /* no need to swap mode byte */ \ } \ -} +} while ( 0 ) /** @@ -4511,25 +4227,37 @@ enum ICODE_TX_CODES ) /** - * @brief A mask of IRIG TX formats supporting a 2 digit year number + * @brief A mask of IRIG TX formats providing a short year number after P5 + * + * The IEEE codes, the AFNOR codes, and some IRIG codes provide a + * 2 digit year number after position identifier P5. However, some + * IRIG G codes provide a 100ths-of-seconds field after P5,and + * eventually provide a year number after P6. + * + * @see @ref MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P6 + * @see @ref MSK_ICODE_TX_HAS_ANY_SHORT_YEAR */ -#define MSK_ICODE_TX_HAS_SHORT_YEAR \ -( \ - MSK_ICODE_TX_AFNOR | \ - MSK_ICODE_TX_IEEE1344 | \ - MSK_ICODE_TX_B2201344 | \ - MSK_ICODE_TX_B006_B126 | \ - MSK_ICODE_TX_B007_B127 | \ - MSK_ICODE_TX_G006_G146 | \ - MSK_ICODE_TX_C37118 | \ - MSK_ICODE_TX_A006_A136 | \ - MSK_ICODE_TX_A007_A137 \ +#define MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P5 \ +( \ + MSK_ICODE_TX_AFNOR | \ + MSK_ICODE_TX_IEEE1344 | \ + MSK_ICODE_TX_B2201344 | \ + MSK_ICODE_TX_B006_B126 | \ + MSK_ICODE_TX_B007_B127 | \ + MSK_ICODE_TX_C37118 | \ + MSK_ICODE_TX_A006_A136 | \ + MSK_ICODE_TX_A007_A137 \ ) /** - * @brief A mask of IRIG TX formats supporting a 2 digit year number + * @brief A mask of IRIG TX formats providing a short year number after P6 + * + * While most time codes that provide a year number do this after P5, + * there are some IRIG codes which provide a 100ths-of-seconds field + * at that position, and eventually provide a year number after P6. * - * This is after the P6 identifier. + * @see @ref MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P5 + * @see @ref MSK_ICODE_TX_HAS_ANY_SHORT_YEAR */ #define MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P6 \ ( \ @@ -4537,6 +4265,21 @@ enum ICODE_TX_CODES ) /** + * @brief A mask of IRIG TX formats providing a short year number in general + * + * Depending on the code format, the year number can be transmitted + * either after position identifier P5, or after P6. + * + * @see @ref MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P5 + * @see @ref MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P6 + */ +#define MSK_ICODE_TX_HAS_ANY_SHORT_YEAR \ +( \ + MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P5 | \ + MSK_ICODE_TX_HAS_SHORT_YEAR_AFTER_P6 \ +) + +/** * @brief A mask of IRIG TX formats supporting TFOM */ #define MSK_ICODE_TX_HAS_TFOM \ @@ -5116,10 +4859,11 @@ typedef struct } IRIG_SETTINGS; #define _mbg_swab_irig_settings( _p ) \ +do \ { \ _mbg_swab16( &(_p)->icode ); \ _mbg_swab16( &(_p)->flags ); \ -} +} while ( 0 ) @@ -5170,10 +4914,11 @@ typedef struct } IRIG_INFO; #define _mbg_swab_irig_info( _p ) \ +do \ { \ _mbg_swab_irig_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_codes ); \ -} +} while ( 0 ) /** @@ -5209,11 +4954,12 @@ typedef struct } IRIG_RX_COMP; #define _mbg_swab_irig_rx_comp( _p ) \ +do \ { \ int i; \ for ( i = 0; i < N_IRIG_RX_COMP_VAL; i++ ) \ _mbg_swab16( &(_p)->c[i] ); \ -} +} while ( 0 ) /** The absolute value of the maximum compensation value accepted by a device */ @@ -5232,10 +4978,11 @@ typedef struct } CAL_REC_HDR; #define _mbg_swab_cal_rec_hdr( _p ) \ +do \ { \ _mbg_swab16( &(_p)->type ); \ _mbg_swab16( &(_p)->idx ); \ -} +} while ( 0 ) /** @@ -5292,10 +5039,11 @@ typedef struct } CAL_REC_IRIG_RX_COMP; #define _mbg_swab_cal_rec_irig_rx_comp( _p ) \ +do \ { \ _mbg_swab_cal_rec_hdr( &(_p)->hdr ); \ _mbg_swab_irig_rx_comp( &(_p)->comp_data ); \ -} +} while ( 0 ) /** @} defgroup group_irig_comp */ @@ -5434,9 +5182,10 @@ typedef struct } MBG_OPT_SETTINGS; #define _mbg_swab_mbg_opt_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** @@ -5453,10 +5202,11 @@ typedef struct } MBG_OPT_INFO; #define _mbg_swab_mbg_opt_info( _p ) \ +do \ { \ _mbg_swab_mbg_opt_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_flags ); \ -} +} while ( 0 ) /** @@ -5630,11 +5380,12 @@ typedef struct } MBG_TIME_SCALE_INFO; #define _mbg_swab_mbg_time_scale_info( _p ) \ +do \ { \ _mbg_swab_mbg_time_scale_settings( &(_p)->settings ); \ _mbg_swab_mbg_time_scale_settings( &(_p)->max_settings ); \ _mbg_swab32( &(_p)->supp_scales ); \ -} +} while ( 0 ) /** @} defgroup group_time_scale */ @@ -5663,9 +5414,10 @@ typedef struct } MBG_DATE; #define _mbg_swab_mbg_date( _p ) \ +do \ { \ _mbg_swab16( &(_p)->year ); \ -} +} while ( 0 ) /** @@ -5697,10 +5449,11 @@ typedef struct } MBG_DATE_TIME; #define _mbg_swab_mbg_date_time( _p ) \ +do \ { \ _mbg_swab_mbg_date( &(_p)->d ); \ _mbg_swab_mbg_time( &(_p)->t ); \ -} +} while ( 0 ) /** @@ -5718,10 +5471,12 @@ typedef struct } POUT_TIME; #define _mbg_swab_pout_time( _p ) \ +do \ { \ _mbg_swab_mbg_date_time( &(_p)->on ); \ _mbg_swab_mbg_date_time( &(_p)->off ); \ -} +} while ( 0 ) + /** @@ -5736,72 +5491,102 @@ typedef struct */ typedef union { - POUT_TIME tm[N_POUT_TIMES]; ///< switching times + /// Switching times. See ::POUT_MODES_DATA_TM, ::POUT_MODES_DATA_TM_0 + POUT_TIME tm[N_POUT_TIMES]; + uint8_t b[N_POUT_TIMES * sizeof( POUT_TIME )]; + + /// Only if ::POUT_SUPP_PULSE_SHIFT is set, this field can be used to + /// configure the time interval in [ns] by which output pulse slopes are + /// to be shifted. The configured pulse shift must be in the range + /// ::DEFAULT_POUT_PULSE_SHIFT_MIN through ::DEFAULT_POUT_PULSE_SHIFT_MAX. + /// The resolution / steps at which the pulse shift interval can be configured + /// is returned in ::POUT_INFO::pulse_shift_res. + /// @see ::POUT_MODES_DATA_PULSE_SHIFT int32_t pulse_shift; } POUT_DATA; +#define DEFAULT_POUT_PULSE_SHIFT_MIN -500000000L ///< Default minimum value for ::POUT_DATA::pulse_shift, in [ns] +#define DEFAULT_POUT_PULSE_SHIFT_MAX 499000000L ///< Default maximum value for ::POUT_DATA::pulse_shift, in [ns] + + +/** + * @brief Convert ::POUT_DATA endianess depending on the mode + * + * Assuming the mode is passed to the macro with correct endianess. + */ +#define _mbg_swab_pout_data( _p, _mode ) \ +do \ +{ \ + uint32_t mode_mask = 1UL << _mode; \ + \ + if ( mode_mask & POUT_MODES_DATA_TM ) \ + { \ + int i; \ + \ + for ( i = 0; i < N_POUT_TIMES; i++ ) \ + _mbg_swab_pout_time( &(_p)->tm[i] ); \ + } \ + else \ + { \ + if ( mode_mask & POUT_MODES_DATA_TM_0 ) \ + _mbg_swab_pout_time( &(_p)->tm[0] ); \ + else \ + if ( mode_mask & POUT_MODES_DATA_PULSE_SHIFT ) \ + _mbg_swab32( &(_p)->pulse_shift ); \ + } \ + \ +} while ( 0 ) + + /** * @brief Configuration settings for a single programmable pulse output */ typedef struct { - uint16_t mode; ///< mode of operation, see ::POUT_MODES - uint16_t mode_param; ///< depending on the mode, e.g. pulse length, or index of a signal source - uint16_t timeout; ///< timeout after which output signal is disabled [min], used with ::POUT_DCF77 and ::POUT_DCF77_M59 only, see ::MAX_POUT_DCF_TIMOUT - uint16_t flags; ///< @see ::POUT_SETTINGS_FLAGS - POUT_DATA pout_data; ///< additional configuration data, see ::POUT_DATA + uint16_t mode; ///< Mode of operation, see ::POUT_MODES + uint16_t mode_param; ///< Optional parameter depending on the mode, see @ref POUT_MODES_PARAM_MASKS + + /// Timeout [min] which can be specified for some modes, see ::POUT_MODES_TIMEOUT, ::MAX_POUT_DCF_TIMOUT. + /// + /// If the clock looses synchronization then the output + /// - is disabled **immediately** if ::POUT_IF_SYNC_ONLY is set in ::POUT_SETTINGS::flags + /// - is disabled after ::POUT_SETTINGS::timeout, if timeout is not 0 (see ::MAX_POUT_DCF_TIMOUT) + /// - stays enabled if timeout is 0 **and** ::POUT_IF_SYNC_ONLY is **not** set + uint16_t timeout; + + uint16_t flags; ///< @see ::POUT_SETTINGS_FLAGS + POUT_DATA pout_data; ///< Additional configuration data, see ::POUT_DATA } POUT_SETTINGS; /** * @brief Convert ::POUT_SETTINGS endianess after reading from a device - * - * When reading data from a device we first need to correct the endianess - * of the mode first, and correct the endianess of the tm field only - * if the tm field is not interpreted as ::POUT_DATA. */ -#define _mbg_swab_pout_settings_on_get( _p ) \ -{ \ - _mbg_swab16( &(_p)->mode ); \ - _mbg_swab16( &(_p)->mode_param ); \ - _mbg_swab16( &(_p)->timeout ); \ - _mbg_swab16( &(_p)->flags ); \ - \ - if ( (_p)->mode != POUT_TIME_SLOTS ) \ - { \ - int i; \ - \ - for ( i = 0; i < N_POUT_TIMES; i++ ) \ - _mbg_swab_pout_time( &(_p)->tm[i] ); \ - } \ -} +#define _mbg_swab_pout_settings_on_get( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->mode ); \ + _mbg_swab16( &(_p)->mode_param ); \ + _mbg_swab16( &(_p)->timeout ); \ + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab_pout_data( &(_p)->pout_data, (_p)->mode ); \ +} while ( 0 ) /** * @brief Convert ::POUT_SETTINGS endianess before writing to a device - * - * When writing data to a device we first need to check the mode, - * and correct the endianess of the tm field only if the tm field - * is not interpreted as ::POUT_DATA. Finally we can also correct - * the endianess of the mode field. */ -#define _mbg_swab_pout_settings_on_set( _p ) \ -{ \ - if ( (_p)->mode != POUT_TIME_SLOTS ) \ - { \ - int i; \ - \ - for ( i = 0; i < N_POUT_TIMES; i++ ) \ - _mbg_swab_pout_time( &(_p)->tm[i] ); \ - } \ - \ - _mbg_swab16( &(_p)->mode ); \ - _mbg_swab16( &(_p)->mode_param ); \ - _mbg_swab16( &(_p)->timeout ); \ - _mbg_swab16( &(_p)->flags ); \ -} +#define _mbg_swab_pout_settings_on_set( _p ) \ +do \ +{ \ + _mbg_swab_pout_data( &(_p)->pout_data, (_p)->mode ); \ + _mbg_swab16( &(_p)->mode ); \ + _mbg_swab16( &(_p)->mode_param ); \ + _mbg_swab16( &(_p)->timeout ); \ + _mbg_swab16( &(_p)->flags ); \ +} while ( 0 ) @@ -5812,6 +5597,7 @@ typedef struct * of time slots per minute is stored in ::POUT_SETTINGS::mode_param. * Valid numbers are all numbers n in the range ::MIN_TIME_SLOTS_PER_MINUTE * to ::MAX_TIME_SLOTS_PER_MINUTE for which the remainder of 60 / n is 0. + * @see ::POUT_MODES_MODE_PARAM_AS_SLOTS_PER_MIN * * @anchor POUT_TIME_SLOTS_MODE_DEFS @{ */ @@ -5854,6 +5640,7 @@ typedef struct * @note Not every programmable pulse output supports all modes. * * @see @ref POUT_MODE_MASKS + * @see @ref POUT_MODES_PARAM_MASKS * @see @ref ENG_POUT_NAMES * @see @ref ENG_POUT_HINTS */ @@ -5865,12 +5652,12 @@ enum POUT_MODES /// Switch 'on' or 'off' at the times specified in ::POUT_DATA::tm. POUT_TIMER, - /// Generate a pulse at the time specified in ::POUT_SETTINGS::POUT_DATA::tm[0]::on. + /// Generate a pulse at the time specified in ::POUT_SETTINGS::pout_data::tm[0]::on. /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units. /// See ::MAX_POUT_PULSE_LEN. POUT_SINGLE_SHOT, - /// Generate a cyclic pulse at the interval specified in ::POUT_SETTINGS::POUT_DATA::tm[0]:on::t. + /// Generate a cyclic pulse at the interval specified in ::POUT_SETTINGS::pout_data::tm[0]:on::t. /// Pulse length according to ::POUT_SETTINGS::mode_param, in [10 ms] units. /// See ::MAX_POUT_PULSE_LEN. POUT_CYCLIC_PULSE, @@ -5891,9 +5678,7 @@ enum POUT_MODES POUT_PER_HOUR, /// Generate DCF77-compatible second marks. - /// Stops generating the output signal when receiver lost sync - /// and ::POUT_SETTINGS::timeout expired. - /// See ::MAX_POUT_DCF_TIMOUT. + /// See ::POUT_DCF77_M59, ::POUT_SETTINGS::timeout and ::MAX_POUT_DCF_TIMOUT. POUT_DCF77, /// Output switched on if receiver position verified (condition nav_solved). @@ -5916,11 +5701,9 @@ enum POUT_MODES /// 10 MHz fixed frequency output. POUT_10MHZ, - /// DCF77-like signal with extra 500 ms pulse in 59th second. - /// The original DCF77 signal has no pulse in the 59th second. - /// Stops generating the output signal when receiver lost sync - /// and ::POUT_SETTINGS::timeout expired. - /// See ::MAX_POUT_DCF_TIMOUT. + /// DCF77-like signal with extra 500 ms pulse in the 59th second + /// (the original DCF77 signal has no such pulse). See ::POUT_DCF77, + /// ::POUT_SETTINGS::timeout and ::MAX_POUT_DCF_TIMOUT. POUT_DCF77_M59, /// Output signal generated by the programmable frequency synthesizer. @@ -5936,15 +5719,15 @@ enum POUT_MODES /// be in the range 0..::MBG_GPIO_CFG_LIMITS::num_io. POUT_GPIO, - /// A 1PPS signal with a fixed 20us pulse length + /// A 1 PPS signal with a fixed 20 us pulse length POUT_PTTI_PPS, /// A HaveQuick signal as configured in ::HAVEQUICK_SETTINGS::format POUT_HAVEQUICK, // New modes have to be added here at the end of the enumeration, and the - // POUT_MODE_MASKS as well as string initializers (also in pcpslstr.h) - // have to be updated accordingly. + // POUT_MODE_MASKS, the POUT_MODES_PARAM_MASKS as well as string initializers + // (also in pcpslstr.h) have to be updated accordingly. N_POUT_MODES ///< the number of known modes }; @@ -5983,6 +5766,150 @@ enum POUT_MODES /** @} anchor POUT_MODE_MASKS */ + +/** + * @brief Bit masks indicating which parameters relevant for which ::POUT_MODES + * + * @see ::POUT_MODES + * @see @ref POUT_MODE_MASKS + * + * @anchor POUT_MODES_PARAM_MASKS @{ */ + + +/** + * @brief POUT modes which use the full ::POUT_DATA::tm array as parameter + */ +#define POUT_MODES_DATA_TM \ +( \ + MSK_POUT_TIMER \ +) + + +/** + * @brief POUT modes which use only ::POUT_DATA::tm[0] as parameter + */ +#define POUT_MODES_DATA_TM_0 \ +( \ + MSK_POUT_SINGLE_SHOT | \ + MSK_POUT_CYCLIC_PULSE \ +) + + +/** + * @brief POUT modes which use ::POUT_SETTINGS::mode_param as pulse length + * + * @see ::MAX_POUT_PULSE_LEN + */ +#define POUT_MODES_MODE_PARAM_AS_PULSE_LEN \ +( \ + MSK_POUT_SINGLE_SHOT | \ + MSK_POUT_CYCLIC_PULSE | \ + MSK_POUT_PER_SEC | \ + MSK_POUT_PER_MIN | \ + MSK_POUT_PER_HOUR \ +) + + +/** + * @brief POUT modes which use ::POUT_SETTINGS::mode_param as COM port index number + */ +#define POUT_MODES_MODE_PARAM_AS_COM_IDX \ +( \ + MSK_POUT_TIMESTR \ +) + + +/** + * @brief POUT modes which use ::POUT_SETTINGS::mode_param as time slots per minute + * + * @see @ref POUT_TIME_SLOTS_MODE_DEFS + */ +#define POUT_MODES_MODE_PARAM_AS_SLOTS_PER_MIN \ +( \ + MSK_POUT_TIME_SLOTS \ +) + + +/** + * @brief POUT modes which use ::POUT_SETTINGS::mode_param as GPIO index number + */ +#define POUT_MODES_MODE_PARAM_AS_GPIO_IDX \ +( \ + MSK_POUT_GPIO \ +) + + +/** + * @brief POUT modes which use ::POUT_SETTINGS::timeout + */ +#define POUT_MODES_TIMEOUT \ +( \ + MSK_POUT_DCF77 | \ + MSK_POUT_DCF77_M59 \ +) + + +/** + * @brief POUT modes which which support ::POUT_TIMEBASE_UTC + */ +#define POUT_MODES_SUPP_TIMEBASE_UTC \ +( \ + MSK_POUT_DCF77 | \ + MSK_POUT_DCF77_M59 \ +) + + +/** + * @brief POUT modes which use ::POUT_DATA::pulse_shift + * + * @note: Supported only if ::POUT_SUPP_PULSE_SHIFT is set + */ +#define POUT_MODES_DATA_PULSE_SHIFT \ +( \ + MSK_POUT_PER_SEC | \ + MSK_POUT_PER_MIN | \ + MSK_POUT_PER_HOUR \ +) + + +/** + * @brief POUT modes which support ::POUT_SUPP_IF_SYNC_ONLY + * + * Even if ::POUT_SUPP_IF_SYNC_ONLY is set in ::POUT_INFO::flags + * the associated flag ::POUT_IF_SYNC_ONLY in ::POUT_SETTINGS::flags + * may be evaluated depending on the mode. + * + * Modes ::POUT_POS_OK, ::POUT_TIME_SYNC, and ::MSK_POUT_ALL_SYNC + * are explicitly excluded. + * + * For modes ::MSK_POUT_DCF77 and ::MSK_POUT_DCF77_M59 see also + * ::POUT_SETTINGS::timeout. + */ +#define POUT_MODES_SUPP_IF_SYNC_ONLY \ +( \ + MSK_POUT_IDLE | \ + MSK_POUT_TIMER | \ + MSK_POUT_SINGLE_SHOT | \ + MSK_POUT_CYCLIC_PULSE | \ + MSK_POUT_PER_SEC | \ + MSK_POUT_PER_MIN | \ + MSK_POUT_PER_HOUR | \ + MSK_POUT_DCF77 | \ + MSK_POUT_TIMECODE | \ + MSK_POUT_TIMESTR | \ + MSK_POUT_10MHZ | \ + MSK_POUT_DCF77_M59 | \ + MSK_POUT_SYNTH | \ + MSK_POUT_TIME_SLOTS | \ + MSK_POUT_GPIO | \ + MSK_POUT_PTTI_PPS | \ + MSK_POUT_HAVEQUICK \ +) + +/** @} anchor POUT_MODES_PARAM_MASKS */ + + + /** * @brief Name strings associated with ::POUT_MODES * @@ -6012,11 +5939,9 @@ enum POUT_MODES #define ENG_POUT_NAME_SYNTH "Synthesizer Frequency" #define ENG_POUT_NAME_TIME_SLOTS "Time Slots per Minute" #define ENG_POUT_NAME_GPIO "GPIO Signal" -#define ENG_POUT_PTTI_PPS "PTTI 1PPS" +#define ENG_POUT_PTTI_PPS "PTTI 1 PPS" #define ENG_POUT_HAVEQUICK "HaveQuick" - - /** @} anchor ENG_POUT_NAMES */ @@ -6124,9 +6049,27 @@ enum POUT_MODES */ enum POUT_SETTINGS_FLAG_BITS { - POUT_BIT_INVERTED, ///< output level is inverted, use only if ::POUT_NOT_INVERTIBLE not set - POUT_BIT_IF_SYNC_ONLY, ///< disable output in holdover mode, use only if ::POUT_SUPP_IF_SYNC_ONLY is set - POUT_BIT_TIMEBASE_UTC, ///< output %UTC if mode is ::POUT_DCF77 or ::POUT_DCF77_M59, use only if ::POUT_SUPP_DCF77_UTC is set + /// Output level is to be inverted. Can only be used + /// if ::POUT_NOT_INVERTIBLE is **not** set, but is + /// supported by all ::POUT_MODES. + POUT_BIT_INVERTED, + + /// Enable output **only** while synchronized. This even overrides + /// the settings in ::ENABLE_FLAGS::pulses, so if this flag is set + /// the output is only enabled if the clock is synchronized, and is + /// disabled when synchronization is lost, i.e. the device enters + /// holdover mode. + /// This flag can only be used with outputs that have ::POUT_SUPP_IF_SYNC_ONLY + /// set, and is only supported for the ::POUT_MODES specified in + /// ::POUT_MODES_SUPP_IF_SYNC_ONLY. + POUT_BIT_IF_SYNC_ONLY, + + /// Output %UTC time instead of local time for DCF77 emulation. + /// This flag can only be used with outputs that have ::POUT_SUPP_DCF77_UTC + /// set, and is only supported for the ::POUT_MODES specified in + /// ::POUT_MODES_SUPP_TIMEBASE_UTC (e.g. ::POUT_DCF77 or ::POUT_DCF77_M59). + POUT_BIT_TIMEBASE_UTC, + N_POUT_SETTINGS_FLAG_BITS ///< Number of known flag bits }; @@ -6163,16 +6106,18 @@ typedef struct } POUT_SETTINGS_IDX; #define _mbg_swab_pout_settings_idx_on_set( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_pout_settings_on_set( &(_p)->pout_settings ); \ -} +} while ( 0 ) #define _mbg_swab_pout_settings_idx_on_get( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_pout_settings_on_get( &(_p)->pout_settings ); \ -} +} while ( 0 ) /** @@ -6188,21 +6133,24 @@ typedef struct typedef struct { POUT_SETTINGS pout_settings; - uint32_t supp_modes; ///< bit mask of modes supp. by this output, see @ref POUT_MODE_MASKS - uint8_t timestr_ports; ///< bit mask of COM ports supported for mode ::POUT_TIMESTR, see ::MAX_POUT_TIMESTR_PORTS - uint8_t reserved_0; ///< reserved for future use, currently unused and always 0 - uint16_t reserved_1; ///< reserved for future use, currently unused and always 0 - uint32_t flags; ///< @see ::POUT_INFO_FLAG_MASKS + uint32_t supp_modes; ///< bit mask of modes supp. by this output, see @ref POUT_MODE_MASKS + uint8_t timestr_ports; ///< bit mask of COM ports supported for mode ::POUT_TIMESTR, see ::MAX_POUT_TIMESTR_PORTS + uint8_t pulse_shift_res; ///< pulse shift resolution, in [ns], only if ::POUT_SUPP_PULSE_SHIFT, see ::POUT_DATA::pulse_shift + uint16_t reserved_1; ///< reserved for future use, currently unused and always 0 + uint32_t flags; ///< @see ::POUT_INFO_FLAG_MASKS } POUT_INFO; #define _mbg_swab_pout_info_on_get( _p ) \ +do \ { \ _mbg_swab_pout_settings_on_get( &(_p)->pout_settings ); \ _mbg_swab32( &(_p)->supp_modes ); \ + _mbg_swab8( &(_p)->timestr_ports ); \ + _mbg_swab8( &(_p)->pulse_shift_res ); \ _mbg_swab16( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) #define MAX_POUT_TIMESTR_PORTS 8 ///< The max number of COM ports that can be handled by ::POUT_INFO::timestr_ports @@ -6220,6 +6168,7 @@ enum POUT_INFO_FLAG_BITS POUT_BIT_SUPP_DCF77_UTC, ///< ::POUT_SUPP_DCF77_UTC is supported for this output POUT_BIT_FIXED_PULSE_LEN, ///< pulse length is limited to the value ::POUT_SETTINGS::mode_param POUT_BIT_NOT_INVERTIBLE, ///< output level can't be inverted, thus ::POUT_INVERTED is not supported for this output + POUT_BIT_SUPP_PULSE_SHIFT, ///< output slopes can be shifted, see ::POUT_DATA::pulse_shift N_POUT_INFO_FLAG_BITS ///< number of known flag bits }; @@ -6234,7 +6183,8 @@ enum POUT_INFO_FLAG_MASKS POUT_SUPP_IF_SYNC_ONLY = ( 1UL << POUT_BIT_SUPP_IF_SYNC_ONLY ), ///< see ::POUT_BIT_SUPP_IF_SYNC_ONLY, ::POUT_IF_SYNC_ONLY POUT_SUPP_DCF77_UTC = ( 1UL << POUT_BIT_SUPP_DCF77_UTC ), ///< see ::POUT_BIT_SUPP_DCF77_UTC, ::POUT_SUPP_DCF77_UTC POUT_FIXED_PULSE_LEN = ( 1UL << POUT_BIT_FIXED_PULSE_LEN ), ///< see ::POUT_BIT_FIXED_PULSE_LEN - POUT_NOT_INVERTIBLE = ( 1UL << POUT_BIT_NOT_INVERTIBLE ) ///< see ::POUT_BIT_NOT_INVERTIBLE, ::POUT_INVERTED + POUT_NOT_INVERTIBLE = ( 1UL << POUT_BIT_NOT_INVERTIBLE ), ///< see ::POUT_BIT_NOT_INVERTIBLE, ::POUT_INVERTED + POUT_SUPP_PULSE_SHIFT = ( 1UL << POUT_BIT_SUPP_PULSE_SHIFT ) ///< see ::POUT_BIT_SUPP_PULSE_SHIFT, ::POUT_DATA::pulse_shift }; @@ -6258,10 +6208,11 @@ typedef struct } POUT_INFO_IDX; #define _mbg_swab_pout_info_idx_on_get( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_pout_info_on_get( &(_p)->pout_info ); \ -} +} while ( 0 ) /** @} defgroup group_pout_api */ @@ -6606,6 +6557,13 @@ typedef struct } XMULTI_REF_ID; +#define _mbg_swab_xmulti_ref_id( _p ) \ +do \ +{ \ + _mbg_swab8( &(_p)->type ); \ + _mbg_swab8( &(_p)->instance ); \ +} while ( 0 ) + /** @@ -6621,6 +6579,16 @@ typedef struct } XMULTI_REF_SETTINGS; +#define _mbg_swab_xmulti_ref_settings( _p ) \ +do \ +{ \ + _mbg_swab_xmulti_ref_id( &(_p)->id ); \ + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab_nano_time( &(_p)->bias ); \ + _mbg_swab_nano_time( &(_p)->precision ); \ + _mbg_swab32( &(_p)->reserved ); \ +} while ( 0 ) + /** @@ -6637,6 +6605,13 @@ typedef struct } XMULTI_REF_SETTINGS_IDX; +#define _mbg_swab_xmulti_ref_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmulti_ref_settings( &(_p)->settings ); \ +} while ( 0 ) + /** @@ -6690,6 +6665,16 @@ typedef struct } XMULTI_REF_INFO; +#define _mbg_swab_xmulti_ref_info( _p ) \ +do \ +{ \ + _mbg_swab_xmulti_ref_settings( &(_p)->settings ); \ + _mbg_swab32( &(_p)->supp_ref ); \ + _mbg_swab8( &(_p)->n_supp_ref ); \ + _mbg_swab8( &(_p)->n_prio ); \ + _mbg_swab16( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -6702,6 +6687,13 @@ typedef struct } XMULTI_REF_INFO_IDX; +#define _mbg_swab_xmulti_ref_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmulti_ref_info( &(_p)->info ); \ +} while ( 0 ) + /** @@ -6718,6 +6710,17 @@ typedef struct } XMULTI_REF_STATUS; +#define _mbg_swab_xmulti_ref_status( _p ) \ +do \ +{ \ + _mbg_swab_xmulti_ref_id( &(_p)->id ); \ + _mbg_swab16( &(_p)->status ); \ + _mbg_swab_nano_time( &(_p)->offset ); \ + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab8( &(_p)->ssm ); \ + _mbg_swab8( &(_p)->soc ); \ +} while ( 0 ) + /** @@ -6730,6 +6733,13 @@ typedef struct } XMULTI_REF_STATUS_IDX; +#define _mbg_swab_xmulti_ref_status_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmulti_ref_status( &(_p)->status ); \ +} while ( 0 ) + /** @@ -6738,9 +6748,12 @@ typedef struct * Used with the ::... field of ::XMULTI_REF_STATUS::flags * * @see ::XMULTI_REF_STATUS::flags - * @see ::XMR_QL_MASK - * @see ::_GET_XMR_QL - * @see ::_PUT_XMR_QL + * @see ::XMR_QL_TDEV_MASK + * @see ::_GET_XMR_QL_TDEV + * @see ::_PUT_XMR_QL_TDEV + * @see ::XMR_QL_MTIE_MASK + * @see ::_GET_XMR_QL_MTIE + * @see ::_PUT_XMR_QL_MTIE */ enum XMR_QL { @@ -6889,6 +6902,13 @@ typedef struct } XMULTI_REF_INSTANCES; +#define _mbg_swab_xmulti_ref_instances( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab16( &(_p)->n_xmr_settings ); \ +} while ( 0 ) + /** @@ -6935,7 +6955,7 @@ enum XMR_INST_FLAG_BIT_MASKS typedef uint32_t XMR_HOLDOVER_INTV; #define _mbg_swab_xmr_holdover_intv( _p ) \ - _mbg_swab32( _p ); + _mbg_swab32( _p ) @@ -6986,6 +7006,20 @@ typedef struct } XMR_HOLDOVER_STATUS; +#define _mbg_swab_xmr_holdover_status( _p ) \ +do \ +{ \ + _mbg_swab8( &(_p)->mode ); \ + _mbg_swab8( &(_p)->curr_prio ); \ + _mbg_swab8( &(_p)->nxt_prio ); \ + _mbg_swab8( &(_p)->remote_watchdog ); \ + _mbg_swab32( &(_p)->time_offset_ns ); \ + _mbg_swab_xmr_holdover_intv( &(_p)->elapsed ); \ + _mbg_swab_xmr_holdover_intv( &(_p)->interval ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + /** @@ -7085,6 +7119,14 @@ typedef struct } XMR_EXT_SRC_INFO; +#define _mbg_swab_xmr_ext_src_info( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->supp_flags ); \ + _mbg_swab16( &(_p)->feat_flags ); \ + _mbg_swab32( &(_p)->reserved_0 ); \ +} while ( 0 ) + typedef struct @@ -7094,6 +7136,13 @@ typedef struct } XMR_EXT_SRC_INFO_IDX; // +#define _mbg_swab_xmr_ext_src_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmr_ext_src_info( &(_p)->info ); \ +} while ( 0 ) + /** @@ -7122,6 +7171,22 @@ typedef struct } XMR_STATS; +#define _mbg_swab_xmr_stats( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->timestamp ); \ + _mbg_swab_nano_time( &(_p)->last_mue ); \ + _mbg_swab_nano_time( &(_p)->last_sigma ); \ + _mbg_swab_nano_time( &(_p)->last_max ); \ + _mbg_swab_nano_time( &(_p)->last_min ); \ + _mbg_swab_nano_time( &(_p)->reserved_0 ); \ + _mbg_swab_nano_time( &(_p)->step_comp_val ); \ + _mbg_swab_nano_time( &(_p)->auto_bias ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7179,6 +7244,13 @@ typedef struct } XMR_STATS_IDX; +#define _mbg_swab_xmr_stats_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmr_stats( &(_p)->stats ); \ +} while ( 0 ) + #define MAX_XMR_METRICS 20 @@ -7197,6 +7269,29 @@ typedef struct } XMR_METRICS; +#define _mbg_swab_xmr_metrics( _p ) \ +do \ +{ \ + int i; \ + \ + _mbg_swab32( &(_p)->timestamp ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab8( &(_p)->mtie_scale ); \ + _mbg_swab8( &(_p)->tdev_scale ); \ + _mbg_swab16( &(_p)->reserved_0 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + \ + for ( i = 0; i < MAX_XMR_METRICS; i++ ) \ + _mbg_swab32( &(_p)->mtie[i] ); \ + \ + for ( i = 0; i < MAX_XMR_METRICS; i++ ) \ + _mbg_swab32( &(_p)->tdev[i] ); \ + \ +} while ( 0 ) + + + // conversion factor scaled FPU32 to double #define _fpu32_to_double_fac( _x ) ( 1.0 / ( 4294967296.0 * ( _x ) ) ) @@ -7214,6 +7309,13 @@ typedef struct } XMR_METRICS_IDX; +#define _mbg_swab_xmr_metrics_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_xmr_metrics( &(_p)->metrics ); \ +} while ( 0 ) + /** @@ -7349,11 +7451,12 @@ typedef struct } MBG_GPIO_CFG_LIMITS; #define _mbg_swab_mbg_gpio_cfg_limits( _p ) \ +do \ { \ _mbg_swab32( &(_p)->num_io ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -7489,10 +7592,11 @@ typedef struct } MBG_GPIO_FREQ; #define _mbg_swab_mbg_gpio_freq( _p ) \ +do \ { \ _mbg_swab32( &(_p)->hz ); \ _mbg_swab32( &(_p)->frac); \ -} +} while ( 0 ) @@ -7514,6 +7618,16 @@ typedef struct } MBG_GPIO_FREQ_IN_SETTINGS; +#define _mbg_swab_mbg_gpio_freq_in_settings( _p ) \ +do \ +{ \ + _mbg_swab_mbg_gpio_freq( &(_p)->freq ); \ + _mbg_swab32( &(_p)->csc_limit ); \ + _mbg_swab32( &(_p)->shape ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7535,6 +7649,17 @@ typedef struct } MBG_GPIO_FREQ_IN_SUPP; +#define _mbg_swab_mbg_gpio_freq_in_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->freq_min ); \ + _mbg_swab32( &(_p)->freq_max ); \ + _mbg_swab32( &(_p)->csc_limit_max ); \ + _mbg_swab32( &(_p)->supp_shapes ); \ + _mbg_swab32( &(_p)->supp_limits ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7555,6 +7680,16 @@ typedef struct } MBG_GPIO_FREQ_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_freq_out_settings( _p ) \ +do \ +{ \ + _mbg_swab_mbg_gpio_freq( &(_p)->freq ); \ + _mbg_swab32( &(_p)->milli_phase ); \ + _mbg_swab32( &(_p)->shape ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7577,6 +7712,18 @@ typedef struct } MBG_GPIO_FREQ_OUT_SUPP; +#define _mbg_swab_mbg_gpio_freq_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->freq_min ); \ + _mbg_swab32( &(_p)->freq_max ); \ + _mbg_swab32( &(_p)->freq_resolution ); \ + _mbg_swab32( &(_p)->milli_phase_max ); \ + _mbg_swab32( &(_p)->supp_shapes ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7655,6 +7802,15 @@ typedef struct } MBG_GPIO_FIXED_FREQ_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_fixed_freq_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->freq_idx ); \ + _mbg_swab32( &(_p)->shape ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7674,6 +7830,15 @@ typedef struct } MBG_GPIO_FIXED_FREQ_OUT_SUPP; +#define _mbg_swab_mbg_gpio_fixed_freq_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_freq ); \ + _mbg_swab32( &(_p)->supp_shapes ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) + /** @@ -7809,6 +7974,38 @@ typedef struct } MBG_GPIO_BITS_IN_SETTINGS; +#define _mbg_swab_mbg_gpio_bits_in_settings( _p, _recv ) \ +do \ +{ \ + uint32_t f = (_p)->format; \ + if ( (_recv) ) \ + _mbg_swab32( &f); \ + _mbg_swab32( &(_p)->format ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->csc_limit ); \ + switch( f ) \ + { \ + case MBG_GPIO_BITS_E1_FRAMED : \ + case MBG_GPIO_BITS_E1_TIMING : \ + _mbg_swab8( &(_p)->quality.e1.ssm ); \ + _mbg_swab8( &(_p)->quality.e1.sa_bits ); \ + _mbg_swab16( &(_p)->quality.e1.reserved ); \ + break; \ + \ + case MBG_GPIO_BITS_T1_FRAMED : \ + case MBG_GPIO_BITS_T1_TIMING : \ + _mbg_swab8( &(_p)->quality.t1.min_boc ); \ + _mbg_swab8( &(_p)->quality.t1.reserved_0 ); \ + _mbg_swab16( &(_p)->quality.t1.reserved_1 ); \ + break; \ + \ + default: \ + break; \ + } \ + _mbg_swab32( &(_p)->err_msk ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -7852,6 +8049,13 @@ typedef struct } MBG_GPIO_BITS_IN_SUPP; +#define _mbg_swab_mbg_gpio_bits_in_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_fmts ); \ + _mbg_swab32( &(_p)->reserved ); \ +} while ( 0 ) + /** @@ -7876,6 +8080,20 @@ typedef struct } MBG_GPIO_BITS_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_bits_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->format ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab8( &(_p)->sa_bits ); \ + _mbg_swab8( &(_p)->ssm ); \ + _mbg_swab8( &(_p)->boc ); \ + _mbg_swab8( &(_p)->reserved_0 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ +} while ( 0 ) + /** @@ -7930,11 +8148,18 @@ enum MBG_GPIO_BITS_OUT_FLAG_MASKS */ typedef struct { - uint32_t supp_fmts; ///< bit mask of supported formats, see ::MBG_GPIO_BITS_FORMAT_MASKS - uint32_t reserved; ///< reserved, currently always 0 + uint32_t supp_fmts; ///< bit mask of supported formats, see ::MBG_GPIO_BITS_FORMAT_MASKS + uint32_t supp_flags; ///< bit mask of supported flags, see ::MBG_GPIO_BITS_OUT_FLAG_MASKS } MBG_GPIO_BITS_OUT_SUPP; +#define _mbg_swab_mbg_gpio_bits_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_fmts ); \ + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) + /** @@ -8021,6 +8246,7 @@ enum MBG_GPIO_VIDEO_FORMAT_MASKS enum MBG_GPIO_VIDEO_OUT_FLAGS { MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF, ///< if set, Out1: HD, Out2: SD + MBG_GPIO_VIDEO_OUT_HAS_TC_SD, ///< supports Time Code for SD Black Bursts N_MBG_GPIO_VIDEO_OUT_FLAGS ///< number of known flags }; @@ -8035,7 +8261,8 @@ enum MBG_GPIO_VIDEO_OUT_FLAGS */ enum MBG_GPIO_VIDEO_OUT_FLAG_MASKS { - MSK_MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF = ( 1UL << MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF ) ///< see ::MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF + MSK_MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF = ( 1UL << MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF ), ///< see ::MBG_GPIO_VIDEO_OUT_HAS_NO_FREE_CONF + MSK_MBG_GPIO_VIDEO_OUT_HAS_TC_SD = ( 1UL << MBG_GPIO_VIDEO_OUT_HAS_TC_SD ) ///< see ::MBG_GPIO_VIDEO_OUT_HAS_TC_SD }; @@ -8093,6 +8320,46 @@ enum MBG_GPIO_VIDEO_EPOCH_MASKS /** + * @brief Enumeration of time code modes used with video type GPIO outputs + * + * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::tc_mode + * + */ +enum MBG_GPIO_VIDEO_TC_MODES +{ + MBG_GPIO_VIDEO_TC_MODE_NONE, ///< None + MBG_GPIO_VIDEO_TC_MODE_VITC, ///< Vertical Interval Time Code + N_MBG_GPIO_VIDEO_TC_MODES +}; + + +/** + * @brief Bit masks associated with ::MBG_GPIO_VIDEO_TC_MODES + * + * Used with ::MBG_GPIO_VIDEO_OUT_SETTINGS::tc_mode + * + */ +enum MBG_GPIO_VIDEO_TC_MODE_MASKS +{ + MSK_MBG_GPIO_VIDEO_TC_MODE_NONE = ( 1UL << MBG_GPIO_VIDEO_TC_MODE_NONE ), ///< see ::MBG_GPIO_VIDEO_TC_MODE_NONE + MSK_MBG_GPIO_VIDEO_TC_MODE_VITC = ( 1UL << MBG_GPIO_VIDEO_TC_MODE_VITC ) ///< see ::MBG_GPIO_VIDEO_TC_MODE_VITC +}; + + +/** + * @brief Initializers for an array of video time code modes + * + * @see ::MBG_GPIO_VIDEO_TC_MODES + */ +#define MBG_GPIO_VIDEO_TC_MODE_STRS \ +{ \ + "None", \ + "VITC" \ +} + + + +/** * @brief Configuration of a GPIO as video output module * * Used as sub-structure of ::MBG_GPIO_SETTINGS. @@ -8106,13 +8373,30 @@ typedef struct uint32_t flags; ///< flags, see ::MBG_GPIO_VIDEO_OUT_FLAG_MASKS int32_t phase_offset; ///< Phase offset in [ns] uint8_t epoch; ///< epoch, see ::MBG_GPIO_VIDEO_EPOCHS - uint8_t reserved2; ///< reserved, currently always 0 - uint16_t reserved3; ///< reserved, currently always 0 + + uint8_t tc_mode; ///< time code mode, see ::MBG_GPIO_VIDEO_TC_MODES + uint8_t tc_line0; ///< first time code line location, valid lines: 6-22 + uint8_t tc_line1; ///< second time code line location, valid lines: 6-22 + uint32_t reserved0; ///< reserved, currently always 0 uint32_t reserved1; ///< reserved, currently always 0 } MBG_GPIO_VIDEO_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_video_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->format ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->phase_offset ); \ + _mbg_swab8( &(_p)->epoch ); \ + _mbg_swab8( &(_p)->tc_mode ); \ + _mbg_swab8( &(_p)->tc_line0 ); \ + _mbg_swab8( &(_p)->tc_line1 ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ +} while ( 0 ) + /** @@ -8126,12 +8410,31 @@ typedef struct typedef struct { uint32_t supp_formats; ///< supported video formats, see ::MBG_GPIO_VIDEO_FORMAT_MASKS - uint32_t supp_flags; ///< supported flags, see::MBG_GPIO_VIDEO_OUT_FLAG_MASKS - uint32_t supp_epochs; ///< supported epochs, see::MBG_GPIO_VIDEO_EPOCH_MASKS + uint32_t supp_flags; ///< supported flags, see ::MBG_GPIO_VIDEO_OUT_FLAG_MASKS + uint32_t supp_epochs; ///< supported epochs, see ::MBG_GPIO_VIDEO_EPOCH_MASKS + + uint8_t supp_tc_modes; ///< supported tc_modes, see ::MBG_GPIO_VIDEO_TC_MODE_MASKS + + uint8_t reserved0; ///< reserved, currently always 0 + uint8_t reserved2; ///< reserved, currently always 0 + uint16_t reserved3; ///< reserved, currently always 0 uint32_t reserved1; ///< reserved, currently always 0 } MBG_GPIO_VIDEO_OUT_SUPP; +#define _mbg_swab_mbg_gpio_video_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_formats ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + _mbg_swab32( &(_p)->supp_epochs ); \ + _mbg_swab8( &(_p)->supp_tc_modes ); \ + _mbg_swab8( &(_p)->reserved0 ); \ + _mbg_swab16( &(_p)->reserved2 ); \ + _mbg_swab16( &(_p)->reserved3 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ +} while ( 0 ) + /** @@ -8232,6 +8535,17 @@ typedef struct } MBG_GPIO_VIDEO_SYNC_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_video_sync_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->type ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ + _mbg_swab32( &(_p)->reserved2 ); \ + _mbg_swab32( &(_p)->reserved3 ); \ +} while ( 0 ) + /** @@ -8251,6 +8565,15 @@ typedef struct } MBG_GPIO_VIDEO_SYNC_OUT_SUPP; +#define _mbg_swab_mbg_gpio_video_sync_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_types ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ +} while ( 0 ) + /** @@ -8429,6 +8752,17 @@ typedef struct } MBG_GPIO_STUDIO_CLOCK_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_studio_clock_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->base_freq ); \ + _mbg_swab32( &(_p)->scale ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ +} while ( 0 ) + + #define MAX_SUPP_BASE_FREQUENCIES 8 ///< max. supported base frequencies for studio clock outputs @@ -8451,12 +8785,25 @@ typedef struct } MBG_GPIO_STUDIO_CLOCK_OUT_SUPP; +#define _mbg_swab_mbg_gpio_studio_clock_out_supp( _p ) \ +do \ +{ \ + uint8_t idx; \ + _mbg_swab8( &(_p)->supp_base_freqs ); \ + _mbg_swab8( &(_p)->reserved0 ); \ + _mbg_swab16( &(_p)->reserved1 ); \ + for( idx = 0; idx < MAX_SUPP_BASE_FREQUENCIES; idx++ ) \ + _mbg_swab16( &(_p)->supp_scales[idx] ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + _mbg_swab32( &(_p)->reserved2 ); \ +} while ( 0 ) + /** * @brief Enumeration of types used with GPIO type digital audio outputs * - * Used with ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT_SETTINGS::type, and used to + * Used with ::MBG_GPIO_DIGITAL_AUDIO_OUT_SETTINGS::type, and to * define ::MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS * * @see ::MBG_GPIO_DIGITAL_AUDIO_TYPE_MASKS @@ -8513,7 +8860,7 @@ enum MBG_GPIO_DIGITAL_AUDIO_FLAGS /** * @brief Bit masks associated with ::MBG_GPIO_DIGITAL_AUDIO_FLAGS * - * Used with ::MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT_SETTINGS::flags + * Used with ::MBG_GPIO_DIGITAL_AUDIO_OUT_SETTINGS::flags * * @see ::MBG_GPIO_DIGITAL_AUDIO_FLAGS */ @@ -8542,6 +8889,16 @@ typedef struct } MBG_GPIO_DIGITAL_AUDIO_OUT_SETTINGS; +#define _mbg_swab_mbg_gpio_digital_audio_out_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->type ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ + _mbg_swab32( &(_p)->reserved2 ); \ +} while ( 0 ) + /** @@ -8562,6 +8919,16 @@ typedef struct } MBG_GPIO_DIGITAL_AUDIO_OUT_SUPP; +#define _mbg_swab_mbg_gpio_digital_audio_out_supp( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_types ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + _mbg_swab32( &(_p)->reserved0 ); \ + _mbg_swab32( &(_p)->reserved1 ); \ + _mbg_swab32( &(_p)->reserved2 ); \ +} while ( 0 ) + /** @@ -8580,7 +8947,7 @@ enum MBG_GPIO_FLAGS /** * @brief Bit masks associated with ::MBG_GPIO_FLAGS * - * Used with ::MBG_GPIO_LIMITS::flags and ::MBG_GPIO_SETTINGS::flags + * Used with ::MBG_GPIO_LIMITS::supp_flags and ::MBG_GPIO_SETTINGS::flags * * @see ::MBG_GPIO_FLAGS */ @@ -8620,6 +8987,32 @@ typedef struct } MBG_GPIO_SETTINGS; +#define _mbg_swab_mbg_gpio_settings( _p, _recv ) \ +do \ +{ \ + uint32_t t = (_p)->type; \ + if ( (_recv) ) \ + _mbg_swab32( &t ); \ + _mbg_swab32( &(_p)->type ); \ + _mbg_swab16( &(_p)->reserved_1 ); \ + _mbg_swab8( &(_p)->reserved_2 ); \ + _mbg_swab8( &(_p)->ass_io_idx ); \ + _mbg_swab32( &(_p)->flags ); \ + switch( t ) \ + { \ + case MBG_GPIO_TYPE_FREQ_IN : _mbg_swab_mbg_gpio_freq_in_settings( &(_p)->u.freq_in ); break; \ + case MBG_GPIO_TYPE_FREQ_OUT : _mbg_swab_mbg_gpio_freq_out_settings( &(_p)->u.freq_out ); break; \ + case MBG_GPIO_TYPE_FIXED_FREQ_OUT : _mbg_swab_mbg_gpio_fixed_freq_out_settings( &(_p)->u.ff_out ); break; \ + case MBG_GPIO_TYPE_BITS_IN : _mbg_swab_mbg_gpio_bits_in_settings( &(_p)->u.bits_in, (_recv) ); break; \ + case MBG_GPIO_TYPE_BITS_OUT : _mbg_swab_mbg_gpio_bits_out_settings( &(_p)->u.bits_out ); break; \ + case MBG_GPIO_TYPE_VIDEO_OUT : _mbg_swab_mbg_gpio_video_out_settings( &(_p)->u.video_out ); break; \ + case MBG_GPIO_TYPE_VIDEO_SYNC_OUT : _mbg_swab_mbg_gpio_video_sync_out_settings( &(_p)->u.video_sync_out ); break; \ + case MBG_GPIO_TYPE_STUDIO_CLOCK_OUT : _mbg_swab_mbg_gpio_studio_clock_out_settings( &(_p)->u.studio_clk_out ); break; \ + case MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT : _mbg_swab_mbg_gpio_digital_audio_out_settings( &(_p)->u.digital_audio_out ); break; \ + default : break; \ + } \ +} while ( 0 ) + /** @@ -8632,6 +9025,13 @@ typedef struct } MBG_GPIO_SETTINGS_IDX; +#define _mbg_swab_mbg_gpio_settings_idx( _p, _recv ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_mbg_gpio_settings( &(_p)->settings, (_recv ) ); \ +} while ( 0 ) + /** @@ -8659,6 +9059,30 @@ typedef struct } MBG_GPIO_LIMITS; +#define _mbg_swab_mbg_gpio_limits( _p, _recv ) \ +do \ +{ \ + uint32_t t = (_p)->type; \ + if ( (_recv) ) \ + _mbg_swab32( &t ); \ + _mbg_swab32( &(_p)->type ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + switch( t ) \ + { \ + case MBG_GPIO_TYPE_FREQ_IN : _mbg_swab_mbg_gpio_freq_in_supp( &(_p)->u.freq_in ); break; \ + case MBG_GPIO_TYPE_FREQ_OUT : _mbg_swab_mbg_gpio_freq_out_supp( &(_p)->u.freq_out ); break; \ + case MBG_GPIO_TYPE_FIXED_FREQ_OUT : _mbg_swab_mbg_gpio_fixed_freq_out_supp( &(_p)->u.ff_out ); break; \ + case MBG_GPIO_TYPE_BITS_IN : _mbg_swab_mbg_gpio_bits_in_supp( &(_p)->u.bits_in ); break; \ + case MBG_GPIO_TYPE_BITS_OUT : _mbg_swab_mbg_gpio_bits_out_supp( &(_p)->u.bits_out ); break; \ + case MBG_GPIO_TYPE_VIDEO_OUT : _mbg_swab_mbg_gpio_video_out_supp( &(_p)->u.video_out ); break; \ + case MBG_GPIO_TYPE_VIDEO_SYNC_OUT : _mbg_swab_mbg_gpio_video_sync_out_supp( &(_p)->u.video_sync_out ); break; \ + case MBG_GPIO_TYPE_STUDIO_CLOCK_OUT : _mbg_swab_mbg_gpio_studio_clock_out_supp( &(_p)->u.studio_clk_out ); break; \ + case MBG_GPIO_TYPE_DIGITAL_AUDIO_OUT : _mbg_swab_mbg_gpio_digital_audio_out_supp( &(_p)->u.digital_audio_out ); break; \ + default : break; \ + } \ +} while ( 0 ) + /** @@ -8672,6 +9096,13 @@ typedef struct } MBG_GPIO_INFO; +#define _mbg_swab_mbg_gpio_info( _p, _recv ) \ +do \ +{ \ + _mbg_swab_mbg_gpio_settings( &(_p)->settings, (_recv) ); \ + _mbg_swab_mbg_gpio_limits( &(_p)->limits, (_recv) ); \ +} while ( 0 ) + /** * @brief A GPIO port's current settings and limits, plus port index @@ -8683,6 +9114,13 @@ typedef struct } MBG_GPIO_INFO_IDX; +#define _mbg_swab_mbg_gpio_info_idx( _p, _recv ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_mbg_gpio_info( &(_p)->info, (_recv) ); \ +} while ( 0 ) + /** @@ -8698,6 +9136,16 @@ typedef struct } MBG_GPIO_STATUS; +#define _mbg_swab_mbg_gpio_status( _p ) \ +do \ +{ \ + _mbg_swab8( &(_p)->port_state ); \ + _mbg_swab8( &(_p)->reserved_0 ); \ + _mbg_swab16( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ +} while ( 0 ) + /** @@ -8710,6 +9158,13 @@ typedef struct } MBG_GPIO_STATUS_IDX; +#define _mbg_swab_mbg_gpio_status_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_mbg_gpio_status( &(_p)->status ); \ +} while ( 0 ) + /** @@ -8846,13 +9301,14 @@ typedef struct } HAVEQUICK_SETTINGS; #define _mbg_swab_havequick_settings( _p ) \ +do \ { \ _mbg_swab16( &(_p)->format ); \ _mbg_swab16( &(_p)->flags ); \ _mbg_swab32( &(_p)->offset ); \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ -} +} while ( 0 ) /** * @brief Current settings and capabilities of a HaveQuick input or output @@ -8867,12 +9323,13 @@ typedef struct } HAVEQUICK_INFO; #define _mbg_swab_havequick_info( _p ) \ +do \ { \ _mbg_swab_havequick_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_formats ); \ _mbg_swab16( &(_p)->supp_flags ); \ _mbg_swab16( &(_p)->reserved ); \ -} +} while ( 0 ) /** @@ -8925,17 +9382,18 @@ typedef struct } MBG_NUM_EVT_LOG_ENTRIES; #define _mbg_swab_mbg_num_evt_log_entries( _p ) \ +do \ { \ _mbg_swab32( &(_p)->used ); \ _mbg_swab32( &(_p)->max ); \ -} +} while ( 0 ) typedef uint16_t MBG_EVT_CODE; -#define _mbg_swab_evt_code( _p ) _mbg_swab16( _p ); +#define _mbg_swab_evt_code( _p ) _mbg_swab16( _p ) typedef uint16_t MBG_EVT_INFO; -#define _mbg_swab_evt_info( _p ) _mbg_swab16( _p ); +#define _mbg_swab_evt_info( _p ) _mbg_swab16( _p ) /** * @brief An event log entry @@ -8949,11 +9407,12 @@ typedef struct } MBG_EVT_LOG_ENTRY; #define _mbg_swab_mbg_evt_log_entry( _p ) \ +do \ { \ _mbg_swab32( &(_p)->time ); \ _mbg_swab_evt_code( &(_p)->code ); \ _mbg_swab_evt_info( &(_p)->info ); \ -} +} while ( 0 ) // ::MBG_EVT_LOG_ENTRY::code is a combination of some bits used for the ID, @@ -9116,11 +9575,12 @@ typedef struct } MBG_IMS_STATE; #define _mbg_swab_mbg_ims_state( _p ) \ +do \ { \ _mbg_swab16( &(_p)->num_sensors ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -9163,6 +9623,7 @@ typedef struct } MBG_IMS_SENSOR_STATE; #define _mbg_swab_mbg_ims_sensor_state( _p ) \ +do \ { \ _mbg_swab16( &(_p)->type ); \ _mbg_swab16( &(_p)->idx ); \ @@ -9170,7 +9631,7 @@ typedef struct _mbg_swab16( &(_p)->exp ); \ _mbg_swab16( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** @@ -9184,10 +9645,11 @@ typedef struct } MBG_IMS_SENSOR_STATE_IDX; #define _mbg_swab_mbg_ims_sensor_state_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_mbg_ims_sensor_state( &(_p)->state ); \ -} +} while ( 0 ) @@ -9249,14 +9711,15 @@ typedef struct } MBG_DAC_SPECS; #define _mbg_swab_mbg_dac_specs( _p ) \ +do \ { \ _mbg_swab32( &(_p)->dac_val_min ); \ - _mbg_swab32( &(-p)->dac_val_max ); \ - _mbg_swab32( &(_P)->u_min ); \ + _mbg_swab32( &(_p)->dac_val_max ); \ + _mbg_swab32( &(_p)->u_min ); \ _mbg_swab32( &(_p)->u_max ); \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ -} +} while ( 0 ) @@ -9278,13 +9741,15 @@ typedef struct } MBG_IMS_FDM_OUTPUT_STATE; #define _mbg_swab_mbg_ims_fdm_output_state( _p ) \ +do \ { \ _mbg_swab32( &(_p)->dac_val ); \ _mbg_swab32( &(_p)->mode ); \ _mbg_swab_mbg_dac_specs( &(_p)->dac_specs ); \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ -} +} while ( 0 ) + /** @@ -9298,10 +9763,11 @@ typedef struct } MBG_IMS_FDM_OUTPUT_STATE_IDX; #define _mbg_swab_mbg_ims_fdm_output_state_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_mbg_ims_fdm_output_state( &(_p)->state ); \ -} +} while ( 0 ) @@ -9318,10 +9784,11 @@ typedef struct } MBG_IMS_FDM_OUTPUT_SETTINGS; #define _mbg_swab_mbg_ims_fdm_output_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->mode ); \ _mbg_swab32( &(_p)->reserved ); \ -} +} while ( 0 ) /** @@ -9335,10 +9802,11 @@ typedef struct } MBG_IMS_FDM_OUTPUT_SETTINGS_IDX; #define _mbg_swab_mbg_ims_fdm_output_settings_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_mbg_ims_fdm_output_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -9354,11 +9822,12 @@ typedef struct } MBG_IMS_FDM_OUTPUT_INFO; #define _mbg_swab_mbg_ims_fdm_output_info( _p ) \ +do \ { \ _mbg_swab_mbg_ims_fdm_output_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_modes ); \ _mbg_swab_mbg_dac_specs( &(_p)->dac_specs ); \ -} +} while ( 0 ) @@ -9373,10 +9842,11 @@ typedef struct } MBG_IMS_FDM_OUTPUT_INFO_IDX; #define _mbg_swab_mbg_ims_fdm_output_info_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_mbg_ims_fdm_output_info( &(_p)->info ); \ -} +} while ( 0 ) @@ -9431,16 +9901,22 @@ typedef struct } MBG_IMS_FDM_LIMITS; #define _mbg_swab_mbg_ims_fdm_limits( _p ) \ +do \ { \ _mbg_swab8( &(_p)->n_outputs ); \ _mbg_swab8( &(_p)->reserved_0 ); \ _mbg_swab16( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->fd_min ); \ - _mbg_swab32( &(_p)->fd_max ); \ - _mbg_swab32( &(_p)->td_min ); \ - _mbg_swab32( &(_p)->td_max ); \ + \ + _mbg_swab32( &(_p)->fd_neg_limit ); \ + _mbg_swab32( &(_p)->fd_pos_limit ); \ + _mbg_swab32( &(_p)->fd_scale ); \ + \ + _mbg_swab32( &(_p)->td_neg_limit ); \ + _mbg_swab32( &(_p)->td_pos_limit ); \ + _mbg_swab32( &(_p)->td_scale ); \ + \ _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -9464,16 +9940,17 @@ typedef struct } MBG_IMS_FDM_STATE; -#define _mbg_swab_mbg_ims_fdm_state( _p ) \ -{ \ - _mbg_swab_mbg_gpio_freq( &(_p)->freq ); \ - _mbg_swab_nano_time_64( &(_p)->t_ref ); \ - _mbg_swab_nano_time_64( &(_p)->t_plt ); \ - _mbg_swab_nano_time_64( &(_p)->t_sync ); \ - _mbg_swab32( &(_p)->line_freq ); \ - _mbg_swab32( &(_p)->flags ); \ - _mbg_swab32( &(_p)->reserved ); \ -} +#define _mbg_swab_mbg_ims_fdm_state( _p ) \ +do \ +{ \ + _mbg_swab_mbg_gpio_freq( &(_p)->freq ); \ + _mbg_swab_nano_time_64( &(_p)->t_ref ); \ + _mbg_swab_nano_time_64( &(_p)->t_plt ); \ + _mbg_swab_nano_time_64( &(_p)->t_sync ); \ + _mbg_swab32( &(_p)->line_freq ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->reserved ); \ +} while ( 0 ) @@ -9567,14 +10044,15 @@ typedef struct } MBG_IMS_FDM_SETTINGS; #define _mbg_swab_mbg_ims_fdm_settings( _p ) \ +do \ { \ - _mbg_swab32( &(_p)->fd_min ); \ - _mbg_swab32( &(_p)->fd_max ); \ - _mbg_swab32( &(_p)->td_min ); \ - _mbg_swab32( &(_p)->td_max ); \ - _mbg_swab32( &(_p)->mode ); \ + _mbg_swab32( &(_p)->fd_neg_limit ); \ + _mbg_swab32( &(_p)->fd_pos_limit ); \ + _mbg_swab32( &(_p)->td_neg_limit ); \ + _mbg_swab32( &(_p)->td_pos_limit ); \ + _mbg_swab32( &(_p)->line_freq ); \ _mbg_swab32( &(_p)->reserved ); \ -} +} while ( 0 ) @@ -9616,12 +10094,13 @@ typedef struct } MBG_IMS_FDM_INFO; #define _mbg_swab_mbg_ims_fdm_info( _p ) \ +do \ { \ _mbg_swab_mbg_ims_fdm_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_line_freqs ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** @} defgroup group_ims */ @@ -9661,10 +10140,11 @@ typedef struct } GEN_IO_INFO; #define _mbg_swab_gen_io_info( _p ) \ +do \ { \ _mbg_swab_gen_io_info_type( &(_p)->type ); \ _mbg_swab16( &(_p)->num ); \ -} +} while ( 0 ) @@ -9744,6 +10224,19 @@ typedef struct } SCU_STAT_INFO; +#define _mbg_swab_scu_stat_info( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->hw_id ); \ + _mbg_swab32( &(_p)->fw_id ); \ + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab8( &(_p)->clk0_info ); \ + _mbg_swab8( &(_p)->clk1_info ); \ + _mbg_swab16( &(_p)->epld_status ); \ + _mbg_swab16( &(_p)->epld_control ); \ +} while ( 0 ) + + typedef struct { @@ -9753,6 +10246,15 @@ typedef struct } SCU_STAT_SETTINGS; +#define _mbg_swab_scu_stat_settings( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->epld_control_mask ); \ + _mbg_swab16( &(_p)->epld_control_value ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + /** * @brief Bit masks used to check the SCU EPLD status @@ -9761,17 +10263,22 @@ typedef struct */ enum SCU_STAT_MASKS { - MSK_EPLD_STAT_TS1 = 0x0001, ///< state of time sync signal clk_1 - MSK_EPLD_STAT_TS2 = 0x0002, ///< state of time sync signal clk_2 - MSK_EPLD_STAT_TL_ERROR = 0x0004, ///< state of time limit error input - MSK_EPLD_STAT_PSU1_OK = 0x0008, ///< state of power supply 1 monitoring input - MSK_EPLD_STAT_PSU2_OK = 0x0010, ///< state of power supply 2 monitoring input - MSK_EPLD_STAT_AUTO = 0x0020, ///< AUTOMATIC/REMOTE or MANUAL Mode - MSK_EPLD_STAT_SEL = 0x0040, ///< select bit for output MUX, ( clk_1 = 0 ) - MSK_EPLD_STAT_ENA = 0x0080, ///< enable Bit for output MUX, set if enabled - - MSK_EPLD_STAT_ACO = 0x4000, ///< Access control override bit - MSK_EPLD_STAT_WDOG_OK = 0x8000 ///< WDT_OK set to zero if watchdog expired + MSK_EPLD_STAT_TS1 = 0x0001, ///< state of time sync signal clk_1 + MSK_EPLD_STAT_TS2 = 0x0002, ///< state of time sync signal clk_2 + MSK_EPLD_STAT_TL_ERROR = 0x0004, ///< state of time limit error input + MSK_EPLD_STAT_PSU1_OK = 0x0008, ///< state of power supply 1 monitoring input + MSK_EPLD_STAT_PSU2_OK = 0x0010, ///< state of power supply 2 monitoring input + MSK_EPLD_STAT_AUTO = 0x0020, ///< AUTOMATIC/REMOTE or MANUAL Mode + MSK_EPLD_STAT_SEL = 0x0040, ///< select bit for output MUX, ( clk_1 = 0 ) + MSK_EPLD_STAT_ENA = 0x0080, ///< enable Bit for output MUX, set if enabled + MSK_EPLD_STAT_HAS_LAN = 0x0100, ///< indicates that the device has a network interface + MSK_EPLD_STAT_RESERVED0 = 0x0200, ///< reserved, DO NOT USE! + MSK_EPLD_STAT_RESERVED1 = 0x0400, ///< reserved, DO NOT USE! + MSK_EPLD_STAT_HAS_4_PSUS = 0x0800, ///< indicates 4 power supplies instead of 2 + MSK_EPLD_STAT_PSU3_OK = 0x1000, ///< state of power supply 3 monitoring input + MSK_EPLD_STAT_PSU4_OK = 0x2000, ///< state of power supply 4 monitoring input + MSK_EPLD_STAT_ACO = 0x4000, ///< Access control override bit + MSK_EPLD_STAT_WDOG_OK = 0x8000 ///< WDT_OK set to zero if watchdog expired }; @@ -9845,7 +10352,7 @@ enum RECEIVER_MODES typedef int16_t DAC_VAL; #define _mbg_swab_dac_val( _p ) \ - _mbg_swab16( _p ); + _mbg_swab16( _p ) @@ -9863,13 +10370,14 @@ typedef struct } STAT_INFO; #define _mbg_swab_stat_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->mode ); \ _mbg_swab16( &(_p)->good_svs ); \ _mbg_swab16( &(_p)->svs_in_view ); \ _mbg_swab_dac_val( &(_p)->dac_val ); \ _mbg_swab_dac_val( &(_p)->dac_cal ); \ -} +} while ( 0 ) #define OSC_DAC_RANGE 4096UL @@ -9891,6 +10399,7 @@ enum MBG_GNSS_TYPES GNSS_TYPE_GALILEO, ///< GALILEO, Europe GNSS_TYPE_WAAS, ///< WAAS, Wide Area Augmentation System GNSS_TYPE_EGNOS, ///< EGNOS, European Geostationary Navigation Overlay Service + GNSS_TYPE_QZSS, ///< QZSS, Quasi Zenit Satellite System N_GNSS_TYPES ///< Number of defined codes }; @@ -9907,7 +10416,8 @@ enum MBG_GNSS_TYPE_MASKS MBG_GNSS_TYPE_MSK_BEIDOU = ( 1UL << GNSS_TYPE_BEIDOU ), ///< see ::GNSS_TYPE_BEIDOU MBG_GNSS_TYPE_MSK_GALILEO = ( 1UL << GNSS_TYPE_GALILEO ), ///< see ::GNSS_TYPE_GALILEO MBG_GNSS_TYPE_MSK_WAAS = ( 1UL << GNSS_TYPE_WAAS ), ///< see ::GNSS_TYPE_WAAS - MBG_GNSS_TYPE_MSK_EGNOS = ( 1UL << GNSS_TYPE_EGNOS ) ///< see ::GNSS_TYPE_EGNOS + MBG_GNSS_TYPE_MSK_EGNOS = ( 1UL << GNSS_TYPE_EGNOS ), ///< see ::GNSS_TYPE_EGNOS + MBG_GNSS_TYPE_MSK_QZSS = ( 1UL << GNSS_TYPE_QZSS ) ///< see ::GNSS_TYPE_QZSS }; @@ -9923,7 +10433,8 @@ enum MBG_GNSS_TYPE_MASKS "BEIDOU", \ "GALILEO", \ "WAAS", \ - "EGNOS" \ + "EGNOS", \ + "QZSS" \ } @@ -9938,63 +10449,69 @@ typedef struct { uint32_t gnss_set; ///< bit mask of currently used GNSS systems, see ::MBG_GNSS_TYPE_MASKS uint8_t prio[N_GNSS_MODE_PRIO]; ///< see ::MBG_GNSS_TYPES, unused fields set to 0xFF, idx 0 is highest prio - uint32_t flags; ///< unused, currently always 0 // ### TODO or see ::MBG_GNSS_MODE_FLAG_MASKS ? + uint32_t flags; ///< unused, currently always 0 (should be named MBG_GNSS_MODE_SETTINGS_FLAG_MASKS) } MBG_GNSS_MODE_SETTINGS; #define _mbg_swab_mbg_gnss_mode_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->gnss_set ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) typedef struct { - MBG_GNSS_MODE_SETTINGS settings; ///< current GNSS mode settings - uint32_t supp_gnss_types; ///< bit masks of supported GNSS types, see ::MBG_GNSS_TYPE_MASKS - uint32_t flags; ///< indicates which flags are supported for settings::flags, see ::MBG_GNSS_MODE_FLAG_MASKS + MBG_GNSS_MODE_SETTINGS settings; ///< Current GNSS mode settings + uint32_t supp_gnss_types; ///< Bit masks of supported GNSS types, see ::MBG_GNSS_TYPE_MASKS + uint16_t flags; ///< See ::MBG_GNSS_MODE_INFO_FLAG_MASKS + uint16_t n_sv_status; ///< Number of ::GNSS_SV_STATUS_IDX structures that can be read (only if ::MBG_GNSS_FLAG_MSK_HAS_SV_STATUS) } MBG_GNSS_MODE_INFO; #define _mbg_swab_mbg_gnss_mode_info( _p ) \ +do \ { \ _mbg_swab_mbg_gnss_mode_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_gnss_types ); \ - _mbg_swab32( &(_p)->flags ); \ -} + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab16( &(_p)->n_sv_status ); \ +} while ( 0 ) + /** - * @brief Flag bits used to define ::MBG_GNSS_MODE_FLAG_MASKS + * @brief Flag bits used to define ::MBG_GNSS_MODE_INFO_FLAG_MASKS * - * @see ::MBG_GNSS_MODE_FLAG_MASKS + * @see ::MBG_GNSS_MODE_INFO_FLAG_MASKS */ -enum MBG_GNSS_MODE_FLAG_BITS +enum MBG_GNSS_MODE_INFO_FLAG_BITS { - MBG_GNSS_FLAG_EXCLUSIVE, ///< (read only) only one of the supported GNSS systems can be used at the same time - MBG_GNSS_FLAG_HAS_PRIORITY, ///< (read only) priority can be configured using the ::MBG_GNSS_MODE_SETTINGS::prio field - MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER, ///< (read only) the ::GNSS_SAT_INFO_IDX structure is supported by the device + MBG_GNSS_FLAG_EXCLUSIVE, ///< Only one of the supported GNSS systems can be used at the same time + MBG_GNSS_FLAG_HAS_PRIORITY, ///< Priority can be configured using the ::MBG_GNSS_MODE_SETTINGS::prio field + MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER, ///< The ::GNSS_SAT_INFO_IDX structure is supported by the device + MBG_GNSS_FLAG_HAS_SV_STATUS, ///< The ::GNSS_SV_STATUS_IDX structure is supported by the device N_MBG_GNSS_FLAGS }; /** - * @brief Flag masks used with MBG_GNSS_MODE_INFO::flags + * @brief Flag masks used with ::MBG_GNSS_MODE_INFO::flags * - * @see ::MBG_GNSS_MODE_FLAG_BITS + * @see ::MBG_GNSS_MODE_INFO_FLAG_BITS */ -enum MBG_GNSS_MODE_FLAG_MASKS +enum MBG_GNSS_MODE_INFO_FLAG_MASKS { - MBG_GNSS_FLAG_MSK_EXCLUSIVE = ( 1UL << MBG_GNSS_FLAG_EXCLUSIVE ), ///< see ::MBG_GNSS_FLAG_EXCLUSIVE - MBG_GNSS_FLAG_MSK_HAS_PRIORITY = ( 1UL << MBG_GNSS_FLAG_HAS_PRIORITY ), ///< see ::MBG_GNSS_FLAG_HAS_PRIORITY - MBG_GNSS_FLAG_MSK_SAT_INFO_IDX_SUPP_SER = ( 1UL << MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER ) ///< see ::MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER + MBG_GNSS_FLAG_MSK_EXCLUSIVE = ( 1UL << MBG_GNSS_FLAG_EXCLUSIVE ), ///< see ::MBG_GNSS_FLAG_EXCLUSIVE + MBG_GNSS_FLAG_MSK_HAS_PRIORITY = ( 1UL << MBG_GNSS_FLAG_HAS_PRIORITY ), ///< see ::MBG_GNSS_FLAG_HAS_PRIORITY + MBG_GNSS_FLAG_MSK_SAT_INFO_IDX_SUPP_SER = ( 1UL << MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER ), ///< see ::MBG_GNSS_FLAG_SAT_INFO_IDX_SUPP_SER + MBG_GNSS_FLAG_MSK_HAS_SV_STATUS = ( 1UL << MBG_GNSS_FLAG_HAS_SV_STATUS ) ///< see ::MBG_GNSS_FLAG_HAS_SV_STATUS }; - #define MAX_USED_SATS 32 /** @@ -10011,10 +10528,11 @@ typedef struct } GNSS_SAT_INFO; #define _mbg_swab_gnss_sat_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->good_svs ); \ _mbg_swab16( &(_p)->svs_in_view ); \ -} +} while ( 0 ) @@ -10036,14 +10554,206 @@ typedef struct } GNSS_SAT_INFO_IDX; -#define _mbg_swab_gnss_sat_info_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ +#define _mbg_swab_gnss_sat_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ _mbg_swab_gnss_sat_info( &(_p)->gnss_sat_info ); \ -} +} while ( 0 ) + + + +/** + * @defgroup group_gnss_sv_status GNSS Satellite Status + * + * @note These structures and associated types are only supported by a device + * if ::MBG_GNSS_FLAG_MSK_HAS_SV_STATUS is set // ::FIXME + * + * @{ */ + +/** + * @brief Detailed GNSS satellite status + * + * @see ::GNSS_SV_STATUS_IDX + * @see @ref group_gnss_sv_stat_flags + */ +typedef struct +{ + uint8_t gnss_type; ///< GNSS type as enumerated in ::MBG_GNSS_TYPES + uint8_t svno; ///< Satellite number, see ::TODO + uint8_t cn_ratio; ///< Carrier-to-noise ratio [dbHz] + int8_t elev; ///< Elevation [deg], range: -90..90 deg + + int16_t azim; ///< Azimuth [deg], range: 0..360 deg + int16_t pr_residual; ///< Pseudo range residual [m] + + uint32_t stat_flags; ///< see @ref group_gnss_sv_stat_flags + +} GNSS_SV_STATUS; + +#define _mbg_swab_gnss_sv_status( _p ) \ +do \ +{ \ + _mbg_swab8( &(_p)->gnss_type ); \ + _mbg_swab8( &(_p)->svno ); \ + _mbg_swab8( &(_p)->cn_ratio ); \ + _mbg_swab8( &(_p)->elev ); \ + _mbg_swab16( &(_p)->azim ); \ + _mbg_swab16( &(_p)->pr_residual ); \ + _mbg_swab32( &(_p)->stat_flags ); \ +} while ( 0 ) + + + +/** + * @defgroup group_gnss_sv_stat_flags GNSS status flags encoding + * + * Used with ::GNSS_SV_STATUS::stat_flags. + * + * @{ */ + +/// Bits 0 to 2 are a 3 bit quality indicator, see ::GNSS_SV_STAT_QUALITY_INDS +#define _gnss_sv_stat_quality_ind( __stat_flags ) \ + ( (uint8_t) ( (__stat_flags) & 0x00000007UL ) ) + +/// Bit 3 is set if the SV is actually used for navigation +#define _gnss_sv_stat_sv_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00000008UL ) != 0 ) + +/// Bits 4 and 5 are a 2 bit health code, see ::GNSS_SV_STAT_HEALTH_CODES +#define _gnss_sv_stat_health_code( __stat_flags ) \ + ( (uint8_t) ( ( (__stat_flags) & 0x00000030UL ) >> 4 ) ) + +/// Bit 6 is set if differential correction is available for this SV +#define _gnss_sv_stat_diff_corr( __stat_flags ) \ + ( ( (__stat_flags) & 0x00000040UL ) != 0 ) + +/// Bit 7 is set if carrier smoothed pseudorange is used for this SV +#define _gnss_sv_stat_smoothed( __stat_flags ) \ + ( ( (__stat_flags) & 0x00000080UL ) != 0 ) + +/// Bits 8 to 10 are a 3 bit code indicating the orbit source, see ::GNSS_SV_STAT_ORBIT_SOURCES +#define _gnss_sv_stat_orbit_src( __stat_flags ) \ + ( (uint8_t) ( ( (__stat_flags) & 0x00000700UL ) >> 8 ) ) + +/// Bit 11 is set if ephemeris parameters are available for this SV +#define _gnss_sv_stat_eph_avail( __stat_flags ) \ + ( ( (__stat_flags) & 0x00000800UL ) != 0 ) + +/// Bit 12 is set if almanac parameters are available for this SV +#define _gnss_sv_stat_alm_avail( __stat_flags ) \ + ( ( (__stat_flags) & 0x00001000UL ) != 0 ) + +/// Bit 13 is set if AssistNow Offline data is available for this SV +#define _gnss_sv_stat_ano_avail( __stat_flags ) \ + ( ( (__stat_flags) & 0x00002000UL ) != 0 ) + +/// Bit 14 is set if AssistNow Autonomous data is available for this SV +#define _gnss_sv_stat_aop_avail( __stat_flags ) \ + ( ( (__stat_flags) & 0x00004000UL ) != 0 ) + +/// Bit 15 is reserved. + +/// Bit 16 is set if SBAS corrections have been used for this SV +#define _gnss_sv_stat_sbas_corr_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00010000UL ) != 0 ) + +/// Bit 17 is set if RTCM corrections have been used for this SV +#define _gnss_sv_stat_rtcm_corr_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00020000UL ) != 0 ) + +/// Bits 18 and 19 are reserved. + +/// Bit 20 is set if pseudorange corrections have been used for this SV +#define _gnss_sv_stat_pr_corr_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00100000UL ) != 0 ) + +/// Bit 21 is set if carrier range corrections have been used for this SV +#define _gnss_sv_stat_cr_corr_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00200000UL ) != 0 ) + +/// Bit 22 is set if range rate (doppler) corrections have been used for this SV +#define _gnss_sv_stat_do_corr_used( __stat_flags ) \ + ( ( (__stat_flags) & 0x00400000UL ) != 0 ) + +/// Bits 23 to 31 are reserved. + +/** @} defgroup group_gnss_sv_stat_flags */ + + +/** + * @brief Quality indicators used with ::GNSS_SV_STATUS::stat_flags + * + * @see ::_gnss_sv_stat_quality_ind + */ +enum GNSS_SV_STAT_QUALITY_INDS +{ + GNSS_SV_STAT_NO_SIGNAL, ///< No signal + GNSS_SV_STAT_SEARCHING, ///< Searching signal + GNSS_SV_STAT_ACQUIRED, ///< Signal acquired + GNSS_SV_STAT_UNUSABLE, ///< Signal detected but unusable + GNSS_SV_STAT_CODE_LOCKED, ///< Code locked and time synchronized + GNSS_SV_STAT_CODE_CARRIER_LOCKED, ///< Code and carrier locked, and time synchronized + GNSS_SV_STAT_CODE_CARRIER_LOCKED_2, ///< Code and carrier locked, and time synchronized + GNSS_SV_STAT_CODE_CARRIER_LOCKED_3 ///< Code and carrier locked, and time synchronized +}; + + +/** + * @brief Health indicators used with ::GNSS_SV_STATUS::stat_flags + * + * @see ::_gnss_sv_stat_health_code + */ +enum GNSS_SV_STAT_HEALTH_CODES +{ + GNSS_SV_STAT_HEALTH_UNKNOWN, ///< Health status unknown + GNSS_SV_STAT_HEALTH_OK, ///< Healthy + GNSS_SV_STAT_HEALTH_NOT_OK ///< Unhealthy +}; + + +/** + * @brief Orbit source codes used with ::GNSS_SV_STATUS::stat_flags + * + * @see ::_gnss_sv_stat_orbit_src + */ +enum GNSS_SV_STAT_ORBIT_SOURCES +{ + GNSS_SV_STAT_ORBIT_SRC_UNKNOWN, ///< Orbit source unknown + GNSS_SV_STAT_ORBIT_SRC_EPH, ///< Ephemeris data used for orbit + GNSS_SV_STAT_ORBIT_SRC_ALM, ///< Almanac data used for orbit + GNSS_SV_STAT_ORBIT_SRC_ASSN_OFFL, ///< AssistNow Offline orbit is used + GNSS_SV_STAT_ORBIT_SRC_ASSN_AUTO, ///< AssistNow Autonomous orbit is used + GNSS_SV_STAT_ORBIT_OTHER_1, ///< Other orbit information is used + GNSS_SV_STAT_ORBIT_OTHER_2, ///< Other orbit information is used + GNSS_SV_STAT_ORBIT_OTHER_3 ///< Other orbit information is used +}; +/** + * @brief Detailed GNSS satellite status, plus index + * + * @see ::GNSS_SV_STATUS + */ +typedef struct +{ + uint32_t idx; ///< Range 0..::MBG_GNSS_MODE_INFO::n_sv_status-1 + GNSS_SV_STATUS gnss_sv_status; + +} GNSS_SV_STATUS_IDX; + +#define _mbg_swab_gnss_sv_status_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_gnss_sv_status( &(_p)->gnss_sv_status ); \ +} while ( 0 ) + + +/** @} defgroup group_gnss_sv_status */ + + #ifndef _IDENT_DEFINED @@ -10058,11 +10768,14 @@ typedef struct #endif #define _mbg_swab_ident( _p ) \ +do \ { \ int i; \ for ( i = 0; i < 4; i++ ) \ _mbg_swab32( &(_p)->lw[i] ); \ -} +} while ( 0 ) + + /** * @brief A data type used to configure the length of an antenna cable [m] @@ -10093,7 +10806,7 @@ typedef struct } MBG_MAC_ADDR; #define _mbg_swab_mbg_mac_addr( _p ) \ - _nop_macro_fnc(); + _nop_macro_fnc() @@ -10103,7 +10816,7 @@ typedef struct typedef uint32_t IP4_ADDR; #define _mbg_swab_ip4_addr( _p ) \ - _mbg_swab32( _p ); + _mbg_swab32( _p ) @@ -10122,6 +10835,8 @@ typedef struct } IP6_ADDR; +#define _mbg_swab_ip6_addr( _p ) _nop_macro_fnc() + /** @@ -10207,9 +10922,13 @@ enum IPV6_MULTICAST_SCOPES */ typedef char MBG_HOSTNAME[MBG_MAX_HOSTNAME_LEN]; ///< ASCIIZ format +#define _mbg_swab_mbg_host_name( _p ) _nop_macro_fnc() + + /** @} defgroup group_net_basic_types */ + /** * @brief The maximum length of an interface name * @@ -10223,10 +10942,13 @@ typedef char MBG_HOSTNAME[MBG_MAX_HOSTNAME_LEN]; ///< ASCIIZ format /** * @brief Hardware type for identification of physical interfaces * - * Use own definition for use under Windows, - * original ARPHRD_ETHER comes from linux/if_arp.h */ -#define MBG_ARPHRD_ETHER 1 +enum MBG_NET_HW_TYPES +{ + MBG_NET_HW_TYPE_UNKNOWN, + MBG_ARPHRD_ETHER, + N_MBG_NET_HW_TYPES +}; /** @@ -10241,7 +10963,7 @@ typedef char MBG_HOSTNAME[MBG_MAX_HOSTNAME_LEN]; ///< ASCIIZ format */ typedef uint16_t MBG_VLAN_CFG; -#define _mbg_swab_mbg_vlan_cfg( _p ) _mbg_swab16( _p ); +#define _mbg_swab_mbg_vlan_cfg( _p ) _mbg_swab16( _p ) #define VLAN_ID_BITS 12 ///< number of bits to hold the ID #define N_VLAN_ID ( 1 << VLAN_ID_BITS ) ///< number of ID values @@ -10297,6 +11019,7 @@ typedef struct } IP4_SETTINGS; #define _mbg_swab_ip4_settings( _p ) \ +do \ { \ _mbg_swab_ip4_addr( &(_p)->ip_addr ); \ _mbg_swab_ip4_addr( &(_p)->netmask ); \ @@ -10304,7 +11027,7 @@ typedef struct _mbg_swab_ip4_addr( &(_p)->gateway ); \ _mbg_swab16( &(_p)->flags ); \ _mbg_swab_mbg_vlan_cfg( &(_p)->vlan_cfg ); \ -} +} while ( 0 ) @@ -10333,13 +11056,14 @@ typedef struct } LAN_IF_INFO; #define _mbg_swab_lan_if_info( _p ) \ +do \ { \ _mbg_swab16( &(_p)->type ); \ _mbg_swab16( &(_p)->ver_code ); \ _mbg_swab32( &(_p)->rsvd_0 ); \ _mbg_swab16( &(_p)->flags ); \ _mbg_swab16( &(_p)->rsvd_1 ); \ -} +} while ( 0 ) /** @@ -10434,6 +11158,7 @@ enum MBG_IP_ADDR_TYPES enum MBG_NET_GLB_CFG_INFO_FLAGS { MBG_NET_GLB_SUPP_STAGE_2, ///< Supports commands which have been added in stage 2 + MBG_NET_GLB_SUPP_BONDING, ///< Supports bonding N_MBG_NET_GLB_INFO_FLAGS }; @@ -10445,7 +11170,8 @@ enum MBG_NET_GLB_CFG_INFO_FLAGS */ enum MBG_NET_GLB_CFG_INFO_MASKS { - MBG_NET_GLB_SUPP_STAGE_2_MASK = (1UL << MBG_NET_GLB_SUPP_STAGE_2) ///< see ::MBG_NET_GLB_SUPP_STAGE_2 + MBG_NET_GLB_SUPP_STAGE_2_MASK = (1UL << MBG_NET_GLB_SUPP_STAGE_2), ///< see ::MBG_NET_GLB_SUPP_STAGE_2 + MBG_NET_GLB_SUPP_BONDING_MASK = (1UL << MBG_NET_GLB_SUPP_BONDING) ///< see ::MBG_NET_GLB_SUPP_BONDING }; @@ -10585,7 +11311,7 @@ enum MBG_NET_INTF_LINK_PORT_TYPE_MASKS /** * @brief Initializers for network interface link port type long strings * - * @see ::MBG_NET_INTF_LINK_PORT_TYPE + * @see ::MBG_NET_INTF_LINK_PORT_TYPES */ #define MBG_NET_INTF_LINK_PORT_TYPE_LONG_STRS \ { \ @@ -10602,7 +11328,7 @@ enum MBG_NET_INTF_LINK_PORT_TYPE_MASKS /** * @brief Initializers for network interface link port type short strings * - * @see ::MBG_NET_INTF_LINK_PORT_TYPE + * @see ::MBG_NET_INTF_LINK_PORT_TYPES */ #define MBG_NET_INTF_LINK_PORT_TYPE_SHORT_STRS \ { \ @@ -10701,6 +11427,8 @@ enum MBG_NET_INTF_LINK_OPTS MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN, MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT, MBG_NET_INTF_LINK_OPT_CAN_AUTONEG, + MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS, + MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS, N_MBG_NET_INTF_LINK_OPTS }; @@ -10713,10 +11441,12 @@ enum MBG_NET_INTF_LINK_OPTS */ enum MBG_NET_INTF_LINK_OPT_MASKS { - MBG_NET_INTF_LINK_OPT_MASK_CAN_SET_MAC = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SET_MAC ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SET_MAC - MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_IN = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN - MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_OUT = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT - MBG_NET_INTF_LINK_OPT_MASK_CAN_AUTONEG = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_AUTONEG ) ///< see ::MBG_NET_INTF_LINK_OPT_CAN_AUTONEG + MBG_NET_INTF_LINK_OPT_MASK_CAN_SET_MAC = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SET_MAC ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SET_MAC + MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_IN = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_IN + MBG_NET_INTF_LINK_OPT_MASK_CAN_SYNCE_OUT = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_SYNCE_OUT + MBG_NET_INTF_LINK_OPT_MASK_CAN_AUTONEG = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_AUTONEG ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_AUTONEG + MBG_NET_INTF_LINK_OPT_MASK_CAN_NTP_HW_TS = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS ), ///< see ::MBG_NET_INTF_LINK_OPT_CAN_NTP_HW_TS + MBG_NET_INTF_LINK_OPT_MASK_CAN_PTP_HW_TS = ( 1UL << MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS ) ///< see ::MBG_NET_INTF_LINK_OPT_CAN_PTP_HW_TS }; @@ -10891,10 +11621,11 @@ typedef struct } MBG_NET_GLB_CFG_SETTINGS; -#define _mbg_swab_net_glb_cfg_settings( _p ) \ -{ \ - _mbg_swab32( &(_p)->flags ); \ -} +#define _mbg_swab_net_glb_cfg_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) /** @@ -10917,6 +11648,7 @@ typedef struct } MBG_NET_GLB_CFG_INFO; #define _mbg_swab_net_glb_cfg_info( _p ) \ +do \ { \ _mbg_swab_net_glb_cfg_settings( &(_p)->glb_settings ); \ _mbg_swab16( &(_p)->n_supp_intf_link ); \ @@ -10929,7 +11661,7 @@ typedef struct _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->feat_flags ); \ _mbg_swab32( &(_p)->flags_2 ); \ -} +} while ( 0 ) @@ -10950,10 +11682,25 @@ typedef struct } MBG_IP_ADDR; -#define _mbg_swab_ip_addr( _p ) \ -{ \ - _mbg_swab16( &(_p)->reserved_2 ); \ -} +#define _mbg_swab_ip_addr( _p ) \ +do \ +{ \ + _mbg_swab8( &(_p)->type ); \ + _mbg_swab8( &(_p)->reserved_1 ); \ + _mbg_swab16( &(_p)->reserved_2 ); \ + \ + switch ( (_p)->type ) \ + { \ + case MBG_IP_ADDR_TYPE_IP4: \ + _mbg_swab_ip4_addr( &(_p)->u_addr.ip4_addr ); \ + break; \ + \ + case MBG_IP_ADDR_TYPE_IP6: \ + _mbg_swab_ip6_addr( &(_p)->u_addr.ip6_addr ); \ + break; \ + } \ + \ +} while ( 0 ) @@ -10967,11 +11714,12 @@ typedef struct } MBG_IP_ADDR_IDX; -#define _mbg_swab_ip_addr_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_ip_addr( &(_p)->addr ); \ -} +#define _mbg_swab_ip_addr_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_ip_addr( &(_p)->addr ); \ +} while ( 0 ) /** @@ -10987,12 +11735,14 @@ typedef struct } MBG_IP_ADDR_PORT; -#define _mbg_swab_ip_addr_port( _p ) \ -{ \ - _mbg_swab_ip_addr( &(_p)->addr ); \ - _mbg_swab16( &(_p)->port ); \ - _mbg_swab16( &(_p)->flags ); \ -} +#define _mbg_swab_ip_addr_port( _p ) \ +do \ +{ \ + _mbg_swab_ip_addr( &(_p)->addr ); \ + _mbg_swab16( &(_p)->port ); \ + _mbg_swab16( &(_p)->flags ); \ +} while ( 0 ) + /** @@ -11004,6 +11754,12 @@ typedef struct } MBG_NET_NAME; +#define _mbg_swab_net_name( _p ) \ +do \ +{ \ + _mbg_swab_mbg_host_name( &(_p)->name ); \ +} while ( 0 ) + /** @@ -11016,10 +11772,13 @@ typedef struct } MBG_NET_NAME_IDX; -#define _mbg_swab_net_name_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ -} +#define _mbg_swab_net_name_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_name( &(_p)->net_name ); \ +} while ( 0 ) + /** @@ -11040,7 +11799,7 @@ typedef struct uint32_t flags; ///< Reserved, currently 0 uint32_t states; ///< see @ref MBG_NET_INTF_LINK_STATE_MASKS - uint32_t hw_type; ///< Hardware type of interface (see linux/if_arp.h, i.e. ARPHRD_ETHER) ::TODO + uint32_t hw_type; ///< Hardware type of interface (see ::MBG_NET_HW_TYPES) uint32_t mtu; ///< Max. packet size in bytes uint32_t txqlen; ///< Transmission queue length (number of packets) uint32_t speed; ///< Link speed in MBit/s @@ -11067,6 +11826,7 @@ typedef struct } MBG_NET_INTF_LINK_SETTINGS; #define _mbg_swab_net_intf_link_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->if_index ); \ _mbg_swab32( &(_p)->common_if_index ); \ @@ -11082,7 +11842,7 @@ typedef struct _mbg_swab16( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ -} +} while ( 0 ) @@ -11096,11 +11856,12 @@ typedef struct } MBG_NET_INTF_LINK_SETTINGS_IDX; -#define _mbg_swab_net_intf_link_settings_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_link_settings( &(_p)->settings ); \ -} +#define _mbg_swab_net_intf_link_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_link_settings( &(_p)->settings ); \ +} while ( 0 ) @@ -11124,6 +11885,7 @@ typedef struct } MBG_NET_INTF_LINK_INFO; #define _mbg_swab_net_intf_link_info( _p ) \ +do \ { \ _mbg_swab_net_intf_link_settings( &(_p)->link_settings ); \ _mbg_swab32( &(_p)->supp_flags ); \ @@ -11137,7 +11899,7 @@ typedef struct _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ _mbg_swab32( &(_p)->reserved_4 ); \ -} +} while ( 0 ) @@ -11151,11 +11913,12 @@ typedef struct } MBG_NET_INTF_LINK_INFO_IDX; -#define _mbg_swab_net_intf_link_info_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_link_info( &(_p)->info ); \ -} +#define _mbg_swab_net_intf_link_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_link_info( &(_p)->info ); \ +} while ( 0 ) /** @@ -11185,18 +11948,19 @@ typedef struct } MBG_NET_INTF_ADDR_SETTINGS; -#define _mbg_swab_net_intf_addr_settings( _p ) \ -{ \ - _mbg_swab32( &(_p)->addr_index ); \ - _mbg_swab32( &(_p)->ass_if_index ); \ - _mbg_swab32( &(_p)->flags ); \ - _mbg_swab_ip_addr( &(_p)->ip ); \ - _mbg_swab_ip_addr( &(_p)->broadcast ); \ - _mbg_swab16( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->reserved_3 ); \ - _mbg_swab32( &(_p)->reserved_4 ); \ - _mbg_swab32( &(_p)->reserved_5 ); \ -} +#define _mbg_swab_net_intf_addr_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->addr_index ); \ + _mbg_swab32( &(_p)->ass_if_index ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab_ip_addr( &(_p)->ip ); \ + _mbg_swab_ip_addr( &(_p)->broadcast ); \ + _mbg_swab16( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ + _mbg_swab32( &(_p)->reserved_4 ); \ + _mbg_swab32( &(_p)->reserved_5 ); \ +} while ( 0 ) /** @@ -11209,11 +11973,12 @@ typedef struct } MBG_NET_INTF_ADDR_SETTINGS_IDX; -#define _mbg_swab_net_intf_addr_settings_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_addr_settings( &(_p)->settings ); \ -} +#define _mbg_swab_net_intf_addr_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_addr_settings( &(_p)->settings ); \ +} while ( 0 ) /** @@ -11228,13 +11993,14 @@ typedef struct } MBG_NET_INTF_ADDR_INFO; -#define _mbg_swab_net_intf_addr_info( _p ) \ -{ \ - _mbg_swab_net_intf_addr_settings( &(_p)->addr_settings ); \ - _mbg_swab32( &(_p)->supp_flags ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +#define _mbg_swab_net_intf_addr_info( _p ) \ +do \ +{ \ + _mbg_swab_net_intf_addr_settings( &(_p)->addr_settings ); \ + _mbg_swab32( &(_p)->supp_flags ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ +} while ( 0 ) /** @@ -11247,11 +12013,12 @@ typedef struct } MBG_NET_INTF_ADDR_INFO_IDX; -#define _mbg_swab_net_intf_addr_info_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_addr_info( &(_p)->info ); \ -} +#define _mbg_swab_net_intf_addr_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_addr_info( &(_p)->info ); \ +} while ( 0 ) /** @@ -11281,17 +12048,18 @@ typedef struct } MBG_NET_INTF_ROUTE_SETTINGS; -#define _mbg_swab_net_intf_route_settings( _p ) \ -{ \ - _mbg_swab16( &(_p)->reserved_2 ); \ - _mbg_swab_ip_addr( &(_p)->gateway ); \ - _mbg_swab_ip_addr( &(_p)->dst ); \ - _mbg_swab32( &(_p)->ass_if_index ); \ - _mbg_swab32( &(_p)->ass_addr_index ); \ - _mbg_swab32( &(_p)->reserved_3 ); \ - _mbg_swab32( &(_p)->reserved_4 ); \ - _mbg_swab32( &(_p)->reserved_5 ); \ -} +#define _mbg_swab_net_intf_route_settings( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->reserved_2 ); \ + _mbg_swab_ip_addr( &(_p)->gateway ); \ + _mbg_swab_ip_addr( &(_p)->dst ); \ + _mbg_swab32( &(_p)->ass_if_index ); \ + _mbg_swab32( &(_p)->ass_addr_index ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ + _mbg_swab32( &(_p)->reserved_4 ); \ + _mbg_swab32( &(_p)->reserved_5 ); \ +} while ( 0 ) /** @@ -11304,11 +12072,12 @@ typedef struct } MBG_NET_INTF_ROUTE_SETTINGS_IDX; -#define _mbg_swab_net_intf_route_settings_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_route_settings( &(_p)->settings ); \ -} +#define _mbg_swab_net_intf_route_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_route_settings( &(_p)->settings ); \ +} while ( 0 ) /** @@ -11324,13 +12093,14 @@ typedef struct } MBG_NET_INTF_ROUTE_INFO; #define _mbg_swab_net_intf_route_info( _p ) \ +do \ { \ _mbg_swab_net_intf_route_settings( &(_p)->route_settings ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ _mbg_swab32( &(_p)->reserved_4 ); \ -} +} while ( 0 ) /** @@ -11343,11 +12113,12 @@ typedef struct } MBG_NET_INTF_ROUTE_INFO_IDX; -#define _mbg_swab_net_intf_route_info_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_net_intf_route_info( &(_p)->info ); \ -} +#define _mbg_swab_net_intf_route_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_net_intf_route_info( &(_p)->info ); \ +} while ( 0 ) /** @} defgroup group_ext_net_cfg */ @@ -11467,13 +12238,14 @@ typedef struct } MBG_UCAP_NET_GLB_SETTINGS; -#define _mbg_swab_ucap_net_glb_settings( _p ) \ -{ \ - _mbg_swab32( &(_p)->num_recvs ); \ - _mbg_swab32( &(_p)->reserved_0 ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +#define _mbg_swab_ucap_net_glb_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->num_recvs ); \ + _mbg_swab32( &(_p)->reserved_0 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ +} while ( 0 ) @@ -11498,6 +12270,7 @@ typedef struct #define _mbg_swab_ucap_net_glb_info( _p ) \ +do \ { \ _mbg_swab_ucap_net_glb_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->n_supp_recvs ); \ @@ -11505,8 +12278,8 @@ typedef struct _mbg_swab32( &(_p)->supp_protos ); \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) @@ -11529,13 +12302,14 @@ typedef struct #define _mbg_swab_ucap_net_recv_settings( _p ) \ +do \ { \ _mbg_swab16( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ _mbg_swab32( &(_p)->ucaps ); \ _mbg_swab_ip_addr_port( &(_p)->addr ); \ -} +} while ( 0 ) @@ -11557,10 +12331,11 @@ typedef struct #define _mbg_swab_ucap_net_recv_settings_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_ucap_net_recv_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -11580,13 +12355,14 @@ typedef struct #define _mbg_swab_ucap_net_recv_info( _p ) \ +do \ { \ _mbg_swab_ucap_net_recv_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ -} +} while ( 0 ) @@ -11607,11 +12383,12 @@ typedef struct } MBG_UCAP_NET_RECV_INFO_IDX; -#define _mbg_swab_ucap_net_recv_info_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_ucap_net_recv_info( &(_p)->info ); \ -} +#define _mbg_swab_ucap_net_recv_info_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_ucap_net_recv_info( &(_p)->info ); \ +} while ( 0 ) /** @} defgroup ext_ucap */ @@ -11927,6 +12704,8 @@ enum PTP_ROLES PTP_ROLE_NTP_SERVER, ///< NTP Unicast Server PTP_ROLE_NTP_CLIENT, ///< NTP Unicast Client PTP_ROLE_TIME_MONITOR, ///< Time Monitor for external PTP or NTP devices + PTP_ROLE_V1_MASTER, ///< PTPv1 Master in Multicast mode + PTP_ROLE_V1_SLAVE, ///< PTPv1 Slave in Multicast mode N_PTP_ROLES ///< number of defined roles }; @@ -11955,7 +12734,9 @@ enum PTP_ROLE_MASKS PTP_ROLE_MSK_BOTH_MASTER = ( 1UL << PTP_ROLE_BOTH_MASTER ), ///< see ::PTP_ROLE_BOTH_MASTER PTP_ROLE_MSK_NTP_SERVER = ( 1UL << PTP_ROLE_NTP_SERVER ), ///< see ::PTP_ROLE_NTP_SERVER PTP_ROLE_MSK_NTP_CLIENT = ( 1UL << PTP_ROLE_NTP_CLIENT ), ///< see ::PTP_ROLE_NTP_CLIENT - PTP_ROLE_MSK_TIME_MONITOR = ( 1UL << PTP_ROLE_TIME_MONITOR ) ///< see ::PTP_ROLE_TIME_MONITOR + PTP_ROLE_MSK_TIME_MONITOR = ( 1UL << PTP_ROLE_TIME_MONITOR ), ///< see ::PTP_ROLE_TIME_MONITOR + PTP_ROLE_MSK_V1_MASTER = ( 1UL << PTP_ROLE_V1_MASTER ), ///< see ::PTP_ROLE_MULTICAST_MASTER + PTP_ROLE_MSK_V1_SLAVE = ( 1UL << PTP_ROLE_V1_SLAVE ) ///< see ::PTP_ROLE_UNICAST_SLAVE }; @@ -11985,7 +12766,9 @@ enum PTP_ROLE_MASKS "UC+MC Master", \ "NTP Server", \ "NTP Client", \ - "Time Monitor" \ + "Time Monitor", \ + "V1 Master", \ + "V1 Slave" \ } @@ -12005,7 +12788,9 @@ enum PTP_ROLE_MASKS "UMM", \ "NSV", \ "NCL", \ - "MON" \ + "MON", \ + "V1M", \ + "V1S" \ } @@ -12037,6 +12822,70 @@ typedef uint16_t PTP_PORT_ID; /** + * @brief A PTP port identity + * + * @note For further information, see IEEE 1588-2008, chapter 5.3.5 + * + * @see ::PTP_CLOCK_ID + * @see ::PTP_PORT_ID + */ +typedef struct +{ + PTP_CLOCK_ID clock_identity; + PTP_PORT_ID port_number; + +} PTP_PORT_IDENTITY; + + +#define _mbg_swab_ptp_port_identity( _p ) \ +{ \ + _mbg_swab_ptp_clock_id( &(_p)->clock_identity ); \ + _mbg_swab_ptp_port_id( &(_p)->port_number ); \ +} + + +/** + * @brief PTP clock quality + * + * @note For further information, see IEEE 1588-2008, chapter 5.3.7 + */ +typedef struct +{ + uint8_t clock_class; ///< PTP clock class representing the current sync status + int8_t clock_accuracy; ///< see ::PTP_CLOCK_ACCURACIES + uint16_t log_variance; ///< PTP offset scaled log variance representing the time stability + +} PTP_CLOCK_QUALITY; + + +#define _mbg_swab_ptp_clock_quality( _p ) \ +{ \ + _mbg_swab8( &(_p)->clock_class ); \ + _mbg_swab8( &(_p)->clock_accuracy ); \ + _mbg_swab16( &(_p)->log_variance ); \ +} + + +/** + * @brief PTP time interval + * + * @note For further information, see IEEE 1588-2008, chapter 5.3.2 + * + */ +typedef struct +{ + int64_t scaled_nanoseconds; + +} PTP_TIME_INTERVAL; + + +#define _mbg_swab_ptp_time_interval( _p ) \ +{ \ + _mbg_swab64( &(_p)->scaled_nanoseconds ); \ +} + + +/** * @brief An enumeration of time scales used with PTP * * @note The standard time scale used by PTP is TAI, which is a linear time scale. @@ -12133,6 +12982,7 @@ typedef struct } PTP_STATE; #define _mbg_swab_ptp_state( _p ) \ +do \ { \ _mbg_swab16( &(_p)->nw_prot ); \ _mbg_swab32( &(_p)->flags ); \ @@ -12147,7 +12997,7 @@ typedef struct _mbg_swab16( &(_p)->utc_offset ); \ _mbg_swab_dac_val( &(_p)->osc_dac_cal ); \ _mbg_swab16( &(_p)->reserved_3 ); \ -} +} while ( 0 ) /** @@ -12221,17 +13071,18 @@ typedef struct } PTP_CFG_SETTINGS; -#define _mbg_swab_ptp_cfg_settings( _p ) \ -{ \ - _mbg_swab16( &(_p)->nw_prot ); \ - _mbg_swab16( &(_p)->sync_intv ); \ - _mbg_swab16( &(_p)->ann_intv ); \ - _mbg_swab16( &(_p)->delay_req_intv ); \ - _mbg_swab32( &(_p)->upper_bound ); \ - _mbg_swab32( &(_p)->lower_bound ); \ - _mbg_swab32( &(_p)->reserved ); \ - _mbg_swab32( &(_p)->flags ); \ -} +#define _mbg_swab_ptp_cfg_settings( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->nw_prot ); \ + _mbg_swab16( &(_p)->sync_intv ); \ + _mbg_swab16( &(_p)->ann_intv ); \ + _mbg_swab16( &(_p)->delay_req_intv ); \ + _mbg_swab32( &(_p)->upper_bound ); \ + _mbg_swab32( &(_p)->lower_bound ); \ + _mbg_swab32( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) @@ -12273,6 +13124,7 @@ typedef struct } PTP_CFG_INFO; #define _mbg_swab_ptp_cfg_info( _p ) \ +do \ { \ _mbg_swab_ptp_cfg_settings( &(_p)->settings ); \ _mbg_swab16( &(_p)->reserved_2 ); \ @@ -12286,7 +13138,7 @@ typedef struct _mbg_swab32( &(_p)->supp_nw_prot ); \ _mbg_swab32( &(_p)->supp_opt_ext ); \ _mbg_swab32( &(_p)->supp_delay_mech ); \ -} +} while ( 0 ) @@ -12341,6 +13193,11 @@ enum PTP_CFG_FLAGS PTP_CFG_CAN_BE_TIME_MONITOR, ///< [R/-] can be Monitoring device for external PTP or NTP devices //### TODO Shouldn't this be an XFEATURE flag? PTP_CFG_HAS_STATISTICS, ///< [R/-] ::MBG_PTP_STATISTICS_INFO can be queried + PTP_CFG_CAN_BE_V1_MASTER, ///< [R/-] supports PTPv1 MASTER role + PTP_CFG_CAN_BE_V1_SLAVE, ///< [R/-] supports PTPv1 SLAVE role + PTP_CFG_HAS_V2_COMMON_DATASETS, ///< [R/-] PTPv2 common dataset structures (see IEEE1588-2008, chapter 8.2) can be queried + PTP_CFG_HAS_V1_COMMON_DATASETS, ///< [R/-] PTPv1 common dataset structures can be queried + N_PTP_CFG_FLAGS ///< the number of defined flags }; @@ -12383,6 +13240,11 @@ enum PTP_CFG_FLAGS #define PTP_CFG_MSK_CAN_BE_TIME_MONITOR ( 1UL << PTP_CFG_CAN_BE_TIME_MONITOR ) ///< see ::PTP_CFG_CAN_BE_TIME_MONITOR #define PTP_CFG_MSK_HAS_STATISTICS ( 1UL << PTP_CFG_HAS_STATISTICS ) ///< see ::PTP_CFG_HAS_STATISTICS +#define PTP_CFG_MSK_CAN_BE_V1_MASTER ( 1UL << PTP_CFG_CAN_BE_V1_MASTER ) ///< see ::PTP_CFG_CAN_BE_V1_MASTER +#define PTP_CFG_MSK_CAN_BE_V1_SLAVE ( 1UL << PTP_CFG_CAN_BE_V1_SLAVE ) ///< see ::PTP_CFG_CAN_BE_V1_SLAVE +#define PTP_CFG_MSK_HAS_V2_COMMON_DATASETS ( 1UL << PTP_CFG_HAS_V2_COMMON_DATASETS ) ///< see ::PTP_CFG_HAS_V2_COMMON_DATASETS +#define PTP_CFG_MSK_HAS_V1_COMMON_DATASETS ( 1UL << PTP_CFG_HAS_V1_COMMON_DATASETS ) ///< see ::PTP_CFG_HAS_V1_COMMON_DATASETS + /** @} defgroup group_PTP_CFG_FLAG_MASKS */ @@ -12483,6 +13345,7 @@ enum PTP_PRESETS PTP_PRESETS_8021AS, ///< IEEE 802.1AS -like profile, only if ::PTP_MSK_OPT_EXT_8021AS is set PTP_PRESETS_6185093, ///< IEC/IEEE FDIS 61850-9-3, only if ::PTP_MSK_OPT_EXT_6185093 is set PTP_PRESETS_TELECOM_PTS, ///< ITU-T G.8275.2 profile extension, only if ::PTP_MSK_OPT_EXT_TELECOM_PTS is set + PTP_PRESETS_DOCSIS_31, ///< only if ::PTP_MSK_OPT_EXT_TELECOM_PHASE is set N_PTP_PRESETS ///< number of supported presets }; @@ -12504,7 +13367,8 @@ enum PTP_PRESETS_MASKS PTP_MSK_PRESETS_AES67 = ( 1UL << PTP_PRESETS_AES67 ), ///< see ::PTP_PRESETS_AES67 PTP_MSK_PRESETS_8021AS = ( 1UL << PTP_PRESETS_8021AS ), ///< see ::PTP_PRESETS_8021AS PTP_MSK_PRESETS_6185093 = ( 1UL << PTP_PRESETS_6185093), ///< see ::PTP_PRESETS_6185093 - PTP_MSK_PRESETS_TELECOM_PTS = ( 1UL << PTP_PRESETS_TELECOM_PTS) ///< see ::PTP_PRESETS_TELECOM_PTS + PTP_MSK_PRESETS_TELECOM_PTS = ( 1UL << PTP_PRESETS_TELECOM_PTS), ///< see ::PTP_PRESETS_TELECOM_PTS + PTP_MSK_PRESETS_DOCSIS_31 = ( 1UL << PTP_PRESETS_DOCSIS_31) ///< see ::PTP_PRESETS_DOCSIS_31 }; @@ -12525,7 +13389,8 @@ enum PTP_PRESETS_MASKS "AES67 Media Profile", \ "IEEE 802.1AS", \ "Utility IEC 61850-9-3", \ - "Telecom ITU-T G.8275.2" \ + "Telecom ITU-T G.8275.2", \ + "DOCSIS 3.1" \ } @@ -12547,6 +13412,7 @@ typedef struct } PTP_POWER_PROFILE_CFG; #define _mbg_swab_ptp_power_profile_cfg( _p ) \ +do \ { \ _mbg_swab32( &(_p)->network_incaccuracy ); \ _mbg_swab8( &(_p)->grandmaster_id ); \ @@ -12554,7 +13420,7 @@ typedef struct _mbg_swab16( &(_p)->reserved_2 ); \ _mbg_swab_tzdl( &(_p)->tzdl ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -12717,13 +13583,14 @@ typedef struct } PTP_TELECOMG8275_PROFILE_CFG; #define _mbg_swab_ptp_telecom8275_profile_cfg( _p ) \ +do \ { \ _mbg_swab8( &(_p)->use_alternate_multicast_mac_address ); \ _mbg_swab8( &(_p)->reserved_1 ); \ _mbg_swab8( &(_p)->reserved_2 ); \ _mbg_swab8( &(_p)->reserved_3 ); \ _mbg_swab32( &(_p)->reserved_4 ); \ -} +} while ( 0 ) @@ -12938,7 +13805,7 @@ enum SDH_NETWORK_OPTIONS /** - * @brief Flag masks used with ::MBG_SYNC_E_INFO::supp_sdh_network_opts + * @brief Flag masks used with MBG_SYNC_E_INFO::supp_sdh_network_opts ::FIXME * * @see ::SDH_NETWORK_OPTIONS */ @@ -12953,7 +13820,7 @@ enum SDH_NETWORK_OPTION_MASKS /** * @brief Name strings for SDH network options * - * @see ::SDH_NETWORK_OPTION + * @see ::SDH_NETWORK_OPTIONS */ #define SDH_NETWORK_OPTION_STRS \ { \ @@ -12983,7 +13850,7 @@ enum GBIT_LINK_COPPER_MODES /** - * @brief Flag masks used with ::MBG_SYNC_E_INFO::supp_gbit_link_copper_modes + * @brief Flag masks used with MBG_SYNC_E_INFO::supp_gbit_link_copper_modes ::FIXME * * @see ::GBIT_LINK_COPPER_MODES */ @@ -13027,6 +13894,12 @@ enum GBIT_LINK_STATUS "AUTO (SFP LINK UP)", \ } +#else // !defined( _PRELIMINARY_CODE ), dummy declarations + +typedef int PTP_SMPTE_PROFILE_CFG; +typedef int PTP_TELECOMG8275_PROFILE_CFG; +typedef int ITU_SSM_CODE; + #endif // defined( _PRELIMINARY_CODE ) @@ -13050,6 +13923,7 @@ typedef struct } PTP_UC_MASTER_CFG_LIMITS; #define _mbg_swab_ptp_uc_master_cfg_limits( _p ) \ +do \ { \ _mbg_swab16( &(_p)->n_supp_master ); \ _mbg_swab16( &(_p)->sync_intv_min ); \ @@ -13061,7 +13935,7 @@ typedef struct _mbg_swab16( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->supp_flags ); \ _mbg_swab32( &(_p)->reserved_1 ); \ -} +} while ( 0 ) @@ -13093,6 +13967,7 @@ typedef struct } PTP_UC_MASTER_SETTINGS; #define _mbg_swab_ptp_uc_master_settings( _p ) \ +do \ { \ _mbg_swab_ptp_clock_id( &(_p)->gm_clock_id ); \ _mbg_swab_ptp_port_id( &(_p)->gm_port_id ); \ @@ -13104,7 +13979,7 @@ typedef struct _mbg_swab16( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -13138,10 +14013,11 @@ typedef struct } PTP_UC_MASTER_SETTINGS_IDX; #define _mbg_swab_ptp_uc_master_settings_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_ptp_uc_master_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -13160,11 +14036,12 @@ typedef struct } PTP_UC_MASTER_INFO; #define _mbg_swab_ptp_uc_master_info( _p ) \ +do \ { \ _mbg_swab_ptp_uc_master_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -13189,15 +14066,14 @@ typedef struct } PTP_UC_MASTER_INFO_IDX; #define _mbg_swab_ptp_uc_master_info_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_ptp_uc_master_info( &(_p)->info ); \ -} +} while ( 0 ) -#if defined( _PRELIMINARY_CODE ) - typedef struct { uint32_t counter_cfg; @@ -13281,11 +14157,611 @@ typedef struct } MBG_PTP_STATISTICS_STATUS; -#else // !defined( _PRELIMINARY_CODE ) - typedef int MBG_PTP_STATISTICS_STATUS; -#endif // !defined( _PRELIMINARY_CODE ) +enum PTP_V1_COMM_IDS +{ + V1_PTP_CLOSED, + V1_PTP_ETHER, + /* reserved */ + V1_PTP_FFBUS = 4, + V1_PTP_PROFIBUS, + V1_PTP_LON, + V1_PTP_DNET, + V1_PTP_SDS, + V1_PTP_CONTROLNET, + V1_PTP_CANOPEN, + /* reserved */ + V1_PTP_IEEE1394 = 243, + V1_PTP_IEEE802_11A, + V1_PTP_IEEE_WIRELESS, + V1_PTP_INFINIBAND, + V1_PTP_BLUETOOTH, + V1_PTP_IEEE802_15_1, + V1_PTP_IEEE1451_3, + V1_PTP_IEEE1451_5, + V1_PTP_USB, + V1_PTP_ISA, + V1_PTP_PCI, + V1_PTP_VXI, + V1_PTP_DEFAULT +}; + + + +#define PTP_CODE_STRING_LENGTH 4 +#define PTP_SUBDOMAIN_NAME_LENGTH 16 + + +/** + * @brief PTPv1 UUID structure used in ::MBG_PTP_V1_DEFAULT_DATASET + * + * @see ::MBG_PTP_V1_DEFAULT_DATASET + */ +typedef struct +{ + uint8_t communication_technology; + uint8_t reserved_1; + uint16_t reserved_2; + PTP_CLOCK_ID clock_uuid; + PTP_PORT_ID port_id; + uint16_t reserved_3; +} PTP_V1_UUID; + + +#define _mbg_swab_ptp_v1_uuid( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->reserved_2 ); \ + _mbg_swab_ptp_clock_id( &(_p)->clock_uuid ); \ + _mbg_swab_ptp_port_id( &(_p)->port_id ); \ + _mbg_swab16( &(_p)->reserved_3 ); \ +} while ( 0 ) + + + +/** + * @brief PTPv1 default dataset flags + * + * @see ::PTP_V1_DEFAULT_DATASET_FLAGS_MASKS + */ +enum PTP_V1_DEFAULT_DATASET_FLAGS +{ + V1_DFLT_CLK_FOLLOWUP_CAPABLE, + V1_DFLT_PREFERRED, + V1_DFLT_INITIALIZABLE, + V1_DFLT_EXT_TIMING, + V1_DFLT_IS_BC +}; + + + +/** + * @brief PTPv1 default dataset flag masks used with ::MBG_PTP_V1_DEFAULT_DATASET::flags + * + * @see ::PTP_V1_DEFAULT_DATASET_FLAGS + */ +enum PTP_V1_DEFAULT_DATASET_FLAGS_MASKS +{ + V1_DFLT_MSK_CLK_FOLLOWUP_CAPABLE = ( 1UL << V1_DFLT_CLK_FOLLOWUP_CAPABLE ), ///< see ::V1_DFLT_CLK_FOLLOWUP_CAPABLE + V1_DFLT_MSK_PREFERRED = ( 1UL << V1_DFLT_PREFERRED ), ///< see ::V1_DFLT_PREFERRED + V1_DFLT_MSK_INITIALIZABLE = ( 1UL << V1_DFLT_INITIALIZABLE ), ///< see ::V1_DFLT_INITIALIZABLE + V1_DFLT_MSK_EXT_TIMING = ( 1UL << V1_DFLT_EXT_TIMING), ///< see ::V1_DFLT_EXT_TIMING + V1_DFLT_MSK_IS_BC = ( 1UL << V1_DFLT_IS_BC ) ///< see ::V1_DFLT_IS_BC +}; + + + +/** + * @brief PTPv1 default dataset containing global information about the device + * + * @see ::PTP_V1_UUID + */ +typedef struct { + PTP_V1_UUID uuid; + uint8_t clock_stratum; + uint8_t clock_identifier[PTP_CODE_STRING_LENGTH]; + uint16_t clock_variance; + int8_t sync_interval; + uint8_t subdomain_name[PTP_SUBDOMAIN_NAME_LENGTH]; + uint16_t number_ports; + uint16_t number_foreign_records; + uint32_t flags; +} MBG_PTP_V1_DEFAULT_DATASET; + + +#define _mbg_swab_ptp_v1_default_dataset( _p ) \ +do \ +{ \ + _mbg_swab_ptp_v1_uuid( &(_p)->uuid ); \ + _mbg_swab16( &(_p)->clock_variance ); \ + _mbg_swab16( &(_p)->number_ports ); \ + _mbg_swab16( &(_p)->number_foreign_records ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + + +/** + * @brief PTPv1 current dataset containing information about the synchronization status of the device + * + * @see ::NANO_TIME + */ +typedef struct +{ + uint16_t steps_removed; + uint16_t reserved_1; + NANO_TIME offset_from_master; + NANO_TIME one_way_delay; +} MBG_PTP_V1_CURRENT_DATASET; + + +#define _mbg_swab_ptp_v1_current_dataset( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->steps_removed ); \ + _mbg_swab16( &(_p)->reserved_1 ); \ + _mbg_swab_nano_time( &(_p)->offset_from_master ); \ + _mbg_swab_nano_time( &(_p)->one_way_delay ); \ +} while ( 0 ) + + + +/** + * @brief PTPv1 parent dataset flags + * + * @see ::PTP_V1_PARENT_DATASET_FLAGS_MASKS + */ +enum PTP_V1_PARENT_DATASET_FLAGS +{ + V1_PARENT_FOLLOWUP_CAPABLE, + V1_PARENT_EXT_TIMING, + V1_PARENT_STATS, + V1_PARENT_UTC_REASONABLE, + V1_PARENT_GM_PREFERRED, + V1_PARENT_GM_IS_BC +}; + + + +/** + * @brief PTPv1 parent dataset flag masks used with ::MBG_PTP_V1_PARENT_DATASET::flags + * + * @see ::PTP_V1_PARENT_DATASET_FLAGS + */ +enum PTP_V1_PARENT_DATASET_FLAGS_MASKS +{ + V1_PARENT_MSK_FOLLOWUP_CAPABLE = ( 1UL << V1_PARENT_FOLLOWUP_CAPABLE ), ///< see ::V1_PARENT_FOLLOWUP_CAPABLE + V1_PARENT_MSK_EXT_TIMING = ( 1UL << V1_PARENT_EXT_TIMING ), ///< see ::V1_PARENT_EXT_TIMING + V1_PARENT_MSK_STATS = ( 1UL << V1_PARENT_STATS ), ///< see ::V1_PARENT_STATS + V1_PARENT_MSK_UTC_REASONABLE = ( 1UL << V1_PARENT_UTC_REASONABLE ), ///< see ::V1_PARENT_UTC_REASONABLE + V1_PARENT_MSK_GM_PREFERRED = ( 1UL << V1_PARENT_GM_PREFERRED ), ///< see ::V1_PARENT_GM_PREFERRED + V1_PARENT_MSK_GM_IS_BC = ( 1UL << V1_PARENT_GM_IS_BC ) ///< see ::V1_PARENT_GM_IS_BC +}; + + + +/** + * @brief PTPv1 parent dataset containing information about the master (parent) of the device + * + * @see ::PTP_V1_UUID + */ +typedef struct +{ + PTP_V1_UUID uuid; + uint16_t parent_last_sync_sequence_number; + int16_t parent_variance; + int16_t observed_variance; + uint16_t reserved_1; + int32_t observed_drift; + PTP_V1_UUID grandmaster_uuid; + uint8_t grandmaster_stratum; + uint8_t grandmaster_identifier[PTP_CODE_STRING_LENGTH]; + int16_t grandmaster_variance; + uint16_t grandmaster_sequence_number; + uint16_t reserved_2; + uint32_t flags; ///< see ::PTP_V1_PARENT_DATASET_FLAGS_MASKS + +} MBG_PTP_V1_PARENT_DATASET; + + +#define _mbg_swab_ptp_v1_parent_dataset( _p ) \ +do \ +{ \ + _mbg_swab_ptp_v1_uuid( &(_p)->uuid ); \ + _mbg_swab16( &(_p)->parent_last_sync_sequence_number ); \ + _mbg_swab16( &(_p)->parent_variance ); \ + _mbg_swab16( &(_p)->observed_variance ); \ + _mbg_swab16( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->observed_drift ); \ + _mbg_swab_ptp_v1_uuid( &(_p)->grandmaster_uuid ); \ + _mbg_swab16( &(_p)->grandmaster_variance ); \ + _mbg_swab16( &(_p)->grandmaster_sequence_number ); \ + _mbg_swab16( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + + +/** + * @brief PTPv1 time drop dataset flags + * + * @see ::PTP_V1_TIME_PROP_DATASET_FLAGS_MASKS + */ +enum PTP_V1_TIME_PROP_DATASET_DATASET_FLAGS +{ + V1_TPROP_LEAP_59, + V1_TPROP_LEAP_61 +}; + + + +/** + * @brief PTPv1 time drop dataset flag masks used with ::MBG_PTP_V1_TIME_PROPERTIES_DATASET::flags + * + * @see ::PTP_V1_TIME_PROP_DATASET_DATASET_FLAGS + */ +enum PTP_V1_TIME_PROP_DATASET_FLAGS_MASKS +{ + V1_TPROP_MSK_LEAP_59 = ( 1UL << V1_TPROP_LEAP_59 ), ///< see ::V1_TPROP_LEAP_59 + V1_TPROP_MSK_LEAP_61 = ( 1UL << V1_TPROP_LEAP_61 ) ///< see ::V1_TPROP_LEAP_61 +}; + + + +/** + * @brief PTPv1 time drop dataset + * + */ +typedef struct +{ + int16_t current_utc_offset; + uint16_t epoch_number; + uint32_t flags; ///< see ::PTP_V1_TIME_PROP_DATASET_FLAGS_MASKS + +} MBG_PTP_V1_TIME_PROPERTIES_DATASET; + + +#define _mbg_swab_ptp_v1_time_properties_dataset( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->current_utc_offset ); \ + _mbg_swab16( &(_p)->epoch_number ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + + +/** + * @brief PTPv1 port dataset flags + * + * @see ::PTP_V1_PORT_DATASET_FLAGS_MASKS + */ +enum PTP_V1_PORT_DATASET_DATASET_FLAGS +{ + V1_PORT_DATASET_BURST_ENB, +}; + + + +/** + * @brief PTPv1 port dataset flag masks used with ::MBG_PTP_V1_PORT_DATASET::flags + * + * @see ::PTP_V1_PORT_DATASET_DATASET_FLAGS + */ +enum PTP_V1_PORT_DATASET_FLAGS_MASKS +{ + V1_PORT_DATASET_MSK_BURST_ENB = ( 1UL << V1_PORT_DATASET_BURST_ENB ), ///< see ::V1_PORT_DATASET_BURST_ENB +}; + + + +/** + * @brief PTPv1 port dataset containing information about the appropriate port of the device + * + * @see ::PTP_V1_UUID + */ +typedef struct +{ + uint8_t port_state; + uint8_t reserved_1; + uint16_t last_sync_event_sequence_number; + uint16_t last_general_event_sequence_number; + uint16_t reserved_2; + uint32_t subdomain_address; + uint16_t event_port_address; + uint16_t general_port_address; + PTP_V1_UUID uuid; + uint32_t flags; +} MBG_PTP_V1_PORT_DATASET; + + +#define _mbg_swab_ptp_v1_port_dataset( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->last_sync_event_sequence_number ); \ + _mbg_swab16( &(_p)->last_general_event_sequence_number ); \ + _mbg_swab16( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->subdomain_address ); \ + _mbg_swab16( &(_p)->event_port_address ); \ + _mbg_swab16( &(_p)->general_port_address ); \ + _mbg_swab_ptp_v1_uuid( &(_p)->uuid ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + + +/** + * @brief Index structure for PTPv1 port dataset + * + * @note Port dataset with index 0..::MBG_PTP_V1_DEFAULT_DATASET::number_ports - 1 can be queried from a device + * + * @see ::MBG_PTP_V1_PORT_DATASET + */ +typedef struct +{ + uint16_t idx; ///< Index of the port dataset, 0..::MBG_PTP_V1_DEFAULT_DATASET::number_ports - 1 + MBG_PTP_V1_PORT_DATASET port_dataset; ///< see ::MBG_PTP_V1_PORT_DATASET + +} MBG_PTP_V1_PORT_DATASET_IDX; + + +#define _mbg_swab_ptp_v1_port_dataset_idx( _p ) \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_ptp_v1_port_dataset( &(_p)->port_dataset ); \ +} + + +/** + * @brief Flags structure for the PTPv2 default dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.1 and 15.5.3.3.1 + * + * @see ::MBG_PTP_V2_DEFAULT_DATASET + */ +typedef struct +{ + uint8_t two_step : 1; ///< indicates, whether the clock is a two-step clock + uint8_t slave_only : 1; ///< indicates, whether the clock is a slave-only clock + uint8_t reserved : 6; ///< reserved, currently always 0 + +} MBG_PTP_V2_DEFAULT_DATASET_FLAGS; + +#define _mbg_swab_ptp_v2_default_dataset_flags( _p ) \ + _nop_macro_fnc() + + +/** + * @brief PTPv2 default dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.1 and 15.5.3.3.1 + * + * @see ::MBG_PTP_V2_DEFAULT_DATASET_FLAGS + * @see ::PTP_CLOCK_QUALITY + * @see ::PTP_CLOCK_ID + */ +typedef struct +{ + MBG_PTP_V2_DEFAULT_DATASET_FLAGS flags; ///< flags field, see ::MBG_PTP_V2_DEFAULT_DATASET_FLAGS + uint8_t reserved_1; ///< reserved, currently always 0 + uint16_t number_ports; ///< number of PTP ports on the device + uint8_t priority_1; ///< priority 1 attribute for the local clock + PTP_CLOCK_QUALITY clock_quality; ///< quality of the local clock, see ::PTP_CLOCK_QUALITY + uint8_t priority_2; ///< priority 2 attribute for the local clock + PTP_CLOCK_ID clock_identity; ///< identity of the local clock, see ::PTP_CLOCK_ID + uint8_t domain_number; ///< domain attribute of the local clock + uint8_t reserved_2; ///< reserved, currently always 0 + +} MBG_PTP_V2_DEFAULT_DATASET; + + +#define _mbg_swab_ptp_v2_default_dataset( _p ) \ +{ \ + _mbg_swab_ptp_v2_default_dataset_flags( &(_p)->flags ); \ + _mbg_swab8( &(_p)->reserved_1 ); \ + _mbg_swab16( &(_p)->number_ports ); \ + _mbg_swab8( &(_p)->priority_1 ); \ + _mbg_swab_ptp_clock_quality( &(_p)->clock_quality ); \ + _mbg_swab8( &(_p)->priority_2 ); \ + _mbg_swab_ptp_clock_id( &(_p)->clock_identity ); \ + _mbg_swab8( &(_p)->domain_number ); \ + _mbg_swab8( &(_p)->reserved_2 ); \ +} + + +/** + * @brief PTPv2 current dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.2 and 15.5.3.4.1 + * + * @see ::PTP_TIME_INTERVAL + */ +typedef struct +{ + uint16_t steps_removed; ///< number of communication paths between local clock and grandmaster + PTP_TIME_INTERVAL offset_from_master; ///< current time difference between master and slave, see ::PTP_TIME_INTERVAL + PTP_TIME_INTERVAL mean_path_delay; ///< current mean propagation time between master and slave, see ::PTP_TIME_INTERVAL + +} MBG_PTP_V2_CURRENT_DATASET; + + +#define _mbg_swab_ptp_v2_current_dataset( _p ) \ +{ \ + _mbg_swab16( &(_p)->steps_removed ); \ + _mbg_swab_ptp_time_interval( &(_p)->offset_from_master ); \ + _mbg_swab_ptp_time_interval( &(_p)->mean_path_delay ); \ +} + + +/** + * @brief Flags structure for the PTPv2 parent dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.3.3 and 15.5.3.5.1.2 + * + * @see ::MBG_PTP_V2_PARENT_DATASET + */ +typedef struct +{ + uint8_t parent_stats : 1; ///< indicates whether the variance and change rate values are valid + uint8_t reserved : 7; ///< reserved, currently always 0 + +} MBG_PTP_V2_PARENT_DATASET_FLAGS; + +#define _mbg_swab_ptp_v2_parent_dataset_flags( _p )\ + _nop_macro_fnc() + + + +/** + * @brief PTPv2 parent dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.3 and 15.5.3.5.1 + * + * @see ::PTP_PORT_IDENTITY + * @see ::MBG_PTP_V2_PARENT_DATASET_FLAGS + * @see ::PTP_CLOCK_QUALITY + * @see ::PTP_CLOCK_ID + */ +typedef struct +{ + PTP_PORT_IDENTITY parent_port_identity; ///< Identity of the master port, that issues the sync messages, see ::PTP_PORT_IDENTITY + MBG_PTP_V2_PARENT_DATASET_FLAGS flags; ///< Flags field, see ::MBG_PTP_V2_PARENT_DATASET_FLAGS + uint8_t reserved; ///< Reserved, currently always 0 + uint16_t parent_log_variance; ///< Estimate of the parent clock's PTP variance, only valid if + ///< ::MBG_PTP_V2_PARENT_DATASET_FLAGS::parent_stats is set in ::MBG_PTP_V2_PARENT_DATASET::flags + int32_t parent_phase_change_rate; ///< Estimate of the parent clock's phase change rate, only valid if + ///< ::MBG_PTP_V2_PARENT_DATASET_FLAGS::parent_stats is set in ::MBG_PTP_V2_PARENT_DATASET::flags + uint8_t grandmaster_priority_1; ///< Priority 1 attribute of the grandmaster clock + PTP_CLOCK_QUALITY grandmaster_clock_quality; ///< Quality of the grandmaster clock, see ::PTP_CLOCK_QUALITY + uint8_t grandmaster_priority_2; ///< Priority 2 attribute of the grandmaster clock + PTP_CLOCK_ID grandmaster_identity; ///< Identity of the grandmaster clock, see ::PTP_CLOCK_ID + +} MBG_PTP_V2_PARENT_DATASET; + + +#define _mbg_swab_ptp_v2_parent_dataset( _p ) \ +{ \ + _mbg_swab_ptp_port_identity( &(_p)->parent_port_identity ); \ + _mbg_swab_ptp_v2_parent_dataset_flags( &(_p)->flags ); \ + _mbg_swab8( &(_p)->reserved ); \ + _mbg_swab16( &(_p)->parent_log_variance ); \ + _mbg_swab32( &(_p)->parent_phase_change_rate ); \ + _mbg_swab8( &(_p)->grandmaster_priority_1 ); \ + _mbg_swab_ptp_clock_quality( &(_p)->grandmaster_clock_quality ); \ + _mbg_swab8( &(_p)->grandmaster_priority_2 ); \ + _mbg_swab_ptp_clock_id( &(_p)->grandmaster_identity ); \ +} + + +/** + * @brief Flags structure for the PTPv2 time properties dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.4 and 15.5.3.6.1 + * + * @see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET + */ +typedef struct +{ + uint8_t leap_61 : 1; ///< set, if the last minute of the current UTC day containts 61 seconds + uint8_t leap_59 : 1; ///< set, if the last minute of the current UTC day containts 59 seconds + uint8_t utc_offset_valid : 1; ///< set, if the current UTC offset is known to be correct + uint8_t ptp_timescale : 1; ///< set, if the timescale of the grandmaster clock is PTP + uint8_t time_traceable : 1; ///< set, if timescale and utc offset are traceable to a primary reference + uint8_t frequency_traceable : 1; ///< set, if the frequency determining the timescale is traceable to a primary reference + uint8_t reserved : 2; ///< reserved, currently always 0 + +} MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS; + + +#define _mbg_swab_ptp_v2_time_properties_dataset_flags( _p ) \ + _nop_macro_fnc() + + +/** + * @brief PTPv2 time properties dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.4 and 15.5.3.6.1 + * + * @see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS + */ +typedef struct +{ + int16_t current_utc_offset; ///< offset between TAI and UTC in seconds + MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS flags; ///< flags field, see ::MBG_PTP_V2_TIME_PROPERTIES_DATASET_FLAGS + uint8_t time_source; ///< source of time used by the grandmaster clock, see ::PTP_TIME_SOURCES + +} MBG_PTP_V2_TIME_PROPERTIES_DATASET; + + +#define _mbg_swab_ptp_v2_time_properties_dataset( _p ) \ +{ \ + _mbg_swab16( &(_p)->current_utc_offset ); \ + _mbg_swab_ptp_v2_time_properties_dataset_flags( &(_p)->flags ); \ + _mbg_swab8( &(_p)->time_source ); \ +} + + +/** + * @brief PTPv2 port dataset + * + * @note For further information, see IEEE 1588-2008, chapters 8.2.5 and 15.5.3.7.1 + * + * @see ::PTP_PORT_IDENTITY + * @see ::PTP_TIME_INTERVAL + * @see ::MBG_PTP_V2_PORT_DATASET_IDX + */ +typedef struct +{ + PTP_PORT_IDENTITY port_identity; ///< identity of the local port, see ::PTP_PORT_IDENTITY + uint8_t port_state; ///< state of the protocol engine associated with this port, see ::PTP_PORT_STATES + int8_t log_min_delay_req_interval; ///< minimum delay request interval for this port + PTP_TIME_INTERVAL peer_mean_path_delay; ///< estimate of the current one-way propagation delay on the link, only valid if P2P is used, see ::PTP_TIME_INTERVAL + int8_t log_announce_interval; ///< announce interval to be used by this port + uint8_t announce_receipt_timeout; ///< shall be an integral multiple of ::MBG_PTP_V2_PORT_DATASET::log_announce_interval + int8_t log_sync_interval; ///< mean sync interval to be used for multicast messages + uint8_t delay_mechanism; ///< propagation delay measuring option, see ::PTP_DELAY_MECHS + int8_t log_min_pdelay_req_interval; ///< minimum peer delay request interval for this port + uint8_t version_number : 4; ///< PTP version in use on the port + uint8_t reserved : 4; ///< reserved, currently always 0 + +} MBG_PTP_V2_PORT_DATASET; + + +#define _mbg_swab_ptp_v2_port_dataset( _p ) \ +{ \ + _mbg_swab_ptp_port_identity( &(_p)->port_identity ); \ + _mbg_swab8( &(_p)->port_state ); \ + _mbg_swab8( &(_p)->log_min_delay_req_interval ); \ + _mbg_swab_ptp_time_interval( &(_p)->peer_mean_path_delay ); \ + _mbg_swab8( &(_p)->log_announce_interval ); \ + _mbg_swab8( &(_p)->announce_receipt_timeout ); \ + _mbg_swab8( &(_p)->log_sync_interval ); \ + _mbg_swab8( &(_p)->delay_mechanism ); \ + _mbg_swab8( &(_p)->log_min_pdelay_req_interval ); \ +} + + +/** + * @brief Index structure for PTPv2 port dataset + * + * @note Port dataset with index 0..::MBG_PTP_V2_DEFAULT_DATASET::number_ports - 1 can be queried from a device + * + * @see ::MBG_PTP_V2_PORT_DATASET + */ +typedef struct +{ + uint16_t idx; ///< Index of the port dataset, 0..::MBG_PTP_V2_DEFAULT_DATASET::number_ports - 1 + MBG_PTP_V2_PORT_DATASET port_dataset; ///< see ::MBG_PTP_V2_PORT_DATASET + +} MBG_PTP_V2_PORT_DATASET_IDX; + + +#define _mbg_swab_ptp_v2_port_dataset_idx( _p ) \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_ptp_v2_port_dataset( &(_p)->port_dataset ); \ +} /** @} defgroup group_ptp */ @@ -13348,7 +14824,6 @@ enum NTP_FLAGS NTP_MULTICAST, ///< transmission via multicast, point to multipoint NTP_MANYCAST, ///< transmission via manycast, point to multipoint NTP_POOL, ///< peer shall be treated as a pool server -#if defined( _PRELIMINARY_CODE ) NTP_PEER, ///< specifies a symmetric-active association should be used with this server NTP_BROADCASTCLIENT, ///< receive broadcast messages on all interfaces NTP_MULTICASTCLIENT, ///< receive messages from the given multicast group @@ -13359,7 +14834,8 @@ enum NTP_FLAGS NTP_STATISTICS, ///< NTP supports statistics (e.g. clockstats, loopstats, etc...) NTP_MISCELLANEOUS, ///< NTP supports misc options (e.g. tinker, driftfile, orphan mode, etc...) NTP_TRUSTED_KEYS, ///< NTP supports specifying trusted symmetric keys -#endif // defined( _PRELIMINARY_CODE ) + NTP_FIXED_REFCLOCKS, ///< NTP refclocks not configurable + N_NTP_FLAGS }; @@ -13392,19 +14868,18 @@ enum NTP_FLAGS #define NTP_MSK_MULTICAST ( 1UL << NTP_MULTICAST ) ///< see ::NTP_MULTICAST #define NTP_MSK_MANYCAST ( 1UL << NTP_MANYCAST ) ///< see ::NTP_MANYCAST #define NTP_MSK_POOL ( 1UL << NTP_POOL ) ///< see ::NTP_POOL +#define NTP_MSK_PEER ( 1UL << NTP_PEER ) ///< see ::NTP_PEER +#define NTP_MSK_BROADCASTCLIENT ( 1UL << NTP_BROADCASTCLIENT) ///< see ::NTP_BROADCASTCLIENT +#define NTP_MSK_MULTICASTCLIENT ( 1UL << NTP_MULTICASTCLIENT) ///< see ::NTP_MULTICASTCLIENT +#define NTP_MSK_MANYCASTCLIENT ( 1UL << NTP_MANYCASTCLIENT) ///< see ::NTP_MANYCASTCLIENT +#define NTP_MSK_RESTRICTIONS ( 1UL << NTP_RESTRICTIONS ) ///< see ::NTP_RESTRICTIONS +#define NTP_MSK_DISCARD ( 1UL << NTP_DISCARD ) ///< see ::NTP_DISCARD +#define NTP_MSK_REFCLOCKS ( 1UL << NTP_REFCLOCKS ) ///< see ::NTP_REFCLOCKS +#define NTP_MSK_STATISTICS ( 1UL << NTP_STATISTICS ) ///< see ::NTP_STATISTICS; if set, ::NTP_STATS_GLB_INFO can be queried +#define NTP_MSK_MISCELLANEOUS ( 1UL << NTP_MISCELLANEOUS ) ///< see ::NTP_MISCELLANEOUS +#define NTP_MSK_TRUSTED_KEYS ( 1UL << NTP_TRUSTED_KEYS ) ///< see ::NTP_TRUSTED_KEYS +#define NTP_MSK_FIXED_REFCLOCKS ( 1UL << NTP_FIXED_REFCLOCKS ) ///< see ::NTP_FIXED_REFCLOCKS -#if defined( _PRELIMINARY_CODE ) - #define NTP_MSK_PEER ( 1UL << NTP_PEER ) ///< see ::NTP_PEER - #define NTP_MSK_BROADCASTCLIENT ( 1UL << NTP_BROADCASTCLIENT) ///< see ::NTP_BROADCASTCLIENT - #define NTP_MSK_MULTICASTCLIENT ( 1UL << NTP_MULTICASTCLIENT) ///< see ::NTP_MULTICASTCLIENT - #define NTP_MSK_MANYCASTCLIENT ( 1UL << NTP_MANYCASTCLIENT) ///< see ::NTP_MANYCASTCLIENT - #define NTP_MSK_RESTRICTIONS ( 1UL << NTP_RESTRICTIONS ) ///< see ::NTP_RESTRICTIONS - #define NTP_MSK_DISCARD ( 1UL << NTP_DISCARD ) ///< see ::NTP_DISCARD - #define NTP_MSK_REFCLOCKS ( 1UL << NTP_REFCLOCKS ) ///< see ::NTP_REFCLOCKS - #define NTP_MSK_STATISTICS ( 1UL << NTP_STATISTICS ) ///< see ::NTP_STATISTICS; if set, ::NTP_STATS_GLB_INFO can be queried - #define NTP_MSK_MISCELLANEOUS ( 1UL << NTP_MISCELLANEOUS ) ///< see ::NTP_MISCELLANEOUS - #define NTP_MSK_TRUSTED_KEYS ( 1UL << NTP_TRUSTED_KEYS ) ///< see ::NTP_TRUSTED_KEYS -#endif // defined( _PRELIMINARY_CODE ) /** @} anchor NTP_FLAG_MASKS */ @@ -13417,25 +14892,52 @@ enum NTP_FLAGS */ typedef struct { - uint8_t ntp_role; ///< one of the supported NTP roles, see ::NTP_ROLES - uint8_t reserved_1; ///< reserved, currently 0 - uint16_t reserved_2; ///< reserved, currently 0 + uint8_t ntp_role; ///< one of the supported NTP roles, see ::NTP_ROLES + uint8_t num_symm_keys; ///< number of configured symm keys + uint8_t num_trusted_keys; ///< number of activated symm keys + uint8_t reserved_1; ///< reserved, currently 0 - uint32_t reserved_3; ///< reserved, currently 0 - uint32_t reserved_4; ///< reserved, currently 0 + uint32_t reserved_2; ///< reserved, currently 0 + uint32_t reserved_3; ///< reserved, currently 0 - uint32_t flags; ///< NTP flags, see @ref NTP_FLAG_MASKS + uint32_t flags; ///< NTP flags, see @ref NTP_FLAG_MASKS } NTP_GLB_SETTINGS; #define _mbg_swab_ntp_glb_settings( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->reserved_3 ); \ - _mbg_swab32( &(_p)->reserved_4 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) + + +/** + * @brief Global configuration info of an NTP device (client/server) + * + * This structure can be used to determine possible configurations of an NTP device + */ +typedef struct +{ + NTP_GLB_SETTINGS settings; ///< current configuration settings + + uint8_t max_symm_keys; ///< number of available symm keys that can be generated, see ::NTP_SYMM_KEY_INFO_IDX + uint8_t max_trusted_keys; ///< number of available trusted keys, see ::NTP_TRUSTED_KEY_INFO_IDX + uint16_t reserved_2; ///< reserved, currently 0 + uint32_t reserved_3; ///< reserved, currently 0 + + uint32_t supp_ntp_roles; ///< supported NTP roles, see ::NTP_ROLE_MASKS + uint32_t supp_flags; ///< supported NTP flags, see @ref NTP_FLAG_MASKS + +} NTP_GLB_INFO; + +#define _mbg_swab_ntp_glb_info( _p ) \ +do \ +{ \ + _mbg_swab_ntp_glb_settings( &(_p)->settings ); \ + _mbg_swab32( &(_p)->supp_ntp_roles ); \ + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) #if defined( _PRELIMINARY_CODE ) @@ -13553,13 +15055,14 @@ typedef struct } NTP_RESTR_LIMITS; #define _mbg_swab_ntp_restr_limits( _p ) \ +do \ { \ _mbg_swab16( &(_p)->max_restrs ); \ _mbg_swab16( &(_p)->cur_restrs ); \ _mbg_swab32( &(_p)->supp_types ); \ _mbg_swab32( &(_p)->supp_flags ); \ _mbg_swab32( &(_p)->reserved ); \ -} +} while ( 0 ) /** * @brief NTP restriction @@ -13580,11 +15083,33 @@ typedef struct } NTP_RESTR; #define _mbg_swab_ntp_restr( _p ) \ +do \ { \ _mbg_swab16( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ _mbg_swab_ntp_restr_discard( &(_p)->u.discard ); \ -} +} while ( 0 ) + + + +/** + * @brief NTP restriction, plus index + * + * @see ::NTP_RESTR + */ +typedef struct +{ + uint32_t idx; + NTP_RESTR restr; + +} NTP_RESTR_IDX; + +#define _mbg_swab_ntp_restr_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_restr( &(_p)->restr ); \ +} while ( 0 ) @@ -13608,11 +15133,12 @@ typedef struct } NTP_DISCARD_LIMITS; #define _mbg_swab_ntp_discard_limits( _p ) \ -{ \ - _mbg_swab16( &(_p)->monitor_min ); \ - _mbg_swab16( &(_p)->monitor_max ); \ - _mbg_swab32( &(_p)->reserved ); \ -} +do \ +{ \ + _mbg_swab16( &(_p)->monitor_min ); \ + _mbg_swab16( &(_p)->monitor_max ); \ + _mbg_swab32( &(_p)->reserved ); \ +} while ( 0 ) @@ -13629,30 +15155,11 @@ typedef struct } NTP_DISCARD_SETTINGS; #define _mbg_swab_ntp_discard_settings( _p ) \ -{ \ - _mbg_swab16( &(_p)->monitor ); \ - _mbg_swab32( &(_p)->reserved ); \ -} - - - -/** - * @brief NTP restriction, plus index - * - * @see ::NTP_RESTR - */ -typedef struct -{ - uint16_t idx; - NTP_RESTR restr; - -} NTP_RESTR_IDX; - -#define _mbg_swab_ntp_restr_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_ntp_restr( &(_p)->restr ); \ -} +do \ +{ \ + _mbg_swab16( &(_p)->monitor ); \ + _mbg_swab32( &(_p)->reserved ); \ +} while ( 0 ) @@ -13696,31 +15203,6 @@ enum NTP_REFCLK_TYPE_MSKS -/** - * @brief General NTP refclock limits to be read from a device - * - * Used to query from a device how many NTP refclocks are supported - * by the device, then index 0..::NTP_REFCLK_CFG_LIMITS::cur_refclks-1 - * refclock records can be read from a device. A maximum of - * ::NTP_REFCLK_CFG_LIMITS::max_refclks can be configured at all. - */ -typedef struct -{ - uint16_t max_refclks; ///< Number of maximum refclocks in ntp.conf - uint16_t cur_refclks; ///< Number of currently configured refclocks - uint32_t feat_flags; ///< Supported refclock specific feature flags, see @ref NTP_FLAG_MASKS - uint32_t reserved; ///< Future use - -} NTP_REFCLK_CFG_LIMITS; - -#define _mbg_swab_ntp_refclk_cfg_limits( _p ) \ -{ \ - _mbg_swab16( &(_p)->max_refclks ); \ - _mbg_swab16( &(_p)->cur_refclks ); \ - _mbg_swab32( &(_p)->feat_flags ); \ - _mbg_swab32( &(_p)->reserved ); \ -} - /** @@ -13772,10 +15254,10 @@ typedef struct { uint8_t type; ///< See ::NTP_REFCLK_TYPES uint8_t instance; ///< Refclock instance of the specified type. Usually up to 4 instances of the same type are supported by ntpd. - uint8_t mode; ///< Driver specific "mode" //### TODO Flag to enable "mode"? + uint8_t mode; ///< Driver specific "mode" ::FIXME Flag to enable "mode"? int8_t stratum; ///< Stratum number to be fudged; -1 if unspecified and thus default is to be used - int8_t refid[4]; ///< Reference id used by driver //### TODO Flag to enable "refid"? + int8_t refid[4]; ///< Reference id used by driver ::FIXME Flag to enable "refid"? uint8_t minpoll; ///< Minimum polling interval, [log2 seconds], 0 if unused/unspecified uint8_t maxpoll; ///< Maximum polling interval, [log2 seconds], 0 if unused/unspecified @@ -13788,21 +15270,21 @@ typedef struct uint16_t drv_flags_enable; ///< Enable/disable driver specific flags, see @ref NTP_FUDGE_FLAG_NUMBERS uint16_t drv_flags_value; ///< 0 or 1, if (drv_flags_enable & x) == 1, see @ref NTP_FUDGE_FLAG_NUMBERS - uint32_t flags; ///< See @ref NTP_FLAG_MASKS. Only flags specified in ::TODO can be used here. + uint32_t flags; ///< See @ref NTP_FLAG_MASKS. Only flags specified in ::FIXME can be used here. uint32_t reserved_3; ///< Future use } NTP_REFCLK_CFG_SETTINGS; #define _mbg_swab_ntp_refclk_cfg_settings( _p ) \ +do \ { \ _mbg_swab_nano_time_64( &(_p)->time1 ); \ _mbg_swab_nano_time_64( &(_p)->time2 ); \ _mbg_swab16( &(_p)->drv_flags_enable ); \ _mbg_swab16( &(_p)->drv_flags_value ); \ _mbg_swab32( &(_p)->flags ); \ - _mbg_swab16( &(_p)->reserved_3 ); \ -} +} while ( 0 ) @@ -13813,16 +15295,17 @@ typedef struct */ typedef struct { - uint16_t idx; + uint32_t idx; NTP_REFCLK_CFG_SETTINGS settings; ///< See ::NTP_REFCLK_CFG_SETTINGS } NTP_REFCLK_CFG_SETTINGS_IDX; #define _mbg_swab_ntp_refclk_cfg_settings_idx( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->idx ); \ + _mbg_swab32( &(_p)->idx ); \ _mbg_swab_ntp_refclk_cfg_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -13841,10 +15324,11 @@ typedef struct } NTP_REFCLK_CFG_INFO; #define _mbg_swab_ntp_refclk_cfg_info( _p ) \ +do \ { \ _mbg_swab_ntp_refclk_cfg_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_refclk_types ); \ -} +} while ( 0 ) @@ -13855,87 +15339,17 @@ typedef struct */ typedef struct { - uint16_t idx; + uint32_t idx; NTP_REFCLK_CFG_INFO info; } NTP_REFCLK_CFG_INFO_IDX; #define _mbg_swab_ntp_refclk_cfg_info_idx( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->idx ); \ + _mbg_swab32( &(_p)->idx ); \ _mbg_swab_ntp_refclk_cfg_info( &(_p)->info ); \ -} - - - -/** - * @brief Enumeration of supported refclock driver specific flags - * - * @see ::NTP_REFCLK_SPEC_MASKS - */ -enum NTP_REFCLK_SPEC_FLAGS -{ - NTP_REFCLK_SPEC_FLAG_TIME1, - NTP_REFCLK_SPEC_FLAG_TIME2, - NTP_REFCLK_SPEC_FLAG_STRATUM, - NTP_REFCLK_SPEC_FLAG_FLAG1, //### TODO use a bit mask instead as for drv_flags_enable? - NTP_REFCLK_SPEC_FLAG_FLAG2, - NTP_REFCLK_SPEC_FLAG_FLAG3, - NTP_REFCLK_SPEC_FLAG_FLAG4, - N_NTP_REFCLK_SPEC_FLAGS -}; - - - -/** - * @brief Flag masks associated with ::NTP_REFCLK_SPEC_FLAGS - * - * @see ::NTP_REFCLK_SPEC_FLAGS - */ -enum NTP_REFCLK_SPEC_MASKS -{ - NTP_REFCLK_SPEC_MSK_TIME1 = ( 1UL << NTP_REFCLK_SPEC_FLAG_TIME1 ), ///< See ::NTP_REFCLK_SPEC_FLAG_TIME1 - NTP_REFCLK_SPEC_MSK_TIME2 = ( 1UL << NTP_REFCLK_SPEC_FLAG_TIME2 ), ///< See ::NTP_REFCLK_SPEC_FLAG_TIME2 - NTP_REFCLK_SPEC_MSK_STRATUM = ( 1UL << NTP_REFCLK_SPEC_FLAG_STRATUM ), ///< See ::NTP_REFCLK_SPEC_FLAG_STRATUM - NTP_REFCLK_SPEC_MSK_FLAG1 = ( 1UL << NTP_REFCLK_SPEC_FLAG_FLAG1 ), ///< See ::NTP_REFCLK_SPEC_FLAG_FLAG1 - NTP_REFCLK_SPEC_MSK_FLAG2 = ( 1UL << NTP_REFCLK_SPEC_FLAG_FLAG2 ), ///< See ::NTP_REFCLK_SPEC_FLAG_FLAG2 - NTP_REFCLK_SPEC_MSK_FLAG3 = ( 1UL << NTP_REFCLK_SPEC_FLAG_FLAG3 ), ///< See ::NTP_REFCLK_SPEC_FLAG_FLAG3 - NTP_REFCLK_SPEC_MSK_FLAG4 = ( 1UL << NTP_REFCLK_SPEC_FLAG_FLAG4 ), ///< See ::NTP_REFCLK_SPEC_FLAG_FLAG4 -}; - - - -#define N_NTP_REFCLK_CFG_CHARS 16 ///< Maximum number of chars for any refclock specifications - -/** - * @brief NTP refclock specification - * - * Structure describes in a refclock specific way how to handle commonly used - * ::NTP_REFCLK_CFG_SETTINGS for this specific refclock. It is informational and - * read-only. - * - * @note ::NTP_REFCLK_CFG_SPEC needs no limit or info structures since the number - * of supported and max. available structures corresponds to ::N_NTP_REFCLK_TYPES. - * Each refclock needs its own spec that is addressed by ::NTP_REFCLK_CFG_SETTINGS::type. - */ -typedef struct -{ - uint8_t max_instances; ///< Number of max. possible driver instances. - ///< For example: /dev/refclock-[0..3] - uint8_t reserved_1; ///< Future use - uint16_t reserved_2; ///< Future use - uint32_t supp_specs; ///< Supported refclock specific flags, see ::N_NTP_REFCLK_CFG_CHARS - uint32_t reserved_3; ///< Future use - -} NTP_REFCLK_CFG_SPEC; - -#define _mbg_swab_ntp_refclk_cfg_spec( _p ) \ -{ \ - _mbg_swab16( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->supp_specs ); \ - _mbg_swab_ntp_refclk_cfg_info( &(_p)->info ); \ -} - +} while ( 0 ) /** @@ -13967,36 +15381,41 @@ enum NTP_SYMM_KEY_HASH_MASKS }; +/** + * @brief Name strings for defined NTP symm key hashes + * + * @see ::NTP_SYMM_KEY_HASHES + */ +#define NTP_SYMM_KEY_HASHES_STRS \ +{ \ + "MD5", \ + "SHA1" \ +} + + /** * @brief General NTP symmetric key limits to be read from a device * - * Used to query from a device how many symmetric keys are supported - * by the device, then index 0..::NTP_SYMM_KEY_LIMITS::n_cur_keys-1 - * keys can be read from a device. A maximum of - * ::NTP_SYMM_KEY_LIMITS::n_supp_keys can be configured at all. * ::NTP_SYMM_KEY_LIMITS::supp_hashes specifies supported hashing algorithms * to create keys with. See ::NTP_SYMM_KEY_HASH_MASKS. Structure can be queried * if ::NTP_MSK_SYMM_KEYS is set in ::NTP_GLB_INFO::supp_flags */ typedef struct { - uint16_t n_supp_keys; ///< Maximum number of supported NTP symmetric keys - uint16_t n_cur_keys; ///< Current number of configured NTP symmetric keys uint16_t supp_hashes; ///< See ::NTP_SYMM_KEY_HASH_MASKS uint16_t reserved_1; ///< Future use uint32_t reserved_2; ///< Future use + uint32_t reserved_3; ///< Future use + uint32_t reserved_4; ///< Future use } NTP_SYMM_KEY_LIMITS; #define _mbg_swab_ntp_symm_key_limits( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->n_supp_keys ); \ - _mbg_swab16( &(_p)->n_cur_keys ); \ _mbg_swab16( &(_p)->supp_hashes ); \ - _mbg_swab16( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -14004,6 +15423,11 @@ typedef struct /// prepared for hash algorithms like SHA256, SH384, up to SHA512. #define N_NTP_SYMM_KEY_LEN 128 +/// Maximum number of ip addresses which can be assign to each key in +/// order to limit usage +#define N_NTP_SYMM_KEY_MAX_IP_ADDR 8 + + /** * @brief NTP symmetric key specific settings @@ -14012,19 +15436,30 @@ typedef struct */ typedef struct { - uint16_t id; ///< Configurable key id (1..65534) - uint8_t hash; ///< See ::NTP_SYMM_KEY_HASHES - uint8_t reserved_1; ///< Future use - uint32_t reserved_2; ///< Future use - uint8_t key[N_NTP_SYMM_KEY_LEN]; ///< Hashed phrase, see ::N_NTP_SYMM_KEY_LEN + uint16_t id; ///< Configurable key id (1..65534) + uint8_t hash; ///< See ::NTP_SYMM_KEY_HASHES + uint8_t reserved_1; ///< Future use + + uint16_t reserved_2; ///< Future use + uint8_t num_ip_addr; ///< Number of configured ip addresses + uint8_t reserved_3; ///< Future use + + uint8_t key[N_NTP_SYMM_KEY_LEN]; ///< Hashed phrase, see ::N_NTP_SYMM_KEY_LEN + + MBG_IP_ADDR ip_addr[N_NTP_SYMM_KEY_MAX_IP_ADDR]; ///< Whitelist of ip addresses see ::N_NTP_SYMM_KEY_MAX_IP_ADDR } NTP_SYMM_KEY_SETTINGS; -#define _mbg_swab_ntp_symm_settings( _p ) \ -{ \ - _mbg_swab16( &(_p)->id ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +#define _mbg_swab_ntp_symm_key_settings( _p ) \ +do \ +{ \ + unsigned i; \ + \ + _mbg_swab16( &(_p)->id ); \ + \ + for ( i = 0; i < N_NTP_SYMM_KEY_MAX_IP_ADDR; ++i) \ + _mbg_swab_ip_addr( &(_p)->ip_addr[i] ); \ +} while ( 0 ) @@ -14035,44 +15470,60 @@ typedef struct */ typedef struct { - uint16_t idx; + uint32_t idx; NTP_SYMM_KEY_SETTINGS settings; } NTP_SYMM_KEY_SETTINGS_IDX; -#define _mbg_swab_ntp_symm_settings_idx( _p ) \ -{ \ - _mbg_swab16( &(_p)->idx ); \ - _mbg_swab_ntp_symm_settings( &(_p)->settings ); \ -} - +#define _mbg_swab_ntp_symm_key_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_symm_key_settings( &(_p)->settings ); \ +} while ( 0 ) /** - * @brief General NTP trusted symmetric key limits to be read from a device + * @brief NTP symmkey info * - * Used to query from a device how many trusted symmetric keys are supported - * by the device, then index 0..::NTP_TRUSTED_KEY_LIMITS::n_cur_keys-1 - * keys can be read from a device. A maximum of - * ::NTP_TRUSTED_KEY_LIMITS::n_supp_keys can be configured at all. Structure can - * be queried if ::NTP_MSK_TRUSTED_KEYS is set in ::NTP_GLB_INFO::supp_flags + * This structure is used to query a symmetric key for NTP. */ typedef struct { - uint16_t n_supp_keys; ///< Maximum number of supported NTP trusted keys - uint16_t n_cur_keys; ///< Current number of configured NTP trusted keys + NTP_SYMM_KEY_SETTINGS settings; - uint32_t reserved_1; ///< Future use + uint32_t reserved_1; ///< Future use + uint32_t reserved_2; ///< Future use + uint32_t reserved_3; ///< Future use + uint32_t reserved_4; ///< Future use -} NTP_TRUSTED_KEY_LIMITS; +} NTP_SYMM_KEY_INFO; -#define _mbg_swab_ntp_trusted_key_limits( _p ) \ -{ \ - _mbg_swab16( &(_p)->n_supp_keys ); \ - _mbg_swab16( &(_p)->n_cur_keys ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ -} +#define _mbg_swab_ntp_symm_key_info( _p ) \ +do \ +{ \ + _mbg_swab_ntp_symm_key_settings( &(_p)->settings ); \ +} while ( 0 ) + + +/** + * @brief NTP symm key info, with index + * + * @see ::NTP_SYMM_KEY_INFO + */ +typedef struct +{ + uint32_t idx; + NTP_SYMM_KEY_INFO info; + +} NTP_SYMM_KEY_INFO_IDX; +#define _mbg_swab_ntp_symm_key_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_symm_key_info( &(_p)->info ); \ +} while ( 0 ) /** @@ -14089,13 +15540,73 @@ typedef struct } NTP_TRUSTED_KEY_SETTINGS; #define _mbg_swab_ntp_trusted_key_settings( _p ) \ -{ \ - _mbg_swab16( &(_p)->id ); \ - _mbg_swab16( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +do \ +{ \ + _mbg_swab16( &(_p)->id ); \ +} while ( 0 ) +/** + * @brief NTP trusted key settings, with index + * + * @see ::NTP_TRUSTED_KEY_SETTINGS + */ +typedef struct +{ + uint32_t idx; + NTP_TRUSTED_KEY_SETTINGS settings; + +} NTP_TRUSTED_KEY_SETTINGS_IDX; + +#define _mbg_swab_ntp_trusted_key_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_trusted_key_settings( &(_p)->settings ); \ +} while ( 0 ) + +/** + * @brief NTP trusted key info + * + * This structure is used to query a trusted symmetric key for NTP. + */ +typedef struct +{ + NTP_TRUSTED_KEY_SETTINGS settings; + + uint32_t reserved_1; ///< Future use + uint32_t reserved_2; ///< Future use + uint32_t reserved_3; ///< Future use + uint32_t reserved_4; ///< Future use + +} NTP_TRUSTED_KEY_INFO; + +#define _mbg_swab_ntp_trusted_key_info( _p ) \ +do \ +{ \ + _mbg_swab_ntp_trusted_key_settings( &(_p)->settings ); \ +} while ( 0 ) + + +/** + * @brief NTP trusted key info, with index + * + * @see ::NTP_TRUSTED_KEY_INFO + */ +typedef struct +{ + uint32_t idx; + NTP_TRUSTED_KEY_INFO info; + +} NTP_TRUSTED_KEY_INFO_IDX; + +#define _mbg_swab_ntp_trusted_key_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_trusted_key_info( &(_p)->info ); \ +} while ( 0 ) + /** * @brief Enumeration of NTP supported statistics @@ -14154,11 +15665,12 @@ typedef struct } NTP_STATS_GLB_SETTINGS; #define _mbg_swab_ntp_stats_glb_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->flags ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -14180,13 +15692,14 @@ typedef struct } NTP_STATS_GLB_INFO; #define _mbg_swab_ntp_stats_glb_info( _p ) \ +do \ { \ _mbg_swab_ntp_stats_glb_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_stats ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->reserved_3 ); \ -} +} while ( 0 ) @@ -14234,11 +15747,10 @@ typedef struct } NTP_MISC_LIMITS; #define _mbg_swab_ntp_misc_limits( _p ) \ +do \ { \ _mbg_swab32( &(_p)->supp_flags ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -14257,13 +15769,37 @@ typedef struct } NTP_MISC_DRIFTFILE_SETTINGS; #define _mbg_swab_ntp_misc_driftfile_settings( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->reserved_2 ); \ -} +} while ( 0 ) + + +/** + * @brief Enumeration of NTP supported (various) misc options + * + * @see ::NTP_ORPHAN_MODE_MSK + */ +enum NTP_ORPHAN_MODE_FLAGS +{ + NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE, ///< Orphan Mode support disabling + + N_NTP_ORPHAN_MODE_FLAGS +}; /** + * @brief Flag masks associated with ::NTP_ORPHAN_MODE_FLAGS + * + * @see ::NTP_ORPHAN_MODE_FLAGS + */ +enum NTP_ORPHAN_MODE_MSK +{ + NTP_ORPHAN_MODE_MSK_SUPP_DISABLE = ( 1UL << NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE ) ///< See ::NTP_ORPHAN_MODE_FLAG_SUPP_DISABLE +}; + + +/** * @brief NTP orphan mode settings to be read from / written to a device * * If ::NTP_MISC_MSK_ORPHAN_MODE is set in ::NTP_MISC_LIMITS::supp_flags @@ -14275,13 +15811,37 @@ typedef struct uint8_t mode; ///< Stratum level when no ref source available uint16_t reserved_1; ///< Future use + uint32_t reserved_2; ///< Future use + } NTP_MISC_ORPHAN_MODE_SETTINGS; #define _mbg_swab_ntp_misc_orphan_mode_settings( _p ) \ +do \ { \ - _mbg_swab16( &(_p)->reserved_1 ); \ -} +} while ( 0 ) + + +/** + * @brief NTP orphan mode info + * + */ +typedef struct +{ + NTP_MISC_ORPHAN_MODE_SETTINGS settings; ///< See ::NTP_MISC_ORPHAN_MODE_SETTINGS + uint32_t supp_flags; ///< See ::NTP_ORPHAN_MODE_MSK + uint32_t reserved_1; ///< Future use + uint32_t reserved_2; ///< Future use + uint32_t reserved_3; ///< Future use + +} NTP_MISC_ORPHAN_MODE_INFO; + +#define _mbg_swab_ntp_misc_orphan_mode_info( _p ) \ +do \ +{ \ + _mbg_swab_ntp_misc_orphan_mode_settings( &(_p)->settings ); \ + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) /** @@ -14299,40 +15859,41 @@ typedef struct } NTP_MISC_LEAPFILE_SETTINGS; #define _mbg_swab_ntp_misc_leapfile_settings( _p ) \ +do \ { \ _mbg_swab16( &(_p)->reserved_2 ); \ -} - -#endif // defined( _PRELIMINARY_CODE ) - - - -/** - * @brief Global configuration info of an NTP device (client/server) - * - * This structure can be used to determine possible configurations of an NTP device - */ -typedef struct -{ - NTP_GLB_SETTINGS settings; ///< current configuration settings +} while ( 0 ) - uint32_t reserved_1; ///< reserved, currently 0 - uint32_t reserved_2; ///< reserved, currently 0 - uint32_t supp_ntp_roles; ///< supported NTP roles, see ::NTP_ROLE_MASKS - uint32_t supp_flags; ///< supported NTP flags, see @ref NTP_FLAG_MASKS - -} NTP_GLB_INFO; - -#define _mbg_swab_ntp_glb_info( _p ) \ -{ \ - _mbg_swab_ntp_glb_settings( &(_p)->settings ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->supp_ntp_roles ); \ - _mbg_swab32( &(_p)->supp_flags ); \ -} +#else // !defined( _PRELIMINARY_CODE ), dummy declarations + + typedef int NTP_RESTR_LIMITS; + typedef int NTP_RESTR; + typedef int NTP_RESTR_IDX; + typedef int NTP_DISCARD_LIMITS; + typedef int NTP_DISCARD_SETTINGS; + typedef int NTP_REFCLK_CFG_SETTINGS; + typedef int NTP_REFCLK_CFG_SETTINGS_IDX; + typedef int NTP_REFCLK_CFG_INFO; + typedef int NTP_REFCLK_CFG_INFO_IDX; + typedef int NTP_SYMM_KEY_LIMITS; + typedef int NTP_SYMM_KEY_SETTINGS; + typedef int NTP_SYMM_KEY_SETTINGS_IDX; + typedef int NTP_SYMM_KEY_INFO; + typedef int NTP_SYMM_KEY_INFO_IDX; + typedef int NTP_TRUSTED_KEY_SETTINGS; + typedef int NTP_TRUSTED_KEY_SETTINGS_IDX; + typedef int NTP_TRUSTED_KEY_INFO; + typedef int NTP_TRUSTED_KEY_INFO_IDX; + typedef int NTP_STATS_GLB_SETTINGS; + typedef int NTP_STATS_GLB_INFO; + typedef int NTP_MISC_LIMITS; + typedef int NTP_MISC_DRIFTFILE_SETTINGS; + typedef int NTP_MISC_ORPHAN_MODE_SETTINGS; + typedef int NTP_MISC_ORPHAN_MODE_INFO; + typedef int NTP_MISC_LEAPFILE_SETTINGS; +#endif // defined( _PRELIMINARY_CODE ) /** @@ -14342,19 +15903,23 @@ typedef struct */ typedef struct { - uint32_t reserved_1; ///< reserved, currently 0 - uint32_t reserved_2; ///< reserved, currently 0 + uint8_t num_peers; ///< number available peers + uint8_t reserved_1; ///< reserved, currently 0 + uint16_t reserved_2; ///< reserved, currently 0 + + uint32_t reserved_3; ///< reserved, currently 0 uint32_t flags; ///< NTP flags, see @ref NTP_FLAG_MASKS } NTP_CLNT_MODE_SETTINGS; #define _mbg_swab_ntp_clnt_mode_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -14381,13 +15946,14 @@ typedef struct } NTP_CLNT_MODE_INFO; #define _mbg_swab_ntp_clnt_mode_info( _p ) \ +do \ { \ _mbg_swab_ntp_clnt_mode_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->supp_flags ); \ _mbg_swab32( &(_p)->supp_peer_flags ); \ -} +} while ( 0 ) @@ -14428,6 +15994,7 @@ typedef struct } NTP_PEER_LIMITS; #define _mbg_swab_ntp_peer_limits( _p ) \ +do \ { \ _mbg_swab16( &(_p)->n_supp_peers ); \ _mbg_swab16( &(_p)->n_cur_peers ); \ @@ -14445,7 +16012,7 @@ typedef struct _mbg_swab32( &(_p)->reserved_4 ); \ _mbg_swab32( &(_p)->reserved_5 ); \ _mbg_swab32( &(_p)->reserved_6 ); \ -} +} while ( 0 ) @@ -14479,12 +16046,13 @@ typedef struct } NTP_PEER_SETTINGS; #define _mbg_swab_ntp_peer_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->key ); \ _mbg_swab32( &(_p)->reserved_3 ); \ _mbg_swab32( &(_p)->reserved_4 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -14501,64 +16069,62 @@ typedef struct } NTP_PEER_SETTINGS_IDX; #define _mbg_swab_ntp_peer_settings_idx( _p ) \ +do \ { \ _mbg_swab32( &(_p)->idx ); \ _mbg_swab_ntp_peer_settings( &(_p)->peer_settings ); \ -} - - +} while ( 0 ) -#if defined( DEBUG ) //### TODO or _PRELIMINARY_CODE ? /** - * @brief Dummy structure for later NTP server implementations, not used, yet + * @brief Server settings of an NTP device + * + * This structure should be sent to an NTP server to configure server parameters */ typedef struct { - uint32_t reserved_1; ///< reserved, currently 0 - uint32_t reserved_2; ///< reserved, currently 0 + uint8_t num_refclks; ///< number of available refclks @ref NTP_REFCLK_CFG_INFO + uint8_t reserved_1; ///< reserved, currently 0 + uint16_t reserved_2; ///< reserved, currently 0 + + uint32_t reserved_3; ///< reserved, currently 0 uint32_t flags; ///< NTP flags, see @ref NTP_FLAG_MASKS } NTP_SRV_MODE_SETTINGS; #define _mbg_swab_ntp_srv_mode_settings( _p ) \ +do \ { \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) /** - * @brief Dummy structure for later NTP server implementations + * @brief Server settings info of an NTP device + * + * This structure should be used to query an NTP server configuration from a device */ typedef struct { NTP_SRV_MODE_SETTINGS settings; - uint32_t reserved_1; ///< reserved, currently 0 - uint32_t reserved_2; ///< reserved, currently 0 + uint8_t max_refclks; ///< number of supported refclks @ref NTP_REFCLK_CFG_INFO + uint8_t reserved_1; ///< reserved, currently 0 + uint16_t reserved_2; ///< reserved, currently 0 + + uint32_t reserved_3; ///< reserved, currently 0 - uint32_t supp_flags; ///< supported NTP flags, see @ref NTP_FLAG_MASKS + uint32_t supp_flags; ///< supported NTP flags, see @ref NTP_FLAG_MASKS } NTP_SRV_MODE_INFO; #define _mbg_swab_ntp_srv_mode_info( _p ) \ +do \ { \ _mbg_swab_ntp_srv_mode_settings( &(_p)->settings ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->supp_flags ); \ -} - -#else - - typedef int NTP_SRV_MODE_INFO; - typedef int NTP_SRV_MODE_SETTINGS; - -#endif // DEBUG - +} while ( 0 ) /** @@ -14575,6 +16141,7 @@ typedef struct } NTP_SHORT_TSTAMP; #define _mbg_swab_ntp_short_tstamp( _p ) \ +do \ { \ _mbg_swab16( &(_p)->seconds ); \ _mbg_swab16( &(_p)->fractions ); \ @@ -14593,10 +16160,11 @@ typedef struct } NTP_TSTAMP; #define _mbg_swab_ntp_tstamp( _p ) \ +do \ { \ _mbg_swab32( &(_p)->seconds ); \ _mbg_swab32( &(_p)->fractions ); \ -} +} while ( 0 ) @@ -14908,6 +16476,7 @@ enum NTP_SYS_STATE_SUPP_FLAGS NTP_SYS_STATE_SUPP_SYS_JITTER, ///< supports combined jitter, see ::NTP_SYS_STATE::sys_jitter NTP_SYS_STATE_SUPP_CLK_JITTER, ///< supports clock jitter, see ::NTP_SYS_STATE::clk_jitter NTP_SYS_STATE_SUPP_CLK_WANDER, ///< supports clock wander, see ::NTP_SYS_STATE::clk_wander + NTP_SYS_STATE_SUPP_SYS_ASSOC, ///< supports sys assoc ID as sys peer, see ::NTP_SYS_STATE::sys_assoc N_NTP_SYS_STATE_SUPP_FLAGS }; @@ -14930,7 +16499,8 @@ enum NTP_SYS_STATE_SUPP_FLAG_MASKS NTP_SYS_STATE_SUPP_FREQ_MSK = ( 1UL << NTP_SYS_STATE_SUPP_FREQ ), ///< see ::NTP_SYS_STATE_SUPP_FREQ NTP_SYS_STATE_SUPP_SYS_JITTER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_SYS_JITTER ), ///< see ::NTP_SYS_STATE_SUPP_SYS_JITTER NTP_SYS_STATE_SUPP_CLK_JITTER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_CLK_JITTER ), ///< see ::NTP_SYS_STATE_SUPP_CLK_JITTER - NTP_SYS_STATE_SUPP_CLK_WANDER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_CLK_WANDER ) ///< see ::NTP_SYS_STATE_SUPP_CLK_WANDER + NTP_SYS_STATE_SUPP_CLK_WANDER_MSK = ( 1UL << NTP_SYS_STATE_SUPP_CLK_WANDER ), ///< see ::NTP_SYS_STATE_SUPP_CLK_WANDER + NTP_SYS_STATE_SUPP_SYS_ASSOC_MSK = ( 1UL << NTP_SYS_STATE_SUPP_SYS_ASSOC ) ///< see ::NTP_SYS_STATE_SUPP_SYS_ASSOC }; @@ -14960,7 +16530,7 @@ typedef struct uint8_t stratum; ///< Current stratum level of the system int8_t precision; ///< Precision of the system clock (2^precision) - uint16_t reserved_1; ///< Reserved, currently always 0 + uint16_t sys_assoc; ///< Association ID of the current system peer, do not use NTP_SYS_STATE::sys_peer if this is supported int32_t root_delay; ///< [us] Total roundtrip delay to the system peer int32_t root_disp; ///< [us] Total dispersion to the system peer @@ -14970,7 +16540,7 @@ typedef struct NTP_TSTAMP ref_time; ///< Last time the system time has been adjusted, see ::NTP_TSTAMP NTP_TSTAMP sys_time; ///< Current system time, see ::NTP_TSTAMP - uint16_t sys_peer; ///< Assocation ID of the current system peer + uint16_t sys_peer; ///< Index of the current system peer uint8_t poll; ///< Current polling interval for the system peer (tc) uint8_t minpoll; ///< Minimal polling interval for the system peer (mintc) @@ -14981,11 +16551,61 @@ typedef struct int32_t clk_jitter; ///< [us] Jitter of the clock int32_t clk_wander; ///< [ppb] Frequency wander of the clock - uint32_t reserved_2; ///< Reserved, currently always 0 + uint8_t cfg_counter; ///< Updated (increased) when config changes + uint8_t reserved_1; ///< Reserved, currently always 0 + uint16_t reserved_2; ///< Reserved, currently always 0 + uint32_t reserved_3; ///< Reserved, currently always 0 } NTP_SYS_STATE; +#define _mbg_swab_ntp_sys_state( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_flags ); \ + \ + _mbg_swab8( &(_p)->leap_ind ); \ + _mbg_swab8( &(_p)->sys_sync_src ); \ + _mbg_swab8( &(_p)->sys_evt_cnt ); \ + _mbg_swab8( &(_p)->sys_rec_evt ); \ + \ + _mbg_swab8( &(_p)->impl_type ); \ + _mbg_swab8( &(_p)->major_version ); \ + _mbg_swab8( &(_p)->minor_version ); \ + _mbg_swab8( &(_p)->micro_version ); \ + \ + _mbg_swab16( &(_p)->patch_lvl ); \ + _mbg_swab8( &(_p)->cpu_type ); \ + _mbg_swab8( &(_p)->system ); \ + \ + _mbg_swab8( &(_p)->stratum ); \ + _mbg_swab8( &(_p)->precision ); \ + _mbg_swab16( &(_p)->sys_assoc ); \ + \ + _mbg_swab32( &(_p)->root_delay ); \ + _mbg_swab32( &(_p)->root_disp ); \ + \ + _mbg_swab_ip_addr( &(_p)->ref_id ); \ + \ + _mbg_swab_ntp_tstamp( &(_p)->ref_time ); \ + _mbg_swab_ntp_tstamp( &(_p)->sys_time ); \ + \ + _mbg_swab16( &(_p)->sys_peer ); \ + _mbg_swab8( &(_p)->poll ); \ + _mbg_swab8( &(_p)->minpoll ); \ + \ + _mbg_swab64( &(_p)->offset ); \ + \ + _mbg_swab32( &(_p)->freq ); \ + _mbg_swab32( &(_p)->sys_jitter ); \ + _mbg_swab32( &(_p)->clk_jitter ); \ + _mbg_swab32( &(_p)->clk_wander ); \ + \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ + \ +} while ( 0 ) + /** @@ -15087,6 +16707,7 @@ enum NTP_REACH_STAT_BITS } + /** * @brief Enumeration of NTP peer selection status * @@ -15478,8 +17099,75 @@ typedef struct uint32_t reserved_9; ///< Reserved, currently always 0 -} NTP_PEER_STATE; +} NTP_PEER_STATE, NTP_REFCLK_STATE; + + +#define _mbg_swab_ntp_peer_state( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_flags ); \ + \ + _mbg_swab16( &(_p)->ass_id ); \ + _mbg_swab16( &(_p)->peer_status_flags ); \ + \ + _mbg_swab8( &(_p)->leap_ind ); \ + _mbg_swab8( &(_p)->peer_sel_stat ); \ + _mbg_swab8( &(_p)->peer_evt_cnt ); \ + _mbg_swab8( &(_p)->peer_rec_evt ); \ + \ + _mbg_swab8( &(_p)->peer_reach_stat ); \ + _mbg_swab8( &(_p)->reserved_1 ); \ + _mbg_swab16( &(_p)->reserved_2 ); \ + \ + _mbg_swab_ip_addr_port( &(_p)->src_addr ); \ + _mbg_swab_ip_addr_port( &(_p)->dst_addr ); \ + \ + _mbg_swab8( &(_p)->stratum ); \ + _mbg_swab8( &(_p)->precision ); \ + _mbg_swab16( &(_p)->reserved_3 ); \ + \ + _mbg_swab32( &(_p)->root_delay ); \ + _mbg_swab32( &(_p)->root_disp ); \ + \ + _mbg_swab_ip_addr( &(_p)->ref_id ); \ + \ + _mbg_swab_ntp_tstamp( &(_p)->ref_time ); \ + _mbg_swab_ntp_tstamp( &(_p)->rec_time ); \ + \ + _mbg_swab8( &(_p)->reach ); \ + _mbg_swab8( &(_p)->reserved_4 ); \ + _mbg_swab16( &(_p)->unreach ); \ + \ + _mbg_swab8( &(_p)->host_mode ); \ + _mbg_swab8( &(_p)->peer_mode ); \ + _mbg_swab8( &(_p)->host_poll ); \ + _mbg_swab8( &(_p)->peer_poll ); \ + \ + _mbg_swab8( &(_p)->headway ); \ + _mbg_swab8( &(_p)->reserved_5 ); \ + _mbg_swab16( &(_p)->flash_stat_flags ); \ + \ + _mbg_swab16( &(_p)->key_id ); \ + _mbg_swab16( &(_p)->reserved_6 ); \ + \ + _mbg_swab64( &(_p)->offset ); \ + _mbg_swab64( &(_p)->delay ); \ + \ + _mbg_swab32( &(_p)->disp ); \ + _mbg_swab32( &(_p)->jitter ); \ + \ + _mbg_swab32( &(_p)->xleave ); \ + \ + _mbg_swab8( &(_p)->n_filter_values ); \ + _mbg_swab8( &(_p)->reserved_7 ); \ + _mbg_swab16( &(_p)->reserved_8 ); \ + \ + _mbg_swab32( &(_p)->reserved_9 ); \ + \ +} while ( 0 ) + +#define _mbg_swab_ntp_refclk_state ( _p ) _mbg_swab_ntp_peer_state( _p ) /** @@ -15494,7 +17182,18 @@ typedef struct uint32_t idx; ///< The index of the observed NTP peer NTP_PEER_STATE peer_state; ///< Peer state, see ::NTP_PEER_STATE -} NTP_PEER_STATE_IDX; +} NTP_PEER_STATE_IDX, NTP_REFCLK_STATE_IDX; + + +#define _mbg_swab_ntp_peer_state_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_ntp_peer_state( &(_p)->peer_state ); \ +} while ( 0 ) + + +#define _mbg_swab_ntp_refclk_state_idx( _p ) _mbg_swab_ntp_peer_state_idx( _p ) /** @} defgroup group_ntp */ @@ -15509,7 +17208,7 @@ typedef struct #define MAX_LNO_OUTPUT 4 /** - * @brief LNO status + * @brief LNO state */ typedef struct { @@ -15525,6 +17224,7 @@ typedef struct } LNO_STATE; #define _mbg_swab_lno_state( _p ) \ +do \ { \ int i; \ \ @@ -15534,11 +17234,11 @@ typedef struct _mbg_swab_16( &(_p)->max_sine_lvl ); \ _mbg_swab_16( &(_p)->reserved_0 ); \ _mbg_swab_16( &(_p)->flags ); \ -} +} while ( 0 ) /** - * @brief Flags used with LNO_STATE::flags + * @brief Flags used with ::LNO_STATE::flags */ enum LNO_STATE_FLAG_BITS { @@ -15587,12 +17287,13 @@ typedef struct } VST_HEADER; #define _mbg_swab_vst_header( _p ) \ +do \ { \ _mbg_swab16( &(_p)->data_type ); \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab16( &(_p)->data_len ); \ _mbg_swab16( &(_p)->reserved ); \ -} +} while ( 0 ) /** @} defgroup group_vst */ @@ -15645,12 +17346,13 @@ typedef struct } SHS_SETTINGS; #define _mbg_swab_shs_settings( _p ) \ +do \ { \ _mbg_swab_nano_time( &(_p)->err_limit ); \ _mbg_swab_nano_time( &(_p)->warn_limit ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -15670,12 +17372,13 @@ typedef struct } SHS_INFO; #define _mbg_swab_shs_info( _p ) \ +do \ { \ _mbg_swab_shs_settings( &(_p)->settings ); \ _mbg_swab_nano_time( &(_p)->max_limit ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -15695,13 +17398,14 @@ typedef struct } SHS_STATUS; #define _mbg_swab_shs_status( _p ) \ +do \ { \ _mbg_swab_nano_time( &(_p)->time_diff ); \ _mbg_swab32( &(_p)->clk_status_1 ); \ _mbg_swab32( &(_p)->clk_status_2 ); \ _mbg_swab16( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -15768,11 +17472,6 @@ enum SHS_FLAG_MASKS * @{ */ /** - * @brief An identifier used to mark an XBP port unused - */ -#define XBP_PORT_RESERVED ( (uint8_t) -1 ) - -/** * @brief An XBP port specifier * * Each controller can provide up to 255 ports with numbers 0..254. @@ -15782,6 +17481,12 @@ typedef uint8_t XBP_PORT; /** + * @brief An identifier used to mark an XBP port unused + */ +#define XBP_PORT_RESERVED ( (XBP_PORT) -1 ) + + +/** * @brief Maximum XBP bus/controller cascading level * * Should be 7 so the total size of ::XBP_ADDR is 8 bytes. @@ -15801,6 +17506,8 @@ typedef struct } XBP_ADDR; +#define _mbg_swab_xbp_addr( _p ) _nop_macro_fnc() // only single bytes + /** @@ -15810,10 +17517,24 @@ typedef struct { uint32_t features; ///< Mask of XBP features, see ::XBP_FEAT_MASKS uint32_t flags; ///< XBP flags, currently not used - uint32_t reserved[4]; ///< reserved, currently not used + uint32_t reserved_0; ///< reserved, currently not used + uint32_t reserved_1; ///< reserved, currently not used + uint32_t reserved_2; ///< reserved, currently not used + uint32_t reserved_3; ///< reserved, currently not used } XBP_LIMITS; +#define _mbg_swab_xbp_limits( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->features ); \ + _mbg_swab32( &(_p)->flags ); \ + _mbg_swab32( &(_p)->reserved_0 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ +} while ( 0 ) + /** @@ -15852,6 +17573,14 @@ typedef struct } XBP_NODE_LIMITS; +#define _mbg_swab_xbp_node_limits( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->node_count ); \ + _mbg_swab32( &(_p)->reserved_0 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ +} while ( 0 ) + /** @@ -15893,6 +17622,17 @@ typedef struct } XBP_NODE_INFO; +#define _mbg_swab_xbp_node_info( _p ) \ +do \ +{ \ + _mbg_swab_xbp_addr( &(_p)->addr ); \ + _mbg_swab_receiver_info( &(_p)->ri ); \ + _mbg_swab8( &(_p)->state ); \ + _mbg_swab8( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->flags ); \ +} while ( 0 ) + + /** * @brief Information on an XBP node with specific index @@ -15906,6 +17646,14 @@ typedef struct } XBP_NODE_INFO_IDX; +#define _mbg_swab_xbp_node_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_xbp_node_info( &(_p)->node_info ); \ +} while ( 0 ) + + /** @} defgroup group_xbp */ @@ -16010,6 +17758,15 @@ enum MBG_TLV_FEAT_TYPES /// 1) ::MBG_TLV_TYPE_STR => Full qualified path including filename on target system MBG_TLV_FEAT_TYPE_FILE_REQUEST, + /// 1) ::MBG_TLV_TYPE_BLOB => ::MBG_LICENSE_PTPV1_IDX, see @ref group_license_limits + MBG_TLV_FEAT_TYPE_LICENSE_PTPV1_IDX, + + /// 1) ::MBG_TLV_TYPE_BLOB => ::MBG_LICENSE_TIME_MONITOR_IDX, see @ref group_license_limits + MBG_TLV_FEAT_TYPE_LICENSE_TIME_MONITOR_IDX, + + /// 1) ::MBG_TLV_TYPE_BLOB => Unified Firmware Update (UFU) file, see mbg_ufu.h + MBG_TLV_FEAT_TYPE_UFU, + N_MBG_TLV_FEAT_TYPES // NOTE If new TLV feature types are appended here then an appropriate // name string has to be appended to ::MBG_TLV_FEAT_TYPE_NAMES, and care must @@ -16034,9 +17791,12 @@ enum MBG_TLV_FEAT_TYPES "TLV Execute Command", \ "TLV License Upgrade", \ "TLV License Limits", \ - "TLV License PTPV2 IDX", \ - "TLV License NTP IDX", \ - "TLV File Request" \ + "TLV License PTPV2", \ + "TLV License NTP", \ + "TLV File Request", \ + "TLV License PTPV1 IDX", \ + "TLV License Time Monitor", \ + "TLV Unified Firmware Update" \ } @@ -16103,10 +17863,11 @@ typedef struct } MBG_TLV_INFO; #define _mbg_swab_tlv_info( _p ) \ +do \ { \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -16147,12 +17908,13 @@ typedef struct } MBG_TLV_DATA; #define _mbg_swab_tlv_data( _p ) \ +do \ { \ _mbg_swab_tlv_uid( &(_p)->uid ); \ _mbg_swab_tlv_type( &(_p)->type ); \ _mbg_swab32( &(_p)->total_bytes ); \ _mbg_swab32( &(_p)->reserved_1 ); \ -} +} while ( 0 ) @@ -16186,11 +17948,12 @@ typedef struct } MBG_TLV_ANNOUNCE; #define _mbg_swab_tlv_announce( _p ) \ +do \ { \ _mbg_swab_tlv_data( &(_p)->data ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -16213,17 +17976,18 @@ typedef struct } MBG_TLV_HDR; -#define _mbg_swab_tlv_header( _p ) \ -{ \ - _mbg_swab32( &(_p)->id ); \ - _mbg_swab32( &(_p)->type ); \ - _mbg_swab32( &(_p)->cur_bytes ); \ - _mbg_swab32( &(_p)->trans_bytes ); \ - _mbg_swab32( &(_p)->total_bytes ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->reserved_3 ); \ -} +#define _mbg_swab_tlv_header( _p ) \ +do \ +{ \ + _mbg_swab_tlv_uid( &(_p)->uid ); \ + _mbg_swab_tlv_type( &(_p)->tlv_type ); \ + _mbg_swab32( &(_p)->cur_bytes ); \ + _mbg_swab32( &(_p)->trans_bytes ); \ + _mbg_swab32( &(_p)->total_bytes ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ +} while ( 0 ) @@ -16238,9 +18002,10 @@ typedef struct } MBG_TLV; #define _mbg_swab_tlv( _p ) \ +do \ { \ _mbg_swab_tlv_header( &(_p)->hdr ); \ -} +} while ( 0 ) /** @} defgroup group_tlv_api */ @@ -16407,6 +18172,7 @@ typedef struct } UTC; #define _mbg_swab_utc_parm( _p ) \ +do \ { \ _mbg_swab_csum( &(_p)->csum ); \ _mbg_swab16( &(_p)->valid ); \ @@ -16415,7 +18181,7 @@ typedef struct _mbg_swab_double( &(_p)->A1 ); \ _mbg_swab16( &(_p)->WNlsf ); \ _mbg_swab16( &(_p)->DNt ); \ -} +} while ( 0 ) @@ -16533,7 +18299,7 @@ typedef struct /** - * @defgroup group_led_api Meinberg TLV API definitions + * @defgroup group_led_api Meinberg LED API definitions * * @note These structures and definitions are only supported by a device * if ::MBG_XFEATURE_LED_API is set in the extended device features. @@ -16562,12 +18328,13 @@ typedef struct } MBG_LED_LIMITS; #define _mbg_swab_mbg_led_limits( _p ) \ +do \ { \ _mbg_swab8( &(_p)->num_leds ); \ _mbg_swab8( &(_p)->reserved_0 ); \ _mbg_swab16( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -16692,11 +18459,12 @@ typedef struct } MBG_LED_SETTINGS; #define _mbg_swab_mbg_led_settings( _p ) \ +do \ { \ _mbg_swab8( &(_p)->mode ); \ _mbg_swab8( &(_p)->color ); \ _mbg_swab16( &(_p)->reserved ); \ -} +} while ( 0 ) @@ -16714,10 +18482,11 @@ typedef struct } MBG_LED_SETTINGS_IDX; #define _mbg_swab_mbg_led_settings_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_mbg_led_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -16741,13 +18510,14 @@ typedef struct } MBG_LED_INFO; #define _mbg_swab_mbg_led_info( _p ) \ +do \ { \ _mbg_swab_mbg_led_settings( &(_p)->settings ); \ _mbg_swab32( &(_p)->supp_modes ); \ _mbg_swab32( &(_p)->supp_colors ); \ _mbg_swab32( &(_p)->reserved ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -16765,10 +18535,11 @@ typedef struct } MBG_LED_INFO_IDX; #define _mbg_swab_mbg_led_info_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_mbg_led_info( &(_p)->info ); \ -} +} while ( 0 ) /** @} defgroup group_led_api */ @@ -16806,13 +18577,14 @@ typedef struct } MBG_LNE_LIMITS; #define _mbg_swab_mbg_lne_limits( _p ) \ +do \ { \ _mbg_swab8( &(_p)->num_ports ); \ _mbg_swab8( &(_p)->reserved_0 ); \ _mbg_swab16( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->features ); \ _mbg_swab32( &(_p)->reserved_2 ); \ -} +} while ( 0 ) @@ -16864,12 +18636,13 @@ typedef struct } MBG_LNE_PORT_SETTINGS; #define _mbg_swab_mbg_lne_port_settings( _p ) \ +do \ { \ _mbg_swab32( &(_p)->reserved_0 ); \ _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -16887,10 +18660,11 @@ typedef struct } MBG_LNE_PORT_SETTINGS_IDX; #define _mbg_swab_mbg_lne_port_settings_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_mbg_lne_port_settings( &(_p)->settings ); \ -} +} while ( 0 ) @@ -16915,6 +18689,7 @@ typedef struct } MBG_LNE_PORT_INFO; #define _mbg_swab_mbg_lne_port_info( _p ) \ +do \ { \ _mbg_swab_mbg_lne_port_settings( &(_p)->settings ); \ _mbg_swab_mbg_mac_addr( &(_p)->mac_addr ); \ @@ -16922,7 +18697,7 @@ typedef struct _mbg_swab32( &(_p)->reserved_1 ); \ _mbg_swab32( &(_p)->reserved_2 ); \ _mbg_swab32( &(_p)->flags ); \ -} +} while ( 0 ) @@ -16940,10 +18715,11 @@ typedef struct } MBG_LNE_PORT_INFO_IDX; #define _mbg_swab_mbg_lne_port_info_idx( _p ) \ +do \ { \ _mbg_swab16( &(_p)->idx ); \ _mbg_swab_mbg_lne_port_info( &(_p)->info ); \ -} +} while ( 0 ) @@ -17016,11 +18792,12 @@ typedef struct } MBG_PWR_CTL; #define _mbg_swab_mbg_pwr_ctl( _p ) \ +do \ { \ _mbg_swab8( &(_p)->state ); \ _mbg_swab8( &(_p)->reserved_0 ); \ _mbg_swab16( &(_p)->reserved_1 ); \ -} +} while ( 0 ) /** @} defgroup group_pwr_ctl_api */ @@ -17152,19 +18929,20 @@ typedef struct } MBG_EXT_SYS_INFO; -#define _mbg_swab_ext_sys_info( _p) \ -{ \ - _mbg_swab32( &(_p)->supp_members ); \ - _mbg_swab32( &(_p)->sw_rev ); \ - _mbg_swab32( &(_p)->hw_rev ); \ - _mbg_swab32( &(_p)->os_rev ); \ - _mbg_swab32( &(_p)->fpga_rev ); \ - _mbg_swab16( &(_p)->proc_type ); \ - _mbg_swab16( &(_p)->fpga_type ); \ - _mbg_swab16( &(_p)->core_mod_type ); \ - _mbg_swab16( &(_p)->reserved ); \ - _mbg_swab32( &(_p)->core_mod_rev ); \ -} +#define _mbg_swab_ext_sys_info( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_members ); \ + _mbg_swab32( &(_p)->sw_rev ); \ + _mbg_swab32( &(_p)->hw_rev ); \ + _mbg_swab32( &(_p)->os_rev ); \ + _mbg_swab32( &(_p)->fpga_rev ); \ + _mbg_swab16( &(_p)->proc_type ); \ + _mbg_swab16( &(_p)->fpga_type ); \ + _mbg_swab16( &(_p)->core_mod_type ); \ + _mbg_swab16( &(_p)->reserved ); \ + _mbg_swab32( &(_p)->core_mod_rev ); \ +} while ( 0 ) #define _mbg_encode_revision( _major, _minor, _patch ) \ @@ -17185,8 +18963,7 @@ typedef struct /** * @defgroup group_license_limits License information * - * @note This structure and its definitions are only supported by a device - * if ::MBG_XFEATURE_LICENSE_LIMITS is set in the extended device features. + * @note This is probably obsolete. * * @{ */ @@ -17215,6 +18992,8 @@ enum MBG_LICENSE_BASE_TYPES { MBG_LICENSE_BASE_TYPE_PTPV2, MBG_LICENSE_BASE_TYPE_NTP, + MBG_LICENSE_BASE_TYPE_PTPV1, + MBG_LICENSE_BASE_TYPE_TIME_MONITOR, N_MBG_LICENSE_BASE_TYPES }; @@ -17260,10 +19039,11 @@ typedef struct } MBG_LICENSE_BASE; -#define _mbg_swab_license_base( _p) \ -{ \ - _mbg_swab32( &(_p)->supp_flags ); \ -} +#define _mbg_swab_license_base( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_flags ); \ +} while ( 0 ) /** @@ -17312,13 +19092,14 @@ typedef struct } MBG_LICENSE_PTPV2; -#define _mbg_swab_license_ptpv2( _p) \ -{ \ - _mbg_swab_license_base( &(_p)->base ); \ - _mbg_swab32( &(_p)->supp_members ); \ - _mbg_swab16( &(_p)->max_uclients ); \ - _mbg_swab32( &(_p)->max_mtrans ); \ -} +#define _mbg_swab_license_ptpv2( _p ) \ +do \ +{ \ + _mbg_swab_license_base( &(_p)->base ); \ + _mbg_swab32( &(_p)->supp_members ); \ + _mbg_swab16( &(_p)->max_uclients ); \ + _mbg_swab32( &(_p)->max_mtrans ); \ +} while ( 0 ) typedef struct @@ -17328,11 +19109,12 @@ typedef struct } MBG_LICENSE_PTPV2_IDX; -#define _mbg_swab_license_ptpv2_idx( _p) \ -{ \ - _mbg_swab_license_ptpv2( &(_p)->license ); \ - _mbg_swab32( &(_p)->idx ); \ -} +#define _mbg_swab_license_ptpv2_idx( _p ) \ +do \ +{ \ + _mbg_swab_license_ptpv2( &(_p)->license ); \ + _mbg_swab32( &(_p)->idx ); \ +} while ( 0 ) /** @@ -17367,7 +19149,7 @@ typedef struct { MBG_LICENSE_BASE base; ///< See ::MBG_LICENSE_BASE uint32_t supp_members; ///< See ::MBG_LICENSE_NTP_MEMBER_MSKS - uint32_t max_rps; ///< Maximum number of supported requests per second + uint32_t max_rps; ///< Maximum number of supported NTP requests per second uint32_t reserved_1; ///< Reserved for future use, currently 0 uint32_t reserved_2; ///< Reserved for future use, currently 0 uint32_t reserved_3; ///< Reserved for future use, currently 0 @@ -17377,12 +19159,14 @@ typedef struct } MBG_LICENSE_NTP; -#define _mbg_swab_license_ntp( _p) \ -{ \ - _mbg_swab_license_base( &(_p)->base ); \ - _mbg_swab32( &(_p)->supp_members ); \ - _mbg_swab32( &(_p)->max_rps ); \ -} +#define _mbg_swab_license_ntp( _p ) \ +do \ +{ \ + _mbg_swab_license_base( &(_p)->base ); \ + _mbg_swab32( &(_p)->supp_members ); \ + _mbg_swab32( &(_p)->max_rps ); \ +} while ( 0 ) + typedef struct @@ -17392,11 +19176,147 @@ typedef struct } MBG_LICENSE_NTP_IDX; -#define _mbg_swab_license_ntp_idx( _p) \ +#define _mbg_swab_license_ntp_idx( _p ) \ +do \ { \ _mbg_swab_license_ntp( &(_p)->license ); \ _mbg_swab32( &(_p)->idx ); \ -} +} while ( 0 ) + +/** + * @brief Bits used to define ::MBG_LICENSE_PTPV1_MEMBER_MSKS + * + * @see ::MBG_LICENSE_PTPV1_MEMBER_MSKS + */ +enum MBG_LICENSE_PTPV1_MEMBERS +{ + MBG_LICENSE_PTPV1_MEMBER_MAX_RPS, + N_MBG_LICENSE_PTPV1_MEMBERS +}; + + +/** + * @brief Bit masks of PTPV1 license specific members + * + * Used with ::MBG_LICENSE_PTPV1::supp_members + * + * @see ::MBG_LICENSE_PTPV2_MEMBERS + */ +enum MBG_LICENSE_PTPV1_MEMBER_MSKS +{ + MBG_LICENSE_PTPV1_MEMBER_MSK_MAX_RPS = ( 1UL << MBG_LICENSE_PTPV1_MEMBER_MAX_RPS ) ///< See ::MBG_LICENSE_PTPV1_MEMBER_MAX_RPS +}; + + +/** + * @brief NTP specific license information + */ +typedef struct +{ + MBG_LICENSE_BASE base; ///< See ::MBG_LICENSE_BASE + uint32_t supp_members; ///< See ::MBG_LICENSE_PTPV1_MEMBER_MSKS + uint32_t max_rps; ///< Maximum number of supported PTPv1 delay requests per second + uint32_t reserved_1; ///< Reserved for future use, currently 0 + uint32_t reserved_2; ///< Reserved for future use, currently 0 + uint32_t reserved_3; ///< Reserved for future use, currently 0 + uint32_t reserved_4; ///< Reserved for future use, currently 0 + uint32_t reserved_5; ///< Reserved for future use, currently 0 + uint32_t reserved_6; ///< Reserved for future use, currently 0 + +} MBG_LICENSE_PTPV1; + +#define _mbg_swab_license_ptpv1( _p ) \ +do \ +{ \ + _mbg_swab_license_base( &(_p)->base ); \ + _mbg_swab32( &(_p)->supp_members ); \ + _mbg_swab32( &(_p)->max_rps ); \ +} while ( 0 ) + + +typedef struct +{ + uint32_t idx; + MBG_LICENSE_PTPV1 license; + +} MBG_LICENSE_PTPV1_IDX; + +#define _mbg_swab_license_ptpv1_idx( _p ) \ +do \ +{ \ + _mbg_swab_license_ptpv1( &(_p)->license ); \ + _mbg_swab32( &(_p)->idx ); \ +} while ( 0 ) + +/** + * @brief Bits used to define ::MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS + * + * @see ::MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS + */ +enum MBG_LICENSE_TIME_MONITOR_MEMBERS +{ + MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS, + MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS, + N_MBG_LICENSE_TIME_MONITOR_MEMBERS +}; + + +/** + * @brief Bit masks of Time Monitor license specific members + * + * Used with ::MBG_LICENSE_TIME_MONITOR::supp_members + * + * @see ::MBG_LICENSE_TIME_MONITOR_MEMBERS + */ +enum MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS +{ + MBG_LICENSE_TIME_MONITOR_MEMBER_MSK_MAX_PTPV2_CLIENTS = ( 1UL << MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS ), ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_PTPV2_CLIENTS + MBG_LICENSE_TIME_MONITOR_MEMBER_MSK_MAX_NTP_CLIENTS = ( 1UL << MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS ) ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MAX_NTP_CLIENTS +}; + + +/** + * @brief Time Monitor specific license information + * + */ +typedef struct +{ + MBG_LICENSE_BASE base; ///< See ::MBG_LICENSE_BASE + uint32_t supp_members; ///< See ::MBG_LICENSE_TIME_MONITOR_MEMBER_MSKS + uint32_t reserved_1; ///< Reserved for future use, currently 0 + uint16_t max_ptpv2_clients; ///< Maximum number of supported PTPv2 clients to be monitored + uint16_t max_ntp_clients; ///< Maximum number of supported NTP clients to be monitored + uint32_t reserved_2; ///< Reserved for future use, currently 0 + uint32_t reserved_3; ///< Reserved for future use, currently 0 + uint32_t reserved_4; ///< Reserved for future use, currently 0 + uint32_t reserved_5; ///< Reserved for future use, currently 0 + uint32_t reserved_6; ///< Reserved for future use, currently 0 + +} MBG_LICENSE_TIME_MONITOR; + +#define _mbg_swab_license_time_monitor( _p ) \ +do \ +{ \ + _mbg_swab_license_base( &(_p)->base ); \ + _mbg_swab32( &(_p)->supp_members ); \ + _mbg_swab16( &(_p)->max_ptpv2_clients ); \ + _mbg_swab16( &(_p)->max_ntp_clients ); \ +} while ( 0 ) + + +typedef struct +{ + uint32_t idx; + MBG_LICENSE_TIME_MONITOR license; + +} MBG_LICENSE_TIME_MONITOR_IDX; + +#define _mbg_swab_license_time_monitor_idx( _p ) \ +do \ +{ \ + _mbg_swab_license_time_monitor( &(_p)->license ); \ + _mbg_swab32( &(_p)->idx ); \ +} while ( 0 ) /** @} defgroup group_license_limits */ @@ -17432,21 +19352,22 @@ typedef struct } MBG_CLK_RES_INFO; -#define _mbg_swab_mbg_clk_res_info( _p) \ -{ \ - _mbg_swab32( &(_p)->base_clk ); \ - _mbg_swab32( &(_p)->num_clk_phase ); \ - _mbg_swab32( &(_p)->reserved_9 ); \ - _mbg_swab32( &(_p)->reserved_8 ); \ - _mbg_swab32( &(_p)->reserved_7 ); \ - _mbg_swab32( &(_p)->reserved_6 ); \ - _mbg_swab32( &(_p)->reserved_5 ); \ - _mbg_swab32( &(_p)->reserved_4 ); \ - _mbg_swab32( &(_p)->reserved_3 ); \ - _mbg_swab32( &(_p)->reserved_2 ); \ - _mbg_swab32( &(_p)->reserved_1 ); \ - _mbg_swab32( &(_p)->reserved_0 ); \ -} +#define _mbg_swab_mbg_clk_res_info( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->base_clk ); \ + _mbg_swab32( &(_p)->num_clk_phase ); \ + _mbg_swab32( &(_p)->reserved_9 ); \ + _mbg_swab32( &(_p)->reserved_8 ); \ + _mbg_swab32( &(_p)->reserved_7 ); \ + _mbg_swab32( &(_p)->reserved_6 ); \ + _mbg_swab32( &(_p)->reserved_5 ); \ + _mbg_swab32( &(_p)->reserved_4 ); \ + _mbg_swab32( &(_p)->reserved_3 ); \ + _mbg_swab32( &(_p)->reserved_2 ); \ + _mbg_swab32( &(_p)->reserved_1 ); \ + _mbg_swab32( &(_p)->reserved_0 ); \ +} while ( 0 ) /** @} defgroup group_clk_res_info */ @@ -17475,9 +19396,1797 @@ enum MBG_TRANSACTION_TYPES */ MBG_TRANSACTION_TYPE_NETWORK, MBG_TRANSACTION_TYPE_PTP, + /* + * Commands in any order if supp. by ::MBG_SNMP_GLB_INFO::max_[...] + * and ::MBG_SNMP_GLB_INFO::supp_versions + * + * Should be used within ::MBG_TRANSACTION_TYPE_MONITORING but may also be + * used stand-alone. + * + * - ::GPS_SNMP_GLB_SETTINGS + * - ::GPS_SNMP_V12_SETTINGS_IDX + * - ::GPS_SNMP_V12_TRAP_SETTINGS_IDX + * - ::GPS_SNMP_V3_SETTINGS_IDX + * - ::GPS_SNMP_V3_TRAP_SETTINGS_IDX + */ + MBG_TRANSACTION_TYPE_MONITORING_SNMP, + /* + * NTP transaction requires at least and as first command: + * ::GPS_NTP_GLB_CFG + * Commands in any order if supp. by ::MBG_NTP_GLB_INFO + * and ::MBG_SNMP_GLB_INFO::supp_versions + * + * - ::GPS_NTP_REFCLK_CFG + * - ::GPS_NTP_MISC_LIMITS + * - ::GPS_NTP_MISC_ORPHAN_MODE + * - ::GPS_NTP_SYMM_KEY_LIMITS + * - ::GPS_NTP_SYMM_KEY_CFG + * - ::GPS_NTP_TRUSTED_KEY_CFG + * - ::GPS_NTP_CLNT_MODE_CFG + * - ::GPS_NTP_SRV_MODE_CFG + * - ::GPS_NTP_PEER_SETTINGS_IDX + * - ::GPS_NTP_SYS_STATE + * - ::GPS_NTP_PEER_STATE_IDX + */ + MBG_TRANSACTION_TYPE_NTP, + /* + * IO Port transaction used to read or write ALL_IO_PORT_INFO + * Commands related to this transaction: + * + * - ::GPS_IO_PORT_LIMITS + * - ::GPS_IO_PORT_SETTINGS_IDX + * - ::GPS_IO_PORT_INFO_IDX + * - ::GPS_IO_PORT_TYPE_INFO_IDX + * - ::GPS_IO_PORT_STATUS_IDX + */ + MBG_TRANSACTION_TYPE_IO_PORT, + /* + * Commands in any order if ::MBG_XFEATURE_MONITORING is set in + * ::MBG_XFEATURE_BUFFER. + * + * Transactions ::MBG_TRANSACTION_TYPE_MONITORING_SNMP and + * ::MBG_TRANSACTION_TYPE_EVENTS may also be opened within + * ::MBG_TRANSACTION_TYPE_MONITORING transaction. + * + * - ::GPS_MONITORING_LIMITS + * - ::GPS_MONITORING_STATUS + */ + MBG_TRANSACTION_TYPE_MONITORING, + /* + * Commands in any order if ::MBG_XFEATURE_MONITORING is set in + * ::MBG_XFEATURE_BUFFER. + * + * Should be used within ::MBG_TRANSACTION_TYPE_MONITORING but may also be + * used stand-alone. + * + * - ::GPS_EVENT_IDX + * - ::GPS_EVENT_STAT_IDX + */ + MBG_TRANSACTION_TYPE_EVENTS, + MAX_MBG_TRANSACTION_TYPES }; + +#define MBG_TRANSACTION_MSK_SET 0x8000 +#define _mbg_is_set_transaction( _type ) ( ( _type ) & MBG_TRANSACTION_MSK_SET ) +#define _mbg_transaction_type_set( _type ) ( ( _type ) |= MBG_TRANSACTION_MSK_SET ) + + +/** + * @defgroup group_io_ports IO Port API + * + * @note This structure and its definitions are only supported by a device + * if ::MBG_XFEATURE_IO_PORTS is set in the extended device features. + * + * @{ */ + +/** + * @brief IO Port types + * + * Used with ::MBG_IO_PORT_TYPE_INFO::port_type and ::MBG_IO_PORT_SETTINGS::port_type + */ +enum MBG_IO_PORT_TYPES +{ + MBG_IO_PORT_TYPE_PPS, + MBG_IO_PORT_TYPE_10MHz, + MBG_IO_PORT_TYPE_2048KHz, + MBG_IO_PORT_TYPE_GPIO, + MBG_IO_PORT_TYPE_ETHERNET, + MBG_IO_PORT_TYPE_TERMINAL, + MBG_IO_PORT_TYPE_MULTI, + MBG_IO_PORT_TYPE_POUT, + N_MBG_IO_PORT_TYPES +}; + +/** + * @brief Port type to be used for an undefined/unassigned port + * + * Only use this for ::MBG_IO_PORT_SETTINGS::port_type + * if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE + */ +#define MBG_IO_PORT_TYPE_NONE ( (uint16_t) -1 ) + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_TYPES + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_TYPES entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_TYPES. + * + * @see ::MBG_IO_PORT_TYPES + */ +#define MBG_IO_PORT_TYPE_STRS \ +{ \ + "PPS", \ + "10 MHz", \ + "2048 KHz", \ + "GPIO", \ + "Ethernet", \ + "Terminal", \ + "Multi", \ + "Prog. Output" \ +} + + +/** + * @brief Port directions (input or output) + * + * @see ::MBG_IO_PORT_DIR_MSKS + */ +enum MBG_IO_PORT_DIRS +{ + MBG_IO_PORT_DIR_NONE = -1, ///< Only use this for ::MBG_IO_PORT_SETTINGS::direction if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE + MBG_IO_PORT_DIR_IN, ///< Port is input like PPS In + MBG_IO_PORT_DIR_OUT, ///< Port is output like 10Mhz + MBG_IO_PORT_DIR_IN_OUT, ///< Port can be in- & output in parallel like network port + N_MBG_IO_PORT_DIRS +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_DIRS + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_DIRS entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_DIRS. + * + * @see ::MBG_IO_PORT_DIRS + */ +#define MBG_IO_PORT_DIR_STRS \ +{ \ + "Input", \ + "Output", \ + "Input/Output" \ +} + + +/** + * @brief Bit masks of Meinberg I/O port directions + * + * Used with ::MBG_IO_PORT_TYPE_INFO::supp_dirs + * + * @see ::MBG_IO_PORT_DIRS + */ +enum MBG_IO_PORT_DIR_MSKS +{ + MBG_IO_PORT_MSK_DIR_IN = ( 1UL << MBG_IO_PORT_DIR_IN ), ///< See ::MBG_IO_PORT_DIR_IN + MBG_IO_PORT_MSK_DIR_OUT = ( 1UL << MBG_IO_PORT_DIR_OUT ), ///< See ::MBG_IO_PORT_DIR_OUT + MBG_IO_PORT_MSK_DIR_IN_OUT = ( 1UL << MBG_IO_PORT_DIR_IN_OUT ) ///< See ::MBG_IO_PORT_DIR_IN_OUT +}; + + +/** + * @brief Port type sources + * + * Configurable sources for an I/O port type + * + * @see ::MBG_IO_PORT_SRC_MSKS + */ +enum MBG_IO_PORT_SRCS +{ + MBG_IO_PORT_SRC_NONE = -1, ///< Only use this for ::MBG_IO_PORT_SETTINGS::source if ::MBG_IO_PORT_SETTINGS::op_mode is ::MBG_IO_PORT_OP_MODE_NONE + MBG_IO_PORT_SRC_STATIC, ///< Static, not configurable + MBG_IO_PORT_SRC_LOCAL, ///< Locally generated, e.g. on (carrier) board + MBG_IO_PORT_SRC_ASSOC_CLOCK, ///< Fixed (wired) clock from back plane (e.g. refclock 1 in M500 IMS) + MBG_IO_PORT_SRC_ACTIVE_CLOCK, ///< Switched clock from back plane (e.g. selected by RSC) + MBG_IO_PORT_SRC_CLK1, ///< Clock 1 fixed (CPU board only) + MBG_IO_PORT_SRC_CLK2, ///< Clock 2 fixed (CPU board only) + MBG_IO_PORT_SRC_ARC, ///< Any rate converter + MBG_IO_PORT_SRC_OSC, ///< Oscillator + MBG_IO_PORT_SRC_SYNCE, ///< SyncE + N_MBG_IO_PORT_SRCS +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_SRCS + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_SRCS entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_SRCS. + * + * @see ::MBG_IO_PORT_SRCS + */ +#define MBG_IO_PORT_SRC_STRS \ +{ \ + "Static", \ + "Locally generated", \ + "Associated clock", \ + "Active clock", \ + "Clock 1 fixed", \ + "Clock 2 fixed", \ + "Any rate converter", \ + "Oscillator", \ + "SyncE" \ +} + + +/** + * @brief Bit masks of Meinberg I/O port attitudes + * + * Used with ::MBG_IO_PORT_TYPE_INFO::supp_srcs + * + * @see ::MBG_IO_PORT_SRCS + */ +enum MBG_IO_PORT_SRC_MSKS +{ + MBG_IO_PORT_SRC_MSK_STATIC = (1UL << MBG_IO_PORT_SRC_STATIC), ///< See ::MBG_IO_PORT_SRC_STATIC + MBG_IO_PORT_SRC_MSK_LOCAL = (1UL << MBG_IO_PORT_SRC_LOCAL), ///< See ::MBG_IO_PORT_SRC_LOCAL + MBG_IO_PORT_SRC_MSK_ASSOC_CLOCK = (1UL << MBG_IO_PORT_SRC_ASSOC_CLOCK), ///< See ::MBG_IO_PORT_SRC_ASSOC_CLOCK + MBG_IO_PORT_SRC_MSK_ACTIVE_CLOCK = (1UL << MBG_IO_PORT_SRC_ACTIVE_CLOCK), ///< See ::MBG_IO_PORT_SRC_ACTIVE_CLOCK + MBG_IO_PORT_SRC_MSK_CLK1 = (1UL << MBG_IO_PORT_SRC_CLK1), ///< See ::MBG_IO_PORT_SRC_CLK1 + MBG_IO_PORT_SRC_MSK_CLK2 = (1UL << MBG_IO_PORT_SRC_CLK2), ///< See ::MBG_IO_PORT_SRC_CLK2 + MBG_IO_PORT_SRC_MSK_ARC = (1UL << MBG_IO_PORT_SRC_ARC), ///< See ::MBG_IO_PORT_SRC_ARC + MBG_IO_PORT_SRC_MSK_OSC = (1UL << MBG_IO_PORT_SRC_OSC), ///< See ::MBG_IO_PORT_SRC_OSC + MBG_IO_PORT_SRC_MSK_SYNCE = (1UL << MBG_IO_PORT_SRC_SYNCE) ///< See ::MBG_IO_PORT_SRC_SYNCE +}; + + +/** + * @brief Port connector types + * + * Used with ::MBG_IO_PORT_INFO::conn_type + * + */ +enum MBG_IO_PORT_CONN_TYPES +{ + MBG_IO_PORT_CONN_TYPE_SMA, + MBG_IO_PORT_CONN_TYPE_BNC, + MBG_IO_PORT_CONN_TYPE_DSUB25, + MBG_IO_PORT_CONN_TYPE_RJ45, + MBG_IO_PORT_CONN_TYPE_SFP, + MBG_IO_PORT_CONN_TYPE_USB_MICRO_B, + MBG_IO_PORT_CONN_TYPE_USB_A, + MBG_IO_PORT_CONN_TYPE_USB_B, + MBG_IO_PORT_CONN_TYPE_SMA_ANT, + MBG_IO_PORT_CONN_TYPE_RJ45_ETH, + MBG_IO_PORT_CONN_TYPE_2_PIN_DFK, + MBG_IO_PORT_CONN_TYPE_3_PIN_DFK, + MBG_IO_PORT_CONN_TYPE_16_PIN_DFK, + MBG_IO_PORT_CONN_TYPE_BNC_ISO, + MBG_IO_PORT_CONN_TYPE_DSUB9, + MBG_IO_PORT_CONN_TYPE_FIBRE_ST, + MBG_IO_PORT_CONN_TYPE_XHE_SPI, + N_MBG_IO_PORT_CONN_TYPES +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_CONN_TYPES + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_CONN_TYPES entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_CONN_TYPES. + * + * @see ::MBG_IO_PORT_CONN_TYPES + */ +#define MBG_IO_PORT_CONN_TYPE_STRS \ +{ \ + "SMA", \ + "BNC", \ + "D-Sub 25", \ + "RJ45", \ + "SFP", \ + "USB Micro B", \ + "USB A", \ + "USB B", \ + "SMA Antenna", \ + "RJ45 Ethernet", \ + "DFK 2-Pin", \ + "DFK 3-Pin", \ + "DFK 16-Pin", \ + "BNC isolated", \ + "D-Sub 9", \ + "Fibre ST", \ + "XHE SPI" \ +} + + +/** + * @brief Position of a port on a card + * + * Used with ::MBG_IO_PORT_INFO::position + * + */ +enum MBG_IO_PORT_POS +{ + MBG_IO_PORT_POS_FRONT_COL_1, ///> Connector column 1, front + MBG_IO_PORT_POS_REAR_COL_1, ///> Connector column 1, rear + MBG_IO_PORT_POS_FRONT_COL_2, ///> Connector column 2, front + MBG_IO_PORT_POS_REAR_COL_2, ///> Connector column 2, rear + MBG_IO_PORT_POS_FRONT_COL_3, ///> Connector column 3, front + MBG_IO_PORT_POS_REAR_COL_3, ///> Connector column 3, rear + MBG_IO_PORT_POS_FRONT_COL_4, ///> Connector column 4, front + MBG_IO_PORT_POS_REAR_COL_4, ///> Connector column 4, rear + N_MBG_IO_PORT_POS +}; + + +/** + * @brief Bit masks of Meinberg I/O port attitudes + * + * Used with ::MBG_IO_PORT_TYPE_INFO::supp_srcs + * + * @see ::MBG_IO_PORT_POS + */ +enum MBG_IO_PORT_POS_MSKS +{ + MBG_IO_PORT_POS_MSK_FRONT_COL_1 = (1UL << MBG_IO_PORT_POS_FRONT_COL_1), ///< See ::MBG_IO_PORT_POS_FRONT_COL_1 + MBG_IO_PORT_POS_MSK_REAR_COL_1 = (1UL << MBG_IO_PORT_POS_REAR_COL_1), ///< See ::MBG_IO_PORT_POS_REAR_COL_1 + MBG_IO_PORT_POS_MSK_FRONT_COL_2 = (1UL << MBG_IO_PORT_POS_FRONT_COL_2), ///< See ::MBG_IO_PORT_POS_FRONT_COL_2 + MBG_IO_PORT_POS_MSK_REAR_COL_2 = (1UL << MBG_IO_PORT_POS_REAR_COL_2), ///< See ::MBG_IO_PORT_POS_REAR_COL_2 + MBG_IO_PORT_POS_MSK_FRONT_COL_3 = (1UL << MBG_IO_PORT_POS_FRONT_COL_3), ///< See ::MBG_IO_PORT_POS_FRONT_COL_3 + MBG_IO_PORT_POS_MSK_REAR_COL_3 = (1UL << MBG_IO_PORT_POS_REAR_COL_3), ///< See ::MBG_IO_PORT_POS_REAR_COL_3 + MBG_IO_PORT_POS_MSK_FRONT_COL_4 = (1UL << MBG_IO_PORT_POS_FRONT_COL_4), ///< See ::MBG_IO_PORT_POS_FRONT_COL_4 + MBG_IO_PORT_POS_MSK_REAR_COL_4 = (1UL << MBG_IO_PORT_POS_REAR_COL_4) ///< See ::MBG_IO_PORT_POS_REAR_COL_4 +}; + + +/** + * @brief IO Port Limits + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef struct +{ + uint8_t num_ports; + uint8_t reserved_1[3]; ///< Reserved, currently 0 + uint32_t supp_positions; ///< Determines the size of the card (i.e. 2 rows, front/rear) See ::MBG_IO_PORT_POS_MSKS + uint32_t reserved_2[10]; ///< Reserved, currently 0 + +} MBG_IO_PORT_LIMITS; + +#define _mbg_swab_io_port_limits( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->supp_positions ); \ +} while ( 0 ) + + + +/** + * @brief Port Operation Bits + * + * Used with ::MBG_IO_PORT_SETTINGS::op_mode + * + * For now, there is a per port operation mode setting which + * is quite equal to ::ENABLE_FLAGS. + * + * @see ::MBG_IO_PORT_OP_MODE_MSKS + */ +enum MBG_IO_PORT_OP_MODE_BITS +{ + MBG_IO_PORT_OP_MODE_NONE = -1, ///< Current mode cannot be determined + MBG_IO_PORT_OP_MODE_DISABLED, ///< Disabled port + MBG_IO_PORT_OP_MODE_ALWAYS, ///< Always enable port + MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY, ///< Enable port if sync only + MBG_IO_PORT_OP_MODE_AFTER_SYNC, ///< Always enable port after being sync once + N_MBG_IO_PORT_OP_MODE_BITS +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_OP_MODE_BITS + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_OP_MODE_BITS entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_OP_MODE_BITS. + * + * @see ::MBG_IO_PORT_OP_MODE_BITS + */ +#define MBG_IO_PORT_OP_MODE_STRS \ +{ \ + "Disabled", \ + "Always enabled", \ + "If sync only", \ + "Always after sync" \ +} + + + +/** + * @brief Masks for ::MBG_IO_PORT_OP_MODE_BITS + * + * Used with ::MBG_IO_PORT_INFO::supp_op_modes + * + * @see ::MBG_IO_PORT_OP_MODE_BITS + */ +enum MBG_IO_PORT_OP_MODE_MSKS +{ + MBG_IO_PORT_OP_MODE_MSK_DISABLED = (1UL << MBG_IO_PORT_OP_MODE_DISABLED), ///< See ::MBG_IO_PORT_OP_MODE_DISABLED + MBG_IO_PORT_OP_MODE_MSK_ALWAYS = (1UL << MBG_IO_PORT_OP_MODE_ALWAYS), ///< See ::MBG_IO_PORT_OP_MODE_ALWAYS + MBG_IO_PORT_OP_MODE_MSK_IF_SYNC_ONLY = (1UL << MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY), ///< See ::MBG_IO_PORT_OP_MODE_IF_SYNC_ONLY + MBG_IO_PORT_OP_MODE_MSK_AFTER_SYNC = (1UL << MBG_IO_PORT_OP_MODE_AFTER_SYNC) ///< See ::MBG_IO_PORT_OP_MODE_AFTER_SYNC +}; + + +/** + * @brief Physical or logical group role bits + * + * Used with ::MBG_IO_PORT_STATUS::phys_grp_role, ::MBG_IO_PORT_STATUS::log_grp_role + * + * @see ::MBG_IO_PORT_GRP_ROLE_MSKS + */ +enum MBG_IO_PORT_GRP_ROLE_BITS +{ + MBG_IO_PORT_GRP_ROLE_NONE, ///< No group role, only possible if port is not assigned to any group + MBG_IO_PORT_GRP_ROLE_MASTER, ///< Master port in group, i.e. configurable port of LIU + MBG_IO_PORT_GRP_ROLE_SLAVE, ///< Slave port in group, i.e. non-configurable port of LIU + MBG_IO_PORT_GRP_ROLE_PASSIVE, ///< Passive port in group, i.e. passive port of network group (i.e. SFP or RJ45) + N_MBG_IO_PORT_GRP_ROLE_BITS +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_GRP_ROLE_BITS + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_GRP_ROLE_BITS entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_GRP_ROLE_BITS. + * + * @see ::MBG_IO_PORT_GRP_ROLE_BITS + */ +#define MBG_IO_PORT_GRP_ROLE_STRS \ +{ \ + "None", \ + "Master", \ + "Slave", \ + "Passive" \ +} + + +/** + * @brief Masks for ::MBG_IO_PORT_GRP_ROLE_BITS + * + * Used with ::MBG_IO_PORT_INFO::supp_phys_grp_roles + * + * @see ::MBG_IO_PORT_GRP_ROLE_BITS + */ +enum MBG_IO_PORT_GRP_ROLE_MSKS +{ + MBG_IO_PORT_GRP_ROLE_MSK_NONE = (1UL << MBG_IO_PORT_GRP_ROLE_NONE), ///< See ::MBG_IO_PORT_GRP_ROLE_NONE + MBG_IO_PORT_GRP_ROLE_MSK_MASTER = (1UL << MBG_IO_PORT_GRP_ROLE_MASTER), ///< See ::MBG_IO_PORT_GRP_ROLE_MASTER + MBG_IO_PORT_GRP_ROLE_MSK_SLAVE = (1UL << MBG_IO_PORT_GRP_ROLE_SLAVE), ///< See ::MBG_IO_PORT_GRP_ROLE_SLAVE + MBG_IO_PORT_GRP_ROLE_MSK_PASSIVE = (1UL << MBG_IO_PORT_GRP_ROLE_PASSIVE) ///< See ::MBG_IO_PORT_GRP_ROLE_PASSIVE +}; + + +/** + * @brief IO Port Settings Union + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef union +{ + MBG_GPIO_SETTINGS gpio_settings; + POUT_SETTINGS pout_settings; + +} MBG_IO_PORT_SETTINGS_U; + +#define _mbg_swab_io_port_settings_u( _type, _p, _recv ) \ +do \ +{ \ + switch ( (_type) ) \ + { \ + case MBG_IO_PORT_TYPE_GPIO: \ + _mbg_swab_mbg_gpio_settings( &(_p)->gpio_settings, (_recv) ); \ + break; \ + \ + case MBG_IO_PORT_TYPE_POUT: \ + if ( _recv ) \ + _mbg_swab_pout_settings_on_get( &(_p)->pout_settings ); \ + else _mbg_swab_pout_settings_on_set( &(_p)->pout_settings ); \ + break; \ + \ + default: break; \ + } \ +} while ( 0 ) + + +#define MBG_IO_PORT_SETTINGS_MIN_SIZE 32 + + +/** + * @brief IO Port Settings + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef struct +{ + uint16_t port_type; ///< ::MBG_IO_PORT_TYPES + uint8_t direction; ///< ::MBG_IO_PORT_DIRS + uint8_t source; ///< ::MBG_IO_PORT_SRCS + uint8_t op_mode; ///< ::MBG_IO_PORT_OP_MODE_BITS + uint8_t reserved_1[3]; ///< Future use and padding, currently 0 + uint32_t reserved_2[6]; ///< Future use and padding, currently 0 + + /* + * Struct members above represent minimum amount of data to be sent. + * See ::MBG_IO_PORT_SETTINGS_MIN_SIZE + */ + + MBG_IO_PORT_SETTINGS_U data; ///< Data union for settings' type + +} MBG_IO_PORT_SETTINGS; + +#define _mbg_swab_io_port_settings( _p, _recv ) \ +do \ +{ \ + uint16_t t = (_p)->port_type; \ + if ( (_recv) ) \ + _mbg_swab16( &t ); \ + _mbg_swab16( &(_p)->port_type ); \ + _mbg_swab_io_port_settings_u( t, &(_p)->data, (_recv) ); \ +} while ( 0 ) + + + + +/** + * @brief IO Port Settings Index + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + * + * Indexes from 0..::MBG_IO_PORT_LIMITS::num_ports - 1 are used + * to set ::MBG_IO_PORT_SETTINGS wrapped in ::MBG_IO_PORT_SETTINGS_IDX. + */ +typedef struct +{ + uint32_t idx; + MBG_IO_PORT_SETTINGS settings; + +} MBG_IO_PORT_SETTINGS_IDX; + +#define _mbg_swab_io_port_settings_idx( _p, _recv ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_io_port_settings( &(_p)->settings, (_recv) ); \ +} while ( 0 ) + + +#define MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE (MBG_IO_PORT_SETTINGS_MIN_SIZE + sizeof( uint32_t )) + + +#define MBG_IO_PORT_SETTINGS_IDX_SIZES \ +{ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_PPS */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_10MHz */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_2048KHz */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE + sizeof( MBG_GPIO_SETTINGS ), /* MBG_IO_PORT_TYPE_GPIO */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_ETHERNET */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_TERMINAL */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_MULTI */ \ + MBG_IO_PORT_SETTINGS_IDX_MIN_SIZE + sizeof( POUT_SETTINGS ) /* MBG_IO_PORT_TYPE_POUT */ \ +} + + +#define MBG_NO_PHYS_GROUP 0xFF +#define MBG_NO_LOG_GROUP 0xFF + +/** + * @brief IO Port Info + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef struct +{ + uint8_t num_types; ///< See ::MBG_IO_PORT_TYPE_INFO + uint8_t conn_type; ///< See ::MBG_IO_PORT_CONN_TYPES + uint8_t position; ///< See ::MBG_IO_PORT_POS + uint8_t reserved_1; ///< Future use and padding, currently 0 + uint16_t supp_op_modes; ///< See ::MBG_IO_PORT_OP_MODE_MSKS + uint16_t supp_phys_grp_roles; ///< Supported roles in ::MBG_IO_PORT_STATUS::phys_grp_role, see ::MBG_IO_PORT_GRP_ROLE_MSKS + uint8_t phys_grp; ///< Physical group number (i.e. SFP/RJ45 on HPS100), or ::MBG_NO_PHYS_GROUP + uint8_t reserved_2[3]; ///< Future use and padding, currently 0 + uint32_t reserved_3[8]; ///< Future use and padding, currently 0 + char rel_str[16]; ///< Indicates internal relation, i.e. "lan0", "fpga0" or "/dev/ttyS0" + MBG_IO_PORT_SETTINGS settings; ///< See ::MBG_IO_PORT_SETTINGS + +} MBG_IO_PORT_INFO; + +#define _mbg_port_has_phys_group( _p ) ( ( _p )->phys_grp != MBG_NO_PHYS_GROUP ) + +#define _mbg_swab_io_port_info( _p, _recv ) \ +do \ +{ \ + _mbg_swab16( &(_p)->supp_op_modes ); \ + _mbg_swab16( &(_p)->supp_phys_grp_roles ); \ + _mbg_swab_io_port_settings( &(_p)->settings, (_recv) ); \ +} while ( 0 ) + + + +#define MBG_IO_PORT_INFO_MIN_SIZE ( 60 + MBG_IO_PORT_SETTINGS_MIN_SIZE ) + + +/** + * @brief IO Port Info Index + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_U + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + * + * Indexes from 0..::MBG_IO_PORT_LIMITS::num_ports - 1 are used + * to query ::MBG_IO_PORT_INFO wrapped in ::MBG_IO_PORT_INFO_IDX. + */ +typedef struct +{ + uint32_t idx; + MBG_IO_PORT_INFO info; + +} MBG_IO_PORT_INFO_IDX; + +#define _mbg_swab_io_port_info_idx( _p, _recv ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_io_port_info( &(_p)->info, (_recv) ); \ +} while ( 0 ) + + + +#define MBG_IO_PORT_INFO_IDX_MIN_SIZE (MBG_IO_PORT_INFO_MIN_SIZE + sizeof( uint32_t )) + + +#define MBG_IO_PORT_INFO_IDX_SIZES \ +{ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_PPS */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_10MHz */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_2048KHz */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE + sizeof( MBG_GPIO_SETTINGS ), /* MBG_IO_PORT_TYPE_GPIO */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_ETHERNET */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_TERMINAL */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_MULTI */ \ + MBG_IO_PORT_INFO_IDX_MIN_SIZE + sizeof( POUT_SETTINGS ) /* MBG_IO_PORT_TYPE_POUT */ \ +} + + +/** + * @brief IO Port Type Info Union + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef union +{ + MBG_GPIO_LIMITS gpio_limits; + POUT_INFO pout_info; + +} MBG_IO_PORT_TYPE_INFO_U; + +#define _mbg_swab_io_port_type_info_u( _type, _p, _recv ) \ +do \ +{ \ + switch ( (_type) ) \ + { \ + case MBG_IO_PORT_TYPE_GPIO: \ + _mbg_swab_mbg_gpio_limits( &(_p)->gpio_limits, (_recv) ); \ + break; \ + \ + case MBG_IO_PORT_TYPE_POUT: \ + _mbg_swab_pout_info_on_get( &(_p)->pout_info ); \ + break; \ + \ + default: break; \ + } \ +} while ( 0 ) + + + +#define MBG_IO_PORT_TYPE_INFO_MIN_SIZE 32 + + +/** + * @brief IO Port Type Info + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_INFO_IDX + * @see ::MBG_IO_PORT_TYPE_INFO_U + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + */ +typedef struct +{ + uint16_t port_type; ///< See ::MBG_IO_PORT_TYPES + uint16_t reserved_1; ///< Future use and padding, currently 0 + uint8_t supp_dirs; ///< See ::MBG_IO_PORT_DIR_MSKS + uint8_t reserved_2[3]; ///< Future use and padding, currently 0 + uint32_t supp_srcs; ///< See ::MBG_IO_PORT_SRC_MSKS + uint32_t reserved_3[5]; ///< Future use and padding, currently 0 + + /* + * Struct members above represent minimum amount of data to be sent. + * See ::MBG_IO_PORT_TYPE_INFO_MIN_SIZE + */ + + MBG_IO_PORT_TYPE_INFO_U data; ///< Port type specific data + +} MBG_IO_PORT_TYPE_INFO; + +#define _mbg_swab_io_port_type_info( _p, _recv ) \ +do \ +{ \ + uint16_t t = (_p)->port_type; \ + if ( (_recv) ) \ + _mbg_swab16( &t ); \ + _mbg_swab16( &(_p)->port_type ); \ + _mbg_swab_io_port_type_info_u( t, &(_p)->data, (_recv) ); \ + _mbg_swab32( &(_p)->supp_srcs ); \ +} while ( 0 ) + + +#define MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE (MBG_IO_PORT_TYPE_INFO_MIN_SIZE + 2 * sizeof( uint32_t )) + + +#define MBG_IO_PORT_TYPE_INFO_IDX_SIZES \ +{ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_PPS */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_10MHz */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_2048KHz */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE + sizeof( MBG_GPIO_LIMITS ), /* MBG_IO_PORT_TYPE_GPIO */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_ETHERNET */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_TERMINAL */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE, /* MBG_IO_PORT_TYPE_MULTI */ \ + MBG_IO_PORT_TYPE_INFO_IDX_MIN_SIZE + sizeof( POUT_INFO ) /* MBG_IO_PORT_TYPE_POUT */ \ +} + + +/** + * @brief IO Port Type Info Index + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_U + * @see ::MBG_IO_PORT_STATUS + * @see ::MBG_IO_PORT_STATUS_IDX + * + * Indexes from 0..::MBG_IO_PORT_INFO::num_types - 1 are used + * to query ::MBG_IO_PORT_TYPE_INFO wrapped in ::MBG_IO_PORT_TYPE_INFO_IDX. + * + */ +typedef struct +{ + uint32_t port_idx; + uint32_t port_type_idx; + MBG_IO_PORT_TYPE_INFO info; + +} MBG_IO_PORT_TYPE_INFO_IDX; + +#define _mbg_swab_io_port_type_info_idx( _p, _recv ) \ +do \ +{ \ + _mbg_swab32( &(_p)->port_idx ); \ + _mbg_swab32( &(_p)->port_type_idx ); \ + _mbg_swab_io_port_type_info( &(_p)->info, (_recv) ); \ +} while ( 0 ) + + + +#define MAX_IO_PORT_STATUS_BITS 64 + + +/** + * @brief Port Type Status Bits + * + */ +enum MBG_IO_PORT_STATUS_BITS +{ + MBG_IO_PORT_STATUS_BIT_DISABLED, ///< See ::MBG_IO_PORT_OP_MODE_DISABLED. Other bits should be 0 in this case + MBG_IO_PORT_STATUS_BIT_CARRIER_DETECTED, ///< Port has physical carrier connection (e.g. BNC cable in BPE's case) + MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_NEVER_AVAIL, ///< Input signal has NEVER been avail + MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_AVAIL, ///< Input signal is avail right now + MBG_IO_PORT_STATUS_BIT_INPUT_SIGNAL_LOST, ///< Input signal is currently not avail, but has been avail before + MBG_IO_PORT_STATUS_BIT_SHORT_CIRCUIT, ///< Short circuit + N_MBG_IO_PORT_STATUS_BITS +}; + + +/** + * @brief Strings descriptions for ::MBG_IO_PORT_STATUS_BITS + * + * Can be used to initialize a string array of ::N_MBG_IO_PORT_STATUS_BITS entries, + * so the number of strings must correspond to ::N_MBG_IO_PORT_STATUS_BITS. + * + * @see ::MBG_IO_PORT_STATUS_BITS + */ +#define MBG_IO_PORT_STATUS_STRS \ +{ \ + "Disabled", \ + "Carrier detected", \ + "Input signal has never been avail", \ + "Input signal is avail", \ + "Input signal is currently lost", \ + "Short circuit" \ +} + + +/** + * @brief Array size required to store all status bits + * + * The number of bytes required to store up to ::MAX_IO_PORT_STATUS_BITS + * feature bits in a byte array. + */ +#define MAX_IO_PORT_STATUS_BYTES ( MAX_IO_PORT_STATUS_BITS / 8 ) + + +/** + * @brief A structure used to store port status bits + * + * Up to ::MAX_IO_PORT_STATUS_BITS totally can be stored, but only + * ::N_MBG_IO_PORT_STATUS_BITS are currently defined. + * + * The ::_set_io_port_status_bit macro should be used by the firmware + * to set a status bit in the buffer, and the ::check_feat_supp_byte_array + * to check if a bit is set + * + * @see ::_set_io_port_status_bit + * @see ::check_feat_supp_byte_array + */ +typedef struct +{ + uint8_t b[MAX_IO_PORT_STATUS_BYTES]; + +} MBG_IO_PORT_STATUS_BUFFER; + +#define _mbg_swab_io_port_status_buffer( _p ) \ + _nop_macro_fnc() + + + +/** + * @brief Set an port status bit in a ::MBG_IO_PORT_STATUS_BUFFER + * + * Should be used by the firmware only to set one of the ::N_MBG_IO_PORT_STATUS_BITS + * in an ::MBG_IO_PORT_STATUS_BUFFER after power-up. + * + * @param[in] _status_bit One of the ::MBG_IO_PORT_STATUS_BITS + * @param[in] _status_buffp Pointer to an ::MBG_IO_PORT_STATUS_BUFFER + */ +#define _set_io_port_status_bit( _status_bit, _status_buffp ) \ + _set_array_bit( _status_bit, (_status_buffp)->b, MAX_IO_PORT_STATUS_BYTES ) + + +/** + * @brief IO Port Type Status + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_U + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS_IDX + * + */ +typedef struct +{ + MBG_IO_PORT_STATUS_BUFFER supp_stati; ///< Supported ::MBG_IO_PORT_STATUS_BITS in ::MBG_IO_PORT_STATUS_BUFFER + MBG_IO_PORT_STATUS_BUFFER status; ///< See ::MBG_IO_PORT_STATUS_BUFFER + + uint8_t cfg_counter; ///< Updated (increased) when config changes + uint8_t phys_grp_role; ///< Physical group role state, see ::MBG_IO_PORT_GRP_ROLE_BITS + uint8_t log_grp; ///< Logical group number (i.e. bond0), or ::MBG_NO_LOG_GROUP + uint8_t log_grp_role; ///< Logical group role (i.e. bond master, bond slave), see ::MBG_IO_PORT_GRP_ROLE_BITS + + uint32_t reserved_2[4]; ///< Future use, currently 0 + +} MBG_IO_PORT_STATUS; + +#define _mbg_port_has_log_group( _p ) ( ( _p )->log_grp != MBG_NO_LOG_GROUP ) + +#define _mbg_swab_io_port_status( _p ) \ +do \ +{ \ + _mbg_swab_io_port_status_buffer( &(_p)->supp_stati ); \ + _mbg_swab_io_port_status_buffer( &(_p)->status ); \ +} while ( 0 ) + + + +/** + * @brief IO Port Type Status + * + * @see @ref group_io_ports + * @see ::MBG_IO_PORT_SETTINGS_U + * @see ::MBG_IO_PORT_LIMITS + * @see ::MBG_IO_PORT_SETTINGS + * @see ::MBG_IO_PORT_SETTINGS_IDX + * @see ::MBG_IO_PORT_TYPE_INFO + * @see ::MBG_IO_PORT_TYPE_INFO_U + * @see ::MBG_IO_PORT_TYPE_INFO_IDX + * @see ::MBG_IO_PORT_STATUS + * + * Indexes from 0..::MBG_IO_PORT_INFO::num_types - 1 are used + * to query ::MBG_IO_PORT_TYPE_INFO wrapped in ::MBG_IO_PORT_TYPE_INFO_IDX. + * + */ +typedef struct +{ + uint32_t idx; + MBG_IO_PORT_STATUS status; + +} MBG_IO_PORT_STATUS_IDX; + +#define _mbg_swab_io_port_status_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_io_port_status( &(_p)->status ); \ +} while ( 0 ) + + +/** @} defgroup group_io_ports */ + + + +/** + * @defgroup group_monitoring Monitoring / notification + * + * @note This structure and its definitions are only supported by a device + * if ::MBG_XFEATURE_MONITORING is set in the extended device features. + * + * TODO: Add proper Doxygen documentation + * + * @{ */ + + +#define MBG_MONITORING_STR_SIZE 32 + +enum MBG_MONITORING_TYPES +{ + MBG_MONITORING_TYPE_SNMP, + MBG_MONITORING_TYPE_EMAIL, + MBG_MONITORING_TYPE_SYSLOG, + N_MBG_MONITORING_TYPES +}; + +#define MBG_MONITORING_TYPE_STRS \ +{ \ + "SNMP", \ + "Email", \ + "Syslog" \ +} + +enum MBG_MONITORING_TYPE_MSKS +{ + MBG_MONITORING_TYPE_MSK_SNMP = (1UL << MBG_MONITORING_TYPE_SNMP), + MBG_MONITORING_TYPE_MSK_EMAIL = (1UL << MBG_MONITORING_TYPE_EMAIL), + MBG_MONITORING_TYPE_MSK_SYSLOG = (1UL << MBG_MONITORING_TYPE_SYSLOG) +}; + + + +typedef struct +{ + uint16_t supp_types; ///< See ::MBG_MONITORING_TYPE_MSKS + uint16_t supp_num_events; ///< Supported number of events. See ::MBG_EVENT_TYPES + uint32_t reserved_2[3]; + +} MBG_MONITORING_LIMITS; + +#define _mbg_swab_monitoring_limits( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->supp_types ); \ + _mbg_swab16( &(_p)->supp_num_events ); \ +} while ( 0 ) + + + +/* If ::MBG_MONITORING_TYPE_MSK_SNMP is set in ::MBG_MONITORING_LIMITS::supp_types */ + +enum MBG_SNMP_VERSIONS +{ + MBG_SNMP_VERSION_V1, + MBG_SNMP_VERSION_V2c, + MBG_SNMP_VERSION_V3, + N_MBG_SNMP_VERSIONS +}; + +#define MBG_SNMP_VERSION_STRS \ +{ \ + "Version 1", \ + "Version 2c", \ + "Version 3" \ +} + +enum MBG_SNMP_VERSION_MSKS +{ + MBG_SNMP_VERSION_MSK_V1 = (1UL << MBG_SNMP_VERSION_V1), + MBG_SNMP_VERSION_MSK_V2c = (1UL << MBG_SNMP_VERSION_V2c), + MBG_SNMP_VERSION_MSK_V3 = (1UL << MBG_SNMP_VERSION_V3) +}; + + + +typedef struct +{ + uint8_t num_v12_settings; ///< Number of configured v1/v2 settings, see ::MBG_SNMP_V12_INFO_IDX + uint8_t num_v3_settings; ///< Number of configured v1/v2 trap receivers, see ::MBG_SNMP_V12_TRAP_INFO_IDX + uint8_t num_v12_trap_receivers; ///< Number of configured v3 settings, see ::MBG_SNMP_V3_INFO_IDX + uint8_t num_v3_trap_receivers; ///< Number of configured v3 trap receivers, see ::MBG_SNMP_V3_TRAP_INFO_IDX + uint16_t listening_port; ///< snmpd listening port, 161 by default + uint16_t reserved_1; + uint32_t reserved_2[3]; + char location[MBG_MONITORING_STR_SIZE]; + char contact[MBG_MONITORING_STR_SIZE]; + char name[MBG_MONITORING_STR_SIZE]; + char reserved_3[MBG_MONITORING_STR_SIZE]; ///< Future use + char reserved_4[MBG_MONITORING_STR_SIZE]; ///< Future use + +} MBG_SNMP_GLB_SETTINGS; + +#define _mbg_swab_snmp_glb_settings( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->listening_port ); \ +} while ( 0 ) + + + +typedef struct +{ + MBG_SNMP_GLB_SETTINGS settings; + uint8_t supp_versions; ///< See ::MBG_SNMP_VERSION_MSKS + uint8_t max_v12_settings; ///< Only valid if ::MBG_SNMP_GLB_INFO::supp_versions contains ::MBG_SNMP_VERSION_MSK_V1 or ::MBG_SNMP_VERSION_MSK_V2c + uint8_t max_v3_settings; ///< Only valid if ::MBG_SNMP_GLB_INFO::supp_versions contains ::MBG_SNMP_VERSION_MSK_V3 + uint8_t max_v12_trap_receivers; ///< Only valid if ::MBG_SNMP_GLB_INFO::supp_versions contains ::MBG_SNMP_VERSION_MSK_V1 or ::MBG_SNMP_VERSION_MSK_V2c + uint8_t max_v3_trap_receivers; ///< Only valid if ::MBG_SNMP_GLB_INFO::supp_versions contains ::MBG_SNMP_VERSION_MSK_V3 + uint8_t reserved_1[3]; + uint32_t reserved_2[2]; + +} MBG_SNMP_GLB_INFO; + +#define _mbg_swab_snmp_glb_info( _p ) \ +do \ +{ \ + _mbg_swab_snmp_glb_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +enum MBG_SNMP_ACCESS_TYPES +{ + MBG_SNMP_ACCESS_TYPE_RO, + MBG_SNMP_ACCESS_TYPE_RW, + N_MBG_SNMP_ACCESS_TYPES +}; + + +#define MBG_SNMP_ACCESS_TYPE_STRS \ +{ \ + "Read-only", \ + "Read-write" \ +} + + + +typedef struct +{ + uint8_t version; ///< See ::MBG_SNMP_VERSIONS + uint8_t access_type; ///< See ::MBG_SNMP_ACCESS_TYPES, ignore in trap settings + uint8_t reserved_1[2]; + uint32_t reserved_2[3]; + char community[MBG_MONITORING_STR_SIZE]; + +} MBG_SNMP_V12_SETTINGS; + +#define _mbg_swab_snmp_v12_settings( _p ) \ +do \ +{ \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V12_SETTINGS settings; + +} MBG_SNMP_V12_SETTINGS_IDX; + +#define _mbg_swab_snmp_v12_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v12_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + MBG_SNMP_V12_SETTINGS settings; + uint32_t reserved_1[4]; + +} MBG_SNMP_V12_INFO; + +#define _mbg_swab_snmp_v12_info( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v12_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V12_INFO info; + +} MBG_SNMP_V12_INFO_IDX; + +#define _mbg_swab_snmp_v12_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v12_info( &(_p)->info ); \ +} while ( 0 ) + + + +typedef struct +{ + uint8_t timeout; ///< In seconds + uint8_t retries; + uint16_t reserved_1; + uint32_t reserved_2[3]; + char reserved_3[MBG_MONITORING_STR_SIZE]; ///< Future use + char reserved_4[MBG_MONITORING_STR_SIZE]; ///< Future use + MBG_SNMP_V12_SETTINGS v12_settings; + MBG_HOSTNAME receiver_addr; + uint16_t dest_port; ///< receiver destination port, 162 by default + uint16_t reserved_5; + +} MBG_SNMP_V12_TRAP_SETTINGS; + +#define _mbg_swab_snmp_v12_trap_settings( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v12_settings( &(_p)->v12_settings ); \ + _mbg_swab16( &(_p)->dest_port ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V12_TRAP_SETTINGS settings; + +} MBG_SNMP_V12_TRAP_SETTINGS_IDX; + +#define _mbg_swab_snmp_v12_trap_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v12_trap_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + MBG_SNMP_V12_TRAP_SETTINGS settings; + uint32_t reserved_1[4]; + +} MBG_SNMP_V12_TRAP_INFO; + +#define _mbg_swab_snmp_v12_trap_info( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v12_trap_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V12_TRAP_INFO info; + +} MBG_SNMP_V12_TRAP_INFO_IDX; + +#define _mbg_swab_snmp_v12_trap_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v12_trap_info( &(_p)->info ); \ +} while ( 0 ) + + + +enum MBG_SNMP_V3_SEC_LEVELS +{ + MBG_SNMP_V3_SEC_LEVEL_NO_AUTH_NO_PRIV, + MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV, + MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV, + N_MBG_SNMP_V3_SEC_LEVELS +}; + +#define MBG_SNMP_V3_SEC_LEVEL_STRS \ +{ \ + "No auth no priv", \ + "Auth no priv", \ + "Auth priv" \ +} + + +enum MBG_SNMP_V3_AUTH_PROTOCOLS +{ + MBG_SNMP_V3_AUTH_PROTOCOL_NONE, + MBG_SNMP_V3_AUTH_PROTOCOL_MD5, + MBG_SNMP_V3_AUTH_PROTOCOL_SHA, + N_MBG_SNMP_V3_AUTH_PROTOCOLS +}; + +#define MBG_SNMP_V3_AUTH_PROTOCOL_STRS \ +{ \ + "None", \ + "MD5", \ + "SHA" \ +} + + +enum MBG_SNMP_V3_PRIV_PROTOCOLS +{ + MBG_SNMP_V3_PRIV_PROTOCOL_NONE, + MBG_SNMP_V3_PRIV_PROTOCOL_DES, + MBG_SNMP_V3_PRIV_PROTOCOL_AES, + N_MBG_SNMP_V3_PRIV_PROTOCOLS +}; + + +#define MBG_SNMP_V3_PRIV_PROTOCOL_STRS \ +{ \ + "None", \ + "DES", \ + "AES" \ +} + + + +typedef struct +{ + uint8_t access_type; ///< See ::MBG_SNMP_ACCESS_TYPES, ignore in trap settings + uint8_t sec_level; ///< See ::MBG_SNMP_V3_SEC_LEVELS + uint8_t auth_protocol; ///< See ::MBG_SNMP_V3_AUTH_PROTOCOLS if ::MBG_SNMP_V3_SETTINGS::sec_level + ///< is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV or ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV + uint8_t priv_protocol; ///< See ::MBG_SNMP_V3_PRIV_PROTOCOLS if ::MBG_SNMP_V3_SETTINGS::sec_level + ///< is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV + uint32_t reserved_1[3]; + char user_name[MBG_MONITORING_STR_SIZE]; ///< User name used for authentication, always required. + char auth_passwd[MBG_MONITORING_STR_SIZE]; ///< Password associated with ::MBG_SNMP_V3_SETTINGS::user_name, if ::MBG_SNMP_V3_SETTINGS::auth_protocol + ///< is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_NO_PRIV or ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV + char sec_engine_id[MBG_MONITORING_STR_SIZE]; ///< Mandatory + char context_engine_id[MBG_MONITORING_STR_SIZE]; ///< Ignore + char context_name[MBG_MONITORING_STR_SIZE]; ///< Ignore + char reserved_2[MBG_MONITORING_STR_SIZE]; ///< Future use + char reserved_3[MBG_MONITORING_STR_SIZE]; ///< Future use + char priv_passwd[MBG_MONITORING_STR_SIZE]; ///< Encryption passwd if ::MBG_SNMP_V3_SETTINGS::auth_protocol is ::MBG_SNMP_V3_SEC_LEVEL_AUTH_PRIV + uint32_t boots; ///< Number of system/deamon restarts -> Ignore + uint32_t time; ///< Timeticks since last "boots" event -> Ignore + uint32_t reserved_4[2]; + +} MBG_SNMP_V3_SETTINGS; + +#define _mbg_swab_snmp_v3_settings( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->boots ); \ + _mbg_swab32( &(_p)->time ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V3_SETTINGS settings; + +} MBG_SNMP_V3_SETTINGS_IDX; + +#define _mbg_swab_snmp_v3_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v3_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + MBG_SNMP_V3_SETTINGS settings; + uint32_t reserved_1[4]; + +} MBG_SNMP_V3_INFO; + +#define _mbg_swab_snmp_v3_info( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v3_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V3_INFO info; + +} MBG_SNMP_V3_INFO_IDX; + +#define _mbg_swab_snmp_v3_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v3_info( &(_p)->info ); \ +} while ( 0 ) + + + +typedef struct +{ + uint8_t timeout; ///< In seconds + uint8_t retries; + uint8_t reserved_1[2]; + uint32_t reserved_2[3]; + MBG_SNMP_V3_SETTINGS v3_settings; + MBG_HOSTNAME receiver_addr; + uint16_t dest_port; ///< receiver destination port, 162 by default + uint16_t reserved_3; + +} MBG_SNMP_V3_TRAP_SETTINGS; + +#define _mbg_swab_snmp_v3_trap_settings( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v3_settings( &(_p)->v3_settings ); \ + _mbg_swab16( &(_p)->dest_port ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V3_TRAP_SETTINGS settings; + +} MBG_SNMP_V3_TRAP_SETTINGS_IDX; + +#define _mbg_swab_snmp_v3_trap_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v3_trap_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + MBG_SNMP_V3_TRAP_SETTINGS settings; + uint32_t reserved_1[4]; + +} MBG_SNMP_V3_TRAP_INFO; + +#define _mbg_swab_snmp_v3_trap_info( _p ) \ +do \ +{ \ + _mbg_swab_snmp_v3_trap_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +typedef struct +{ + uint32_t idx; + MBG_SNMP_V3_TRAP_INFO info; + +} MBG_SNMP_V3_TRAP_INFO_IDX; + +#define _mbg_swab_snmp_v3_trap_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_snmp_v3_trap_info( &(_p)->info ); \ +} while ( 0 ) + + + +enum MBG_EVENT_TYPES +{ + MBG_EVENT_TYPE_NTP_STATE, + MBG_EVENT_TYPE_HEARTBEAT, + N_MBG_EVENT_TYPES +}; + +#define MBG_EVENT_TYPE_STRS \ +{ \ + "NTP state", \ + "Heartbeat" \ +} + +enum MBG_EVENT_SEVERITIES +{ + MBG_EVENT_SEVERITY_INFO, + MBG_EVENT_SEVERITY_WARNING, + MBG_EVENT_SEVERITY_ERROR, + MBG_EVENT_SEVERITY_CRITICAL, + N_MBG_EVENT_SEVERITIES +}; + +#define MBG_EVENT_SEVERITY_STRS \ +{ \ + "Info", \ + "Warning", \ + "Error", \ + "Critical" \ +} + +enum MBG_EVENT_SEVERITY_MSKS +{ + MBG_EVENT_SEVERITY_MSK_INFO = (1UL << MBG_EVENT_SEVERITY_INFO), + MBG_EVENT_SEVERITY_MSK_WARNING = (1UL << MBG_EVENT_SEVERITY_WARNING), + MBG_EVENT_SEVERITY_MSK_ERROR = (1UL << MBG_EVENT_SEVERITY_ERROR), + MBG_EVENT_SEVERITY_MSK_CRITICAL = (1UL << MBG_EVENT_SEVERITY_CRITICAL) +}; + +typedef struct +{ + uint8_t severity; ///< See ::MBG_EVENT_SEVERITIES + uint8_t reserved_1; + uint16_t triggers; ///< See ::MBG_MONITORING_TYPE_MSKS if set in ::MBG_MONITORING_LIMITS::supp_types + uint16_t interval; ///< [s], only if ::MBG_EVENT_SUPP_FLAG_INTERVAL is set in ::MBG_EVENT_INFO::supp_flags, else 0. + uint16_t reserved_2; + uint32_t reserved_3[6]; + +} MBG_EVENT_SETTINGS; + +#define _mbg_swab_event_settings( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->triggers ); \ + _mbg_swab16( &(_p)->interval ); \ +} while ( 0 ) + + + +/** + * @brief Structure for monitoring event settings + * + * @see ::MBG_EVENT_INFO_IDX + */ +typedef struct +{ + uint32_t idx; + MBG_EVENT_SETTINGS settings; + +} MBG_EVENT_SETTINGS_IDX; + +#define _mbg_swab_event_settings_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_event_settings( &(_p)->settings ); \ +} while ( 0 ) + + + +enum MBG_EVENT_SUPP_FLAGS +{ + MBG_EVENT_SUPP_FLAG_INTERVAL, ///< Event can be sent cyclically + N_MBG_EVENT_SUPP_FLAGS +}; + + +enum MBG_EVENT_SUPP_FLAG_MSKS +{ + MBG_EVENT_SUPP_FLAG_MSK_INTERVAL = ( 1UL << MBG_EVENT_SUPP_FLAG_INTERVAL ) +}; + + + +enum MBG_EVENT_FLAGS +{ + MBG_EVENT_FLAG_NOT_AVAIL, ///< Event is currently not available, i.e. card in slot has been removed + N_MBG_EVENT_FLAGS +}; + + +enum MBG_EVENT_FLAG_MSKS +{ + MBG_EVENT_FLAG_MSK_NOT_AVAIL = ( 1UL << MBG_EVENT_FLAG_NOT_AVAIL ) +}; + +#define MBG_OWN_EVENT_CHASSIS 0xFF +#define MBG_OWN_EVENT_SLOT 0xFF +#define MBG_INV_EVENT_PORT 0xFF + + + +typedef struct +{ + MBG_EVENT_SETTINGS settings; + uint16_t type; ///< See ::MBG_EVENT_TYPES + uint8_t chassis_idx; ///< Index of the associated IMS chassis + uint8_t slot_idx; ///< Index of the associated IMS slot + uint8_t port_idx; ///< Index of the associated IO port + uint8_t reserved_1; ///< Reserved, currently 0 + uint16_t reserved_2; ///< Reserved, currently 0 + + uint16_t supp_severities; ///< See ::MBG_EVENT_SEVERITY_MSKS + uint16_t supp_flags; ///< See ::MBG_EVENT_SUPP_FLAG_MSKS + uint16_t supp_triggers; ///< See ::MBG_MONITORING_TYPE_MSKS + uint16_t flags; ///< See ::MBG_EVENT_FLAG_MSKS + + uint32_t reserved_3[4]; + +} MBG_EVENT_INFO; + +#define _mbg_swab_event_info( _p ) \ +do \ +{ \ + _mbg_swab_event_settings( &(_p)->settings ); \ + _mbg_swab16( &(_p)->type ); \ + _mbg_swab16( &(_p)->supp_severities ); \ + _mbg_swab16( &(_p)->supp_flags ); \ + _mbg_swab16( &(_p)->supp_triggers ); \ + _mbg_swab16( &(_p)->flags ); \ +} while ( 0 ) + + + +/** + * @brief Structure for monitoring event info + * + * @note idx represents the event type, see ::MBG_EVENT_TYPES + * Before requesting the struct, its availability should be checked + * in ::MBG_MONITORING_LIMITS::supp_num_events. + * + * @see ::MBG_EVENT_TYPES + * @see ::MBG_MONITORING_LIMITS + */ +typedef struct +{ + uint32_t idx; + MBG_EVENT_INFO info; + +} MBG_EVENT_INFO_IDX; + +#define _mbg_swab_event_info_idx( _p ) \ +do \ +{ \ + _mbg_swab32( &(_p)->idx ); \ + _mbg_swab_event_info( &(_p)->info ); \ +} while ( 0 ) + + + +typedef struct +{ + uint8_t snmp_cfg_counter; ///< Updated (increased) when SNMP config changes + uint8_t email_cfg_counter; ///< Updated (increased) when Email config changes + uint8_t syslog_cfg_counter; ///< Updated (increased) when Syslog config changes + uint8_t event_cfg_counter; ///< Updated (increased) when event config changes + uint32_t reserved_2[3]; + +} MBG_MONITORING_STATUS; + +#define _mbg_swab_monitoring_status( _p ) \ +do \ +{ \ +} while ( 0 ) + + + +enum MBG_EVENT_STATUS_FLAGS +{ + MBG_EVENT_STATUS_FLAG_ACTIVE, ///< Event is currently active + N_MBG_EVENT_STATUS_FLAGS +}; + + +enum MBG_EVENT_STATUS_FLAG_MSKS +{ + MBG_EVENT_STATUS_FLAG_MSK_ACTIVE = (1UL << MBG_EVENT_STATUS_FLAG_ACTIVE) +}; + + + +typedef struct +{ + uint16_t flags; ///< See ::MBG_EVENT_STATUS_FLAGS + uint16_t reserved_1; + uint32_t last_triggered; ///< Unix timestamp when this event has been triggered + uint32_t reserved_2[6]; + +} MBG_EVENT_STATUS; + +#define _mbg_swab_event_status( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->flags ); \ + _mbg_swab32( &(_p)->last_triggered ); \ +} while ( 0 ) + + + +typedef struct +{ + uint16_t idx; + MBG_EVENT_STATUS status; + +} MBG_EVENT_STATUS_IDX; + +#define _mbg_swab_event_status_idx( _p ) \ +do \ +{ \ + _mbg_swab16( &(_p)->idx ); \ + _mbg_swab_event_status( &(_p)->status ); \ +} while ( 0 ) + +/** @} defgroup group_monitoring */ + + +/** + * @defgroup group_usb_lock USB locks + * + * @note This structure and its definitions are only supported by a device + * if ::MBG_XFEATURE_USB_LOCK is set in the extended device features. + * Feature can electrically disconnect an USB slave device from + * the USB host bus. It cannot be reset via software, it's a one way action only. + * + * TODO: Add proper Doxygen documentation + * + * @{ */ + + +enum MBG_USB_LOCK_FLAGS +{ + MBG_USB_LOCK_FLAG_ACTIVE, ///< USB connection is interrupted + N_MBG_USB_LOCK_FLAGS +}; + + +enum MBG_USB_LOCK_FLAG_MSKS +{ + MBG_USB_LOCK_FLAG_MSK_ACTIVE = (1UL << MBG_USB_LOCK_FLAG_ACTIVE) ///< See ::MBG_USB_LOCK_FLAG_ACTIVE +}; + + +typedef struct +{ + uint8_t flags; ///< ::MBG_USB_LOCK_FLAG_MSKS + uint8_t reserved_1[3]; + uint32_t reserved_2[3]; + +} MBG_USB_LOCK_SETTINGS; + +#define _mbg_swab_usb_lock_settings( _p ) do {} while ( 0 ) + + +typedef struct +{ + MBG_USB_LOCK_SETTINGS settings; + uint8_t supp_flags; ///< ::MBG_USB_LOCK_FLAG_MSKS + uint8_t reserved_1[3]; + uint32_t reserved_2[3]; + +} MBG_USB_LOCK_INFO; + +#define _mbg_swab_usb_lock_info( _p ) \ +do \ +{ \ + _mbg_swab_usb_lock_settings( _p ); \ +} while ( 0 ) + + +typedef struct +{ + uint8_t flags; ///< ::MBG_USB_LOCK_FLAG_MSKS + uint8_t reserved_1[3]; + uint32_t reserved_2[3]; + +} MBG_USB_LOCK_STATUS; + +#define _mbg_swab_usb_lock_status( _p ) do {} while ( 0 ) + + +/** @} defgroup group_usb_lock */ + + #if defined( _USING_BYTE_ALIGNMENT ) #pragma pack() // set default alignment #undef _USING_BYTE_ALIGNMENT diff --git a/mbglib/common/mbg_ntp_test_util.c b/mbglib/common/mbg_ntp_test_util.c index 163c906..ba19d77 100755 --- a/mbglib/common/mbg_ntp_test_util.c +++ b/mbglib/common/mbg_ntp_test_util.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_ntp_test_util.c 1.6 2016/11/21 17:22:49 martin REL_M $ + * $Id: mbg_ntp_test_util.c 1.8 2017/09/06 14:04:26 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,12 @@ * * ----------------------------------------------------------------------- * $Log: mbg_ntp_test_util.c $ + * Revision 1.8 2017/09/06 14:04:26 martin + * Root delay and root dispersion are now printed + * with 6 instead of only 4 fractional digits. + * Revision 1.7 2016/12/01 17:06:50 martin + * Account for modified packet structure. + * Print leap smear offset decoded from refid field. * Revision 1.6 2016/11/21 17:22:49 martin * Adjustable client poll value sent to server, defaults to 6. * Revision 1.5 2016/08/05 12:35:43 martin @@ -277,20 +283,20 @@ void print_ntp_packet( const char *msg, const NTP_PACKET_INFO *p, int print_date for ( i = 0; ; ) { - unsigned char uc = BYTE_OF( pbp->reference_id, i ); + unsigned char uc = BYTE_OF( pbp->refid.as_u32, i ); if ( !isdigit( uc ) ) { - sprintf( ref_id_str, "%.*s", - (int) sizeof( pbp->reference_id ), - (char *) &pbp->reference_id + sprintf( ref_id_str, "%.*s", // TODO FIXME + (int) sizeof( pbp->refid ), + pbp->refid.as_chars ); break; } cp += sprintf( cp, "%u", uc ); - if ( ++i >= sizeof( pbp->reference_id ) ) + if ( ++i >= sizeof( pbp->refid ) ) { *cp = 0; break; @@ -300,13 +306,13 @@ void print_ntp_packet( const char *msg, const NTP_PACKET_INFO *p, int print_date } printf( - INDENT "root delay: %08lX (%.4f s)\n" - INDENT "root dispersion: %08lX (%.4f s/s)\n" + INDENT "root delay: %08lX (%.6f s)\n" + INDENT "root dispersion: %08lX (%.6f s/s)\n" INDENT "reference id: %08lX (%s)\n" , (long) pbp->root_delay, _u_fp_to_d( pbp->root_delay ), (long) pbp->root_dispersion, _u_fp_to_d( pbp->root_dispersion ), - (long) pbp->reference_id, + (long) pbp->refid.as_u32, ref_id_str ); @@ -543,7 +549,21 @@ void print_ntp_results( const NTP_RESULTS *p_rslt, const NTP_PACKET_INFO *p_req, print_ntp_packet( "Request packet:", p_req, print_date_time ); if ( p_rcv ) + { + double d; + bool smearing_active; print_ntp_packet( "Response packet:", p_rcv, print_date_time ); + smearing_active = leap_smearing_active( &p_rcv->packet.base.refid, &d ); + if ( verbose || smearing_active ) + { + if ( smearing_active ) + printf( "Leap smearing active, offset: %.6f s\n", d ); + else + printf( "Leap smearing not active\n" ); + + printf( "\n" ); + } + } if ( p_rslt ) // p_stats may be NULL { diff --git a/mbglib/common/mbg_tgt.h b/mbglib/common/mbg_tgt.h index f5b3538..0a268e6 100755 --- a/mbglib/common/mbg_tgt.h +++ b/mbglib/common/mbg_tgt.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbg_tgt.h 1.35.1.6 2016/09/27 15:33:30 martin TRASH $ + * $Id: mbg_tgt.h 1.38 2017/08/08 13:07:31 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,18 +11,23 @@ * * ----------------------------------------------------------------------- * $Log: mbg_tgt.h $ - * Revision 1.35.1.6 2016/09/27 15:33:30 martin - * Added definition for _NO_MBG_API. - * Revision 1.35.1.5 2016/09/26 16:17:36 martin - * Fixed definitions for Windows kernel mode build. - * Revision 1.35.1.4 2016/08/31 08:17:51Z thomas-b - * Do not typedef ssize_t if HAVE_SSIZE_T is defined already - * Revision 1.35.1.3 2016/08/11 08:27:17 martin + * Revision 1.38 2017/08/08 13:07:31 martin + * Proper fix for PRId64 and others. + * Define _CRT_SECURE_NO_WARNINGS only if not already defined. + * Revision 1.37 2017/07/10 07:08:45 thomas-b + * Define PRId64 if it is not defined in inttypes.h + * Revision 1.36 2017/07/04 12:35:11 martin * Fixed build for Windows kernel space. - * Revision 1.35.1.2 2016/08/10 12:26:49Z martin - * *** empty log message *** - * Revision 1.35.1.1 2016/08/09 15:59:25 martin - * *** empty log message *** + * Don't define ssize_t if HAVE_SSIZE_T is already defined. + * Added definition for _NO_MBG_API. + * Fixed missing 'bool' type for old Linux kernels. + * Fixed missing 'struct timespec' for DOS. + * Evaluate preprocessor symbol KERNEL_HAS_BOOL to avoid + * compiler errors due to duplicate definitions in specific + * Linux kernels patched by the distro maintainers. + * Provide ssize_t for C++Builder 5. + * Improved Visual Studio version checking. + * New define MBG_TGT_HAS_NODE_NAME. * Revision 1.35 2016/08/05 12:21:34 martin * Conditionally define a macro _DEPRECATED_BY which can be used to * tag functions as deprecated, so compilers can emit appropriate warnings. @@ -201,6 +206,11 @@ /* Start of header body */ +#ifdef __cplusplus +extern "C" { +#endif + + #if defined( _CVI_ ) #define MBG_TGT_CVI @@ -302,13 +312,6 @@ #define MBG_TGT_SUNOS - #define __mbg_inline __inline__ - - #include <stdint.h> - #include <inttypes.h> - #include <stdbool.h> - #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 - #elif defined( __QNX__ ) // any compiler for target QNX @@ -352,8 +355,16 @@ #define MBG_TGT_POSIX #define MBG_TGT_UNIX + #endif +#if defined( MBG_TGT_WIN32 ) + + #if !defined( _CRT_SECURE_NO_WARNINGS ) + #define _CRT_SECURE_NO_WARNINGS 1 + #endif + +#endif // Some definitions depending on the build environment ... @@ -407,12 +418,25 @@ #include <linux/version.h> #if ( LINUX_VERSION_CODE <= KERNEL_VERSION( 2, 6, 4 ) ) || \ - ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 4 ) ) //##++++ must be true for 2.6.32-5-sparc64 + ( LINUX_VERSION_CODE >= KERNEL_VERSION( 2, 6, 4 ) ) // must be true for 2.6.32-5-sparc64 #define _ULONG_DEFINED 1 #define _USHORT_DEFINED 1 #define _UINT_DEFINED 1 #endif + // The 'bool' type is supported by the vanilla Linux kernel 2.6.19 and later. + // However, looks like at least the RedHat folks have backported this to 2.6.18, + // so KERNEL_HAS_BOOL can be defined to avoid a compiler error due to + // duplicate definition. + #if ( ( LINUX_VERSION_CODE < KERNEL_VERSION( 2, 6, 19 ) ) && !defined( KERNEL_HAS_BOOL ) ) + typedef _Bool bool; + #define bool bool + #endif + + // 'true' and 'false' are also defined by newer kernel versions + // as enum in linux/stddef.h, but may not be defined by + // older kernels. + #else #include <stdint.h> @@ -427,6 +451,8 @@ #endif + #define MBG_TGT_HAS_DEV_FN 1 + #elif defined( MBG_TGT_BSD ) #if defined( MBG_TGT_KERNEL ) @@ -437,6 +463,8 @@ #include <stdbool.h> #endif + #define MBG_TGT_HAS_DEV_FN 1 + #elif defined( MBG_TGT_QNX_NTO ) // QNX 6.x (Neutrino) #include <unistd.h> @@ -477,6 +505,7 @@ #elif defined( _MSC_VER ) // Known predifined MS compiler version codes: + // 1910: MSVC++ 15.0 (Visual Studio 2017) // 1900: MSVC++ 14.0 (Visual Studio 2015) // 1800: MSVC++ 12.0 (Visual Studio 2013) // 1700: MSVC++ 11.0 (Visual Studio 2012) @@ -488,6 +517,35 @@ // 1200: MSVC++ 6.0 // 1100: MSVC++ 5.0 + // Enable this to get compile-time messages on the compiler version + #if 0 + #if ( _MSC_VER >= 1910 ) + #error >= 1910: MSVC++ 15.0 (Visual Studio 2017), or later + #elif ( _MSC_VER >= 1900 ) + #error 1900: MSVC++ 14.0 (Visual Studio 2015) + #elif ( _MSC_VER >= 1800 ) + #error 1800: MSVC++ 12.0 (Visual Studio 2013) + #elif ( _MSC_VER >= 1700 ) + #error 1700: MSVC++ 11.0 (Visual Studio 2012) + #elif ( _MSC_VER >= 1600 ) + #error 1600: MSVC++ 10.0 (Visual Studio 2010) + #elif ( _MSC_VER >= 1500 ) + #error 1500: MSVC++ 9.0 (Visual Studio 2008) + #elif ( _MSC_VER >= 1400 ) + #error STRINGIFY( _MSC_VER ) MSVC++ 8.0 (Visual Studio 2005, Windows Server 2003 SP1 DDK - AMD64) + #elif ( _MSC_VER >= 1310 ) + #error 1310: MSVC++ 7.1 (Visual Studio .NET 2003, Windows Server 2003 DDK) + #elif ( _MSC_VER >= 1300 ) + #error 1300: MSVC++ 7.0 (Visual Studio .NET 2002, Windows XP SP1 DDK) + #elif ( _MSC_VER >= 1200 ) + #error 1200: MSVC++ 6.0 + #elif ( _MSC_VER >= 1100 ) + #error 1100: MSVC++ 5.0 + #else + #error <1100: Older than MSVC 4 + #endif + #endif + // "struct timespec" is supported only since VS2015 // If it is then also the symbol TIME_UTC should be defined. // Functions to read the current time as struct timespec @@ -499,13 +557,7 @@ // to get monotonic time stamps and intervals. #if ( _MSC_VER < 1900 ) #if !defined( HAVE_STRUCT_TIMESPEC ) - #include <time.h> - - struct timespec - { - time_t tv_sec; - long tv_nsec; - }; + #define MBG_TGT_MISSING_STRUCT_TIMESPEC 1 #endif #endif @@ -513,6 +565,10 @@ #include <stdint.h> #include <inttypes.h> #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + + #if !defined( PRId64 ) + #define MBG_PRE64_PREFIX "I64" + #endif #else #define MBG_TGT_HAS_INT_8_16_32 1 #define MBG_PRE64_PREFIX "I64" @@ -537,9 +593,13 @@ #define __func__ "func_???" #endif - // "deprecated" attribute - #if ( _MSC_VER >= 1400 ) - // This is supported since Visual Studio 2005 + // The "deprecated" attribute should be supported since Visual Studio 2005, + // but doesn't seem to be supported by the compiler shipped with the + // "Windows Server 2003 SP1 DDK", which is used to build kernel drivers + // and defines the same _MSC_VER number as VS2005. For now we assume + // that this is supported by compilers shipped with newer SDKs. + #if ( ( _MSC_VER >= 1500 ) || \ + ( ( _MSC_VER >= 1400 ) && !defined( _KDD_ ) ) ) #define _DEPRECATED_BY( _s ) __declspec(deprecated("deprecated, use \"" _s "\"")) #endif @@ -566,7 +626,7 @@ #define HAVE_SSIZE_T 1 - #endif + #endif // !defined ( HAVE_SSIZE_T ) #elif defined( _CVI_ ) @@ -622,26 +682,29 @@ #include <stdint.h> #include <inttypes.h> #include <stdbool.h> - #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 #elif ( __BORLANDC__ >= 0x570 ) // BDS/Borland C++ Builder 2006 starts to provide at least stdint.h #include <stdint.h> #include <inttypes.h> - #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 + #define MBG_TGT_HAS_EXACT_SIZE_TYPES 1 #if !defined( __cplusplus ) - #define MBG_TGT_MISSING_BOOL_TYPE 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 #endif #elif ( __BORLANDC__ >= 0x0550 ) - #define MBG_TGT_HAS_INT_8_16_32 1 - #define MBG_PRE64_PREFIX "I64" + #define MBG_TGT_HAS_INT_8_16_32 1 + #define MBG_PRE64_PREFIX "I64" #if !defined( __cplusplus ) - #define MBG_TGT_MISSING_BOOL_TYPE 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 #endif #else // e.g. BC 3.1 or earlier #if ( __BORLANDC__ <= 0x410 ) - #define MBG_TGT_MISSING_64_BIT_TYPES 1 - #define MBG_TGT_MISSING_BOOL_TYPE 1 - #define USE_LONG_FOR_INT32 1 + #define MBG_TGT_MISSING_64_BIT_TYPES 1 + #define MBG_TGT_MISSING_BOOL_TYPE 1 + #define USE_LONG_FOR_INT32 1 + #define MBG_TGT_MISSING_STRUCT_TIMESPEC 1 + + typedef int ssize_t; #endif #endif @@ -655,6 +718,11 @@ #define __mbg_inline // up to BC3.1 not supported for C #endif + #if !defined ( HAVE_SSIZE_T ) + typedef int ssize_t; // required at least for C++ Builder 5 + #define HAVE_SSIZE_T 1 + #endif + #elif defined( __WATCOMC__ ) // 1050 v10.5 @@ -713,8 +781,6 @@ #if defined( MBG_TGT_WIN32 ) - #define _CRT_SECURE_NO_WARNINGS 1 - #if defined( _AMD64_ ) // This is used for AMD64 architecture and for // Intel XEON CPUs with 64 bit extension. @@ -864,6 +930,22 @@ #define MBG_USE_MM_IO_FOR_PCI 0 #endif +#if !defined( MBG_TGT_HAS_DEV_FN ) + #define MBG_TGT_HAS_DEV_FN 0 +#endif + +#if defined( MBG_TGT_MISSING_STRUCT_TIMESPEC ) + +#include <time.h> + + struct timespec + { + time_t tv_sec; + long tv_nsec; + }; + +#endif // defined( MBG_TGT_MISSING_STRUCT_TIMESPEC ) + // The macros below are defined in order to be able to check if // certain C language extensions are available on the target system: @@ -898,17 +980,6 @@ -/* End of header body */ - -#undef _ext - - -/* function prototypes: */ - -#ifdef __cplusplus -extern "C" { -#endif - /* ----- function prototypes begin ----- */ /* This section was generated automatically */ @@ -922,5 +993,8 @@ extern "C" { } #endif +/* End of header body */ + +#undef _ext #endif /* _MBG_TGT_H */ diff --git a/mbglib/common/mbgerror.c b/mbglib/common/mbgerror.c index c2e089d..ffd4bb8 100755 --- a/mbglib/common/mbgerror.c +++ b/mbglib/common/mbgerror.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgerror.c 1.2.1.3 2016/09/13 10:24:02 martin TRASH $ + * $Id: mbgerror.c 1.3 2017/07/05 09:20:07 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,12 +10,20 @@ * * ----------------------------------------------------------------------- * $Log: mbgerror.c $ - * Revision 1.2.1.3 2016/09/13 10:24:02 martin - * Fixed some compiler warnings. - * Revision 1.2.1.2 2016/08/16 12:48:30Z gregoire.diehl - * CVI fixes - * Revision 1.2.1.1 2016/08/11 07:58:15 martin - * Fixed a compiler warning. + * Revision 1.3 2017/07/05 09:20:07 martin + * Fixed a bug where POSIX error ENODEV wasn't mapped at all, but + * EXDEV was instead translated erraneously to MBG_ERR_NO_DEV. + * Mapped POSIX error ENOSPC to MBG_ERR_NO_SPACE, and EFAULT + * to MBG_ERR_INV_PARM. + * Mapped Windows WSA error codes WSAEFAULT and WSAEINVAL + * to MBG_ERR_INV_PARM. + * Renamed mbg_ioctl_err() to mbg_cond_err_msg(). + * New function mbg_cond_err_msg_info() which takes an optional + * info string which is printed if the error code to be checked + * is MBG_ERR_NOT_SUPP_BY_DEV. + * Fixed build in Windows kernel mode. + * Fixed syntax error in CVI-specific code. + * Quieted some compiler warnings. * Revision 1.2 2016/08/05 12:25:44Z martin * Added some functions. * Revision 1.1 2014/03/07 12:08:14 martin @@ -84,12 +92,12 @@ static ERRNO_CNV_ENTRY posix_errno_table[] = // { EAGAIN, }, // 11, Try again { ENOMEM, MBG_ERR_NO_MEM }, // 12, Out of memory { EACCES, MBG_ERR_ACCESS }, // 13, Permission denied - // { EFAULT, }, // 14, Bad address + { EFAULT, MBG_ERR_INV_PARM }, // 14, Bad address, e.g. invalid pointer // { ENOTBLK, }, // 15, Block device required { EBUSY, MBG_ERR_BUSY }, // 16, Device or resource busy { EEXIST, MBG_ERR_EXIST }, // 17, File exists - { EXDEV, MBG_ERR_NO_DEV }, // 18, Cross-device link - // { ENODEV, }, // 19, No such device + // { EXDEV, }, // 18, Cross-device link + { ENODEV, MBG_ERR_NO_DEV }, // 19, No such device // { ENOTDIR, }, // 20, Not a directory // { EISDIR, }, // 21, Is a directory { EINVAL, MBG_ERR_INV_PARM }, // 22, Invalid argument @@ -98,7 +106,7 @@ static ERRNO_CNV_ENTRY posix_errno_table[] = // { ENOTTY, }, // 25, Not a typewriter // { ETXTBSY, }, // 26, Text file busy // { EFBIG, }, // 27, File too large - // { ENOSPC, }, // 28, No space left on device + { ENOSPC, MBG_ERR_NO_SPACE }, // 28, No space left on device { ESPIPE, MBG_ERR_PIPE }, // 29, Illegal seek // { EROFS, }, // 30, Read-only file system // { EMLINK, }, // 31, Too many links @@ -142,8 +150,8 @@ static ERRNO_CNV_ENTRY posix_h_errno_table[] = #if defined( MBG_TGT_CVI ) -static ERRNO_CNV_ENTRY cvi_rs232_error_table[] = -{ +static ERRNO_CNV_ENTRY cvi_rs232_error_table[] = +{ // { kRS_UnknownSysError, }, // Unknown system error. // { kRS_InvalidPortNum, }, // In valid port number. // { kRS_PortNotOpen, }, // Port is not open. @@ -201,11 +209,14 @@ static ERRNO_CNV_ENTRY cvi_rs232_error_table[] = -#if defined( MBG_TGT_WIN32 ) +#if defined( MBG_TGT_WIN32 ) && !defined( MBG_TGT_KERNEL ) static ERRNO_CNV_ENTRY win32_error_table[] = { - // System Error Codes (1300-1699) + // Windows System Error Codes (0-499) + { ERROR_INVALID_PARAMETER, MBG_ERR_INV_PARM }, + + // Windows System Error Codes (1300-1699) { ERROR_ACCESS_DENIED, MBG_ERR_ACCESS }, // { ERROR_PRIVILEGE_NOT_HELD, MBG_ERR_PERM }, // { ERROR_INVALID_HANDLE, MBG_ERR_INV_HANDLE }, // @@ -236,8 +247,8 @@ static ERRNO_CNV_ENTRY win32_wsa_err_table[] = { WSAEINTR, MBG_ERR_INTR }, // 10004L A blocking operation was interrupted by a call to WSACancelBlockingCall. // { WSAEBADF // 10009L The file handle supplied is not valid. // { WSAEACCES // 10013L An attempt was made to access a socket in a way forbidden by its access permissions. - // { WSAEFAULT // 10014L The system detected an invalid pointer address in attempting to use a pointer argument in a call. - // { WSAEINVAL // 10022L An invalid argument was supplied. + { WSAEFAULT, MBG_ERR_INV_PARM }, // 10014L The system detected an invalid pointer address in attempting to use a pointer argument in a call. + { WSAEINVAL, MBG_ERR_INV_PARM }, // 10022L An invalid argument was supplied. // { WSAEMFILE // 10024L Too many open sockets. // { WSAEWOULDBLOCK // 10035L A non-blocking socket operation could not be completed immediately. // { WSAEINPROGRESS // 10036L A blocking operation is currently executing. @@ -343,7 +354,7 @@ const char *mbg_strerror( int mbg_errno ) for ( p = tbl; p->name; p++ ) { - if ( (ulong) mbg_errno == p->code ) + if ( mbg_errno == p->code ) return p->name; } @@ -354,20 +365,62 @@ const char *mbg_strerror( int mbg_errno ) -// test if ioctl error and print msg if true -//### TODO check if this should be renamed +#if !( defined( MBG_TGT_WIN32 ) && defined( MBG_TGT_KERNEL ) ) // not supported in Windows kernel mode + +/*HDR*/ +/** + * @brief Check if a value is an error code and print an associated error message + * + * @param[in] rc A positive number including ::MBG_SUCCESS, or one of the @ref MBG_ERROR_CODES + * @param[in] what A string indicated what failed + * + * @return true if rc represented an error code, and a message has been printed, else false + */ +bool mbg_cond_err_msg( int rc, const char *what ) +{ + return mbg_cond_err_msg_info( rc, what, NULL ); + +} // mbg_cond_err_msg + + + /*HDR*/ -int mbg_ioctl_err( int rc, const char *descr ) +/** + * @brief Check if a value is an general or a "not supported" error code and print an associated message + * + * If rc contains an error code then an error message is printed, and true is returned. + * + * If the optional parameter string info2 is not NULL then it should contain + * the name of a feature which has been tested before. In this case, if the error + * code is the specific error ::MBG_ERR_NOT_SUPP_BY_DEV then a "not supported" message + * is printed using info2. + * + * If info2 is NULL, or the error code is not ::MBG_ERR_NOT_SUPP_BY_DEV then the standard + * error message is printed anyway. + * + * @param[in] rc A positive number including ::MBG_SUCCESS, or one of the @ref MBG_ERROR_CODES + * @param[in] what A string indicated what failed + * @param[in] info An optional informational string telling what is not supported (may be NULL). + * + * @return true if rc represented an error code, and a message has been printed, else false + */ +bool mbg_cond_err_msg_info( int rc, const char *what, const char *info ) { if ( mbg_rc_is_error( rc ) ) { - fprintf( stderr, "** %s: %s (rc: %i)\n", descr, mbg_strerror( rc ), rc ); - return -1; + if ( info && ( rc == MBG_ERR_NOT_SUPP_BY_DEV ) ) + fprintf( stderr, "This device does not %s.\n", info ); + else + fprintf( stderr, "** %s failed: %s (rc: %i)\n", what, mbg_strerror( rc ), rc ); + + return true; } - return 0; + return false; -} // mbg_ioctl_err +} // mbg_cond_err_msg_info + +#endif // !( defined( MBG_TGT_WIN32 ) && defined( MBG_TGT_KERNEL ) ) @@ -401,7 +454,7 @@ int mbg_cvi_rs232_error_to_mbg( int cvi_rc, const char *info ) -#if defined( MBG_TGT_WIN32 ) +#if defined( MBG_TGT_WIN32 ) && !defined( MBG_TGT_KERNEL ) /*HDR*/ /** @@ -541,11 +594,15 @@ int mbg_get_last_error( const char *info ) { #if defined( MBG_TGT_WIN32 ) - // Under Windows the "last error" code after a non-socket function - // has to be retrieved by calling GetLastError(), whereas - // the "last error" code from POSIX-like socket functions - // is retrieved by calling WSAGetLastError(). - return mbg_win32_last_err_to_mbg( GetLastError(), info ); + #if !defined( MBG_TGT_KERNEL ) + // Under Windows the "last error" code after a non-socket function + // has to be retrieved by calling GetLastError(), whereas + // the "last error" code from POSIX-like socket functions + // is retrieved by calling WSAGetLastError(). + return mbg_win32_last_err_to_mbg( GetLastError(), info ); + #else + return MBG_ERR_GENERIC; + #endif #elif defined( MBG_TGT_POSIX ) @@ -590,11 +647,15 @@ int mbg_get_last_socket_error( const char *info ) #elif defined( MBG_TGT_WIN32 ) - // Under Windows the "last error" code after a socket function - // has to be retrieved by calling WSAGetLastError, whereas - // the "last error" code from non-socket POSIX-like functions - // is stored in errno as usual. - return mbg_win32_wsa_err_to_mbg( WSAGetLastError(), info ); + #if !defined( MBG_TGT_KERNEL ) + // Under Windows the "last error" code after a socket function + // has to be retrieved by calling WSAGetLastError, whereas + // the "last error" code from non-socket POSIX-like functions + // is stored in errno as usual. + return mbg_win32_wsa_err_to_mbg( WSAGetLastError(), info ); + #else + return MBG_ERR_GENERIC; + #endif #elif defined( MBG_TGT_POSIX ) @@ -637,7 +698,11 @@ int mbg_get_gethostbyname_error( const char *info ) #elif defined( MBG_TGT_WIN32 ) - return mbg_win32_wsa_err_to_mbg( WSAGetLastError(), info ); + #if !defined( MBG_TGT_KERNEL ) + return mbg_win32_wsa_err_to_mbg( WSAGetLastError(), info ); + #else + return MBG_ERR_GENERIC; + #endif #elif defined( MBG_TGT_POSIX ) @@ -723,6 +788,6 @@ int mbg_zlib_error_to_mbg( int zlib_error, const char *info, const char *msg ) } // mbg_zlib_error_to_mbg -#endif // defined(USE_MBG_ZLIB) +#endif // defined( USE_MBG_ZLIB ) diff --git a/mbglib/common/mbgerror.h b/mbglib/common/mbgerror.h index 5727f96..20a3edc 100755 --- a/mbglib/common/mbgerror.h +++ b/mbglib/common/mbgerror.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgerror.h 1.9 2016/10/31 17:41:55 martin TRASH $ + * $Id: mbgerror.h 1.15 2017/07/05 09:27:25 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -11,6 +11,24 @@ * * ----------------------------------------------------------------------- * $Log: mbgerror.h $ + * Revision 1.15 2017/07/05 09:27:25 martin + * New error code MBG_ERR_PARM_FMT. + * Changed message text for MBG_ERR_NO_ENTITY. + * Replaced old _mbg_err_to_os() macro by new inline functions + * mbg_errno_to_os() and mbg_ret_val_to_os(). + * Fixed build under Windows. + * Updated doxygen comments. + * Updated function prototypes. + * Revision 1.14 2017/05/10 15:21:39 martin + * Tiny cleanup. + * Revision 1.13 2017/02/28 15:23:14 gregoire + * error code MBG_ERR_INV_IDX added + * Revision 1.12 2017/01/10 15:54:56 philipp + * Fixed syntax error + * Revision 1.11 2017/01/10 14:26:31 philipp + * Added error MBG_ERR_NOT_CONFIGURED + * Revision 1.10 2016/12/16 12:40:33 thomas-b + * Added MBG_ERR_NO_SPACE * Revision 1.9 2016/10/31 17:41:55 martin * New error code MBG_ERR_DATA_FMT. * Revision 1.8 2016/08/05 12:29:20 martin @@ -62,10 +80,23 @@ /* Start of header body */ +#ifdef __cplusplus +extern "C" { +#endif + +#if defined( MBG_TGT_WIN32 ) + + #if !defined( STATUS_SUCCESS ) // not in kernel mode + #define STATUS_SUCCESS 0 + #endif + +#endif + + #if !defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_KERNEL ) - //### TODO Surprisingly we need this also for Windows - // in kernel mode. This should be fixed. - #define DWORD uint32_t // just to avoid compiler errors + // A dummy declaration for DWORD to avoid compiler errors. + // Also reqired in Windows kernel mode. + #define DWORD uint32_t #endif @@ -75,6 +106,11 @@ * * Appropriate error strings can be retrieved via the ::mbg_strerror function. * + * @see ::MBG_ERR_NAMES_ENG + * + * @anchor MBG_RETURN_CODES @{ */ + +/* ### TODO * Under Windows, some message strings are provided as resources appended * to the mbgctrl DLL, but the codes specified here have to be translated * to Windows-specific error codes before the appropriate resource string @@ -82,10 +118,7 @@ * of an error code and have it or'ed with 0xE0000000 afterwards, e.g. * ::MBG_ERR_GENERIC (-19) will yield Windows code 0xE0000013. * * See ::_mbg_err_to_os - * - * @see ::MBG_ERR_NAMES_ENG - * - * @anchor MBG_RETURN_CODES @{ */ + */ // NOTE: Some of these codes have to match codes which are defined in pcpsdefs.h // and returned by the firmware of bus-level devices, so the definitions @@ -187,12 +220,18 @@ #define MBG_ERR_EXIST -93 ///< file exists #define MBG_ERR_DATA_SIZE -94 ///< the received data size toesn't match the expected data size -#define MBG_ERR_NO_ENTITY -95 ///< no such entity //### TODO or use MBG_ERR_NO_DEV / MBG_ERR_NOT_FOUND ? +#define MBG_ERR_NO_ENTITY -95 ///< no such file or directory #define MBG_ERR_ALREADY_ALLOC -96 ///< pointer already allocated when trying to allocate memory #define MBG_ERR_HOST_NOT_FOUND -97 ///< host not found #define MBG_ERR_CONN_RESET -98 ///< connection reset by peer #define MBG_ERR_DATA_FMT -99 ///< invalid data format +#define MBG_ERR_NO_SPACE -100 ///< insufficient disk space left on the device +#define MBG_ERR_NOT_CONFIGURED -101 ///< configuration option is not active/configured +#define MBG_ERR_INV_IDX -102 ///< invalid index value used + +#define MBG_ERR_PARM_FMT -103 ///< parameter string format error + // NOTE: New codes have to be appended to this list, and the sequence of codes must not // be changed. Whenever new codes have been defined, appropriate entries have to be added // to the ::MBG_ERR_NAMES_ENG table initializer below, and the Windows-specific message @@ -279,11 +318,15 @@ { MBG_ERR_INV_TLV_UID, "MBG_ERR_INV_TLV_UID" }, /* ### TODO */ \ { MBG_ERR_EXIST, "File exists" }, \ { MBG_ERR_DATA_SIZE, "Received data size mismatch" }, \ - { MBG_ERR_NO_ENTITY, "No such entity" }, \ + { MBG_ERR_NO_ENTITY, "No such file or directory" }, \ { MBG_ERR_ALREADY_ALLOC, "Memory already allocated" }, \ { MBG_ERR_HOST_NOT_FOUND, "Host not found" }, \ { MBG_ERR_CONN_RESET, "Connection reset by peer" }, \ { MBG_ERR_DATA_FMT, "Invalid data format" }, \ + { MBG_ERR_NO_SPACE, "Insufficient disk space" }, \ + { MBG_ERR_NOT_CONFIGURED, "Configuration is not active and/or configured" }, \ + { MBG_ERR_INV_IDX, "Invalid or unsupported index value used"}, \ + { MBG_ERR_PARM_FMT, "Parameter string format error" }, \ { 0, NULL } /* end of table */ \ } @@ -335,30 +378,62 @@ bool mbg_rc_is_success( int rc ) -#if defined( MBG_TGT_WIN32 ) +static __mbg_inline /*HDR*/ +/** + * @brief Convert one of the @ref MBG_ERROR_CODES to an OS-specific format + * + * @param[in] err_no One of the @ref MBG_ERROR_CODES. + * + * @see @ref MBG_ERROR_CODES + */ +int mbg_errno_to_os( int err_no ) +{ + #if defined( MBG_TGT_WIN32 ) - // Windows-specific codes and code conversion + // Windows uses specially encoded numbers + return ( -err_no | 0xE0000000L ); + + #elif defined( MBG_TGT_BSD ) + + return -err_no; + + #else + + return err_no; - #if !defined( STATUS_SUCCESS ) // not in kernel mode - #define STATUS_SUCCESS 0 #endif - #define _mbg_err_to_os( _c ) \ - ( ( (_c) == MBG_SUCCESS ) ? STATUS_SUCCESS : ( abs( _c ) | 0xE0000000 ) ) +} // mbg_errno_to_os -#else - #define _mbg_err_to_os( _c ) (_c ) //### TODO remove this -#endif +static __mbg_inline /*HDR*/ +/** + * @brief Convert one of the @ref MBG_RETURN_CODES to an OS-specific format + * + * @param[in] rc One of the @ref MBG_RETURN_CODES. + * + * @see @ref MBG_RETURN_CODES + */ +int mbg_ret_val_to_os( int rc ) +{ + #if defined( MBG_TGT_WIN32 ) + return mbg_rc_is_error( rc ) ? mbg_errno_to_os( rc ) : STATUS_SUCCESS; + #elif defined( MBG_TGT_BSD ) + + return mbg_rc_is_error( rc ) ? mbg_errno_to_os( rc ) : MBG_SUCCESS; + + #else + + return rc; + + #endif + +} // mbg_ret_val_to_os -/* function prototypes: */ -#ifdef __cplusplus -extern "C" { -#endif /* ----- function prototypes begin ----- */ @@ -374,7 +449,37 @@ extern "C" { */ const char *mbg_strerror( int mbg_errno ) ; - int mbg_ioctl_err( int rc, const char *descr ) ; + /** + * @brief Check if a value is an error code and print an associated error message + * + * @param[in] rc A positive number including ::MBG_SUCCESS, or one of the @ref MBG_ERROR_CODES + * @param[in] what A string indicated what failed + * + * @return true if rc represented an error code, and a message has been printed, else false + */ + bool mbg_cond_err_msg( int rc, const char *what ) ; + + /** + * @brief Check if a value is an general or a "not supported" error code and print an associated message + * + * If rc contains an error code then an error message is printed, and true is returned. + * + * If the optional parameter string info2 is not NULL then it should contain + * the name of a feature which has been tested before. In this case, if the error + * code is the specific error ::MBG_ERR_NOT_SUPP_BY_DEV then a "not supported" message + * is printed using info2. + * + * If info2 is NULL, or the error code is not ::MBG_ERR_NOT_SUPP_BY_DEV then the standard + * error message is printed anyway. + * + * @param[in] rc A positive number including ::MBG_SUCCESS, or one of the @ref MBG_ERROR_CODES + * @param[in] what A string indicated what failed + * @param[in] info An optional informational string telling what is not supported (may be NULL). + * + * @return true if rc represented an error code, and a message has been printed, else false + */ + bool mbg_cond_err_msg_info( int rc, const char *what, const char *info ) ; + /** * @brief Translate an error code from the Labwindows/CVI RS-232 library to one of the @ref MBG_ERROR_CODES * diff --git a/mbglib/common/mbgntp.h b/mbglib/common/mbgntp.h index d208b45..1b00f7f 100755 --- a/mbglib/common/mbgntp.h +++ b/mbglib/common/mbgntp.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: mbgntp.h 1.8 2016/07/14 08:17:23 martin REL_M $ + * $Id: mbgntp.h 1.10 2017/08/15 15:45:02 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,11 @@ * * ----------------------------------------------------------------------- * $Log: mbgntp.h $ + * Revision 1.10 2017/08/15 15:45:02 martin + * Define NSECS_PER_SEC only if it hasn't been defined before. + * Revision 1.9 2016/12/01 17:05:24 martin + * Use new union NTP_REFID or the packet's refid field. + * New function leap_smearing_active() which also decodes the offset from the refid. * Revision 1.8 2016/07/14 08:17:23 martin * Fixed build under Windows. * Revision 1.7 2014/10/28 08:52:33Z martin @@ -90,7 +95,9 @@ #define NTP_SEC_BIAS 2208988800UL -#define NSECS_PER_SEC 1000000000UL +#if !defined( NSECS_PER_SEC ) + #define NSECS_PER_SEC 1000000000UL +#endif #define NTP_FRAC_PER_SEC (uint64_t) 4294967296.0 @@ -199,6 +206,32 @@ typedef struct /** + * @brief The refid field used in NTP packets + * + * This field can be interpreted in different ways. + * It can contain a 4 character ASCII string <b>without terminating 0</b>, + * or an IPv4 address, or the hash of an IPv6 address. In case of an NTP + * server where leap second smearing is in progress the contents is a + * pseudo IPv4 address 254.x.y.z where x.y.z have to be interpreted as + * signed 24 bit number, scaled to the range +/-2, representing the + * current leap smear offset. + * Endianess needs to be taken into account. + * + * @see ::leap_smear_offset_from_refid + * @see https://support.ntp.org/bin/view/Dev/LeapSmearForNTPv4 + * @see http://bugs.ntp.org/show_bug.cgi?id=2855 + */ +typedef union +{ + uint32_t as_u32; + uint8_t as_u8s[sizeof( uint32_t )]; + char as_chars[sizeof( uint32_t )]; + +} NTP_REFID; + + + +/** * @brief The NTP base packet * * If authentication is used an ::NTP_MAC field can be appended to the packet, @@ -217,7 +250,7 @@ typedef struct NTP_FLAGS flags; NTP_U_FP root_delay; NTP_U_FP root_dispersion; - uint32_t reference_id; + NTP_REFID refid; NTP_TSTAMP reference_time; NTP_TSTAMP originate_time; NTP_TSTAMP receive_time; @@ -418,6 +451,41 @@ double delta_tstamps( const NTP_TSTAMP *t, +/** + * @brief Check refid if leap smearing active, and decode smear offset + * + * @param[in] p The refid field received in an NTP packet from a server + * @param[out] p_offs Used to return the decoded leap smear offset, if applicable, else 0 + * + * @return true if leap smearing is active, else false. + */ +static __mbg_inline /*HDR*/ +bool leap_smearing_active( const NTP_REFID *p, double *p_offs ) +{ + // If smearing is active the refid contains a pseudo IP address + // 254.x.y.z where x.y.z contains the current smear offset. + // See ::NTP_REFID + bool smearing_active = p->as_u8s[0] == 254; + + if ( p_offs ) // we need to return the current offset + { + double offs = 0.0; // default, if smearing not active + + if ( smearing_active ) + { + int32_t tmp = ( ntohl( p->as_u32 ) << 8 ) & 0xFFFFFF00UL; + offs = ( (double) tmp ) / (double) 0x40000000; + } + + *p_offs = offs; + } + + return smearing_active; + +} // leap_smearing_active + + + /* function prototypes: */ #ifdef __cplusplus diff --git a/mbglib/common/mbgtime.h b/mbglib/common/mbgtime.h new file mode 100755 index 0000000..02f5fd9 --- /dev/null +++ b/mbglib/common/mbgtime.h @@ -0,0 +1,731 @@ + +/************************************************************************** + * + * $Id: mbgtime.h 1.25 2017/08/15 15:48:59 martin REL_M $ + * + * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany + * + * Description: + * Definitions and prototypes for mbgtime.c. + * + * ----------------------------------------------------------------------- + * $Log: mbgtime.h $ + * Revision 1.25 2017/08/15 15:48:59 martin + * Define NSECS_PER_SEC only if it hasn't been defined before. + * Revision 1.24 2017/07/04 14:02:25 martin + * Made definitions of some constants signed to avoid + * signed/unsigned compiler warnings. + * Moved some macros and inline functions for fraction + * conversion here. They are excluded from build in kernel + * mode, though, since some kernels don't support this properly. + * Moved some NANO_TIME- and NANO_TIME_64-related inline + * functions to new module nanotime.c. + * Renamed PCPS_HRT_BIN_FRAC_SCALE to MBG_FRAC32_UNITS_PER_SEC. + * Updated function prototypes. + * Doxygen stuff. + * Revision 1.23 2017/03/16 12:26:13 martin + * Updated function prototypes. + * Revision 1.22 2017/01/25 13:10:55 gregoire.diehl + * nano_time_64_to_double and double_to_nano_time_64 added + * Revision 1.21 2016/12/15 17:44:59Z martin + * Changed conditions to include time.h. + * Fixed spelling. + * Removed trailing spaces. + * Revision 1.20 2014/05/27 08:09:19 martin + * Added NTP_SEC_BIAS. + * Revision 1.19 2013/05/22 16:47:01 martin + * Added some useful macros. + * Revision 1.18 2012/10/02 18:51:11 martin + * Include <time.h> for WIN32 target and firmware only + * Fixed build under QNX, DOS, and FreeBSD. + * Revision 1.17 2010/08/06 13:03:03 martin + * Removed obsolete code. + * Revision 1.16 2010/07/16 10:22:07Z martin + * Moved definitions of HNS_PER_SEC and HNS_PER_MS here. + * Conditionally define FILETIME_1970. + * Defined MASK_CLOCK_T for ARM/Cortex. + * Revision 1.15 2009/10/23 09:55:21 martin + * Added MJD numbers for commonly used epochs. + * Revision 1.14 2009/08/12 10:28:12 daniel + * Added definition NSECS_PER_SEC. + * Revision 1.13 2009/06/12 13:31:44Z martin + * Fix build errors with arm-linux-gcc. + * Revision 1.12 2009/03/27 14:14:00 martin + * Cleanup for CVI. + * Revision 1.11 2009/03/13 09:30:06Z martin + * Include mystd.h in mbgtime.c rather than here. The bit type used + * here is now defined in words.h. + * Updated comments for GPS_SEC_BIAS. + * Revision 1.10 2008/12/11 10:45:41Z martin + * Added clock_t mask for gcc (GnuC). + * Revision 1.9 2006/08/25 09:33:46Z martin + * Updated function prototypes. + * Revision 1.8 2004/12/28 11:29:02Z martin + * Added macro _n_days. + * Updated function prototypes. + * Revision 1.7 2002/09/06 07:15:48Z martin + * Added MASK_CLOCK_T for Linux. + * Revision 1.6 2002/02/25 08:37:44 Andre + * definition MASK_CLOCK_T for ARM added + * Revision 1.5 2001/03/02 10:18:10Z MARTIN + * Added MASK_CLOCK_T for Watcom C. + * Revision 1.4 2000/09/15 07:57:53 MARTIN + * Removed outdated function prototypes. + * Revision 1.3 2000/07/21 14:05:18 MARTIN + * Defined some new constants. + * + **************************************************************************/ + +#ifndef _MBGTIME_H +#define _MBGTIME_H + + +/* Other headers to be included */ + +#include <gpsdefs.h> + +#if !defined( MBG_TGT_KERNEL ) || defined( MBG_TGT_WIN32 ) + #include <time.h> +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _MBGTIME + #define _ext + #define _DO_INIT +#else + #define _ext extern +#endif + + +/* Start of header body */ + + +/** + * @brief GPS epoch bias from ordinary time_t epoch + * + * The Unix time_t epoch is usually 1970-01-01 00:00 whereas + * the GPS epoch is 1980-01-06 00:00, so the difference is 10 years, + * plus 2 days due to leap years (1972 and 1976), plus the difference + * of the day-of-month (6 - 1), so:<br> + * + * time_t t = ( gps_week * ::SECS_PER_WEEK ) + sec_of_week + ::GPS_SEC_BIAS + */ +#define GPS_SEC_BIAS 315964800UL // ( ( ( 10UL * 365UL ) + 2 + 5 ) * SECS_PER_DAY ) + + +/** + * @brief NTP epoch bias from ordinary time_t epoch + * + * The Unix time_t epoch is usually 1970-01-01 00:00 whereas + * the NTP epoch is 1900-01-01 00:00, so the difference is + * a constant number of seconds:<br> + * + * time_t t = ntp_time - ::NTP_SEC_BIAS + */ +#define NTP_SEC_BIAS 2208988800UL + + + +// Modified Julian Day (MJD) numbers for some commonly used epochs. +// To compute the MJD for a given date just compute the days since epoch +// and add the constant number of days according to the epoch, e.g.: +// current_unix_mjd = ( time( NULL ) / SECS_PER_DAY ) + MJD_AT_UNIX_EPOCH; +#define MJD_AT_GPS_EPOCH 44244UL // MJD at 1980-01-06 +#define MJD_AT_UNIX_EPOCH 40587UL // MJD at 1970-01-01 +#define MJD_AT_NTP_EPOCH 40587UL // MJD at 1900-01-01 + + +// The constant below defines the Windows FILETIME number (100 ns intervals +// since 1601-01-01) for 1970-01-01, which is usually the epoch for the time_t +// type used by the standard C library. +#if !defined( FILETIME_1970 ) + // FILETIME represents a 64 bit number, so we need to defined the + // constant with an appendix depending on the compiler. + #if MBG_TGT_C99 || defined( __GNUC__ ) + // syntax introduced by C99 standard + #define FILETIME_1970 0x019db1ded53e8000ULL // Epoch offset from FILETIME to UNIX + #elif defined( MBG_TGT_WIN32 ) + // MSC-specific syntax + #define FILETIME_1970 0x019db1ded53e8000ui64 + #endif +#endif + + +#if defined( _C166 ) + #if _C166 >= 50 + #define MASK_CLOCK_T 0x7FFFFFFFL + #else + #define MASK_CLOCK_T 0x7FFF /* time.h not shipped with compiler */ + #endif +#endif + +#if defined( __WATCOMC__ ) + #define MASK_CLOCK_T 0x7FFFFFFFL +#endif + +#if defined( _CVI ) || defined( _CVI_ ) + #define MASK_CLOCK_T 0x7FFFFFFFL +#endif + +#if defined( _MSC_VER ) + #define MASK_CLOCK_T 0x7FFFFFFFL +#endif + +#if defined( __NETWARE_386__ ) + #define MASK_CLOCK_T 0x7FFFFFFFL +#endif + +#if defined( __ARM ) + #define MASK_CLOCK_T 0x7FFFFFFFL +#endif + +#if defined( __ARMCC_VERSION ) + #define MASK_CLOCK_T ( ( (ulong) (clock_t) -1 ) >> 1 ) +#endif + +#if defined( __GNUC__ ) + #if defined( __linux ) + #define MASK_CLOCK_T ( ( (ulong) (clock_t) -1 ) >> 1 ) + #else // Windows / MinGW + #define MASK_CLOCK_T 0x7FFFFFFFL + #endif +#endif + + +#if !defined( MASK_CLOCK_T ) + #if sizeof( clock_t ) == sizeof( short ) + #define MASK_CLOCK_T 0x7FFF + #elif sizeof( clock_t ) == sizeof( long ) + #define MASK_CLOCK_T 0x7FFFFFFFL + #endif +#endif + +typedef struct +{ + clock_t start; + clock_t stop; + short is_set; + +} TIMEOUT; + + +#define DAYS_PER_WEEK 7 + +#define SECS_PER_MIN 60 +#define MINS_PER_HOUR 60 +#define HOURS_PER_DAY 24 +#define DAYS_PER_WEEK 7 + +#define MINS_PER_DAY ( MINS_PER_HOUR * HOURS_PER_DAY ) + +#define SECS_PER_HOUR 3600 +#define SECS_PER_DAY 86400L +#define SECS_PER_WEEK 604800L + +#define SEC100S_PER_SEC 100L +#define SEC100S_PER_MIN ( SEC100S_PER_SEC * SECS_PER_MIN ) +#define SEC100S_PER_HOUR ( SEC100S_PER_SEC * SECS_PER_HOUR ) +#define SEC100S_PER_DAY ( SEC100S_PER_SEC * SECS_PER_DAY ) + +#if !defined( MSEC_PER_SEC ) + #define MSEC_PER_SEC 1000L +#endif + +#define MSEC_PER_MIN ( MSEC_PER_SEC * SECS_PER_MIN ) +#define MSEC_PER_HOUR ( MSEC_PER_SEC * SECS_PER_HOUR ) +#define MSEC_PER_DAY ( MSEC_PER_SEC * SECS_PER_DAY ) + +#if !defined( NSECS_PER_SEC ) + #define NSECS_PER_SEC 1000000000L +#endif + +#if !defined( HNS_PER_SEC ) + #define HNS_PER_SEC 10000000L +#endif + +#if !defined( HNS_PER_MS ) + #define HNS_PER_MS 10000L +#endif + + +/** + * @brief A table with the days of month + * + * First row is for standard years, second row is + * for leap years. + * + * @see DAYS_OF_MONTH_TABLE_INIT + */ +typedef char DAYS_OF_MONTH_TABLE[2][12]; + + +/** + * @brief An initializer for a ::DAYS_OF_MONTH_TABLE + */ +#define DAYS_OF_MONTH_TABLE_INIT \ +{ \ + { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, \ + { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } \ +} + + + + +_ext TM_GPS dhms; +_ext TM_GPS datum; + + +_ext const char *short_time_fmt +#ifdef _DO_INIT + = "%2i:%02i" +#endif +; + +_ext const char *time_fmt +#ifdef _DO_INIT + = "%2i:%02i:%02i" +#endif +; + +_ext const char *long_time_fmt +#ifdef _DO_INIT + = "%2i:%02i:%02i.%02i" +#endif +; + +_ext const char *date_fmt +#ifdef _DO_INIT + = "%2i.%02i.%04i" +#endif +; + +_ext const char *day_date_fmt +#ifdef _DO_INIT + = "%s, %2i.%02i.%04i" +#endif +; + +_ext const char *day_name_eng[] +#ifdef _DO_INIT + = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" } +#endif +; + +_ext const char *day_name_ger[] +#ifdef _DO_INIT + = { "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" } +#endif +; + +_ext const TM_GPS init_tm +#ifdef _DO_INIT + = { 1980, 1, 1, 0, 0, 0, 0, 0, 0, 0 } +#endif +; + + +_ext DAYS_OF_MONTH_TABLE days_of_month +#ifdef _DO_INIT + = DAYS_OF_MONTH_TABLE_INIT +#endif +; + + +// simplify call to n_days with structures +#define _n_days( _s ) \ + n_days( (_s)->mday, (_s)->month, (_s)->year ) + + +#define _is_leap_year( _y ) \ + ( ( ( ( (_y) % 4 ) == 0 ) && ( ( (_y) % 100 ) != 0 ) ) || ( ( (_y) % 400 ) == 0 ) ) + + +#define _get_days_of_month( _y, _m ) \ + days_of_month[ _is_leap_year( _y ) ][_m] + + + +#if !defined( MBG_TGT_KERNEL ) + +/** + * @brief Data type used for intermediate results on 32 bit multiplications + * + * We need 64 bits for intermediate integer results to avoid a range overflow + * from 32 x 32 bit multiplications. On systems which don't support 64 bit types + * we use the "double" type as a workaround. + */ +#if defined( MBG_TGT_MISSING_64_BIT_TYPES ) + #define MBG_FRAC32_CONVERSION_TYPE double +#else + #define MBG_FRAC32_CONVERSION_TYPE int64_t +#endif + +/** + * @brief Constant used to convert e.g. ::PCPS_TIME_STAMP::frac values + * + * Max value of ::PCPS_TIME_STAMP::frac + 1, used for scaling + */ +#define MBG_FRAC32_UNITS_PER_SEC ( (MBG_FRAC32_CONVERSION_TYPE) 4294967296.0 ) // == 0x100000000 + + + +/** + * @brief Convert a 16 bit binary fraction to a scaled decimal + * + * @param[in] bin The binary fraction + * @param[in] scale The scale factor + * + * @return The calculated number + * + * @see ::dec_frac_to_bin_frac_16 + * @see ::dec_frac_to_bin_frac_32 + * @see ::bin_frac_32_to_dec_frac + * @see ::frac_sec_from_bin + */ +static __mbg_inline +uint32_t bin_frac_16_to_dec_frac( uint16_t bin, uint32_t scale ) +{ + return (uint32_t) ( (MBG_FRAC32_CONVERSION_TYPE) bin * scale + / 0x10000UL ); + +} // bin_frac_16_to_dec_frac + + + +/** + * @brief Convert a 32 bit binary fraction to a scaled decimal + * + * @param[in] bin The binary fraction + * @param[in] scale The scale factor + * + * @return The calculated number + * + * @see ::dec_frac_to_bin_frac_32 + * @see ::dec_frac_to_bin_frac_16 + * @see ::bin_frac_16_to_dec_frac + */ +static __mbg_inline +uint32_t bin_frac_32_to_dec_frac( uint32_t bin, uint32_t scale ) +{ + return (uint32_t) ( (MBG_FRAC32_CONVERSION_TYPE) bin * scale + / MBG_FRAC32_UNITS_PER_SEC ); + +} // bin_frac_32_to_dec_frac + + + +#if !defined( MBG_TGT_MISSING_64_BIT_TYPES ) + +// On targets which don't provide 64 bit data types +// MBG_FRAC32_CONVERSION_TYPE is defined as double, +// in which case the ">> 1" operation in the 2 functions +// below yields an "invalid use of floating point" error. +// This could probably be fixed by a different way of +// casting, at least for a partial expression. + +static __mbg_inline +uint16_t dec_frac_to_bin_frac_16( uint32_t dec, uint32_t scale ) +{ + return (uint16_t) ( ( ( (MBG_FRAC32_CONVERSION_TYPE) dec * 0x20000 / scale ) + 1 ) >> 1 ); + +} // dec_frac_to_bin_frac_16 + + +static __mbg_inline +uint32_t dec_frac_to_bin_frac_32( uint32_t dec, uint32_t scale ) +{ + return (uint32_t) ( ( ( (MBG_FRAC32_CONVERSION_TYPE) dec * MBG_FRAC32_UNITS_PER_SEC * 2 / scale ) + 1 ) >> 1 ); + +} // dec_frac_to_bin_frac_32 + +#endif // !defined( MBG_TGT_MISSING_64_BIT_TYPES ) + + + +#define bin_frac_32_to_msec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000L ) +#define bin_frac_32_to_usec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000000L ) +#define bin_frac_32_to_nsec( _bin ) bin_frac_32_to_dec_frac( (_bin), 1000000000L ) +#define bin_frac_16_to_msec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000L ) +#define bin_frac_16_to_usec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000000L ) +#define bin_frac_16_to_nsec( _bin ) bin_frac_16_to_dec_frac( (_bin), 1000000000L ) + + +#define msec_to_bin_frac_32( _msec ) dec_frac_to_bin_frac_32( (_msec), 1000L ) +#define usec_to_bin_frac_32( _usec ) dec_frac_to_bin_frac_32( (_usec), 1000000L ) +#define nsec_to_bin_frac_32( _nsec ) dec_frac_to_bin_frac_32( (_nsec), 1000000000L ) +#define msec_to_bin_frac_16( _msec ) dec_frac_to_bin_frac_16( (_msec), 1000L ) +#define usec_to_bin_frac_16( _usec ) dec_frac_to_bin_frac_16( (_usec), 1000000L ) +#define nsec_to_bin_frac_16( _nsec ) dec_frac_to_bin_frac_16( (_nsec), 1000000000L ) + + + +/** + * @brief Convert a binary fraction to a scaled decimal + * + * Convert a binary fraction (e.g. of a second, as in ::PCPS_TIME_STAMP::frac) + * to a decimal fraction, using a specified scale factor. + * + * @deprecated This function is deprecated, use ::bin_frac_32_to_dec_frac preferably. + * + * @param[in] b The binary fraction + * @param[in] scale The scale factor + * + * @return The calculated number + * + * @see ::bin_frac_32_to_dec_frac + */ +static __mbg_inline +uint32_t _DEPRECATED_BY( "bin_frac_32_to_dec_frac" ) frac_sec_from_bin( uint32_t b, uint32_t scale ) +{ + return bin_frac_32_to_dec_frac( b, scale ); + +} // frac_sec_from_bin + + + +/** + * @brief Convert a binary fraction to "double" fractions + * + * Convert a binary fraction (e.g. of a second, as in ::PCPS_TIME_STAMP::frac) + * to a "double" with the units of seconds.<br> + * E.g. a 0xFFFFFFFF fraction yields 0.9999999999.... + * + * @note Excluded from build for kernel drivers which usually + * don't support floating point operations. + * + * @param[in] b The binary fraction + * + * @return The calculated fraction + * + * @see ::MBG_FRAC32_UNITS_PER_SEC + */ +static __mbg_inline +double dfrac_sec_from_bin( uint32_t b ) +{ + return (double) b / (double) MBG_FRAC32_UNITS_PER_SEC; + +} // dfrac_sec_from_bin + +#endif // !defined( MBG_TGT_KERNEL ) + + + +/* ----- function prototypes begin ----- */ + +/* This section was generated automatically */ +/* by MAKEHDR, do not remove the comments. */ + + /** + * @brief Set a timeout object to specified interval + * + * @param[out] t The timeout object + * @param[in] clk The current time, in clock_t ticks + * @param[in] interval The interval until expiration, in clock_t ticks + */ + void set_timeout( TIMEOUT *t, clock_t clk, clock_t interval ) ; + + /** + * @brief Stretch a timeout specified in given timeout object + * + * @param[in,out] t The timeout object + * @param[in] interval The interval until expiration, in clock_t ticks + */ + void stretch_timeout( TIMEOUT *t, clock_t interval ) ; + + /** + * @brief Check if a timeout object has expired + * + * @param[in] t The timeout object + * @param[in] clk The current time, in clock_t ticks + * + * @return 1 if timeout expired, else 0 + */ + bit check_timeout( TIMEOUT *t, clock_t clk ) ; + + /** + * @brief Check if a ::TM_GPS structure contains a valid date and time + * + * @param[in] tm The date/time structure to be checked + * + * @return 0 if date/time is valid, else a negative number indicating + * which field was found invalid + */ + int err_tm( const TM_GPS *tm ) ; + + /** + * @brief Set the time in a ::TM_GPS structure to 00:00:00.000 + * + * @param[in,out] tm The date/time structure to be set + * + * @return Pointer to the ::TM_GPS structure that has been passed + */ + TM_GPS *clear_time( TM_GPS *tm ) ; + + /** + * @brief Convert second-of-week to day-of-week and time-of-day + * + * @param[in] wsec The second-of-week number to be converted + * @param[out] tm Address of a ::TM_GPS structure which takes the computed results + * + * @return Pointer to the ::TM_GPS structure that has been passed + * + * @see ::tm_to_wsec + */ + TM_GPS *wsec_to_tm( long wsec, TM_GPS *tm ) ; + + /** + * @brief Compute second-of-week from day-of-week and time-of-day + * + * @todo Specify input / output ranges + * + * @param[in] tm Address of a ::TM_GPS structure providing day-of-week and time-of-day + * + * @return The computed second-of-week number + * + * @see ::wsec_to_tm + */ + long tm_to_wsec( const TM_GPS *tm ) ; + + /** + * @brief Check if a specific year is a leap year + * + * @param[in] y The full year number + * + * @return != 0 if the year is a leap year, else 0 + */ + int is_leap_year( int y ) ; + + /** + * @brief Compute the day-of-year from a given date + * + * @param[in] day The day-of-month + * @param[in] month The month + * @param[in] year The full year number + * + * @return The computed day-of-year + */ + int day_of_year( int day, int month, int year ) ; + + /** + * @brief Compute a date from a given year and day-of-year + * + * @param[in] year The full year number + * @param[in] day_num Number of days from the beginning of that year, may be negative + * @param[out] tm Address of a ::TM_GPS structure which takes the computed results + */ + void date_of_year ( int year, int day_num, TM_GPS *tm ) ; + + /** + * @brief Compute day-of-week from a given date + * + * @todo Specify range of returned day-of-week. Should we just call n_days()? + * + * @param[in] day The day-of-month + * @param[in] month The month + * @param[in] year The full year number + * + * @return The computed day-of-week + * + * @see ::n_days + */ + int day_of_week( int day, int month, int year ) ; + + /** + * @brief Update a year number by a number of days, accounting for leap years + * + * @param[in] day_num The number of days to evaluate + * @param[in] year The year number to start with + * + * @return The computed year number + */ + int days_to_years( long *day_num, int year ) ; + + /** + * @brief Compute number of days after Jan 1, 0000 for a given date + * + * @param[in] mday The day-of-month + * @param[in] month The month + * @param[in] year The full year number + * + * @return The computed number of days + * + * @see ::day_of_week + */ + long n_days( ushort mday, ushort month, ushort year ) ; + + /** + * @brief Print time with hours, minutes, seconds to a string + * + * @param[out] s Address of a string buffer to be filled + * @param[in] tm Address of a ::TM_GPS structure providing date and time + */ + int sprint_time( char *s, const TM_GPS *tm ) ; + + /** + * @brief Print time with hours, minutes to a string + * + * @param[out] s Address of a string buffer to be filled + * @param[in] tm Address of a ::TM_GPS structure providing date and time + */ + int sprint_short_time( char *s, const TM_GPS *tm ) ; + + /** + * @brief Print date to a string + * + * @param[out] s Address of a string buffer to be filled + * @param[in] tm Address of a ::TM_GPS structure providing date and time + */ + int sprint_date( char *s, const TM_GPS *tm ) ; + + /** + * @brief Print day-of-week and date to a string + * + * @param[out] s Address of a string buffer to be filled + * @param[in] tm Address of a ::TM_GPS structure providing date and time + */ + int sprint_day_date( char *s, const TM_GPS *tm ) ; + + /** + * @brief Print day-of-week, date and time to a string + * + * @param[out] s Address of a string buffer to be filled + * @param[in] tm Address of a ::TM_GPS structure providing date and time + */ + int sprint_tm( char *s, const TM_GPS *tm ) ; + + /** + * @brief Extract a time from a string + * + * @param[in] s A time string in format hh:mm:ss + * @param[out] tm Address of a ::TM_GPS structure which takes the extracted time + */ + void sscan_time( const char *s, TM_GPS *tm ) ; + + /** + * @brief Extract a date from a string + * + * @param[in] s A date string in format dd.mm. or dd.mm.yyyy + * @param[out] tm Address of a ::TM_GPS structure which takes the extracted date + */ + void sscan_date( char *s, TM_GPS *tm ) ; + + +/* ----- function prototypes end ----- */ + + +/* End of header body */ + + +#undef _ext +#undef _DO_INIT + +#ifdef __cplusplus +} +#endif + + +#endif /* _MBGTIME_H */ diff --git a/mbglib/common/str_util.h b/mbglib/common/str_util.h index 2408e73..3b49318 100755 --- a/mbglib/common/str_util.h +++ b/mbglib/common/str_util.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: str_util.h 1.2 2016/08/05 12:33:17 martin REL_M $ + * $Id: str_util.h 1.4 2017/05/10 15:26:10 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,6 +10,10 @@ * * ----------------------------------------------------------------------- * $Log: str_util.h $ + * Revision 1.4 2017/05/10 15:26:10 martin + * Tiny cleanup. + * Revision 1.3 2016/12/14 16:22:24 martin + * Added macro _sn_cpy_str_safe() to simplify calls. * Revision 1.2 2016/08/05 12:33:17 martin * Moved string trim functions from cfg_util module here. * Added variable str_not_avail. @@ -52,8 +56,8 @@ _ext const char *str_not_avail #endif ; +#define _sn_cpy_str_safe( _dst, _src ) sn_cpy_str_safe( _dst, sizeof( _dst ), _src ) -/* function prototypes: */ /* ----- function prototypes begin ----- */ diff --git a/mbglib/common/timeutil.c b/mbglib/common/timeutil.c index 026570f..a239f04 100755 --- a/mbglib/common/timeutil.c +++ b/mbglib/common/timeutil.c @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: timeutil.c 1.1.1.3 2016/11/21 15:22:37 martin TRASH $ + * $Id: timeutil.c 1.3 2017/08/24 13:51:48 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,11 +10,11 @@ * * ----------------------------------------------------------------------- * $Log: timeutil.c $ - * Revision 1.1.1.3 2016/11/21 15:22:37 martin - * Revision 1.1.1.2 2016/08/11 15:09:46Z martin - * *** empty log message *** - * Revision 1.1.1.1 2016/08/11 07:54:40 martin - * Fixed build with old Visual Studio. + * Revision 1.3 2017/08/24 13:51:48 martin + * Fixed a xcompiler warning under Windows (x64). + * Revision 1.2 2017/07/05 07:10:48Z martin + * Added mbg_clock_gettime(), mbg_clock_settime(), + * and check_precise_time_api() for Windows. * Revision 1.1 2016/07/15 14:14:19Z martin * Initial revision * @@ -24,19 +24,20 @@ #include <timeutil.h> #undef _TIMEUTIL +#include <mbgtime.h> #include <str_util.h> -#include <mbgerror.h> #if defined( MBG_TGT_WIN32 ) + #include <mbgerror.h> // NSECS_PER_SEC #include <stdio.h> #endif /*HDR*/ -int snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc ) +size_t snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc ) { - int n = snprintf_safe( s, max_len, "gmtime() call failed" ); + size_t n = snprintf_safe( s, max_len, "gmtime() call failed" ); if ( calling_fnc ) n += snprintf_safe( &s[n], max_len - n, " in %s", calling_fnc ); @@ -58,27 +59,29 @@ int snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, cons #if defined( MBG_TGT_WIN32 ) -#define CLOCK_REALTIME 0 +typedef int clockid_t; +#define clockid_t clockid_t + +#define CLOCK_REALTIME ( (clockid_t) 0 ) /*HDR*/ -int mbg_clock_gettime( int clock_id, struct timespec *res ) +int mbg_clock_gettime( clockid_t clock_id, struct timespec *tp ) { if ( clock_id == CLOCK_REALTIME ) { #if defined( TIME_UTC ) // C11 / VS2015+ - int rc = timespec_get( res, TIME_UTC ); // TODO Check this code + int rc = timespec_get( tp, TIME_UTC ); // TODO Check this code return ( rc == 0 ) ? -1 : 0 // rc == 0 means error #else #define EPOCH_HNS 116444736000000000i64 - #define NSEC_PER_SEC 1000000000i64 FILETIME ft; unsigned __int64 tmp; gstaft_fnc( &ft ); tmp = ( (__int64) ft.dwHighDateTime << 32 ) | ft.dwLowDateTime; tmp -= EPOCH_HNS; // convert to Unix epoch tmp *= 100; // convert to nanoseconds - res->tv_sec = ( tmp / NSEC_PER_SEC ); - res->tv_nsec = ( tmp % NSEC_PER_SEC ); + tp->tv_sec = ( tmp / NSECS_PER_SEC ); + tp->tv_nsec = (long) ( tmp % NSECS_PER_SEC ); return 0; #endif } @@ -89,7 +92,39 @@ int mbg_clock_gettime( int clock_id, struct timespec *res ) -bool force_legacy_gstaft; +/*HDR*/ +int mbg_clock_settime( clockid_t clock_id, const struct timespec *tp ) +{ + if ( clock_id == CLOCK_REALTIME ) + { +#if 0 // ### TODO FIXME This needs to be implemented. + #if defined( TIME_UTC ) // C11 / VS2015+ + int rc = timespec_get( res, TIME_UTC ); // TODO Check this code + return ( rc == 0 ) ? -1 : 0 // rc == 0 means error + #else + #define EPOCH_HNS 116444736000000000i64 + FILETIME ft; + unsigned __int64 tmp; + gstaft_fnc( &ft ); + tmp = ( (__int64) ft.dwHighDateTime << 32 ) | ft.dwLowDateTime; + tmp -= EPOCH_HNS; // convert to Unix epoch + tmp *= 100; // convert to nanoseconds + res->tv_sec = ( tmp / NSECS_PER_SEC ); + res->tv_nsec = ( tmp % NSECS_PER_SEC ); + return 0; + #endif +#endif + + return 0; // FIXME this is actually not true + } + else + return -1; // TODO this is e.g. in case of CLOCK_MONOTONIC, we could use QPC then. + +} // mbg_clock_settime + + + +bool force_legacy_gstaft; /*HDR*/ diff --git a/mbglib/common/timeutil.h b/mbglib/common/timeutil.h index d5f7e02..233c174 100755 --- a/mbglib/common/timeutil.h +++ b/mbglib/common/timeutil.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: timeutil.h 1.2.1.1 2016/08/11 15:09:51 martin TRASH $ + * $Id: timeutil.h 1.3 2017/07/05 07:15:00 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,10 +10,10 @@ * * ----------------------------------------------------------------------- * $Log: timeutil.h $ - * Revision 1.2.1.1 2016/08/11 15:09:51 martin - * *** empty log message *** - * Revision 1.2 2016/08/11 13:44:00 martin - * Include stddef.h. + * Revision 1.3 2017/07/05 07:15:00 martin + * Provide basic support for clock_gettime()/clock_settime() + * compatible functions for Windows. + * Updated function prototypes. * Revision 1.1 2016/07/15 14:14:20Z martin * Initial revision * @@ -46,6 +46,17 @@ extern "C" { #endif +#if defined( MBG_TGT_WIN32 ) || defined( MBG_TGT_DOS ) + +typedef int clockid_t; +#define clockid_t clockid_t + +#define CLOCK_REALTIME ( (clockid_t) 0 ) + +#endif + + + #if defined( MBG_TGT_WIN32 ) #define __const__ const @@ -67,8 +78,6 @@ _ext GSTAFT_FNC gstaft_fnc #endif -/* function prototypes: */ - static __mbg_inline time_t cvt_to_time_t( time_t t ) { @@ -100,7 +109,10 @@ int mbg_gmtime( struct tm *p_tm, const time_t *p_time ) /* This section was generated automatically */ /* by MAKEHDR, do not remove the comments. */ - int snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc ) ; + size_t snprint_gmtime_error( char *s, size_t max_len, int mbg_errno, time_t t, const char *calling_fnc ) ; + int mbg_clock_gettime( clockid_t clock_id, struct timespec *tp ) ; + int mbg_clock_settime( clockid_t clock_id, const struct timespec *tp ) ; + void check_precise_time_api( void ) ; /* ----- function prototypes end ----- */ diff --git a/mbglib/common/words.h b/mbglib/common/words.h index 95042a7..9cbc841 100755 --- a/mbglib/common/words.h +++ b/mbglib/common/words.h @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: words.h 1.35 2016/08/05 12:17:21 martin REL_M $ + * $Id: words.h 1.42 2017/07/26 14:28:50 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -10,10 +10,27 @@ * * ----------------------------------------------------------------------- * $Log: words.h $ + * Revision 1.42 2017/07/26 14:28:50 martin + * Fixed build for NetBSD. + * Revision 1.41 2017/07/05 12:06:35 martin + * Moved macro _int_from_size_t() here. + * Revision 1.40 2017/06/12 11:14:25 martin + * Empty _DEPRECATED_BY definition for firmware targets. + * Revision 1.39 2017/03/15 10:01:09 martin + * Added comments how to represent negative numbers in NANO_TIME + * and NANO_TIME_64 structures. + * Added macros _nano_time_zero() and _nano_time_64_zero(). + * Revision 1.38 2017/02/22 11:56:33 martin + * Made MBG_CODE_NAME_TABLE_ENTRY::code signed to + * avoid signed/unsigned warnings with some code tables. + * Revision 1.37 2017/01/27 12:24:35Z martin + * Moved STRINGIFY() macro here. + * Revision 1.36 2017/01/27 08:59:43 martin + * Fixed macro syntax. * Revision 1.35 2016/08/05 12:17:21 martin * Moved definitions for NANO_TIME and NANO_TIME_64 here. * New macro _nano_time_64_negative(). - * Conditionally define _abs64() macro. + * Conditionally define _abs64() macro. * Include <inttypes.h> for Keil ARMCC target. * Added some conditional debugging code. * Fixed some spelling. @@ -136,6 +153,10 @@ #else #define MBG_TGT_MISSING_64_BIT_TYPES 1 #endif + + #if !defined( _DEPRECATED_BY ) + #define _DEPRECATED_BY( _s ) // empty definition + #endif #endif @@ -311,10 +332,11 @@ #endif -#if defined( MBG_TGT_MISSING_BOOL_TYPE ) /* from mbg_tgt.h */ \ - || ( !defined( __cplusplus ) /* C++ */ \ - && !defined( __bool_true_false_are_defined ) /* C99 */ \ - && !defined( _LINUX_TYPES_H ) ) +#if defined( MBG_TGT_MISSING_BOOL_TYPE ) /* from mbg_tgt.h */ \ + || ( !defined( __cplusplus ) /* C++ */ \ + && !defined( __bool_true_false_are_defined ) /* C99 */ \ + && !defined( _LINUX_TYPES_H ) ) /* Linux kernel */ \ + && !( defined( MBG_TGT_NETBSD ) && defined( _SYS_TYPES_H_ ) ) /* NetBSD kernel */ // There's no native support for a "bool" type, so we // need a substitute. @@ -500,7 +522,7 @@ do \ */ typedef struct { - ulong code; + long code; const char *name; } MBG_CODE_NAME_TABLE_ENTRY; @@ -526,10 +548,19 @@ typedef struct /** * @brief A timestamp with nanosecond resolution * + * @note If the structure is to represent a negative value then both the + * fields nano_secs and secs have to be set to the negative values. + * Otherwise the sign of the represented number was ambiguous if either + * of the fields was accidentally 0, and only the other field was not 0. + * The macro ::_nano_time_negative should always be used to determine + * if the sign of the represented value is negative, or not. + * * @note The secs field will roll over on 2038-01-19 03:14:07 * if used for the number of seconds since 1970-01-01, just like * 32 bit POSIX time_t. * + * @see ::_nano_time_negative + * @see ::_nano_time_zero * @see ::NANO_TIME_64 */ typedef struct @@ -544,20 +575,38 @@ typedef struct } NANO_TIME; #define _mbg_swab_nano_time( _p ) \ +do \ { \ _mbg_swab32( &(_p)->nano_secs ); \ _mbg_swab32( &(_p)->secs ); \ -} +} while ( 0 ) -// The macro below checks if a ::NANO_TIME value is negative. +/** + * Check if the value of the ::NANO_TIME structure _nt is negative + */ #define _nano_time_negative( _nt ) \ ( ( (_nt)->secs < 0 ) || ( (_nt)->nano_secs < 0 ) ) +/** + * Check if the value of the ::NANO_TIME structure _nt is 0 + */ +#define _nano_time_zero( _nt ) \ + ( ( (_nt)->secs == 0 ) && ( (_nt)->nano_secs == 0 ) ) + /** * @brief A timestamp with nanosecond resolution, but 64 bit size * + * @note If the structure is to represent a negative value then both the + * fields nano_secs and secs have to be set to the negative values. + * Otherwise the sign of the represented number was ambiguous if either + * of the fields was accidentally 0, and only the other field was not 0. + * The macro ::_nano_time_64_negative should always be used to determine + * if the sign of the represented value is negative, or not. + * + * @see ::_nano_time_64_negative + * @see ::_nano_time_64_zero * @see ::NANO_TIME */ typedef struct @@ -572,15 +621,62 @@ typedef struct } NANO_TIME_64; #define _mbg_swab_nano_time_64( _p ) \ +do \ { \ _mbg_swab64( &(_p)->secs ); \ _mbg_swab64( &(_p)->nano_secs ); \ -} +} while ( 0 ) -// The macro below checks if a ::NANO_TIME_64 value is negative. +/** + * Check if the value of the ::NANO_TIME_64 structure _nt is negative + */ #define _nano_time_64_negative( _nt ) \ ( ( (_nt)->secs < 0 ) || ( (_nt)->nano_secs < 0 ) ) +/** + * Check if the value of the ::NANO_TIME_64 structure _nt is 0 + */ +#define _nano_time_64_zero( _nt ) \ + ( ( (_nt)->secs == 0 ) && ( (_nt)->nano_secs == 0 ) ) + + + +// The size_t type can eventually be larger than an int type. +// However, some snprintf-like functions expect a size_t value +// to specify the buffer size, but just return an int value. +// So we take care that at least the return value is limited +// to MAXINT. +#if defined( MBG_TGT_WIN32 ) + #define _int_from_size_t( _n ) \ + ( ( (_n) > INT_MAX ) ? INT_MAX : (int) (_n) ) +#else + #define _int_from_size_t( _n ) (_n) +#endif + + + +/** + * @brief Make a string from a constant definition + * + * This macro can be used e.g. to define a constant string on the + * compiler's command line, e.g. like -DVERSION_STRING="v1.0 BETA". + * Source code like + * @code{.c} + const char version_string[] = VERSION_STRING; + * @endcode + * + * may not work for every compiler since the double quotes + * in VERSION_STRING may be removed when the definition is evaluated. + * A proper solution is to use the STRINGIFY() macro defined here: + * @code{.c} + const char version_string[] = STRINGIFY( VERSION_STRING ); + * @endcode + */ +#define STRINGIFY(x) XSTRINGIFY(x) + +// The XSTRINGIFY() macro is just a helper macro to implement STRINGIFY() +// and should not be used alone. +#define XSTRINGIFY(x) #x /* End of header body */ @@ -1,7 +1,7 @@ /************************************************************************** * - * $Id: ntptest.c 1.7 2016/11/21 17:32:54 martin REL_M $ + * $Id: ntptest.c 1.11 2017/09/06 14:26:59 martin REL_M $ * * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany * @@ -12,6 +12,16 @@ * * ----------------------------------------------------------------------- * $Log: ntptest.c $ + * Revision 1.11 2017/09/06 14:26:59 martin + * Support build under Windows. + * Revision 1.10 2017/09/06 14:14:40Z martin + * Changed version code to 1.7, and copyright year to 2017. + * Revision 1.9 2017/01/05 14:08:58 martin + * Changed version code to 1.6. + * Conditionally display dispersion and leap smear offset. + * Revision 1.8 2016/12/01 17:09:20 martin + * New version number 1.5. + * Distinguish flags which increase verbosity or print packets. * Revision 1.7 2016/11/21 17:32:54 martin * New parameter -P to set client poll value sent to server. * Moved some Windows-specific code elsewhere. @@ -38,6 +48,7 @@ #include <mbg_ntp_test_util.h> #include <mbgerror.h> +#include <timeutil.h> #if defined( MBG_TGT_WIN32 ) #include <wingetopt.h> @@ -59,13 +70,14 @@ static const char program_name[] = "ntptest"; -static const char program_version[] = "v1.4"; -static const char program_copyright[] = "(c) Meinberg 2014-2016"; +static const char program_version[] = "v1.7"; +static const char program_copyright[] = "(c) Meinberg 2014-2017"; static const char program_contact[] = "contact: <martin.burnicki@meinberg.de>"; #if defined( MBG_TGT_WIN32 ) #define __const__ const + #define clock_gettime mbg_clock_gettime #endif @@ -94,7 +106,8 @@ static int sleep_intv = MIN_SLEEP_INTV; // -s, (-u, -Z also on non-POSIX), slee #endif static int prot_version; // -V, protocol version to be used static unsigned long rcv_timeout; // -T, [msec] receive timeout after request sent -static int verbose; // -v print full packet details +static int print_packets; // print full packet details +static int verbose; // -v print more verbose output static int compensate_initial_offset; // -Z, compensate initial time offset to server #if defined( MBG_TGT_WIN32 ) static bool force_legacy_gstaft; @@ -222,8 +235,8 @@ void do_ntp_queries( void ) eval_ntp_packet( &rslt, &reply_info, &glb_query_stats ); ntoh_ntp_packet( &req_info ); - if ( verbose ) - print_ntp_results( &rslt, &req_info, &reply_info, &glb_query_stats, 1, 1 ); + if ( print_packets ) + print_ntp_results( &rslt, &req_info, &reply_info, &glb_query_stats, 1, verbose ); else { NTP_PACKET *p = &reply_info.packet; @@ -248,10 +261,24 @@ void do_ntp_queries( void ) } print_ntp_time( "", &p->base.transmit_time, NULL, 1 ); - printf( ", st %u, leap %u, offs[ms]: %+.3f\n", + printf( ", st %u, leap %u, offs[ms]: %+.3f", p->base.flags.stratum, p->base.flags.leap_ind, rslt.ntp_offs * 1000 ); + if ( verbose ) + { + double d = 0.0; + + printf( ", spoll: %u", p->base.flags.poll ); + + if ( verbose > 1 ) + printf( ", disp[s/s]: %.4f", _u_fp_to_d( p->base.root_dispersion ) ); + + if ( leap_smearing_active( &p->base.refid, &d ) || ( verbose > 2 ) ) + printf( ", smear[s]: %.6f", d ); + } + + printf( "\n" ); fflush( NULL ); } @@ -357,7 +384,7 @@ void check_options( int argc, char *argv[] ) case 'P': - client_poll_value = strtol( optarg, NULL, 10 ); + client_poll_value = (uint8_t) strtol( optarg, NULL, 10 ); break; @@ -368,7 +395,7 @@ void check_options( int argc, char *argv[] ) #else usleep_intv = DFLT_SHORT_SLEEP_INTV; // 4 req/s #endif - verbose = 0; + print_packets = 0; compensate_initial_offset = 1; break; @@ -400,7 +427,7 @@ int main( int argc, char *argv[] ) check_options( argc, argv ); if ( !run_continuously ) - verbose = 1; + print_packets = 1; if ( rcv_timeout == 0 ) rcv_timeout = RCV_TIMEOUT; |