Skip to content

Commit 5aceb1d

Browse files
Merge pull request #3 from PADL/lhoward/rx-tx-timestamps
support for RX and TX timestamps
2 parents a38a4c2 + d3ee77e commit 5aceb1d

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

contrib/ports/xmos/include/netif/ethernetif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int xcore_ethernetif_init(const uint8_t* mac_address_phy, const xtcp_ipconfig_t*
3939
void xcore_lwip_init_timers(uint32_t period[NUM_TIMEOUTS], uint32_t timeout[NUM_TIMEOUTS], uint32_t time_now);
4040

4141
/* LwIP Ethernet packet input function */
42-
void ethernetif_input(const uint8_t buffer[], int32_t n_bytes);
42+
void ethernetif_input(const uint8_t buffer[], int32_t n_bytes, uint32_t timestamp);
4343

4444
/* Wrapper for LwIP link notifications */
4545
void xcore_net_link_up(void);

contrib/ports/xmos/include/netif/xcore_netif_output.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ void xcore_netif_output_init(client ethernet_tx_if ?i_eth_tx, client mii_if ?i_m
2626
*/
2727
void xcore_netif_low_level_output(int buffer[], size_t n_bytes);
2828

29+
uint32_t xcore_netif_low_level_output_timed(int buffer[], size_t n_bytes);
30+
2931
#endif /* __XCORE_NETIF_H__ */

contrib/ports/xmos/lib/minimal/lwipopts.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,20 @@
160160

161161
// Custom data in pbuf to hold remote address for UDP recvfrom()
162162
#include "xtcp.h"
163-
#define LWIP_PBUF_CUSTOM_DATA xtcp_host_t remote;
164-
#define LWIP_PBUF_CUSTOM_DATA_INIT(p) p->remote.ipaddr[0] = 0; p->remote.ipaddr[1] = 0; p->remote.ipaddr[2] = 0; p->remote.ipaddr[3] = 0; p->remote.port_number = 0;
163+
#define LWIP_PBUF_CUSTOM_DATA \
164+
xtcp_host_t remote; \
165+
unsigned timestamp;
166+
167+
#define LWIP_PBUF_CUSTOM_DATA_INIT(p) \
168+
p->remote.ipaddr[0] = 0; \
169+
p->remote.ipaddr[1] = 0; \
170+
p->remote.ipaddr[2] = 0; \
171+
p->remote.ipaddr[3] = 0; \
172+
p->remote.port_number = 0; \
173+
p->timestamp = 0;
174+
175+
// this reuses the flag field to avoid adding an additional field;
176+
// care should be taken if lwIP adds additional flags
177+
#define PBUF_FLAG_TX_TIMESTAMP 0x80
165178

166179
#endif /* __LWIPOPTS_H__ */

contrib/ports/xmos/lib/standard/lwipopts.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,20 @@
159159

160160
// Custom data in pbuf to hold remote address for UDP recvfrom()
161161
#include "xtcp.h"
162-
#define LWIP_PBUF_CUSTOM_DATA xtcp_host_t remote;
163-
#define LWIP_PBUF_CUSTOM_DATA_INIT(p) p->remote.ipaddr[0] = 0; p->remote.ipaddr[1] = 0; p->remote.ipaddr[2] = 0; p->remote.ipaddr[3] = 0; p->remote.port_number = 0;
162+
#define LWIP_PBUF_CUSTOM_DATA \
163+
xtcp_host_t remote; \
164+
unsigned timestamp;
165+
166+
#define LWIP_PBUF_CUSTOM_DATA_INIT(p) \
167+
p->remote.ipaddr[0] = 0; \
168+
p->remote.ipaddr[1] = 0; \
169+
p->remote.ipaddr[2] = 0; \
170+
p->remote.ipaddr[3] = 0; \
171+
p->remote.port_number = 0; \
172+
p->timestamp = 0;
173+
174+
// this reuses the flag field to avoid adding an additional field;
175+
// care should be taken if lwIP adds additional flags
176+
#define PBUF_FLAG_TX_TIMESTAMP 0x80
164177

165178
#endif /* __LWIPOPTS_H__ */

contrib/ports/xmos/port/ethernetif.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,18 @@ static err_t xcore_ethernetif_linkoutput(struct netif *netif, struct pbuf *p) {
162162

163163
n_bytes = 60;
164164
/* Start MAC transmit here */
165-
xcore_netif_low_level_output(txbuf, n_bytes);
165+
if (p->flags & PBUF_FLAG_TX_TIMESTAMP)
166+
p->timestamp = xcore_netif_low_level_output_timed(txbuf, n_bytes);
167+
else
168+
xcore_netif_low_level_output(txbuf, n_bytes);
166169
} else {
167170
// NOTE: this is not expecting or setup to deal with pbuf chains
168171

169172
/* Start MAC transmit here */
170-
xcore_netif_low_level_output(p->payload, n_bytes);
173+
if (p->flags & PBUF_FLAG_TX_TIMESTAMP)
174+
p->timestamp = xcore_netif_low_level_output_timed(p->payload, n_bytes);
175+
else
176+
xcore_netif_low_level_output(p->payload, n_bytes);
171177
}
172178

173179
#if ETH_PAD_SIZE
@@ -324,12 +330,14 @@ void xcore_timeout(xtcp_lwip_timeout_type timeout) {
324330
* interface.
325331
*
326332
*/
327-
void ethernetif_input(const uint8_t buffer[], int32_t n_bytes) {
333+
void ethernetif_input(const uint8_t buffer[], int32_t n_bytes, uint32_t timestamp) {
328334
/* move received packet into a new pbuf */
329335
struct pbuf *p = xcore_net_low_level_input(buffer, n_bytes);
330336

331337
/* if no packet could be read, silently ignore this */
332338
if (p != NULL) {
339+
p->timestamp = timestamp;
340+
333341
/* pass all packets to ethernet_input, which decides what packets it supports */
334342
if (xcore_netif.input(p, &xcore_netif) != ERR_OK) {
335343

contrib/ports/xmos/port/xcore_netif_output.xc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@ void xcore_netif_low_level_output(int buffer[], size_t n_bytes) {
6262
fail("xcore_netif_low_level_output: netif output interface not set.\n");
6363
}
6464
}
65+
66+
uint32_t xcore_netif_low_level_output_timed(int buffer[], size_t n_bytes) {
67+
if (xcore_netif_eth == XCORE_NETIF_ETH_TX) {
68+
unsafe {
69+
// TODO - Check whether ETHERNET_ALL_INTERFACES is correct when we support dual-PHY
70+
return ((client interface ethernet_tx_if)xtcp_i_eth_tx).send_timed_packet((char *)buffer,
71+
n_bytes,
72+
ETHERNET_ALL_INTERFACES);
73+
}
74+
} else {
75+
fail("xcore_netif_low_level_output: netif output interface not set.\n");
76+
return 0;
77+
}
78+
}

0 commit comments

Comments
 (0)