| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627 |
- `timescale 1ns/1ps
- `default_nettype none
- // Independent observable axis model. The implementation uses a four-state
- // phase machine; this oracle instead uses explicit setup/high/low countdowns.
- module prod2u_p4_fast_jog_axis_oracle #(
- parameter integer DIR_SETUP_CYCLES = 3,
- parameter integer STEP_HALF_CYCLES = 2
- ) (
- input wire clk,
- input wire rst_n,
- input wire command_start,
- input wire command_dir,
- input wire [15:0] command_steps,
- output reg step_out,
- output reg dir_out,
- output reg started_pulse,
- output reg active,
- output reg [15:0] steps_left
- );
- reg [15:0] setup_left;
- reg [15:0] high_left;
- reg [15:0] low_left;
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- step_out <= 1'b0;
- dir_out <= 1'b0;
- started_pulse <= 1'b0;
- active <= 1'b0;
- steps_left <= 16'd0;
- setup_left <= 16'd0;
- high_left <= 16'd0;
- low_left <= 16'd0;
- end else begin
- started_pulse <= 1'b0;
- if (command_start) begin
- step_out <= 1'b0;
- dir_out <= command_dir;
- active <= 1'b1;
- steps_left <= command_steps;
- setup_left <= DIR_SETUP_CYCLES;
- high_left <= 16'd0;
- low_left <= 16'd0;
- end else if (active) begin
- if (setup_left != 16'd0) begin
- if (setup_left == 16'd1) begin
- setup_left <= 16'd0;
- step_out <= 1'b1;
- high_left <= STEP_HALF_CYCLES;
- started_pulse <= 1'b1;
- end else begin
- setup_left <= setup_left - 16'd1;
- end
- end else if (step_out) begin
- if (high_left == 16'd1) begin
- step_out <= 1'b0;
- high_left <= 16'd0;
- low_left <= STEP_HALF_CYCLES;
- end else begin
- high_left <= high_left - 16'd1;
- end
- end else if (low_left != 16'd0) begin
- if (low_left == 16'd1) begin
- low_left <= 16'd0;
- if (steps_left == 16'd1) begin
- active <= 1'b0;
- steps_left <= 16'd0;
- end else begin
- steps_left <= steps_left - 16'd1;
- step_out <= 1'b1;
- high_left <= STEP_HALF_CYCLES;
- end
- end else begin
- low_left <= low_left - 16'd1;
- end
- end
- end
- end
- end
- endmodule
- // End-to-end core proof with deliberately short periods. A legal fast JOG is
- // compared against two independent axis oracles while an unrelated ordinary
- // command and TX backpressure are unconstrained. Any dependency on
- // request_ready, the core state, command_inflight, or frame_ready breaks the
- // observable equivalence.
- module prod2u_p4_fast_jog_path_formal;
- localparam integer FORMAL_DIR_SETUP_CYCLES = 3;
- localparam integer FORMAL_STEP_HALF_CYCLES = 2;
- (* gclk *) reg clk;
- reg rst_n = 1'b0;
- reg past_valid = 1'b0;
- (* anyseq *) reg ordinary_request_valid;
- (* anyseq *) reg ordinary_request_is_snapshot;
- (* anyseq *) reg frame_ready;
- (* anyseq *) reg fast_jog_valid;
- (* anyseq *) reg [1:0] fast_jog_axis;
- (* anyseq *) reg fast_jog_dir;
- (* anyseq *) reg [15:0] fast_jog_steps;
- wire request_ready;
- wire frame_valid;
- wire [7:0] frame_type;
- wire [7:0] frame_payload_len;
- wire [143:0] frame_payload;
- wire [191:0] ptc_percent;
- wire [31:0] fan_percent;
- wire [7:0] solenoid_percent;
- wire [15:0] state_hash16;
- wire [2:0] step_out;
- wire [2:0] dir_out;
- wire en_n;
- wire disabled;
- wire watchdog_timeout;
- wire [2:0] dut_state;
- wire x_spec_step;
- wire x_spec_dir;
- wire x_spec_started;
- wire x_spec_active;
- wire [15:0] x_spec_steps_left;
- wire y_spec_step;
- wire y_spec_dir;
- wire y_spec_started;
- wire y_spec_active;
- wire [15:0] y_spec_steps_left;
- reg [2:0] previous_step = 3'd0;
- reg saw_tx_blocked_fast = 1'b0;
- reg blocked_fast_axis = 1'b0;
- reg saw_nonidle_fast = 1'b0;
- reg nonidle_fast_axis = 1'b0;
- reg saw_ffff_fast = 1'b0;
- reg x_two_active = 1'b0;
- reg [1:0] x_two_rises = 2'd0;
- reg x_two_complete = 1'b0;
- // GET_STATUS occupies the response scheduler; a valid snapshot reaches
- // the non-IDLE validate/commit states without creating a motor command.
- reg [271:0] snapshot_request_payload;
- integer snapshot_index;
- always @* begin
- snapshot_request_payload = 272'd0;
- snapshot_request_payload[7:0] = 8'h2a;
- for (snapshot_index = 0; snapshot_index < 24;
- snapshot_index = snapshot_index + 1) begin
- snapshot_request_payload[(snapshot_index + 2) * 8 +: 8] = 8'd10;
- end
- for (snapshot_index = 0; snapshot_index < 4;
- snapshot_index = snapshot_index + 1) begin
- snapshot_request_payload[(snapshot_index + 26) * 8 +: 8] = 8'd30;
- end
- end
- wire [7:0] ordinary_request_type =
- ordinary_request_is_snapshot ? 8'h07 : 8'h05;
- wire [5:0] ordinary_request_length =
- ordinary_request_is_snapshot ? 6'd34 : 6'd4;
- wire [271:0] ordinary_payload = ordinary_request_is_snapshot ?
- snapshot_request_payload : {264'd0, 8'h24};
- prod2u_p4_normal_v3_core #(
- .CLK_HZ(4),
- .WATCHDOG_SECONDS(2),
- .DIR_SETUP_CYCLES(FORMAL_DIR_SETUP_CYCLES),
- .STEP_HALF_CYCLES(FORMAL_STEP_HALF_CYCLES)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .request_valid(ordinary_request_valid),
- .request_ready(request_ready),
- .request_type(ordinary_request_type),
- .request_length(ordinary_request_length),
- .request_payload(ordinary_payload),
- .request_crc16(16'h1234),
- .fast_jog_valid(fast_jog_valid),
- .fast_jog_axis(fast_jog_axis),
- .fast_jog_dir(fast_jog_dir),
- .fast_jog_steps(fast_jog_steps),
- .frame_valid(frame_valid),
- .frame_ready(frame_ready),
- .frame_type(frame_type),
- .frame_payload_len(frame_payload_len),
- .frame_payload(frame_payload),
- .ptc_percent(ptc_percent),
- .fan_percent(fan_percent),
- .solenoid_percent(solenoid_percent),
- .state_hash16(state_hash16),
- .step_out(step_out),
- .dir_out(dir_out),
- .en_n(en_n),
- .disabled(disabled),
- .watchdog_timeout(watchdog_timeout),
- .formal_state(dut_state)
- );
- prod2u_p4_fast_jog_axis_oracle #(
- .DIR_SETUP_CYCLES(FORMAL_DIR_SETUP_CYCLES),
- .STEP_HALF_CYCLES(FORMAL_STEP_HALF_CYCLES)
- ) x_oracle (
- .clk(clk),
- .rst_n(rst_n),
- .command_start(fast_jog_valid && (fast_jog_axis == 2'd0)),
- .command_dir(fast_jog_dir),
- .command_steps(fast_jog_steps),
- .step_out(x_spec_step),
- .dir_out(x_spec_dir),
- .started_pulse(x_spec_started),
- .active(x_spec_active),
- .steps_left(x_spec_steps_left)
- );
- prod2u_p4_fast_jog_axis_oracle #(
- .DIR_SETUP_CYCLES(FORMAL_DIR_SETUP_CYCLES),
- .STEP_HALF_CYCLES(FORMAL_STEP_HALF_CYCLES)
- ) y_oracle (
- .clk(clk),
- .rst_n(rst_n),
- .command_start(fast_jog_valid && (fast_jog_axis == 2'd1)),
- .command_dir(fast_jog_dir),
- .command_steps(fast_jog_steps),
- .step_out(y_spec_step),
- .dir_out(y_spec_dir),
- .started_pulse(y_spec_started),
- .active(y_spec_active),
- .steps_left(y_spec_steps_left)
- );
- always @(posedge clk) begin
- past_valid <= 1'b1;
- rst_n <= 1'b1;
- previous_step <= step_out;
- if (rst_n && fast_jog_valid) begin
- assume(fast_jog_axis <= 2'd1);
- // RAW_U16_TRUSTED_HOST_NO_CPLD_CAP: the host owns zero rejection.
- assume(fast_jog_steps != 16'd0);
- end
- if (!rst_n) begin
- saw_tx_blocked_fast <= 1'b0;
- blocked_fast_axis <= 1'b0;
- saw_nonidle_fast <= 1'b0;
- nonidle_fast_axis <= 1'b0;
- saw_ffff_fast <= 1'b0;
- x_two_active <= 1'b0;
- x_two_rises <= 2'd0;
- x_two_complete <= 1'b0;
- end else begin
- if (frame_valid && !frame_ready && fast_jog_valid) begin
- saw_tx_blocked_fast <= 1'b1;
- blocked_fast_axis <= fast_jog_axis[0];
- end
- if (fast_jog_valid && (dut_state != 3'd0)) begin
- saw_nonidle_fast <= 1'b1;
- nonidle_fast_axis <= fast_jog_axis[0];
- end
- if (fast_jog_valid && (fast_jog_steps == 16'hffff)) begin
- saw_ffff_fast <= 1'b1;
- end
- if (fast_jog_valid && (fast_jog_axis == 2'd0)) begin
- x_two_active <= (fast_jog_steps == 16'd2);
- x_two_rises <= 2'd0;
- x_two_complete <= 1'b0;
- end else if (x_two_active) begin
- if (step_out[0] && !previous_step[0]) begin
- x_two_rises <= x_two_rises + 1'b1;
- end
- if (!x_spec_active && (x_two_rises == 2'd2)) begin
- x_two_active <= 1'b0;
- x_two_complete <= 1'b1;
- end
- end
- end
- if (rst_n) begin
- assert(step_out[0] == x_spec_step);
- assert(dir_out[0] == x_spec_dir);
- assert(step_out[1] == y_spec_step);
- assert(dir_out[1] == y_spec_dir);
- assert(!step_out[2]);
- assert(!dir_out[2]);
- assert(!en_n);
- assert(!x_spec_started || x_spec_step);
- assert(!y_spec_started || y_spec_step);
- end
- cover(saw_tx_blocked_fast &&
- step_out[blocked_fast_axis] &&
- !previous_step[blocked_fast_axis]);
- cover(saw_nonidle_fast &&
- step_out[nonidle_fast_axis] &&
- !previous_step[nonidle_fast_axis]);
- cover(rst_n && step_out[0] && step_out[1]);
- cover(saw_ffff_fast && (step_out[0] || step_out[1]));
- cover(x_two_complete);
- end
- wire unused = request_ready ^ frame_type[0] ^ frame_payload_len[0] ^
- frame_payload[0] ^ ptc_percent[0] ^ fan_percent[0] ^
- solenoid_percent[0] ^ state_hash16[0] ^ disabled ^
- watchdog_timeout ^ x_spec_steps_left[0] ^ y_spec_steps_left[0] ^
- dut_state[0] ^ past_valid;
- endmodule
- // A complete CRC-correct JOG must use the RX fast exit even while an older
- // ordinary request is held. Axis, direction, speed, and steps remain symbolic;
- // the classifier intentionally has no assumption on the raw 16-bit steps.
- module prod2u_p4_fast_jog_rx_formal;
- (* gclk *) reg clk;
- reg rst_n = 1'b0;
- reg [6:0] stream_index = 7'd0;
- reg [15:0] harness_crc = 16'hffff;
- reg held_request_seen = 1'b0;
- reg fast_event_seen = 1'b0;
- reg fast_event_previous = 1'b0;
- reg [7:0] held_request_type = 8'd0;
- reg [5:0] held_request_length = 6'd0;
- reg [271:0] held_request_payload = 272'd0;
- reg [15:0] held_request_crc16 = 16'd0;
- (* anyconst *) reg [1:0] jog_axis;
- (* anyconst *) reg jog_dir;
- (* anyconst *) reg [1:0] jog_speed;
- (* anyconst *) reg [15:0] jog_steps;
- wire first_frame = (stream_index <= 7'd19);
- wire second_frame = (stream_index >= 7'd22) &&
- (stream_index <= 7'd45);
- wire drive_valid = rst_n && (first_frame || second_frame);
- wire [6:0] local_index = second_frame ?
- (stream_index - 7'd22) : stream_index;
- wire [6:0] crc_low_index = second_frame ? 7'd22 : 7'd18;
- wire [6:0] crc_high_index = second_frame ? 7'd23 : 7'd19;
- reg [7:0] drive_data;
- wire [15:0] harness_crc_next;
- wire rx_ready;
- wire request_valid;
- wire [7:0] request_type;
- wire [5:0] request_length;
- wire [271:0] request_payload;
- wire [15:0] request_crc16;
- wire fast_jog_valid;
- wire [1:0] fast_jog_axis;
- wire fast_jog_dir;
- wire [15:0] fast_jog_steps;
- wire [15:0] crc_error_count;
- wire [15:0] timeout_count;
- wire [15:0] format_error_count;
- binary921_crc16 u_harness_crc (
- .crc_in(harness_crc),
- .data(drive_data),
- .crc_out(harness_crc_next)
- );
- prod2u_p4_normal_v3_rx #(
- .CLK_HZ(1000),
- .INTER_BYTE_TIMEOUT_MS(2)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .rx_valid(drive_valid),
- .rx_ready(rx_ready),
- .rx_data(drive_data),
- .request_valid(request_valid),
- .request_ready(1'b0),
- .request_type(request_type),
- .request_length(request_length),
- .request_payload(request_payload),
- .request_crc16(request_crc16),
- .fast_jog_valid(fast_jog_valid),
- .fast_jog_axis(fast_jog_axis),
- .fast_jog_dir(fast_jog_dir),
- .fast_jog_steps(fast_jog_steps),
- .crc_error_count(crc_error_count),
- .timeout_count(timeout_count),
- .format_error_count(format_error_count)
- );
- always @* begin
- if (local_index == 7'd0) begin
- drive_data = 8'ha5;
- end else if (local_index == 7'd1) begin
- drive_data = 8'h5a;
- end else if (local_index == 7'd2) begin
- drive_data = 8'h02;
- end else if (local_index == 7'd3) begin
- drive_data = 8'h04;
- end else if (local_index == 7'd4) begin
- drive_data = second_frame ? 8'h11 : 8'h05;
- end else if (local_index >= 7'd5 && local_index <= 7'd12) begin
- drive_data = 8'd0;
- end else if (local_index == 7'd13) begin
- drive_data = second_frame ? 8'd8 : 8'd4;
- end else if (local_index < crc_low_index) begin
- if (!second_frame) begin
- case (local_index)
- 7'd14: drive_data = 8'h24;
- default: drive_data = 8'd0;
- endcase
- end else begin
- case (local_index)
- 7'd14: drive_data = 8'h35;
- 7'd15: drive_data = {6'd0, jog_axis};
- 7'd16: drive_data = {7'd0, jog_dir};
- 7'd17: drive_data = {6'd0, jog_speed};
- 7'd18: drive_data = jog_steps[7:0];
- 7'd19: drive_data = jog_steps[15:8];
- default: drive_data = 8'd0;
- endcase
- end
- end else if (local_index == crc_low_index) begin
- drive_data = harness_crc[7:0];
- end else begin
- drive_data = harness_crc[15:8];
- end
- end
- always @(posedge clk) begin
- assume(jog_axis <= 2'd1);
- rst_n <= 1'b1;
- fast_event_previous <= fast_jog_valid;
- if (!rst_n) begin
- stream_index <= 7'd0;
- harness_crc <= 16'hffff;
- held_request_seen <= 1'b0;
- fast_event_seen <= 1'b0;
- fast_event_previous <= 1'b0;
- held_request_type <= 8'd0;
- held_request_length <= 6'd0;
- held_request_payload <= 272'd0;
- held_request_crc16 <= 16'd0;
- end else begin
- assert(rx_ready);
- assert(crc_error_count == 16'd0);
- assert(timeout_count == 16'd0);
- assert(format_error_count == 16'd0);
- if (stream_index < 7'd50) begin
- stream_index <= stream_index + 1'b1;
- end
- if (drive_valid && (local_index >= 7'd2) &&
- (local_index < crc_low_index)) begin
- harness_crc <= harness_crc_next;
- end else if (drive_valid && (local_index == crc_high_index)) begin
- harness_crc <= 16'hffff;
- end
- if (request_valid && !held_request_seen) begin
- held_request_seen <= 1'b1;
- held_request_type <= request_type;
- held_request_length <= request_length;
- held_request_payload <= request_payload;
- held_request_crc16 <= request_crc16;
- assert(request_type == 8'h05);
- assert(request_length == 6'd4);
- assert(request_payload == {240'd0, 32'h00000024});
- end
- if (held_request_seen) begin
- assert(request_valid);
- assert(request_type == held_request_type);
- assert(request_length == held_request_length);
- assert(request_payload == held_request_payload);
- assert(request_crc16 == held_request_crc16);
- end
- if (fast_jog_valid) begin
- assert(!fast_event_previous);
- assert(!fast_event_seen);
- assert(held_request_seen);
- assert(fast_jog_axis == jog_axis);
- assert(fast_jog_dir == jog_dir);
- assert(fast_jog_steps == jog_steps);
- fast_event_seen <= 1'b1;
- end
- if (stream_index >= 7'd48) begin
- assert(held_request_seen);
- assert(fast_event_seen);
- end
- end
- cover(fast_event_seen && held_request_seen);
- end
- endmodule
- // The small-parameter proof above supplies the independent countdown oracle.
- // This production instance proves the exact reload constants and every local
- // transition, which establishes 25,000 setup clocks and 12,500 clocks for each
- // STEP level without unrolling those full intervals.
- module prod2u_p4_fast_jog_production_timing_formal;
- localparam integer PRODUCTION_DIR_SETUP_CYCLES = 25000;
- localparam integer PRODUCTION_STEP_HALF_CYCLES = 12500;
- (* gclk *) reg clk;
- reg rst_n = 1'b0;
- (* anyseq *) reg fast_jog_valid;
- (* anyseq *) reg fast_jog_dir;
- (* anyseq *) reg [15:0] fast_jog_steps;
- reg past_valid = 1'b0;
- wire dut_step;
- wire dut_dir;
- wire dut_started;
- wire [1:0] dut_motion_phase;
- wire [31:0] dut_phase_counter;
- wire [15:0] dut_remaining_steps;
- prod2u_p4_axis_executor #(
- .DIR_SETUP_CYCLES(PRODUCTION_DIR_SETUP_CYCLES),
- .STEP_HALF_CYCLES(PRODUCTION_STEP_HALF_CYCLES)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .command_start(fast_jog_valid),
- .command_dir(fast_jog_dir),
- .command_steps(fast_jog_steps),
- .step_out(dut_step),
- .dir_out(dut_dir),
- .started_pulse(dut_started),
- .formal_motion_phase(dut_motion_phase),
- .formal_phase_counter(dut_phase_counter),
- .formal_remaining_steps(dut_remaining_steps)
- );
- always @(posedge clk) begin
- past_valid <= 1'b1;
- rst_n <= 1'b1;
- if (rst_n && fast_jog_valid) begin
- assume(fast_jog_steps != 16'd0);
- end
- if (!rst_n) begin
- assert(!dut_step);
- assert(!dut_started);
- end
- if (past_valid && $past(rst_n)) begin
- if ($past(fast_jog_valid)) begin
- assert(dut_motion_phase == 2'd1);
- assert(dut_phase_counter == 32'd24999);
- assert(dut_remaining_steps == $past(fast_jog_steps));
- assert(dut_dir == $past(fast_jog_dir));
- assert(!dut_step);
- assert(!dut_started);
- end else begin
- case ($past(dut_motion_phase))
- 2'd0: begin
- assert(dut_motion_phase == 2'd0);
- assert(dut_phase_counter == 32'd0);
- assert(dut_remaining_steps == 16'd0);
- assert(!dut_step);
- assert(!dut_started);
- end
- 2'd1: begin
- if ($past(dut_phase_counter) != 32'd0) begin
- assert(dut_motion_phase == 2'd1);
- assert(dut_phase_counter ==
- $past(dut_phase_counter) - 1'b1);
- assert(!dut_step);
- assert(!dut_started);
- end else begin
- assert(dut_motion_phase == 2'd2);
- assert(dut_phase_counter == 32'd12499);
- assert(dut_step);
- assert(dut_started);
- end
- assert(dut_remaining_steps ==
- $past(dut_remaining_steps));
- assert(dut_dir == $past(dut_dir));
- end
- 2'd2: begin
- if ($past(dut_phase_counter) != 32'd0) begin
- assert(dut_motion_phase == 2'd2);
- assert(dut_phase_counter ==
- $past(dut_phase_counter) - 1'b1);
- assert(dut_step);
- end else begin
- assert(dut_motion_phase == 2'd3);
- assert(dut_phase_counter == 32'd12499);
- assert(!dut_step);
- end
- assert(dut_remaining_steps ==
- $past(dut_remaining_steps));
- assert(dut_dir == $past(dut_dir));
- assert(!dut_started);
- end
- 2'd3: begin
- if ($past(dut_phase_counter) != 32'd0) begin
- assert(dut_motion_phase == 2'd3);
- assert(dut_phase_counter ==
- $past(dut_phase_counter) - 1'b1);
- assert(dut_remaining_steps ==
- $past(dut_remaining_steps));
- assert(!dut_step);
- end else if ($past(dut_remaining_steps) == 16'd1) begin
- assert(dut_motion_phase == 2'd0);
- assert(dut_phase_counter == 32'd0);
- assert(dut_remaining_steps == 16'd0);
- assert(!dut_step);
- end else begin
- assert(dut_motion_phase == 2'd2);
- assert(dut_phase_counter == 32'd12499);
- assert(dut_remaining_steps ==
- $past(dut_remaining_steps) - 1'b1);
- assert(dut_step);
- end
- assert(dut_dir == $past(dut_dir));
- assert(!dut_started);
- end
- endcase
- end
- assert(!dut_started || dut_step);
- end
- cover(rst_n && fast_jog_valid && (fast_jog_steps == 16'hffff));
- end
- endmodule
- `default_nettype wire
|