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

Subversion Repositories rio

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

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

Line No. Rev Author Line
1 47 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 components that can simulate various interfaces used in the RapidIO
10
-- IP library project.
11
-- 
12
-- To Do:
13
-- - Add Symbol-testport from TestRioSerial here.
14
-- 
15
-- Author(s): 
16
-- - Magnus Rosenius, magro732@opencores.org 
17
-- 
18
-------------------------------------------------------------------------------
19
-- 
20
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
21
-- 
22
-- This source file may be used and distributed without 
23
-- restriction provided that this copyright statement is not 
24
-- removed from the file and that any derivative work contains 
25
-- the original copyright notice and the associated disclaimer. 
26
-- 
27
-- This source file is free software; you can redistribute it 
28
-- and/or modify it under the terms of the GNU Lesser General 
29
-- Public License as published by the Free Software Foundation; 
30
-- either version 2.1 of the License, or (at your option) any 
31
-- later version. 
32
-- 
33
-- This source is distributed in the hope that it will be 
34
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
35
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
36
-- PURPOSE. See the GNU Lesser General Public License for more 
37
-- details. 
38
-- 
39
-- You should have received a copy of the GNU Lesser General 
40
-- Public License along with this source; if not, download it 
41
-- from http://www.opencores.org/lgpl.shtml 
42
-- 
43
-------------------------------------------------------------------------------
44
 
45
 
46
-------------------------------------------------------------------------------
47
-- 
48
-------------------------------------------------------------------------------
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use work.rio_common.all;
52 48 magro732
use std.textio.all;
53 47 magro732
 
54
-------------------------------------------------------------------------------
55
-- 
56
-------------------------------------------------------------------------------
57
package TestPortPackage is
58
  constant ADDRESS_WIDTH_MAX : natural := 64;
59
  constant DATA_WIDTH_MAX : natural := 64;
60
  constant SEL_WIDTH_MAX : natural := 8;
61
 
62
  type TestPortMessageWishbone is record
63
    writeAccess : boolean;
64
    address : std_logic_vector(ADDRESS_WIDTH_MAX-1 downto 0);
65
    byteSelect : std_logic_vector(SEL_WIDTH_MAX-1 downto 0);
66
    data : std_logic_vector(DATA_WIDTH_MAX-1 downto 0);
67
    continue : boolean;
68
    latency : natural;
69
  end record;
70
  type TestPortMessageWishboneArray is
71
    array (natural range <>) of TestPortMessageWishbone;
72
 
73
  type TestPortMessageSymbol is record
74
    symbolType : std_logic_vector(1 downto 0);
75
    symbolContent : std_logic_vector(31 downto 0);
76
    ignoreIdle : boolean;
77
  end record;
78
  type TestPortMessageSymbolArray is
79
    array (natural range <>) of TestPortMessageSymbol;
80
 
81
  type TestPortMessagePacketBuffer is record
82
    frame : RioFrame;
83
    willAbort : boolean;
84
  end record;
85
  type TestPortMessagePacketBufferArray is
86
    array (natural range <>) of TestPortMessagePacketBuffer;
87
 
88
  -----------------------------------------------------------------------------
89
  -- 
90
  -----------------------------------------------------------------------------
91
 
92
  component TestPortWishbone is
93
    generic(
94
      ADDRESS_WIDTH : natural := 31;
95
      SEL_WIDTH : natural := 8;
96
      DATA_WIDTH : natural := 64);
97
    port(
98
      clk : in std_logic;
99
      areset_n : in std_logic;
100
 
101
      messageEmpty_o : out std_logic;
102
      messageWrite_i : in std_logic;
103
      message_i : in TestPortMessageWishbone;
104
      messageAck_o : out std_logic;
105
 
106
      cyc_i : in std_logic;
107
      stb_i : in std_logic;
108
      we_i : in std_logic;
109
      adr_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
110
      sel_i : in std_logic_vector(SEL_WIDTH-1 downto 0);
111
      dat_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
112
      dat_o : out std_logic_vector(DATA_WIDTH-1 downto 0);
113
      err_o : out std_logic;
114
      ack_o : out std_logic);
115
  end component;
116
 
117
  component TestPortPacketBuffer is
118
    generic(
119
      READ_CONTENT_END_DATA_VALID : boolean := true);
120
    port(
121
      clk : in std_logic;
122
      areset_n : in std_logic;
123
 
124
      readEmpty_o : out std_logic;
125
      readWrite_i : in std_logic;
126
      readMessage_i : in TestPortMessagePacketBuffer;
127
      readAck_o : out std_logic;
128
 
129
      writeEmpty_o : out std_logic;
130
      writeWrite_i : in std_logic;
131
      writeMessage_i : in TestPortMessagePacketBuffer;
132
      writeAck_o : out std_logic;
133
 
134
      readFrameEmpty_o : out std_logic;
135
      readFrame_i : in std_logic;
136
      readFrameRestart_i : in std_logic;
137
      readFrameAborted_o : out std_logic;
138
      readWindowEmpty_o : out std_logic;
139
      readWindowReset_i : in std_logic;
140
      readWindowNext_i : in std_logic;
141
      readContentEmpty_o : out std_logic;
142
      readContent_i : in std_logic;
143
      readContentEnd_o : out std_logic;
144
      readContentData_o : out std_logic_vector(31 downto 0);
145
 
146
      writeFrame_i : in std_logic;
147
      writeFrameAbort_i : in std_logic;
148
      writeContent_i : in std_logic;
149
      writeContentData_i : in std_logic_vector(31 downto 0));
150
  end component;
151
 
152
  -----------------------------------------------------------------------------
153
  -- 
154
  -----------------------------------------------------------------------------
155
  procedure TestPortWishboneWrite(
156
    signal writeSignal : out std_logic;
157
    signal messageSignal : out TestPortMessageWishbone;
158
    signal ackSignal : in std_logic;
159
    constant writeAccess : in boolean;
160
    constant address : in std_logic_vector(ADDRESS_WIDTH_MAX-1 downto 0);
161
    constant byteSelect : in std_logic_vector(SEL_WIDTH_MAX-1 downto 0);
162
    constant data : in std_logic_vector(DATA_WIDTH_MAX-1 downto 0);
163
    constant continue : in boolean := false;
164
    constant latency : in natural := 0);
165
 
166
  procedure TestPortPacketBufferWrite(
167
    signal writeSignal : out std_logic;
168
    signal messageSignal : out TestPortMessagePacketBuffer;
169
    signal ackSignal : in std_logic;
170
    constant frame : in RioFrame;
171
    constant willAbort : in boolean := false);
172
 
173 48 magro732
  -----------------------------------------------------------------------------
174
  -- Function to print a std_logic_vector.
175
  -----------------------------------------------------------------------------
176
  function to_string(constant value : std_logic_vector)
177
    return string;
178
 
179
  ---------------------------------------------------------------------------
180
  -- Procedures for test control.
181
  ---------------------------------------------------------------------------
182
 
183
  procedure TestWarning(constant tag : in string);
184
  procedure TestError(constant tag : in string;
185
                      constant stopAtError : in boolean := true);
186
  procedure TestCompare(constant expression : in boolean;
187
                        constant tag : in string := "";
188
                        constant stopAtError : in boolean := true);
189
  procedure TestCompare(constant got : in std_logic;
190
                        constant expected : in std_logic;
191
                        constant tag : in string := "";
192
                        constant stopAtError : in boolean := true);
193
  procedure TestCompare(constant got : in std_logic_vector;
194
                        constant expected : in std_logic_vector;
195
                        constant tag : in string := "";
196
                        constant stopAtError : in boolean := true);
197
  procedure TestCompare(constant got : in natural;
198
                        constant expected : in natural;
199
                        constant tag : in string := "";
200
                        constant stopAtError : in boolean := true);
201
  procedure TestCompare(constant got : in time;
202
                        constant expected : in time;
203
                        constant tag : in string := "";
204
                        constant stopAtError : in boolean := true);
205
 
206
  procedure TestWait(signal waitSignal : in std_logic;
207
                     constant waitValue : in std_logic;
208
                     constant tag : in string := "";
209
                     constant waitTime : in time := 1 ms;
210
                     constant stopAtError : in boolean := true);
211
  procedure TestWait(signal waitSignal : in std_logic;
212
                     constant waitValue : in std_logic;
213
                     signal ackSignal : inout std_logic;
214
                     constant tag : in string := "";
215
                     constant waitTime : in time := 1 ms;
216
                     constant stopAtError : in boolean := true);
217
 
218
  procedure TestEnd;
219
 
220 47 magro732
end package;
221
 
222
-------------------------------------------------------------------------------
223
-- 
224
-------------------------------------------------------------------------------
225
package body TestPortPackage is
226
 
227
  -----------------------------------------------------------------------------
228
  -- 
229
  -----------------------------------------------------------------------------
230
  procedure TestPortWishboneWrite(
231
    signal writeSignal : out std_logic;
232
    signal messageSignal : out TestPortMessageWishbone;
233
    signal ackSignal : in std_logic;
234
    constant writeAccess : in boolean;
235
    constant address : in std_logic_vector(ADDRESS_WIDTH_MAX-1 downto 0);
236
    constant byteSelect : in std_logic_vector(SEL_WIDTH_MAX-1 downto 0);
237
    constant data : in std_logic_vector(DATA_WIDTH_MAX-1 downto 0);
238
    constant continue : in boolean := false;
239
    constant latency : in natural := 0) is
240
  begin
241
    writeSignal <= '1';
242
    messageSignal.writeAccess <= writeAccess;
243
    messageSignal.address <= address;
244
    messageSignal.byteSelect <= byteSelect;
245
    messageSignal.data <= data;
246
    messageSignal.continue <= continue;
247
    messageSignal.latency <= latency;
248
    wait until ackSignal = '1';
249
    writeSignal <= '0';
250
    wait until ackSignal = '0';
251
  end procedure;
252
 
253
  -----------------------------------------------------------------------------
254
  -- 
255
  -----------------------------------------------------------------------------
256
  procedure TestPortPacketBufferWrite(
257
    signal writeSignal : out std_logic;
258
    signal messageSignal : out TestPortMessagePacketBuffer;
259
    signal ackSignal : in std_logic;
260
    constant frame : in RioFrame;
261
    constant willAbort : in boolean := false) is
262
  begin
263
    writeSignal <= '1';
264
    messageSignal.frame <= frame;
265
    messageSignal.willAbort <= willAbort;
266
    wait until ackSignal = '1';
267
    writeSignal <= '0';
268
    wait until ackSignal = '0';
269
  end procedure;
270
 
271 48 magro732
  -----------------------------------------------------------------------------
272
  -- Function to print std_logic_vector.
273
  -----------------------------------------------------------------------------
274
  function to_string(constant value : std_logic) return string is
275
    variable s : string(1 to 1);
276
  begin
277
    if (value = '0') then
278
      s(1) := '0';
279
    elsif (value = '1') then
280
      s(1) := '1';
281
    elsif (value = 'U') then
282
      s(1) := 'U';
283
    elsif (value = 'X') then
284
      s(1) := 'X';
285
    else
286
      s(1) := '?';
287
    end if;
288
    return s;
289
  end function;
290
  function to_string(constant value : std_logic_vector) return string is
291
    variable s : string(1 to value'length);
292
    variable index : positive;
293
    variable i : natural;
294
  begin
295
    index := 1;
296
    for i in value'range loop
297
      if (value(i) = '0') then
298
        s(index) := '0';
299
      elsif (value(i) = '1') then
300
        s(index) := '1';
301
      elsif (value(i) = 'U') then
302
        s(index) := 'U';
303
      elsif (value(i) = 'X') then
304
        s(index) := 'X';
305
      else
306
        s(index) := '?';
307
      end if;
308
      index := index + 1;
309
    end loop;
310
    return s;
311
  end function;
312
 
313
  ---------------------------------------------------------------------------
314
  -- Procedures to handle tests.
315
  ---------------------------------------------------------------------------
316
 
317
  procedure TestWarning(constant tag : in string) is
318
    variable writeBuffer : line;
319
  begin
320
    write(writeBuffer, now);
321
    write(writeBuffer, string'(":WARNING:"));
322
    write(writeBuffer, tag);
323
    writeline(OUTPUT, writeBuffer);
324
  end procedure;
325
 
326
  procedure TestError(constant tag : in string;
327
                      constant stopAtError : in boolean := true) is
328
    variable writeBuffer : line;
329
  begin
330
    write(writeBuffer, now);
331
    write(writeBuffer, string'(":FAILED:"));
332
    write(writeBuffer, tag);
333
    writeline(OUTPUT, writeBuffer);
334
 
335
    if (stopAtError) then
336
      std.env.stop(0);
337
    end if;
338
  end procedure;
339
 
340
  procedure TestCompare(constant expression : in boolean;
341
                        constant tag : in string := "";
342
                        constant stopAtError : in boolean := true) is
343
    variable writeBuffer : line;
344
  begin
345
    write(writeBuffer, now);
346
    if (not expression) then
347
      write(writeBuffer, string'(":FAILED:"));
348
    else
349
      write(writeBuffer, string'(":PASSED:"));
350
    end if;
351
    write(writeBuffer, tag);
352
    writeline(OUTPUT, writeBuffer);
353
 
354
    if (stopAtError) and (not expression) then
355
      std.env.stop(0);
356
    end if;
357
  end procedure;
358
 
359
  procedure TestCompare(constant got : in std_logic;
360
                        constant expected : in std_logic;
361
                        constant tag : in string := "";
362
                        constant stopAtError : in boolean := true) is
363
    variable writeBuffer : line;
364
  begin
365
    write(writeBuffer, now);
366
    if (expected /= got) then
367
      write(writeBuffer, string'(":FAILED:"));
368
      write(writeBuffer, tag);
369
      write(writeBuffer, ":got=" & to_string(got));
370
      write(writeBuffer, ":expected=" & to_string(expected));
371
    else
372
      write(writeBuffer, string'(":PASSED:"));
373
      write(writeBuffer, tag);
374
    end if;
375
    writeline(OUTPUT, writeBuffer);
376
 
377
    if (stopAtError) and (expected /= got) then
378
      std.env.stop(0);
379
    end if;
380
  end procedure;
381
 
382
  procedure TestCompare(constant got : in std_logic_vector;
383
                        constant expected : in std_logic_vector;
384
                        constant tag : in string := "";
385
                        constant stopAtError : in boolean := true) is
386
    variable writeBuffer : line;
387
  begin
388
    write(writeBuffer, now);
389
    if (expected /= got) then
390
      write(writeBuffer, string'(":FAILED:"));
391
      write(writeBuffer, tag);
392
      write(writeBuffer, ":got=" & to_string(got));
393
      write(writeBuffer, ":expected=" & to_string(expected));
394
    else
395
      write(writeBuffer, string'(":PASSED:"));
396
      write(writeBuffer, tag);
397
    end if;
398
    writeline(OUTPUT, writeBuffer);
399
 
400
    if (stopAtError) and (expected /= got) then
401
      std.env.stop(0);
402
    end if;
403
  end procedure;
404
 
405
  procedure TestCompare(constant got : in natural;
406
                        constant expected : in natural;
407
                        constant tag : in string := "";
408
                        constant stopAtError : in boolean := true) is
409
    variable writeBuffer : line;
410
  begin
411
    write(writeBuffer, now);
412
    if (expected /= got) then
413
      write(writeBuffer, string'(":FAILED:"));
414
      write(writeBuffer, tag);
415
      write(writeBuffer, ":got=" & integer'image(got));
416
      write(writeBuffer, ":expected=" & integer'image(expected));
417
    else
418
      write(writeBuffer, string'(":PASSED:"));
419
      write(writeBuffer, tag);
420
    end if;
421
    writeline(OUTPUT, writeBuffer);
422
 
423
    if (stopAtError) and (expected /= got) then
424
      std.env.stop(0);
425
    end if;
426
  end procedure;
427
 
428
  procedure TestCompare(constant got : in time;
429
                        constant expected : in time;
430
                        constant tag : in string := "";
431
                        constant stopAtError : in boolean := true) is
432
    variable writeBuffer : line;
433
  begin
434
    write(writeBuffer, now);
435
    if (expected /= got) then
436
      write(writeBuffer, string'(":FAILED:"));
437
      write(writeBuffer, tag);
438
      write(writeBuffer, string'(":got="));
439
      write(writeBuffer, got);
440
      write(writeBuffer, string'(":expected="));
441
      write(writeBuffer, expected);
442
    else
443
      write(writeBuffer, string'(":PASSED:"));
444
      write(writeBuffer, tag);
445
    end if;
446
    writeline(OUTPUT, writeBuffer);
447
 
448
    if (stopAtError) and (expected /= got) then
449
      std.env.stop(0);
450
    end if;
451
  end procedure;
452
 
453
  procedure TestWait(signal waitSignal : in std_logic;
454
                     constant waitValue : in std_logic;
455
                     constant tag : in string := "";
456
                     constant waitTime : in time := 1 ms;
457
                     constant stopAtError : in boolean := true) is
458
    variable writeBuffer : line;
459
  begin
460
    if (waitSignal /= waitValue) then
461
      wait until waitSignal = waitValue for waitTime;
462
      if (waitSignal /= waitValue) then
463
        write(writeBuffer, now);
464
        write(writeBuffer, string'(":FAILED:"));
465
        write(writeBuffer, tag);
466
        writeline(OUTPUT, writeBuffer);
467
 
468
        if (stopAtError) then
469
          std.env.stop(0);
470
        end if;
471
      end if;
472
    end if;
473
  end procedure;
474
 
475
  procedure TestWait(signal waitSignal : in std_logic;
476
                     constant waitValue : in std_logic;
477
                     signal ackSignal : inout std_logic;
478
                     constant tag : in string := "";
479
                     constant waitTime : in time := 1 ms;
480
                     constant stopAtError : in boolean := true) is
481
    variable writeBuffer : line;
482
  begin
483
    if (waitSignal /= waitValue) then
484
 
485
      wait until waitSignal = waitValue for waitTime;
486
 
487
      if (waitSignal /= waitValue) then
488
        write(writeBuffer, now);
489
        write(writeBuffer, string'(":FAILED:"));
490
        write(writeBuffer, tag);
491
        writeline(OUTPUT, writeBuffer);
492
 
493
        if (stopAtError) then
494
          std.env.stop(0);
495
        end if;
496
      end if;
497
    end if;
498
 
499
    ackSignal <= not ackSignal;
500
 
501
    wait until waitSignal /= waitValue for waitTime;
502
 
503
    if (waitSignal = waitValue) then
504
      write(writeBuffer, now);
505
      write(writeBuffer, string'(":FAILED:"));
506
      write(writeBuffer, tag);
507
      writeline(OUTPUT, writeBuffer);
508
 
509
      if (stopAtError) then
510
        std.env.stop(0);
511
      end if;
512
    end if;
513
  end procedure;
514
 
515
  procedure TestEnd is
516
    variable writeBuffer : line;
517
  begin
518
    write(writeBuffer, now);
519
    write(writeBuffer, string'(":COMPLETED"));
520
    writeline(OUTPUT, writeBuffer);
521
    std.env.stop(0);
522
  end TestEnd;
523
 
524 47 magro732
end package body;
525
 
526
 
527
 
528
 
529
-------------------------------------------------------------------------------
530
-- 
531
-------------------------------------------------------------------------------
532
library ieee;
533
use ieee.std_logic_1164.all;
534
use ieee.numeric_std.all;
535
library std;
536
use std.textio.all;
537
use work.rio_common.all;
538
use work.TestPortPackage.all;
539
 
540
 
541
-------------------------------------------------------------------------------
542
-- 
543
-------------------------------------------------------------------------------
544
entity TestPortPacketBuffer is
545
  generic(
546
    READ_CONTENT_END_DATA_VALID : boolean := true);
547
  port(
548
    clk : in std_logic;
549
    areset_n : in std_logic;
550
 
551
    readEmpty_o : out std_logic;
552
    readWrite_i : in std_logic;
553
    readMessage_i : in TestPortMessagePacketBuffer;
554
    readAck_o : out std_logic;
555
 
556
    writeEmpty_o : out std_logic;
557
    writeWrite_i : in std_logic;
558
    writeMessage_i : in TestPortMessagePacketBuffer;
559
    writeAck_o : out std_logic;
560
 
561
    readFrameEmpty_o : out std_logic;
562
    readFrame_i : in std_logic;
563
    readFrameRestart_i : in std_logic;
564
    readFrameAborted_o : out std_logic;
565
    readWindowEmpty_o : out std_logic;
566
    readWindowReset_i : in std_logic;
567
    readWindowNext_i : in std_logic;
568
    readContentEmpty_o : out std_logic;
569
    readContent_i : in std_logic;
570
    readContentEnd_o : out std_logic;
571
    readContentData_o : out std_logic_vector(31 downto 0);
572
 
573
    -- writeFrameFull_o is missing yes, but you can control it from the testbench directly
574
    -- instead.
575
    writeFrame_i : in std_logic;
576
    writeFrameAbort_i : in std_logic;
577
    writeContent_i : in std_logic;
578
    writeContentData_i : in std_logic_vector(31 downto 0));
579
end entity;
580
 
581
 
582
-------------------------------------------------------------------------------
583
-- 
584
-------------------------------------------------------------------------------
585
architecture TestPortPacketBufferPortImpl of TestPortPacketBuffer is
586 48 magro732
  constant QUEUE_SIZE : natural := 255;
587 47 magro732
  type QueueArray is array (natural range <>) of TestPortMessagePacketBuffer;
588
 
589
  function QueueIndexInc(constant i : natural) return natural is
590
    variable returnValue : natural;
591
  begin
592
    if(i = QUEUE_SIZE) then
593
      returnValue := 0;
594
    else
595
      returnValue := i + 1;
596
    end if;
597
    return returnValue;
598
  end function;
599
 
600
begin
601
 
602
  -----------------------------------------------------------------------------
603
  -- 
604
  -----------------------------------------------------------------------------
605
  Reader: process
606
    variable frameQueue : QueueArray(0 to QUEUE_SIZE);
607
    variable front, back, window : natural range 0 to QUEUE_SIZE;
608
    variable frameIndex : natural;
609
  begin
610
    wait until areset_n = '1';
611
 
612
    readFrameEmpty_o <= '1';
613
    readFrameAborted_o <= '0';
614
    readWindowEmpty_o <= '1';
615
    readContentEmpty_o <= '1';
616
    readContentEnd_o <= '0';
617
    readContentData_o <= (others=>'0');
618
 
619
    front := 0;
620
    back := 0;
621
    window := 0;
622
    frameIndex := 0;
623
    readEmpty_o <= '1';
624
    readAck_o <= '0';
625
 
626
    loop
627
      wait until clk = '1' or readWrite_i = '1';
628
 
629
      if (clk'event) then
630
        if (readFrame_i = '1') then
631 48 magro732
          if ((not frameQueue(back).willAbort) and (frameIndex < frameQueue(back).frame.length)) then
632
            TestError("READ:BACK:reading unfinished frame");
633
          end if;
634 47 magro732
          if (back /= front) then
635
            back := QueueIndexInc(back);
636
          else
637
            TestError("READ:BACK:reading when no frame is present");
638
          end if;
639
        end if;
640
 
641
        if (readFrameRestart_i = '1') then
642
          frameIndex := 0;
643
        end if;
644
 
645
        if (readWindowReset_i = '1') then
646
          window := back;
647
          frameIndex := 0;
648
        end if;
649
 
650
        if (readWindowNext_i = '1') then
651
          if (window /= front) then
652
            window := QueueIndexInc(window);
653
            frameIndex := 0;
654
          else
655
            TestError("READ:WINDOW:reading when no frame is present");
656
          end if;
657
        end if;
658
 
659
        if (readContent_i = '1') then
660
          if (back /= front) then
661
            if (READ_CONTENT_END_DATA_VALID) then
662
              if (frameIndex < frameQueue(window).frame.length) then
663
                readContentData_o <= frameQueue(window).frame.payload(frameIndex);
664
                frameIndex := frameIndex + 1;
665
                if (frameIndex = frameQueue(window).frame.length) then
666
                  readContentEnd_o <= '1';
667
                else
668
                  readContentEnd_o <= '0';
669
                end if;
670
              else
671
                TestError("READ:CONTENT:reading when frame has ended");
672
              end if;
673
            else
674
              if (frameIndex < frameQueue(window).frame.length) then
675
                readContentData_o <= frameQueue(window).frame.payload(frameIndex);
676
                readContentEnd_o <= '0';
677
                frameIndex := frameIndex + 1;
678
              elsif (frameIndex = frameQueue(window).frame.length) then
679
                readContentData_o <= (others=>'U');
680
                readContentEnd_o <= '1';
681
              else
682
                TestError("READ:CONTENT:reading when frame has ended");
683
              end if;
684
            end if;
685
          else
686
            TestError("READ:CONTENT:reading when no frame is present");
687
          end if;
688
        end if;
689
 
690
        if (front = back) then
691
          readFrameEmpty_o <= '1';
692
        else
693
          readFrameEmpty_o <= '0';
694
        end if;
695
 
696
        if (front = window) then
697
          readWindowEmpty_o <= '1';
698
          readContentEmpty_o <= '1';
699
        else
700
          readWindowEmpty_o <= '0';
701
          if (frameIndex /= frameQueue(window).frame.length) then
702
            readContentEmpty_o <= '0';
703
          else
704
            readContentEmpty_o <= '1';
705
          end if;
706
        end if;
707
 
708
        if (front = back) then
709
          readEmpty_o <= '1';
710
        else
711
          readEmpty_o <= '0';
712
        end if;
713
      elsif (readWrite_i'event) then
714
        frameQueue(front) := readMessage_i;
715
        front := QueueIndexInc(front);
716 48 magro732
        if (front = back) then
717
          TestError("Queue full");
718
        end if;
719 47 magro732
 
720
        readEmpty_o <= '0';
721
        readAck_o <= '1';
722
        wait until readWrite_i = '0';
723
        readAck_o <= '0';
724
      end if;
725
    end loop;
726
  end process;
727
 
728
  -----------------------------------------------------------------------------
729
  -- 
730
  -----------------------------------------------------------------------------
731
  Writer: process
732
    variable frameQueue : QueueArray(0 to QUEUE_SIZE);
733
    variable front, back : natural range 0 to QUEUE_SIZE;
734
    variable frameIndex : natural range 0 to 69;
735
  begin
736
    wait until areset_n = '1';
737
 
738
    writeEmpty_o <= '1';
739
    writeAck_o <= '0';
740
 
741
    front := 0;
742
    back := 0;
743
    frameIndex := 0;
744
 
745
    loop
746
      wait until clk = '1' or writeWrite_i = '1';
747
 
748
      if (clk'event) then
749
 
750
        if (writeFrame_i = '1') then
751
          if (frameIndex = 0) then
752
            TestError("WRITE:Empty frame written.");
753
          end if;
754
          if (frameIndex /= frameQueue(back).frame.length) then
755
            TestError("WRITE:Frame with unmatching length was written.");
756
          end if;
757
          if (back /= front) then
758
            back := QueueIndexInc(back);
759
          else
760
            TestError("WRITE:Unexpected frame written.");
761
          end if;
762
          frameIndex := 0;
763
        end if;
764
 
765
        if (writeFrameAbort_i = '1') then
766
          if (back /= front) then
767
            if (frameQueue(back).willAbort) then
768
              TestCompare(frameIndex,
769
                          frameQueue(back).frame.length,
770
                          "frameIndex abort");
771
              back := QueueIndexInc(back);
772
            else
773
              TestError("WRITE:Not expecting this frame to abort.");
774
            end if;
775
          end if;
776
          frameIndex := 0;
777
        end if;
778
 
779
        if (writeContent_i = '1') then
780
          if (frameIndex < frameQueue(back).frame.length) then
781
            TestCompare(writeContentData_i,
782
                        frameQueue(back).frame.payload(frameIndex),
783
                        "frame content");
784
            frameIndex := frameIndex + 1;
785
          else
786
            TestError("WRITE:Receiving more frame content than expected.");
787
          end if;
788
        end if;
789
 
790
        if (front = back) then
791
          writeEmpty_o <= '1';
792
        else
793
          writeEmpty_o <= '0';
794
        end if;
795
      elsif (writeWrite_i'event) then
796
        frameQueue(front) := writeMessage_i;
797
        front := QueueIndexInc(front);
798 48 magro732
        if (front = back) then
799
          TestError("Queue full");
800
        end if;
801 47 magro732
 
802
        writeEmpty_o <= '0';
803
        writeAck_o <= '1';
804
        wait until writeWrite_i = '0';
805
        writeAck_o <= '0';
806
      end if;
807
    end loop;
808
  end process;
809
 
810
end architecture;
811
 
812
 
813
 
814
-------------------------------------------------------------------------------
815
-- 
816
-------------------------------------------------------------------------------
817
library ieee;
818
use ieee.std_logic_1164.all;
819
use ieee.numeric_std.all;
820
library std;
821
use std.textio.all;
822
use work.rio_common.all;
823
use work.TestPortPackage.all;
824
 
825
 
826
-------------------------------------------------------------------------------
827
-- 
828
-------------------------------------------------------------------------------
829
entity TestPortWishbone is
830
  generic(
831
    ADDRESS_WIDTH : natural := 31;
832
    SEL_WIDTH : natural := 8;
833
    DATA_WIDTH : natural := 64);
834
  port(
835
    clk : in std_logic;
836
    areset_n : in std_logic;
837
 
838
    messageEmpty_o : out std_logic;
839
    messageWrite_i : in std_logic;
840
    message_i : in TestPortMessageWishbone;
841
    messageAck_o : out std_logic;
842
 
843
    cyc_i : in std_logic;
844
    stb_i : in std_logic;
845
    we_i : in std_logic;
846
    adr_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
847
    sel_i : in std_logic_vector(SEL_WIDTH-1 downto 0);
848
    dat_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
849
    dat_o : out std_logic_vector(DATA_WIDTH-1 downto 0);
850
    err_o : out std_logic;
851
    ack_o : out std_logic);
852
end entity;
853
 
854
 
855
-------------------------------------------------------------------------------
856
-- 
857
-------------------------------------------------------------------------------
858
architecture TestPortWishboneImpl of TestPortWishbone is
859
  constant QUEUE_SIZE : natural := 63;
860
  type QueueArray is array (natural range <>) of TestPortMessageWishbone;
861
 
862
  function QueueIndexInc(constant i : natural) return natural is
863
    variable returnValue : natural;
864
  begin
865
    if(i = QUEUE_SIZE) then
866
      returnValue := 0;
867
    else
868
      returnValue := i + 1;
869
    end if;
870
    return returnValue;
871
  end function;
872
 
873
begin
874
 
875
  -----------------------------------------------------------------------------
876
  -- 
877
  -----------------------------------------------------------------------------
878
  Slave: process
879
    variable queue : QueueArray(0 to QUEUE_SIZE);
880
    variable front, back : natural range 0 to QUEUE_SIZE;
881
    variable latencyCounter : natural;
882
    variable activeCycle : boolean;
883
  begin
884
    wait until areset_n = '1';
885
 
886
    messageEmpty_o <= '1';
887
    messageAck_o <= '0';
888
 
889
    dat_o <= (others=>'U');
890
    err_o <= '0';
891
    ack_o <= '0';
892
 
893
    front := 0;
894
    back := 0;
895
    latencyCounter := 0;
896
    activeCycle := false;
897
 
898
    loop
899
      wait until clk = '1' or messageWrite_i = '1';
900
 
901
      if (clk'event) then
902
        if (cyc_i = '1') then
903
          if (front /= back) then
904
            if (stb_i = '1') then
905
              if (latencyCounter <= queue(back).latency) then
906
                TestCompare(stb_i, '1', "stb_i");
907
                if (queue(back).writeAccess) then
908
                  TestCompare(we_i, '1', "we_i");
909
                else
910
                  TestCompare(we_i, '0', "we_i");
911
                end if;
912
                TestCompare(adr_i, queue(back).address(ADDRESS_WIDTH-1 downto 0), "adr_i");
913
                TestCompare(sel_i, queue(back).byteSelect(SEL_WIDTH-1 downto 0), "sel_i");
914
                if (queue(back).writeAccess) then
915
                  TestCompare(dat_i, queue(back).data(DATA_WIDTH-1 downto 0), "dat_i");
916
                end if;
917
              end if;
918
 
919
              if (latencyCounter < queue(back).latency) then
920
                dat_o <= (others=>'U');
921
                ack_o <= '0';
922
                latencyCounter := latencyCounter + 1;
923
              elsif (latencyCounter = queue(back).latency) then
924
                if (queue(back).writeAccess) then
925
                  dat_o <= (others=>'U');
926
                else
927
                  dat_o <= queue(back).data(DATA_WIDTH-1 downto 0);
928
                end if;
929
                ack_o <= '1';
930
                latencyCounter := latencyCounter + 1;
931
              else
932
                dat_o <= (others=>'U');
933
                ack_o <= '0';
934
                latencyCounter := 0;
935
                activeCycle := queue(back).continue;
936
                back := QueueIndexInc(back);
937
              end if;
938
            end if;
939
          else
940
            TestError("Unexpected access.");
941
          end if;
942
        else
943
          if (activeCycle or (latencyCounter /= 0)) then
944
            TestError("Cycle unexpectedly aborted.");
945
            latencyCounter := 0;
946
          end if;
947
          TestCompare(stb_i, '0', "stb_i");
948
        end if;
949
 
950
        if (front = back) then
951
          messageEmpty_o <= '1';
952
        else
953
          messageEmpty_o <= '0';
954
        end if;
955
      elsif (messageWrite_i'event) then
956
        queue(front) := message_i;
957
        front := QueueIndexInc(front);
958
 
959
        messageEmpty_o <= '0';
960
        messageAck_o <= '1';
961
        wait until messageWrite_i = '0';
962
        messageAck_o <= '0';
963
      end if;
964
    end loop;
965
  end process;
966
 
967
end architecture;
968
 
969
 

powered by: WebSVN 2.1.0

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