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

Subversion Repositories astron_mm

[/] [astron_mm/] [trunk/] [tb_mm_file.vhd] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2012
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
--
22
-- Author:
23
--   D. van der Schuur  May 2012  Original with manual file IO using an editor.
24
--   E. Kooistra        Feb 2017  Added purpose and description
25
--                                Added external control by p_mm_stimuli and
26
--                                p_sim_stimuli
27
-- Purpose: Testbench for MM and simulation control via file io
28
-- Description:
29
--   This testbench verifies mm_file and mm_file_pkg.
30
--   1) p_mm_stimuli
31
--     The p_mm_stimuli uses mmf_mm_bus_wr() and mmf_mm_bus_rd() to access a MM
32
--     slave register instance of common_reg_r_w_dc via mm_file using a MM slave
33
--     .ctrl and .stat file. The p_mm_stimuli verifies the W/R accesses.
34
--   2) p_sim_stimuli
35
--     The p_sim_stimuli waits for get_now and then it uses mmf_sim_get_now() to
36
--     read the simulator status via mmf_poll_sim_ctrl_file() using a sim.ctrl
37
--     and sim.stat file. The p_sim_stimuli does not verify read rd_now value,
38
--     but it does print it.
39
-- Usage:
40
--   > as 5
41
--   > run -all
42
--   The tb is self stopping and self checking. 
43
--   For example observe mm_mosi, mm_miso, rd_now and out_reg_arr in wave window.
44
 
45
LIBRARY IEEE, common_pkg_lib, common_ram_lib;
46
USE IEEE.std_logic_1164.ALL;
47
USE IEEE.numeric_std.ALL;
48
USE common_pkg_lib.common_pkg.ALL;
49
USE common_ram_lib.common_ram_pkg.ALL;
50
USE common_pkg_lib.common_str_pkg.ALL;
51
USE common_pkg_lib.tb_common_pkg.ALL;
52
USE work.mm_file_pkg.ALL;
53
 
54
ENTITY tb_mm_file IS
55
  GENERIC (
56
    g_tb_index           : NATURAL := 0;
57
    g_mm_nof_accesses    : NATURAL := 100;
58
    g_mm_timeout         : TIME := 0 ns;--100 ns;   -- default 0 ns for full speed MM, use > 0 to define number of mm_clk without MM access after which the MM file IO is paused
59
    g_mm_pause           : TIME := 1000 ns;  -- defines the time for which MM file IO is paused to reduce the file IO rate when the MM slave is idle
60
    g_timeout_gap        : INTEGER := -1;--4;    -- no gap when < 0, else force MM access gap after g_timeout_gap wr or rd strobes
61
    g_cross_clock_domain : BOOLEAN := FALSE --TRUE
62
  );
63
END tb_mm_file;
64
 
65
ARCHITECTURE tb OF tb_mm_file IS
66
 
67
  CONSTANT c_mm_clk_period            : TIME := c_mmf_mm_clk_period;  -- = 100 ps;
68
  CONSTANT c_mm_nof_dat               : NATURAL := smallest(c_mem_reg_init_w/c_32, g_mm_nof_accesses);
69
  CONSTANT c_mm_rd_latency            : NATURAL := 2;
70
 
71
  CONSTANT c_cross_nof_mm_clk         : NATURAL := sel_a_b(g_cross_clock_domain, 100, 0);  -- > 2*24 see common_reg_cross_domain, factor 2 for W/R
72
 
73
  -- Determine node mm_file prefix based on --unb --gn (similar as done in mmf_unb_file_prefix())
74
  CONSTANT c_unb_nr                   : NATURAL := 3;  --unb
75
  CONSTANT c_pn_nr                    : NATURAL := 1;  --gn = 0:7
76
  CONSTANT c_node_type                : STRING(1 TO 2):= sel_a_b(c_pn_nr<4, "FN", "BN");
77
  CONSTANT c_node_nr                  : NATURAL := sel_a_b(c_node_type="BN", c_pn_nr-4, c_pn_nr);
78
 
79
  -- Use local mmfiles/ subdirectory in mm project build directory
80
  CONSTANT c_sim_file_pathname        : STRING := mmf_slave_prefix("TB", g_tb_index) & "sim";
81
  CONSTANT c_reg_r_w_dc_file_pathname : STRING := mmf_slave_prefix("TB", g_tb_index, "UNB", c_unb_nr, c_node_type, c_node_nr) & "REG_R_W_DC";
82
 
83
  --TYPE t_c_mem IS RECORD
84
  --  latency   : NATURAL;    -- read latency
85
  --  adr_w     : NATURAL;
86
  --  dat_w     : NATURAL;
87
  --  nof_dat   : NATURAL;    -- optional, nof dat words <= 2**adr_w
88
  --  init_sl   : STD_LOGIC;  -- optional, init all dat words to std_logic '0', '1' or 'X'
89
  --  --init_file : STRING;     -- "UNUSED", unconstrained length can not be in record
90
  --END RECORD;
91
  CONSTANT c_mem_reg            : t_c_mem := (c_mm_rd_latency, ceil_log2(c_mm_nof_dat), c_32, c_mm_nof_dat, '0');
92
 
93
  SIGNAL tb_state           : STRING(1 TO 5) := "Init ";
94
  SIGNAL tb_end             : STD_LOGIC := '0';
95
  SIGNAL mm_clk             : STD_LOGIC := '0';
96
  SIGNAL mm_rst             : STD_LOGIC;
97
 
98
  SIGNAL get_now            : STD_LOGIC := '0';
99
  SIGNAL rd_now             : STRING(1 TO 16);  -- sufficient to fit TIME NOW in ns as a string
100
 
101
  SIGNAL mm_mosi            : t_mem_mosi;
102
  SIGNAL mm_miso            : t_mem_miso;
103
  SIGNAL file_wr_data       : STD_LOGIC_VECTOR(c_32-1 DOWNTO 0);
104
  SIGNAL file_rd_data       : STD_LOGIC_VECTOR(c_32-1 DOWNTO 0);
105
 
106
  SIGNAL reg_wr_arr         : STD_LOGIC_VECTOR(     c_mem_reg.nof_dat-1 DOWNTO 0);
107
  SIGNAL reg_rd_arr         : STD_LOGIC_VECTOR(     c_mem_reg.nof_dat-1 DOWNTO 0);
108
  SIGNAL in_new             : STD_LOGIC := '1';
109
  SIGNAL in_reg             : STD_LOGIC_VECTOR(c_32*c_mem_reg.nof_dat-1 DOWNTO 0);
110
  SIGNAL out_reg            : STD_LOGIC_VECTOR(c_32*c_mem_reg.nof_dat-1 DOWNTO 0);
111
  SIGNAL out_new            : STD_LOGIC;    -- Pulses '1' when new data has been written.
112
 
113
  SIGNAL out_reg_arr        : t_slv_32_arr(c_mem_reg.nof_dat-1 DOWNTO 0);
114
 
115
BEGIN
116
 
117
  mm_clk <= NOT mm_clk OR tb_end AFTER c_mm_clk_period/2;
118
  mm_rst <= '1', '0' AFTER c_mm_clk_period*10;
119
 
120
  -- DUT mm access files 'c_reg_r_w_dc_file_pathname'.ctrl and 'c_reg_r_w_dc_file_pathname'.stat
121
  p_mm_stimuli : PROCESS
122
    VARIABLE v_addr : NATURAL;
123
  BEGIN
124
    proc_common_wait_until_low(mm_clk, mm_rst);
125
    proc_common_wait_some_cycles(mm_clk, 3);
126
 
127
    -- Write all nof_dat once
128
    tb_state <= "Write";
129
    FOR I IN 0 TO c_mm_nof_dat-1 LOOP
130
      IF I=g_timeout_gap THEN
131
        WAIT FOR 2*c_mmf_mm_timeout;
132
      END IF;
133
      file_wr_data <= TO_UVEC(I, c_32);
134
      mmf_mm_bus_wr(c_reg_r_w_dc_file_pathname, I, I, mm_clk);
135
    END LOOP;
136
 
137
    proc_common_wait_some_cycles(mm_clk, c_cross_nof_mm_clk);
138
 
139
    -- Read all nof_dat once
140
    tb_state <= "Read ";
141
    FOR I IN 0 TO c_mm_nof_dat-1 LOOP
142
      IF I=g_timeout_gap THEN
143
        WAIT FOR 2*c_mmf_mm_timeout;
144
      END IF;
145
      mmf_mm_bus_rd(c_reg_r_w_dc_file_pathname, c_mem_reg.latency, I, file_rd_data, mm_clk);
146
      ASSERT I=TO_UINT(file_rd_data) REPORT "Read data is wrong." SEVERITY ERROR;
147
    END LOOP;
148
 
149
    -- Write/Read
150
    tb_state <= "Both ";
151
    FOR I IN 0 TO g_mm_nof_accesses-1 LOOP
152
      IF I=g_timeout_gap THEN
153
        WAIT FOR 2*c_mmf_mm_timeout;
154
      END IF;
155
      file_wr_data <= TO_UVEC(I, c_32);
156
      v_addr := I MOD c_mm_nof_dat;
157
      mmf_mm_bus_wr(c_reg_r_w_dc_file_pathname, v_addr, I, mm_clk);
158
      proc_common_wait_some_cycles(mm_clk, c_cross_nof_mm_clk);
159
      mmf_mm_bus_rd(c_reg_r_w_dc_file_pathname, c_mem_reg.latency, v_addr, file_rd_data, mm_clk);
160
      ASSERT TO_UINT(file_wr_data)=TO_UINT(file_rd_data) REPORT "Write/read data is wrong." SEVERITY ERROR;
161
    END LOOP;
162
 
163
    proc_common_gen_pulse(mm_clk, get_now);
164
    tb_state <= "End  ";
165
 
166
    proc_common_wait_some_cycles(mm_clk, g_mm_nof_accesses);
167
    tb_end <= '1';
168
    WAIT;
169
  END PROCESS;
170
 
171
  u_mm_file : ENTITY work.mm_file
172
  GENERIC MAP(
173
    g_file_prefix   => c_reg_r_w_dc_file_pathname,
174
    g_mm_rd_latency => c_mem_reg.latency,  -- the mm_file g_mm_rd_latency must be >= the MM slave read latency
175
    g_mm_timeout    => g_mm_timeout,
176
    g_mm_pause      => g_mm_pause
177
  )
178
  PORT MAP (
179
    mm_rst        => mm_rst,
180
    mm_clk        => mm_clk,
181
 
182
    mm_master_out => mm_mosi,
183
    mm_master_in  => mm_miso
184
  );
185
 
186
  -- Target MM reg
187
  u_reg_r_w_dc : ENTITY work.common_reg_r_w_dc
188
  GENERIC MAP (
189
    g_cross_clock_domain => g_cross_clock_domain,
190
    g_in_new_latency     => 0,
191
    g_readback           => FALSE,
192
    g_reg                => c_mem_reg
193
    --g_init_reg           => STD_LOGIC_VECTOR(c_mem_reg_init_w-1 DOWNTO 0) := (OTHERS => '0')
194
  )
195
  PORT MAP (
196
    -- Clocks and reset
197
    mm_rst      => mm_rst,
198
    mm_clk      => mm_clk,
199
    st_rst      => mm_rst,
200
    st_clk      => mm_clk,
201
 
202
    -- Memory Mapped Slave in mm_clk domain
203
    sla_in      => mm_mosi,
204
    sla_out     => mm_miso,
205
 
206
    -- MM registers in st_clk domain
207
    reg_wr_arr  => reg_wr_arr,
208
    reg_rd_arr  => reg_rd_arr,
209
    in_new      => in_new,
210
    in_reg      => in_reg,
211
    out_reg     => out_reg,
212
    out_new     => out_new
213
  );
214
 
215
  in_reg <= out_reg;
216
 
217
  p_wire : PROCESS(out_reg)
218
  BEGIN
219
    FOR I IN c_mem_reg.nof_dat-1 DOWNTO 0 LOOP
220
      out_reg_arr(I) <= out_reg((I+1)*c_32-1 DOWNTO I*c_32);
221
    END LOOP;
222
  END PROCESS;
223
 
224
  -- Also verify simulation status access
225
  mmf_poll_sim_ctrl_file(mm_clk, c_sim_file_pathname & ".ctrl", c_sim_file_pathname & ".stat");
226
 
227
  p_sim_stimuli : PROCESS
228
  BEGIN
229
    proc_common_wait_until_low(mm_clk, mm_rst);
230
    proc_common_wait_some_cycles(mm_clk, 10);
231
 
232
    proc_common_wait_until_hi_lo(mm_clk, get_now);
233
    mmf_sim_get_now(c_sim_file_pathname, rd_now, mm_clk);
234
    WAIT;
235
  END PROCESS;
236
 
237
END tb;

powered by: WebSVN 2.1.0

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