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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [work/] [tb/] [riscv_soc_tb.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
-----------------------------------------------------------------------------
2
--! @file
3
--! @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved.
4
--! @author    Sergey Khabarov - sergeykhbr@gmail.com
5
--! @brief     Testbench file for the SoC top-level implementation
6
------------------------------------------------------------------------------
7
 
8
library ieee;
9
use ieee.std_logic_1164.all;
10
library std;
11
use std.textio.all;
12
library commonlib;
13
use commonlib.types_util.all;
14
library rocketlib;
15
--use rocketlib.types_rocket.all;
16
 
17
entity riscv_soc_tb is
18
  constant INCR_TIME : time := 3571 ps;--100 ns;--3571 ps;
19
end riscv_soc_tb;
20
 
21
architecture behavior of riscv_soc_tb is
22
  -- input/output signals:
23
  signal i_rst : std_logic := '1';
24
  signal i_sclk_p : std_logic;
25
  signal i_sclk_n : std_logic;
26
  signal i_dip : std_logic_vector(3 downto 0);
27
  signal o_led : std_logic_vector(7 downto 0);
28
  signal i_uart1_ctsn : std_logic := '0';
29
  signal i_uart1_rd : std_logic := '1';
30
  signal o_uart1_td : std_logic;
31
  signal o_uart1_rtsn : std_logic;
32
  signal i_uart2_ctsn : std_logic := '0';
33
  signal i_uart2_rd : std_logic := '1';
34
  signal o_uart2_td : std_logic;
35
  signal o_uart2_rtsn : std_logic;
36
 
37
  signal o_emdc    : std_logic;
38
  signal io_emdio  : std_logic;
39
  signal i_rxd  : std_logic_vector(3 downto 0) := "0000";
40
  signal i_rxdv : std_logic := '0';
41
  signal o_txd  : std_logic_vector(3 downto 0);
42
  signal o_txdv : std_logic;
43
 
44
  signal uart_wr_str : std_logic;
45
  signal uart_instr : string(1 to 256);
46
  signal uart_busy : std_logic;
47
  signal uart_bin_data : std_logic_vector(63 downto 0);
48
  signal uart_bin_bytes_sz : integer;
49
 
50
  signal jtag_test_ena : std_logic;
51
  signal jtag_test_burst : std_logic_vector(7 downto 0);
52
  signal jtag_test_addr : std_logic_vector(31 downto 0);
53
  signal jtag_test_we : std_logic;
54
  signal jtag_test_wdata : std_logic_vector(31 downto 0);
55
  signal jtag_tdi : std_logic;
56
  signal jtag_tdo : std_logic;
57
  signal jtag_tms : std_logic;
58
  signal jtag_tck : std_logic;
59
  signal jtag_ntrst : std_logic;
60
 
61
  signal clk_cur: std_logic := '1';
62
  signal check_clk_bus : std_logic := '0';
63
  signal iClkCnt : integer := 0;
64
  signal iErrCnt : integer := 0;
65
  signal iErrCheckedCnt : integer := 0;
66
  signal iEdclCnt : integer := 0;
67
 
68
component riscv_soc is port
69
(
70
  i_rst     : in std_logic; -- button "Center"
71
  i_sclk_p  : in std_logic;
72
  i_sclk_n  : in std_logic;
73
  i_dip     : in std_logic_vector(3 downto 0);
74
  o_led     : out std_logic_vector(7 downto 0);
75
  --! JTAG signals:
76
  i_jtag_tck : in std_logic;
77
  i_jtag_ntrst : in std_logic;
78
  i_jtag_tms : in std_logic;
79
  i_jtag_tdi : in std_logic;
80
  o_jtag_tdo : out std_logic;
81
  o_jtag_vref : out std_logic;
82
  -- uart1
83
  i_uart1_ctsn : in std_logic;
84
  i_uart1_rd   : in std_logic;
85
  o_uart1_td   : out std_logic;
86
  o_uart1_rtsn : out std_logic;
87
  -- uart2 (debug port)
88
  i_uart2_ctsn : in std_logic;
89
  i_uart2_rd   : in std_logic;
90
  o_uart2_td   : out std_logic;
91
  o_uart2_rtsn : out std_logic;
92
  -- Ethernet
93
  i_gmiiclk_p : in    std_ulogic;
94
  i_gmiiclk_n : in    std_ulogic;
95
  o_egtx_clk  : out   std_ulogic;
96
  i_etx_clk   : in    std_ulogic;
97
  i_erx_clk   : in    std_ulogic;
98
  i_erxd      : in    std_logic_vector(3 downto 0);
99
  i_erx_dv    : in    std_ulogic;
100
  i_erx_er    : in    std_ulogic;
101
  i_erx_col   : in    std_ulogic;
102
  i_erx_crs   : in    std_ulogic;
103
  i_emdint    : in std_ulogic;
104
  o_etxd      : out   std_logic_vector(3 downto 0);
105
  o_etx_en    : out   std_ulogic;
106
  o_etx_er    : out   std_ulogic;
107
  o_emdc      : out   std_ulogic;
108
  io_emdio    : inout std_logic;
109
  o_erstn     : out   std_ulogic
110
);
111
end component;
112
 
113
  component uart_sim is
114
  generic (
115
    clock_rate : integer := 10;
116
    binary_bytes_max : integer := 8;
117
    use_binary : boolean := false
118
  );
119
  port (
120
    rst : in std_logic;
121
    clk : in std_logic;
122
    wr_str : in std_logic;
123
    instr : in string;
124
    bin_data : in std_logic_vector(8*binary_bytes_max-1 downto 0);
125
    bin_bytes_sz : in integer;
126
    td  : in std_logic;
127
    rtsn : in std_logic;
128
    rd  : out std_logic;
129
    ctsn : out std_logic;
130
    busy : out std_logic
131
  );
132
  end component;
133
 
134
  component ethphy_sim is
135
  port (
136
    rst : in std_logic;
137
    clk : in std_logic;
138
    o_rxd  : out std_logic_vector(3 downto 0);
139
    o_rxdv : out std_logic
140
  );
141
  end component;
142
 
143
  component jtag_sim is
144
  generic (
145
    clock_rate : integer := 10;
146
    irlen : integer := 4
147
  );
148
  port (
149
    rst : in std_logic;
150
    clk : in std_logic;
151
    i_test_ena : in std_logic;
152
    i_test_burst : in std_logic_vector(7 downto 0);
153
    i_test_addr : in std_logic_vector(31 downto 0);
154
    i_test_we : in std_logic;
155
    i_test_wdata : in std_logic_vector(31 downto 0);
156
    i_tdi  : in std_logic;
157
    o_tck : out std_logic;
158
    o_ntrst : out std_logic;
159
    o_tms : out std_logic;
160
    o_tdo : out std_logic
161
  );
162
  end component;
163
begin
164
 
165
  -- Process of reading
166
  procReadingFile : process
167
    variable clk_next: std_logic;
168
  begin
169
 
170
    wait for INCR_TIME;
171
 
172
    while true loop
173
      clk_next := not clk_cur;
174
      if (clk_next = '1' and clk_cur = '0') then
175
        check_clk_bus <= '1';
176
      end if;
177
 
178
      wait for 1 ps;
179
      check_clk_bus <= '0';
180
      clk_cur <= clk_next;
181
 
182
      wait for INCR_TIME;
183
      if clk_cur = '1' then
184
        iClkCnt <= iClkCnt + 1;
185
      end if;
186
 
187
    end loop;
188
    report "Total clocks checked: " & tost(iErrCheckedCnt) & " Errors: " & tost(iErrCnt);
189
    wait for 1 sec;
190
  end process procReadingFile;
191
 
192
 
193
  i_sclk_p <= clk_cur;
194
  i_sclk_n <= not clk_cur;
195
 
196
  procSignal : process (i_sclk_p, iClkCnt)
197
 
198
  begin
199
    if rising_edge(i_sclk_p) then
200
 
201
      --! @note to make sync. reset  of the logic that are clocked by
202
      --!       htif_clk which is clock/512 by default.
203
      if iClkCnt = 15 then
204
        i_rst <= '0';
205
      end if;
206
    end if;
207
  end process procSignal;
208
 
209
  i_dip <= "0001";
210
 
211
  udatagen0 : process (i_sclk_n, iClkCnt)
212
  begin
213
    if rising_edge(i_sclk_n) then
214
        uart_wr_str <= '0';
215
        if iClkCnt = 82000 then
216
           uart_wr_str <= '1';
217
           uart_instr(1 to 4) <= "ping";
218
           uart_instr(5) <= cr;
219
           uart_instr(6) <= lf;
220
        elsif iClkCnt = 108000 then
221
           uart_wr_str <= '1';
222
           uart_instr(1 to 3) <= "pnp";
223
           uart_instr(4) <= cr;
224
           uart_instr(5) <= lf;
225
        end if;
226
 
227
        jtag_test_ena <= '0';
228
        if iClkCnt = 3000 then
229
           jtag_test_ena <= '1';
230
           jtag_test_burst <= (others => '0');
231
           jtag_test_addr <= X"10000000";
232
           jtag_test_we <= '0';
233
           jtag_test_wdata <= (others => '0');
234
        elsif iClkCnt = 5000 then
235
           jtag_test_ena <= '1';
236
           jtag_test_burst <= (others => '0');
237
           jtag_test_addr <= X"fffff004";
238
           jtag_test_we <= '1';
239
           jtag_test_wdata <= X"12345678";
240
        elsif iClkCnt = 7000 then
241
           jtag_test_ena <= '1';
242
           jtag_test_burst <= X"01";
243
           jtag_test_addr <= X"10000004";
244
           jtag_test_we <= '0';
245
           jtag_test_wdata <= (others => '0');
246
        elsif iClkCnt = 10000 then
247
           jtag_test_ena <= '1';
248
           jtag_test_burst <= X"02";
249
           jtag_test_addr <= X"FFFFF004";
250
           jtag_test_we <= '1';
251
           jtag_test_wdata <= X"DEADBEEF";
252
       end if;
253
    end if;
254
  end process;
255
 
256
 
257
  uart0 : uart_sim generic map (
258
    clock_rate => 2*20
259
  ) port map (
260
    rst => i_rst,
261
    clk => i_sclk_p,
262
    wr_str => uart_wr_str,
263
    instr => uart_instr,
264
    bin_data => uart_bin_data,
265
    bin_bytes_sz => uart_bin_bytes_sz,
266
    td  => o_uart1_td,
267
    rtsn => o_uart1_rtsn,
268
    rd  => i_uart1_rd,
269
    ctsn => i_uart1_ctsn,
270
    busy => uart_busy
271
  );
272
 
273
  phy0 : ethphy_sim port map (
274
    rst => i_rst,
275
    clk  => i_sclk_p,
276
    o_rxd  => i_rxd,
277
    o_rxdv => i_rxdv
278
  );
279
 
280
  jsim0 : jtag_sim  generic map (
281
    clock_rate => 4,
282
    irlen => 4
283
  ) port map (
284
    rst => i_rst,
285
    clk => i_sclk_p,
286
    i_test_ena => jtag_test_ena,
287
    i_test_burst => jtag_test_burst,
288
    i_test_addr => jtag_test_addr,
289
    i_test_we => jtag_test_we,
290
    i_test_wdata => jtag_test_wdata,
291
    i_tdi => jtag_tdi,
292
    o_tck => jtag_tck,
293
    o_ntrst => jtag_ntrst,
294
    o_tms => jtag_tms,
295
    o_tdo => jtag_tdo
296
  );
297
 
298
  -- signal parsment and assignment
299
  tt : riscv_soc port map
300
  (
301
    i_rst     => i_rst,
302
    i_sclk_p  => i_sclk_p,
303
    i_sclk_n  => i_sclk_n,
304
    i_dip     => i_dip,
305
    o_led     => o_led,
306
    i_jtag_tck => jtag_tck,
307
    i_jtag_ntrst => jtag_ntrst,
308
    i_jtag_tms => jtag_tms,
309
    i_jtag_tdi => jtag_tdo,
310
    o_jtag_tdo => jtag_tdi,
311
    o_jtag_vref => open,
312
    i_uart1_ctsn => i_uart1_ctsn,
313
    i_uart1_rd   => i_uart1_rd,
314
    o_uart1_td   => o_uart1_td,
315
    o_uart1_rtsn => o_uart1_rtsn,
316
    i_uart2_ctsn => i_uart2_ctsn,
317
    i_uart2_rd   => i_uart2_rd,
318
    o_uart2_td   => o_uart2_td,
319
    o_uart2_rtsn => o_uart2_rtsn,
320
    i_gmiiclk_p => '0',
321
    i_gmiiclk_n => '1',
322
    o_egtx_clk  => open,
323
    i_etx_clk   => i_sclk_p,
324
    i_erx_clk   => i_sclk_p,
325
    i_erxd      => i_rxd,
326
    i_erx_dv    => i_rxdv,
327
    i_erx_er    => '0',
328
    i_erx_col   => '0',
329
    i_erx_crs   => '0',
330
    i_emdint    => '0',
331
    o_etxd      => o_txd,
332
    o_etx_en    => o_txdv,
333
    o_etx_er    => open,
334
    o_emdc      => o_emdc,
335
    io_emdio    => io_emdio,
336
    o_erstn     => open
337
 );
338
 
339
  procCheck : process (i_rst, check_clk_bus)
340
  begin
341
    if rising_edge(check_clk_bus) then
342
      if i_rst = '0' then
343
        iErrCheckedCnt <= iErrCheckedCnt + 1;
344
      end if;
345
    end if;
346
  end process procCheck;
347
 
348
end;

powered by: WebSVN 2.1.0

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