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
16};
17
19 PTP_TLVP_GPTP_ORG, // gPTP (802.1AS) TLV
21};
22
23// -------- gPTP -------------
24
25typedef struct __attribute__((packed)) {
27 uint8_t organizationId[3];
28 uint8_t organizationSubType[3];
29 uint32_t cumulativeScaleRateOffset;
30 uint16_t gmTimeBaseIndicator;
31 uint8_t lastGmPhaseChange[12];
32 uint32_t scaledLastGmFreqChange;
34
37 .length = FLEXPTP_ntohs(28),
38 .organizationId = {0x00, 0x80, 0xC2},
39 .organizationSubType = {0x00, 0x00, 0x01},
40 .cumulativeScaleRateOffset = FLEXPTP_ntohl(0),
41 .gmTimeBaseIndicator = FLEXPTP_ntohs(0),
42 .lastGmPhaseChange = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
43 .scaledLastGmFreqChange = FLEXPTP_ntohl(0)};
44
46 .data = &gPtp_OrgTlv,
47 .size = sizeof(PtpGPtpOrganizationTlv),
48 .msgType = PTP_MT_Follow_Up,
49 NULL};
50
51// ---------------------------
52
56typedef struct {
60
64typedef struct {
68
69// clang-format off
70
75 {
76 "gptp",
78 }
79};
80
85 {"default",
86 {
90 0,
91 0,
92 1,
93 0,
95 ""
96 }
97 },
98 {"gPTP",
99 {
103 0,
104 -3,
105 0,
106 0,
108 "gptp"
109 }
110 },
111 {"defp2p",
112 {
116 0,
117 0,
118 1,
119 0,
121 ""
122 }
123 }
124};
125
126// clang-format on
127
128const PtpProfile *ptp_profile_preset_get(const char *pName) {
129 size_t i = 0;
130 PtpProfile *pProfile = NULL;
131 for (i = 0; i < PTP_PROFILE_N; i++) {
132 if (!strcmp(sPtpProfiles[i].name, pName)) {
133 pProfile = &sPtpProfiles[i].profile;
134 break;
135 }
136 }
137 return pProfile;
138}
139
141 size_t i = 0;
142 const PtpProfileTlvElement *pTlvChain = NULL;
143 for (i = 0; i < PTP_TLVP_N; i++) {
144 if (!strcmp(sTlvPresets[i].name, pName)) {
145 pTlvChain = sTlvPresets[i].tlvList;
146 break;
147 }
148 }
149 return pTlvChain;
150}
151
153 return PTP_PROFILE_N;
154}
155
157 return PTP_TLVP_N;
158}
159
160const char *ptp_profile_preset_get_name(size_t i) {
161 if (i < PTP_PROFILE_N) {
162 return sPtpProfiles[i].name;
163 } else {
164 return NULL;
165 }
166}
167
168const char *ptp_tlv_chain_preset_get_name(size_t i) {
169 if (i < PTP_TLVP_N) {
170 return sTlvPresets[i].name;
171 } else {
172 return NULL;
173 }
174}
175
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:58
#define PTP_MAX_PROFILE_NAME_LENGTH
Maximum profile name length.
Definition: ptp_defs.h:57
#define FLEXPTP_ntohl(a)
Definition: ptp_defs.h:169
#define FLEXPTP_ntohs(a)
Definition: ptp_defs.h:175
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_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:129
@ PTP_TP_802_3
Ethernet Transport Type.
Definition: ptp_types.h:130
@ PTP_TLV_ORGANIZATION_EXTENSION
Organization extension.
Definition: ptp_types.h:350
#define PTP_TLV_HEADER
Definition: ptp_types.h:373
@ PTP_MT_Follow_Up
Follow Up.
Definition: ptp_types.h:34
@ PTP_DM_E2E
End-to-End Delay Mechanism.
Definition: ptp_types.h:137
@ PTP_DM_P2P
Peer-to-Peer Delay Mechanism.
Definition: ptp_types.h:138
@ PTP_TSPEC_GPTP_8021AS
802.1AS Transport Specific Flag
Definition: ptp_types.h:146
@ PTP_TSPEC_UNKNOWN_DEF
Unkown Transport Specific Flag (default)
Definition: ptp_types.h:145
@ PTP_PF_NONE
Empty profile flags.
Definition: ptp_types.h:322
@ 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:323
PTP profile structure.
Definition: ptp_types.h:331
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:311
const void * data
Pointer to the data block.
Definition: ptp_types.h:312
PTP TLV presets.
char name[(7)+1]
Name of the TLV preset.
const PtpProfileTlvElement * tlvList
Linked list of the TLVs.