diff --git a/packages/embeddedci/CHANGELOG.md b/packages/embeddedci/CHANGELOG.md index a578f83..d75e6e3 100644 --- a/packages/embeddedci/CHANGELOG.md +++ b/packages/embeddedci/CHANGELOG.md @@ -2,6 +2,19 @@ ## 4.0.5 +For BenchPod firmware 4.0.5 (features table revision 18, gateware v66). + +- **The emulation image has no SWD, JTAG, SPI master or I2C master** (gateware v65). + - `bp.has_bus_masters()` says whether the running image has them. + - `flash()` over SWD or JTAG, `open_spi()`, `spi_flash()`, `open_i2c()`, `expansion()` and + `capture_la(send=I2CSend/SpiSend)` switch the pod from the emulation image to the loop image (logged, + about 3 s) when no I2C, SPI or UART sensor runs, and raise `UnsupportedFeatureError` (`BP0059`) while + one does: stop the sensors first, or flash before starting them. + - The `benchpod_capability("spi_master")` and `("i2c_master")` markers do the same switch. +- **`bp.lowlevel.dac_set(code16=...)` holds a 16-bit DAC code** (0..65535). The 8-bit + `dac_set(code)` still works. With `code16` the request also carries the 8-bit level, so firmware + before 4.0.5 holds the nearest one. +- `Capabilities.dac_bits` reads 16 from firmware 4.0.5 (it reported 8, the old generator depth). - **The pod's lease is released when the process exits.** A script that ends without `close()` (for example `bp = BenchPod(...); bp.generate(...)`) used to leave the pod's lease held for its full TTL, so every other client got `BP0025` for about two minutes. An `atexit` hook now releases the leases @@ -9,15 +22,6 @@ application has not installed its own handler. A lease joined from `BENCHPOD_LEASE` is still the runner's and is not released. -For gateware v65 (features table revision 18): the emulation image has no SWD, JTAG, SPI master or I2C master. - -- `bp.has_bus_masters()` says whether the running image has them. -- `flash()` over SWD or JTAG, `open_spi()`, `spi_flash()`, `open_i2c()`, `expansion()` and - `capture_la(send=I2CSend/SpiSend)` switch the pod from the emulation image to the loop image (logged, - about 3 s) when no I2C, SPI or UART sensor runs, and raise `UnsupportedFeatureError` (`BP0059`) while - one does: stop the sensors first, or flash before starting them. -- The `benchpod_capability("spi_master")` and `("i2c_master")` markers do the same switch. - ## 4.0.4 For BenchPod firmware 4.0.4 (features table revision 17). diff --git a/packages/embeddedci/README.md b/packages/embeddedci/README.md index a3f4f3c..bd9b795 100644 --- a/packages/embeddedci/README.md +++ b/packages/embeddedci/README.md @@ -2880,7 +2880,7 @@ These sit below the stable API and are **not** covered by the stability promise: * `bp.transport` — the underlying transport object. * `bp.lowlevel` — individual analog switches and raw DAC codes for bring-up and diagnostics: `dac_mux(ctrl1=, ctrl2=)`, `dac_mux_status()`, `cal_switch(cal1=, cal2=, current_in=, cal_path=)`, - `cal_switch_status()`, `dac_set(code, divider=)`. Prefer the named paths — these can leave the + `cal_switch_status()`, `dac_set(code16=, divider=)` (16-bit; `dac_set(code)` takes the older 8-bit level). Prefer the named paths — these can leave the front end in a state no named path describes. ## API reference diff --git a/packages/embeddedci/src/embeddedci/benchpod/lowlevel.py b/packages/embeddedci/src/embeddedci/benchpod/lowlevel.py index d066607..9f11318 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/lowlevel.py +++ b/packages/embeddedci/src/embeddedci/benchpod/lowlevel.py @@ -82,15 +82,33 @@ def cal_switch_status(self) -> Dict[str, Any]: """Report the calibration-relay (U58) state without changing it.""" return _dict(self._pod.command({"cmd": "cal_switch"})) - def dac_set(self, code: int, *, divider: Optional[int] = None) -> Dict[str, Any]: - """Hold a raw 8-bit DAC code (0..255) on whatever path is routed, uncalibrated. - + def dac_set( + self, + code: Optional[int] = None, + *, + code16: Optional[int] = None, + divider: Optional[int] = None, + ) -> Dict[str, Any]: + """Hold a raw DAC code on whatever path is routed, uncalibrated. + + ``code16`` is the 16-bit code (0..65535). ``code`` is the older 8-bit level (0..255), held + as ``code * 256``. Give one of the two. With ``code16`` the request also carries its 8-bit + level, so firmware before 4.0.5 (no ``code16``) holds the nearest 8-bit level. ``divider`` is the DAC sequencer clock divider. Prefer :meth:`~embeddedci.benchpod.client.BenchPod.dac_output`, which takes calibrated volts. """ - if not 0 <= int(code) <= 255: - raise ValueError(f"code must be 0..255, got {code!r}") - req: Dict[str, Any] = {"cmd": "dac_set", "value": int(code)} + if (code is None) == (code16 is None): + raise ValueError("give code (0..255) or code16 (0..65535)") + req: Dict[str, Any] = {"cmd": "dac_set"} + if code16 is not None: + if not 0 <= int(code16) <= 65535: + raise ValueError(f"code16 must be 0..65535, got {code16!r}") + req["code16"] = int(code16) + req["value"] = int(code16) >> 8 + else: + if not 0 <= int(code) <= 255: # type: ignore[arg-type] + raise ValueError(f"code must be 0..255, got {code!r}") + req["value"] = int(code) # type: ignore[arg-type] if divider is not None: req["divider"] = int(divider) return _dict(self._pod.command(req)) diff --git a/packages/embeddedci/tests/api_surface.json b/packages/embeddedci/tests/api_surface.json index bf6573e..ce2e34b 100644 --- a/packages/embeddedci/tests/api_surface.json +++ b/packages/embeddedci/tests/api_surface.json @@ -856,7 +856,7 @@ "cal_switch_status": "(self) -> 'Dict[str, Any]'", "dac_mux": "(self, *, ctrl1: 'Optional[str]' = None, ctrl2: 'Optional[str]' = None) -> 'Dict[str, Any]'", "dac_mux_status": "(self) -> 'Dict[str, Any]'", - "dac_set": "(self, code: 'int', *, divider: 'Optional[int]' = None) -> 'Dict[str, Any]'" + "dac_set": "(self, code: 'Optional[int]' = None, *, code16: 'Optional[int]' = None, divider: 'Optional[int]' = None) -> 'Dict[str, Any]'" }, "MacAddresses": { "__fields__": [ diff --git a/packages/embeddedci/tests/test_client_v2.py b/packages/embeddedci/tests/test_client_v2.py index 5106880..09ced41 100644 --- a/packages/embeddedci/tests/test_client_v2.py +++ b/packages/embeddedci/tests/test_client_v2.py @@ -487,6 +487,11 @@ def test_lowlevel_controls(): bp.lowlevel.cal_switch(cal1=True, cal2=True) with pytest.raises(ValueError): bp.lowlevel.dac_set(256) + bp.lowlevel.dac_set(code16=40000) + assert t.commands[-1] == {"cmd": "dac_set", "code16": 40000, "value": 156} + for bad in ({"code16": 65536}, {"code16": -1}, {}, {"code": 1, "code16": 1}): + with pytest.raises(ValueError): + bp.lowlevel.dac_set(**bad) def test_deep_replay_refused_on_an_image_without_it():