diff --git a/packages/embeddedci/CHANGELOG.md b/packages/embeddedci/CHANGELOG.md index 99c5100..22a3cb0 100644 --- a/packages/embeddedci/CHANGELOG.md +++ b/packages/embeddedci/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog — `embeddedci` +## 4.0.1 + +Not released yet. + +- **`la_pins` reads a long listing in pages.** On firmware with the `la_pins_paged` feature + (features table revision 12), a reply that cannot carry every pin says `next`; the SDK asks + again with `"from": next` (and the same `la`) and joins the pins, so `bp.la_pins()` and the MCP + `la_pins` tool get all 14 pins over the cloud even with a long sensor name on every pin. It + stops after 16 replies, or when `next` does not move forward. Older firmware is read in two + halves after `BP0053`/`BP0054`, as before. +- Features table revision 12. + ## 4.0.0 Pairs with BenchPod firmware 4.0.0 (client API 2). Breaking changes: diff --git a/packages/embeddedci/README.md b/packages/embeddedci/README.md index f8d1086..b4a3a79 100644 --- a/packages/embeddedci/README.md +++ b/packages/embeddedci/README.md @@ -1341,7 +1341,8 @@ to finish. `bp.la_pins()` lists every channel's `LaPinState` (`function`, `gpio` mode, `level`, `pull`, `pull_on`, `pull_dirs`); `bp.la_pins(la=[3, 4])` only those channels. A listing too large for one cloud reply (a long -sensor instance name on every channel) is read in two parts by itself (firmware after 3.10.12), +sensor instance name on every channel) is read in parts by itself: in pages on firmware after +4.0.0 (`la_pins_paged`), else in two halves (firmware after 3.10.12), and `bp.configure_gpio(channels, mode)` is the same group claim as `gpio_pins()` returning those states. Captures observe every channel whatever its function. GPIO channels stay GPIO — also across disconnects — until released (the pytest `benchpod` fixture releases them at session start and end), diff --git a/packages/embeddedci/src/embeddedci/benchpod/client.py b/packages/embeddedci/src/embeddedci/benchpod/client.py index 4c432d2..44f9447 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/client.py +++ b/packages/embeddedci/src/embeddedci/benchpod/client.py @@ -188,6 +188,8 @@ _SEND_PRE_SAMPLES = 64 #: Seconds to wait for the server's cached capabilities to follow an image switch. +#: la_pins pages a listing too large for one reply; a full one takes at most 14. +_LA_PINS_MAX_PAGES = 16 _SERVER_CAPS_WAIT = 15.0 @@ -3459,9 +3461,10 @@ def la_pins(self, la: Union[Pin, int, str, Sequence[Union[Pin, int, str]], None] """Every LA channel's function (``none``, ``gpio``, ``uart_rx``, …), GPIO mode and level, and bias resistor. A channel that is in use refuses other functions. - ``la``: only these channels (a channel, a wiring name, or a list), in pin order. A full - listing too large for one cloud reply (a long sensor instance name on every pin) is read - in two parts by itself.""" + ``la``: only these channels (a channel, a wiring name, or a list), in pin order. A listing + too large for one cloud reply (a long sensor instance name on every pin) is read in parts by + itself: in pages (``from``/``next``) on firmware with ``la_pins_paged``, else in two + halves.""" self._require_capability("la_pins", "LA pin modes and GPIO") if la == "all": la = None @@ -3477,15 +3480,37 @@ def la_pins(self, la: Union[Pin, int, str, Sequence[Union[Pin, int, str]], None] return first + [p for p in self._la_pins_query(list(range(8, 15))) if p.la >= 8] def _la_pins_query(self, las: Optional[List[int]]) -> List[LaPinState]: + """One la_pins listing. On firmware with ``la_pins_paged`` a reply that could not carry + every pin says ``next``: ask again ``from`` there (with the same ``la``) and join the pins; + ``pull_dirs`` comes from the last reply. The loop stops after 16 replies, or when ``next`` + does not move forward.""" req: Dict[str, Any] = {"cmd": "la_pins"} if las is not None: req["la"] = las - with _classified_errors(): - data = _dict(self.command(req)) + paged = self.supports("la_pins_paged") + entries: List[Any] = [] + data: Dict[str, Any] = {} + last = 1 # the pin the last reply started from + for _ in range(_LA_PINS_MAX_PAGES): + with _classified_errors(): + data = _dict(self.command(req)) + entries.extend(data.get("pins") or []) + nxt = data.get("next") + if not paged or not isinstance(nxt, int) or isinstance(nxt, bool): + break + if nxt <= last or nxt > 14: + _log.warning("la_pins: next %s does not follow from %s; the listing stops there", + nxt, last) + break + last = nxt + req = dict(req, **{"from": nxt}) + else: + _log.warning("la_pins: still not done after %d replies; the listing stops there", + _LA_PINS_MAX_PAGES) # Digital v3r4 says the directions once for every channel ("pull_dirs"). dirs = data.get("pull_dirs") return [LaPinState.from_reply(e, pull_dirs=dirs if isinstance(dirs, list) else None) - for e in data.get("pins") or []] + for e in entries] def _entry_pull_dirs(self, entries: Any) -> Optional[Tuple[str, ...]]: """The pull directions for listing replies that do not say them (la_dir, gpio): on digital diff --git a/packages/embeddedci/src/embeddedci/benchpod/feature_map.json b/packages/embeddedci/src/embeddedci/benchpod/feature_map.json index 1b5ea18..1515380 100644 --- a/packages/embeddedci/src/embeddedci/benchpod/feature_map.json +++ b/packages/embeddedci/src/embeddedci/benchpod/feature_map.json @@ -1,10 +1,10 @@ { "_generated": "GENERATED by tools/gen_features.py from features/features.toml. DO NOT EDIT: edit the table.", "schema": 1, - "revision": 11, + "revision": 12, "api": 2, "min_client_api": 2, - "table_sha256": "ea8870a74cd198ed990eeec337ab4792870bb26185f2c5449c7a23bd8dc94b05", + "table_sha256": "875940ed02d7f8b7a9058803971565fc38e7f095d1795a80ee83627c563736dd", "floor": "3.9.2", "docs_base": "https://github.com/embeddedci-com/benchpod-firmware/blob/main/docs/", "facts": { @@ -134,6 +134,11 @@ "firmware": "3.10.13", "gateware": 59, "date": "2026-11-19" + }, + { + "firmware": "4.0.0", + "gateware": 59, + "date": "2026-11-20" } ], "features": { @@ -701,69 +706,75 @@ }, "client_api": { "rev": 8, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#client-compatibility" }, "lan_tls_default": { "rev": 9, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#lan_tls--the-lan-api-over-tls" }, "sig_always_required": { "rev": 9, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#sig_policy--which-firmware-and-blob-updates-the-pod-accepts" }, "generate_volts_only": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "analog", "docs": "API.md#generate--dac-waveform-output" }, "json_names_4": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#commands" }, "can_start_stop": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#can_start--bring-can-up" }, "la_step_pull_split": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#la_pull--la-pin-pull-resistors" }, "json_booleans_4": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#target_power--enabledisable-a-target-power-efuse" }, "console_recovery_json": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "usb-serial-interface.md#removed-in-firmware-400" }, "usb_host": { "rev": 10, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#usb_host--usb-host-mode" }, "dac_pinout_guard": { "rev": 11, - "firmware": "next", + "firmware": "4.0.0", "board": "any", "docs": "API.md#dac-pinout-on-the-flat-cable" + }, + "la_pins_paged": { + "rev": 12, + "firmware": "next", + "board": "any", + "docs": "API.md#la_pins--report-every-la-pin" } } } diff --git a/packages/embeddedci/tests/test_digital_v3r4.py b/packages/embeddedci/tests/test_digital_v3r4.py index ed4061e..31cd2de 100644 --- a/packages/embeddedci/tests/test_digital_v3r4.py +++ b/packages/embeddedci/tests/test_digital_v3r4.py @@ -204,3 +204,76 @@ def test_profile_takes_5v(): assert Wiring(la_mv=5000).la_voltage == 5.0 with pytest.raises(ValueError, match="1800, 3300 or 5000"): Wiring(la_mv=2500) + + +class PagedPod(Pod): + """Firmware with la_pins_paged (features rev 12): a reply carries at most ``page`` pins and + says ``next``; ``from`` continues there, with or without ``la``.""" + + def __init__(self, page: int = 5, features_rev: int = 12) -> None: + super().__init__(True, features_rev) + self.page = page + self.bad_next = False + + def command(self, req: dict) -> Any: + if req.get("cmd") != "la_pins": + return super().command(req) + self.sent.append(req) + want = req.get("la") or list(range(1, 15)) + if self.features_rev < 12: # older firmware ignores "from" + start = 1 + else: + start = req.get("from", 1) + todo = [n for n in want if n >= start] + out: Dict[str, Any] = {"pins": [self._entry(n) for n in todo[:self.page]], + "pull_dirs": ["up", "down"], "levels": len(self.sent)} + if len(todo) > self.page: + out["next"] = 1 if self.bad_next else todo[self.page] + return out + + +def test_la_pins_pages_with_from_and_next(): + pod = PagedPod(page=5) + bp = BenchPod(transport=pod, lease=False, wiring={"version": 2}) + assert bp.supports("la_pins_paged") + pins = bp.la_pins() + assert [p.la for p in pins] == list(range(1, 15)) + assert all(p.pull_dirs == ("up", "down") for p in pins) + assert [r for r in pod.sent if r["cmd"] == "la_pins"] == [ + {"cmd": "la_pins"}, {"cmd": "la_pins", "from": 6}, {"cmd": "la_pins", "from": 11}] + + +def test_la_pins_pages_a_subset_with_the_same_la(): + pod = PagedPod(page=2) + bp = BenchPod(transport=pod, lease=False, wiring={"version": 2}) + pins = bp.la_pins(la=[2, 4, 6, 8, 10]) + assert [p.la for p in pins] == [2, 4, 6, 8, 10] + assert [r for r in pod.sent if r["cmd"] == "la_pins"] == [ + {"cmd": "la_pins", "la": [2, 4, 6, 8, 10]}, + {"cmd": "la_pins", "la": [2, 4, 6, 8, 10], "from": 6}, + {"cmd": "la_pins", "la": [2, 4, 6, 8, 10], "from": 10}] + + +def test_la_pins_listing_that_fits_is_one_round_trip(): + pod = PagedPod(page=14) + bp = BenchPod(transport=pod, lease=False, wiring={"version": 2}) + assert len(bp.la_pins()) == 14 + assert [r for r in pod.sent if r["cmd"] == "la_pins"] == [{"cmd": "la_pins"}] + + +def test_la_pins_stops_when_next_does_not_move_forward(): + pod = PagedPod(page=5) + pod.bad_next = True + bp = BenchPod(transport=pod, lease=False, wiring={"version": 2}) + pins = bp.la_pins() + assert [p.la for p in pins] == [1, 2, 3, 4, 5] + assert len([r for r in pod.sent if r["cmd"] == "la_pins"]) == 1 + + +def test_la_pins_ignores_next_without_the_feature(): + # Firmware before la_pins_paged never says next; if a reply did, the SDK would not page. + pod = PagedPod(page=5, features_rev=11) + bp = BenchPod(transport=pod, lease=False, wiring={"version": 2}) + assert not bp.supports("la_pins_paged") + assert [p.la for p in bp.la_pins()] == [1, 2, 3, 4, 5] + assert [r for r in pod.sent if r["cmd"] == "la_pins"] == [{"cmd": "la_pins"}]