<< >>

PTP Client API

The PTP client API can be used if you want extra information about the PTP time domain. An application does not need to directly use this to control the AVB endpoint since the talker, listener and media clock server units communicate with the PTP server directly.

Time Data Structures

ptp_timestamp

This type represents a timestamp in the gptp clock domain.

Structure Members:

unsigned int seconds
unsigned int nanoseconds

Getting PTP Time Information

ptp_time_info

This type is used to relate local XCore time with gptp time.

It can be retrieved from the PTP server using the ptp_get_time_info() function.

ptp_time_info_mod64

This structure is used to relate local XCore time with the least significant 64 bits of gptp time.

The 64 bits of time is the PTP time in nanoseconds from the epoch.

It can be retrieved from the PTP server using the ptp_get_time_info_mod64() function.

void ptp_get_time_info(chanend ptp_server, ptp_time_info &info)

Retrieve time information from the ptp server.

This function gets an up-to-date structure of type ptp_time_info to use to convert local time to PTP time.

Parameters:
  • ptp_server – chanend connected to the ptp_server
  • info – structure to be filled with time information
void ptp_get_time_info_mod64(chanend ptp_server, ptp_time_info_mod64 &info)

Retrieve time information from the ptp server.

This function gets an up-to-date structure of type ptp_time_info_mod64 to use to convert local time to ptp time (modulo 64 bits).

Parameters:
  • ptp_server – chanend connected to the ptp_server
  • info – structure to be filled with time information
void ptp_request_time_info(chanend ptp_server)

This function requests a ptp_time_info structure from the PTP server.

This is an asynchronous call so needs to be completed later with a call to ptp_get_requested_time_info().

Parameters:
  • ptp_server – chanend connecting to the ptp server
void ptp_request_time_info_mod64(chanend ptp_server)

This function requests a ptp_time_info_mod64 structure from the PTP server.

This is an asynchronous call so needs to be completed later with a call to ptp_get_requested_time_info_mod64().

Parameters:
  • ptp_server – chanend connecting to the PTP server
void ptp_get_requested_time_info(chanend ptp_server, ptp_time_info &info)

This function receives a ptp_time_info structure from the PTP server.

This completes an asynchronous transaction initiated with a call to ptp_request_time_info(). The function can be placed in a select case which will activate when the PTP server is ready to send.

Parameters:
  • ptp_server – chanend connecting to the PTP server
  • info – a reference parameter to be filled with the time information structure
void ptp_get_requested_time_info_mod64(chanend ptp_server, ptp_time_info_mod64 &info)

This function receives a ptp_time_info_mod64 structure from the PTP server.

This completes an asynchronous transaction initiated with a call to ptp_request_time_info_mod64(). The function can be placed in a select case which will activate when the PTP server is ready to send.

Parameters:
  • ptp_server – chanend connecting to the PTP server
  • info – a reference parameter to be filled with the time information structure

Converting Timestamps

void local_timestamp_to_ptp(ptp_timestamp &ptp_ts, unsigned local_ts, ptp_time_info &info)

Convert a timestamp from the local XCore timer to PTP time.

This function takes a 32-bit timestamp taken from an XCore timer and converts it to PTP time.

Parameters:
  • ptp_ts – the PTP timestamp structure to be filled with the converted time
  • local_ts – the local timestamp to be converted
  • info – a time information structure retrieved from the ptp server
unsigned local_timestamp_to_ptp_mod32(unsigned local_ts, ptp_time_info_mod64 &info)

Convert a timestamp from the local XCore timer to the least significant 32 bits of PTP time.

This function takes a 32-bit timestamp taken from an XCore timer and converts it to the least significant 32 bits of global PTP time.

Parameters:
  • local_ts – the local timestamp to be converted
  • info – a time information structure retrieved from the PTP server
Returns:

the least significant 32-bits of ptp time in nanoseconds

unsigned ptp_timestamp_to_local(ptp_timestamp &ts, ptp_time_info &info)

Convert a PTP timestamp to a local XCore timestamp.

This function takes a PTP timestamp and converts it to a local 32-bit timestamp that is related to the XCore timer.

Parameters:
  • ts – the PTP timestamp to convert
  • info – a time information structure retrieved from the PTP server.
Returns:

the local timestamp