1

Is there a way to get the size of a field in a structure? For instance, $bits does not work. any other approach?

localparam L_DATA_BITS      = $bits(pkt_char_t.length);

typedef struct packed {
   logic [15:0]   checksum;
   logic [3:0]    offload_flags;
   logic          length_err;
   logic [13:0]   length;
   } pkt_char_t;
EML
  • 9,619
  • 6
  • 46
  • 78
Mike J
  • 11
  • 2

1 Answers1

0

You cannot reference a field of a type. You also cannot reference a type before it is defined.

You can reference a field of a variable or parameter.

module top;
   typedef struct packed {
   logic [15:0]   checksum;
   logic [3:0]    offload_flags;
   logic          length_err;
   logic [13:0]   length;
   } pkt_char_t;

   pkt_char_t pkt_char;
   localparam int L_DATA_BITS =  $bits(pkt_char.length);
   initial $display(L_DATA_BITS);
endmodule
dave_59
  • 39,096
  • 3
  • 24
  • 63