stimulus_reload_priority_tb.v 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. `timescale 1ns/1ps
  2. module stimulus_reload_priority_tb;
  3. reg clk = 0;
  4. reg rst_n = 0;
  5. reg tick_1s = 0;
  6. reg stimulus_wr_en = 0;
  7. reg [4:0] stimulus_wr_addr = 0;
  8. reg [7:0] stimulus_wr_data = 0;
  9. reg stimulus_commit = 0;
  10. reg [7:0] stimulus_duration = 0;
  11. wire [4:0] bmc_rd_index;
  12. wire stimulus_active;
  13. integer i;
  14. always #5 clk = ~clk;
  15. thermal_control_core #(.ENABLE_STIMULUS(1)) dut (
  16. .clk(clk), .rst_n(rst_n), .tick_1s(tick_1s),
  17. .target_commit(1'b0), .target_celsius(8'd0),
  18. .stimulus_wr_en(stimulus_wr_en),
  19. .stimulus_wr_addr(stimulus_wr_addr),
  20. .stimulus_wr_data(stimulus_wr_data),
  21. .stimulus_commit(stimulus_commit),
  22. .stimulus_duration_seconds(stimulus_duration),
  23. .bmc_epoch(16'd0), .bmc_stale(1'b0),
  24. .bmc_valid_mask(24'hff_ffff), .bmc_rd_index(bmc_rd_index),
  25. .bmc_rd_raw(16'd0), .bmc_rd_valid(1'b1),
  26. .ct_epoch(16'd0), .ct_stale(1'b0),
  27. .ct_valid_mask(27'h7ff_ffff), .snapshot_lock(1'b0),
  28. .snapshot_lock_bank(1'b0), .pwm_rd_addr(5'd0),
  29. .pwm_rd_data(), .snapshot_output_bank(1'b0),
  30. .snapshot_rd_addr(5'd0), .snapshot_requested_data(),
  31. .snapshot_applied_data(), .active_output_bank(),
  32. .control_state(), .current_target_celsius(),
  33. .host_target_seen(), .control_epoch(), .safety_override_mask(),
  34. .lane_fault_mask(), .global_fault(), .output_commit(),
  35. .stimulus_active(stimulus_active), .pwm_phase_boundary(1'b0),
  36. .pwm_scan_idle(1'b1), .boot_init_complete()
  37. );
  38. task stage_vector;
  39. input [7:0] base;
  40. begin
  41. for (i = 0; i < 32; i = i + 1) begin
  42. @(negedge clk);
  43. stimulus_wr_en = 1;
  44. stimulus_wr_addr = i[4:0];
  45. stimulus_wr_data = base + i[7:0];
  46. end
  47. @(negedge clk);
  48. stimulus_wr_en = 0;
  49. end
  50. endtask
  51. task commit_vector;
  52. input [7:0] duration;
  53. input with_tick;
  54. begin
  55. @(negedge clk);
  56. stimulus_duration = duration;
  57. stimulus_commit = 1;
  58. tick_1s = with_tick;
  59. @(negedge clk);
  60. stimulus_commit = 0;
  61. tick_1s = 0;
  62. end
  63. endtask
  64. initial begin
  65. repeat (2) @(negedge clk);
  66. rst_n = 1;
  67. stage_vector(8'd10);
  68. commit_vector(8'd1, 1'b0);
  69. if (!stimulus_active || dut.stimulus_remaining !== 8'd1)
  70. $fatal(1, "initial one-second stimulus did not start");
  71. stage_vector(8'd50);
  72. // The last tick of vector A and the legal commit of vector B share
  73. // one edge. Commit must win so the fresh 7-second duration survives.
  74. commit_vector(8'd7, 1'b1);
  75. if (!stimulus_active)
  76. $fatal(1, "same-cycle reload was overwritten by expiry");
  77. if (dut.stimulus_remaining !== 8'd7)
  78. $fatal(1, "reload remaining=%0d expected=7", dut.stimulus_remaining);
  79. $display("PASS: stimulus commit wins over same-cycle expiry tick");
  80. $finish;
  81. end
  82. endmodule