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

powered by: WebSVN 2.1.0

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