How to pass a class between two modules?

3.9k Views Asked by At

I have two modules and a class and I would like to move that class from one module to the other. Something like this:

class foo;
   int x;
   int y;
endclass

module mod_A(output foo foo_inst, output event trig);
   initial begin
      foo my_foo = new;
      my_foo.x = 1;
      my_foo.y = 2;
      foo_inst = my_foo;
      ->trig;
   end
endmodule

module mod_B(input foo foo_inst, input event trig);
   always @(trig) begin
       $display("%d%d, is a funky number.", foo_inst.x, foo_inst.y);
   end
endmodule

module top();
   event trig;
   foo   foo_inst;
   mod_A mod_A(.trig, .foo_inst);
   mod_B mod_B(.trig, .foo_inst);
endmodule

Of course there're also some functions defined in the class which are used in each module. The issue with this setup is that I'm seeing errors for each ports of mod_B:

Error-[RIPLIP] Register in low conn of input port
Non-net variable 'foo_inst' cannot be an input or inout port.
Non-net variable   'trig'   cannot be an input or inout port.

EDAplayground does not support class objects as module ports and 1800-2012 only mentions interface declarations, events, arrays structures or unions in Port declarations (23.2.2) so my questions are:

  • Is it even legal to pass classes through ports? If not, what is an elegant method of accomplishing this?
  • What does "Register in low conn of input port" mean? I'm aware that this might be a compiler specific error and nothing indicative but if I knew what it was trying to tell me I might be a step closer to fixing this.
1

There are 1 best solutions below

3
On BEST ANSWER

A variable of any type can be an input or output port. You might have to write for your compiler

input var foo foo_inst,

But it would be better to use a ref when a port is really a handle.

module mod_A(ref foo foo_inst, ref event trig);

Note that you have a typo with foo_o or foo_inst and a race condition between a trigger ->trig and an event control @(trig).