|
@@ -29,6 +29,8 @@ module project_adapter_tb;
|
|
|
integer motor_starts;
|
|
integer motor_starts;
|
|
|
integer tx_starts;
|
|
integer tx_starts;
|
|
|
integer i;
|
|
integer i;
|
|
|
|
|
+ reg [7:0] written_targets [0:11];
|
|
|
|
|
+ reg [11:0] written_seen;
|
|
|
|
|
|
|
|
always #1 clk = ~clk;
|
|
always #1 clk = ~clk;
|
|
|
|
|
|
|
@@ -47,7 +49,13 @@ module project_adapter_tb;
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
always @(posedge clk) begin
|
|
|
- if (target_wr_en) target_writes = target_writes + 1;
|
|
|
|
|
|
|
+ if (target_wr_en) begin
|
|
|
|
|
+ target_writes = target_writes + 1;
|
|
|
|
|
+ if (target_wr_addr < 12) begin
|
|
|
|
|
+ written_targets[target_wr_addr] = target_wr_data;
|
|
|
|
|
+ written_seen[target_wr_addr] = 1'b1;
|
|
|
|
|
+ end
|
|
|
|
|
+ end
|
|
|
if (motor_start) motor_starts = motor_starts + 1;
|
|
if (motor_start) motor_starts = motor_starts + 1;
|
|
|
if (tx_start) tx_starts = tx_starts + 1;
|
|
if (tx_start) tx_starts = tx_starts + 1;
|
|
|
end
|
|
end
|
|
@@ -70,21 +78,60 @@ module project_adapter_tb;
|
|
|
end
|
|
end
|
|
|
endtask
|
|
endtask
|
|
|
|
|
|
|
|
|
|
+ task clear_write_scoreboard;
|
|
|
|
|
+ begin
|
|
|
|
|
+ target_writes = 0;
|
|
|
|
|
+ written_seen = 12'd0;
|
|
|
|
|
+ for (i = 0; i < 12; i = i + 1) written_targets[i] = 8'hxx;
|
|
|
|
|
+ end
|
|
|
|
|
+ endtask
|
|
|
|
|
+
|
|
|
|
|
+ task load_payload;
|
|
|
|
|
+ input [7:0] f0; input [7:0] f1; input [7:0] f2; input [7:0] f3;
|
|
|
|
|
+ input [7:0] p0; input [7:0] p1; input [7:0] p2; input [7:0] p3;
|
|
|
|
|
+ input [7:0] intake; input [7:0] x_cmd; input [7:0] y_cmd;
|
|
|
|
|
+ begin
|
|
|
|
|
+ payload_memory[0] = f0;
|
|
|
|
|
+ payload_memory[1] = f1;
|
|
|
|
|
+ payload_memory[2] = f2;
|
|
|
|
|
+ payload_memory[3] = f3;
|
|
|
|
|
+ payload_memory[4] = p0;
|
|
|
|
|
+ payload_memory[5] = p1;
|
|
|
|
|
+ payload_memory[6] = p2;
|
|
|
|
|
+ payload_memory[7] = p3;
|
|
|
|
|
+ payload_memory[8] = intake;
|
|
|
|
|
+ payload_memory[9] = x_cmd;
|
|
|
|
|
+ payload_memory[10] = y_cmd;
|
|
|
|
|
+ end
|
|
|
|
|
+ endtask
|
|
|
|
|
+
|
|
|
|
|
+ task check_ptc_duplicate_and_fan;
|
|
|
|
|
+ begin
|
|
|
|
|
+ if (written_seen !== 12'hFFF)
|
|
|
|
|
+ $fatal(1, "SET_ALL did not write all 12 target slots seen=%b", written_seen);
|
|
|
|
|
+ // Chamber PTC i duplicates to physical PTC 2*i and 2*i+1.
|
|
|
|
|
+ if (written_targets[0] !== payload_memory[4] || written_targets[1] !== payload_memory[4])
|
|
|
|
|
+ $fatal(1, "chamber0 PTC duplicate mismatch %0d/%0d vs %0d",
|
|
|
|
|
+ written_targets[0], written_targets[1], payload_memory[4]);
|
|
|
|
|
+ if (written_targets[2] !== payload_memory[5] || written_targets[3] !== payload_memory[5])
|
|
|
|
|
+ $fatal(1, "chamber1 PTC duplicate mismatch");
|
|
|
|
|
+ if (written_targets[4] !== payload_memory[6] || written_targets[5] !== payload_memory[6])
|
|
|
|
|
+ $fatal(1, "chamber2 PTC duplicate mismatch");
|
|
|
|
|
+ if (written_targets[6] !== payload_memory[7] || written_targets[7] !== payload_memory[7])
|
|
|
|
|
+ $fatal(1, "chamber3 PTC duplicate mismatch");
|
|
|
|
|
+ // FAN 4 channels map to target addresses 8..11.
|
|
|
|
|
+ if (written_targets[8] !== payload_memory[0] || written_targets[9] !== payload_memory[1] ||
|
|
|
|
|
+ written_targets[10] !== payload_memory[2] || written_targets[11] !== payload_memory[3])
|
|
|
|
|
+ $fatal(1, "FAN target mapping mismatch");
|
|
|
|
|
+ end
|
|
|
|
|
+ endtask
|
|
|
|
|
+
|
|
|
initial begin
|
|
initial begin
|
|
|
- payload_memory[0] = 10;
|
|
|
|
|
- payload_memory[1] = 20;
|
|
|
|
|
- payload_memory[2] = 30;
|
|
|
|
|
- payload_memory[3] = 40;
|
|
|
|
|
- payload_memory[4] = 11;
|
|
|
|
|
- payload_memory[5] = 22;
|
|
|
|
|
- payload_memory[6] = 33;
|
|
|
|
|
- payload_memory[7] = 44;
|
|
|
|
|
- payload_memory[8] = 1;
|
|
|
|
|
- payload_memory[9] = 2;
|
|
|
|
|
- payload_memory[10] = 0;
|
|
|
|
|
- target_writes = 0;
|
|
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
motor_starts = 0;
|
|
motor_starts = 0;
|
|
|
tx_starts = 0;
|
|
tx_starts = 0;
|
|
|
|
|
+ // Mixed golden-style payload: fans, chamber PTC, intake open, X close, Y hold.
|
|
|
|
|
+ load_payload(10, 20, 30, 40, 11, 22, 33, 44, 1, 2, 0);
|
|
|
repeat (3) @(posedge clk);
|
|
repeat (3) @(posedge clk);
|
|
|
rst_n = 1'b1;
|
|
rst_n = 1'b1;
|
|
|
submit_frame(8'h01, 11);
|
|
submit_frame(8'h01, 11);
|
|
@@ -92,33 +139,77 @@ module project_adapter_tb;
|
|
|
wait (motor_start);
|
|
wait (motor_start);
|
|
|
@(negedge clk);
|
|
@(negedge clk);
|
|
|
if (target_writes !== 12) $fatal(1, "valid SET_ALL target write count=%0d", target_writes);
|
|
if (target_writes !== 12) $fatal(1, "valid SET_ALL target write count=%0d", target_writes);
|
|
|
- // bit0=X, bit1=Y; payload exhaust_x=2 (close), exhaust_y=0
|
|
|
|
|
|
|
+ check_ptc_duplicate_and_fan();
|
|
|
|
|
+ // bit0=X, bit1=Y; exhaust_x=2 close -> DIR=1, exhaust_y=0 hold
|
|
|
if (motor_active_mask !== 2'b01 || motor_dir_mask !== 2'b01) begin
|
|
if (motor_active_mask !== 2'b01 || motor_dir_mask !== 2'b01) begin
|
|
|
- $fatal(1, "valid SET_ALL motor contract failed mask=%b dir=%b", motor_active_mask, motor_dir_mask);
|
|
|
|
|
|
|
+ $fatal(1, "close DIR contract failed mask=%b dir=%b", motor_active_mask, motor_dir_mask);
|
|
|
end
|
|
end
|
|
|
if (intake_solenoid_out !== 1'b1) $fatal(1, "intake solenoid open expected");
|
|
if (intake_solenoid_out !== 1'b1) $fatal(1, "intake solenoid open expected");
|
|
|
|
|
|
|
|
|
|
+ // Open DIR semantics: 01 -> DIR=0 on both axes, overlapping start.
|
|
|
|
|
+ wait (!busy);
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
|
|
+ motor_starts = 0;
|
|
|
|
|
+ load_payload(1, 2, 3, 4, 5, 6, 7, 8, 2, 1, 1);
|
|
|
|
|
+ submit_frame(8'h01, 11);
|
|
|
|
|
+ wait (motor_start);
|
|
|
|
|
+ @(negedge clk);
|
|
|
|
|
+ check_ptc_duplicate_and_fan();
|
|
|
|
|
+ if (motor_active_mask !== 2'b11 || motor_dir_mask !== 2'b00)
|
|
|
|
|
+ $fatal(1, "open DIR contract failed mask=%b dir=%b", motor_active_mask, motor_dir_mask);
|
|
|
|
|
+ if (intake_solenoid_out !== 1'b0) $fatal(1, "intake solenoid closed expected");
|
|
|
|
|
+
|
|
|
|
|
+ // Override while busy: new close on X only must re-pulse motor_start with new DIR.
|
|
|
|
|
+ motor_busy = 1'b1;
|
|
|
|
|
+ wait (!busy);
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
|
|
+ motor_starts = 0;
|
|
|
|
|
+ load_payload(0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0);
|
|
|
|
|
+ submit_frame(8'h01, 11);
|
|
|
|
|
+ wait (motor_start);
|
|
|
|
|
+ @(negedge clk);
|
|
|
|
|
+ if (motor_starts !== 1)
|
|
|
|
|
+ $fatal(1, "busy override did not re-assert motor_start starts=%0d", motor_starts);
|
|
|
|
|
+ if (motor_active_mask !== 2'b01 || motor_dir_mask !== 2'b01)
|
|
|
|
|
+ $fatal(1, "busy override DIR/mask mismatch mask=%b dir=%b", motor_active_mask, motor_dir_mask);
|
|
|
|
|
+ motor_busy = 1'b0;
|
|
|
|
|
+
|
|
|
|
|
+ // Stop override (00/00) while busy must start with active_mask=0.
|
|
|
|
|
+ wait (!busy);
|
|
|
|
|
+ motor_busy = 1'b1;
|
|
|
|
|
+ motor_starts = 0;
|
|
|
|
|
+ load_payload(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
|
+ submit_frame(8'h01, 11);
|
|
|
|
|
+ wait (motor_start);
|
|
|
|
|
+ @(negedge clk);
|
|
|
|
|
+ if (motor_active_mask !== 2'b00)
|
|
|
|
|
+ $fatal(1, "stop override expected active_mask=0 got %b", motor_active_mask);
|
|
|
|
|
+ motor_busy = 1'b0;
|
|
|
|
|
+
|
|
|
wait (!busy);
|
|
wait (!busy);
|
|
|
- target_writes = 0;
|
|
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
submit_frame(8'h01, 11);
|
|
submit_frame(8'h01, 11);
|
|
|
- // Second pulse while first SET_ALL is still busy must be ignored.
|
|
|
|
|
|
|
+ // Second pulse while first SET_ALL is still busy must be ignored (atomicity / no queue).
|
|
|
submit_frame(8'h01, 11);
|
|
submit_frame(8'h01, 11);
|
|
|
wait (!busy);
|
|
wait (!busy);
|
|
|
if (target_writes !== 12) $fatal(1, "busy frame was not silently dropped (writes=%0d)", target_writes);
|
|
if (target_writes !== 12) $fatal(1, "busy frame was not silently dropped (writes=%0d)", target_writes);
|
|
|
|
|
|
|
|
- target_writes = 0;
|
|
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
payload_memory[0] = 101;
|
|
payload_memory[0] = 101;
|
|
|
submit_frame(8'h01, 11);
|
|
submit_frame(8'h01, 11);
|
|
|
wait (!busy);
|
|
wait (!busy);
|
|
|
@(negedge clk);
|
|
@(negedge clk);
|
|
|
if (target_writes !== 0 || valid_set_all_commit) $fatal(1, "invalid duty caused an action");
|
|
if (target_writes !== 0 || valid_set_all_commit) $fatal(1, "invalid duty caused an action");
|
|
|
|
|
|
|
|
|
|
+ // Invalid late door byte must not partially apply earlier validated fan/PTC values.
|
|
|
payload_memory[0] = 10;
|
|
payload_memory[0] = 10;
|
|
|
payload_memory[9] = 3;
|
|
payload_memory[9] = 3;
|
|
|
|
|
+ clear_write_scoreboard();
|
|
|
submit_frame(8'h01, 11);
|
|
submit_frame(8'h01, 11);
|
|
|
wait (!busy);
|
|
wait (!busy);
|
|
|
@(negedge clk);
|
|
@(negedge clk);
|
|
|
- if (target_writes !== 0 || valid_set_all_commit) $fatal(1, "invalid door command caused an action");
|
|
|
|
|
|
|
+ if (target_writes !== 0 || valid_set_all_commit)
|
|
|
|
|
+ $fatal(1, "invalid door broke SET_ALL atomicity writes=%0d", target_writes);
|
|
|
|
|
|
|
|
payload_memory[9] = 2;
|
|
payload_memory[9] = 2;
|
|
|
submit_frame(8'h01, 14);
|
|
submit_frame(8'h01, 14);
|