From 3c5c3a4555c5b8405e8d441d8ecab6187ba52c33 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 6 Jun 2022 18:13:21 +0200 Subject: [PATCH] vhdl: use big-endian network byte order liteeth splits the rx data stream into 4-byte chunks and interprets them as little-endian 32-bit vecs; similar for the other direction. --- vhdl/arty_a7.vhdl | 6 ++++-- vhdl/util.vhdl | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 vhdl/util.vhdl diff --git a/vhdl/arty_a7.vhdl b/vhdl/arty_a7.vhdl index e08b9cf..9084462 100644 --- a/vhdl/arty_a7.vhdl +++ b/vhdl/arty_a7.vhdl @@ -2,6 +2,8 @@ library ieee; use ieee.std_logic_1164.all, ieee.numeric_std.all; +use work.util.flip_endianness; + entity arty_a7 is generic ( IS_SIMULATION : std_logic := '0' @@ -242,7 +244,7 @@ begin pixel_sink_last => pixel_sink_last, pixel_sink_last_be => pixel_sink_last_be, pixel_sink_ready => pixel_sink_ready, - pixel_sink_data => pixel_sink_data, + pixel_sink_data => flip_endianness(pixel_sink_data), -- source pixel_source_src_ip_address => pixel_source_src_ip_address, @@ -337,7 +339,7 @@ begin udp_valid => pixel_source_valid, udp_last => pixel_source_last, - udp_data => pixel_source_data, + udp_data => flip_endianness(pixel_source_data), frame_number => frame_number, diff --git a/vhdl/util.vhdl b/vhdl/util.vhdl new file mode 100644 index 0000000..67933b7 --- /dev/null +++ b/vhdl/util.vhdl @@ -0,0 +1,23 @@ +library ieee; +use ieee.std_logic_1164.all; + +package util is + function flip_endianness(val : in std_logic_vector) return std_logic_vector; +end package; + +package body util is + function flip_endianness(val : in std_logic_vector) return std_logic_vector is + constant BYTES : natural := val'length / 8; + variable ret : std_logic_vector(val'length-1 downto 0); + begin + assert val'length mod 8 = 0 + report "length of vector not a multiple of 8" + severity failure; + + for i in 0 to BYTES-1 loop + ret((BYTES-i)*8 - 1 downto (BYTES-i-1) * 8) := val((i+1)*8 - 1 downto i*8); + end loop; + + return ret; + end function; +end package body;