1 #ifndef TEST_UTILITY_H 2 #define TEST_UTILITY_H 3 4 #include "nxd_ptp_client.h" 5 6 void test_control_return(UINT status); 7 8 #ifdef DEBUG 9 #define DBGPRINTF(...) printf(##__VA_ARGS__) 10 #else 11 #define DBGPRINTF(...) 12 #endif 13 14 #define ASSERT_DEBUG(c) printf("\n[%s:%d]Assert fail: %s\n", __FILE__, __LINE__, (c)); 15 #define ASSERT_TRUE(p) {if (!(p)) {ASSERT_DEBUG(#p);test_control_return(1);}} 16 #define ASSERT_SUCCESS(v) ASSERT_TRUE((v) == 0) 17 18 /* Define the UDP ports */ 19 #define PTP_EVENT_UDP_PORT 319 20 #define PTP_GENERAL_UDP_PORT 320 21 22 /* Define the IPv4 multicast address "224.0.1.129" */ 23 #define PTP_IPV4_MULTICAST_ADDR IP_ADDRESS(224,0,1,129) 24 25 /* Define the IPv6 multicast address "ff0e::181" */ 26 #define PTP_IPV6_MULTICAST_ADDR_SET(x) { \ 27 (x) -> nxd_ip_version = NX_IP_VERSION_V6; \ 28 (x) -> nxd_ip_address.v6[0] = 0xff0e0000UL; \ 29 (x) -> nxd_ip_address.v6[1] = 0; \ 30 (x) -> nxd_ip_address.v6[2] = 0; \ 31 (x) -> nxd_ip_address.v6[3] = 0x181; } 32 33 typedef struct 34 { 35 36 /* Timestamp from master. */ 37 NX_PTP_TIME sync; 38 NX_PTP_TIME follow_up; 39 NX_PTP_TIME delay_response; 40 41 /* Timestamp from client. */ 42 NX_PTP_TIME sync_received; 43 NX_PTP_TIME delay_request; 44 } TEST_TIMESTAMP; 45 46 typedef struct 47 { 48 UCHAR clock_id[NX_PTP_CLOCK_PORT_IDENTITY_SIZE]; 49 UCHAR sequence_id[2]; 50 } DELAY_REQUEST_CONTEXT; 51 52 53 VOID create_socket(NX_IP *ip_ptr, NX_UDP_SOCKET *socket_ptr, UINT port); 54 VOID send_announce(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, USHORT utc_offset); 55 VOID send_sync(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, NX_PTP_TIME *ts); 56 VOID send_follow_up(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, NX_PTP_TIME *ts); 57 VOID send_delay_response(NX_UDP_SOCKET *socket_ptr, NX_PACKET_POOL *pool_ptr, 58 DELAY_REQUEST_CONTEXT *context, NX_PTP_TIME *ts); 59 UINT receive_delay_request(NX_UDP_SOCKET *socket_ptr, DELAY_REQUEST_CONTEXT *context, 60 UINT wait_option); 61 VOID set_two_steps(UCHAR two_steps); 62 VOID set_clock_id(UCHAR *clock_id); 63 VOID set_ip_version(UCHAR ip_version); 64 VOID calibrate_timestamp(TEST_TIMESTAMP *test_ts, NX_PTP_TIME *ts); 65 VOID _netx_ptp_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req); 66 UINT _netx_ptp_clock_callback(NX_PTP_CLIENT *client_ptr, UINT operation, 67 NX_PTP_TIME *time_ptr, NX_PACKET *packet_ptr, 68 VOID *callback_data); 69 70 #endif /* TEST_UTILITY_H */