| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- module host_watchdog_contract_formal (
- input wire clk,
- input wire rst_n,
- input wire tick_500us,
- input wire valid_set_all_commit,
- input wire motor_start,
- input wire [1:0] motor_active_mask,
- input wire [1:0] motor_dir_mask
- );
- // The formal target proves ordering with a small parameter. The production
- // 20,000-tick boundary is covered by tests/sim/host_watchdog_tb.v.
- localparam integer FORMAL_TIMEOUT_TICKS = 4;
- localparam integer FORMAL_FIXED_STEPS = 4;
- localparam integer FORMAL_DIR_SETUP_TICKS = 2;
- localparam integer DEPTH = 12;
- localparam integer PTC_COUNT = 8;
- localparam [7:0] WATCHDOG_PTC_TARGET = 8'd0;
- localparam [7:0] WATCHDOG_FAN_TARGET = 8'd20;
- wire dut_rst_n = rst_n;
- wire watchdog_active;
- wire timeout_event;
- wire motor_busy;
- wire motor_done;
- wire [1:0] step;
- wire [1:0] motor_dir;
- wire [7:0] target_rd_data;
- reg [1:0] reset_cycles;
- reg [3:0] target_rd_addr;
- reg [3:0] previous_rd_addr;
- reg previous_watchdog_active;
- reg target_read_valid;
- reg commit_pending;
- reg timeout_seen;
- host_watchdog #(.TIMEOUT_TICKS(FORMAL_TIMEOUT_TICKS)) u_watchdog (
- .clk(clk), .rst_n(dut_rst_n), .tick_500us(tick_500us),
- .valid_set_all_commit(valid_set_all_commit), .watchdog_active(watchdog_active),
- .timeout_event(timeout_event)
- );
- output_target_ram #(
- .DEPTH(DEPTH), .PTC_COUNT(PTC_COUNT),
- .BOOT_PTC_TARGET(8'd0), .BOOT_FAN_TARGET(8'd10),
- .WATCHDOG_PTC_TARGET(WATCHDOG_PTC_TARGET),
- .WATCHDOG_FAN_TARGET(WATCHDOG_FAN_TARGET)
- ) u_targets (
- .clk(clk), .rst_n(dut_rst_n), .wr_en(1'b0), .wr_addr(4'd0),
- .wr_data(8'd0), .commit(1'b0), .watchdog_active(watchdog_active),
- .rd_addr(target_rd_addr), .rd_data(target_rd_data)
- );
- door_motor_engine #(
- .FIXED_STEPS(FORMAL_FIXED_STEPS),
- .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
- ) u_motor (
- .clk(clk), .rst_n(dut_rst_n), .start(motor_start),
- .active_mask(motor_active_mask), .dir_mask(motor_dir_mask),
- .tick_500us(tick_500us), .abort(timeout_event), .busy(motor_busy),
- .done(motor_done), .step(step), .dir(motor_dir)
- );
- initial begin
- reset_cycles = 2'd0;
- target_rd_addr = 4'd0;
- previous_rd_addr = 4'd0;
- previous_watchdog_active = 1'b0;
- target_read_valid = 1'b0;
- commit_pending = 1'b0;
- timeout_seen = 1'b0;
- end
- always @(posedge clk) begin
- assume (rst_n == 1'b0 || rst_n == 1'b1);
- assume (tick_500us == 1'b0 || tick_500us == 1'b1);
- assume (valid_set_all_commit == 1'b0 || valid_set_all_commit == 1'b1);
- assume (motor_start == 1'b0 || motor_start == 1'b1);
- assume ((^motor_active_mask) == 1'b0 || (^motor_active_mask) == 1'b1);
- assume ((^motor_dir_mask) == 1'b0 || (^motor_dir_mask) == 1'b1);
- assume (!motor_busy || !motor_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
- target_rd_addr <= 4'd0;
- previous_rd_addr <= 4'd0;
- previous_watchdog_active <= 1'b0;
- target_read_valid <= 1'b0;
- commit_pending <= 1'b0;
- timeout_seen <= 1'b0;
- end else begin
- if (target_rd_addr == DEPTH - 1)
- target_rd_addr <= 4'd0;
- else
- target_rd_addr <= target_rd_addr + 1'b1;
- // output_target_ram is a synchronous read: target_rd_data at this
- // edge belongs to the address and watchdog mode sampled at the
- // preceding edge. Guard the assertion until that pipeline state
- // has been established by reset; no shadow/active model is needed.
- if (target_read_valid && previous_watchdog_active) begin
- if (previous_rd_addr < PTC_COUNT)
- assert (target_rd_data == WATCHDOG_PTC_TARGET);
- else
- assert (target_rd_data == WATCHDOG_FAN_TARGET);
- end
- previous_rd_addr <= target_rd_addr;
- previous_watchdog_active <= watchdog_active;
- target_read_valid <= 1'b1;
- // host_watchdog gives a valid SET commit/feed priority over a
- // timeout decision. This checks the registered result one clock
- // after the sampled commit input.
- if (commit_pending) begin
- assert (!watchdog_active);
- assert (!timeout_event);
- end
- commit_pending <= valid_set_all_commit;
- // timeout_event is registered. The motor consumes it on the next
- // system clock; this flag observes the post-NBA STEP value one
- // sample later and avoids asserting against the pre-update value.
- if (timeout_event) timeout_seen <= 1'b1;
- if (timeout_seen) begin
- assert (step == 2'b00);
- timeout_seen <= 1'b0;
- end
- end
- end
- always @(posedge clk) begin
- cover (dut_rst_n && timeout_event);
- cover (dut_rst_n && motor_busy && timeout_event);
- cover (dut_rst_n && watchdog_active && target_rd_addr == 4'd8);
- end
- endmodule
|