From 3a42c865c6a97ddf6463a7455829915ccfc86df8 Mon Sep 17 00:00:00 2001 From: Markus Perkins Date: Tue, 7 Oct 2025 13:58:41 +0200 Subject: [PATCH] udpprot: Add round-robin scheduler --- trashernet/trashernet_udpprot.vhd | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/trashernet/trashernet_udpprot.vhd b/trashernet/trashernet_udpprot.vhd index 43d4cf6..a4790ea 100644 --- a/trashernet/trashernet_udpprot.vhd +++ b/trashernet/trashernet_udpprot.vhd @@ -16,6 +16,9 @@ use ieee.numeric_std.all; use work.trashernet_pkg.all; entity trashernet_udpprot is + generic( + ROUND_ROBIN : boolean := true -- Prioritize, but prevent one channel from hogging all bandwidth (may add one cycle of latency between frames) + ); port( -- Global clk : in std_logic; -- Global clock @@ -98,8 +101,9 @@ begin elsif rising_edge(clk) then case state is when IDLE => + tx_sel <= udpprot_tx_out'left; for i in udpprot_tx_in'range loop - if udpprot_tx_in(i).tx_en then + if (udpprot_tx_in(i).tx_en = '1') and (i >= tx_sel) then tx_sel <= i; state <= TXD; exit; -- Prioritize according to vector @@ -111,8 +115,12 @@ begin when WAITDONE => if udp_out.tx_err_stb or udp_out.tx_ok_stb then - state <= IDLE; - tx_sel <= udpprot_tx_in'left; -- To avoid arbitration errors, always select the highest priority one by default + state <= IDLE; + if (not ROUND_ROBIN) or (tx_sel = udpprot_tx_out'high) then + tx_sel <= udpprot_tx_out'left; + else + tx_sel <= tx_sel + 1; + end if; end if; end case; end if;