- added command fifo for xfer unit

- completed first version of receiver
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/


git-svn-id: http://moon:8086/svn/vhdl/trunk@811 cc03376c-175c-47c8-b038-4cd826a8556b
This commit is contained in:
2010-03-23 11:34:28 +00:00
parent c3c2cdfe2b
commit cd285df8e8
5 changed files with 558 additions and 173 deletions
+92 -99
View File
@@ -33,20 +33,25 @@ ARCHITECTURE behavior OF emac_tx IS
subtype word_ptr_t is unsigned(RAM_ADDR_WIDTH-1 downto 0);
signal fifo_din : unsigned(35 downto 0);
signal fifo_dout : unsigned(35 downto 0);
signal fifo_we : std_logic;
signal fifo_re : std_logic;
signal fifo_empty : std_logic;
signal fifo_full : std_logic;
signal mii_fifo_din : unsigned(35 downto 0);
signal mii_fifo_dout : unsigned(35 downto 0);
signal mii_fifo_we : std_logic;
signal mii_fifo_re : std_logic;
signal mii_fifo_empty : std_logic;
signal mii_fifo_full : std_logic;
signal cmd_fifo_din : unsigned(35 downto 0);
signal cmd_fifo_dout : unsigned(35 downto 0);
signal cmd_fifo_we : std_logic;
signal cmd_fifo_re : std_logic;
signal cmd_fifo_empty : std_logic;
signal cmd_fifo_full : std_logic;
signal flush_en : std_logic;
signal flush_rdy : std_logic;
signal flush_ptr_set : std_logic;
signal flush_ptr : word_ptr_t;
signal alloc_req_size : unsigned(15 downto 0);
signal fill_base : word_ptr_t;
signal fill_size : word_ptr_t;
signal fill_cnt : word_ptr_t;
signal fill_ptr : word_ptr_t;
@@ -62,7 +67,6 @@ ARCHITECTURE behavior OF emac_tx IS
signal alloc_ack : std_logic;
signal nwords_free : word_ptr_t;
signal alloc_base : word_ptr_t;
signal alloc_size : word_ptr_t;
signal alloc_en : std_logic;
@@ -86,13 +90,13 @@ ARCHITECTURE behavior OF emac_tx IS
signal ram_en_a : std_logic;
signal ram_we_a : std_logic;
signal ram_addr_a : word_ptr_t;
signal ram_din_a : unsigned(35 downto 0);
signal ram_dout_a : unsigned(35 downto 0);
signal ram_din_a : unsigned(31 downto 0);
signal ram_dout_a : unsigned(31 downto 0);
signal ram_en_b : std_logic;
signal ram_we_b : std_logic;
signal ram_addr_b : word_ptr_t;
signal ram_din_b : unsigned(35 downto 0);
signal ram_dout_b : unsigned(35 downto 0);
signal ram_din_b : unsigned(31 downto 0);
signal ram_dout_b : unsigned(31 downto 0);
signal piso_din_be : unsigned(3 downto 0);
signal piso_din_rdy : std_logic;
@@ -102,16 +106,6 @@ ARCHITECTURE behavior OF emac_tx IS
signal inter_frame_gap_cnt : inter_frame_gap_cnt_t;
signal inter_frame_gap_rdy : std_logic;
alias ram_data_in_a is ram_din_a(31 downto 0);
alias ram_tag_in_a is ram_din_a(35 downto 32);
alias ram_data_out_a is ram_dout_a(31 downto 0);
alias ram_tag_out_a is ram_dout_a(35 downto 32);
alias ram_data_in_b is ram_din_b(31 downto 0);
alias ram_tag_in_b is ram_din_b(35 downto 32);
alias ram_data_out_b is ram_dout_b(31 downto 0);
alias ram_tag_out_b is ram_dout_b(35 downto 32);
type host_state_t is (host_init, host_flush, host_idle, host_alloc, host_setup, host_arm, host_fill, host_commit);
signal host_s, host_sn : host_state_t;
@@ -130,28 +124,30 @@ ARCHITECTURE behavior OF emac_tx IS
begin
ctrl_out.alloc_req <= alloc_req;
ctrl_out.tx_req <= alloc_req;
mii_tx_er <= ctrl_in.tx_er;
ram_tag_in_b <= "0000";
ram_en_b <= not fifo_full or uncommit_en or flush_en;
ram_we_b <= uncommit_en or flush_en;
ram_addr_b <= flush_ptr when (flush_en = '1' or uncommit_en = '1') else xfer_ptr;
xfer_tag <= ram_tag_out_b;
ram_en_a <= '1';
ram_we_a <= commit_en or fill_cnt_adv;
ram_tag_in_a <= fill_remain & "01" when commit_en = '1' else "0000";
ram_data_in_a <= resize(fill_size, 16) & resize(alloc_base, 16) when commit_en = '1' else din;
ram_addr_a <= alloc_base when commit_en = '1' else fill_ptr;
ram_we_a <= fill_ptr_adv;
ram_din_a <= din;
ram_addr_a <= fill_ptr;
piso_din_be <= (others => '1');
fifo_re <= piso_din_rdy;
data_vld <= not fifo_empty;
mii_fifo_re <= piso_din_rdy;
data_vld <= not mii_fifo_empty;
fifo_din(35 downto 32) <= piso_byte_mask_rom(to_integer(xfer_remain)) when xfer_remain_en = '1' else "1111";
fifo_din(31 downto 0) <= ram_data_out_b;
mii_fifo_din(35 downto 32) <= piso_byte_mask_rom(to_integer(xfer_remain)) when xfer_remain_en = '1' else "1111";
mii_fifo_din(31 downto 0) <= ram_dout_b;
cmd_fifo_we <= commit_en;
cmd_fifo_re <= uncommit_en;
cmd_fifo_din <= fill_remain & "01" & resize(fill_size, 16) & resize(fill_base, 16);
ram_en_b <= not mii_fifo_full or uncommit_en;
ram_we_b <= '0';
ram_addr_b <= xfer_ptr;
xfer_tag <= cmd_fifo_dout(35 downto 32);
------------------------------------------------------------------
host_state_next:
@@ -167,17 +163,16 @@ host_state_next:
end process;
host_state:
process(host_s, flush_rdy, alloc_req, alloc_OK, fill_rdy, ctrl_in.data_vld)
process(host_s, alloc_req, alloc_OK, fill_rdy, ctrl_in.data_vld)
begin
flush_en <= '0';
flush_ptr_set <= '0';
alloc_ack <= '0';
fill_cnt_set <= '0';
fill_cnt_adv <= '0';
fill_ptr_set <= '0';
fill_ptr_adv <= '0';
commit_en <= '0';
alloc_ack <= '0';
alloc_en <= '0';
host_sn <= host_s;
@@ -185,15 +180,12 @@ host_state:
case host_s is
when host_init =>
flush_ptr_set <= '1';
flush_en <= '1';
host_sn <= host_flush;
when host_flush =>
flush_en <= '1';
if flush_rdy = '1' then
flush_en <= '0';
host_sn <= host_idle;
end if;
host_sn <= host_idle;
when host_idle =>
if alloc_req = '1' then
@@ -212,7 +204,6 @@ host_state:
host_sn <= host_arm;
when host_arm =>
fill_ptr_adv <= '1';
fill_cnt_adv <= '1';
host_sn <= host_fill;
@@ -243,7 +234,7 @@ alloc_req_size_register:
process(clk)
begin
if rising_edge(clk) then
if ctrl_in.alloc_req_size_vld = '1' then
if ctrl_in.tx_size_vld = '1' then
alloc_req_size <= din(15 downto 0);
end if;
end if;
@@ -256,14 +247,14 @@ alloc_request_logic:
if rising_edge(clk) then
if rst = '1' then
alloc_req <= '0';
elsif ctrl_in.alloc_req_en = '1' and alloc_req = '0' then
elsif ctrl_in.tx_req_en = '1' and alloc_req = '0' then
alloc_req <= '1';
fill_remain <= alloc_req_size(1 downto 0);
fill_size <= alloc_req_size(word_ptr_t'left+2 downto 2);
if din(1 downto 0) /= "00" then
fill_size <= alloc_req_size(word_ptr_t'left+2 downto 2) + 1;
end if;
ctrl_out.alloc_req_size <= resize(alloc_req_size(word_ptr_t'left downto 0), 16);
ctrl_out.tx_size <= resize(alloc_req_size(word_ptr_t'left downto 0), 16);
elsif alloc_ack = '1' then
alloc_req <= '0';
@@ -273,14 +264,14 @@ alloc_request_logic:
end process;
------------------------------------------------------------------
alloc_base_logic:
fill_base_logic:
process(clk)
begin
if rising_edge(clk) then
if flush_en = '1' then
alloc_base <= (others => '0');
fill_base <= (others => '0');
elsif commit_en = '1' then
alloc_base <= fill_ptr;
fill_base <= fill_ptr;
end if;
end if;
end process;
@@ -314,26 +305,6 @@ nwords_free_counter:
end if;
end process;
------------------------------------------------------------------
flush_counter:
process(clk)
begin
if rising_edge(clk) then
if flush_en = '0' then
flush_rdy <= '0';
if flush_ptr_set = '1' then
flush_ptr <= (others => '1');
elsif xfer_ptr_set = '1' then
flush_ptr <= ram_data_out_b(flush_ptr'left downto 0);
end if;
elsif flush_ptr /= 0 then
flush_ptr <= flush_ptr - 1;
else
flush_rdy <= '1';
end if;
end if;
end process;
------------------------------------------------------------------
-- Fill stuff
------------------------------------------------------------------
@@ -359,7 +330,7 @@ fill_pointer:
begin
if rising_edge(clk) then
if fill_ptr_set = '1' then
fill_ptr <= alloc_base;
fill_ptr <= fill_base;
elsif fill_ptr_adv = '1' then
fill_ptr <= fill_ptr + 1;
end if;
@@ -382,7 +353,7 @@ xfer_state_next:
end process;
xfer_state:
process(xfer_s, xfer_tag, xfer_odd, xfer_rdy, inter_frame_gap_rdy, alloc_en, fifo_full)
process(xfer_s, cmd_fifo_empty, xfer_odd, xfer_rdy, inter_frame_gap_rdy, alloc_en, mii_fifo_full)
begin
xfer_cnt_set <= '0';
@@ -390,7 +361,7 @@ xfer_state:
xfer_ptr_set <= '0';
xfer_ptr_adv <= '0';
xfer_remain_en <= '0';
fifo_we <= '0';
mii_fifo_we <= '0';
free_en <= '0';
uncommit_en <= '0';
@@ -402,7 +373,7 @@ xfer_state:
xfer_sn <= xfer_idle;
when xfer_idle =>
if xfer_tag(0) = '1' then
if cmd_fifo_empty = '0' then
xfer_ptr_set <= '1';
xfer_cnt_set <= '1';
xfer_sn <= xfer_wait;
@@ -411,25 +382,23 @@ xfer_state:
when xfer_wait =>
if inter_frame_gap_rdy = '1' then
xfer_sn <= xfer_setup;
xfer_ptr_adv <= '1';
xfer_cnt_adv <= '1';
uncommit_en <= '1';
end if;
when xfer_setup =>
xfer_ptr_adv <= '1';
xfer_cnt_adv <= '1';
xfer_ptr_adv <= '1';
xfer_sn <= xfer_active;
when xfer_active =>
fifo_we <= '1';
xfer_cnt_adv <= not fifo_full;
xfer_ptr_adv <= not fifo_full;
mii_fifo_we <= '1';
xfer_cnt_adv <= not mii_fifo_full;
xfer_ptr_adv <= not mii_fifo_full;
if xfer_rdy = '1' then
xfer_remain_en <= xfer_odd;
xfer_cnt_adv <= '0';
xfer_ptr_adv <= '0';
if fifo_full = '0' then
if mii_fifo_full = '0' then
xfer_sn <= xfer_free;
end if;
end if;
@@ -437,6 +406,7 @@ xfer_state:
when xfer_free =>
free_en <= not alloc_en;
if alloc_en = '0' then
uncommit_en <= '1';
xfer_sn <= xfer_idle;
end if;
@@ -453,7 +423,7 @@ interframe_gap_counter:
if rising_edge(clk) then
if flush_en = '1' then
inter_frame_gap_rdy <= '1';
elsif fifo_empty = '0' then
elsif mii_fifo_empty = '0' then
inter_frame_gap_rdy <= '0';
inter_frame_gap_cnt <= inter_frame_gap_cnt_t'high;
elsif inter_frame_gap_cnt /= 0 then
@@ -472,7 +442,7 @@ xfer_counter:
if xfer_cnt_set = '1' then
xfer_size <= (others => '0');
xfer_rdy <= '0';
xfer_cnt <= ram_data_out_b(xfer_ptr'left+16 downto 16);
xfer_cnt <= cmd_fifo_dout(xfer_ptr'left+16 downto 16);
elsif xfer_cnt_adv = '1' then
if xfer_cnt /= 0 then
xfer_cnt <= xfer_cnt - 1;
@@ -490,7 +460,7 @@ xfer_pointer:
begin
if rising_edge(clk) then
if xfer_ptr_set = '1' then
xfer_ptr <= ram_data_out_b(xfer_ptr'left downto 0);
xfer_ptr <= cmd_fifo_dout(xfer_ptr'left downto 0);
xfer_remain <= xfer_tag(3 downto 2);
xfer_odd <= '0';
if xfer_tag(3 downto 2) /= "00" then
@@ -503,11 +473,12 @@ xfer_pointer:
end process;
------------------------------------------------------------------
inst_ram : entity work.dpram_2w2r
GENERIC MAP
(
addr_width => RAM_ADDR_WIDTH,
data_width => 36
data_width => 32
)
PORT MAP
(
@@ -526,11 +497,33 @@ inst_ram : entity work.dpram_2w2r
);
-- Instantiate synchronous FIFO
inst_fifo: entity work.fifo_async
inst_cmd_fifo: entity work.fifo_sync
GENERIC MAP
(
addr_width => NextExpBaseTwo(RAM_SIZE) - 4, -- RAMSIZE(words)/MIN_PACKET_LEN(words)
data_width => cmd_fifo_din'length,
do_last_read_update => true
)
PORT MAP
(
rst => flush_en,
clk => clk,
we => cmd_fifo_we,
re => cmd_fifo_re,
fifo_full => cmd_fifo_full,
fifo_empty => cmd_fifo_empty,
fifo_afull => open,
fifo_aempty => open,
data_w => cmd_fifo_din,
data_r => cmd_fifo_dout
);
-- Instantiate synchronous FIFO
inst_mii_fifo: entity work.fifo_async
GENERIC MAP
(
addr_width => 4,
data_width => 36,
data_width => mii_fifo_din'length,
do_last_read_update => true
)
PORT MAP
@@ -538,14 +531,14 @@ inst_fifo: entity work.fifo_async
rst => rst,
clk_w => clk,
clk_r => mii_tx_clk,
we => fifo_we,
re => fifo_re,
fifo_full => fifo_full,
fifo_empty => fifo_empty,
we => mii_fifo_we,
re => mii_fifo_re,
fifo_full => mii_fifo_full,
fifo_empty => mii_fifo_empty,
fifo_afull => open,
fifo_aempty => open,
data_w => fifo_din,
data_r => fifo_dout
data_w => mii_fifo_din,
data_r => mii_fifo_dout
);
inst_piso : entity work.piso
@@ -561,8 +554,8 @@ inst_piso : entity work.piso
clk => mii_tx_clk,
din_vld => data_vld,
din_rdy => piso_din_rdy,
din_be => fifo_dout(35 downto 32),
din => fifo_dout(31 downto 0),
din_be => mii_fifo_dout(35 downto 32),
din => mii_fifo_dout(31 downto 0),
dout_en => mii_tx_en,
dout => mii_tx