SZSPTP ez430-RF2480 1.0

ZigBee Sensor Network with synchronized time and time-stamped measurements.
ptp_types.h
Go to the documentation of this file.
1 /*
2  * ptp_types.h
3  *
4  * Date: 19/06/2014
5  * Author: Fernando Biazi Nascimento
6  * Copyright © 2014 Fernando Biazi Nascimento. All rights reserved.
7  *
8  * License of use and copy on file license.txt
9  *
10  */
11 
21 #ifndef PTP_TYPES_H
22 #define PTP_TYPES_H
23 
24 /*
25  * ======== Includes ========
26  */
27 
28 /*
29  * ======== Doxygen ========
30  */
31 
40 /*
41  * ======== Constants ========
42  */
43 
44 /*
45  * ======== Macros ========
46  */
47 
48 #define PTP_CLOCK_TYPE_BOUNDARY 1
49 #define PTP_CLOCK_TYPE_ORDINARY 2
50 #define PTP_CLOCK_TYPE_TRANSPARENT 4
51 
52 #define PTP_FALSE 0
53 #define PTP_TRUE 1
54 
55 /*
56  * ======== Types ========
57  */
58 
68 typedef unsigned char ptp_boolean;
69 
70 // Numeric types
71 
75 typedef signed char ptp_integer4;
76 
80 typedef unsigned char ptp_uinteger4;
81 
85 typedef signed char ptp_integer8;
86 
90 typedef unsigned char ptp_uinteger8;
91 
95 typedef short ptp_integer16;
96 
100 typedef unsigned short ptp_uinteger16;
101 
105 typedef long ptp_integer32;
106 
110 typedef unsigned long ptp_uinteger32;
111 
115 typedef unsigned long long ptp_uinteger48; // Está ocupando 64 bits, deveria ser 48, converter quando necessario
116 
120 typedef long long ptp_integer64;
121 
125 typedef unsigned long long ptp_uinteger64;
126 
127 // Types not interpreted as a number
128 
132 typedef char ptp_nibble;
133 
137 typedef char ptp_octet;
138 
152 typedef enum ptp_networkProtocol {
153  // Reserved = 0x0000
154  PTP_NP_UDP_IPv4 = 0x0001,
155  PTP_NP_UDP_IPv6 = 0x0002,
156  PTP_NP_IEEE_802_3 = 0x0003,
157  PTP_NP_DeviceNe = 0x0004,
158  PTP_NP_ControlNet = 0x0005,
159  PTP_NP_PROFINET = 0x0006,
160  // Reserved for assignment by the Precise Networked Clock Working Group
161  // of the IM/ST Committee 0007 - EFFF
162  // Reserved for assignment in a PTP profile F000 - FFFD
163  PTP_NP_Unknown = 0xFFFE
164 // Reserved = FFFF
165 } ptp_networkProtocol; // Enum16
166 
170 typedef enum ptp_clockAccuracy {
171  //00-1F Reserved
172  PTP_CA_025NS = 0x20, // The time is accurate to within 25 ns
173  PTP_CA_100NS = 0x21, // The time is accurate to within 100 ns
174  PTP_CA_250NS = 0x22, // The time is accurate to within 250 ns
175  PTP_CA_001US = 0x23, // The time is accurate to within 1 us
176  PTP_CA_002US = 0x24, // The time is accurate to within 2.5 us
177  PTP_CA_010US = 0x25, // The time is accurate to within 10 us
178  PTP_CA_025US = 0x26, // The time is accurate to within 25 us
179  PTP_CA_100US = 0x27, // The time is accurate to within 100 us
180  PTP_CA_250US = 0x28, // The time is accurate to within 250 us
181  PTP_CA_001MS = 0x29, // The time is accurate to within 1 ms
182  PTP_CA_002MS = 0x2A, // The time is accurate to within 2.5 ms
183  PTP_CA_010MS = 0x2B, // The time is accurate to within 10 ms
184  PTP_CA_025MS = 0x2C, // The time is accurate to within 25 ms
185  PTP_CA_100MS = 0x2D, // The time is accurate to within 100 ms
186  PTP_CA_250MS = 0x2E, // The time is accurate to within 250 ms
187  PTP_CA_001S = 0x2F, // The time is accurate to within 1 s
188  PTP_CA_010S = 0x30, // The time is accurate to within 10 s
189  PTP_CA_OVER = 0x31, // The time is accurate to >10 s
190  // 32 - 7F Reserved
191  // 80 - FD For use by alternate PTP profiles
192  PTP_CA_Unknown = 0xFE // Unknown
193 // FF Reserved
194 } ptp_clockAccuracy; // Enum8
195 
199 typedef enum ptp_tlvType {
200  // Reserved 0000
201  // Standard TLVs
202  PTP_TT_MANAGEMENT = 0x0001,
205  // Optional unicast message negotiation TLVs - IEC 61588-2009 / IEEE 1588-2008 16.1
206  PTP_TT_REQUEST_UNICAST_TRANSMISSION = 0x0004,
207  PTP_TT_GRANT_UNICAST_TRANSMISSION = 0x0005,
208  PTP_TT_CANCEL_UNICAST_TRANSMISSION = 0x0006,
209  PTP_TT_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION = 0x0007,
210  // Optional path trace mechanism TLV - IEC 61588-2009 / IEEE 1588-2008 16.2
211  PTP_TT_PATH_TRACE = 0x0008,
212  // Optional alternate timescale TLV - IEC 61588-2009 / IEEE 1588-2008 16.3
213  PTP_TT_ALTERNATE_TIME_OFFSET_INDICATOR = 0x0009,
214  // Reserved for standard TLVs 000A - 1FFF
215  // Experimental TLVs - IEC 61588-2009 / IEEE 1588-2008 14.2
216  // Security TLVs Annex K
217  PTP_TT_AUTHENTICATION = 0x2000,
218  PTP_TT_AUTHENTICATION_CHALLENGE = 0x2001,
219  PTP_TT_SECURITY_ASSOCIATION_UPDATE = 0x2002,
220  // Cumulative frequency scale factor offset - IEC 61588-2009 / IEEE 1588-2008 Annex L
221  PTP_TT_PTP_TLV_CUM_FREQ_SCALE_FACTOR_OFFSET = 0x2003
222 // Reserved for Experimental TLVs 2004 - 3FFF
223 // Reserved 4000 - FFFF
224 } ptp_tlvType; // Enum16
225 
229 typedef enum ptp_severityCode {
230  PTP_SC_EMERGENCY = 0x00, // system is unusable
231  PTP_SC_ALERT = 0x01, // immediate action needed
232  PTP_SC_CRITICAL = 0x02, // critical conditions
233  PTP_SC_ERROR = 0x03, // error conditions
234  PTP_SC_WARNING = 0x04, // warning conditions
235  PTP_SC_NOTICE = 0x05, // normal but significant condition
236  PTP_SC_INFORMATIONAL = 0x06, // informational messages
237  PTP_SC_DEBUG = 0x07 // debug-level messages
238 // 08 - FF Reserved
239 } ptp_severityCode; // Enum8
240 
244 typedef enum ptp_timeSource {
245  PTP_TS_ATOMIC_CLOCK = 0x10,
246  PTP_TS_GPS = 0x20,
247  PTP_TS_TERRESTRIAL_RADIO = 0x30,
248  PTP_TS_PTP = 0x40,
249  PTP_TS_NTP = 0x50,
250  PTP_TS_HAND_SET = 0x60,
251  PTP_TS_OTHER = 0x90,
252  PTP_TS_INTERNAL_OSCILLATOR = 0xA0
253 // F0-FE For use by alternate PTP profiles
254 // FF Reserved
255 } ptp_timeSource; // Enum8;
256 
260 typedef enum ptp_portState {
261  // 00 Reserved
262  PTP_PS_INITIALIZING = 0x01,
263  PTP_PS_FAULTY = 0x02,
264  PTP_PS_DISABLED = 0x03,
265  PTP_PS_LISTENING = 0x04,
266  PTP_PS_PRE_MASTER = 0x05,
267  PTP_PS_MASTER = 0x06,
268  PTP_PS_PASSIVE = 0x07,
269  PTP_PS_UNCALIBRATED = 0x08,
270  PTP_PS_SLAVE = 0x09
271 // 10-FF Reserved
272 } ptp_portState; // Enum8
273 
277 typedef enum ptp_delayMechanism {
278  PTP_DM_E2E = 0x01,
279  PTP_DM_P2P = 0x02,
281 } ptp_delayMechanism; //Enum8
282 
286 typedef enum ptp_clockType {
290 } ptp_clockType; //Enum8
291 
295 typedef enum ptp_recommendedState {
303 } ptp_recommendedState; // Enum8
304 
315 //
316 // Derived data type specifications
317 //
318 
323 
327 typedef struct PTP_TimeInterval {
328  ptp_integer64 scalatedNanoseconds;
330 
331 // PTP_SecondsCount
335 typedef struct PTP_SecondsCount {
336  ptp_uinteger32 secondsLow;
337  ptp_uinteger16 secondsHigh;
339 
343 typedef struct PTP_TimeStamp {
344  PTP_SecondsCount secondsField;
345  ptp_uinteger32 nanoSecondsField;
346 } PTP_TimeStamp;
347 
348 // All values of this type are read from other locations when it would be used
350 // * Port identity with clock identity as pointer
351 // */
352 //typedef struct PTP_PortIdentityP {
355 //} PTP_PortIdentityP;
356 
359 // * Port identity
360 // */
361 //typedef struct PTP_PortIdentity {
362 // ptp_clockIdentity clockIdentity;
364 //} PTP_PortIdentity;
365 
369 typedef struct PTP_ParentPortIdentityP {
370  ptp_clockIdentity *clockIdentity;
371  ptp_uinteger16 portNumber;
373 
377 typedef struct PTP_PortAddress {
378  ptp_networkProtocol networkProtocol;
379  ptp_uinteger16 addressLength;
380  ptp_octet *addressField;
382 
386 typedef struct PTP_ClockQuality {
387  ptp_uinteger8 clockClass;
388  ptp_clockAccuracy clockAccuracy :8;
389  ptp_uinteger16 offsetScaledLogVariance;
391 
395 typedef struct PTP_TLV {
396  ptp_tlvType tlvType;
397  ptp_uinteger16 lengthField;
398  ptp_octet *valueField;
399 } PTP_TLV;
400 
404 typedef struct PTP_PTPText {
405  ptp_uinteger8 lengthField;
406  ptp_octet *textField;
407 } PTP_PTPText;
408 
412 typedef struct PTP_FaultRecord {
413  ptp_uinteger16 faultRecordLength;
414  PTP_TimeStamp faultTime;
415  ptp_severityCode severityCode :8;
416  PTP_PTPText faultName;
417  PTP_PTPText faultValue;
418  PTP_PTPText faultDescription;
420 
425 /*
426  * ======== Global Variables ========
427  */
428 
429 /*
430  * ======== Global Functions ========
431  */
432 
437 #endif /* PTP_TYPES_H */
Boundary clock.
Definition: ptp_types.h:287
unsigned char ptp_boolean
Definition: ptp_types.h:68
struct PTP_ParentPortIdentityP PTP_ParentPortIdentityP
IEC 61588-2009 / IEEE 1588-2008 Annex G.
Definition: ptp_types.h:157
IEC 61588-2009 / IEEE 1588-2008 14.3.
Definition: ptp_types.h:204
struct PTP_TimeStamp PTP_TimeStamp
IEC 61588-2009 / IEEE 1588-2008 Annex H.
Definition: ptp_types.h:158
unsigned char ptp_uinteger4
Definition: ptp_types.h:80
unsigned long long ptp_uinteger64
Definition: ptp_types.h:125
Ordinary clock (only one port)
Definition: ptp_types.h:288
ptp_severityCode
Definition: ptp_types.h:229
pear-to-pear
Definition: ptp_types.h:279
Master on clockClass 1 ~ 127 and grandMaster.
Definition: ptp_types.h:296
Slave.
Definition: ptp_types.h:299
long long ptp_integer64
Definition: ptp_types.h:120
Master on clockClass > 128 and grandMaster.
Definition: ptp_types.h:297
unsigned long ptp_uinteger32
Definition: ptp_types.h:110
IEC 61588-2009 / IEEE 1588-2008 Annex F.
Definition: ptp_types.h:156
ptp_timeSource
Definition: ptp_types.h:244
When port have no connection, keep listening state.
Definition: ptp_types.h:302
struct PTP_FaultRecord PTP_FaultRecord
struct PTP_ClockQuality PTP_ClockQuality
Transparent clock (forward PTP messages, do not count as a node to PTP messages)
Definition: ptp_types.h:289
ptp_networkProtocol
Definition: ptp_types.h:152
struct PTP_PortAddress PTP_PortAddress
see IEC 61588/IEEE 1588
Definition: ptp_types.h:280
signed char ptp_integer8
Definition: ptp_types.h:85
struct PTP_PTPText PTP_PTPText
char ptp_nibble
Definition: ptp_types.h:132
ptp_portState
Definition: ptp_types.h:260
clockClass > 128 and is PASSIVE to break a timing loop
Definition: ptp_types.h:301
ptp_octet ptp_clockIdentity[8]
Definition: ptp_types.h:322
struct PTP_TLV PTP_TLV
IEC 61588-2009 / IEEE 1588-2008 15.5.3.
Definition: ptp_types.h:202
unsigned char ptp_uinteger8
Definition: ptp_types.h:90
unsigned long long ptp_uinteger48
Definition: ptp_types.h:115
ptp_clockAccuracy
Definition: ptp_types.h:170
signed char ptp_integer4
Definition: ptp_types.h:75
IEC 61588-2009 / IEEE 1588-2008 Annex I.
Definition: ptp_types.h:159
short ptp_integer16
Definition: ptp_types.h:95
IEC 61588-2009 / IEEE 1588-2008 Annex E.
Definition: ptp_types.h:155
Master and NOT grandMaster.
Definition: ptp_types.h:298
char ptp_octet
Definition: ptp_types.h:137
long ptp_integer32
Definition: ptp_types.h:105
ptp_recommendedState
Definition: ptp_types.h:295
clockClass 1 ~ 127 and NOT grandMaster or is PASSIVE to break a timing loop
Definition: ptp_types.h:300
IEC 61588-2009 / IEEE 1588-2008 15.5.4.
Definition: ptp_types.h:203
ptp_tlvType
Definition: ptp_types.h:199
IEC 61588-2009 / IEEE 1588-2008 Annex D.
Definition: ptp_types.h:154
struct PTP_SecondsCount PTP_SecondsCount
ptp_clockType
Definition: ptp_types.h:286
struct PTP_TimeInterval PTP_TimeInterval
unsigned short ptp_uinteger16
Definition: ptp_types.h:100
end-to-end
Definition: ptp_types.h:278
ptp_delayMechanism
Definition: ptp_types.h:277