add "comp", a program for writing HAL boilerplate

This commit is contained in:
Jeff Epler 2006-09-06 22:43:35 +00:00
parent 975b7e4663
commit d29cb53fec
16 changed files with 470 additions and 19 deletions

View file

@ -1,4 +1,5 @@
classicladder
comp
emc_module_helper
emcsh
emcrsh
@ -30,3 +31,4 @@ emctop
keystick
mdi
xemc
yapps

4
debian/control vendored
View file

@ -3,12 +3,12 @@ Source: emc2
Section: misc
Priority: extra
Maintainer: Chris Radek <chris@timeguy.com>
Build-Depends: debhelper (>> 4.0.0),linux-headers-2.6.12-magma,g++,gcc-3.4,make,libc6-dev,tcl8.4-dev,tk8.4-dev,libgtk2.0-dev,pciutils-dev,libncurses-dev,gettext,libxaw7-dev,rtai-modules-2.6.12-magma,libreadline5-dev,lyx,lyx-qt,python,tetex-bin,latex2html
Build-Depends: debhelper (>> 4.0.0),linux-headers-2.6.12-magma,g++,gcc-3.4,make,libc6-dev,tcl8.4-dev,tk8.4-dev,libgtk2.0-dev,pciutils-dev,libncurses-dev,gettext,libxaw7-dev,rtai-modules-2.6.12-magma,libreadline5-dev,lyx,lyx-qt,python,tetex-bin,latex2html,yapps2
Standards-Version: 2.0.0-rc0
Package: emc2
Architecture: any
Depends: ${shlibs:Depends},linux-image-2.6.12-magma,rtai-modules-2.6.12-magma,libgtk2.0,tcl8.4,tk8.4,bwidget,libncurses,libreadline5
Depends: ${shlibs:Depends},linux-image-2.6.12-magma,rtai-modules-2.6.12-magma,libgtk2.0,tcl8.4,tk8.4,bwidget,libncurses,libreadline5,yapps2-runtime
Provides: emc2
Suggests: emc2-axis
Description: PC based motion controller for real-time Linux.

4
debian/control.in vendored
View file

@ -2,12 +2,12 @@ Source: emc2
Section: misc
Priority: extra
Maintainer: Chris Radek <chris@timeguy.com>
Build-Depends: debhelper (>> 4.0.0),linux-headers-@@KVERSION@@,g++,gcc-3.4,make,libc6-dev,tcl8.4-dev,tk8.4-dev,libgtk2.0-dev,pciutils-dev,libncurses-dev,gettext,libxaw7-dev,rtai-modules-2.6.12-magma,libreadline5-dev,lyx,lyx-qt,python,tetex-bin,latex2html
Build-Depends: debhelper (>> 4.0.0),linux-headers-@@KVERSION@@,g++,gcc-3.4,make,libc6-dev,tcl8.4-dev,tk8.4-dev,libgtk2.0-dev,pciutils-dev,libncurses-dev,gettext,libxaw7-dev,rtai-modules-2.6.12-magma,libreadline5-dev,lyx,lyx-qt,python,tetex-bin,latex2html,yapps2
Standards-Version: 2.0.0-rc0
Package: emc2
Architecture: any
Depends: ${shlibs:Depends},linux-image-@@KVERSION@@,rtai-modules-@@KVERSION@@,libgtk2.0,tcl8.4,tk8.4,bwidget,libncurses,libreadline5
Depends: ${shlibs:Depends},linux-image-@@KVERSION@@,rtai-modules-@@KVERSION@@,libgtk2.0,tcl8.4,tk8.4,bwidget,libncurses,libreadline5,yapps2-runtime
Provides: emc2
Suggests: emc2-axis
Description: PC based motion controller for real-time Linux.

View file

@ -417,6 +417,10 @@ $(call CONFILES,core_sim.hal): %/core_sim.hal: ../configs/common/core_sim.hal
endif # userspace
ifneq ($(KERNELRELEASE),)
include $(BASEPWD)/hal/components/Submakefile
endif
# KERNELRELEASE is nonempty, therefore we are building modules using the
# "kbuild" system. $(BASEPWD) is used here, instead of relative paths, because
# that's what kbuild seems to require

65
src/configure vendored
View file

@ -312,7 +312,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE EMC2VERSION SIMULATOR RTNAME RTAI RTLINUX RTLINUXPRO RTPREFIX KERNELDIR RTFLAGS RTDIR EMC2_HOME AUTODIRS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP WFLAGS DEPSTYLE EGREP KERNEL_VERS MODEXT BUILD_SYS EXT_RTFLAGS MODULE_DIR RIP_MODULE_DIR RUN_IN_PLACE EMC2_BIN_DIR EMC2_TCL_DIR EMC2_HELP_DIR EMC2_RTLIB_DIR EMC2_LANG_DIR EMC2_CONFIG_PATH EMC2_NCFILES_DIR REALTIME EMC2_IMAGE_DIR GTK_VER GTK_LIBS GTK_CFLAGS CXX CXXFLAGS ac_ct_CXX SET_MAKE RANLIB ac_ct_RANLIB AR GREP INSTALL SED PS KILL WHOAMI AWK INSMOD RMMOD LSMOD PIDOF IPCS FUSER PYTHON LYX PDFLATEX LATEX2HTML EPSTOPDF BUILD_DOCS USE_LIBM USE_STUBS USE_RTLIBM MATHINC MATHLIB RTAI3_MOD RTAI_MOD RTL_MOD MODPATH_adeos MODPATH_rtai_hal MODPATH_rtai_ksched MODPATH_rtai_fifos MODPATH_rtai_shm MODPATH_rtai_sem MODPATH_rtai_math MODPATH_rtai MODPATH_rt_mem_mgr MODPATH_rtai_sched MODPATH_rtai_libm MODPATH_rtl MODPATH_mbuff MODPATH_rtl_time MODPATH_rtl_sched MODPATH_rtl_posixio MODPATH_rtl_fifo TCL_DBGX TK_DBGX TCL_CFLAGS TK_CFLAGS TCL_LIBS TK_LIBS DATE HAVE_XAW XAW_LIBS HAVE_READLINE READLINE_LIBS HAVE_NCURSES NCURSES_LIBS USE_NLS HAVE_LOCALE_H LANGUAGES HAVE_LIBINTL_H HAVE_LIBINTL LOCALEDIR XGETTEXT XGETTEXT_TCL_WORKS MSGFMT MSGFMT_TCL_WORKS BUILD_AXIS BUILD_PYTHON INCLUDEPY SITEPY LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS PACKAGE EMC2VERSION SIMULATOR RTNAME RTAI RTLINUX RTLINUXPRO RTPREFIX KERNELDIR RTFLAGS RTDIR EMC2_HOME AUTODIRS CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP WFLAGS DEPSTYLE EGREP KERNEL_VERS MODEXT BUILD_SYS EXT_RTFLAGS MODULE_DIR RIP_MODULE_DIR RUN_IN_PLACE EMC2_BIN_DIR EMC2_TCL_DIR EMC2_HELP_DIR EMC2_RTLIB_DIR EMC2_LANG_DIR EMC2_CONFIG_PATH EMC2_NCFILES_DIR REALTIME EMC2_IMAGE_DIR GTK_VER GTK_LIBS GTK_CFLAGS CXX CXXFLAGS ac_ct_CXX SET_MAKE RANLIB ac_ct_RANLIB AR GREP INSTALL SED PS KILL WHOAMI AWK INSMOD RMMOD LSMOD PIDOF IPCS FUSER PYTHON YAPPS LYX PDFLATEX LATEX2HTML EPSTOPDF BUILD_DOCS USE_LIBM USE_STUBS USE_RTLIBM MATHINC MATHLIB RTAI3_MOD RTAI_MOD RTL_MOD MODPATH_adeos MODPATH_rtai_hal MODPATH_rtai_ksched MODPATH_rtai_fifos MODPATH_rtai_shm MODPATH_rtai_sem MODPATH_rtai_math MODPATH_rtai MODPATH_rt_mem_mgr MODPATH_rtai_sched MODPATH_rtai_libm MODPATH_rtl MODPATH_mbuff MODPATH_rtl_time MODPATH_rtl_sched MODPATH_rtl_posixio MODPATH_rtl_fifo TCL_DBGX TK_DBGX TCL_CFLAGS TK_CFLAGS TCL_LIBS TK_LIBS DATE HAVE_XAW XAW_LIBS HAVE_READLINE READLINE_LIBS HAVE_NCURSES NCURSES_LIBS USE_NLS HAVE_LOCALE_H LANGUAGES HAVE_LIBINTL_H HAVE_LIBINTL LOCALEDIR XGETTEXT XGETTEXT_TCL_WORKS MSGFMT MSGFMT_TCL_WORKS BUILD_AXIS BUILD_PYTHON INCLUDEPY SITEPY LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@ -4615,6 +4615,61 @@ echo "${ECHO_T}no" >&6
fi
if test $PYTHON = "none"
then
{ { echo "$as_me:$LINENO: error: python not found" >&5
echo "$as_me: error: python not found" >&2;}
{ (exit 1); exit 1; }; }
fi
# Extract the first word of "yapps", so it can be a program name with args.
set dummy yapps; ac_word=$2
echo "$as_me:$LINENO: checking for $ac_word" >&5
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
if test "${ac_cv_path_YAPPS+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
case $YAPPS in
[\\/]* | ?:[\\/]*)
ac_cv_path_YAPPS="$YAPPS" # Let the user override the test with a path.
;;
*)
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
as_dummy="/bin:/usr/bin:/usr/local/bin"
for as_dir in $as_dummy
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_path_YAPPS="$as_dir/$ac_word$ac_exec_ext"
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
test -z "$ac_cv_path_YAPPS" && ac_cv_path_YAPPS=""none""
;;
esac
fi
YAPPS=$ac_cv_path_YAPPS
if test -n "$YAPPS"; then
echo "$as_me:$LINENO: result: $YAPPS" >&5
echo "${ECHO_T}$YAPPS" >&6
else
echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6
fi
if test $YAPPS = "none"
then
{ { echo "$as_me:$LINENO: error: yapps not found -- install the 'yapps2' package" >&5
echo "$as_me: error: yapps not found -- install the 'yapps2' package" >&2;}
{ (exit 1); exit 1; }; }
fi
echo "$as_me:$LINENO: checking whether to build documentation" >&5
echo $ECHO_N "checking whether to build documentation... $ECHO_C" >&6
# Check whether --enable-build-documentation or --disable-build-documentation was given.
@ -4848,13 +4903,6 @@ fi
echo "$as_me: WARNING: no epstopdf, documentation will not be built" >&2;}
fi
fi
if ( test "$BUILD_DOCS" = "yes" ) ; then
if ( test "none" = "$PYTHON" ) ; then
BUILD_DOCS=no
{ echo "$as_me:$LINENO: WARNING: no python, documentation will not be built" >&5
echo "$as_me: WARNING: no python, documentation will not be built" >&2;}
fi
fi
#############################################################################
@ -8660,6 +8708,7 @@ s,@PIDOF@,$PIDOF,;t t
s,@IPCS@,$IPCS,;t t
s,@FUSER@,$FUSER,;t t
s,@PYTHON@,$PYTHON,;t t
s,@YAPPS@,$YAPPS,;t t
s,@LYX@,$LYX,;t t
s,@PDFLATEX@,$PDFLATEX,;t t
s,@LATEX2HTML@,$LATEX2HTML,;t t

View file

@ -795,6 +795,17 @@ AC_ARG_WITH(python,
])
AC_PATH_PROG(PYTHON,$PYTHON,"none", /bin:/usr/bin:/usr/local/bin)
if test $PYTHON = "none"
then
AC_MSG_ERROR([python not found])
fi
AC_PATH_PROG(YAPPS,yapps,"none", /bin:/usr/bin:/usr/local/bin)
if test $YAPPS = "none"
then
AC_MSG_ERROR([yapps not found -- install the 'yapps2' package])
fi
AC_MSG_CHECKING([whether to build documentation])
AC_ARG_ENABLE(build-documentation,
[ --disable-build-documentation Do not build documentation automatcally],
@ -855,12 +866,6 @@ if ( test "$BUILD_DOCS" = "yes" ) ; then
AC_MSG_WARN([no epstopdf, documentation will not be built])
fi
fi
if ( test "$BUILD_DOCS" = "yes" ) ; then
if ( test "none" = "$PYTHON" ) ; then
BUILD_DOCS=no
AC_MSG_WARN([no python, documentation will not be built])
fi
fi
AC_SUBST(BUILD_DOCS)
#############################################################################

View file

@ -39,7 +39,7 @@ $(TOGLMODULE): $(call TOOBJS, $(TOGLMODULESRCS))
PYTARGETS += $(EMCMODULE) $(MINIGLMODULE) $(SETICONMODULE) $(TOGLMODULE)
PYSCRIPTS := axis.py axis-remote.py emctop.py hal_manualtoolchange.py \
mdi.py image-to-gcode.py lintini.py
mdi.py image-to-gcode.py lintini.py comp.py
PYTARGETS += $(patsubst %.py,../bin/%,$(PYSCRIPTS))
@ -53,6 +53,9 @@ PYI18NSRCS := $(addprefix emc/usr_intf/axis/scripts/, $(PYSCRIPTS)) \
../lib/python/propertywindow.py \
../share/axis/tcl/axis.tcl
%.py: %.g
$(YAPPS) $< $@
po/axis.pot: $(PYI18NSRCS)
$(XGETTEXT) -k_ -o $@ $^
PYTARGETS += po/axis.pot

View file

@ -1,3 +1,4 @@
comp.py
.xvpics
.xvpthumb
dist

View file

@ -0,0 +1,213 @@
#!/usr/bin/python
# This is 'comp', a tool to write HAL boilerplate
# Copyright 2006 Jeff Epler <jepler@unpythonic.net>
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import sys
%%
parser Hal:
ignore: "//.*"
ignore: "/[*](.|\n)*?[*]/"
ignore: "[ \t\r\n]+"
token END: ";;"
token DIRECTION: "r|w|rw"
token PINDIRECTION: "in|out|io"
token TYPE: "float|bit|u32|s32|u16|s16|u8|s8"
token NAME: "[a-zA-Z_][a-zA-Z0-9_]*"
token NUMBER: "[0-9]+|0x[0-9a-fA-F]+"
rule File: Declaration* "$" {{ return True }}
rule Declaration:
"component" NAME ";" {{ comp(NAME); }}
| "pin" NAME TYPE PINDIRECTION ";" {{ pin(NAME, TYPE, PINDIRECTION) }}
| "param" NAME TYPE DIRECTION ";"{{ param(NAME, TYPE, DIRECTION) }}
| "function" NAME OptFP ";" {{ function(NAME, OptFP) }}
| "option" NAME Value ";" {{ option(NAME, Value) }}
rule OptFP: "fp" {{ return 1 }} | "nofp" {{ return 0 }} | {{ return 1 }}
rule Value: "yes" {{ return 1 }} | "no" {{ return 0 }}
| NAME {{ return NAME }}
| NUMBER {{ return int(NUMBER,0) }}
%%
dirmap = {'r': 'HAL_RD_WR', 'w': 'HAL_WR', 'rw': 'HAL_RD_WR', 'in': 'HAL_RD', 'out': 'HAL_WR', 'io': 'HAL_RD_WR' }
functions = []; params = []; pins = []; options = {}
comp_name = None
def comp(name):
global comp_name
comp_name = name;
def pin(name, type, dir):
pins.append((name, type, dir))
def param(name, type, dir):
params.append((name, type, dir))
def function(name, fp):
functions.append((name, fp))
def option(name, value):
options[name] = value
def prologue(f):
print >> f, """\
#include "rtapi.h"
#include "rtapi_app.h"
#include "hal.h"
static int comp_id;
#define FUNCTION(name) static void name(struct state *arg, long period)
"""
names = {}
has_data = options.get("data")
print >>f
print >>f, "struct state {"
for name, type, dir in pins:
if names.has_key(name):
raise RuntimeError, "Duplicate pin name: %s" % name
print >>f, " hal_%s_t *%s;" % (type, name)
names[name] = 1
for name, type, dir in params:
if names.has_key(name):
raise RuntimeError, "Duplicate param name: %s" % name
print >>f, " hal_%s_t %s;" % (type, name)
names[name] = 1
if has_data:
print >>f, " void *_data;"
print >>f, "};"
print >>f
names = {}
for name, fp in functions:
if names.has_key(name):
raise RuntimeError, "Duplicate function name: %s" % name
print >>f, "static void %s(struct state *arg, long period);" % name
names[name] = 1
print >>f, "static int get_data_size(void);"
print >>f
print >>f, "static int export(char *prefix) {"
print >>f, " char buf[HAL_NAME_LEN + 2];"
print >>f, " int r = 0;"
print >>f, " int sz = sizeof(struct state) + get_data_size();"
print >>f, " struct state *arg = hal_malloc(sz);"
for name, type, dir in pins:
print >>f, " r = hal_pin_%s_newf(%s, &(arg->%s), comp_id," % (
type, dirmap[dir], name)
print >>f, " \"%%s.%s\", prefix);" % (name.replace("_", "-"))
print >>f, " if(r != 0) return r;"
for name, type, dir in params:
print >>f, " r = hal_param_%s_newf(%s, &(arg->%s), comp_id," % (
type, dirmap[dir], name)
print >>f, " \"%%s.%s\", prefix);" % (name.replace("_", "-"))
print >>f, " if(r != 0) return r;"
for name, fp in functions:
print >>f, " rtapi_snprintf(buf, HAL_NAME_LEN, \"%%s.%s\", prefix);"\
% name
print >>f, " r = hal_export_funct(buf, (void(*)(void *arg, long))%s, arg, %s, 0, comp_id);" % (
name, int(fp))
print >>f, " if(r != 0) return r;"
print >>f, " return 0;"
print >>f, "}"
if options.get("count_function"):
print >>f, "static int get_count(void);"
if options.get("rtapi_app", 1):
if not options.get("singleton") and not options.get("count_function") :
print >>f, "static int count = %s;" \
% options.get("default_count", 1)
print >>f, "MODULE_PARM(count, \"i\");"
print >>f, "MODULE_PARM_DESC(count, \"number of %s\");" % comp_name
print >>f, "int rtapi_app_main(void) {"
print >>f, " int r = 0;"
if not options.get("singleton"):
print >>f, " int i;"
if options.get("count_function"):
print >>f, " int count = get_count();"
print >>f, " comp_id = hal_init(\"%s\");" % comp_name
print >>f, " if(comp_id < 0) return comp_id;"
if options.get("singleton"):
print >>f, " r = export(\"%s\");" % \
comp_name.replace("_", "-")
else:
print >>f, " for(i=0; i<count; i++) {"
print >>f, " char buf[HAL_NAME_LEN + 2];"
print >>f, " rtapi_snprintf(buf, HAL_NAME_LEN, " \
"\"%s.%%d\", i);" % \
comp_name.replace("_", "-")
print >>f, " r = export(buf);"
print >>f, " if(r != 0) break;"
print >>f, " }"
print >>f, " if(r) hal_exit(comp_id);"
print >>f, " return r;";
print >>f, "}"
print >>f
print >>f, "void rtapi_app_exit(void) { hal_exit(comp_id); }"
print >>f
if not options.get("no_convenience_defines"):
for name, type, dir in pins:
print >>f, "#define %s (*arg->%s)" % (name, name)
for name, type, dir in params:
print >>f, "#define %s (arg->%s)" % (name, name)
if has_data:
print >>f, "#define data (*(%s*)&(arg->_data))" % options['data']
print >>f
print >>f
def epilogue(f):
data = options.get('data')
print >>f
if data:
print >>f, "static int get_data_size(void) { return sizeof(%s); }" % data
else:
print >>f, "static int get_data_size(void) { return 0; }"
import sys
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = sys.stdin
f = f.read()
a, b = f.split("\n;;\n", 1)
p = parse('File', a)
if not p: raise SyntaxError
if len(sys.argv) > 2:
f = open(sys.argv[2], "w")
else:
f = sys.stdout
prologue(f)
f.write(b)
epilogue(f)

View file

@ -0,0 +1,25 @@
ifneq ($(KERNELRELEASE),)
COMPS := $(patsubst $(BASEPWD)/%,%,$(wildcard $(BASEPWD)/hal/components/*.comp))
include $(patsubst %.comp, $(BASEPWD)/objects/%.mak, $(COMPS))
else
P=
COMPS := $(wildcard hal/components/*.comp)
-include $(patsubst %.comp, objects/%.mak, $(COMPS))
Makefile: $(patsubst %.comp, objects/%.mak, $(COMPS))
endif
obj-m += $(patsubst hal/components/%.comp, %.o, $(COMPS))
objects/%.mak: %.comp
$(ECHO) "Creating $(notdir $@)"
@mkdir -p $(dir $@)
@echo $(notdir $*)-objs := objects/$*.o > $@.tmp
@echo ../rtlib/$(notdir $*).o: objects/$*.o >> $@.tmp
@mv -f $@.tmp $@
objects/%.c: %.comp ../bin/comp
$(ECHO) "Preprocessing $(notdir $<)"
@mkdir -p $(dir $@)
@../bin/comp $< $@
modules: $(patsubst %.comp, objects/%.c, $(COMPS))

View file

@ -0,0 +1,18 @@
component blend;
pin in_1 float in;
pin in_2 float in;
pin select float in;
pin out float out;
param open bit w;
function update;
;;
FUNCTION(update) {
double select_ = select;
if(!open) { if(select_ < 0) select_ = 0; if(select_ > 1) select_ = 1; }
out = in_1 * select_ + in_2 + (1 - select_);
}

View file

@ -0,0 +1,24 @@
// This is a 'charge-pump' component for EMC2 HAL
// Copyright 2006 Jeff Epler <jepler@unpythonic.net>
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
component charge_pump;
option singleton yes;
pin out bit out;
function update nofp;
;;
MODULE_LICENSE("GPL");
FUNCTION(update) { out = !out; }

View file

@ -0,0 +1,18 @@
component ddt;
pin in float in;
pin out float out;
option data ddt_data;
function update;
;;
typedef struct { float old; } ddt_data;
FUNCTION(update) {
float tmp = in;
out = (tmp - data.old) / (period * 1e-9);
data.old = tmp;
}

View file

@ -0,0 +1,32 @@
component edge;
pin in bit in;
pin out bit out;
pin out_invert bit out;
param in_edge bit w;
param out_width float w;
param time_left float r;
param last_in bit r;
function update;
;;
FUNCTION(update){
float fperiod = period * 1e-9;
int new_in = in;
if(in_edge) new_in = ! new_in;
if(new_in && new_in != last_in) {
time_left = out_width;
out = 1; out_invert = 0;
} else if(time_left > 0) {
time_left -= fperiod;
out = 1; out_invert = 0;
} else {
time_left = 0;
out = 0; out_invert = 1;
}
last_in = new_in;
}

View file

@ -0,0 +1,40 @@
// This is a 'majority-of-3' component for EMC2 HAL
// Copyright 2006 Jeff Epler <jepler@unpythonic.net>
//
// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
component maj3;
pin in1 bit in;
pin in2 bit in;
pin in3 bit in;
pin out bit out;
param invert bit w;
function update nofp;
;;
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jeff Epler");
MODULE_DESCRIPTION("'Majority of 3' block for EMC HAL");
FUNCTION(update) {
if(invert)
out = (in1 + in2 + in3) < 2;
else
out = (in1 + in2 + in3) >= 2;
}

View file

@ -0,0 +1,17 @@
component offset;
function update_output;
function update_feedback;
pin offset float in;
pin in float in;
pin out float out;
pin fb_in float in;
pin fb_out float out;
;;
FUNCTION(update_feedback) { fb_out = fb_in - offset; }
FUNCTION(update_output) { out = in + offset; }