host_watchdog_tb.v 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. `timescale 1ns/1ps
  2. module host_watchdog_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg enable = 1'b0;
  6. reg tick_500us = 1'b0;
  7. reg valid_set_all_commit = 1'b0;
  8. wire watchdog_active;
  9. wire timeout_event;
  10. always #1 clk = ~clk;
  11. initial begin
  12. #100000;
  13. $fatal(1, "watchdog production-boundary timeout count=%0d active=%b event=%b",
  14. dut.tick_count, watchdog_active, timeout_event);
  15. end
  16. // Boundary sim with compact timeout; production 60000 covered by params/unit.
  17. host_watchdog #(.TIMEOUT_TICKS(20000)) dut (
  18. .clk(clk), .rst_n(rst_n), .enable(enable), .tick_500us(tick_500us),
  19. .valid_set_all_commit(valid_set_all_commit), .watchdog_active(watchdog_active),
  20. .timeout_event(timeout_event)
  21. );
  22. task pulse_tick;
  23. begin
  24. @(negedge clk);
  25. tick_500us = 1'b1;
  26. @(negedge clk);
  27. tick_500us = 1'b0;
  28. end
  29. endtask
  30. initial begin
  31. repeat (2) @(posedge clk);
  32. if (dut.tick_count !== 0 || watchdog_active || timeout_event)
  33. $fatal(1, "watchdog reset state is not idle");
  34. rst_n = 1'b1;
  35. // Disabled: ticks must not advance or trip
  36. repeat (8) pulse_tick();
  37. if (dut.tick_count !== 0 || watchdog_active)
  38. $fatal(1, "disabled watchdog advanced");
  39. @(negedge clk);
  40. enable = 1'b1;
  41. repeat (19999) pulse_tick();
  42. if (dut.tick_count !== 19999 || watchdog_active || timeout_event)
  43. $fatal(1, "watchdog pre-timeout boundary mismatch count=%0d", dut.tick_count);
  44. pulse_tick();
  45. if (!timeout_event || !watchdog_active) $fatal(1, "watchdog did not expire at timeout");
  46. @(posedge clk);
  47. @(negedge clk);
  48. if (timeout_event) $fatal(1, "watchdog timeout event was not one cycle");
  49. @(negedge clk);
  50. valid_set_all_commit = 1'b1;
  51. tick_500us = 1'b1;
  52. @(negedge clk);
  53. valid_set_all_commit = 1'b0;
  54. tick_500us = 1'b0;
  55. repeat (3) pulse_tick();
  56. if (watchdog_active || timeout_event) $fatal(1, "valid commit did not reset watchdog");
  57. // Clear enable then re-enable: counter restarts
  58. @(negedge clk);
  59. enable = 1'b0;
  60. @(negedge clk);
  61. enable = 1'b1;
  62. if (dut.tick_count !== 0 || watchdog_active)
  63. $fatal(1, "re-enable did not clear counter");
  64. $display("host_watchdog_tb PASS");
  65. $finish;
  66. end
  67. endmodule