erster versuch das ganze mal zu flashen -> es blinkt!!111
[calu.git] / cpu / src / pipeline_tb.vhd
1 library IEEE;
2 use IEEE.std_logic_1164.all;
3 use IEEE.numeric_std.all;
4
5 use work.common_pkg.all;
6 use work.core_pkg.all;
7 use work.extension_pkg.all;
8 -------------------------------------------------------------------------------
9 -- ENTITY
10 -------------------------------------------------------------------------------
11 entity pipeline_tb is
12
13 end pipeline_tb;
14
15
16 -------------------------------------------------------------------------------
17 -- ARCHITECTURE
18 -------------------------------------------------------------------------------
19 architecture behavior of pipeline_tb is
20
21         constant cc : time := 30 ns;        -- test clock period
22         
23                 signal sys_clk_pin : std_logic;
24                 signal sys_res_n_pin : std_logic;
25                 --Data input
26                 
27                 signal dummy : std_logic;
28
29                 signal jump_result_pin : instruction_addr_t;
30                 signal prediction_result_pin : instruction_addr_t;
31                 signal branch_prediction_bit_pin : std_logic;
32                 signal alu_jump_bit_pin : std_logic;
33                 signal instruction_pin : instruction_word_t;
34                 signal prog_cnt : instruction_addr_t;
35
36                 signal reg_w_addr_pin : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
37                 signal reg_wr_data_pin : gp_register_t;
38                 signal reg_we_pin : std_logic;
39                 signal to_next_stage_pin : dec_op;
40
41                  signal result_pin : gp_register_t;--reg
42                  signal result_addr_pin : gp_addr_t;--reg
43                  signal addr_pin : word_t; --memaddr
44                  signal data_pin : gp_register_t; --mem data --ureg
45                  signal alu_jump_pin : std_logic;--reg
46                  signal brpr_pin  : std_logic;  --reg
47                  signal wr_en_pin : std_logic;--regop --reg
48                  signal dmem_pin  : std_logic;--memop
49                  signal dmem_wr_en_pin : std_logic;
50                  signal hword_pin  : std_logic;
51                  signal byte_s_pin : std_logic;
52                                  
53                                   signal gpm_in_pin : extmod_rec;
54                                  signal gpm_out_pin : gp_register_t;
55                  signal nop_pin : std_logic;
56
57                  signal cycle_cnt : integer;
58
59
60 begin
61
62 --              instruction_ram : r_w_ram
63 --              generic map (
64 --                      PHYS_INSTR_ADDR_WIDTH,
65 --                      WORD_WIDTH
66 --              )
67 --              
68 --              port map (
69 --                      sys_clk,
70 --                      instr_w_addr(PHYS_INSTR_ADDR_WIDTH-1 downto 0),
71 --                      instr_r_addr_nxt(PHYS_INSTR_ADDR_WIDTH-1 downto 0),
72 --                      instr_we,
73 --                      instr_wr_data,
74 --                      instr_rd_data
75 --              );
76
77         fetch_st : fetch_stage
78                 generic map (
79         
80                         '0',
81                         '1'
82                 )
83                 
84                 port map (
85                 --System inputs
86                         clk => sys_clk_pin, --: in std_logic;
87                         reset => sys_res_n_pin, --: in std_logic;
88                 
89                 --Data inputs
90                         jump_result => jump_result_pin, --: in instruction_addr_t;
91                         prediction_result => prediction_result_pin, --: in instruction_addr_t;
92                         branch_prediction_bit => branch_prediction_bit_pin,  --: in std_logic;
93                         alu_jump_bit => alu_jump_bit_pin, --: in std_logic;
94
95                 --Data outputs
96                         instruction => instruction_pin, --: out instruction_word_t
97                         prog_cnt => prog_cnt
98                 );      
99
100         decode_st : decode_stage
101                 generic map (
102                         -- active reset value
103                         '0',
104                         -- active logic value
105                         '1'
106                         
107                         )
108                 port map (
109                 --System inputs
110                         clk => sys_clk_pin, --: in std_logic;
111                         reset => sys_res_n_pin, -- : in std_logic;
112
113                 --Data inputs
114                         instruction => instruction_pin, --: in instruction_word_t;
115                         prog_cnt => prog_cnt,
116                         reg_w_addr => reg_w_addr_pin, --: in std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
117                         reg_wr_data => reg_wr_data_pin, --: in gp_register_t;
118                         reg_we => reg_we_pin, --: in std_logic;
119                         nop => nop_pin,
120
121                 --Data outputs
122                         branch_prediction_res => prediction_result_pin, --: instruction_word_t;
123                         branch_prediction_bit => branch_prediction_bit_pin, --: std_logic
124                         to_next_stage => to_next_stage_pin
125                         
126                 );
127           exec_st : execute_stage
128                 generic map('0')
129                 port map(sys_clk_pin, sys_res_n_pin,to_next_stage_pin,reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, gpm_in_pin, result_pin, result_addr_pin,addr_pin,
130                 data_pin, alu_jump_pin,brpr_pin, wr_en_pin, dmem_pin,dmem_wr_en_pin,hword_pin,byte_s_pin, gpm_out_pin);
131
132           writeback_st : writeback_stage
133                 generic map('0', '1')
134                 port map(sys_clk_pin, sys_res_n_pin, result_pin, result_addr_pin, addr_pin, data_pin, alu_jump_pin, brpr_pin, 
135                 wr_en_pin, dmem_pin, dmem_wr_en_pin, hword_pin, byte_s_pin,
136                 reg_wr_data_pin, reg_we_pin, reg_w_addr_pin, jump_result_pin, alu_jump_bit_pin);
137
138
139
140
141         nop_pin <= (alu_jump_bit_pin);-- xor brpr_pin);
142
143 -------------------------------------------------------------------------------
144 -- generate simulation clock
145 -------------------------------------------------------------------------------
146   CLKGEN : process
147   begin
148     sys_clk_pin <= '1';
149     wait for cc/2;
150     sys_clk_pin <= '0';
151     wait for cc/2;
152   end process CLKGEN;
153   
154
155   cnt : process(sys_clk_pin, sys_res_n_pin)
156
157   begin
158
159         if (sys_res_n_pin = '0') then
160                 cycle_cnt <= 0;
161         elsif (sys_clk_pin'event and sys_clk_pin = '1') then
162                 cycle_cnt <= cycle_cnt + 1;
163         end if;
164
165   end process cnt;
166 -------------------------------------------------------------------------------
167 -- test the design
168 -------------------------------------------------------------------------------
169   TEST_IT : process
170
171     -- wait for n clock cycles
172     procedure icwait(cycles : natural) is
173     begin
174       for i in 1 to cycles loop
175         wait until sys_clk_pin = '1' and sys_clk_pin'event;
176       end loop;
177     end;
178         
179   begin
180     -----------------------------------------------------------------------------
181     -- initial reset
182     -----------------------------------------------------------------------------
183         sys_res_n_pin <= '0';
184 --      reg_w_addr_pin <= (others => '0');
185 --      reg_wr_data_pin <= (others => '0');
186 --      reg_we_pin <= '0';
187
188         icwait(10);
189         dummy <= '1';
190         sys_res_n_pin <= '1';
191         wait until sys_res_n_pin = '1';
192         
193
194         icwait(1000000000);
195
196     ---------------------------------------------------------------------------
197     -- exit testbench
198     ---------------------------------------------------------------------------
199     assert false
200       report "Test finished"
201       severity error;
202
203   end process test_it;
204
205 end behavior;
206
207
208 -------------------------------------------------------------------------------
209 -- configuration
210 -------------------------------------------------------------------------------
211 configuration pipeline_conf_beh of pipeline_tb is
212   for behavior
213     for fetch_st : fetch_stage use entity work.fetch_stage(behav);
214     end for;
215     for decode_st : decode_stage use entity work.decode_stage(behav);
216     end for;
217     for exec_st : execute_stage use entity work.execute_stage(behav);
218     end for;
219     for writeback_st : writeback_stage use entity work.writeback_stage(behav);
220     end for;
221
222   end for;
223 end pipeline_conf_beh;