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

Subversion Repositories hf-risc

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

powered by: WebSVN 2.1.0

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