interfacing w/ rl78/g10 ocd works
This commit is contained in:
parent
72371a13fd
commit
53b6034272
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue