AM263x MCU+ SDK  09.02.00
gptpbasetypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Texas Instruments Incorporated
3  * Copyright (c) 2023 Excelfore Corporation (https://excelfore.com)
4  *
5  * All rights reserved not granted herein.
6  * Limited License.
7  *
8  * Texas Instruments Incorporated grants a world-wide, royalty-free,
9  * non-exclusive license under copyrights and patents it now or hereafter
10  * owns or controls to make, have made, use, import, offer to sell and sell ("Utilize")
11  * this software subject to the terms herein. With respect to the foregoing patent
12  * license, such license is granted solely to the extent that any such patent is necessary
13  * to Utilize the software alone. The patent license shall not apply to any combinations which
14  * include this software, other than combinations with devices manufactured by or for TI ("TI Devices").
15  * No hardware patent is licensed hereunder.
16  *
17  * Redistributions must preserve existing copyright notices and reproduce this license (including the
18  * above copyright notice and the disclaimer and (if applicable) source code license limitations below)
19  * in the documentation and/or other materials provided with the distribution
20  *
21  * Redistribution and use in binary form, without modification, are permitted provided that the following
22  * conditions are met:
23  *
24  * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any
25  * software provided in binary form.
26  * * any redistribution and use are licensed by TI for use only with TI Devices.
27  * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
28  *
29  * If software source code is provided to you, modification and redistribution of the source code are permitted
30  * provided that the following conditions are met:
31  *
32  * * any redistribution and use of the source code, including any resulting derivative works, are licensed by
33  * TI for use only with TI Devices.
34  * * any redistribution and use of any object code compiled from the source code and any resulting derivative
35  * works, are licensed by TI for use only with TI Devices.
36  *
37  * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or
38  * promote products derived from this software without specific prior written permission.
39  *
40  * DISCLAIMER.
41  *
42  * THIS SOFTWARE IS PROVIDED BY TI AND TI"S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
43  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
44  * IN NO EVENT SHALL TI AND TI"S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
46  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48  * POSSIBILITY OF SUCH DAMAGE.
49 */
58 #ifndef GPTPBASETYPES_H_
59 #define GPTPBASETYPES_H_
60 
61 #include <string.h>
62 
72 #define MAX_PATH_TRACE_N 179
73 
77 #define CLOCK_IDENTITY_LENGTH 8
78 
80 
96 typedef uint8_t Nibble;
97 typedef uint8_t Octet;
98 typedef uint8_t Octet2[2];
99 typedef uint8_t Octet3[3];
100 typedef uint8_t Octet4[4];
101 typedef uint8_t Enumeration2;
102 typedef uint8_t Enumeration4;
103 typedef uint8_t Enumeration8;
104 typedef uint16_t Enumeration16;
105 typedef uint32_t Enumeration24;
106 typedef uint8_t UInteger4;
107 
112 typedef struct PortIdentity {
114  uint16_t portIndex;
115 } PortIdentity;
116 
120 typedef struct ClockQuality {
121  uint8_t clockClass;
124 } ClockQuality;
125 
129 typedef struct UInteger48 {
130  uint32_t lsb;
131  uint16_t msb;
132 } UInteger48;
136 typedef struct UInteger48m32 {
137  uint16_t lsb;
138  uint32_t msb;
139 } UInteger48m32;
140 
144 typedef struct UInteger112 {
145  uint8_t priority1;
146  uint8_t clockClass;
147  uint8_t clockAccuracy;
149  uint8_t priority2;
151 } __attribute__((packed, aligned(1))) UInteger112;
152 
157 typedef struct UInteger224 {
159  uint16_t stepsRemoved;
161  uint16_t portNumber;
162 } __attribute__((packed, aligned(1))) UInteger224;
163 
168 typedef struct ScaledNs {
169  uint16_t subns;
170  int64_t nsec;
171  int16_t nsec_msb;
172 } ScaledNs;
173 
183 typedef struct UScaledNs {
184  uint16_t subns;
185  uint64_t nsec;
186  uint16_t nsec_msb;
187 } UScaledNs;
188 
189 /*
190  * @brief 2^-16 ns scaling multiplier
191  */
192 #define SCALEDNS_FACTOR 0x10000
193 
194 /*
195  * @brief The TimeInterval type represents time intervals, in units of 2^-16 ns
196  * @verbatim Example to express ns@endverbatim
197  * @code
198  * 2.5 ns expressed as below
199  * 0x0000 0000 0002 8000
200  * @endcode
201  *
202  */
203 typedef struct TimeInterval {
205 } TimeInterval;
206 
215 typedef struct Timestamp {
216  uint32_t nanoseconds;
218 } Timestamp;
219 
230 typedef struct ExtendedTimestamp {
234 
235 #define VALUE_DISABLED 0u
236 #define VALUE_ENABLED 1u
237 
241 typedef enum {
242  ATOMIC_CLOCK = 0x10,
243  GPS = 0x20,
245  PTP = 0x40,
246  NTP = 0x50,
247  HAND_SET = 0x60,
248  OTHER = 0x90,
250 } TimeSource;
251 
252 // 14.8.3 portState, (from IEEE 1588 Table-8)
260 typedef enum {
265 } PTPPortState;
266 
267 typedef enum {
272 
273 #endif
274 
ScaledNs::nsec_msb
int16_t nsec_msb
Definition: gptpbasetypes.h:171
SlavePort
@ SlavePort
Definition: gptpbasetypes.h:264
UInteger112::offsetScaledLogVariance
uint16_t offsetScaledLogVariance
Definition: gptpbasetypes.h:148
UInteger224::portNumber
uint16_t portNumber
Definition: gptpbasetypes.h:161
ExtendedTimestamp
The ExtendTimestamp type represents a positive time with respect to the epoch. The fractionalNanoseco...
Definition: gptpbasetypes.h:230
PortIdentity
The portIdentity identifies a port of a time-aware system.
Definition: gptpbasetypes.h:112
UScaledNs::nsec_msb
uint16_t nsec_msb
Definition: gptpbasetypes.h:186
Enumeration4
uint8_t Enumeration4
Definition: gptpbasetypes.h:102
PassivePort
@ PassivePort
Definition: gptpbasetypes.h:263
UInteger224
UInteger224 (802.1AS, 10.3.4 time-synchronization spanning tree priority vectors )
Definition: gptpbasetypes.h:157
UInteger4
uint8_t UInteger4
Definition: gptpbasetypes.h:106
UInteger112::priority1
uint8_t priority1
Definition: gptpbasetypes.h:145
PortIdentity::portIndex
uint16_t portIndex
Definition: gptpbasetypes.h:114
Enumeration2
uint8_t Enumeration2
Definition: gptpbasetypes.h:101
Timestamp::seconds
UInteger48 seconds
Definition: gptpbasetypes.h:217
ScaledNs
The ScaledNs type represents signed values of time and time interval in units of 2e-16 ns.
Definition: gptpbasetypes.h:168
ClockQuality::clockAccuracy
Enumeration8 clockAccuracy
Definition: gptpbasetypes.h:122
MasterPort
@ MasterPort
Definition: gptpbasetypes.h:262
UInteger224::sourcePortIdentity
PortIdentity sourcePortIdentity
Definition: gptpbasetypes.h:160
GMSYNC_SYNC
@ GMSYNC_SYNC
Definition: gptpbasetypes.h:269
UInteger224::stepsRemoved
uint16_t stepsRemoved
Definition: gptpbasetypes.h:159
Octet4
uint8_t Octet4[4]
Definition: gptpbasetypes.h:100
ClockQuality::clockClass
uint8_t clockClass
Definition: gptpbasetypes.h:121
UScaledNs::subns
uint16_t subns
Definition: gptpbasetypes.h:184
ExtendedTimestamp::fractionalNanoseconds
UInteger48m32 fractionalNanoseconds
Definition: gptpbasetypes.h:231
UScaledNs::nsec
uint64_t nsec
Definition: gptpbasetypes.h:185
DisabledPort
@ DisabledPort
Definition: gptpbasetypes.h:261
OTHER
@ OTHER
Definition: gptpbasetypes.h:248
TimeInterval::scaledNanoseconds
int64_t scaledNanoseconds
Definition: gptpbasetypes.h:204
ClockQuality
The clock quality represents quality of clock.
Definition: gptpbasetypes.h:120
Octet3
uint8_t Octet3[3]
Definition: gptpbasetypes.h:99
Octet
uint8_t Octet
Definition: gptpbasetypes.h:97
GMSYNC_SYNC_STABLE
@ GMSYNC_SYNC_STABLE
Definition: gptpbasetypes.h:270
UInteger112::clockIdentity
ClockIdentity clockIdentity
Definition: gptpbasetypes.h:150
UInteger48::msb
uint16_t msb
Definition: gptpbasetypes.h:131
Nibble
uint8_t Nibble
Primitive data types specifications for IEEE 802.1AS. All non-primitive data types are derived from t...
Definition: gptpbasetypes.h:96
Timestamp::nanoseconds
uint32_t nanoseconds
Definition: gptpbasetypes.h:216
__attribute__
struct UInteger112 __attribute__((packed, aligned(1))) UInteger112
UInteger112 (802.1AS, 10.3.2 systemIdentity)
GPS
@ GPS
Definition: gptpbasetypes.h:243
HAND_SET
@ HAND_SET
Definition: gptpbasetypes.h:247
gmsync_status_t
gmsync_status_t
Definition: gptpbasetypes.h:267
INTERNAL_OSCILLATOR
@ INTERNAL_OSCILLATOR
Definition: gptpbasetypes.h:249
ExtendedTimestamp::seconds
UInteger48 seconds
Definition: gptpbasetypes.h:232
ATOMIC_CLOCK
@ ATOMIC_CLOCK
Definition: gptpbasetypes.h:242
Enumeration24
uint32_t Enumeration24
Definition: gptpbasetypes.h:105
UInteger48::lsb
uint32_t lsb
Definition: gptpbasetypes.h:130
UInteger48
48bit variable, lsb is 32 bits
Definition: gptpbasetypes.h:129
PTP
@ PTP
Definition: gptpbasetypes.h:245
UScaledNs
The ScaledNs type represents unsigned values of time and time interval in units of 2^-16 ns.
Definition: gptpbasetypes.h:183
UInteger112::clockAccuracy
uint8_t clockAccuracy
Definition: gptpbasetypes.h:147
PTPPortState
PTPPortState
value of the port state (802.1AS 14.8.3 portState)
Definition: gptpbasetypes.h:260
UInteger48m32::msb
uint32_t msb
Definition: gptpbasetypes.h:138
UInteger112
UInteger112 (802.1AS, 10.3.2 systemIdentity)
Definition: gptpbasetypes.h:144
UInteger48m32
48bit variable, msb is 32 bits
Definition: gptpbasetypes.h:136
ScaledNs::nsec
int64_t nsec
Definition: gptpbasetypes.h:170
CLOCK_IDENTITY_LENGTH
#define CLOCK_IDENTITY_LENGTH
Macro which defines Clock Identity Length.
Definition: gptpbasetypes.h:77
NTP
@ NTP
Definition: gptpbasetypes.h:246
GMSYNC_UNSYNC
@ GMSYNC_UNSYNC
Definition: gptpbasetypes.h:268
UInteger112::clockClass
uint8_t clockClass
Definition: gptpbasetypes.h:146
Enumeration16
uint16_t Enumeration16
Definition: gptpbasetypes.h:104
TimeSource
TimeSource
the type of source of time used by a ClockMaster(802.1AS, 8.6.2.7 timeSource)
Definition: gptpbasetypes.h:241
UInteger48m32::lsb
uint16_t lsb
Definition: gptpbasetypes.h:137
Octet2
uint8_t Octet2[2]
Definition: gptpbasetypes.h:98
PortIdentity::clockIdentity
ClockIdentity clockIdentity
Definition: gptpbasetypes.h:113
TimeInterval
Definition: gptpbasetypes.h:203
UInteger112::priority2
uint8_t priority2
Definition: gptpbasetypes.h:149
Enumeration8
uint8_t Enumeration8
Definition: gptpbasetypes.h:103
UInteger224::rootSystemIdentity
UInteger112 rootSystemIdentity
Definition: gptpbasetypes.h:158
ClockIdentity
uint8_t ClockIdentity[CLOCK_IDENTITY_LENGTH]
Definition: gptpbasetypes.h:79
TERRESTRIAL_RADIO
@ TERRESTRIAL_RADIO
Definition: gptpbasetypes.h:244
Timestamp
The Timestamp type represents a positive time with respect to the epoch.
Definition: gptpbasetypes.h:215
ClockQuality::offsetScaledLogVariance
uint16_t offsetScaledLogVariance
Definition: gptpbasetypes.h:123
ScaledNs::subns
uint16_t subns
Definition: gptpbasetypes.h:169