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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [or1ksim/] [vapi/] [vapi.c] - Diff between revs 440 and 442

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

Rev 440 Rev 442
Line 46... Line 46...
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;
 
 
void server_request(void);
 
 
 
static int tcp_level = 0;
static int tcp_level = 0;
 
 
static struct vapi_handler {
static struct vapi_handler {
  int fd;
  int fd;
  unsigned long id;
  unsigned long id;
  void (*read_func)(unsigned long, unsigned long);
  void (*read_func)(unsigned long, unsigned long);
  struct vapi_handler *next;
  struct vapi_handler *next;
  int temp;
  int temp;
} *vapi_handler;
} *vapi_handler = NULL;
 
 
/* Structure for polling, it is cached, that it doesn't have to be rebuilt each time */
/* Structure for polling, it is cached, that it doesn't have to be rebuilt each time */
static struct pollfd *fds = NULL;
static struct pollfd *fds = NULL;
static int nfds = 0;
static int nfds = 0;
 
 
Line 116... Line 114...
  nhandlers++;
  nhandlers++;
  rebuild_fds ();
  rebuild_fds ();
  return tt;
  return tt;
}
}
 
 
/* Added by Erez 09/12/01 */
 
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.log_device_id && devid <= VAPI_MAX_DEVID)
  if (config.vapi.log_device_id && devid <= VAPI_MAX_DEVID)
Line 293... Line 290...
  }
  }
 
 
  return sockfd;
  return sockfd;
}
}
 
 
void server_request()
static void server_request()
{
{
  struct sockaddr_in sa;
  struct sockaddr_in sa;
  struct sockaddr* addr = (struct sockaddr*)&sa;
  struct sockaddr* addr = (struct sockaddr*)&sa;
  int n = sizeof(struct sockaddr_in);
  int n = sizeof(struct sockaddr_in);
  int fd = accept(server_fd, addr, &n);
  int fd = accept(server_fd, addr, &n);
Line 381... Line 378...
  if (vapi_write_stream(t->fd, &data, sizeof (data)) < 0)
  if (vapi_write_stream(t->fd, &data, sizeof (data)) < 0)
    return 1;
    return 1;
  return 0;
  return 0;
}
}
 
 
static int read_packet (unsigned long id, unsigned long *data) {
static int read_packet (int fd, unsigned long *id, unsigned long *data)
  unsigned long t_id;
{
  struct vapi_handler *t = find_handler (id);
  if (fd <= 0)
  if (!t || !t->fd)
 
    return 1;
 
  if (vapi_read_stream(t->fd, &t_id, sizeof (unsigned long)) < 0)
 
    return 1;
    return 1;
  t_id = htonl (t_id);
  if (vapi_read_stream(fd, id, sizeof(unsigned long)) < 0)
  if (t_id != id) {
 
    fprintf (stderr, "IDs not the same (got %x, expected %x)\n", t_id, id);
 
    return 1;
    return 1;
  }
  *id = ntohl (*id);
  if (vapi_read_stream(t->fd, data, sizeof (unsigned long)) < 0)
  if (vapi_read_stream(fd, data, sizeof(unsigned long)) < 0)
    return 1;
    return 1;
  *data = htonl (*data);
  *data = ntohl (*data);
  return 0;
  return 0;
}
}
 
 
static void vapi_request (struct vapi_handler *t) {
static void vapi_request (struct vapi_handler *t)
  unsigned long data;
{
  if(read_packet (t->id, &data)) {
  unsigned long id, data;
    if(t->fd) {
 
 
  if (read_packet(t->fd, &id, &data)) {
 
    if (t->fd >= 0) {
      perror("vapi read");
      perror("vapi read");
      close(t->fd);
      close(t->fd);
      t->fd = 0;
      t->fd = 0;
      rebuild_fds ();
      rebuild_fds ();
    }
    }
    return;
    return;
  }
  }
 
 
  vapi_write_log_file (0, t->id, data);
  vapi_write_log_file (VAPI_COMMAND_REQUEST, id, data);
  debug (4, "[%08x, %08x]\n", t->id, data);
  debug (4, "[%08x, %08x]\n", id, data);
  if (!t->read_func)
 
    fprintf (stderr, "WARNING: packet sent to undefined id %x, %x\n", t->id, data);
  /* This packet may be for another handler */
 
  if (t->id != id)
 
    t = find_handler (id);
 
  if (!t || !t->read_func)
 
    fprintf (stderr, "WARNING: Received packet for undefined id %08x, data %08x\n", id, data);
  else
  else
    t->read_func(t->id, data);
    t->read_func(id, data);
}
}
 
 
void vapi_check ()
void vapi_check ()
{
{
  struct vapi_handler *t;
  struct vapi_handler *t;
Line 511... Line 509...
  serverIP = 0;
  serverIP = 0;
  free (fds);
  free (fds);
  fds = 0;
  fds = 0;
  if (runtime.vapi.vapi_file) {
  if (runtime.vapi.vapi_file) {
    /* Mark end of simulation */
    /* Mark end of simulation */
    vapi_write_log_file (2, t->id, 0);
    vapi_write_log_file (VAPI_COMMAND_END, 0, 0);
    fclose (runtime.vapi.vapi_file);
    fclose (runtime.vapi.vapi_file);
  }
  }
 
 
  while (vapi_handler) {
  while (vapi_handler) {
    t = vapi_handler;
    t = vapi_handler;
Line 570... Line 568...
 
 
/* Sends a packet to specified test */
/* Sends a packet to specified test */
int vapi_send (unsigned long id, unsigned long data)
int vapi_send (unsigned long id, unsigned long data)
{
{
  debug (4, "vapi_send [%08x %08x]\n", id, data);
  debug (4, "vapi_send [%08x %08x]\n", id, data);
  vapi_write_log_file (1, id, data);
  vapi_write_log_file (VAPI_COMMAND_SEND, id, data);
  write_packet (id, data);
  write_packet (id, data);
}
}
 
 
/*
/*
int main ()
int main ()

powered by: WebSVN 2.1.0

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