summaryrefslogtreecommitdiff
path: root/src/test_mbox.c
diff options
context:
space:
mode:
authorCharlie Root <root@dangofactory.local>2026-10-25 10:15:31 +0900
committerCharlie Root <root@dangofactory.local>2026-10-25 10:15:31 +0900
commit7318435b737394904bb1c5ce9fe013b0eee1882f (patch)
tree41adf14909f5f8d15c8e1c5db361e6ea0ac97598 /src/test_mbox.c
downloadmpegcap-baseline-1016.tar.gz
mpegcap-baseline-1016.zip
kare / spoon - CX23416 + FX2 USB MPEG capture toolHEADbaseline-1016
Capture tool for the I-O DATA GV-MVP/RZ2 (04bb:0514): Conexant CX23416 MPEG encoder behind an EZ-USB FX2 bridge, with a CX25837 video decoder (I2C 0x44) and a WM8739 audio ADC (I2C 0x1a). libusb-1.0, C99, built with GNU make on FreeBSD/Linux. kare capture: MPEG-2 PS or raw HM12 (y4m), MPEG audio, --pcm WAV, live parameter control through CTLFILE spoon live viewer: pipe -> ffmpeg -> SDL2, clickable control bar, resizable window, raw PCM playback on -r State at this commit: - MPEG-2 PS 720x480 ~6.5 Mbit/s, colour, mp2 48 kHz stereo 224 kbit/s - raw HM12 (NV12_16L16, 518,416-byte frames) with selective median denoise - S-Video works: luma In1 + chroma In5 (0x103=0xd0); RCA is In2+In6 (0xe1) - VBI cropped: 0x0474=24 with 0x0477=28 (they must move together, +4) - audio: never issue an I2C READ to the WM8739 (write-only part) History note: this repository was squashed to a single commit on 2026-10-25 because the earlier history carried the CX23416 firmware images and the vendor trees. Those still exist on the working copy (firmware/, ref/) and are in .gitignore; only src/, include/, Makefile, README.md and .gitignore are versioned. The pre-squash history is preserved locally as a bundle.
Diffstat (limited to 'src/test_mbox.c')
-rw-r--r--src/test_mbox.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/test_mbox.c b/src/test_mbox.c
new file mode 100644
index 0000000..f991761
--- /dev/null
+++ b/src/test_mbox.c
@@ -0,0 +1,113 @@
+/*
+ * test_mbox.c - isolate the MBOX read/write path
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "pvrusb2.h"
+
+static void msleep(int ms){struct timespec ts={ms/1000,(long)(ms%1000)*1000000L};nanosleep(&ts,NULL);}
+
+int main(int argc, char **argv)
+{
+ pvr2_dev *p = calloc(1, sizeof(*p));
+ uint8_t *fw; size_t fwlen;
+ const char *fwp = argc > 1 ? argv[1] : "firmware/cx23416/cx_1_swapped.bin";
+ uint8_t in[256];
+ int n;
+
+ pvr2_init(p);
+ p->verbose = 1;
+ pvr2_find_device(p, DEFAULT_VID, DEFAULT_PID);
+
+ /* ---- exactly the mpegcapt.c sequence ---- */
+ pvr2_simple_cmd(p, 0xde, NULL, 0);
+ pvr2_simple_cmd(p, 0x0b, NULL, 0);
+ (void)bulk_cmd_in(p, in, sizeof(in));
+ pvr2_simple_cmd(p, 0xeb, NULL, 0);
+ (void)bulk_cmd_in(p, in, sizeof(in));
+
+ pvr2_write_reg(p, 0x0048, 0xffffffff);
+ pvr2_gpio_dir(p, 0xffffffff, 0x00000088);
+ pvr2_gpio_out(p, 0xffffffff, 0x00000008);
+ pvr2_simple_cmd(p, 0xdd, NULL, 0);
+ pvr2_write_reg(p, 0xa064, 0);
+ pvr2_gpio_dir(p, 0xffffffff, 0x00000408);
+ pvr2_gpio_out(p, 0xffffffff, 0x00000008);
+ pvr2_write_reg(p, 0x9058, 0xffffffed);
+ pvr2_write_reg(p, 0x9054, 0xfffffffd);
+ pvr2_write_reg(p, 0x07f8, 0x80000800);
+ pvr2_write_reg(p, 0x07fc, 0x1a);
+ pvr2_write_reg(p, 0x0700, 0);
+ pvr2_write_reg(p, 0xaa00, 0);
+ pvr2_write_reg(p, 0xaa04, 0x57810);
+ pvr2_write_reg(p, 0xaa10, 0x148500);
+ pvr2_write_reg(p, 0xaa18, 0x840000);
+ pvr2_simple_cmd(p, 0x52, NULL, 0);
+ pvr2_simple_cmd(p, 0x06, &(uint8_t){0}, 1);
+
+ if (pvr2_load_file(fwp, &fw, &fwlen) < 0) return 1;
+ if (pvr2_upload_firmware2(p, fw, fwlen) < 0) return 1;
+
+ pvr2_write_reg(p, 0x9054, 0xffffffff);
+ pvr2_write_reg(p, 0x9058, 0xffffffe8);
+ pvr2_simple_cmd(p, 0x06, &(uint8_t){0}, 1);
+
+ /* --- raw MBOX read, exactly like mpegcapt readmem(0x44) --- */
+ printf("\n=== raw single-word MBOX read at 0x44 (mpegcapt style) ===\n");
+ {
+ uint8_t b[8];
+ memset(b, 0, 8);
+ b[0] = 0x02;
+ b[5] = 0x00; b[6] = 0x00; b[7] = 0x44;
+ pvr2_simple_cmd(p, 0, NULL, 0); /* noop to flush? */
+ bulk_cmd_out(p, b, 8);
+ n = bulk_cmd_in(p, in, sizeof(in));
+ printf("read %d bytes:", n);
+ { int i; for (i = 0; i < n && i < 8; i++) printf(" %02x", in[i]); }
+ printf("\n");
+ }
+
+ /* --- write a known pattern to MBOX then read it back --- */
+ printf("\n=== MBOX write/readback test (addr 0x44, 4 words) ===\n");
+ {
+ uint32_t wr[4] = { 0x11223344, 0x55667788, 0x99aabbcc, 0xddeeff00 };
+ uint32_t rd[4] = {0};
+ int i;
+ if (pvr2_mbox_write(p, 0x44, wr, 4) < 0) printf("write FAILED\n");
+ msleep(50);
+ if (pvr2_mbox_read(p, 0x44, rd, 4) < 0) printf("read FAILED\n");
+ for (i = 0; i < 4; i++)
+ printf(" wr %08x -> rd %08x %s\n", wr[i], rd[i],
+ wr[i] == rd[i] ? "OK" : "MISMATCH");
+ }
+
+ /* --- now try the PING handshake with verbose tracing --- */
+ printf("\n=== PING handshake ===\n");
+ {
+ uint32_t data[16];
+ uint32_t stat;
+ int i;
+ for (i = 0; i < 16; i++) data[i] = 0;
+ data[0] = 0; data[1] = 0x80; data[2] = 0; data[3] = 0x00060000;
+ printf("writing 12 words...\n");
+ if (pvr2_mbox_write(p, 0x44, data, 12) < 0) printf(" write fail\n");
+ {
+ uint32_t go = 3;
+ printf("writing go word (3)...\n");
+ if (pvr2_mbox_write(p, 0x44, &go, 1) < 0) printf(" go fail\n");
+ }
+ for (i = 0; i < 20; i++) {
+ if (pvr2_mbox_read(p, 0x44, &stat, 1) < 0) { printf(" read fail\n"); break; }
+ printf(" poll %d: mbox[0] = %08x%s\n", i, stat,
+ (stat & 4) ? " <-- FIRMWARE_DONE" : "");
+ if (stat & 4) break;
+ msleep(50);
+ }
+ }
+
+ free(fw);
+ pvr2_exit(p);
+ return 0;
+}