SystemVerilog: Parameterized interface in classes

H

Haja

Guest
Hello,

I am facing some problem with parametrized interface in class. Below
is a snippet of the code

interface v_node_intf #(width = 0) ( );
logic [width-1:0] x;
logic [width-1:0] y;

modport vnode_if(input x, output y);

endinterface

class v_node;
v_node_intf.vnode_if #(.width(4)) vn_if;

// Error is pointed in tjhe above line: near ".": syntax error,
unexpected '.', expecting "IDENTIFIER" or '='
.....
......
endclass

If I change it to "virtual v_node_intf.vnode_if #(.width(4)) vn_if"
there is no error. I don't understand this behavior.

Also, is it possible to re-define the interface parameter run-time?

I would appreciate if someone can answer this.

Regards,
Haja
 
On Tue, 12 Feb 2008 15:00:13 -0800 (PST),
Haja <hajam99@gmail.com> wrote:

I am facing some problem with parametrized interface in class. Below
is a snippet of the code

interface v_node_intf #(width = 0) ( );
logic [width-1:0] x;
logic [width-1:0] y;

modport vnode_if(input x, output y);

endinterface

class v_node;
v_node_intf.vnode_if #(.width(4)) vn_if;

// Error is pointed in tjhe above line: near ".": syntax error,
unexpected '.', expecting "IDENTIFIER" or '='
.....
......
endclass

If I change it to "virtual v_node_intf.vnode_if #(.width(4)) vn_if"
there is no error. I don't understand this behavior.
The erroneous line in your class:
v_node_intf.vnode_if #(.width(4)) vn_if;
looks very much like an interface INSTANCE (except that
it lacks the necessary parentheses after the instance
name vn_if). Obviously, you can't put an interface instance
inside a class. What you want, of course, is a REFERENCE
to an interface instance. In SystemVerilog, such references
are stored in variables of "virtual interface" type.
By prefixing the line with the keyword "virtual", you create
such a variable.

Also, is it possible to re-define the interface parameter run-time?
No. It's never possible to redefine parameters at run-time.
By definition, they are evaluated at elaboration time and are
constants at run time.

There may be a small problem with the parameterization of your
virtual interface variable. SystemVerilog IEEE 1800-2005 did
not permit parameterization of virtual interface types. This
is fixed in current drafts of the 2008 standard, and I suspect
most tool vendors are already implementing the fix; but your
syntax is wrong, because it's the interface that is parameterized,
not the modport. So the correct syntax is:
virtual v_node_intf #(.width(4)).vnode_if vn_if;

If you can't get that to work, try this:
virtual v_node_intf #(.width(4)) vn_if;

and then, when setting up the value of the virtual interface,
be sure to assign to it a reference to the modport:

...
v_node v_node_object = new;
v_node_object.vn_if = some_vnode_intf_instance.vnode_if;

In my experience there are still some tricky tool issues
with parameterized virtual interfaces, so - good luck!

HTH
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Wed, 13 Feb 2008 08:50:10 +0000, Jonathan Bromley wrote:

If you can't get that to work, try this:
virtual v_node_intf #(.width(4)) vn_if;

and then, when setting up the value of the virtual interface,
be sure to assign to it a reference to the modport:

...
v_node v_node_object = new;
v_node_object.vn_if = some_vnode_intf_instance.vnode_if;
Sorry, that's garbage. You can't assign a modport-selected
interface reference to a non-modport virtual interface.
More realistic workarounds:
1) don't use the modport
2) don't parameterize: instead, create explicitly a new
specialised form of the interface for each different
value of "width" that you use.

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Wed, 13 Feb 2008 09:20:56 -0800 (PST),
Haja <hajam99@gmail.com> wrote:

I am still not clear how to use interfaces in classes. I have changed
little bit and removed modports in my interface and still facing some
problem.

******************************
interface v_node_intf();
logic x[10:0];
logic y[10:0];
endinterface

class v_node;
virtual v_node_intf v_n_if;
........
function new(virtual v_node_intf v_if);
v_n_if = v_if;
endfunction
......
.....
endclass;

module test();
v_node v_n[];
v_node_intf vn_if ();

inital begin
v_n = new[4];
v_n = new(vn_if); // error showing in the following line?
Don't you mean

v_n[0] = new(vn_if);

??? Try it without the dynamic array, first; just use
a single variable of the class type. That will give less
risk of error.

Otherwise it looks fine. It might be better to put
the class declaration into a package, or `include it
into module test, but otherwise it's OK.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Thanks Jonathan for you detailed reply.

I somehow got rid of the parameterization and fixing it to certain
maximum value.

I am still not clear how to use interfaces in classes. I have changed
little bit and removed modports in my interface and still facing some
problem.

******************************
interface v_node_intf();
logic x[10:0];
logic y[10:0];
endinterface

class v_node;
virtual v_node_intf v_n_if;
........
function new(virtual v_node_intf v_if);
v_n_if = v_if;
endfunction
.......
......
endclass;

module test();
v_node v_n[];
v_node_intf vn_if ();

inital begin
v_n = new[4];
v_n = new(vn_if); // error showing in the following line?
.....
end
endmodule
*****************************************
Any idea what I am making wrong?

Haja

On Feb 13, 4:04 am, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
On Wed, 13 Feb 2008 08:50:10 +0000, Jonathan Bromley wrote:
If you can't get that to work, try this:
virtual v_node_intf #(.width(4)) vn_if;

and then, when setting up the value of the virtual interface,
be sure to assign to it a reference to the modport:

...
v_node v_node_object = new;
v_node_object.vn_if = some_vnode_intf_instance.vnode_if;

Sorry, that's garbage. You can't assign a modport-selected
interface reference to a non-modport virtual interface.
More realistic workarounds:
1) don't use the modport
2) don't parameterize: instead, create explicitly a new
specialised form of the interface for each different
value of "width" that you use.

--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Feb 13, 12:37 pm, Jonathan Bromley <jonathan.brom...@MYCOMPANY.com>
wrote:
On Wed, 13 Feb 2008 09:20:56 -0800 (PST),



Haja <haja...@gmail.com> wrote:
I am still not clear how to use interfaces in classes. I have changed
little bit and removed modports in my interface and still facing some
problem.

******************************
interface v_node_intf();
logic x[10:0];
logic y[10:0];
endinterface

class v_node;
virtual v_node_intf v_n_if;
........
function new(virtual v_node_intf v_if);
v_n_if = v_if;
endfunction
......
.....
endclass;

module test();
v_node v_n[];
v_node_intf vn_if ();

inital begin
v_n = new[4];
v_n = new(vn_if); // error showing in the following line?

Don't you mean

v_n[0] = new(vn_if);

??? Try it without the dynamic array, first; just use
a single variable of the class type. That will give less
risk of error.
That was a good catch and stupid mistake from my side. It works fine
with dynamic objects too. Thanks again.

Otherwise it looks fine. It might be better to put
the class declaration into a package, or `include it
into module test, but otherwise it's OK.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.brom...@MYCOMPANY.comhttp://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top