prod2u_p4_normal_v3_watchdog_contract_tb.v 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. `timescale 1ns/1ps
  2. module prod2u_p4_normal_v3_watchdog_contract_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg arm = 1'b0;
  6. reg refresh = 1'b0;
  7. reg disable_cmd = 1'b0;
  8. wire disabled;
  9. wire armed;
  10. wire watchdog_timeout;
  11. wire expiry_due;
  12. wire force_safe;
  13. always #5 clk = ~clk;
  14. prod2u_p4_normal_v3_watchdog #(
  15. .CLK_HZ(10),
  16. .WATCHDOG_SECONDS(1)
  17. ) dut (
  18. .clk(clk),
  19. .rst_n(rst_n),
  20. .arm(arm),
  21. .refresh(refresh),
  22. .disable_cmd(disable_cmd),
  23. .disabled(disabled),
  24. .armed(armed),
  25. .watchdog_timeout(watchdog_timeout),
  26. .expiry_due(expiry_due),
  27. .force_safe(force_safe)
  28. );
  29. task pulse_arm;
  30. begin
  31. @(negedge clk); arm = 1'b1;
  32. @(negedge clk); arm = 1'b0;
  33. end
  34. endtask
  35. integer i;
  36. initial begin
  37. repeat (2) @(negedge clk);
  38. rst_n = 1'b1;
  39. @(negedge clk);
  40. if (!disabled || armed || watchdog_timeout) $fatal(1, "reset contract");
  41. // Refresh is side-effect free while disabled and cannot arm a lease.
  42. refresh = 1'b1;
  43. @(negedge clk);
  44. refresh = 1'b0;
  45. if (!disabled || armed || watchdog_timeout) $fatal(1, "refresh armed disabled watchdog");
  46. pulse_arm();
  47. if (disabled || !armed || watchdog_timeout) $fatal(1, "arm contract");
  48. // Arm clears the elapsed counter. The first eight complete clocks are
  49. // ordinary lease time. At clock nine expiry_due must hard-stop pins in
  50. // the same combinational cycle, before timeout/disabled are registered.
  51. for (i = 1; i < 9; i = i + 1) begin
  52. @(posedge clk);
  53. #1;
  54. if (expiry_due || watchdog_timeout || force_safe || disabled || !armed)
  55. $fatal(1, "watchdog expired early at elapsed clock %0d", i);
  56. end
  57. @(posedge clk);
  58. #1;
  59. if (!expiry_due || watchdog_timeout || !force_safe || disabled || !armed)
  60. $fatal(1, "expiry arbitration boundary mismatch");
  61. @(negedge clk);
  62. refresh = 1'b1;
  63. @(posedge clk);
  64. #1;
  65. if (!watchdog_timeout || force_safe || !disabled || armed)
  66. $fatal(1, "expiry boundary not exposed after full lease");
  67. @(negedge clk);
  68. refresh = 1'b0;
  69. if (!disabled || armed || !watchdog_timeout || force_safe)
  70. $fatal(1, "expiry did not win over refresh");
  71. // A legal actuation arm is the recovery action after timeout.
  72. pulse_arm();
  73. if (disabled || !armed || watchdog_timeout || force_safe)
  74. $fatal(1, "arm did not recover timed-out watchdog");
  75. // DISABLE remains the highest-priority input when arm is asserted in
  76. // the same cycle. It must leave the watchdog disabled and unarmed.
  77. @(negedge clk);
  78. arm = 1'b1;
  79. disable_cmd = 1'b1;
  80. @(posedge clk);
  81. #1;
  82. if (!disabled || armed || watchdog_timeout || !force_safe)
  83. $fatal(1, "disable did not win over simultaneous arm");
  84. @(negedge clk);
  85. arm = 1'b0;
  86. disable_cmd = 1'b0;
  87. #1;
  88. if (!disabled || armed || watchdog_timeout || force_safe) begin
  89. $display("DISABLE_PERSIST disabled=%0d armed=%0d timeout=%0d due=%0d safe=%0d",
  90. disabled, armed, watchdog_timeout, expiry_due, force_safe);
  91. $fatal(1, "disable priority state did not persist");
  92. end
  93. pulse_arm();
  94. if (disabled || !armed || watchdog_timeout) $fatal(1, "post-disable arm failed");
  95. $display("PASS: prod2u_p4_normal_v3_watchdog_contract_tb");
  96. $finish;
  97. end
  98. endmodule