module bsm (input clk, input reset, input clear, input write_done, input read_done, output readable, output writeable); reg state; localparam ST_WRITEABLE = 0; localparam ST_READABLE = 1; always @(posedge clk) if(reset | clear) state <= ST_WRITEABLE; else case(state) ST_WRITEABLE : if(write_done) state <= ST_READABLE; ST_READABLE : if(read_done) state <= ST_WRITEABLE; endcase // case (state) assign readable = (state == ST_READABLE); assign writeable = (state == ST_WRITEABLE); endmodule // bsm module dbsm (input clk, input reset, input clear, output reg read_sel, output read_ready, input read_done, output reg write_sel, output write_ready, input write_done); localparam NUM_BUFS = 2; wire [NUM_BUFS-1:0] readable, writeable, read_done_buf, write_done_buf; // Two of these buffer state machines genvar i; for(i=0;i