OpenCores
URL https://opencores.org/ocsvn/adv_debug_sys/adv_debug_sys/trunk

Subversion Repositories adv_debug_sys

[/] [adv_debug_sys/] [trunk/] [Software/] [adv_jtag_bridge/] [hwp_server.c] - Diff between revs 56 and 59

Show entire file | Details | Blame | View Log

Rev 56 Rev 59
Line 99... Line 99...
 
 
/*----------------------------------------------------------*/
/*----------------------------------------------------------*/
/* Public API                                               */
/* Public API                                               */
/*----------------------------------------------------------*/
/*----------------------------------------------------------*/
 
 
void hwp_init(int portNum)
int hwp_init(int portNum)
{
{
  int status;
  int status;
  struct addrinfo hints;
  struct addrinfo hints;
  struct addrinfo *servinfo;  // will point to the results of getaddrinfo
  struct addrinfo *servinfo;  // will point to the results of getaddrinfo
  int optval; /* Socket options */
  int optval; /* Socket options */
Line 139... Line 139...
            }
            }
        }
        }
      debug("HWP %i is %s\n", i, hwp_in_use[i] ? "absent":"present");
      debug("HWP %i is %s\n", i, hwp_in_use[i] ? "absent":"present");
    }
    }
 
 
  if(status > 0)
  if(status <= 0)
    {
    {
      fprintf(stderr, "HWP server initializing with %i watchpoints available\n", status);
      fprintf(stderr, "No watchpoint hardware found, HWP server not starting\n");
 
      return 0;
    }
    }
  else
  else
    {
    {
      fprintf(stderr, "No watchpoint hardware found, HWP server not starting\n");
      fprintf(stderr, "HWP server initializing with %i watchpoints available\n", status);
    }
 
 
 
  /* We have watchpoint hardware.  Initialize the server. */
  /* We have watchpoint hardware.  Initialize the server. */
  hwp_server_fd      = -1;
  hwp_server_fd      = -1;
  hwp_client_fd      = -1;
  hwp_client_fd      = -1;
  hwp_portnum = portNum;
  hwp_portnum = portNum;
Line 164... Line 164...
  hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
  hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
  hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
  hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
 
 
  if ((status = getaddrinfo(NULL, portnum, &hints, &servinfo)) != 0) {
  if ((status = getaddrinfo(NULL, portnum, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    return;
        return 0;
  }
  }
 
 
 
 
  /* *** TODO: Select the appropriate servinfo in the linked list
  /* *** TODO: Select the appropriate servinfo in the linked list
   * For now, we just use the first entry in servinfo.
   * For now, we just use the first entry in servinfo.
Line 205... Line 205...
  /* Create the socket */
  /* Create the socket */
  hwp_server_fd = socket (servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  hwp_server_fd = socket (servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol);
  if (hwp_server_fd < 0)
  if (hwp_server_fd < 0)
    {
    {
      fprintf (stderr, "Error: HWP could not create server socket: %s\n", strerror(errno));
      fprintf (stderr, "Error: HWP could not create server socket: %s\n", strerror(errno));
      return;
          return 0;
    }
    }
 
 
  /* Set this socket to reuse its address. */
  /* Set this socket to reuse its address. */
  optval = 1;
  optval = 1;
  if (setsockopt(hwp_server_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (optval)) == -1)
  if (setsockopt(hwp_server_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof (optval)) == -1)
    {
    {
      fprintf (stderr, "Cannot set SO_REUSEADDR option on server socket %d: %s\n", hwp_server_fd, strerror(errno));
      fprintf (stderr, "Cannot set SO_REUSEADDR option on server socket %d: %s\n", hwp_server_fd, strerror(errno));
      hwp_server_close();
      hwp_server_close();
      return;
          return 0;
    }
    }
 
 
  /* Bind the socket to the local address */
  /* Bind the socket to the local address */
  if (bind (hwp_server_fd, servinfo->ai_addr, servinfo->ai_addrlen) < 0)
  if (bind (hwp_server_fd, servinfo->ai_addr, servinfo->ai_addrlen) < 0)
    {
    {
      fprintf (stderr, "Error: Unable to bind HWP server socket %d to port %d: %s\n", hwp_server_fd, portNum, strerror(errno));
      fprintf (stderr, "Error: Unable to bind HWP server socket %d to port %d: %s\n", hwp_server_fd, portNum, strerror(errno));
      hwp_server_close();
      hwp_server_close();
      return;
          return 0;
    }
    }
 
 
  /* Set us up as a server, with a maximum backlog of 1 connection */
  /* Set us up as a server, with a maximum backlog of 1 connection */
  if (listen (hwp_server_fd, 1) < 0)
  if (listen (hwp_server_fd, 1) < 0)
    {
    {
      fprintf (stderr, "Warning: Unable to set HWP backlog on server socket %d to %d: %s\n", hwp_server_fd, 1, strerror(errno));
      fprintf (stderr, "Warning: Unable to set HWP backlog on server socket %d to %d: %s\n", hwp_server_fd, 1, strerror(errno));
      hwp_server_close();
      hwp_server_close();
      return;
          return 0;
    }
    }
 
 
  fprintf(stderr, "HWP server listening on host %s (%s), port %i, address family %s\n",
  fprintf(stderr, "HWP server listening on host %s (%s), port %i, address family %s\n",
          hwp_hostname, hwp_ipstr, hwp_portnum, hwp_ipver);
          hwp_hostname, hwp_ipstr, hwp_portnum, hwp_ipver);
 
 
  /* Register for stall/unstall events from the target monitor thread. Also creates pipe
  /* Register for stall/unstall events from the target monitor thread. Also creates pipe
   * for sending stall/unstall command to the target monitor, unused by us. */
   * for sending stall/unstall command to the target monitor, unused by us. */
  if(0 > register_with_monitor_thread(hwp_pipe_fds)) {  // pipe_fds[0] is for writing to monitor, [1] is to read from it
  if(0 > register_with_monitor_thread(hwp_pipe_fds)) {  // pipe_fds[0] is for writing to monitor, [1] is to read from it
    fprintf(stderr, "HWP server failed to register with monitor thread, exiting");
    fprintf(stderr, "HWP server failed to register with monitor thread, exiting");
    hwp_server_close();
    hwp_server_close();
    return;
        return 0;
 
      }
  }
  }
 
 
 
  return 1;
}
}
 
 
 
 
int hwp_server_start(void)
int hwp_server_start(void)
{
{

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.