-- -- Transition Radiation Detector -- -- MCM Control Unit - Configuration Network -- -- -- -- $Id$ -- -- Robin Gareus, Kirchhoff Institute for Physics, Heidelberg -- rgareus@kip.uni-heidelberg.de -- ------------------------------------------------------------ -- -- simple Counter to add stuff bits in a serialized data stream. -- -- data is strobed in. (stuffing_strobe_in, stuffing_data_in) -- and _held_ on output until next strobe. -- if a stuff bit is inserted, the 'stuff_bit_inserted' is set to '1' -- (in this case the current data_in must be strobed again -- to be transmitted) -- -- if 'stuffing_start_n' is '0' when strobing data in, it is assumed to -- be the first bit transmitted, and the internal counter is reset. -- -- use generic 'stuff_length' to specify how many bits of same type -- may get through unstuffed. -- -------------------------------------------------- -- standard includes, library definitions. -------------------------------------------------- library ieee; use ieee.std_logic_1164.all; -------------------------------------------------- -- ENTITY -------------------------------------------------- entity mcm_nw_stuffing is generic ( stuff_length : integer := 4); port( stuffing_data_in : in std_logic; -- data to be stuffed stuffing_strobe_in : in std_logic; -- strobe of data_in stuffing_start_n : in std_logic; -- reset stuff counter stuff_bit_inserted : out std_logic; -- stuff bit has been inserted stuffed_data_out : out std_logic; -- stuffed data out. reset_n : in std_logic; clk : in std_logic ); end mcm_nw_stuffing; -------------------------------------------------- -- ARCHITECTURE -------------------------------------------------- architecture structural of mcm_nw_stuffing is SIGNAL state : integer RANGE 0 to stuff_length; -- this is the counter SIGNAL stuff,data,data_tx : std_logic; begin count: process(clk,reset_n) begin if (reset_n = '0') then data_tx <= '0'; --async reset -- check&verify the following reset values :) stuff_bit_inserted <= '0'; data <= '0'; state <= 0; elsif (clk'event and clk= '1') then if (stuffing_start_n = '0') then data_tx <= '0'; end if; if (stuffing_strobe_in = '1') then -- if no strobe -> do nothing stuff_bit_inserted <= '0'; data <= stuffing_data_in; -- defaults. data_tx <= stuffing_data_in; if (stuffing_start_n = '0') then state <= 0; --reset on start_n elsif (state < stuff_length ) then -- still ok to transmit... if (data = stuffing_data_in) then state <= state + 1; else state <= 0; end if; -- bit changed, so restart. else -- insert stuff bit. and restart. state <= 0; stuff_bit_inserted <= '1'; data_tx <= not data; data <= not data; end if; end if; end if; end process count; stuffed_data_out <= data_tx; end structural; -------------------------- -- CONFIGURATION -------------------------- -- synopsys translate_off configuration mcm_nw_stuffing_CFG of mcm_nw_stuffing is for structural end for; end mcm_nw_stuffing_CFG; -- synopsys translate_on