xiaoxiang781216 commented on code in PR #3791:
URL: https://github.com/apache/nuttx-apps/pull/3791#discussion_r4056299018
##########
netutils/ptpd/ptpd.c:
##########
@@ -116,6 +122,13 @@ struct ptp_state_s
int tx_socket;
+ /* Hardware TX timestamp retrieval: consecutive failures, and whether it
+ * was given up on because the driver does not provide the timestamps.
+ */
+
+ unsigned int hwts_tx_failures;
Review Comment:
why need dynamically detect whether driver support hw timestamp in a close
system? is it enough to check CONFIG_NET_TIMESTAMP
##########
netutils/ptpd/ptpd.c:
##########
@@ -880,11 +899,103 @@ static int ptp_check_multicast_status(FAR struct
ptp_state_s *state)
return OK;
}
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
+/****************************************************************************
+ * Name: ptp_get_tx_timestamp
+ *
+ * Description:
+ * Retrieve the hardware TX timestamp delivered via MSG_ERRQUEUE on the
+ * socket after transmission.
+ *
+ * Input Parameters:
+ * state - Pointer to PTP daemon state
+ * tx_ts - Location to return the hardware timestamp
+ *
+ * Returned Value:
+ * OK on success; ERROR on failure or timeout.
+ *
+ ****************************************************************************/
+
+static int ptp_get_tx_timestamp(FAR struct ptp_state_s *state,
+ FAR struct timespec *tx_ts)
+{
+ struct pollfd pfd;
+ int ret;
+
+ pfd.fd = state->tx_socket;
+ pfd.events = POLLPRI;
+ pfd.revents = 0;
+
+ ret = poll(&pfd, 1, 500);
+ if (ret > 0 && (pfd.revents & (POLLPRI | POLLERR)) != 0)
+ {
+ char errbuf[128];
+ char cmsgbuf[128];
+ struct msghdr msg;
+ struct iovec iov;
+ FAR struct cmsghdr *cmsg;
+ ssize_t n;
+
+ memset(&msg, 0, sizeof(msg));
+ iov.iov_base = errbuf;
+ iov.iov_len = sizeof(errbuf);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = cmsgbuf;
+ msg.msg_controllen = sizeof(cmsgbuf);
+
+ n = recvmsg(state->tx_socket, &msg, MSG_ERRQUEUE);
+ if (n >= 0)
+ {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+ cmsg = CMSG_NXTHDR(&msg, cmsg))
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET &&
+ cmsg->cmsg_type == SO_TIMESTAMPING)
+ {
+ FAR struct timespec *ts =
+ (FAR struct timespec *)CMSG_DATA(cmsg);
+
+ *tx_ts = ts[2];
+ return OK;
+ }
+ }
+
+ ptpwarn("PTP TX HWTS: recvmsg %zd B without SO_TIMESTAMPING\n",
+ n);
+ }
+ else
+ {
+ ptpwarn("PTP TX HWTS: recvmsg MSG_ERRQUEUE failed errno=%d\n",
+ errno);
+ }
+ }
+ else
+ {
+ ptpwarn("PTP TX HWTS: poll ret=%d revents=0x%04x errno=%d\n",
+ ret, pfd.revents, errno);
+ }
+
+ return ERROR;
+}
+#endif
+
static int ptp_sendmsg(FAR struct ptp_state_s *state, FAR const void *buf,
size_t buflen, FAR const void *addr,
socklen_t addrlen, FAR struct timespec *sendts)
{
int ret;
+ struct timespec sw_ts;
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
Review Comment:
#ifdef CONFIG_NET_TIMESTAMP
##########
netutils/ptpd/ptpd.c:
##########
@@ -880,11 +899,103 @@ static int ptp_check_multicast_status(FAR struct
ptp_state_s *state)
return OK;
}
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
Review Comment:
ifdef CONFIG_NET_TIMESTAMP
##########
netutils/ptpd/ptpd.c:
##########
@@ -938,9 +1049,48 @@ static int ptp_sendmsg(FAR struct ptp_state_s *state, FAR
const void *buf,
msg.msg_control = NULL;
msg.msg_controllen = 0;
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
Review Comment:
ditto
##########
netutils/ptpd/ptpd.c:
##########
@@ -951,7 +1101,38 @@ static int ptp_sendmsg(FAR struct ptp_state_s *state, FAR
const void *buf,
if (sendts != NULL)
{
- ptp_gettime(state, sendts);
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
Review Comment:
ditto
##########
netutils/ptpd/ptpd.c:
##########
@@ -2311,15 +2497,47 @@ int ptpd_start(FAR const struct ptpd_config_s *config)
if (pollfds[0].revents)
{
- /* Receive time-critical packet, potentially with cmsg
- * indicating the timestamp.
+#if defined(CONFIG_NET_TIMESTAMP) && defined(SO_TIMESTAMPING)
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]