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