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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [vapi/] [vapi.c] - Diff between revs 1147 and 1308

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1147 Rev 1308
Line 39... Line 39...
#include <netdb.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
 
 
#include "sim-config.h"
#include "sim-config.h"
#include "vapi.h"
#include "vapi.h"
 
#include "debug.h"
 
 
static unsigned int serverIP = 0;
static unsigned int serverIP = 0;
 
 
static unsigned int server_fd = 0;
static unsigned int server_fd = 0;
static unsigned int nhandlers = 0;
static unsigned int nhandlers = 0;
Line 124... Line 125...
void vapi_write_log_file(VAPI_COMMAND command, unsigned long devid, unsigned long data)
void vapi_write_log_file(VAPI_COMMAND command, unsigned long devid, unsigned long data)
{
{
  if (!runtime.vapi.vapi_file)
  if (!runtime.vapi.vapi_file)
    return;
    return;
  if (!config.vapi.hide_device_id && devid <= VAPI_MAX_DEVID)
  if (!config.vapi.hide_device_id && devid <= VAPI_MAX_DEVID)
    fprintf (runtime.vapi.vapi_file, "%04x", devid);
    fprintf (runtime.vapi.vapi_file, "%04lx", devid);
  fprintf (runtime.vapi.vapi_file, "%1x%08x\n", command, data);
  fprintf (runtime.vapi.vapi_file, "%1x%08lx\n", command, data);
}
}
 
 
static int vapi_write_stream(int fd, void* buf, int len)
static int vapi_write_stream(int fd, void* buf, int len)
{
{
  int n;
  int n;
Line 221... Line 222...
  tcp_level = protocol->p_proto; /* Save for later */
  tcp_level = protocol->p_proto; /* Save for later */
 
 
  /* If we weren't passed a non standard port, get the port
  /* If we weren't passed a non standard port, get the port
     from the services directory. */
     from the services directory. */
  if(!port) {
  if(!port) {
    if(service = getservbyname(name,protocol->p_name))
    if((service = getservbyname(name,protocol->p_name)))
      port = ntohs(service->s_port);
      port = ntohs(service->s_port);
  }
  }
 
 
  /* Create the socket using the TCP protocol */
  /* Create the socket using the TCP protocol */
  if((sockfd = socket(PF_INET,SOCK_STREAM,protocol->p_proto)) < 0) {
  if((sockfd = socket(PF_INET,SOCK_STREAM,protocol->p_proto)) < 0) {
Line 353... Line 354...
      return;
      return;
    }
    }
    t = find_handler (id);
    t = find_handler (id);
    if (t) {
    if (t) {
      if (t->fd) {
      if (t->fd) {
        fprintf (stderr, "WARNING: Test with id %x already connected. Ignoring.\n", id);
        fprintf (stderr, "WARNING: Test with id %lx already connected. Ignoring.\n", id);
        close (fd);
        close (fd);
        return;
        return;
      } else {
      } else {
        t->fd = fd;
        t->fd = fd;
        rebuild_fds ();
        rebuild_fds ();
      }
      }
    } else {
    } else {
      fprintf (stderr, "WARNING: Test with id %x not registered. Ignoring.\n", id);
      fprintf (stderr, "WARNING: Test with id %lx not registered. Ignoring.\n", id);
      close(fd); /* kill the connection */
      close(fd); /* kill the connection */
      return;
      return;
    }
    }
    if(config.sim.verbose)
    if(config.sim.verbose)
      PRINTF ("\nConnection with test (id %x) established.\n", id);
      PRINTF ("\nConnection with test (id %lx) established.\n", id);
  }
  }
}
}
 
 
static int write_packet (unsigned long id, unsigned long data) {
static int write_packet (unsigned long id, unsigned long data) {
  struct vapi_handler *t = find_handler (id);
  struct vapi_handler *t = find_handler (id);
Line 417... Line 418...
 
 
  /* This packet may be for another handler */
  /* This packet may be for another handler */
  if (!handler_fits_id (t, id))
  if (!handler_fits_id (t, id))
    t = find_handler (id);
    t = find_handler (id);
  if (!t || !t->read_func)
  if (!t || !t->read_func)
    fprintf (stderr, "WARNING: Received packet for undefined id %08x, data %08x\n", id, data);
    fprintf (stderr, "WARNING: Received packet for undefined id %08lx, data %08lx\n", id, data);
  else
  else
    t->read_func(id, data);
    t->read_func(id, data);
}
}
 
 
void vapi_check ()
void vapi_check ()
Line 484... Line 485...
  if (!runtime.vapi.server_port) {
  if (!runtime.vapi.server_port) {
    fprintf (stderr, "WARNING: server_port = 0, shutting down VAPI\n");
    fprintf (stderr, "WARNING: server_port = 0, shutting down VAPI\n");
    runtime.vapi.enabled = 0;
    runtime.vapi.enabled = 0;
    return 1;
    return 1;
  }
  }
  if (server_fd = get_server_socket("or1ksim", "tcp", runtime.vapi.server_port))
  if ((server_fd = get_server_socket("or1ksim", "tcp", runtime.vapi.server_port)))
    PRINTF("VAPI Server started on port %d\n", runtime.vapi.server_port);
    PRINTF("VAPI Server started on port %d\n", runtime.vapi.server_port);
  else {
  else {
    perror ("Connection");
    perror ("Connection");
    return 1;
    return 1;
  }
  }
Line 543... Line 544...
  if (read_func == NULL) {
  if (read_func == NULL) {
    struct vapi_handler **t = &vapi_handler;
    struct vapi_handler **t = &vapi_handler;
    while ((*t) && !handler_fits_id (*t, base_id))
    while ((*t) && !handler_fits_id (*t, base_id))
      t = &(*t)->next;
      t = &(*t)->next;
    if (!t) {
    if (!t) {
      fprintf (stderr, "Cannot uninstall VAPI read handler from id %x\n", base_id);
      fprintf (stderr, "Cannot uninstall VAPI read handler from id %lx\n",
 
               base_id);
      exit (1);
      exit (1);
    }
    }
    tt = *t;
    tt = *t;
    (*t) = (*t)->next;
    (*t) = (*t)->next;
    free (tt);
    free (tt);
Line 572... Line 574...
  for (; t; t = t->next) {
  for (; t; t = t->next) {
    if (!t->fd) {
    if (!t->fd) {
      numu++;
      numu++;
      if (printout) {
      if (printout) {
        if ( t->num_ids == 1 )
        if ( t->num_ids == 1 )
          PRINTF (" 0x%x", t->base_id);
          PRINTF (" 0x%lx", t->base_id);
        else
        else
          PRINTF (" 0x%x..0x%x", t->base_id, t->base_id + t->num_ids - 1);
          PRINTF (" 0x%lx..0x%lx", t->base_id, t->base_id + t->num_ids - 1);
      }
      }
    }
    }
  }
  }
  return numu;
  return numu;
}
}

powered by: WebSVN 2.1.0

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