module simple_motor_temperature_contract_formal ( input wire clk, input wire rst_n, input wire start, input wire [1:0] active_mask, input wire [1:0] dir_mask, input wire tick_500us, input wire abort, input wire [1:0] stop_mask ); // This target proves parameterized motor invariants. Production 450-step // timing is covered by tests/sim/door_motor_engine_tb.v. localparam integer FORMAL_FIXED_STEPS = 4; localparam integer FORMAL_DIR_SETUP_TICKS = 2; wire busy; wire done; wire [1:0] step; wire [1:0] dir; wire dut_rst_n = rst_n; reg [1:0] expected_active; reg [1:0] expected_dir; reg [1:0] previous_step; reg [31:0] rising_edges; reg [1:0] reset_cycles; reg start_seen; reg run_started; door_motor_engine #( .FIXED_STEPS(FORMAL_FIXED_STEPS), .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS) ) motor ( .clk(clk), .rst_n(dut_rst_n), .start(start), .active_mask(active_mask), .dir_mask(dir_mask), .tick_500us(tick_500us), .abort(abort), .stop_mask(stop_mask), .busy(busy), .done(done), .step(step), .dir(dir) ); // Existing contract target proves behavior without stop_mask; stop semantics are // covered by additional dedicated targets. always @(posedge clk) begin assume (stop_mask == 2'b00); end initial begin expected_active = 2'b00; expected_dir = 2'b00; previous_step = 2'b00; rising_edges = 32'd0; reset_cycles = 2'd0; start_seen = 1'b0; run_started = 1'b0; end always @(posedge clk) begin assume (rst_n == 1'b0 || rst_n == 1'b1); assume (start == 1'b0 || start == 1'b1); assume ((^active_mask) == 1'b0 || (^active_mask) == 1'b1); assume ((^dir_mask) == 1'b0 || (^dir_mask) == 1'b1); assume (tick_500us == 1'b0 || tick_500us == 1'b1); assume (abort == 1'b0 || abort == 1'b1); assume (!start_seen || !start); assume (!busy || !start); if ($initstate || reset_cycles < 2) begin assume (!dut_rst_n); reset_cycles <= reset_cycles + 1'b1; end else begin assume (dut_rst_n); end if (!dut_rst_n) begin expected_active <= 2'b00; expected_dir <= 2'b00; previous_step <= 2'b00; rising_edges <= 32'd0; start_seen <= 1'b0; run_started <= 1'b0; end else begin if (!busy && start) begin expected_active <= active_mask; expected_dir <= dir_mask; rising_edges <= 32'd0; run_started <= (active_mask != 2'b00); end if (start) start_seen <= 1'b1; if (!busy) assert (step == 2'b00); assert ((step & ~expected_active) == 2'b00); if (busy) assert (dir == expected_dir); if (step[0]) assert (expected_active[0]); if (step[1]) assert (expected_active[1]); if (previous_step != 2'b00) assert (step == previous_step || step == 2'b00); if (step != 2'b00 && previous_step == 2'b00) begin // Every STEP rising edge is produced by a 500 us tick. assert (busy); assert ($past(tick_500us)); rising_edges <= rising_edges + 1'b1; end assert (rising_edges <= FORMAL_FIXED_STEPS); if (done) begin assert (step == 2'b00); if (run_started) assert (rising_edges == FORMAL_FIXED_STEPS); run_started <= 1'b0; end if (abort) run_started <= 1'b0; if ($past(abort)) begin // Abort takes effect on the next system-clock edge. assert (!busy); assert (step == 2'b00); end previous_step <= step; end end always @(posedge clk) begin cover (dut_rst_n && start && active_mask == 2'b11); cover (dut_rst_n && busy && step == 2'b11); cover (dut_rst_n && run_started && done); cover (dut_rst_n && abort && busy); end endmodule