FreeRTOS+TCP HW Timestamping Option


I’m wondering if there is any way to provide / enable a HW timestamping option for FreeRTOS + TCP. The micro that I’m using provides a HW timestamp on exactly when the ethernet frame was processed by the ethernet MAC, and it would be ideal to be able to propagate this information up the stack to be consumed by PTP or the like somewhere down the line.

If this doesn’t exist, can you please guide me to information on working on a patch and possibly getting it added into the FreeRTOS mainline? Would be great to get this feature added (maybe behind a #define in FreeRTOSIPConfig.h)


This sounds to be a very port specific thing and currently there is no way of attaching metadata to network packets. From memory it should be possible to add a new optional field into the network packet structure to store additional information - and as that data is coming from the MAC it would have to be filled in within the driver in your case. Then that additional information would follow the network packet as it flowed through the stack up to the application.

Thanks for your reply. I’m getting a working example that sort of mimics normal sockets API with SO_TIMESTAMP. Once I’ve got this working, what’s the procedure for getting changes back into mainline? Is this possible?

Yes it is definitely possible - the master copy of the TCP code is currently here so you can open a pull request.

The development of a general-purpose library is often guided by 2 contradicting desires: the wish to make it as complete as possible, and on the other hand, the wish to keep things simple. TCP Time-stamping has disappeared from the library in order to decrease its complexity.

But it is possibly not TCP time-stamping what you want to do?

Like Richard suggested, you could add a new field to NetworkBufferDescriptor_t:

typedef struct xNETWORK_BUFFER
	#if( ipconfigUSE_MESSAGE_TIME_STAMP != 0 )
		uint32_t ulTimeStamp;
} NetworkBufferDescriptor_t;

Just curiosity: does your application have to do with ( synchronising ) audio?

Thanks again for the quick response. I got this part working quite nicely actually, but now I’ve run into another issue that it looks that the network stack does not support IGMP or Multicast messaging.
My goal was to add a PTP library to FreeRTOS+TCP to replace lwIP, but the lack of multicast support means this is pretty difficult.
I did see this post:
which mentions what you need to do to support multicast, but I’d really rather not hack up the library so much if at all possible.

Any chance multicast / IGMP support will be arriving any time soon?

There have been many proposals to add multi-casting, and also mDNS, but a decision has not been taken yet.

Note that in principle you can use multi-casting already: create a UDP socket, bind it to the desired UDP port number and call recvfrom().

Make sure that incoming multicast packets are not dropped by a filter.
You can define ipconfigETHERNET_DRIVER_FILTERS_PACKETS, and make sure that all multicast packets are let through in your NetworkInterface.c.

Also the peripheral (the EMAC) must be programmed to accept IPv4 multicast packets ( 0x01, 0x00, 0x5E ).
I am attaching 2 functions for IPv4 multi-cast addresses.

/* Return pdTRUE if the IPv4 address is a multicast address. */
BaseType_t xIsIPv4Multicast( uint32_t ulIPAddress );

/* Set the MAC-address that belongs to a given IPv4 multi-cast address. */
void vSetMultiCastIPv4MacAddress( uint32_t ulIPAddress, MACAddress_t *pxMACAddress );

multicast.c (2.4 KB)