mbgtools-lx  4.2.8
ptp_util.h
Go to the documentation of this file.
1 
2 /**************************************************************************
3  *
4  * $Id: ptp_util.h 1.6 2017/05/10 15:26:10 martin REL_M $
5  *
6  * Copyright (c) Meinberg Funkuhren, Bad Pyrmont, Germany
7  *
8  * Description:
9  * Definitions and prototypes for ptp_util.c.
10  *
11  * -----------------------------------------------------------------------
12  * $Log: ptp_util.h $
13  * Revision 1.6 2017/05/10 15:26:10 martin
14  * Tiny cleanup.
15  * Revision 1.5 2017/04/25 12:54:21 gregoire.diehl
16  * Merge changes from 1.3.1.7 & 1.4
17  * Revision 1.4 2016/11/10 09:05:26Z martin
18  * Support for PTP Time Monitor role added by udo.
19  * Support for NTP modes added by daniel.
20  * Updated some comments.
21  * Revision 1.3 2013/09/12 11:05:44 martin
22  * Added inline function get_supp_ptp_role_mask().
23  * Revision 1.2 2013/08/06 12:08:06 udo
24  * new ptp_clock_id_from_str()
25  * Revision 1.1 2011/11/14 16:03:39 martin
26  * Initial revision.
27  *
28  **************************************************************************/
29 
30 #ifndef _PTP_UTIL_H
31 #define _PTP_UTIL_H
32 
33 
34 /* Other headers to be included */
35 #include <stdio.h>
36 #include <lan_util.h>
37 #include <gpsdefs.h>
38 
39 
40 #ifdef _PTP_UTIL
41  #define _ext
42  #define _DO_INIT
43 #else
44  #define _ext extern
45 #endif
46 
47 
48 /* Start of header body */
49 
50 #if defined( _USE_PACK )
51  #pragma pack( 1 ) // set byte alignment
52  #define _USING_BYTE_ALIGNMENT
53 #endif
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 
81 static __mbg_inline
82 uint32_t get_supp_ptp_role_mask( uint32_t flags )
83 {
84  uint32_t role_mask = 0;
85 
87  {
88  // multicast slave role is only supported
89  // if a different flag is also set
91  role_mask |= PTP_ROLE_MSK_MULTICAST_SLAVE;
92  }
93  else // multicast slave role is definitely supported
94  role_mask |= PTP_ROLE_MSK_MULTICAST_SLAVE;
95 
97  role_mask |= PTP_ROLE_MSK_UNICAST_SLAVE;
98 
100  role_mask |= PTP_ROLE_MSK_MULTICAST_MASTER;
101 
102  if ( flags & PTP_CFG_MSK_CAN_BE_UNICAST_MASTER )
103  role_mask |= PTP_ROLE_MSK_UNICAST_MASTER;
104 
105  if ( flags & PTP_CFG_MSK_CAN_BE_MULTICAST_AUTO )
106  role_mask |= PTP_ROLE_MSK_MULTICAST_AUTO;
107 
108  if ( flags & PTP_CFG_MSK_CAN_BE_BOTH_MASTER )
109  role_mask |= PTP_ROLE_MSK_BOTH_MASTER;
110 
111  if ( flags & PTP_CFG_MSK_NTP_HW_TS_MASTER )
112  role_mask |= PTP_ROLE_MSK_NTP_SERVER;
113 
114  if ( flags & PTP_CFG_MSK_NTP_HW_TS_SLAVE )
115  role_mask |= PTP_ROLE_MSK_NTP_CLIENT;
116 
117  if ( flags & PTP_CFG_MSK_CAN_BE_TIME_MONITOR )
118  role_mask |= PTP_ROLE_MSK_TIME_MONITOR;
119 
120  if ( flags & PTP_CFG_MSK_CAN_BE_V1_MASTER )
121  role_mask |= PTP_ROLE_MSK_V1_MASTER;
122 
123  if ( flags & PTP_CFG_MSK_CAN_BE_V1_SLAVE )
124  role_mask |= PTP_ROLE_MSK_V1_SLAVE;
125 
126  return role_mask;
127 
128 } // get_supp_ptp_role_mask
129 
130 
131 
132 /* ----- function prototypes begin ----- */
133 
134 /* This section was generated automatically */
135 /* by MAKEHDR, do not remove the comments. */
136 
146  void mac_from_ptp_clock_id( MBG_MAC_ADDR *p_mac_addr, const PTP_CLOCK_ID *p_clock_id ) ;
147 
157  void ptp_clock_id_from_mac( PTP_CLOCK_ID *p_clock_id, const MBG_MAC_ADDR *p_mac_addr ) ;
158 
168  void ptp_clock_id_from_str( PTP_CLOCK_ID *p_clock_id, const char *p_str ) ;
169 
170 
171 /* ----- function prototypes end ----- */
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 
178 #if defined( _USING_BYTE_ALIGNMENT )
179  #pragma pack() // set default alignment
180  #undef _USING_BYTE_ALIGNMENT
181 #endif
182 
183 /* End of header body */
184 
185 
186 #undef _ext
187 #undef _DO_INIT
188 
189 #endif /* _PTP_UTIL_H */
190 
#define PTP_CFG_MSK_CAN_BE_TIME_MONITOR
see PTP_CFG_CAN_BE_TIME_MONITOR
Definition: gpsdefs.h:13483
#define PTP_CFG_MSK_CAN_BE_MULTICAST_AUTO
see PTP_CFG_CAN_BE_MULTICAST_AUTO
Definition: gpsdefs.h:13464
The MAC address of a network interface.
Definition: gpsdefs.h:11031
see PTP_ROLE_MULTICAST_SLAVE
Definition: gpsdefs.h:12964
#define PTP_CFG_MSK_NTP_HW_TS_MASTER
see PTP_CFG_NTP_HW_TS_MASTER
Definition: gpsdefs.h:13478
A PTP clock identity.
Definition: gpsdefs.h:13038
#define PTP_CFG_MSK_CAN_BE_UNICAST_SLAVE
see PTP_CFG_CAN_BE_UNICAST_SLAVE
Definition: gpsdefs.h:13461
see PTP_ROLE_MULTICAST_MASTER
Definition: gpsdefs.h:12973
static __mbg_inline uint32_t get_supp_ptp_role_mask(uint32_t flags)
Derive a "supported PTP roles" bit mask from PTP_CFG_INFO::supp_flags.
Definition: ptp_util.h:82
#define PTP_CFG_MSK_CAN_BE_MULTICAST_MASTER
see PTP_CFG_CAN_BE_MULTICAST_MASTER
Definition: gpsdefs.h:13462
#define PTP_CFG_MSK_CAN_BE_V1_SLAVE
see PTP_CFG_CAN_BE_V1_SLAVE
Definition: gpsdefs.h:13487
#define PTP_CFG_MSK_CAN_BE_BOTH_MASTER
see PTP_CFG_CAN_BE_BOTH_MASTER
Definition: gpsdefs.h:13466
void ptp_clock_id_from_mac(PTP_CLOCK_ID *p_clock_id, const MBG_MAC_ADDR *p_mac_addr)
Get the PTP clock ID from the MAC addr.
see PTP_ROLE_TIME_MONITOR
Definition: gpsdefs.h:12972
void ptp_clock_id_from_str(PTP_CLOCK_ID *p_clock_id, const char *p_str)
Get the PTP clock ID from a string.
#define PTP_CFG_MSK_SUPP_MCAST_SLAVE_FLAG
see PTP_CFG_SUPP_MCAST_SLAVE_FLAG
Definition: gpsdefs.h:13472
see PTP_ROLE_MULTICAST_MASTER
Definition: gpsdefs.h:12966
#define PTP_CFG_MSK_CAN_BE_V1_MASTER
see PTP_CFG_CAN_BE_V1_MASTER
Definition: gpsdefs.h:13486
#define PTP_CFG_MSK_CAN_BE_MULTICAST_SLAVE
see PTP_CFG_CAN_BE_MULTICAST_SLAVE
Definition: gpsdefs.h:13473
see PTP_ROLE_BOTH_MASTER
Definition: gpsdefs.h:12969
see PTP_ROLE_UNICAST_SLAVE
Definition: gpsdefs.h:12974
#define PTP_CFG_MSK_CAN_BE_UNICAST_MASTER
see PTP_CFG_CAN_BE_UNICAST_MASTER
Definition: gpsdefs.h:13463
see PTP_ROLE_UNICAST_SLAVE
Definition: gpsdefs.h:12965
see PTP_ROLE_UNICAST_MASTER
Definition: gpsdefs.h:12967
void mac_from_ptp_clock_id(MBG_MAC_ADDR *p_mac_addr, const PTP_CLOCK_ID *p_clock_id)
Get the MAC addr from a PTP clock ID.
see PTP_ROLE_MULTICAST_AUTO
Definition: gpsdefs.h:12968
see PTP_ROLE_NTP_CLIENT
Definition: gpsdefs.h:12971
see PTP_ROLE_NTP_SERVER
Definition: gpsdefs.h:12970
#define PTP_CFG_MSK_NTP_HW_TS_SLAVE
see PTP_CFG_NTP_HW_TS_SLAVE
Definition: gpsdefs.h:13479