unofficial-rtos-docs

Chapter 3 - Description of NetX Duo PTP Client Services

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.

nx_ptp_client_create

Create a PTP client instance.

Prototype

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);

Description

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).

Input Parameters

Return Values

Allowed From

Threads

Example

/* 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. */

nx_ptp_client_delete

Deletes a PTP client instance.

Prototype

UINT nx_ptp_client_delete(NX_PTP_CLIENT *client_ptr);

Description

This service deletes an instance of the PTP client.

Input Parameters

Return Values

Allowed From

Threads

Example

/* Delete the PTP client instance */
status = nx_ptp_client_delete(&ptp_client);

/* If the client was successfully deleted, status = NX_SUCCESS. */

nx_ptp_client_master_info_get

Get master clock information.

Prototype

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);

Description

This service gets information of master clock. The master control block is passed to user application through event callback function.

Input Parameters

Return Values

Allowed From

Threads

Example

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. */
    }
}

nx_ptp_client_packet_timestamp_notify

Notify PTP client the timestamp of the packet.

Prototype

VOID nx_ptp_client_packet_timestamp_notify(
    NX_PTP_CLIENT *client_ptr, 
    NX_PACKET *packet_ptr, 
    NX_PTP_TIME *timestamp_ptr);

Description

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.

Input Parameters

Return Values

None

Allowed From

Threads

Example

/* Call notification callback */
nx_ptp_client_packet_timestamp_notify(client_ptr, packet_ptr, &ts);

nx_ptp_client_soft_clock_callback

Software implementation of a PTP clock.

Prototype

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);

Description

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.

Input Parameters

Return Values

Allowed From

PTP internal

Example

```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)

Description

This service starts a previously created PTP client instance.

Input Parameters

Return Values

Allowed From

Threads

Example

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. */

nx_ptp_client_stop

Stop PTP client. After the PTP client is stopped, it does not process PTP packets, nor does it transmit PTP packets.

Prototype

UINT nx_ptp_client_stop(NX_PTP_CLIENT *client_ptr);

Description

This service stops a previously created and started PTP client instance.

Input Parameters

Return Values

Allowed From

Threads

Example

status = nx_ptp_client_stop(&ptp_client);

/* If the client was successfully stopped, status = NX_SUCCESS. */

nx_ptp_client_sync_info_get

Get Sync information.

Prototype

UINT nx_ptp_client_sync_info_get(
    NX_PTP_CLIENT_SYNC *sync_ptr, 
    USHORT *flags, 
    SHORT *utc_offset);

Description

This service gets information of Sync message. The Sync control block is passed to user application through event callback function.

Input Parameters

Return Values

Allowed From

Threads

Example

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. */
    }
}

nx_ptp_client_time_get

Get current time.

Prototype

UINT nx_ptp_client_time_get(
    NX_PTP_CLIENT *client_ptr, 
    NX_PTP_TIME *time_ptr);

Description

This service gets the current value of the PTP clock. It is available no matter PTP client is synchronized with master clock or not.

Input Parameters

Return Values

Allowed From

Threads

Example

/* Get the PTP clock */
nx_ptp_client_time_get(&ptp_client, &tm);

nx_ptp_client_time_set

Set current time.

Prototype

UINT nx_ptp_client_time_set(
    NX_PTP_CLIENT *client_ptr, 
    NX_PTP_TIME *time_ptr);

Description

This service sets the current value of the PTP clock. It must be invoked before PTP client starts.

Input Parameters

Return Values

Allowed From

Threads

Example

/* Set current time before PTP client started.  */
status = nx_ptp_client_time_set(&ptp_client, &tm);

nx_ptp_client_utility_convert_time_to_date

Convert PTP time to a UTC date and time.

Prototype

UINT nx_ptp_client_utility_convert_time_to_date(
    NX_PTP_TIME *time_ptr, 
    LONG offset, 
    NX_PTP_DATE_TIME *date_time_ptr);

Description

This service converts PTP time to a UTC date and time.

Input Parameters

Return Values

Allowed From

Threads

Example

/* 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. */

nx_ptp_client_utility_time_diff

Diff two PTP times.

Prototype

UINT nx_ptp_client_utility_time_diff(
    NX_PTP_TIME *time1_ptr, 
    NX_PTP_TIME *time2_ptr, 
    NX_PTP_TIME *result_ptr);

Description

This service computes the difference between two PTP times.

Input Parameters

Return Values

Allowed From

Threads

Example

/* Diff time.  */
status = nx_ptp_client_utility_time_diff(&time1, &time2, &result);

/* If the calculation was successfully, status = NX_SUCCESS. */