`timescale 1ns/1ns module sequence_detect( input clk, input rst_n, input data, input data_valid, output reg match ); reg [1:0]cs,ns; always@(posedge clk or negedge rst_n)begin if(!rst_n)begin cs<=0; end else begin cs<=ns; end end always@(*)begin case(cs) 2'b00:begin if(data_valid)begin ns=(data==0)?2'b01:2'b00; end else begin ns=cs; end end 2'b01:begin if(data_valid)begin ns=(data==1)?2'b10:2'b01; end else begin ns=cs; end end 2'b10:begin if(data_valid)begin ns=(data==1)?2'b11:2'b00; end else begin ns=cs; end end 2'b11:begin if(data_valid)begin ns=0; end else begin ns=cs; end end endcase end always@(posedge clk or negedge rst_n)begin if(!rst_n)begin match<=0; end else begin match<=((cs==2'b11)&&(data==0)&&(data_valid==1))?1:0; end end endmodule