OpenCores
URL https://opencores.org/ocsvn/mblite/mblite/trunk

Subversion Repositories mblite

[/] [mblite/] [trunk/] [designs/] [core/] [testbench.vhd] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 takar
----------------------------------------------------------------------------------------------
2
--
3
--      Input file         : config_Pkg.vhd
4
--      Design name        : config_Pkg
5
--      Author             : Tamar Kranenburg
6
--      Company            : Delft University of Technology
7
--                         : Faculty EEMCS, Department ME&CE
8
--                         : Systems and Circuits group
9
--
10
--      Description        : Testbench instantiates core, data memory and instruction memory,
11
--                           together with a character device.
12
--
13
----------------------------------------------------------------------------------------------
14
 
15 8 takar
library ieee;
16
use ieee.std_logic_1164.all;
17
use ieee.std_logic_unsigned.all;
18 2 takar
 
19 8 takar
library std;
20
use std.textio.all;
21 2 takar
 
22 8 takar
library mblite;
23
use mblite.config_Pkg.all;
24
use mblite.core_Pkg.all;
25
use mblite.std_Pkg.all;
26 2 takar
 
27 8 takar
entity testbench is
28
end testbench;
29 2 takar
 
30 8 takar
architecture arch of testbench is
31 2 takar
 
32 8 takar
    signal dmem_o : dmem_out_type;
33
    signal imem_o : imem_out_type;
34
    signal dmem_i : dmem_in_type;
35
    signal imem_i : imem_in_type;
36 2 takar
 
37 8 takar
    signal sys_clk_i : std_logic := '0';
38
    signal sys_int_i : std_logic := '0';
39
    signal sys_rst_i : std_logic := '0';
40
    signal sys_ena_i : std_logic := '1';
41 2 takar
 
42 8 takar
    constant std_out_adr : std_logic_vector(CFG_DMEM_SIZE - 1 downto 0) := X"FFFFFFC0";
43
    constant rom_size    : integer := 16;
44
    constant ram_size    : integer := 16;
45 2 takar
 
46 8 takar
    signal mem_enable : std_logic;
47
    signal chr_enable : std_logic;
48
    signal chr_read   : std_logic;
49
    signal sel_o      : std_logic_vector(3 downto 0);
50
    signal mem_dat    : std_logic_vector(31 downto 0);
51
    signal chr_dat    : std_logic_vector(31 downto 0);
52
    signal chr_cnt    : integer := 0;
53 2 takar
 
54
BEGIN
55
 
56 8 takar
    sys_clk_i <= not sys_clk_i after 10000 ps;
57
    sys_rst_i <= '1' after 0 ps, '0' after  150000 ps;
58
    sys_int_i <= '1' after 500000000 ps, '0' after 500040000 ps;
59 2 takar
 
60
 
61
    dmem_i.ena_i <= sys_ena_i;
62 8 takar
    sel_o <= dmem_o.sel_o when dmem_o.we_o = '1' else (others => '0');
63 2 takar
 
64 8 takar
    mem_enable <= not sys_rst_i and dmem_o.ena_o and not compare(dmem_o.adr_o, std_out_adr);
65
    chr_enable <= not sys_rst_i and dmem_o.ena_o and compare(dmem_o.adr_o, std_out_adr);
66 2 takar
 
67 8 takar
    dmem_i.dat_i <= chr_dat when chr_read = '1' else mem_dat;
68 2 takar
 
69
    -- Character device
70 8 takar
    stdio: process(sys_clk_i)
71
        variable s    : line;
72
        variable byte : std_logic_vector(7 downto 0);
73
        variable char : character;
74
    begin
75
        if rising_edge(sys_clk_i) then
76
            if chr_enable = '1' then
77
                if dmem_o.we_o = '1' then
78 2 takar
                -- WRITE STDOUT
79 8 takar
                    case dmem_o.sel_o is
80
                        when "0001" => byte := dmem_o.dat_o( 7 downto  0);
81
                        when "0010" => byte := dmem_o.dat_o(15 downto  8);
82
                        when "0100" => byte := dmem_o.dat_o(23 downto 16);
83
                        when "1000" => byte := dmem_o.dat_o(31 downto 24);
84
                        when others => null;
85
                    end case;
86 2 takar
                    char := character'val(my_conv_integer(byte));
87 8 takar
                    if byte = X"0D" then
88 2 takar
                        -- Ignore character 13
89 8 takar
                    elsif byte = X"0A" then
90 2 takar
                        -- Writeline on character 10 (newline)
91
                        writeline(output, s);
92 8 takar
                    else
93 2 takar
                        -- Write to buffer
94
                        write(s, char);
95 8 takar
                    end if;
96 2 takar
                    chr_read <= '0';
97 8 takar
                else
98 2 takar
                    chr_read <= '1';
99 8 takar
                    if chr_cnt = 0 then
100 2 takar
                        chr_cnt <= 1;
101
                        chr_dat <= X"4C4C4C4C";
102 8 takar
                    elsif chr_cnt = 1 then
103 2 takar
                        chr_cnt <= 2;
104
                        chr_dat <= X"4D4D4D4D";
105 8 takar
                    elsif chr_cnt = 2 then
106 2 takar
                        chr_cnt <= 3;
107
                        chr_dat <= X"4E4E4E4E";
108 8 takar
                    elsif chr_cnt = 3 then
109 2 takar
                        chr_cnt <= 0;
110
                        chr_dat <= X"0A0A0A0A";
111 8 takar
                    end if;
112
                end if;
113
            else
114 2 takar
                chr_read <= '0';
115 8 takar
            end if;
116
        end if;
117 2 takar
 
118 8 takar
    end process;
119 2 takar
 
120
    -- Warning: an infinite loop like while(1) {} triggers this timeout too!
121
    -- disable this feature when a premature finish occur.
122 8 takar
    timeout: process(sys_clk_i)
123
    begin
124
        if now = 10 ms then
125
            report "TIMEOUT" severity FAILURE;
126
        end if;
127 2 takar
        -- BREAK ON EXIT (0xB8000000)
128 8 takar
        if compare(imem_i.dat_i, "10111000000000000000000000000000") = '1' then
129 2 takar
            -- Make sure the simulator finishes when an error is encountered.
130
            -- For modelsim: see menu Simulate -> Runtime options -> Assertions
131 8 takar
            report "FINISHED" severity FAILURE;
132
        end if;
133
    end process;
134 2 takar
 
135 8 takar
    imem : sram generic map
136 2 takar
    (
137
        WIDTH => CFG_IMEM_WIDTH,
138
        SIZE => rom_size - 2
139
    )
140 8 takar
    port map
141 2 takar
    (
142
        dat_o => imem_i.dat_i,
143
        dat_i => "00000000000000000000000000000000",
144 8 takar
        adr_i => imem_o.adr_o(rom_size - 1 downto 2),
145 2 takar
        wre_i => '0',
146
        ena_i => imem_o.ena_o,
147
        clk_i => sys_clk_i
148
    );
149
 
150 8 takar
    dmem : sram_4en generic map
151 2 takar
    (
152
        WIDTH => CFG_DMEM_WIDTH,
153
        SIZE => ram_size - 2
154
    )
155 8 takar
    port map
156 2 takar
    (
157
        dat_o => mem_dat,
158
        dat_i => dmem_o.dat_o,
159 8 takar
        adr_i => dmem_o.adr_o(ram_size - 1 downto 2),
160 2 takar
        wre_i => sel_o,
161
        ena_i => mem_enable,
162
        clk_i => sys_clk_i
163
    );
164
 
165 8 takar
    core0 : core port map
166 2 takar
    (
167
        imem_o => imem_o,
168
        dmem_o => dmem_o,
169
        imem_i => imem_i,
170
        dmem_i => dmem_i,
171
        int_i  => sys_int_i,
172
        rst_i  => sys_rst_i,
173
        clk_i  => sys_clk_i
174
    );
175
 
176 8 takar
end arch;
177 2 takar
 
178
----------------------------------------------------------------------------------------------
179
-- USE CONFIGURATIONS INSTEAD OF GENERICS TO IMPLEMENT - FOR EXAMPLE - DIFFERENT MEMORIES.
180
-- CONFIGURATIONS CAN HIERARCHICALLY INVOKE OTHER CONFIGURATIONS TO REDUCE THE SIZE OF THE
181
-- CONFIGURATION DECLARATION
182
----------------------------------------------------------------------------------------------
183 8 takar
configuration tb_conf_example of testbench is
184
    for arch
185
        for all: sram_4en
186
            use entity mblite.sram_4en(arch);
187
        end for;
188
    end for;
189
end tb_conf_example;

powered by: WebSVN 2.1.0

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