flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
ptp_profile_presets.c
Go to the documentation of this file.
2#include "ptp_types.h"
3#include "ptp_defs.h"
4
5#include <stdint.h>
6#include <string.h>
7
12 PTP_PROFILE_DEFAULT, // default profile
13 PTP_PROFILE_GPTP, // gPTP (802.1AS)
14 PTP_PROFILE_DEF_P2P, // default, but with P2P delay mechanism
15 PTP_PROFILE_PUP_61850, // Power Utility Profile (IEC/IEEE 61850-9-3)
17};
18
20 PTP_TLVP_GPTP_ORG, // gPTP (802.1AS) TLV
22};
23
24// -------- gPTP -------------
25
26typedef struct __attribute__((packed)) {
28 uint8_t organizationId[3];
29 uint8_t organizationSubType[3];
30 uint32_t cumulativeScaleRateOffset;
31 uint16_t gmTimeBaseIndicator;
32 uint8_t lastGmPhaseChange[12];
33 uint32_t scaledLastGmFreqChange;
35
38 .length = FLEXPTP_ntohs(28),
39 .organizationId = {0x00, 0x80, 0xC2},
40 .organizationSubType = {0x00, 0x00, 0x01},
41 .cumulativeScaleRateOffset = FLEXPTP_ntohl(0),
42 .gmTimeBaseIndicator = FLEXPTP_ntohs(0),
43 .lastGmPhaseChange = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
44 .scaledLastGmFreqChange = FLEXPTP_ntohl(0)};
45
47 .data = &gPtp_OrgTlv,
48 .size = sizeof(PtpGPtpOrganizationTlv),
49 .msgType = PTP_MT_Follow_Up,
50 NULL};
51
52// ---------------------------
53
57typedef struct {
61
65typedef struct {
69
70// clang-format off
71
76 {
77 "gptp",
79 }
80};
81
86 {"default",
87 {
91 0,
92 0,
93 1,
94 0,
96 "",
97 {},
98 {}
99 }
100 },
101 {"gPTP",
102 {
106 0,
107 -3,
108 0,
109 0,
111 "gptp",
112 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E },
113 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E }
114 }
115 },
116 {"defp2p",
117 {
121 0,
122 0,
123 1,
124 0,
126 "",
127 {},
128 {}
129 }
130 },
131 { "PUP", // Power Utility Profile (IEC/IEEE 61850-9-3)
132 {
136 0, // Pdelay_Req interval 1s
137 0, // Sync interval 1s
138 0, // Announce interval 1s
139 93, // Standard recommends domain 93 for IEC 61850-9-3
141 "",
142 { 0x01, 0x18, 0x19, 0x00, 0x00, 0x00 },
143 { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x0E }
144 }
145 }
146};
147
148// clang-format on
149
150const PtpProfile *ptp_profile_preset_get(const char *pName) {
151 size_t i = 0;
152 PtpProfile *pProfile = NULL;
153 for (i = 0; i < PTP_PROFILE_N; i++) {
154 if (!strcmp(sPtpProfiles[i].name, pName)) {
155 pProfile = &sPtpProfiles[i].profile;
156 break;
157 }
158 }
159 return pProfile;
160}
161
163 size_t i = 0;
164 const PtpProfileTlvElement *pTlvChain = NULL;
165 for (i = 0; i < PTP_TLVP_N; i++) {
166 if (!strcmp(sTlvPresets[i].name, pName)) {
167 pTlvChain = sTlvPresets[i].tlvList;
168 break;
169 }
170 }
171 return pTlvChain;
172}
173
175 return PTP_PROFILE_N;
176}
177
179 return PTP_TLVP_N;
180}
181
182const char *ptp_profile_preset_get_name(size_t i) {
183 if (i < PTP_PROFILE_N) {
184 return sPtpProfiles[i].name;
185 } else {
186 return NULL;
187 }
188}
189
190const char *ptp_tlv_chain_preset_get_name(size_t i) {
191 if (i < PTP_TLVP_N) {
192 return sTlvPresets[i].name;
193 } else {
194 return NULL;
195 }
196}
197
In here reside a multitude of fundamental PTP-related constants and definitions.
#define PTP_MAX_TLV_PRESET_NAME_LENGTH
Maximum TLV preset name length.
Definition: ptp_defs.h:66
#define PTP_MAX_PROFILE_NAME_LENGTH
Maximum profile name length.
Definition: ptp_defs.h:65
#define FLEXPTP_ntohl(a)
Definition: ptp_defs.h:228
#define FLEXPTP_ntohs(a)
Definition: ptp_defs.h:234
static PtpProfilePreset sPtpProfiles[PTP_PROFILE_N]
const PtpProfileTlvElement * ptp_tlv_chain_preset_get(const char *pName)
PtpGPtpOrganizationTlv
const char * ptp_tlv_chain_preset_get_name(size_t i)
const PtpProfile * ptp_profile_preset_get(const char *pName)
PtpProfileEnum
Enumeration type for predefined profiles.
@ PTP_PROFILE_DEF_P2P
@ PTP_PROFILE_GPTP
@ PTP_PROFILE_PUP_61850
@ PTP_PROFILE_N
@ PTP_PROFILE_DEFAULT
size_t ptp_tlv_chain_preset_cnt()
PtpTlvPresetEnum
@ PTP_TLVP_N
@ PTP_TLVP_GPTP_ORG
const char * ptp_profile_preset_get_name(size_t i)
size_t ptp_profile_preset_cnt()
static const PtpGPtpOrganizationTlv gPtp_OrgTlv
struct __attribute__((packed))
static const PtpProfileTlvElement gPtp_TlvSet
static PtpTlvPreset sTlvPresets[PTP_TLVP_N]
This module manages predefined profile presets. It allows their fetching by name or ID.
This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP ...
@ PTP_TP_IPv4
IPv4 Transport Type.
Definition: ptp_types.h:137
@ PTP_TP_802_3
Ethernet Transport Type.
Definition: ptp_types.h:138
@ PTP_TLV_ORGANIZATION_EXTENSION
Organization extension.
Definition: ptp_types.h:378
#define PTP_TLV_HEADER
Definition: ptp_types.h:401
@ PTP_MT_Follow_Up
Follow Up.
Definition: ptp_types.h:42
@ PTP_DM_E2E
End-to-End Delay Mechanism.
Definition: ptp_types.h:145
@ PTP_DM_P2P
Peer-to-Peer Delay Mechanism.
Definition: ptp_types.h:146
@ PTP_TSPEC_GPTP_8021AS
802.1AS Transport Specific Flag
Definition: ptp_types.h:154
@ PTP_TSPEC_UNKNOWN_DEF
Unkown Transport Specific Flag (default)
Definition: ptp_types.h:153
@ PTP_PF_ISSUE_SYNC_FOR_COMPLIANT_SLAVE_ONLY_IN_P2P
Send Sync messages only for a compliant peer in P2P mode.
Definition: ptp_types.h:349
@ PTP_PF_NO_FLAGS
Empty profile flags.
Definition: ptp_types.h:348
PTP profile structure.
Definition: ptp_types.h:357
PTP profile preset structure.
PtpProfile profile
Associated profile object.
char name[(7)+1]
Name of the profile.
PTP profile additional data list element.
Definition: ptp_types.h:337
const void * data
Pointer to the data block.
Definition: ptp_types.h:338
PTP TLV presets.
char name[(7)+1]
Name of the TLV preset.
const PtpProfileTlvElement * tlvList
Linked list of the TLVs.