OpenCores
URL https://opencores.org/ocsvn/hf-risc/hf-risc/trunk

Subversion Repositories hf-risc

[/] [hf-risc/] [trunk/] [hf-riscv/] [sim/] [hf-riscv_tb.vhd] - Blame information for rev 13

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 13 serginhofr
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_textio.all;
4
use ieee.std_logic_unsigned.all;
5
use std.textio.all;
6
use ieee.numeric_std.all;
7
 
8
entity tb is
9
        generic(
10
                address_width: integer := 16;
11
                memory_file : string := "code.txt";
12
                log_file: string := "out.txt";
13
                uart_support : string := "yes"
14
        );
15
end tb;
16
 
17
architecture tb of tb is
18
        signal clock_in, reset, busy_cpu, stall_cpu, data, stall, stall_sig: std_logic := '0';
19
        signal uart_read, uart_write: std_logic;
20
        signal boot_enable_n, ram_enable_n, irq_cpu, irq_ack_cpu, exception_cpu, data_access_cpu, ram_dly: std_logic;
21
        signal address, data_read, data_write, data_read_boot, data_read_ram, irq_vector_cpu, inst_addr_cpu, inst_in_cpu, data_addr_cpu, data_in_cpu, data_out_cpu: std_logic_vector(31 downto 0);
22
        signal ext_irq: std_logic_vector(7 downto 0);
23
        signal data_we, data_w_n_ram, data_w_cpu: std_logic_vector(3 downto 0);
24
begin
25
 
26
        process                                         --25Mhz system clock
27
        begin
28
                clock_in <= not clock_in;
29
                wait for 20 ns;
30
                clock_in <= not clock_in;
31
                wait for 20 ns;
32
        end process;
33
 
34
        process
35
        begin
36
                stall <= not stall;
37
                wait for 123 ns;
38
                stall <= not stall;
39
                wait for 123 ns;
40
        end process;
41
 
42
        reset <= '0', '1' after 5 ns, '0' after 500 ns;
43
        stall_sig <= stall;
44
        ext_irq <= x"00";
45
        uart_read <= '1';
46
        boot_enable_n <= '0' when (address(31 downto 28) = "0000" and stall_cpu = '0') or reset = '1' else '1';
47
        ram_enable_n <= '0' when (address(31 downto 28) = "0100" and stall_cpu = '0') or reset = '1' else '1';
48
        data_read <= data_read_boot when address(31 downto 28) = "0000" and ram_dly = '0' else data_read_ram;
49
        data_w_n_ram <= not data_we;
50
 
51
        process(clock_in, reset)
52
        begin
53
                if reset = '1' then
54
                        ram_dly <= '0';
55
                elsif clock_in'event and clock_in = '1' then
56
                        ram_dly <= not ram_enable_n;
57
                end if;
58
        end process;
59
 
60
        -- HF-RISC core
61
        core: entity work.datapath
62
        port map(       clock => clock_in,
63
                        reset => reset,
64
                        stall => stall_cpu,
65
                        busy => busy_cpu,
66
                        irq_vector => irq_vector_cpu,
67
                        irq => irq_cpu,
68
                        irq_ack => irq_ack_cpu,
69
                        exception => exception_cpu,
70
                        inst_addr => inst_addr_cpu,
71
                        inst_in => inst_in_cpu,
72
                        data_addr => data_addr_cpu,
73
                        data_in => data_in_cpu,
74
                        data_out => data_out_cpu,
75
                        data_w => data_w_cpu,
76
                        data_access => data_access_cpu
77
        );
78
 
79
        -- peripherals / busmux logic
80
        peripherals_busmux: entity work.busmux
81
        generic map(
82
                log_file => log_file,
83
                uart_support => uart_support
84
        )
85
        port map(
86
                clock => clock_in,
87
                reset => reset,
88
 
89
                stall => stall_sig,
90
 
91
                stall_cpu => stall_cpu,
92
                busy_cpu => busy_cpu,
93
                irq_vector_cpu => irq_vector_cpu,
94
                irq_cpu => irq_cpu,
95
                irq_ack_cpu => irq_ack_cpu,
96
                exception_cpu => exception_cpu,
97
                inst_addr_cpu => inst_addr_cpu,
98
                inst_in_cpu => inst_in_cpu,
99
                data_addr_cpu => data_addr_cpu,
100
                data_in_cpu => data_in_cpu,
101
                data_out_cpu => data_out_cpu,
102
                data_w_cpu => data_w_cpu,
103
                data_access_cpu => data_access_cpu,
104
 
105
                addr_mem => address,
106
                data_read_mem => data_read,
107
                data_write_mem => data_write,
108
                data_we_mem => data_we,
109
                extio_in => ext_irq,
110
                extio_out => open,
111
                uart_read => uart_read,
112
                uart_write => uart_write
113
        );
114
 
115
        -- boot ROM
116
        boot0lb: entity work.boot_ram
117
        generic map (   memory_file => "boot.txt",
118
                                        data_width => 8,
119
                                        address_width => 12,
120
                                        bank => 0)
121
        port map(
122
                clk     => clock_in,
123
                addr    => address(11 downto 2),
124
                cs_n    => boot_enable_n,
125
                we_n    => '1',
126
                data_i  => (others => '0'),
127
                data_o  => data_read_boot(7 downto 0)
128
        );
129
 
130
        boot0ub: entity work.boot_ram
131
        generic map (   memory_file => "boot.txt",
132
                                        data_width => 8,
133
                                        address_width => 12,
134
                                        bank => 1)
135
        port map(
136
                clk     => clock_in,
137
                addr    => address(11 downto 2),
138
                cs_n    => boot_enable_n,
139
                we_n    => '1',
140
                data_i  => (others => '0'),
141
                data_o  => data_read_boot(15 downto 8)
142
        );
143
 
144
        boot1lb: entity work.boot_ram
145
        generic map (   memory_file => "boot.txt",
146
                                        data_width => 8,
147
                                        address_width => 12,
148
                                        bank => 2)
149
        port map(
150
                clk     => clock_in,
151
                addr    => address(11 downto 2),
152
                cs_n    => boot_enable_n,
153
                we_n    => '1',
154
                data_i  => (others => '0'),
155
                data_o  => data_read_boot(23 downto 16)
156
        );
157
 
158
        boot1ub: entity work.boot_ram
159
        generic map (   memory_file => "boot.txt",
160
                                        data_width => 8,
161
                                        address_width => 12,
162
                                        bank => 3)
163
        port map(
164
                clk     => clock_in,
165
                addr    => address(11 downto 2),
166
                cs_n    => boot_enable_n,
167
                we_n    => '1',
168
                data_i  => (others => '0'),
169
                data_o  => data_read_boot(31 downto 24)
170
        );
171
 
172
        -- RAM
173
        memory0lb: entity work.bram
174
        generic map (   memory_file => memory_file,
175
                                        data_width => 8,
176
                                        address_width => address_width,
177
                                        bank => 0)
178
        port map(
179
                clk     => clock_in,
180
                addr    => address(address_width -1 downto 2),
181
                cs_n    => ram_enable_n,
182
                we_n    => data_w_n_ram(0),
183
                data_i  => data_write(7 downto 0),
184
                data_o  => data_read_ram(7 downto 0)
185
        );
186
 
187
        memory0ub: entity work.bram
188
        generic map (   memory_file => memory_file,
189
                                        data_width => 8,
190
                                        address_width => address_width,
191
                                        bank => 1)
192
        port map(
193
                clk     => clock_in,
194
                addr    => address(address_width -1 downto 2),
195
                cs_n    => ram_enable_n,
196
                we_n    => data_w_n_ram(1),
197
                data_i  => data_write(15 downto 8),
198
                data_o  => data_read_ram(15 downto 8)
199
        );
200
 
201
        memory1lb: entity work.bram
202
        generic map (   memory_file => memory_file,
203
                                        data_width => 8,
204
                                        address_width => address_width,
205
                                        bank => 2)
206
        port map(
207
                clk     => clock_in,
208
                addr    => address(address_width -1 downto 2),
209
                cs_n    => ram_enable_n,
210
                we_n    => data_w_n_ram(2),
211
                data_i  => data_write(23 downto 16),
212
                data_o  => data_read_ram(23 downto 16)
213
        );
214
 
215
        memory1ub: entity work.bram
216
        generic map (   memory_file => memory_file,
217
                                        data_width => 8,
218
                                        address_width => address_width,
219
                                        bank => 3)
220
        port map(
221
                clk     => clock_in,
222
                addr    => address(address_width -1 downto 2),
223
                cs_n    => ram_enable_n,
224
                we_n    => data_w_n_ram(3),
225
                data_i  => data_write(31 downto 24),
226
                data_o  => data_read_ram(31 downto 24)
227
        );
228
 
229
        -- debug process
230
        debug:
231
        if uart_support = "no" generate
232
                process(clock_in, data_addr_cpu)
233
                        file store_file : text open write_mode is "debug.txt";
234
                        variable hex_file_line : line;
235
                        variable c : character;
236
                        variable index : natural;
237
                        variable line_length : natural := 0;
238
                begin
239
                        if clock_in'event and clock_in = '1' then
240
                                if data_addr_cpu = x"f00000d0" and data = '0' then
241
                                        data <= '1';
242
                                        index := conv_integer(data_write(30 downto 24));
243
                                        if index /= 10 then
244
                                                c := character'val(index);
245
                                                write(hex_file_line, c);
246
                                                line_length := line_length + 1;
247
                                        end if;
248
                                        if index = 10 or line_length >= 72 then
249
                                                writeline(store_file, hex_file_line);
250
                                                line_length := 0;
251
                                        end if;
252
                                else
253
                                        data <= '0';
254
                                end if;
255
                        end if;
256
                end process;
257
        end generate;
258
 
259
        process(clock_in, reset, address)
260
        begin
261
                if reset = '1' then
262
                elsif clock_in'event and clock_in = '0' then
263
                        assert address /= x"e0000000" report "end of simulation" severity failure;
264
                        assert (address < x"50000000") or (address >= x"f0000000") report "out of memory region" severity failure;
265
                        assert address /= x"40000100" report "handling IRQ" severity warning;
266
                end if;
267
        end process;
268
 
269
end tb;
270
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.