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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [tb/] [mips_tb.vhdl] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 193 ja_rd
--##############################################################################
2
-- Simulation test bench -- not synthesizable.
3
--
4
-- Simulates the MCU core connected to a simulated external static RAM on a 
5
-- 16-bit bus, plus an optional 8-bit static ROM. This setup is more or less 
6
-- that of develoment board DE-1 from Terasic.
7
--------------------------------------------------------------------------------
8
-- Console logging:
9
--
10
-- Console output (at addresses compatible to Plasma's) is logged to text file
11
-- "hw_sim_console_log.txt".
12
--
13
-- IMPORTANT: The code that echoes UART TX data to the simulation console does
14
-- line buffering; it will not print anything until it gets a CR (0x0d), and
15
-- will ifnore LFs (0x0a). Bear this in mind if you see no output when you 
16
-- expect it.
17
--
18
-- Console logging is done by monitoring CPU writes to the UART, NOT by looking
19
-- at the TxD pin. It will NOT catch baud-related problems, etc.
20
--------------------------------------------------------------------------------
21
-- WARNING: Will only work on Modelsim; uses custom library SignalSpy.
22
--##############################################################################
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
use ieee.std_logic_arith.all;
27
use ieee.std_logic_unsigned.all;
28
use std.textio.all;
29
 
30
use work.mips_pkg.all;
31
use work.mips_tb_pkg.all;
32
use work.sim_params_pkg.all;
33
use work.txt_util.all;
34
 
35
entity mips_tb is
36
end;
37
 
38
 
39
architecture testbench of mips_tb is
40
 
41
-- NOTE: simulation parameters are defined in sim_params_pkg
42
 
43
 
44
-- External SRAM and interface signals -----------------------------------------
45
 
46
signal sram1 : t_sram := ( others => X"00");
47
signal sram0 : t_sram := ( others => X"00");
48
 
49
signal sram_chip_addr :     std_logic_vector(SRAM_ADDR_SIZE downto 1);
50
signal sram_output :        std_logic_vector(15 downto 0);
51
 
52
 
53
-- PROM table and interface signals --------------------------------------------
54
 
55
-- We'll simulate a 16-bit-wide static PROM (e.g. a Flash) with some serious
56
-- cycle time (70 or 90 ns).
57
 
58
signal prom_rd_addr :       t_prom_address;
59
signal prom_output :        std_logic_vector(7 downto 0);
60
signal prom_oe_n :          std_logic;
61
 
62
signal prom : t_prom := ( PROM_DATA );
63
 
64
 
65
 
66
-- I/O devices -----------------------------------------------------------------
67
 
68
signal data_uart :          std_logic_vector(31 downto 0);
69
signal data_uart_status :   std_logic_vector(31 downto 0);
70
signal uart_tx_rdy :        std_logic := '1';
71
signal uart_rx_rdy :        std_logic := '1';
72
 
73
--------------------------------------------------------------------------------
74
 
75
signal clk :                std_logic := '0';
76
signal reset :              std_logic := '1';
77
signal interrupt :          std_logic := '0';
78
signal done :               std_logic := '0';
79
 
80
-- interface to asynchronous 16-bit-wide external SRAM
81
signal mpu_sram_address :   t_word;
82
signal mpu_sram_data_rd :   std_logic_vector(15 downto 0);
83
signal mpu_sram_data_wr :   std_logic_vector(15 downto 0);
84
signal mpu_sram_byte_we_n : std_logic_vector(1 downto 0);
85
signal mpu_sram_oe_n :      std_logic;
86
 
87
-- interface to i/o
88
signal io_rd_data :         std_logic_vector(31 downto 0);
89
signal io_wr_data :         std_logic_vector(31 downto 0);
90
signal io_rd_addr :         std_logic_vector(31 downto 2);
91
signal io_wr_addr :         std_logic_vector(31 downto 2);
92
signal io_rd_vma :          std_logic;
93
signal io_byte_we :         std_logic_vector(3 downto 0);
94
 
95
signal rxd :                std_logic;
96
signal txd :                std_logic;
97
 
98
 
99
--------------------------------------------------------------------------------
100
-- Logging signals
101
 
102
 
103
-- Log file
104
file log_file: TEXT open write_mode is "hw_sim_log.txt";
105
 
106
-- Console output log file
107
file con_file: TEXT open write_mode is "hw_sim_console_log.txt";
108
 
109
-- All the info needed by the logger is here
110
signal log_info :           t_log_info;
111
 
112
-- Debug signals ---------------------------------------------------------------
113
 
114
 
115
 
116
begin
117
 
118
    -- UUT instantiation -------------------------------------------------------
119
    mpu: entity work.mips_mpu
120
    generic map (
121
        CLOCK_FREQ     => 50000000,
122
        SRAM_ADDR_SIZE => 32
123
    )
124
    port map (
125
        interrupt       => '0',
126
 
127
        -- interface to FPGA i/o devices
128
        io_rd_data      => io_rd_data,
129
        io_rd_addr      => io_rd_addr,
130
        io_wr_addr      => io_wr_addr,
131
        io_wr_data      => io_wr_data,
132
        io_rd_vma       => io_rd_vma,
133
        io_byte_we      => io_byte_we,
134
 
135
        -- interface to asynchronous 16-bit-wide EXTERNAL SRAM
136
        sram_address    => mpu_sram_address,
137
        sram_data_rd    => mpu_sram_data_rd,
138
        sram_data_wr    => mpu_sram_data_wr,
139
        sram_byte_we_n  => mpu_sram_byte_we_n,
140
        sram_oe_n       => mpu_sram_oe_n,
141
 
142
        uart_rxd        => rxd,
143
        uart_txd        => txd,
144
 
145
        debug_info      => OPEN,
146
 
147
        clk             => clk,
148
        reset           => reset
149
    );
150
 
151
 
152
    -- Master clock: free running clock used as main module clock --------------
153
    run_master_clock:
154
    process(done, clk)
155
    begin
156
        if done = '0' then
157
            clk <= not clk after T/2;
158
        end if;
159
    end process run_master_clock;
160
 
161
    -- Main simulation process: reset MCU and wait for fixed period ------------
162
    drive_uut:
163
    process
164
    variable l : line;
165
    begin
166
        wait for T*4;
167
        reset <= '0';
168
 
169
        wait for T*SIMULATION_LENGTH;
170
 
171
        -- Flush console output to log console file (in case the end of the
172
        -- simulation caugh an unterminated line in the buffer)
173
        if log_info.con_line_ix > 1 then
174
            write(l, log_info.con_line_buf(1 to log_info.con_line_ix));
175
            writeline(con_file, l);
176
        end if;
177
 
178
        print("TB finished");
179
        done <= '1';
180
        wait;
181
 
182
    end process drive_uut;
183
 
184
 
185
 
186
    -- SRAM/FLASH mux (on a real board this would be a simple address decoder)
187
    mpu_sram_data_rd <=
188
        X"00" & prom_output when mpu_sram_address(31 downto 27)="10110" else
189
        sram_output;
190
 
191
 
192
    -- Do a very basic simulation of an external SRAM --------------------------
193
 
194
    sram_chip_addr <= mpu_sram_address(SRAM_ADDR_SIZE downto 1);
195
 
196
    -- FIXME should add some verification of /WE 
197
    sram_output <=
198
        sram1(conv_integer(unsigned(sram_chip_addr))) &
199
        sram0(conv_integer(unsigned(sram_chip_addr)))   when mpu_sram_oe_n='0'
200
        else (others => 'Z');
201
 
202
    simulated_sram_write:
203
    process(mpu_sram_byte_we_n, mpu_sram_address, mpu_sram_oe_n)
204
    begin
205
        -- Write cycle
206
        -- FIXME should add OE\ to write control logic
207
        if mpu_sram_byte_we_n'event or mpu_sram_address'event then
208
            if mpu_sram_byte_we_n(1)='0' then
209
                sram1(conv_integer(unsigned(sram_chip_addr))) <= mpu_sram_data_wr(15 downto  8);
210
            end if;
211
            if mpu_sram_byte_we_n(0)='0' then
212
                sram0(conv_integer(unsigned(sram_chip_addr))) <= mpu_sram_data_wr( 7 downto  0);
213
            end if;
214
        end if;
215
    end process simulated_sram_write;
216
 
217
 
218
    -- Do a very basic simulation of an external PROM (FLASH) ------------------
219
    -- (wired to the same bus as the sram and both are static).
220
 
221
    prom_rd_addr <= mpu_sram_address(PROM_ADDR_SIZE+1 downto 2);
222
 
223
    prom_oe_n <= mpu_sram_oe_n;
224
 
225
    prom_output <=
226
        prom(conv_integer(unsigned(prom_rd_addr)))(31 downto 24) when prom_oe_n='0' and mpu_sram_address(1 downto 0)="00" else
227
        prom(conv_integer(unsigned(prom_rd_addr)))(23 downto 16) when prom_oe_n='0' and mpu_sram_address(1 downto 0)="01" else
228
        prom(conv_integer(unsigned(prom_rd_addr)))(15 downto  8) when prom_oe_n='0' and mpu_sram_address(1 downto 0)="10" else
229
        prom(conv_integer(unsigned(prom_rd_addr)))( 7 downto  0) when prom_oe_n='0' and mpu_sram_address(1 downto 0)="11" else
230
        (others => 'Z');
231
 
232
 
233
    -- Simulate dummy I/O traffic external to the MCU --------------------------
234
    -- FIXME console logging missing! IO too!
235
 
236
    -- This is useless (the simulated UART will not be actually used)
237
    -- but at least prevents the simulator from optimizing the logic away.
238
    rxd <= txd;
239
 
240
 
241
    -- Logging process: launch logger function ---------------------------------
242
    log_execution:
243
    process
244
    begin
245
        log_cpu_activity(clk, reset, done,
246
                         "mips_tb/mpu", "cpu",
247
                         log_info, "log_info",
248
                         LOG_TRIGGER_ADDRESS, log_file, con_file);
249
        wait;
250
    end process log_execution;
251
 
252
 
253
end architecture testbench;

powered by: WebSVN 2.1.0

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