mrdimm_pwm_commit_race_tb.v 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. `timescale 1ns/1ps
  2. // Historical diagnostic for the retired mrdimm_output_core. This is a
  3. // reproduction script, not a current production-top acceptance gate: it prints
  4. // any mixed-image observation and exits normally even when one is found.
  5. module mrdimm_pwm_commit_race_tb;
  6. reg clk = 0;
  7. always #20 clk = ~clk; // 25 MHz
  8. reg rst_n = 0;
  9. reg tick_1s = 0;
  10. reg wr_en = 0;
  11. reg [2:0] wr_addr = 0;
  12. reg [7:0] wr_data = 0;
  13. reg commit = 0;
  14. wire commit_done;
  15. wire commit_ok;
  16. reg keepalive_reload = 0;
  17. wire [31:0] applied_fan, applied_ptc;
  18. wire [31:0] requested_fan, requested_ptc;
  19. wire [3:0] manual_active;
  20. wire lease_active;
  21. wire [7:0] watchdog_remaining;
  22. wire [3:0] fan_pwm_on;
  23. wire [3:0] ptc_pwm_on;
  24. mrdimm_output_core #(
  25. .BOOT_FAN_PERCENT(8'd0),
  26. .BOOT_PTC_PERCENT(8'd0),
  27. .PWM_PERIOD_CLKS(2000),
  28. .PWM_CLKS_PER_PERCENT(20)
  29. ) dut (
  30. .clk(clk),
  31. .rst_n(rst_n),
  32. .tick_1s(tick_1s),
  33. .wr_en(wr_en),
  34. .wr_addr(wr_addr),
  35. .wr_data(wr_data),
  36. .commit(commit),
  37. .commit_done(commit_done),
  38. .commit_ok(commit_ok),
  39. .keepalive_reload(keepalive_reload),
  40. .applied_fan(applied_fan),
  41. .applied_ptc(applied_ptc),
  42. .requested_fan(requested_fan),
  43. .requested_ptc(requested_ptc),
  44. .manual_active(manual_active),
  45. .lease_active(lease_active),
  46. .watchdog_remaining(watchdog_remaining),
  47. .fan_pwm_on(fan_pwm_on),
  48. .ptc_pwm_on(ptc_pwm_on)
  49. );
  50. wire [7:0] combined_bitmap = {ptc_pwm_on, fan_pwm_on};
  51. integer sweep_offset;
  52. integer mixed_generation_errors = 0;
  53. reg [7:0] captured_bitmap;
  54. initial begin
  55. $display("=== Starting MRDIMM PWM Commit Race Reproduction ===");
  56. // Sweep50 arrival offsets with the local accelerated PWM parameters
  57. for (sweep_offset = 0; sweep_offset < 50; sweep_offset = sweep_offset + 1) begin
  58. // Reset DUT
  59. rst_n = 0;
  60. commit = 0;
  61. wr_en = 0;
  62. repeat (5) @(posedge clk);
  63. rst_n = 1;
  64. repeat (20) @(posedge clk);
  65. // Pre-stage all 8 channels to 100% before the target phase starts
  66. for (int ch = 0; ch < 8; ch = ch + 1) begin
  67. wr_en = 1; wr_addr = ch; wr_data = 8'd100;
  68. @(posedge clk);
  69. end
  70. wr_en = 0;
  71. // Wait until phase boundary (phase_clk == 0)
  72. while (dut.u_pwm.phase_clk != 0) @(posedge clk);
  73. // Advance to the exact target clock offset within the scan window
  74. repeat (sweep_offset) @(posedge clk);
  75. // Commit at the exact clock offset
  76. commit = 1;
  77. @(posedge clk);
  78. commit = 0;
  79. // Wait until commit_done
  80. while (!commit_done) @(posedge clk);
  81. // Check bitmap over the next 2 full phases (1000 clocks)
  82. repeat (1000) begin
  83. @(posedge clk);
  84. captured_bitmap = combined_bitmap;
  85. // Duty was 0 (bitmap 8'h00) -> 100 (bitmap 8'hFF)
  86. // A valid bitmap MUST be either 8'h00 or 8'hFF!
  87. // Any intermediate value (like 8'hE0, 8'hF8, 8'h0F) indicates channel mixing!
  88. if (captured_bitmap != 8'h00 && captured_bitmap != 8'hFF) begin
  89. mixed_generation_errors = mixed_generation_errors + 1;
  90. $display("RACE DETECTED at sweep offset %0d: mixed bitmap = 0x%02X at phase %0d, phase_clk %0d",
  91. sweep_offset, captured_bitmap, dut.u_pwm.phase, dut.u_pwm.phase_clk);
  92. end
  93. end
  94. end
  95. if (mixed_generation_errors > 0) begin
  96. $display("REPRODUCTION CONFIRMED: Found %0d mixed generation bitmap events!", mixed_generation_errors);
  97. end else begin
  98. $display("CLEAN: No mixed generation bitmap events observed.");
  99. end
  100. $finish;
  101. end
  102. endmodule