summaryrefslogtreecommitdiff
path: root/test/regression/ptp_test/netx_ptp_utility.h
blob: 15b44fc35b837c7ce35f5a55a72085bb85a5c878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

#ifndef TEST_UTILITY_H
#define TEST_UTILITY_H

#include "nxd_ptp_client.h"

void test_control_return(UINT status);

#ifdef DEBUG
#define DBGPRINTF(...)  printf(##__VA_ARGS__)
#else
#define DBGPRINTF(...)
#endif

#define ASSERT_DEBUG(c) printf("\n[%s:%d]Assert fail: %s\n", __FILE__, __LINE__, (c));
#define ASSERT_TRUE(p) {if (!(p)) {ASSERT_DEBUG(#p);test_control_return(1);}}
#define ASSERT_SUCCESS(v) ASSERT_TRUE((v) == 0)

/* Define the UDP ports */
#define PTP_EVENT_UDP_PORT          319
#define PTP_GENERAL_UDP_PORT        320

/* Define the IPv4 multicast address "224.0.1.129" */
#define PTP_IPV4_MULTICAST_ADDR     IP_ADDRESS(224,0,1,129)

/* Define the IPv6 multicast address "ff0e::181" */
#define PTP_IPV6_MULTICAST_ADDR_SET(x)  {           \
        (x) -> nxd_ip_version = NX_IP_VERSION_V6;   \
        (x) -> nxd_ip_address.v6[0] = 0xff0e0000UL; \
        (x) -> nxd_ip_address.v6[1] = 0;            \
        (x) -> nxd_ip_address.v6[2] = 0;            \
        (x) -> nxd_ip_address.v6[3] = 0x181; }

typedef struct
{

    /* Timestamp from master.  */
    NX_PTP_TIME sync;
    NX_PTP_TIME follow_up;
    NX_PTP_TIME delay_response;

    /* Timestamp from client.  */
    NX_PTP_TIME sync_received;
    NX_PTP_TIME delay_request;
} TEST_TIMESTAMP;

typedef struct
{
    UCHAR clock_id[NX_PTP_CLOCK_PORT_IDENTITY_SIZE];
    UCHAR sequence_id[2];
} DELAY_REQUEST_CONTEXT;


VOID create_socket(NX_IP *ip_ptr, NX_UDP_SOCKET *socket_ptr, UINT port);
VOID send_announce(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, USHORT utc_offset);
VOID send_sync(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, NX_PTP_TIME *ts);
VOID send_follow_up(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, NX_PTP_TIME *ts);
VOID send_delay_response(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr,
                         DELAY_REQUEST_CONTEXT *context, NX_PTP_TIME *ts);
UINT receive_delay_request(NX_UDP_SOCKET *socket_ptr, DELAY_REQUEST_CONTEXT *context,
                           UINT wait_option);
VOID set_two_steps(UCHAR two_steps);
VOID set_clock_id(UCHAR *clock_id);
VOID set_ip_version(UCHAR ip_version);
VOID calibrate_timestamp(TEST_TIMESTAMP *test_ts, NX_PTP_TIME *ts);
VOID _netx_ptp_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
UINT _netx_ptp_clock_callback(NX_PTP_CLIENT *client_ptr, UINT operation,
                              NX_PTP_TIME *time_ptr, NX_PACKET *packet_ptr,
                              VOID *callback_data);

#endif /* TEST_UTILITY_H */