1

This is related to my previous question. Consider the following module declaration:

module DFF(d, q, CLK, RESET);
 parameter W = 2;
 input  [W-1:0] d;                      
 input  CLK;                                
 input  RESET;      
 output logic [W-1:0]   q; 

//....
endmodule

What is the proper way of instantiating it where d and q are of struct type? Here is my struct type:

typedef struct { logic s1; logic s2} T_STATE;

I would like to instantiate the DFF for a T_STATE variable type:

T_STATE d, q;
DFF dff_inst (.d(d), .q(q), .CLK(CLK), .RESET(RESET));

I have unsuccessfully tried the followings:

typedef logic [$bits(T_STATE) - 1 : 0] T_STATE_LOGIC; 
DFF dff_inst (.d(T_STATE_LOGIC'(d)), .q(T_STATE_LOGIC'(q)), .CLK(CLK), .RESET(RESET));

and

DFF dff_inst (.d({d}), .q({q}), .CLK(CLK), .RESET(RESET));

I need the code to be synthesizable.

Community
  • 1
  • 1
Ari
  • 7,251
  • 11
  • 40
  • 70

1 Answers1

4

Make it a struct of packed bits.

Change:

typedef struct { logic s1; logic s2} T_STATE;

to:

typedef struct packed { logic s1; logic s2;} T_STATE;

Your DDF can be instantiated as:

DFF dff_inst (.d(d), .q(q), .CLK(CLK), .RESET(RESET));

Note: you were missing a semicolon for s2 in the struct definition.

Greg
  • 18,111
  • 5
  • 46
  • 68