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 45

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

powered by: WebSVN 2.1.0

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