Hi all,
How to write functional coverage for FSM , im stuck at like how to extract the states into functional coverage.
module example (
output wire [1:0] out,
input wire clk,
input wire in,
input wire rst_n
);
/ / s t a t e b i t s
parameter
S0 = 2’b00, / / out [ 1 : 0 ]=0 0
S1 = 2’b01, / / out [ 1 : 0 ]=0 1
S2 = 2’b10; / / out [ 1 : 0 ]=1 0
reg [1:0] state;
reg [1:0] nextstate;
/ / comb alway s b l o c k
always @* begin
nextstate = state;
c as e (state)
S0: begin
i f (in = 1) begin
nextstate = S1;
end
e l s e begin
nextstate = S0;
end
end
S1: begin
i f (in = 1) begin
nextstate = S2;
end
e l s e begin
nextstate = S0;
end
end
S2: begin
begin
nextstate = S0;
end
end
endcase
end
/ / As s ign reg ’ d o u t p u t s t o s t a t e b i t s
a s s i g n out[1:0] = state[1:0];
/ / s e q u e n t i a l alway s b l o c k
always @(posedge clk or negedge rst_n) begin
i f (!rst_n)
state <= S0;
e l s e
state <= nextstate;
end
endmodule