| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- """Production-parameter POR to runtime PWM handoff regression."""
- from __future__ import annotations
- import cocotb
- from cocotb.triggers import ReadOnly, RisingEdge
- PWM_PERIOD_CLKS = 50_000
- EXPECTED_FAN_HIGH = 10_000
- @cocotb.test()
- async def test_por_boot_safe_pwm_until_complete_runtime_scan(dut):
- dut.host_rs232_rx.value = 1
- dut.host_ttl_rx.value = 1
- dut.bmc_rs232_rx.value = 1
- dut.tick_1s_test.value = 0
- dut.reset_test.value = 0
- dut.bmc_epoch_override_enable.value = 0
- dut.bmc_epoch_override_value.value = 0
- previous_bitmap = None
- saw_por_low = False
- saw_por_release = False
- saw_boot_ready = False
- saw_scan_complete = False
- takeover_boundary = None
- for period in range(3):
- ptc_high = [0] * 24
- front_connector_high = [0] * 4
- rear_connector_high = [0] * 4
- front_ball_low = [0] * 4
- rear_ball_high = [0] * 4
- for sample in range(PWM_PERIOD_CLKS):
- await RisingEdge(dut.sys_clk)
- await ReadOnly()
- rst_n = int(dut.rst_n_mon.value)
- boundary = int(dut.pwm_boundary_mon.value)
- bitmap = int(dut.logical_bitmap_mon.value)
- boot_ready = int(dut.boot_init_complete_mon.value)
- scan_complete = int(dut.runtime_scan_complete_mon.value)
- saw_por_low |= not bool(rst_n)
- saw_por_release |= bool(rst_n)
- saw_boot_ready |= bool(boot_ready)
- if scan_complete and not saw_scan_complete:
- saw_scan_complete = True
- if previous_bitmap is not None and bitmap != previous_bitmap:
- assert boundary, "logical PWM bitmap changed away from phase boundary"
- if scan_complete and takeover_boundary is None:
- takeover_boundary = period * PWM_PERIOD_CLKS + sample
- previous_bitmap = bitmap
- ptc = int(dut.ptc_pwm_out.value)
- front_ball = int(dut.front_fan_pwm_out.value)
- rear_ball = int(dut.rear_fan_pwm_out.value)
- front_connector = (~front_ball) & 0xF
- rear_connector = rear_ball
- for channel in range(24):
- ptc_high[channel] += (ptc >> channel) & 1
- for channel in range(4):
- front_connector_high[channel] += (front_connector >> channel) & 1
- rear_connector_high[channel] += (rear_connector >> channel) & 1
- front_ball_low[channel] += 1 - ((front_ball >> channel) & 1)
- rear_ball_high[channel] += (rear_ball >> channel) & 1
- if not boot_ready or not scan_complete:
- assert ptc == 0
- assert ptc_high == [0] * 24
- assert front_connector_high == [EXPECTED_FAN_HIGH] * 4
- assert rear_connector_high == [EXPECTED_FAN_HIGH] * 4
- assert front_ball_low == [EXPECTED_FAN_HIGH] * 4
- assert rear_ball_high == [EXPECTED_FAN_HIGH] * 4
- assert saw_por_low
- assert saw_por_release
- assert saw_boot_ready
- assert saw_scan_complete
- assert not int(dut.pwm_deadline_miss_mon.value)
- if takeover_boundary is not None:
- # The first sampled rising edge is cycle index zero, so the 500th
- # clock and every phase boundary thereafter have index 499 mod 500.
- assert (takeover_boundary + 1) % 500 == 0
- dut._log.info(
- "PASS: 3x50000 clocks, PTC high=0, Front/Rear connector high=10000; "
- "POR release, boot init, full scan and phase-boundary handoff observed"
- )
|