Remove dp_low_read() and use exception protected dp_read()
This commit is contained in:
parent
f9d343af3e
commit
4f36c1ddf8
|
@ -26,7 +26,6 @@ struct exception *innermost_exception;
|
||||||
void raise_exception(uint32_t type, const char *msg)
|
void raise_exception(uint32_t type, const char *msg)
|
||||||
{
|
{
|
||||||
struct exception *e;
|
struct exception *e;
|
||||||
DEBUG_WARN("Exception: %s\n", msg);
|
|
||||||
for (e = innermost_exception; e; e = e->outer) {
|
for (e = innermost_exception; e; e = e->outer) {
|
||||||
if (e->mask & type) {
|
if (e->mask & type) {
|
||||||
e->type = type;
|
e->type = type;
|
||||||
|
@ -35,6 +34,7 @@ void raise_exception(uint32_t type, const char *msg)
|
||||||
longjmp(e->jmpbuf, type);
|
longjmp(e->jmpbuf, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DEBUG_WARN("Unhandled exception: %s\n", msg);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -415,36 +415,6 @@ int dap_jtag_dp_init(ADIv5_DP_t *dp)
|
||||||
|
|
||||||
#define SWD_SEQUENCE_IN 0x80
|
#define SWD_SEQUENCE_IN 0x80
|
||||||
#define DAP_SWD_SEQUENCE 0x1d
|
#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)
|
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);
|
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);
|
dap_reset_link(false);
|
||||||
if (has_swd_sequence) {
|
if (has_swd_sequence) {
|
||||||
/* DAP_SWD_SEQUENCE does not do auto turnaround, use own!*/
|
/* 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;
|
dp->dp_low_write = dap_dp_low_write;
|
||||||
} else {
|
} else {
|
||||||
dp->error = dap_dp_error;
|
dp->error = dap_dp_error;
|
||||||
|
|
|
@ -173,8 +173,6 @@ typedef struct ADIv5_DP_s {
|
||||||
/* dp_low_write returns true if no OK resonse. */
|
/* dp_low_write returns true if no OK resonse. */
|
||||||
bool (*dp_low_write)(struct ADIv5_DP_s *dp, uint16_t addr,
|
bool (*dp_low_write)(struct ADIv5_DP_s *dp, uint16_t addr,
|
||||||
const uint32_t data);
|
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 (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr);
|
||||||
uint32_t (*error)(struct ADIv5_DP_s *dp);
|
uint32_t (*error)(struct ADIv5_DP_s *dp);
|
||||||
uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW,
|
uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW,
|
||||||
|
|
|
@ -61,14 +61,6 @@ bool firmware_dp_low_write(ADIv5_DP_t *dp, uint16_t addr, const uint32_t data)
|
||||||
return (res != 1);
|
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.
|
/* Try first the dormant to SWD procedure.
|
||||||
* If target id given, scan DPs 0 .. 15 on that device and return.
|
* If target id given, scan DPs 0 .. 15 on that device and return.
|
||||||
* Otherwise
|
* Otherwise
|
||||||
|
@ -78,7 +70,6 @@ int adiv5_swdp_scan(uint32_t targetid)
|
||||||
target_list_free();
|
target_list_free();
|
||||||
ADIv5_DP_t idp = {
|
ADIv5_DP_t idp = {
|
||||||
.dp_low_write = firmware_dp_low_write,
|
.dp_low_write = firmware_dp_low_write,
|
||||||
.dp_low_read = firmware_dp_low_read,
|
|
||||||
.error = firmware_swdp_error,
|
.error = firmware_swdp_error,
|
||||||
.dp_read = firmware_swdp_read,
|
.dp_read = firmware_swdp_read,
|
||||||
.low_access = firmware_swdp_low_access,
|
.low_access = firmware_swdp_low_access,
|
||||||
|
@ -108,8 +99,7 @@ int adiv5_swdp_scan(uint32_t targetid)
|
||||||
dp_line_reset(initial_dp);
|
dp_line_reset(initial_dp);
|
||||||
volatile struct exception e;
|
volatile struct exception e;
|
||||||
TRY_CATCH (e, EXCEPTION_ALL) {
|
TRY_CATCH (e, EXCEPTION_ALL) {
|
||||||
idcode = initial_dp->low_access(initial_dp, ADIV5_LOW_READ,
|
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
|
||||||
ADIV5_DP_IDCODE, 0);
|
|
||||||
}
|
}
|
||||||
if (e.type || initial_dp->fault) {
|
if (e.type || initial_dp->fault) {
|
||||||
is_v2 = false;
|
is_v2 = false;
|
||||||
|
@ -121,8 +111,7 @@ int adiv5_swdp_scan(uint32_t targetid)
|
||||||
initial_dp->fault = 0;
|
initial_dp->fault = 0;
|
||||||
volatile struct exception e2;
|
volatile struct exception e2;
|
||||||
TRY_CATCH (e2, EXCEPTION_ALL) {
|
TRY_CATCH (e2, EXCEPTION_ALL) {
|
||||||
idcode = initial_dp->low_access(initial_dp, ADIV5_LOW_READ,
|
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
|
||||||
ADIV5_DP_IDCODE, 0);
|
|
||||||
}
|
}
|
||||||
if (e2.type || initial_dp->fault) {
|
if (e2.type || initial_dp->fault) {
|
||||||
DEBUG_WARN("No usable DP found\n");
|
DEBUG_WARN("No usable DP found\n");
|
||||||
|
@ -153,16 +142,19 @@ int adiv5_swdp_scan(uint32_t targetid)
|
||||||
} else {
|
} else {
|
||||||
target_id = targetid;
|
target_id = targetid;
|
||||||
}
|
}
|
||||||
int nr_dps = (is_v2) ? 16: 1;
|
volatile int nr_dps = (is_v2) ? 16: 1;
|
||||||
uint32_t dp_targetid;
|
volatile uint32_t dp_targetid;
|
||||||
for (int i = 0; i < nr_dps; i++) {
|
for (volatile int i = 0; i < nr_dps; i++) {
|
||||||
if (is_v2) {
|
if (is_v2) {
|
||||||
dp_line_reset(initial_dp);
|
dp_line_reset(initial_dp);
|
||||||
dp_targetid = (i << 28) | (target_id & 0x0fffffff);
|
dp_targetid = (i << 28) | (target_id & 0x0fffffff);
|
||||||
initial_dp->dp_low_write(initial_dp, ADIV5_DP_TARGETSEL,
|
initial_dp->dp_low_write(initial_dp, ADIV5_DP_TARGETSEL,
|
||||||
dp_targetid);
|
dp_targetid);
|
||||||
if (initial_dp->dp_low_read(initial_dp, ADIV5_DP_IDCODE,
|
volatile struct exception e;
|
||||||
&idcode)) {
|
TRY_CATCH (e, EXCEPTION_ALL) {
|
||||||
|
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
|
||||||
|
}
|
||||||
|
if (e.type || initial_dp->fault) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -202,8 +194,8 @@ uint32_t firmware_swdp_read(ADIv5_DP_t *dp, uint16_t addr)
|
||||||
* => Reselect with right target! */
|
* => Reselect with right target! */
|
||||||
dp_line_reset(dp);
|
dp_line_reset(dp);
|
||||||
dp->dp_low_write(dp, ADIV5_DP_TARGETSEL, dp->targetid);
|
dp->dp_low_write(dp, ADIV5_DP_TARGETSEL, dp->targetid);
|
||||||
uint32_t dummy;
|
dp->dp_read(dp, ADIV5_DP_IDCODE);
|
||||||
dp->dp_low_read(dp, ADIV5_DP_IDCODE, &dummy);
|
/* Exception here is unexpected, so do not catch */
|
||||||
}
|
}
|
||||||
uint32_t err, clr = 0;
|
uint32_t err, clr = 0;
|
||||||
err = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) &
|
err = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) &
|
||||||
|
|
Loading…
Reference in New Issue