]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-dad.git/blob - hw/tb/lx_dad_top_tb.vhd
Testbed updated -g option to work with latest 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          -- signal connected to external JK FF
28          event_jk_j : out std_logic;
29          -- signals to image sensor
30          phi1       : out std_logic;
31          phi2       : out std_logic;
32          phi_rst    : out std_logic;
33          LED_1      : out std_logic;
34          sck_o      : out std_logic;
35          cnv_o      : out std_logic;
36          phist      : out std_logic;
37          sck_i      : in std_logic;
38          SDI        : in std_logic
39     );
40     END COMPONENT;
41
42
43    --Inputs
44    --signal clk_cpu : std_logic := '0';
45          signal clk_50m : std_logic := '0';
46    signal cs0_xc : std_logic := '1';
47    signal rd : std_logic := '1';
48    signal bls : std_logic_vector(3 downto 0) := (others => '1');
49    signal address : std_logic_vector(15 downto 0) := (others => '0');
50
51    signal init : std_logic := '1';
52          --BiDirs
53
54    signal data : std_logic_vector(31 downto 0);
55
56    -- Clock period definitions
57          --constant clk_period_cpu : time := 13.8 ns;
58    constant clk_period_50m : time := 20 ns;
59
60    signal adc_sck : std_logic;
61
62 BEGIN
63
64    -- Instantiate the Unit Under Test (UUT)
65    uut: lx_dad_top PORT MAP (
66           --clk_cpu => clk_cpu,
67           clk_50m => clk_50m,
68           cs0_xc => cs0_xc,
69           rd => rd,
70           bls => bls,
71           address => address,
72           data => data,
73
74           init => init,
75
76           event_jk_j => open,
77           -- signals to image sensor
78           phi1       => open,
79           phi2       => open,
80           phi_rst    => open,
81           LED_1      => open,
82           sck_o      => adc_sck,
83           cnv_o      => open,
84           phist      => open,
85           sck_i      => adc_sck,
86           SDI        => adc_sck
87         );
88
89    -- Clock process definitions
90 --   clk_cpu_process :process
91 --   begin
92 --              clk_cpu <= '1';
93 --              wait for clk_period_cpu/2;
94 --              clk_cpu <= '0';
95 --              wait for clk_period_cpu/2;
96 --   end process;
97
98          clk_50m_process :process
99    begin
100                 clk_50m <= '1';
101                 wait for clk_period_50m/2;
102                 clk_50m <= '0';
103                 wait for clk_period_50m/2;
104    end process;
105
106
107    -- Stimulus process
108    stim_proc: process
109    begin
110       -- External ModelSim script
111
112       wait;
113    end process;
114
115         setup_imem_process : process
116         --      file imem_file : text open READ_MODE is "imem.bits";
117         --      variable my_line : LINE;
118         --      variable bits_line : LINE;
119         --      variable mem_location : bit_vector(31 downto 0);
120         --      variable imem_fill_addr : natural range 0 to 2**8-1 := 0;
121
122         procedure  mcu_write(
123                          constant addr: std_logic_vector(15 downto 0);
124                          constant wrdata: std_logic_vector(31 downto 0)
125                          ) is
126         begin
127                 wait until clk_50m'event and clk_50m = '1';
128                 wait until clk_50m'event and clk_50m = '0';
129                 rd <= '1';
130                 address <= addr;
131                 data <= wrdata;
132                 bls <= "0000";
133                 cs0_xc <= '0';
134                 wait until clk_50m'event and clk_50m = '1';
135                 wait until clk_50m'event and clk_50m = '1';
136                 wait until clk_50m'event and clk_50m = '1';
137                 cs0_xc <= '1';
138                 bls <= "1111";
139                 data <= (others => 'Z');
140                 wait until clk_50m'event and clk_50m = '1';
141         end mcu_write;
142
143         begin
144
145                 -- Assert LX_DAD system reset for 3 clock cycles
146                 wait until clk_50m'event and clk_50m = '1';
147                 init <= '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                 init <= '1';
152
153                 -- Fill Tumbl instruction memory
154                 --fill_loop: while not endfile(imem_file) loop
155                 --      wait until clk_50m'event and clk_50m = '1';
156                 --      cs0_xc <= '1';
157                 --      rd <= '1';
158                 --      bls <= "1111";
159                 --      wait until clk_50m'event and clk_50m = '1';
160                 --      address <= std_logic_vector(to_unsigned(imem_fill_addr, 16));
161                 --      readline(imem_file, bits_line);
162                 --      read(bits_line, mem_location);
163                 --      data <= to_stdLogicVector(mem_location);
164                 --      bls <= "0000";
165                 --      cs0_xc <= '0';
166                 --      imem_fill_addr := imem_fill_addr + 1;
167                 --      wait until clk_50m'event and clk_50m = '1';
168                 --      wait until clk_50m'event and clk_50m = '1';
169                 --      cs0_xc <= '1';
170                 --      rd <= '1';
171                 --      bls <= "1111";
172                 --end loop fill_loop;
173
174                 -- Write to example bus memory
175                 mcu_write(x"1000", x"00000000");
176
177                 mcu_write(x"1001", x"00000009"); -- 9
178                 mcu_write(x"1002", x"00000020"); -- 399
179                 mcu_write(x"1003", x"00000020"); -- 409
180                 mcu_write(x"1004", x"00000020"); -- 399
181                 mcu_write(x"1005", x"00000009"); -- 9
182                 mcu_write(x"1006", x"00000040"); -- 599
183                 mcu_write(x"1007", x"00000050"); -- 609
184                 mcu_write(x"1008", x"00002000"); -- 5023999
185                 mcu_write(x"1009", x"00000008"); -- 499
186
187                 mcu_write(x"100C", x"00000010");
188
189                 mcu_write(x"1000", x"00000009"); -- standard
190                 -- mcu_write(x"1000", x"00000011"); -- leakage
191                 -- mcu_write(x"1000", x"00000021"); -- multi
192
193                 -- Simulate external master accesses example bus memory
194                 xmem_loop: loop
195                         wait until clk_50m'event and clk_50m = '1';
196                         wait until clk_50m'event and clk_50m = '1';
197                         address <= x"0000";
198                         rd <= '0';
199                         cs0_xc <= '0';
200                         wait until clk_50m'event and clk_50m = '1';
201                         wait until clk_50m'event and clk_50m = '1';
202                         wait until clk_50m'event and clk_50m = '1';
203                         wait until clk_50m'event and clk_50m = '1';
204                         cs0_xc <= '1';
205                         rd <= '1';
206                         bls <= "1111";
207                 end loop xmem_loop;
208
209                 wait;
210
211         end process;
212
213 END;