X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fremote_bitbang.c;h=73d9cfcc0d9164d97b75f9af525cf872359fba73;hb=7bfcc10839d2a9190cb7ae9fae02280e643b3450;hp=d3ab1b11d3cd83282ea21b3362b4916b0e20b50c;hpb=1411ad11c182d02769bb0954f7f5b01d66652a6b;p=openocd.git diff --git a/src/jtag/drivers/remote_bitbang.c b/src/jtag/drivers/remote_bitbang.c index d3ab1b11d3..73d9cfcc0d 100644 --- a/src/jtag/drivers/remote_bitbang.c +++ b/src/jtag/drivers/remote_bitbang.c @@ -17,36 +17,42 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#ifndef _WIN32 #include #include +#endif #include #include "bitbang.h" -// from unix man page and sys/un.h: -#define UNIX_PATH_MAX 108 +#ifndef UNIX_PATH_LEN +#define UNIX_PATH_LEN 108 +#endif -// arbitrary limit on host name length: +/* arbitrary limit on host name length: */ #define REMOTE_BITBANG_HOST_MAX 255 #define REMOTE_BITBANG_RAISE_ERROR(expr ...) \ - LOG_ERROR(expr); LOG_ERROR("Terminating openocd."); exit(-1); + do { \ + LOG_ERROR(expr); \ + LOG_ERROR("Terminating openocd."); \ + exit(-1); \ + } while (0) static char remote_bitbang_host[REMOTE_BITBANG_HOST_MAX] = "openocd"; -static uint16_t remote_bitbang_port = 0; +static uint16_t remote_bitbang_port; -FILE* remote_bitbang_in; -FILE* remote_bitbang_out; +FILE *remote_bitbang_in; +FILE *remote_bitbang_out; static void remote_bitbang_putc(int c) { - if (EOF == fputc(c, remote_bitbang_out)) { + if (EOF == fputc(c, remote_bitbang_out)) REMOTE_BITBANG_RAISE_ERROR("remote_bitbang_putc: %s", strerror(errno)); - } } static int remote_bitbang_quit(void) @@ -60,9 +66,9 @@ static int remote_bitbang_quit(void) LOG_ERROR("fflush: %s", strerror(errno)); return ERROR_FAIL; } - - // We only need to close one of the FILE*s, because they both use the same - // underlying file descriptor. + + /* We only need to close one of the FILE*s, because they both use the same */ + /* underlying file descriptor. */ if (EOF == fclose(remote_bitbang_out)) { LOG_ERROR("fclose: %s", strerror(errno)); return ERROR_FAIL; @@ -72,7 +78,7 @@ static int remote_bitbang_quit(void) return ERROR_OK; } -// Get the next read response. +/* Get the next read response. */ static int remote_bitbang_rread(void) { if (EOF == fflush(remote_bitbang_out)) { @@ -82,12 +88,14 @@ static int remote_bitbang_rread(void) int c = fgetc(remote_bitbang_in); switch (c) { - case '0': return 0; - case '1': return 1; + case '0': + return 0; + case '1': + return 1; default: remote_bitbang_quit(); REMOTE_BITBANG_RAISE_ERROR( - "remote_bitbang: invalid read response: %c(%i)", c, c); + "remote_bitbang: invalid read response: %c(%i)", c, c); } } @@ -136,14 +144,22 @@ static int remote_bitbang_init_tcp(void) return ERROR_FAIL; } - struct hostent* hent = gethostbyname(remote_bitbang_host); + struct hostent *hent = gethostbyname(remote_bitbang_host); if (hent == NULL) { - char* errorstr = "???"; + char *errorstr = "???"; switch (h_errno) { - case HOST_NOT_FOUND: errorstr = "host not found"; break; - case NO_ADDRESS: errorstr = "no address"; break; - case NO_RECOVERY: errorstr = "no recovery"; break; - case TRY_AGAIN: errorstr = "try again"; break; + case HOST_NOT_FOUND: + errorstr = "host not found"; + break; + case NO_ADDRESS: + errorstr = "no address"; + break; + case NO_RECOVERY: + errorstr = "no recovery"; + break; + case TRY_AGAIN: + errorstr = "try again"; + break; } LOG_ERROR("gethostbyname: %s", errorstr); return ERROR_FAIL; @@ -152,8 +168,8 @@ static int remote_bitbang_init_tcp(void) struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(remote_bitbang_port); - addr.sin_addr = *(struct in_addr*)hent->h_addr; - if (connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_in)) < 0) { + addr.sin_addr = *(struct in_addr *)hent->h_addr; + if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) { LOG_ERROR("connect: %s", strerror(errno)); return ERROR_FAIL; } @@ -185,10 +201,10 @@ static int remote_bitbang_init_unix(void) struct sockaddr_un addr; addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_MAX); - addr.sun_path[UNIX_PATH_MAX-1] = '\0'; + strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_LEN); + addr.sun_path[UNIX_PATH_LEN-1] = '\0'; - if (connect(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr_un)) < 0) { + if (connect(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0) { LOG_ERROR("connect: %s", strerror(errno)); return ERROR_FAIL; } @@ -214,26 +230,24 @@ static int remote_bitbang_init(void) bitbang_interface = &remote_bitbang_bitbang; LOG_INFO("Initializing remote_bitbang driver"); - if (remote_bitbang_port == 0) { + if (remote_bitbang_port == 0) return remote_bitbang_init_unix(); - } return remote_bitbang_init_tcp(); } -static int remote_bitbang_khz(int khz, int* jtag_speed) +static int remote_bitbang_khz(int khz, int *jtag_speed) { *jtag_speed = 0; return ERROR_OK; } -static int remote_bitbang_speed_div(int speed, int* khz) +static int remote_bitbang_speed_div(int speed, int *khz) { - // I don't think this really matters any. + /* I don't think this really matters any. */ *khz = 1; return ERROR_OK; } - COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_port_command) { if (CMD_ARGC == 1) { @@ -253,7 +267,6 @@ COMMAND_HANDLER(remote_bitbang_handle_remote_bitbang_host_command) return ERROR_COMMAND_SYNTAX_ERROR; } - static const struct command_registration remote_bitbang_command_handlers[] = { { .name = "remote_bitbang_port",