build: cleanup src/jtag/drivers directory
[openocd.git] / src / jtag / drivers / remote_bitbang.c
index d3ab1b11d3cd83282ea21b3362b4916b0e20b50c..eb98423cd7f12a3586a1e396751d28dff484998c 100644 (file)
@@ -17,6 +17,7 @@
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 #include <jtag/interface.h>
 #include "bitbang.h"
 
-// from unix man page and sys/un.h:
+/* from unix man page and sys/un.h: */
 #define UNIX_PATH_MAX 108
 
-// 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;
 
-FILEremote_bitbang_in;
-FILEremote_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 +64,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 +76,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 +86,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 +142,22 @@ static int remote_bitbang_init_tcp(void)
                return ERROR_FAIL;
        }
 
-       struct hostenthent = gethostbyname(remote_bitbang_host);
+       struct hostent *hent = gethostbyname(remote_bitbang_host);
        if (hent == NULL) {
-               charerrorstr = "???";
+               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 +166,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;
        }
@@ -188,7 +202,7 @@ static int remote_bitbang_init_unix(void)
        strncpy(addr.sun_path, remote_bitbang_host, UNIX_PATH_MAX);
        addr.sun_path[UNIX_PATH_MAX-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,21 +228,20 @@ 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, intjtag_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, intkhz)
+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;
 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)