diff --git a/src/remote.c b/src/remote.c index 06c04fa..ebaf2e9 100644 --- a/src/remote.c +++ b/src/remote.c @@ -61,68 +61,64 @@ uint64_t remotehston(uint32_t limit, char *s) } #if PC_HOSTED == 0 -static void _send_buf(uint8_t* buffer, size_t len) +static void remote_send_buf(uint8_t *buffer, size_t len) { - uint8_t* p = buffer; + uint8_t *p = buffer; char hex[2]; do { - hexify(hex, (const void*)p++, 1); + hexify(hex, (const void *)p++, 1); gdb_if_putchar(hex[0], 0); gdb_if_putchar(hex[1], 0); - } while (p<(buffer+len)); + } while (p < (buffer + len)); } -static void _respond_buf(char respCode, uint8_t* buffer, size_t len) +static void remote_respond_buf(char respCode, uint8_t *buffer, size_t len) { gdb_if_putchar(REMOTE_RESP, 0); gdb_if_putchar(respCode, 0); - _send_buf(buffer, len); + remote_send_buf(buffer, len); gdb_if_putchar(REMOTE_EOM, 1); } - -static void _respond(char respCode, uint64_t param) - /* Send response to far end */ - +static void remote_respond(char respCode, uint64_t param) { char buf[35]; /*Response, code, EOM and 2*16 hex nibbles*/ - char *p=buf; + char *p = buf; - gdb_if_putchar(REMOTE_RESP,0); - gdb_if_putchar(respCode,0); + gdb_if_putchar(REMOTE_RESP, 0); + gdb_if_putchar(respCode, 0); do { - *p++=NTOH((param&0x0f)); - param>>=4; - } - while (param); + *p++ = NTOH((param & 0x0f)); + param >>= 4; + } while (param); /* At this point the number to print is the buf, but backwards, so spool it out */ do { - gdb_if_putchar(*--p,0); - } while (p>buf); - gdb_if_putchar(REMOTE_EOM,1); + gdb_if_putchar(*--p, 0); + } while (p > buf); + gdb_if_putchar(REMOTE_EOM, 1); } -static void _respondS(char respCode, const char *s) +static void remote_respond_string(char respCode, const char *s) /* Send response to far end */ { - gdb_if_putchar(REMOTE_RESP,0); - gdb_if_putchar(respCode,0); + gdb_if_putchar(REMOTE_RESP, 0); + gdb_if_putchar(respCode, 0); while (*s) { /* Just clobber illegal characters so they don't disturb the protocol */ - if ((*s=='$') || (*s==REMOTE_SOM) || (*s==REMOTE_EOM)) + if ((*s == '$') || (*s == REMOTE_SOM) || (*s == REMOTE_EOM)) gdb_if_putchar(' ', 0); else gdb_if_putchar(*s, 0); s++; - } - gdb_if_putchar(REMOTE_EOM,1); + } + gdb_if_putchar(REMOTE_EOM, 1); } static ADIv5_DP_t remote_dp = { @@ -146,40 +142,40 @@ static void remotePacketProcessSWD(unsigned i, char *packet) remote_dp.low_access = firmware_swdp_low_access; remote_dp.abort = firmware_swdp_abort; swdptap_init(&remote_dp); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); } else { - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); } break; case REMOTE_IN_PAR: /* SI = In parity ============================= */ ticks=remotehston(2,&packet[2]); badParity = remote_dp.seq_in_parity(¶m, ticks); - _respond(badParity?REMOTE_RESP_PARERR:REMOTE_RESP_OK,param); + remote_respond(badParity?REMOTE_RESP_PARERR:REMOTE_RESP_OK,param); break; case REMOTE_IN: /* Si = In ======================================= */ ticks=remotehston(2,&packet[2]); param = remote_dp.seq_in(ticks); - _respond(REMOTE_RESP_OK,param); + remote_respond(REMOTE_RESP_OK,param); break; case REMOTE_OUT: /* So= Out ====================================== */ ticks=remotehston(2,&packet[2]); param=remotehston(-1, &packet[4]); remote_dp.seq_out(param, ticks); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_OUT_PAR: /* SO = Out parity ========================== */ ticks=remotehston(2,&packet[2]); param=remotehston(-1, &packet[4]); remote_dp.seq_out_parity(param, ticks); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; default: - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); break; } } @@ -197,12 +193,12 @@ static void remotePacketProcessJTAG(unsigned i, char *packet) remote_dp.low_access = fw_adiv5_jtagdp_low_access; remote_dp.abort = adiv5_jtagdp_abort; jtagtap_init(); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_RESET: /* JR = reset ================================= */ jtag_proc.jtagtap_reset(); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_TMS: /* JT = TMS Sequence ============================ */ @@ -210,10 +206,10 @@ static void remotePacketProcessJTAG(unsigned i, char *packet) MS=remotehston(2,&packet[4]); if (i<4) { - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); } else { jtag_proc.jtagtap_tms_seq( MS, ticks); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); } break; @@ -221,7 +217,7 @@ static void remotePacketProcessJTAG(unsigned i, char *packet) case REMOTE_TDITDO_NOTMS: if (i<5) { - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); } else { ticks=remotehston(2,&packet[2]); DI=remotehston(-1,&packet[4]); @@ -231,22 +227,22 @@ static void remotePacketProcessJTAG(unsigned i, char *packet) if (ticks < 64) DO &= (1LL << ticks) - 1; - _respond(REMOTE_RESP_OK, DO); + remote_respond(REMOTE_RESP_OK, DO); } break; case REMOTE_NEXT: /* JN = NEXT ======================================== */ if (i != 4) - _respond(REMOTE_RESP_ERR, REMOTE_ERROR_WRONGLEN); + remote_respond(REMOTE_RESP_ERR, REMOTE_ERROR_WRONGLEN); else { uint32_t dat = jtag_proc.jtagtap_next(packet[2] == '1', packet[3] == '1'); - _respond(REMOTE_RESP_OK, dat); + remote_respond(REMOTE_RESP_OK, dat); } break; case REMOTE_ADD_JTAG_DEV: /* JJ = fill firmware jtag_devs */ if (i < 22) { - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); } else { memset(&jtag_dev, 0, sizeof(jtag_dev)); uint8_t index = remotehston(2, &packet[ 2]); @@ -257,12 +253,12 @@ static void remotePacketProcessJTAG(unsigned i, char *packet) jtag_dev.ir_postscan = remotehston(2, &packet[12]); jtag_dev.current_ir = remotehston(8, &packet[14]); jtag_add_device(index, &jtag_dev); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); } break; default: - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); break; } } @@ -274,24 +270,24 @@ static void remotePacketProcessGEN(unsigned i, char *packet) uint32_t freq; switch (packet[1]) { case REMOTE_VOLTAGE: - _respondS(REMOTE_RESP_OK, platform_target_voltage()); + remote_respond_string(REMOTE_RESP_OK, platform_target_voltage()); break; case REMOTE_NRST_SET: platform_nrst_set_val(packet[2] == '1'); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_NRST_GET: - _respond(REMOTE_RESP_OK, platform_nrst_get_val()); + remote_respond(REMOTE_RESP_OK, platform_nrst_get_val()); break; case REMOTE_FREQ_SET: platform_max_frequency_set( remotehston(8, packet + 2)); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_FREQ_GET: freq = platform_max_frequency_get(); - _respond_buf(REMOTE_RESP_OK, (uint8_t*)&freq, 4); + remote_respond_buf(REMOTE_RESP_OK, (uint8_t*)&freq, 4); break; case REMOTE_PWR_SET: @@ -302,21 +298,21 @@ static void remotePacketProcessGEN(unsigned i, char *packet) /* want to enable target power, but voltage > 0.5V sensed * on the pin -> cancel */ - _respond(REMOTE_RESP_ERR, 0); + remote_respond(REMOTE_RESP_ERR, 0); } else { platform_target_set_power(packet[2] == '1'); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); } #else - _respond(REMOTE_RESP_NOTSUP, 0); + remote_respond(REMOTE_RESP_NOTSUP, 0); #endif break; case REMOTE_PWR_GET: #ifdef PLATFORM_HAS_POWER_SWITCH - _respond(REMOTE_RESP_OK, platform_target_get_power()); + remote_respond(REMOTE_RESP_OK, platform_target_get_power()); #else - _respond(REMOTE_RESP_NOTSUP, 0); + remote_respond(REMOTE_RESP_NOTSUP, 0); #endif break; @@ -324,11 +320,11 @@ static void remotePacketProcessGEN(unsigned i, char *packet) # define PLATFORM_IDENT() BOARD_IDENT #endif case REMOTE_START: - _respondS(REMOTE_RESP_OK, PLATFORM_IDENT "" FIRMWARE_VERSION); + remote_respond_string(REMOTE_RESP_OK, PLATFORM_IDENT "" FIRMWARE_VERSION); break; default: - _respond(REMOTE_RESP_ERR, REMOTE_ERROR_UNRECOGNISED); + remote_respond(REMOTE_RESP_ERR, REMOTE_ERROR_UNRECOGNISED); break; } } @@ -344,7 +340,7 @@ static void remotePacketProcessHL(unsigned i, char *packet) void *src = (void *)(((uint32_t)packet + 7) & ~7); char index = packet[1]; if (index == REMOTE_HL_CHECK) { - _respond(REMOTE_RESP_OK, REMOTE_HL_VERSION); + remote_respond(REMOTE_RESP_OK, REMOTE_HL_VERSION); return; } packet += 2; @@ -357,7 +353,7 @@ static void remotePacketProcessHL(unsigned i, char *packet) packet += 2; uint16_t addr16 = remotehston(4, packet); uint32_t data = adiv5_dp_read(&remote_dp, addr16); - _respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); + remote_respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); break; case REMOTE_LOW_ACCESS: /* HL = Low level access */ packet += 2; @@ -365,13 +361,13 @@ static void remotePacketProcessHL(unsigned i, char *packet) packet += 4; uint32_t value = remotehston(8, packet); data = remote_dp.low_access(&remote_dp, remote_ap.apsel, addr16, value); - _respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); + remote_respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); break; case REMOTE_AP_READ: /* Ha = Read from AP register*/ packet += 2; addr16 = remotehston(4, packet); data = adiv5_ap_read(&remote_ap, addr16); - _respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); + remote_respond_buf(REMOTE_RESP_OK, (uint8_t*)&data, 4); break; case REMOTE_AP_WRITE: /* Ha = Write to AP register*/ packet += 2; @@ -379,7 +375,7 @@ static void remotePacketProcessHL(unsigned i, char *packet) packet += 4; value = remotehston(8, packet); adiv5_ap_write(&remote_ap, addr16, value); - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; case REMOTE_AP_MEM_READ: /* HM = Read from Mem and set csw */ packet += 2; @@ -394,10 +390,10 @@ static void remotePacketProcessHL(unsigned i, char *packet) packet += 8; adiv5_mem_read(&remote_ap, src, address, count); if (remote_ap.dp->fault == 0) { - _respond_buf(REMOTE_RESP_OK, src, count); + remote_respond_buf(REMOTE_RESP_OK, src, count); break; } - _respond(REMOTE_RESP_ERR, 0); + remote_respond(REMOTE_RESP_ERR, 0); remote_ap.dp->fault = 0; break; case REMOTE_AP_MEM_WRITE_SIZED: /* Hm = Write to memory and set csw */ @@ -415,7 +411,7 @@ static void remotePacketProcessHL(unsigned i, char *packet) packet += 8; if (len & ((1 << align) - 1)) { /* len and align do not fit*/ - _respond(REMOTE_RESP_ERR, 0); + remote_respond(REMOTE_RESP_ERR, 0); break; } /* Read as stream of hexified bytes*/ @@ -423,14 +419,14 @@ static void remotePacketProcessHL(unsigned i, char *packet) adiv5_mem_write_sized(&remote_ap, dest, src, len, align); if (remote_ap.dp->fault) { /* Errors handles on hosted side.*/ - _respond(REMOTE_RESP_ERR, 0); + remote_respond(REMOTE_RESP_ERR, 0); remote_ap.dp->fault = 0; break; } - _respond(REMOTE_RESP_OK, 0); + remote_respond(REMOTE_RESP_OK, 0); break; default: - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); break; } SET_IDLE_STATE(1); @@ -457,7 +453,7 @@ void remotePacketProcess(unsigned i, char *packet) break; default: /* Oh dear, unrecognised, return an error */ - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); + remote_respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); break; } }