otsdaq_prepmodernization  v2_05_02_indev
crc_splice.vhd
1 ----------------------------------------------------------------------------------
2 -- Company: FNAL
3 -- Engineer: Ryan Rivera
4 --
5 -- Create Date: 16:52:08 12/04/2007
6 -- Dependencies:
7 --
8 -- Revision:
9 -- Revision 0.01 - File Created
10 -- Additional Comments:
11 --
12 ----------------------------------------------------------------------------------
13 library IEEE;
14 use IEEE.STD_LOGIC_1164.ALL;
15 use IEEE.STD_LOGIC_ARITH.ALL;
16 use IEEE.STD_LOGIC_UNSIGNED.ALL;
17 
18 entity crc_splice is
19  Port (
20  data : in STD_LOGIC_VECTOR (7 downto 0);
21  crc : in STD_LOGIC_VECTOR (7 downto 0);
22  rd : in STD_LOGIC;
23 
24  clk : in STD_LOGIC;
25  tx_en_in : in STD_LOGIC;
26  tx_er_in : in STD_LOGIC;
27  four_bit_mode : in STD_LOGIC;
28 
29  crc_mask : out STD_LOGIC;
30  tx_en : out STD_LOGIC;
31  tx_er : out STD_LOGIC;
32  txd : out STD_LOGIC_VECTOR(7 downto 0)
33  );
34 end entity;
35 
36 architecture arch of crc_splice is
37 
38  signal dataout : STD_LOGIC_VECTOR (7 downto 0);
39  signal nibble_reg : STD_LOGIC_VECTOR (3 downto 0); --crc doesn't hold output, so need to latch
40  signal flip_flop : STD_LOGIC;
41 begin
42 
43  crc_mask <= not flip_flop;
44 
45  dataout <= crc when rd = '1' else data;
46 
47  process(clk)
48  begin
49 
50  if rising_edge(clk) then
51  tx_en <= tx_en_in;
52  tx_er <= tx_er_in;
53 
54  if four_bit_mode = '0' then
55  txd <= dataout;
56  flip_flop <= '0'; --disable mask
57  else -- in four bit mode alternate nibbles during tx_en = 1
58  if tx_en_in = '0' then
59  flip_flop <= '0';
60  else
61  flip_flop <= not flip_flop;
62  end if;
63 
64  if flip_flop = '0' then
65  txd(3 downto 0) <= dataout(3 downto 0);
66  nibble_reg <= dataout(7 downto 4); --forced by crc gen block
67  else
68  txd(3 downto 0) <= nibble_reg;
69  end if;
70 
71  end if;
72  end if;
73  end process;
74 
75 end arch;
76