Debian Codegraph @

hdl/fpga/ip/nuand/synthesis/bit_stripper.vhd

raw
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4
5
6 entity bit_stripper is
7 generic(
8 INPUT_WIDTH : positive := 32;
9 OUTPUT_WIDTH : positive := 1;
10 CPS : positive := 2
11 );
12
13 port(
14 clock : in std_logic;
15 reset : in std_logic;
16
17 enable : in std_logic;
18
19 in_data : in std_logic_vector(INPUT_WIDTH-1 downto 0);
20 in_data_request : out std_logic;
21 in_data_valid : in std_logic;
22
23 out_data : out std_logic_vector(OUTPUT_WIDTH-1 downto 0);
24 out_data_request : in std_logic;
25 out_data_valid : out std_logic
26 );
27 end entity;
28
29 architecture arch of bit_stripper is
30
31 signal data_buffer : std_logic_vector( (INPUT_WIDTH + OUTPUT_WIDTH)-1 downto 0);
32
33 type stripper_fsm_t is (FLUSH,SHIFT_BUFFER,OUTPUT_DATA);
34 signal stripper_fsm : stripper_fsm_t;
35
36 constant THRESHOLD : positive := OUTPUT_WIDTH;
37
38
39 begin
40
41 rip_bit : process(clock,reset)
42 variable bit_count : natural range 0 to (INPUT_WIDTH + THRESHOLD + 1);
43 begin
44 if reset = '1' then
45 data_buffer <= (others =>'0');
46 bit_count := 0;
47 stripper_fsm <= FLUSH;
48
49 out_data <= (others => '0');
50 out_data_valid <= '0';
51 in_data_request <= '0';
52
53 elsif rising_edge(clock) then
54
55 out_data_valid <= '0';
56 in_data_request <= '0';
57
58 if enable = '0' then
59 stripper_fsm <= FLUSH;
60 end if;
61
62 case stripper_fsm is
63 when FLUSH =>
64 bit_count := 0;
65 data_buffer <= (others => '0');
66 if enable = '1' then
67 stripper_fsm <= SHIFT_BUFFER;
68 end if;
69
70 when SHIFT_BUFFER =>
71 --
72 case bit_count is
73 when 0 => data_buffer <= "0000" & in_data;
74 when 1 => data_buffer <= "000" & in_data & data_buffer(0);
75 when 2 => data_buffer <= "00" & in_data & data_buffer(1 downto 0);
76 when 3 => data_buffer <= '0' & in_data & data_buffer(2 downto 0);
77 when 4 => data_buffer <= in_data & data_buffer(3 downto 0);
78 when others => data_buffer <= "0000" & in_data;
79 end case;
80 bit_count := bit_count + INPUT_WIDTH;
81 stripper_fsm <= OUTPUT_DATA;
82 in_data_request <= '1';
83
84 when OUTPUT_DATA =>
85
86 if out_data_request = '1' then
87 out_data <= data_buffer(OUTPUT_WIDTH -1 downto 0);
88 out_data_valid <= '1';
89 --shift the data down
90 data_buffer <= (OUTPUT_WIDTH-1 downto 0 => '0') & data_buffer( (INPUT_WIDTH+OUTPUT_WIDTH)-1 downto OUTPUT_WIDTH);
91 bit_count := bit_count - OUTPUT_WIDTH;
92
93 end if;
94
95 if bit_count <= THRESHOLD then
96 stripper_fsm <= SHIFT_BUFFER;
97 end if;
98
99
100 end case;
101
102 end if;
103 end process;
104 end architecture;