Is it possible to combine interface signals inside a struct and define the struct inside the clocking block for directions?

Hello !

Is it possible to use struct inside the clocking/modport for defining the directions for signals defined inside a struct. I was trying to define a simple struct as shown below.


  typedef struct packed {
    logic rst;
    logic addr;
  } dummy_struct_if;

And tried instantiating inside an interface to use the same inside the clocking block


  interface dummy_if;
    dummy_struct_if dummy_struct_if_s;

    clocking dummy_cb@(posedge clk);
     input dummy_struct_if_s.rst;
     input dummy_struct_if_s.addr;
    endclocking: dummy_cb  
  endinterface: dummy_if

But I faced this below compile error.


Error-[SE] Syntax error
  Following verilog source has syntax error :
  "../../dummy_if.sv", 30: token is '.'
     input  dummy_struct_if_s.ram_rst;

I haven’t seen any examples in the SV LRM as well portraying using struct inside the clocking block. Is it possible to define a struct inside a clocking block/modport or not ?

In reply to desperadorocks:

Clocking block variables need simple names. You need to use this syntax.

interface dummy_if;
    dummy_struct_if dummy_struct_if_s;
 
    clocking dummy_cb@(posedge clk);
     input rst = dummy_struct_if_s.rst;
     input addr = dummy_struct_if_s.addr;
    endclocking: dummy_cb  
  endinterface: dummy_if

Now you can refer to dummy_cb.rst and dummy_cb.addr.

In reply to dave_59:

Thanks Dave for your inputs. But won’t this be like duplicating the signals ?
a. By default we need to use/define rst and addr in the interface.
b. Along with that we need to instantiate the dummy_struct_if, and do the connection you described above.

So that we can use dummy_struct_if within the active and passive components to drive/monitor right? Any specific reason why the LRM/rules doesn’t allow declaring straight-away the structs which contains the signal and define the sampling and directions ? Please clarify.

In reply to desperadorocks:
If you want all the fields of the struct in the same direction, just declare dummy_struct_if_s as a clocking block input; there’s no need to specify the individual fields.

And you are in fact declaring “duplicate “ variables in the scope of the clocking block which is why the variable names need to be simple identifiers.