forked from xl4-shiro/excelfore-gptp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gptpbasetypes.h
239 lines (217 loc) · 6.35 KB
/
gptpbasetypes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* Excelfore gptp - Implementation of gPTP(IEEE 802.1AS)
* Copyright (C) 2019 Excelfore Corporation (https://excelfore.com)
*
* This file is part of Excelfore-gptp.
*
* Excelfore-gptp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Excelfore-gptp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Excelfore-gptp. If not, see
* <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>.
*/
/**
* @addtogroup gptp
* @{
* @file gptpbasetypes.h
* @author Shiro Ninomiya <[email protected]>
* @copyright Copyright (C) 2017-2018 Excelfore Corporation
* @brief File contains base datatypes used, as per IEEE 802.1AS
* Standard Documentation.
*/
#ifndef __GPTPBASETYPES_H_
#define __GPTPBASETYPES_H_
#include <string.h>
/**
* @brief Macro which defines Maximum port number limit for gPTP2.
* @note CONF_MAX_PORT_NUMBER can be configured at a runtime,
* it must be less than this numumber
*/
#define MAX_PORT_NUMBER_LIMIT 33
/**
* @brief Macro to define maximum path trace.
* @note The maximum possible number is 179 based on specification we can set
* the maximum here and restrict the frame using MAX_PTP_PACKET instead
* @code{.c}
* #define MAX_PATH_TRACE_N 179
* @endcode
* @see 10.3.8.23 pathTrace
*/
#define MAX_PATH_TRACE_N 179
/**
* @brief Macro which defines Clock Identity Length.
*/
#define CLOCK_IDENTITY_LENGTH 8
typedef uint8_t ClockIdentity[CLOCK_IDENTITY_LENGTH];
/**
* @brief Primitive data types specifications for IEEE 802.1AS.
* All non-primitive data types are derived from the primitive types, signed integers are
* represented as two's complement form.
* @verbatim See the following Table@endverbatim
* Data Types | Definition
* ---------- | ----------------------------------------------
* EnumerationN | N-bit enumerated value
* UIntegerN | N-bit unsigned integer
* Nibble | 4-bit field not interpreted as a number
* Octet | 8-bit field not interpreted as a number
* OctetN | N-octet fiels not interpreted as a number
* Double | Double precision (64-bit) floating-point vlaue
*/
typedef uint8_t Nibble;
typedef uint8_t Octet;
typedef uint8_t Octet2[2];
typedef uint8_t Octet3[3];
typedef uint8_t Octet4[4];
typedef uint8_t Enumeration2;
typedef uint8_t Enumeration4;
typedef uint8_t Enumeration8;
typedef uint16_t Enumeration16;
typedef uint32_t Enumeration24;
typedef uint8_t UInteger4;
/**
* @brief The portIdentity identifies a port of a time-aware system.
* @note ClockIdentity is a array of unsigned char which is used to identify time-aware system.
*/
typedef struct PortIdentity {
ClockIdentity clockIdentity;
uint16_t portNumber;
} PortIdentity;
/**
* @brief The clock quality represents quality of clock.
*/
typedef struct ClockQuality {
uint8_t clockClass;
Enumeration8 clockAccuracy;
uint16_t offsetScaledLogVariance;
} ClockQuality;
/**
* @brief 48bit variable, lsb is 32 bits
*/
typedef struct UInteger48 {
uint32_t lsb;
uint16_t msb;
} UInteger48;
/**
* @brief 48bit variable, msb is 32 bits
*/
typedef struct UInteger48m32 {
uint16_t lsb;
uint32_t msb;
} UInteger48m32;
/**
* @brief UInteger112 (802.1AS, 10.3.2 systemIdentity)
*/
typedef struct UInteger112 {
uint8_t priority1;
uint8_t clockClass;
uint8_t clockAccuracy;
uint16_t offsetScaledLogVariance;
uint8_t priority2;
ClockIdentity clockIdentity;
} __attribute__((packed, aligned(1))) UInteger112;
/**
* @brief UInteger224 (802.1AS, 10.3.4 time-synchronization spanning
* tree priority vectors )
*/
typedef struct UInteger224 {
UInteger112 rootSystemIdentity;
uint16_t stepsRemoved;
PortIdentity sourcePortIdentity;
uint16_t portNumber;
} __attribute__((packed, aligned(1))) UInteger224;
/**
* @brief The ScaledNs type represents signed values of time and time
* interval in units of 2e-16 ns.
*/
typedef struct ScaledNs {
uint16_t subns;
int64_t nsec;
int16_t nsec_msb;
} ScaledNs;
/**
* @brief The ScaledNs type represents unsigned values of time and
* time interval in units of 2^-16 ns.
* @code
* //2.5 ns expressed as below
* 0x0000 0000 0000 0000 0002 8000
* @endcode
*
*/
typedef struct UScaledNs {
uint16_t subns;
uint64_t nsec;
uint16_t nsec_msb;
} UScaledNs;
/*
* @brief The TimeInterval type represents time intervals, in units of 2^-16 ns
* @verbatim Example to express ns@endverbatim
* @code
* //2.5 ns expressed as below
* 0x0000 0000 0002 8000
* @endcode
*
*/
typedef struct TimeInterval {
int64_t scaledNanoseconds;
} TimeInterval;
/**
* @brief The Timestamp type represents a positive time with respect to the epoch.
* @verbatim For example:@endverbatim
* @code
* +2.000000001 seconds is represented by seconds = 0x0000 0000 0002 and nanoseconds= 0x0000 0001
* @endcode
*
*/
typedef struct Timestamp {
uint32_t nanoseconds;
UInteger48 seconds;
} Timestamp;
/**
* @brief The ExtendTimestamp type represents a positive time with respect to the epoch.
* The fractionalNanoseconds member is the fractional portion of the timestamp in units of 2^16 ns.
* @verbatim For example:@endverbatim
* @code
* +2.000000001 seconds is represented by seconds = 0x0000 0000 0002
* and fractionalNnanoseconds = 0x0000 0001 0000
* @endcode
*
*/
typedef struct ExtendedTimestamp {
UInteger48m32 fractionalNanoseconds;
UInteger48 seconds;
} ExtendedTimestamp;
#define VALUE_DISABLED 0
#define VALUE_ENABLED 1
/**
* @breif the type of source of time used by a ClockMaster(802.1AS, 8.6.2.7 timeSource)
*/
typedef enum {
ATOMIC_CLOCK = 0x10,
GPS = 0x20,
TERRESTRIAL_RADIO = 0x30,
PTP = 0x40,
NTP = 0x50,
HAND_SET = 0x60,
OTHER = 0x90,
INTERNAL_OSCILLATOR = 0xA0,
} TimeSource;
// 14.8.3 portState, (from IEEE 1588 Table-8)
/**
* @brief value of the port state (802.1AS 14.8.3 portState)
*/
typedef enum {
DisabledPort = 3,
MasterPort = 6,
PassivePort = 7,
SlavePort = 9,
} PTPPortState;
#endif
/** @}*/