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

Subversion Repositories spi_slave

[/] [spi_slave/] [trunk/] [bench/] [vhdl/] [opb_spi_slave_tb.vhd] - Blame information for rev 27

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

Line No. Rev Author Line
1 12 dkoethe
-------------------------------------------------------------------------------
2
-- Title      : Testbench for design "opb_spi_slave"
3
-- Project    : 
4
-------------------------------------------------------------------------------
5
-- File       : opb_spi_slave_tb.vhd
6
-- Author     : 
7
-- Company    : 
8
-- Created    : 2007-09-02
9 27 dkoethe
-- Last update: 2008-03-23
10 12 dkoethe
-- Platform   : 
11
-- Standard   : VHDL'87
12
-------------------------------------------------------------------------------
13
-- Description: 
14
-------------------------------------------------------------------------------
15
-- Copyright (c) 2007 
16
-------------------------------------------------------------------------------
17
-- Revisions  :
18
-- Date        Version  Author  Description
19
-- 2007-09-02  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
library work;
28
use work.opb_spi_slave_pack.all;
29
-------------------------------------------------------------------------------
30
 
31
entity opb_spi_slave_tb is
32 17 dkoethe
  generic (
33
    -- 0: simple transfer 1 byte transmit/receive
34
    -- 1: transfer 4 bytes and check flags
35
    -- 2: write until TX-FIFO asserts full, read until RX-FIFO asserts full, read
36
    --    and compare data
37
    -- 3: check FIFO Reset form underflow condition
38
    -- 4: check FIFO Flags IRQ Generation
39
    -- 5: check Slave select IRQ Generation
40
    -- 6: test opb Master Transfer
41 27 dkoethe
    test : std_logic_vector(7 downto 0) := "01000000");
42 12 dkoethe
end opb_spi_slave_tb;
43
 
44
-------------------------------------------------------------------------------
45
 
46
architecture behavior of opb_spi_slave_tb is
47
  constant C_BASEADDR        : std_logic_vector(0 to 31) := X"00000000";
48
  constant C_HIGHADDR        : std_logic_vector(0 to 31) := X"FFFFFFFF";
49
  constant C_USER_ID_CODE    : integer                   := 0;
50
  constant C_OPB_AWIDTH      : integer                   := 32;
51
  constant C_OPB_DWIDTH      : integer                   := 32;
52
  constant C_FAMILY          : string                    := "virtex-4";
53
  --
54
  -- constant C_SR_WIDTH        : integer                   := 8;
55
  constant C_SR_WIDTH        : integer                   := 32;
56
  -- 
57
  constant C_MSB_FIRST       : boolean                   := true;
58
  constant C_CPOL            : integer range 0 to 1      := 0;
59
  constant C_PHA             : integer range 0 to 1      := 0;
60
  constant C_FIFO_SIZE_WIDTH : integer range 4 to 7      := 7;
61 17 dkoethe
  constant C_DMA_EN          : boolean                   := true;
62 27 dkoethe
  constant C_CRC_EN          : boolean                   := true;
63 17 dkoethe
 
64 12 dkoethe
  component opb_spi_slave
65
    generic (
66
      C_BASEADDR        : std_logic_vector(0 to 31);
67
      C_HIGHADDR        : std_logic_vector(0 to 31);
68
      C_USER_ID_CODE    : integer;
69
      C_OPB_AWIDTH      : integer;
70
      C_OPB_DWIDTH      : integer;
71
      C_FAMILY          : string;
72
      C_SR_WIDTH        : integer;
73
      C_MSB_FIRST       : boolean;
74
      C_CPOL            : integer range 0 to 1;
75
      C_PHA             : integer range 0 to 1;
76
      C_FIFO_SIZE_WIDTH : integer range 4 to 7;
77 27 dkoethe
      C_DMA_EN          : boolean;
78
      C_CRC_EN          : boolean);
79 12 dkoethe
    port (
80
      OPB_ABus     : in  std_logic_vector(0 to C_OPB_AWIDTH-1);
81
      OPB_BE       : in  std_logic_vector(0 to C_OPB_DWIDTH/8-1);
82
      OPB_Clk      : in  std_logic;
83
      OPB_DBus     : in  std_logic_vector(0 to C_OPB_DWIDTH-1);
84
      OPB_RNW      : in  std_logic;
85
      OPB_Rst      : in  std_logic;
86
      OPB_select   : in  std_logic;
87
      OPB_seqAddr  : in  std_logic;
88
      Sln_DBus     : out std_logic_vector(0 to C_OPB_DWIDTH-1);
89
      Sln_errAck   : out std_logic;
90
      Sln_retry    : out std_logic;
91
      Sln_toutSup  : out std_logic;
92
      Sln_xferAck  : out std_logic;
93
      M_request    : out std_logic;
94
      MOPB_MGrant  : in  std_logic;
95
      M_busLock    : out std_logic;
96
      M_ABus       : out std_logic_vector(0 to C_OPB_AWIDTH-1);
97
      M_BE         : out std_logic_vector(0 to C_OPB_DWIDTH/8-1);
98
      M_DBus       : out std_logic_vector(0 to C_OPB_DWIDTH-1);
99
      M_RNW        : out std_logic;
100
      M_select     : out std_logic;
101
      M_seqAddr    : out std_logic;
102
      MOPB_errAck  : in  std_logic;
103
      MOPB_retry   : in  std_logic;
104
      MOPB_timeout : in  std_logic;
105
      MOPB_xferAck : in  std_logic;
106
      sclk         : in  std_logic;
107
      ss_n         : in  std_logic;
108
      mosi         : in  std_logic;
109
      miso_o       : out std_logic;
110
      miso_i       : in  std_logic;
111
      miso_t       : out std_logic;
112
      opb_irq      : out std_logic);
113
  end component;
114
 
115
  signal OPB_ABus     : std_logic_vector(0 to C_OPB_AWIDTH-1);
116
  signal OPB_BE       : std_logic_vector(0 to C_OPB_DWIDTH/8-1);
117
  signal OPB_Clk      : std_logic;
118
  signal OPB_DBus     : std_logic_vector(0 to C_OPB_DWIDTH-1);
119
  signal OPB_RNW      : std_logic;
120
  signal OPB_Rst      : std_logic;
121
  signal OPB_select   : std_logic;
122
  signal OPB_seqAddr  : std_logic;
123
  signal Sln_DBus     : std_logic_vector(0 to C_OPB_DWIDTH-1);
124
  signal Sln_errAck   : std_logic;
125
  signal Sln_retry    : std_logic;
126
  signal Sln_toutSup  : std_logic;
127
  signal Sln_xferAck  : std_logic;
128
  signal M_request    : std_logic;
129
  signal MOPB_MGrant  : std_logic;
130
  signal M_busLock    : std_logic;
131
  signal M_ABus       : std_logic_vector(0 to C_OPB_AWIDTH-1);
132
  signal M_BE         : std_logic_vector(0 to C_OPB_DWIDTH/8-1);
133
  signal M_DBus       : std_logic_vector(0 to C_OPB_DWIDTH-1);
134
  signal M_RNW        : std_logic;
135
  signal M_select     : std_logic;
136
  signal M_seqAddr    : std_logic;
137
  signal MOPB_errAck  : std_logic;
138
  signal MOPB_retry   : std_logic;
139
  signal MOPB_timeout : std_logic;
140
  signal MOPB_xferAck : std_logic;
141
  signal sclk         : std_logic;
142
  signal ss_n         : std_logic;
143
  signal mosi         : std_logic;
144
  signal miso_o       : std_logic;
145
  signal miso_i       : std_logic;
146
  signal miso_t       : std_logic;
147
  signal opb_irq      : std_logic;
148
 
149
-- testbench
150
  constant clk_period     : time := 10 ns;
151
  constant spi_clk_period : time := 50 ns;
152
 
153
  signal miso : std_logic;
154
 
155
  signal opb_read_data : std_logic_vector(31 downto 0);
156
  signal spi_value_in  : std_logic_vector(C_SR_WIDTH-1 downto 0);
157 17 dkoethe
 
158
  signal OPB_Transfer_Abort : boolean;
159 27 dkoethe
  signal OPB_DBus0          : std_logic_vector(0 to C_OPB_DWIDTH-1);
160
  signal OPB_DBus1          : std_logic_vector(0 to C_OPB_DWIDTH-1);
161 12 dkoethe
 
162
begin  -- behavior
163
 
164
  -- component instantiation
165
  DUT : opb_spi_slave
166
    generic map (
167
      C_BASEADDR        => C_BASEADDR,
168
      C_HIGHADDR        => C_HIGHADDR,
169
      C_USER_ID_CODE    => C_USER_ID_CODE,
170
      C_OPB_AWIDTH      => C_OPB_AWIDTH,
171
      C_OPB_DWIDTH      => C_OPB_DWIDTH,
172
      C_FAMILY          => C_FAMILY,
173
      C_SR_WIDTH        => C_SR_WIDTH,
174
      C_MSB_FIRST       => C_MSB_FIRST,
175
      C_CPOL            => C_CPOL,
176
      C_PHA             => C_PHA,
177
      C_FIFO_SIZE_WIDTH => C_FIFO_SIZE_WIDTH,
178 27 dkoethe
      C_DMA_EN          => C_DMA_EN,
179
      C_CRC_EN          => C_CRC_EN)
180 12 dkoethe
    port map (
181
      OPB_ABus     => OPB_ABus,
182
      OPB_BE       => OPB_BE,
183
      OPB_Clk      => OPB_Clk,
184
      OPB_DBus     => OPB_DBus,
185
      OPB_RNW      => OPB_RNW,
186
      OPB_Rst      => OPB_Rst,
187
      OPB_select   => OPB_select,
188
      OPB_seqAddr  => OPB_seqAddr,
189
      Sln_DBus     => Sln_DBus,
190
      Sln_errAck   => Sln_errAck,
191
      Sln_retry    => Sln_retry,
192
      Sln_toutSup  => Sln_toutSup,
193
      Sln_xferAck  => Sln_xferAck,
194
      M_request    => M_request,
195
      MOPB_MGrant  => MOPB_MGrant,
196
      M_busLock    => M_busLock,
197
      M_ABus       => M_ABus,
198
      M_BE         => M_BE,
199
      M_DBus       => M_DBus,
200
      M_RNW        => M_RNW,
201
      M_select     => M_select,
202
      M_seqAddr    => M_seqAddr,
203
      MOPB_errAck  => MOPB_errAck,
204
      MOPB_retry   => MOPB_retry,
205
      MOPB_timeout => MOPB_timeout,
206
      MOPB_xferAck => MOPB_xferAck,
207
      sclk         => sclk,
208
      ss_n         => ss_n,
209
      mosi         => mosi,
210
      miso_o       => miso_o,
211
      miso_i       => miso_i,
212
      miso_t       => miso_t,
213
      opb_irq      => opb_irq);
214
 
215
 
216
 
217
  -- clock generation
218
  process
219
  begin
220
    OPB_Clk <= '0';
221
    wait for clk_period;
222
    OPB_Clk <= '1';
223
    wait for clk_period;
224
  end process;
225
 
226
  -- IOB-Buffer
227
  miso <= miso_o when (miso_t = '0') else
228
          'Z';
229
  miso_i <= miso;
230
 
231
  -- OPB-Master arbiter/xferack generation
232
  process(OPB_Rst, OPB_Clk)
233
  begin
234
    if (OPB_Rst = '1') then
235
      MOPB_MGrant  <= '0';
236
      MOPB_xferAck <= '0';
237 27 dkoethe
      MOPB_errAck  <= '0';
238 12 dkoethe
    elsif rising_edge(OPB_Clk) then
239
      -- arbiter
240
      if (M_request = '1') then
241
        MOPB_MGrant <= '1';
242
      else
243
        MOPB_MGrant <= '0';
244
      end if;
245
 
246
      -- xfer_Ack
247
      if (M_select = '1') then
248 17 dkoethe
        if (OPB_Transfer_Abort) then
249 27 dkoethe
          MOPB_errAck <= '1';
250 17 dkoethe
        else
251 27 dkoethe
          if (conv_integer(M_ABus)>=16#24000000#) then
252
          if (M_RNW = '1') then
253
            -- read
254
            OPB_DBus0(C_OPB_DWIDTH-C_SR_WIDTH to C_OPB_DWIDTH-1) <= "0000000000000000" & "00" & M_ABus(16 to C_OPB_DWIDTH-3);
255
          end if;
256
          MOPB_xferAck <= not MOPB_xferAck;
257 17 dkoethe
        end if;
258
 
259 27 dkoethe
        end if;
260 17 dkoethe
 
261 27 dkoethe
 
262 12 dkoethe
      else
263 27 dkoethe
        OPB_DBus0    <= (others => '0');
264
        MOPB_errAck  <= '0';
265 12 dkoethe
        MOPB_xferAck <= '0';
266
      end if;
267
 
268
    end if;
269
  end process;
270 27 dkoethe
  -------------------------------------------------------------------------------
271
  u1 : for i in 0 to 31 generate
272
    OPB_DBus(i) <= OPB_DBus0(i) or OPB_DBus1(i);
273
  end generate u1;
274 12 dkoethe
 
275 27 dkoethe
  ------------------------------------------------------------------------------
276 12 dkoethe
  -- waveform generation
277
  WaveGen_Proc : process
278
    variable temp  : std_logic_vector(31 downto 0);
279
    variable first : std_logic_vector(7 downto 0) := (others => '0');
280
 
281
    ---------------------------------------------------------------------------
282
    procedure opb_write (
283
      constant adr  : in std_logic_vector(7 downto 2);
284
      constant data : in integer) is
285
    begin
286
      -- write transmit data
287
      wait until rising_edge(OPB_Clk);
288
      OPB_ABus   <= transport conv_std_logic_vector(conv_integer(adr & "00"), 32) after 2 ns;
289
      OPB_select <= transport '1' after 2 ns;
290
      OPB_RNW    <= transport '0' after 2 ns;
291 27 dkoethe
      OPB_DBus1  <= transport conv_std_logic_vector(data, 32)                     after 2 ns;
292 12 dkoethe
 
293
      for i in 0 to 3 loop
294
        wait until rising_edge(OPB_Clk);
295
        if (Sln_xferAck = '1') then
296
          exit;
297
        end if;
298
      end loop;  -- i
299 27 dkoethe
      OPB_DBus1  <= transport X"00000000" after 2 ns;
300 12 dkoethe
      OPB_ABus   <= transport X"00000000" after 2 ns;
301
      OPB_select <= '0';
302
    end procedure opb_write;
303
    -------------------------------------------------------------------------------
304
    procedure opb_read (
305
      constant adr : in std_logic_vector(7 downto 2)) is
306
    begin
307
      wait until rising_edge(OPB_Clk);
308
      OPB_ABus   <= transport conv_std_logic_vector(conv_integer(adr & "00"), 32) after 2 ns;
309
      OPB_select <= transport '1' after 2 ns;
310
      OPB_RNW    <= transport '1' after 2 ns;
311 27 dkoethe
      OPB_DBus1  <= transport conv_std_logic_vector(0, 32)                        after 2 ns;
312 12 dkoethe
 
313
      for i in 0 to 3 loop
314
        wait until rising_edge(OPB_Clk);
315
        if (Sln_xferAck = '1') then
316
          opb_read_data <= Sln_DBus;
317
          exit;
318
        end if;
319
      end loop;  -- i
320
      OPB_ABus   <= transport X"00000000" after 2 ns;
321
      OPB_select <= transport '0' after 2 ns;
322
      wait until rising_edge(OPB_Clk);
323
    end procedure opb_read;
324
    -------------------------------------------------------------------------------
325
    procedure spi_transfer(
326
      constant spi_value_out : in std_logic_vector(C_SR_WIDTH-1 downto 0)) is
327
    begin
328
      -- CPHA=0 CPOL=0 C_MSB_FIRST=TRUE
329
      ss_n <= '0';
330
      for i in C_SR_WIDTH-1 downto 0 loop
331
        mosi            <= spi_value_out(i);
332
        wait for spi_clk_period/2;
333
        sclk            <= '1';
334
        spi_value_in(i) <= miso;
335
        wait for spi_clk_period/2;
336
        sclk            <= '0';
337
      end loop;  -- i
338
      mosi <= 'Z';
339
      wait for clk_period/2;
340
      ss_n <= '1';
341
      wait for clk_period/2;
342
    end procedure spi_transfer;
343
    -------------------------------------------------------------------------------
344
 
345
  begin
346
    sclk   <= '0';
347
    ss_n   <= '1';
348
    mosi   <= 'Z';
349
    miso_i <= '0';
350
 
351
    -- init OPB-Slave
352
    OPB_ABus    <= (others => '0');
353
    OPB_BE      <= (others => '0');
354
    OPB_RNW     <= '0';
355
    OPB_select  <= '0';
356
    OPB_seqAddr <= '0';
357
 
358
    -- int opb_master
359
    MOPB_retry   <= '0';
360
    MOPB_timeout <= '0';
361
 
362 17 dkoethe
    OPB_Transfer_Abort <= false;
363
 
364 12 dkoethe
    -- reset active
365
    OPB_Rst <= '1';
366
    wait for 100 ns;
367
    -- reset inactive
368
    OPB_Rst <= '0';
369
 
370
 
371
    for i in 0 to 7 loop
372
      wait until rising_edge(OPB_Clk);
373
    end loop;  -- i 
374
 
375
    -- write TX Threshold
376
    -- Bit [15:00] Prog Full Threshold
377
    -- Bit [31:16] Prog Empty Threshold   
378
    opb_write(C_ADR_TX_THRESH, 16#0005000B#);
379
 
380
    -- write RX Threshold
381
    -- Bit [15:00] Prog Full Threshold
382
    -- Bit [31:16] Prog Empty Threshold   
383
    opb_write(C_ADR_RX_THRESH, 16#0006000C#);
384
 
385
 
386
    ---------------------------------------------------------------------------
387
    -- simple transfer 1 byte transmit/receive
388 17 dkoethe
    if (test(0) = '1') then
389
      -- write transmit data
390
      opb_write(C_ADR_TX_DATA, 16#78#);
391 12 dkoethe
 
392 17 dkoethe
      -- enable GDE and TX_EN and RX_EN
393
      opb_write(C_ADR_CTL, 16#7#);
394 12 dkoethe
 
395 17 dkoethe
      -- send/receive 8bit
396
      spi_transfer(conv_std_logic_vector(16#B5#, C_SR_WIDTH));
397 12 dkoethe
 
398 17 dkoethe
      -- compare transmit data
399
      assert (spi_value_in = conv_std_logic_vector(16#78#, C_SR_WIDTH)) report "Master Receive Failure" severity failure;
400 12 dkoethe
 
401 17 dkoethe
      -- read RX-Data Value
402
      opb_read(C_ADR_RX_DATA);
403 12 dkoethe
 
404 17 dkoethe
      -- compare receive data
405
      assert (opb_read_data = conv_std_logic_vector(16#B5#, C_SR_WIDTH)) report "Master Transfer Failure" severity failure;
406
 
407
    end if;
408 12 dkoethe
    ---------------------------------------------------------------------------
409
    -- transfer 4 bytes and check flags
410 17 dkoethe
    if (test(1) = '1') then
411
      opb_read(C_ADR_STATUS);
412
      -- only empty Bit and prog_empty set
413 12 dkoethe
 
414 17 dkoethe
      temp                           := (others => '0');
415
      temp(SPI_SR_Bit_TX_Prog_empty) := '1';
416
      temp(SPI_SR_Bit_TX_Empty)      := '1';
417
      temp(SPI_SR_Bit_RX_Prog_empty) := '1';
418
      temp(SPI_SR_Bit_RX_Empty)      := '1';
419
      temp(SPI_SR_Bit_SS_n)          := '1';
420 12 dkoethe
 
421 17 dkoethe
      assert (opb_read_data = temp) report "Check Status Bits: TX: 0, RX: 0" severity failure;
422 12 dkoethe
 
423 17 dkoethe
      -- write transmit data
424
      opb_write(C_ADR_TX_DATA, 16#01#);
425 12 dkoethe
 
426
 
427 17 dkoethe
      opb_read(C_ADR_STATUS);
428
      temp                           := (others => '0');
429
      temp(SPI_SR_Bit_TX_Prog_empty) := '1';
430
      temp(SPI_SR_Bit_RX_Prog_empty) := '1';
431
      temp(SPI_SR_Bit_RX_Empty)      := '1';
432
      temp(SPI_SR_Bit_SS_n)          := '1';
433 12 dkoethe
 
434 17 dkoethe
      assert (opb_read_data = temp) report "Check Status Bits: TX: 1, RX:0" severity failure;
435
    end if;
436
---------------------------------------------------------------------------
437
-- write until TX-FIFO asserts full, read until RX-FIFO asserts full, read an
438
-- compare data
439
    if (test(2) = '1') then
440
      for i in 2 to 255 loop
441
        opb_write(C_ADR_TX_DATA, i);
442
        opb_read(C_ADR_STATUS);
443
        -- check TX prog_empty deassert
444
        if ((opb_read_data(SPI_SR_Bit_TX_Prog_empty) = '0') and first(0) = '0') then
445
          assert (false) report "TX prog_emtpy deassert after " & integer'image(i) & " writes." severity warning;
446
          first(0) := '1';
447
        end if;
448 12 dkoethe
 
449 17 dkoethe
        -- check TX prog_full assert
450
        if ((opb_read_data(SPI_SR_Bit_TX_Prog_Full) = '1') and first(1) = '0') then
451
          assert (false) report "TX prog_full assert after " & integer'image(i) & " writes." severity warning;
452
          first(1) := '1';
453
        end if;
454 12 dkoethe
 
455 17 dkoethe
        -- check TX full assert
456
        if ((opb_read_data(SPI_SR_Bit_TX_Full) = '1') and first(2) = '0') then
457
          assert (false) report "TX full assert after " & integer'image(i) & " writes." severity warning;
458
          first(2) := '1';
459
          exit;
460
        end if;
461
 
462
      end loop;  -- i
463 12 dkoethe
 
464 17 dkoethe
      ---------------------------------------------------------------------------
465
      first := (others => '0');
466 12 dkoethe
 
467 17 dkoethe
      -- 16 spi transfer
468
      for i in 1 to 255 loop
469
        spi_transfer(conv_std_logic_vector(i, C_SR_WIDTH));
470
        opb_read(C_ADR_STATUS);
471 12 dkoethe
 
472 17 dkoethe
        -------------------------------------------------------------------------
473
        -- check TX FIFO flags
474
        -- check TX full deassert
475
        if ((opb_read_data(SPI_SR_Bit_TX_Full) = '0') and first(0) = '0') then
476
          assert (false) report "TX full deassert after " & integer'image(i) & " transfers." severity warning;
477
          first(0) := '1';
478
        end if;
479 12 dkoethe
 
480 17 dkoethe
        -- check TX prog_full deassert
481
        if ((opb_read_data(SPI_SR_Bit_TX_Prog_Full) = '0') and first(1) = '0') then
482
          assert (false) report "TX prog_full deassert after " & integer'image(i) & " transfers." severity warning;
483
          first(1) := '1';
484
        end if;
485 12 dkoethe
 
486 17 dkoethe
        -- check TX prog_emtpy assert
487
        if ((opb_read_data(SPI_SR_Bit_TX_Prog_empty) = '1') and first(2) = '0') then
488
          assert (false) report "TX prog_empty assert after " & integer'image(i) & " transfers." severity warning;
489
          first(2) := '1';
490
        end if;
491 12 dkoethe
 
492 17 dkoethe
        -- check TX emtpy assert
493
        if ((opb_read_data(SPI_SR_Bit_TX_Empty) = '1') and first(3) = '0') then
494
          assert (false) report "TX empty assert after " & integer'image(i) & " transfers." severity warning;
495
          first(3) := '1';
496
        end if;
497 12 dkoethe
 
498 17 dkoethe
        -------------------------------------------------------------------------
499
        -- check RX FIFO flags
500
        -- check RX empty deassert
501
        if ((opb_read_data(SPI_SR_Bit_RX_Empty) = '0') and first(4) = '0') then
502
          assert (false) report "RX empty deassert after " & integer'image(i) & " transfers." severity warning;
503
          first(4) := '1';
504
        end if;
505 12 dkoethe
 
506 17 dkoethe
        -- check RX prog_empty deassert
507
        if ((opb_read_data(SPI_SR_Bit_RX_Prog_empty) = '0') and first(5) = '0') then
508
          assert (false) report "RX prog_empty deassert after " & integer'image(i) & " transfers." severity warning;
509
          first(5) := '1';
510
        end if;
511 12 dkoethe
 
512 17 dkoethe
        -- check RX prog_full deassert
513
        if ((opb_read_data(SPI_SR_Bit_RX_Prog_Full) = '1') and first(6) = '0') then
514
          assert (false) report "RX prog_full assert after " & integer'image(i) & " transfers." severity warning;
515
          first(6) := '1';
516
        end if;
517 12 dkoethe
 
518 17 dkoethe
        -- check RX full deassert
519
        if ((opb_read_data(SPI_SR_Bit_RX_Full) = '1') and first(7) = '0') then
520
          assert (false) report "RX full assert after " & integer'image(i) & " transfers." severity warning;
521
          first(7) := '1';
522
          exit;
523
        end if;
524
      end loop;  -- i    
525 12 dkoethe
 
526
 
527 17 dkoethe
      ---------------------------------------------------------------------------
528
      -- read data from fifo
529
      first := (others => '0');
530 12 dkoethe
 
531 17 dkoethe
      for i in 1 to 255 loop
532
        opb_read(C_ADR_RX_DATA);
533 12 dkoethe
 
534 17 dkoethe
        -- check data
535
        assert (i = conv_integer(opb_read_data)) report "Read data failure at " & integer'image(i) severity failure;
536 12 dkoethe
 
537 17 dkoethe
        opb_read(C_ADR_STATUS);
538
        -- check RX FIFO flags
539 12 dkoethe
 
540 17 dkoethe
        -- check RX full deassert
541
        if ((opb_read_data(SPI_SR_Bit_RX_Full) = '0') and first(0) = '0') then
542
          assert (false) report "RX full deassert after " & integer'image(i) & " transfers." severity warning;
543
          first(0) := '1';
544
        end if;
545 12 dkoethe
 
546 17 dkoethe
        -- check RX prog_full deassert
547
        if ((opb_read_data(SPI_SR_Bit_RX_Prog_Full) = '0') and first(1) = '0') then
548
          assert (false) report "RX prog_full deassert after " & integer'image(i) & " transfers." severity warning;
549
          first(1) := '1';
550
        end if;
551 12 dkoethe
 
552 17 dkoethe
        -- check RX prog_empty assert
553
        if ((opb_read_data(SPI_SR_Bit_RX_Prog_empty) = '1') and first(2) = '0') then
554
          assert (false) report "RX prog_empty assert after " & integer'image(i) & " transfers." severity warning;
555
          first(2) := '1';
556
        end if;
557 12 dkoethe
 
558
 
559 17 dkoethe
        -- check RX empty assert
560
        if ((opb_read_data(SPI_SR_Bit_RX_Empty) = '1') and first(3) = '0') then
561
          assert (false) report "RX empty assert after " & integer'image(i) & " transfers." severity warning;
562
          first(3) := '1';
563
          exit;
564
        end if;
565
      end loop;  -- i        
566
    end if;
567 12 dkoethe
 
568 17 dkoethe
---------------------------------------------------------------------------
569
-- check FIFO Reset form underflow condition
570
    if (test(3) = '1') then
571
      -- add transfer to go in underflow condition
572
      spi_transfer(conv_std_logic_vector(0, C_SR_WIDTH));
573 12 dkoethe
 
574 17 dkoethe
      -- reset core (Bit 4)
575
      opb_write(C_ADR_CTL, 16#F#);
576 12 dkoethe
 
577 17 dkoethe
      --Check flags
578
      temp                           := (others => '0');
579
      temp(SPI_SR_Bit_TX_Prog_empty) := '1';
580
      temp(SPI_SR_Bit_TX_Empty)      := '1';
581
      temp(SPI_SR_Bit_RX_Prog_empty) := '1';
582
      temp(SPI_SR_Bit_RX_Empty)      := '1';
583
      temp(SPI_SR_Bit_SS_n)          := '1';
584 12 dkoethe
 
585 17 dkoethe
      assert (opb_read_data = temp) report "Status Bits after Reset failure" severity failure;
586
    end if;
587
-------------------------------------------------------------------------------    
588
-- check FIFO Flags IRQ Generation
589
    if (test(4) = '1') then
590
      -- enable all IRQ except Chip select
591
      opb_write(C_ADR_IER, 16#3F#);
592
      -- global irq enable
593
      opb_write(C_ADR_DGIE, 16#1#);
594 12 dkoethe
 
595 17 dkoethe
      -- fill transmit buffer
596
      for i in 1 to 255 loop
597
        opb_write(C_ADR_TX_DATA, i);
598
        opb_read(C_ADR_STATUS);
599
        -- check TX full assert
600
        if ((opb_read_data(SPI_SR_Bit_TX_Full) = '1')) then
601
          assert (false) report "TX full assert after " & integer'image(i) & " writes." severity warning;
602
          exit;
603
        end if;
604
      end loop;  -- i
605 12 dkoethe
 
606 17 dkoethe
      -- SPI-Data Transfers an Check TX Prog_Empty and TX Empty IRQ Generation
607
      for i in 1 to 255 loop
608
        spi_transfer(conv_std_logic_vector(0, C_SR_WIDTH));
609
        wait until rising_edge(OPB_Clk);
610
        wait until rising_edge(OPB_Clk);
611
        wait until rising_edge(OPB_Clk);
612
        if (opb_irq = '1') then
613
          opb_read(C_ADR_ISR);
614
          -- TX Prog Empty
615
          if ((opb_read_data(SPI_ISR_Bit_TX_Prog_Empty) = '1')) then
616
            report "TX prog empty irq after " & integer'image(i) & " transfers.";
617
            -- clear_irq
618
            opb_write(C_ADR_ISR, 16#1#);
619
            wait until rising_edge(OPB_Clk);
620
            assert (opb_irq = '0') report "TX Prog Empty not cleared" severity warning;
621
          end if;
622 12 dkoethe
 
623 17 dkoethe
          -- TX EMPTY
624
          if ((opb_read_data(SPI_ISR_Bit_TX_Empty) = '1')) then
625
            report "TX empty irq after " & integer'image(i) & " transfers.";
626
            -- clear_irq
627
            opb_write(C_ADR_ISR, 16#2#);
628
            wait until rising_edge(OPB_Clk);
629
            assert (opb_irq = '0') report "IRQ TX Empty not cleared" severity warning;
630
          end if;
631 12 dkoethe
 
632 17 dkoethe
          -- TX Underflow
633
          if ((opb_read_data(SPI_ISR_Bit_TX_Underflow) = '1')) then
634
            report "TX underflow irq after " & integer'image(i) & " transfers.";
635
            -- clear_irq
636
            opb_write(C_ADR_ISR, 16#4#);
637
            wait until rising_edge(OPB_Clk);
638
            assert (opb_irq = '0') report "IRQ TX underflow not cleared" severity warning;
639
          end if;
640
 
641
          -- RX Prog Full
642
          if ((opb_read_data(SPI_ISR_Bit_RX_Prog_Full) = '1')) then
643
            report "RX prog full irq after " & integer'image(i) & " transfers.";
644
            -- clear_irq
645
            opb_write(C_ADR_ISR, 16#8#);
646
            wait until rising_edge(OPB_Clk);
647
            assert (opb_irq = '0') report "RX Prog Full not cleared" severity warning;
648
          end if;
649
 
650
          -- RX Full
651
          if ((opb_read_data(SPI_ISR_Bit_RX_Full) = '1')) then
652
            report "RX full irq after " & integer'image(i) & " transfers.";
653
            -- clear_irq
654
            opb_write(C_ADR_ISR, 16#10#);
655
            wait until rising_edge(OPB_Clk);
656
            assert (opb_irq = '0') report "RX Full not cleared" severity warning;
657
          end if;
658
 
659
          -- RX Overflow
660
          if ((opb_read_data(SPI_ISR_Bit_RX_Overflow) = '1')) then
661
            report "RX overflow irq after " & integer'image(i) & " transfers.";
662
            -- clear_irq
663
            opb_write(C_ADR_ISR, 2**SPI_ISR_Bit_RX_Overflow);
664
            wait until rising_edge(OPB_Clk);
665
            assert (opb_irq = '0') report "RX Overflow not cleared" severity warning;
666
            exit;
667
          end if;
668
 
669
        end if;
670
 
671
      end loop;  -- i    
672
    end if;
673
---------------------------------------------------------------------------
674
    -- check slave select irq
675
    if (test(5) = '1') then
676
      -- reset core
677
      opb_write(C_ADR_CTL, 16#F#);
678
 
679
      -- eable Chip select fall/rise IRQ
680
      opb_write(C_ADR_IER, 16#C0#);
681
 
682
      ss_n <= '0';
683 12 dkoethe
      wait until rising_edge(OPB_Clk);
684
      wait until rising_edge(OPB_Clk);
685
      wait until rising_edge(OPB_Clk);
686
      if (opb_irq = '1') then
687
        opb_read(C_ADR_ISR);
688 17 dkoethe
        if ((opb_read_data(SPI_ISR_Bit_SS_Fall) = '1')) then
689
          report "SS Fall irq found";
690 12 dkoethe
          -- clear_irq
691 17 dkoethe
          opb_write(C_ADR_ISR, 2**SPI_ISR_Bit_SS_Fall);
692 12 dkoethe
          wait until rising_edge(OPB_Clk);
693 17 dkoethe
          assert (opb_irq = '0') report "SS_Fall IRQ  not cleared" severity warning;
694 12 dkoethe
        end if;
695 17 dkoethe
      end if;
696 12 dkoethe
 
697 17 dkoethe
      ss_n <= '1';
698
      wait until rising_edge(OPB_Clk);
699
      wait until rising_edge(OPB_Clk);
700
      wait until rising_edge(OPB_Clk);
701
      if (opb_irq = '1') then
702
        opb_read(C_ADR_ISR);
703
        if ((opb_read_data(SPI_ISR_Bit_SS_Rise) = '1')) then
704
          report "SS Rise irq found";
705 12 dkoethe
          -- clear_irq
706 17 dkoethe
          opb_write(C_ADR_ISR, 2**SPI_ISR_Bit_SS_Rise);
707 12 dkoethe
          wait until rising_edge(OPB_Clk);
708 17 dkoethe
          assert (opb_irq = '0') report "SS_Rise IRQ  not cleared" severity warning;
709 12 dkoethe
        end if;
710
      end if;
711
    end if;
712
-------------------------------------------------------------------------------
713
    -- test opb Master Transfer
714 17 dkoethe
    if (test(6) = '1') then
715 27 dkoethe
 
716
      -- enable SPI and CRC
717
      opb_write(C_ADR_CTL, 2**C_OPB_CTL_REG_DGE+2**C_OPB_CTL_REG_TX_EN+2**C_OPB_CTL_REG_RX_EN+2**C_OPB_CTL_REG_CRC_EN);
718 17 dkoethe
      -- write TX Threshold
719
      -- Bit [15:00] Prog Full Threshold
720
      -- Bit [31:16] Prog Empty Threshold   
721
      opb_write(C_ADR_TX_THRESH, 16#0005000B#);
722 12 dkoethe
 
723 17 dkoethe
      -- write RX Threshold
724
      -- Bit [15:00] Prog Full Threshold
725
      -- Bit [31:16] Prog Empty Threshold   
726 12 dkoethe
 
727 17 dkoethe
      -- Pog full must greater or equal than 16(Block Transfer Size)! 
728
      opb_write(C_ADR_RX_THRESH, 16#0006000F#);
729 12 dkoethe
 
730 17 dkoethe
      -- set transmit buffer Base Adress
731
      opb_write(C_ADR_TX_DMA_ADDR, 16#24000000#);
732 27 dkoethe
      -- set block number
733
      opb_write(C_ADR_TX_DMA_NUM, 1);
734
 
735
      -- set RX-Buffer base adress
736
      opb_write(C_ADR_RX_DMA_ADDR, 16#25000000#);
737
      -- set block number
738
      opb_write(C_ADR_RX_DMA_NUM, 1);
739
 
740
      -- enable dma write transfer
741
      opb_write(C_ADR_RX_DMA_CTL, 1);
742
 
743 17 dkoethe
      -- enable dma read transfer
744 27 dkoethe
      opb_write(C_ADR_TX_DMA_CTL, 1);
745 12 dkoethe
 
746 27 dkoethe
      -- time to fill fifo from ram
747 17 dkoethe
      for i in 0 to 15 loop
748 27 dkoethe
        wait until rising_edge(OPB_Clk);
749 17 dkoethe
      end loop;  -- i
750 12 dkoethe
 
751 17 dkoethe
      -- transfer 16 bytes
752 27 dkoethe
      -- data block
753 17 dkoethe
      for i in 0 to 15 loop
754
        spi_transfer(conv_std_logic_vector(i, C_SR_WIDTH));
755
        assert (conv_integer(spi_value_in) = i) report "DMA Transfer 1 read data failure" severity failure;
756
      end loop;  -- i
757 12 dkoethe
 
758 27 dkoethe
      -- crc_block
759
      for i in 16 to 30 loop
760
        spi_transfer(conv_std_logic_vector(i, C_SR_WIDTH));
761
        assert (conv_integer(spi_value_in) = i) report "DMA Transfer 1 read data failure" severity failure;
762 17 dkoethe
      end loop;  -- i
763 12 dkoethe
 
764 27 dkoethe
      -- check CRC
765
      spi_transfer(conv_std_logic_vector(31, C_SR_WIDTH));
766
      assert (conv_integer(spi_value_in) = 16#eb99fa90#) report "TX CRC_Failure"  severity failure;
767 12 dkoethe
 
768 27 dkoethe
      -- wait until RX transfer done
769
      for i in 0 to 15 loop
770
      opb_read(C_ADR_STATUS);
771
      if (opb_read_data(SPI_SR_Bit_RX_DMA_Done) ='1') then
772
        exit;
773
      end if;
774
      wait for 1 us;
775 17 dkoethe
      end loop;  -- i
776 12 dkoethe
 
777 27 dkoethe
      -- check TX CRC Register
778
      opb_read(C_ADR_TX_CRC);
779
      assert (conv_integer(opb_read_data)=16#eb99fa90#) report "TX Register CRC Failure" severity failure;
780
 
781
      -- check RX CRC Register
782
      opb_read(C_ADR_RX_CRC);
783
      assert (conv_integer(opb_read_data)=16#eb99fa90#) report "RX Register CRC Failure" severity failure;
784 12 dkoethe
 
785 17 dkoethe
      wait for 1 us;
786
    end if;
787
---------------------------------------------------------------------------
788 12 dkoethe
 
789
 
790 17 dkoethe
 
791 12 dkoethe
    assert false report "Simulation sucessful" severity failure;
792
  end process WaveGen_Proc;
793
 
794
 
795
 
796
end behavior;
797
 
798
-------------------------------------------------------------------------------
799
 
800
configuration opb_spi_slave_tb_behavior_cfg of opb_spi_slave_tb is
801
  for behavior
802 17 dkoethe
  end for;
803 12 dkoethe
end opb_spi_slave_tb_behavior_cfg;
804
 
805
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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