From 6f4776e29a4d862e8e99e6318f85d91c2a1d734c Mon Sep 17 00:00:00 2001 From: hadeshyp Date: Fri, 3 Nov 2006 16:31:30 +0000 Subject: [PATCH] working on IOBUF, Ingo --- trb_net_ibuf.vhd | 31 ++++-- trb_net_iobuf.vhd | 247 ++++++++++++++++++++++++++++++++++++++++++++++ trb_net_obuf.vhd | 44 ++++++++- trb_net_std.vhd | 12 +++ 4 files changed, 326 insertions(+), 8 deletions(-) create mode 100644 trb_net_iobuf.vhd diff --git a/trb_net_ibuf.vhd b/trb_net_ibuf.vhd index cb85a77..8491b05 100644 --- a/trb_net_ibuf.vhd +++ b/trb_net_ibuf.vhd @@ -71,7 +71,8 @@ signal got_ack_internal, reg_ack_internal : std_logic; --should be raised for --arrived signal is_locked, got_locked,release_locked : std_logic; signal got_eob_out, reg_eob_out: std_logic; -signal tmp_INT_DATAREADY_OUT: std_logic; +signal tmp_INT_DATAREADY_OUT, reg_INT_DATAREADY_OUT: std_logic; +signal tmp_INT_DATA_OUT, reg_INT_DATA_OUT: std_logic_vector(50 downto 0); signal current_last_header, next_last_header : std_logic_vector(50 downto 0); type ERROR_STATE is (IDLE, GOT_OVERFLOW_ERROR, GOT_LOCKED_ERROR, GOT_UNDEFINED_ERROR); @@ -159,17 +160,18 @@ reg_buffer: process(CLK) FILTER_DATA_OUT : process (INT_HEADER_IN, fifo_data_out, current_last_header, tmp_INT_DATAREADY_OUT) begin - INT_DATA_OUT <= (others => '0'); + tmp_INT_DATA_OUT <= (others => '0'); if INT_HEADER_IN = '1' then - INT_DATA_OUT <= current_last_header; + tmp_INT_DATA_OUT <= current_last_header; elsif tmp_INT_DATAREADY_OUT ='1' then - INT_DATA_OUT <= fifo_data_out; + tmp_INT_DATA_OUT <= fifo_data_out; else - INT_DATA_OUT(TYPE_POSITION) <= TYPE_ILLEGAL; + tmp_INT_DATA_OUT(TYPE_POSITION) <= TYPE_ILLEGAL; end if; end process; -- calculate the INT_DATAREADY_OUT + --header transmit will happen 1CLK later due to registering!! CALC_INT_DATAREADY_OUT: process (fifo_empty, fifo_data_out) begin if fifo_empty = '0' and not (fifo_data_out(TYPE_POSITION) = TYPE_EOB) then @@ -179,7 +181,24 @@ reg_buffer: process(CLK) end if; end process; -INT_DATAREADY_OUT <= tmp_INT_DATAREADY_OUT; +reg_dataout: process(CLK) + begin + if rising_edge(CLK) then + if RESET = '1' then + reg_INT_DATA_OUT <= (others => '0'); + reg_INT_DATAREADY_OUT <= '0'; + elsif CLK_EN = '1' then + reg_INT_DATA_OUT <= tmp_INT_DATA_OUT; + reg_INT_DATAREADY_OUT <= tmp_INT_DATAREADY_OUT; + else + reg_INT_DATA_OUT <= reg_INT_DATA_OUT; + reg_INT_DATAREADY_OUT <= reg_INT_DATAREADY_OUT; + end if; + end if; + end process; + +INT_DATAREADY_OUT <= reg_INT_DATAREADY_OUT; +INT_DATA_OUT <= reg_INT_DATA_OUT; -- this process control the read of the internal point from the fifo FILTER_OUT: process (INT_READ_IN, INT_HEADER_IN, fifo_data_out, diff --git a/trb_net_iobuf.vhd b/trb_net_iobuf.vhd new file mode 100644 index 0000000..8394254 --- /dev/null +++ b/trb_net_iobuf.vhd @@ -0,0 +1,247 @@ +-- main working horse for the trbnet +-- for a description see HADES wiki +-- http://hades-wiki.gsi.de/cgi-bin/view/DaqSlowControl/TrbNetIOBUF + +LIBRARY IEEE; +USE IEEE.STD_LOGIC_1164.ALL; +USE IEEE.STD_LOGIC_ARITH.ALL; +USE IEEE.STD_LOGIC_UNSIGNED.ALL; + +use work.trb_net_std.all; + +--Entity decalaration for clock generator +entity trb_net_iobuf is + + generic (INIT_DEPTH : integer := 3; -- Depth of the FIFO, 2^(n+1), if + -- the initibuf + REPLY_DEPTH : integer := 3); -- or the replyibuf + + port( + -- Misc + CLK : in std_logic; + RESET : in std_logic; + CLK_EN : in std_logic; + -- Media direction port + MED_DATAREADY_OUT: out STD_LOGIC; --Data word ready to be read out + --by the media (via the TrbNetIOMultiplexer) + MED_DATA_OUT: out STD_LOGIC_VECTOR (51 downto 0); -- Data word + MED_READ_IN: in STD_LOGIC; -- Media is reading + MED_ERROR_OUT: out STD_LOGIC_VECTOR (2 downto 0); -- Status bits + MED_DATAREADY_IN: in STD_LOGIC; -- Data word is offered by the Media + -- (the IOBUF MUST read) + MED_DATA_IN: in STD_LOGIC_VECTOR (51 downto 0); -- Data word + MED_READ_OUT: out STD_LOGIC; -- buffer reads a word from media + MED_ERROR_IN: in STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Internal direction port + + INT_INIT_DATAREADY_OUT: out STD_LOGIC; + INT_INIT_DATA_OUT: out STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_INIT_READ_IN: in STD_LOGIC; + INT_INIT_ERROR_OUT: out STD_LOGIC_VECTOR (2 downto 0); -- Status bits + INT_INIT_DATAREADY_IN: in STD_LOGIC; + INT_INIT_DATA_IN: in STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_INIT_READ_OUT: out STD_LOGIC; + INT_INIT_ERROR_IN: in STD_LOGIC_VECTOR (2 downto 0); -- Status bits + + INT_REPLY_HEADER_IN: in STD_LOGIC; -- Concentrator kindly asks to resend the last + -- header (only for the reply path) + INT_REPLY_DATAREADY_OUT: out STD_LOGIC; + INT_REPLY_DATA_OUT: out STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_REPLY_READ_IN: in STD_LOGIC; + INT_REPLY_ERROR_OUT: out STD_LOGIC_VECTOR (2 downto 0); -- Status bits + INT_REPLY_DATAREADY_IN: in STD_LOGIC; + INT_REPLY_DATA_IN: in STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_REPLY_READ_OUT: out STD_LOGIC; + INT_REPLY_ERROR_IN: in STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Status and control port + STAT_GEN: out STD_LOGIC_VECTOR (31 downto 0); -- General Status + STAT_LOCKED: out STD_LOGIC_VECTOR (31 downto 0); -- Status of the handshake and buffer control + STAT_INIT_BUFFER: out STD_LOGIC_VECTOR (31 downto 0); -- Status of the handshake and buffer control + STAT_REPLY_BUFFER: out STD_LOGIC_VECTOR (31 downto 0); -- General Status + CTRL_GEN: in STD_LOGIC_VECTOR (31 downto 0); + CTRL_LOCKED: in STD_LOGIC_VECTOR (31 downto 0); + CTRL_INIT_BUFFER: in STD_LOGIC_VECTOR (31 downto 0); + CTRL_REPLY_BUFFER: in STD_LOGIC_VECTOR (31 downto 0) + ); +END trb_net_iobuf; + +architecture trb_net_iobuf_arch of trb_net_iobuf is + + component trb_net_ibuf is + + generic (DEPTH : integer := 3); -- Depth of the FIFO, 2^(n+1) + + port( + -- Misc + CLK : in std_logic; + RESET : in std_logic; + CLK_EN : in std_logic; + -- Media direction port + MED_DATAREADY_IN: in STD_LOGIC; -- Data word is offered by the Media (the IOBUF MUST read) + MED_DATA_IN: in STD_LOGIC_VECTOR (50 downto 0); -- Data word + MED_READ_OUT: out STD_LOGIC; -- buffer reads a word from media + MED_ERROR_IN: in STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Internal direction port + INT_HEADER_IN: in STD_LOGIC; -- Concentrator kindly asks to resend the last header + INT_DATAREADY_OUT: out STD_LOGIC; + INT_DATA_OUT: out STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_READ_IN: in STD_LOGIC; + INT_ERROR_OUT: out STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Status and control port + STAT_LOCKED: out STD_LOGIC_VECTOR (15 downto 0); + CTRL_LOCKED: in STD_LOGIC_VECTOR (15 downto 0); + STAT_BUFFER: out STD_LOGIC_VECTOR (31 downto 0) + ); + END component; + + component trb_net_obuf is + + port( + -- Misc + CLK : in std_logic; + RESET : in std_logic; + CLK_EN : in std_logic; + -- Media direction port + MED_DATAREADY_OUT: out STD_LOGIC; + MED_DATA_OUT: out STD_LOGIC_VECTOR (50 downto 0); -- Data word + MED_READ_IN: in STD_LOGIC; + MED_ERROR_OUT: out STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Internal direction port + INT_DATAREADY_IN: in STD_LOGIC; + INT_DATA_IN: in STD_LOGIC_VECTOR (50 downto 0); -- Data word + INT_READ_OUT: out STD_LOGIC; + INT_ERROR_IN: in STD_LOGIC_VECTOR (2 downto 0); -- Status bits + -- Status and control port + STAT_LOCKED: out STD_LOGIC_VECTOR (15 downto 0); + CTRL_LOCKED: in STD_LOGIC_VECTOR (15 downto 0); + STAT_BUFFER: out STD_LOGIC_VECTOR (31 downto 0); + CTRL_BUFFER: in STD_LOGIC_VECTOR (31 downto 0) + ); + END component; + + -- internal signals for the INITIBUF + signal INITIBUF_med_dataready_in: STD_LOGIC; + signal INITIBUF_med_data_in: STD_LOGIC_VECTOR (50 downto 0); + signal INITIBUF_med_red_out: STD_LOGIC; + signal INITIBUF_error_in: STD_LOGIC_VECTOR (2 downto 0); + signal INITIBUF_stat_locked, INITIBUF_ctrl_locked: STD_LOGIC_VECTOR (15 downto 0); + signal INITIBUF_stat_buffer : STD_LOGIC_VECTOR (31 downto 0); + + -- internal signals for the REPLYIBUF + signal REPLYIBUF_med_dataready_in: STD_LOGIC; + signal REPLYIBUF_med_data_in: STD_LOGIC_VECTOR (50 downto 0); + signal REPLYIBUF_med_red_out: STD_LOGIC; + signal REPLYIBUF_header_in: STD_LOGIC; + signal REPLYIBUF_error_in: STD_LOGIC_VECTOR (2 downto 0); + signal REPLYIBUF_stat_locked, REPLYIBUF_ctrl_locked: STD_LOGIC_VECTOR (15 downto 0); + signal REPLYIBUF_stat_buffer : STD_LOGIC_VECTOR (31 downto 0); + + -- internal signals for the INITOBUF + signal INITOBUF_med_dataready_out: STD_LOGIC; + signal INITOBUF_med_data_out: STD_LOGIC_VECTOR (50 downto 0); + signal INITOBUF_med_red_in: STD_LOGIC; + signal INITOBUF_error_out: STD_LOGIC_VECTOR (2 downto 0); + signal INITOBUF_stat_locked, INITOBUF_ctrl_locked: STD_LOGIC_VECTOR (15 downto 0); + signal INITOBUF_stat_buffer, INITOBUF_ctrl_buffer: STD_LOGIC_VECTOR (31 downto 0); + + -- internal signals for the REPLYOBUF + signal REPLYOBUF_med_dataready_out: STD_LOGIC; + signal REPLYOBUF_med_data_out: STD_LOGIC_VECTOR (50 downto 0); + signal REPLYOBUF_med_red_in: STD_LOGIC; + signal REPLYOBUF_error_out: STD_LOGIC_VECTOR (2 downto 0); + signal REPLYOBUF_stat_locked, REPLYOBUF_ctrl_locked: STD_LOGIC_VECTOR (15 downto 0); + signal REPLYOBUF_stat_buffer, REPLYOBUF_ctrl_buffer: STD_LOGIC_VECTOR (31 downto 0); + + begin + + INITIBUF : trb_net_ibuf + generic map ( + DEPTH => 3) + port map ( + CLK => CLK, + RESET => RESET, + CLK_EN => CLK_EN, + MED_DATAREADY_IN => INITIBUF_med_dataready_in, + MED_DATA_IN => INITIBUF_med_data_in, + MED_READ_OUT => INITIBUF_med_red_out, + MED_ERROR_IN => INITIBUF_error_in, + INT_HEADER_IN => '0', + INT_DATAREADY_OUT => INT_INIT_DATAREADY_OUT, + INT_DATA_OUT => INT_INIT_DATA_OUT, + INT_READ_IN => INT_INIT_READ_IN, + INT_ERROR_OUT => INT_INIT_ERROR_OUT, + STAT_LOCKED(15 downto 0) => INITIBUF_stat_locked, + CTRL_LOCKED(15 downto 0) => INITIBUF_ctrl_locked, + STAT_BUFFER(31 downto 0) => INITIBUF_stat_buffer + ); + + REPLYIBUF : trb_net_ibuf + generic map ( + DEPTH => 3) + port map ( + CLK => CLK, + RESET => RESET, + CLK_EN => CLK_EN, + MED_DATAREADY_IN => REPLYIBUF_med_dataready_in, + MED_DATA_IN => REPLYIBUF_med_data_in, + MED_READ_OUT => REPLYIBUF_med_red_out, + MED_ERROR_IN => REPLYIBUF_error_in, + INT_HEADER_IN => REPLYIBUF_header_in, + INT_DATAREADY_OUT => INT_REPLY_DATAREADY_OUT, + INT_DATA_OUT => INT_REPLY_DATA_OUT, + INT_READ_IN => INT_REPLY_READ_IN, + INT_ERROR_OUT => INT_REPLY_ERROR_OUT, + STAT_LOCKED(15 downto 0) => REPLYIBUF_stat_locked, + CTRL_LOCKED(15 downto 0) => REPLYIBUF_ctrl_locked, + STAT_BUFFER(31 downto 0) => REPLYIBUF_stat_buffer + ); + + INITOBUF : trb_net_obuf + port map ( + CLK => CLK, + RESET => RESET, + CLK_EN => CLK_EN, + MED_DATAREADY_OUT => INITOBUF_med_dataready_out, + MED_DATA_OUT => INITOBUF_med_data_out, + MED_READ_IN => INITOBUF_med_red_in, + MED_ERROR_OUT => INITOBUF_error_out, + INT_DATAREADY_IN => INT_INIT_DATAREADY_IN, + INT_DATA_IN => INT_INIT_DATA_IN, + INT_READ_OUT => INT_INIT_READ_OUT, + INT_ERROR_IN => INT_INIT_ERROR_IN, + STAT_LOCKED(15 downto 0) => INITOBUF_stat_locked, + CTRL_LOCKED(15 downto 0) => INITOBUF_ctrl_locked, + STAT_BUFFER(31 downto 0) => INITOBUF_stat_buffer, + CTRL_BUFFER(31 downto 0) => INITOBUF_ctrl_buffer + ); + + REPLYOBUF : trb_net_obuf + port map ( + CLK => CLK, + RESET => RESET, + CLK_EN => CLK_EN, + MED_DATAREADY_OUT => REPLYOBUF_med_dataready_out, + MED_DATA_OUT => REPLYOBUF_med_data_out, + MED_READ_IN => REPLYOBUF_med_red_in, + MED_ERROR_OUT => REPLYOBUF_error_out, + INT_DATAREADY_IN => INT_REPLY_DATAREADY_IN, + INT_DATA_IN => INT_REPLY_DATA_IN, + INT_READ_OUT => INT_REPLY_READ_OUT, + INT_ERROR_IN => INT_REPLY_ERROR_IN, + STAT_LOCKED(15 downto 0) => REPLYOBUF_stat_locked, + CTRL_LOCKED(15 downto 0) => REPLYOBUF_ctrl_locked, + STAT_BUFFER(31 downto 0) => REPLYOBUF_stat_buffer, + CTRL_BUFFER(31 downto 0) => REPLYOBUF_ctrl_buffer + ); + +-- build the registers according to the wiki page + STAT_INIT_BUFFER(11 downto 0) <= INITIBUF_stat_buffer(11 downto 0); + STAT_INIT_BUFFER(15 downto 14) <= INITOBUF_stat_buffer(1 downto 0); + STAT_INIT_BUFFER(31 downto 16) <= INITOBUF_stat_buffer(31 downto 16); + STAT_REPLY_BUFFER(11 downto 0) <= REPLYIBUF_stat_buffer(11 downto 0); + STAT_REPLY_BUFFER(15 downto 14) <= REPLYOBUF_stat_buffer(1 downto 0); + STAT_REPLY_BUFFER(31 downto 16) <= REPLYOBUF_stat_buffer(31 downto 16); + + +end trb_net_iobuf_arch; + diff --git a/trb_net_obuf.vhd b/trb_net_obuf.vhd index 6266af9..941654f 100644 --- a/trb_net_obuf.vhd +++ b/trb_net_obuf.vhd @@ -11,7 +11,6 @@ use work.trb_net_std.all; --Entity decalaration for clock generator entity trb_net_obuf is - generic (DEPTH : integer := 3); -- Depth of the FIFO, 2^(n+1) port( -- Misc @@ -56,7 +55,9 @@ architecture trb_net_obuf_arch of trb_net_obuf is signal SEND_ACK_IN : STD_LOGIC; signal GOT_ACK_IN : STD_LOGIC; - type BUFFER_STATE is (BUFFER_IDLE, BUFFER_SEND_ACK, BUFFER_SEND_EOB, BUFFER_SEND_DATA, BUFFER_BLOCKED); + signal is_locked, got_locked,release_locked : std_logic; + + -- type BUFFER_STATE is (BUFFER_IDLE, BUFFER_SEND_ACK, BUFFER_SEND_EOB, BUFFER_SEND_DATA, BUFFER_BLOCKED); begin @@ -219,6 +220,45 @@ architecture trb_net_obuf_arch of trb_net_obuf is end if; end if; end process; + + + --locking control + comb_locked : process (MED_READ_IN, current_output_buffer, release_locked, is_locked) + + begin -- process + got_locked <= is_locked; + + if MED_READ_IN = '1' then + + if current_output_buffer(TYPE_POSITION) = TYPE_TRM then + if release_locked = '0' then + got_locked <= '1'; + end if; + end if; + end if; -- MED_READ_IN + end process; + + release_locked <= CTRL_LOCKED(0); + STAT_LOCKED(0) <= is_locked; + STAT_LOCKED(15 downto 1) <= (others => '0'); + + reg_locked: process(CLK) + begin + if rising_edge(CLK) then + if RESET = '1' then + is_locked <= '0'; + elsif CLK_EN = '1' then + if release_locked = '1' then + is_locked <= '0'; + else + is_locked <= got_locked; + end if; + else + is_locked <= is_locked; + end if; + end if; + end process; + end trb_net_obuf_arch; diff --git a/trb_net_std.vhd b/trb_net_std.vhd index 137d384..01d1d94 100644 --- a/trb_net_std.vhd +++ b/trb_net_std.vhd @@ -28,6 +28,18 @@ package trb_net_std is constant F1_CHECK_ACK : std_logic_vector(15 downto 0) := x"0000"; subtype BUFFER_SIZE_POSITION is integer range 19 downto 16; + + type mii_d51 is + record + INT_DATAREADY_OUT: STD_LOGIC; + INT_DATA_OUT: STD_LOGIC_VECTOR (51 downto 0); -- Data word + INT_READ_IN: STD_LOGIC; + INT_ERROR_OUT: STD_LOGIC_VECTOR (2 downto 0); -- Status bits + INT_DATAREADY_IN: STD_LOGIC; + INT_DATA_IN: STD_LOGIC_VECTOR (51 downto 0); -- Data word + INT_READ_OUT: STD_LOGIC; + INT_ERROR_IN: STD_LOGIC_VECTOR (2 downto 0); -- Status bits + end record; end package trb_net_std; -- 2.43.0