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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc2/] [or1ksim/] [vapi/] [vapi.c] - Diff between revs 336 and 355

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

Rev 336 Rev 355
Line 338... Line 338...
      perror ("Cannot get id");
      perror ("Cannot get id");
      close (fd);
      close (fd);
      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 %x already connected. Ignoring.\n", id);
        close (fd);
        close (fd);
        return;
        return;
      } else t->fd = fd;
      } else {
    else {
 
      t = add_handler (id);
 
      t->fd = fd;
      t->fd = fd;
      rebuild_fds ();
      rebuild_fds ();
    }
    }
 
    } else {
 
      fprintf (stderr, "WARNING: Test with id %x not registered. Ignoring.\n", id);
 
      close(fd); /* kill the connection */
 
      return;
 
    }
    if(config.sim.verbose)
    if(config.sim.verbose)
      printf ("\nConnection with test (id %x) established.\n", id);
      printf ("\nConnection with test (id %x) established.\n", id);
  }
  }
}
}
 
 
Line 396... Line 399...
      t->fd = 0;
      t->fd = 0;
    }
    }
    return;
    return;
  }
  }
 
 
  debug ("[%08x, %08x]\n", t->id, data);
  if (config.vapi.vapi_file)
 
    fprintf (config.vapi.vapi_file, "1%08x\n", data);
 
  debug (4, "[%08x, %08x]\n", t->id, data);
  if (!t->read_func)
  if (!t->read_func)
    fprintf (stderr, "WARNING: packet sent to undefined id %x, %x\n", t->id, data);
    fprintf (stderr, "WARNING: packet sent to undefined id %x, %x\n", t->id, data);
  else
  else
    t->read_func(t->id, data);
    t->read_func(t->id, data);
}
}
Line 412... Line 417...
  if (!server_fd || !fds) {
  if (!server_fd || !fds) {
    fprintf (stderr, "FATAL: Unable to maintain VAPI server.\n");
    fprintf (stderr, "FATAL: Unable to maintain VAPI server.\n");
    exit (1);
    exit (1);
  }
  }
 
 
 
  debug(4, ".");
 
 
  /* Handle everything in queue. */
  /* Handle everything in queue. */
  while(1) {
  while(1) {
    switch(poll(fds, nfds, 0)) {
    switch(poll(fds, nfds, 0)) {
    case -1:
    case -1:
      if(errno == EINTR)
      if(errno == EINTR)
Line 470... Line 477...
    perror ("Connection");
    perror ("Connection");
    return 1;
    return 1;
  }
  }
 
 
  rebuild_fds ();
  rebuild_fds ();
 
 
 
  if ((config.vapi.vapi_file = fopen (config.vapi.vapi_fn, "wt+")) == NULL)
 
    fprintf (stderr, "WARNING: cannot open VAPI log file\n");
 
 
  return 0;
  return 0;
}
}
 
 
/* Closes the VAPI */
/* Closes the VAPI */
void vapi_done ()
void vapi_done ()
Line 487... Line 498...
  server_fd = 0;
  server_fd = 0;
  config.vapi.enabled = 0;
  config.vapi.enabled = 0;
  serverIP = 0;
  serverIP = 0;
  free (fds);
  free (fds);
  fds = 0;
  fds = 0;
 
  if (config.vapi.vapi_file)
 
    fclose (config.vapi.vapi_file);
 
 
  while (vapi_handler) {
  while (vapi_handler) {
    t = vapi_handler;
    t = vapi_handler;
    vapi_handler = vapi_handler->next;
    vapi_handler = vapi_handler->next;
    free (t);
    free (t);
  }
  }
Line 498... Line 512...
 
 
/* Installs a vapi handler to VAPI id */
/* Installs a vapi handler to VAPI id */
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long))
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long))
{
{
  struct vapi_handler *tt;
  struct vapi_handler *tt;
 
 
 
  debug(4, "vapi_install_handler %08x, %08x", id, read_func);
  if (read_func == NULL) {
  if (read_func == NULL) {
    struct vapi_handler **t = &vapi_handler;
    struct vapi_handler **t = &vapi_handler;
    while ((*t) && (*t)->id != id)
    while ((*t) && (*t)->id != id)
      t = &(*t)->next;
      t = &(*t)->next;
    if (!t) {
    if (!t) {
Line 511... Line 527...
    tt = *t;
    tt = *t;
    (*t) = (*t)->next;
    (*t) = (*t)->next;
    free (tt);
    free (tt);
    nhandlers--;
    nhandlers--;
  } else {
  } else {
 
    tt = find_handler (id);
 
    if (!tt) {
    tt = add_handler (id);
    tt = add_handler (id);
    tt->read_func = read_func;
    tt->read_func = read_func;
 
    } else {
 
      tt->read_func = read_func;
 
      rebuild_fds ();
 
    }
  }
  }
}
}
 
 
/* Returns number of unconnected handles.  */
/* Returns number of unconnected handles.  */
int vapi_num_unconnected (int printout)
int vapi_num_unconnected (int printout)
Line 533... Line 555...
}
}
 
 
/* 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);
 
  if (config.vapi.vapi_file)
 
    fprintf (config.vapi.vapi_file, "0%08x\n", data);
  write_packet (id, data);
  write_packet (id, data);
}
}
 
 
 
 
/*
/*
int main ()
int main ()
{
{
  config.vapi.enabled = 1;
  config.vapi.enabled = 1;
  config.vapi.server_port = 9999;
  config.vapi.server_port = 9999;

powered by: WebSVN 2.1.0

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