-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathll_gptpsupport.h
144 lines (122 loc) · 4.65 KB
/
ll_gptpsupport.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
/*
* 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>.
*/
#ifndef __LL_GPTPSUPPORT_H_
#define __LL_GPTPSUPPORT_H_
#ifndef PTPFD_TYPE
#define PTPFD_TYPE int
#define PTPFD_VALID(ptpfd) (ptpfd>=0)
#define PTPFD_INVALID -1
#define PRiFD "%d"
#endif
/*******************************************************
* functions supported in the platform dependent layer
*******************************************************/
PTPFD_TYPE ptpdev_clock_open(char *ptpdev, int permission);
int ptpdev_clock_close(PTPFD_TYPE fd);
int ptpdev_clock_gettime(PTPFD_TYPE fd, int64_t *ts64);
int ptpdev_clock_settime(PTPFD_TYPE fd, int64_t *ts64);
int ptpdev_clock_adjtime(PTPFD_TYPE ptpfd, int adjppb);
/*******************************************************/
/*
* Virtual clock is a clock that has prefix name as #CB_VIRTUAL_PTPDEV_PREFIX
* and fd range from #GPTP_VIRTUAL_PTPDEV_FDBASE to #GPTP_VIRTUAL_PTPDEV_FDMAX.
*/
#ifdef PTP_VIRTUAL_CLOCK_SUPPORT
#define VIRTUAL_CLOCKFD(fd) \
((fd>=(PTPFD_TYPE)GPTP_VIRTUAL_PTPDEV_FDBASE) && \
(fd<=(PTPFD_TYPE)GPTP_VIRTUAL_PTPDEV_FDMAX))
#define VIRTUAL_CLOCKNAME(name) \
(strstr(name, CB_VIRTUAL_PTPDEV_PREFIX)==name)
/*----------------------------------------------------------*/
/* These macros are used by application that use libgptp2 */
static inline int _zero_return(void){return 0;}
#define PTPDEV_CLOCK_OPEN(name, perm) \
VIRTUAL_CLOCKNAME(name)?(PTPFD_TYPE)GPTP_VIRTUAL_PTPDEV_FDBASE:ptpdev_clock_open(name,perm)
#define PTPDEV_CLOCK_CLOSE(fd) \
(fd==(PTPFD_TYPE)(GPTP_VIRTUAL_PTPDEV_FDBASE))?_zero_return():ptpdev_clock_close(fd)
#define PTPDEV_CLOCK_GETTIME(fd,ts64) \
{\
if(!VIRTUAL_CLOCKFD(fd)){\
ptpdev_clock_gettime(fd, (int64_t *)&(ts64));\
}else{\
ts64=ub_rt_gettime64();\
}\
}
/*----------------------------------------------------------*/
/*----------------------------------------------------------*/
/* These macros are used by gptp2d */
uint64_t gptp_vclock_gettime(PTPFD_TYPE ptpfd);
int gptp_vclock_settime(PTPFD_TYPE ptpfd, uint64_t ts64);
#define GPTP_CLOCK_GETTIME(fd,ts64) \
{\
if(!VIRTUAL_CLOCKFD(fd)){\
ptpdev_clock_gettime(fd, (int64_t *)&(ts64));\
}else{\
ts64=gptp_vclock_gettime(fd);\
}\
}
#define GPTP_CLOCK_SETTIME(fd,ts64) \
{\
if(!VIRTUAL_CLOCKFD(fd)){\
ptpdev_clock_settime(fd, (int64_t *)&(ts64));\
}else{\
gptp_vclock_settime(fd, ts64);\
}\
}
/*----------------------------------------------------------*/
#else //!PTP_VIRTUAL_CLOCK_SUPPORT
/*----------------------------------------------------------*/
/* These macros are used by application that use libgptp2 */
#define PTPDEV_CLOCK_OPEN(name, perm) ptpdev_clock_open(name,perm)
#define PTPDEV_CLOCK_CLOSE(fd) ptpdev_clock_close(fd)
#define PTPDEV_CLOCK_GETTIME(fd,ts64) ptpdev_clock_gettime(fd, (int64_t *)&(ts64))
/*----------------------------------------------------------*/
/*----------------------------------------------------------*/
/* These macros are used by gptp2d */
#define GPTP_CLOCK_GETTIME(fd,ts64) ptpdev_clock_gettime(fd, (int64_t *)&(ts64))
#define GPTP_CLOCK_SETTIME(fd,ts64) ptpdev_clock_settime(fd, (int64_t *)&(ts64))
/*----------------------------------------------------------*/
#endif //!PTP_VIRTUAL_CLOCK_SUPPORT
/**
* @brief enables H/W Timestamping for socket
* @param dev ethernet device name like 'eth0', 'eno1', 'enp2s0'.
* @return 0 on success, -1 on error
*/
int ll_set_hw_timestamping(CB_SOCKET_T cfd, const char *dev);
/**
* @brief disables hardware timestamping for socket
* @param dev ethernet device name like 'eth0'
* @return 0 on success, -1 on error
*/
int ll_close_hw_timestamping(CB_SOCKET_T cfd, const char *dev);
/**
* @brief get Tx timestamp from msg
* @param tts return timestamp
* @return 0 on success, -1 on error
*/
int ll_txmsg_timestamp(void *p, int64_t *ts64);
/**
* @brief get Rx timestamp from msg
* @param ts return timestamp
* @return 0 on success, -1 on error
*/
int ll_recv_timestamp(void *p, int64_t *ts64);
#endif