Remove dp_low_read() and use exception protected dp_read()

This commit is contained in:
Uwe Bonnes 2021-10-23 18:07:25 +02:00
parent f9d343af3e
commit 4f36c1ddf8
4 changed files with 13 additions and 54 deletions

View File

@ -26,7 +26,6 @@ struct exception *innermost_exception;
void raise_exception(uint32_t type, const char *msg)
{
struct exception *e;
DEBUG_WARN("Exception: %s\n", msg);
for (e = innermost_exception; e; e = e->outer) {
if (e->mask & type) {
e->type = type;
@ -35,6 +34,7 @@ void raise_exception(uint32_t type, const char *msg)
longjmp(e->jmpbuf, type);
}
}
DEBUG_WARN("Unhandled exception: %s\n", msg);
abort();
}

View File

@ -415,36 +415,6 @@ int dap_jtag_dp_init(ADIv5_DP_t *dp)
#define SWD_SEQUENCE_IN 0x80
#define DAP_SWD_SEQUENCE 0x1d
/* DAP_SWD_SEQUENCE does not do auto turnaround*/
static bool dap_dp_low_read(ADIv5_DP_t *dp, uint16_t addr, uint32_t *res)
{
(void)dp;
unsigned int paket_request = make_packet_request(ADIV5_LOW_READ, addr);
uint8_t buf[32] = {
DAP_SWD_SEQUENCE,
5,
8,
paket_request,
4 + SWD_SEQUENCE_IN, /* one turn-around + read 3 bit ACK */
32 + SWD_SEQUENCE_IN, /* read 32 bit data */
1 + SWD_SEQUENCE_IN, /* read parity bit */
1, /* one bit turn around to drive SWDIO */
0
};
dbg_dap_cmd(buf, sizeof(buf), 9);
if (buf[0])
DEBUG_WARN("dap_dp_low_read failed\n");
uint32_t ack = (buf[1] >> 1) & 7;
uint32_t data = (buf[2] << 0) + (buf[3] << 8) + (buf[4] << 16)
+ (buf[5] << 24);
int parity = __builtin_parity(data);
bool ret = ((parity != buf[6]) || (ack != 1));
*res = data;
DEBUG_PROBE("dap_dp_low_read ack %d, res %08" PRIx32 ", parity %s\n", ack,
data, (ret)? "ERR": "OK");
return ret;
}
static bool dap_dp_low_write(ADIv5_DP_t *dp, uint16_t addr, const uint32_t data)
{
DEBUG_PROBE("dap_dp_low_write %08" PRIx32 "\n", data);
@ -485,7 +455,6 @@ int dap_swdptap_init(ADIv5_DP_t *dp)
dap_reset_link(false);
if (has_swd_sequence) {
/* DAP_SWD_SEQUENCE does not do auto turnaround, use own!*/
dp->dp_low_read = dap_dp_low_read;
dp->dp_low_write = dap_dp_low_write;
} else {
dp->error = dap_dp_error;

View File

@ -173,8 +173,6 @@ typedef struct ADIv5_DP_s {
/* dp_low_write returns true if no OK resonse. */
bool (*dp_low_write)(struct ADIv5_DP_s *dp, uint16_t addr,
const uint32_t data);
/* dp_low_read returns true with parity error */
bool (*dp_low_read)(struct ADIv5_DP_s *dp, uint16_t addr, uint32_t *data);
uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr);
uint32_t (*error)(struct ADIv5_DP_s *dp);
uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW,

View File

@ -61,14 +61,6 @@ bool firmware_dp_low_write(ADIv5_DP_t *dp, uint16_t addr, const uint32_t data)
return (res != 1);
}
static bool firmware_dp_low_read(ADIv5_DP_t *dp, uint16_t addr, uint32_t *res)
{
unsigned int request = make_packet_request(ADIV5_LOW_READ, addr & 0xf);
dp->seq_out(request, 8);
dp->seq_in(3);
return dp->seq_in_parity(res, 32);
}
/* Try first the dormant to SWD procedure.
* If target id given, scan DPs 0 .. 15 on that device and return.
* Otherwise
@ -78,7 +70,6 @@ int adiv5_swdp_scan(uint32_t targetid)
target_list_free();
ADIv5_DP_t idp = {
.dp_low_write = firmware_dp_low_write,
.dp_low_read = firmware_dp_low_read,
.error = firmware_swdp_error,
.dp_read = firmware_swdp_read,
.low_access = firmware_swdp_low_access,
@ -108,8 +99,7 @@ int adiv5_swdp_scan(uint32_t targetid)
dp_line_reset(initial_dp);
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
idcode = initial_dp->low_access(initial_dp, ADIV5_LOW_READ,
ADIV5_DP_IDCODE, 0);
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
}
if (e.type || initial_dp->fault) {
is_v2 = false;
@ -121,8 +111,7 @@ int adiv5_swdp_scan(uint32_t targetid)
initial_dp->fault = 0;
volatile struct exception e2;
TRY_CATCH (e2, EXCEPTION_ALL) {
idcode = initial_dp->low_access(initial_dp, ADIV5_LOW_READ,
ADIV5_DP_IDCODE, 0);
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
}
if (e2.type || initial_dp->fault) {
DEBUG_WARN("No usable DP found\n");
@ -153,16 +142,19 @@ int adiv5_swdp_scan(uint32_t targetid)
} else {
target_id = targetid;
}
int nr_dps = (is_v2) ? 16: 1;
uint32_t dp_targetid;
for (int i = 0; i < nr_dps; i++) {
volatile int nr_dps = (is_v2) ? 16: 1;
volatile uint32_t dp_targetid;
for (volatile int i = 0; i < nr_dps; i++) {
if (is_v2) {
dp_line_reset(initial_dp);
dp_targetid = (i << 28) | (target_id & 0x0fffffff);
initial_dp->dp_low_write(initial_dp, ADIV5_DP_TARGETSEL,
dp_targetid);
if (initial_dp->dp_low_read(initial_dp, ADIV5_DP_IDCODE,
&idcode)) {
volatile struct exception e;
TRY_CATCH (e, EXCEPTION_ALL) {
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
}
if (e.type || initial_dp->fault) {
continue;
}
} else {
@ -202,8 +194,8 @@ uint32_t firmware_swdp_read(ADIv5_DP_t *dp, uint16_t addr)
* => Reselect with right target! */
dp_line_reset(dp);
dp->dp_low_write(dp, ADIV5_DP_TARGETSEL, dp->targetid);
uint32_t dummy;
dp->dp_low_read(dp, ADIV5_DP_IDCODE, &dummy);
dp->dp_read(dp, ADIV5_DP_IDCODE);
/* Exception here is unexpected, so do not catch */
}
uint32_t err, clr = 0;
err = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) &