Compare commits

...

4 commits

Author SHA1 Message Date
Xiretza bad48d0e9b vhdl: workaround ghdl#2080
https://github.com/ghdl/ghdl/issues/2080
2022-06-06 18:16:31 +02:00
Xiretza dc31375b55 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.
2022-06-06 18:13:21 +02:00
Xiretza 4bced13726 vhdl: implement magic number on receive 2022-06-06 17:11:39 +02:00
Xiretza 904f34f4d4 vhdl: implement frame number checking 2022-06-06 16:45:16 +02:00
2 changed files with 74 additions and 31 deletions

View file

@ -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'
@ -190,7 +192,13 @@ architecture a of arty_a7 is
signal sys_reset : std_logic;
signal frame_done : std_logic;
signal frame_number : unsigned(31 downto 0);
signal prev_frame_number : unsigned(31 downto 0);
-- little-endian pixel sink data
signal pixel_sink_data_le : std_logic_vector(31 downto 0);
-- big-endian pixel source data
signal pixel_source_data_be : std_logic_vector(31 downto 0);
begin
leds_simple <= (others => '0');
led0 <= (others => '0');
@ -241,7 +249,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 => pixel_sink_data_le,
-- source
pixel_source_src_ip_address => pixel_source_src_ip_address,
@ -254,6 +262,7 @@ begin
pixel_source_ready => '1',
pixel_source_data => pixel_source_data
);
pixel_sink_data_le <= flip_endianness(pixel_sink_data);
-- 800 MHz VCO
-- 80 MHz system clock
@ -299,27 +308,28 @@ begin
pmod_d <= drivers(23 downto 16);
sender: process(sys_clk)
variable frame_counter : unsigned(31 downto 0);
begin
if sys_reset then
frame_counter := (others => '0');
elsif rising_edge(sys_clk) then
if pixel_source_valid then
remote_ip_address <= pixel_source_src_ip_address;
remote_port <= pixel_source_src_port;
end if;
if rising_edge(sys_clk) then
if sys_reset then
prev_frame_number <= frame_number;
else
if pixel_source_valid then
remote_ip_address <= pixel_source_src_ip_address;
remote_port <= pixel_source_src_port;
end if;
if frame_done then
pixel_sink_length <= x"0004";
pixel_sink_data <= std_logic_vector(frame_counter);
pixel_sink_valid <= '1';
pixel_sink_last <= '1';
if frame_number /= prev_frame_number then
prev_frame_number <= frame_number;
frame_counter := frame_counter + 1;
end if;
pixel_sink_length <= x"0004";
pixel_sink_data <= std_logic_vector(frame_number);
pixel_sink_valid <= '1';
pixel_sink_last <= '1';
end if;
if pixel_sink_ready and pixel_sink_valid then
pixel_sink_valid <= '0';
if pixel_sink_ready and pixel_sink_valid then
pixel_sink_valid <= '0';
end if;
end if;
end if;
end process;
@ -335,10 +345,11 @@ begin
udp_valid => pixel_source_valid,
udp_last => pixel_source_last,
udp_data => pixel_source_data,
udp_data => pixel_source_data_be,
frame_done => frame_done,
frame_number => frame_number,
drivers => drivers
);
pixel_source_data_be <= flip_endianness(pixel_source_data);
end architecture;

View file

@ -15,7 +15,7 @@ entity splink is
udp_last : in std_logic;
udp_data : in std_logic_vector(31 downto 0);
frame_done : out std_logic;
frame_number : out unsigned(31 downto 0);
drivers : out std_logic_vector(NUM_STRANDS-1 downto 0)
);
@ -37,10 +37,19 @@ architecture a of splink is
signal active_strand: natural range 0 to NUM_STRANDS-1;
signal num_pixels: natural range 1 to MAX_STRAND_LEN;
signal frame_number: unsigned(31 downto 0);
signal current_frame: unsigned(31 downto 0);
signal pixels_received: natural range 0 to MAX_STRAND_LEN-1;
type receive_state_t is (FRAME_NUM, STRAND_NUM, DATA, DROP);
signal clear_write_flags : std_logic;
signal all_strands_written : std_logic;
signal some_strands_written : std_logic;
-- "PIXL"
constant MAGIC_NUMBER : std_logic_vector(31 downto 0) := x"5049584c";
type receive_state_t is (MAGIC, FRAME_NUM, STRAND_NUM, DATA, DROP);
constant RESET_STATE : receive_state_t := MAGIC;
signal receive_state : receive_state_t;
begin
driver_gen: for i in 0 to NUM_STRANDS-1 generate
@ -85,7 +94,7 @@ begin
end if;
end if;
if frame_done then
if clear_write_flags then
led_data_arr(i).was_written <= '0';
end if;
end if;
@ -94,11 +103,14 @@ begin
process(led_data_arr)
begin
frame_done <= '1';
all_strands_written <= '1';
some_strands_written <= '0';
for i in 0 to NUM_STRANDS-1 loop
if not led_data_arr(i).was_written then
frame_done <= '0';
if led_data_arr(i).was_written then
some_strands_written <= '1';
else
all_strands_written <= '0';
end if;
end loop;
end process;
@ -106,15 +118,30 @@ begin
fsm: process(clk)
begin
if rising_edge(clk) then
clear_write_flags <= '0';
if all_strands_written then
frame_number <= current_frame;
clear_write_flags <= '1';
end if;
if reset then
receive_state <= STRAND_NUM;
clear_write_flags <= '1';
receive_state <= RESET_STATE;
elsif udp_valid then
if udp_last then
-- always resynchronize to start of packet
receive_state <= STRAND_NUM;
receive_state <= RESET_STATE;
end if;
case receive_state is
when MAGIC =>
if udp_data = MAGIC_NUMBER then
receive_state <= STRAND_NUM;
else
receive_state <= DROP;
end if;
when STRAND_NUM =>
-- TODO udp_length, range check with MAX_STRAND_LEN
num_pixels <= MAX_STRAND_LEN;
@ -125,7 +152,12 @@ begin
receive_state <= FRAME_NUM;
when FRAME_NUM =>
frame_number <= unsigned(udp_data);
if not some_strands_written then
current_frame <= unsigned(udp_data);
elsif current_frame /= unsigned(udp_data) then
current_frame <= unsigned(udp_data);
clear_write_flags <= '1';
end if;
pixels_received <= 0;
receive_state <= DATA;