diff options
Diffstat (limited to 'src/test_mbox.c')
| -rw-r--r-- | src/test_mbox.c | 113 |
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; +} |
