From 6d59c3812c3711a1d7fefc388305dc5f0a36b987 Mon Sep 17 00:00:00 2001 From: Andrey Kruchinkin Date: Mon, 9 Nov 2026 00:58:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D1=83?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=BF=D1=83=D1=81=D0=BA=D0=BE=D0=B2=20RJ2?= =?UTF-8?q?=20=D0=B8=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D1=83=20DSView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/dsview/build.py | 25 +++++++++++++++----- tools/dsview/pwm-waveform.patch | 3 +-- tools/dsview/zynq-ethernet/README.md | 5 ++-- tools/dsview/zynq-ethernet/build.py | 16 +------------ tools/dsview/zynq-ethernet/zynq.c | 35 ++++++++++++++++++++-------- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/tools/dsview/build.py b/tools/dsview/build.py index e4c580f..cce252c 100644 --- a/tools/dsview/build.py +++ b/tools/dsview/build.py @@ -11,6 +11,7 @@ from pathlib import Path import re import shutil import subprocess +import tempfile REVISION = '2e9e2c8e' @@ -65,6 +66,7 @@ def main(): parser.add_argument('--source', type=Path, required=True) parser.add_argument('--output', type=Path, required=True) parser.add_argument('--msys-root', type=Path, default=Path(r'C:\setcorp\tools\msys64')) + parser.add_argument('--extra-patch', type=Path) args = parser.parse_args() source, output = args.source.resolve(), args.output.resolve() prefix = args.msys_root.resolve() / 'ucrt64' @@ -73,17 +75,28 @@ def main(): revision = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=source, text=True).strip() if not revision.startswith(REVISION): raise SystemExit('Expected DSView revision ' + REVISION + ', got ' + revision) + patch_cmd = ['git', 'apply', '--ignore-space-change'] for retired_name in ('driver-summary.patch', 'gate-pair-checkbox.patch'): retired = Path(__file__).with_name(retired_name) if subprocess.run(['git', 'apply', '--ignore-space-change', '--reverse', '--check', str(retired)], cwd=source, capture_output=True).returncode == 0: subprocess.run(['git', 'apply', '--ignore-space-change', '--reverse', str(retired)], cwd=source, check=True) - for patch_name in ('setgui-host.patch', 'decoder-panel.patch', 'windows-usb-events.patch', 'pwm-waveform.patch'): - patch = Path(__file__).with_name(patch_name) - applied = subprocess.run(['git', 'apply', '--ignore-space-change', '--reverse', '--check', str(patch)], cwd=source, capture_output=True) - if applied.returncode: - subprocess.run(['git', 'apply', '--ignore-space-change', '--check', str(patch)], cwd=source, check=True) - subprocess.run(['git', 'apply', '--ignore-space-change', str(patch)], cwd=source, check=True) + patches = [Path(__file__).with_name(name) for name in + ('setgui-host.patch', 'decoder-panel.patch', 'windows-usb-events.patch', 'pwm-waveform.patch')] + if args.extra_patch: + patches.append(args.extra_patch.resolve()) + # Later patches may change the context of earlier ones. Check and apply + # their combined diff without touching the checkout's real index. + with tempfile.TemporaryDirectory() as temp: + index_env = dict(os.environ, GIT_INDEX_FILE=str(Path(temp) / 'index')) + subprocess.run(['git', 'read-tree', 'HEAD'], cwd=source, env=index_env, check=True) + for patch in patches: + subprocess.run(patch_cmd + ['--cached', str(patch)], cwd=source, env=index_env, check=True) + combined = subprocess.check_output(['git', 'diff', '--cached', '--binary', 'HEAD'], + cwd=source, env=index_env) + if subprocess.run(patch_cmd + ['--reverse', '--check'], cwd=source, input=combined, + capture_output=True).returncode: + subprocess.run(patch_cmd, cwd=source, input=combined, check=True) shutil.copy2(Path(__file__).with_name('native') / 'pwm_waveform.h', source / 'DSView/pv/view/pwm_waveform.h') env = dict(os.environ) env['PATH'] = os.pathsep.join([str(prefix/'bin'), str(args.msys_root/'usr/bin'), env.get('PATH', '')]) diff --git a/tools/dsview/pwm-waveform.patch b/tools/dsview/pwm-waveform.patch index 8ca447d..ea5f8b2 100644 --- a/tools/dsview/pwm-waveform.patch +++ b/tools/dsview/pwm-waveform.patch @@ -8,10 +8,9 @@ #include "../sigsession.h" #include "../data/decoderstack.h" #include "../data/decode/decoder.h" -@@ -269,6 +270,36 @@ +@@ -269,5 +270,35 @@ if ((*i).second) { const Row &row = (*i).first; - + // A PWM envelope stays a curve even when carrier periods + // are narrower than a pixel (normal annotation fallback + // would replace the entire sine with a solid box). diff --git a/tools/dsview/zynq-ethernet/README.md b/tools/dsview/zynq-ethernet/README.md index b96c0f1..d783528 100644 --- a/tools/dsview/zynq-ethernet/README.md +++ b/tools/dsview/zynq-ethernet/README.md @@ -3,8 +3,9 @@ Драйвер регистрирует сетевой прибор в списке DSView. Через нативные Run и Stop он читает каналы по TCP (ZLA1/ZLS1) или UDP (ZLT1/ZLB1/ZLP1/ZLP2/ZLR1). Фронты декодируются из тех же отсчётов, которые получает экран DSView. -Для RJ2 драйвер запрашивает буфер сокета 16 МиБ и восстанавливает -порядок отсчётов в окне на 4096 UDP-пакетов. +Для RJ2 драйвер запрашивает буфер сокета 32 МиБ и восстанавливает +порядок отсчётов в окне на 16 384 UDP-пакета. При разрыве запись +сохраняет непрерывный фрагмент до пропущенного пакета. Для сборки нужны MSYS2 UCRT64 и зависимости из [основного рецепта](../README.md). Исходный DSView берётся из diff --git a/tools/dsview/zynq-ethernet/build.py b/tools/dsview/zynq-ethernet/build.py index d78b6b8..01f866d 100644 --- a/tools/dsview/zynq-ethernet/build.py +++ b/tools/dsview/zynq-ethernet/build.py @@ -7,17 +7,6 @@ import sys HERE = Path(__file__).resolve().parent TEMPLATES = HERE.parents[2] -TEMPLATE_PATCHES = ('setgui-host.patch', 'decoder-panel.patch', 'windows-usb-events.patch') - - -def apply_patch(source, patch): - command = ['git', 'apply', '--ignore-space-change'] - if subprocess.run(command + ['--reverse', '--check', str(patch)], - cwd=source, capture_output=True).returncode: - subprocess.run(command + ['--check', str(patch)], cwd=source, check=True) - subprocess.run(command + [str(patch)], cwd=source, check=True) - - def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--source', type=Path, default=Path('build/dsview-upstream')) @@ -31,10 +20,6 @@ def main(): if not revision.startswith('2e9e2c8e'): parser.error('DSView checkout must be at revision 2e9e2c8e') - for name in TEMPLATE_PATCHES: - apply_patch(source, recipe / name) - apply_patch(source, HERE / 'ethernet.patch') - analyzer = TEMPLATES / 'hdl/logic-analyzer/include' ethernet = TEMPLATES / 'hdl/logic-udp-ethernet/include' inputs = (HERE / 'zynq.c', HERE / 'zynq_record.c', HERE / 'zynq_record.h', @@ -46,6 +31,7 @@ def main(): shutil.copy2(path, driver / path.name) subprocess.run([sys.executable, str(recipe / 'build.py'), '--source', str(source), + '--extra-patch', str(HERE / 'ethernet.patch'), '--output', str(output), '--msys-root', str(args.msys_root.resolve())], check=True) source_files = output / 'zynq-source' source_files.mkdir(exist_ok=True) diff --git a/tools/dsview/zynq-ethernet/zynq.c b/tools/dsview/zynq-ethernet/zynq.c index e43a1a1..651d6a8 100644 --- a/tools/dsview/zynq-ethernet/zynq.c +++ b/tools/dsview/zynq-ethernet/zynq.c @@ -19,7 +19,8 @@ #define SNAPSHOT_TIMEOUT (65 * G_TIME_SPAN_SECOND) #define STREAM_MIN_DIVIDER 10 #define PL_HEARTBEAT (250 * G_TIME_SPAN_MILLISECOND) -#define PL_REORDER_BLOCKS 4096u +#define PL_REORDER_BLOCKS 16384u +#define PL_SOCKET_BUFFER (32 * 1024 * 1024) enum receive_state { REPLY, FRAME_HEADER, SAMPLES }; @@ -79,7 +80,7 @@ struct zynq_device { static const uint32_t dividers[] = { 50000, 20000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 40, 25, - 20, 14, 10, 7, 5, 4, 2, 1 + 20, 14, 10, 7, 5, 4, 3, 2, 1 }; static const char *const max_heights[] = {"1X", "2X", "3X", "4X", "5X"}; @@ -108,7 +109,7 @@ static GSocket *connect_udp(const char *address) if (socket) { // Buffer bursts while the host schedules the receiver at 100 MB/s. - g_socket_set_option(socket, SOL_SOCKET, SO_RCVBUF, 16 * 1024 * 1024, NULL); + g_socket_set_option(socket, SOL_SOCKET, SO_RCVBUF, PL_SOCKET_BUFFER, NULL); g_socket_set_blocking(socket, FALSE); } return socket; @@ -768,8 +769,14 @@ static void prepare_receive(struct zynq_device *device, enum receive_state state static int receive_failure(const struct sr_dev_inst *sdi, const char *reason) { + struct zynq_device *device = sdi->priv; sr_err("%s: %s", sdi->name, reason); - set_error(sdi->priv, reason); + set_error(device, reason); + // Preserve the contiguous tail that was already decoded before the gap. + if (device->recorder && device->pl_count && !zynq_record_failed(device->recorder)) { + deliver(sdi, device->pl_count); + device->pl_count = 0; + } finish(sdi, SR_PKT_DATA_ERROR); return FALSE; } @@ -865,10 +872,15 @@ static int receive_pl(const struct sr_dev_inst *sdi) } device->keepalive = now + PL_HEARTBEAT; } - if (now >= device->deadline) - return receive_failure(sdi, device->pl_pending ? - "RJ2 потерял UDP-пакет. Уменьшите частоту или проверьте сеть." : - "RJ2 не отвечает. Проверьте Ethernet и адрес платы."); + if (now >= device->deadline) { + if (device->pl_pending) { + g_autofree char *reason = g_strdup_printf( + "RJ2 не получил UDP-пакет №%u. В очереди %u следующих пакетов.", + device->sequence, device->pl_pending); + return receive_failure(sdi, reason); + } + return receive_failure(sdi, "RJ2 не отвечает. Проверьте Ethernet и адрес платы."); + } for (unsigned n = 0; n < 64; n++) { uint8_t response[ZLP_BLOCK + 17]; @@ -920,8 +932,11 @@ static int receive_pl(const struct sr_dev_inst *sdi) uint32_t ahead = value - device->sequence; if (ahead >= (UINT32_C(1) << 31)) continue; /* Old duplicate. */ - if (ahead >= PL_REORDER_BLOCKS) - return receive_failure(sdi, "RJ2 потерял UDP-пакет. Уменьшите частоту или проверьте сеть."); + if (ahead >= PL_REORDER_BLOCKS) { + g_autofree char *reason = g_strdup_printf( + "Разрыв UDP в RJ2: ожидался пакет №%u, получен №%u.", device->sequence, value); + return receive_failure(sdi, reason); + } device->pl_started = TRUE; struct pl_sample_block *block = &device->pl_reorder[value % PL_REORDER_BLOCKS];