Struct with enum field - Reset issue


Resetting a struct with a enum inside it needs special consideration, as enum can only have it's label as values. So a '{default:0} won't work.

To fix this, write a function which assigns the default value for the struct (Basically enum with default label)

e.g.:

typedef enum logic {

RD,

WR

} op_e;


typedef struct packed {

op_e optype;

logic exclusive;

} op_t;


typedef struct packed {

op_t op;

logic [63:0] data;

} inst_t;


inst_t inst;


always_comb begin

inst = '{default:0};

end


function automatic inst_t rst_inst_t;

inst_t.op.optype = RD;

inst_t.op.exclusive = '0;

inst_t.data = '0;

endfunction


always_comb begin

inst = rst_inst_t();

end


Tags: #enum #struct #reset