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

Subversion Repositories or1k

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /or1k/tags/nog_patch_46/or1ksim/peripheral/channels
    from Rev 1417 to Rev 1765
    Reverse comparison

Rev 1417 → Rev 1765

/Makefile.in
0,0 → 1,349
# Makefile.in generated by automake 1.6.3 from Makefile.am.
# @configure_input@
 
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
 
@SET_MAKE@
 
# Makefile -- Makefile for peripherals channels to host
# Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
#
# This file is part of OpenRISC 1000 Architectural Simulator.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
SHELL = @SHELL@
 
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
 
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ../..
 
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
 
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_HEADER = $(INSTALL_DATA)
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_alias = @build_alias@
build_triplet = @build@
host_alias = @host_alias@
host_triplet = @host@
target_alias = @target_alias@
target_triplet = @target@
 
EXEEXT = @EXEEXT@
OBJEXT = @OBJEXT@
PATH_SEPARATOR = @PATH_SEPARATOR@
AMTAR = @AMTAR@
AR = @AR@
ARFLAGS = @ARFLAGS@
AWK = @AWK@
BUILD_DIR = @BUILD_DIR@
CC = @CC@
CFLAGS = @CFLAGS@
CPU_ARCH = @CPU_ARCH@
DEPDIR = @DEPDIR@
INCLUDES = @INCLUDES@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LOCAL_CFLAGS = @LOCAL_CFLAGS@
LOCAL_DEFS = @LOCAL_DEFS@
MAKE_SHELL = @MAKE_SHELL@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
STRIP = @STRIP@
SUMVERSION = @SUMVERSION@
TERMCAP_LIB = @TERMCAP_LIB@
VERSION = @VERSION@
am__include = @am__include@
am__quote = @am__quote@
host = @host@
host_cpu = @host_cpu@
host_os = @host_os@
install_sh = @install_sh@
 
noinst_LIBRARIES = libchannels.a
libchannels_a_SOURCES = \
channel.c \
fd.c \
file.c \
generic.c \
xterm.c \
tcp.c \
tty.c
 
subdir = peripheral/channels
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
LIBRARIES = $(noinst_LIBRARIES)
 
libchannels_a_AR = $(AR) cru
libchannels_a_LIBADD =
am_libchannels_a_OBJECTS = channel.$(OBJEXT) fd.$(OBJEXT) file.$(OBJEXT) \
generic.$(OBJEXT) xterm.$(OBJEXT) tcp.$(OBJEXT) tty.$(OBJEXT)
libchannels_a_OBJECTS = $(am_libchannels_a_OBJECTS)
 
DEFS = @DEFS@
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/channel.Po ./$(DEPDIR)/fd.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/file.Po ./$(DEPDIR)/generic.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/tcp.Po ./$(DEPDIR)/tty.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/xterm.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(libchannels_a_SOURCES)
DIST_COMMON = Makefile.am Makefile.in
SOURCES = $(libchannels_a_SOURCES)
 
all: all-am
 
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu peripheral/channels/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
 
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
libchannels.a: $(libchannels_a_OBJECTS) $(libchannels_a_DEPENDENCIES)
-rm -f libchannels.a
$(libchannels_a_AR) libchannels.a $(libchannels_a_OBJECTS) $(libchannels_a_LIBADD)
$(RANLIB) libchannels.a
 
mostlyclean-compile:
-rm -f *.$(OBJEXT) core *.core
 
distclean-compile:
-rm -f *.tab.c
 
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/channel.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generic.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tcp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tty.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xterm.Po@am__quote@
 
distclean-depend:
-rm -rf ./$(DEPDIR)
 
.c.o:
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
$(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
 
.c.obj:
@AMDEP_TRUE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
$(COMPILE) -c `cygpath -w $<`
CCDEPMODE = @CCDEPMODE@
uninstall-info-am:
 
ETAGS = etags
ETAGSFLAGS =
 
tags: TAGS
 
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
 
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
 
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
 
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 
top_distdir = ../..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
 
distdir: $(DISTFILES)
@list='$(DISTFILES)'; for file in $$list; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LIBRARIES)
 
installdirs:
 
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
 
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
 
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
 
clean-generic:
 
distclean-generic:
-rm -f Makefile $(CONFIG_CLEAN_FILES)
 
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
 
clean-am: clean-generic clean-noinstLIBRARIES mostlyclean-am
 
distclean: distclean-am
 
distclean-am: clean-am distclean-compile distclean-depend \
distclean-generic distclean-tags
 
dvi: dvi-am
 
dvi-am:
 
info: info-am
 
info-am:
 
install-data-am:
 
install-exec-am:
 
install-info: install-info-am
 
install-man:
 
installcheck-am:
 
maintainer-clean: maintainer-clean-am
 
maintainer-clean-am: distclean-am maintainer-clean-generic
 
mostlyclean: mostlyclean-am
 
mostlyclean-am: mostlyclean-compile mostlyclean-generic
 
uninstall-am: uninstall-info-am
 
.PHONY: GTAGS all all-am check check-am clean clean-generic \
clean-noinstLIBRARIES distclean distclean-compile \
distclean-depend distclean-generic distclean-tags distdir dvi \
dvi-am info info-am install install-am install-data \
install-data-am install-exec install-exec-am install-info \
install-info-am install-man install-strip installcheck \
installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic tags uninstall uninstall-am \
uninstall-info-am
 
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
/channel.c
0,0 → 1,256
/* channel.h -- Definition of types and structures for
peripheral to communicate with host. Addapted from UML.
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#if HAVE_CONFIG_H
#include "config.h"
#endif
 
#define _GNU_SOURCE /* for strndup */
 
#include <stdio.h> /* perror */
#include <stdlib.h> /* exit */
 
#if HAVE_MALLOC_H
#include <malloc.h> /* calloc, free */
#endif
 
#include <string.h> /* strndup, strcmp, strlen, strchr */
#include <errno.h> /* errno */
 
#include "port.h"
 
#include "channel.h"
 
struct channel_factory
{
const char * name;
const struct channel_ops * ops;
struct channel_factory * next;
};
 
extern struct channel_ops fd_channel_ops, file_channel_ops,
xterm_channel_ops, tcp_channel_ops, tty_channel_ops;
 
static struct channel_factory preloaded[] =
{
{ "fd", &fd_channel_ops, &preloaded[1] },
{ "file", &file_channel_ops, &preloaded[2] },
{ "xterm", &xterm_channel_ops, &preloaded[3] },
{ "tcp", &tcp_channel_ops, &preloaded[4] },
{ "tty", &tty_channel_ops, NULL }
};
 
static struct channel_factory * head = &preloaded[0];
 
static struct channel_factory * find_channel_factory(const char * name);
 
struct channel * channel_init(const char * descriptor)
{
struct channel * retval;
struct channel_factory * current;
char * args, * name;
int count;
 
if(!descriptor)
{
return NULL;
}
 
retval = (struct channel*)calloc(1, sizeof(struct channel));
 
if(!retval)
{
perror(descriptor);
exit(1);
}
 
args = strchr(descriptor, ':');
 
if(args)
{
count = args - descriptor;
args++;
}
else
{
count = strlen(descriptor);
}
 
name = (char*)strndup(descriptor, count);
 
if(!name)
{
perror(name);
exit(1);
}
 
current = find_channel_factory(name);
if(!current)
{
errno = ENODEV;
perror(descriptor);
exit(1);
}
 
retval->ops = current->ops;
 
free(name);
 
if(!retval->ops)
{
errno = ENODEV;
perror(descriptor);
exit(1);
}
 
if(retval->ops->init)
{
retval->data = (retval->ops->init)(args);
 
if(!retval->data)
{
perror(descriptor);
exit(1);
}
}
 
return retval;
}
 
int channel_open(struct channel * channel)
{
if(channel && channel->ops && channel->ops->open)
{
return (channel->ops->open)(channel->data);
}
errno = ENOSYS;
return -1;
}
 
int channel_read(struct channel * channel, char * buffer, int size)
{
if(channel && channel->ops && channel->ops->read)
{
return (channel->ops->read)(channel->data, buffer, size);
}
errno = ENOSYS;
return -1;
}
 
int channel_write(struct channel * channel, const char * buffer, int size)
{
if(channel && channel->ops && channel->ops->write)
{
return (channel->ops->write)(channel->data, buffer, size);
}
errno = ENOSYS;
return -1;
}
 
void channel_close(struct channel * channel)
{
if(channel && channel->ops && channel->ops->close)
{
(channel->ops->close)(channel->data);
}
}
 
void channel_free(struct channel * channel)
{
if(channel && channel->ops && channel->ops->free)
{
(channel->ops->free)(channel->data);
free(channel);
}
}
 
 
int channel_ok(struct channel * channel)
{
if(channel && channel->ops)
{
if(channel->ops->isok)
return (channel->ops->isok)(channel->data);
else
return 1;
}
return 0;
}
 
char * channel_status(struct channel * channel)
{
if(channel && channel->ops && channel->ops->status)
{
return (channel->ops->status)(channel->data);
}
return "";
}
 
 
 
static struct channel_factory * find_channel_factory(const char * name)
{
struct channel_factory * current = head;
 
current = head;
while(current && strcmp(current->name, name))
{
current = current->next;
}
 
return current;
}
 
int register_channel(const char * name, const struct channel_ops * ops)
{
struct channel_factory * new;
 
 
if(find_channel_factory(name))
{
errno = EEXIST;
perror(name);
exit(1);
}
 
new = (struct channel_factory *)calloc(1, sizeof(struct channel_factory));
 
if(!new)
{
perror(name);
exit(1);
}
 
new->name = name;
new->ops = ops;
new->next = head;
head = new;
 
return (int)new; /* dummy */
}
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
 
/xterm.c
0,0 → 1,265
/* xterm.c -- Definition of functions and structures for
peripheral to communicate with host through an xterm.
Inspired from SWI-Prolog by Jan Wielemaker (GPL too)
even if there is really few in common.
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
/*
* I really dislike using stuff beginning with '_'
* They are suppose to be reserved for the compiler
* as explained in C standards.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
 
#define _XOPEN_SOURCE /* grantpt() and al. */
#define _GNU_SOURCE /* on_exit */
 
#include <sys/types.h> /* waitpid() */
#include <sys/wait.h> /* waitpid() */
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* kill(), on_exit() */
#include <unistd.h> /* close() */
#include <fcntl.h> /* O_RDWR */
#include <string.h> /* strchr() */
 
#ifndef __CYGWIN__
#if HAVE_SYS_STROPTS_H
#include <sys/stropts.h> /* grantpt(), unlockpt() */
#endif
#include <libgen.h> /* basename() */
#endif /* __CYGWIN__ */
 
#include <termios.h> /* struct termios and al. */
#include <signal.h> /* signal() and al. */
#include <errno.h> /* errno and al. */
 
#include "channel.h"
#include "generic.h"
#include "fd.h"
 
struct xterm_channel
{
struct fd_channel fds;
int pid;
char** argv;
};
 
#ifdef __CYGWIN__
char *basename(const char *filename)
{
char *p = strrchr (filename, '/');
return p ? p + 1 : (char *) filename;
}
#endif /* __CYGWIN__ */
 
static void xterm_close(void * data)
{
struct xterm_channel * xt = data;
 
if(!xt)
return;
 
if(xt->fds.fdin != -1)
close(xt->fds.fdin);
 
if(xt->pid != -1)
{
kill(xt->pid, SIGKILL);
waitpid(xt->pid, NULL, 0);
}
if (xt->argv)
free (xt->argv);
 
xt->fds.fdin = -1;
xt->fds.fdout = -1;
xt->pid = -1;
xt->argv = NULL;
}
 
static void xterm_exit(int i, void * data)
{
xterm_close(data);
}
 
#define MAX_XTERM_ARGS 100
static void * xterm_init(const char * input)
{
struct xterm_channel * retval = malloc(sizeof(struct xterm_channel));
if(retval)
{
int i;
char *arglist;
 
retval->fds.fdin = -1;
retval->fds.fdout = -1;
retval->pid = -1;
 
#if defined(HAS_ON_EXIT)
/* reset cause exit(1), leaving an xterm opened */
on_exit(xterm_exit, retval);
#endif
i = 2;
arglist = (char*)input;
retval->argv = malloc(sizeof(char*) * MAX_XTERM_ARGS);
if (!retval->argv) {
free(retval);
return NULL;
}
/* Assume xterm arguments are separated by whitespace */
while ((retval->argv[i++] = strtok(arglist, " \t\n"))) {
arglist = NULL;
if (i == MAX_XTERM_ARGS - 1) {
free(retval);
return NULL;
}
}
}
return (void*)retval;
}
 
 
 
static int xterm_open(void * data)
{
#if defined(HAS_GRANTPT) && defined(HAS_UNLOCKPT) && defined(HAS_PTSNAME)
struct xterm_channel * xt = data;
int master, retval;
char * slavename;
struct termios termio;
char arg[64], * fin;
 
if(!data)
{
errno = ENODEV;
return -1;
}
 
master = open("/dev/ptmx", O_RDWR);
 
if(master < 0)
return -1;
 
grantpt(master);
unlockpt(master);
slavename = (char*)ptsname(master);
 
if(!slavename)
{
errno = ENOTTY;
goto closemastererror;
}
 
xt->fds.fdout = xt->fds.fdin = open(slavename, O_RDWR);
if(xt->fds.fdout < 0) goto closemastererror;
 
//#if !defined(linux) && !defined(__CYGWIN__)
#if defined(I_PUSH)
/* Linux does not support STREAMS-style line discipline, even with LiS. */
retval = ioctl(xt->fds.fdin, I_PUSH, "ptem");
if(retval < 0) goto closeslaveerror;
 
retval = ioctl(xt->fds.fdin, I_PUSH, "ldterm");
if(retval < 0) goto closeslaveerror;
#endif
retval = tcgetattr(xt->fds.fdin, &termio);
if(retval < 0) goto closeslaveerror;
termio.c_lflag &= ~ECHO;
retval = tcsetattr(xt->fds.fdin, TCSADRAIN, &termio);
if(retval < 0) goto closeslaveerror;
 
xt->pid = fork();
 
if(xt->pid == -1) goto closeslaveerror;
 
if(xt->pid == 0)
{
/* Ctrl-C on sim still kill the xterm, grrr */
signal(SIGINT, SIG_IGN);
 
fin = slavename+strlen(slavename)-2;
if (strchr(fin, '/' ))
{
sprintf(arg, "-S%s/%d",
basename(slavename),
master);
}
else
{
sprintf(arg, "-S%c%c%d", fin[0], fin[1], master);
}
xt->argv[0] = "xterm";
xt->argv[1] = arg;
execvp("xterm", xt->argv);
write(master, "\n", 1);
exit(1);
}
 
do retval = read(xt->fds.fdin, &arg, 1);
while(retval >= 0 && arg[0] != '\n');
if(retval < 0) goto closeslaveerror;
 
termio.c_lflag |= ECHO;
retval = tcsetattr(xt->fds.fdin, TCSADRAIN, &termio);
 
if(retval < 0) goto closeslaveerror;
return 0;
 
closeslaveerror:
close(xt->fds.fdin);
 
closemastererror:
close(master);
xt->pid = xt->fds.fdin = xt->fds.fdout = -1;
return -1;
 
#else
/* I don't see how this stuff should be working on a system that doesn't know
grantpt(), unlockpt(), ptsname(). Mac OS X also does not have /dev/ptmx.
-hpanther
*/
return -1;
#endif
}
struct channel_ops xterm_channel_ops =
{
init: xterm_init,
open: xterm_open,
close: xterm_close,
read: fd_read,
write: fd_write,
free: generic_free,
};
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
 
/tty.c
0,0 → 1,196
/* tty.c -- Definition of functions for peripheral to
* communicate with host via a tty.
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
 
#include "channel.h"
#include "generic.h"
#include "fd.h"
 
// Default parameters if not specified in config file
#define DEFAULT_BAUD B19200
#define DEFAULT_TTY_DEVICE "/dev/ttyS0"
 
struct tty_channel
{
struct fd_channel fds;
};
 
static struct {
char* name;
int value;
} baud_table[] = {
{"50", B50},
{"2400", B2400},
{"4800", B4800},
{"9600", B9600},
{"19200", B19200},
{"38400", B38400},
{"115200", B115200},
{"230400", B230400},
{0, 0}
};
 
// Convert baud rate string to termio baud rate constant
int
parse_baud(char* baud_string)
{
int i;
for (i = 0; baud_table[i].name; i++) {
if (!strcmp(baud_table[i].name, baud_string))
return baud_table[i].value;
}
 
fprintf(stderr, "Error: unknown baud rate: %s\n", baud_string);
fprintf(stderr, " Known baud rates: ");
 
for (i = 0; baud_table[i].name; i++) {
fprintf(stderr, "%s%s", baud_table[i].name, baud_table[i+1].name ? ", " : "\n");
}
return B0;
}
 
static void * tty_init(const char * input)
{
int fd, baud;
char *param_name, *param_value, *device;
struct termios options;
struct tty_channel* channel;
 
channel = (struct tty_channel*)malloc(sizeof(struct tty_channel));
if (!channel)
return NULL;
 
// Make a copy of config string, because we're about to mutate it
input = strdup(input);
if (!input)
goto error;
 
baud = DEFAULT_BAUD;
device = DEFAULT_TTY_DEVICE;
 
// Parse command-line parameters
// Command line looks like name1=value1,name2,name3=value3,...
while ((param_name = strtok((char*)input, ","))) {
 
input = NULL;
 
// Parse a parameter's name and value
param_value = strchr(param_name,'=');
if (param_value != NULL) {
*param_value = '\0';
param_value++; // Advance past '=' character
}
 
if (!strcmp(param_name, "baud") && param_value) {
baud = parse_baud(param_value);
if (baud == B0) {
goto error;
}
} else if (!strcmp(param_name, "device")) {
device = param_value;
} else {
fprintf(stderr, "error: unknown tty channel parameter \"%s\"\n", param_name);
goto error;
}
}
 
fd = open(device, O_RDWR);
if (fd < 0)
goto error;
 
// Get the current options for the port...
if (tcgetattr(fd, &options) < 0)
goto error;
 
// Set the serial baud rate
cfsetispeed(&options, baud);
cfsetospeed(&options, baud);
 
// Enable the receiver and set local mode...
 
/* cfmakeraw(&options);
*
* cygwin lacks cfmakeraw(), just do it explicitly
*/
options.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
|INLCR|IGNCR|ICRNL|IXON);
options.c_oflag &= ~OPOST;
options.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
options.c_cflag &= ~(CSIZE|PARENB);
options.c_cflag |= CS8;
options.c_cflag |= (CLOCAL | CREAD);
 
 
// Set the new options for the port...
if (tcsetattr(fd, TCSANOW, &options) < 0)
goto error;
 
channel->fds.fdin = channel->fds.fdout = fd;
free((void *)input);
return channel;
error:
if (fd > 0)
close(fd);
free(channel);
if (input)
free((void *)input);
return NULL;
}
 
static int tty_open(void * data)
{
return 0;
}
 
static int tty_read(void * data, char * buffer, int size)
{
return fd_read(data, buffer, size);
}
 
static int tty_write(void * data, const char * buffer, int size)
{
return fd_write(data, buffer, size);
}
 
struct channel_ops tty_channel_ops =
{
init: tty_init,
open: tty_open,
close: generic_close,
read: fd_read,
write: fd_write,
free: generic_free,
};
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
 
/tcp.c
0,0 → 1,181
/* tcp.c -- Definition of functions for peripheral to
* communicate with host via a tcp socket.
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
#include "channel.h"
#include "generic.h"
#include "fd.h"
 
struct tcp_channel
{
struct fd_channel fds;
int socket_fd; /* Socket to listen to */
int port_number; /* TCP port number */
int connected; /* If 0, no remote endpoint yet */
int nonblocking; /* If 0, read/write will block until
remote client connects */
};
 
static void * tcp_init(const char * input)
{
int port_number, fd, flags;
struct sockaddr_in local_ip;
struct tcp_channel* channel = (struct tcp_channel*)malloc(sizeof(struct tcp_channel));
if (!channel)
return NULL;
 
fd = 0;
channel->nonblocking = 1;
channel->fds.fdin = -1;
channel->fds.fdout = -1;
channel->socket_fd = -1;
channel->port_number = -1;
port_number = atoi(input);
if (port_number == 0)
goto error;
 
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
goto error;
 
flags = 1;
if(setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(const char*)&flags,sizeof(int)) < 0)
{
perror("Can not set SO_REUSEADDR option on channel socket");
goto error;
}
 
memset(&local_ip, 0, sizeof(local_ip));
local_ip.sin_family = AF_INET;
local_ip.sin_addr.s_addr = htonl(INADDR_ANY);
local_ip.sin_port = htons(port_number);
if (bind(fd, (struct sockaddr*)&local_ip, sizeof(local_ip)) < 0) {
perror("Can't bind local address");
goto error;
}
 
if (channel->nonblocking) {
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
{
perror("Can not make channel socket non-blocking");
goto error;
}
}
 
if (listen(fd, 1) < 0)
goto error;
 
channel->socket_fd = fd;
channel->port_number = port_number;
channel->connected = 0;
return (void*)channel;
error:
if (fd)
close(fd);
free(channel);
return NULL;
}
 
static int tcp_open(void * data)
{
/* Socket is opened lazily, upon first read or write, so do nothing here */
return 0;
}
 
 
static int wait_for_tcp_connect(struct tcp_channel* channel)
{
int fd, sizeof_remote_ip;
struct sockaddr_in remote_ip;
 
sizeof_remote_ip = sizeof(remote_ip);
fd = accept(channel->socket_fd, (struct sockaddr*)&remote_ip, &sizeof_remote_ip);
if (fd < 0) {
if (channel->nonblocking) {
/* Not an error if there is not yet a remote connection - try again later */
if (errno == EAGAIN)
return 0;
}
perror("Couldn't accept connection");
return -1;
}
 
channel->fds.fdin = channel->fds.fdout = fd;
close(channel->socket_fd);
channel->socket_fd = -1;
channel->connected = 1;
return 1;
}
 
static int tcp_read(void * data, char * buffer, int size)
{
struct tcp_channel* channel = data;
 
/* Lazily connect to tcp partner on read/write */
if (!channel->connected) {
int retval = wait_for_tcp_connect(data);
if (retval <= 0)
return retval;
}
return fd_read(data, buffer, size);
}
 
static int tcp_write(void * data, const char * buffer, int size)
{
struct tcp_channel* channel = data;
 
/* Lazily connect to tcp partner on read/write */
if (!channel->connected) {
int retval = wait_for_tcp_connect(data);
if (retval < 0)
return retval;
}
return fd_write(data, buffer, size);
}
 
struct channel_ops tcp_channel_ops =
{
init: tcp_init,
open: tcp_open,
close: generic_close,
read: tcp_read,
write: tcp_write,
free: generic_free,
};
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
 
/file.c
0,0 → 1,162
/* file.c -- Definition of functions and structures for
peripheral to communicate with host through files
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#if HAVE_CONFIG_H
#include <config.h>
#endif
 
#define _GNU_SOURCE /* for strndup */
 
#include <sys/types.h> /* open() */
#include <sys/stat.h> /* open() */
#include <fcntl.h> /* open() */
#if HAVE_MALLOC_H
#include <malloc.h> /* calloc, free */
#endif
#include <string.h> /* strndup(), strchr() */
#include <errno.h> /* errno */
#include <unistd.h> /* close() */
 
#include "channel.h" /* struct channel_ops */
#include "fd.h" /* struct fd_channel, fd_read(), fd_write() */
 
struct file_channel
{
struct fd_channel fds;
char * namein;
char * nameout;
};
 
static void * file_init(const char * args)
{
struct file_channel * retval;
char * nameout;
 
if(!args)
{
errno = EINVAL;
return NULL;
}
 
retval = (struct file_channel*)calloc(1, sizeof(struct file_channel));
 
if(!retval)
{
return NULL;
}
 
retval->fds.fdin = -1;
retval->fds.fdout = -1;
 
nameout = strchr(args, ',');
 
if(nameout)
{
retval->namein = strndup(args, nameout - args);
retval->nameout = strdup(nameout+1);
}
else
{
retval->nameout = retval->namein = strdup(args);
}
 
return (void*)retval;
}
 
static int file_open(void * data)
{
struct file_channel * files = (struct file_channel *)data;
 
if(!files)
{
errno = ENODEV;
return -1;
}
 
if(files->namein == files->nameout)
{
/* if we have the same name in and out
* it cannot (logically) be a regular files.
* so we wont create one
*/
files->fds.fdin = files->fds.fdout = open(files->namein, O_RDWR);
 
return files->fds.fdin < 0 ? -1 : 0;
}
 
 
files->fds.fdin = open(files->namein, O_RDONLY | O_CREAT, 0664);
 
if(files->fds.fdin < 0)
return -1;
 
files->fds.fdout = open(files->nameout, O_WRONLY | O_CREAT, 0664);
 
if(files->fds.fdout < 0)
{
close(files->fds.fdout);
files->fds.fdout = -1;
return -1;
}
 
return 0;
}
 
static void file_close(void * data)
{
struct file_channel * files = (struct file_channel *)data;
 
if(files->fds.fdin != files->fds.fdout)
close(files->fds.fdin);
 
close(files->fds.fdout);
 
files->fds.fdin = -1;
files->fds.fdout = -1;
}
 
static void file_free(void * data)
{
struct file_channel * files = (struct file_channel *)data;
 
if(files->namein != files->nameout)
free(files->namein);
 
free(files->nameout);
 
free(files);
}
 
struct channel_ops file_channel_ops =
{
init: file_init,
open: file_open,
close: file_close,
read: fd_read,
write: fd_write,
free: file_free,
};
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
/fd.c
0,0 → 1,160
/* fd.c -- Definition of functions and structures for
peripheral to communicate with host through file descriptors
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#if HAVE_CONFIG_H
#include <config.h>
#endif
 
#include <sys/time.h> /* struct timeval */
#include <sys/types.h> /* fd_set */
#include <stdio.h> /* perror */
#include <stdlib.h> /* atoi */
#include <unistd.h> /* read, write, select */
#if HAVE_MALLOC_H
#include <malloc.h> /* calloc, free */
#endif
#include <string.h> /* strchr */
#include <errno.h> /* errno */
 
#include "channel.h"
#include "generic.h"
#include "fd.h"
 
static void * fd_init(const char * args)
{
struct fd_channel * retval;
 
retval = (struct fd_channel*)calloc(1, sizeof(struct fd_channel));
 
if(!retval)
{
return NULL;
}
 
 
retval->fdin = atoi(args); /* so 0 if garbage */
/* TODO: strtoul */
 
args = strchr(args, ',');
 
if(args)
{
retval->fdout = atoi(args+1);
}
else
{
retval->fdout = retval->fdin;
}
 
return (void*)retval;
}
 
int fd_read(void * data, char * buffer, int size)
{
struct fd_channel * fds = (struct fd_channel *)data;
struct timeval timeout = { 0, 0 };
fd_set rfds;
int retval;
 
if(!fds)
{
errno = ENODEV;
return -1;
}
 
FD_ZERO(&rfds);
FD_SET(fds->fdin, &rfds);
 
retval = select(fds->fdin+1, &rfds, NULL, NULL, &timeout);
 
if(retval <= 0)
return retval;
 
return read(fds->fdin, buffer, size);
}
 
int fd_write(void * data, const char * buffer, int size)
{
struct fd_channel * fds = (struct fd_channel *)data;
if(fds)
{
return write(fds->fdout, buffer, size);
}
errno = ENODEV;
return -1;
}
 
static int fd_isok(void * data)
{
struct fd_channel * fds = (struct fd_channel *)data;
if(fds)
{
return fds->fdout != -1 && fds->fdin != -1;
}
return 0;
}
 
static int fd_status_fd(int fd, char * str, int size)
{
if(fd == -1)
return snprintf(str, size, "closed");
 
return snprintf(str, size, "opened(fd=%d)", fd);
}
 
char * fd_status(void * data)
{
static char retval[256];
int index = 0;
 
struct fd_channel * fds = (struct fd_channel *)data;
if(fds)
{
index += snprintf(retval + index, sizeof(retval) - index, "in ");
index += fd_status_fd(fds->fdin, retval + index, sizeof(retval) - index);
 
index += snprintf(retval + index, sizeof(retval) - index, "out ");
index += fd_status_fd(fds->fdout, retval + index, sizeof(retval) - index);
}
else
{
snprintf(retval, sizeof(retval), "(null)");
}
return retval;
}
 
struct channel_ops fd_channel_ops =
{
init: fd_init,
open: generic_open,
close: generic_close,
read: fd_read,
write: fd_write,
free: generic_free,
isok: fd_isok,
status: fd_status,
};
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
/generic.c
0,0 → 1,61
/* generic.c -- Definition of generic functions for peripheral to
* communicate with host
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#if HAVE_CONFIG_H
#include <config.h>
#endif
 
#if HAVE_MALLOC_H
#include <malloc.h> /* calloc, free */
#endif
 
#include <errno.h> /* errno */
 
 
int generic_open(void * data)
{
if(data)
{
return 0;
}
errno = ENODEV;
return -1;
}
 
void generic_close(void * data)
{
return;
}
 
void generic_free(void * data)
{
if(data)
{
free(data);
}
}
 
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
/Makefile.am
0,0 → 1,30
# Makefile -- Makefile for peripherals channels to host
# Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
#
# This file is part of OpenRISC 1000 Architectural Simulator.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
 
noinst_LIBRARIES = libchannels.a
libchannels_a_SOURCES = \
channel.c \
fd.c \
file.c \
generic.c \
xterm.c \
tcp.c \
tty.c
 
/fd.h
0,0 → 1,34
/* generic.h -- Declaration of generic functions for peripheral to
* communicate with host
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#ifndef FD_H
#define FD_H
 
struct fd_channel
{
int fdin;
int fdout;
};
 
int fd_read(void * data, char * buffer, int size);
int fd_write(void * data, const char * buffer, int size);
 
#endif
/generic.h
0,0 → 1,29
/* generic.h -- Declaration of generic functions for peripheral to
* communicate with host
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#ifndef GENERIC_H
#define GENERIC_H
 
int generic_open(void * data);
void generic_close(void * data);
void generic_free(void * data);
 
#endif
/channel.h
0,0 → 1,68
/* channel.h -- Definition of types and structures for
peripheral to communicate with host. Addapted from UML.
Copyright (C) 2002 Richard Prescott <rip@step.polymtl.ca>
 
This file is part of OpenRISC 1000 Architectural Simulator.
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
#ifndef CHANNEL_H
#define CHANNEL_H
 
struct channel_ops
{
void *(*init)(const char *);
int (*open)(void *);
void (*close)(void *);
int (*read)(void *, char *, int);
int (*write)(void *, const char *, int);
void (*free)(void *);
int (*isok)(void*);
char* (*status)(void*);
};
 
struct channel
{
const struct channel_ops * ops;
void * data;
};
 
 
struct channel * channel_init(const char * descriptor);
/* read operation in non-blocking */
int channel_open(struct channel * channel);
int channel_read(struct channel * channel, char * buffer, int size);
int channel_write(struct channel * channel, const char * buffer, int size);
void channel_free(struct channel * channel);
int channel_ok(struct channel * channel);
char * channel_status(struct channel * channel);
 
void channel_close(struct channel * channel);
 
int register_channel(const char * name, const struct channel_ops * ops);
/* TODO: int unregister_channel(const char * name); */
 
/* for those who wants to automatically register at startup */
#define REGISTER_CHANNEL(NAME,OPS) \
static int NAME ## _dummy_register = register_channel(#NAME, OPS)
 
#endif
 
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
/.
. Property changes : Added: svn:ignore ## -0,0 +1,2 ## +Makefile +.deps

powered by: WebSVN 2.1.0

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