Hi folks,
I get one question on unnamed enum type from DUT assigning to interface variable.
At time 0, the interface variable - nxt_st contains 0 somehow. Can someone help me understand it?
If interface always wants to skip the time 0 change on nxt_st without modifying module - my_fsm, how to fix it in a reasonable way?
`define ANONYMOUS_INT
module my_fsm(
input clk,
input rst_n
);
`ifdef ANONYMOUS_INT
enum { //0: 'h0, 'h40
`else
enum logic [7:0] { //0: 'h40
`endif
S0 = 'h40,
S1 = 'h0, //non-initial state
S2 = 'h1,
S3 = 'h2
} st, nxt_st;
always @(posedge clk or negedge rst_n) begin
if(~rst_n) begin
st <= S0;
end else begin
st <= nxt_st;
end
end
always @(*) begin
nxt_st = st;
end
// always @(nxt_st) begin
// $display("%0t: %s",$realtime, nxt_st.name());
// end
endmodule
interface my_if(input clk, rst_n);
logic [7:0] nxt_st;
assign nxt_st = tb.dut.nxt_st;
always @(nxt_st) begin
$display("%0t: 'h%0h",$realtime, nxt_st);
end
endinterface
module tb;
bit clk, rst_n;
my_fsm dut(.clk(clk), .rst_n(rst_n));
my_if if0(.clk(clk), .rst_n(rst_n));
always #1 clk = ~clk;
initial begin
#2 rst_n = 1;
#10 $finish();
end
initial begin
$dumpfile("dump.vcd");
$dumpvars(0, tb);
end
endmodule
Thanks ~