host_watchdog_contract_formal.v 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. module host_watchdog_contract_formal (
  2. input wire clk,
  3. input wire rst_n,
  4. input wire tick_500us,
  5. input wire valid_set_all_commit,
  6. input wire motor_start,
  7. input wire [1:0] motor_active_mask,
  8. input wire [1:0] motor_dir_mask
  9. );
  10. // The formal target proves ordering with a small parameter. The production
  11. // 20,000-tick boundary is covered by tests/sim/host_watchdog_tb.v.
  12. localparam integer FORMAL_TIMEOUT_TICKS = 4;
  13. localparam integer FORMAL_FIXED_STEPS = 4;
  14. localparam integer FORMAL_DIR_SETUP_TICKS = 2;
  15. localparam integer DEPTH = 12;
  16. localparam integer PTC_COUNT = 8;
  17. localparam [7:0] WATCHDOG_PTC_TARGET = 8'd0;
  18. localparam [7:0] WATCHDOG_FAN_TARGET = 8'd20;
  19. wire dut_rst_n = rst_n;
  20. wire watchdog_active;
  21. wire timeout_event;
  22. wire motor_busy;
  23. wire motor_done;
  24. wire [1:0] step;
  25. wire [1:0] motor_dir;
  26. wire [7:0] target_rd_data;
  27. reg [1:0] reset_cycles;
  28. reg [3:0] target_rd_addr;
  29. reg [3:0] previous_rd_addr;
  30. reg previous_watchdog_active;
  31. reg target_read_valid;
  32. reg commit_pending;
  33. reg timeout_seen;
  34. host_watchdog #(.TIMEOUT_TICKS(FORMAL_TIMEOUT_TICKS)) u_watchdog (
  35. .clk(clk), .rst_n(dut_rst_n), .tick_500us(tick_500us),
  36. .valid_set_all_commit(valid_set_all_commit), .watchdog_active(watchdog_active),
  37. .timeout_event(timeout_event)
  38. );
  39. output_target_ram #(
  40. .DEPTH(DEPTH), .PTC_COUNT(PTC_COUNT),
  41. .BOOT_PTC_TARGET(8'd0), .BOOT_FAN_TARGET(8'd10),
  42. .WATCHDOG_PTC_TARGET(WATCHDOG_PTC_TARGET),
  43. .WATCHDOG_FAN_TARGET(WATCHDOG_FAN_TARGET)
  44. ) u_targets (
  45. .clk(clk), .rst_n(dut_rst_n), .wr_en(1'b0), .wr_addr(4'd0),
  46. .wr_data(8'd0), .commit(1'b0), .watchdog_active(watchdog_active),
  47. .rd_addr(target_rd_addr), .rd_data(target_rd_data)
  48. );
  49. door_motor_engine #(
  50. .FIXED_STEPS(FORMAL_FIXED_STEPS),
  51. .DIR_SETUP_TICKS(FORMAL_DIR_SETUP_TICKS)
  52. ) u_motor (
  53. .clk(clk), .rst_n(dut_rst_n), .start(motor_start),
  54. .active_mask(motor_active_mask), .dir_mask(motor_dir_mask),
  55. .tick_500us(tick_500us), .abort(timeout_event), .busy(motor_busy),
  56. .done(motor_done), .step(step), .dir(motor_dir)
  57. );
  58. initial begin
  59. reset_cycles = 2'd0;
  60. target_rd_addr = 4'd0;
  61. previous_rd_addr = 4'd0;
  62. previous_watchdog_active = 1'b0;
  63. target_read_valid = 1'b0;
  64. commit_pending = 1'b0;
  65. timeout_seen = 1'b0;
  66. end
  67. always @(posedge clk) begin
  68. assume (rst_n == 1'b0 || rst_n == 1'b1);
  69. assume (tick_500us == 1'b0 || tick_500us == 1'b1);
  70. assume (valid_set_all_commit == 1'b0 || valid_set_all_commit == 1'b1);
  71. assume (motor_start == 1'b0 || motor_start == 1'b1);
  72. assume ((^motor_active_mask) == 1'b0 || (^motor_active_mask) == 1'b1);
  73. assume ((^motor_dir_mask) == 1'b0 || (^motor_dir_mask) == 1'b1);
  74. assume (!motor_busy || !motor_start);
  75. if ($initstate || reset_cycles < 2) begin
  76. assume (!dut_rst_n);
  77. reset_cycles <= reset_cycles + 1'b1;
  78. end else begin
  79. assume (dut_rst_n);
  80. end
  81. if (!dut_rst_n) begin
  82. target_rd_addr <= 4'd0;
  83. previous_rd_addr <= 4'd0;
  84. previous_watchdog_active <= 1'b0;
  85. target_read_valid <= 1'b0;
  86. commit_pending <= 1'b0;
  87. timeout_seen <= 1'b0;
  88. end else begin
  89. if (target_rd_addr == DEPTH - 1)
  90. target_rd_addr <= 4'd0;
  91. else
  92. target_rd_addr <= target_rd_addr + 1'b1;
  93. // output_target_ram is a synchronous read: target_rd_data at this
  94. // edge belongs to the address and watchdog mode sampled at the
  95. // preceding edge. Guard the assertion until that pipeline state
  96. // has been established by reset; no shadow/active model is needed.
  97. if (target_read_valid && previous_watchdog_active) begin
  98. if (previous_rd_addr < PTC_COUNT)
  99. assert (target_rd_data == WATCHDOG_PTC_TARGET);
  100. else
  101. assert (target_rd_data == WATCHDOG_FAN_TARGET);
  102. end
  103. previous_rd_addr <= target_rd_addr;
  104. previous_watchdog_active <= watchdog_active;
  105. target_read_valid <= 1'b1;
  106. // host_watchdog gives a valid SET commit/feed priority over a
  107. // timeout decision. This checks the registered result one clock
  108. // after the sampled commit input.
  109. if (commit_pending) begin
  110. assert (!watchdog_active);
  111. assert (!timeout_event);
  112. end
  113. commit_pending <= valid_set_all_commit;
  114. // timeout_event is registered. The motor consumes it on the next
  115. // system clock; this flag observes the post-NBA STEP value one
  116. // sample later and avoids asserting against the pre-update value.
  117. if (timeout_event) timeout_seen <= 1'b1;
  118. if (timeout_seen) begin
  119. assert (step == 2'b00);
  120. timeout_seen <= 1'b0;
  121. end
  122. end
  123. end
  124. always @(posedge clk) begin
  125. cover (dut_rst_n && timeout_event);
  126. cover (dut_rst_n && motor_busy && timeout_event);
  127. cover (dut_rst_n && watchdog_active && target_rd_addr == 4'd8);
  128. end
  129. endmodule