Network Wizard for VHDL Test Benches
PTP Library

IEEE1588v2

The PTP library provides functions for creating and manipulating IEEE1588v2 packets.

Functionality

  • Create PTPv2 messages
  • Extract PTPv2 messages


More details in nw_ptpv2_pkg

Example use

Include the libraries:

library nw_util;
context nw_util.nw_util_context;
library nw_ptp;
use nw_ptp.nw_ptpv2.all;
library ne_ethernet;
context nw_ethernet.nw_ethernet_context;

In many other NetWiz protocols a packet consists of a header and a payload. The PTP packet (or message) is contained completely in a record.

variable v_msg : t_ptpv2_msg; -- message record
variable v_len : natural;
variable v_pkt : t_slv_arr(0 to 127)(7 downto 0);

Example 1: Create a Sync message in an Ethernet packet.

v_msg := C_DEFAULT_PTPV2_MSG; -- copy default msg
v_msg.header.message_type := C_MSG_SYNC; -- Sync message
v_msg.header.sequence_id := x"1234"; -- Sequence ID
v_msg.origin_timestamp.seconds := x"0000511003fc"; -- seconds
v_msg.origin_timestamp.nanoseconds := x"0188fa34";-- nanoseconds
-- PTP message record is ready, now setup Ethernet header
v_eth_header := C_DEFAULT_ETH_HEADER;
v_eth_header.mac_dest := f_eth_mac_2_slv_arr("01:1b:19:00:00:00"); -- IEEE1588 broadcast MAC
v_eth_header.ethertype := C_ET_PTP; -- PTP over Ethernet
-- Create Ethernet packet with Sync message
v_len := f_eth_create_pkt_len(v_eth_header, f_ptpv2_create_pkt(v_msg)); -- get length of packet
v_pkt(0 to v_len -1) := f_eth_create_pkt(v_eth_header, f_ptpv2_create_pkt(v_msg)); -- v_pkt now holds Ethernet+Sync

See further examples in the test bench nw_ptp_tb.vhd.