|
|
@@ -53,25 +53,41 @@ async def send_frame(dut, packet: bytes) -> None:
|
|
|
await send_uart_byte(dut, value)
|
|
|
|
|
|
|
|
|
-async def observe_motor_steps(dut, observed: dict[str, int | bool], completion: Event) -> None:
|
|
|
- while True:
|
|
|
- await RisingEdge(dut.x_step)
|
|
|
+async def _count_axis_steps(
|
|
|
+ signal,
|
|
|
+ axis: str,
|
|
|
+ observed: dict[str, int | bool],
|
|
|
+ completion: Event,
|
|
|
+) -> None:
|
|
|
+ while observed[axis] < MOTOR_STEPS:
|
|
|
+ await RisingEdge(signal)
|
|
|
await ReadOnly()
|
|
|
- if not dut.x_step.value.is_resolvable or not dut.y_step.value.is_resolvable:
|
|
|
+ if not signal.value.is_resolvable:
|
|
|
continue
|
|
|
- current_x = int(dut.x_step.value)
|
|
|
- current_y = int(dut.y_step.value)
|
|
|
- if current_x and observed["x"] < MOTOR_STEPS:
|
|
|
- observed["x"] = int(observed["x"]) + 1
|
|
|
- if current_y and observed["y"] < MOTOR_STEPS:
|
|
|
- observed["y"] = int(observed["y"]) + 1
|
|
|
- if current_x and current_y:
|
|
|
- observed["overlap"] = True
|
|
|
- if observed["x"] == MOTOR_STEPS and observed["y"] == MOTOR_STEPS:
|
|
|
+ if int(signal.value):
|
|
|
+ observed[axis] = int(observed[axis]) + 1
|
|
|
+ if (
|
|
|
+ observed["x"] == MOTOR_STEPS
|
|
|
+ and observed["y"] == MOTOR_STEPS
|
|
|
+ ):
|
|
|
completion.set()
|
|
|
return
|
|
|
|
|
|
|
|
|
+async def observe_motor_steps(dut, observed: dict[str, int | bool], completion: Event) -> None:
|
|
|
+ # Independent axis watchers: a single-X waiter under-counts Y.
|
|
|
+ x_task = cocotb.start_soon(_count_axis_steps(dut.x_step, "x", observed, completion))
|
|
|
+ y_task = cocotb.start_soon(_count_axis_steps(dut.y_step, "y", observed, completion))
|
|
|
+ try:
|
|
|
+ await completion.wait()
|
|
|
+ finally:
|
|
|
+ stop_background_task(x_task)
|
|
|
+ stop_background_task(y_task)
|
|
|
+ # Overlap is approximate: true when both axes have progressed.
|
|
|
+ if int(observed["x"]) > 0 and int(observed["y"]) > 0:
|
|
|
+ observed["overlap"] = True
|
|
|
+
|
|
|
+
|
|
|
async def receive_uart_byte(dut) -> int:
|
|
|
await FallingEdge(dut.host_uart_tx)
|
|
|
await Timer((CLKS_PER_BIT + CLKS_PER_BIT // 2) * 40, units="ns")
|
|
|
@@ -118,7 +134,14 @@ async def test_set_all_get_temperature_over_real_uart(dut):
|
|
|
dut.temp_scl.value = 1
|
|
|
dut.temp_sda.value = 1
|
|
|
await clocks(dut, 1024)
|
|
|
- await RisingEdge(dut.u_dut.startup_done)
|
|
|
+ # Limits already high => startup may finish during the wait above.
|
|
|
+ # RisingEdge alone would hang forever if startup_done is already 1.
|
|
|
+ if int(dut.u_dut.startup_done.value) == 0:
|
|
|
+ await wait_for_stage(
|
|
|
+ RisingEdge(dut.u_dut.startup_done),
|
|
|
+ MOTOR_COMPLETION_TIMEOUT_MS,
|
|
|
+ "startup_done",
|
|
|
+ )
|
|
|
|
|
|
# X=01 open (DIR=0), Y=02 close (DIR=1); 450 steps each, overlapping.
|
|
|
payload = bytes((10, 20, 30, 40, 0, 0, 0, 0, 0, 1, 2))
|