| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- // Startup close/seek BMC with REAL door_motor_engine + top-style STEP truncate
- // gate. Stop semantics modeled as ACTUAL RTL truncate (not finish-high):
- // truncate_current_high_pulse_immediately_after_synchronized_limit
- module startup_close_seek_formal (
- input wire clk,
- input wire rst_n,
- input wire tick_500us,
- input wire [2:0] limit_ls_sync,
- input wire [2:0] limit_hs_sync
- );
- localparam integer FORMAL_CLOSE_STEPS = 2;
- localparam integer FORMAL_BACKOFF_STEPS = 2;
- localparam integer FORMAL_DIR_SETUP_TICKS = 1;
- localparam integer AXIS_COUNT = 3;
- localparam [AXIS_COUNT-1:0] FORMAL_CLOSE_DIR_MASK = {AXIS_COUNT{1'b1}};
- wire startup_done;
- wire motor_start;
- wire [AXIS_COUNT-1:0] motor_active_mask;
- wire [AXIS_COUNT-1:0] motor_dir_mask;
- wire [AXIS_COUNT-1:0] motor_stop_mask;
- wire [2:0] motor_step_count;
- wire motor_done;
- wire motor_busy;
- wire [AXIS_COUNT-1:0] engine_step;
- wire [AXIS_COUNT-1:0] engine_dir;
- reg [2:0] reset_cycles;
- reg formal_sync_valid;
- reg saw_ls_low;
- reg [AXIS_COUNT-1:0] prev_gated_step;
- reg past_valid;
- reg [3:0] backoff_rising_x;
- reg in_backoff;
- reg close_phase;
- reg found_ls_frozen;
- reg [AXIS_COUNT-1:0] shadow_found_ls;
- 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
- // Default polarity: close_limit=LS, open_limit=HS.
- wire [AXIS_COUNT-1:0] close_limit = limit_ls_sync;
- wire [AXIS_COUNT-1:0] open_limit = limit_hs_sync;
- startup_close_seek #(
- .CLOSE_STEPS(FORMAL_CLOSE_STEPS),
- .BACKOFF_STEPS(FORMAL_BACKOFF_STEPS),
- .AXIS_COUNT(AXIS_COUNT),
- .CLOSE_DIR_MASK(FORMAL_CLOSE_DIR_MASK)
- ) u_startup (
- .clk(clk),
- .rst_n(rst_n),
- .limit_sync_valid(formal_sync_valid),
- .close_limit(close_limit),
- .open_limit(open_limit),
- .startup_done(startup_done),
- .motor_start(motor_start),
- .motor_active_mask(motor_active_mask),
- .motor_dir_mask(motor_dir_mask),
- .motor_step_count(motor_step_count),
- .motor_stop_mask(motor_stop_mask),
- .motor_done(motor_done)
- );
- door_motor_engine #(
- .AXIS_COUNT(AXIS_COUNT),
- .MAX_STEPS(FORMAL_CLOSE_STEPS),
- .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
- ) u_motor (
- .clk(clk),
- .rst_n(rst_n),
- .start(motor_start),
- .active_mask(motor_active_mask),
- .dir_mask(motor_dir_mask),
- .step_count(motor_step_count),
- .tick_500us(tick_500us),
- .abort(1'b0),
- .stop_mask(motor_stop_mask),
- .busy(motor_busy),
- .done(motor_done),
- .step(engine_step),
- .dir(engine_dir)
- );
- // Top-style external STEP truncate gate on selected logical limit.
- wire [AXIS_COUNT-1:0] selected_limit;
- wire [AXIS_COUNT-1:0] gated_step;
- assign selected_limit[0] = engine_dir[0] ? close_limit[0] : open_limit[0];
- assign selected_limit[1] = engine_dir[1] ? close_limit[1] : open_limit[1];
- assign selected_limit[2] = engine_dir[2] ? close_limit[2] : open_limit[2];
- assign gated_step[0] = engine_step[0] & ~selected_limit[0];
- assign gated_step[1] = engine_step[1] & ~selected_limit[1];
- assign gated_step[2] = engine_step[2] & ~selected_limit[2];
- wire motor_en_n = 1'b1;
- initial begin
- reset_cycles = 3'd0;
- saw_ls_low = 1'b0;
- prev_gated_step = 3'b000;
- past_valid = 1'b0;
- backoff_rising_x = 4'd0;
- in_backoff = 1'b0;
- close_phase = 1'b0;
- found_ls_frozen = 1'b0;
- shadow_found_ls = 3'b000;
- end
- always @(posedge clk) begin
- assume (rst_n == 1'b0 || rst_n == 1'b1);
- assume (tick_500us == 1'b0 || tick_500us == 1'b1);
- assume ((^limit_ls_sync) == 1'b0 || (^limit_ls_sync) == 1'b1);
- assume ((^limit_hs_sync) == 1'b0 || (^limit_hs_sync) == 1'b1);
- if ($initstate || reset_cycles < 3) begin
- assume (!rst_n);
- reset_cycles <= reset_cycles + 1'b1;
- past_valid <= 1'b0;
- saw_ls_low <= 1'b0;
- prev_gated_step <= 3'b000;
- backoff_rising_x <= 4'd0;
- in_backoff <= 1'b0;
- close_phase <= 1'b0;
- found_ls_frozen <= 1'b0;
- shadow_found_ls <= 3'b000;
- end else begin
- assume (rst_n);
- past_valid <= 1'b1;
- end
- if (rst_n) begin
- assert (motor_en_n == 1'b1);
- if (limit_ls_sync != 3'b111)
- saw_ls_low <= 1'b1;
- // Mirror DUT found_ls only during close-wait (freeze on motor_done).
- if (motor_start && (motor_dir_mask == FORMAL_CLOSE_DIR_MASK)) begin
- close_phase <= 1'b1;
- found_ls_frozen <= 1'b0;
- // Non-participants already sat on LS; OR current LS on first close beat.
- shadow_found_ls <= (~motor_active_mask) | limit_ls_sync;
- end else if (close_phase && !found_ls_frozen) begin
- shadow_found_ls <= shadow_found_ls | limit_ls_sync;
- if (motor_done)
- found_ls_frozen <= 1'b1;
- end
- if (startup_done || (motor_start && (motor_dir_mask == 3'b000)))
- close_phase <= 1'b0;
- // Backoff start: DIR=0 and a new motor_start.
- if (motor_start && (motor_dir_mask == 3'b000)) begin
- in_backoff <= 1'b1;
- backoff_rising_x <= 4'd0;
- assert (motor_step_count == FORMAL_BACKOFF_STEPS[2:0]);
- // Axes that already found LS during close must not enter backoff.
- assert ((motor_active_mask & shadow_found_ls) == 3'b000);
- end
- if (startup_done)
- in_backoff <= 1'b0;
- if (in_backoff && !prev_gated_step[0] && gated_step[0])
- backoff_rising_x <= backoff_rising_x + 1'b1;
- // Sticky idle after startup_done.
- if (!$initstate && $past(startup_done)) begin
- assert (startup_done);
- assert (motor_start == 1'b0);
- assert (motor_active_mask == 3'b000);
- assert (motor_dir_mask == 3'b000);
- assert (motor_stop_mask == 3'b000);
- end
- if ($past(motor_start)) assert (!motor_start);
- // All LS high from reset: no external STEP rising edges.
- if (!saw_ls_low) begin
- assert (gated_step == 3'b000);
- if (past_valid)
- assert (!( !prev_gated_step[0] && gated_step[0] ));
- end
- // Truncate pin path: selected logical limit => gated STEP 0 same cycle.
- if (selected_limit[0])
- assert (gated_step[0] == 1'b0);
- if (selected_limit[1])
- assert (gated_step[1] == 1'b0);
- if (selected_limit[2])
- assert (gated_step[2] == 1'b0);
- // Missed-axis backoff budget: at most BACKOFF_STEPS rising edges.
- assert (backoff_rising_x <= FORMAL_BACKOFF_STEPS[3:0]);
- if (past_valid) begin
- // Engine truncate: registered STEP cleared the cycle after stop_mask.
- if ($past(motor_stop_mask[0]) && $past(rst_n))
- assert (engine_step[0] == 1'b0);
- if ($past(motor_stop_mask[1]) && $past(rst_n))
- assert (engine_step[1] == 1'b0);
- if ($past(motor_stop_mask[2]) && $past(rst_n))
- assert (engine_step[2] == 1'b0);
- // During backoff, HS can terminate early (no new rise while HS high).
- if (in_backoff && $past(limit_hs_sync[0]) && !engine_dir[0])
- assert (!( !prev_gated_step[0] && gated_step[0] ));
- end
- prev_gated_step <= gated_step;
- end
- end
- always @(posedge clk) begin
- cover (rst_n && startup_done);
- cover (rst_n && motor_active_mask == 3'b111);
- cover (rst_n && startup_done && limit_ls_sync == 3'b000);
- cover (rst_n && motor_start && motor_dir_mask == 3'b000);
- cover (rst_n && !saw_ls_low && startup_done);
- end
- endmodule
|