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 18

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 18 serginhofr
                uart_support : string := "no"
14 13 serginhofr
        );
15
end tb;
16
 
17
architecture tb of tb is
18 18 serginhofr
        signal clock_in, reset, stall_cpu, data, stall, stall_sig: std_logic := '0';
19 13 serginhofr
        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 18 serginhofr
        signal address, data_read, data_write, data_read_boot, data_read_ram, irq_vector_cpu, address_cpu, data_in_cpu, data_out_cpu: std_logic_vector(31 downto 0);
22 13 serginhofr
        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 18 serginhofr
        stall_sig <= '0'; --stall;
44 13 serginhofr
        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
                        irq_vector => irq_vector_cpu,
66
                        irq => irq_cpu,
67
                        irq_ack => irq_ack_cpu,
68
                        exception => exception_cpu,
69 18 serginhofr
                        address => address_cpu,
70 13 serginhofr
                        data_in => data_in_cpu,
71
                        data_out => data_out_cpu,
72
                        data_w => data_w_cpu,
73
                        data_access => data_access_cpu
74
        );
75
 
76
        -- peripherals / busmux logic
77
        peripherals_busmux: entity work.busmux
78
        generic map(
79
                log_file => log_file,
80
                uart_support => uart_support
81
        )
82
        port map(
83
                clock => clock_in,
84
                reset => reset,
85
 
86
                stall => stall_sig,
87
 
88
                stall_cpu => stall_cpu,
89
                irq_vector_cpu => irq_vector_cpu,
90
                irq_cpu => irq_cpu,
91
                irq_ack_cpu => irq_ack_cpu,
92
                exception_cpu => exception_cpu,
93 18 serginhofr
                address_cpu => address_cpu,
94 13 serginhofr
                data_in_cpu => data_in_cpu,
95
                data_out_cpu => data_out_cpu,
96
                data_w_cpu => data_w_cpu,
97
                data_access_cpu => data_access_cpu,
98
 
99
                addr_mem => address,
100
                data_read_mem => data_read,
101
                data_write_mem => data_write,
102
                data_we_mem => data_we,
103
                extio_in => ext_irq,
104
                extio_out => open,
105
                uart_read => uart_read,
106
                uart_write => uart_write
107
        );
108
 
109
        -- boot ROM
110
        boot0lb: entity work.boot_ram
111
        generic map (   memory_file => "boot.txt",
112
                                        data_width => 8,
113
                                        address_width => 12,
114
                                        bank => 0)
115
        port map(
116
                clk     => clock_in,
117
                addr    => address(11 downto 2),
118
                cs_n    => boot_enable_n,
119
                we_n    => '1',
120
                data_i  => (others => '0'),
121
                data_o  => data_read_boot(7 downto 0)
122
        );
123
 
124
        boot0ub: entity work.boot_ram
125
        generic map (   memory_file => "boot.txt",
126
                                        data_width => 8,
127
                                        address_width => 12,
128
                                        bank => 1)
129
        port map(
130
                clk     => clock_in,
131
                addr    => address(11 downto 2),
132
                cs_n    => boot_enable_n,
133
                we_n    => '1',
134
                data_i  => (others => '0'),
135
                data_o  => data_read_boot(15 downto 8)
136
        );
137
 
138
        boot1lb: entity work.boot_ram
139
        generic map (   memory_file => "boot.txt",
140
                                        data_width => 8,
141
                                        address_width => 12,
142
                                        bank => 2)
143
        port map(
144
                clk     => clock_in,
145
                addr    => address(11 downto 2),
146
                cs_n    => boot_enable_n,
147
                we_n    => '1',
148
                data_i  => (others => '0'),
149
                data_o  => data_read_boot(23 downto 16)
150
        );
151
 
152
        boot1ub: entity work.boot_ram
153
        generic map (   memory_file => "boot.txt",
154
                                        data_width => 8,
155
                                        address_width => 12,
156
                                        bank => 3)
157
        port map(
158
                clk     => clock_in,
159
                addr    => address(11 downto 2),
160
                cs_n    => boot_enable_n,
161
                we_n    => '1',
162
                data_i  => (others => '0'),
163
                data_o  => data_read_boot(31 downto 24)
164
        );
165
 
166
        -- RAM
167
        memory0lb: entity work.bram
168
        generic map (   memory_file => memory_file,
169
                                        data_width => 8,
170
                                        address_width => address_width,
171
                                        bank => 0)
172
        port map(
173
                clk     => clock_in,
174
                addr    => address(address_width -1 downto 2),
175
                cs_n    => ram_enable_n,
176
                we_n    => data_w_n_ram(0),
177
                data_i  => data_write(7 downto 0),
178
                data_o  => data_read_ram(7 downto 0)
179
        );
180
 
181
        memory0ub: entity work.bram
182
        generic map (   memory_file => memory_file,
183
                                        data_width => 8,
184
                                        address_width => address_width,
185
                                        bank => 1)
186
        port map(
187
                clk     => clock_in,
188
                addr    => address(address_width -1 downto 2),
189
                cs_n    => ram_enable_n,
190
                we_n    => data_w_n_ram(1),
191
                data_i  => data_write(15 downto 8),
192
                data_o  => data_read_ram(15 downto 8)
193
        );
194
 
195
        memory1lb: entity work.bram
196
        generic map (   memory_file => memory_file,
197
                                        data_width => 8,
198
                                        address_width => address_width,
199
                                        bank => 2)
200
        port map(
201
                clk     => clock_in,
202
                addr    => address(address_width -1 downto 2),
203
                cs_n    => ram_enable_n,
204
                we_n    => data_w_n_ram(2),
205
                data_i  => data_write(23 downto 16),
206
                data_o  => data_read_ram(23 downto 16)
207
        );
208
 
209
        memory1ub: entity work.bram
210
        generic map (   memory_file => memory_file,
211
                                        data_width => 8,
212
                                        address_width => address_width,
213
                                        bank => 3)
214
        port map(
215
                clk     => clock_in,
216
                addr    => address(address_width -1 downto 2),
217
                cs_n    => ram_enable_n,
218
                we_n    => data_w_n_ram(3),
219
                data_i  => data_write(31 downto 24),
220
                data_o  => data_read_ram(31 downto 24)
221
        );
222
 
223
        -- debug process
224
        debug:
225
        if uart_support = "no" generate
226 18 serginhofr
                process(clock_in, address_cpu)
227 13 serginhofr
                        file store_file : text open write_mode is "debug.txt";
228
                        variable hex_file_line : line;
229
                        variable c : character;
230
                        variable index : natural;
231
                        variable line_length : natural := 0;
232
                begin
233
                        if clock_in'event and clock_in = '1' then
234 18 serginhofr
                                if address_cpu = x"f00000d0" and data = '0' then
235 13 serginhofr
                                        data <= '1';
236
                                        index := conv_integer(data_write(30 downto 24));
237
                                        if index /= 10 then
238
                                                c := character'val(index);
239
                                                write(hex_file_line, c);
240
                                                line_length := line_length + 1;
241
                                        end if;
242
                                        if index = 10 or line_length >= 72 then
243
                                                writeline(store_file, hex_file_line);
244
                                                line_length := 0;
245
                                        end if;
246
                                else
247
                                        data <= '0';
248
                                end if;
249
                        end if;
250
                end process;
251
        end generate;
252
 
253
        process(clock_in, reset, address)
254
        begin
255
                if reset = '1' then
256
                elsif clock_in'event and clock_in = '0' then
257
                        assert address /= x"e0000000" report "end of simulation" severity failure;
258
                        assert (address < x"50000000") or (address >= x"f0000000") report "out of memory region" severity failure;
259
                        assert address /= x"40000100" report "handling IRQ" severity warning;
260
                end if;
261
        end process;
262
 
263
end tb;
264
 

powered by: WebSVN 2.1.0

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