Skip to content

Commit

Permalink
Added instructions on using UDP interface
Browse files Browse the repository at this point in the history
Added "our_gateway" to the top level
  • Loading branch information
hamsternz committed Jun 13, 2016
1 parent 640572e commit 1316977
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
58 changes: 58 additions & 0 deletions Using the UDP interface.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Here's how to use the UDP interface.

General setup
=============
In the top level design, set the MAC address, IP address, netmask and gateway:

Here is an example for a MAC & IP setup (for 10.0.0.10/24, gw 10.0.0.254
)
-- NOTE this is 02:23:45:67:89:AB
constant our_mac : std_logic_vector(47 downto 0) := x"AB_89_67_45_23_02";
-- NOTE octets are reversed
constant our_ip : std_logic_vector(31 downto 0) := x"0A_00_00_0A";
constant our_netmask : std_logic_vector(31 downto 0) := x"00_FF_FF_FF";
constant our_gateway : std_logic_vector(31 downto 0) := x"FE_00_00_0A";

Transmitting UDP packets
========================
(see example in hdl/udp/udp_test_source.vhd)
0. (not yet written) Resolve the target IP address into a MAC address using
the ARP resolver.

1. Wait until 'udp_tx_busy' is zero

2. Provide the target MAC, source and destination ports and destination IP address,
and first byte of data to the udp_tx interface, and assert udp_tx_valid.

Here is an example, of broadcasting to 10.0.0.255. Note the ordering of the
octets in the IP address:

udp_tx_valid <= '1';
udp_tx_src_port <= std_logic_vector(to_unsigned(4660,16));
udp_tx_dst_mac <= x"FF_FF_FF_FF_FF_FF";
udp_tx_dst_ip <= x"FF_00_00_0A";
udp_tx_dst_port <= std_logic_vector(to_unsigned(9029,16));
udp_tx_data <= x"FF";

3. Provide additional data bytes on contiguious cycles. When udp_tx_valid drops it is
considered the end of the packet. Do not send more than 1472 bytes at a time.

4. Go back to step 1 to send the next packet.

Receiving UDP packets
=====================
(see example in hdl/udp/udp_test_sink.vhd)

1. Wait for 'udp_rx_valid' to be asserted.

2. Check for your desired UDP port number on 'udp_rx_dst_port'

2. Data will be on 'udp_rx_data' while 'udp_rx_valid' is asserted.

Here is an example, of recieving on port 4660.

if udp_rx_valid = '1' then
if udp_rx_dst_port = std_logic_vector(to_unsigned(4660, 16)) then
leds <= udp_rx_data;
end if;
end if;
2 changes: 2 additions & 0 deletions hdl/FPGA_webserver.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ architecture Behavioral of FPGA_webserver is
constant our_mac : std_logic_vector(47 downto 0) := x"AB_89_67_45_23_02"; -- NOTE this is 02:23:45:67:89:AB
constant our_ip : std_logic_vector(31 downto 0) := x"0A_00_00_0A"; -- NOTE octets are reversed
constant our_netmask : std_logic_vector(31 downto 0) := x"00_FF_FF_FF"; -- NOTE octets are reversed
constant our_gateway : std_logic_vector(31 downto 0) := x"FE_00_00_0A"; -- NOTE octets are reversed

signal phy_ready : std_logic := '0';
-----------------------------
-- For the clocking
Expand Down
4 changes: 2 additions & 2 deletions hdl/udp/udp_test_source.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ process(clk)
udp_tx_data <= std_logic_vector(data_count);

data_count <= data_count + 1;
if data_count = 31 then
state <= waiting; -- sending as fast as possible.
if data_count = 2 then
state <= waiting;
end if;
when others =>
state <= waiting;
Expand Down

0 comments on commit 1316977

Please sign in to comment.