test_6400_v1_pwm_boot_integration.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """Production-parameter POR to runtime PWM handoff regression."""
  2. from __future__ import annotations
  3. import cocotb
  4. from cocotb.triggers import ReadOnly, RisingEdge
  5. PWM_PERIOD_CLKS = 50_000
  6. EXPECTED_FAN_HIGH = 10_000
  7. @cocotb.test()
  8. async def test_por_boot_safe_pwm_until_complete_runtime_scan(dut):
  9. dut.host_rs232_rx.value = 1
  10. dut.host_ttl_rx.value = 1
  11. dut.bmc_rs232_rx.value = 1
  12. dut.tick_1s_test.value = 0
  13. dut.reset_test.value = 0
  14. dut.bmc_epoch_override_enable.value = 0
  15. dut.bmc_epoch_override_value.value = 0
  16. previous_bitmap = None
  17. saw_por_low = False
  18. saw_por_release = False
  19. saw_boot_ready = False
  20. saw_scan_complete = False
  21. takeover_boundary = None
  22. for period in range(3):
  23. ptc_high = [0] * 24
  24. front_connector_high = [0] * 4
  25. rear_connector_high = [0] * 4
  26. front_ball_low = [0] * 4
  27. rear_ball_high = [0] * 4
  28. for sample in range(PWM_PERIOD_CLKS):
  29. await RisingEdge(dut.sys_clk)
  30. await ReadOnly()
  31. rst_n = int(dut.rst_n_mon.value)
  32. boundary = int(dut.pwm_boundary_mon.value)
  33. bitmap = int(dut.logical_bitmap_mon.value)
  34. boot_ready = int(dut.boot_init_complete_mon.value)
  35. scan_complete = int(dut.runtime_scan_complete_mon.value)
  36. saw_por_low |= not bool(rst_n)
  37. saw_por_release |= bool(rst_n)
  38. saw_boot_ready |= bool(boot_ready)
  39. if scan_complete and not saw_scan_complete:
  40. saw_scan_complete = True
  41. if previous_bitmap is not None and bitmap != previous_bitmap:
  42. assert boundary, "logical PWM bitmap changed away from phase boundary"
  43. if scan_complete and takeover_boundary is None:
  44. takeover_boundary = period * PWM_PERIOD_CLKS + sample
  45. previous_bitmap = bitmap
  46. ptc = int(dut.ptc_pwm_out.value)
  47. front_ball = int(dut.front_fan_pwm_out.value)
  48. rear_ball = int(dut.rear_fan_pwm_out.value)
  49. front_connector = (~front_ball) & 0xF
  50. rear_connector = rear_ball
  51. for channel in range(24):
  52. ptc_high[channel] += (ptc >> channel) & 1
  53. for channel in range(4):
  54. front_connector_high[channel] += (front_connector >> channel) & 1
  55. rear_connector_high[channel] += (rear_connector >> channel) & 1
  56. front_ball_low[channel] += 1 - ((front_ball >> channel) & 1)
  57. rear_ball_high[channel] += (rear_ball >> channel) & 1
  58. if not boot_ready or not scan_complete:
  59. assert ptc == 0
  60. assert ptc_high == [0] * 24
  61. assert front_connector_high == [EXPECTED_FAN_HIGH] * 4
  62. assert rear_connector_high == [EXPECTED_FAN_HIGH] * 4
  63. assert front_ball_low == [EXPECTED_FAN_HIGH] * 4
  64. assert rear_ball_high == [EXPECTED_FAN_HIGH] * 4
  65. assert saw_por_low
  66. assert saw_por_release
  67. assert saw_boot_ready
  68. assert saw_scan_complete
  69. assert not int(dut.pwm_deadline_miss_mon.value)
  70. if takeover_boundary is not None:
  71. # The first sampled rising edge is cycle index zero, so the 500th
  72. # clock and every phase boundary thereafter have index 499 mod 500.
  73. assert (takeover_boundary + 1) % 500 == 0
  74. dut._log.info(
  75. "PASS: 3x50000 clocks, PTC high=0, Front/Rear connector high=10000; "
  76. "POR release, boot init, full scan and phase-boundary handoff observed"
  77. )