libptpmgmt 2.0
libptpmgmt library that provides the functionality of linuxptp pmc
Loading...
Searching...
No Matches
ptp.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-3.0-or-later
2 SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3
15#ifndef __PTPMGMT_IF_H
16#define __PTPMGMT_IF_H
17
18#ifdef __cplusplus
19#include <vector>
20#include <ctime>
21#include "types.h"
22#ifdef __linux__
23#include <linux/ethtool.h>
24#endif
25
26__PTPMGMT_NAMESPACE_BEGIN
27
28/* The macro might be used, we prefer C++ const */
29#ifndef CLOCK_INVALID
31const clockid_t CLOCK_INVALID = -1;
32#endif
34const int NO_SUCH_IF = -1;
36const int NO_SUCH_PTP = -1;
38typedef long double float_freq;
39
43class IfInfo
44{
45 private:
46 bool m_isInit = false;
47 int m_ifIndex = NO_SUCH_IF, m_ptpIndex = NO_SUCH_PTP;
48 std::string m_ifName;
49 Binary m_mac;
50
51 bool initPtp(int fd, struct ifreq &m_ifr);
52
53 public:
59 bool initUsingName(const std::string &ifName);
70 bool isInit() const;
75 int ifIndex() const;
80 const std::string &ifName() const;
85 const char *ifName_c() const;
90 const Binary &mac() const;
95 const uint8_t *mac_c() const;
100 size_t mac_size() const;
108 int ptpIndex() const;
109};
137struct PtpPin_t {
138 unsigned int index;
143 std::string description;
145 unsigned int channel;
146};
151const uint8_t PTP_EXTERN_TS_RISING_EDGE = 1 << 1;
156const uint8_t PTP_EXTERN_TS_FALLING_EDGE = 1 << 2;
161const uint8_t PTP_EXTERN_TS_STRICT = 1 << 3;
166const uint8_t PTP_PERIOD_ONE_SHOT = 1 << 0;
171const uint8_t PTP_PERIOD_WIDTH = 1 << 1;
176const uint8_t PTP_PERIOD_PHASE = 1 << 2;
177
182 unsigned int index;
184};
220{
221 protected:
225 clockid_t m_clkId;
226 bool m_isInit;
227 bool m_freq;
233 BaseClock(clockid_t clkId, bool freq) : m_clkId(clkId), m_isInit(true),
234 m_freq(freq) {}
239 BaseClock() : m_clkId(CLOCK_INVALID), m_isInit(false), m_freq(false) {}
241 public:
242 virtual ~BaseClock();
253 bool setTime(const Timestamp_t &ts) const;
259 bool offsetClock(int64_t offset) const;
270 bool setFreq(float_freq freq) const;
276 bool setPhase(int64_t offset) const;
277};
281class SysClock : public BaseClock
282{
283 public:
284 SysClock();
285};
296class PtpClock : public BaseClock
297{
298 private:
299 int m_fd, m_ptpIndex;
300 std::string m_device;
301 bool init(const char *device, bool readonly);
302
303 public:
304 PtpClock();
305 virtual ~PtpClock();
312 static bool isCharFile(const std::string &file);
319 bool initUsingDevice(const std::string &device, bool readonly = false);
326 bool initUsingIndex(int ptpIndex, bool readonly = false);
331 bool isInit() const;
336 clockid_t clkId() const;
341 int getFd() const;
346 int fileno() const;
352 int ptpIndex() const;
357 const std::string &device() const;
362 const char *device_c() const;
367 bool setTimeFromSys() const;
372 bool setTimeToSys() const;
378 bool fetchCaps(PtpCaps_t &caps) const;
386 bool readPin(unsigned int index, PtpPin_t &pin) const;
394 bool writePin(const PtpPin_t &pin) const;
403 bool ExternTSEbable(unsigned int index, uint8_t flags) const;
410 bool ExternTSDisable(unsigned int index) const;
415 bool MaskClearAll() const;
422 bool MaskEnable(unsigned int index) const;
428 bool readEvent(PtpEvent_t &event) const;
436 bool readEvents(std::vector<PtpEvent_t> &events, size_t max = 0) const;
446 bool setPinPeriod(unsigned int index, PtpPinPeriodDef_t times,
447 uint8_t flags = 0) const;
455 bool setPtpPpsEvent(bool enable) const;
463 bool samplePtpSys(size_t count, std::vector<PtpSample_t> &samples) const;
472 bool extSamplePtpSys(size_t count, std::vector<PtpSampleExt_t> &samples) const;
473
481};
482
483__PTPMGMT_NAMESPACE_END
484#else /* __cplusplus */
485#include "c/ptp.h"
486#endif /* __cplusplus */
487
488#endif /* __PTPMGMT_IF_H */
C interface to network and PHC classes.
Definition ptp.h:220
Timestamp_t getTime() const
bool setPhase(int64_t offset) const
bool setFreq(float_freq freq) const
float_freq getFreq() const
bool offsetClock(int64_t offset) const
bool setTime(const Timestamp_t &ts) const
Definition bin.h:27
Definition ptp.h:44
int ptpIndex() const
bool isInit() const
const uint8_t * mac_c() const
size_t mac_size() const
const Binary & mac() const
const std::string & ifName() const
bool initUsingName(const std::string &ifName)
int ifIndex() const
bool initUsingIndex(int ifIndex)
const char * ifName_c() const
POSIX dynamic clock id generator.
Definition ptp.h:297
clockid_t clkId() const
bool MaskClearAll() const
bool initUsingDevice(const std::string &device, bool readonly=false)
static bool isCharFile(const std::string &file)
int getFd() const
bool ExternTSDisable(unsigned int index) const
bool setTimeFromSys() const
bool fetchCaps(PtpCaps_t &caps) const
bool initUsingIndex(int ptpIndex, bool readonly=false)
bool setTimeToSys() const
bool readEvents(std::vector< PtpEvent_t > &events, size_t max=0) const
bool ExternTSEbable(unsigned int index, uint8_t flags) const
const char * device_c() const
bool readEvent(PtpEvent_t &event) const
bool preciseSamplePtpSys(PtpSamplePrecise_t &sample) const
bool MaskEnable(unsigned int index) const
bool writePin(const PtpPin_t &pin) const
bool setPinPeriod(unsigned int index, PtpPinPeriodDef_t times, uint8_t flags=0) const
int ptpIndex() const
int fileno() const
bool setPtpPpsEvent(bool enable) const
const std::string & device() const
bool isInit() const
bool samplePtpSys(size_t count, std::vector< PtpSample_t > &samples) const
bool extSamplePtpSys(size_t count, std::vector< PtpSampleExt_t > &samples) const
bool readPin(unsigned int index, PtpPin_t &pin) const
Definition ptp.h:282
const uint8_t PTP_PERIOD_ONE_SHOT
Definition ptp.h:166
const uint8_t PTP_EXTERN_TS_FALLING_EDGE
Definition ptp.h:156
long double float_freq
Definition ptp.h:38
const int NO_SUCH_IF
Definition ptp.h:34
const uint8_t PTP_EXTERN_TS_RISING_EDGE
Definition ptp.h:151
const uint8_t PTP_PERIOD_WIDTH
Definition ptp.h:171
const uint8_t PTP_EXTERN_TS_STRICT
Definition ptp.h:161
__PTPMGMT_NAMESPACE_BEGIN const clockid_t CLOCK_INVALID
Definition ptp.h:31
const int NO_SUCH_PTP
Definition ptp.h:36
PtpPinFunc_e
Definition ptp.h:128
@ PTP_PIN_EXTERNAL_TS
Definition ptp.h:130
@ PTP_PIN_PERIODIC_OUT
Definition ptp.h:131
@ PTP_PIN_PHY_SYNC
Definition ptp.h:132
@ PTP_PIN_UNUSED
Definition ptp.h:129
const uint8_t PTP_PERIOD_PHASE
Definition ptp.h:176
Definition ptp.h:113
bool adjust_phase
Definition ptp.h:122
int num_alarm
Definition ptp.h:115
int num_periodic_sig
Definition ptp.h:117
int64_t max_ppb
Definition ptp.h:114
int num_pins
Definition ptp.h:119
bool cross_timestamping
Definition ptp.h:121
int64_t max_phase_adj
Definition ptp.h:123
int num_external_channels
Definition ptp.h:116
bool pps
Definition ptp.h:118
Definition ptp.h:181
unsigned int index
Definition ptp.h:182
Timestamp_t time
Definition ptp.h:183
Definition ptp.h:211
Timestamp_t width
Definition ptp.h:213
Timestamp_t phase
Definition ptp.h:214
Timestamp_t period
Definition ptp.h:212
Definition ptp.h:137
PtpPinFunc_e functional
Definition ptp.h:144
unsigned int index
Definition ptp.h:138
std::string description
Definition ptp.h:143
unsigned int channel
Definition ptp.h:145
Definition ptp.h:195
Timestamp_t before
Definition ptp.h:196
Timestamp_t phcClk
Definition ptp.h:197
Timestamp_t after
Definition ptp.h:198
Definition ptp.h:203
Timestamp_t sysClk
Definition ptp.h:205
Timestamp_t phcClk
Definition ptp.h:204
Timestamp_t monoClk
Definition ptp.h:206
Definition ptp.h:188
Timestamp_t phcClk
Definition ptp.h:190
Timestamp_t sysClk
Definition ptp.h:189
Definition types.h:419
Types, enumerators, and structers used by PTP management messages.