hosted/remote: Cleaned up the error handling so the compiler can usefully tell us of errors in conditions
This commit is contained in:
parent
fbe804f905
commit
826840bf90
|
@ -42,10 +42,10 @@ int remote_init(void)
|
||||||
platform_buffer_write((uint8_t *)construct, c);
|
platform_buffer_write((uint8_t *)construct, c);
|
||||||
c = platform_buffer_read((uint8_t *)construct, REMOTE_MAX_MSG_SIZE);
|
c = platform_buffer_read((uint8_t *)construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((c < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (c < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("Remote Start failed, error %s\n",
|
DEBUG_WARN("Remote Start failed, error %s\n",
|
||||||
c ? (char *)&(construct[1]) : "unknown");
|
c ? (char *)&(construct[1]) : "unknown");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
DEBUG_PROBE("Remote is %s\n", &construct[1]);
|
DEBUG_PROBE("Remote is %s\n", &construct[1]);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -62,13 +62,13 @@ bool remote_target_get_power(void)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN(" platform_target_get_power failed, error %s\n",
|
DEBUG_WARN("platform_target_get_power failed, error %s\n",
|
||||||
s ? (char *)&(construct[1]) : "unknown");
|
s ? (char *)&(construct[1]) : "unknown");
|
||||||
exit (-1);
|
exit (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (construct[1] == '1');
|
return construct[1] == '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool remote_target_set_power(bool power)
|
bool remote_target_set_power(bool power)
|
||||||
|
@ -82,9 +82,9 @@ bool remote_target_set_power(bool power)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("platform_target_set_power failed, error %s\n",
|
DEBUG_WARN("platform_target_set_power failed, error %s\n",
|
||||||
s ? (char *)&(construct[1]) : "unknown");
|
s ? (char *)&(construct[1]) : "unknown");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -101,10 +101,10 @@ void remote_nrst_set_val(bool assert)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("platform_srst_set_val failed, error %s\n",
|
DEBUG_WARN("platform_nrst_set_val failed, error %s\n",
|
||||||
s ? (char *)&(construct[1]) : "unknown");
|
s ? (char *)&(construct[1]) : "unknown");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,10 +119,10 @@ bool remote_nrst_get_val(void)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("platform_srst_set_val failed, error %s\n",
|
DEBUG_WARN("platform_nrst_set_val failed, error %s\n",
|
||||||
s ? (char *)&(construct[1]) : "unknown");
|
s ? (char *)&(construct[1]) : "unknown");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
return (construct[1] == '1');
|
return (construct[1] == '1');
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ void remote_max_frequency_set(uint32_t freq)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("Update Firmware to allow to set max SWJ frequency\n");
|
DEBUG_WARN("Update Firmware to allow to set max SWJ frequency\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ uint32_t remote_max_frequency_get(void)
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR))
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR)
|
||||||
return FREQ_FIXED;
|
return FREQ_FIXED;
|
||||||
|
|
||||||
uint32_t freq[1];
|
uint32_t freq[1];
|
||||||
|
@ -167,15 +167,15 @@ const char *remote_target_voltage(void)
|
||||||
int s;
|
int s;
|
||||||
|
|
||||||
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE," %s",
|
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE," %s",
|
||||||
REMOTE_VOLTAGE_STR);
|
REMOTE_VOLTAGE_STR);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
|
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("platform_target_voltage failed, error %s\n",
|
DEBUG_WARN("platform_target_voltage failed, error %s\n",
|
||||||
s ? (char *)&(construct[1]) : "unknown");
|
s ? (char *)&(construct[1]) : "unknown");
|
||||||
exit(- 1);
|
exit(- 1);
|
||||||
}
|
}
|
||||||
return (char *)&construct[1];
|
return (char *)&construct[1];
|
||||||
}
|
}
|
||||||
|
@ -185,10 +185,10 @@ static uint32_t remote_adiv5_dp_read(ADIv5_DP_t *dp, uint16_t addr)
|
||||||
(void)dp;
|
(void)dp;
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_DP_READ_STR,
|
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_DP_READ_STR,
|
||||||
dp->dp_jd_index, addr);
|
dp->dp_jd_index, addr);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("%s error %d\n", __func__, s);
|
DEBUG_WARN("%s error %d\n", __func__, s);
|
||||||
}
|
}
|
||||||
uint32_t dest[1];
|
uint32_t dest[1];
|
||||||
|
@ -203,10 +203,10 @@ static uint32_t remote_adiv5_low_access(
|
||||||
(void)dp;
|
(void)dp;
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,
|
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,
|
||||||
REMOTE_LOW_ACCESS_STR, dp->dp_jd_index, RnW, addr, value);
|
REMOTE_LOW_ACCESS_STR, dp->dp_jd_index, RnW, addr, value);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("%s error %d\n", __func__, s);
|
DEBUG_WARN("%s error %d\n", __func__, s);
|
||||||
}
|
}
|
||||||
uint32_t dest[1];
|
uint32_t dest[1];
|
||||||
|
@ -218,10 +218,10 @@ static uint32_t remote_adiv5_ap_read(ADIv5_AP_t *ap, uint16_t addr)
|
||||||
{
|
{
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_READ_STR,
|
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_READ_STR,
|
||||||
ap->dp->dp_jd_index, ap->apsel, addr);
|
ap->dp->dp_jd_index, ap->apsel, addr);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("%s error %d\n", __func__, s);
|
DEBUG_WARN("%s error %d\n", __func__, s);
|
||||||
}
|
}
|
||||||
uint32_t dest[1];
|
uint32_t dest[1];
|
||||||
|
@ -233,10 +233,10 @@ static void remote_adiv5_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value)
|
||||||
{
|
{
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_WRITE_STR,
|
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_WRITE_STR,
|
||||||
ap->dp->dp_jd_index, ap->apsel, addr, value);
|
ap->dp->dp_jd_index, ap->apsel, addr, value);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR)) {
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR) {
|
||||||
DEBUG_WARN("%s error %d\n", __func__, s);
|
DEBUG_WARN("%s error %d\n", __func__, s);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -250,7 +250,7 @@ static void remote_mem_read(
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
DEBUG_WIRE("memread @ %" PRIx32 " len %ld, start: \n",
|
DEBUG_WIRE("memread @ %" PRIx32 " len %ld, start: \n",
|
||||||
src, len);
|
src, len);
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s;
|
int s;
|
||||||
int batchsize = (REMOTE_MAX_MSG_SIZE - 32) / 2;
|
int batchsize = (REMOTE_MAX_MSG_SIZE - 32) / 2;
|
||||||
|
@ -263,7 +263,7 @@ static void remote_mem_read(
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
|
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s > 0) && (construct[0] == REMOTE_RESP_OK)) {
|
if (s > 0 && construct[0] == REMOTE_RESP_OK) {
|
||||||
unhexify(dest, (const char*)&construct[1], count);
|
unhexify(dest, (const char*)&construct[1], count);
|
||||||
src += count;
|
src += count;
|
||||||
dest += count;
|
dest += count;
|
||||||
|
@ -293,30 +293,30 @@ static void remote_ap_mem_read(
|
||||||
return;
|
return;
|
||||||
char construct[REMOTE_MAX_MSG_SIZE];
|
char construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int batchsize = (REMOTE_MAX_MSG_SIZE - 0x20) / 2;
|
int batchsize = (REMOTE_MAX_MSG_SIZE - 0x20) / 2;
|
||||||
while(len) {
|
while (len) {
|
||||||
int s;
|
int s;
|
||||||
int count = len;
|
int count = len;
|
||||||
if (count > batchsize)
|
if (count > batchsize)
|
||||||
count = batchsize;
|
count = batchsize;
|
||||||
s = snprintf(construct, REMOTE_MAX_MSG_SIZE,
|
s = snprintf(construct, REMOTE_MAX_MSG_SIZE, REMOTE_AP_MEM_READ_STR,
|
||||||
REMOTE_AP_MEM_READ_STR, ap->dp->dp_jd_index, ap->apsel, ap->csw, src, count);
|
ap->dp->dp_jd_index, ap->apsel, ap->csw, src, count);
|
||||||
platform_buffer_write((uint8_t*)construct, s);
|
platform_buffer_write((uint8_t*)construct, s);
|
||||||
s = platform_buffer_read((uint8_t*)construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read((uint8_t*)construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s > 0) && (construct[0] == REMOTE_RESP_OK)) {
|
if (s > 0 && construct[0] == REMOTE_RESP_OK) {
|
||||||
unhexify(dest, (const char*)&construct[1], count);
|
unhexify(dest, (const char*)&construct[1], count);
|
||||||
src += count;
|
src += count;
|
||||||
dest += count;
|
dest += count;
|
||||||
len -= count;
|
len -= count;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if(construct[0] == REMOTE_RESP_ERR) {
|
if (construct[0] == REMOTE_RESP_ERR) {
|
||||||
ap->dp->fault = 1;
|
ap->dp->fault = 1;
|
||||||
DEBUG_WARN("%s returned REMOTE_RESP_ERR at apsel %d, "
|
DEBUG_WARN("%s returned REMOTE_RESP_ERR at apsel %d, "
|
||||||
"addr: 0x%08" PRIx32 "\n", __func__, ap->apsel, src);
|
"addr: 0x%08" PRIx32 "\n", __func__, ap->apsel, src);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
DEBUG_WARN("%s error %d around 0x%08" PRIx32 "\n",
|
DEBUG_WARN("%s error %d around 0x%08" PRIx32 "\n",
|
||||||
__func__, s, src);
|
__func__, s, src);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,9 +337,8 @@ static void remote_ap_mem_write_sized(
|
||||||
int count = len;
|
int count = len;
|
||||||
if (count > batchsize)
|
if (count > batchsize)
|
||||||
count = batchsize;
|
count = batchsize;
|
||||||
int s = snprintf(construct, REMOTE_MAX_MSG_SIZE,
|
int s = snprintf(construct, REMOTE_MAX_MSG_SIZE, REMOTE_AP_MEM_WRITE_SIZED_STR,
|
||||||
REMOTE_AP_MEM_WRITE_SIZED_STR,
|
ap->dp->dp_jd_index, ap->apsel, ap->csw, align, dest, count);
|
||||||
ap->dp->dp_jd_index, ap->apsel, ap->csw, align, dest, count);
|
|
||||||
char *p = construct + s;
|
char *p = construct + s;
|
||||||
hexify(p, src, count);
|
hexify(p, src, count);
|
||||||
p += 2 * count;
|
p += 2 * count;
|
||||||
|
@ -351,15 +350,15 @@ static void remote_ap_mem_write_sized(
|
||||||
platform_buffer_write((uint8_t*)construct, p - construct);
|
platform_buffer_write((uint8_t*)construct, p - construct);
|
||||||
|
|
||||||
s = platform_buffer_read((uint8_t*)construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read((uint8_t*)construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s > 0) && (construct[0] == REMOTE_RESP_OK))
|
if (s > 0 && construct[0] == REMOTE_RESP_OK)
|
||||||
continue;
|
continue;
|
||||||
if ((s > 0) && (construct[0] == REMOTE_RESP_ERR)) {
|
if (s > 0 && construct[0] == REMOTE_RESP_ERR) {
|
||||||
ap->dp->fault = 1;
|
ap->dp->fault = 1;
|
||||||
DEBUG_WARN("%s returned REMOTE_RESP_ERR at apsel %d, "
|
DEBUG_WARN("%s returned REMOTE_RESP_ERR at apsel %d, "
|
||||||
"addr: 0x%08x\n", __func__, ap->apsel, dest);
|
"addr: 0x%08x\n", __func__, ap->apsel, dest);
|
||||||
} else {
|
} else {
|
||||||
DEBUG_WARN("%s error %d around address 0x%08" PRIx32 "\n",
|
DEBUG_WARN("%s error %d around address 0x%08" PRIx32 "\n",
|
||||||
__func__, s, dest);
|
__func__, s, dest);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,13 +368,12 @@ void remote_adiv5_dp_defaults(ADIv5_DP_t *dp)
|
||||||
{
|
{
|
||||||
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
uint8_t construct[REMOTE_MAX_MSG_SIZE];
|
||||||
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s",
|
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s",
|
||||||
REMOTE_HL_CHECK_STR);
|
REMOTE_HL_CHECK_STR);
|
||||||
platform_buffer_write(construct, s);
|
platform_buffer_write(construct, s);
|
||||||
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
|
||||||
if ((s < 1) || (construct[0] == REMOTE_RESP_ERR) ||
|
if (s < 1 || construct[0] == REMOTE_RESP_ERR ||
|
||||||
((construct[1] - '0') < REMOTE_HL_VERSION)) {
|
construct[1] - '0' < REMOTE_HL_VERSION) {
|
||||||
DEBUG_WARN(
|
DEBUG_WARN("Please update BMP firmware for substantial speed increase!\n");
|
||||||
"Please update BMP firmware for substantial speed increase!\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dp->low_access = remote_adiv5_low_access;
|
dp->low_access = remote_adiv5_low_access;
|
||||||
|
|
Loading…
Reference in New Issue