-- -- Transition Radiation Detector -- -- MCM Control Unit - Configuration Network -- -- -- -- $Id$ -- -- Robin Gareus, Kirchhoff Institute for Physics, Heidelberg -- rgareus@kip.uni-heidelberg.de -- ------------------------------------------------------------ -- -- simple counter to remove stuff bits: -- -- data is strobed in ('data_in','strobe_in') and when -- data is no stuff bit, it is forwarded to the -- output ('strobe_out','data_out'). -- on recieving more than 'stuff_length' bits of the same -- type an error is detected and the 'stuff_err' flag is set to '1' -- -- This entity can transparently be inserted in any datapath. -- but will cause a latency of 1 clock cycle, since the data -- is buffered in a DFF. -- -- use generic 'stuff_length' to specify how many bits of same type -- may get through before removing one stuff bit. -- -- reset_n is synchroneous here, and resets the counter. -- -------------------------------------------------- -- standard includes, library definitions. -------------------------------------------------- library ieee; use ieee.std_logic_1164.all; -------------------------------------------------- -- ENTITY -------------------------------------------------- entity mcm_nw_destuffing is generic ( stuff_length : integer := 4); port( data_in : in std_logic; -- data to be destuffed strobe_in : in std_logic; -- stobe in data_out : out std_logic; -- unstuffed data out strobe_out : out std_logic; -- strobe stuff_err : out std_logic; -- error occured stuff_reset_n : in std_logic; clk : in std_logic ); end mcm_nw_destuffing; -------------------------------------------------- -- ARCHITECTURE -------------------------------------------------- architecture structural of mcm_nw_destuffing is SIGNAL counter : integer RANGE 0 to stuff_length; SIGNAL valid,data : std_logic; begin destuff: process(clk,stuff_reset_n) begin if (clk'event AND clk = '1') then -- synchroneus process. stuff_err <= '0'; valid <= '0'; if (stuff_reset_n = '0') then counter <= 0; -- reset counter data <= '1'; -- start bit elsif ( strobe_in = '1') then -- data is strobed in... if (data = data_in) then -- .. and data bit has not changed... if ( counter < stuff_length ) then -- still < 4 bits of same type. counter <= counter + 1; -- so increse counter valid <= '1'; -- and strobe out valid bit. else -- oops, this is one bit too much. counter <= 0; -- so reset and stuff_err <= '1'; -- ...error! end if; else -- if we get here, there was a change of the data bit if ( counter < stuff_length ) then valid <= '1'; end if; counter <= 0; -- since the bit has changed. restart end if; data <= data_in; end if; end if; end process destuff; data_out <= data when valid = '1' ELSE '-'; strobe_out <= valid; end structural; -------------------------------------------------- -- CONFIGURATION -------------------------------------------------- -- synopsys translate_off configuration mcm_nw_destuffing_CFG of mcm_nw_destuffing is for structural end for; end mcm_nw_destuffing_CFG; -- synopsys translate_on