| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- `timescale 1ns/1ps
- module motor_limit_domain_tb;
- reg clk;
- reg rst_n;
- reg global_enable;
- reg fault_latched;
- reg [3:0] fault_code;
- reg motor_open_req;
- reg motor_close_req;
- reg button_open_req;
- reg button_close_req;
- reg limit_open;
- reg limit_close;
- reg interlock;
- wire motor_enable;
- wire [1:0] motor_dir;
- wire motor_force_off;
- wire [3:0] motor_reason;
- wire [1:0] motor_state;
- wire [1:0] limit_status;
- wire [1:0] button_status;
- motor_limit_domain dut (
- .clk(clk),
- .rst_n(rst_n),
- .global_enable(global_enable),
- .fault_latched(fault_latched),
- .fault_code(fault_code),
- .motor_open_req(motor_open_req),
- .motor_close_req(motor_close_req),
- .button_open_req(button_open_req),
- .button_close_req(button_close_req),
- .limit_open(limit_open),
- .limit_close(limit_close),
- .interlock(interlock),
- .motor_enable(motor_enable),
- .motor_dir(motor_dir),
- .motor_force_off(motor_force_off),
- .motor_reason(motor_reason),
- .motor_state(motor_state),
- .limit_status(limit_status),
- .button_status(button_status)
- );
- initial begin
- clk = 1'b0;
- forever #5 clk = ~clk;
- end
- initial begin
- rst_n = 1'b0;
- global_enable = 1'b1;
- fault_latched = 1'b0;
- fault_code = 4'd0;
- motor_open_req = 1'b0;
- motor_close_req = 1'b0;
- button_open_req = 1'b0;
- button_close_req = 1'b0;
- limit_open = 1'b0;
- limit_close = 1'b0;
- interlock = 1'b0;
- repeat (4) @(negedge clk);
- rst_n = 1'b1;
- button_open_req = 1'b1;
- @(negedge clk);
- if (!motor_enable || motor_dir !== 2'd1 || motor_state !== 2'd1 || button_status !== 2'd1) begin
- $display("motor limit domain should accept button open request");
- $fatal;
- end
- limit_open = 1'b1;
- @(negedge clk);
- if (motor_enable || motor_state !== 2'd0 || limit_status !== 2'd1) begin
- $display("motor limit domain should stop at open limit");
- $fatal;
- end
- interlock = 1'b1;
- @(negedge clk);
- if (!motor_force_off || motor_reason !== 4'd7) begin
- $display("motor limit domain should force off on interlock");
- $fatal;
- end
- $display("PASS: motor_limit_domain_tb");
- $finish;
- end
- endmodule
|