Home > Community > Forums > Functional Verification > DPI and Classes

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 DPI and Classes 

Last post Wed, Mar 7 2007 8:32 AM by archive. 4 replies.
Started by archive 07 Mar 2007 08:32 AM. Topic has 4 replies and 2157 views
Page 1 of 1 (5 items)
Sort Posts:
  • Wed, Mar 7 2007 8:32 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    DPI and Classes Reply

    I'm using the DPI to instantiate and run our firmware and have a problem when the firmware tries to call exported tasks.

    I cannot seem to do an export on a class tasks so I have to declare my export tasks outside of the class.

    However, I don't know how to call the class member task (which is what I really want) from these outside tasks.


    This is my code.  I've tried hierarchical names to get the the write and read member tasks in the driver but get the following error from ncvlog:

      test.prgm.sys.spi.drv.read(address, data);
                                                     |
    ncvlog: *E,ILLHIN (../tb/spi/spi_driver.sv,52|49): illegal location for a hierarchical name (in a package).

    -------------------------------------------

    export "DPI-C" SV_spi_read = task spi_read;
    export "DPI-C" SV_spi_write = task spi_write;

    class spi_driver;
    extern function new;
    extern task write;
    extern task read;
    endclass : spi_driver

    function spi_driver::new;
    $display("spi_driver::new()");
    endfunction : new

    task spi_driver::write(input byte address, input byte data);
    $display("spi_write of %x to address %x", data, address);
    endtask : write

    task spi_driver::read( input byte address, output byte data);;
    $display("spi_read of address %x", address);
    endtask : read



    /////////////////////////////////////////////////////////////
    //
    // I cannot figure out how to export a class member task to the DPI so
    // these two functions are stand-alone functions.
    //
    task spi_read( input byte address, output byte data);
    $display("spi_read of address %x", address);
    spi_driver
    ::spi_read(Address, data);  // I don't know how to call class member from here.
    endtask
    : spi_read

    task spi_write(input byte address, input byte data);
    $display("spi_write of %x to address %x", data, address);
    spi_driver
    ::spi_write(Address, data);  // I don't know how to call class member from here.
    endtask : spi_write

    ----------------------------


    Originally posted in cdnusers.org by dfechser
    • Post Points: 0
  • Wed, Mar 7 2007 8:43 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: DPI and Classes Reply

    Hi,
      Refer to IEEE LRM 26.6, it clearly says:

    "One important restriction exists. Class member functions cannot be exported, but all other SystemVerilog functions can be exported."

    So what you are seeing is legal restriction as per LRM.

    Regards
    Ajeetha, CVC
    www.noveldv.com


    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Wed, Mar 7 2007 10:15 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: DPI and Classes Reply

    I was playing around with some example code - modifying my previous example on this forum called "Example Test Bench Using Interface and Classes". I inserted the dpi import/export declarations, and the export function inside the interface, and I was able to access the import function from both modules attached to the interface. Perhaps you can use this methodology. Email me for the complete example: tmackett@cadence.com


    Originally posted in cdnusers.org by tmackett
    • Post Points: 0
  • Wed, Mar 7 2007 10:36 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: DPI and Classes Reply

    I think you may have missed my problem due to the comments in my example.
    1. My C code is finding the exported functions just fine.
    2. My exported tasks need to access 'read' and 'write' tasks within the spi_driver class but I cannot find a way to do this.

    Hiererchical names don't work in a task declared at the package level so I can't refer to "read" and "write" with their full hierarchical names - which would seem illogical anyway as the package would no longer be portable. My question is, how can the spi_write task access the spi_driver.write task?


    Originally posted in cdnusers.org by dfechser
    • Post Points: 0
  • Thu, Mar 8 2007 7:04 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: DPI and Classes Reply

    Hi,

    We now have a product called Incisive Software Extensions (ISX) which, reading between the lines of your request, might be of interest, though it does not directly answer your System Verilog question. 

    ISX provides a mechanism to build a link between an advanced verification environment and your embedded software so that you can call embedded software functions and drive and monitor embedded software variables from the verification environment. The main difference between this and what you are doing right now is that ISX will maintain this interface capability irrespective of the Processor model kind, i.e. you can run it on you firmware compiled for the workstation as you are doing right now, and you can still use it when the embedded software is running on a processor model in the simulation, even if the model is an abstract ISS (Instruction Set Simulator) or the final RTL. We can even link to it if the design including the processor and software resides on an Accelerator or Emulator. 

    If you are interested to learn more about ISX please fell free to drop me a mail at giles@cadence.com 

    Best regards

    Giles


    Originally posted in cdnusers.org by giles
    • Post Points: 0
Page 1 of 1 (5 items)
Sort Posts:
Started by archive at 07 Mar 2007 08:32 AM. Topic has 4 replies.