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

Subversion Repositories rio

[/] [rio/] [branches/] [2.0.0-development/] [bench/] [vhdl/] [TestRioWbBridge.vhd] - Blame information for rev 44

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

Line No. Rev Author Line
1 42 magro732
-------------------------------------------------------------------------------
2
-- 
3
-- RapidIO IP Library Core
4
-- 
5
-- This file is part of the RapidIO IP library project
6
-- http://www.opencores.org/cores/rio/
7
-- 
8
-- Description
9
-- Contains automatic test code to verify a RioWbBridge implementation.
10
-- 
11
-- To Do:
12
-- -
13
-- 
14
-- Author(s): 
15
-- - Magnus Rosenius, magro732@opencores.org 
16
-- 
17
-------------------------------------------------------------------------------
18
-- 
19
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
20
-- 
21
-- This source file may be used and distributed without 
22
-- restriction provided that this copyright statement is not 
23
-- removed from the file and that any derivative work contains 
24
-- the original copyright notice and the associated disclaimer. 
25
-- 
26
-- This source file is free software; you can redistribute it 
27
-- and/or modify it under the terms of the GNU Lesser General 
28
-- Public License as published by the Free Software Foundation; 
29
-- either version 2.1 of the License, or (at your option) any 
30
-- later version. 
31
-- 
32
-- This source is distributed in the hope that it will be 
33
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
34
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
35
-- PURPOSE. See the GNU Lesser General Public License for more 
36
-- details. 
37
-- 
38
-- You should have received a copy of the GNU Lesser General 
39
-- Public License along with this source; if not, download it 
40
-- from http://www.opencores.org/lgpl.shtml 
41
-- 
42
-------------------------------------------------------------------------------
43
 
44
 
45
-- REMARK: Move the testport package and entities to a seperate file.
46
-------------------------------------------------------------------------------
47
-- 
48
-------------------------------------------------------------------------------
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use work.rio_common.all;
52
 
53
-------------------------------------------------------------------------------
54
-- 
55
-------------------------------------------------------------------------------
56
package TestPortPackage is
57
  constant ADDRESS_WIDTH : natural := 31;
58
  constant DATA_SIZE_MAX : natural := 32;
59
 
60
  type TestPortMessageWishbone is record
61
    writeAccess : boolean;
62
    address : std_logic_vector(ADDRESS_WIDTH-1 downto 0);
63
    byteSelect : std_logic_vector(7 downto 0);
64
    length : natural range 1 to DATA_SIZE_MAX;
65 44 magro732
    data : DoublewordArray(0 to DATA_SIZE_MAX-1);
66 42 magro732
    latency : natural;
67
  end record;
68
 
69
  type TestPortMessageSymbol is record
70
    symbolType : std_logic_vector(1 downto 0);
71
    symbolContent : std_logic_vector(31 downto 0);
72
    ignoreIdle : boolean;
73
  end record;
74
 
75
  type TestPortMessagePacketBuffer is record
76
    frame : RioFrame;
77
    willAbort : boolean;
78
  end record;
79
 
80
  -----------------------------------------------------------------------------
81
  -- 
82
  -----------------------------------------------------------------------------
83
 
84
  component TestPortWishbone is
85
    port(
86
      clk : in std_logic;
87
      areset_n : in std_logic;
88
 
89
      messageEmpty_o : out std_logic;
90
      messageWrite_i : in std_logic;
91
      message_i : in TestPortMessageWishbone;
92
      messageAck_o : out std_logic;
93
 
94
      cyc_i : in std_logic;
95
      stb_i : in std_logic;
96
      we_i : in std_logic;
97
      adr_i : in std_logic_vector(30 downto 0);
98
      sel_i : in std_logic_vector(7 downto 0);
99
      dat_i : in std_logic_vector(63 downto 0);
100 44 magro732
      dat_o : out std_logic_vector(63 downto 0);
101 42 magro732
      err_o : out std_logic;
102
      ack_o : out std_logic);
103
  end component;
104
 
105
  component TestPortPacketBuffer is
106
    port(
107
      clk : in std_logic;
108
      areset_n : in std_logic;
109
 
110 44 magro732
      readEmpty_o : out std_logic;
111
      readWrite_i : in std_logic;
112
      readMessage_i : in TestPortMessagePacketBuffer;
113
      readAck_o : out std_logic;
114 42 magro732
 
115 44 magro732
      writeEmpty_o : out std_logic;
116
      writeWrite_i : in std_logic;
117
      writeMessage_i : in TestPortMessagePacketBuffer;
118
      writeAck_o : out std_logic;
119 42 magro732
 
120
      readFrameEmpty_o : out std_logic;
121
      readFrame_i : in std_logic;
122
      readFrameRestart_i : in std_logic;
123
      readFrameAborted_o : out std_logic;
124
      readWindowEmpty_o : out std_logic;
125
      readWindowReset_i : in std_logic;
126
      readWindowNext_i : in std_logic;
127
      readContentEmpty_o : out std_logic;
128
      readContent_i : in std_logic;
129
      readContentEnd_o : out std_logic;
130
      readContentData_o : out std_logic_vector(31 downto 0);
131
 
132
      writeFrame_i : in std_logic;
133
      writeFrameAbort_i : in std_logic;
134
      writeContent_i : in std_logic;
135
      writeContentData_i : in std_logic_vector(31 downto 0));
136
  end component;
137
 
138
  -----------------------------------------------------------------------------
139
  -- 
140
  -----------------------------------------------------------------------------
141
  procedure TestPortWishboneWrite(
142
    signal writeSignal : out std_logic;
143
    signal messageSignal : out TestPortMessageWishbone;
144
    signal ackSignal : in std_logic;
145
    constant writeAccess : in boolean;
146
    constant address : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
147
    constant byteSelect : in std_logic_vector(7 downto 0);
148
    constant length : in natural range 1 to DATA_SIZE_MAX;
149
    constant data : in DoublewordArray(0 to DATA_SIZE_MAX-1);
150
    constant latency : natural := 0);
151
 
152
  procedure TestPortPacketBufferWrite(
153
    signal writeSignal : out std_logic;
154
    signal messageSignal : out TestPortMessagePacketBuffer;
155
    signal ackSignal : in std_logic;
156
    constant frame : in RioFrame;
157
    constant willAbort : boolean := false);
158
 
159
end package;
160
 
161
-------------------------------------------------------------------------------
162
-- 
163
-------------------------------------------------------------------------------
164
package body TestPortPackage is
165
 
166
  -----------------------------------------------------------------------------
167
  -- 
168
  -----------------------------------------------------------------------------
169
  procedure TestPortWishboneWrite(
170
    signal writeSignal : out std_logic;
171
    signal messageSignal : out TestPortMessageWishbone;
172
    signal ackSignal : in std_logic;
173
    constant writeAccess : in boolean;
174
    constant address : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
175
    constant byteSelect : in std_logic_vector(7 downto 0);
176
    constant length : in natural range 1 to DATA_SIZE_MAX;
177
    constant data : in DoublewordArray(0 to DATA_SIZE_MAX-1);
178
    constant latency : natural := 0) is
179
  begin
180
    writeSignal <= '1';
181
    messageSignal.writeAccess <= writeAccess;
182
    messageSignal.address <= address;
183
    messageSignal.byteSelect <= byteSelect;
184
    messageSignal.length <= length;
185
    messageSignal.data <= data;
186
    messageSignal.latency <= latency;
187
    wait until ackSignal = '1';
188
    writeSignal <= '0';
189
    wait until ackSignal = '0';
190
  end procedure;
191
 
192
  -----------------------------------------------------------------------------
193
  -- 
194
  -----------------------------------------------------------------------------
195
  procedure TestPortPacketBufferWrite(
196
    signal writeSignal : out std_logic;
197
    signal messageSignal : out TestPortMessagePacketBuffer;
198
    signal ackSignal : in std_logic;
199
    constant frame : in RioFrame;
200
    constant willAbort : boolean := false) is
201
  begin
202
    writeSignal <= '1';
203
    messageSignal.frame <= frame;
204
    messageSignal.willAbort <= willAbort;
205
    wait until ackSignal = '1';
206
    writeSignal <= '0';
207
    wait until ackSignal = '0';
208
  end procedure;
209
 
210
end package body;
211
 
212
 
213
 
214
 
215
-------------------------------------------------------------------------------
216
-- 
217
-------------------------------------------------------------------------------
218
library ieee;
219
use ieee.std_logic_1164.all;
220
use ieee.numeric_std.all;
221
library std;
222
use std.textio.all;
223
use work.rio_common.all;
224
use work.TestPortPackage.all;
225
 
226
 
227
-------------------------------------------------------------------------------
228
-- 
229
-------------------------------------------------------------------------------
230
entity TestPortPacketBuffer is
231
  port(
232
    clk : in std_logic;
233
    areset_n : in std_logic;
234
 
235 44 magro732
    readEmpty_o : out std_logic;
236
    readWrite_i : in std_logic;
237
    readMessage_i : in TestPortMessagePacketBuffer;
238
    readAck_o : out std_logic;
239 42 magro732
 
240 44 magro732
    writeEmpty_o : out std_logic;
241
    writeWrite_i : in std_logic;
242
    writeMessage_i : in TestPortMessagePacketBuffer;
243
    writeAck_o : out std_logic;
244 42 magro732
 
245
    readFrameEmpty_o : out std_logic;
246
    readFrame_i : in std_logic;
247
    readFrameRestart_i : in std_logic;
248
    readFrameAborted_o : out std_logic;
249
    readWindowEmpty_o : out std_logic;
250
    readWindowReset_i : in std_logic;
251
    readWindowNext_i : in std_logic;
252
    readContentEmpty_o : out std_logic;
253
    readContent_i : in std_logic;
254
    readContentEnd_o : out std_logic;
255
    readContentData_o : out std_logic_vector(31 downto 0);
256
 
257
    -- writeFrameFull_o is missing yes, but you can control it from the testbench directly
258
    -- instead.
259
    writeFrame_i : in std_logic;
260
    writeFrameAbort_i : in std_logic;
261
    writeContent_i : in std_logic;
262
    writeContentData_i : in std_logic_vector(31 downto 0));
263
end entity;
264
 
265
 
266
-------------------------------------------------------------------------------
267
-- 
268
-------------------------------------------------------------------------------
269
architecture TestPortPacketBufferPortImpl of TestPortPacketBuffer is
270
  constant QUEUE_SIZE : natural := 63;
271 44 magro732
  type QueueArray is array (natural range <>) of TestPortMessagePacketBuffer;
272 42 magro732
 
273
  function QueueIndexInc(constant i : natural) return natural is
274
    variable returnValue : natural;
275
  begin
276
    if(i = QUEUE_SIZE) then
277
      returnValue := 0;
278
    else
279
      returnValue := i + 1;
280
    end if;
281
    return returnValue;
282
  end function;
283
 
284
begin
285
 
286
  -----------------------------------------------------------------------------
287
  -- 
288
  -----------------------------------------------------------------------------
289 44 magro732
  Reader: process
290 42 magro732
    variable frameQueue : QueueArray(0 to QUEUE_SIZE);
291
    variable front, back, window : natural range 0 to QUEUE_SIZE;
292
    variable frameIndex : natural;
293
  begin
294
    wait until areset_n = '1';
295
 
296
    readFrameEmpty_o <= '1';
297
    readFrameAborted_o <= '0';
298
    readWindowEmpty_o <= '1';
299
    readContentEmpty_o <= '1';
300
    readContentEnd_o <= '0';
301
    readContentData_o <= (others=>'0');
302
 
303
    front := 0;
304
    back := 0;
305
    window := 0;
306
    frameIndex := 0;
307 44 magro732
    readEmpty_o <= '1';
308
    readAck_o <= '0';
309 42 magro732
 
310
    loop
311 44 magro732
      wait until clk = '1' or readWrite_i = '1';
312 42 magro732
 
313
      if (clk'event) then
314
        if (readFrame_i = '1') then
315
          if (back /= front) then
316
            back := QueueIndexInc(back);
317
          else
318 44 magro732
            TestError("READ:BACK:reading when no frame is present");
319 42 magro732
          end if;
320
        end if;
321
 
322
        if (readFrameRestart_i = '1') then
323
          frameIndex := 0;
324
        end if;
325
 
326
        if (readWindowReset_i = '1') then
327
          window := back;
328
          frameIndex := 0;
329
        end if;
330
 
331
        if (readWindowNext_i = '1') then
332
          if (window /= front) then
333
            window := QueueIndexInc(window);
334
            frameIndex := 0;
335
          else
336 44 magro732
            TestError("READ:WINDOW:reading when no frame is present");
337 42 magro732
          end if;
338
        end if;
339
 
340
        if (readContent_i = '1') then
341
          if (back /= front) then
342
            if (frameIndex < frameQueue(window).frame.length) then
343
              readContentData_o <= frameQueue(window).frame.payload(frameIndex);
344
              frameIndex := frameIndex + 1;
345
              if (frameIndex = frameQueue(window).frame.length) then
346
                readContentEnd_o <= '1';
347
              else
348
                readContentEnd_o <= '0';
349
              end if;
350
            else
351 44 magro732
              TestError("READ:CONTENT:reading when frame has ended");
352 42 magro732
            end if;
353
          else
354 44 magro732
            TestError("READ:CONTENT:reading when no frame is present");
355 42 magro732
          end if;
356
        end if;
357
 
358
        if (front = back) then
359
          readFrameEmpty_o <= '1';
360
        else
361
          readFrameEmpty_o <= '0';
362
        end if;
363
 
364
        if (front = window) then
365
          readWindowEmpty_o <= '1';
366
          readContentEmpty_o <= '1';
367
        else
368
          readWindowEmpty_o <= '0';
369
          if (frameIndex /= frameQueue(window).frame.length) then
370
            readContentEmpty_o <= '0';
371
          else
372
            readContentEmpty_o <= '1';
373
          end if;
374
        end if;
375
 
376
        if (front = back) then
377 44 magro732
          readEmpty_o <= '1';
378 42 magro732
        else
379 44 magro732
          readEmpty_o <= '0';
380 42 magro732
        end if;
381 44 magro732
      elsif (readWrite_i'event) then
382
        frameQueue(front) := readMessage_i;
383 42 magro732
        front := QueueIndexInc(front);
384
 
385 44 magro732
        readEmpty_o <= '0';
386
        readAck_o <= '1';
387
        wait until readWrite_i = '0';
388
        readAck_o <= '0';
389 42 magro732
      end if;
390
    end loop;
391
  end process;
392
 
393
  -----------------------------------------------------------------------------
394
  -- 
395
  -----------------------------------------------------------------------------
396 44 magro732
  Writer: process
397 42 magro732
    variable frameQueue : QueueArray(0 to QUEUE_SIZE);
398
    variable front, back : natural range 0 to QUEUE_SIZE;
399
    variable frameIndex : natural range 0 to 69;
400
  begin
401
    wait until areset_n = '1';
402
 
403 44 magro732
    writeEmpty_o <= '1';
404
    writeAck_o <= '0';
405 42 magro732
 
406
    front := 0;
407
    back := 0;
408
    frameIndex := 0;
409
 
410
    loop
411 44 magro732
      wait until clk = '1' or writeWrite_i = '1';
412 42 magro732
 
413
      if (clk'event) then
414
 
415
        if (writeFrame_i = '1') then
416
          if (frameIndex = 0) then
417 44 magro732
            TestError("WRITE:Empty frame written.");
418 42 magro732
          end if;
419
          if (frameIndex /= frameQueue(back).frame.length) then
420 44 magro732
            TestError("WRITE:Frame with unmatching length was written.");
421 42 magro732
          end if;
422
          if (back /= front) then
423
            back := QueueIndexInc(back);
424
          else
425 44 magro732
            TestError("WRITE:Unexpected frame written.");
426 42 magro732
          end if;
427
          frameIndex := 0;
428
        end if;
429
 
430
        if (writeFrameAbort_i = '1') then
431
          if (back /= front) then
432
            if (frameQueue(back).willAbort) then
433 44 magro732
              TestCompare(frameIndex,
434
                          frameQueue(back).frame.length,
435
                          "frameIndex abort");
436 42 magro732
              back := QueueIndexInc(back);
437
            else
438 44 magro732
              TestError("WRITE:Not expecting this frame to abort.");
439 42 magro732
            end if;
440
          end if;
441
          frameIndex := 0;
442
        end if;
443
 
444
        if (writeContent_i = '1') then
445
          if (frameIndex < frameQueue(back).frame.length) then
446 44 magro732
            TestCompare(writeContentData_i,
447
                        frameQueue(back).frame.payload(frameIndex),
448
                        "frame content");
449 42 magro732
            frameIndex := frameIndex + 1;
450
          else
451 44 magro732
            TestError("WRITE:Receiving more frame content than expected.");
452 42 magro732
          end if;
453
        end if;
454
 
455
        if (front = back) then
456 44 magro732
          writeEmpty_o <= '1';
457 42 magro732
        else
458 44 magro732
          writeEmpty_o <= '0';
459 42 magro732
        end if;
460 44 magro732
      elsif (writeWrite_i'event) then
461
        frameQueue(front) := writeMessage_i;
462 42 magro732
        front := QueueIndexInc(front);
463
 
464 44 magro732
        writeEmpty_o <= '0';
465
        writeAck_o <= '1';
466
        wait until writeWrite_i = '0';
467
        writeAck_o <= '0';
468 42 magro732
      end if;
469
    end loop;
470
  end process;
471
 
472
end architecture;
473
 
474
 
475
 
476
-------------------------------------------------------------------------------
477
-- 
478
-------------------------------------------------------------------------------
479
library ieee;
480
use ieee.std_logic_1164.all;
481
use ieee.numeric_std.all;
482
library std;
483
use std.textio.all;
484
use work.rio_common.all;
485
use work.TestPortPackage.all;
486
 
487
 
488
-------------------------------------------------------------------------------
489
-- 
490
-------------------------------------------------------------------------------
491
entity TestPortWishbone is
492
  port(
493
    clk : in std_logic;
494
    areset_n : in std_logic;
495
 
496
    messageEmpty_o : out std_logic;
497
    messageWrite_i : in std_logic;
498
    message_i : in TestPortMessageWishbone;
499
    messageAck_o : out std_logic;
500
 
501
    cyc_i : in std_logic;
502
    stb_i : in std_logic;
503
    we_i : in std_logic;
504
    adr_i : in std_logic_vector(30 downto 0);
505
    sel_i : in std_logic_vector(7 downto 0);
506
    dat_i : in std_logic_vector(63 downto 0);
507 44 magro732
    dat_o : out std_logic_vector(63 downto 0);
508 42 magro732
    err_o : out std_logic;
509
    ack_o : out std_logic);
510
end entity;
511
 
512
 
513
-------------------------------------------------------------------------------
514
-- 
515
-------------------------------------------------------------------------------
516 44 magro732
architecture TestPortWishboneImpl of TestPortWishbone is
517 42 magro732
  constant QUEUE_SIZE : natural := 63;
518 44 magro732
  type QueueArray is array (natural range <>) of TestPortMessageWishbone;
519 42 magro732
 
520
  function QueueIndexInc(constant i : natural) return natural is
521
    variable returnValue : natural;
522
  begin
523
    if(i = QUEUE_SIZE) then
524
      returnValue := 0;
525
    else
526
      returnValue := i + 1;
527
    end if;
528
    return returnValue;
529
  end function;
530
 
531
begin
532
 
533
  -----------------------------------------------------------------------------
534
  -- 
535
  -----------------------------------------------------------------------------
536
  Slave: process
537
    variable queue : QueueArray(0 to QUEUE_SIZE);
538
    variable front, back : natural range 0 to QUEUE_SIZE;
539
    variable cyclePosition : natural;
540
    variable latencyCounter : natural;
541
  begin
542
    wait until areset_n = '1';
543
 
544
    messageEmpty_o <= '1';
545
    messageAck_o <= '0';
546
 
547
    dat_o <= (others=>'U');
548
    err_o <= '0';
549
    ack_o <= '0';
550
 
551
    front := 0;
552
    back := 0;
553
    cyclePosition := 0;
554
    latencyCounter := 0;
555
 
556
    loop
557
      wait until clk = '1' or messageWrite_i = '1';
558
 
559
      if (clk'event) then
560
        if (cyc_i = '1') then
561
          if (front /= back) then
562 44 magro732
            if (cyclePosition < queue(back).length) then
563
              TestCompare(stb_i, '1', "stb_i");
564
              if (queue(back).writeAccess) then
565
                TestCompare(we_i, '1', "we_i");
566
              else
567
                TestCompare(we_i, '0', "we_i");
568
              end if;
569
              -- REMARK: Add this...
570
              --TestCompare(adr_i, std_logic_vector(unsigned(queue(back).address)+cyclePosition), "adr_i");
571
              TestCompare(sel_i, queue(back).byteSelect, "sel_i");
572
              if (queue(back).writeAccess) then
573
                TestCompare(dat_i, queue(back).data(cyclePosition), "dat_i");
574
              end if;
575 42 magro732
 
576 44 magro732
              if (latencyCounter = queue(back).latency) then
577
                dat_o <= queue(back).data(cyclePosition);
578
                ack_o <= '1';
579
                latencyCounter := 0;
580
                cyclePosition := cyclePosition + 1;
581 42 magro732
              else
582 44 magro732
                dat_o <= (others=>'U');
583
                ack_o <= '0';
584
                latencyCounter := latencyCounter + 1;
585 42 magro732
              end if;
586
            else
587 44 magro732
              back := QueueIndexInc(back);
588
              cyclePosition := 0;
589
              latencyCounter := 0;
590
              dat_o <= (others=>'U');
591 42 magro732
              ack_o <= '0';
592
            end if;
593
          else
594
            TestError("Unexpected access.");
595
          end if;
596
        else
597 44 magro732
          if (cyclePosition /= 0) or (latencyCounter /= 0) then
598 42 magro732
            TestError("Cycle unexpectedly aborted.");
599
            cyclePosition := 0;
600
            latencyCounter := 0;
601
          end if;
602
          TestCompare(stb_i, '0', "stb_i");
603
        end if;
604
 
605
        if (front = back) then
606 44 magro732
          messageEmpty_o <= '1';
607 42 magro732
        else
608 44 magro732
          messageEmpty_o <= '0';
609 42 magro732
        end if;
610
      elsif (messageWrite_i'event) then
611
        queue(front) := message_i;
612
        front := QueueIndexInc(front);
613
 
614
        messageEmpty_o <= '0';
615
        messageAck_o <= '1';
616
        wait until messageWrite_i = '0';
617
        messageAck_o <= '0';
618
      end if;
619
    end loop;
620
  end process;
621
 
622
end architecture;
623
 
624
 
625
-------------------------------------------------------------------------------
626
-- TestRioWbBridge.
627
-------------------------------------------------------------------------------
628
 
629
library ieee;
630
use ieee.std_logic_1164.all;
631
use ieee.numeric_std.all;
632
use ieee.math_real.all;
633
library std;
634
use std.textio.all;
635
use work.rio_common.all;
636
use work.TestPortPackage.all;
637
 
638
 
639
-------------------------------------------------------------------------------
640
-- Entity for TestRioWbBridge.
641
-------------------------------------------------------------------------------
642
entity TestRioWbBridge is
643
end entity;
644
 
645
 
646
-------------------------------------------------------------------------------
647
-- Architecture for TestRioWbBridge.
648
-------------------------------------------------------------------------------
649
architecture TestRioWbBridgeImpl of TestRioWbBridge is
650
 
651
  component RioWbBridge is
652
    generic(
653
      EXTENDED_ADDRESS : natural range 0 to 2 := 0;
654
      DEVICE_IDENTITY : std_logic_vector(15 downto 0);
655
      DEVICE_VENDOR_IDENTITY : std_logic_vector(15 downto 0);
656
      DEVICE_REV : std_logic_vector(31 downto 0);
657
      ASSY_IDENTITY : std_logic_vector(15 downto 0);
658
      ASSY_VENDOR_IDENTITY : std_logic_vector(15 downto 0);
659
      ASSY_REV : std_logic_vector(15 downto 0));
660
    port(
661
      clk : in std_logic;
662
      areset_n : in std_logic;
663 44 magro732
      enable : in std_logic;
664 42 magro732
 
665
      readFrameEmpty_i : in std_logic;
666
      readFrame_o : out std_logic;
667
      readContent_o : out std_logic;
668
      readContentEnd_i : in std_logic;
669
      readContentData_i : in std_logic_vector(31 downto 0);
670
      writeFrameFull_i : in std_logic;
671
      writeFrame_o : out std_logic;
672
      writeFrameAbort_o : out std_logic;
673
      writeContent_o : out std_logic;
674
      writeContentData_o : out std_logic_vector(31 downto 0);
675
 
676
      cyc_o : out std_logic;
677
      stb_o : out std_logic;
678
      we_o : out std_logic;
679
      adr_o : out std_logic_vector(16*EXTENDED_ADDRESS+30 downto 0);
680
      sel_o : out std_logic_vector(7 downto 0);
681
      dat_o : out std_logic_vector(63 downto 0);
682
      dat_i : in std_logic_vector(63 downto 0);
683
      err_i : in std_logic;
684
      ack_i : in std_logic);
685
  end component;
686
 
687
  -----------------------------------------------------------------------------
688
  -- 
689
  -----------------------------------------------------------------------------
690
 
691
  signal clk : std_logic;
692
  signal areset_n : std_logic;
693
  signal enable : std_logic;
694
 
695
  signal writeFrameFull : std_logic;
696
  signal writeFrame : std_logic;
697
  signal writeFrameAbort : std_logic;
698
  signal writeContent : std_logic;
699
  signal writeContentData : std_logic_vector(31 downto 0);
700
 
701
  signal readFrameEmpty : std_logic;
702
  signal readFrame : std_logic;
703
  signal readFrameRestart : std_logic;
704
  signal readFrameAborted : std_logic;
705
  signal readContentEmpty : std_logic;
706
  signal readContent : std_logic;
707
  signal readContentEnd : std_logic;
708
  signal readContentData : std_logic_vector(31 downto 0);
709
 
710
  signal wbCyc : std_logic;
711
  signal wbStb : std_logic;
712
  signal wbWe : std_logic;
713
  signal wbAdr : std_logic_vector(30 downto 0);
714
  signal wbSel : std_logic_vector(7 downto 0);
715
  signal wbDatWrite : std_logic_vector(63 downto 0);
716
  signal wbDatRead : std_logic_vector(63 downto 0);
717
  signal wbAck : std_logic;
718
  signal wbErr : std_logic;
719
 
720
  signal outboundEmpty : std_logic;
721
  signal outboundWrite : std_logic;
722
  signal outboundMessage : TestPortMessagePacketBuffer;
723
  signal outboundAck : std_logic;
724
 
725
  signal inboundEmpty : std_logic;
726
  signal inboundWrite : std_logic;
727
  signal inboundMessage : TestPortMessagePacketBuffer;
728
  signal inboundAck : std_logic;
729
 
730
  signal wbMessageEmpty : std_logic;
731
  signal wbMessageWrite : std_logic;
732
  signal wbMessage : TestPortMessageWishbone;
733
  signal wbMessageAck : std_logic;
734
 
735
begin
736
 
737
  -----------------------------------------------------------------------------
738
  -- Clock generation.
739
  -----------------------------------------------------------------------------
740
  ClockGenerator: process
741
  begin
742
    clk <= '0';
743
    wait for 20 ns;
744
    clk <= '1';
745
    wait for 20 ns;
746
  end process;
747
 
748
 
749
  -----------------------------------------------------------------------------
750
  -- Serial port emulator.
751
  -----------------------------------------------------------------------------
752
  TestDriver: process
753
 
754
    -----------------------------------------------------------------------------
755
    -- Procedures to handle outbound and inbound packets.
756
    -----------------------------------------------------------------------------
757
    procedure OutboundFrame(constant frame : in RioFrame) is
758
    begin
759
      TestPortPacketBufferWrite(outboundWrite, outboundMessage, outboundAck,
760
                                frame, false);
761
    end procedure;
762
 
763
    procedure InboundFrame(constant frame : in RioFrame) is
764
    begin
765
      TestPortPacketBufferWrite(inboundWrite, inboundMessage, inboundAck,
766
                                frame, false);
767
    end procedure;
768
 
769
    ---------------------------------------------------------------------------
770
    -- Procedure to handle wishbone accesses.
771
    ---------------------------------------------------------------------------
772
    procedure SetSlaveAccess(constant writeAccess : in boolean;
773
                             constant address : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
774
                             constant byteSelect : in std_logic_vector(7 downto 0);
775
                             constant length : in natural range 1 to DATA_SIZE_MAX;
776
                             constant data : in DoublewordArray(0 to DATA_SIZE_MAX-1);
777 44 magro732
                             constant latency : natural := 1) is
778 42 magro732
    begin
779
      TestPortWishboneWrite(wbMessageWrite, wbMessage, wbMessageAck,
780
                            writeAccess, address, byteSelect, length, data, latency);
781
    end procedure;
782 44 magro732
 
783
    ---------------------------------------------------------------------------
784
    -- 
785
    ---------------------------------------------------------------------------
786
    function getReadSize(constant rdsize : in std_logic_vector(3 downto 0);
787
                         constant wdptr : in std_logic) return natural is
788
    begin
789
      case rdsize is
790
        when "0000" | "0001" | "0010" | "0011" =>
791
          return 1;
792
        when "0100" | "0110" =>
793
          return 1;
794
        when "0101" =>
795
          return 1;
796
        when "1000" =>
797
          return 1;
798
        when "0111" =>
799
          return 1;
800
        when "1001" =>
801
          return 1;
802
        when "1010" =>
803
          return 1;
804
        when "1011" =>
805
          if (wdptr = '0') then
806
            return 1;
807
          else
808
            return 2;
809
          end if;
810
        when "1100" =>
811
          if (wdptr = '0') then
812
            return 4;
813
          else
814
            return 8;
815
          end if;
816
        when "1101" =>
817
          if (wdptr = '0') then
818
            return 12;
819
          else
820
            return 16;
821
          end if;
822
        when "1110" =>
823
          if (wdptr = '0') then
824
            return 20;
825
          else
826
            return 24;
827
          end if;
828
        when "1111" =>
829
          if (wdptr = '0') then
830
            return 28;
831
          else
832
            return 32;
833
          end if;
834
        when others =>
835
          return 0;
836
      end case;
837
    end function;
838 42 magro732
 
839 44 magro732
    function getReadMask(constant rdsize : in std_logic_vector(3 downto 0);
840
                         constant wdptr : in std_logic) return std_logic_vector is
841
    begin
842
      case rdsize is
843
        when "0000" =>
844
          if (wdptr = '0') then
845
            return "10000000";
846
          else
847
            return "00001000";
848
          end if;
849
        when "0001" =>
850
          if (wdptr = '0') then
851
            return "01000000";
852
          else
853
            return "00000100";
854
          end if;
855
        when "0010" =>
856
          if (wdptr = '0') then
857
            return "00100000";
858
          else
859
            return "00000010";
860
          end if;
861
        when "0011" =>
862
          if (wdptr = '0') then
863
            return "00010000";
864
          else
865
            return "00000001";
866
          end if;
867
        when "0100" =>
868
          if (wdptr = '0') then
869
            return "11000000";
870
          else
871
            return "00001100";
872
          end if;
873
        when "0110" =>
874
          if (wdptr = '0') then
875
            return "00110000";
876
          else
877
            return "00000011";
878
          end if;
879
        when "0101" =>
880
          if (wdptr = '0') then
881
            return "11100000";
882
          else
883
            return "00000111";
884
          end if;
885
        when "1000" =>
886
          if (wdptr = '0') then
887
            return "11110000";
888
          else
889
            return "00001111";
890
          end if;
891
        when "0111" =>
892
          if (wdptr = '0') then
893
            return "11111000";
894
          else
895
            return "00011111";
896
          end if;
897
        when "1001" =>
898
          if (wdptr = '0') then
899
            return "11111100";
900
          else
901
            return "00111111";
902
          end if;
903
        when "1010" =>
904
          if (wdptr = '0') then
905
            return "11111110";
906
          else
907
            return "01111111";
908
          end if;
909
        when others =>
910
          return "11111111";
911
      end case;
912
    end function;
913 42 magro732
 
914
    ---------------------------------------------------------------------------
915
    -- 
916
    ---------------------------------------------------------------------------
917
    variable seed1 : positive := 1;
918
    variable seed2: positive := 1;
919
 
920 44 magro732
    variable rdsize : std_logic_vector(3 downto 0);
921
    variable wdptr : std_logic;
922 42 magro732
    variable ioData : DoubleWordArray(0 to 31);
923
    variable frame : RioFrame;
924
 
925
  begin
926
    areset_n <= '0';
927 44 magro732
    enable <= '1';
928 42 magro732
 
929 44 magro732
    inboundWrite <= '0';
930
    outboundWrite <= '0';
931
    wbMessageWrite <= '0';
932
 
933 42 magro732
    writeFrameFull <= '0';
934
 
935
    wait until clk'event and clk = '1';
936
    wait until clk'event and clk = '1';
937
    areset_n <= '1';
938
    wait until clk'event and clk = '1';
939
    wait until clk'event and clk = '1';
940
 
941
    ---------------------------------------------------------------------------
942
    PrintS("-----------------------------------------------------------------");
943 44 magro732
    PrintS("TG_RioWbBridge");
944 42 magro732
    PrintS("-----------------------------------------------------------------");
945 44 magro732
    PrintS("TG_RioWbBridge-TC1");
946
    PrintS("Description: Test maintenance requests.");
947 42 magro732
    PrintS("Requirement: XXXXX");
948
    PrintS("-----------------------------------------------------------------");
949
    PrintS("Step 1:");
950
    PrintS("Action: Send maintenance read request for one word on even offset.");
951
    PrintS("Result: Check the accesses on the external configuration port.");
952
    PrintS("-----------------------------------------------------------------");
953
    ---------------------------------------------------------------------------
954 44 magro732
    PrintR("TG_RioWbBridge-TC1-Step1");
955 42 magro732
    ---------------------------------------------------------------------------
956
 
957 44 magro732
    ---------------------------------------------------------------------------
958
    PrintS("-----------------------------------------------------------------");
959
    PrintS("TG_RioWbBridge-TC2");
960
    PrintS("Description: Test request class packets.");
961
    PrintS("Requirement: XXXXX");
962
    PrintS("-----------------------------------------------------------------");
963
    PrintS("Step 1:");
964
    PrintS("Action: Send maintenance read request for one word on even offset.");
965
    PrintS("Result: Check the accesses on the external configuration port.");
966
    PrintS("-----------------------------------------------------------------");
967
    ---------------------------------------------------------------------------
968
    PrintR("TG_RioWbBridge-TC2-Step1");
969
    ---------------------------------------------------------------------------
970
    -- REMARK: Change the address also...
971
    for i in 0 to 15 loop
972
      for j in 0 to 1 loop
973
        rdsize := std_logic_vector(to_unsigned(i, 4));
974
        if (j = 0) then
975
          wdptr := '0';
976
        else
977
          wdptr:= '1';
978
        end if;
979
 
980
        CreateRandomPayload(ioData, seed1, seed2);
981 42 magro732
 
982 44 magro732
        InboundFrame(RioFrameCreate(ackId=>"00000", vc=>'0', crf=>'0', prio=>"00",
983
                                    tt=>"01", ftype=>FTYPE_REQUEST_CLASS,
984
                                    sourceId=>x"dead", destId=>x"beef",
985
                                    payload=>RioNread(rdsize=>rdsize,
986 42 magro732
                                                      tid=>x"aa",
987 44 magro732
                                                      address=>"00000000000000000000000000000",
988
                                                      wdptr=>wdptr,
989
                                                      xamsbs=>"00")));
990 42 magro732
 
991 44 magro732
        OutboundFrame(RioFrameCreate(ackId=>"00000", vc=>'0', crf=>'0', prio=>"00",
992
                                     tt=>"01", ftype=>FTYPE_RESPONSE_CLASS,
993
                                     sourceId=>x"beef", destId=>x"dead",
994
                                     payload=>RioResponse(status=>"0000",
995
                                                          tid=>x"aa",
996
                                                          dataLength=>getReadSize(rdsize, wdptr),
997
                                                          data=>ioData)));
998 42 magro732
 
999 44 magro732
        SetSlaveAccess(false, "0000000000000000000000000000000",
1000
                       getReadMask(rdsize, wdptr),
1001
                       getReadSize(rdsize, wdptr),
1002
                       ioData);
1003
 
1004
        TestWait(inboundEmpty, '1', "inbound frame");
1005
        TestWait(outboundEmpty, '1', "outbound frame");
1006
        TestWait(wbMessageEmpty, '1', "wishbone access");
1007
      end loop;
1008
    end loop;
1009 42 magro732
 
1010
    ---------------------------------------------------------------------------
1011
    -- Test completed.
1012
    ---------------------------------------------------------------------------
1013
 
1014
    TestEnd;
1015
  end process;
1016
 
1017
  -----------------------------------------------------------------------------
1018
  -- Instantiate the test object.
1019
  -----------------------------------------------------------------------------
1020
  TestObject: RioWbBridge
1021
    generic map(
1022 44 magro732
      EXTENDED_ADDRESS=>0,
1023
      DEVICE_IDENTITY=>x"dead",
1024
      DEVICE_VENDOR_IDENTITY=>x"beef",
1025
      DEVICE_REV=>x"c0debabe",
1026
      ASSY_IDENTITY=>x"1111",
1027
      ASSY_VENDOR_IDENTITY=>x"2222",
1028
      ASSY_REV=>x"3333")
1029 42 magro732
    port map(
1030
      clk=>clk,
1031 44 magro732
      areset_n=>areset_n,
1032
      enable=>enable,
1033 42 magro732
      readFrameEmpty_i=>readFrameEmpty,
1034
      readFrame_o=>readFrame,
1035
      readContent_o=>readContent,
1036
      readContentEnd_i=>readContentEnd,
1037
      readContentData_i=>readContentData,
1038
      writeFrameFull_i=>writeFrameFull,
1039
      writeFrame_o=>writeFrame,
1040
      writeFrameAbort_o=>writeFrameAbort,
1041
      writeContent_o=>writeContent,
1042
      writeContentData_o=>writeContentData,
1043
      cyc_o=>wbCyc,
1044
      stb_o=>wbStb,
1045
      we_o=>wbWe,
1046
      adr_o=>wbAdr,
1047
      sel_o=>wbSel,
1048
      dat_o=>wbDatWrite,
1049
      dat_i=>wbDatRead,
1050
      err_i=>wbErr,
1051
      ack_i=>wbAck);
1052
 
1053
  -----------------------------------------------------------------------------
1054
  -- Instantiate the test ports.
1055
  -----------------------------------------------------------------------------
1056
 
1057
  TestPortPacketBufferInst: TestPortPacketBuffer
1058
    port map(
1059
      clk=>clk, areset_n=>areset_n,
1060 44 magro732
      readEmpty_o=>inboundEmpty,
1061
      readWrite_i=>inboundWrite,
1062
      readMessage_i=>inboundMessage,
1063
      readAck_o=>inboundAck,
1064
      writeEmpty_o=>outboundEmpty,
1065
      writeWrite_i=>outboundWrite,
1066
      writeMessage_i=>outboundMessage,
1067
      writeAck_o=>outboundAck,
1068 42 magro732
      readFrameEmpty_o=>readFrameEmpty,
1069
      readFrame_i=>readFrame,
1070 44 magro732
      readFrameRestart_i=>'0',
1071
      readFrameAborted_o=>readFrameAborted,
1072
      readWindowEmpty_o=>open,
1073
      readWindowReset_i=>'0',
1074
      readWindowNext_i=>readFrame,
1075 42 magro732
      readContentEmpty_o=>readContentEmpty,
1076
      readContent_i=>readContent,
1077
      readContentEnd_o=>readContentEnd,
1078
      readContentData_o=>readContentData,
1079
      writeFrame_i=>writeFrame,
1080
      writeFrameAbort_i=>writeFrameAbort,
1081
      writeContent_i=>writeContent,
1082
      writeContentData_i=>writeContentData);
1083
 
1084
  TestPortWishboneInst: TestPortWishbone
1085
    port map(
1086
      clk=>clk,
1087
      areset_n=>areset_n,
1088
      messageEmpty_o=>wbMessageEmpty,
1089
      messageWrite_i=>wbMessageWrite,
1090
      message_i=>wbMessage,
1091
      messageAck_o=>wbMessageAck,
1092
      cyc_i=>wbCyc,
1093
      stb_i=>wbStb,
1094
      we_i=>wbWe,
1095
      adr_i=>wbAdr,
1096
      sel_i=>wbSel,
1097
      dat_i=>wbDatWrite,
1098
      dat_o=>wbDatRead,
1099
      err_o=>wbErr,
1100
      ack_o=>wbAck);
1101
 
1102
end architecture;

powered by: WebSVN 2.1.0

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