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

Subversion Repositories light52

[/] [light52/] [trunk/] [boards/] [terasic_de1/] [vhdl/] [c2sb_soc_tb.vhdl] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 ja_rd
--------------------------------------------------------------------------------
2
-- c2sb_soc_tb.vhdl -- Minimal test bench for c2sb_soc.
3
--
4
-- c2sb_soc is a light52 MCU demo on a Cyclone 2 starter Board (C2SB). This
5
-- is a minimalistic simulation test bench. The test bench only drives the clock
6
-- and reset inputs.
7
--
8
-- This simulation test bench can be marginally useful for basic troubleshooting
9
-- of a C2SB board demo or as a starting point for a true test bench.
10
--------------------------------------------------------------------------------
11
 
12
library ieee;
13
use ieee.std_logic_1164.ALL;
14
use ieee.std_logic_unsigned.all;
15
use ieee.numeric_std.ALL;
16
use std.textio.all;
17
 
18
use work.light52_tb_pkg.all;
19
use work.txt_util.all;
20
 
21
 
22
entity c2sb_soc_tb is
23
end entity c2sb_soc_tb;
24
 
25
architecture testbench of c2sb_soc_tb is
26
 
27
--------------------------------------------------------------------------------
28
-- Simulation parameters
29
 
30
-- T: simulated clock period (50MHz)
31
constant T : time := 20 ns;
32
 
33
-- SIMULATION_LENGTH: maximum simulation time in clock cycles 
34
constant SIMULATION_LENGTH : natural := 99000000; -- enough for most purposes
35
 
36
-- Size of ROM, as defined in the top file. Used to catch stray jumps.
37
constant ROM_SIZE : natural := 16384;
38
 
39
 
40
--------------------------------------------------------------------------------
41
-- FPGA interface & simulation signals
42
 
43
signal clk :                std_logic := '0';
44
signal reset :              std_logic;
45
signal done :               std_logic := '0';
46
signal buttons :            std_logic_vector(3 downto 0);
47
signal switches :           std_logic_vector(9 downto 0);
48
signal green_leds :         std_logic_vector(7 downto 0);
49
signal txd :                std_logic;
50
 
51
 
52
--------------------------------------------------------------------------------
53
-- Logging signals
54
 
55
-- Log file
56
file log_file: TEXT open write_mode is "hw_sim_log.txt";
57
-- Console output log file
58
file con_file: TEXT open write_mode is "hw_sim_console_log.txt";
59
-- Info record needed by the logging fuctions
60
signal log_info :           t_log_info;
61
 
62
 
63
begin
64
 
65
---- UUT instantiation ---------------------------------------------------------
66
 
67
  -- We're leaving unconnected all the FPGA pins that ars not used in the demo
68
    uut: entity work.c2sb_soc
69
    port map (
70
        clk_50MHz =>        clk,
71
        buttons =>          buttons,
72
        switches =>         switches,
73
        rxd =>              txd,
74
        txd =>              txd,
75
 
76
        flash_data =>       (others => '0'),
77
        sd_data =>          '0',
78
        green_leds =>       green_leds
79
    );
80
 
81
    -- The reset signal is used by the logging functions only.
82
    reset <= not switches(9);
83
 
84
 
85
    ---- Master clock: free running clock used as main module clock ------------
86
    run_master_clock:
87
    process(done, clk)
88
    begin
89
        if done = '0' then
90
            clk <= not clk after T/2;
91
        end if;
92
    end process run_master_clock;
93
 
94
    ---- Main simulation process: reset MCU and wait for fixed period ----------
95
 
96
    drive_uut:
97
    process
98
    begin
99
        switches <= (others => '0');
100
        -- Leave reset asserted for a few clock cycles...
101
        switches(9) <= '0';
102
        wait for T*4;
103
        switches(9) <= '1';
104
 
105
        -- ...and wait for the test to hit a termination condition (evaluated by
106
        -- function log_cpu_activity) or to just timeout.
107
        wait for T * SIMULATION_LENGTH;
108
 
109
        -- If we arrive here, the simulation timed out (termination conditions
110
        -- trigger a failed assertion).
111
        -- So print a timeout message and quit.
112
        print("TB timed out.");
113
        done <= '1';
114
        wait;
115
 
116
    end process drive_uut;
117
 
118
 
119
    -- Logging process: launch logger functions --------------------------------
120
    log_execution:
121
    process
122
    begin
123
        -- Log cpu activity until done='1'.
124
        log_cpu_activity(clk, reset, done, "/uut/mcu",
125
                         log_info, ROM_SIZE, "log_info",
126
                         X"0000", log_file, con_file);
127
 
128
        -- Flush console log file when finished.
129
        log_flush_console(log_info, con_file);
130
 
131
        wait;
132
    end process log_execution;
133
 
134
end testbench;

powered by: WebSVN 2.1.0

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