From 53b6034272af14f6191c8a7cc5f47e1f9f8d0564 Mon Sep 17 00:00:00 2001 From: sys64738 Date: Thu, 21 Apr 2022 20:08:33 +0200 Subject: [PATCH] interfacing w/ rl78/g10 ocd works --- src/cli/rl78.c | 2 + src/tool78/tool78_cmds.c | 87 ++++++++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/src/cli/rl78.c b/src/cli/rl78.c index 5760e52..7037aa8 100644 --- a/src/cli/rl78.c +++ b/src/cli/rl78.c @@ -214,6 +214,8 @@ void cli_tool78_g10_ocdtest(void) { st = tool78_ocd_read(hw, 0x0080, 1, &val); printf("read: st=%d val=%02x\n", st, val); + busy_wait_ms(1000); + hw->deinit(); } diff --git a/src/tool78/tool78_cmds.c b/src/tool78/tool78_cmds.c index 3280dbd..a452d03 100644 --- a/src/tool78/tool78_cmds.c +++ b/src/tool78/tool78_cmds.c @@ -1183,14 +1183,29 @@ int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len, rr = hw->send(sizeof hdr, hdr, -1); if (rr != sizeof hdr) return -1; - rr = hw->recv(2, data, 1000); - if (rr != 2) return -2; - if (data[1] != 0x00) return -3; + // command echoed back + rr = hw->recv(4, hdr, 1000); + if (rr != 4) return -2; + if (hdr[0] == 0xff) { // frame error bullshit + hdr[0] = hdr[1]; + hdr[1] = hdr[2]; + hdr[2] = hdr[3]; + rr = hw->recv(1, &hdr[3], 1000); + if (rr != 1) return -2; + } + + // status + rr = hw->recv(1, hdr, 1000); + if (rr != 1) return -1; + if (hdr[0] != 0x00) return -3; hdr[0] = tool78ocd_cmdg10_read_word; rr = hw->send(1, hdr, -1); if (rr != 1) return -1; + rr = hw->recv(1, hdr, 1000); // command echoed back + if (rr != 1) return -1; + rr = hw->recv(2, data, 1000*len); if (rr != 2) return -2; return 0; @@ -1201,20 +1216,34 @@ int tool78_ocd_read(struct tool78_hw* hw, uint16_t off, uint8_t len, hdr[3] = len; // b rr = hw->send(sizeof hdr, hdr, -1); if (rr != sizeof hdr) return -1; - printf("sent hdr\n"); + //printf("sent hdr\n"); - rr = hw->recv(2, data, 1000); - printf("stat rr=%d data=%02x %02x\n", rr, data[0], data[1]); - if (rr != 2) return -2; - if (data[1] != 0x00) return -3; + rr = hw->recv(4, hdr, 1000); + //printf("stat rr=%d hdr=%02x %02x %02x %02x\n", rr, hdr[0], hdr[1], hdr[2], hdr[3]); + if (rr != 4) return -2; + if (hdr[0] == 0xff) { // frame error bullshit + hdr[0] = hdr[1]; + hdr[1] = hdr[2]; + hdr[2] = hdr[3]; + rr = hw->recv(1, &hdr[3], 1000); + if (rr != 1) return -2; + } + rr = hw->recv(1, hdr, 1000); + //printf("stat rr=%d hdr=%02x\n", rr, hdr[0]); + if (rr != 1) return -1; + if (hdr[0] != 0x00) return -3; hdr[0] = tool78ocd_cmdg10_read_raw; rr = hw->send(1, hdr, -1); if (rr != 1) return -1; - printf("sent rdcmd\n"); + //printf("sent rdcmd\n"); + + rr = hw->recv(1, hdr, 1000); // command echoed back + //printf("recv dd=%d hdr=%02x\n", rr, hdr[0]); + if (rr != 1) return -1; rr = hw->recv(len, data, 1000*len); - printf("got data rr=%d data=%02x\n", rr, data[0]); + //printf("got data rr=%d data=%02x\n", rr, data[0]); if (rr != len) return -2; return 0; } @@ -1259,16 +1288,32 @@ int tool78_ocd_write(struct tool78_hw* hw, uint16_t addr, uint8_t len, rr = hw->send(sizeof hdr, hdr, -1); if (rr != sizeof hdr) return -1; + // command echoed back + rr = hw->recv(4, hdr, 1000); + if (rr != 4) return -2; + if (hdr[0] == 0xff) { // frame error bullshit + hdr[0] = hdr[1]; + hdr[1] = hdr[2]; + hdr[2] = hdr[3]; + rr = hw->recv(1, &hdr[3], 1000); + if (rr != 1) return -2; + } + + // status + rr = hw->recv(1, hdr, 1000); + if (rr != 1) return -1; + if (hdr[0] != 0x00) return -3; + hdr[0] = tool78ocd_cmdg10_write_word; hdr[1] = data[0]; // a rr = hw->send(2, hdr, -1); if (rr != 2) return -1; - rr = hw->recv(2, hdr, 1000*len); - if (rr != 2) return -1; + rr = hw->recv(3, hdr, 1000); // command echoed back + ack + if (rr != 3) return -1; - return (hdr[1] == 0) ? 0 : -2; + return (hdr[2] == 0) ? 0 : -2; } else { hdr[0] = tool78ocd_cmdg10_setptr; hdr[1] = addr & 0xff; // l @@ -1278,6 +1323,22 @@ int tool78_ocd_write(struct tool78_hw* hw, uint16_t addr, uint8_t len, rr = hw->send(sizeof hdr, hdr, -1); if (rr != sizeof hdr) return -1; + // command echoed back + rr = hw->recv(4, hdr, 1000); + if (rr != 4) return -2; + if (hdr[0] == 0xff) { // frame error bullshit + hdr[0] = hdr[1]; + hdr[1] = hdr[2]; + hdr[2] = hdr[3]; + rr = hw->recv(1, &hdr[3], 1000); + if (rr != 1) return -2; + } + + // status + rr = hw->recv(1, hdr, 1000); + if (rr != 1) return -1; + if (hdr[0] != 0x00) return -3; + hdr[0] = tool78ocd_cmdg10_write_raw; rr = hw->send(1, hdr, -1);