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

Subversion Repositories spi_slave

[/] [spi_slave/] [trunk/] [bench/] [vhdl/] [opb_m_if_tb.vhd] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dkoethe
-------------------------------------------------------------------------------
2
-- Title      : Testbench for design "opb_m_if"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : opb_m_if_tb.vhd
6
-- Author     : 
7
-- Company    : 
8
-- Created    : 2007-10-29
9
-- Last update: 2007-11-12
10
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2007 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2007-10-29  1.0      d.koethe        Created
20
-------------------------------------------------------------------------------
21
library ieee;
22
use ieee.std_logic_1164.all;
23
use IEEE.STD_LOGIC_ARITH.all;
24
use IEEE.STD_LOGIC_UNSIGNED.all;
25
use IEEE.numeric_std.all;               -- conv_integer()
26
-------------------------------------------------------------------------------
27
 
28
entity opb_m_if_tb is
29
 
30
end opb_m_if_tb;
31
 
32
-------------------------------------------------------------------------------
33
 
34
architecture behavior of opb_m_if_tb is
35
 
36
  component opb_m_if
37
    generic (
38
      C_BASEADDR        : std_logic_vector(0 to 31);
39
      C_HIGHADDR        : std_logic_vector(0 to 31);
40
      C_USER_ID_CODE    : integer;
41
      C_OPB_AWIDTH      : integer;
42
      C_OPB_DWIDTH      : integer;
43
      C_FAMILY          : string;
44
      C_SR_WIDTH        : integer;
45
      C_MSB_FIRST       : boolean;
46
      C_CPOL            : integer range 0 to 1;
47
      C_PHA             : integer range 0 to 1;
48
      C_FIFO_SIZE_WIDTH : integer range 4 to 7);
49
    port (
50
      OPB_Clk         : in  std_logic;
51
      OPB_Rst         : in  std_logic;
52
      OPB_DBus        : in  std_logic_vector(0 to C_OPB_DWIDTH-1);
53
      M_request       : out std_logic;
54
      MOPB_MGrant     : in  std_logic;
55
      M_busLock       : out std_logic;
56
      M_ABus          : out std_logic_vector(0 to C_OPB_AWIDTH-1);
57
      M_BE            : out std_logic_vector(0 to C_OPB_DWIDTH/8-1);
58
      M_DBus          : out std_logic_vector(0 to C_OPB_DWIDTH-1);
59
      M_RNW           : out std_logic;
60
      M_select        : out std_logic;
61
      M_seqAddr       : out std_logic;
62
      MOPB_errAck     : in  std_logic;
63
      MOPB_retry      : in  std_logic;
64
      MOPB_timeout    : in  std_logic;
65
      MOPB_xferAck    : in  std_logic;
66
      opb_m_tx_req    : in  std_logic;
67
      opb_m_tx_en     : out std_logic;
68
      opb_m_tx_data   : out std_logic_vector(C_SR_WIDTH-1 downto 0);
69
      opb_tx_dma_ctl  : in  std_logic_vector(0 downto 0);
70
      opb_tx_dma_addr : in  std_logic_vector(C_OPB_DWIDTH-1 downto 0);
71
      opb_tx_dma_num  : in  std_logic_vector(15 downto 0);
72
      opb_tx_dma_done : out std_logic;
73
      opb_m_rx_req    : in  std_logic;
74
      opb_m_rx_en     : out std_logic;
75
      opb_m_rx_data   : in  std_logic_vector(C_SR_WIDTH-1 downto 0);
76
      opb_rx_dma_ctl  : in  std_logic_vector(0 downto 0);
77
      opb_rx_dma_addr : in  std_logic_vector(C_OPB_DWIDTH-1 downto 0);
78
      opb_rx_dma_num  : in  std_logic_vector(15 downto 0);
79
      opb_rx_dma_done : out std_logic);
80
  end component;
81
 
82
 
83
 
84
  -- component generics
85
  constant C_BASEADDR        : std_logic_vector(0 to 31) := X"00000000";
86
  constant C_HIGHADDR        : std_logic_vector(0 to 31) := X"FFFFFFFF";
87
  constant C_USER_ID_CODE    : integer                   := 0;
88
  constant C_OPB_AWIDTH      : integer                   := 32;
89
  constant C_OPB_DWIDTH      : integer                   := 32;
90
  constant C_FAMILY          : string                    := "virtex-4";
91
  constant C_SR_WIDTH        : integer                   := 8;
92
  constant C_MSB_FIRST       : boolean                   := true;
93
  constant C_CPOL            : integer range 0 to 1      := 0;
94
  constant C_PHA             : integer range 0 to 1      := 0;
95
  constant C_FIFO_SIZE_WIDTH : integer range 4 to 7      := 7;
96
 
97
  -- component ports
98
  signal OPB_Clk         : std_logic;
99
  signal OPB_Rst         : std_logic;
100
  signal OPB_DBus        : std_logic_vector(0 to C_OPB_DWIDTH-1);
101
  signal M_request       : std_logic;
102
  signal MOPB_MGrant     : std_logic;
103
  signal M_busLock       : std_logic;
104
  signal M_ABus          : std_logic_vector(0 to C_OPB_AWIDTH-1);
105
  signal M_BE            : std_logic_vector(0 to C_OPB_DWIDTH/8-1);
106
  signal M_DBus          : std_logic_vector(0 to C_OPB_DWIDTH-1);
107
  signal M_RNW           : std_logic;
108
  signal M_select        : std_logic;
109
  signal M_seqAddr       : std_logic;
110
  signal MOPB_errAck     : std_logic;
111
  signal MOPB_retry      : std_logic;
112
  signal MOPB_timeout    : std_logic;
113
  signal MOPB_xferAck    : std_logic;
114
  signal opb_m_tx_req    : std_logic;
115
  signal opb_m_tx_en     : std_logic;
116
  signal opb_m_tx_data   : std_logic_vector(C_SR_WIDTH-1 downto 0);
117
  signal opb_tx_dma_ctl  : std_logic_vector(0 downto 0);
118
  signal opb_tx_dma_addr : std_logic_vector(C_OPB_DWIDTH-1 downto 0);
119
  signal opb_tx_dma_num  : std_logic_vector(15 downto 0);
120
  signal opb_tx_dma_done : std_logic;
121
  signal opb_m_rx_req    : std_logic;
122
  signal opb_m_rx_en     : std_logic;
123
  signal opb_m_rx_data   : std_logic_vector(C_SR_WIDTH-1 downto 0);
124
  signal opb_rx_dma_ctl  : std_logic_vector(0 downto 0);
125
  signal opb_rx_dma_addr : std_logic_vector(C_OPB_DWIDTH-1 downto 0);
126
  signal opb_rx_dma_num  : std_logic_vector(15 downto 0);
127
  signal opb_rx_dma_done : std_logic;
128
 
129
  signal opb_rx_data : std_logic_vector(C_SR_WIDTH-1 downto 0);
130
  signal opb_tx_data : std_logic_vector(0 to C_SR_WIDTH-1);
131
 
132
begin  -- behavior
133
 
134
  -- component instantiation
135
  opb_m_if_1: opb_m_if
136
    generic map (
137
      C_BASEADDR        => C_BASEADDR,
138
      C_HIGHADDR        => C_HIGHADDR,
139
      C_USER_ID_CODE    => C_USER_ID_CODE,
140
      C_OPB_AWIDTH      => C_OPB_AWIDTH,
141
      C_OPB_DWIDTH      => C_OPB_DWIDTH,
142
      C_FAMILY          => C_FAMILY,
143
      C_SR_WIDTH        => C_SR_WIDTH,
144
      C_MSB_FIRST       => C_MSB_FIRST,
145
      C_CPOL            => C_CPOL,
146
      C_PHA             => C_PHA,
147
      C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH)
148
    port map (
149
      OPB_Clk         => OPB_Clk,
150
      OPB_Rst         => OPB_Rst,
151
      OPB_DBus        => OPB_DBus,
152
      M_request       => M_request,
153
      MOPB_MGrant     => MOPB_MGrant,
154
      M_busLock       => M_busLock,
155
      M_ABus          => M_ABus,
156
      M_BE            => M_BE,
157
      M_DBus          => M_DBus,
158
      M_RNW           => M_RNW,
159
      M_select        => M_select,
160
      M_seqAddr       => M_seqAddr,
161
      MOPB_errAck     => MOPB_errAck,
162
      MOPB_retry      => MOPB_retry,
163
      MOPB_timeout    => MOPB_timeout,
164
      MOPB_xferAck    => MOPB_xferAck,
165
      opb_m_tx_req    => opb_m_tx_req,
166
      opb_m_tx_en     => opb_m_tx_en,
167
      opb_m_tx_data   => opb_m_tx_data,
168
      opb_tx_dma_ctl  => opb_tx_dma_ctl,
169
      opb_tx_dma_addr => opb_tx_dma_addr,
170
      opb_tx_dma_num  => opb_tx_dma_num,
171
      opb_tx_dma_done => opb_tx_dma_done,
172
      opb_m_rx_req    => opb_m_rx_req,
173
      opb_m_rx_en     => opb_m_rx_en,
174
      opb_m_rx_data   => opb_m_rx_data,
175
      opb_rx_dma_ctl  => opb_rx_dma_ctl,
176
      opb_rx_dma_addr => opb_rx_dma_addr,
177
      opb_rx_dma_num  => opb_rx_dma_num,
178
      opb_rx_dma_done => opb_rx_dma_done);
179
 
180
 
181
  -- clock generation
182
  process
183
  begin
184
    OPB_Clk <= '0';
185
    wait for 10 ns;
186
    OPB_Clk <= '1';
187
    wait for 10 ns;
188
  end process;
189
 
190
 
191
  -- arbiter/xferack
192
  process(OPB_Rst, OPB_Clk)
193
  begin
194
    if (OPB_Rst = '1') then
195
      MOPB_MGrant  <= '0';
196
      MOPB_xferAck <= '0';
197
      opb_tx_data  <= (others => '0');
198
    elsif rising_edge(OPB_Clk) then
199
      -- arbiter
200
      if (M_request = '1') then
201
        MOPB_MGrant <= '1';
202
      else
203
        MOPB_MGrant <= '0';
204
      end if;
205
 
206
      -- xfer_Ack
207
      if (M_select = '1') then
208
        if (M_RNW = '1' and MOPB_xferAck = '1') then
209
          opb_tx_data <= opb_tx_data+1;
210
        end if;
211
        MOPB_xferAck <= not MOPB_xferAck;
212
      else
213
        opb_tx_data  <= (others => '0');
214
        MOPB_xferAck <= '0';
215
      end if;
216
     end if;
217
  end process;
218
 
219
  OPB_DBus( 0 to C_OPB_DWIDTH-C_SR_WIDTH-1) <= (others => '0');
220
  OPB_DBus(C_OPB_DWIDTH-C_SR_WIDTH to C_OPB_DWIDTH-1)    <= opb_tx_data;
221
 
222
  -- rx fifo emulation
223
  process(OPB_Rst, OPB_Clk)
224
  begin
225
    if (OPB_Rst = '1') then
226
      opb_rx_data <= (others => '0');
227
    elsif rising_edge(OPB_Clk) then
228
      if (opb_m_rx_en = '1') then
229
        opb_rx_data <= opb_rx_data+1;
230
      end if;
231
    end if;
232
  end process;
233
 
234
  opb_m_rx_data <= opb_rx_data;
235
 
236
 
237
  -- waveform generation
238
  WaveGen_Proc : process
239
  begin
240
    -- reset active
241
    OPB_Rst <= '1';
242
 
243
    MOPB_errAck  <= '0';
244
    MOPB_retry   <= '0';
245
    MOPB_timeout <= '0';
246
 
247
    opb_m_tx_req    <= '0';
248
    opb_tx_dma_ctl  <= (others => '0');
249
    opb_tx_dma_addr <= (others => '0');
250
    opb_m_rx_req    <= '0';
251
    opb_rx_dma_ctl  <= (others => '0');
252
    opb_rx_dma_addr <= (others => '0');
253
 
254
 
255
 
256
 
257
    wait for 100 ns;
258
    -- remove rst
259
    OPB_Rst <= '0';
260
    ---------------------------------------------------------------------------
261
    -- write transfer
262
    opb_tx_dma_addr <= conv_std_logic_vector(16#24000000#, 32);
263
 
264
    wait until rising_edge(OPB_Clk);
265
    opb_tx_dma_ctl(0) <= '1';
266
 
267
 
268
    wait until rising_edge(OPB_Clk);
269
    opb_m_tx_req <= '1';                -- asssert almost full flag
270
    wait until rising_edge(OPB_Clk);
271
    opb_m_tx_req <= '0';                -- deassert almost full flag
272
 
273
    wait for 1 us;
274
 
275
    ---------------------------------------------------------------------------
276
    -- read transfer
277
    opb_rx_dma_addr <= conv_std_logic_vector(16#25000000#, 32);
278
 
279
    wait until rising_edge(OPB_Clk);
280
    opb_rx_dma_ctl(0) <= '1';
281
 
282
    -- first transfer
283
    wait until rising_edge(OPB_Clk);
284
    opb_m_rx_req <= '1';                -- asssert almost full flag
285
    wait until rising_edge(OPB_Clk);
286
    opb_m_rx_req <= '0';                -- deassert almost full flag
287
    wait for 1 us;
288
 
289
    -- second transfer
290
    wait until rising_edge(OPB_Clk);
291
    opb_m_rx_req <= '1';                -- asssert almost full flag
292
    wait until rising_edge(OPB_Clk);
293
    opb_m_rx_req <= '0';                -- deassert almost full flag
294
    wait for 1 us;
295
    ---------------------------------------------------------------------------
296
 
297
 
298
    assert false report "Simulation Sucessful" severity failure;
299
 
300
  end process WaveGen_Proc;
301
 
302
 
303
 
304
end behavior;
305
 
306
-------------------------------------------------------------------------------
307
 
308
configuration opb_m_if_tb_behavior_cfg of opb_m_if_tb is
309
  for behavior
310
  end for;
311
end opb_m_if_tb_behavior_cfg;
312
 
313
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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