| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- `timescale 1ns/1ps
- module prod2u_p4_normal_v3_watchdog_contract_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg arm = 1'b0;
- reg refresh = 1'b0;
- reg disable_cmd = 1'b0;
- wire disabled;
- wire armed;
- wire watchdog_timeout;
- wire expiry_due;
- wire force_safe;
- always #5 clk = ~clk;
- prod2u_p4_normal_v3_watchdog #(
- .CLK_HZ(10),
- .WATCHDOG_SECONDS(1)
- ) dut (
- .clk(clk),
- .rst_n(rst_n),
- .arm(arm),
- .refresh(refresh),
- .disable_cmd(disable_cmd),
- .disabled(disabled),
- .armed(armed),
- .watchdog_timeout(watchdog_timeout),
- .expiry_due(expiry_due),
- .force_safe(force_safe)
- );
- task pulse_arm;
- begin
- @(negedge clk); arm = 1'b1;
- @(negedge clk); arm = 1'b0;
- end
- endtask
- integer i;
- initial begin
- repeat (2) @(negedge clk);
- rst_n = 1'b1;
- @(negedge clk);
- if (!disabled || armed || watchdog_timeout) $fatal(1, "reset contract");
- // Refresh is side-effect free while disabled and cannot arm a lease.
- refresh = 1'b1;
- @(negedge clk);
- refresh = 1'b0;
- if (!disabled || armed || watchdog_timeout) $fatal(1, "refresh armed disabled watchdog");
- pulse_arm();
- if (disabled || !armed || watchdog_timeout) $fatal(1, "arm contract");
- // Arm clears the elapsed counter. The first eight complete clocks are
- // ordinary lease time. At clock nine expiry_due must hard-stop pins in
- // the same combinational cycle, before timeout/disabled are registered.
- for (i = 1; i < 9; i = i + 1) begin
- @(posedge clk);
- #1;
- if (expiry_due || watchdog_timeout || force_safe || disabled || !armed)
- $fatal(1, "watchdog expired early at elapsed clock %0d", i);
- end
- @(posedge clk);
- #1;
- if (!expiry_due || watchdog_timeout || !force_safe || disabled || !armed)
- $fatal(1, "expiry arbitration boundary mismatch");
- @(negedge clk);
- refresh = 1'b1;
- @(posedge clk);
- #1;
- if (!watchdog_timeout || !force_safe)
- $fatal(1, "expiry boundary not exposed after full lease");
- @(negedge clk);
- refresh = 1'b0;
- if (!disabled || armed || !watchdog_timeout || !force_safe)
- $fatal(1, "expiry did not win over refresh");
- // A legal actuation arm is the recovery action after timeout.
- pulse_arm();
- if (disabled || !armed || watchdog_timeout || force_safe)
- $fatal(1, "arm did not recover timed-out watchdog");
- // DISABLE remains the highest-priority input when arm is asserted in
- // the same cycle. It must leave the watchdog disabled and unarmed.
- @(negedge clk);
- arm = 1'b1;
- disable_cmd = 1'b1;
- @(posedge clk);
- #1;
- if (!disabled || armed || watchdog_timeout || !force_safe)
- $fatal(1, "disable did not win over simultaneous arm");
- @(negedge clk);
- arm = 1'b0;
- disable_cmd = 1'b0;
- #1;
- if (!disabled || armed || watchdog_timeout || force_safe) begin
- $display("DISABLE_PERSIST disabled=%0d armed=%0d timeout=%0d due=%0d safe=%0d",
- disabled, armed, watchdog_timeout, expiry_due, force_safe);
- $fatal(1, "disable priority state did not persist");
- end
- pulse_arm();
- if (disabled || !armed || watchdog_timeout) $fatal(1, "post-disable arm failed");
- $display("PASS: prod2u_p4_normal_v3_watchdog_contract_tb");
- $finish;
- end
- endmodule
|