• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Example Test Bench Using Interface and Classes

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 64
  • Views 13393
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Example Test Bench Using Interface and Classes

archive
archive over 18 years ago

I'm sharing this code, which is an example of using an SV Interface to transmit a class of data & functions to a DUT. // Todd Mackett Cadence Design Systems // ncverilog class_across_interface.sv +sv +linedebug +gui // tested wtih IUS5.83s1 /* top-------------------------- | test --->interface---->dut | |----------------------------- */ package mypack; class some_class; //class is the rudimentry data container int some_int; real some_real; protected string some_string; // needs to be protected for IUS5.83 function void set_data (int i, real r, string s); some_int =i; some_real = r; some_string = s; endfunction task get_data(output int i, output real r, output string s); i = some_int; r = some_real; s = some_string; endtask function void print_data(); $display("Int: %d, Real: %f, String: %s", some_int, some_real, some_string); endfunction endclass endpackage // ------ // This channel is an interface that is a queue of classes interface myIF; import mypack::*; event some_event; some_class some_classQ[$]; function int some_classQ_size(); return some_classQ.size(); endfunction task push_class_in_Q(input some_class Qin); some_classQ.push_front(Qin); endtask task pop_class_out_Q(output some_class Qout); Qout = some_classQ.pop_back(); endtask endinterface // ----------------- module top(); int top_int; reg clk = 'b1; initial forever clk = #10 ~clk; // system clk myIF myIFi(); // instantiate interface test testi(clk, myIFi); dut duti(clk, myIFi); endmodule // -------------- // The test module create a class of information and puts it in the // channel (a queue in the interface) module test (input clk, myIF myIFi); import mypack::*; int i; real r; string s; initial #200 $finish; some_class top_class; always @(posedge clk) begin top_class = new; // randomize the data per class object i = $urandom_range(5,1); randcase 1: r = 3.14; 1: r = 123.456; 1: r = -943.825; endcase randcase 1: s = "IUS SystemVerilog"; 1: s = "Cadence"; 1: s = "Who needs VHDL?"; endcase top_class.set_data(i, r, s); // set the values into class myIFi.push_class_in_Q(top_class); // transmit the class -> myIFi.some_event; // cause the event end endmodule // ------------- // The dut module consumes the class when the event is valid // and displays its contents as it comes across the interface module dut (input clk, myIF myIFi); import mypack::*; some_class dut_class =new; always @(myIFi.some_event) // process event begin $display("\nQueue Size %d",myIFi.some_classQ_size() ); myIFi.pop_class_out_Q(dut_class); dut_class.print_data(); end endmodule


Originally posted in cdnusers.org by tmackett
  • Cancel
Parents
  • archive
    archive over 18 years ago

    Hi Todd,
      Thanks for the code share, it helps!

    Your compile command is:

    >> ncverilog class_across_interface.sv +sv +linedebug +gui

    Recently CDN ran a Specman Debug survey which I also gave my inputs. Will NC
    reuse some of the excellent debug capabilities of Specman or will it all be
    newly built under Simvision? I would prefer the former as Veristy had done
    an excellent job there and CDN has the enviable lead among vendors in that
    domain. Esecially on this example you showed class under module and +gui option

    Are classes/instances/objects visible as waveform in Simvision? As you would know
    Specman had a nice way of doing it for years, it will be really sad if that can't
    be reused for SV under NC.


    BTW - will there by any consolidated report on the debug survey conducted recently
    by CDN?

    Thanks
    Ajeetha, CVC
    www.noveldv.com



    Originally posted in cdnusers.org by ajeetha
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 18 years ago

    Hi Todd,
      Thanks for the code share, it helps!

    Your compile command is:

    >> ncverilog class_across_interface.sv +sv +linedebug +gui

    Recently CDN ran a Specman Debug survey which I also gave my inputs. Will NC
    reuse some of the excellent debug capabilities of Specman or will it all be
    newly built under Simvision? I would prefer the former as Veristy had done
    an excellent job there and CDN has the enviable lead among vendors in that
    domain. Esecially on this example you showed class under module and +gui option

    Are classes/instances/objects visible as waveform in Simvision? As you would know
    Specman had a nice way of doing it for years, it will be really sad if that can't
    be reused for SV under NC.


    BTW - will there by any consolidated report on the debug survey conducted recently
    by CDN?

    Thanks
    Ajeetha, CVC
    www.noveldv.com



    Originally posted in cdnusers.org by ajeetha
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information