| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- module startup_close_seek_formal (
- input wire clk,
- input wire rst_n,
- input wire tick_500us,
- input wire [1:0] limit_sync
- );
- localparam integer FORMAL_MAX_BURSTS = 2;
- localparam integer FORMAL_INTER_BURST_TICKS = 2;
- localparam integer FORMAL_FIXED_STEPS = 2;
- localparam integer FORMAL_DIR_SETUP_TICKS = 1;
- localparam integer FORMAL_STEP_HALF_CYCLES = 2;
- localparam [1:0] FORMAL_DIR_MASK = 2'b11;
- wire startup_done;
- wire motor_start;
- wire [1:0] motor_active_mask;
- wire [1:0] motor_dir_mask;
- wire [1:0] motor_stop_mask;
- wire motor_done;
- reg [2:0] reset_cycles;
- reg [3:0] burst_counter;
- reg motor_busy;
- reg formal_sync_valid;
- // The synchronizer is modelled as invalid for the first three cycles after reset.
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- formal_sync_valid <= 1'b0;
- end else if (reset_cycles < 3) begin
- formal_sync_valid <= 1'b0;
- end else begin
- formal_sync_valid <= 1'b1;
- end
- end
- startup_close_seek #(
- .FIXED_STEPS(FORMAL_FIXED_STEPS),
- .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS),
- .STEP_HALF_CYCLES(FORMAL_STEP_HALF_CYCLES),
- .MAX_BURSTS(FORMAL_MAX_BURSTS),
- .INTER_BURST_TICKS(FORMAL_INTER_BURST_TICKS),
- .DIR_MASK(FORMAL_DIR_MASK)
- ) u_startup (
- .clk(clk),
- .rst_n(rst_n),
- .tick_500us(tick_500us),
- .limit_sync_valid(formal_sync_valid),
- .limit_sync(limit_sync),
- .startup_done(startup_done),
- .motor_start(motor_start),
- .motor_active_mask(motor_active_mask),
- .motor_dir_mask(motor_dir_mask),
- .motor_stop_mask(motor_stop_mask),
- .motor_done(motor_done)
- );
- // Fair motor model: when start is asserted, it becomes busy for a bounded
- // number of ticks and then asserts done for one cycle.
- reg [3:0] motor_count;
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- motor_busy <= 1'b0;
- motor_count <= 4'd0;
- end else begin
- if (motor_start && !motor_busy) begin
- motor_busy <= 1'b1;
- motor_count <= 4'd0;
- end else if (motor_busy) begin
- if (motor_count < FORMAL_FIXED_STEPS + FORMAL_DIR_SETUP_TICKS) begin
- motor_count <= motor_count + 1'b1;
- end else begin
- motor_busy <= 1'b0;
- end
- end
- end
- end
- assign motor_done = motor_busy && (motor_count == FORMAL_FIXED_STEPS + FORMAL_DIR_SETUP_TICKS);
- initial reset_cycles = 3'd0;
- always @(posedge clk) begin
- assume (rst_n == 1'b0 || rst_n == 1'b1);
- assume (tick_500us == 1'b0 || tick_500us == 1'b1);
- assume ((^limit_sync) == 1'b0 || (^limit_sync) == 1'b1);
- if ($initstate || reset_cycles < 3) begin
- assume (!rst_n);
- reset_cycles <= reset_cycles + 1'b1;
- end else begin
- assume (rst_n);
- end
- if (rst_n) begin
- // Once done, the module must stay done and inactive. Use $past so
- // the check observes the settled register values one cycle after the
- // transition into DONE, avoiding combinational-delta races between
- // the DUT and the witness assertions.
- if (!$initstate && $past(startup_done)) begin
- assert (startup_done);
- assert (motor_start == 1'b0);
- assert (motor_active_mask == 2'b00);
- assert (motor_dir_mask == 2'b00);
- // Post-calibration one-shot: stop mask to the motor engine is inert.
- assert (motor_stop_mask == 2'b00);
- end
- // Active mask is always a subset of the two axes and never changes
- // during a burst except at burst boundaries.
- assert (motor_active_mask == 2'b00 || motor_active_mask == 2'b01 ||
- motor_active_mask == 2'b10 || motor_active_mask == 2'b11);
- // Direction mask is either zero or the configured close direction.
- assert (motor_dir_mask == 2'b00 || motor_dir_mask == FORMAL_DIR_MASK);
- // motor_start is a single-cycle pulse.
- if ($past(motor_start)) assert (!motor_start);
- end
- end
- always @(posedge clk) begin
- cover (rst_n && startup_done);
- cover (rst_n && motor_active_mask == 2'b11);
- cover (rst_n && startup_done && limit_sync == 2'b00);
- cover (rst_n && startup_done && limit_sync == 2'b11);
- end
- endmodule
|