| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- `timescale 1ns/1ps
- // 3-axis dispatcher: byte8=Z, byte9=X, byte10=Y; 00/01/02; busy ignores new start.
- module door_action_dispatcher_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg door_action_valid = 1'b0;
- reg [1:0] z_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),
- .z_door_cmd(z_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] z_cmd;
- input [1:0] x_cmd;
- input [1:0] y_cmd;
- begin
- @(negedge clk);
- z_door_cmd = z_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;
- pulse_action(2'd1, 2'd1, 2'd1);
- if (!motor_start) $fatal(1, "open all: missing motor_start");
- if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b000)
- $fatal(1, "open all mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- pulse_action(2'd2, 2'd2, 2'd2);
- if (!motor_start) $fatal(1, "close all: missing motor_start");
- if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b111)
- $fatal(1, "close all mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- pulse_action(2'd1, 2'd2, 2'd1);
- if (motor_active_mask !== 3'b111 || motor_dir_mask !== 3'b001)
- $fatal(1, "mixed open/close mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- pulse_action(2'd0, 2'd0, 2'd0);
- if (motor_start) $fatal(1, "idle 00/00 must not start when not busy");
- // Z-only open: bit2 active, DIR=0.
- pulse_action(2'd1, 2'd0, 2'd0);
- if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
- $fatal(1, "Z open mask/dir mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- // Busy ignores new command (mask/dir unchanged).
- motor_busy = 1'b1;
- pulse_action(2'd2, 2'd0, 2'd0);
- if (motor_start) $fatal(1, "busy must not re-pulse motor_start");
- if (motor_active_mask !== 3'b100 || motor_dir_mask !== 3'b000)
- $fatal(1, "busy must ignore new command mask=%b dir=%b", motor_active_mask, motor_dir_mask);
- watchdog_abort = 1'b1;
- @(posedge clk);
- @(negedge clk);
- if (motor_active_mask !== 3'b000) $fatal(1, "watchdog abort must clear active_mask");
- $display("door_action_dispatcher_tb PASS");
- $finish;
- end
- endmodule
|