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 442 and 477

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

Rev 442 Rev 477
Line 50... Line 50...
 
 
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 base_id, num_ids;
  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 = NULL;
} *vapi_handler = NULL;
 
 
Line 87... Line 87...
    } else
    } else
      t->temp = -1;
      t->temp = -1;
  }
  }
}
}
 
 
 
/* Determines whether a certain handler handles an ID */
 
static inline int handler_fits_id( const struct vapi_handler *t, unsigned long id ) {
 
  return ((id >= t->base_id) && (id < t->base_id + t->num_ids));
 
}
 
 
/* Finds a handler with given ID, return it, NULL if not found.  */
/* Finds a handler with given ID, return it, NULL if not found.  */
static struct vapi_handler *find_handler (unsigned long id) {
static struct vapi_handler *find_handler (unsigned long id) {
  struct vapi_handler *t = vapi_handler;
  struct vapi_handler *t = vapi_handler;
  while (t && t->id != id)
  while (t && !handler_fits_id (t, id))
    t = t->next;
    t = t->next;
  return t;
  return t;
}
}
 
 
/* Adds a handler with given id and returns it.  */
/* Adds a handler with given id and returns it.  */
static struct vapi_handler *add_handler (unsigned long id) {
static struct vapi_handler *add_handler (unsigned long base_id, unsigned long num_ids) {
  struct vapi_handler **t = &vapi_handler;
  struct vapi_handler **t = &vapi_handler;
  struct vapi_handler *tt;
  struct vapi_handler *tt;
  while ((*t))
  while ((*t))
    t = &(*t)->next;
    t = &(*t)->next;
  tt = (struct vapi_handler *)malloc (sizeof (struct vapi_handler));
  tt = (struct vapi_handler *)malloc (sizeof (struct vapi_handler));
  tt->next = NULL;
  tt->next = NULL;
  tt->id = id;
  tt->base_id = base_id;
 
  tt->num_ids = num_ids;
  tt->read_func = NULL;
  tt->read_func = NULL;
  tt->fd = 0;
  tt->fd = 0;
  (*t) = tt;
  (*t) = tt;
  free (fds);
  free (fds);
  fds = NULL;
  fds = NULL;
Line 118... Line 124...
 
 
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.hide_device_id && devid <= VAPI_MAX_DEVID)
    fprintf (runtime.vapi.vapi_file, "%04x", devid);
    fprintf (runtime.vapi.vapi_file, "%04x", devid);
  fprintf (runtime.vapi.vapi_file, "%1x%08x\n", command, data);
  fprintf (runtime.vapi.vapi_file, "%1x%08x\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)
Line 396... Line 402...
static void vapi_request (struct vapi_handler *t)
static void vapi_request (struct vapi_handler *t)
{
{
  unsigned long id, data;
  unsigned long id, data;
 
 
  if (read_packet(t->fd, &id, &data)) {
  if (read_packet(t->fd, &id, &data)) {
    if (t->fd >= 0) {
    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 ();
    }
    }
Line 409... Line 415...
 
 
  vapi_write_log_file (VAPI_COMMAND_REQUEST, id, data);
  vapi_write_log_file (VAPI_COMMAND_REQUEST, id, data);
  debug (4, "[%08x, %08x]\n", id, data);
  debug (4, "[%08x, %08x]\n", id, data);
 
 
  /* This packet may be for another handler */
  /* This packet may be for another handler */
  if (t->id != 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 %08x, data %08x\n", id, data);
  else
  else
    t->read_func(id, data);
    t->read_func(id, data);
Line 520... Line 526...
    vapi_handler = vapi_handler->next;
    vapi_handler = vapi_handler->next;
    free (t);
    free (t);
  }
  }
}
}
 
 
/* Installs a vapi handler to VAPI id */
/* Installs a vapi handler for one 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))
{
{
 
  vapi_install_multi_handler (id, 1, read_func);
 
}
 
 
 
/* Installs a vapi handler for many VAPI id */
 
void vapi_install_multi_handler (unsigned long base_id, unsigned long num_ids, void (*read_func) (unsigned long, unsigned long))
 
{
  struct vapi_handler *tt;
  struct vapi_handler *tt;
 
 
  debug(4, "vapi_install_handler %08x, %08x\n", id, read_func);
  debug(4, "vapi_install_handler %08x, %u, %08x\n", base_id, num_ids, 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) && !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", id);
      fprintf (stderr, "Cannot uninstall VAPI read handler from id %x\n", base_id);
      exit (1);
      exit (1);
    }
    }
    tt = *t;
    tt = *t;
    (*t) = (*t)->next;
    (*t) = (*t)->next;
    free (tt);
    free (tt);
    nhandlers--;
    nhandlers--;
  } else {
  } else {
    tt = find_handler (id);
    tt = find_handler (base_id);
    if (!tt) {
    if (!tt) {
      tt = add_handler (id);
      tt = add_handler (base_id, num_ids);
      tt->read_func = read_func;
      tt->read_func = read_func;
    } else {
    } else {
      tt->read_func = read_func;
      tt->read_func = read_func;
      rebuild_fds ();
      rebuild_fds ();
    }
    }
Line 558... Line 570...
  struct vapi_handler *t = vapi_handler;
  struct vapi_handler *t = vapi_handler;
  int numu = 0;
  int numu = 0;
  for (; t; t = t->next) {
  for (; t; t = t->next) {
    if (!t->fd) {
    if (!t->fd) {
      numu++;
      numu++;
      if (printout) printf (" 0x%x", t->id);
      if (printout) {
 
        if ( t->num_ids == 1 )
 
          printf (" 0x%x", t->base_id);
 
        else
 
          printf (" 0x%x..0x%x", 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.