]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - hw/tb/lx_dad_top_tb.vhd
Include testbed for simulation in GHDL.
[fpga/lx-cpu1/lx-dad.git] / hw / tb / lx_dad_top_tb.vhd
1 LIBRARY ieee;
2 USE ieee.std_logic_1164.ALL;
3 USE ieee.numeric_std.all;
4
5 LIBRARY std;
6 USE std.textio.all;
7
8 ENTITY lx_dad_top_tb IS
9 END lx_dad_top_tb;
10
11 ARCHITECTURE behavior OF lx_dad_top_tb IS
12
13     -- Component Declaration for the Unit Under Test (UUT)
14
15     COMPONENT lx_dad_top
16     PORT(
17          --clk_cpu : IN  std_logic;
18                                  clk_50m : IN  std_logic;
19          cs0_xc : IN  std_logic;
20          rd : IN  std_logic;
21          bls : IN  std_logic_vector(3 downto 0);
22          address : IN  std_logic_vector(15 downto 0);
23          data : INOUT  std_logic_vector(31 downto 0);
24
25          init : IN  std_logic
26         );
27     END COMPONENT;
28
29
30    --Inputs
31    --signal clk_cpu : std_logic := '0';
32          signal clk_50m : std_logic := '0';
33    signal cs0_xc : std_logic := '1';
34    signal rd : std_logic := '1';
35    signal bls : std_logic_vector(3 downto 0) := (others => '1');
36    signal address : std_logic_vector(15 downto 0) := (others => '0');
37
38    signal init : std_logic := '1';
39          --BiDirs
40
41    signal data : std_logic_vector(31 downto 0);
42
43    -- Clock period definitions
44          --constant clk_period_cpu : time := 13.8 ns;
45    constant clk_period_50m : time := 20 ns;
46
47 BEGIN
48
49         -- Instantiate the Unit Under Test (UUT)
50    uut: lx_dad_top PORT MAP (
51           --clk_cpu => clk_cpu,
52                                         clk_50m => clk_50m,
53           cs0_xc => cs0_xc,
54           rd => rd,
55           bls => bls,
56           address => address,
57           data => data,
58
59           init => init
60         );
61
62    -- Clock process definitions
63 --   clk_cpu_process :process
64 --   begin
65 --              clk_cpu <= '1';
66 --              wait for clk_period_cpu/2;
67 --              clk_cpu <= '0';
68 --              wait for clk_period_cpu/2;
69 --   end process;
70
71          clk_50m_process :process
72    begin
73                 clk_50m <= '1';
74                 wait for clk_period_50m/2;
75                 clk_50m <= '0';
76                 wait for clk_period_50m/2;
77    end process;
78
79
80    -- Stimulus process
81    stim_proc: process
82    begin
83       -- External ModelSim script
84
85       wait;
86    end process;
87
88         setup_imem_process : process
89         --      file imem_file : text open READ_MODE is "imem.bits";
90         --      variable my_line : LINE;
91         --      variable bits_line : LINE;
92         --      variable mem_location : bit_vector(31 downto 0);
93         --      variable imem_fill_addr : natural range 0 to 2**8-1 := 0;
94         begin
95
96                 -- Assert LX_DAD system reset for 3 clock cycles
97                 wait until clk_50m'event and clk_50m = '1';
98                 init <= '0';
99                 wait until clk_50m'event and clk_50m = '1';
100                 wait until clk_50m'event and clk_50m = '1';
101                 wait until clk_50m'event and clk_50m = '1';
102                 init <= '1';
103
104                 -- Fill Tumbl instruction memory
105                 --fill_loop: while not endfile(imem_file) loop
106                 --      wait until clk_50m'event and clk_50m = '1';
107                 --      cs0_xc <= '1';
108                 --      rd <= '1';
109                 --      bls <= "1111";
110                 --      wait until clk_50m'event and clk_50m = '1';
111                 --      address <= std_logic_vector(to_unsigned(imem_fill_addr, 16));
112                 --      readline(imem_file, bits_line);
113                 --      read(bits_line, mem_location);
114                 --      data <= to_stdLogicVector(mem_location);
115                 --      bls <= "0000";
116                 --      cs0_xc <= '0';
117                 --      imem_fill_addr := imem_fill_addr + 1;
118                 --      wait until clk_50m'event and clk_50m = '1';
119                 --      wait until clk_50m'event and clk_50m = '1';
120                 --      cs0_xc <= '1';
121                 --      rd <= '1';
122                 --      bls <= "1111";
123                 --end loop fill_loop;
124
125                 -- Write to example bus memory
126                 wait until clk_50m'event and clk_50m = '1';
127                 wait until clk_50m'event and clk_50m = '1';
128                 address <= x"0004";
129                 data <= x"12345678";
130                 bls <= "0000";
131                 cs0_xc <= '0';
132                 wait until clk_50m'event and clk_50m = '1';
133                 wait until clk_50m'event and clk_50m = '1';
134                 cs0_xc <= '1';
135                 rd <= '1';
136                 data <= x"abcdef01";
137                 bls <= "1111";
138                 data <= (others => 'Z');
139                 wait until clk_50m'event and clk_50m = '1';
140
141                 -- Simulate external master accesses example bus memory
142                 xmem_loop: loop
143                         wait until clk_50m'event and clk_50m = '1';
144                         wait until clk_50m'event and clk_50m = '1';
145                         address <= x"0000";
146                         rd <= '0';
147                         cs0_xc <= '0';
148                         wait until clk_50m'event and clk_50m = '1';
149                         wait until clk_50m'event and clk_50m = '1';
150                         wait until clk_50m'event and clk_50m = '1';
151                         wait until clk_50m'event and clk_50m = '1';
152                         cs0_xc <= '1';
153                         rd <= '1';
154                         bls <= "1111";
155
156                         wait until clk_50m'event and clk_50m = '1';
157                         wait until clk_50m'event and clk_50m = '1';
158                         address <= x"0004";
159                         rd <= '0';
160                         cs0_xc <= '0';
161                         wait until clk_50m'event and clk_50m = '1';
162                         wait until clk_50m'event and clk_50m = '1';
163                         wait until clk_50m'event and clk_50m = '1';
164                         wait until clk_50m'event and clk_50m = '1';
165                         cs0_xc <= '1';
166                         rd <= '1';
167                         bls <= "1111";
168                 end loop xmem_loop;
169
170                 wait;
171
172         end process;
173
174 END;