This chapter contains a description of all NetX Duo PTP client services (listed below) in alphabetical order.
Note: In the Return Values section in the following API function descriptions, values in BOLD are not affected by the NX_DISABLE_ERROR_CHECKING define that is used to disable API error checking, while non-bold values are completely disabled.
Create a PTP client instance.
UINT nx_ptp_client_create(
NX_PTP_CLIENT *client_ptr,
NX_IP *ip_ptr,
UINT interface_index,
NX_PACKET_POOL *packet_pool_ptr,
UINT thread_priority,
UCHAR *thread_stack,
UINT stack_size,
NX_PTP_CLIENT_CLOCK_CALLBACK clock_callback,
VOID *clock_callback_data);
This service creates an instance of the PTP client.
Note that the application must first create an IP instance and a packet pool for the PTP client to transmit packets. For the packet pool, application may use the same packet pool in the IP instance; or it can create a dedicated packet pool for PTP client. The dedicated packet pool approach has the advantage of using small packets (128 bytes packets if IPv6 is used, or 108 bytes for IPv4-only).
Threads
/* Create the PTP client instance */
status = nx_ptp_client_create(&ptp_client, &ip_0, 0, &pool_0,
PTP_THREAD_PRIORITY, (UCHAR *)ptp_stack, sizeof(ptp_stack),
clock_callback, NX_NULL);
/* If the client was successfully created, status = NX_SUCCESS. */
Deletes a PTP client instance.
UINT nx_ptp_client_delete(NX_PTP_CLIENT *client_ptr);
This service deletes an instance of the PTP client.
Threads
/* Delete the PTP client instance */
status = nx_ptp_client_delete(&ptp_client);
/* If the client was successfully deleted, status = NX_SUCCESS. */
Get master clock information.
UINT nx_ptp_client_master_info_get(
NX_PTP_CLIENT_MASTER *master_ptr,
NXD_ADDRESS *address,
UCHAR **port_identity,
UINT *port_identity_length,
UCHAR *priority1,
UCHAR *priority2,
UCHAR *clock_class,
UCHAR *clock_accuracy,
USHORT *clock_variance,
UCHAR **grandmaster_identity,
UINT *grandmaster_identity_length,
USHORT *steps_removed,
UCHAR *time_source);
This service gets information of master clock. The master control block is passed to user application through event callback function.
Threads
static UINT ptp_event_callback(NX_PTP_CLIENT *ptp_client_ptr, UINT event, VOID *event_data, VOID *callback_data)
{
NXD_ADDRESS address;
UCHAR *port_identity;
UINT port_identity_length;
UCHAR priority1, priority2;
UCHAR clock_class, clock_accuracy;
USHORT clock_variance;
UCHAR *grandmaster_identity;
UINT grandmaster_identity_length;
USHORT steps_removed;
UCHAR time_source;
switch (event)
{
case NX_PTP_CLIENT_EVENT_MASTER:
{
status = nx_ptp_client_master_info_get((NX_PTP_CLIENT_MASTER *)event_data,
&address, &port_identity,
&port_identity_length, &priority1,
&priority2, &clock_class,
&clock_accuracy, &clock_variance,
&grandmaster_identity,
&grandmaster_identity_length,
&steps_removed, &time_source);
/* If the master clock information was successfully get, status = NX_SUCCESS. */
break;
}
/* Other event process. */
}
}
Notify PTP client the timestamp of the packet.
VOID nx_ptp_client_packet_timestamp_notify(
NX_PTP_CLIENT *client_ptr,
NX_PACKET *packet_ptr,
NX_PTP_TIME *timestamp_ptr);
This service notifies the PTP client that packet is transmitted with timestamp. This service is designed for network driver and invoked when the packet is transmitted. The timestamp is usually generated by hardware.
None
Threads
/* Call notification callback */
nx_ptp_client_packet_timestamp_notify(client_ptr, packet_ptr, &ts);
Software implementation of a PTP clock.
UINT nx_ptp_client_soft_clock_callback(
NX_PTP_CLIENT *client_ptr,
UINT operation,
NX_PTP_TIME *time_ptr,
NX_PACKET *packet_ptr,
VOID *callback_data);
This callback function serves as a simulated low resolution clock source for PTP. This routine is provided as a reference and cannot be used for production.
time_ptr.time_ptr.packet_ptr to time_ptr.packet_ptr which requires to notify PTP client the timestamp when it is transmitted.PTP internal
```C/* Create the PTP client instance */ status = nx_ptp_client_create(&ptp_client, &ip_0, 0, &pool_0, PTP_THREAD_PRIORITY, (UCHAR *)ptp_stack, sizeof(ptp_stack), nx_ptp_client_soft_clock_callback, NX_NULL);
/* If the client was successfully created, status = NX_SUCCESS. */
## nx_ptp_client_start
Start PTP client.
### Prototype
```C
UINT nx_ptp_client_start(
NX_PTP_CLIENT *client_ptr,
UCHAR *client_port_identity_ptr,
UINT client_port_identity_length,
UINT domain,
UINT transport_specific,
NX_PTP_CLIENT_EVENT_CALLBACK event_callback,
VOID *event_callback_data)
This service starts a previously created PTP client instance.
Threads
status = nx_ptp_client_start(&ptp_client, NX_NULL, 0, 0, 0, ptp_event_callback, NX_NULL);
/* If the client was successfully started, status = NX_SUCCESS. */
Stop PTP client. After the PTP client is stopped, it does not process PTP packets, nor does it transmit PTP packets.
UINT nx_ptp_client_stop(NX_PTP_CLIENT *client_ptr);
This service stops a previously created and started PTP client instance.
Threads
status = nx_ptp_client_stop(&ptp_client);
/* If the client was successfully stopped, status = NX_SUCCESS. */
Get Sync information.
UINT nx_ptp_client_sync_info_get(
NX_PTP_CLIENT_SYNC *sync_ptr,
USHORT *flags,
SHORT *utc_offset);
This service gets information of Sync message. The Sync control block is passed to user application through event callback function.
Threads
static UINT ptp_event_callback(NX_PTP_CLIENT *ptp_client_ptr, UINT event, VOID *event_data, VOID *callback_data)
{
USHORT utc_offset;
switch (event)
{
case NX_PTP_CLIENT_EVENT_SYNC:
{
nx_ptp_client_sync_info_get((NX_PTP_CLIENT_SYNC *)event_data, NX_NULL, &utc_offset);
/* If the Sync information was successfully get, status = NX_SUCCESS. */
break;
}
/* Other event process. */
}
}
Get current time.
UINT nx_ptp_client_time_get(
NX_PTP_CLIENT *client_ptr,
NX_PTP_TIME *time_ptr);
This service gets the current value of the PTP clock. It is available no matter PTP client is synchronized with master clock or not.
Threads
/* Get the PTP clock */
nx_ptp_client_time_get(&ptp_client, &tm);
Set current time.
UINT nx_ptp_client_time_set(
NX_PTP_CLIENT *client_ptr,
NX_PTP_TIME *time_ptr);
This service sets the current value of the PTP clock. It must be invoked before PTP client starts.
Threads
/* Set current time before PTP client started. */
status = nx_ptp_client_time_set(&ptp_client, &tm);
Convert PTP time to a UTC date and time.
UINT nx_ptp_client_utility_convert_time_to_date(
NX_PTP_TIME *time_ptr,
LONG offset,
NX_PTP_DATE_TIME *date_time_ptr);
This service converts PTP time to a UTC date and time.
Threads
/* convert PTP time to UTC date and time */
status = nx_ptp_client_utility_convert_time_to_date(&tm, -ptp_utc_offset, &date);
/* If the time was successfully converted, status = NX_SUCCESS. */
Diff two PTP times.
UINT nx_ptp_client_utility_time_diff(
NX_PTP_TIME *time1_ptr,
NX_PTP_TIME *time2_ptr,
NX_PTP_TIME *result_ptr);
This service computes the difference between two PTP times.
Threads
/* Diff time. */
status = nx_ptp_client_utility_time_diff(&time1, &time2, &result);
/* If the calculation was successfully, status = NX_SUCCESS. */