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

Subversion Repositories mblite

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

Go to most recent revision | 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
LIBRARY ieee;
16
USE ieee.std_logic_1164.ALL;
17
USE ieee.std_logic_unsigned.ALL;
18
 
19
LIBRARY std;
20
USE std.textio.ALL;
21
 
22
LIBRARY mblite;
23
USE mblite.config_Pkg.ALL;
24
USE mblite.core_Pkg.ALL;
25
USE mblite.std_Pkg.ALL;
26
 
27
ENTITY testbench IS
28
END testbench;
29
 
30
ARCHITECTURE arch OF testbench IS
31
 
32
    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
 
37
    SIGNAL sys_clk_i : std_ulogic := '0';
38
    SIGNAL sys_int_i : std_ulogic := '0';
39
    SIGNAL sys_rst_i : std_ulogic := '0';
40
    SIGNAL sys_ena_i : std_ulogic := '1';
41
 
42
    CONSTANT std_out_adr : std_ulogic_vector(CFG_DMEM_SIZE - 1 DOWNTO 0) := X"FFFFFFC0";
43
    CONSTANT rom_size : integer := 16;
44
    CONSTANT ram_size : integer := 16;
45
 
46
    SIGNAL mem_enable : std_ulogic;
47
    SIGNAL chr_enable : std_ulogic;
48
    SIGNAL chr_read : std_ulogic;
49
    SIGNAL sel_o : std_ulogic_vector(3 DOWNTO 0);
50
    SIGNAL mem_dat : std_ulogic_vector(31 DOWNTO 0);
51
    SIGNAL chr_dat : std_ulogic_vector(31 DOWNTO 0);
52
    SIGNAL chr_cnt : integer := 0;
53
 
54
BEGIN
55
 
56
    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
 
60
 
61
    dmem_i.ena_i <= sys_ena_i;
62
    sel_o <= dmem_o.sel_o WHEN dmem_o.we_o = '1' ELSE (OTHERS => '0');
63
 
64
    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
 
67
    dmem_i.dat_i <= chr_dat WHEN chr_read = '1' ELSE mem_dat;
68
 
69
    -- Character device
70
    stdio: PROCESS(sys_clk_i)
71
        VARIABLE s    : line;
72
        VARIABLE byte : std_ulogic_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
                -- WRITE STDOUT
79
                    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
                    char := character'val(my_conv_integer(byte));
87
                    IF byte = X"0D" THEN
88
                        -- Ignore character 13
89
                    ELSIF byte = X"0A" THEN
90
                        -- Writeline on character 10 (newline)
91
                        writeline(output, s);
92
                    ELSE
93
                        -- Write to buffer
94
                        write(s, char);
95
                    END IF;
96
                    chr_read <= '0';
97
                ELSE
98
                    chr_read <= '1';
99
                    IF chr_cnt = 0 THEN
100
                        chr_cnt <= 1;
101
                        chr_dat <= X"4C4C4C4C";
102
                    ELSIF chr_cnt = 1 THEN
103
                        chr_cnt <= 2;
104
                        chr_dat <= X"4D4D4D4D";
105
                    ELSIF chr_cnt = 2 THEN
106
                        chr_cnt <= 3;
107
                        chr_dat <= X"4E4E4E4E";
108
                    ELSIF chr_cnt = 3 THEN
109
                        chr_cnt <= 0;
110
                        chr_dat <= X"0A0A0A0A";
111
                    END IF;
112
                END IF;
113
            ELSE
114
                chr_read <= '0';
115
            END IF;
116
        END IF;
117
 
118
    END PROCESS;
119
 
120
    -- Warning: an infinite loop like while(1) {} triggers this timeout too!
121
    -- disable this feature when a premature finish occur.
122
    timeout: PROCESS(sys_clk_i)
123
    BEGIN
124
        IF NOW = 10 ms THEN
125
            REPORT "TIMEOUT" SEVERITY FAILURE;
126
        END IF;
127
        -- BREAK ON EXIT (0xB8000000)
128
        IF compare(imem_i.dat_i, "10111000000000000000000000000000") = '1' THEN
129
            -- Make sure the simulator finishes when an error is encountered.
130
            -- For modelsim: see menu Simulate -> Runtime options -> Assertions
131
            REPORT "FINISHED" SEVERITY FAILURE;
132
        END IF;
133
    END PROCESS;
134
 
135
    imem : sram GENERIC MAP
136
    (
137
        WIDTH => CFG_IMEM_WIDTH,
138
        SIZE => rom_size - 2
139
    )
140
    PORT MAP
141
    (
142
        dat_o => imem_i.dat_i,
143
        dat_i => "00000000000000000000000000000000",
144
        adr_i => imem_o.adr_o(rom_size - 1 DOWNTO 2),
145
        wre_i => '0',
146
        ena_i => imem_o.ena_o,
147
        clk_i => sys_clk_i
148
    );
149
 
150
    dmem : sram_4en GENERIC MAP
151
    (
152
        WIDTH => CFG_DMEM_WIDTH,
153
        SIZE => ram_size - 2
154
    )
155
    PORT MAP
156
    (
157
        dat_o => mem_dat,
158
        dat_i => dmem_o.dat_o,
159
        adr_i => dmem_o.adr_o(ram_size - 1 DOWNTO 2),
160
        wre_i => sel_o,
161
        ena_i => mem_enable,
162
        clk_i => sys_clk_i
163
    );
164
 
165
    core0 : core PORT MAP
166
    (
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
END arch;
177
 
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
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.