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 335 and 336

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

Rev 335 Rev 336
Line 15... Line 15...
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
//#include "config.h"
#include "config.h"
 
 
#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
Line 38... Line 38...
#include <fcntl.h>
#include <fcntl.h>
#include <netdb.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
#include <inttypes.h>
#include <inttypes.h>
 
 
//#include "sim-config.h"
#include "sim-config.h"
 
 
static unsigned int serverIP = 0;
static unsigned int serverIP = 0;
 
 
struct {
 
  struct {
 
    int enabled;
 
    unsigned int server_port;
 
  } vapi;
 
  struct {
 
    int verbose;
 
  } sim;
 
} config;
 
#define debug printf
 
 
 
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);
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);
  void (*read_func)(unsigned long, unsigned long);
  struct vapi_handler *next;
  struct vapi_handler *next;
  int temp;
  int temp;
} *vapi_handler;
} *vapi_handler;
 
 
 
 
/* 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;
 
 
/* Rebuilds the fds structures; see fds.  */
/* Rebuilds the fds structures; see fds.  */
Line 299... Line 287...
void server_request()
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);
  int on_off = 0; /* Turn off Nagel's algorithm on the socket */
  int on_off = 0; /* Turn off Nagel's algorithm on the socket */
  int flags;
  int flags;
  char sTemp[256];
  char sTemp[256];
 
 
  if(fd < 0) {
  if(fd < 0) {
Line 362... Line 350...
      t = add_handler (id);
      t = add_handler (id);
      t->fd = fd;
      t->fd = fd;
      rebuild_fds ();
      rebuild_fds ();
    }
    }
    if(config.sim.verbose)
    if(config.sim.verbose)
      printf ("Connection with test (id %x) established.\n", id);
      printf ("\nConnection with test (id %x) 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 412... Line 400...
 
 
  debug ("[%08x, %08x]\n", t->id, data);
  debug ("[%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(data);
    t->read_func(t->id, data);
}
}
 
 
void vapi_check ()
void vapi_check ()
{
{
  struct vapi_handler *t;
  struct vapi_handler *t;
Line 507... Line 495...
    free (t);
    free (t);
  }
  }
}
}
 
 
/* 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))
void vapi_install_handler (unsigned long id, void (*read_func) (unsigned long, unsigned long))
{
{
  struct vapi_handler *tt;
  struct vapi_handler *tt;
  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)
Line 529... Line 517...
    tt->read_func = read_func;
    tt->read_func = read_func;
  }
  }
}
}
 
 
/* Returns number of unconnected handles.  */
/* Returns number of unconnected handles.  */
int vapi_num_unconnected ()
int vapi_num_unconnected (int printout)
{
{
  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) numu++;
    if (!t->fd) {
 
      numu++;
 
      if (printout) printf (" %x", t->id);
 
    }
 
  }
  return numu;
  return numu;
}
}
 
 
/* 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)

powered by: WebSVN 2.1.0

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