| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- `timescale 1ns/1ps
- // AXIS_COUNT=3: intake on bit2, exhaust X/Y on bits 0/1. Byte8 semantics via
- // intake_door_cmd: 00 stop, 01 DIR=0, 02 DIR=1; latest wins.
- module door_action_dispatcher_axis3_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg door_action_valid = 1'b0;
- reg [1:0] intake_door_cmd = 2'd0;
- reg [1:0] exhaust_x_cmd = 2'd0;
- reg [1:0] exhaust_y_cmd = 2'd0;
- reg watchdog_abort = 1'b0;
- reg motor_busy = 1'b0;
- wire motor_start;
- wire [2:0] motor_active_mask;
- wire [2:0] motor_dir_mask;
- always #1 clk = ~clk;
- door_action_dispatcher #(.OPEN_DIR(0), .CLOSE_DIR(1), .AXIS_COUNT(3)) dut (
- .clk(clk), .rst_n(rst_n),
- .door_action_valid(door_action_valid),
- .intake_door_cmd(intake_door_cmd),
- .exhaust_x_cmd(exhaust_x_cmd),
- .exhaust_y_cmd(exhaust_y_cmd),
- .watchdog_abort(watchdog_abort),
- .motor_start(motor_start),
- .motor_active_mask(motor_active_mask),
- .motor_dir_mask(motor_dir_mask),
- .motor_busy(motor_busy)
- );
- task pulse_action;
- input [1:0] intake_cmd;
- input [1:0] x_cmd;
- input [1:0] y_cmd;
- begin
- @(negedge clk);
- intake_door_cmd = intake_cmd;
- exhaust_x_cmd = x_cmd;
- exhaust_y_cmd = y_cmd;
- door_action_valid = 1'b1;
- @(posedge clk);
- @(negedge clk);
- door_action_valid = 1'b0;
- end
- endtask
- initial begin
- repeat (3) @(posedge clk);
- rst_n = 1'b1;
- // Intake open only -> bit2 active, DIR=0.
- pulse_action(2'd1, 2'd0, 2'd0);
- if (!motor_start) $fatal(1, "intake open missing motor_start");
- if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
- $fatal(1, "intake open mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- // Intake close.
- pulse_action(2'd2, 2'd0, 2'd0);
- if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b100)
- $fatal(1, "intake close mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- // All three axes mixed.
- pulse_action(2'd1, 2'd2, 2'd1);
- if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b001)
- $fatal(1, "mixed 3-axis mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- // Latest-wins stop while busy.
- motor_busy = 1'b1;
- pulse_action(2'd0, 2'd0, 2'd0);
- if (!motor_start) $fatal(1, "busy stop missing motor_start");
- if (motor_active_mask !== 3'b000)
- $fatal(1, "busy stop active_mask=%b", motor_active_mask);
- $display("door_action_dispatcher_axis3_tb PASS");
- $finish;
- end
- endmodule
|