diff options
245 files changed, 877 insertions, 29509 deletions
diff --git a/Makefile.common b/Makefile.common index 64891345ba..aafe85fe79 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1,6 +1,6 @@ # -*- Makefile -*- # -# Copyright 2004,2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright 2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -55,17 +55,13 @@ libspudir = $(libdir)spu # This used to be set in configure.ac but is now defined here for all # Makefiles when this fragment is included. STD_DEFINES_AND_INCLUDES = $(DEFINES) $(BOOST_CPPFLAGS) \ - $(OMNITHREAD_INCLUDES) $(GNURADIO_INCLUDES) $(GRUEL_INCLUDES) + $(GNURADIO_INCLUDES) $(GRUEL_INCLUDES) # when including for compilation from pre-installed libraries and such, # need to make sure those are put last on the compile command WITH_INCLUDES = @with_INCLUDES@ WITH_SWIG_INCLUDES = @with_SWIG_INCLUDES@ -# How to link in the top-level omnithreads library from inside the tree -OMNITHREAD_INCLUDES = @omnithread_INCLUDES@ -OMNITHREAD_LA = @omnithread_LA@ - # Where to find gnuradio include files in the current build tree # top_srcdir for original stuff, top_builddir for generated files GNURADIO_INCLUDES = @gnuradio_core_INCLUDES@ @@ -81,10 +77,6 @@ GRUEL_LA = @gruel_LA@ USRP_INCLUDES = @usrp_INCLUDES@ USRP_LA = @usrp_LA@ -# How to link the mblock library from inside the tree -MBLOCK_INCLUDES = @mblock_INCLUDES@ -MBLOCK_LA = @mblock_LA@ - # How to link the gcell library from inside the tree (the PPU part) GCELL_INCLUDES = @gcell_INCLUDES@ GCELL_LA = @gcell_LA@ @@ -100,8 +92,7 @@ GCELL_EMBEDSPU_LIBTOOL = @abs_top_srcdir@/gcell/lib/runtime/gcell-embedspu-libto # using AM_PATH_PROG, but now here have to add a -f to be like GNU make RM=$(RM_PROG) -f -RUN_GUILE = GUILE_LOAD_PATH="@abs_top_srcdir@/gruel/src/scheme:@abs_top_srcdir@/mblock/src/scheme" @GUILE@ -e main -s -COMPILE_MBH = $(RUN_GUILE) $(top_srcdir)/mblock/src/scheme/gnuradio/compile-mbh.scm +RUN_GUILE = GUILE_LOAD_PATH="@abs_top_srcdir@/gruel/src/scheme" @GUILE@ -e main -s # Base directory for example applications exampledir = $(datadir)/gnuradio/examples @@ -177,7 +177,7 @@ http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103 We use Smart Pointers, the thread library and a bunch of other boost stuff. If your system doesn't have boost 1.35 or later, see README.building-boost -for additional info. +for additional info. (Note: Mac OSX systems require 1.37 or later.) (7) cppunit 1.9.14 or later. http://cppunit.sourceforge.net diff --git a/README.components b/README.components deleted file mode 100755 index 996f2ee545..0000000000 --- a/README.components +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/sh - -# $Id$ - -# Copyright 2008 Free Software Foundation. -# -# DO NOT RUN THIS SCRIPT UNTIL YOU UNDERSTAND IT!!! IT WILL REMOVE -# FILES ON YOUR SYSTEM. -# -# Read the script thoroughly before running it; it will *remove* -# /usr/local/gnuradio and repopulate it. -# -# This script provides a way to build GNU Radio modules individually, -# and both serves as an example of using the component build system -# and provides a way to test the build system. When run, it will -# build and install each GNU Radio module in turn, using the -# just-installed modules as prerequisites. It places the output of -# each build in a separate file BUILD.NNN.options, so that one can do -# 'tail -f BUILD.*' to see which components were successfully built. - -# This script is intended to be broadly portable; be careful when -# modifying not to cause problems on systems that place dependencies -# in other than /usr -# -# Besides GNU Radio dependencies, this program requires sudo, with a -# timer long enough to build each module (or no password requirement). -# - -set -x - -# Do not use /opt, because many systems do not have /opt and that -# risks running out of space in /. /usr/local/gnuradio is believed to -# be reasonable on all of *BSD and GNU/Linux. Probably this needs -# OS-specific overrides. -PREFIX=/usr/local/gnuradio - -echo "ABOUT TO COMPLETELY REMOVE $PREFIX in 10 SECONDS!" -sleep 10 - -echo -n "README.components START "; date - -# This file provides an example of how to build GNU Radio under pkgsrc. - -# Avoid using rm -rf with $PREFIX, which could be /. Make a backup of -# the old prefix. -sudo rm -rf $PREFIX.old -if [ -d $PREFIX ]; then - sudo mv $PREFIX $PREFIX.old -fi -rm -rf BUILD.* - -# Bootstrap just once, rather than once per module. -./bootstrap - -# Determine where prereqs come from. -export LDFLAGS= -export CPPFLAGS= -export PKG_CONFIG_PATH= -if [ -d /usr/pkg ]; then - # pkgsrc - LDFLAGS="$LDFLAGS -L/usr/pkg/lib -R/usr/pkg/lib" - CPPFLAGS="$CPPFLAGS -I/usr/pkg/include" - - # pkg-config is from pkgsrc, so already knows about /usr/pkg/lib/pkgconfig - PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PREFIX/lib/pkgconfig" -fi - -echo LDFLAGS ,$LDFLAGS, -echo CPPFLAGS ,$CPPFLAGS, -echo PKG_CONFIG_PATH ,$PKG_CONFIG_PATH, - -# Determine number of cpus and thus how many jobs to run. -ncpus=1 -case x`uname` in - xNetBSD) - ncpus=`sysctl hw.ncpu|awk '{print $3}'` - ;; -esac -jflag=-j`expr $ncpus \* 2` - -# These are currently ignored. -CONF_DOC_ARGS=" ---enable-doxygen ---enable-dot ---enable-latex-docs -" -CONF_DISABLE_ALL="--disable-all-components" - -# We use % instead of ' ' to be able to iterate with /bin/sh's for. -# This variable should list all possible arguments, in tsorted order. -CONF_ENABLE_ARGS=" ---enable-omnithread ---with-omnithread%--enable-gnuradio-core ---with-omnithread%--enable-pmt ---with-omnithread%--with-pmt%--enable-mblock ---with-omnithread%--with-pmt%--with-mblock%--enable-usrp ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--with-usrp%--enable-gr-usrp ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-msdd6000 ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-alsa ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-jack ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-oss ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-osx ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-portaudio ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-audio-windows ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-atsc ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-comedi ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-cvsd-vocoder ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--with-usrp%--enable-gr-gpio ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-gsm-fr-vocoder ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-pager ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--with-usrp%--enable-gr-radar-mono ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-radio-astronomy ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-trellis ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-video-sdl ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gr-wxgui ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--with-usrp%--enable-gr-sounder ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--with-usrp%--with-gr-usrp%--with-gr-wxgui%--enable-gr-utils ---with-omnithread%--with-gnuradio-core%--with-pmt%--with-mblock%--enable-gnuradio-examples -" - -seq=0 -for arg in $CONF_ENABLE_ARGS; do - - # Convert sequence numbers and arguments to usable values. - seqprint=`printf "%03d" $seq` - argspace=`echo $arg | sed -e 's/%/ /g'` - - echo "BUILDING WITH $argspace" - - ( - # configure with just one module - ./configure --prefix=$PREFIX $CONF_DISABLE_ALL $argspace && - - # remove all prior objects - make clean && - - # build - make $jflag && - - # install - sudo make install && - - echo "SUCCEEDED $argspace" - - ) > BUILD.$seqprint.$arg 2>&1 - - seq=`expr $seq + 1` -done - -echo -n "README.components FINISH "; date diff --git a/README.organization b/README.organization deleted file mode 100644 index 138d90189a..0000000000 --- a/README.organization +++ /dev/null @@ -1,239 +0,0 @@ -[This file is currently not baked and does not claim to represent -consensus.] - -* Introduction - -This file describes the current organization of the GNU Radio source -tree. It is intended to be both descriptive and normative. - -* Unresolved issues in organization - -The big issues are: - -1) Should we separate by "code needed to implement protocol/modulation -foo", or related blocks. to (that are therefore not so likely to be -used together). - -2) How do m-blocks impact organization? If m-blocks are in a separate -module, which seems reasonable, then do we have most modules depend on -m-blocks rather than just core, or do we have two versions of blocks - -the classic continuous block and the m-block wrapped block? If -m-blocks become the main path, what will be less awkward? - -3) Because some (ADROIT at BBN) have proposed to implement MACs in -click instead of GNU Radio, should we have a clean separation of -MAC/PHY within GNU Radio, to facilitate using MACs implemented in -various places? - -4) Examples abound, and many are in gnuradio-examples. It might be -better to put examples near the code they use, and to separate useful -programs (like USRP benchmarks) from true examples. Examples should -probably be installed in $prefix/share/examples/gnuradio. - -* Plan (normative) [[NOT BAKED!!! NO CONSENSUS!!!]] - -Create a new module gr-packet, to hold blocks generally relevant to -sending blocks of data. Create subdirectories within gr-packet for -specific protocols (e.g. 802.11, GNU Radio's GMSK "protocol"). - -Convert tunnel.py to be OS-independent and a general source/sink -block, decoupling modulation from OS plumbing. - -* Pointers to code to be integrated - -The immediate question is how to integrate the 802.11 implementation -done by BBN (and assigned to FSF), available at: - - http://acert.ir.bbn.com/viewvc/adroitgrdevel/adroitgrdevel/gr-bbn/ - -This contains blocks at various places in the stack, and gdt believs -that putting them in an 802.11 module will lead to less reuse and less -of a tendency to generalize. - -* Organization of the GNU Radio source tree (mostly descriptive) - -The GNU Radio source tree is rooted at the directory containing this -file; see README for how to get it if you're using a release or -tarball. - -Within this directory, there are a number of subdirectories, most of -which can be enabled or disabled independently. See README for how to -do that; this document is concerned with describing what each module -does enough to help someone who is familiar enough with GNU Radio to -write new code to choose where to put it. The list is not exhaustive. -The description of some modules also lists things that don't belong, -tagged with ?M. - -** gnuradio-core [foundational code for the rest of GNU Radio] - -(gen_interpolator_taps is not installed. Why? How is it used?) - -doc: glue to use with doxygen - -?M doc/other/tv-channel-frequencies: (TV specific) - -?M src/lib/g72x: - G.711 family codec - -src/lib/filter: - implementation and coefficient generation -src/lib/general: - foundational blocks not specific to any technology: - type conversion, {de,}vectorization, add, sub - rms power, throttle, sources, sinks, squelch base class - - general blocks: - agc, pll, sync, costas loop, power squelch, quadrature demod - - ?M framer/correlator - ?M packet source/sink - -src/lib/io: - basic file io, message io - oscope (trigger support) - i2c bus - ?M microtune eval board (like USRP; should probably have own module) - ?M SDR1000 - -src/lib/omnithread: - portable threading library (for when POSIX isn't portable enough) - -src/lib/reed-solomon: - reed-solomon implementation. Unclear how/whether it's wrapped into - blocks. - -src/lib/runtime: - blocks (basic, hier) and associated buffering - flowgraphs - timers - doubly-mapped circular buffers - -src/lib/swig: - code to wrap the rest in python - ?M atsc.i (cruft? moved?) - -src/python: - build utilities - -src/python/bin: - ?M microtune.py: microtune control program (installed and EXTRA_DIST!) - -src/python/gnuradio: - audio base class - engineering notation support - test harness support - test code (not installed) - basic block/flow_graph - -src/tests: - test code - ?M test_atsc.cc (# in Makefile.am, but still present) - -src/utils: - octave and Scheme scripts (not installed) - -** usrp - -This contains code to deal with the USRP, but not GNU Radio support. - -?M fusb - The "fusb" abstraction is arguably useful for all interface devices - that use USB, not just the USRP. - -** gr-usrp - -Code to use the USRP with GNU Radio. - -?M Arguably the Gnu Radio/USRP benchmarks belong here, but are in -examples - -** gr-audio-alsa -** gr-audio-jack -** gr-audio-oss -** gr-audio-osx -** gr-audio-portaudio -** gr-audio-windows - [All of these support audio for some particular audio backend. - -** gr-atsc - ATSC (HDTV) transmitter and receiver. - All blocks seem to be specific to ATSC. - ?M Perhaps some blocks should be abstracted out for reuse with other - than ATSC parameters. - -** gr-comedi - This module is missing a README that explains what it does. - http://www.comedi.org/ - -** gr-gsm-fr-vocoder - GSM 06.10 full rate vocoder, and gsm library - (Note that the presence of this argues for moving the G.711 code discussed above.) - -** gr-pager - POCSAG and FLEX - (gdt suspects there are blocks in here that could be generalized.) - -** gr-radio-astronomy - seems to use only standard blocks from python - -** gr-trellis - This module provides trellis code support, and appears generic. - -** gr-video-sdl - This appears to be like the audio modules, but for video and - specifically for SDL. Unlike audio which has a base class, there - does not appear to be an abstract video class in gnuradio-core. - -** gr-wxgui - Support for using wxwidgets from python. - ?M (Linux-specific??) code to use the Griffin Powermate (and hook it to a GUI) - glue to connect FFT and scope to gui - -** pmt - polymorphic types (building block) - -** mblock - Message block implementation. - Note that mblock being a module means that signal processing blocks - that are mblock-aware must depend on this module and thus probably - cannot be in gnuradio-core. Thus, m-block wrappers for the blocks - in gnuradio-core must be elsewhere and it is maybe a good idea to - move them to someplace like gnuradio-common where the streaming and - m-block versions can be together. - -** ezdop - Code to deal with the ezdop direction-finding hardware. - -** gr-ezdop - Glue code to use the ezdop from GNU Radio. - -** gr-rdf - (Currently empty) code to perform direction finding. - -** gnuradio-examples - - It's arguable that all of these are misplaced, and that examples - belong with the code that they use. - - Bona fide examples (code not intended to be useful except for reading): - c++/dial_tone (how to do things only in C++) - python/audio - - Test programs: - python/channel-coding - python/digital-voice - python/multi-antenna (?) - - Programs in between test and useful: - python/digital - ?M tunnel.py: glue to get packets to Linux, conflates modulation - and packet handling - python/multi_usrp - python/networking/measurement_slave (goes with what?) - - ?M Programs intended to be useful - python/apps/hf_{explorer,radio} - - ?M Kitchen sink: - python/usrp - benchmarks, test, basic fm/wfm/tv receivers, spectrum sensing, - fft, oscope diff --git a/config/Makefile.am b/config/Makefile.am index 527aefa7e4..959b8f014b 100644 --- a/config/Makefile.am +++ b/config/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2006,2008,2009 Free Software Foundation, Inc. +# Copyright 2001,2006,2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -69,7 +69,6 @@ m4macros = \ grc_gr_usrp.m4 \ grc_gr_video_sdl.m4 \ grc_gr_wxgui.m4 \ - grc_mblock.m4 \ grc_gruel.m4 \ grc_vrt.m4 \ gr_check_createfilemapping.m4 \ @@ -87,7 +86,6 @@ m4macros = \ gr_lib64.m4 \ gr_libgnuradio_core_extra_ldflags.m4 \ gr_no_undefined.m4 \ - gr_omnithread.m4 \ gr_pwin32.m4 \ gr_python.m4 \ gr_require_mc4020.m4 \ diff --git a/config/gr_omnithread.m4 b/config/gr_omnithread.m4 deleted file mode 100644 index 054f078247..0000000000 --- a/config/gr_omnithread.m4 +++ /dev/null @@ -1,52 +0,0 @@ -# Check for Omnithread (pthread/NT) thread support. -*- Autoconf -*- - -# Copyright 2003,2007 Free Software Foundation, Inc. - -# 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 3, 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., 51 Franklin Street, Boston, MA -# 02110-1301, USA. - -AC_DEFUN([GR_OMNITHREAD], -[ - # Check first for POSIX - ACX_PTHREAD( - [ AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]) - ot_posix="yes" - DEFINES="$DEFINES -DOMNITHREAD_POSIX=1" - ],[ - # If no POSIX support found, then check for NT threads - AC_MSG_CHECKING([for NT threads]) - - AC_LINK_IFELSE([ - #include <windows.h> - #include <winbase.h> - int main() { InitializeCriticalSection(NULL); return 0; } - ], - [ - ot_nt="yes" - DEFINES="$DEFINES -DOMNITHREAD_NT=1" - ], - [AC_MSG_FAILURE([GNU Radio requires POSIX threads. pthreads not found.])] - ) - AC_MSG_RESULT(yes) - ]) - AM_CONDITIONAL(OMNITHREAD_POSIX, test "x$ot_posix" = xyes) - AM_CONDITIONAL(OMNITHREAD_NT, test "x$ot_nt" = xyes) - - save_LIBS="$LIBS" - AC_SEARCH_LIBS([clock_gettime], [rt], [PTHREAD_LIBS="$PTHREAD_LIBS $LIBS"]) - AC_CHECK_FUNCS([clock_gettime gettimeofday nanosleep]) - LIBS="$save_LIBS" -]) - diff --git a/config/grc_gcell.m4 b/config/grc_gcell.m4 index ff289d1aec..b94deb4db4 100644 --- a/config/grc_gcell.m4 +++ b/config/grc_gcell.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc. +dnl Copyright 2001,2002,2003,2004,2005,2006,2008,2010 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -21,9 +21,6 @@ AC_DEFUN([GRC_GCELL],[ GRC_ENABLE(gcell) dnl GRC_WITH(gcell) - dnl Don't do gcell if omnithread skipped - GRC_CHECK_DEPENDENCY(gcell, omnithread) - dnl If execution gets to here, $passed will be: dnl with : if the --with code didn't error out dnl yes : if the --enable code passed muster and all dependencies are met diff --git a/config/grc_gr_audio_osx.m4 b/config/grc_gr_audio_osx.m4 index 95fbc17d55..df8634ff6f 100644 --- a/config/grc_gr_audio_osx.m4 +++ b/config/grc_gr_audio_osx.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc. +dnl Copyright 2001,2002,2003,2004,2005,2006,2008,2010 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -20,8 +20,7 @@ dnl Boston, MA 02110-1301, USA. AC_DEFUN([GRC_GR_AUDIO_OSX],[ GRC_ENABLE(gr-audio-osx) - dnl Don't do gr-audio-osx if omnithread or gnuradio-core skipped - GRC_CHECK_DEPENDENCY(gr-audio-osx, omnithread) + dnl Don't do gr-audio-osx if gnuradio-core skipped GRC_CHECK_DEPENDENCY(gr-audio-osx, gnuradio-core) dnl If execution gets to here, $passed will be: diff --git a/config/grc_gr_audio_portaudio.m4 b/config/grc_gr_audio_portaudio.m4 index 08d71f8fb2..ff551b38a7 100644 --- a/config/grc_gr_audio_portaudio.m4 +++ b/config/grc_gr_audio_portaudio.m4 @@ -22,7 +22,6 @@ AC_DEFUN([GRC_GR_AUDIO_PORTAUDIO],[ dnl Don't do gr-audio-portaudio if gnuradio-core skipped GRC_CHECK_DEPENDENCY(gr-audio-portaudio, gnuradio-core) - GRC_CHECK_DEPENDENCY(gr-audio-portaudio, omnithread) dnl If execution gets to here, $passed will be: dnl with : if the --with code didn't error out diff --git a/config/grc_mblock.m4 b/config/grc_mblock.m4 deleted file mode 100644 index e3ae1817f1..0000000000 --- a/config/grc_mblock.m4 +++ /dev/null @@ -1,59 +0,0 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc. -dnl -dnl This file is part of GNU Radio -dnl -dnl GNU Radio is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 3, or (at your option) -dnl any later version. -dnl -dnl GNU Radio is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with GNU Radio; see the file COPYING. If not, write to -dnl the Free Software Foundation, Inc., 51 Franklin Street, -dnl Boston, MA 02110-1301, USA. - -AC_DEFUN([GRC_MBLOCK],[ - GRC_ENABLE(mblock) - - GRC_WITH(mblock) - - dnl Don't do mblock if omnithread or pmt skipped - GRC_CHECK_DEPENDENCY(mblock, pmt) - GRC_CHECK_DEPENDENCY(mblock, omnithread) - - dnl If execution gets to here, $passed will be: - dnl with : if the --with code didn't error out - dnl yes : if the --enable code passed muster and all dependencies are met - dnl no : otherwise - if test $passed = yes; then - dnl Don't do mblock if guile not available - GRC_CHECK_GUILE(mblock) - fi - if test $passed != with; then - dnl how and where to find INCLUDES and LA - mblock_INCLUDES="-I\${abs_top_srcdir}/mblock/src/include" - mblock_LA="\${abs_top_builddir}/mblock/src/lib/libmblock.la" - fi - - AC_CONFIG_FILES([\ - mblock/Makefile \ - mblock/mblock.pc \ - mblock/doc/Makefile \ - mblock/src/Makefile \ - mblock/src/include/Makefile \ - mblock/src/include/mblock/Makefile \ - mblock/src/lib/Makefile \ - mblock/src/scheme/Makefile \ - mblock/src/scheme/gnuradio/Makefile \ - ]) - - GRC_BUILD_CONDITIONAL(mblock,[ - dnl run_tests is created from run_tests.in. Make it executable. - dnl AC_CONFIG_COMMANDS([run_tests_mblock], [chmod +x mblock/src/python/run_tests]) - ]) -]) diff --git a/config/grc_omnithread.m4 b/config/grc_omnithread.m4 deleted file mode 100644 index 1bcedebe18..0000000000 --- a/config/grc_omnithread.m4 +++ /dev/null @@ -1,46 +0,0 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc. -dnl -dnl This file is part of GNU Radio -dnl -dnl GNU Radio is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU General Public License as published by -dnl the Free Software Foundation; either version 3, or (at your option) -dnl any later version. -dnl -dnl GNU Radio is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU General Public License for more details. -dnl -dnl You should have received a copy of the GNU General Public License -dnl along with GNU Radio; see the file COPYING. If not, write to -dnl the Free Software Foundation, Inc., 51 Franklin Street, -dnl Boston, MA 02110-1301, USA. - -AC_DEFUN([GRC_OMNITHREAD],[ - GRC_ENABLE(omnithread) - - GRC_WITH(omnithread, [], gnuradio-omnithread) - - dnl If execution gets to here, $passed will be: - dnl with : if the --with code didn't error out - dnl yes : if the --enable code passed muster and all dependencies are met - dnl no : otherwise - if test $passed != with; then - dnl how and where to find INCLUDES and LA and such - omnithread_INCLUDES="-I\${abs_top_srcdir}/omnithread" - omnithread_LA="\${abs_top_builddir}/omnithread/libgromnithread.la" - omnithread_LIBDIRPATH="\${abs_top_builddir}/omnithread:\${abs_top_builddir}/omnithread/.libs" - fi - - AC_CONFIG_FILES([ \ - omnithread/Makefile \ - omnithread/gnuradio/Makefile \ - omnithread/gnuradio-omnithread.pc - ]) - - GRC_BUILD_CONDITIONAL(omnithread,[ - dnl run_tests is created from run_tests.in. Make it executable. - dnl AC_CONFIG_COMMANDS([run_tests_omnithread], [chmod +x omnithread/run_tests]) - ]) -]) diff --git a/config/grc_usrp.m4 b/config/grc_usrp.m4 index 286641928b..999b9c5c33 100644 --- a/config/grc_usrp.m4 +++ b/config/grc_usrp.m4 @@ -22,8 +22,8 @@ AC_DEFUN([GRC_USRP],[ GRC_WITH(usrp) - dnl Don't do usrp if omnithread skipped - GRC_CHECK_DEPENDENCY(usrp, omnithread) + dnl Don't do usrp if gruel is skipped + GRC_CHECK_DEPENDENCY(usrp, gruel) dnl Make sure the fast usb technique is set, OS dependent. dnl This is always performed, since it puts out CLI flags. @@ -59,18 +59,6 @@ AC_DEFUN([GRC_USRP],[ usrp_LA="\${abs_top_builddir}/usrp/host/lib/libusrp.la" fi - dnl There pkg-config file for usrp requires omnithread for Darwin only. Create a variable - dnl for just the usrp.pc.in case. - case "$host_os" in - darwin*) - usrp_darwin_omnithread_pc_requires="gnuradio-omnithread" - ;; - *) dnl (blanks) - usrp_darwin_omnithread_pc_requires="" - ;; - esac - AC_SUBST(usrp_darwin_omnithread_pc_requires) - AC_CONFIG_FILES([ \ usrp/Makefile \ usrp/usrp.pc \ diff --git a/config/grc_usrp2.m4 b/config/grc_usrp2.m4 index f7064c9168..701b100ad9 100644 --- a/config/grc_usrp2.m4 +++ b/config/grc_usrp2.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2008 Free Software Foundation, Inc. +dnl Copyright 2008,2010 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -23,9 +23,8 @@ AC_DEFUN([GRC_USRP2],[ dnl firmware uses a subsidiary configure.ac AC_CONFIG_SUBDIRS([usrp2/firmware]) - dnl Don't do usrp if omnithread or gruel is skipped + dnl Don't do usrp if gruel is skipped GRC_CHECK_DEPENDENCY(usrp2, gruel) - GRC_CHECK_DEPENDENCY(usrp2, omnithread) dnl USRP2 host code only works on Linux at the moment AC_MSG_CHECKING([whether host_os is linux*]) diff --git a/configure.ac b/configure.ac index 3ba5bb387d..a170933858 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. +dnl Copyright 2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -149,9 +149,6 @@ AM_CONDITIONAL([HAS_XMLTO], [test x$XMLTO = xyes]) dnl Checks for libraries. AC_CHECK_LIB(socket,socket) -dnl check for omnithreads (will soon be removed) -GR_OMNITHREAD - dnl Set the c++ compiler that we use for the build system when cross compiling if test x$CXX_FOR_BUILD = x then @@ -264,7 +261,17 @@ dnl We require the boost headers, thread lib and date_time lib. dnl AX_BOOST_BASE finds the headers and the lib dir (-L<foo>) dnl dnl calls AC_SUBST(BOOST_CPPFLAGS), AC_SUBST(BOOST_LDFLAGS) and defines HAVE_BOOST -AX_BOOST_BASE([1.35]) +dnl +dnl Current Boost version requirement is >=1.35 for all platforms except Darwin, +dnl which requires >=1.37 for code in usrp host library. +case "$host_os" in + darwin*) + AX_BOOST_BASE([1.37]) + ;; + *) + AX_BOOST_BASE([1.35]) + ;; +esac dnl calls AC_SUBST(BOOST_THREAD_LIB), AC_SUBST(BOOST_CXXFLAGS) and defines HAVE_BOOST_THREAD AX_BOOST_THREAD @@ -329,16 +336,13 @@ AC_ARG_ENABLE( build_dirs="config" GRC_GRUEL dnl must come first -GRC_OMNITHREAD dnl must come before gnuradio-core and mblock GRC_GCELL GRC_GNURADIO_CORE -GRC_MBLOCK dnl this must come after GRC_GRUEL GRC_USRP GRC_USRP2 GRC_VRT GRC_GR_USRP dnl this must come after GRC_USRP GRC_GR_USRP2 -dnl GRC_GR_VRT GRC_GR_GCELL dnl this must come after GRC_GCELL and GRC_GNURADIO_CORE GRC_GR_MSDD6000 GRC_GR_AUDIO_ALSA diff --git a/docs/doxygen/Doxyfile.in b/docs/doxygen/Doxyfile.in index bf9b0ef478..243fa00bfd 100644 --- a/docs/doxygen/Doxyfile.in +++ b/docs/doxygen/Doxyfile.in @@ -648,8 +648,6 @@ EXCLUDE = @abs_top_builddir@/docs/doxygen/html \ @abs_top_builddir@/gr-video-sdl/src/video_sdl.py \ @abs_top_builddir@/gr-wxgui/src/python \ @abs_top_builddir@/grc \ - @abs_top_builddir@/omnithread/mach.cc \ - @abs_top_builddir@/omnithread/nt.cc \ @abs_top_builddir@/usrp/doc \ @abs_top_builddir@/usrp/firmware \ @abs_top_builddir@/usrp/fpga \ @@ -689,7 +687,6 @@ EXCLUDE_PATTERNS = */.deps/* \ */__init__.py \ */gr-atsc/src/lib/Gr* \ */moc_*.cc \ - */omnithread/ot_* \ */qa_*.cc \ */qa_*.h \ */qa_*.py diff --git a/docs/doxygen/other/Makefile.am b/docs/doxygen/other/Makefile.am index 5e05d5d363..eb5f170af3 100644 --- a/docs/doxygen/other/Makefile.am +++ b/docs/doxygen/other/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2001,2004 Free Software Foundation, Inc. +# Copyright 2001,2004,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -24,9 +24,6 @@ include $(top_srcdir)/Makefile.common EXTRA_DIST = \ doxypy.py \ group_defs.dox \ - omnithread.html \ - omnithread.pdf \ - omnithread.ps \ shared_ptr_docstub.h \ tv-channel-frequencies \ vector_docstub.h diff --git a/docs/doxygen/other/omnithread.html b/docs/doxygen/other/omnithread.html deleted file mode 100644 index 5682d1d0b1..0000000000 --- a/docs/doxygen/other/omnithread.html +++ /dev/null @@ -1,411 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" - "http://www.w3.org/TR/REC-html40/loose.dtd"> -<HTML> -<HEAD><TITLE>The OMNI Thread Abstraction</TITLE> - -<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> -<META name="GENERATOR" content="hevea 1.06"> -</HEAD> -<BODY > -<!--HEVEA command line is: /usr/local/bin/hevea omnithread --> -<!--HTMLHEAD--> -<!--ENDHTML--> -<!--PREFIX <ARG ></ARG>--> -<!--CUT DEF section 1 --> - - -<H1 ALIGN=center>The OMNI Thread Abstraction</H1> - -<H3 ALIGN=center>Tristan Richardson<BR> -AT&T Laboratories Cambridge<BR> -</H3> - -<H3 ALIGN=center><I>Revised</I> November 2001</H3> -<!--TOC section Introduction--> - -<H2><A NAME="htoc1">1</A> Introduction</H2><!--SEC END --> - -The OMNI thread abstraction is designed to provide a common set of -thread operations for use in programs written in C++. Programs -written using the abstraction should be much easier to port between -different architectures with different underlying threads primitives.<BR> -<BR> -The programming interface is designed to be similar to the C language -interface to POSIX threads (IEEE draft standard 1003.1c --- previously -1003.4a, often known as ``pthreads'' [<A HREF="#pthreads"><CITE>POSIX94</CITE></A>]).<BR> -<BR> -Much of the abstraction consists of simple C++ object wrappers around -pthread calls. However for some features such as thread-specific -data, a better interface can be offered because of the use of C++.<BR> -<BR> -Some of the more complex features of pthreads are not supported -because of the difficulty of ensuring the same features can be offered -on top of other thread systems. Such features include thread -cancellation and complex scheduling control (though simple thread -priorities are supported).<BR> -<BR> -The abstraction layer is currently implemented for the following -architectures / thread systems: -<UL><LI>Solaris 2.x using pthreads draft 10 -<LI>Solaris 2.x using solaris threads (but pthreads version is now standard) -<LI>Alpha OSF1 using pthreads draft 4 -<LI>Windows NT using NT threads -<LI>Linux 2.x using Linuxthread 0.5 (which is based on pthreads draft 10) -<LI>Linux 2.x using MIT pthreads (which is based on draft 8) -<LI>ATMos using pthreads draft 6 (but not Virata ATMos)</UL> -See the <TT>omnithread.h</TT> header file for full details of the API. -The descriptions below assume you have some previous knowledge of -threads, mutexes, condition variables and semaphores. Also refer to -other documentation ([<A HREF="#birrell"><CITE>Birrell89</CITE></A>], [<A HREF="#pthreads"><CITE>POSIX94</CITE></A>]) for further -explanation of these ideas (particularly condition variables, the use -of which may not be particularly intuitive when first encountered).<BR> -<BR> -<!--TOC section Synchronisation objects--> - -<H2><A NAME="htoc2">2</A> Synchronisation objects</H2><!--SEC END --> - -Synchronisation objects are used to synchronise threads within the -same process. There is no inter-process synchronisation provided. -The synchronisation objects provided are mutexes, condition variables -and counting semaphores.<BR> -<BR> -<!--TOC subsection Mutex--> - -<H3><A NAME="htoc3">2.1</A> Mutex</H3><!--SEC END --> - -An object of type <TT>omni_mutex</TT> is used for mutual exclusion. -It provides two operations, <TT>lock()</TT> and <TT>unlock()</TT>. -The alternative names <TT>acquire()</TT> and <TT>release()</TT> can be -used if preferred. Behaviour is undefined when a thread attempts to -lock the same mutex again or when a mutex is locked by one thread and -unlocked by a different thread.<BR> -<BR> -<!--TOC subsection Condition Variable--> - -<H3><A NAME="htoc4">2.2</A> Condition Variable</H3><!--SEC END --> - -A condition variable is represented by an <TT>omni_condition</TT> and -is used for signalling between threads. A call to <TT>wait()</TT> -causes a thread to wait on the condition variable. A call to -<TT>signal()</TT> wakes up at least one thread if any are waiting. A -call to <TT>broadcast()</TT> wakes up all threads waiting on the -condition variable.<BR> -<BR> -When constructed, a pointer to an <TT>omni_mutex</TT> must be given. -A condition variable <TT>wait()</TT> has an implicit mutex -<TT>unlock()</TT> and <TT>lock()</TT> around it. The link between -condition variable and mutex lasts for the lifetime of the condition -variable (unlike pthreads where the link is only for the duration of -the wait). The same mutex may be used with several condition -variables.<BR> -<BR> -A wait with a timeout can be achieved by calling -<TT>timed_wait()</TT>. This is given an absolute time to wait until. -The routine <TT>omni_thread::get_time()</TT> can be used to turn a -relative time into an absolute time. <TT>timed_wait()</TT> returns -<TT>true</TT> if the condition was signalled, <TT>false</TT> if the -time expired before the condition variable was signalled.<BR> -<BR> -<!--TOC subsection Counting semaphores--> - -<H3><A NAME="htoc5">2.3</A> Counting semaphores</H3><!--SEC END --> - -An <TT>omni_semaphore</TT> is a counting semaphore. When created it -is given an initial unsigned integer value. When <TT>wait()</TT> is -called, the value is decremented if non-zero. If the value is zero -then the thread blocks instead. When <TT>post()</TT> is called, if -any threads are blocked in <TT>wait()</TT>, exactly one thread is -woken. If no threads were blocked then the value of the semaphore is -incremented.<BR> -<BR> -If a thread calls <TT>try_wait()</TT>, then the thread won't block if -the semaphore's value is 0, returning <TT>false</TT> instead.<BR> -<BR> -There is no way of querying the value of the semaphore.<BR> -<BR> -<!--TOC section Thread object--> - -<H2><A NAME="htoc6">3</A> Thread object</H2><!--SEC END --> - -A thread is represented by an <TT>omni_thread</TT> object. There are -broadly two different ways in which it can be used.<BR> -<BR> -The first way is simply to create an <TT>omni_thread</TT> object, -giving a particular function which the thread should execute. This is -like the POSIX (or any other) C language interface.<BR> -<BR> -The second method of use is to create a new class which inherits from -<TT>omni_thread</TT>. In this case the thread will execute the -<TT>run()</TT> member function of the new class. One advantage of -this scheme is that thread-specific data can be implemented simply by -having data members of the new class.<BR> -<BR> -When constructed a thread is in the "new" state and has not actually -started. A call to <TT>start()</TT> causes the thread to begin -executing. A static member function <TT>create()</TT> is provided to -construct and start a thread in a single call. A thread exits by -calling <TT>exit()</TT> or by returning from the thread function.<BR> -<BR> -Threads can be either detached or undetached. Detached threads are -threads for which all state will be lost upon exit. Other threads -cannot determine when a detached thread will disappear, and therefore -should not attempt to access the thread object unless some explicit -synchronisation with the detached thread guarantees that it still -exists.<BR> -<BR> -Undetached threads are threads for which storage is not reclaimed -until another thread waits for its termination by calling -<TT>join()</TT>. An exit value can be passed from an undetached -thread to the thread which joins it.<BR> -<BR> -Detached / undetached threads are distinguished on creation by the -type of function they execute. Undetached threads execute a function -which has a <TT>void*</TT> return type, whereas detached threads -execute a function which has a <TT>void</TT> return type. -Unfortunately C++ member functions are not allowed to be distinguished -simply by their return type. Thus in the case of a derived class of -<TT>omni_thread</TT> which needs an undetached thread, the member -function executed by the thread is called <TT>run_undetached()</TT> -rather than <TT>run()</TT>, and it is started by calling -<TT>start_undetached()</TT> instead of <TT>start()</TT>.<BR> -<BR> -The abstraction currently supports three priorities of thread, but no -guarantee is made of how this will affect underlying thread -scheduling. The three priorities are <TT>PRIORITY_LOW</TT>, -<TT>PRIORITY_NORMAL</TT> and <TT>PRIORITY_HIGH</TT>. By default all -threads run at <TT>PRIORITY_NORMAL</TT>. A different priority can be -specified on thread creation, or while the thread is running using -<TT>set_priority().</TT> A thread's current priority is returned by -<TT>priority()</TT>.<BR> -<BR> -Other functions provided are <TT>self()</TT> which returns the calling -thread's <TT>omni_thread</TT> object, <TT>yield()</TT> which -requests that other threads be allowed to run, <TT>id()</TT> which -returns an integer id for the thread for use in debugging, -<TT>state()</TT>, <TT>sleep()</TT> and <TT>get_time()</TT>.<BR> -<BR> -<!--TOC section Per-thread data--> - -<H2><A NAME="htoc7">4</A> Per-thread data</H2><!--SEC END --> - -omnithread supports per-thread data, via member functions of the -<TT>omni_thread</TT> object.<BR> -<BR> -First, you must allocate a key for with the -<TT>omni_thread::allocate_key()</TT> function. Then, any object -whose class is derived from <TT>omni_thread::value_t</TT> can be -stored using the <TT>set_value()</TT> function. Values are retrieved -or removed with <TT>get_value()</TT> and <TT>remove_value()</TT> -respectively.<BR> -<BR> -When the thread exits, all per-thread data is deleted (hence the base -class with virtual destructor).<BR> -<BR> -Note that the per-thread data functions are <B>not</B> thread safe, -so although you can access one thread's storage from another thread, -there is no concurrency control. Unless you really know what you are -doing, it is best to only access per-thread data from the thread it is -attached to.<BR> -<BR> -<!--TOC section Using OMNI threads in your program--> - -<H2><A NAME="htoc8">5</A> Using OMNI threads in your program</H2><!--SEC END --> - -Obviously you need to include the <TT>omnithread.h</TT> header file in -your source code, and link in the omnithread library with your -executable. Because there is a single <TT>omnithread.h</TT> for all -platforms, certain preprocessor defines must be given as compiler -options. The easiest way to do this is to study the makefiles given -in the examples provided with this distribution. If you are to -include OMNI threads in your own development environment, these are -the necessary preprocessor defines:<BR> -<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1> -<TR><TD ALIGN=left NOWRAP>Platform</TD> -<TD ALIGN=left NOWRAP>Preprocessor Defines</TD> -</TR> -<TR><TD ALIGN=left NOWRAP>Sun Solaris 2.x</TD> -<TD ALIGN=left NOWRAP><CODE>-D__sunos__ -D__sparc__ -D__OSVERSION__=5</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP> </TD> -<TD ALIGN=left NOWRAP><CODE>-DSVR4 -DUsePthread -D_REENTRANT</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP>x86 Linux 2.0</TD> -<TD ALIGN=left NOWRAP><CODE>-D__linux__ -D__i86__ -D__OSVERSION__=2</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP>with linuxthreads 0.5</TD> -<TD ALIGN=left NOWRAP><CODE>-D_REENTRANT</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP>Digital Unix 3.2</TD> -<TD ALIGN=left NOWRAP><CODE>-D__osf1__ -D__alpha__ -D__OSVERSION__=3</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP> </TD> -<TD ALIGN=left NOWRAP><CODE>-D_REENTRANT</CODE></TD> -</TR> -<TR><TD ALIGN=left NOWRAP>Windows NT</TD> -<TD ALIGN=left NOWRAP><CODE>-D__NT__ -MD</CODE></TD> -</TR></TABLE><BR> -<!--TOC section Threaded I/O shutdown for Unix--> - -<H2><A NAME="htoc9">6</A> Threaded I/O shutdown for Unix</H2><!--SEC END --> - -or, how one thread should tell another thread to shut down when it -might be doing a blocking call on a socket.<BR> -<BR> -<B>If you are using omniORB, you don't need to worry about all -this, since omniORB does it for you.</B> This section is only relevant -if you are using omnithread in your own socket-based programming. It -is also seriously out of date.<BR> -<BR> -Unfortunately there doesn't seem to be a standard way of doing this -which works across all Unix systems. I have investigated the -behaviour of Solaris 2.5 and Digital Unix 3.2. On Digital Unix -everything is fine, as the obvious method using shutdown() seems to -work OK. Unfortunately on Solaris shutdown can only be used on a -connected socket, so we need devious means to get around this -limitation. The details are summarised below:<BR> -<BR> -<!--TOC subsection read()--> - -<H3><A NAME="htoc10">6.1</A> read()</H3><!--SEC END --> - -Thread A is in a loop, doing <CODE>read(sock)</CODE>, processing the data, -then going back into the read.<BR> -<BR> -Thread B comes along and wants to shut it down --- it can't cancel -thread A since (i) working out how to clean up according to where A is -in its loop is a nightmare, and (ii) this isn't available in -omnithread anyway.<BR> -<BR> -On Solaris 2.5 and Digital Unix 3.2 the following strategy works:<BR> -<BR> -Thread B does <CODE>shutdown(sock,2)</CODE>.<BR> -<BR> -At this point thread A is either blocked inside <CODE>read(sock)</CODE>, or -is elsewhere in the loop. If the former then read will return 0, -indicating that the socket is closed. If the latter then eventually -thread A will call <CODE>read(sock)</CODE> and then this will return 0. -Thread A should <CODE>close(sock)</CODE>, do any other tidying up, and exit.<BR> -<BR> -If there is another point in the loop that thread A can block then -obviously thread B needs to be aware of this and be able to wake it up -in the appropriate way from that point.<BR> -<BR> -<!--TOC subsection accept()--> - -<H3><A NAME="htoc11">6.2</A> accept()</H3><!--SEC END --> - -Again thread A is in a loop, this time doing an accept on listenSock, -dealing with a new connection and going back into accept. Thread B -wants to cancel it.<BR> -<BR> -On Digital Unix 3.2 the strategy is identical to that for read:<BR> -<BR> -Thread B does <CODE>shutdown(listenSock,2)</CODE>. Wherever thread A is in -the loop, eventually it will return <CODE>ECONNABORTED</CODE> from the -accept call. It should <CODE>close(listenSock)</CODE>, tidy up as necessary -and exit.<BR> -<BR> -On Solaris 2.5 thread B can't do <CODE>shutdown(listenSock,2)</CODE> --- -this returns <CODE>ENOTCONN</CODE>. Instead the following strategy can be -used:<BR> -<BR> -First thread B sets some sort of "shutdown flag" associated with -listenSock. Then it does <CODE>getsockaddr(listenSock)</CODE> to find out -which port listenSock is on (or knows already), sets up a socket -dummySock, does <CODE>connect(dummySock,</CODE> <CODE>this host, port)</CODE> and -finally does <CODE>close(dummySock)</CODE>.<BR> -<BR> -Wherever thread A is in the loop, eventually it will call -<CODE>accept(listenSock)</CODE>. This will return successfully with a new -socket, say connSock. Thread A then checks to see if the "shutdown -flag" is set. If not, then it's a normal connection. If it is set, -then thread A closes listenSock and connSock, tidies up and exits.<BR> -<BR> -<!--TOC subsection write()--> - -<H3><A NAME="htoc12">6.3</A> write()</H3><!--SEC END --> - -Thread A may be blocked in write, or about to go in to a -potentially-blocking write. Thread B wants to shut it down.<BR> -<BR> -On Solaris 2.5:<BR> -<BR> -Thread B does <CODE>shutdown(sock,2)</CODE>.<BR> -<BR> -If thread A is already in <CODE>write(sock)</CODE> then it will return with -<CODE>ENXIO</CODE>. If thread A calls write after thread B calls shutdown -this will return <CODE>EIO</CODE>.<BR> -<BR> -On Digital Unix 3.2:<BR> -<BR> -Thread B does <CODE>shutdown(sock,2)</CODE>.<BR> -<BR> -If thread A is already in <CODE>write(sock)</CODE> then it will return the -number of bytes written before it became blocked. A subsequent call -to write will then generate <CODE>SIGPIPE</CODE> (or <CODE>EPIPE</CODE> will be -returned if <CODE>SIGPIPE</CODE> is ignored by the thread).<BR> -<BR> -<!--TOC subsection connect()--> - -<H3><A NAME="htoc13">6.4</A> connect()</H3><!--SEC END --> - -Thread A may be blocked in connect, or about to go in to a -potentially-blocking connect. Thread B wants to shut it down.<BR> -<BR> -On Digital Unix 3.2:<BR> -<BR> -Thread B does <CODE>shutdown(sock,2)</CODE>.<BR> -<BR> -If thread A is already in <CODE>connect(sock)</CODE> then it will return a -successful connection. Subsequent reading or writing will show that -the socket has been shut down (i.e. read returns 0, write generates -<CODE>SIGPIPE</CODE> or returns <CODE>EPIPE</CODE>). If thread A calls connect -after thread B calls shutdown this will return <CODE>EINVAL</CODE>.<BR> -<BR> -On Solaris 2.5:<BR> -<BR> -There is no way to wake up a thread which is blocked in connect. -Instead Solaris forces us through a ridiculous procedure whichever way -we try it. One way is this:<BR> -<BR> -First thread A creates a pipe in addition to the socket. Instead of -shutting down the socket, thread B simply writes a byte to the pipe.<BR> -<BR> -Thread A meanwhile sets the socket to non-blocking mode using -<CODE>fcntl(sock,</CODE> <CODE>F_SETFL, O_NONBLOCK)</CODE>. Then it calls connect -on the socket --- this will return <CODE>EINPROGRESS</CODE>. Then it must -call <CODE>select()</CODE>, waiting for either sock to become writable or -for the pipe to become readable. If select returns that just sock is -writable then the connection has succeeded. It then needs to set the -socket back to blocking mode using <CODE>fcntl(sock, F_SETFL, 0)</CODE>. If -instead select returns that the pipe is readable, thread A closes the -socket, tidies up and exits.<BR> -<BR> -An alternative method is similar but to use polling instead of the -pipe. Thread B justs sets a flag and thread A calls select with a -timeout, periodically waking up to see if the flag has been set.<BR> -<BR> -<!--TOC section References--> - -<H2>References</H2><!--SEC END --> -<DL COMPACT=compact><DT><A NAME="pthreads"><FONT COLOR=purple>[POSIX94]</FONT></A><DD> -<EM>Portable Operating System Interface (POSIX) Threads Extension</EM>, -P1003.1c Draft 10, -IEEE, -September 1994.<BR> -<BR> -<DT><A NAME="birrell"><FONT COLOR=purple>[Birrell89]</FONT></A><DD> -<EM>An Introduction to Programming with Threads</EM>, -Research Report 35, -DEC Systems Research Center, -Palo Alto, CA, -January 1989.</DL> -<!--HTMLFOOT--> -<!--ENDHTML--> -<!--FOOTER--> -<HR SIZE=2> -<BLOCKQUOTE><EM>This document was translated from L<sup>A</sup>T<sub>E</sub>X by -</EM><A HREF="http://pauillac.inria.fr/~maranget/hevea/index.html"><EM>H<FONT SIZE=2><sup>E</sup></FONT>V<FONT SIZE=2><sup>E</sup></FONT>A</EM></A><EM>. -</EM></BLOCKQUOTE> -</BODY> -</HTML> diff --git a/docs/doxygen/other/omnithread.pdf b/docs/doxygen/other/omnithread.pdf Binary files differdeleted file mode 100644 index b0033072ff..0000000000 --- a/docs/doxygen/other/omnithread.pdf +++ /dev/null diff --git a/docs/doxygen/other/omnithread.ps b/docs/doxygen/other/omnithread.ps deleted file mode 100644 index 9e858f0b7d..0000000000 --- a/docs/doxygen/other/omnithread.ps +++ /dev/null @@ -1,730 +0,0 @@ -%!PS-Adobe-2.0 -%%Creator: dvipsk 5.86 p1.5d Copyright 1996-2001 ASCII Corp.(www-ptex@ascii.co.jp) -%%based on dvipsk 5.86 Copyright 1999 Radical Eye Software (www.radicaleye.com) -%%Title: omnithread.dvi -%%Pages: 7 -%%PageOrder: Ascend -%%BoundingBox: 0 0 596 842 -%%DocumentFonts: Palatino-Roman Palatino-Italic Palatino-Bold Courier -%%EndComments -%DVIPSWebPage: (www.radicaleye.com) -%DVIPSCommandLine: dvips omnithread -%DVIPSParameters: dpi=600, compressed -%DVIPSSource: TeX output 2002.08.15:1756 -%%BeginProcSet: texc.pro -%! -/TeXDict 300 dict def TeXDict begin/N{def}def/B{bind def}N/S{exch}N/X{S -N}B/A{dup}B/TR{translate}N/isls false N/vsize 11 72 mul N/hsize 8.5 72 -mul N/landplus90{false}def/@rigin{isls{[0 landplus90{1 -1}{-1 1}ifelse 0 -0 0]concat}if 72 Resolution div 72 VResolution div neg scale isls{ -landplus90{VResolution 72 div vsize mul 0 exch}{Resolution -72 div hsize -mul 0}ifelse TR}if Resolution VResolution vsize -72 div 1 add mul TR[ -matrix currentmatrix{A A round sub abs 0.00001 lt{round}if}forall round -exch round exch]setmatrix}N/@landscape{/isls true N}B/@manualfeed{ -statusdict/manualfeed true put}B/@copies{/#copies X}B/FMat[1 0 0 -1 0 0] -N/FBB[0 0 0 0]N/nn 0 N/IEn 0 N/ctr 0 N/df-tail{/nn 8 dict N nn begin -/FontType 3 N/FontMatrix fntrx N/FontBBox FBB N string/base X array -/BitMaps X/BuildChar{CharBuilder}N/Encoding IEn N end A{/foo setfont}2 -array copy cvx N load 0 nn put/ctr 0 N[}B/sf 0 N/df{/sf 1 N/fntrx FMat N -df-tail}B/dfs{div/sf X/fntrx[sf 0 0 sf neg 0 0]N df-tail}B/E{pop nn A -definefont setfont}B/Cw{Cd A length 5 sub get}B/Ch{Cd A length 4 sub get -}B/Cx{128 Cd A length 3 sub get sub}B/Cy{Cd A length 2 sub get 127 sub} -B/Cdx{Cd A length 1 sub get}B/Ci{Cd A type/stringtype ne{ctr get/ctr ctr -1 add N}if}B/id 0 N/rw 0 N/rc 0 N/gp 0 N/cp 0 N/G 0 N/CharBuilder{save 3 -1 roll S A/base get 2 index get S/BitMaps get S get/Cd X pop/ctr 0 N Cdx -0 Cx Cy Ch sub Cx Cw add Cy setcachedevice Cw Ch true[1 0 0 -1 -.1 Cx -sub Cy .1 sub]/id Ci N/rw Cw 7 add 8 idiv string N/rc 0 N/gp 0 N/cp 0 N{ -rc 0 ne{rc 1 sub/rc X rw}{G}ifelse}imagemask restore}B/G{{id gp get/gp -gp 1 add N A 18 mod S 18 idiv pl S get exec}loop}B/adv{cp add/cp X}B -/chg{rw cp id gp 4 index getinterval putinterval A gp add/gp X adv}B/nd{ -/cp 0 N rw exit}B/lsh{rw cp 2 copy get A 0 eq{pop 1}{A 255 eq{pop 254}{ -A A add 255 and S 1 and or}ifelse}ifelse put 1 adv}B/rsh{rw cp 2 copy -get A 0 eq{pop 128}{A 255 eq{pop 127}{A 2 idiv S 128 and or}ifelse} -ifelse put 1 adv}B/clr{rw cp 2 index string putinterval adv}B/set{rw cp -fillstr 0 4 index getinterval putinterval adv}B/fillstr 18 string 0 1 17 -{2 copy 255 put pop}for N/pl[{adv 1 chg}{adv 1 chg nd}{1 add chg}{1 add -chg nd}{adv lsh}{adv lsh nd}{adv rsh}{adv rsh nd}{1 add adv}{/rc X nd}{ -1 add set}{1 add clr}{adv 2 chg}{adv 2 chg nd}{pop nd}]A{bind pop} -forall N/D{/cc X A type/stringtype ne{]}if nn/base get cc ctr put nn -/BitMaps get S ctr S sf 1 ne{A A length 1 sub A 2 index S get sf div put -}if put/ctr ctr 1 add N}B/I{cc 1 add D}B/bop{userdict/bop-hook known{ -bop-hook}if/SI save N @rigin 0 0 moveto/V matrix currentmatrix A 1 get A -mul exch 0 get A mul add .99 lt{/QV}{/RV}ifelse load def pop pop}N/eop{ -SI restore userdict/eop-hook known{eop-hook}if showpage}N/@start{ -userdict/start-hook known{start-hook}if pop/VResolution X/Resolution X -1000 div/DVImag X/IEn 256 array N 2 string 0 1 255{IEn S A 360 add 36 4 -index cvrs cvn put}for pop 65781.76 div/vsize X 65781.76 div/hsize X}N -/dir 0 def/dyy{/dir 0 def}B/dyt{/dir 1 def}B/dty{/dir 2 def}B/dtt{/dir 3 -def}B/p{dir 2 eq{-90 rotate show 90 rotate}{dir 3 eq{-90 rotate show 90 -rotate}{show}ifelse}ifelse}N/RMat[1 0 0 -1 0 0]N/BDot 260 string N/Rx 0 -N/Ry 0 N/V{}B/RV/v{/Ry X/Rx X V}B statusdict begin/product where{pop -false[(Display)(NeXT)(LaserWriter 16/600)]{A length product length le{A -length product exch 0 exch getinterval eq{pop true exit}if}{pop}ifelse} -forall}{false}ifelse end{{gsave TR -.1 .1 TR 1 1 scale Rx Ry false RMat{ -BDot}imagemask grestore}}{{gsave TR -.1 .1 TR Rx Ry scale 1 1 false RMat -{BDot}imagemask grestore}}ifelse B/QV{gsave newpath transform round exch -round exch itransform moveto Rx 0 rlineto 0 Ry neg rlineto Rx neg 0 -rlineto fill grestore}B/a{moveto}B/delta 0 N/tail{A/delta X 0 rmoveto}B -/M{S p delta add tail}B/b{S p tail}B/c{-4 M}B/d{-3 M}B/e{-2 M}B/f{-1 M} -B/g{0 M}B/h{1 M}B/i{2 M}B/j{3 M}B/k{4 M}B/w{0 rmoveto}B/l{p -4 w}B/m{p --3 w}B/n{p -2 w}B/o{p -1 w}B/q{p 1 w}B/r{p 2 w}B/s{p 3 w}B/t{p 4 w}B/x{ -0 S rmoveto}B/y{3 2 roll p a}B/bos{/SS save N}B/eos{SS restore}B end - -%%EndProcSet -%%BeginProcSet: 8r.enc -% @@psencodingfile@{ -% author = "S. Rahtz, P. MacKay, Alan Jeffrey, B. Horn, K. Berry", -% version = "0.6", -% date = "1 July 1998", -% filename = "8r.enc", -% email = "tex-fonts@@tug.org", -% docstring = "Encoding for TrueType or Type 1 fonts -% to be used with TeX." -% @} -% -% Idea is to have all the characters normally included in Type 1 fonts -% available for typesetting. This is effectively the characters in Adobe -% Standard Encoding + ISO Latin 1 + extra characters from Lucida. -% -% Character code assignments were made as follows: -% -% (1) the Windows ANSI characters are almost all in their Windows ANSI -% positions, because some Windows users cannot easily reencode the -% fonts, and it makes no difference on other systems. The only Windows -% ANSI characters not available are those that make no sense for -% typesetting -- rubout (127 decimal), nobreakspace (160), softhyphen -% (173). quotesingle and grave are moved just because it's such an -% irritation not having them in TeX positions. -% -% (2) Remaining characters are assigned arbitrarily to the lower part -% of the range, avoiding 0, 10 and 13 in case we meet dumb software. -% -% (3) Y&Y Lucida Bright includes some extra text characters; in the -% hopes that other PostScript fonts, perhaps created for public -% consumption, will include them, they are included starting at 0x12. -% -% (4) Remaining positions left undefined are for use in (hopefully) -% upward-compatible revisions, if someday more characters are generally -% available. -% -% (5) hyphen appears twice for compatibility with both -% ASCII and Windows. -% -/TeXBase1Encoding [ -% 0x00 (encoded characters from Adobe Standard not in Windows 3.1) - /.notdef /dotaccent /fi /fl - /fraction /hungarumlaut /Lslash /lslash - /ogonek /ring /.notdef - /breve /minus /.notdef -% These are the only two remaining unencoded characters, so may as -% well include them. - /Zcaron /zcaron -% 0x10 - /caron /dotlessi -% (unusual TeX characters available in, e.g., Lucida Bright) - /dotlessj /ff /ffi /ffl - /.notdef /.notdef /.notdef /.notdef - /.notdef /.notdef /.notdef /.notdef - % very contentious; it's so painful not having quoteleft and quoteright - % at 96 and 145 that we move the things normally found there to here. - /grave /quotesingle -% 0x20 (ASCII begins) - /space /exclam /quotedbl /numbersign - /dollar /percent /ampersand /quoteright - /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash -% 0x30 - /zero /one /two /three /four /five /six /seven - /eight /nine /colon /semicolon /less /equal /greater /question -% 0x40 - /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O -% 0x50 - /P /Q /R /S /T /U /V /W - /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore -% 0x60 - /quoteleft /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o -% 0x70 - /p /q /r /s /t /u /v /w - /x /y /z /braceleft /bar /braceright /asciitilde - /.notdef % rubout; ASCII ends -% 0x80 - /.notdef /.notdef /quotesinglbase /florin - /quotedblbase /ellipsis /dagger /daggerdbl - /circumflex /perthousand /Scaron /guilsinglleft - /OE /.notdef /.notdef /.notdef -% 0x90 - /.notdef /.notdef /.notdef /quotedblleft - /quotedblright /bullet /endash /emdash - /tilde /trademark /scaron /guilsinglright - /oe /.notdef /.notdef /Ydieresis -% 0xA0 - /.notdef % nobreakspace - /exclamdown /cent /sterling - /currency /yen /brokenbar /section - /dieresis /copyright /ordfeminine /guillemotleft - /logicalnot - /hyphen % Y&Y (also at 45); Windows' softhyphen - /registered - /macron -% 0xD0 - /degree /plusminus /twosuperior /threesuperior - /acute /mu /paragraph /periodcentered - /cedilla /onesuperior /ordmasculine /guillemotright - /onequarter /onehalf /threequarters /questiondown -% 0xC0 - /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla - /Egrave /Eacute /Ecircumflex /Edieresis - /Igrave /Iacute /Icircumflex /Idieresis -% 0xD0 - /Eth /Ntilde /Ograve /Oacute - /Ocircumflex /Otilde /Odieresis /multiply - /Oslash /Ugrave /Uacute /Ucircumflex - /Udieresis /Yacute /Thorn /germandbls -% 0xE0 - /agrave /aacute /acircumflex /atilde - /adieresis /aring /ae /ccedilla - /egrave /eacute /ecircumflex /edieresis - /igrave /iacute /icircumflex /idieresis -% 0xF0 - /eth /ntilde /ograve /oacute - /ocircumflex /otilde /odieresis /divide - /oslash /ugrave /uacute /ucircumflex - /udieresis /yacute /thorn /ydieresis -] def - -%%EndProcSet -%%BeginProcSet: texps.pro -%! -TeXDict begin/rf{findfont dup length 1 add dict begin{1 index/FID ne 2 -index/UniqueID ne and{def}{pop pop}ifelse}forall[1 index 0 6 -1 roll -exec 0 exch 5 -1 roll VResolution Resolution div mul neg 0 0]/Metrics -exch def dict begin 0 1 255{exch dup type/integertype ne{pop pop 1 sub -dup 0 le{pop}{[}ifelse}{FontMatrix 0 get div Metrics 0 get div def} -ifelse}for Metrics/Metrics currentdict end def[2 index currentdict end -definefont 3 -1 roll makefont/setfont cvx]cvx def}def/ObliqueSlant{dup -sin S cos div neg}B/SlantFont{4 index mul add}def/ExtendFont{3 -1 roll -mul exch}def/ReEncodeFont{CharStrings rcheck{/Encoding false def dup[ -exch{dup CharStrings exch known not{pop/.notdef/Encoding true def}if} -forall Encoding{]exch pop}{cleartomark}ifelse}if/Encoding exch def}def -end - -%%EndProcSet -TeXDict begin 39158280 55380996 1000 600 600 (omnithread.dvi) -@start /Fa 134[ 45 45 66 1[ 51 30 35 35 1[ 45 40 51 71 -25 2[ 25 45 45 25 35 45 37 42 40 8[ 66 3[ 56 51 2[ 56 -71 5[ 30 3[ 56 3[ 66 23[ 30 30 40[{ TeXBase1Encoding ReEncodeFont} 31 -90.9091 /Palatino-Italic rf /Fb 134[ 51 1[ 76 1[ 56 30 -40 35 2[ 51 56 81 30 2[ 30 56 51 35 45 56 40 56 45 14[ 66 -2[ 76 5[ 35 6[ 61 19[ 23 30 23 4[ 25 39[{ TeXBase1Encoding ReEncodeFont} -27 90.9091 /Palatino-Bold rf /Fc 135[ 50 83 1[ 61 33 -44 39 1[ 61 55 61 89 33 2[ 33 61 55 1[ 50 61 44 61 50 -10[ 78 8[ 100 9[ 72 12[ 50 1[ 50 50 50 50 2[ 25 4[ 33 -33 40[{ TeXBase1Encoding ReEncodeFont} 30 99.6264 /Palatino-Bold -rf /Fd 134[ 55 55 55 55 55 55 55 55 55 55 55 55 55 55 -55 55 55 55 55 55 55 55 55 55 55 1[ 55 5[ 55 55 55 55 -55 55 55 55 1[ 55 55 55 55 55 55 1[ 55 55 55 55 55 55 -55 55 55 3[ 55 2[ 55 1[ 55 1[ 55 55 55 55 55 55 55 1[ 55 -55 55 1[ 55 55 55 40[{ TeXBase1Encoding ReEncodeFont} 65 -90.9091 /Courier rf /Fe 141[ 36 12[ 44 56 2[ 45 7[ 61 -61 91 1[ 71 56 48 61 2[ 71 76 3[ 30 31 76 1[ 51 56 70 -64 56 71 10[ 45 3[ 45 45 1[ 55 23 4[ 30 30 40[{ -.167 SlantFont TeXBase1Encoding ReEncodeFont} 29 90.9091 -/Palatino-Roman rf -%DVIPSBitmapFont: Ff cmsy10 10.95 1 -/Ff 1 16 df<EB0FFCEB3FFF90B512C0000314F04880488048804880A2481580A3B712C0 -AA6C1580A36C1500A26C5C6C5C6C5C6C5CC614C0013F90C7FCEB0FFC22227BA72D> 15 -D E -%EndDVIPSBitmapFont -/Fg 104[ 91 2[ 45 45 24[ 45 51 47 76 51 55 30 39 36 51 -55 50 53 80 26 51 21 26 53 51 30 44 56 40 50 45 3[ 30 -1[ 30 2[ 61 91 66 71 56 48 61 1[ 55 71 76 86 56 66 30 -31 76 1[ 51 56 70 64 56 71 6[ 23 45 45 45 45 45 45 45 -45 45 45 55 23 30 23 55 1[ 30 30 25 4[ 34 30[ 55 55 2[{ -TeXBase1Encoding ReEncodeFont} 75 90.9091 /Palatino-Roman -rf /Fh 134[ 66 60 100 1[ 73 40 53 47 1[ 73 66 73 106 -2[ 40 40 73 66 47 60 73 53 73 60 11[ 93 80 73 86 1[ 73 -100 100 120 3[ 47 18[ 60 60 60 60 60 60 1[ 35 1[ 40 45[{ -TeXBase1Encoding ReEncodeFont} 38 119.552 /Palatino-Bold -rf /Fi 137[ 50 2[ 39 9[ 28 3[ 39 50 17[ 66 82[{ -TeXBase1Encoding ReEncodeFont} 6 99.6264 /Palatino-Italic -rf /Fj 137[ 56 1[ 32 42 39 2[ 54 58 88 3[ 29 58 55 1[ 48 -61 44 55 50 12[ 61 1[ 67 3[ 83 1[ 61 8[ 71 1[ 78 14[ 50 -50 50 9[ 78 38[{ TeXBase1Encoding ReEncodeFont} 25 99.6264 -/Palatino-Roman rf /Fk 139[ 47 61 57 2[ 78 83 4[ 42 83 -2[ 69 88 64 79 72 12[ 88 4[ 113 119 136 3[ 48 7[ 112 -65[{ TeXBase1Encoding ReEncodeFont} 18 143.462 /Palatino-Roman -rf end -%%EndProlog -%%BeginSetup -%%Feature: *Resolution 600dpi -TeXDict begin -%%PaperSize: A4 - -%%EndSetup -%%Page: 1 1 -1 0 bop Fk 728 918 a(The) 36 b(OMNI) g(Thr) m(ead) f(Abstracti) n(on) p -Fj 1293 1176 a(T) -9 b(ristan) 26 b(Richar) n(dson) 1022 -1293 y(A) -7 b(T&T) 24 b(Laboratories) i(Cambridge) p -Fi 1192 1504 a(Revised) p Fj 24 w(November) f(2001) p -Fh 63 1961 a(1) 119 b(Introduction) p Fg 63 2183 a(The) 20 -b(OMNI) h(thr) n(ead) g(abstraction) g(is) h(des) n(igned) f(to) f(pr) n -(ovide) h(a) h(common) f(set) f(of) h(thr) n(ead) g(oper) n(-) 63 -2296 y(ations) h(for) g(use) g(in) h(pr) n(ograms) f(written) f(in) i -(C++.) 29 b(Pr) n(ograms) 22 b(written) g(using) f(the) h(abstraction) -63 2409 y(should) 30 b(be) g(much) i(easier) e(to) g(port) g(betwee) n -(n) h(dif) n(fer) n(ent) g(ar) n(chi) r(tectur) l(es) g(with) g(dif) n -(fer) n(ent) f(un-) 63 2522 y(derlying) 21 b(thr) n(eads) h -(primitives.) 204 2640 y(The) 17 b(pr) n(ogramming) h(interface) g(is) f -(designed) f(to) h(be) h(similar) h(to) e(the) g(C) i(language) e -(interface) 63 2753 y(to) k(POSIX) h(thr) n(eads) f(\(IEEE) g(draft) h -(standar) n(d) f(100) r(3.1c) i(\227) f(pr) n(eviously) g(1003) r(.4a,) -g(often) g(known) 63 2866 y(as) g(\223pthr) n(eads\224) h([POSIX94]\).) -204 2985 y(Much) 18 b(of) f(the) g(abstraction) i(consists) d(of) i -(simple) g(C++) g(object) g(wrappers) e(ar) n(ound) h(pthr) n(ead) 63 -3098 y(calls.) 28 b(Howe) n(ver) 20 b(for) f(some) f(featur) n(es) g -(such) h(as) h(thr) n(ead-spe) n(ci\002c) h(data,) f(a) f(better) f -(interface) i(can) 63 3211 y(be) i(of) n(fer) n(ed) g(because) h(of) f -(the) g(use) g(of) g(C++.) 204 3329 y(Some) 28 b(of) h(the) f(mor) n(e) -h(complex) f(featur) n(es) g(of) h(pthr) n(eads) f(ar) n(e) h(not) f -(suppo) n(rted) g(because) h(of) 63 3442 y(the) e(dif) n(\002culty) i -(of) f(ensuring) g(the) f(same) h(featur) n(es) g(can) h(be) f(of) n -(fer) n(ed) g(on) g(top) g(of) g(other) f(thr) n(ead) 63 -3555 y(sys) n(tems.) f(Such) 17 b(featur) n(es) g(include) h(thr) n -(ead) f(cancell) r(ation) g(and) h(complex) g(schedu) n(ling) h(contr) n -(ol) 63 3668 y(\(thoug) n(h) k(simple) g(thr) n(ead) f(priorities) g -(ar) n(e) h(supp) n(orted\).) 204 3787 y(The) i(abstraction) h(layer) h -(is) f(curr) n(ently) f(implemented) g(for) h(the) f(following) i(ar) n -(chitectur) n(es) 63 3900 y(/) 22 b(thr) n(ead) h(sys) n(tems:) p -Ff 199 4141 a(\017) p Fg 46 w(Solaris) g(2.x) g(using) f(pthr) n(eads) f -(draft) h(10) p Ff 199 4351 a(\017) p Fg 46 w(Solaris) h(2.x) g(using) f -(solaris) g(thr) n(eads) g(\(but) h(pthr) n(eads) e(version) h(is) h -(now) f(standar) n(d\)) p Ff 199 4561 a(\017) p Fg 46 -w(Alpha) h(OSF1) g(using) f(pthr) n(eads) f(draft) i(4) p -Ff 199 4772 a(\017) p Fg 46 w(W) -5 b(indows) 21 b(NT) h(using) g(NT) g -(thr) n(eads) p Ff 199 4982 a(\017) p Fg 46 w(Linux) g(2.x) h(using) f -(Linuxthr) n(ead) g(0.5) h(\(which) h(is) e(based) g(on) h(pthr) n -(eads) e(draft) i(10\)) p Ff 199 5193 a(\017) p Fg 46 -w(Linux) f(2.x) h(using) f(MIT) g(pthr) n(eads) f(\(which) j(is) f -(based) f(on) g(draft) h(8\)) p Ff 199 5403 a(\017) p -Fg 46 w(A) -7 b(TMos) 22 b(using) g(pthr) n(eads) f(draft) h(6) i -(\(but) e(not) g(V) -5 b(irata) 23 b(A) -7 b(TMos\)) 1684 -5652 y(1) p 90 rotate dyy eop -%%Page: 2 2 -2 1 bop Fg 221 249 a(2) p Fe 1797 w(2) 91 b(SYNCHRONI) n(SA) -7 -b(TION) 22 b(OBJECTS) p Fg 362 548 a(See) h(the) p Fd -22 w(omni) n(thre) n(ad.h) p Fg 22 w(header) f(\002le) i(for) f(full) i -(det) n(ail) r(s) e(of) g(the) g(API.) f(The) h(des) n(criptions) 221 -661 y(below) 35 b(assume) g(you) g(have) h(some) e(pr) n(evious) h -(knowled) n(ge) g(of) h(thr) n(eads) n(,) j(mutexes) n(,) g(condi-) 221 -774 y(tion) f(varia) r(bles) g(and) g(semaphor) n(es) n(.) 75 -b(Also) 38 b(r) n(efer) f(to) h(other) f(document) n(ation) i(\([Birr) n -(ell89) r(],) 221 887 y([POSIX94) q(]\)) 22 b(for) g(further) f -(explanation) i(of) f(thes) n(e) g(ideas) g(\(particularly) h -(condition) f(variab) r(les,) 221 1000 y(the) g(use) g(of) g(which) h -(may) g(not) f(be) h(particularly) h(intuitive) f(when) f(\002rst) f -(encounter) n(ed) n(\).) p Fh 221 1299 a(2) 119 b(Synchronisation) 31 -b(objects) p Fg 221 1510 a(Synchr) n(onisation) 26 b(objects) h(ar) n -(e) g(used) e(to) h(synchr) n(onise) g(thr) n(eads) g(within) h(the) f -(same) h(pr) n(ocess) n(.) 221 1623 y(Ther) n(e) j(is) i(no) f(inter) n -(-pr) n(ocess) f(synchr) n(onisation) g(pr) n(ovided.) 53 -b(The) 30 b(synchr) n(onisation) h(objects) 221 1735 -y(pr) n(ovided) 22 b(ar) n(e) h(mutexes) n(,) g(condition) f(variab) r -(les) g(and) h(counting) f(semaphor) n(e) n(s.) p Fc -221 1991 a(2.1) 99 b(Mutex) p Fg 221 2168 a(An) 26 b(object) g(of) h -(typ) n(e) p Fd 26 w(omni) n(_mute) n(x) p Fg 26 w(is) g(use) n(d) f -(for) h(mutual) f(exclusion.) 39 b(It) 26 b(pr) n(ovides) f(two) g(op-) -221 2281 y(erations,) p Fd 37 w(lock\() n(\)) p Fg 35 -w(and) p Fd 35 w(unloc) n(k\(\)) p Fg(.) 64 b(The) 35 -b(alternative) h(names) p Fd 35 w(acq) n(uire\() n(\)) p -Fg 35 w(and) p Fd 35 w(re-) 221 2393 y(leas) n(e\(\)) p -Fg 19 w(can) 21 b(be) f(used) f(if) i(pr) n(eferr) n(ed) n(.) 27 -b(Behaviour) 20 b(is) g(unde\002ne) n(d) g(when) f(a) i(thr) n(ead) f -(attempt) n(s) 221 2506 y(to) 30 b(lock) h(the) e(same) i(mutex) f -(again) h(or) f(when) g(a) h(mutex) f(is) h(locked) e(by) i(one) e(thr) -n(ead) h(and) h(un-) 221 2619 y(locked) 22 b(by) h(a) g(dif) n(fer) n -(ent) f(thr) n(ead.) p Fc 221 2874 a(2.2) 99 b(Condition) 26 -b(V) -11 b(ariable) p Fg 221 3051 a(A) 28 b(condition) f(varia) r(ble) h -(is) g(r) n(epr) n(ese) n(nted) f(by) h(an) p Fd 28 w(omn) n(i_con) n -(diti) n(on) p Fg 27 w(and) g(is) g(used) e(for) i(sig-) 221 -3164 y(nalli) r(ng) 20 b(betwee) n(n) g(thr) n(eads.) 26 -b(A) 21 b(call) h(to) p Fd 19 w(wait\() n(\)) p Fg 20 -w(causes) e(a) h(thr) n(ead) e(to) h(wait) h(on) f(the) f(condition) 221 -3277 y(varia) r(ble.) 45 b(A) 28 b(call) i(to) p Fd 27 -w(sign) n(al\(\)) p Fg 27 w(wakes) d(up) h(at) g(least) g(one) f(thr) n -(ead) h(if) h(any) f(ar) n(e) g(waiting.) 45 b(A) 221 -3390 y(call) 25 b(to) p Fd 22 w(bro) n(adca) n(st\(\)) p -Fg 21 w(wakes) d(up) g(all) i(thr) n(eads) e(waiting) h(on) f(the) g -(condition) g(varia) r(ble.) 362 3503 y(When) 30 b(constr) o(ucte) n -(d,) i(a) e(pointer) f(to) h(an) p Fd 30 w(omni) n(_mute) n(x) p -Fg 30 w(must) f(be) h(given.) 50 b(A) 30 b(condition) 221 -3616 y(varia) r(ble) p Fd 33 w(wait\() n(\)) p Fg 33 -w(has) j(an) h(implic) r(it) f(mutex) p Fd 33 w(unlo) n(ck\(\)) p -Fg 32 w(and) p Fd 33 w(lock) n(\(\)) p Fg 33 w(ar) n(ound) g(it.) 60 -b(The) 221 3729 y(link) 30 b(between) f(condition) g(varia) r(ble) h -(and) g(mutex) f(lasts) g(for) h(the) f(lifetime) i(of) e(the) g -(condition) 221 3842 y(varia) r(ble) c(\(unlike) h(pthr) n(eads) e -(wher) n(e) g(the) h(link) h(is) f(only) g(for) g(the) g(duration) f -(of) i(the) e(wait\).) 37 b(The) 221 3955 y(same) 23 -b(mutex) f(may) h(be) f(used) f(with) i(several) f(condition) h(variab) -r(les.) 362 4068 y(A) c(wait) g(with) g(a) g(timeout) f(can) i(be) e -(achieved) h(by) g(call) r(ing) p Fd 19 w(tim) n(ed_w) n(ait\(\)) p -Fg -2 w(.) 27 b(This) 18 b(is) h(given) 221 4181 y(an) 27 -b(absolute) e(time) h(to) f(wait) h(until.) 38 b(The) 26 -b(r) n(outine) p Fd 25 w(omn) n(i_thr) n(ead:) n(:get_) n(time) n(\(\)) -p Fg 25 w(can) h(be) 221 4293 y(used) 21 b(to) h(turn) g(a) h(r) n -(elativ) r(e) f(time) g(into) h(an) g(absolute) f(time.) p -Fd 28 w(tim) n(ed_wa) n(it\(\)) p Fg 21 w(r) n(eturns) p -Fd 21 w(true) p Fg 21 w(if) 221 4406 y(the) 27 b(condition) h(was) g -(signalled,) p Fd 29 w(false) p Fg 26 w(if) h(the) f(time) g(expir) n -(ed) f(befor) n(e) g(the) h(condition) f(vari) r(-) 221 -4519 y(able) d(was) e(signalled.) p Fc 221 4774 a(2.3) 99 -b(Counting) 26 b(semaphores) p Fg 221 4951 a(An) p Fd -21 w(omn) n(i_sem) n(apho) n(re) p Fg 20 w(is) 21 b(a) h(counting) e -(semaphor) n(e) n(.) 28 b(When) 20 b(cr) n(eated) g(it) h(is) g(given) g -(an) g(initial) 221 5064 y(unsigned) j(intege) n(r) i(value.) 36 -b(When) p Fd 25 w(wai) n(t\(\)) p Fg 24 w(is) 26 b(called,) g(the) f -(value) h(is) f(decr) n(emente) n(d) g(if) h(non-) 221 -5177 y(zer) n(o.) 43 b(If) 27 b(the) g(value) h(is) f(zer) n(o) h(then) -f(the) f(thr) n(ead) h(blocks) h(instead.) 41 b(When) p -Fd 27 w(post) n(\(\)) p Fg 27 w(is) 27 b(cal) r(led,) 221 -5290 y(if) h(any) g(thr) n(eads) e(ar) n(e) i(blocked) f(in) p -Fd 27 w(wait\() n(\)) p Fg(,) h(exactly) f(one) g(thr) n(ead) g(is) g -(woken.) 41 b(If) 27 b(no) g(thr) n(eads) 221 5403 y(wer) n(e) 22 -b(blocked) g(then) g(the) g(value) h(of) g(the) e(semaphor) n(e) h(is) h -(incr) n(emented.) p 90 rotate dyy eop -%%Page: 3 3 -3 2 bop Fg 3306 249 a(3) 204 548 y(If) 27 b(a) h(thr) n(ead) e(cal) r -(ls) p Fd 27 w(try) n(_wait) n(\(\)) p Fg(,) h(then) g(the) f(thr) n -(ead) g(won't) h(block) h(if) f(the) g(semaphor) n(e's) 63 -661 y(value) c(is) g(0,) g(r) n(eturning) p Fd 21 w(false) p -Fg 21 w(instead.) 204 777 y(Ther) n(e) f(is) g(no) h(way) f(of) h -(query) n(ing) g(the) f(value) h(of) g(the) f(semaphor) n(e) n(.) p -Fh 63 1095 a(3) 119 b(Thread) 29 b(object) p Fg 63 1313 -a(A) 23 b(thr) n(ead) g(is) h(r) n(epr) n(ese) n(nted) e(by) i(an) p -Fd 24 w(omni) n(_thr) n(ead) p Fg 23 w(object.) 30 b(Ther) n(e) 23 -b(ar) n(e) h(br) n(oadly) g(two) e(dif) n(fer) n(-) 63 -1426 y(ent) f(ways) i(in) g(which) g(it) g(can) g(be) g(used) n(.) 204 -1542 y(The) 28 b(\002rst) g(way) h(is) h(simply) f(to) f(cr) n(eate) h -(an) p Fd 30 w(omn) n(i_thr) n(ead) p Fg 28 w(object,) h(giving) g(a) f -(particula) r(r) 63 1655 y(function) c(which) h(the) e(thr) n(ead) h -(should) f(execute) n(.) 36 b(This) 25 b(is) g(like) g(the) g(POSIX) f -(\(or) i(any) f(other) n(\)) h(C) 63 1768 y(language) c(interface.) 204 -1884 y(The) k(second) f(method) h(of) h(use) e(is) i(to) f(cr) n(eate) h -(a) g(new) g(class) g(which) g(inherits) f(fr) n(om) p -Fd 28 w(omn) n(i_) 63 1997 y(thr) n(ead) p Fg(.) 50 b(In) 31 -b(this) f(case) g(the) g(thr) n(ead) g(will) i(execute) d(the) p -Fd 29 w(run\(\)) p Fg 29 w(member) h(function) h(of) f(the) 63 -2109 y(new) 22 b(class.) 29 b(One) 23 b(advantage) g(of) g(this) g -(scheme) f(is) h(that) g(thr) n(ead-speci\002c) g(data) g(can) h(be) f -(imple-) 63 2222 y(mented) e(simply) h(by) h(having) g(data) g(members) -f(of) h(the) f(new) g(class.) 204 2339 y(When) f(constr) o(ucted) g(a) i -(thr) n(ead) f(is) g(in) h(the) e("new") h(state) f(and) h(has) g(not) g -(actuall) r(y) g(starte) n(d.) 28 b(A) 63 2451 y(call) j(to) p -Fd 29 w(sta) n(rt\(\)) p Fg 28 w(causes) e(the) g(thr) n(ead) g(to) g -(begin) g(executing.) 47 b(A) 29 b(static) h(member) f(function) p -Fd 63 2564 a(cre) n(ate\() n(\)) p Fg 32 w(is) j(pr) n(ovided) f(to) g -(constr) o(uct) g(and) g(start) g(a) i(thr) n(ead) e(in) h(a) g(single) -g(call.) 57 b(A) 31 b(thr) n(ead) 63 2677 y(exits) 21 -b(by) i(call) r(ing) p Fd 22 w(exit\() n(\)) p Fg 22 -w(or) g(by) f(r) n(eturning) g(fr) n(om) h(the) f(thr) n(ead) g -(function.) 204 2793 y(Thr) n(eads) 27 b(can) j(be) e(either) g -(detached) f(or) h(undetached) n(.) 46 b(Detached) 28 -b(thr) n(eads) g(ar) n(e) h(thr) n(eads) 63 2906 y(for) h(which) i(all) -g(state) e(will) i(be) f(lost) f(upon) g(exit.) 52 b(Other) 30 -b(thr) n(eads) g(cannot) h(dete) n(rmine) g(when) 63 -3019 y(a) e(detached) f(thr) n(ead) h(will) h(disappear) -7 -b(,) 31 b(and) e(ther) n(efor) n(e) f(should) g(not) h(attempt) f(to) g -(access) h(the) 63 3132 y(thr) n(ead) 23 b(object) g(unless) f(some) h -(explicit) h(synchr) n(onisation) f(with) g(the) g(detached) f(thr) n -(ead) h(guar) n(-) 63 3245 y(antees) e(that) h(it) h(still) g(exists.) -204 3361 y(Undet) n(ached) 33 b(thr) n(eads) f(ar) n(e) i(thr) n(eads) e -(for) h(which) g(storage) f(is) h(not) f(r) n(eclai) r(med) g(until) i -(an-) 63 3474 y(othe) n(r) g(thr) n(ead) g(waits) g(for) g(its) g -(termination) g(by) g(call) r(ing) p Fd 34 w(joi) n(n\(\)) p -Fg(.) 61 b(An) 34 b(exit) g(value) h(can) g(be) 63 3587 -y(passe) n(d) 23 b(fr) n(om) g(an) g(undet) n(ached) g(thr) n(ead) f -(to) g(the) g(thr) n(ead) g(which) h(joins) g(it.) 204 -3703 y(Detached) 31 b(/) h(undetached) e(thr) n(eads) h(ar) n(e) i -(distinguish) n(ed) f(on) f(cr) n(eation) h(by) g(the) f(type) g(of) 63 -3816 y(function) 24 b(they) e(execute.) 30 b(Undetached) 22 -b(thr) n(eads) h(execute) g(a) h(function) g(which) g(has) g(a) p -Fd 25 w(voi) n(d*) p Fg 63 3929 a(r) n(eturn) c(typ) n(e,) h(wher) n -(eas) f(detached) f(thr) n(eads) h(execute) f(a) j(function) f(which) g -(has) g(a) p Fd 21 w(void) p Fg 19 w(r) n(eturn) 63 4042 -y(typ) n(e.) 52 b(Unfortunate) n(ly) 31 b(C++) g(member) g(functions) f -(ar) n(e) h(not) f(allowed) g(to) g(be) h(distingu) n(ished) 63 -4155 y(simply) 26 b(by) h(their) f(r) n(eturn) g(type) n(.) 40 -b(Thus) 26 b(in) h(the) f(case) h(of) g(a) g(derived) f(class) h(of) p -Fd 26 w(omni_) n(thre) n(ad) p Fg 63 4268 a(which) 20 -b(needs) e(an) j(undet) n(ached) f(thr) n(ead,) g(the) f(member) h -(function) g(execute) n(d) g(by) g(the) f(thr) n(ead) g(is) 63 -4380 y(called) p Fd 19 w(run_u) n(ndet) n(ache) n(d\(\)) p -Fg 18 w(rather) f(than) p Fd 19 w(run\() n(\)) p Fg(,) h(and) g(it) g -(is) g(started) e(by) i(calli) r(ng) p Fd 18 w(star) n(t_) 63 -4493 y(und) n(etac) n(hed\(\)) p Fg 21 w(instead) j(of) p -Fd 22 w(start) n(\(\)) p Fg(.) 204 4610 y(The) i(abstraction) i(curr) n -(ently) e(suppo) n(rts) h(thr) n(ee) f(priorities) g(of) h(thr) n(ead,) -g(but) g(no) g(guarantee) 63 4722 y(is) 33 b(made) g(of) h(how) f(this) -g(will) h(af) n(f) r(ect) f(underlying) f(thr) n(ead) h(scheduling.) 59 -b(The) 33 b(thr) n(ee) f(priori-) 63 4835 y(ties) 18 -b(ar) n(e) p Fd 20 w(PRIO) n(RITY) n(_LOW) p Fg(,) p -Fd 18 w(PRIO) n(RITY) n(_NOR) n(MAL) p Fg 19 w(and) p -Fd 19 w(PRIO) n(RITY) n(_HIG) n(H) p Fg(.) h(By) g(default) g(all) 63 -4948 y(thr) n(eads) i(r) o(un) i(at) p Fd 23 w(PRIO) n(RITY) n(_NORM) n -(AL) p Fg(.) f(A) g(dif) n(fer) n(ent) h(priority) f(can) i(be) e -(speci\002ed) g(on) g(thr) n(ead) 63 5061 y(cr) n(eation,) h(or) f -(while) h(the) f(thr) n(ead) g(is) h(r) o(unning) g(using) p -Fd 22 w(set_) n(prio) n(rity\() n(\).) p Fg 28 w(A) g(thr) n(ead's) f -(cur) n(-) 63 5174 y(r) n(ent) g(priority) g(is) g(r) n(eturned) f(by) p -Fd 23 w(pri) n(ority) n(\(\)) p Fg(.) 204 5290 y(Other) d(functions) g -(pr) n(ovided) g(ar) n(e) p Fd 19 w(sel) n(f\(\)) p Fg -18 w(which) h(r) n(eturns) e(the) h(calli) r(ng) g(thr) n(ead's) p -Fd 18 w(omn) n(i_) 63 5403 y(thr) n(ead) p Fg 36 w(object,) p -Fd 40 w(yie) n(ld\(\)) p Fg 35 w(which) 38 b(r) n(eques) n(ts) e(that) h -(other) e(thr) n(eads) h(be) h(allowed) g(to) f(r) o(un,) p -90 rotate dyy eop -%%Page: 4 4 -4 3 bop Fg 221 249 a(4) p Fe 1367 w(6) 91 b(THRE) n(ADED) 23 -b(I/O) g(SHUTDOWN) f(FOR) g(UNIX) p Fd 221 548 a(id\(\)) p -Fg 27 w(which) 29 b(r) n(eturns) e(an) i(intege) n(r) g(id) f(for) h -(the) e(thr) n(ead) h(for) g(use) g(in) h(debug) n(ging,) p -Fd 29 w(state) n(\(\)) p Fg(,) p Fd 221 661 a(slee) n(p\(\)) p -Fg 22 w(and) p Fd 22 w(get_t) n(ime\() n(\)) p Fg(.) p -Fh 221 953 a(4) 119 b(Per) n(-threa) n(d) 30 b(data) p -Fg 221 1164 a(omnithr) n(ead) 22 b(suppo) n(rts) g(per) n(-thr) n(ead) f -(data,) h(via) i(member) e(functions) f(of) i(the) p -Fd 21 w(omni) n(_thr) n(ead) p Fg 221 1277 a(object.) 362 -1390 y(First,) d(you) g(must) h(allocate) h(a) f(key) f(for) g(with) h -(the) p Fd 20 w(omni) n(_thre) n(ad::) n(allo) n(cate_) n(key\() n(\)) p -Fg 221 1502 a(function.) 28 b(Then,) 21 b(any) h(object) g(whose) f -(class) h(is) g(derived) f(fr) n(om) p Fd 23 w(omni) n(_thr) n(ead::) n -(valu) n(e_t) p Fg 221 1615 a(can) 27 b(be) f(stor) n(e) n(d) g(using) f -(the) p Fd 26 w(set) n(_val) n(ue\(\)) p Fg 25 w(function.) 38 -b(V) -8 b(alues) 25 b(ar) n(e) h(r) n(etrieved) f(or) h(r) n(emoved) 221 -1728 y(with) p Fd 23 w(get) n(_valu) n(e\(\)) p Fg 21 -w(and) p Fd 23 w(remo) n(ve_v) n(alue\() n(\)) p Fg 22 -w(r) n(espectively) -10 b(.) 362 1841 y(When) 23 b(the) g(thr) n(ead) g -(exits,) g(all) i(per) n(-thr) n(ead) e(data) h(is) g(delet) n(ed) f -(\(hence) h(the) e(base) i(class) g(with) 221 1954 y(virtual) g(dest) n -(r) o(uctor\).) 362 2067 y(Note) 17 b(that) i(the) f(per) n(-thr) n -(ead) f(data) i(functions) f(ar) n(e) p Fb 19 w(not) p -Fg 18 w(thr) n(ead) g(safe,) i(so) d(although) i(you) e(can) 221 -2180 y(access) 29 b(one) e(thr) n(ead's) h(storage) f(fr) n(om) i -(another) f(thr) n(ead,) h(ther) n(e) e(is) i(no) f(concurr) n(ency) g -(contr) n(ol.) 221 2293 y(Unless) j(you) g(r) n(eall) r(y) h(know) f -(what) h(you) f(ar) n(e) i(doing,) g(it) g(is) f(best) f(to) h(only) g -(access) g(per) n(-thr) n(ead) 221 2406 y(data) 23 b(fr) n(om) g(the) f -(thr) n(ead) g(it) h(is) g(attached) f(to.) p Fh 221 -2698 a(5) 119 b(Using) 31 b(OMNI) d(threads) h(in) h(your) g(program) p -Fg 221 2909 a(Obvi) r(ously) 16 b(you) h(need) g(to) g(include) h(the) p -Fd 16 w(omnit) n(hrea) n(d.h) p Fg 17 w(header) e(\002le) i(in) g(your) -f(sour) n(ce) g(code,) 221 3021 y(and) 25 b(link) g(in) h(the) e -(omnithr) n(ead) g(libra) r(ry) g(with) h(your) f(execut) n(abl) r(e.) -34 b(Because) 23 b(ther) n(e) h(is) h(a) g(single) p -Fd 221 3134 a(omni) n(threa) n(d.h) p Fg 30 w(for) 32 -b(all) h(platforms,) h(certain) e(pr) n(epr) n(oces) n(sor) f -(de\002nes) f(must) h(be) g(given) h(as) 221 3247 y(compiler) 25 -b(options) n(.) 33 b(The) 23 b(easiest) g(way) h(to) g(do) f(this) h -(is) g(to) g(stud) n(y) g(the) g(make\002les) f(given) h(in) h(the) 221 -3360 y(examples) i(pr) n(ovided) g(with) g(this) g(distribution.) 42 -b(If) 27 b(you) g(ar) n(e) g(to) g(include) h(OMNI) f(thr) n(eads) g -(in) 221 3473 y(your) 18 b(own) g(development) g(envir) n(onment,) h -(thes) n(e) g(ar) n(e) g(the) f(necessary) g(pr) n(epr) n(oce) n(ssor) g -(de\002nes) n(:) p 362 3567 3287 4 v 360 3680 4 113 v -412 3646 a(Platform) p 1312 3680 V 599 w(Pr) n(epr) n(ocess) n(or) 23 -b(De\002nes) p 3648 3680 V 362 3683 3287 4 v 362 3700 -V 360 3813 4 113 v 412 3779 a(Sun) f(Solaris) h(2.x) p -1312 3813 V Fd 365 w(-D__) n(suno) n(s__) 54 b(-D_) n(_spa) n(rc__) f -(-D__) n(OSVER) n(SION) n(__=5) p 3648 3813 V 360 3926 -V 1312 3926 V 1363 3892 a(-DSV) n(R4) h(-DUs) n(ePth) n(read) f(-D_R) n -(EENT) n(RANT) p 3648 3926 V 362 3929 3287 4 v 360 4042 -4 113 v Fg 412 4008 a(x86) 24 b(Linux) e(2.0) p 1312 -4042 V Fd 418 w(-D__) n(linu) n(x__) 54 b(-D_) n(_i86) n(__) g(-D__) n -(OSVE) n(RSION) n(__=2) p 3648 4042 V 360 4155 V Fg 412 -4121 a(with) 23 b(linuxthr) n(eads) f(0.5) p 1312 4155 -V Fd 100 w(-D_R) n(EENT) n(RANT) p 3648 4155 V 362 4158 -3287 4 v 360 4271 4 113 v Fg 412 4237 a(Digital) i(Unix) f(3.2) p -1312 4271 V Fd 320 w(-D__) n(osf1) n(__) 54 b(-D__) n(alph) n(a__) g -(-D_) n(_OSV) n(ERSIO) n(N__=) n(3) p 3648 4271 V 360 -4384 V 1312 4384 V 1363 4350 a(-D_R) n(EENT) n(RANT) p -3648 4384 V 362 4387 3287 4 v 360 4500 4 113 v Fg 412 -4466 a(W) -5 b(indows) 22 b(NT) p 1312 4500 V Fd 411 -w(-D__) n(NT__) 53 b(-MD) p 3648 4500 V 362 4503 3287 -4 v Fh 221 4740 a(6) 119 b(Threaded) 29 b(I/O) g(shutdown) h(for) g -(Unix) p Fg 221 4951 a(or) -7 b(,) 20 b(how) e(one) g(thr) n(ead) h -(shou) n(ld) h(tell) f(another) f(thr) n(ead) g(to) h(shut) f(down) g -(when) g(it) h(might) g(be) g(doing) 221 5064 y(a) k(blocking) g(cal) r -(l) g(on) f(a) h(socket) n(.) p Fb 362 5177 a(If) h(you) e(are) i -(using) e(omniOR) n(B,) h(you) e(don') n(t) i(need) g(to) g(worry) f -(about) g(all) i(this,) f(since) h(om-) 221 5290 y(niORB) i(does) h(it) -h(for) f(you) n(.) p Fg 41 w(This) g(section) f(is) h(only) g(r) n -(elevant) g(if) h(you) e(ar) n(e) h(using) f(omnithr) n(ead) 221 -5403 y(in) d(your) f(own) g(socket) n(-based) h(pr) n(ogramming.) k(It) -22 b(is) h(also) g(serious) n(ly) g(out) f(of) h(date.) p -90 rotate dyy eop -%%Page: 5 5 -5 4 bop Fe 63 249 a(6.1) 91 b(r) n(ead\(\)) p Fg 2800 -w(5) 204 548 y(Unfortunate) n(ly) 35 b(ther) n(e) e(doe) n(sn't) h -(seem) f(to) h(be) g(a) h(standar) n(d) e(way) i(of) f(doing) f(this) h -(which) 63 661 y(works) 19 b(acr) n(oss) i(all) i(Unix) e(syst) n(ems.) -27 b(I) 21 b(have) g(investigated) f(the) h(behaviour) g(of) g(Solaris) -h(2.5) g(and) 63 774 y(Digital) k(Unix) g(3.2.) 36 b(On) 26 -b(Digital) h(Unix) e(everyth) n(ing) h(is) f(\002ne,) g(as) h(the) e -(obvious) h(method) f(using) 63 887 y(shutd) n(own\(\)) 32 -b(seems) f(to) h(work) f(OK.) h(Unfortunately) f(on) h(Solaris) h(shut) -n(down) f(can) h(only) f(be) 63 1000 y(used) 25 b(on) h(a) h(connected) -e(socke) n(t,) i(so) f(we) g(need) f(devious) h(means) g(to) g(get) f -(ar) n(ound) h(this) g(lim) r(ita-) 63 1112 y(tion.) h(The) 22 -b(details) g(ar) n(e) h(summarised) g(below:) p Fc 63 -1429 a(6.1) 99 b(read\(\)) p Fg 63 1627 a(Thr) n(ead) 28 -b(A) h(is) g(in) h(a) g(loop,) g(doing) p Fd 28 w(rea) n(d\(soc) n(k\)) -p Fg(,) g(pr) n(ocess) n(ing) f(the) g(data,) h(then) f(going) f(back) -63 1739 y(into) 22 b(the) g(r) n(ead.) 204 1862 y(Thr) n(ead) 30 -b(B) h(comes) f(along) h(and) g(wants) f(to) g(shut) g(it) h(down) f -(\227) h(it) g(can't) g(cancel) h(thr) n(ead) f(A) 63 -1975 y(since) 21 b(\(i\)) h(working) e(out) g(how) g(to) h(clean) h(up) -e(accor) n(ding) i(to) e(wher) n(e) g(A) h(is) g(in) h(its) f(loop) f -(is) h(a) h(night-) 63 2088 y(mar) n(e,) h(and) f(\(ii\)) i(this) f -(isn't) f(ava) r(ilabl) r(e) g(in) h(omnithr) n(ead) f(anyway) -10 -b(.) 204 2211 y(On) 23 b(Solaris) g(2.5) g(and) g(Digital) h(Unix) f -(3.2) g(the) f(following) h(strate) n(gy) f(works:) 204 -2334 y(Thr) n(ead) g(B) g(does) p Fd 21 w(shut) n(down\() n(sock) n -(,2\)) p Fg(.) 204 2457 y(At) g(this) g(point) h(thr) n(ead) f(A) g(is) -h(either) f(blocked) g(inside) p Fd 23 w(rea) n(d\(so) n(ck\)) p -Fg(,) g(or) g(is) h(elsewhe) n(r) n(e) g(in) 63 2570 -y(the) 18 b(loop.) 26 b(If) 18 b(the) g(former) h(then) f(r) n(ead) h -(will) h(r) n(eturn) e(0,) i(indicating) f(that) g(the) f(socke) n(t) h -(is) g(closed.) 26 b(If) 63 2683 y(the) 21 b(latter) h(then) f -(eventually) h(thr) n(ead) g(A) g(will) i(call) p Fd -24 w(rea) n(d\(so) n(ck\)) p Fg 21 w(and) f(then) e(this) h(will) h(r) n -(eturn) 63 2796 y(0.) 28 b(Thr) n(ead) 22 b(A) h(should) p -Fd 21 w(clos) n(e\(soc) n(k\)) p Fg(,) f(do) g(any) g(other) g(tidying) -f(up,) h(and) h(exit.) 204 2919 y(If) 34 b(ther) n(e) g(is) h(another) f -(point) g(in) h(the) e(loop) i(that) f(thr) n(ead) g(A) h(can) g(block) -g(then) f(obviously) 63 3032 y(thr) n(ead) 19 b(B) h(needs) f(to) h(be) -g(awar) n(e) h(of) f(this) g(and) g(be) h(able) g(to) e(wake) h(it) h -(up) f(in) g(the) g(appr) n(opriate) g(way) 63 3145 y(fr) n(om) j(that) -f(point.) p Fc 63 3462 a(6.2) 99 b(accept\(\)) p Fg 63 -3659 a(Again) 25 b(thr) n(ead) g(A) h(is) f(in) h(a) g(loop,) g(this) f -(time) h(doing) e(an) i(acc) r(ept) e(on) h(listenSock,) g(dealing) h -(with) 63 3772 y(a) d(new) f(connection) g(and) h(going) e(back) j -(into) e(accept.) 28 b(Thr) n(ead) 22 b(B) g(wants) h(to) f(cancel) h -(it.) 204 3895 y(On) g(Digital) h(Unix) f(3.2) g(the) f(strateg) n(y) g -(is) h(identical) h(to) e(that) g(for) h(r) n(ead:) 204 -4018 y(Thr) n(ead) 39 b(B) g(does) p Fd 38 w(shut) n(down) n(\(list) n -(enSo) n(ck,2) n(\)) p Fg(.) 79 b(Wher) n(ever) 38 b(thr) n(ead) h(A) h -(is) f(in) h(the) 63 4131 y(loop,) i(eventually) c(it) h(will) h(r) n -(eturn) p Fd 38 w(ECONN) n(ABOR) n(TED) p Fg 38 w(fr) n(om) f(the) f -(accept) h(call) r(.) 76 b(It) 39 b(shou) n(ld) p Fd -63 4244 a(clo) n(se\(l) n(isten) n(Sock) n(\)) p Fg(,) 22 -b(tidy) g(up) g(as) h(necessary) e(and) i(exit.) 204 -4367 y(On) 30 b(Solaris) f(2.5) i(thr) n(ead) e(B) g(can't) h(do) p -Fd 29 w(shu) n(tdow) n(n\(lis) n(tenS) n(ock,2) n(\)) p -Fg 29 w(\227) g(this) f(r) n(eturns) p Fd 63 4480 a(ENO) n(TCON) n(N) p -Fg(.) 22 b(Instead) f(the) h(following) h(strateg) n(y) g(can) g(be) g -(used) n(:) 204 4603 y(First) 35 b(thr) n(ead) h(B) g(set) n(s) g(some) -f(sort) g(of) h("shutdo) n(wn) g(\003ag") g(associated) g(with) g -(listenSock.) 63 4716 y(Then) 31 b(it) h(does) p Fd 30 -w(gets) n(ocka) n(ddr\(l) n(iste) n(nSock) n(\)) p Fg -32 w(to) f(\002nd) g(out) g(which) i(port) e(listenSock) f(is) 63 -4828 y(on) 18 b(\(or) h(knows) e(alr) n(eady\),) j(sets) d(up) h(a) h -(socket) e(dummySock,) i(doe) n(s) p Fd 19 w(con) n(nect) n(\(dumm) n -(ySoc) n(k,) 63 4941 y(thi) n(s) 54 b(host,) f(por) n(t\)) p -Fg 22 w(and) 23 b(\002nally) g(does) p Fd 21 w(clos) n(e\(dum) n(mySo) n -(ck\)) p Fg(.) 204 5064 y(Wher) n(ever) 16 b(thr) n(ead) h(A) g(is) g -(in) h(the) e(loop,) h(eventually) g(it) h(will) g(call) p -Fd 19 w(acce) n(pt\(li) n(sten) n(Sock) n(\)) p Fg(.) 63 -5177 y(This) 35 b(will) j(r) n(eturn) d(successfully) g(with) h(a) h -(new) e(socket,) j(say) e(connSock.) 67 b(Thr) n(ead) 36 -b(A) f(then) 63 5290 y(checks) 20 b(to) h(see) f(if) i(the) f("shutd) n -(own) g(\003ag") h(is) f(set.) 26 b(If) c(not,) e(then) h(it's) g(a) h -(normal) g(connection.) 27 b(If) 21 b(it) 63 5403 y(is) h(set,) g(then) -f(thr) n(ead) h(A) h(closes) f(listenSock) f(and) i(connSock,) e -(tidies) h(up) g(and) h(exits.) p 90 rotate dyy eop -%%Page: 6 6 -6 5 bop Fg 221 249 a(6) p Fe 1367 w(6) 91 b(THRE) n(ADED) 23 -b(I/O) g(SHUTDOWN) f(FOR) g(UNIX) p Fc 221 548 a(6.3) 99 -b(write\(\)) p Fg 221 768 a(Thr) n(ead) 19 b(A) f(may) h(be) g(blocked) -f(in) i(write,) f(or) f(about) h(to) f(go) g(in) h(to) g(a) g(poten) n -(tiall) r(y-blocking) g(write.) 221 881 y(Thr) n(ead) j(B) h(wants) f -(to) g(shut) f(it) i(down.) 362 1016 y(On) g(Solaris) g(2.5:) 362 -1150 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23 w(shu) n(tdown) n(\(soc) n -(k,2\)) p Fg -2 w(.) 362 1285 y(If) c(thr) n(ead) f(A) h(is) g(alr) n -(eady) g(in) p Fd 20 w(wri) n(te\(s) n(ock\)) p Fg 17 -w(then) f(it) h(will) i(r) n(eturn) d(with) p Fd 18 w(ENXIO) p -Fg -2 w(.) h(If) g(thr) n(ead) 221 1398 y(A) k(calls) h(write) e(after) -g(thr) n(ead) g(B) h(calls) h(shut) n(down) e(this) g(will) i(r) n -(eturn) p Fd 22 w(EIO) p Fg(.) 362 1532 y(On) f(Digital) h(Unix) f -(3.2:) 362 1666 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23 -w(shu) n(tdown) n(\(soc) n(k,2\)) p Fg -2 w(.) 362 1801 -y(If) h(thr) n(ead) f(A) g(is) h(alr) n(eady) g(in) p -Fd 24 w(writ) n(e\(so) n(ck\)) p Fg 23 w(then) e(it) i(will) h(r) n -(eturn) e(the) f(number) i(of) f(bytes) 221 1914 y(written) 31 -b(befor) n(e) h(it) g(became) g(blocked.) 55 b(A) 32 -b(subseq) n(uent) f(cal) r(l) h(to) f(write) h(will) h(then) e(gene) n -(rate) p Fd 221 2027 a(SIGP) n(IPE) p Fg 22 w(\(or) p -Fd 22 w(EPIP) n(E) p Fg 23 w(will) 24 b(be) e(r) n(eturned) f(if) p -Fd 24 w(SIG) n(PIPE) p Fg 21 w(is) i(ignor) n(ed) e(by) i(the) f(thr) n -(ead\).) p Fc 221 2413 a(6.4) 99 b(connect\(\)) p Fg -221 2634 a(Thr) n(ead) 30 b(A) f(may) h(be) g(blocked) f(in) i -(connect,) g(or) e(about) h(to) f(go) g(in) i(to) e(a) h(poten) n -(tiall) r(y-blocking) 221 2747 y(connect.) d(Thr) n(ead) c(B) f(wants) g -(to) g(shut) g(it) g(down.) 362 2881 y(On) h(Digital) h(Unix) f(3.2:) -362 3016 y(Thr) n(ead) f(B) h(doe) n(s) p Fd 23 w(shu) n(tdown) n -(\(soc) n(k,2\)) p Fg -2 w(.) 362 3150 y(If) j(thr) n(ead) f(A) g(is) h -(alr) n(eady) g(in) p Fd 26 w(conn) n(ect\() n(sock) n(\)) p -Fg 26 w(then) e(it) i(will) h(r) n(eturn) e(a) h(successful) f(con-) 221 -3263 y(nection.) 54 b(Subsequ) n(ent) 31 b(r) n(eading) g(or) g -(writing) g(will) i(show) d(that) i(the) e(socket) g(has) h(been) g -(shut) 221 3376 y(down) 22 b(\(i.e.) 28 b(r) n(ead) 23 -b(r) n(eturns) e(0,) i(write) f(generate) n(s) p Fd 23 -w(SIG) n(PIPE) p Fg 21 w(or) g(r) n(eturns) p Fd 22 w(EPI) n(PE) p -Fg(\).) g(If) h(thr) n(ead) f(A) 221 3489 y(call) r(s) g(connect) g -(after) h(thr) n(ead) f(B) g(call) r(s) g(shutdo) n(wn) h(this) f(will) -i(r) n(eturn) p Fd 22 w(EIN) n(VAL) p Fg(.) 362 3623 -y(On) f(Solaris) g(2.5:) 362 3758 y(Ther) n(e) 35 b(is) h(no) f(way) g -(to) g(wake) g(up) g(a) h(thr) n(ead) f(which) h(is) g(blocked) f(in) h -(connect.) 66 b(Inst) n(ead) 221 3871 y(Solaris) 33 b(for) n(ces) g(us) -f(thr) n(ough) g(a) i(ridiculous) f(pr) n(oced) n(ur) n(e) g(whichever) -g(way) g(we) f(try) g(it.) 59 b(One) 221 3984 y(way) 23 -b(is) f(this:) 362 4118 y(First) d(thr) n(ead) h(A) g(cr) n(eates) f(a) -h(pipe) g(in) g(addition) g(to) f(the) g(socket) n(.) 27 -b(Instead) 19 b(of) h(shut) n(ting) g(down) 221 4231 -y(the) i(socket) n(,) h(thr) n(ead) f(B) g(simply) h(writes) e(a) i -(byte) f(to) g(the) g(pipe.) 362 4365 y(Thr) n(ead) 17 -b(A) g(meanwhile) h(set) n(s) f(the) g(socke) n(t) g(to) g -(non-blocking) g(mode) f(using) p Fd 17 w(fcn) n(tl\(s) n(ock,) 221 -4478 y(F_SE) n(TFL,) 53 b(O_NO) n(NBLO) n(CK\)) p Fg(.) 26 -b(Then) h(it) g(cal) r(ls) g(connect) g(on) g(the) f(socket) g(\227) h -(this) g(will) i(r) n(eturn) p Fd 221 4591 a(EINP) n(ROGRE) n(SS) p -Fg(.) k(Then) h(it) h(must) e(cal) r(l) p Fd 35 w(sel) n(ect\() n(\)) p -Fg(,) k(waiting) e(for) f(either) g(sock) g(to) f(become) 221 -4704 y(writable) 39 b(or) f(for) h(the) e(pipe) h(to) g(become) g(r) n -(eadable.) 75 b(If) 39 b(select) e(r) n(eturns) g(that) i(just) e(sock) -h(is) 221 4817 y(writable) 30 b(then) f(the) g(connection) g(has) h -(succeede) n(d.) 49 b(It) 29 b(then) g(need) n(s) h(to) f(set) f(the) h -(socket) f(back) 221 4930 y(to) i(blocking) h(mode) f(using) p -Fd 30 w(fcnt) n(l\(so) n(ck,) 54 b(F_S) n(ETFL) n(,) h(0\)) p -Fg(.) c(If) 31 b(instead) e(select) h(r) n(eturns) 221 -5043 y(that) 23 b(the) e(pipe) h(is) h(r) n(eadable,) g(thr) n(ead) f -(A) h(closes) e(the) h(socket) n(,) h(tidies) f(up) g(and) h(exits.) 362 -5177 y(An) g(alternative) h(method) e(is) i(similar) h(but) e(to) g -(use) f(polling) i(instead) e(of) i(the) e(pipe.) 29 -b(Thr) n(ead) 221 5290 y(B) 24 b(justs) e(sets) g(a) j(\003ag) f(and) g -(thr) n(ead) f(A) h(calls) h(select) e(with) g(a) i(timeout,) e(period) -n(ica) r(lly) h(waking) f(up) 221 5403 y(to) f(see) g(if) h(the) f -(\003ag) h(has) f(been) g(set.) p 90 rotate dyy eop -%%Page: 7 7 -7 6 bop Fe 63 249 a(REF) n(ERENCES) p Fg 2660 w(7) p -Fh 63 548 a(Refere) n(nces) p Fg 63 759 a([POSIX94]) p -Fa 46 w(Portable) 29 b(Operat) r(ing) f(System) g(Interface) h -(\(POSIX\)) e(Thr) n(ea) r(ds) h(Extension) p Fg(,) h(P1003) r(.1c) 245 -872 y(Draft) 23 b(10,) g(IEEE,) e(Septe) n(mber) i(1994) r(.) 63 -1059 y([Birr) n(ell89]) p Fa 47 w(An) 28 b(Intr) n(od) r(uction) g(to) h -(Pr) n(ogr) r(amming) g(with) g(Thr) n(ead) r(s) p Fg(,) h(Rese) n(ar) n -(ch) g(Repo) n(rt) e(35,) j(DEC) 245 1172 y(Syst) n(ems) 22 -b(Resear) n(ch) g(Center) -7 b(,) 22 b(Palo) h(Alto,) f(CA,) h(January) -g(1989) r(.) p 90 rotate dyy eop -%%Trailer -end -userdict /end-hook known{end-hook}if -%%EOF diff --git a/gcell/apps/Makefile.am b/gcell/apps/Makefile.am index 7cf9122a34..c3a2092a33 100644 --- a/gcell/apps/Makefile.am +++ b/gcell/apps/Makefile.am @@ -22,9 +22,7 @@ include $(top_srcdir)/Makefile.common SUBDIRS = spu . -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_INCLUDES) \ - $(GCELL_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) - +AM_CPPFLAGS = $(DEFINES) $(GCELL_INCLUDES) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) GCELL_QA_LA = $(top_builddir)/gcell/lib/libgcell-qa.la diff --git a/gcell/apps/benchmark_dma.cc b/gcell/apps/benchmark_dma.cc index a84defe370..bc3b3f3289 100644 --- a/gcell/apps/benchmark_dma.cc +++ b/gcell/apps/benchmark_dma.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include <config.h> #endif #include <gcell/gc_job_manager.h> -#include <gnuradio/omni_time.h> +#include <boost/date_time/posix_time/posix_time_types.hpp> #include <getopt.h> #include <stdlib.h> #include <stdio.h> @@ -95,6 +95,8 @@ init_jd(gc_job_desc *jd, unsigned int usecs, static void run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getput_mask) { + using namespace boost::posix_time; + static const int64_t TOTAL_SIZE_DMA = 5LL << 30; static const int NJDS = 64; unsigned int njobs = (unsigned int)(TOTAL_SIZE_DMA / dma_size); @@ -148,7 +150,7 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getp for (int iter = 0; iter < 1; iter++){ - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); nsubmitted = 0; ncompleted = 0; @@ -203,9 +205,9 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getp } // stop timing - omni_time t_stop = omni_time::time(); + ptime t_stop(microsec_clock::universal_time()); - double delta = (t_stop - t_start).double_time(); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f dma_size: %5d dma_throughput: %7.3e\n", mgr->nspes(), usecs, delta, dma_size, (double) njobs * dma_size / delta * (getput_mask == BENCHMARK_GET_PUT ? 2.0 : 1.0)); diff --git a/gcell/apps/benchmark_nop.cc b/gcell/apps/benchmark_nop.cc index dee46c8420..a27373db40 100644 --- a/gcell/apps/benchmark_nop.cc +++ b/gcell/apps/benchmark_nop.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include <config.h> #endif #include <gcell/gc_job_manager.h> -#include <gnuradio/omni_time.h> +#include <boost/date_time/posix_time/posix_time_types.hpp> #include <getopt.h> #include <stdlib.h> #include <stdio.h> @@ -47,6 +47,8 @@ init_jd(gc_job_desc *jd, unsigned int usecs) static void run_test(unsigned int nspes, unsigned int usecs, int njobs) { + using namespace boost::posix_time; + static const int NJDS = 64; int nsubmitted = 0; int ncompleted = 0; @@ -73,7 +75,7 @@ run_test(unsigned int nspes, unsigned int usecs, int njobs) init_jd(all_jds[i], usecs); } - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); ci = 0; njds[0] = 0; @@ -122,8 +124,8 @@ run_test(unsigned int nspes, unsigned int usecs, int njobs) } // stop timing - omni_time t_stop = omni_time::time(); - double delta = (t_stop - t_start).double_time(); + ptime t_stop(microsec_clock::universal_time()); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f njobs: %g speedup: %6.3f\n", mgr->nspes(), usecs, delta, (double) njobs, njobs * usecs * 1e-6 / delta); diff --git a/gcell/apps/benchmark_roundtrip.cc b/gcell/apps/benchmark_roundtrip.cc index 8ba37c968e..b994182a88 100644 --- a/gcell/apps/benchmark_roundtrip.cc +++ b/gcell/apps/benchmark_roundtrip.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include <config.h> #endif #include <gcell/gc_job_manager.h> -#include <gnuradio/omni_time.h> +#include <boost/date_time/posix_time/posix_time_types.hpp> #include <getopt.h> #include <stdlib.h> #include <stdio.h> @@ -96,6 +96,8 @@ static void run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getput_mask, int njobs_at_once) { + using namespace boost::posix_time; + int NJDS = njobs_at_once; gc_job_desc *all_jds[NJDS]; bool done[NJDS]; @@ -140,7 +142,7 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, } int niter = 100000; - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); for (int iter = 0; iter < niter; iter++){ @@ -164,8 +166,8 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, } // stop timing - omni_time t_stop = omni_time::time(); - double delta = (t_stop - t_start).double_time(); + ptime t_stop(microsec_clock::universal_time()); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f dma_size: %5d dma_throughput: %7.3e round_trip: %gus\n", mgr->nspes(), usecs, delta, dma_size, (double) NJDS * niter * dma_size / delta * (getput_mask == BENCHMARK_GET_PUT ? 2.0 : 1.0), diff --git a/gcell/gcell.pc.in b/gcell/gcell.pc.in index d88d0fb674..e602ff7c39 100644 --- a/gcell/gcell.pc.in +++ b/gcell/gcell.pc.in @@ -6,7 +6,7 @@ gcell_embedspu_libtool=@bindir@/gcell-embedspu-libtool Name: gcell Description: The GNU Radio SPE scheduler and RPC mechanism -Requires: gnuradio-omnithread +Requires: Version: @VERSION@ Libs: -L${libdir} -lgcell Cflags: -I${includedir} @DEFINES@ diff --git a/gcell/lib/Makefile.am b/gcell/lib/Makefile.am index e7b349331d..fa9c4a0031 100644 --- a/gcell/lib/Makefile.am +++ b/gcell/lib/Makefile.am @@ -36,7 +36,7 @@ libgcell_la_LIBADD = \ runtime/libruntime.la \ wrapper/libwrapper.la \ -lspe2 \ - $(OMNITHREAD_LA) + $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) libgcell_qa_la_LIBADD = \ runtime/libruntime-qa.la \ diff --git a/gcell/lib/runtime/Makefile.am b/gcell/lib/runtime/Makefile.am index 2c653918e6..4d13790cd2 100644 --- a/gcell/lib/runtime/Makefile.am +++ b/gcell/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,7 +23,7 @@ include $(top_srcdir)/Makefile.common IBM_PPU_SYNC_INCLUDES = -I$(top_srcdir)/gcell/ibm/sync/ppu_source -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_INCLUDES) $(MBLOCK_INCLUDES) $(CPPUNIT_INCLUDES) \ +AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) \ $(GCELL_INCLUDES) $(IBM_PPU_SYNC_INCLUDES) $(WITH_INCLUDES) diff --git a/gcell/lib/runtime/gc_client_thread_info.h b/gcell/lib/runtime/gc_client_thread_info.h index 9f46ecca77..e49c070975 100644 --- a/gcell/lib/runtime/gc_client_thread_info.h +++ b/gcell/lib/runtime/gc_client_thread_info.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_GC_CLIENT_THREAD_INFO_H #define INCLUDED_GC_CLIENT_THREAD_INFO_H -#include <gnuradio/omnithread.h> +#include <boost/thread.hpp> #include <boost/utility.hpp> enum gc_ct_state { @@ -40,7 +40,7 @@ enum gc_ct_state { class gc_client_thread_info : boost::noncopyable { public: gc_client_thread_info() : - d_free(1), d_cond(&d_mutex), d_state(CT_NOT_WAITING), + d_free(1), d_cond(), d_state(CT_NOT_WAITING), d_jobs_done(0), d_njobs_waiting_for(0), d_jobs_waiting_for(0){ } @@ -59,10 +59,10 @@ public: uint16_t d_client_id; //! hold this mutex to manipulate anything below here - omni_mutex d_mutex; + boost::mutex d_mutex; //! signaled by event handler to wake client thread up - omni_condition d_cond; + boost::condition_variable d_cond; //! Is this client waiting? gc_ct_state d_state; diff --git a/gcell/lib/runtime/gc_job_manager_impl.cc b/gcell/lib/runtime/gc_job_manager_impl.cc index cc49fd1f3a..58597cf276 100644 --- a/gcell/lib/runtime/gc_job_manager_impl.cc +++ b/gcell/lib/runtime/gc_job_manager_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,6 +39,7 @@ #include <string.h> #include <sched.h> +typedef boost::unique_lock<boost::mutex> scoped_lock; #define __nop() __asm__ volatile ("ori 0,0,0" : : : "memory") #define __cctpl() __asm__ volatile ("or 1,1,1" : : : "memory") @@ -116,9 +117,9 @@ is_power_of_2(uint32_t x) gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) : d_debug(0), d_spu_args(0), - d_eh_cond(&d_eh_mutex), d_eh_thread(0), d_eh_state(EHS_INIT), + d_eh_cond(), d_eh_thread(0), d_eh_state(EHS_INIT), d_shutdown_requested(false), - d_jc_cond(&d_jc_mutex), d_jc_thread(0), d_jc_state(JCS_INIT), d_jc_njobs_active(0), + d_jc_cond(), d_jc_thread(0), d_jc_state(JCS_INIT), d_jc_njobs_active(0), d_ntell(0), d_tell_start(0), d_client_thread(0), d_ea_args_maxsize(0), d_proc_def(0), d_proc_def_ls_addr(0), d_nproc_defs(0) @@ -368,12 +369,12 @@ gc_job_manager_impl::~gc_job_manager_impl() bool gc_job_manager_impl::shutdown() { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); { - omni_mutex_lock l2(d_jc_mutex); + scoped_lock l2(d_jc_mutex); d_shutdown_requested = true; // set flag for event handler thread - d_jc_cond.signal(); // wake up job completer + d_jc_cond.notify_one(); // wake up job completer } // should only happens during early QA code @@ -381,7 +382,7 @@ gc_job_manager_impl::shutdown() return false; while (d_eh_state != EHS_DEAD) // wait for it to finish - d_eh_cond.wait(); + d_eh_cond.wait(l); return true; } @@ -459,13 +460,13 @@ gc_job_manager_impl::free_job_desc(gc_job_desc *jd) inline bool gc_job_manager_impl::incr_njobs_active() { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); if (d_shutdown_requested) return false; if (d_jc_njobs_active++ == 0) // signal on 0 to 1 transition - d_jc_cond.signal(); + d_jc_cond.notify_one(); return true; } @@ -473,7 +474,7 @@ gc_job_manager_impl::incr_njobs_active() inline void gc_job_manager_impl::decr_njobs_active(int n) { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); d_jc_njobs_active -= n; } @@ -614,7 +615,7 @@ gc_job_manager_impl::wait_jobs(unsigned int njobs, } { - omni_mutex_lock l(cti->d_mutex); + scoped_lock l(cti->d_mutex); // setup info for event handler cti->d_state = (mode == GC_WAIT_ANY) ? CT_WAIT_ANY : CT_WAIT_ALL; @@ -646,7 +647,7 @@ gc_job_manager_impl::wait_jobs(unsigned int njobs, // FIXME what happens when somebody calls shutdown? - cti->d_cond.wait(); // wait for event handler to wake us up + cti->d_cond.wait(l); // wait for event handler to wake us up } cti->d_state = CT_NOT_WAITING; @@ -835,17 +836,17 @@ gc_job_manager_impl::create_event_handler() void gc_job_manager_impl::set_eh_state(evt_handler_state s) { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); d_eh_state = s; - d_eh_cond.broadcast(); + d_eh_cond.notify_all(); } void gc_job_manager_impl::set_ea_args_maxsize(int maxsize) { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); d_ea_args_maxsize = maxsize; - d_eh_cond.broadcast(); + d_eh_cond.notify_all(); } void @@ -956,7 +957,7 @@ gc_job_manager_impl::notify_clients_jobs_are_done(unsigned int spe_num, // FIXME we could distinguish between CT_WAIT_ALL & CT_WAIT_ANY if (last_cti->d_state == CT_WAIT_ANY || last_cti->d_state == CT_WAIT_ALL) - last_cti->d_cond.signal(); // wake client thread up + last_cti->d_cond.notify_one(); // wake client thread up last_cti->d_mutex.unlock(); cti->d_mutex.lock(); @@ -970,7 +971,7 @@ gc_job_manager_impl::notify_clients_jobs_are_done(unsigned int spe_num, // "wind-out" if (last_cti->d_state == CT_WAIT_ANY || last_cti->d_state == CT_WAIT_ALL) - last_cti->d_cond.signal(); // wake client thread up + last_cti->d_cond.notify_one(); // wake client thread up last_cti->d_mutex.unlock(); ci->in_use = 0; // clear flag so SPE knows we're done with it @@ -1189,13 +1190,13 @@ gc_job_manager_impl::job_completer_loop() while (1){ { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); if (d_jc_njobs_active == 0){ if (d_shutdown_requested){ d_jc_state = JCS_DEAD; return; } - d_jc_cond.wait(); + d_jc_cond.wait(l); } } @@ -1280,10 +1281,10 @@ gc_job_manager_impl::free_cti(gc_client_thread_info *cti) int gc_job_manager_impl::ea_args_maxsize() { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); while (d_ea_args_maxsize == 0) // wait for it to be initialized - d_eh_cond.wait(); + d_eh_cond.wait(l); return d_ea_args_maxsize; } diff --git a/gcell/lib/runtime/gc_job_manager_impl.h b/gcell/lib/runtime/gc_job_manager_impl.h index a56117870b..640fdfe793 100644 --- a/gcell/lib/runtime/gc_job_manager_impl.h +++ b/gcell/lib/runtime/gc_job_manager_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -107,16 +107,16 @@ class gc_job_manager_impl : public gc_job_manager boost::shared_ptr<void> _d_comp_info_boost; // hack for automatic storage mgmt // used to coordinate communication w/ the event handling thread - omni_mutex d_eh_mutex; - omni_condition d_eh_cond; + boost::mutex d_eh_mutex; + boost::condition_variable d_eh_cond; pthread_t d_eh_thread; // the event handler thread volatile evt_handler_state d_eh_state; volatile bool d_shutdown_requested; spe_event_handler d_spe_event_handler; // used to coordinate communication w/ the job completer thread - omni_mutex d_jc_mutex; - omni_condition d_jc_cond; + boost::mutex d_jc_mutex; + boost::condition_variable d_jc_cond; pthread_t d_jc_thread; // the job completion thread volatile job_completer_state d_jc_state; int d_jc_njobs_active; // # of jobs submitted but not yet reaped diff --git a/gnuradio-core/gnuradio-core.pc.in b/gnuradio-core/gnuradio-core.pc.in index dc06fcf89f..9ff8350411 100644 --- a/gnuradio-core/gnuradio-core.pc.in +++ b/gnuradio-core/gnuradio-core.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@/gnuradio Name: gnuradio-core Description: GNU Software Radio toolkit -Requires: gruel fftw3f gsl gnuradio-omnithread +Requires: gruel fftw3f gsl Version: @VERSION@ Libs.private: @BOOST_LDFLAGS@ @BOOST_THREAD_LIB@ @BOOST_DATE_TIME_LIB@ Libs: -L${libdir} -lgnuradio-core diff --git a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc index 48eb849ab1..5a6e753ab4 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -79,8 +79,8 @@ gr_pfb_arb_resampler_ccf::gr_pfb_arb_resampler_ccf (float rate, // Now, actually set the filters' taps std::vector<float> dtaps; create_diff_taps(taps, dtaps); - set_taps(taps, d_taps, d_filters); - set_taps(dtaps, d_dtaps, d_diff_filters); + create_taps(taps, d_taps, d_filters); + create_taps(dtaps, d_dtaps, d_diff_filters); } gr_pfb_arb_resampler_ccf::~gr_pfb_arb_resampler_ccf () @@ -91,9 +91,9 @@ gr_pfb_arb_resampler_ccf::~gr_pfb_arb_resampler_ccf () } void -gr_pfb_arb_resampler_ccf::set_taps (const std::vector<float> &newtaps, - std::vector< std::vector<float> > &ourtaps, - std::vector<gr_fir_ccf*> &ourfilter) +gr_pfb_arb_resampler_ccf::create_taps (const std::vector<float> &newtaps, + std::vector< std::vector<float> > &ourtaps, + std::vector<gr_fir_ccf*> &ourfilter) { int i,j; diff --git a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h index b99ad286b8..cf5a79d4ee 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_arb_resampler_ccf.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -139,18 +139,23 @@ class gr_pfb_arb_resampler_ccf : public gr_block void create_diff_taps(const std::vector<float> &newtaps, std::vector<float> &difftaps); - -public: - ~gr_pfb_arb_resampler_ccf (); - + /*! * Resets the filterbank's filter taps with the new prototype filter - * \param taps (vector/list of floats) The prototype filter to populate the filterbank. The taps - * should be generated at the interpolated sampling rate. + * \param newtaps (vector of floats) The prototype filter to populate the filterbank. + * The taps should be generated at the interpolated sampling rate. + * \param ourtaps (vector of floats) Reference to our internal member of holding the taps. + * \param ourfilter (vector of filters) Reference to our internal filter to set the taps for. */ - void set_taps (const std::vector<float> &newtaps, - std::vector< std::vector<float> > &ourtaps, - std::vector<gr_fir_ccf*> &ourfilter); + void create_taps (const std::vector<float> &newtaps, + std::vector< std::vector<float> > &ourtaps, + std::vector<gr_fir_ccf*> &ourfilter); + + +public: + ~gr_pfb_arb_resampler_ccf (); + + // FIXME: See about a set_taps function during runtime. /*! * Print all of the filterbank taps to screen. diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc index 7e34551c8e..5fda47880f 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -33,20 +33,33 @@ #include <cstring> gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps) + const std::vector<float> &taps, + float oversample_rate) { - return gr_pfb_channelizer_ccf_sptr (new gr_pfb_channelizer_ccf (numchans, taps)); + return gr_pfb_channelizer_ccf_sptr (new gr_pfb_channelizer_ccf (numchans, taps, + oversample_rate)); } gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps) - : gr_sync_block ("pfb_channelizer_ccf", - gr_make_io_signature (numchans, numchans, sizeof(gr_complex)), - gr_make_io_signature (1, 1, numchans*sizeof(gr_complex))), - d_updated (false) + const std::vector<float> &taps, + float oversample_rate) + : gr_block ("pfb_channelizer_ccf", + gr_make_io_signature (numchans, numchans, sizeof(gr_complex)), + gr_make_io_signature (1, 1, numchans*sizeof(gr_complex))), + d_updated (false), d_numchans(numchans), d_oversample_rate(oversample_rate) { - d_numchans = numchans; + // The over sampling rate must be rationally related to the number of channels + // in that it must be N/i for i in [1,N], which gives an outputsample rate + // of [fs/N, fs] where fs is the input sample rate. + // This tests the specified input sample rate to see if it conforms to this + // requirement within a few significant figures. + double intp = 0; + double x = (10000.0*rint(numchans / oversample_rate)) / 10000.0; + double fltp = modf(numchans / oversample_rate, &intp); + if(fltp != 0.0) + throw std::invalid_argument("gr_pfb_channelizer: oversample rate must be N/i for i in [1, N]"); + d_filters = std::vector<gr_fir_ccf*>(d_numchans); // Create an FIR filter for each channel and zero out the taps @@ -60,10 +73,28 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans, // Create the FFT to handle the output de-spinning of the channels d_fft = new gri_fft_complex (d_numchans, false); + + // Although the filters change, we use this look up table + // to set the index of the FFT input buffer, which equivalently + // performs the FFT shift operation on every other turn. + d_rate_ratio = (int)rintf(d_numchans / d_oversample_rate); + d_idxlut = new int[d_numchans]; + for(unsigned int i = 0; i < d_numchans; i++) { + d_idxlut[i] = d_numchans - ((i + d_rate_ratio) % d_numchans) - 1; + } + + // Calculate the number of filtering rounds to do to evenly + // align the input vectors with the output channels + d_output_multiple = 1; + while((d_output_multiple * d_rate_ratio) % d_numchans != 0) + d_output_multiple++; + set_output_multiple(d_output_multiple); } gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf () { + delete [] d_idxlut; + for(unsigned int i = 0; i < d_numchans; i++) { delete d_filters[i]; } @@ -101,7 +132,7 @@ gr_pfb_channelizer_ccf::set_taps (const std::vector<float> &taps) } // Set the history to ensure enough input items for each filter - set_history (d_taps_per_filter); + set_history (d_taps_per_filter+1); d_updated = true; } @@ -121,9 +152,10 @@ gr_pfb_channelizer_ccf::print_taps() int -gr_pfb_channelizer_ccf::work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) +gr_pfb_channelizer_ccf::general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) { gr_complex *in = (gr_complex *) input_items[0]; gr_complex *out = (gr_complex *) output_items[0]; @@ -133,20 +165,35 @@ gr_pfb_channelizer_ccf::work (int noutput_items, return 0; // history requirements may have changed. } - for(int i = 0; i < noutput_items; i++) { - // Move through filters from bottom to top - for(int j = d_numchans-1; j >= 0; j--) { - // Take in the items from the first input stream to d_numchans - in = (gr_complex*)input_items[d_numchans - 1 - j]; + int n=1, i=-1, j=0, last; + int toconsume = (int)rintf(noutput_items/d_oversample_rate); + while(n <= toconsume) { + j = 0; + i = (i + d_rate_ratio) % d_numchans; + last = i; + while(i >= 0) { + in = (gr_complex*)input_items[j]; + d_fft->get_inbuf()[d_idxlut[j]] = d_filters[i]->filter(&in[n]); + j++; + i--; + } - // Filter current input stream from bottom filter to top - d_fft->get_inbuf()[j] = d_filters[j]->filter(&in[i]); + i = d_numchans-1; + while(i > last) { + in = (gr_complex*)input_items[j]; + d_fft->get_inbuf()[d_idxlut[j]] = d_filters[i]->filter(&in[n-1]); + j++; + i--; } + n += (i+d_rate_ratio) >= (int)d_numchans; + // despin through FFT d_fft->execute(); - memcpy(&out[d_numchans*i], d_fft->get_outbuf(), d_numchans*sizeof(gr_complex)); + memcpy(out, d_fft->get_outbuf(), d_numchans*sizeof(gr_complex)); + out += d_numchans; } - + + consume_each(toconsume); return noutput_items; } diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.h index b2e67e8173..751673bc7a 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,12 +24,13 @@ #ifndef INCLUDED_GR_PFB_CHANNELIZER_CCF_H #define INCLUDED_GR_PFB_CHANNELIZER_CCF_H -#include <gr_sync_block.h> +#include <gr_block.h> class gr_pfb_channelizer_ccf; typedef boost::shared_ptr<gr_pfb_channelizer_ccf> gr_pfb_channelizer_ccf_sptr; gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps); + const std::vector<float> &taps, + float oversample_rate=1); class gr_fir_ccf; class gri_fft_complex; @@ -88,6 +89,19 @@ class gri_fft_complex; * <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, * attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B> * + * The filter output can also be overs ampled. The over sampling rate + * is the ratio of the the actual output sampling rate to the normal + * output sampling rate. It must be rationally related to the number + * of channels as N/i for i in [1,N], which gives an outputsample rate + * of [fs/N, fs] where fs is the input sample rate and N is the number + * of channels. + * + * For example, for 6 channels with fs = 6000 Hz, the normal rate is + * 6000/6 = 1000 Hz. Allowable oversampling rates are 6/6, 6/5, 6/4, + * 6/3, 6/2, and 6/1 where the output sample rate of a 6/1 oversample + * ratio is 6000 Hz, or 6 times the normal 1000 Hz. A rate of 6/5 = 1.2, + * so the output rate would be 1200 Hz. + * * The theory behind this block can be found in Chapter 6 of * the following book. * @@ -96,31 +110,50 @@ class gri_fft_complex; * */ -class gr_pfb_channelizer_ccf : public gr_sync_block +class gr_pfb_channelizer_ccf : public gr_block { private: /*! * Build the polyphase filterbank decimator. * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM> * \param taps (vector/list of floats) The prototype filter to populate the filterbank. + * \param oversample_rate (float) The over sampling rate is the ratio of the the actual + * output sampling rate to the normal output sampling rate. + * It must be rationally related to the number of channels + * as N/i for i in [1,N], which gives an outputsample rate + * of [fs/N, fs] where fs is the input sample rate and N is + * the number of channels. + * + * For example, for 6 channels with fs = 6000 Hz, the normal + * rate is 6000/6 = 1000 Hz. Allowable oversampling rates + * are 6/6, 6/5, 6/4, 6/3, 6/2, and 6/1 where the output + * sample rate of a 6/1 oversample ratio is 6000 Hz, or + * 6 times the normal 1000 Hz. */ friend gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps); + const std::vector<float> &taps, + float oversample_rate); + bool d_updated; + unsigned int d_numchans; + float d_oversample_rate; std::vector<gr_fir_ccf*> d_filters; std::vector< std::vector<float> > d_taps; - gri_fft_complex *d_fft; - unsigned int d_numchans; unsigned int d_taps_per_filter; - bool d_updated; + gri_fft_complex *d_fft; + int *d_idxlut; + int d_rate_ratio; + int d_output_multiple; /*! * Build the polyphase filterbank decimator. * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM> * \param taps (vector/list of floats) The prototype filter to populate the filterbank. + * \param oversample_rate (float) The output over sampling rate. */ gr_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps); + const std::vector<float> &taps, + float oversample_rate); public: ~gr_pfb_channelizer_ccf (); @@ -136,9 +169,10 @@ public: */ void print_taps(); - int work (int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items); + int general_work (int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; #endif diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.i b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.i index 4bef90e222..63e3e0fe6a 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.i +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,13 +23,15 @@ GR_SWIG_BLOCK_MAGIC(gr,pfb_channelizer_ccf); gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps); + const std::vector<float> &taps, + float oversample_rate=1); -class gr_pfb_channelizer_ccf : public gr_sync_block +class gr_pfb_channelizer_ccf : public gr_block { private: gr_pfb_channelizer_ccf (unsigned int numchans, - const std::vector<float> &taps); + const std::vector<float> &taps, + float oversample_rate); public: ~gr_pfb_channelizer_ccf (); diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h index 70857173bf..4e6ef5fc48 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_ccf.h @@ -43,6 +43,71 @@ class gr_fir_ccf; * * \ingroup filter_blk * + * This block performs timing synchronization for PAM signals by minimizing the + * derivative of the filtered signal, which in turn maximizes the SNR and + * minimizes ISI. + * + * This approach works by setting up two filterbanks; one filterbanke contains the + * signal's pulse shaping matched filter (such as a root raised cosine filter), + * where each branch of the filterbank contains a different phase of the filter. + * The second filterbank contains the derivatives of the filters in the first + * filterbank. Thinking of this in the time domain, the first filterbank contains + * filters that have a sinc shape to them. We want to align the output signal to + * be sampled at exactly the peak of the sinc shape. The derivative of the sinc + * contains a zero at the maximum point of the sinc (sinc(0) = 1, sinc(0)' = 0). + * Furthermore, the region around the zero point is relatively linear. We make + * use of this fact to generate the error signal. + * + * If the signal out of the derivative filters is d_i[n] for the ith filter, and + * the output of the matched filter is x_i[n], we calculate the error as: + * e[n] = (Re{x_i[n]} * Re{d_i[n]} + Im{x_i[n]} * Im{d_i[n]}) / 2.0 + * This equation averages the error in the real and imaginary parts. There are two + * reasons we multiply by the signal itself. First, if the symbol could be positive + * or negative going, but we want the error term to always tell us to go in the + * same direction depending on which side of the zero point we are on. The sign of + * x_i[n] adjusts the error term to do this. Second, the magnitude of x_i[n] scales + * the error term depending on the symbol's amplitude, so larger signals give us + * a stronger error term because we have more confidence in that symbol's value. + * Using the magnitude of x_i[n] instead of just the sign is especially good for + * signals with low SNR. + * + * The error signal, e[n], gives us a value proportional to how far away from the zero + * point we are in the derivative signal. We want to drive this value to zero, so we + * set up a second order loop. We have two variables for this loop; d_k is the filter + * number in the filterbank we are on and d_rate is the rate which we travel through + * the filters in the steady state. That is, due to the natural clock differences between + * the transmitter and receiver, d_rate represents that difference and would traverse + * the filter phase paths to keep the receiver locked. Thinking of this as a second-order + * PLL, the d_rate is the frequency and d_k is the phase. So we update d_rate and d_k + * using the standard loop equations based on two error signals, d_alpha and d_beta. + * We have these two values set based on each other for a critically damped system, so in + * the block constructor, we just ask for "gain," which is d_alpha while d_beta is + * equal to (gain^2)/4. + * + * The clock sync block needs to know the number of samples per second (sps), because it + * only returns a single point representing the sample. The sps can be any positive real + * number and does not need to be an integer. The filter taps must also be specified. The + * taps are generated by first conceiving of the prototype filter that would be the signal's + * matched filter. Then interpolate this by the number of filters in the filterbank. These + * are then distributed among all of the filters. So if the prototype filter was to have + * 45 taps in it, then each path of the filterbank will also have 45 taps. This is easily + * done by building the filter with the sample rate multiplied by the number of filters + * to use. + * + * The number of filters can also be set and defaults to 32. With 32 filters, you get a + * good enough resolution in the phase to produce very small, almost unnoticeable, ISI. + * Going to 64 filters can reduce this more, but after that there is very little gained + * for the extra complexity. + * + * The initial phase is another settable parameter and refers to the filter path the + * algorithm initially looks at (i.e., d_k starts at init_phase). This value defaults + * to zero, but it might be useful to start at a different phase offset, such as the mid- + * point of the filters. + * + * The final parameter is the max_rate_devitation, which defaults to 1.5. This is how far + * we allow d_rate to swing, positive or negative, from 0. Constraining the rate can help + * keep the algorithm from walking too far away to lock during times when there is no signal. + * */ class gr_pfb_clock_sync_ccf : public gr_block @@ -50,6 +115,14 @@ class gr_pfb_clock_sync_ccf : public gr_block private: /*! * Build the polyphase filterbank timing synchronizer. + * \param sps (double) The number of samples per second in the incoming signal + * \param gain (float) The alpha gain of the control loop; beta = (gain^2)/4 by default. + * \param taps (vector<int>) The filter taps. + * \param filter_size (uint) The number of filters in the filterbank (default = 32). + * \param init_phase (float) The initial phase to look at, or which filter to start + * with (default = 0). + * \param max_rate_deviation (float) Distance from 0 d_rate can get (default = 1.5). + * */ friend gr_pfb_clock_sync_ccf_sptr gr_make_pfb_clock_sync_ccf (double sps, float gain, const std::vector<float> &taps, @@ -96,24 +169,46 @@ public: void set_taps (const std::vector<float> &taps, std::vector< std::vector<float> > &ourtaps, std::vector<gr_fir_ccf*> &ourfilter); + + /*! + * Returns the taps of the matched filter + */ std::vector<float> channel_taps(int channel); + + /*! + * Returns the taps in the derivative filter + */ std::vector<float> diff_channel_taps(int channel); /*! * Print all of the filterbank taps to screen. */ void print_taps(); + + /*! + * Print all of the filterbank taps of the derivative filter to screen. + */ void print_diff_taps(); + /*! + * Set the gain value alpha for the control loop + */ void set_alpha(float alpha) { d_alpha = alpha; } + + /*! + * Set the gain value beta for the control loop + */ void set_beta(float beta) { d_beta = beta; } + /*! + * Set the maximum deviation from 0 d_rate can have + */ void set_max_rate_deviation(float m) { d_max_dev = m; diff --git a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_fff.h b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_fff.h index 10eec4f540..fa1279a7cb 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_fff.h +++ b/gnuradio-core/src/lib/filter/gr_pfb_clock_sync_fff.h @@ -43,6 +43,71 @@ class gr_fir_fff; * * \ingroup filter_blk * + * This block performs timing synchronization for PAM signals by minimizing the + * derivative of the filtered signal, which in turn maximizes the SNR and + * minimizes ISI. + * + * This approach works by setting up two filterbanks; one filterbanke contains the + * signal's pulse shaping matched filter (such as a root raised cosine filter), + * where each branch of the filterbank contains a different phase of the filter. + * The second filterbank contains the derivatives of the filters in the first + * filterbank. Thinking of this in the time domain, the first filterbank contains + * filters that have a sinc shape to them. We want to align the output signal to + * be sampled at exactly the peak of the sinc shape. The derivative of the sinc + * contains a zero at the maximum point of the sinc (sinc(0) = 1, sinc(0)' = 0). + * Furthermore, the region around the zero point is relatively linear. We make + * use of this fact to generate the error signal. + * + * If the signal out of the derivative filters is d_i[n] for the ith filter, and + * the output of the matched filter is x_i[n], we calculate the error as: + * e[n] = (Re{x_i[n]} * Re{d_i[n]} + Im{x_i[n]} * Im{d_i[n]}) / 2.0 + * This equation averages the error in the real and imaginary parts. There are two + * reasons we multiply by the signal itself. First, if the symbol could be positive + * or negative going, but we want the error term to always tell us to go in the + * same direction depending on which side of the zero point we are on. The sign of + * x_i[n] adjusts the error term to do this. Second, the magnitude of x_i[n] scales + * the error term depending on the symbol's amplitude, so larger signals give us + * a stronger error term because we have more confidence in that symbol's value. + * Using the magnitude of x_i[n] instead of just the sign is especially good for + * signals with low SNR. + * + * The error signal, e[n], gives us a value proportional to how far away from the zero + * point we are in the derivative signal. We want to drive this value to zero, so we + * set up a second order loop. We have two variables for this loop; d_k is the filter + * number in the filterbank we are on and d_rate is the rate which we travel through + * the filters in the steady state. That is, due to the natural clock differences between + * the transmitter and receiver, d_rate represents that difference and would traverse + * the filter phase paths to keep the receiver locked. Thinking of this as a second-order + * PLL, the d_rate is the frequency and d_k is the phase. So we update d_rate and d_k + * using the standard loop equations based on two error signals, d_alpha and d_beta. + * We have these two values set based on each other for a critically damped system, so in + * the block constructor, we just ask for "gain," which is d_alpha while d_beta is + * equal to (gain^2)/4. + * + * The clock sync block needs to know the number of samples per second (sps), because it + * only returns a single point representing the sample. The sps can be any positive real + * number and does not need to be an integer. The filter taps must also be specified. The + * taps are generated by first conceiving of the prototype filter that would be the signal's + * matched filter. Then interpolate this by the number of filters in the filterbank. These + * are then distributed among all of the filters. So if the prototype filter was to have + * 45 taps in it, then each path of the filterbank will also have 45 taps. This is easily + * done by building the filter with the sample rate multiplied by the number of filters + * to use. + * + * The number of filters can also be set and defaults to 32. With 32 filters, you get a + * good enough resolution in the phase to produce very small, almost unnoticeable, ISI. + * Going to 64 filters can reduce this more, but after that there is very little gained + * for the extra complexity. + * + * The initial phase is another settable parameter and refers to the filter path the + * algorithm initially looks at (i.e., d_k starts at init_phase). This value defaults + * to zero, but it might be useful to start at a different phase offset, such as the mid- + * point of the filters. + * + * The final parameter is the max_rate_devitation, which defaults to 1.5. This is how far + * we allow d_rate to swing, positive or negative, from 0. Constraining the rate can help + * keep the algorithm from walking too far away to lock during times when there is no signal. + * */ class gr_pfb_clock_sync_fff : public gr_block @@ -50,6 +115,14 @@ class gr_pfb_clock_sync_fff : public gr_block private: /*! * Build the polyphase filterbank timing synchronizer. + * \param sps (double) The number of samples per second in the incoming signal + * \param gain (float) The alpha gain of the control loop; beta = (gain^2)/4 by default. + * \param taps (vector<int>) The filter taps. + * \param filter_size (uint) The number of filters in the filterbank (default = 32). + * \param init_phase (float) The initial phase to look at, or which filter to start + * with (default = 0). + * \param max_rate_deviation (float) Distance from 0 d_rate can get (default = 1.5). + * */ friend gr_pfb_clock_sync_fff_sptr gr_make_pfb_clock_sync_fff (double sps, float gain, const std::vector<float> &taps, @@ -96,24 +169,46 @@ public: void set_taps (const std::vector<float> &taps, std::vector< std::vector<float> > &ourtaps, std::vector<gr_fir_fff*> &ourfilter); + + /*! + * Returns the taps of the matched filter + */ std::vector<float> channel_taps(int channel); + + /*! + * Returns the taps in the derivative filter + */ std::vector<float> diff_channel_taps(int channel); /*! * Print all of the filterbank taps to screen. */ void print_taps(); + + /*! + * Print all of the filterbank taps of the derivative filter to screen. + */ void print_diff_taps(); + /*! + * Set the gain value alpha for the control loop + */ void set_alpha(float alpha) { d_alpha = alpha; } + + /*! + * Set the gain value beta for the control loop + */ void set_beta(float beta) { d_beta = beta; } + /*! + * Set the maximum deviation from 0 d_rate can have + */ void set_max_rate_deviation(float m) { d_max_dev = m; diff --git a/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h index 178e18f3e8..db060793e1 100644 --- a/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h +++ b/gnuradio-core/src/lib/general/gr_fll_band_edge_cc.h @@ -48,12 +48,12 @@ class gri_fft_complex; * * The FLL works by filtering the upper and lower band edges into x_u(t) and x_l(t), respectively. * These are combined to form cc(t) = x_u(t) + x_l(t) and ss(t) = x_u(t) - x_l(t). Combining - * these to form the signal e(t) = Re{cc(t) \times ss(t)^*} (where ^* is the complex conjugate) + * these to form the signal e(t) = Re{cc(t) \\times ss(t)^*} (where ^* is the complex conjugate) * provides an error signal at the DC term that is directly proportional to the carrier frequency. * We then make a second-order loop using the error signal that is the running average of e(t). * * In theory, the band-edge filter is the derivative of the matched filter in frequency, - * (H_be(f) = \frac{H(f)}{df}. In practice, this comes down to a quarter sine wave at the point + * (H_be(f) = \\frac{H(f)}{df}. In practice, this comes down to a quarter sine wave at the point * of the matched filter's rolloff (if it's a raised-cosine, the derivative of a cosine is a sine). * Extend this sine by another quarter wave to make a half wave around the band-edges is equivalent * in time to the sum of two sinc functions. The baseband filter fot the band edges is therefore @@ -93,7 +93,11 @@ class gr_fll_band_edge_cc : public gr_sync_block /*! * Build the FLL - * \param taps (vector/list of gr_complex) The taps of the band-edge filter + * \param samps_per_sym (float) number of samples per symbol + * \param rolloff (float) Rolloff (excess bandwidth) of signal filter + * \param filter_size (int) number of filter taps to generate + * \param alpha (float) Alpha gain in the control loop + * \param beta (float) Beta gain in the control loop */ gr_fll_band_edge_cc(float samps_per_sym, float rolloff, int filter_size, float alpha, float beta); diff --git a/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc b/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc index 74bd65a50a..7f6b2b01c9 100644 --- a/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc +++ b/gnuradio-core/src/lib/general/gr_ofdm_sampler.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -45,6 +45,7 @@ gr_ofdm_sampler::gr_ofdm_sampler (unsigned int fft_length, gr_make_io_signature2 (2, 2, sizeof (gr_complex)*fft_length, sizeof(char)*fft_length)), d_state(STATE_NO_SIG), d_timeout_max(timeout), d_fft_length(fft_length), d_symbol_length(symbol_length) { + set_relative_rate(1.0/(double) fft_length); // buffer allocator hint } void diff --git a/gnuradio-core/src/lib/io/Makefile.am b/gnuradio-core/src/lib/io/Makefile.am index 9eacd137d9..c525546457 100644 --- a/gnuradio-core/src/lib/io/Makefile.am +++ b/gnuradio-core/src/lib/io/Makefile.am @@ -39,7 +39,6 @@ libio_la_SOURCES = \ gr_oscope_guts.cc \ gr_oscope_sink_f.cc \ gr_oscope_sink_x.cc \ - gri_logger.cc \ i2c.cc \ i2c_bitbang.cc \ i2c_bbio.cc \ @@ -72,7 +71,6 @@ grinclude_HEADERS = \ gr_oscope_sink_f.h \ gr_oscope_sink_x.h \ gr_trigger_mode.h \ - gri_logger.h \ i2c.h \ i2c_bitbang.h \ i2c_bbio.h \ diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc deleted file mode 100644 index 473a7c5edc..0000000000 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#if 0 // This needs reimplementation with boost threads and synchronization - -#include <gri_logger.h> -#include <stdio.h> -#include <stdarg.h> -#include <stdexcept> -#include <boost/weak_ptr.hpp> -#include <string.h> - - -/* - * This class creates the thread that reads from the ringbuffer and - * and writes to the file. This is opaque to the user. - */ -class gri_log_poster : public omni_thread -{ - FILE *d_fp; - gr_buffer_sptr d_writer; - gr_buffer_reader_sptr d_reader; - omni_semaphore d_ringbuffer_ready; - volatile bool d_time_to_die; - volatile bool d_writer_overrun; - - virtual void* run_undetached(void * arg); - -public: - gri_log_poster(const char *filename); - ~gri_log_poster(); - - void kill() { d_time_to_die = true; post(); } - gr_buffer_sptr writer() const { return d_writer; } - void post() { d_ringbuffer_ready.post(); } - void note_writer_overrun() { d_writer_overrun = true; } -}; - -gri_log_poster::gri_log_poster(const char *filename) - : omni_thread(), - d_ringbuffer_ready(1, 1), // binary semaphore - d_time_to_die(false), - d_writer_overrun(false) -{ - if ((d_fp = fopen(filename, "w")) == 0){ - perror (filename); - throw std::runtime_error("can't open file"); - } - - // Create a 1MB buffer. - d_writer = gr_make_buffer(1 * 1024 * 1024, sizeof(unsigned char)); - d_reader = gr_buffer_add_reader(d_writer, 0); - - start_undetached(); // start the thread -} - -gri_log_poster::~gri_log_poster() -{ - if (d_fp != 0){ - fclose(d_fp); - d_fp = 0; - } -} - -/* - * This is the body of the logging thread. - */ -void * -gri_log_poster::run_undetached(void *arg) -{ - int nbytes; - - //fprintf(stderr, "Enter: run_undetached!\n"); - - while (!d_time_to_die){ - while ((nbytes = d_reader->items_available()) > 0){ - fwrite(d_reader->read_pointer(), 1, nbytes, d_fp); - d_reader->update_read_pointer(nbytes); - } - fflush(d_fp); - d_ringbuffer_ready.wait(); - - if (d_writer_overrun){ - fputs(">>>>> gri_logger: writer overrun. Info lost <<<<<\n", d_fp); - d_writer_overrun = false; - } - } - - // fprintf(stderr, "Exit: run_undetached!\n"); - return 0; -} - -// ------------------------------------------------------------------------ - -static boost::weak_ptr<gri_logger> s_singleton; // weak pointer IQ test ;-) -static omni_mutex s_singleton_mutex; - -gri_logger_sptr -gri_logger::singleton() -{ - omni_mutex_lock l(s_singleton_mutex); - gri_logger_sptr r; - - if (r = s_singleton.lock()) - return r; - - r = gri_logger_sptr(new gri_logger("gri_logger.log")); - s_singleton = r; - return r; -} - - -gri_logger::gri_logger(const char *filename) -{ - d_poster = new gri_log_poster(filename); -} - -gri_logger::~gri_logger() -{ - d_poster->kill(); - d_poster->join(NULL); -} - -void -gri_logger::write(const void *buf, size_t count) -{ - omni_mutex_lock l(d_write_mutex); - gr_buffer_sptr writer = d_poster->writer(); - - // either write it all, or drop it on the ground - if (count <= (size_t) writer->space_available()){ - memcpy(writer->write_pointer(), buf, count); - writer->update_write_pointer(count); - d_poster->post(); - } - else { - d_poster->note_writer_overrun(); - } -} - -void -gri_logger::printf(const char *format, ...) -{ - va_list ap; - char buf[4096]; - int n; - - va_start(ap, format); - n = vsnprintf(buf, sizeof(buf), format, ap); - va_end(ap); - if (n > -1 && n < (ssize_t) sizeof(buf)) - write(buf, n); -} - -#endif diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h deleted file mode 100644 index 0a1414540f..0000000000 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_GRI_LOGGER_H -#define INCLUDED_GRI_LOGGER_H - -#if 0 // This needs reimplementation with boost threads and synchronization - -#include <stddef.h> -#include <gnuradio/omnithread.h> -#include <gr_buffer.h> - -class gri_log_poster; -class gri_logger; -typedef boost::shared_ptr<gri_logger> gri_logger_sptr; - - -/*! - * \brief non-blocking logging to a file. - * - * In reality, this may block, but only for a bounded time. - * Trust me, it's safe to use from portaudio and JACK callbacks. - */ -class gri_logger -{ - gri_log_poster *d_poster; - omni_mutex d_write_mutex; - -public: - static gri_logger_sptr singleton(); - - gri_logger(const char *filename); - ~gri_logger(); - - void write(const void *buf, size_t count); - void printf(const char *format, ...); -}; - -#endif - -#endif /* INCLUDED_GRI_LOGGER_H */ diff --git a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py index c45ae4d1a9..a479ed48ea 100644 --- a/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py +++ b/gnuradio-core/src/python/gnuradio/blks2impl/pfb_channelizer.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2009 Free Software Foundation, Inc. +# Copyright 2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -29,16 +29,18 @@ class pfb_channelizer_ccf(gr.hier_block2): This simplifies the interface by allowing a single input stream to connect to this block. It will then output a stream for each channel. ''' - def __init__(self, numchans, taps): + def __init__(self, numchans, taps, oversample_rate=1): gr.hier_block2.__init__(self, "pfb_channelizer_ccf", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(numchans, numchans, gr.sizeof_gr_complex)) # Output signature self._numchans = numchans self._taps = taps + self._oversample_rate = oversample_rate self.s2ss = gr.stream_to_streams(gr.sizeof_gr_complex, self._numchans) - self.pfb = gr.pfb_channelizer_ccf(self._numchans, self._taps) + self.pfb = gr.pfb_channelizer_ccf(self._numchans, self._taps, + self._oversample_rate) self.v2s = gr.vector_to_streams(gr.sizeof_gr_complex, self._numchans) self.connect(self, self.s2ss) diff --git a/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py b/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py index 8d46e8192f..f2808c4489 100644 --- a/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py +++ b/gnuradio-core/src/python/gnuradio/gruimpl/hexint.py @@ -30,3 +30,15 @@ def hexint(mask): if mask >= 2**31: return int(mask-2**32) return mask + +def hexshort(mask): + """ + Convert unsigned masks into signed shorts. + + This allows us to use hex constants like 0x8000 when talking to + our hardware and not get screwed by them getting treated as python + longs. + """ + if mask >= 2**15: + return int(mask-2**16) + return mask diff --git a/gnuradio-examples/python/pfb/channelize.py b/gnuradio-examples/python/pfb/channelize.py index bc83fae273..27d87e558b 100755 --- a/gnuradio-examples/python/pfb/channelize.py +++ b/gnuradio-examples/python/pfb/channelize.py @@ -101,7 +101,7 @@ def main(): X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs, window = lambda d: d*winfunc(fftlen), scale_by_freq=True) - X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X))) + X_in = 10.0*scipy.log10(abs(X)) f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(X_in.size)) pin_f = spin_f.plot(f_in, X_in, "b") spin_f.set_xlim([min(f_in), max(f_in)+1]) @@ -144,7 +144,7 @@ def main(): X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen/4, Fs=fs_o, window = lambda d: d*winfunc(fftlen), scale_by_freq=True) - X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X))) + X_o = 10.0*scipy.log10(abs(X)) f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(X_o.size)) p2_f = sp1_f.plot(f_o, X_o, "b") sp1_f.set_xlim([min(f_o), max(f_o)+1]) diff --git a/gr-audio-osx/src/Makefile.am b/gr-audio-osx/src/Makefile.am index 6099dc20b6..5bf28b8e7e 100644 --- a/gr-audio-osx/src/Makefile.am +++ b/gr-audio-osx/src/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2006,2008,2009 Free Software Foundation, Inc. +# Copyright 2006,2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio. # @@ -32,8 +32,7 @@ grinclude_HEADERS = \ noinst_HEADERS = \ audio_osx.h \ - circular_buffer.h \ - mld_threads.h + circular_buffer.h noinst_PYTHON = \ qa_osx.py \ @@ -46,8 +45,7 @@ libgnuradio_audio_osx_la_SOURCES = \ audio_osx_source.cc libgnuradio_audio_osx_la_LIBADD = \ - $(GNURADIO_CORE_LA) \ - $(OMNITHREAD_LA) + $(GNURADIO_CORE_LA) libgnuradio_audio_osx_la_LDFLAGS = \ -framework AudioUnit \ diff --git a/gr-audio-osx/src/audio_osx_sink.cc b/gr-audio-osx/src/audio_osx_sink.cc index e91716c0ac..20fd895b98 100644 --- a/gr-audio-osx/src/audio_osx_sink.cc +++ b/gr-audio-osx/src/audio_osx_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -24,8 +24,6 @@ #include "config.h" #endif -#define _USE_OMNI_THREADS_ - #include <audio_osx_sink.h> #include <gr_io_signature.h> #include <stdexcept> @@ -172,11 +170,15 @@ audio_osx_sink::audio_osx_sink (int sample_rate, // create the stuff to regulate I/O - d_cond_data = new mld_condition (); + d_cond_data = new gruel::condition_variable (); if (d_cond_data == NULL) - CheckErrorAndThrow (errno, "new mld_condition (data)", - "audio_osx_source::audio_osx_source"); - d_internal = d_cond_data->mutex (); + CheckErrorAndThrow (errno, "new condition (data)", + "audio_osx_sink::audio_osx_sink"); + + d_internal = new gruel::mutex (); + if (d_internal == NULL) + CheckErrorAndThrow (errno, "new mutex (internal)", + "audio_osx_sink::audio_osx_sink"); // initialize the AU for output @@ -253,6 +255,9 @@ audio_osx_sink::~audio_osx_sink () // close and delete control stuff delete d_cond_data; + d_cond_data = 0; + delete d_internal; + d_internal = 0; } audio_osx_sink_sptr @@ -274,7 +279,7 @@ audio_osx_sink::work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); /* take the input data, copy it, and push it to the bottom of the queue mono input are pushed onto queue[0]; @@ -307,8 +312,8 @@ audio_osx_sink::work (int noutput_items, while (d_queueSampleCount > l_max_count) { // release control so-as to allow data to be retrieved; // block until there is data to return - d_cond_data->wait (); -// the condition's signal() was called; acquire control + d_cond_data->wait (l); +// the condition's 'notify' was called; acquire control // to keep thread safe } } @@ -353,9 +358,6 @@ audio_osx_sink::work (int noutput_items, << d_queueSampleCount << ", mSC = " << d_max_sample_count << std::endl; #endif -// release control to allow for other processing parts to run - d_internal->unlock (); - return (noutput_items); } @@ -370,7 +372,7 @@ OSStatus audio_osx_sink::AUOutputCallback audio_osx_sink* This = (audio_osx_sink*) inRefCon; OSStatus err = noErr; - This->d_internal->lock (); + gruel::scoped_lock l (*This->d_internal); #if _OSX_AU_DEBUG_ std::cerr << "cb_in: SC = " << This->d_queueSampleCount @@ -403,10 +405,7 @@ OSStatus audio_osx_sink::AUOutputCallback #endif // signal that data is available - This->d_cond_data->signal (); - -// release control to allow for other processing parts to run - This->d_internal->unlock (); + This->d_cond_data->notify_one (); return (err); } diff --git a/gr-audio-osx/src/audio_osx_sink.h b/gr-audio-osx/src/audio_osx_sink.h index ceb291d0fb..a1a56502cb 100644 --- a/gr-audio-osx/src/audio_osx_sink.h +++ b/gr-audio-osx/src/audio_osx_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -59,8 +59,8 @@ class audio_osx_sink : public gr_sync_block { UInt32 d_n_channels; UInt32 d_queueSampleCount, d_max_sample_count; bool d_do_block; - mld_mutex_ptr d_internal; - mld_condition_ptr d_cond_data; + gruel::mutex* d_internal; + gruel::condition_variable* d_cond_data; circular_buffer<float>** d_buffers; // AudioUnits and Such diff --git a/gr-audio-osx/src/audio_osx_source.cc b/gr-audio-osx/src/audio_osx_source.cc index 61838745b5..538cfd8f69 100644 --- a/gr-audio-osx/src/audio_osx_source.cc +++ b/gr-audio-osx/src/audio_osx_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -24,8 +24,6 @@ #include "config.h" #endif -#define _USE_OMNI_THREADS_ - #include <audio_osx_source.h> #include <gr_io_signature.h> #include <stdexcept> @@ -446,11 +444,15 @@ audio_osx_source::audio_osx_source (int sample_rate, // create the stuff to regulate I/O - d_cond_data = new mld_condition (); + d_cond_data = new gruel::condition_variable (); if (d_cond_data == NULL) - CheckErrorAndThrow (errno, "new mld_condition (data)", + CheckErrorAndThrow (errno, "new condition (data)", + "audio_osx_source::audio_osx_source"); + + d_internal = new gruel::mutex (); + if (d_internal == NULL) + CheckErrorAndThrow (errno, "new mutex (internal)", "audio_osx_source::audio_osx_source"); - d_internal = d_cond_data->mutex (); // initialize the AU for input @@ -600,6 +602,9 @@ audio_osx_source::~audio_osx_source () // close and delete the control stuff delete d_cond_data; + d_cond_data = 0; + delete d_internal; + d_internal = 0; } audio_osx_source_sptr @@ -654,7 +659,7 @@ audio_osx_source::work gr_vector_void_star &output_items) { // acquire control to do processing here only - d_internal->lock (); + gruel::scoped_lock l (*d_internal); #if _OSX_AU_DEBUG_ std::cerr << "work1: SC = " << d_queueSampleCount @@ -677,14 +682,12 @@ audio_osx_source::work while (d_queueSampleCount == 0) { // release control so-as to allow data to be retrieved; // block until there is data to return - d_cond_data->wait (); - // the condition's signal() was called; acquire control to + d_cond_data->wait (l); + // the condition's 'notify' was called; acquire control to // keep thread safe } } else { // no data & not blocking; return nothing - // release control so-as to allow data to be retrieved - d_internal->unlock (); return (0); } } @@ -718,15 +721,8 @@ audio_osx_source::work #if _OSX_AU_DEBUG_ std::cerr << "work2: SC = " << d_queueSampleCount - << ", act#OI = " << actual_noutput_items << std::endl; -#endif - - // release control to allow for other processing parts to run - - d_internal->unlock (); - -#if _OSX_AU_DEBUG_ - std::cerr << "work3: Returning." << std::endl; + << ", act#OI = " << actual_noutput_items << std::endl + << "Returning." << std::endl; #endif return (actual_noutput_items); @@ -782,7 +778,7 @@ audio_osx_source::AUInputCallback (void* inRefCon, OSStatus err = noErr; audio_osx_source* This = static_cast<audio_osx_source*>(inRefCon); - This->d_internal->lock (); + gruel::scoped_lock l (*This->d_internal); #if _OSX_AU_DEBUG_ std::cerr << "cb0: in#F = " << inNumberFrames @@ -911,17 +907,10 @@ audio_osx_source::AUInputCallback (void* inRefCon, #endif // signal that data is available, if appropraite - This->d_cond_data->signal (); - -#if _OSX_AU_DEBUG_ - std::cerr << "cb5: releasing internal mutex." << std::endl; -#endif - -// release control to allow for other processing parts to run - This->d_internal->unlock (); + This->d_cond_data->notify_one (); #if _OSX_AU_DEBUG_ - std::cerr << "cb6: returning." << std::endl; + std::cerr << "cb5: returning." << std::endl; #endif return (err); diff --git a/gr-audio-osx/src/audio_osx_source.h b/gr-audio-osx/src/audio_osx_source.h index 780f7ec6b8..e8df47b16f 100644 --- a/gr-audio-osx/src/audio_osx_source.h +++ b/gr-audio-osx/src/audio_osx_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -66,8 +66,8 @@ class audio_osx_source : public gr_sync_block { UInt32 d_n_AvailableInputFrames, d_n_ActualInputFrames; UInt32 d_n_user_channels, d_n_max_channels, d_n_deviceChannels; bool d_do_block, d_passThrough, d_waiting_for_data; - mld_mutex_ptr d_internal; - mld_condition_ptr d_cond_data; + gruel::mutex* d_internal; + gruel::condition_variable* d_cond_data; circular_buffer<float>** d_buffers; // AudioUnits and Such diff --git a/gr-audio-osx/src/circular_buffer.h b/gr-audio-osx/src/circular_buffer.h index 6d491fb6f0..48758bf878 100644 --- a/gr-audio-osx/src/circular_buffer.h +++ b/gr-audio-osx/src/circular_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -23,7 +23,7 @@ #ifndef _CIRCULAR_BUFFER_H_ #define _CIRCULAR_BUFFER_H_ -#include "mld_threads.h" +#include <gruel/thread.h> #include <iostream> #include <stdexcept> @@ -37,7 +37,8 @@ #define DEBUG(X) do{} while(0); #endif -template <class T> class circular_buffer +template <class T> +class circular_buffer { private: // the buffer to use @@ -48,8 +49,9 @@ private: size_t d_n_avail_write_I, d_n_avail_read_I; // stuff to control access to class internals - mld_mutex_ptr d_internal; - mld_condition_ptr d_readBlock, d_writeBlock; + gruel::mutex* d_internal; + gruel::condition_variable* d_readBlock; + gruel::condition_variable* d_writeBlock; // booleans to decide how to control reading, writing, and aborting bool d_doWriteBlock, d_doFullRead, d_doAbort; @@ -94,16 +96,14 @@ public: }; inline size_t n_avail_write_items () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); size_t retVal = d_n_avail_write_I; - d_internal->unlock (); return (retVal); }; inline size_t n_avail_read_items () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); size_t retVal = d_n_avail_read_I; - d_internal->unlock (); return (retVal); }; @@ -120,13 +120,13 @@ public: // create a mutex to handle contention of shared resources; // any routine needed access to shared resources uses lock() // before doing anything, then unlock() when finished. - d_internal = new mld_mutex (); + d_internal = new gruel::mutex (); // link the internal mutex to the read and write conditions; // when wait() is called, the internal mutex will automatically - // be unlock()'ed. Upon return (from a signal() to the condition), + // be unlock()'ed. Upon return (from a notify_one() to the condition), // the internal mutex will be lock()'ed. - d_readBlock = new mld_condition (d_internal); - d_writeBlock = new mld_condition (d_internal); + d_readBlock = new gruel::condition_variable (); + d_writeBlock = new gruel::condition_variable (); }; /* @@ -167,9 +167,8 @@ public: if (!buf) throw std::runtime_error ("circular_buffer::enqueue(): " "input buffer is NULL.\n"); - d_internal->lock (); + gruel::scoped_lock l (*d_internal); if (d_doAbort) { - d_internal->unlock (); return (2); } // set the return value to 1: success; change if needed @@ -178,11 +177,11 @@ public: if (d_doWriteBlock) { while (bufLen_I > d_n_avail_write_I) { DEBUG (std::cerr << "enqueue: #len > #a, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_writeBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_writeBlock->wait (l); + // and auto re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "enqueue: #len > #a, aborting." << std::endl); return (2); } @@ -208,8 +207,7 @@ public: d_writeNdx_I += n_now_I; d_n_avail_read_I += bufLen_I; d_n_avail_write_I -= bufLen_I; - d_readBlock->signal (); - d_internal->unlock (); + d_readBlock->notify_one (); return (retval); }; @@ -255,19 +253,18 @@ public: throw std::runtime_error ("circular_buffer::dequeue()"); } - d_internal->lock (); + gruel::scoped_lock l (*d_internal); if (d_doAbort) { - d_internal->unlock (); return (2); } if (d_doFullRead) { while (d_n_avail_read_I < l_bufLen_I) { DEBUG (std::cerr << "dequeue: #a < #len, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_readBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_readBlock->wait (l); + // and re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "dequeue: #a < #len, aborting." << std::endl); return (2); } @@ -276,11 +273,11 @@ public: } else { while (d_n_avail_read_I == 0) { DEBUG (std::cerr << "dequeue: #a == 0, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_readBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_readBlock->wait (l); + // and re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "dequeue: #a == 0, aborting." << std::endl); return (2); } @@ -303,17 +300,15 @@ public: *bufLen_I = l_bufLen_I; d_n_avail_read_I -= l_bufLen_I; d_n_avail_write_I += l_bufLen_I; - d_writeBlock->signal (); - d_internal->unlock (); + d_writeBlock->notify_one (); return (1); }; void abort () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); d_doAbort = true; - d_writeBlock->signal (); - d_readBlock->signal (); - d_internal->unlock (); + d_writeBlock->notify_one (); + d_readBlock->notify_one (); }; }; diff --git a/gr-audio-osx/src/mld_threads.h b/gr-audio-osx/src/mld_threads.h deleted file mode 100644 index d2fb4ea7c0..0000000000 --- a/gr-audio-osx/src/mld_threads.h +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio. - * - * Primary Author: Michael Dickens, NCIP Lab, University of Notre Dame - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _INCLUDED_MLD_THREADS_H_ -#define _INCLUDED_MLD_THREADS_H_ - -/* classes which allow for either pthreads or omni_threads */ - -#define __macos__ -#ifdef _USE_OMNI_THREADS_ -#include <gnuradio/omnithread.h> -#else -#include <pthread.h> -#endif - -#include <stdexcept> - -#define __INLINE__ inline -#define DO_DEBUG 0 - -#if DO_DEBUG -#define DEBUG(X) do{X} while(0); -#else -#define DEBUG(X) do{} while(0); -#endif - -class mld_condition_t; - -class mld_mutex_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_mutex l_mutex, *l_mutex_ptr; -#else - typedef pthread_mutex_t l_mutex, *l_mutex_ptr; -#endif - - friend class mld_condition_t; - -private: - l_mutex_ptr d_mutex; - -protected: - inline l_mutex_ptr mutex () { return (d_mutex); }; - -public: - __INLINE__ mld_mutex_t () { -#ifdef _USE_OMNI_THREADS_ - d_mutex = new omni_mutex (); -#else - d_mutex = (l_mutex_ptr) new l_mutex; - int l_ret = pthread_mutex_init (d_mutex, NULL); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating mutex.\n", l_ret); - throw std::runtime_error ("mld_mutex_t::mld_mutex_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_mutex_t () { - unlock (); -#ifndef _USE_OMNI_THREADS_ - int l_ret = pthread_mutex_destroy (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::~mld_mutex_t(): " - "Error %d destroying mutex.\n", l_ret); - } -#endif - delete d_mutex; - d_mutex = NULL; - }; - - __INLINE__ void lock () { -#ifdef _USE_OMNI_THREADS_ - d_mutex->lock (); -#else - int l_ret = pthread_mutex_lock (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::lock(): " - "Error %d locking mutex.\n", l_ret); - } -#endif - }; - - __INLINE__ void unlock () { -#ifdef _USE_OMNI_THREADS_ - d_mutex->unlock (); -#else - int l_ret = pthread_mutex_unlock (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::unlock(): " - "Error %d locking mutex.\n", l_ret); - } -#endif - }; - - __INLINE__ bool trylock () { -#ifdef _USE_OMNI_THREADS_ - int l_ret = d_mutex->trylock (); -#else - int l_ret = pthread_mutex_unlock (d_mutex); -#endif - return (l_ret == 0 ? true : false); - }; - - inline void acquire () { lock(); }; - inline void release () { unlock(); }; - inline void wait () { lock(); }; - inline void post () { unlock(); }; -}; - -typedef mld_mutex_t mld_mutex, *mld_mutex_ptr; - -class mld_condition_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_condition l_condition, *l_condition_ptr; -#else - typedef pthread_cond_t l_condition, *l_condition_ptr; -#endif - -private: - l_condition_ptr d_condition; - mld_mutex_ptr d_mutex; - bool d_i_own_mutex; - -public: - __INLINE__ mld_condition_t (mld_mutex_ptr mutex = NULL) { - if (mutex) { - d_i_own_mutex = false; - d_mutex = mutex; - } else { - d_i_own_mutex = true; - d_mutex = new mld_mutex (); - } -#ifdef _USE_OMNI_THREADS_ - d_condition = new omni_condition (d_mutex->mutex ()); -#else - d_condition = (l_condition_ptr) new l_condition; - int l_ret = pthread_cond_init (d_condition, NULL); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating condition.\n", l_ret); - throw std::runtime_error ("mld_condition_t::mld_condition_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_condition_t () { - signal (); -#ifndef _USE_OMNI_THREADS_ - int l_ret = pthread_cond_destroy (d_condition); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::mld_condition_t(): " - "Error %d destroying condition.\n", l_ret); - } -#endif - delete d_condition; - d_condition = NULL; - if (d_i_own_mutex) - delete d_mutex; - d_mutex = NULL; - }; - - __INLINE__ mld_mutex_ptr mutex () {return (d_mutex);}; - - __INLINE__ void signal () { - DEBUG (fprintf (stderr, "a ")); - -#ifdef _USE_OMNI_THREADS_ - d_condition->signal (); -#else - int l_ret = pthread_cond_signal (d_condition); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::signal(): " - "Error %d.\n", l_ret); - } -#endif - DEBUG (fprintf (stderr, "b ")); - }; - - __INLINE__ void wait () { - DEBUG (fprintf (stderr, "c ")); -#ifdef _USE_OMNI_THREADS_ - d_condition->wait (); -#else - int l_ret = pthread_cond_wait (d_condition, d_mutex->mutex ()); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::wait(): " - "Error %d.\n", l_ret); - } -#endif - DEBUG (printf (stderr, "d ")); - }; -}; - -typedef mld_condition_t mld_condition, *mld_condition_ptr; - -class mld_thread_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_thread l_thread, *l_thread_ptr; -#else - typedef pthread_t l_thread, *l_thread_ptr; -#endif - -private: -#ifndef _USE_OMNI_THREADS_ - l_thread d_thread; - void (*d_start_routine)(void*); - void *d_arg; -#else - l_thread_ptr d_thread; -#endif - -#ifndef _USE_OMNI_THREADS_ - static void* local_start_routine (void *arg) { - mld_thread_t* This = (mld_thread_t*) arg; - (*(This->d_start_routine))(This->d_arg); - return (NULL); - }; -#endif - -public: - __INLINE__ mld_thread_t (void (*start_routine)(void *), void *arg) { -#ifdef _USE_OMNI_THREADS_ - d_thread = new omni_thread (start_routine, arg); - d_thread->start (); -#else - d_start_routine = start_routine; - d_arg = arg; - int l_ret = pthread_create (&d_thread, NULL, local_start_routine, this); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating thread.\n", l_ret); - throw std::runtime_error ("mld_thread_t::mld_thread_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_thread_t () { -#ifdef _USE_OMNI_THREADS_ -// delete d_thread; - d_thread = NULL; -#else - int l_ret = pthread_detach (d_thread); - if (l_ret != 0) { - fprintf (stderr, "Error %d detaching thread.\n", l_ret); - throw std::runtime_error ("mld_thread_t::~mld_thread_t()\n"); - } -#endif - }; -}; - -typedef mld_thread_t mld_thread, *mld_thread_ptr; - -#endif /* _INCLUDED_MLD_THREADS_H_ */ diff --git a/gr-audio-portaudio/src/Makefile.am b/gr-audio-portaudio/src/Makefile.am index 20213d16b5..1df6bbceaf 100644 --- a/gr-audio-portaudio/src/Makefile.am +++ b/gr-audio-portaudio/src/Makefile.am @@ -46,7 +46,6 @@ libgnuradio_audio_portaudio_la_SOURCES = \ libgnuradio_audio_portaudio_la_LIBADD = \ $(GNURADIO_CORE_LA) \ - $(OMNITHREAD_LA) \ $(PORTAUDIO_LIBS) libgnuradio_audio_portaudio_la_LDFLAGS = \ diff --git a/gr-audio-portaudio/src/audio_portaudio_sink.cc b/gr-audio-portaudio/src/audio_portaudio_sink.cc index 2e48feb4af..65a38f9119 100644 --- a/gr-audio-portaudio/src/audio_portaudio_sink.cc +++ b/gr-audio-portaudio/src/audio_portaudio_sink.cc @@ -32,7 +32,6 @@ #include <unistd.h> #include <stdexcept> #include <gri_portaudio.h> -#include <gnuradio/omnithread.h> #include <string.h> //#define LOGGING 0 // define to 0 or 1 @@ -84,31 +83,33 @@ portaudio_sink_callback (const void *inputBuffer, int navail_samples = self->d_reader->items_available(); - if (nreqd_samples <= navail_samples){ // We've got enough data... - //if (LOGGING) - // self->d_log->printf("PAsink cb: f/b = %4ld\n", framesPerBuffer); - // copy from ringbuffer into output buffer - memcpy(outputBuffer, - self->d_reader->read_pointer(), - nreqd_samples * sizeof(sample_t)); - self->d_reader->update_read_pointer(nreqd_samples); - + if (nreqd_samples <= navail_samples) { // We've got enough data... + { + gruel::scoped_lock guard(self->d_ringbuffer_mutex); + + memcpy(outputBuffer, + self->d_reader->read_pointer(), + nreqd_samples * sizeof(sample_t)); + self->d_reader->update_read_pointer(nreqd_samples); + + self->d_ringbuffer_ready = true; + } + // Tell the sink thread there is new room in the ringbuffer. - self->d_ringbuffer_ready.post(); + self->d_ringbuffer_cond.notify_one(); return paContinue; } else { // underrun - //if (LOGGING) - // self->d_log->printf("PAsink cb: f/b = %4ld UNDERRUN\n", framesPerBuffer); - self->d_nunderuns++; ::write(2, "aU", 2); // FIXME change to non-blocking call // FIXME we should transfer what we've got and pad the rest memset(outputBuffer, 0, nreqd_samples * sizeof(sample_t)); - self->d_ringbuffer_ready.post(); // Tell the sink to get going! + self->d_ringbuffer_ready = true; + self->d_ringbuffer_cond.notify_one(); // Tell the sink to get going! + return paContinue; } } @@ -135,7 +136,9 @@ audio_portaudio_sink::audio_portaudio_sink(int sampling_rate, d_verbose(gr_prefs::singleton()->get_bool("audio_portaudio", "verbose", false)), d_portaudio_buffer_size_frames(0), d_stream(0), - d_ringbuffer_ready(1, 1), // binary semaphore + d_ringbuffer_mutex(), + d_ringbuffer_cond(), + d_ringbuffer_ready(false), d_nunderuns(0) { memset(&d_output_parameters, 0, sizeof(d_output_parameters)); @@ -297,12 +300,17 @@ audio_portaudio_sink::work (int noutput_items, const unsigned nchan = d_output_parameters.channelCount; // # of channels == samples/frame int k; - for (k = 0; k < noutput_items; ){ + for (k = 0; k < noutput_items; ){ int nframes = d_writer->space_available() / nchan; // How much space in ringbuffer if (nframes == 0){ // no room... if (d_ok_to_block){ - d_ringbuffer_ready.wait(); // block here, then try again + { + gruel::scoped_lock guard(d_ringbuffer_mutex); + while (!d_ringbuffer_ready) + d_ringbuffer_cond.wait(guard); + } + continue; } else { @@ -316,16 +324,21 @@ audio_portaudio_sink::work (int noutput_items, } // We can write the smaller of the request and the room we've got - int nf = std::min(noutput_items - k, nframes); - - float *p = (float *) d_writer->write_pointer(); - for (int i = 0; i < nf; i++){ - for (unsigned int c = 0; c < nchan; c++){ - *p++ = in[c][k + i]; - } + { + gruel::scoped_lock guard(d_ringbuffer_mutex); + + int nf = std::min(noutput_items - k, nframes); + float *p = (float *) d_writer->write_pointer(); + + for (int i = 0; i < nf; i++) + for (unsigned int c = 0; c < nchan; c++) + *p++ = in[c][k + i]; + + d_writer->update_write_pointer(nf * nchan); + k += nf; + + d_ringbuffer_ready = false; } - d_writer->update_write_pointer(nf * nchan); - k += nf; } return k; // tell how many we actually did diff --git a/gr-audio-portaudio/src/audio_portaudio_sink.h b/gr-audio-portaudio/src/audio_portaudio_sink.h index 1a0729799f..71cbfcf9f0 100644 --- a/gr-audio-portaudio/src/audio_portaudio_sink.h +++ b/gr-audio-portaudio/src/audio_portaudio_sink.h @@ -24,7 +24,7 @@ #include <gr_sync_block.h> #include <gr_buffer.h> -#include <gnuradio/omnithread.h> +#include <gruel/thread.h> #include <string> #include <portaudio.h> #include <stdexcept> @@ -74,8 +74,10 @@ class audio_portaudio_sink : public gr_sync_block { gr_buffer_sptr d_writer; // buffer used between work and callback gr_buffer_reader_sptr d_reader; - omni_semaphore d_ringbuffer_ready; // binary semaphore + gruel::mutex d_ringbuffer_mutex; + gruel::condition_variable d_ringbuffer_cond; + bool d_ringbuffer_ready; // random stats int d_nunderuns; // count of underruns diff --git a/gr-audio-portaudio/src/audio_portaudio_source.cc b/gr-audio-portaudio/src/audio_portaudio_source.cc index 9e883ad8a3..484b7f1e54 100644 --- a/gr-audio-portaudio/src/audio_portaudio_source.cc +++ b/gr-audio-portaudio/src/audio_portaudio_source.cc @@ -32,7 +32,6 @@ #include <unistd.h> #include <stdexcept> #include <gri_portaudio.h> -#include <gnuradio/omnithread.h> #include <string.h> //#define LOGGING 0 // define to 0 or 1 @@ -88,32 +87,28 @@ portaudio_source_callback (const void *inputBuffer, // self->d_log->printf("PAsrc cb: f/b = %4ld\n", framesPerBuffer); // copy from input buffer to ringbuffer - memcpy(self->d_writer->write_pointer(), - inputBuffer, - nframes_to_copy * nchan * sizeof(sample_t)); - self->d_writer->update_write_pointer(nframes_to_copy * nchan); + { + gruel::scoped_lock(d_ringbuffer_mutex); + + memcpy(self->d_writer->write_pointer(), + inputBuffer, + nframes_to_copy * nchan * sizeof(sample_t)); + self->d_writer->update_write_pointer(nframes_to_copy * nchan); - // Tell the source thread there is new data in the ringbuffer. - self->d_ringbuffer_ready.post(); + // Tell the source thread there is new data in the ringbuffer. + self->d_ringbuffer_ready = true; + } + + self->d_ringbuffer_cond.notify_one(); return paContinue; } else { // overrun - //if (LOGGING) - // self->d_log->printf("PAsrc cb: f/b = %4ld OVERRUN\n", framesPerBuffer); - self->d_noverruns++; ::write(2, "aO", 2); // FIXME change to non-blocking call -#if 0 - // copy any frames that will fit - memcpy(self->d_writer->write_pointer(), - inputBuffer, - nframes_room * nchan * sizeof(sample_t)); - self->d_writer->update_write_pointer(nframes_room * nchan); -#endif - - self->d_ringbuffer_ready.post(); // Tell the sink to get going! + self->d_ringbuffer_ready = false; + self->d_ringbuffer_cond.notify_one(); // Tell the sink to get going! return paContinue; } } @@ -140,7 +135,9 @@ audio_portaudio_source::audio_portaudio_source(int sampling_rate, d_verbose(gr_prefs::singleton()->get_bool("audio_portaudio", "verbose", false)), d_portaudio_buffer_size_frames(0), d_stream(0), - d_ringbuffer_ready(1, 1), // binary semaphore + d_ringbuffer_mutex(), + d_ringbuffer_cond(), + d_ringbuffer_ready(false), d_noverruns(0) { memset(&d_input_parameters, 0, sizeof(d_input_parameters)); @@ -303,11 +300,13 @@ audio_portaudio_source::work (int noutput_items, if (k > 0) // If we've produced anything so far, return that return k; - if (d_ok_to_block){ - d_ringbuffer_ready.wait(); // block here, then try again + if (d_ok_to_block) { + gruel:: scoped_lock guard(d_ringbuffer_mutex); + while (d_ringbuffer_ready == false) + d_ringbuffer_cond.wait(guard); // block here, then try again continue; } - + assert(k == 0); // There's no data and we're not allowed to block. @@ -320,27 +319,38 @@ audio_portaudio_source::work (int noutput_items, // FIXME We'll fill with zeros for now. Yes, it will "click"... // Fill with some frames of zeros - int nf = std::min(noutput_items - k, (int) d_portaudio_buffer_size_frames); - for (int i = 0; i < nf; i++){ - for (unsigned int c = 0; c < nchan; c++){ - out[c][k + i] = 0; + { + gruel::scoped_lock guard(d_ringbuffer_mutex); + + int nf = std::min(noutput_items - k, (int) d_portaudio_buffer_size_frames); + for (int i = 0; i < nf; i++){ + for (unsigned int c = 0; c < nchan; c++){ + out[c][k + i] = 0; + } } + k += nf; + + d_ringbuffer_ready = false; + return k; } - k += nf; - return k; } // We can read the smaller of the request and what's in the buffer. - int nf = std::min(noutput_items - k, nframes); + { + gruel::scoped_lock guard(d_ringbuffer_mutex); - const float *p = (const float *) d_reader->read_pointer(); - for (int i = 0; i < nf; i++){ - for (unsigned int c = 0; c < nchan; c++){ - out[c][k + i] = *p++; + int nf = std::min(noutput_items - k, nframes); + + const float *p = (const float *) d_reader->read_pointer(); + for (int i = 0; i < nf; i++){ + for (unsigned int c = 0; c < nchan; c++){ + out[c][k + i] = *p++; + } } + d_reader->update_read_pointer(nf * nchan); + k += nf; + d_ringbuffer_ready = false; } - d_reader->update_read_pointer(nf * nchan); - k += nf; } return k; // tell how many we actually did diff --git a/gr-audio-portaudio/src/audio_portaudio_source.h b/gr-audio-portaudio/src/audio_portaudio_source.h index 3102db739c..31e70a1277 100644 --- a/gr-audio-portaudio/src/audio_portaudio_source.h +++ b/gr-audio-portaudio/src/audio_portaudio_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006.2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,11 +24,10 @@ #include <gr_sync_block.h> #include <gr_buffer.h> -#include <gnuradio/omnithread.h> +#include <gruel/thread.h> #include <string> #include <portaudio.h> #include <stdexcept> -//#include <gri_logger.h> class audio_portaudio_source; typedef boost::shared_ptr<audio_portaudio_source> audio_portaudio_source_sptr; @@ -74,11 +73,13 @@ class audio_portaudio_source : public gr_sync_block { gr_buffer_sptr d_writer; // buffer used between work and callback gr_buffer_reader_sptr d_reader; - omni_semaphore d_ringbuffer_ready; // binary semaphore + + gruel::mutex d_ringbuffer_mutex; + gruel::condition_variable d_ringbuffer_cond; + bool d_ringbuffer_ready; // random stats int d_noverruns; // count of overruns - //gri_logger_sptr d_log; // handle to non-blocking logging instance void output_error_msg (const char *msg, int err); void bail (const char *msg, int err) throw (std::runtime_error); @@ -87,7 +88,7 @@ class audio_portaudio_source : public gr_sync_block { protected: audio_portaudio_source (int sampling_rate, const std::string device_name, - bool ok_to_block); + bool ok_to_block); public: ~audio_portaudio_source (); diff --git a/gr-wxgui/src/python/scope_window.py b/gr-wxgui/src/python/scope_window.py index 08a025e1ef..f7c0ffa82e 100644 --- a/gr-wxgui/src/python/scope_window.py +++ b/gr-wxgui/src/python/scope_window.py @@ -55,6 +55,9 @@ CHANNEL_COLOR_SPECS = ( (0.0, 0.8, 0.0), (1.0, 0.0, 0.0), (0.8, 0.0, 0.8), + (0.7, 0.7, 0.0), + (0.15, 0.90, 0.98), + ) TRIGGER_COLOR_SPEC = (1.0, 0.4, 0.0) AUTORANGE_UPDATE_RATE = 0.5 #sec diff --git a/grc/gui/Param.py b/grc/gui/Param.py index b3018dab21..7c00c1b67f 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -1,5 +1,5 @@ """ -Copyright 2007, 2008, 2009 Free Software Foundation, Inc. +Copyright 2007, 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -135,10 +135,21 @@ PARAM_LABEL_MARKUP_TMPL="""\ <span underline="$underline" foreground="$foreground" font_desc="Sans 9">$encode($param.get_name())</span>""" TIP_MARKUP_TMPL="""\ +######################################## +#def truncate(string) + #set $max_len = 100 + #set $string = str($string) + #if len($string) > $max_len +$('%s...%s'%($string[:$max_len/2], $string[-$max_len/2:]))#slurp + #else +$string#slurp + #end if +#end def +######################################## Key: $param.get_key() Type: $param.get_type() #if $param.is_valid() -Value: $param.get_evaluated() +Value: $truncate($param.get_evaluated()) #elif len($param.get_error_messages()) == 1 Error: $(param.get_error_messages()[0]) #else diff --git a/grc/python/Param.py b/grc/python/Param.py index e04bc8fcb5..6dd008d1d0 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -1,5 +1,5 @@ """ -Copyright 2008, 2009 Free Software Foundation, Inc. +Copyright 2008, 2009, 2010 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion is free software; you can redistribute it and/or @@ -108,7 +108,23 @@ class Param(_Param, _GUIParam): Get the repr (nice string format) for this param. @return the string representation """ - if not self.is_valid(): return self.get_value() + ################################################## + # truncate helper method + ################################################## + def _truncate(string, style=0): + max_len = max(27 - len(self.get_name()), 3) + if len(string) > max_len: + if style < 0: #front truncate + string = '...' + string[3-max_len:] + elif style == 0: #center truncate + string = string[:max_len/2 -3] + '...' + string[-max_len/2:] + elif style > 0: #rear truncate + string = string[:max_len-3] + '...' + return string + ################################################## + # simple conditions + ################################################## + if not self.is_valid(): return _truncate(self.get_value()) if self.get_value() in self.get_option_keys(): return self.get_option(self.get_value()).get_name() ################################################## # display logic for numbers @@ -126,7 +142,6 @@ class Param(_Param, _GUIParam): # split up formatting by type ################################################## truncate = 0 #default center truncate - max_len = max(27 - len(self.get_name()), 3) e = self.get_evaluated() t = self.get_type() if isinstance(e, bool): return str(e) @@ -141,16 +156,9 @@ class Param(_Param, _GUIParam): truncate = -1 else: dt_str = str(e) #other types ################################################## - # truncate + # done ################################################## - if len(dt_str) > max_len: - if truncate < 0: #front truncate - dt_str = '...' + dt_str[3-max_len:] - elif truncate == 0: #center truncate - dt_str = dt_str[:max_len/2 -3] + '...' + dt_str[-max_len/2:] - elif truncate > 0: #rear truncate - dt_str = dt_str[:max_len-3] + '...' - return dt_str + return _truncate(dt_str, truncate) def get_input(self, *args, **kwargs): if self.get_type() in ('file_open', 'file_save'): return FileParam(self, *args, **kwargs) diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h index 0e7acaa856..d72e5520ce 100644 --- a/gruel/src/include/gruel/thread.h +++ b/gruel/src/include/gruel/thread.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2009 Free Software Foundation, Inc. + * Copyright 2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,12 +22,20 @@ #define INCLUDED_THREAD_H #include <boost/thread.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> namespace gruel { + typedef boost::thread thread; typedef boost::mutex mutex; typedef boost::unique_lock<boost::mutex> scoped_lock; typedef boost::condition_variable condition_variable; + typedef boost::posix_time::time_duration duration; + + /*! + * Returns absolute time 'secs' into the future + */ + boost::system_time get_new_timeout(double secs); } /* namespace gruel */ diff --git a/gruel/src/lib/Makefile.am b/gruel/src/lib/Makefile.am index b21f8023c7..6bde9ee272 100644 --- a/gruel/src/lib/Makefile.am +++ b/gruel/src/lib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2008,2009 Free Software Foundation, Inc. +# Copyright 2008,2009,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -45,6 +45,7 @@ MSG_LIB = msg/libmsg.la libgruel_la_SOURCES = \ realtime.cc \ sys_pri.cc \ + thread.cc \ thread_body_wrapper.cc \ thread_group.cc diff --git a/mblock/src/lib/mb_util.cc b/gruel/src/lib/thread.cc index 60a0e44fbf..d8f77b5067 100644 --- a/mblock/src/lib/mb_util.cc +++ b/gruel/src/lib/thread.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,13 +22,14 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif +#include <gruel/thread.h> -#include <mb_util.h> +namespace gruel { + boost::system_time + get_new_timeout(double secs) + { + return boost::get_system_time() + boost::posix_time::milliseconds(long(secs*1e3)); + } -std::string -mb_util::join_names(const std::string &comp_name, - const std::string &port_name) -{ - return comp_name + ":" + port_name; } diff --git a/mblock/.gitignore b/mblock/.gitignore deleted file mode 100644 index 36b77742f2..0000000000 --- a/mblock/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Makefile -/Makefile.in -/mblock.pc diff --git a/mblock/Makefile.am b/mblock/Makefile.am deleted file mode 100644 index 69e2f22c06..0000000000 --- a/mblock/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright 2004 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -EXTRA_DIST = \ - mblock.pc.in - -SUBDIRS = src -DIST_SUBDIRS = src doc - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = mblock.pc diff --git a/mblock/README b/mblock/README deleted file mode 100644 index 1f3ba697b4..0000000000 --- a/mblock/README +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright 2006,2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -The "Message block" implementation, a work in progress... - -http://gnuradio.org/trac/wiki/MessageBlocks diff --git a/mblock/doc/.gitignore b/mblock/doc/.gitignore deleted file mode 100644 index f65ab6cf72..0000000000 --- a/mblock/doc/.gitignore +++ /dev/null @@ -1,18 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/*.la -/*.lo -/autom4te.cache -/*.cache -/howto-write-a-block.html -/gr_block.h.xml -/howto_1.i.xml -/howto_square_ff.cc.xml -/howto_square_ff.h.xml -/qa_howto_1.py.xml -/src_lib_Makefile_1.am.xml -/src_lib_Makefile_2.am.xml -/howto_square2_ff.cc.xml -/howto_square2_ff.h.xml diff --git a/mblock/doc/Makefile.am b/mblock/doc/Makefile.am deleted file mode 100644 index a806b25cf0..0000000000 --- a/mblock/doc/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -# -# Copyright 2004,2005,2006 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -TARGETS = - - -# To avoid build problems for folks who don't have xmlto installed, we -# don't build the docs by default. - -# html: $(TARGETS) -all: $(TARGETS) - - -EXTRA_DIST = - -BUILT_XML_FILES = - - -# ---------------------------------------------------------------- - -clean: - -rm -f $(TARGETS) $(BUILT_XML_FILES) - -# This is non-portable pattern rule. -#%.html : %.xml -# xmlto html-nochunks $< diff --git a/mblock/mblock.pc.in b/mblock/mblock.pc.in deleted file mode 100644 index 3d849995b4..0000000000 --- a/mblock/mblock.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: mblock -Description: The GNU Radio message block library -Requires: pmt gnuradio-omnithread -Version: @VERSION@ -Libs: -L${libdir} -lmblock -Cflags: -I${includedir}
\ No newline at end of file diff --git a/mblock/src/.gitignore b/mblock/src/.gitignore deleted file mode 100644 index bb3f277779..0000000000 --- a/mblock/src/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/howto.cc -/howto.py diff --git a/mblock/src/Makefile.am b/mblock/src/Makefile.am deleted file mode 100644 index 60995c9720..0000000000 --- a/mblock/src/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright 2004,2006,2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -SUBDIRS = include lib scheme diff --git a/mblock/src/include/.gitignore b/mblock/src/include/.gitignore deleted file mode 100644 index b336cc7cec..0000000000 --- a/mblock/src/include/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/mblock/src/include/Makefile.am b/mblock/src/include/Makefile.am deleted file mode 100644 index d5672989c6..0000000000 --- a/mblock/src/include/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright 2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = mblock diff --git a/mblock/src/include/mblock/.gitignore b/mblock/src/include/mblock/.gitignore deleted file mode 100644 index b336cc7cec..0000000000 --- a/mblock/src/include/mblock/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/mblock/src/include/mblock/Makefile.am b/mblock/src/include/mblock/Makefile.am deleted file mode 100644 index e36215aa40..0000000000 --- a/mblock/src/include/mblock/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright 2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -mbincludedir = $(includedir)/mblock - -mbinclude_HEADERS = \ - common.h \ - class_registry.h \ - exception.h \ - mblock.h \ - message.h \ - msg_accepter.h \ - msg_queue.h \ - port.h \ - protocol_class.h \ - runtime.h \ - time.h diff --git a/mblock/src/include/mblock/class_registry.h b/mblock/src/include/mblock/class_registry.h deleted file mode 100644 index e4341f7d14..0000000000 --- a/mblock/src/include/mblock/class_registry.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_CLASS_REGISTRY_H -#define INCLUDED_MB_CLASS_REGISTRY_H - -#include <mblock/common.h> - -//! conceptually, pointer to constructor -typedef mb_mblock_sptr (*mb_mblock_maker_t)(mb_runtime *runtime, - const std::string &instance_name, - pmt::pmt_t user_arg); - -/* - * \brief Maintain mapping between mblock class_name and factory (maker) - */ -class mb_class_registry : public boost::noncopyable { -public: - static bool register_maker(const std::string &name, mb_mblock_maker_t maker); - static bool lookup_maker(const std::string &name, mb_mblock_maker_t *maker); -}; - -template<class mblock> -mb_mblock_sptr mb_mblock_maker(mb_runtime *runtime, - const std::string &instance_name, - pmt::pmt_t user_arg) -{ - return mb_mblock_sptr(new mblock(runtime, instance_name, user_arg)); -} - -#define REGISTER_MBLOCK_CLASS(name) \ - bool __RBC__ ## name = mb_class_registry::register_maker(#name, &mb_mblock_maker<name>) - -#endif /* INCLUDED_MB_CLASS_REGISTRY_H */ diff --git a/mblock/src/include/mblock/common.h b/mblock/src/include/mblock/common.h deleted file mode 100644 index 054b9987eb..0000000000 --- a/mblock/src/include/mblock/common.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_COMMON_H -#define INCLUDED_MB_COMMON_H - -#include <gruel/pmt.h> -#include <vector> -#include <stdexcept> -#include <boost/utility.hpp> -#include <boost/enable_shared_from_this.hpp> -#include <boost/weak_ptr.hpp> - -/* - * The priority type and valid range - */ -typedef unsigned int mb_pri_t; -static const mb_pri_t MB_PRI_BEST = 0; -static const mb_pri_t MB_PRI_DEFAULT = 4; -static const mb_pri_t MB_PRI_WORST = 7; -static const mb_pri_t MB_NPRI = MB_PRI_WORST + 1; // number of valid priorities - -/*! - * \brief return true iff priority a is better than priority b - */ -inline static bool -mb_pri_better(mb_pri_t a, mb_pri_t b) -{ - return a < b; -} - -/*! - * \brief return true iff priority a is worse than priority b - */ -inline static bool -mb_pri_worse(mb_pri_t a, mb_pri_t b) -{ - return a > b; -} - -/*! - * \brief ensure that pri is valid - */ -inline static mb_pri_t -mb_pri_clamp(mb_pri_t p) -{ - return p < MB_NPRI ? p : MB_NPRI - 1; -} - -class mb_runtime; -typedef boost::shared_ptr<mb_runtime> mb_runtime_sptr; - -//class mb_runtime_impl; -//typedef boost::shared_ptr<mb_runtime_impl> mb_runtime_impl_sptr; - -class mb_mblock; -typedef boost::shared_ptr<mb_mblock> mb_mblock_sptr; - -class mb_mblock_impl; -typedef boost::shared_ptr<mb_mblock_impl> mb_mblock_impl_sptr; - -class mb_port; -typedef boost::shared_ptr<mb_port> mb_port_sptr; - -//class mb_port_detail; -//typedef boost::shared_ptr<mb_port_detail> mb_port_detail_sptr; - -class mb_msg_accepter; -typedef boost::shared_ptr<mb_msg_accepter> mb_msg_accepter_sptr; - -class mb_message; -typedef boost::shared_ptr<mb_message> mb_message_sptr; - -class mb_msg_queue; -typedef boost::shared_ptr<mb_msg_queue> mb_msg_queue_sptr; - -#endif /* INCLUDED_MB_COMMON_H */ diff --git a/mblock/src/include/mblock/exception.h b/mblock/src/include/mblock/exception.h deleted file mode 100644 index 6cc4566569..0000000000 --- a/mblock/src/include/mblock/exception.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_EXCEPTION_H -#define INCLUDED_MB_EXCEPTION_H - -#include <stdexcept> - -class mb_mblock; - - -class mbe_base : public std::logic_error -{ -public: - mbe_base(mb_mblock *mb, const std::string &msg); -}; - -class mbe_not_implemented : public mbe_base -{ -public: - mbe_not_implemented(mb_mblock *mb, const std::string &msg); -}; - -class mbe_no_such_class : public mbe_base -{ -public: - mbe_no_such_class(mb_mblock *, const std::string &class_name); -}; - -class mbe_no_such_component : public mbe_base -{ -public: - mbe_no_such_component(mb_mblock *, const std::string &component_name); -}; - -class mbe_duplicate_component : public mbe_base -{ -public: - mbe_duplicate_component(mb_mblock *, const std::string &component_name); -}; - -class mbe_no_such_port : public mbe_base -{ -public: - mbe_no_such_port(mb_mblock *, const std::string &port_name); -}; - - -class mbe_duplicate_port : public mbe_base -{ -public: - mbe_duplicate_port(mb_mblock *, const std::string &port_name); -}; - -class mbe_already_connected : public mbe_base -{ -public: - mbe_already_connected(mb_mblock *, const std::string &comp_name, - const std::string &port_name); -}; - -class mbe_incompatible_ports : public mbe_base -{ -public: - mbe_incompatible_ports(mb_mblock *, - const std::string &comp1_name, - const std::string &port1_name, - const std::string &comp2_name, - const std::string &port2_name); -}; - -class mbe_invalid_port_type : public mbe_base -{ -public: - mbe_invalid_port_type(mb_mblock *, const std::string &comp_name, - const std::string &port_name); -}; - -class mbe_mblock_failed : public mbe_base -{ -public: - mbe_mblock_failed(mb_mblock *, const std::string &msg); -}; - - - -// not derived from mbe_base to simplify try/catch -class mbe_terminate -{ -public: - mbe_terminate(); -}; - -// not derived from mbe_base to simplify try/catch -class mbe_exit -{ -public: - mbe_exit(); -}; - -#endif /* INCLUDED_MB_EXCEPTION_H */ diff --git a/mblock/src/include/mblock/mblock.h b/mblock/src/include/mblock/mblock.h deleted file mode 100644 index 2f036e4145..0000000000 --- a/mblock/src/include/mblock/mblock.h +++ /dev/null @@ -1,318 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MBLOCK_H -#define INCLUDED_MB_MBLOCK_H - -#include <mblock/common.h> -#include <mblock/message.h> -#include <mblock/port.h> -#include <mblock/time.h> - - -/*! - * Abstract class implementing visitor pattern - * \ingroup internal - */ -class mb_visitor -{ -public: - virtual ~mb_visitor(); - virtual bool operator()(mb_mblock *mblock) = 0; -}; - -// ---------------------------------------------------------------------- - -/*! - * \brief Parent class for all message passing blocks - * - * Subclass this to define your mblocks. - */ -class mb_mblock : boost::noncopyable, - public boost::enable_shared_from_this<mb_mblock> -{ -private: - mb_mblock_impl_sptr d_impl; // implementation details - - friend class mb_runtime; - friend class mb_mblock_impl; - friend class mb_worker; - -protected: - /*! - * \brief mblock constructor. - * - * Initializing all mblocks in the system is a 3 step procedure. - * - * The top level mblock's constructor is run. That constructor - * (a) registers all of its ports using define_port, (b) registers any - * subcomponents it may have via the define_component method, and - * then (c) issues connect calls to wire its subcomponents together. - * - * \param runtime the runtime associated with this mblock - * \param instance_name specify the name of this instance - * (for debugging, NUMA mapping, etc) - * \param user_arg argument passed by user to constructor - * (ignored by the mb_mblock base class) - */ - mb_mblock(mb_runtime *runtime, const std::string &instance_name, pmt::pmt_t user_arg); - -public: - /*! - * \brief Called by the runtime system to execute the initial - * transition of the finite state machine. - * - * This method is called by the runtime after all blocks are - * constructed and before the first message is delivered. Override - * this to initialize your finite state machine. - */ - virtual void initial_transition(); - -protected: - /*! - * \brief Called by the runtime system when there's a message to handle. - * - * Override this to define your behavior. - * - * Do not issue any potentially blocking calls in this method. This - * includes things such reads or writes on sockets, pipes or slow - * i/o devices. - */ - virtual void handle_message(mb_message_sptr msg); - - /*! - * \brief Define a port. - * - * EXTERNAL and RELAY ports are part of our peer interface. - * INTERNAL ports are used to talk to sub-components. - * - * \param port_name The name of the port (must be unique within this mblock). - * \param protocol_class_name The name of the protocol class associated with - * this port. It must already be defined. - * \param conjugated Are the incoming and outgoing message sets swapped? - * \param port_type INTERNAL, EXTERNAL or RELAY. - */ - mb_port_sptr - define_port(const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - /*! - * \brief Define a subcomponent by name. - * - * Called within the constructor to tell the system the - * names and identities of our sub-component mblocks. - * - * \param component_name The name of the sub-component (must be unique with this mblock). - * \param class_name The class of the instance that is to be created. - * \param user_arg The argument to pass to the constructor of the component. - */ - void - define_component(const std::string &component_name, - const std::string &class_name, - pmt::pmt_t user_arg = pmt::PMT_NIL); - - /*! - * \brief connect endpoint_1 to endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To connect an internal or relay port, use "self" as the component name. - */ - void - connect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect endpoint_1 from endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To disconnect an internal or relay port, use "self" as the component name. - */ - void - disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect all connections to specified component - * \param component_name component to disconnect - */ - void - disconnect_component(const std::string &component_name); - - /*! - * \brief disconnect all connections to all components - */ - void - disconnect_all(); - - /*! - * \brief Return number of connections (QA mostly) - */ - int - nconnections() const; - - //! Set the class name - void set_class_name(const std::string &name); - - /*! - * \brief Tell runtime that we are done. - * - * This method does not return. - */ - void exit(); - - /*! - * \brief Ask runtime to execute the shutdown procedure for all blocks. - * - * \param result sets value of \p result output argument of runtime->run(...) - * - * The runtime first sends a maximum priority %shutdown message to - * all blocks. All blocks should handle the %shutdown message, - * perform whatever clean up is required, and call this->exit(); - * - * After a period of time (~100ms), any blocks which haven't yet - * called this->exit() are sent a maximum priority %halt message. - * %halt is detected in main_loop, and this->exit() is called. - * - * After an additional period of time (~100ms), any blocks which - * still haven't yet called this->exit() are sent a SIG<FOO> (TBD) - * signal, which will blow them out of any blocking system calls and - * raise an mbe_terminate exception. The default top-level - * runtime-provided exception handler will call this->exit() to - * finish the process. - * - * runtime->run(...) returns when all blocks have called exit. - */ - void shutdown_all(pmt::pmt_t result); - - /*! - * \brief main event dispatching loop - * - * Although it is possible to override this, the default implementation - * should work for virtually all cases. - */ - virtual void main_loop(); - -public: - virtual ~mb_mblock(); - - //! Return instance name of this block - std::string instance_name() const; - - //! Return the class name of this block - std::string class_name() const; - - //! Set the instance name of this block. - void set_instance_name(const std::string &name); - - //! Return the parent of this mblock, or 0 if we're the top-level block. - mb_mblock *parent() const; - - /*! - * \brief Schedule a "one shot" timeout. - * - * \param abs_time the absolute time at which the timeout should fire - * \param user_data the data passed in the %timeout message. - * - * When the timeout fires, a message will be sent to the mblock. - * - * The message will have port_id = %sys-port, signal = %timeout, - * data = user_data, metadata = the handle returned from - * schedule_one_shot_timeout, pri = MB_PRI_BEST. - * - * \returns a handle that can be used in cancel_timeout, and is passed - * as the metadata field of the generated %timeout message. - * - * To cancel a pending timeout, call cancel_timeout. - */ - pmt::pmt_t - schedule_one_shot_timeout(const mb_time &abs_time, pmt::pmt_t user_data); - - /*! - * \brief Schedule a periodic timeout. - * - * \param first_abs_time The absolute time at which the first timeout should fire. - * \param delta_time The relative delay between the first and successive timeouts. - * \param user_data the data passed in the %timeout message. - * - * When the timeout fires, a message will be sent to the mblock, and a - * new timeout will be scheduled for previous absolute time + delta_time. - * - * The message will have port_id = %sys-port, signal = %timeout, - * data = user_data, metadata = the handle returned from - * schedule_one_shot_timeout, pri = MB_PRI_BEST. - * - * \returns a handle that can be used in cancel_timeout, and is passed - * as the metadata field of the generated %timeout message. - * - * To cancel a pending timeout, call cancel_timeout. - */ - pmt::pmt_t - schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt::pmt_t user_data); - - /*! - * \brief Attempt to cancel a pending timeout. - * - * Note that this only stops a future timeout from firing. It is - * possible that a timeout may have already fired and enqueued a - * %timeout message, but that that message has not yet been seen by - * handle_message. - * - * \param handle returned from schedule_one_shot_timeout or schedule_periodic_timeout. - */ - void cancel_timeout(pmt::pmt_t handle); - - /*! - * \brief Perform a pre-order depth-first traversal of the hierarchy. - * - * The traversal stops and returns false if any call to visitor returns false. - */ - bool - walk_tree(mb_visitor *visitor); - - - //! \internal - // internal use only - mb_mblock_impl_sptr - impl() const { return d_impl; } - -}; - - -#endif /* INCLUDED_MB_MBLOCK_H */ diff --git a/mblock/src/include/mblock/message.h b/mblock/src/include/mblock/message.h deleted file mode 100644 index 4051d0c8e6..0000000000 --- a/mblock/src/include/mblock/message.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MESSAGE_H -#define INCLUDED_MB_MESSAGE_H - -#include <mblock/common.h> -#include <iosfwd> - -#define MB_MESSAGE_LOCAL_ALLOCATOR 0 // define to 0 or 1 - -class mb_message; -typedef boost::shared_ptr<mb_message> mb_message_sptr; - -/*! - * \brief construct a message and return boost::shared_ptr - * - * \param signal identifier of the message - * \param data the data to be operated on - * \param metadata information about the data - * \param priority urgency - */ -mb_message_sptr -mb_make_message(pmt::pmt_t signal, - pmt::pmt_t data = pmt::PMT_NIL, - pmt::pmt_t metadata = pmt::PMT_NIL, - mb_pri_t priority = MB_PRI_DEFAULT); - -class mb_message { - mb_message_sptr d_next; // link field for msg queue - pmt::pmt_t d_signal; - pmt::pmt_t d_data; - pmt::pmt_t d_metadata; - mb_pri_t d_priority; - pmt::pmt_t d_port_id; // name of port msg was rcvd on (symbol) - - friend class mb_msg_queue; - - friend mb_message_sptr - mb_make_message(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); - - // private constructor - mb_message(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); - -public: - ~mb_message(); - - pmt::pmt_t signal() const { return d_signal; } - pmt::pmt_t data() const { return d_data; } - pmt::pmt_t metadata() const { return d_metadata; } - mb_pri_t priority() const { return d_priority; } - pmt::pmt_t port_id() const { return d_port_id; } - - void set_port_id(pmt::pmt_t port_id){ d_port_id = port_id; } - -#if (MB_MESSAGE_LOCAL_ALLOCATOR) - void *operator new(size_t); - void operator delete(void *, size_t); -#endif -}; - -std::ostream& operator<<(std::ostream& os, const mb_message &msg); - -inline -std::ostream& operator<<(std::ostream& os, const mb_message_sptr msg) -{ - os << *(msg.get()); - return os; -} - -#endif /* INCLUDED_MB_MESSAGE_H */ diff --git a/mblock/src/include/mblock/msg_accepter.h b/mblock/src/include/mblock/msg_accepter.h deleted file mode 100644 index 7dc1e50cb2..0000000000 --- a/mblock/src/include/mblock/msg_accepter.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_ACCEPTER_H -#define INCLUDED_MB_MSG_ACCEPTER_H - -#include <mblock/common.h> - -/*! - * \brief Abstract class that accepts messages - * - * The mb_port::send method ultimately resolves the (local) - * destination of a send to an object of this type. The resulting - * object is called to deliver the message. - * - * Expect derived classes such as these: - * - * smp : target is visible in this address space - * mpi : target is on the other end of an MPI link - * ppe->spe : sending from Cell PPE to Cell SPE - * spe->ppe : sending from Cell SPE to Cell PPE - */ -class mb_msg_accepter { -public: - mb_msg_accepter(){}; - virtual ~mb_msg_accepter(); - - virtual void operator()(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority) = 0; -}; - -#endif /* INCLUDED_MB_MSG_ACCEPTER_H */ diff --git a/mblock/src/include/mblock/msg_queue.h b/mblock/src/include/mblock/msg_queue.h deleted file mode 100644 index a23397081a..0000000000 --- a/mblock/src/include/mblock/msg_queue.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_QUEUE_H -#define INCLUDED_MB_MSG_QUEUE_H - -#include <mblock/common.h> -#include <gnuradio/omnithread.h> -#include <mblock/time.h> - -/*! - * \brief priority queue for mblock messages - */ -class mb_msg_queue : boost::noncopyable -{ - // When empty both head and tail are zero. - struct subq { - mb_message_sptr head; - mb_message_sptr tail; - - bool empty_p() const { return head == 0; } - }; - - omni_mutex d_mutex; - omni_condition d_not_empty; // reader waits on this - - // FIXME add bitmap to indicate which queues are non-empty. - subq d_queue[MB_NPRI]; - - mb_message_sptr get_highest_pri_msg_helper(); - -public: - mb_msg_queue(); - ~mb_msg_queue(); - - //! Insert \p msg into priority queue. - void insert(mb_message_sptr msg); - - /* - * \brief Delete highest pri message from the queue and return it. - * Returns equivalent of zero pointer if queue is empty. - */ - mb_message_sptr get_highest_pri_msg_nowait(); - - /* - * \brief Delete highest pri message from the queue and return it. - * If the queue is empty, this call blocks until it can return a message. - */ - mb_message_sptr get_highest_pri_msg(); - - /* - * \brief Delete highest pri message from the queue and return it. - * If the queue is empty, this call blocks until it can return a message - * or real-time exceeds the absolute time, abs_time. - * - * \param abs_time specifies the latest absolute time to wait until. - * \sa mb_time::time - * - * \returns a valid mb_message_sptr, or the equivalent of a zero pointer - * if the call timed out while waiting. - */ - mb_message_sptr get_highest_pri_msg_timedwait(const mb_time &abs_time); -}; - -#endif /* INCLUDED_MB_MSG_QUEUE_H */ diff --git a/mblock/src/include/mblock/port.h b/mblock/src/include/mblock/port.h deleted file mode 100644 index 1664765db1..0000000000 --- a/mblock/src/include/mblock/port.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_PORT_H -#define INCLUDED_MB_PORT_H - -#include <mblock/common.h> - -/*! - * \brief Abstract port characteristics - */ -class mb_port : boost::noncopyable -{ -public: - - //! port classification - enum port_type_t { - EXTERNAL, //< Externally visible - RELAY, //< Externally visible but really connected to a sub-component - INTERNAL //< Visible to self only - }; - -private: - - std::string d_port_name; - pmt::pmt_t d_port_symbol; // the port_name as a pmt::pmt symbol - pmt::pmt_t d_protocol_class; - bool d_conjugated; - port_type_t d_port_type; - -protected: - mb_mblock *d_mblock; // mblock we're defined in - - // protected constructor - mb_port(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - mb_mblock *mblock() const { return d_mblock; } - -public: - std::string port_name() const { return d_port_name; } - pmt::pmt_t port_symbol() const { return d_port_symbol; } - pmt::pmt_t protocol_class() const { return d_protocol_class; } - bool conjugated() const { return d_conjugated; } - port_type_t port_type() const { return d_port_type; } - - pmt::pmt_t incoming_message_set() const; - pmt::pmt_t outgoing_message_set() const; - - virtual ~mb_port(); - - /*! - * \brief send a message - * - * \param signal the event name - * \param data optional data - * \param metadata optional metadata - * \param priority the urgency at which the message is sent - */ - virtual void - send(pmt::pmt_t signal, - pmt::pmt_t data = pmt::PMT_F, - pmt::pmt_t metadata = pmt::PMT_F, - mb_pri_t priority = MB_PRI_DEFAULT) = 0; - - /* - * \brief Invalidate any cached peer resolutions - * \internal - */ - virtual void invalidate_cache() = 0; -}; - -#endif /* INCLUDED_MB_PORT_H */ diff --git a/mblock/src/include/mblock/protocol_class.h b/mblock/src/include/mblock/protocol_class.h deleted file mode 100644 index a01e68d8f5..0000000000 --- a/mblock/src/include/mblock/protocol_class.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_PROTOCOL_CLASS_H -#define INCLUDED_MB_PROTOCOL_CLASS_H - -#include <mblock/common.h> - -/*! - * \brief construct a protocol_class - * - * \param name the name of the class (symbol) - * \param incoming incoming message set (list of symbols) - * \param outgoing outgoing message set (list of symbols) - */ -pmt::pmt_t mb_make_protocol_class(pmt::pmt_t name, pmt::pmt_t incoming, pmt::pmt_t outgoing); - -// Accessors -pmt::pmt_t mb_protocol_class_name(pmt::pmt_t pc); //< return name of protocol class -pmt::pmt_t mb_protocol_class_incoming(pmt::pmt_t pc); //< return incoming message set -pmt::pmt_t mb_protocol_class_outgoing(pmt::pmt_t pc); //< return outgoing message set - -pmt::pmt_t mb_protocol_class_lookup(pmt::pmt_t name); //< lookup an existing protocol class by name - - -/*! - * \brief Initialize one or more protocol class from a serialized description. - * Used by machine generated code. - */ -class mb_protocol_class_init { -public: - mb_protocol_class_init(const char *data, size_t len); -}; - -#endif /* INCLUDED_MB_PROTOCOL_CLASS_H */ diff --git a/mblock/src/include/mblock/runtime.h b/mblock/src/include/mblock/runtime.h deleted file mode 100644 index 9afc38b767..0000000000 --- a/mblock/src/include/mblock/runtime.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_RUNTIME_H -#define INCLUDED_MB_RUNTIME_H - -#include <mblock/common.h> -#include <gnuradio/omnithread.h> - -/*! - * \brief Public constructor (factory) for mb_runtime objects. - */ -mb_runtime_sptr mb_make_runtime(); - -/*! - * \brief Abstract runtime support for m-blocks - * - * There should generally be only a single instance of this class. - */ -class mb_runtime : boost::noncopyable, - public boost::enable_shared_from_this<mb_runtime> -{ -protected: - mb_mblock_sptr d_top; - -public: - mb_runtime(){} - virtual ~mb_runtime(); - - /*! - * \brief Construct and run the specified mblock hierarchy. - * - * This routine turns into the m-block scheduler, and - * blocks until the system is shutdown. - * - * \param instance_name name of the top-level mblock (conventionally "top") - * \param class_name The class of the top-level mblock to create. - * \param user_arg The argument to pass to the top-level mblock constructor - * \param result The value passed to shutdown_all. - * - * \returns true if the system ran successfully. - */ - virtual bool run(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg, - pmt::pmt_t *result = 0) = 0; - - // QA only... - mb_mblock_sptr top() { return d_top; } -}; - -#endif /* INCLUDED_MB_RUNTIME_H */ diff --git a/mblock/src/include/mblock/time.h b/mblock/src/include/mblock/time.h deleted file mode 100644 index 630fa845c1..0000000000 --- a/mblock/src/include/mblock/time.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_TIME_H -#define INCLUDED_MB_TIME_H - -#include <gnuradio/omni_time.h> -typedef omni_time mb_time; - -#endif /* INCLUDED_MB_TIME_H */ diff --git a/mblock/src/lib/.gitignore b/mblock/src/lib/.gitignore deleted file mode 100644 index b2a2f45a7a..0000000000 --- a/mblock/src/lib/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/test_mblock -/qa_bitset_mbh.cc -/benchmark_send -/getres diff --git a/mblock/src/lib/Makefile.am b/mblock/src/lib/Makefile.am deleted file mode 100644 index dbdfcdd9d5..0000000000 --- a/mblock/src/lib/Makefile.am +++ /dev/null @@ -1,132 +0,0 @@ -# -# Copyright 2006,2007,2008,2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_INCLUDES) $(GRUEL_INCLUDES) \ - $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) \ - $(MBLOCK_INCLUDES) - -# disable test until we fix ticket:180 -# TESTS = test_mblock - -lib_LTLIBRARIES = libmblock.la libmblock-qa.la - -EXTRA_DIST = \ - README.locking \ - qa_bitset.mbh - - -BUILT_SOURCES = \ - qa_bitset_mbh.cc - -qa_bitset_mbh.cc : qa_bitset.mbh - $(COMPILE_MBH) $(srcdir)/qa_bitset.mbh qa_bitset_mbh.cc - -# These are the source files that go into the mblock shared library -libmblock_la_SOURCES = \ - mb_class_registry.cc \ - mb_connection.cc \ - mb_endpoint.cc \ - mb_exception.cc \ - mb_gettid.cc \ - mb_mblock.cc \ - mb_mblock_impl.cc \ - mb_message.cc \ - mb_msg_accepter.cc \ - mb_msg_accepter_msgq.cc \ - mb_msg_accepter_smp.cc \ - mb_msg_queue.cc \ - mb_port.cc \ - mb_port_simple.cc \ - mb_protocol_class.cc \ - mb_runtime.cc \ - mb_runtime_base.cc \ - mb_runtime_nop.cc \ - mb_runtime_thread_per_block.cc \ - mb_timer_queue.cc \ - mb_util.cc \ - mb_worker.cc - - -# magic flags -libmblock_la_LDFLAGS = $(NO_UNDEFINED) - -# link the library against the c++ standard library -libmblock_la_LIBADD = \ - $(OMNITHREAD_LA) \ - $(GRUEL_LA) \ - -lstdc++ - -noinst_HEADERS = \ - mb_gettid.h \ - mb_msg_accepter_msgq.h \ - mb_port_simple.h \ - mb_util.h \ - mb_connection.h \ - mb_endpoint.h \ - mb_mblock_impl.h \ - mb_msg_accepter_smp.h \ - mb_runtime_base.h \ - mb_runtime_nop.h \ - mb_runtime_thread_per_block.h \ - mb_timer_queue.h \ - mb_worker.h \ - mbi_runtime_lock.h \ - qa_mblock.h \ - qa_mblock_prims.h \ - qa_mblock_send.h \ - qa_mblock_sys.h \ - qa_timeouts.h - - -# Build the qa code into its own library - -libmblock_qa_la_SOURCES = \ - qa_bitset.cc \ - qa_bitset_mbh.cc \ - qa_disconnect.cc \ - qa_mblock.cc \ - qa_mblock_prims.cc \ - qa_mblock_send.cc \ - qa_mblock_sys.cc \ - qa_timeouts.cc - - -# magic flags -libmblock_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version - -# link the library against the c++ standard library -libmblock_qa_la_LIBADD = \ - libmblock.la \ - $(CPPUNIT_LIBS) \ - -lstdc++ - - -noinst_PROGRAMS = \ - test_mblock \ - benchmark_send - -test_mblock_SOURCES = test_mblock.cc -test_mblock_LDADD = libmblock-qa.la - -benchmark_send_SOURCES = benchmark_send.cc -benchmark_send_LDADD = libmblock-qa.la diff --git a/mblock/src/lib/README.locking b/mblock/src/lib/README.locking deleted file mode 100644 index 12d4735e72..0000000000 --- a/mblock/src/lib/README.locking +++ /dev/null @@ -1,4 +0,0 @@ -The Big Runtime Lock must be held when: - -Manipulating or traversing any mblock's d_port_map, d_comp_map or d_conn_table. - diff --git a/mblock/src/lib/benchmark_send.cc b/mblock/src/lib/benchmark_send.cc deleted file mode 100644 index a02b37c0d5..0000000000 --- a/mblock/src/lib/benchmark_send.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <mblock/runtime.h> -#include <iostream> - -using namespace pmt; - -int -main(int argc, char **argv) -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 1000000; - long batch_size = 100; - - pmt_t arg = pmt_list2(pmt_from_long(nmsgs), // # of messages to send through pipe - pmt_from_long(batch_size)); - - rt->run("top", "qa_bitset_top", arg, &result); - - if (!pmt_equal(PMT_T, result)){ - std::cerr << "benchmark_send: incorrect result"; - return 1; - } - - return 0; -} diff --git a/mblock/src/lib/getres.cc b/mblock/src/lib/getres.cc deleted file mode 100644 index c05ba792a5..0000000000 --- a/mblock/src/lib/getres.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include <time.h> -#include <stdio.h> - -int -main(int argc, char **argv) -{ - bool ok = true; - struct timespec ts; - int r; - - r = clock_getres(CLOCK_REALTIME, &ts); - if (r != 0){ - perror("clock_getres(CLOCK_REALTIME, ...)"); - ok = false; - } - else - printf("clock_getres(CLOCK_REALTIME, ...) => %11.9f\n", - (double) ts.tv_sec + ts.tv_nsec * 1e-9); - - - r = clock_getres(CLOCK_MONOTONIC, &ts); - if (r != 0){ - perror("clock_getres(CLOCK_MONOTONIC, ..."); - ok = false; - } - else - printf("clock_getres(CLOCK_MONOTONIC, ...) => %11.9f\n", - (double) ts.tv_sec + ts.tv_nsec * 1e-9); - - - return ok == true ? 0 : 1; -} diff --git a/mblock/src/lib/mb_class_registry.cc b/mblock/src/lib/mb_class_registry.cc deleted file mode 100644 index 7ccee2969f..0000000000 --- a/mblock/src/lib/mb_class_registry.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/class_registry.h> -#include <map> - -static std::map<std::string, mb_mblock_maker_t> s_registry; - -bool -mb_class_registry::register_maker(const std::string &name, mb_mblock_maker_t maker) -{ - s_registry[name] = maker; - return true; -} - -bool -mb_class_registry::lookup_maker(const std::string &name, mb_mblock_maker_t *maker) -{ - if (s_registry.count(name) == 0){ // not registered - *maker = (mb_mblock_maker_t) 0; - return false; - } - - *maker = s_registry[name]; - return true; -} diff --git a/mblock/src/lib/mb_connection.cc b/mblock/src/lib/mb_connection.cc deleted file mode 100644 index 7e3bb8977f..0000000000 --- a/mblock/src/lib/mb_connection.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mb_connection.h> - -bool -mb_conn_table::lookup_conn_by_name(const std::string &component_name, - const std::string &port_name, - mb_conn_iter *itp, int *which_ep) -{ - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; ++it){ - - if (it->d_ep[0].component_name() == component_name - && it->d_ep[0].port_name() == port_name){ - *itp = it; - *which_ep = 0; - return true; - } - - if (it->d_ep[1].component_name() == component_name - && it->d_ep[1].port_name() == port_name){ - *itp = it; - *which_ep = 1; - return true; - } - } - - return false; -} - -bool -mb_conn_table::lookup_conn_by_port(const mb_port *port, - mb_conn_iter *itp, int *which_ep) -{ - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; ++it){ - if (it->d_ep[0].port().get() == port){ - *itp = it; - *which_ep = 0; - return true; - } - if (it->d_ep[1].port().get() == port){ - *itp = it; - *which_ep = 1; - return true; - } - } - - return false; -} - -void -mb_conn_table::create_conn(const mb_endpoint &ep0, const mb_endpoint &ep1) -{ - d_connections.push_back(mb_connection(ep0, ep1)); -} - -void -mb_conn_table::disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - mb_conn_iter it; - int which_ep; - - // look for comp_name1/port_name1 - bool found = lookup_conn_by_name(comp_name1, port_name1, &it, &which_ep); - - if (!found) // no error if not found - return; - - // FIXME if/when we do replicated ports, we may have one-to-many, - // or many-to-many bindings. For now, be paranoid - assert(it->d_ep[which_ep^1].component_name() == comp_name2); - assert(it->d_ep[which_ep^1].port_name() == port_name2); - - d_connections.erase(it); // Poof! -} - -void -mb_conn_table::disconnect_component(const std::string component_name) -{ - mb_conn_iter next; - mb_conn_iter end = d_connections.end(); - for (mb_conn_iter it = d_connections.begin(); it != end; it = next){ - if (it->d_ep[0].component_name() == component_name - || it->d_ep[1].component_name() == component_name) - next = d_connections.erase(it); // Poof! - else - next = ++it; - } -} - -void -mb_conn_table::disconnect_all() -{ - d_connections.clear(); // All gone! -} - -int -mb_conn_table::nconnections() const -{ - return d_connections.size(); -} diff --git a/mblock/src/lib/mb_connection.h b/mblock/src/lib/mb_connection.h deleted file mode 100644 index 2aa604054f..0000000000 --- a/mblock/src/lib/mb_connection.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_CONNECTION_H -#define INCLUDED_MB_CONNECTION_H - -#include <mb_endpoint.h> -#include <list> - -/*! - * \brief Representation of a connection - */ -struct mb_connection { - mb_endpoint d_ep[2]; - - mb_connection(const mb_endpoint &ep0, const mb_endpoint &ep1){ - d_ep[0] = ep0; - d_ep[1] = ep1; - } -}; - -typedef std::list<mb_connection>::iterator mb_conn_iter; -typedef std::list<mb_connection>::const_iterator mb_conn_const_iter; - -/*! - * \brief data structure that keeps track of connections - */ -class mb_conn_table { - std::list<mb_connection> d_connections; - -public: - bool - lookup_conn_by_name(const std::string &component_name, - const std::string &port_name, - mb_conn_iter *it, int *which_ep); - - bool - lookup_conn_by_port(const mb_port *port, - mb_conn_iter *it, int *which_ep); - - void - create_conn(const mb_endpoint &ep0, const mb_endpoint &ep1); - - - void - disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - void - disconnect_component(const std::string component_name); - - void - disconnect_all(); - - int - nconnections() const; - -}; - -#endif /* INCLUDED_MB_CONNECTION_H */ diff --git a/mblock/src/lib/mb_endpoint.cc b/mblock/src/lib/mb_endpoint.cc deleted file mode 100644 index 721c66b8c4..0000000000 --- a/mblock/src/lib/mb_endpoint.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_endpoint.h> - -using namespace pmt; - -bool -mb_endpoint::inside_of_relay_port_p() const -{ - return d_port->port_type() == mb_port::RELAY && d_component_name == "self"; -} - -pmt_t -mb_endpoint::incoming_message_set() const -{ - if (inside_of_relay_port_p()) // swap incoming and outgoing - return port()->outgoing_message_set(); - else - return port()->incoming_message_set(); -} - -pmt_t -mb_endpoint::outgoing_message_set() const -{ - if (inside_of_relay_port_p()) // swap incoming and outgoing - return port()->incoming_message_set(); - else - return port()->outgoing_message_set(); -} diff --git a/mblock/src/lib/mb_endpoint.h b/mblock/src/lib/mb_endpoint.h deleted file mode 100644 index c4d8b6114f..0000000000 --- a/mblock/src/lib/mb_endpoint.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_ENDPOINT_H -#define INCLUDED_MB_ENDPOINT_H - -#include <string> -#include <mblock/port.h> - -/*! - * \brief Endpoint specification for connection - */ -class mb_endpoint -{ - std::string d_component_name; - std::string d_port_name; - mb_port_sptr d_port; // the port object that this maps to - -public: - mb_endpoint(){} - - mb_endpoint(const std::string &component_name, - const std::string &port_name, - mb_port_sptr port) - : d_component_name(component_name), - d_port_name(port_name), - d_port(port) {} - - const std::string &component_name() const { return d_component_name; } - const std::string &port_name() const { return d_port_name; } - mb_port_sptr port() const { return d_port; } - - //! Does this endpoint represent the inside of a relay port - bool inside_of_relay_port_p() const; - - pmt::pmt_t incoming_message_set() const; - pmt::pmt_t outgoing_message_set() const; -}; - -#endif /* INCLUDED_MB_ENDPOINT_H */ diff --git a/mblock/src/lib/mb_exception.cc b/mblock/src/lib/mb_exception.cc deleted file mode 100644 index 810131840d..0000000000 --- a/mblock/src/lib/mb_exception.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_util.h> - - -mbe_base::mbe_base(mb_mblock *mb, const std::string &msg) - : logic_error(msg) // FIXME extract block class name and id and add to msg -{ -} - -mbe_not_implemented::mbe_not_implemented(mb_mblock *mb, const std::string &msg) - : mbe_base(mb, "Not implemented: " + msg) -{ -} - -mbe_no_such_class::mbe_no_such_class(mb_mblock *mb, const std::string &class_name) - : mbe_base(mb, "No such class: " + class_name) -{ -} - -mbe_no_such_component::mbe_no_such_component(mb_mblock *mb, const std::string &component_name) - : mbe_base(mb, "No such component: " + component_name) -{ -} - - -mbe_duplicate_component::mbe_duplicate_component(mb_mblock *mb, const std::string &component_name) - : mbe_base(mb, "Duplicate component: " + component_name) -{ -} - -mbe_no_such_port::mbe_no_such_port(mb_mblock *mb, const std::string &port_name) - : mbe_base(mb, "No such port: " + port_name) -{ -} - -mbe_duplicate_port::mbe_duplicate_port(mb_mblock *mb, const std::string &port_name) - : mbe_base(mb, "Duplicate port: " + port_name) -{ -} - -mbe_already_connected::mbe_already_connected(mb_mblock *mb, - const std::string &comp_name, - const std::string &port_name) - : mbe_base(mb, "Port already connected: " + mb_util::join_names(comp_name, port_name)) -{ -} - - - -mbe_incompatible_ports::mbe_incompatible_ports(mb_mblock *mb, - const std::string &comp1_name, - const std::string &port1_name, - const std::string &comp2_name, - const std::string &port2_name) - : mbe_base(mb, "Incompatible ports: " - + mb_util::join_names(comp1_name, port1_name) + " " - + mb_util::join_names(comp2_name, port2_name)) -{ -} - -mbe_invalid_port_type::mbe_invalid_port_type(mb_mblock *mb, - const std::string &comp_name, - const std::string &port_name) - : mbe_base(mb, "Invalid port type for connection: " + mb_util::join_names(comp_name, port_name)) -{ -} - -mbe_mblock_failed::mbe_mblock_failed(mb_mblock *mb, - const std::string &msg) - : mbe_base(mb, "Message block failed: " + msg) -{ -} - -mbe_terminate::mbe_terminate() -{ -} - -mbe_exit::mbe_exit() -{ -} diff --git a/mblock/src/lib/mb_gettid.cc b/mblock/src/lib/mb_gettid.cc deleted file mode 100644 index 9383d35acd..0000000000 --- a/mblock/src/lib/mb_gettid.cc +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_gettid.h> - -#define NEED_STUB - -#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_UNISTD_H) - -#include <sys/syscall.h> -#include <unistd.h> - -#if defined(SYS_gettid) -#undef NEED_STUB - -int mb_gettid() -{ - return syscall(SYS_gettid); -} - -#endif -#endif - -#if defined(NEED_STUB) - -int -mb_gettid() -{ - return 0; -} - -#endif diff --git a/mblock/src/lib/mb_gettid.h b/mblock/src/lib/mb_gettid.h deleted file mode 100644 index adbad126c9..0000000000 --- a/mblock/src/lib/mb_gettid.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/*! - * \brief Return Linux taskid, or 0 if not available - */ -int mb_gettid(); - diff --git a/mblock/src/lib/mb_mblock.cc b/mblock/src/lib/mb_mblock.cc deleted file mode 100644 index 2e77dc4af9..0000000000 --- a/mblock/src/lib/mb_mblock.cc +++ /dev/null @@ -1,230 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/runtime.h> -#include <mblock/exception.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_halt = pmt_intern("%halt"); - -mb_visitor::~mb_visitor() -{ - // nop base case for virtual destructor. -} - - -mb_mblock::mb_mblock(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : d_impl(mb_mblock_impl_sptr( - new mb_mblock_impl(dynamic_cast<mb_runtime_base*>(runtime), - this, instance_name))) -{ -} - -mb_mblock::~mb_mblock() -{ -} - - -void -mb_mblock::initial_transition() -{ - // default implementation does nothing -} - -void -mb_mblock::handle_message(mb_message_sptr msg) -{ - // default implementation does nothing -} - - -void -mb_mblock::main_loop() -{ - while (1){ - mb_message_sptr msg; - try { - while (1){ - msg = impl()->msgq().get_highest_pri_msg(); - - // check for %halt from %sys-port - if (pmt_eq(msg->port_id(), s_sys_port) && pmt_eq(msg->signal(), s_halt)) - exit(); - - handle_message(msg); - } - } - catch (pmt_exception e){ - std::cerr << "\nmb_mblock::main_loop: ignored pmt_exception: " - << e.what() - << "\nin mblock instance \"" << instance_name() - << "\" while handling message:" - << "\n port_id = " << msg->port_id() - << "\n signal = " << msg->signal() - << "\n data = " << msg->data() - << "\n metatdata = " << msg->metadata() << std::endl; - } - } -} - -//////////////////////////////////////////////////////////////////////// -// Forward other methods to implementation class // -//////////////////////////////////////////////////////////////////////// - -mb_port_sptr -mb_mblock::define_port(const std::string &port_name_string, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) -{ - return d_impl->define_port(port_name_string, protocol_class_name, - conjugated, port_type); -} - -void -mb_mblock::define_component(const std::string &component_name, - const std::string &class_name, - pmt_t user_arg) - -{ - d_impl->define_component(component_name, class_name, user_arg); -} - -void -mb_mblock::connect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - d_impl->connect(comp_name1, port_name1, - comp_name2, port_name2); -} - - -void -mb_mblock::disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2) -{ - d_impl->disconnect(comp_name1, port_name1, - comp_name2, port_name2); -} - -void -mb_mblock::disconnect_component(const std::string &component_name) -{ - d_impl->disconnect_component(component_name); -} - -void -mb_mblock::disconnect_all() -{ - d_impl->disconnect_all(); -} - -int -mb_mblock::nconnections() const -{ - return d_impl->nconnections(); -} - -bool -mb_mblock::walk_tree(mb_visitor *visitor) -{ - return d_impl->walk_tree(visitor); -} - -std::string -mb_mblock::instance_name() const -{ - return d_impl->instance_name(); -} - -void -mb_mblock::set_instance_name(const std::string &name) -{ - d_impl->set_instance_name(name); -} - -std::string -mb_mblock::class_name() const -{ - return d_impl->class_name(); -} - -void -mb_mblock::set_class_name(const std::string &name) -{ - d_impl->set_class_name(name); -} - -mb_mblock * -mb_mblock::parent() const -{ - return d_impl->mblock_parent(); -} - -void -mb_mblock::exit() -{ - throw mbe_exit(); // adios... -} - -void -mb_mblock::shutdown_all(pmt_t result) -{ - d_impl->runtime()->request_shutdown(result); -} - -pmt_t -mb_mblock::schedule_one_shot_timeout(const mb_time &abs_time, pmt_t user_data) -{ - mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port); - return d_impl->runtime()->schedule_one_shot_timeout(abs_time, user_data, - accepter); -} - -pmt_t -mb_mblock::schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data) -{ - mb_msg_accepter_sptr accepter = impl()->make_accepter(s_sys_port); - return d_impl->runtime()->schedule_periodic_timeout(first_abs_time, - delta_time, - user_data, - accepter); -} - -void -mb_mblock::cancel_timeout(pmt_t handle) -{ - d_impl->runtime()->cancel_timeout(handle); -} - diff --git a/mblock/src/lib/mb_mblock_impl.cc b/mblock/src/lib/mb_mblock_impl.cc deleted file mode 100644 index 8a1784f4dc..0000000000 --- a/mblock/src/lib/mb_mblock_impl.cc +++ /dev/null @@ -1,328 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_mblock_impl.h> -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/port.h> -#include <mb_port_simple.h> -#include <mblock/exception.h> -#include <mb_util.h> -#include <mb_msg_accepter_smp.h> -#include <mbi_runtime_lock.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_self = pmt_intern("self"); - -//////////////////////////////////////////////////////////////////////// - -bool -mb_mblock_impl::port_is_defined(const std::string &name) -{ - return d_port_map.count(name) != 0; -} - -bool -mb_mblock_impl::comp_is_defined(const std::string &name) -{ - return name == "self" || d_comp_map.count(name) != 0; -} - -//////////////////////////////////////////////////////////////////////// - -mb_mblock_impl::mb_mblock_impl(mb_runtime_base *runtime, mb_mblock *mb, - const std::string &instance_name) - : d_runtime(runtime), d_mb(mb), d_mb_parent(0), - d_instance_name(instance_name), d_class_name("mblock") -{ -} - -mb_mblock_impl::~mb_mblock_impl() -{ - d_mb = 0; // we don't own it -} - - -mb_port_sptr -mb_mblock_impl::define_port(const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) -{ - mbi_runtime_lock l(this); - - if (port_is_defined(port_name)) - throw mbe_duplicate_port(d_mb, port_name); - - mb_port_sptr p = - mb_port_sptr(new mb_port_simple(d_mb, - port_name, protocol_class_name, - conjugated, port_type)); - d_port_map[port_name] = p; - return p; -} - -void -mb_mblock_impl::define_component(const std::string &name, - const std::string &class_name, - pmt_t user_arg) -{ - { - mbi_runtime_lock l(this); - - if (comp_is_defined(name)) // check for duplicate name - throw mbe_duplicate_component(d_mb, name); - } - - // We ask the runtime to create the component so that it can worry about - // mblock placement on a NUMA machine or on a distributed multicomputer - - mb_mblock_sptr component = - d_runtime->create_component(instance_name() + "/" + name, - class_name, user_arg); - { - mbi_runtime_lock l(this); - - component->d_impl->d_mb_parent = d_mb; // set component's parent link - d_comp_map[name] = component; - } -} - -void -mb_mblock_impl::connect(const std::string &comp_name1, - const std::string &port_name1, - const std::string &comp_name2, - const std::string &port_name2) -{ - mbi_runtime_lock l(this); - - mb_endpoint ep0 = check_and_resolve_endpoint(comp_name1, port_name1); - mb_endpoint ep1 = check_and_resolve_endpoint(comp_name2, port_name2); - - if (!endpoints_are_compatible(ep0, ep1)) - throw mbe_incompatible_ports(d_mb, - comp_name1, port_name1, - comp_name2, port_name2); - // FIXME more checks? - - d_conn_table.create_conn(ep0, ep1); -} - -void -mb_mblock_impl::disconnect(const std::string &comp_name1, - const std::string &port_name1, - const std::string &comp_name2, - const std::string &port_name2) -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect(comp_name1, port_name1, comp_name2, port_name2); - invalidate_all_port_caches(); -} - -void -mb_mblock_impl::disconnect_component(const std::string component_name) -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect_component(component_name); - invalidate_all_port_caches(); -} - -void -mb_mblock_impl::disconnect_all() -{ - mbi_runtime_lock l(this); - - d_conn_table.disconnect_all(); - invalidate_all_port_caches(); -} - -int -mb_mblock_impl::nconnections() -{ - mbi_runtime_lock l(this); - - return d_conn_table.nconnections(); -} - -//////////////////////////////////////////////////////////////////////// - -mb_endpoint -mb_mblock_impl::check_and_resolve_endpoint(const std::string &comp_name, - const std::string &port_name) -{ - mb_conn_iter it; - int which_ep; - mb_port_sptr port = resolve_port(comp_name, port_name); - - // Confirm that we're not trying to connect to the inside of one of - // our EXTERNAL ports. Connections that include "self" as the - // component name must be either INTERNAL or RELAY. - - if (comp_name == "self" && port->port_type() == mb_port::EXTERNAL) - throw mbe_invalid_port_type(d_mb, comp_name, port_name); - - // Is this endpoint already connected? - if (d_conn_table.lookup_conn_by_name(comp_name, port_name, &it, &which_ep)) - throw mbe_already_connected(d_mb, comp_name, port_name); - - return mb_endpoint(comp_name, port_name, port); -} - -mb_port_sptr -mb_mblock_impl::resolve_port(const std::string &comp_name, - const std::string &port_name) -{ - if (comp_name == "self"){ - // Look through our ports. - if (!port_is_defined(port_name)) - throw mbe_no_such_port(d_mb, mb_util::join_names("self", port_name)); - return d_port_map[port_name]; - } - else { - // Look through the specified child's ports. - if (!comp_is_defined(comp_name)) - throw mbe_no_such_component(d_mb, comp_name); - - mb_mblock_impl_sptr c_impl = d_comp_map[comp_name]->d_impl; // childs impl pointer - if (!c_impl->port_is_defined(port_name)) - throw mbe_no_such_port(d_mb, mb_util::join_names(comp_name, port_name)); - - mb_port_sptr c_port = c_impl->d_port_map[port_name]; - - if (c_port->port_type() == mb_port::INTERNAL) // can't "see" a child's internal ports - throw mbe_no_such_port(d_mb, mb_util::join_names(comp_name, port_name)); - - return c_port; - } -} - - - -bool -mb_mblock_impl::endpoints_are_compatible(const mb_endpoint &ep0, - const mb_endpoint &ep1) -{ - pmt_t p0_outgoing = ep0.outgoing_message_set(); - pmt_t p0_incoming = ep0.incoming_message_set(); - - pmt_t p1_outgoing = ep1.outgoing_message_set(); - pmt_t p1_incoming = ep1.incoming_message_set(); - - return (pmt_subsetp(p0_outgoing, p1_incoming) - && pmt_subsetp(p1_outgoing, p0_incoming)); -} - -bool -mb_mblock_impl::walk_tree(mb_visitor *visitor) -{ - if (!(*visitor)(d_mb)) - return false; - - mb_comp_map_t::iterator it; - for (it = d_comp_map.begin(); it != d_comp_map.end(); ++it) - if (!(it->second->walk_tree(visitor))) - return false; - - return true; -} - -mb_msg_accepter_sptr -mb_mblock_impl::make_accepter(pmt_t port_name) -{ - // FIXME this should probably use some kind of configurable factory - mb_msg_accepter *ma = - new mb_msg_accepter_smp(d_mb->shared_from_this(), port_name); - - return mb_msg_accepter_sptr(ma); -} - -bool -mb_mblock_impl::lookup_other_endpoint(const mb_port *port, mb_endpoint *ep) -{ - mb_conn_iter it; - int which_ep = 0; - - if (!d_conn_table.lookup_conn_by_port(port, &it, &which_ep)) - return false; - - *ep = it->d_ep[which_ep^1]; - return true; -} - -mb_mblock_sptr -mb_mblock_impl::component(const std::string &comp_name) -{ - if (comp_name == "self") - return d_mb->shared_from_this(); - - if (d_comp_map.count(comp_name) == 0) - return mb_mblock_sptr(); // null pointer - - return d_comp_map[comp_name]; -} - -void -mb_mblock_impl::set_instance_name(const std::string &name) -{ - d_instance_name = name; -} - -void -mb_mblock_impl::set_class_name(const std::string &name) -{ - d_class_name = name; -} - -/* - * This is the "Big Hammer" port cache invalidator. - * It invalidates _all_ of the port caches in the entire mblock tree. - * It's overkill, but was simple to code. - */ -void -mb_mblock_impl::invalidate_all_port_caches() -{ - class invalidator : public mb_visitor - { - public: - bool operator()(mb_mblock *mblock) - { - mb_mblock_impl_sptr impl = mblock->impl(); - mb_port_map_t::iterator it = impl->d_port_map.begin(); - mb_port_map_t::iterator end = impl->d_port_map.end(); - for (; it != end; ++it) - it->second->invalidate_cache(); - return true; - } - }; - - invalidator visitor; - - // Always true, except in early QA code - if (runtime()->top()) - runtime()->top()->walk_tree(&visitor); -} diff --git a/mblock/src/lib/mb_mblock_impl.h b/mblock/src/lib/mb_mblock_impl.h deleted file mode 100644 index f460ecc5b1..0000000000 --- a/mblock/src/lib/mb_mblock_impl.h +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MBLOCK_IMPL_H -#define INCLUDED_MB_MBLOCK_IMPL_H - -#include <mblock/mblock.h> -#include <mb_runtime_base.h> -#include <mb_connection.h> -#include <mblock/msg_queue.h> -#include <list> -#include <map> - - -typedef std::map<std::string, mb_port_sptr> mb_port_map_t; -typedef std::map<std::string, mb_mblock_sptr> mb_comp_map_t; - - -/*! - * \brief The private implementation details of the mblock system. - */ -class mb_mblock_impl : boost::noncopyable -{ - mb_runtime_base *d_runtime; // pointer to runtime - mb_mblock *d_mb; // pointer to our associated mblock - mb_mblock *d_mb_parent; // pointer to our parent - - std::string d_instance_name; // hierarchical name - std::string d_class_name; // name of this (derived) class - - mb_port_map_t d_port_map; // our ports - mb_comp_map_t d_comp_map; // our components - mb_conn_table d_conn_table; // our connections - - mb_msg_queue d_msgq; // incoming messages for us - -public: - mb_mblock_impl(mb_runtime_base *runtime, mb_mblock *mb, - const std::string &instance_name); - ~mb_mblock_impl(); - - /*! - * \brief Define a port. - * - * EXTERNAL and RELAY ports are part of our peer interface. - * INTERNAL ports are used to talk to sub-components. - * - * \param port_name The name of the port (must be unique within this mblock). - * \param protocol_class_name The name of the protocol class associated with - * this port. It must already be defined. - * \param conjugated Are the incoming and outgoing message sets swapped? - * \param port_type INTERNAL, EXTERNAL or RELAY. - */ - mb_port_sptr - define_port(const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - /*! - * \brief Define a subcomponent by name. - * - * Called within the constructor to tell the system the - * names and identities of our sub-component mblocks. - * - * \param component_name The name of the sub-component (must be unique with this mblock). - * \param class_name The class of the instance that is to be created. - * \param user_arg The argument to pass to the constructor of the component. - */ - void - define_component(const std::string &component_name, - const std::string &class_name, - pmt::pmt_t user_arg); - - /*! - * \brief connect endpoint_1 to endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To connect an internal or relay port, use "self" as the component name. - */ - void - connect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect endpoint_1 from endpoint_2 - * - * \param comp_name1 component on one end of the connection - * \param port_name1 the name of the port on comp1 - * \param comp_name2 component on the other end of the connection - * \param port_name2 the name of the port on comp2 - * - * An endpoint is specified by the component's local name (given as - * component_name in the call to register_component) and the name of - * the port on that component. - * - * To disconnect an internal or relay port, use "self" as the component name. - */ - void - disconnect(const std::string &comp_name1, const std::string &port_name1, - const std::string &comp_name2, const std::string &port_name2); - - /*! - * \brief disconnect all connections to specified component - * \param component_name component to disconnect - */ - void - disconnect_component(const std::string component_name); - - /*! - * \brief disconnect all connections to all components - */ - void - disconnect_all(); - - /*! - * \brief Return number of connections (QA mostly) - */ - int - nconnections(); - - bool - walk_tree(mb_visitor *visitor); - - mb_msg_accepter_sptr - make_accepter(pmt::pmt_t port_name); - - mb_msg_queue & - msgq() { return d_msgq; } - - //! Return instance name of this block - std::string instance_name() const { return d_instance_name; } - - //! Set the instance name of this block - void set_instance_name(const std::string &name); - - //! Return the class name of this block - std::string class_name() const { return d_class_name; } - - //! Set the class name - void set_class_name(const std::string &name); - - /*! - * \brief If bound, store endpoint from the other end of the connection. - * - * \param port [in] port the port that we're searching for. - * \param ep [out] the other end point from the matching connection. - * - * \returns true iff there's a matching connection. - */ - bool - lookup_other_endpoint(const mb_port *port, mb_endpoint *ep); - - - //! Return point to associated mblock - mb_mblock *mblock() const { return d_mb; } - - //! Return pointer to the parent of our mblock - mb_mblock *mblock_parent() const { return d_mb_parent; } - - //! Lookup a component by name - mb_mblock_sptr component(const std::string &comp_name); - - //! Return the runtime instance - mb_runtime_base *runtime() { return d_runtime; } - - //! Set the runtime instance - void set_runtime(mb_runtime_base *runtime) { d_runtime = runtime; } - - /* - * Our implementation methods - */ -private: - //bool port_is_defined(pmt::pmt_t name); - bool port_is_defined(const std::string &name); - //bool comp_is_defined(pmt::pmt_t name); - bool comp_is_defined(const std::string &name); - - mb_endpoint - check_and_resolve_endpoint(const std::string &comp_name, - const std::string &port_name); - - - mb_port_sptr - resolve_port(const std::string &comp_name, - const std::string &port_name); - - static bool - endpoints_are_compatible(const mb_endpoint &ep0, - const mb_endpoint &ep1); - - /*! - * \brief walk mblock tree and invalidate all port resolution caches. - * \internal - */ - void - invalidate_all_port_caches(); -}; - - -#endif /* INCLUDED_MB_MBLOCK_IMPL_H */ diff --git a/mblock/src/lib/mb_message.cc b/mblock/src/lib/mb_message.cc deleted file mode 100644 index 4daa340796..0000000000 --- a/mblock/src/lib/mb_message.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/message.h> -#include <stdio.h> -#include <gruel/pmt_pool.h> - -using namespace pmt; - -static const int CACHE_LINE_SIZE = 64; // good guess -static const int MAX_MESSAGES = 1024; // KLUDGE max number of messages in sys - // 0 -> no limit -#if MB_MESSAGE_LOCAL_ALLOCATOR - -static pmt_pool -global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE, 16*1024, MAX_MESSAGES); - -void * -mb_message::operator new(size_t size) -{ - void *p = global_msg_pool.malloc(); - - // fprintf(stderr, "mb_message::new p = %p\n", p); - assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0); - return p; -} - -void -mb_message::operator delete(void *p, size_t size) -{ - global_msg_pool.free(p); -} - -#endif - - -mb_message_sptr -mb_make_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) -{ - return mb_message_sptr(new mb_message(signal, data, metadata, priority)); -} - -mb_message::mb_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) - : d_signal(signal), d_data(data), d_metadata(metadata), d_priority(priority), - d_port_id(PMT_NIL) -{ -} - -mb_message::~mb_message() -{ - // NOP -} - -std::ostream& -operator<<(std::ostream& os, const mb_message &msg) -{ - os << "<msg: signal=" << msg.signal() - << " port_id=" << msg.port_id() - << " data=" << msg.data() - << " metadata=" << msg.metadata() - << " pri=" << msg.priority() - << ">"; - - return os; -} diff --git a/mblock/src/lib/mb_msg_accepter.cc b/mblock/src/lib/mb_msg_accepter.cc deleted file mode 100644 index 88b92394c4..0000000000 --- a/mblock/src/lib/mb_msg_accepter.cc +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/msg_accepter.h> - -mb_msg_accepter::~mb_msg_accepter() -{ - // nop -} diff --git a/mblock/src/lib/mb_msg_accepter_msgq.cc b/mblock/src/lib/mb_msg_accepter_msgq.cc deleted file mode 100644 index 6c74ac47a8..0000000000 --- a/mblock/src/lib/mb_msg_accepter_msgq.cc +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_msg_accepter_msgq.h> -#include <mblock/message.h> - -using namespace pmt; - -pmt_t s_sys_port = pmt_intern("%sys-port"); - -mb_msg_accepter_msgq::mb_msg_accepter_msgq(mb_msg_queue *msgq) - : d_msgq(msgq) -{ -} - -mb_msg_accepter_msgq::~mb_msg_accepter_msgq() -{ -} - -void -mb_msg_accepter_msgq::operator()(pmt_t signal, pmt_t data, - pmt_t metadata, mb_pri_t priority) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(s_sys_port); - d_msgq->insert(msg); -} diff --git a/mblock/src/lib/mb_msg_accepter_msgq.h b/mblock/src/lib/mb_msg_accepter_msgq.h deleted file mode 100644 index f84bca596c..0000000000 --- a/mblock/src/lib/mb_msg_accepter_msgq.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_ACCEPTER_MSGQ_H -#define INCLUDED_MB_MSG_ACCEPTER_MSGQ_H - -#include <mblock/msg_accepter.h> -#include <mblock/msg_queue.h> - -/*! - * \brief Concrete class that accepts messages and inserts them into a message queue. - */ -class mb_msg_accepter_msgq : public mb_msg_accepter { - mb_msg_queue *d_msgq; - -public: - mb_msg_accepter_msgq(mb_msg_queue *msgq); - ~mb_msg_accepter_msgq(); - void operator()(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); -}; - -#endif /* INCLUDED_MB_MSG_ACCEPTER_MSGQ_H */ diff --git a/mblock/src/lib/mb_msg_accepter_smp.cc b/mblock/src/lib/mb_msg_accepter_smp.cc deleted file mode 100644 index 1ec8c5bfd5..0000000000 --- a/mblock/src/lib/mb_msg_accepter_smp.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_msg_accepter_smp.h> -#include <mblock/common.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/message.h> - -using namespace pmt; - -mb_msg_accepter_smp::mb_msg_accepter_smp(mb_mblock_sptr mblock, pmt_t port_name) - : d_mb(mblock), d_port_name(port_name) -{ -} - -mb_msg_accepter_smp::~mb_msg_accepter_smp() -{ - // nop -} - -void -mb_msg_accepter_smp::operator()(pmt_t signal, pmt_t data, - pmt_t metadata, mb_pri_t priority) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(d_port_name); - d_mb->impl()->msgq().insert(msg); -} diff --git a/mblock/src/lib/mb_msg_accepter_smp.h b/mblock/src/lib/mb_msg_accepter_smp.h deleted file mode 100644 index 3028484f73..0000000000 --- a/mblock/src/lib/mb_msg_accepter_smp.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_MSG_ACCEPTER_SMP_H -#define INCLUDED_MB_MSG_ACCEPTER_SMP_H - -#include <mblock/msg_accepter.h> - -/*! - * \brief Concrete message acceptor that does an mb_msg_queue insertion - */ -class mb_msg_accepter_smp : public mb_msg_accepter -{ - mb_mblock_sptr d_mb; - pmt::pmt_t d_port_name; - -public: - mb_msg_accepter_smp(mb_mblock_sptr mblock, pmt::pmt_t port_name); - ~mb_msg_accepter_smp(); - - void operator()(pmt::pmt_t signal, pmt::pmt_t data, pmt::pmt_t metadata, mb_pri_t priority); -}; - - -#endif /* INCLUDED_MB_MSG_ACCEPTER_SMP_H */ diff --git a/mblock/src/lib/mb_msg_queue.cc b/mblock/src/lib/mb_msg_queue.cc deleted file mode 100644 index c68c5fd64b..0000000000 --- a/mblock/src/lib/mb_msg_queue.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/msg_queue.h> -#include <mblock/message.h> - - -mb_msg_queue::mb_msg_queue() - : d_not_empty(&d_mutex) -{ -} - -mb_msg_queue::~mb_msg_queue() -{ -} - -void -mb_msg_queue::insert(mb_message_sptr msg) -{ - omni_mutex_lock l(d_mutex); - - mb_pri_t q = mb_pri_clamp(msg->priority()); - - if (d_queue[q].empty_p()){ - d_queue[q].tail = d_queue[q].head = msg; - msg->d_next.reset(); //msg->d_next = 0; - } - else { - d_queue[q].tail->d_next = msg; - d_queue[q].tail = msg; - msg->d_next.reset(); // msg->d_next = 0; - } - - // FIXME set bit in bitmap - - d_not_empty.signal(); -} - -/* - * Delete highest pri message from the queue and return it. - * Returns equivalent of zero pointer if queue is empty. - * - * Caller must be holding d_mutex - */ -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_helper() -{ - // FIXME use bitmap and ffz to find best queue in O(1) - - for (mb_pri_t q = 0; q <= MB_PRI_WORST; q++){ - - if (!d_queue[q].empty_p()){ - mb_message_sptr msg = d_queue[q].head; - d_queue[q].head = msg->d_next; - if (d_queue[q].head == 0){ - d_queue[q].tail.reset(); // d_queue[q].tail = 0; - // FIXME clear bit in bitmap - } - - msg->d_next.reset(); // msg->d_next = 0; - return msg; - } - } - - return mb_message_sptr(); // eqv to a zero pointer -} - - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_nowait() -{ - omni_mutex_lock l(d_mutex); - - return get_highest_pri_msg_helper(); -} - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg() -{ - omni_mutex_lock l(d_mutex); - - while (1){ - mb_message_sptr msg = get_highest_pri_msg_helper(); - if (msg) // Got one; return it - return msg; - - d_not_empty.wait(); // Wait for something - } -} - -mb_message_sptr -mb_msg_queue::get_highest_pri_msg_timedwait(const mb_time &abs_time) -{ - unsigned long secs = abs_time.d_secs; - unsigned long nsecs = abs_time.d_nsecs; - - omni_mutex_lock l(d_mutex); - - while (1){ - mb_message_sptr msg = get_highest_pri_msg_helper(); - if (msg) // Got one; return it - return msg; - - if (!d_not_empty.timedwait(secs, nsecs)) // timed out - return mb_message_sptr(); // eqv to zero pointer - } -} diff --git a/mblock/src/lib/mb_port.cc b/mblock/src/lib/mb_port.cc deleted file mode 100644 index a26a2c4140..0000000000 --- a/mblock/src/lib/mb_port.cc +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/port.h> -#include <mblock/protocol_class.h> - -using namespace pmt; - -mb_port::mb_port(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) - : d_port_name(port_name), d_port_symbol(pmt_intern(port_name)), - d_conjugated(conjugated), d_port_type(port_type), - d_mblock(mblock) -{ - pmt_t pc = mb_protocol_class_lookup(pmt_intern(protocol_class_name)); - if (pmt_is_null(pc)){ - throw std::runtime_error("mb_port: unknown protocol class '" - + protocol_class_name + "'"); - } - d_protocol_class = pc; -} - -mb_port::~mb_port() -{ - // nop -} - -pmt_t -mb_port::incoming_message_set() const -{ - if (!conjugated()) - return mb_protocol_class_incoming(protocol_class()); - else // swap the sets - return mb_protocol_class_outgoing(protocol_class()); -} - -pmt_t -mb_port::outgoing_message_set() const -{ - if (!conjugated()) - return mb_protocol_class_outgoing(protocol_class()); - else // swap the sets - return mb_protocol_class_incoming(protocol_class()); -} diff --git a/mblock/src/lib/mb_port_simple.cc b/mblock/src/lib/mb_port_simple.cc deleted file mode 100644 index 235e59de22..0000000000 --- a/mblock/src/lib/mb_port_simple.cc +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mb_port_simple.h> -#include <mblock/msg_accepter.h> -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <assert.h> -#include <mbi_runtime_lock.h> - -using namespace pmt; - -mb_port_simple::mb_port_simple(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type) - : mb_port(mblock, port_name, protocol_class_name, conjugated, port_type), - d_cache_valid(false) -{ -} - -mb_port_simple::~mb_port_simple() -{ - // nop -} - -void -mb_port_simple::send(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority) -{ - if (port_type() == mb_port::RELAY) // Can't send directly to a RELAY port - throw mbe_invalid_port_type(mblock(), mblock()->instance_name(), port_name()); - - mb_msg_accepter_sptr accepter = find_accepter(this); - if (accepter) - (*accepter)(signal, data, metadata, priority); -} - - -mb_msg_accepter_sptr -mb_port_simple::find_accepter(mb_port_simple *start) -{ - mb_port_simple *p = start; - mb_port_simple *pp = 0; - mb_mblock *context = 0; - mb_endpoint peer_ep; - mb_msg_accepter_sptr r; - - if (start->d_cache_valid) - return start->d_cached_accepter; - - mbi_runtime_lock l(p->mblock()); - - // Set up initial context. - - switch(p->port_type()){ - case mb_port::INTERNAL: // binding is in our name space - context = p->mblock(); - break; - - case mb_port::EXTERNAL: // binding is in parent's name space - context = p->mblock()->parent(); - if (!context) // can't be bound if there's no parent - return mb_msg_accepter_sptr(); // not bound - break; - - default: - throw std::logic_error("Can't happen: mb_port_simple::find_accepter [1]"); - } - - - traverse: - - if (!context->impl()->lookup_other_endpoint(p, &peer_ep)) - return mb_msg_accepter_sptr(); // not bound - - pp = dynamic_cast<mb_port_simple *>(peer_ep.port().get()); // peer port - assert(pp); - - switch (pp->port_type()){ - case mb_port::INTERNAL: // Terminate here. - case mb_port::EXTERNAL: - r = pp->make_accepter(); - - // cache the result - - start->d_cached_accepter = r; - start->d_cache_valid = true; - return r; - - case mb_port::RELAY: // Traverse to other side of relay port. - if (peer_ep.inside_of_relay_port_p()){ - // We're on inside of relay port, headed out. - p = pp; - context = p->mblock()->parent(); - - // Corner case: we're attempting to traverse a relay port on the border - // of the top block... - if (!context) - return mb_msg_accepter_sptr(); // not bound - - goto traverse; - } - else { - // We're on the outside of relay port, headed in. - p = pp; - context = p->mblock(); - goto traverse; - } - break; - - default: - throw std::logic_error("Can't happen: mb_port_simple::find_accepter [2]"); - } -} - - -mb_msg_accepter_sptr -mb_port_simple::make_accepter() -{ - return d_mblock->impl()->make_accepter(port_symbol()); -} - -void -mb_port_simple::invalidate_cache() -{ - d_cache_valid = false; - d_cached_accepter.reset(); -} diff --git a/mblock/src/lib/mb_port_simple.h b/mblock/src/lib/mb_port_simple.h deleted file mode 100644 index 485c809fe6..0000000000 --- a/mblock/src/lib/mb_port_simple.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_PORT_SIMPLE_H -#define INCLUDED_MB_PORT_SIMPLE_H - -#include <mblock/port.h> - -/*! - * \brief Concrete port realization - */ -class mb_port_simple : public mb_port -{ - bool d_cache_valid; - mb_msg_accepter_sptr d_cached_accepter; - -protected: - static mb_msg_accepter_sptr - find_accepter(mb_port_simple *start); - - mb_msg_accepter_sptr - make_accepter(); - -public: - mb_port_simple(mb_mblock *mblock, - const std::string &port_name, - const std::string &protocol_class_name, - bool conjugated, - mb_port::port_type_t port_type); - - ~mb_port_simple(); - - /*! - * \brief send a message - * - * \param signal the event name - * \param data optional data - * \param metadata optional metadata - * \param priority the urgency at which the message is sent - */ - void - send(pmt::pmt_t signal, - pmt::pmt_t data = pmt::PMT_NIL, - pmt::pmt_t metadata = pmt::PMT_NIL, - mb_pri_t priority = MB_PRI_DEFAULT); - - /* - * \brief Invalidate any cached peer resolutions - * \internal - */ - void invalidate_cache(); - -}; - -#endif /* INCLUDED_MB_PORT_SIMPLE_H */ diff --git a/mblock/src/lib/mb_protocol_class.cc b/mblock/src/lib/mb_protocol_class.cc deleted file mode 100644 index 1c696fb7c0..0000000000 --- a/mblock/src/lib/mb_protocol_class.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/protocol_class.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_ALL_PROTOCOL_CLASSES = PMT_NIL; - -pmt_t -mb_make_protocol_class(pmt_t name, pmt_t incoming, pmt_t outgoing) -{ - // (protocol-class <name> <incoming> <outgoing>) - - if (!pmt_is_symbol(name)) - throw pmt_wrong_type("mb_make_protocol_class: NAME must be symbol", name); - if (!(pmt_is_pair(incoming) || pmt_is_null(incoming))) - throw pmt_wrong_type("mb_make_protocol_class: INCOMING must be a list", name); - if (!(pmt_is_pair(outgoing) || pmt_is_null(outgoing))) - throw pmt_wrong_type("mb_make_protocol_class: OUTGOING must be a list", name); - - pmt_t t = pmt_cons(pmt_intern("protocol-class"), - pmt_cons(name, - pmt_cons(incoming, - pmt_cons(outgoing, PMT_NIL)))); - - // Remember this protocol class. - s_ALL_PROTOCOL_CLASSES = pmt_cons(t, s_ALL_PROTOCOL_CLASSES); - return t; -} - -pmt_t -mb_protocol_class_name(pmt_t pc) -{ - return pmt_nth(1, pc); -} - -pmt_t -mb_protocol_class_incoming(pmt_t pc) -{ - return pmt_nth(2, pc); -} - -pmt_t -mb_protocol_class_outgoing(pmt_t pc) -{ - return pmt_nth(3, pc); -} - -pmt_t -mb_protocol_class_lookup(pmt_t name) -{ - pmt_t lst = s_ALL_PROTOCOL_CLASSES; - - while (pmt_is_pair(lst)){ - if (pmt_eq(name, mb_protocol_class_name(pmt_car(lst)))) - return pmt_car(lst); - lst = pmt_cdr(lst); - } - - return PMT_NIL; -} - -mb_protocol_class_init::mb_protocol_class_init(const char *data, size_t len) -{ - std::stringbuf sb; - sb.str(std::string(data, len)); - - while (1){ - pmt_t obj = pmt_deserialize(sb); - - if (0){ - pmt_write(obj, std::cout); - std::cout << std::endl; - } - - if (pmt_is_eof_object(obj)) - return; - - mb_make_protocol_class(pmt_nth(0, obj), // protocol-class name - pmt_nth(1, obj), // list of incoming msg names - pmt_nth(2, obj)); // list of outgoing msg names - } -} diff --git a/mblock/src/lib/mb_runtime.cc b/mblock/src/lib/mb_runtime.cc deleted file mode 100644 index 57a05c416f..0000000000 --- a/mblock/src/lib/mb_runtime.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/runtime.h> -#include <mb_runtime_thread_per_block.h> - -mb_runtime_sptr -mb_make_runtime() -{ - return mb_runtime_sptr(new mb_runtime_thread_per_block()); -} - -mb_runtime::~mb_runtime() -{ - // nop -} - diff --git a/mblock/src/lib/mb_runtime_base.cc b/mblock/src/lib/mb_runtime_base.cc deleted file mode 100644 index f259a690d5..0000000000 --- a/mblock/src/lib/mb_runtime_base.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_base.h> - -using namespace pmt; - -/* - * Default nop implementations... - */ - -void -mb_runtime_base::request_shutdown(pmt_t result) -{ -} - -pmt_t -mb_runtime_base::schedule_one_shot_timeout(const mb_time &abs_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - return PMT_F; -} - -pmt_t -mb_runtime_base::schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - return PMT_F; -} - -void -mb_runtime_base::cancel_timeout(pmt_t handle) -{ -} - diff --git a/mblock/src/lib/mb_runtime_base.h b/mblock/src/lib/mb_runtime_base.h deleted file mode 100644 index 78be2922da..0000000000 --- a/mblock/src/lib/mb_runtime_base.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_RUNTIME_BASE_H -#define INCLUDED_MB_RUNTIME_BASE_H - -#include <mblock/runtime.h> -#include <gnuradio/omnithread.h> -#include <mblock/time.h> - -/* - * \brief This is the runtime class used by the implementation. - */ -class mb_runtime_base : public mb_runtime -{ - omni_mutex d_brl; // big runtime lock (avoid using this if possible...) - -protected: - mb_msg_accepter_sptr d_accepter; - -public: - - /*! - * \brief lock the big runtime lock - * \internal - */ - inline void lock() { d_brl.lock(); } - - /*! - * \brief unlock the big runtime lock - * \internal - */ - inline void unlock() { d_brl.unlock(); } - - virtual void request_shutdown(pmt::pmt_t result); - - virtual mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg) = 0; - - virtual pmt::pmt_t - schedule_one_shot_timeout(const mb_time &abs_time, pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - - virtual pmt::pmt_t - schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - virtual void - cancel_timeout(pmt::pmt_t handle); - - mb_msg_accepter_sptr - accepter() { return d_accepter; } - -}; - - -#endif /* INCLUDED_MB_RUNTIME_BASE_H */ diff --git a/mblock/src/lib/mb_runtime_nop.cc b/mblock/src/lib/mb_runtime_nop.cc deleted file mode 100644 index 8293e0c241..0000000000 --- a/mblock/src/lib/mb_runtime_nop.cc +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_nop.h> -#include <mblock/mblock.h> -#include <mblock/class_registry.h> -#include <mblock/exception.h> - -using namespace pmt; - -mb_runtime_sptr -mb_make_runtime_nop() -{ - return mb_runtime_sptr(new mb_runtime_nop()); -} - - -mb_runtime_nop::mb_runtime_nop() -{ - // nop for now -} - -mb_runtime_nop::~mb_runtime_nop() -{ - // nop for now -} - - -bool -mb_runtime_nop::run(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg, pmt_t *result) -{ - class initial_visitor : public mb_visitor - { - public: - bool operator()(mb_mblock *mblock) - { - mblock->initial_transition(); - return true; - } - }; - - initial_visitor visitor; - - if (result) - *result = PMT_T; - - d_top = create_component(instance_name, class_name, user_arg); - d_top->walk_tree(&visitor); - - return true; -} - -mb_mblock_sptr -mb_runtime_nop::create_component(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg) -{ - mb_mblock_maker_t maker; - if (!mb_class_registry::lookup_maker(class_name, &maker)) - throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")"); - - return maker(this, instance_name, user_arg); -} diff --git a/mblock/src/lib/mb_runtime_nop.h b/mblock/src/lib/mb_runtime_nop.h deleted file mode 100644 index 735c0405e0..0000000000 --- a/mblock/src/lib/mb_runtime_nop.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_RUNTIME_NOP_H -#define INCLUDED_MB_RUNTIME_NOP_H - -#include <mb_runtime_base.h> - -/*! - * \brief Public constructor (factory) for mb_runtime_nop objects. - */ -mb_runtime_sptr mb_make_runtime_nop(); - -/*! - * \brief Concrete runtime that does nothing. Used only during early QA tests. - */ -class mb_runtime_nop : public mb_runtime_base -{ -public: - mb_runtime_nop(); - ~mb_runtime_nop(); - - bool run(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg, - pmt::pmt_t *result); - -protected: - mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg); -}; - -#endif /* INCLUDED_MB_RUNTIME_NOP_H */ diff --git a/mblock/src/lib/mb_runtime_thread_per_block.cc b/mblock/src/lib/mb_runtime_thread_per_block.cc deleted file mode 100644 index b160094363..0000000000 --- a/mblock/src/lib/mb_runtime_thread_per_block.cc +++ /dev/null @@ -1,350 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_runtime_thread_per_block.h> -#include <mblock/mblock.h> -#include <mb_mblock_impl.h> -#include <mblock/class_registry.h> -#include <mblock/exception.h> -#include <mb_worker.h> -#include <gnuradio/omnithread.h> -#include <iostream> -#include <mb_msg_accepter_msgq.h> - -using namespace pmt; - -static pmt_t s_halt = pmt_intern("%halt"); -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_shutdown = pmt_intern("%shutdown"); -static pmt_t s_request_shutdown = pmt_intern("%request-shutdown"); -static pmt_t s_worker_state_changed = pmt_intern("%worker-state-changed"); -static pmt_t s_timeout = pmt_intern("%timeout"); -static pmt_t s_request_timeout = pmt_intern("%request-timeout"); -static pmt_t s_cancel_timeout = pmt_intern("%cancel-timeout"); -static pmt_t s_send_halt = pmt_intern("send-halt"); -static pmt_t s_exit_now = pmt_intern("exit-now"); - -static void -send_sys_msg(mb_msg_queue &msgq, pmt_t signal, - pmt_t data = PMT_F, pmt_t metadata = PMT_F, - mb_pri_t priority = MB_PRI_BEST) -{ - mb_message_sptr msg = mb_make_message(signal, data, metadata, priority); - msg->set_port_id(s_sys_port); - msgq.insert(msg); -} - - -mb_runtime_thread_per_block::mb_runtime_thread_per_block() - : d_shutdown_in_progress(false), - d_shutdown_result(PMT_T) -{ - d_accepter = mb_msg_accepter_sptr(new mb_msg_accepter_msgq(&d_msgq)); -} - -mb_runtime_thread_per_block::~mb_runtime_thread_per_block() -{ - // FIXME iterate over workers and ensure that they are dead. - - if (!d_workers.empty()) - std::cerr << "\nmb_runtime_thread_per_block: dtor (# workers = " - << d_workers.size() << ")\n"; -} - -void -mb_runtime_thread_per_block::request_shutdown(pmt_t result) -{ - (*accepter())(s_request_shutdown, result, PMT_F, MB_PRI_BEST); -} - -bool -mb_runtime_thread_per_block::run(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg, pmt_t *result) -{ - if (result) // set it to something now, in case we throw - *result = PMT_F; - - // reset the shutdown state - d_shutdown_in_progress = false; - d_shutdown_result = PMT_T; - - assert(d_workers.empty()); - - while (!d_timer_queue.empty()) // ensure timer queue is empty - d_timer_queue.pop(); - - /* - * Create the top-level component, and recursively all of its - * subcomponents. - */ - d_top = create_component(instance_name, class_name, user_arg); - - try { - run_loop(); - } - catch (...){ - d_top.reset(); - throw; - } - - if (result) - *result = d_shutdown_result; - - d_top.reset(); - return true; -} - -void -mb_runtime_thread_per_block::run_loop() -{ - while (1){ - mb_message_sptr msg; - - if (d_timer_queue.empty()) // Any timeouts pending? - msg = d_msgq.get_highest_pri_msg(); // Nope. Block forever. - - else { - mb_timeout_sptr to = d_timer_queue.top(); // Yep. Get earliest timeout. - - // wait for a msg or the timeout... - msg = d_msgq.get_highest_pri_msg_timedwait(to->d_when); - - if (!msg){ // We timed out. - d_timer_queue.pop(); // Remove timeout from timer queue. - - // send the %timeout msg - (*to->d_accepter)(s_timeout, to->d_user_data, to->handle(), MB_PRI_BEST); - - if (to->d_is_periodic){ - to->d_when = to->d_when + to->d_delta; // update time of next firing - d_timer_queue.push(to); // push it back into the queue - } - continue; - } - } - - pmt_t signal = msg->signal(); - - if (pmt_eq(signal, s_worker_state_changed)){ // %worker-state-changed - omni_mutex_lock l1(d_workers_mutex); - reap_dead_workers(); - if (d_workers.empty()) // no work left to do... - return; - } - else if (pmt_eq(signal, s_request_shutdown)){ // %request-shutdown - if (!d_shutdown_in_progress){ - d_shutdown_in_progress = true; - d_shutdown_result = msg->data(); - - // schedule a timeout for ourselves... - schedule_one_shot_timeout(mb_time::time(0.100), s_send_halt, d_accepter); - send_all_sys_msg(s_shutdown); - } - } - else if (pmt_eq(signal, s_request_timeout)){ // %request-timeout - mb_timeout_sptr to = - boost::any_cast<mb_timeout_sptr>(pmt_any_ref(msg->data())); - d_timer_queue.push(to); - } - else if (pmt_eq(signal, s_cancel_timeout)){ // %cancel-timeout - d_timer_queue.cancel(msg->data()); - } - else if (pmt_eq(signal, s_timeout) - && pmt_eq(msg->data(), s_send_halt)){ // %timeout, send-halt - - // schedule another timeout for ourselves... - schedule_one_shot_timeout(mb_time::time(0.100), s_exit_now, d_accepter); - send_all_sys_msg(s_halt); - } - else if (pmt_eq(signal, s_timeout) - && pmt_eq(msg->data(), s_exit_now)){ // %timeout, exit-now - - // We only get here if we've sent all workers %shutdown followed - // by %halt, and one or more of them is still alive. They must - // be blocked in the kernel. FIXME We could add one more step: - // pthread_kill(...) but for now, we'll just ignore them... - return; - } - else { - std::cerr << "mb_runtime_thread_per_block: unhandled msg: " << msg << std::endl; - } - } -} - -void -mb_runtime_thread_per_block::reap_dead_workers() -{ - // Already holding mutex - // omni_mutex_lock l1(d_workers_mutex); - - for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ){ - bool is_dead; - - // We can't join while holding the worker mutex, since that would - // attempt to destroy the mutex we're holding (omnithread's join - // deletes the omni_thread object after the pthread_join - // completes) Instead, we lock just long enough to figure out if - // the worker is dead. - { - omni_mutex_lock l2((*wi)->d_mutex); - is_dead = (*wi)->d_state == mb_worker::TS_DEAD; - } - - if (is_dead){ - if (0) - std::cerr << "\nruntime: " - << "(" << (*wi)->id() << ") " - << (*wi)->d_mblock->instance_name() << " is TS_DEAD\n"; - void *ignore; - (*wi)->join(&ignore); - wi = d_workers.erase(wi); - continue; - } - ++wi; - } -} - -// -// Create the thread, then create the component in the thread. -// Return a pointer to the created mblock. -// -// Can be invoked from any thread -// -mb_mblock_sptr -mb_runtime_thread_per_block::create_component(const std::string &instance_name, - const std::string &class_name, - pmt_t user_arg) -{ - mb_mblock_maker_t maker; - if (!mb_class_registry::lookup_maker(class_name, &maker)) - throw mbe_no_such_class(0, class_name + " (in " + instance_name + ")"); - - // FIXME here's where we'd lookup NUMA placement requests & mblock - // priorities and communicate them to the worker we're creating... - - // Create the worker thread - mb_worker *w = - new mb_worker(this, maker, instance_name, user_arg); - - w->start_undetached(); // start it - - // Wait for it to reach TS_RUNNING or TS_DEAD - - bool is_dead; - mb_worker::cause_of_death_t why_dead; - { - omni_mutex_lock l(w->d_mutex); - while (!(w->d_state == mb_worker::TS_RUNNING - || w->d_state == mb_worker::TS_DEAD)) - w->d_state_cond.wait(); - - is_dead = w->d_state == mb_worker::TS_DEAD; - why_dead = w->d_why_dead; - } - - // If the worker failed to init (constructor or initial_transition - // raised an exception), reap the worker now and raise an exception. - - if (is_dead && why_dead != mb_worker::RIP_EXIT){ - - void *ignore; - w->join(&ignore); - - // FIXME with some work we ought to be able to propagate the - // exception from the worker. - throw mbe_mblock_failed(0, instance_name); - } - - assert(w->d_mblock); - - // Add w to the vector of workers, and return the mblock. - { - omni_mutex_lock l(d_workers_mutex); - d_workers.push_back(w); - } - - if (0) - std::cerr << "\nruntime: created " - << "(" << w->id() << ") " - << w->d_mblock->instance_name() << "\n"; - - return w->d_mblock; -} - -void -mb_runtime_thread_per_block::send_all_sys_msg(pmt_t signal, - pmt_t data, - pmt_t metadata, - mb_pri_t priority) -{ - omni_mutex_lock l1(d_workers_mutex); - - for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ++wi){ - send_sys_msg((*wi)->d_mblock->impl()->msgq(), - signal, data, metadata, priority); - } -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -pmt_t -mb_runtime_thread_per_block::schedule_one_shot_timeout - (const mb_time &abs_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - mb_timeout_sptr to(new mb_timeout(abs_time, user_data, accepter)); - (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST); - return to->handle(); -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -pmt_t -mb_runtime_thread_per_block::schedule_periodic_timeout - (const mb_time &first_abs_time, - const mb_time &delta_time, - pmt_t user_data, - mb_msg_accepter_sptr accepter) -{ - mb_timeout_sptr to(new mb_timeout(first_abs_time, delta_time, - user_data, accepter)); - (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST); - return to->handle(); -} - -// -// Can be invoked from any thread. -// Sends a message to the runtime. -// -void -mb_runtime_thread_per_block::cancel_timeout(pmt_t handle) -{ - (*d_accepter)(s_cancel_timeout, handle, PMT_F, MB_PRI_BEST); -} diff --git a/mblock/src/lib/mb_runtime_thread_per_block.h b/mblock/src/lib/mb_runtime_thread_per_block.h deleted file mode 100644 index 74ed6073a4..0000000000 --- a/mblock/src/lib/mb_runtime_thread_per_block.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H -#define INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H - -#include <mb_runtime_base.h> -#include <mb_worker.h> -#include <mblock/msg_queue.h> -#include <mb_timer_queue.h> - -/*! - * \brief Concrete runtime that uses a thread per mblock - * \internal - * - * These are all implementation details. - */ -class mb_runtime_thread_per_block : public mb_runtime_base -{ -public: - omni_mutex d_workers_mutex; // hold while manipulating d_workers - std::vector<mb_worker*> d_workers; - bool d_shutdown_in_progress; - pmt::pmt_t d_shutdown_result; - mb_msg_queue d_msgq; - mb_timer_queue d_timer_queue; - - typedef std::vector<mb_worker*>::iterator worker_iter_t; - - mb_runtime_thread_per_block(); - ~mb_runtime_thread_per_block(); - - bool run(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg, - pmt::pmt_t *result); - - void request_shutdown(pmt::pmt_t result); - -protected: - mb_mblock_sptr - create_component(const std::string &instance_name, - const std::string &class_name, - pmt::pmt_t user_arg); - - pmt::pmt_t - schedule_one_shot_timeout(const mb_time &abs_time, pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - - pmt::pmt_t - schedule_periodic_timeout(const mb_time &first_abs_time, - const mb_time &delta_time, - pmt::pmt_t user_data, - mb_msg_accepter_sptr accepter); - void - cancel_timeout(pmt::pmt_t handle); - -private: - void reap_dead_workers(); - void run_loop(); - - void send_all_sys_msg(pmt::pmt_t signal, pmt::pmt_t data = pmt::PMT_F, - pmt::pmt_t metadata = pmt::PMT_F, - mb_pri_t priority = MB_PRI_BEST); -}; - -#endif /* INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H */ diff --git a/mblock/src/lib/mb_timer_queue.cc b/mblock/src/lib/mb_timer_queue.cc deleted file mode 100644 index 411900c59e..0000000000 --- a/mblock/src/lib/mb_timer_queue.cc +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_timer_queue.h> - -using namespace pmt; - -static pmt_t -make_handle() -{ - static long counter = 0; - pmt_t n = pmt_from_long(counter++); - return pmt_list1(n); // guaranteed to be a unique object -} - -// one-shot constructor -mb_timeout::mb_timeout(const mb_time &abs_time, - pmt_t user_data, mb_msg_accepter_sptr accepter) - : d_when(abs_time), d_is_periodic(false), - d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter) -{ -} - -// periodic constructor -mb_timeout::mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time, - pmt_t user_data, mb_msg_accepter_sptr accepter) - : d_when(first_abs_time), d_delta(delta_time), d_is_periodic(true), - d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter) -{ -} - -void -mb_timer_queue::cancel(pmt_t handle) -{ - container_type::iterator it; - - for (it = c.begin(); it != c.end();){ - if (pmt_equal((*it)->handle(), handle)) - it = c.erase(it); - else - ++it; - } - std::make_heap(c.begin(), c.end(), comp); -} diff --git a/mblock/src/lib/mb_timer_queue.h b/mblock/src/lib/mb_timer_queue.h deleted file mode 100644 index 7a1ad6fa30..0000000000 --- a/mblock/src/lib/mb_timer_queue.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_TIMER_QUEUE_H -#define INCLUDED_MB_TIMER_QUEUE_H - -#include <mblock/time.h> -#include <vector> -#include <queue> -#include <gruel/pmt.h> -#include <mblock/msg_accepter.h> - -class mb_timeout { -public: - mb_time d_when; // absolute time to fire timeout - mb_time d_delta; // if periodic, delta_t to next timeout - bool d_is_periodic; // true iff this is a periodic timeout - pmt::pmt_t d_user_data; // data from %timeout msg - pmt::pmt_t d_handle; // handle for cancellation - mb_msg_accepter_sptr d_accepter; // where to send the message - - // one-shot constructor - mb_timeout(const mb_time &abs_time, - pmt::pmt_t user_data, mb_msg_accepter_sptr accepter); - - // periodic constructor - mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time, - pmt::pmt_t user_data, mb_msg_accepter_sptr accepter); - - pmt::pmt_t handle() const { return d_handle; } -}; - -typedef boost::shared_ptr<mb_timeout> mb_timeout_sptr; - - -//! Sort criterion for priority_queue -class timeout_later -{ -public: - bool operator() (const mb_timeout_sptr t1, const mb_timeout_sptr t2) - { - return t1->d_when > t2->d_when; - } -}; - - -class mb_timer_queue : public std::priority_queue<mb_timeout_sptr, - std::vector<mb_timeout_sptr>, - timeout_later> -{ -public: - void cancel(pmt::pmt_t handle); -}; - -#endif /* INCLUDED_MB_TIMER_QUEUE_H */ diff --git a/mblock/src/lib/mb_util.h b/mblock/src/lib/mb_util.h deleted file mode 100644 index fe420d6ede..0000000000 --- a/mblock/src/lib/mb_util.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_UTIL_H -#define INCLUDED_MB_UTIL_H - -#include <string> - -class mb_util -{ -public: - static std::string - join_names(const std::string &comp_name, - const std::string &port_name); -}; - -#endif /* INCLUDED_MB_UTIL_H */ diff --git a/mblock/src/lib/mb_worker.cc b/mblock/src/lib/mb_worker.cc deleted file mode 100644 index 7d2896a114..0000000000 --- a/mblock/src/lib/mb_worker.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mb_worker.h> -#include <mb_runtime_thread_per_block.h> -#include <mblock/exception.h> -#include <mblock/mblock.h> -#include <mb_gettid.h> -#include <mblock/msg_accepter.h> -#include <iostream> -#include <cstdio> -#ifdef HAVE_SCHED_H -#include <sched.h> -#endif - -#define VERBOSE 0 // define to 0 or 1 - -using namespace pmt; - -static pmt_t s_worker_state_changed = pmt_intern("%worker-state-changed"); - - -mb_worker::mb_worker(mb_runtime_thread_per_block *runtime, - mb_mblock_maker_t maker, - const std::string &instance_name, - pmt_t user_arg) - : omni_thread((void *) 0, PRIORITY_NORMAL), - d_runtime(runtime), d_maker(maker), - d_instance_name(instance_name), d_user_arg(user_arg), - d_state_cond(&d_mutex), d_state(TS_UNINITIALIZED), - d_why_dead(RIP_NOT_DEAD_YET) -{ -} - -#if 0 -mb_worker::~mb_worker() -{ -} -#endif - -#ifdef HAVE_SCHED_SETAFFINITY -static void -set_affinity(const std::string &instance_name, const std::string &class_name) -{ - //static int counter = 0; - cpu_set_t mask; - CPU_ZERO(&mask); - - if (0){ - - //CPU_SET(counter & 0x1, &mask); - //counter++; - CPU_SET(0, &mask); - - int r = sched_setaffinity(mb_gettid(), sizeof(mask), &mask); - if (r == -1) - perror("sched_setaffinity"); - } -} -#else -static void -set_affinity(const std::string &instance_name, const std::string &class_name) -{ -} -#endif - -void -mb_worker::set_state(worker_state_t state) -{ - { - omni_mutex_lock l2(d_mutex); - - d_state = state; // update our state - d_state_cond.broadcast(); // Notify everybody who cares... - } - - // send msg to runtime, telling it something changed. - (*d_runtime->accepter())(s_worker_state_changed, PMT_F, PMT_F, MB_PRI_BEST); -} - -void * -mb_worker::run_undetached(void *ignored) -{ - // FIXME add pthread_sigmask stuff - - //set_affinity(d_instance_name, d_class_name); - set_affinity(d_instance_name, ""); - - try { - worker_thread_top_level(); - d_why_dead = RIP_EXIT; - } - catch (mbe_terminate){ - d_why_dead = RIP_TERMINATE; - } - catch (mbe_exit){ - d_why_dead = RIP_EXIT; - } - catch (std::logic_error e){ - if (d_why_dead == RIP_NOT_DEAD_YET) - d_why_dead = RIP_UNHANDLED_EXCEPTION; - - std::cerr << "\nmb_worker::run_undetached: unhandled exception:\n"; - std::cerr << " " << e.what() << std::endl; - } - catch (...){ - if (d_why_dead == RIP_NOT_DEAD_YET) - d_why_dead = RIP_UNHANDLED_EXCEPTION; - } - - if (VERBOSE) - std::cerr << "\nrun_undetached: about to return, d_why_dead = " - << d_why_dead << std::endl; - - set_state(TS_DEAD); - return 0; -} - -void -mb_worker::worker_thread_top_level() -{ - if (VERBOSE) - std::cerr << "worker_thread_top_level (enter):" << std::endl - << " instance_name: " << d_instance_name << std::endl - << " omnithread id: " << id() << std::endl - << " gettid: " << mb_gettid() << std::endl - << " getpid: " << getpid() << std::endl; - - cause_of_death_t pending_cause_of_death = RIP_NOT_DEAD_YET; - - try { - pending_cause_of_death = RIP_CTOR_EXCEPTION; - d_mblock = d_maker(d_runtime, d_instance_name, d_user_arg); - - if (VERBOSE) - std::cerr << "worker_thread_top_level (post-construction):" << std::endl - << " instance_name: " << d_instance_name << std::endl; - - pending_cause_of_death = RIP_INIT_EXCEPTION; - d_mblock->initial_transition(); - - if (VERBOSE) - std::cerr << "worker_thread_top_level (post-initial-transition):" << std::endl - << " instance_name: " << d_instance_name << std::endl; - - set_state(TS_RUNNING); - - pending_cause_of_death = RIP_UNHANDLED_EXCEPTION; - d_mblock->main_loop(); - } - catch (...){ - d_why_dead = pending_cause_of_death; - throw; - } - - if (VERBOSE) - std::cerr << "worker_thread_top_level (exit):" << std::endl - << " instance_name: " << d_instance_name << std::endl; -} diff --git a/mblock/src/lib/mb_worker.h b/mblock/src/lib/mb_worker.h deleted file mode 100644 index 0037d131fd..0000000000 --- a/mblock/src/lib/mb_worker.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MB_WORKER_H -#define INCLUDED_MB_WORKER_H - -#include <gnuradio/omnithread.h> -#include <mblock/common.h> -#include <mblock/class_registry.h> - - -class mb_worker; -//typedef boost::shared_ptr<mb_worker> mb_worker_sptr; - -class mb_runtime_thread_per_block; - -/*! - * \brief Worker thread for thread_per_block runtime - * \internal - */ -class mb_worker : public omni_thread -{ -public: - //! worker thread states - enum worker_state_t { - TS_UNINITIALIZED, // new, uninitialized - TS_RUNNING, // normal steady-state condition. - TS_DEAD // thread is dead - }; - - //! why we're dead - enum cause_of_death_t { - RIP_NOT_DEAD_YET, // not dead - RIP_EXIT, // normal exit - RIP_TERMINATE, // caught terminate exception - RIP_CTOR_EXCEPTION, // constructor raised an exception - RIP_INIT_EXCEPTION, // initial_transition rasised an exception - RIP_UNHANDLED_EXCEPTION // somebody (most likely handle_message) raised an exception - }; - - /* - * Args used by new thread to create mb_mblock - */ - mb_runtime_thread_per_block *d_runtime; - mb_mblock_maker_t d_maker; - std::string d_instance_name; - pmt::pmt_t d_user_arg; - - mb_mblock_sptr d_mblock; //< holds pointer to created mblock - - /*! - * \brief General mutex for all these fields. - * - * They are accessed by both the main runtime thread and the newly - * created thread that runs the mblock's main loop. - */ - omni_mutex d_mutex; - omni_condition d_state_cond; //< state change notifications - worker_state_t d_state; - cause_of_death_t d_why_dead; - - mb_worker(mb_runtime_thread_per_block *runtime, - mb_mblock_maker_t maker, - const std::string &instance_name, - pmt::pmt_t user_arg); - - // ~mb_worker(); - - - /*! - * \brief This code runs as the top-level of the new thread - */ - void worker_thread_top_level(); - - /*! - * \brief Invokes the top-level of the new thread (name kind of sucks) - */ - void *run_undetached(void *arg); - -private: - // Neither d_mutex nor runtime->d_mutex may be held while calling this. - // It locks and unlocks them itself. - void set_state(worker_state_t state); -}; - - - -#endif /* INCLUDED_MB_WORKER_H */ diff --git a/mblock/src/lib/mbi_runtime_lock.h b/mblock/src/lib/mbi_runtime_lock.h deleted file mode 100644 index 020cd733ce..0000000000 --- a/mblock/src/lib/mbi_runtime_lock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_MBI_RUNTIME_LOCK_H -#define INCLUDED_MBI_RUNTIME_LOCK_H - -#include <mblock/runtime.h> -#include <mb_mblock_impl.h> -#include <boost/utility.hpp> - -/*! - * \brief acquire and release big runtime lock - * - * As an alternative to: - * { - * rt->lock(); - * ..... - * rt->unlock(); - * } - * - * you can use a single instance of the mbi_runtime_lock class: - * - * { - * mbi_runtime_lock l(rt); - * .... - * } - * - * This has the advantage that rt->unlock() will be called automatically - * when an exception is thrown. - */ - -class mbi_runtime_lock : boost::noncopyable { - mb_runtime_base *d_rt; -public: - mbi_runtime_lock(mb_runtime_base *rt) : d_rt(rt) { d_rt->lock(); } - mbi_runtime_lock(mb_mblock_impl *mi) : d_rt(mi->runtime()) { d_rt->lock(); } - mbi_runtime_lock(mb_mblock *mb) : d_rt(mb->impl()->runtime()) { d_rt->lock(); } - ~mbi_runtime_lock(void) { d_rt->unlock(); } - -}; - -#endif /* INCLUDED_MBI_RUNTIME_LOCK_H */ - diff --git a/mblock/src/lib/qa_bitset.cc b/mblock/src/lib/qa_bitset.cc deleted file mode 100644 index 7cfd83856e..0000000000 --- a/mblock/src/lib/qa_bitset.cc +++ /dev/null @@ -1,496 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/class_registry.h> -#include <iostream> -#include <cstdio> -#include <sstream> -#include <bitset> - -using namespace pmt; - -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_start = pmt_intern("start"); -static pmt_t s_send_batch = pmt_intern("send-batch"); -static pmt_t s_long0 = pmt_from_long(0); - -static std::string -str(long x) -{ - std::ostringstream s; - s << x; - return s.str(); -} - -/*! - * \brief mblock used for QA. - * - * Messages arriving on "in" consist of a pair containing a (long) - * message number in the car, and a (long) bitmap in the cdr. For - * each message received on "in", a new message is sent on "out". The - * new message is the same format as the input, but the bitmap in - * the cdr has a "1" or'd into it that corresponds to the bit number - * specified in the constructor. - * - * The bitmap can be used by the ultimate receiver to confirm - * traversal of a set of blocks, if the blocks are assigned unique bit - * numbers. - */ -class qa_bitset : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - int d_bitno; - -public: - qa_bitset(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); -}; - -qa_bitset::qa_bitset(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::EXTERNAL); - d_out = define_port("out", "qa-bitset", true, mb_port::EXTERNAL); -} - -void -qa_bitset::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->port_id(), s_in) && pmt_eq(msg->signal(), s_data)){ - d_out->send(s_data, - pmt_cons(pmt_car(msg->data()), - pmt_from_long((1L << d_bitno) | pmt_to_long(pmt_cdr(msg->data()))))); - } -} - -REGISTER_MBLOCK_CLASS(qa_bitset); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset mblocks. - */ -class qa_bitset2 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset2::qa_bitset2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset", pmt_from_long(bitno + 1)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset2); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset2 mblocks. - */ -class qa_bitset4 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset4(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset4::qa_bitset4(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset2", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset2", pmt_from_long(bitno + 2)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset4); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset4 mblocks. - */ -class qa_bitset8 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset8(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset8::qa_bitset8(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset4", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset4", pmt_from_long(bitno + 4)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset8); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset8 mblocks. - */ -class qa_bitset16 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset16(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset16::qa_bitset16(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset8", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset8", pmt_from_long(bitno + 8)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset16); - -// ------------------------------------------------------------------------ - -/*! - * \brief mblock used for QA. Compose two qa_bitset16 mblocks. - */ -class qa_bitset32 : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - -public: - qa_bitset32(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); -}; - -qa_bitset32::qa_bitset32(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - long bitno = pmt_to_long(user_arg); // The bit we are to set - - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - - define_component("bs0", "qa_bitset16", pmt_from_long(bitno)); - define_component("bs1", "qa_bitset16", pmt_from_long(bitno + 16)); - connect("self", "in", "bs0", "in"); - connect("bs0", "out", "bs1", "in"); - connect("bs1", "out", "self", "out"); -} - -REGISTER_MBLOCK_CLASS(qa_bitset32); - -// ------------------------------------------------------------------------ - -class qa_bitset_src : public mb_mblock -{ - mb_port_sptr d_cs_top; - mb_port_sptr d_cs; - - mb_port_sptr d_out; - - long d_msg_number; // starting message number - long d_nmsgs_to_send; // # of messages to send - long d_batch_size; // # of messages to send per batch - -public: - qa_bitset_src(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); - -protected: - void send_one(); - void send_batch(); -}; - -qa_bitset_src::qa_bitset_src(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_msg_number = pmt_to_long(pmt_nth(0, user_arg)); - d_nmsgs_to_send = pmt_to_long(pmt_nth(1, user_arg)); - d_batch_size = pmt_to_long(pmt_nth(2, user_arg)); - - d_cs_top = define_port("cs_top", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs = define_port("cs", "qa-bitset-cs", true, mb_port::EXTERNAL); - - d_out = define_port("out", "qa-bitset", true, mb_port::EXTERNAL); -} - -void -qa_bitset_src::handle_message(mb_message_sptr msg) -{ - if ((pmt_eq(msg->port_id(), d_cs_top->port_symbol()) - || pmt_eq(msg->port_id(), d_cs->port_symbol())) - && pmt_eq(msg->signal(), s_send_batch)){ - send_batch(); - } -} - -void -qa_bitset_src::send_batch() -{ - for (int i = 0; i < d_batch_size; i++) - send_one(); -} - -void -qa_bitset_src::send_one() -{ - if (d_nmsgs_to_send > 0){ - pmt_t msg_number = pmt_from_long(d_msg_number++); - d_out->send(s_data, pmt_cons(msg_number, s_long0)); - } - if (--d_nmsgs_to_send <= 0) - exit(); -} - -REGISTER_MBLOCK_CLASS(qa_bitset_src); - -// ------------------------------------------------------------------------ - -class qa_bitset_sink : public mb_mblock -{ - // Maximum number of messages we can track - static const size_t MAX_MSGS = 1 * 1024 * 1024; - - mb_port_sptr d_cs0; - mb_port_sptr d_cs1; - mb_port_sptr d_cs2; - mb_port_sptr d_cs3; - - mb_port_sptr d_in0; - mb_port_sptr d_in1; - mb_port_sptr d_in2; - mb_port_sptr d_in3; - - long d_nmsgs_to_recv; // # of messages to receive - long d_batch_size; // # of messages to receive per batch - uint32_t d_expected_mask; - - std::bitset<MAX_MSGS> d_bitset; - long d_nrecvd; - -public: - qa_bitset_sink(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void handle_message(mb_message_sptr msg); - -protected: - void receive_one(mb_message_sptr msg); -}; - -qa_bitset_sink::qa_bitset_sink(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nrecvd(0) -{ - d_nmsgs_to_recv = pmt_to_long(pmt_nth(0, user_arg)); - d_batch_size = pmt_to_long(pmt_nth(1, user_arg)); - d_expected_mask = pmt_to_long(pmt_nth(2, user_arg)); - - if (d_nmsgs_to_recv > (long) MAX_MSGS) - throw std::out_of_range("qa_bitset_sink: nmsgs_to_recv is too big"); - - if (d_batch_size < 1) - throw std::out_of_range("qa_bitset_sink: batch_size must be >= 1"); - - d_cs0 = define_port("cs0", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs1 = define_port("cs1", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs2 = define_port("cs2", "qa-bitset-cs", true, mb_port::EXTERNAL); - d_cs3 = define_port("cs3", "qa-bitset-cs", true, mb_port::EXTERNAL); - - d_in0 = define_port("in0", "qa-bitset", false, mb_port::EXTERNAL); - d_in1 = define_port("in1", "qa-bitset", false, mb_port::EXTERNAL); - d_in2 = define_port("in2", "qa-bitset", false, mb_port::EXTERNAL); - d_in3 = define_port("in3", "qa-bitset", false, mb_port::EXTERNAL); -} - -void -qa_bitset_sink::handle_message(mb_message_sptr msg) -{ - if ((pmt_eq(msg->port_id(), d_in0->port_symbol()) - || pmt_eq(msg->port_id(), d_in1->port_symbol()) - || pmt_eq(msg->port_id(), d_in2->port_symbol()) - || pmt_eq(msg->port_id(), d_in3->port_symbol())) - && pmt_eq(msg->signal(), s_data)){ - - receive_one(msg); - } -} - -void -qa_bitset_sink::receive_one(mb_message_sptr msg) -{ - long msg_number = pmt_to_long(pmt_car(msg->data())); - uint32_t mask = pmt_to_long(pmt_cdr(msg->data())); - - // std::cout << msg->data() << std::endl; - - d_nrecvd++; - if (d_nrecvd % d_batch_size == d_batch_size - 1){ - d_cs0->send(s_send_batch); - d_cs1->send(s_send_batch); - d_cs2->send(s_send_batch); - d_cs3->send(s_send_batch); - } - - if (msg_number >= d_nmsgs_to_recv){ - std::cerr << "qa_bitset_sink::receive_one: msg_number too big (" - << msg_number << ")\n"; - shutdown_all(PMT_F); - return; - } - if (mask != d_expected_mask){ - fprintf(stderr, - "qa_bitset_sink::receive_one: Wrong mask. Expected 0x%08x, got 0x%08x\n", - d_expected_mask, mask); - shutdown_all(PMT_F); - return; - } - - if (d_bitset.test((size_t) msg_number)){ - std::cerr << "qa_bitset_sink::receive_one: duplicate msg_number (" - << msg_number << ")\n"; - shutdown_all(PMT_F); - return; - } - - d_bitset.set((size_t) msg_number); - if (d_nrecvd == d_nmsgs_to_recv) - shutdown_all(PMT_T); // we're done! -} - -REGISTER_MBLOCK_CLASS(qa_bitset_sink); - -// ------------------------------------------------------------------------ - -class qa_bitset_top : public mb_mblock -{ - static const int NPIPES = 4; - - std::vector<mb_port_sptr> d_cs; - - long d_nmsgs; // # of messages to send - long d_batch_size; // # of messages to receive per batch - -public: - qa_bitset_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); -}; - -qa_bitset_top::qa_bitset_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_nmsgs = pmt_to_long(pmt_nth(0, user_arg)); - d_nmsgs = (d_nmsgs / NPIPES) * NPIPES; - d_batch_size = pmt_to_long(pmt_nth(1, user_arg)); - - /* - * We build NPIPES sources which feed NPIPES pipelines, each of which - * consists of 8-mblocks. All pipelines feed into a single sink - * which keeps track the results. - */ - for (int i = 0; i < NPIPES; i++){ - d_cs.push_back(define_port("cs"+str(i), "qa-bitset-cs", false, mb_port::INTERNAL)); - - // sources of test messages - define_component("src"+str(i), "qa_bitset_src", - pmt_list3(pmt_from_long(i * d_nmsgs/NPIPES), - pmt_from_long(d_nmsgs/NPIPES), - pmt_from_long(d_batch_size))); - - // 8-mblock processing pipelines - define_component("pipeline"+str(i), "qa_bitset8", pmt_from_long(0)); - } - - // sink for output of pipelines - define_component("sink", "qa_bitset_sink", - pmt_list3(pmt_from_long(d_nmsgs), - pmt_from_long(d_batch_size * NPIPES), - pmt_from_long(0x000000ff))); - - for (int i = 0; i < NPIPES; i++){ - connect("self", "cs"+str(i), "src"+str(i), "cs_top"); - connect("src"+str(i), "out", "pipeline"+str(i), "in"); - connect("src"+str(i), "cs", "sink", "cs"+str(i)); - connect("pipeline"+str(i), "out", "sink", "in"+str(i)); - } -} - -void -qa_bitset_top::initial_transition() -{ - for (int i = 0; i < NPIPES; i++){ - d_cs[i]->send(s_send_batch); // prime the pump - d_cs[i]->send(s_send_batch); - } -} - -REGISTER_MBLOCK_CLASS(qa_bitset_top); diff --git a/mblock/src/lib/qa_bitset.mbh b/mblock/src/lib/qa_bitset.mbh deleted file mode 100644 index 3fbcb80db3..0000000000 --- a/mblock/src/lib/qa_bitset.mbh +++ /dev/null @@ -1,61 +0,0 @@ -;; -*- scheme -*- ; not really, but tells emacs how to format this -;; -;; Copyright 2007 Free Software Foundation, Inc. -;; -;; This file is part of GNU Radio -;; -;; GNU Radio 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 3, or (at your option) -;; any later version. -;; -;; GNU Radio 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., -;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -;; - -;; ---------------------------------------------------------------- -;; qa-bitset -- interface to mblock QA code -;; - -(define-protocol-class qa-bitset - - (:incoming - - (data n bitmask) - - ) - ) - -(define-protocol-class qa-bitset-cs - - (:outgoing - - (send-batch) - - ) - ) - -;; ---------------------------------------------------------------- -;; qa-disconnect -- interface to mblock QA code -;; - -(define-protocol-class qa-disconnect-cs - - (:outgoing - - (select-pipe n) - - ) - - (:incoming - - (ack n) - - ) - ) diff --git a/mblock/src/lib/qa_disconnect.cc b/mblock/src/lib/qa_disconnect.cc deleted file mode 100644 index c7619bfc36..0000000000 --- a/mblock/src/lib/qa_disconnect.cc +++ /dev/null @@ -1,241 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <mblock/mblock.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/class_registry.h> -#include <iostream> -#include <cstdio> -#include <sstream> -#include <bitset> - -using namespace pmt; - -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_ack = pmt_intern("ack"); -static pmt_t s_select_pipe = pmt_intern("select-pipe"); -static pmt_t s_long0 = pmt_from_long(0); -static pmt_t s_sys_port = pmt_intern("%sys-port"); -static pmt_t s_shutdown = pmt_intern("%shutdown"); - -class qa_disconnect_mux : public mb_mblock -{ - mb_port_sptr d_in; - mb_port_sptr d_out; - mb_port_sptr d_cs; - -public: - qa_disconnect_mux(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_disconnect_mux::qa_disconnect_mux(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_in = define_port("in", "qa-bitset", false, mb_port::RELAY); - d_out = define_port("out", "qa-bitset", true, mb_port::RELAY); - d_cs = define_port("cs", "qa-disconnect-cs", true, mb_port::EXTERNAL); - - define_component("pipeline0", "qa_bitset8", pmt_from_long(0)); - define_component("pipeline1", "qa_bitset8", pmt_from_long(8)); -} - -void -qa_disconnect_mux::initial_transition(){} - -void -qa_disconnect_mux::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->port_id(), d_cs->port_symbol()) // select-pipe on cs - && pmt_eq(msg->signal(), s_select_pipe)){ - - long which_pipe = pmt_to_long(pmt_nth(0, msg->data())); - - disconnect_component("pipeline0"); - disconnect_component("pipeline1"); - - switch(which_pipe){ - - case 0: - connect("self", "in", "pipeline0", "in"); - connect("self", "out", "pipeline0", "out"); - break; - - case 1: - connect("self", "in", "pipeline1", "in"); - connect("self", "out", "pipeline1", "out"); - break; - } - - d_cs->send(s_ack, msg->data()); - return; - } -} - -REGISTER_MBLOCK_CLASS(qa_disconnect_mux); - -// ------------------------------------------------------------------------ - -class qa_disconnect_top : public mb_mblock -{ - enum state_t { - UNINITIALIZED, - WAIT_FOR_ACK, - WAIT_FOR_DATA - }; - - state_t d_state; - int d_msg_number; - int d_nmsgs_to_send; - - mb_port_sptr d_in; - mb_port_sptr d_out; - mb_port_sptr d_cs; - - void check_pipe_send_next_msg(); - void send_next_msg(); - void select_pipe(int n); - - // alternate pipes every 128 messages - static int which_pipe(int msg_number) { return (msg_number >> 7) & 0x1; } - bool time_to_switch() { return (d_msg_number & 0x7f) == 0; } - -public: - qa_disconnect_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_disconnect_top::qa_disconnect_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_state(UNINITIALIZED), d_msg_number(0) -{ - d_nmsgs_to_send = pmt_to_long(pmt_nth(0, user_arg)); - - d_in = define_port("in", "qa-bitset", false, mb_port::INTERNAL); - d_out = define_port("out", "qa-bitset", true, mb_port::INTERNAL); - d_cs = define_port("cs", "qa-disconnect-cs", false, mb_port::INTERNAL); - - define_component("mux", "qa_disconnect_mux", PMT_F); - - connect("self", "cs", "mux", "cs"); - connect("self", "out", "mux", "in"); - connect("self", "in", "mux", "out"); -} - -void -qa_disconnect_top::initial_transition() -{ - check_pipe_send_next_msg(); -} - -void -qa_disconnect_top::handle_message(mb_message_sptr msg) -{ - if (0) - std::cerr << "qa_disconnect_top::handle_msg state = " - << d_state << "\n msg = " << msg << std::endl; - - if (pmt_eq(msg->port_id(), d_cs->port_symbol()) // ack on cs - && pmt_eq(msg->signal(), s_ack) - && d_state == WAIT_FOR_ACK){ - - send_next_msg(); - return; - } - - if (pmt_eq(msg->port_id(), d_in->port_symbol()) // data on in - && pmt_eq(msg->signal(), s_data) - && d_state == WAIT_FOR_DATA){ - - /* - * Confirm that msg passed through the pipe that we expect... - */ - static const long expected_mask[2] = { 0x000000ff, 0x0000ff00 }; - - long msg_number = pmt_to_long(pmt_car(msg->data())); - long mask = pmt_to_long(pmt_cdr(msg->data())); - - if (mask != expected_mask[which_pipe(msg_number)]){ - fprintf(stderr, "\nqa_disconnect_top: wrong mask in msg_number = 0x%08lx\n", - msg_number); - fprintf(stderr, " expected = 0x%08lx, actual = 0x%08lx\n", - expected_mask[which_pipe(msg_number)], mask); - shutdown_all(PMT_F); - return; - } - - if (msg_number == d_nmsgs_to_send - 1){ // we're done (and were successful) - shutdown_all(PMT_T); - return; - } - - check_pipe_send_next_msg(); - return; - } - - if (pmt_eq(msg->port_id(), s_sys_port) // ignore %shutdown on %sys-port - && pmt_eq(msg->signal(), s_shutdown)) - return; - - std::cerr << "qa_disconnect_top: unhandled msg: state = " - << d_state << "\n msg = " << msg << std::endl; -} - -void -qa_disconnect_top::select_pipe(int n) -{ - d_cs->send(s_select_pipe, pmt_list1(pmt_from_long(n))); - d_state = WAIT_FOR_ACK; -} - -void -qa_disconnect_top::send_next_msg() -{ - d_state = WAIT_FOR_DATA; - if (d_msg_number == d_nmsgs_to_send) // we've sent all we're supposed to - return; - - d_out->send(s_data, pmt_cons(pmt_from_long(d_msg_number), s_long0)); - d_msg_number++; -} - -void -qa_disconnect_top::check_pipe_send_next_msg() -{ - if (time_to_switch()) - select_pipe(which_pipe(d_msg_number)); - else - send_next_msg(); -} - -REGISTER_MBLOCK_CLASS(qa_disconnect_top); diff --git a/mblock/src/lib/qa_mblock.cc b/mblock/src/lib/qa_mblock.cc deleted file mode 100644 index c0629790d3..0000000000 --- a/mblock/src/lib/qa_mblock.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * This class gathers together all the test cases for mblock into - * a single test suite. As you create new test cases, add them here. - */ - -#include <qa_mblock.h> -#include <qa_mblock_prims.h> -#include <qa_mblock_send.h> -#include <qa_mblock_sys.h> -#include <qa_timeouts.h> - -CppUnit::TestSuite * -qa_mblock::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("mblock"); - - s->addTest (qa_mblock_prims::suite()); - s->addTest (qa_mblock_send::suite()); - s->addTest (qa_mblock_sys::suite()); - s->addTest (qa_timeouts::suite()); - - return s; -} diff --git a/mblock/src/lib/qa_mblock.h b/mblock/src/lib/qa_mblock.h deleted file mode 100644 index 056c422377..0000000000 --- a/mblock/src/lib/qa_mblock.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef INCLUDED_QA_MBLOCK_H -#define INCLUDED_QA_MBLOCK_H - -#include <cppunit/TestSuite.h> - -//! collect all the tests for mblock - -class qa_mblock { - public: - //! return suite of tests for all of mblock - static CppUnit::TestSuite *suite(); -}; - -#endif /* INCLUDED_QA_MBLOCK_H */ diff --git a/mblock/src/lib/qa_mblock_prims.cc b/mblock/src/lib/qa_mblock_prims.cc deleted file mode 100644 index e49bd60d4d..0000000000 --- a/mblock/src/lib/qa_mblock_prims.cc +++ /dev/null @@ -1,448 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_prims.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> - -using namespace pmt; - -static pmt_t s_cs = pmt_intern("cs"); -static pmt_t s_debug = pmt_intern("debug"); -static pmt_t s_in = pmt_intern("in"); -static pmt_t s_out = pmt_intern("out"); - - -// ================================================================ - -class dp_1 : public mb_mblock -{ -public: - dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_1(); -}; - -dp_1::dp_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ -} - -dp_1::~dp_1(){} - -REGISTER_MBLOCK_CLASS(dp_1); - -// ---------------------------------------------------------------- - -class dp_2 : public mb_mblock -{ -public: - dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_2(); -}; - -dp_2::dp_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); -} - -dp_2::~dp_2(){} - -REGISTER_MBLOCK_CLASS(dp_2); - -// ---------------------------------------------------------------- - -class dp_3 : public mb_mblock -{ -public: - dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dp_3(); -}; - -dp_3::dp_3(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); - define_port("cs", "cs-protocol", false, mb_port::EXTERNAL); // duplicate def -} - -dp_3::~dp_3(){} - -REGISTER_MBLOCK_CLASS(dp_3); - -// ---------------------------------------------------------------- - -void -qa_mblock_prims::test_define_ports() -{ - - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // Should work - mb_mblock_sptr mb1 = mb_mblock_sptr(new dp_1(rt, "top", PMT_F)); - - // raises runtime_error because of unknown protocol "cs-protocol" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_2(rt, "top", PMT_F)), - std::runtime_error); - - // define the protocol class - pmt_t pc = mb_make_protocol_class(pmt_intern("cs-protocol"), - pmt_list2(pmt_intern("start"), - pmt_intern("stop")), - PMT_NIL); - - // std::cout << "pc = " << pc << '\n'; - - mb_mblock_sptr mb2 = mb_mblock_sptr(new dp_2(rt, "top", PMT_F)); - - // raises pmt_exception because of duplicate port definition of "cs" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dp_3(rt, "top", PMT_F)), - mbe_duplicate_port); -} - -// ================================================================ - -class dc_0 : public mb_mblock -{ -public: - dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_0(); -}; - -dc_0::dc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ -} - -dc_0::~dc_0() {} - -REGISTER_MBLOCK_CLASS(dc_0); - -// ---------------------------------------------------------------- - -class dc_ok : public mb_mblock -{ -public: - dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_ok(); -}; - -dc_ok::dc_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "dc_0"); - define_component("c1", "dc_0"); - define_component("c2", "dc_0"); -} - -dc_ok::~dc_ok(){} - -REGISTER_MBLOCK_CLASS(dc_ok); - -// ---------------------------------------------------------------- - -class dc_not_ok : public mb_mblock -{ -public: - dc_not_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~dc_not_ok(); -}; - -dc_not_ok::dc_not_ok(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "dc_0"); - define_component("c0", "dc_0"); // duplicate name -} - -dc_not_ok::~dc_not_ok(){} - -REGISTER_MBLOCK_CLASS(dc_not_ok); - -// ---------------------------------------------------------------- - -void -qa_mblock_prims::test_define_components() -{ - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // Should work - mb_mblock_sptr mb1 = mb_mblock_sptr(new dc_ok(rt, "top", PMT_F)); - - // raises pmt_exception because of duplicate component definition of "c0" - CPPUNIT_ASSERT_THROW(mb_mblock_sptr(new dc_not_ok(rt, "top", PMT_F)), - mbe_duplicate_component); -} - -// ================================================================ - -class tc_norm : public mb_mblock -{ -public: - tc_norm(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_port("data", "i/o", false, mb_port::EXTERNAL); - define_port("norm", "i/o", false, mb_port::EXTERNAL); - define_port("conj", "i/o", true, mb_port::EXTERNAL); - define_port("int", "i/o", false, mb_port::INTERNAL); - } - - ~tc_norm(); -}; - -tc_norm::~tc_norm(){} - -REGISTER_MBLOCK_CLASS(tc_norm); - -//////////////////////////////////////////////////////////////// - -class tc_0 : public mb_mblock -{ -public: - tc_0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_port("norm", "i/o", false, mb_port::EXTERNAL); - define_port("conj", "i/o", true, mb_port::EXTERNAL); - define_port("int", "i/o", false, mb_port::INTERNAL); - - define_component("c0", "tc_norm"); - define_component("c1", "tc_norm"); - define_component("c2", "tc_norm"); - define_component("c3", "tc_norm"); - define_component("c4", "tc_norm"); - define_component("c5", "tc_norm"); - - // OK - connect("c0", "norm", "c1", "conj"); - - // No: No such component name - CPPUNIT_ASSERT_THROW(connect("foo", "data", "c1", "norm"), mbe_no_such_component); - - // No: No such port name - CPPUNIT_ASSERT_THROW(connect("c0", "data", "c1", "foo"), mbe_no_such_port); - - // No: already connected - CPPUNIT_ASSERT_THROW(connect("c0", "norm", "c2", "data"), mbe_already_connected); - - // No: already connected - CPPUNIT_ASSERT_THROW(connect("c2", "data", "c0", "norm"), mbe_already_connected); - - // No: incompatible ports - CPPUNIT_ASSERT_THROW(connect("c1", "norm", "c2", "norm"), mbe_incompatible_ports); - - // OK - connect("c1", "norm", "c2", "conj"); - - // No: No such port name - CPPUNIT_ASSERT_THROW(connect("c2", "norm", "self", "foo"), mbe_no_such_port); - - // No: can't connect to child's internal port - CPPUNIT_ASSERT_THROW(connect("c0", "conj", "c2", "int"), mbe_no_such_port); - - // No: can't connect to our own external port - CPPUNIT_ASSERT_THROW(connect("self", "norm", "c0", "conj"), mbe_invalid_port_type); - - // OK: connecting to one of our internal ports - connect("self", "int", "c3", "conj"); - - // ===== Now test disconnecting some stuff ===== - - // Confirm we're already connected - CPPUNIT_ASSERT_THROW(connect("self", "int", "c3", "conj"), mbe_already_connected); - - int nc = nconnections(); - disconnect("self", "int", "c3", "conj"); // disconnect - CPPUNIT_ASSERT_EQUAL(nc-1, nconnections()); - - connect("self", "int", "c3", "conj"); // reconnect - CPPUNIT_ASSERT_EQUAL(nc, nconnections()); - - // confirm we're already connected - CPPUNIT_ASSERT_THROW(connect("self", "int", "c3", "conj"), mbe_already_connected); - - - connect("c0", "conj", "c5", "data"); - connect("c4", "norm", "c5", "conj"); - connect("c4", "conj", "c5", "norm"); - - nc = nconnections(); - disconnect_component("c4"); - CPPUNIT_ASSERT_EQUAL(nc-2, nconnections()); - - disconnect_component("c5"); - CPPUNIT_ASSERT_EQUAL(nc-3, nconnections()); - - disconnect_all(); - CPPUNIT_ASSERT_EQUAL(0, nconnections()); - - } - - ~tc_0(); -}; - -tc_0::~tc_0(){} - -REGISTER_MBLOCK_CLASS(tc_0); - -//////////////////////////////////////////////////////////////// - -class tc_1 : public mb_mblock -{ -public: - tc_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) - { - define_component("c0", "tc_norm"); - define_component("c1", "tc_norm"); - - connect("c0", "norm", "c1", "conj"); - } - - ~tc_1(); -}; - -tc_1::~tc_1(){} - -REGISTER_MBLOCK_CLASS(tc_1); - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_connect() -{ - // define the protocol class - mb_make_protocol_class(pmt_intern("data"), // name of class - pmt_list1(pmt_intern("data")), // in - PMT_NIL); // out - - mb_make_protocol_class(pmt_intern("i/o"), // name of class - pmt_list1(pmt_intern("in")), // in - pmt_list1(pmt_intern("out"))); // out - - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - mb_mblock_sptr mb0 = mb_mblock_sptr(new tc_0(rt, "top", PMT_F)); -} - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_msg_queue() -{ - mb_msg_queue q; - - // check initial state - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); - - CPPUNIT_ASSERT(MB_NPRI >= 5); // sanity check for this test - - // insert three messages at the same pri and ensure that they come out in order - // signal data metadata pri - q.insert(mb_make_message(PMT_NIL, pmt_from_long(0), PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, pmt_from_long(1), PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, pmt_from_long(2), PMT_NIL, MB_PRI_BEST + 2)); - - CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(q.get_highest_pri_msg_nowait()->data())); - - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); - - - // insert messages of different priorities in pseudo-random order - // signal data metadata pri - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 3)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 4)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 0)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 1)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 3)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 2)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 4)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 0)); - q.insert(mb_make_message(PMT_NIL, PMT_NIL, PMT_NIL, MB_PRI_BEST + 1)); - - // confirm that they come out in order - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 0, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 1, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 2, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 3, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority()); - CPPUNIT_ASSERT_EQUAL(MB_PRI_BEST + 4, q.get_highest_pri_msg_nowait()->priority()); - - // check final state - CPPUNIT_ASSERT(q.get_highest_pri_msg_nowait() == 0); -} - -//////////////////////////////////////////////////////////////// - -void -qa_mblock_prims::test_make_accepter() -{ - mb_runtime_sptr rts = mb_make_runtime(); - mb_runtime *rt = rts.get(); - - // create a block - mb_mblock_sptr mb = mb_mblock_sptr(new dp_2(rt, "top", PMT_F)); - - // use "internal use only" method... - mb_msg_accepter_sptr accepter = mb->impl()->make_accepter(pmt_intern("cs")); - - // Now push a few messages into it... - // signal data metadata pri - (*accepter)(PMT_NIL, pmt_from_long(0), PMT_NIL, MB_PRI_BEST + 2); - (*accepter)(PMT_NIL, pmt_from_long(1), PMT_NIL, MB_PRI_BEST + 2); - (*accepter)(PMT_NIL, pmt_from_long(2), PMT_NIL, MB_PRI_BEST + 2); - - // try to pull them out - - pmt_t cs = pmt_intern("cs"); - - mb_message_sptr msg = mb->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(pmt_eq(cs, msg->port_id())); // confirm that port_id is set - CPPUNIT_ASSERT_EQUAL(0L, pmt_to_long(msg->data())); // and that data is correct - - CPPUNIT_ASSERT_EQUAL(1L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data())); - CPPUNIT_ASSERT_EQUAL(2L, pmt_to_long(mb->impl()->msgq().get_highest_pri_msg_nowait()->data())); -} diff --git a/mblock/src/lib/qa_mblock_prims.h b/mblock/src/lib/qa_mblock_prims.h deleted file mode 100644 index cf928ee4f8..0000000000 --- a/mblock/src/lib/qa_mblock_prims.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_PRIMS_H -#define INCLUDED_QA_MBLOCK_PRIMS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_prims : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_prims); - CPPUNIT_TEST(test_define_ports); - CPPUNIT_TEST(test_define_components); - CPPUNIT_TEST(test_connect); - CPPUNIT_TEST(test_msg_queue); - CPPUNIT_TEST(test_make_accepter); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_define_ports(); - void test_define_components(); - void test_connect(); - void test_msg_queue(); - void test_make_accepter(); -}; - -#endif /* INCLUDED_QA_MBLOCK_PRIMS_H */ - diff --git a/mblock/src/lib/qa_mblock_send.cc b/mblock/src/lib/qa_mblock_send.cc deleted file mode 100644 index 53f93927b5..0000000000 --- a/mblock/src/lib/qa_mblock_send.cc +++ /dev/null @@ -1,477 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_send.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> - -using namespace pmt; - -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_status = pmt_intern("status"); -static pmt_t s_control = pmt_intern("control"); -static pmt_t s_p0 = pmt_intern("p0"); -static pmt_t s_p1 = pmt_intern("p1"); -static pmt_t s_p2 = pmt_intern("p2"); -static pmt_t s_p3 = pmt_intern("p3"); -static pmt_t s_e1 = pmt_intern("e1"); -static pmt_t s_r1 = pmt_intern("r1"); - -static void -define_protocol_classes() -{ - // Defined from client point-of-view. - mb_make_protocol_class(pmt_intern("qa-send-cs"), // name - pmt_list1(s_status), // incoming - pmt_list1(s_control)); // outgoing - -} - -mb_mblock_sptr -get_top(mb_runtime_sptr rts) -{ - return dynamic_cast<mb_runtime_nop *>(rts.get())->top(); -} - -// ================================================================ -// test_simple_routing -// ================================================================ - -// sub-block for test_simple_routing - -class sr1 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - mb_port_sptr d_p3; - -public: - sr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sr1(); - void initial_transition(); -}; - -sr1::sr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL); - d_p2 = define_port("p2", "qa-send-cs", true, mb_port::EXTERNAL); - d_p3 = define_port("p3", "qa-send-cs", false, mb_port::EXTERNAL); -} - -sr1::~sr1(){} - -void -sr1::initial_transition() -{ - // std::cout << instance_name() << "[sr1]: initial_transition\n"; - - // send two messages to each port - pmt_t our_name = pmt_intern(instance_name()); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); - - d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(0))); - d_p2->send(s_status, pmt_list3(our_name, s_p2, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(sr1); - -// ---------------------------------------------------------------- - -// top-level container block for test_simple_routing -class sr0 : public mb_mblock -{ - mb_port_sptr d_p0; - -public: - sr0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sr0(); - void initial_transition(); -}; - -sr0::sr0(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p0 = define_port("p0", "qa-send-cs", false, mb_port::INTERNAL); - - define_component("mb1", "sr1"); - define_component("mb2", "sr1"); - - connect("self", "p0", "mb1", "p1"); - connect("mb1", "p2", "mb2", "p3"); - connect("mb1", "p3", "mb2", "p2"); -} - -sr0::~sr0(){} - -void -sr0::initial_transition() -{ - // std::cout << instance_name() << "[sr0]: initial_transition\n"; - - // send two messages to p0 - pmt_t our_name = pmt_intern(instance_name()); - d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(0))); - d_p0->send(s_control, pmt_list3(our_name, s_p0, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(sr0); - -// ---------------------------------------------------------------- - -/* - * This tests basic message routing using INTERNAL and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_simple_routing() -{ - define_protocol_classes(); - - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "sr0", PMT_F); - - mb_mblock_sptr mb0 = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - // mb0 should have received two messages sent from mb1 via its p1 - msg = mb0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = mb0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p0, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p1, pmt_from_long(1)), - msg->data())); - - // mb1 should have received - // two messages from mb0 via its p0 and - // two messages from mb2 via its p3 - - mb_mblock_sptr mb1 = mb0->impl()->component("mb1"); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(0)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p1, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top"), s_p0, pmt_from_long(1)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(0)), - msg->data())); - - msg = mb1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb2"), s_p2, pmt_from_long(1)), - msg->data())); - - - // mb2 should have received - // two messages from mb2 via its p2 - - mb_mblock_sptr mb2 = mb0->impl()->component("mb2"); - - msg = mb2->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(0)), - msg->data())); - - msg = mb2->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p3, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/mb1"), s_p2, pmt_from_long(1)), - msg->data())); -} - -// ================================================================ -// test_relay_routing_1 -// ================================================================ - -// internal block for test_relay_routing - -class rr2 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - -public: - rr2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr2(); - void initial_transition(); -}; - -rr2::rr2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::EXTERNAL); - d_p2 = define_port("p2", "qa-send-cs", false, mb_port::EXTERNAL); -} - -rr2::~rr2(){} - -void -rr2::initial_transition() -{ - // std::cout << instance_name() << "[rr2]: initial_transition\n"; - - // send two messages via p1 - pmt_t our_name = pmt_intern(instance_name()); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(0))); - d_p1->send(s_status, pmt_list3(our_name, s_p1, pmt_from_long(1))); -} - -REGISTER_MBLOCK_CLASS(rr2); - -// ---------------------------------------------------------------- - -// intermediate block for test_relay_routing - -class rr1 : public mb_mblock -{ - mb_port_sptr d_p1; - mb_port_sptr d_p2; - -public: - rr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr1(); -}; - -rr1::rr1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_p1 = define_port("p1", "qa-send-cs", true, mb_port::RELAY); - d_p2 = define_port("p2", "qa-send-cs", false, mb_port::RELAY); - - define_component("c0", "rr2"); - - connect("self", "p1", "c0", "p1"); - connect("self", "p2", "c0", "p2"); -} - -rr1::~rr1(){} - -REGISTER_MBLOCK_CLASS(rr1); - -// ---------------------------------------------------------------- - -// top-level container for test_relay_routing - -class rr0_a : public mb_mblock -{ -public: - rr0_a(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr0_a(); -}; - -rr0_a::rr0_a(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "rr1"); - define_component("c1", "rr2"); - - connect("c0", "p1", "c1", "p2"); - connect("c0", "p2", "c1", "p1"); -} - -rr0_a::~rr0_a(){} - -REGISTER_MBLOCK_CLASS(rr0_a); - -/* - * This tests basic message routing using RELAY and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_relay_routing_1() -{ - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "rr0_a", PMT_F); - mb_mblock_sptr top = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - mb_mblock_sptr c0 = top->impl()->component("c0"); - mb_mblock_sptr c0c0 = c0->impl()->component("c0"); - - mb_mblock_sptr c1 = top->impl()->component("c1"); - - // c0c0 should have received - // two message from c1 via its p2 - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1"), s_p1, pmt_from_long(1)), - msg->data())); - - // c1 should have received - // two message from c0c0 via its p2 - - msg = c1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c1->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - //std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)), - msg->data())); -} - -// ================================================================ -// test_relay_routing_2 -// ================================================================ - -// top-level container for test_relay_routing_2 - -class rr0_b : public mb_mblock -{ -public: - rr0_b(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~rr0_b(); -}; - -rr0_b::rr0_b(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - define_component("c0", "rr1"); - define_component("c1", "rr1"); - - connect("c0", "p1", "c1", "p2"); - connect("c0", "p2", "c1", "p1"); -} - -rr0_b::~rr0_b(){} - -REGISTER_MBLOCK_CLASS(rr0_b); - -/* - * This tests basic message routing using RELAY and EXTERNAL ports. - * It does not rely on the guts of the runtime being complete, - * which is good, because at the time this is being written, it isn't. - */ -void -qa_mblock_send::test_relay_routing_2() -{ - mb_message_sptr msg; - - mb_runtime_sptr rt = mb_make_runtime_nop(); - rt->run("top", "rr0_b", PMT_F); - mb_mblock_sptr top = get_top(rt); - - // Reach into the guts and see if the messages ended up where they should have - - mb_mblock_sptr c0 = top->impl()->component("c0"); - mb_mblock_sptr c0c0 = c0->impl()->component("c0"); - - mb_mblock_sptr c1 = top->impl()->component("c1"); - mb_mblock_sptr c1c0 = c1->impl()->component("c0"); - - // c0c0 should have received - // two message from c1c0 via its p2 - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c0c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c1/c0"), s_p1, pmt_from_long(1)), - msg->data())); - - // c1c0 should have received - // two message from c0c0 via its p2 - - msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(0)), - msg->data())); - - msg = c1c0->impl()->msgq().get_highest_pri_msg_nowait(); - CPPUNIT_ASSERT(msg); - // std::cerr << msg->data() << std::endl; - CPPUNIT_ASSERT_EQUAL(s_p2, msg->port_id()); - CPPUNIT_ASSERT(pmt_equal(pmt_list3(pmt_intern("top/c0/c0"), s_p1, pmt_from_long(1)), - msg->data())); -} diff --git a/mblock/src/lib/qa_mblock_send.h b/mblock/src/lib/qa_mblock_send.h deleted file mode 100644 index b1a6832ce1..0000000000 --- a/mblock/src/lib/qa_mblock_send.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_SEND_H -#define INCLUDED_QA_MBLOCK_SEND_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_send : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_send); - CPPUNIT_TEST(test_simple_routing); - CPPUNIT_TEST(test_relay_routing_1); - CPPUNIT_TEST(test_relay_routing_2); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_simple_routing(); - void test_relay_routing_1(); - void test_relay_routing_2(); -}; - -#endif /* INCLUDED_QA_MBLOCK_SEND_H */ - diff --git a/mblock/src/lib/qa_mblock_sys.cc b/mblock/src/lib/qa_mblock_sys.cc deleted file mode 100644 index 8c8dbbf0ab..0000000000 --- a/mblock/src/lib/qa_mblock_sys.cc +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_mblock_sys.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <stdio.h> -#include <string.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_data = pmt_intern("data"); -static pmt_t s_status = pmt_intern("status"); -static pmt_t s_control = pmt_intern("control"); -static pmt_t s_p0 = pmt_intern("p0"); -static pmt_t s_p1 = pmt_intern("p1"); -static pmt_t s_p2 = pmt_intern("p2"); -static pmt_t s_p3 = pmt_intern("p3"); -static pmt_t s_e1 = pmt_intern("e1"); -static pmt_t s_r1 = pmt_intern("r1"); - -static void -define_protocol_classes() -{ - mb_make_protocol_class(s_data, // name - pmt_list1(s_data), // incoming - pmt_list1(s_data)); // outgoing -} - - -// ================================================================ -// test_sys_1 -// ================================================================ - -class sys_1 : public mb_mblock -{ - pmt_t d_user_arg; - mb_port_sptr d_data; - -public: - sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~sys_1(); - void initial_transition(); -}; - -sys_1::sys_1(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_user_arg(user_arg) -{ - d_data = define_port("data", "data", true, mb_port::EXTERNAL); -} - -sys_1::~sys_1(){} - -void -sys_1::initial_transition() -{ - shutdown_all(d_user_arg); -} - -REGISTER_MBLOCK_CLASS(sys_1); - -void -qa_mblock_sys::test_sys_1() -{ - define_protocol_classes(); - - pmt_t result; - pmt_t n1 = pmt_from_long(1); - pmt_t n2 = pmt_from_long(2); - - mb_runtime_sptr rt1 = mb_make_runtime(); - -#if 0 - try { - rt1->run("top-1", "sys_1", n1, &result); - } - catch (omni_thread_fatal e){ - std::cerr << "caught omni_thread_fatal: error = " << e.error - << ": " << strerror(e.error) << std::endl; - } - catch (omni_thread_invalid){ - std::cerr << "caught omni_thread_invalid\n"; - } -#else - rt1->run("top-1", "sys_1", n1, &result); -#endif - CPPUNIT_ASSERT(pmt_equal(n1, result)); - - // Execute run a second time, with the same rt, to ensure sanity. - rt1->run("top-2", "sys_1", n2, &result); - CPPUNIT_ASSERT(pmt_equal(n2, result)); -} - -// ================================================================ -// test_sys_2 -// ================================================================ - -class squarer : public mb_mblock -{ - mb_port_sptr d_data; - -public: - squarer(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - - void handle_message(mb_message_sptr msg); -}; - -squarer::squarer(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_data = define_port("data", "data", true, mb_port::EXTERNAL); -} - -void -squarer::handle_message(mb_message_sptr msg) -{ - if (!pmt_eq(msg->signal(), s_data)) // we only handle the "data" message - return; - - // long x -> (long x . long (x * x)) - - pmt_t x_pmt = msg->data(); - long x = pmt_to_long(x_pmt); - d_data->send(s_data, pmt_cons(x_pmt, pmt_from_long(x * x))); -} - -REGISTER_MBLOCK_CLASS(squarer); - -// ---------------------------------------------------------------- - -class sys_2 : public mb_mblock -{ - mb_port_sptr d_data; - -public: - sys_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -sys_2::sys_2(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_data = define_port("data", "data", true, mb_port::INTERNAL); - define_component("squarer", "squarer"); - connect("self", "data", "squarer", "data"); -} - -void -sys_2::initial_transition() -{ - // FIXME start timer to detect general failure - - d_data->send(s_data, pmt_from_long(0)); // send initial message -} - -void -sys_2::handle_message(mb_message_sptr msg) -{ - if (!pmt_eq(msg->signal(), s_data)) // we only handle the "data" message - return; - - // first check correctness of message - - long x = pmt_to_long(pmt_car(msg->data())); - long y = pmt_to_long(pmt_cdr(msg->data())); - - // std::cout << msg->data() << std::endl; - - if (y != x * x){ - std::cerr << "sys_2::handle_message: Expected y == x * x. Got y = " - << y << " for x = " << x << std::endl; - - shutdown_all(PMT_F); // failed - } - - if (x == 100) - shutdown_all(PMT_T); // done, OK - else - d_data->send(s_data, pmt_from_long(x + 1)); // send next request -} - -REGISTER_MBLOCK_CLASS(sys_2); - -// ---------------------------------------------------------------- - -void -qa_mblock_sys::test_sys_2() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - // std::cerr << "qa_mblock_sys::test_sys_2 (enter)\n"; - - rt->run("top-sys-2", "sys_2", PMT_F, &result); - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ================================================================ -// test_bitset_1 -// ================================================================ - -void -qa_mblock_sys::test_bitset_1() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 1000; - long batch_size = 8; - - pmt_t arg = pmt_list2(pmt_from_long(nmsgs), // # of messages to send through pipe - pmt_from_long(batch_size)); - - rt->run("top", "qa_bitset_top", arg, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ================================================================ -// test_disconnect -// ================================================================ - -void -qa_mblock_sys::test_disconnect() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - long nmsgs = 10240; - - pmt_t arg = pmt_list1(pmt_from_long(nmsgs)); // # of messages to send through pipe - - - rt->run("top", "qa_disconnect_top", arg, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} diff --git a/mblock/src/lib/qa_mblock_sys.h b/mblock/src/lib/qa_mblock_sys.h deleted file mode 100644 index 0e0053a5d8..0000000000 --- a/mblock/src/lib/qa_mblock_sys.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_MBLOCK_SYS_H -#define INCLUDED_QA_MBLOCK_SYS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_mblock_sys : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_mblock_sys); - CPPUNIT_TEST(test_sys_1); - CPPUNIT_TEST(test_sys_2); - CPPUNIT_TEST(test_bitset_1); - CPPUNIT_TEST(test_disconnect); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_sys_1(); - void test_sys_2(); - void test_bitset_1(); - void test_disconnect(); -}; - -#endif /* INCLUDED_QA_MBLOCK_SYS_H */ - diff --git a/mblock/src/lib/qa_timeouts.cc b/mblock/src/lib/qa_timeouts.cc deleted file mode 100644 index b230f86d8d..0000000000 --- a/mblock/src/lib/qa_timeouts.cc +++ /dev/null @@ -1,291 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <qa_timeouts.h> -#include <cppunit/TestAssert.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <mb_timer_queue.h> -#include <string.h> -#include <iostream> - -using namespace pmt; - -static pmt_t s_timeout = pmt_intern("%timeout"); -static pmt_t s_done = pmt_intern("done"); - - -// ------------------------------------------------------------------------ -// Exercise the priority queue used to implement timeouts. -// ------------------------------------------------------------------------ -void -qa_timeouts::test_timer_queue() -{ - mb_timer_queue tq; - mb_msg_accepter_sptr accepter; - - mb_timeout_sptr t1000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(1000,0), PMT_F, accepter)); - - mb_timeout_sptr t2000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(2000,0), PMT_F, accepter)); - - mb_timeout_sptr t3000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,0), PMT_F, accepter)); - - mb_timeout_sptr t3000_125 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,125), PMT_F, accepter)); - - mb_timeout_sptr t3000_250 = - mb_timeout_sptr(new mb_timeout(mb_time(3000,250), PMT_F, accepter)); - - mb_timeout_sptr t4000_000 = - mb_timeout_sptr(new mb_timeout(mb_time(4000,0), PMT_F, accepter)); - - // insert in pseudo-random order - - tq.push(t3000_125); - tq.push(t1000_000); - tq.push(t4000_000); - tq.push(t3000_250); - tq.push(t2000_000); - tq.push(t3000_000); - - CPPUNIT_ASSERT_EQUAL(t1000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_250, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT(tq.empty()); - - // insert in pseudo-random order - - tq.push(t3000_000); - tq.push(t4000_000); - tq.push(t3000_125); - tq.push(t1000_000); - tq.push(t2000_000); - tq.push(t3000_250); - - tq.cancel(t1000_000->handle()); - - CPPUNIT_ASSERT_EQUAL(t2000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t3000_000, tq.top()); - tq.pop(); - - tq.cancel(t3000_250->handle()); - - CPPUNIT_ASSERT_EQUAL(t3000_125, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT_EQUAL(t4000_000, tq.top()); - tq.pop(); - - CPPUNIT_ASSERT(tq.empty()); -} - -// ------------------------------------------------------------------------ -// Test one-shot timeouts -// ------------------------------------------------------------------------ - -// FWIW, on SuSE 10.1 for x86-64, clock_getres returns 0.004 seconds. - -// #define TIMING_MARGIN 0.010 // seconds // was failing on some systems -#define TIMING_MARGIN 0.025 // seconds (really sloppy; consider enabling RT scheduler) - - -class qa_timeouts_1_top : public mb_mblock -{ - int d_nleft; - int d_nerrors; - mb_time d_t0; - -public: - qa_timeouts_1_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg); - - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_timeouts_1_top::qa_timeouts_1_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nleft(0), d_nerrors(0) -{ -} - -void -qa_timeouts_1_top::initial_transition() -{ - d_t0 = mb_time::time(); // now - - schedule_one_shot_timeout(d_t0 + 0.200, pmt_from_double(0.200)); - schedule_one_shot_timeout(d_t0 + 0.125, pmt_from_double(0.125)); - schedule_one_shot_timeout(d_t0 + 0.075, pmt_from_double(0.075)); - schedule_one_shot_timeout(d_t0 + 0.175, pmt_from_double(0.175)); - - d_nleft = 4; -} - -void -qa_timeouts_1_top::handle_message(mb_message_sptr msg) -{ - if (pmt_eq(msg->signal(), s_timeout)){ - mb_time t_now = mb_time::time(); - double expected_delta_t = pmt_to_double(msg->data()); - double actual_delta_t = (t_now - d_t0).double_time(); - double delta = expected_delta_t - actual_delta_t; - - if (fabs(delta) > TIMING_MARGIN){ - std::cerr << "qa_timeouts_1_top: expected_delta_t = " << expected_delta_t - << " actual_delta_t = " << actual_delta_t << std::endl; - d_nerrors++; - } - - if (--d_nleft <= 0) - shutdown_all(d_nerrors == 0 ? PMT_T : PMT_F); - } -} - -REGISTER_MBLOCK_CLASS(qa_timeouts_1_top); - -void -qa_timeouts::test_timeouts_1() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "qa_timeouts_1_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -// ------------------------------------------------------------------------ -// Test periodic timeouts -// ------------------------------------------------------------------------ - -class qa_timeouts_2_top : public mb_mblock -{ - int d_nhandled; - int d_nerrors; - double d_delta_t; - mb_time d_t0; - -public: - qa_timeouts_2_top(mb_runtime *runtime, - const std::string &instance_name, pmt_t user_arg); - - void initial_transition(); - void handle_message(mb_message_sptr msg); -}; - -qa_timeouts_2_top::qa_timeouts_2_top(mb_runtime *runtime, - const std::string &instance_name, - pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_nhandled(0), d_nerrors(0), d_delta_t(0.075) -{ -} - -void -qa_timeouts_2_top::initial_transition() -{ - d_t0 = mb_time::time(); // now - - schedule_periodic_timeout(d_t0 + d_delta_t, mb_time(d_delta_t), PMT_T); -} - -void -qa_timeouts_2_top::handle_message(mb_message_sptr msg) -{ - static const int NMSGS_TO_HANDLE = 5; - - if (pmt_eq(msg->signal(), s_timeout) - && !pmt_eq(msg->data(), s_done)){ - - mb_time t_now = mb_time::time(); - - d_nhandled++; - - double expected_delta_t = d_delta_t * d_nhandled; - double actual_delta_t = (t_now - d_t0).double_time(); - double delta = expected_delta_t - actual_delta_t; - - if (fabs(delta) > TIMING_MARGIN){ - std::cerr << "qa_timeouts_2_top: expected_delta_t = " << expected_delta_t - << " actual_delta_t = " << actual_delta_t << std::endl; - d_nerrors++; - } - - if (d_nhandled == NMSGS_TO_HANDLE){ - cancel_timeout(msg->metadata()); // test cancel_timeout... - schedule_one_shot_timeout(d_t0 + (d_delta_t * (d_nhandled + 2)), s_done); - } - } - - if (pmt_eq(msg->signal(), s_timeout) - && pmt_eq(msg->data(), s_done)){ - if (d_nhandled != NMSGS_TO_HANDLE){ - std::cerr << "qa_timeouts_2_top: d_nhandled = " << d_nhandled - << " expected d_nhandled = " << NMSGS_TO_HANDLE - << " (cancel_timeout didn't work)\n"; - d_nerrors++; - } - shutdown_all(d_nerrors == 0 ? PMT_T : PMT_F); - } -} - -REGISTER_MBLOCK_CLASS(qa_timeouts_2_top); - -void -qa_timeouts::test_timeouts_2() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "qa_timeouts_2_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} diff --git a/mblock/src/lib/qa_timeouts.h b/mblock/src/lib/qa_timeouts.h deleted file mode 100644 index 7c64436467..0000000000 --- a/mblock/src/lib/qa_timeouts.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006,2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef INCLUDED_QA_TIMEOUTS_H -#define INCLUDED_QA_TIMEOUTS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_timeouts : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_timeouts); - CPPUNIT_TEST(test_timer_queue); - CPPUNIT_TEST(test_timeouts_1); - CPPUNIT_TEST(test_timeouts_2); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_timer_queue(); - void test_timeouts_1(); - void test_timeouts_2(); -}; - -#endif /* INCLUDED_QA_TIMEOUTS_H */ - diff --git a/mblock/src/lib/test_mblock.cc b/mblock/src/lib/test_mblock.cc deleted file mode 100644 index b98d1b5a73..0000000000 --- a/mblock/src/lib/test_mblock.cc +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <cppunit/TextTestRunner.h> -#include <qa_mblock.h> - -int -main(int argc, char **argv) -{ - - CppUnit::TextTestRunner runner; - - runner.addTest(qa_mblock::suite ()); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} diff --git a/mblock/src/scheme/.gitignore b/mblock/src/scheme/.gitignore deleted file mode 100644 index a02b6ff73c..0000000000 --- a/mblock/src/scheme/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/mblock/src/scheme/Makefile.am b/mblock/src/scheme/Makefile.am deleted file mode 100644 index 4980063d70..0000000000 --- a/mblock/src/scheme/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -# -# Copyright 2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -SUBDIRS = gnuradio diff --git a/mblock/src/scheme/gnuradio/.gitignore b/mblock/src/scheme/gnuradio/.gitignore deleted file mode 100644 index a02b6ff73c..0000000000 --- a/mblock/src/scheme/gnuradio/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo diff --git a/mblock/src/scheme/gnuradio/Makefile.am b/mblock/src/scheme/gnuradio/Makefile.am deleted file mode 100644 index e9bfc88e94..0000000000 --- a/mblock/src/scheme/gnuradio/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -EXTRA_DIST = \ - compile-mbh.scm - diff --git a/mblock/src/scheme/gnuradio/compile-mbh.scm b/mblock/src/scheme/gnuradio/compile-mbh.scm deleted file mode 100755 index 30085340f9..0000000000 --- a/mblock/src/scheme/gnuradio/compile-mbh.scm +++ /dev/null @@ -1,231 +0,0 @@ -#!/usr/bin/guile \ --e main -s -!# -;; -*-scheme-*- -;; -;; Copyright 2007,2008 Free Software Foundation, Inc. -;; -;; This file is part of GNU Radio -;; -;; GNU Radio 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 3, or (at your option) -;; any later version. -;; -;; GNU Radio 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., -;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -;; - -;; usage: compile-mbh <input-file> <output-file> - -(use-modules (ice-9 getopt-long)) -(use-modules (ice-9 format)) -(use-modules (ice-9 pretty-print)) -;(use-modules (ice-9 slib)) -(use-modules (gnuradio pmt-serialize)) -(use-modules (gnuradio macros-etc)) - -(debug-enable 'backtrace) - -;; ---------------------------------------------------------------- - -(define (main args) - - (define (usage) - (format 0 "usage: ~a input-file output-file~%" (car args))) - - (when (not (= (length args) 3)) - (usage) - (exit 1)) - - (let ((input-filename (cadr args)) - (output-filename (caddr args))) - (if (compile-mbh-file input-filename output-filename) - (exit 0) - (exit 1)))) - - -;; ---------------------------------------------------------------- -;; constructor and accessors for protocol-class - -(define %protocol-class-tag (string->symbol "[PROTOCOL-CLASS-TAG]")) - -(define (make-protocol-class name incoming outgoing) - (vector %protocol-class-tag name incoming outgoing)) - -(define (protocol-class? obj) - (and (vector? obj) (eq? %protocol-class-tag (vector-ref obj 0)))) - -(define (protocol-class-name pc) - (vector-ref pc 1)) - -(define (protocol-class-incoming pc) - (vector-ref pc 2)) - -(define (protocol-class-outgoing pc) - (vector-ref pc 3)) - - -;; ---------------------------------------------------------------- - -(define (syntax-error msg e) - (throw 'syntax-error msg e)) - -(define (unrecognized-form form) - (syntax-error "Unrecognized form" form)) - - -(define (mbh-chk-length= e y n) - (cond ((and (null? y)(zero? n)) - #f) - ((null? y) - (syntax-error "Expression has too few subexpressions" e)) - ((atom? y) - (syntax-error (if (atom? e) - "List expected" - "Expression ends with `dotted' atom") - e)) - ((zero? n) - (syntax-error "Expression has too many subexpressions" e)) - (else - (mbh-chk-length= e (cdr y) (- n 1))))) - -(define (mbh-chk-length>= e y n) - (cond ((and (null? y)(< n 1)) - #f) - ((atom? y) - (mbh-chk-length= e y -1)) - (else - (mbh-chk-length>= e (cdr y) (- n 1))))) - - -(define (compile-mbh-file input-filename output-filename) - (let ((i-port (open-input-file input-filename)) - (o-port (open-output-file output-filename))) - - (letrec - ((protocol-classes '()) ; alist - - (lookup-protocol-class ; returns protocol-class or #f - (lambda (name) - (cond ((assq name protocol-classes) => cdr) - (else #f)))) - - (register-protocol-class - (lambda (pc) - (set! protocol-classes (acons (protocol-class-name pc) - pc protocol-classes)) - pc)) - - (parse-top-level-form - (lambda (form) - (mbh-chk-length>= form form 1) - (case (car form) - ((define-protocol-class) (parse-define-protocol-class form)) - (else (syntax-error form))))) - - (parse-define-protocol-class - (lambda (form) - (mbh-chk-length>= form form 2) - ;; form => (define-protocol-class name - ;; (:include protocol-class-name) - ;; (:incoming list-of-msgs) - ;; (:outgoing list-of-msgs)) - (let ((name (cadr form)) - (incoming '()) - (outgoing '())) - (if (lookup-protocol-class name) - (syntax-error "Duplicate protocol-class name" name)) - (for-each - (lambda (sub-form) - (mbh-chk-length>= sub-form sub-form 1) - (case (car sub-form) - ((:include) - (mbh-chk-length>= sub-form sub-form 2) - (cond ((lookup-protocol-class (cadr sub-form)) => - (lambda (pc) - (set! incoming (append incoming (protocol-class-incoming pc))) - (set! outgoing (append outgoing (protocol-class-outgoing pc))))) - (else - (syntax-error "Unknown protocol-class-name" (cadr sub-form))))) - ((:incoming) - (set! incoming (append incoming (cdr sub-form)))) - ((:outgoing) - (set! outgoing (append outgoing (cdr sub-form)))) - (else - (unrecognized-form (car sub-form))))) - (cddr form)) - - (register-protocol-class (make-protocol-class name incoming outgoing))))) - - ) ; end of bindings - - (for-each-in-file i-port parse-top-level-form) - - ;; generate the output here... - - (letrec ((classes (map cdr protocol-classes)) - (so-stream (make-serial-output-stream)) - (format-output-for-c++ - (lambda (output) - (format o-port "//~%") - (format o-port "// Machine generated by compile-mbh from ~a~%" input-filename) - (format o-port "//~%") - (format o-port "// protocol-classes: ~{~a ~}~%" (map car protocol-classes)) - (format o-port "//~%") - - (format o-port "#include <mblock/protocol_class.h>~%") - (format o-port "#include <unistd.h>~%") - (format o-port - "static const char~%protocol_class_init_data[~d] = {~% " - (length output)) - - (do ((lst output (cdr lst)) - (i 0 (+ i 1))) - ((null? lst) #t) - (format o-port "~a, " (car lst)) - (when (= 15 (modulo i 16)) - (format o-port "~% "))) - - (format o-port "~&};~%") - (format o-port "static mb_protocol_class_init _init_(protocol_class_init_data, sizeof(protocol_class_init_data));~%") - ))) - - - (map (lambda (pc) - (let ((obj-to-dump - (list (protocol-class-name pc) ; class name - (map car (protocol-class-incoming pc)) ; incoming msg names - (map car (protocol-class-outgoing pc)) ; outgoing msg names - ;;(protocol-class-incoming pc) ; full incoming msg descriptions - ;;(protocol-class-outgoing pc) ; full outgoing msg descriptions - ))) - ;;(pretty-print obj-to-dump) - (pmt-serialize obj-to-dump (so-stream 'put-byte)))) - classes) - - (format-output-for-c++ ((so-stream 'get-output))) - - #t)))) - - -(define (make-serial-output-stream) - (letrec ((output '()) - (put-byte - (lambda (byte) - (set! output (cons byte output)))) - (get-output - (lambda () - (reverse output)))) - (lambda (key) - (case key - ((put-byte) put-byte) - ((get-output) get-output) - (else (error "Unknown key" key)))))) - diff --git a/omnithread/.gitignore b/omnithread/.gitignore deleted file mode 100644 index 5a51e3bc3c..0000000000 --- a/omnithread/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/gnuradio-omnithread.pc diff --git a/omnithread/Makefile.am b/omnithread/Makefile.am deleted file mode 100644 index 291cc8beb0..0000000000 --- a/omnithread/Makefile.am +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright 2003,2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = gnuradio - -# This is the omnithread package, -# extracted from the omniORB-4.0.1 distribution - -# we should do some configure hacking to determine these on the fly -OMNITHREAD_DEFINES = -DPthreadDraftVersion=10 - -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_DEFINES) $(OMNITHREAD_INCLUDES) \ - $(WITH_INCLUDES) - -# we call it libgromnithread to avoid a collision with libomnithread on Debian -lib_LTLIBRARIES = libgromnithread.la - -# At this point we only support the posix and nt pthreads i/f... - -if OMNITHREAD_POSIX -libgromnithread_la_SOURCES = \ - omni_time.cc \ - posix.cc -endif - -if OMNITHREAD_NT -libgromnithread_la_SOURCES = \ - omni_time.cc \ - nt.cc -endif - -libgromnithread_la_LDFLAGS = $(NO_UNDEFINED) - -libgromnithread_la_LIBADD = \ - $(PTHREAD_LIBS) - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = gnuradio-omnithread.pc - -# ... but this code also came with the package - -EXTRA_DIST = \ - gnuradio-omnithread.pc.in \ - mach.cc \ - nt.cc \ - posix.cc \ - solaris.cc \ - threaddata.cc \ - vxWorks.cc \ - dir.mk \ - README diff --git a/omnithread/README b/omnithread/README deleted file mode 100644 index 1943d0ed56..0000000000 --- a/omnithread/README +++ /dev/null @@ -1,2 +0,0 @@ -The code in this directory is deprecated, please use the Boost thread -library for new code. diff --git a/omnithread/dir.mk b/omnithread/dir.mk deleted file mode 100644 index d53803417c..0000000000 --- a/omnithread/dir.mk +++ /dev/null @@ -1,229 +0,0 @@ -ifeq ($(ThreadSystem),Solaris) -CXXSRCS = solaris.cc -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) -endif - -ifeq ($(ThreadSystem),Posix) -CXXSRCS = posix.cc -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) $(OMNITHREAD_POSIX_CPPFLAGS) -endif - -ifeq ($(ThreadSystem),NT) -CXXSRCS = nt.cc -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) -MSVC_STATICLIB_CXXNODEBUGFLAGS += -D_WINSTATIC -MSVC_STATICLIB_CXXDEBUGFLAGS += -D_WINSTATIC -MSVC_DLL_CXXNODEBUGFLAGS += -D_OMNITHREAD_DLL -MSVC_DLL_CXXDEBUGFLAGS += -D_OMNITHREAD_DLL -endif - -ifeq ($(ThreadSystem),NTPosix) -CXXSRCS = posix.cc -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) -MSVC_STATICLIB_CXXNODEBUGFLAGS += -D_WINSTATIC -MSVC_STATICLIB_CXXDEBUGFLAGS += -D_WINSTATIC -MSVC_DLL_CXXNODEBUGFLAGS += -D_OMNITHREAD_DLL -MSVC_DLL_CXXDEBUGFLAGS += -D_OMNITHREAD_DLL -endif - -ifeq ($(ThreadSystem),Mach) -CXXSRCS = mach.cc -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) -endif - -ifeq ($(ThreadSystem),vxWorks) -CXXSRCS = vxWorks.cc -OBJS = vxWorks.o -DIR_CPPFLAGS = $(OMNITHREAD_CPPFLAGS) -endif - -LIB_NAME := omnithread -LIB_VERSION := $(OMNITHREAD_VERSION) -LIB_OBJS := $(CXXSRCS:.cc=.o) -LIB_IMPORTS := $(OMNITHREAD_PLATFORM_LIB) - -all:: mkstatic mkshared - -export:: mkstatic mkshared - -ifdef INSTALLTARGET -install:: mkstatic mkshared -endif - -vers := $(subst ., ,$(LIB_VERSION)) -ifeq ($(words $(vers)), 2) - vers := _ $(vers) - major := "" -else - major := $(word 1, $(vers)) -endif - -namespec := $(LIB_NAME) $(vers) - -############################################################################## -# Build Static library -############################################################################## - -ifndef NoStaticLibrary - -staticlib := static/$(patsubst %,$(LibNoDebugPattern),$(LIB_NAME)$(major)) - -mkstatic:: - @(dir=static; $(CreateDir)) - -mkstatic:: $(staticlib) - -$(staticlib): $(patsubst %, static/%, $(LIB_OBJS)) - @$(StaticLinkLibrary) - -export:: $(staticlib) - @$(ExportLibrary) - -ifdef INSTALLTARGET -install:: $(staticlib) - @$(InstallLibrary) -endif - -clean:: - $(RM) static/*.o - $(RM) $(staticlib) - -veryclean:: - $(RM) static/*.o - $(RM) $(staticlib) - -else - -mkstatic:: - -endif - - -############################################################################## -# Build Shared library -############################################################################## -ifdef BuildSharedLibrary - -shlib := shared/$(shell $(SharedLibraryFullName) $(namespec)) - -ifdef Win32Platform -# in case of Win32 lossage: - imps := $(patsubst $(DLLDebugSearchPattern),$(DLLNoDebugSearchPattern), \ - $(LIB_IMPORTS)) -else - imps := $(LIB_IMPORTS) -endif - -mkshared:: - @(dir=shared; $(CreateDir)) - -mkshared:: $(shlib) - -$(shlib): $(patsubst %, shared/%, $(LIB_OBJS)) - @(namespec="$(namespec)" extralibs="$(imps)" nodeffile=1; \ - $(MakeCXXSharedLibrary)) - -export:: $(shlib) - @(namespec="$(namespec)"; \ - $(ExportSharedLibrary)) - -ifdef INSTALLTARGET -install:: $(shlib) - @(namespec="$(namespec)"; \ - $(InstallSharedLibrary)) -endif - -clean:: - $(RM) shared/*.o - (dir=shared; $(CleanSharedLibrary)) - -veryclean:: - $(RM) shared/*.o - @(dir=shared; $(CleanSharedLibrary)) - -else - -mkshared:: - -endif - -############################################################################## -# Build debug libraries for Win32 -############################################################################## -ifdef Win32Platform - -ifdef BuildSharedLibrary - -all:: mkstaticdbug mkshareddbug - -export:: mkstaticdbug mkshareddbug - -else - -all:: mkstaticdbug - -export:: mkstaticdbug - -endif - - -##################################################### -# Static debug libraries -##################################################### - -dbuglib := debug/$(patsubst %,$(LibDebugPattern),$(LIB_NAME)$(major)) - -mkstaticdbug:: - @(dir=debug; $(CreateDir)) - -mkstaticdbug:: $(dbuglib) - -$(dbuglib): $(patsubst %, debug/%, $(LIB_OBJS)) - @$(StaticLinkLibrary) - -export:: $(dbuglib) - @$(ExportLibrary) - -clean:: - $(RM) debug/*.o - $(RM) $(dbuglib) - -veryclean:: - $(RM) debug/*.o - $(RM) $(dbuglib) - -##################################################### -# DLL debug libraries -##################################################### - -ifdef BuildSharedLibrary - -dbugshlib := shareddebug/$(shell $(SharedLibraryDebugFullName) $(namespec)) - -dbugimps := $(patsubst $(DLLNoDebugSearchPattern),$(DLLDebugSearchPattern), \ - $(LIB_IMPORTS)) - -mkshareddbug:: - @(dir=shareddebug; $(CreateDir)) - -mkshareddbug:: $(dbugshlib) - -$(dbugshlib): $(patsubst %, shareddebug/%, $(LIB_OBJS)) - (namespec="$(namespec)" debug=1 extralibs="$(dbugimps)" nodeffile=1; \ - $(MakeCXXSharedLibrary)) - -export:: $(dbugshlib) - @(namespec="$(namespec)" debug=1; \ - $(ExportSharedLibrary)) - -clean:: - $(RM) shareddebug/*.o - @(dir=shareddebug; $(CleanSharedLibrary)) - -veryclean:: - $(RM) shareddebug/*.o - @(dir=shareddebug; $(CleanSharedLibrary)) - -endif -endif - diff --git a/omnithread/gnuradio-omnithread.pc.in b/omnithread/gnuradio-omnithread.pc.in deleted file mode 100644 index 0a94562e9e..0000000000 --- a/omnithread/gnuradio-omnithread.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@/gnuradio - -Name: gnuradio-omnithread -Description: The GNU Radio omniORB threading library -Requires: -Version: @VERSION@ -Libs: -L${libdir} -lgromnithread -Cflags: -I${includedir} @DEFINES@ @PTHREAD_CFLAGS@ diff --git a/omnithread/gnuradio/.gitignore b/omnithread/gnuradio/.gitignore deleted file mode 100644 index b336cc7cec..0000000000 --- a/omnithread/gnuradio/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/omnithread/gnuradio/Makefile.am b/omnithread/gnuradio/Makefile.am deleted file mode 100644 index 1ec5612999..0000000000 --- a/omnithread/gnuradio/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -# -# Copyright 2009 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -grinclude_HEADERS = \ - omnithread.h \ - omni_time.h \ - ot_mach.h \ - ot_nt.h \ - ot_posix.h \ - ot_pthread_nt.h \ - ot_solaris.h \ - ot_VxThread.h diff --git a/omnithread/gnuradio/omni_time.h b/omnithread/gnuradio/omni_time.h deleted file mode 100644 index bfb1516104..0000000000 --- a/omnithread/gnuradio/omni_time.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_OMNI_TIME_H -#define INCLUDED_OMNI_TIME_H - -struct omni_time { - long int d_secs; // seconds. - long int d_nsecs; // nanoseconds. Always in [0, 1e9-1] - - omni_time() : d_secs(0), d_nsecs(0) {} - omni_time(long secs, long nanosecs=0) : d_secs(secs), d_nsecs(nanosecs) {} - - // N.B., this only makes sense for differences between times. - // Double doesn't have enough bits to precisely represent an absolute time. - omni_time(double secs); - - // N.B. This only makes sense for differences between times. - // Double doesn't have enough bits to precisely represent an absolute time. - double double_time() const { return (double)d_secs + d_nsecs * 1e-9; } - - /*! - * \brief Return an absolute time suitable for use with - * schedule_one_shot_timeout & schedule_periodic_timeout - * - * The return value is the current time plus the given relative offset. - */ - static omni_time time(const omni_time &relative_offset = omni_time()); -}; - - -inline static bool -operator<(const omni_time &x, const omni_time &y) -{ - return ((x.d_secs < y.d_secs) - || (x.d_secs == y.d_secs && x.d_nsecs < y.d_nsecs)); -} - -inline static bool -operator>(const omni_time &x, const omni_time &y) -{ - return ((x.d_secs > y.d_secs) - || (x.d_secs == y.d_secs && x.d_nsecs > y.d_nsecs)); -} - -inline static bool -operator>=(const omni_time &x, const omni_time &y) -{ - return ((x.d_secs > y.d_secs) - || (x.d_secs == y.d_secs && x.d_nsecs >= y.d_nsecs)); -} - -inline static bool -operator<=(const omni_time &x, const omni_time &y) -{ - return ((x.d_secs < y.d_secs) - || (x.d_secs == y.d_secs && x.d_nsecs <= y.d_nsecs)); -} - -inline static bool -operator==(const omni_time &x, const omni_time &y) -{ - return (x.d_secs == y.d_secs && x.d_nsecs == y.d_nsecs); -} - - -omni_time operator+(const omni_time &x, const omni_time &y); -omni_time operator+(const omni_time &x, double y); -omni_time operator-(const omni_time &x, const omni_time &y); -omni_time operator-(const omni_time &x, double y); - -#endif /* INCLUDED_OMNI_TIME_H */ diff --git a/omnithread/gnuradio/omnithread.h b/omnithread/gnuradio/omnithread.h deleted file mode 100644 index 8e8162b102..0000000000 --- a/omnithread/gnuradio/omnithread.h +++ /dev/null @@ -1,626 +0,0 @@ -// -*- Mode: C++; -*- -// Package : omnithread -// omnithread.h Created : 7/94 tjr -// -// Copyright (C) 2006 Free Software Foundation, Inc. -// Copyright (C) 1994,1995,1996, 1997 Olivetti & Oracle Research Laboratory -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// - -// -// Interface to OMNI thread abstraction. -// -// This file declares classes for threads and synchronisation objects -// (mutexes, condition variables and counting semaphores). -// -// Wherever a seemingly arbitrary choice has had to be made as to the interface -// provided, the intention here has been to be as POSIX-like as possible. This -// is why there is no semaphore timed wait, for example. -// - -#ifndef __omnithread_h_ -#define __omnithread_h_ - -#ifndef NULL -#define NULL 0 -#endif - -class omni_mutex; -class omni_condition; -class omni_semaphore; -class omni_thread; - -// -// OMNI_THREAD_EXPOSE can be defined as public or protected to expose the -// implementation class - this may be useful for debugging. Hopefully this -// won't change the underlying structure which the compiler generates so that -// this can work without recompiling the library. -// - -#ifndef OMNI_THREAD_EXPOSE -#define OMNI_THREAD_EXPOSE private -#endif - -// -// Include implementation-specific header file. -// -// This must define 4 CPP macros of the form OMNI_x_IMPLEMENTATION for mutex, -// condition variable, semaphore and thread. Each should define any -// implementation-specific members of the corresponding classes. -// - - -// -// For now, we assume they've always got a Posix Threads implementation. -// If not, it'll take some configure hacking to sort it out, along with -// the relevant libraries to link with, etc. -// - -#if !defined(OMNITHREAD_POSIX) && !defined(OMNITHREAD_NT) && defined HAVE_CONFIG_H -// #include <config.h> // No, No, No! Never include <config.h> from a header -#endif - -#if defined(OMNITHREAD_POSIX) -#include <gnuradio/ot_posix.h> - -#elif defined(OMNITHREAD_NT) -#include <gnuradio/ot_nt.h> - -#ifdef _MSC_VER - -// Using MSVC++ to compile. If compiling library as a DLL, -// define _OMNITHREAD_DLL. If compiling as a statuc library, define -// _WINSTATIC -// If compiling an application that is to be statically linked to omnithread, -// define _WINSTATIC (if the application is to be dynamically linked, -// there is no need to define any of these macros). - -#if defined (_OMNITHREAD_DLL) && defined(_WINSTATIC) -#error "Both _OMNITHREAD_DLL and _WINSTATIC are defined." -#elif defined(_OMNITHREAD_DLL) -#define _OMNITHREAD_NTDLL_ __declspec(dllexport) -#elif !defined(_WINSTATIC) -#define _OMNITHREAD_NTDLL_ __declspec(dllimport) -#elif defined(_WINSTATIC) -#define _OMNITHREAD_NTDLL_ -#endif - // _OMNITHREAD_DLL && _WINSTATIC - -#else - -// Not using MSVC++ to compile -#define _OMNITHREAD_NTDLL_ - -#endif - // _MSC_VER - -#elif defined(__vxWorks__) -#include <gnuradio/ot_VxThread.h> - -#elif defined(__sunos__) -#if __OSVERSION__ != 5 -// XXX Workaround for SUN C++ compiler (seen on 4.2) Template.DB code -// regeneration bug. See omniORB2/CORBA_sysdep.h for details. -#if !defined(__SUNPRO_CC) || __OSVERSION__ != '5' -#error "Only SunOS 5.x or later is supported." -#endif -#endif -#ifdef UseSolarisThreads -#include <gnuradio/ot_solaris.h> -#else -#include <gnuradio/ot_posix.h> -#endif - -#elif defined(__rtems__) -#include <gnuradio/ot_posix.h> -#include <sched.h> - -#elif defined(__macos__) -#include <gnuradio/ot_posix.h> -#include <sched.h> - -#else -#error "No implementation header file" -#endif - - -#if !defined(__WIN32__) -#define _OMNITHREAD_NTDLL_ -#endif - -#if (!defined(OMNI_MUTEX_IMPLEMENTATION) || \ - !defined(OMNI_MUTEX_LOCK_IMPLEMENTATION) || \ - !defined(OMNI_MUTEX_TRYLOCK_IMPLEMENTATION)|| \ - !defined(OMNI_MUTEX_UNLOCK_IMPLEMENTATION) || \ - !defined(OMNI_CONDITION_IMPLEMENTATION) || \ - !defined(OMNI_SEMAPHORE_IMPLEMENTATION) || \ - !defined(OMNI_THREAD_IMPLEMENTATION)) -#error "Implementation header file incomplete" -#endif - - -// -// This exception is thrown in the event of a fatal error. -// - -class _OMNITHREAD_NTDLL_ omni_thread_fatal { -public: - int error; - omni_thread_fatal(int e = 0) : error(e) {} -}; - - -// -// This exception is thrown when an operation is invoked with invalid -// arguments. -// - -class _OMNITHREAD_NTDLL_ omni_thread_invalid {}; - - -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// - -class _OMNITHREAD_NTDLL_ omni_mutex { - -public: - omni_mutex(void); - ~omni_mutex(void); - - inline void lock(void) { OMNI_MUTEX_LOCK_IMPLEMENTATION } - inline void unlock(void) { OMNI_MUTEX_UNLOCK_IMPLEMENTATION } - inline int trylock(void) { return OMNI_MUTEX_TRYLOCK_IMPLEMENTATION } - // if mutex is unlocked, lock it and return 1 (true). - // If it's already locked then return 0 (false). - - inline void acquire(void) { lock(); } - inline void release(void) { unlock(); } - // the names lock and unlock are preferred over acquire and release - // since we are attempting to be as POSIX-like as possible. - - friend class omni_condition; - -private: - // dummy copy constructor and operator= to prevent copying - omni_mutex(const omni_mutex&); - omni_mutex& operator=(const omni_mutex&); - -OMNI_THREAD_EXPOSE: - OMNI_MUTEX_IMPLEMENTATION -}; - -// -// As an alternative to: -// { -// mutex.lock(); -// ..... -// mutex.unlock(); -// } -// -// you can use a single instance of the omni_mutex_lock class: -// -// { -// omni_mutex_lock l(mutex); -// .... -// } -// -// This has the advantage that mutex.unlock() will be called automatically -// when an exception is thrown. -// - -class _OMNITHREAD_NTDLL_ omni_mutex_lock { - omni_mutex& mutex; -public: - omni_mutex_lock(omni_mutex& m) : mutex(m) { mutex.lock(); } - ~omni_mutex_lock(void) { mutex.unlock(); } -private: - // dummy copy constructor and operator= to prevent copying - omni_mutex_lock(const omni_mutex_lock&); - omni_mutex_lock& operator=(const omni_mutex_lock&); -}; - - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// - -class _OMNITHREAD_NTDLL_ omni_condition { - - omni_mutex* mutex; - -public: - omni_condition(omni_mutex* m); - // constructor must be given a pointer to an existing mutex. The - // condition variable is then linked to the mutex, so that there is an - // implicit unlock and lock around wait() and timed_wait(). - - ~omni_condition(void); - - void wait(void); - // wait for the condition variable to be signalled. The mutex is - // implicitly released before waiting and locked again after waking up. - // If wait() is called by multiple threads, a signal may wake up more - // than one thread. See POSIX threads documentation for details. - - int timedwait(unsigned long secs, unsigned long nanosecs = 0); - // timedwait() is given an absolute time to wait until. To wait for a - // relative time from now, use omni_thread::get_time. See POSIX threads - // documentation for why absolute times are better than relative. - // Returns 1 (true) if successfully signalled, 0 (false) if time - // expired. - - void signal(void); - // if one or more threads have called wait(), signal wakes up at least - // one of them, possibly more. See POSIX threads documentation for - // details. - - void broadcast(void); - // broadcast is like signal but wakes all threads which have called - // wait(). - -private: - // dummy copy constructor and operator= to prevent copying - omni_condition(const omni_condition&); - omni_condition& operator=(const omni_condition&); - -OMNI_THREAD_EXPOSE: - OMNI_CONDITION_IMPLEMENTATION -}; - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting (or binary) semaphore -// -/////////////////////////////////////////////////////////////////////////// - -class _OMNITHREAD_NTDLL_ omni_semaphore { - -public: - // if max_count == 1, you've got a binary semaphore. - omni_semaphore(unsigned int initial = 1, unsigned int max_count = 0x7fffffff); - ~omni_semaphore(void); - - void wait(void); - // if semaphore value is > 0 then decrement it and carry on. If it's - // already 0 then block. - - int trywait(void); - // if semaphore value is > 0 then decrement it and return 1 (true). - // If it's already 0 then return 0 (false). - - void post(void); - // if any threads are blocked in wait(), wake one of them up. Otherwise - // increment the value of the semaphore. - -private: - // dummy copy constructor and operator= to prevent copying - omni_semaphore(const omni_semaphore&); - omni_semaphore& operator=(const omni_semaphore&); - -OMNI_THREAD_EXPOSE: - OMNI_SEMAPHORE_IMPLEMENTATION -}; - -// -// A helper class for semaphores, similar to omni_mutex_lock above. -// - -class _OMNITHREAD_NTDLL_ omni_semaphore_lock { - omni_semaphore& sem; -public: - omni_semaphore_lock(omni_semaphore& s) : sem(s) { sem.wait(); } - ~omni_semaphore_lock(void) { sem.post(); } -private: - // dummy copy constructor and operator= to prevent copying - omni_semaphore_lock(const omni_semaphore_lock&); - omni_semaphore_lock& operator=(const omni_semaphore_lock&); -}; - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - -class _OMNITHREAD_NTDLL_ omni_thread { - -public: - - enum priority_t { - PRIORITY_LOW, - PRIORITY_NORMAL, - PRIORITY_HIGH - }; - - enum state_t { - STATE_NEW, // thread object exists but thread hasn't - // started yet. - STATE_RUNNING, // thread is running. - STATE_TERMINATED // thread has terminated but storage has not - // been reclaimed (i.e. waiting to be joined). - }; - - // - // Constructors set up the thread object but the thread won't start until - // start() is called. The create method can be used to construct and start - // a thread in a single call. - // - - omni_thread(void (*fn)(void*), void* arg = NULL, - priority_t pri = PRIORITY_NORMAL); - omni_thread(void* (*fn)(void*), void* arg = NULL, - priority_t pri = PRIORITY_NORMAL); - // these constructors create a thread which will run the given function - // when start() is called. The thread will be detached if given a - // function with void return type, undetached if given a function - // returning void*. If a thread is detached, storage for the thread is - // reclaimed automatically on termination. Only an undetached thread - // can be joined. - - void start(void); - // start() causes a thread created with one of the constructors to - // start executing the appropriate function. - -protected: - - omni_thread(void* arg = NULL, priority_t pri = PRIORITY_NORMAL); - // this constructor is used in a derived class. The thread will - // execute the run() or run_undetached() member functions depending on - // whether start() or start_undetached() is called respectively. - -public: - - void start_undetached(void); - // can be used with the above constructor in a derived class to cause - // the thread to be undetached. In this case the thread executes the - // run_undetached member function. - -protected: - - virtual ~omni_thread(void); - // destructor cannot be called by user (except via a derived class). - // Use exit() or cancel() instead. This also means a thread object must - // be allocated with new - it cannot be statically or automatically - // allocated. The destructor of a class that inherits from omni_thread - // shouldn't be public either (otherwise the thread object can be - // destroyed while the underlying thread is still running). - -public: - - void join(void**); - // join causes the calling thread to wait for another's completion, - // putting the return value in the variable of type void* whose address - // is given (unless passed a null pointer). Only undetached threads - // may be joined. Storage for the thread will be reclaimed. - - void set_priority(priority_t); - // set the priority of the thread. - - static omni_thread* create(void (*fn)(void*), void* arg = NULL, - priority_t pri = PRIORITY_NORMAL); - static omni_thread* create(void* (*fn)(void*), void* arg = NULL, - priority_t pri = PRIORITY_NORMAL); - // create spawns a new thread executing the given function with the - // given argument at the given priority. Returns a pointer to the - // thread object. It simply constructs a new thread object then calls - // start. - - static void exit(void* return_value = NULL); - // causes the calling thread to terminate. - - static omni_thread* self(void); - // returns the calling thread's omni_thread object. If the - // calling thread is not the main thread and is not created - // using this library, returns 0. (But see create_dummy() - // below.) - - static void yield(void); - // allows another thread to run. - - static void sleep(unsigned long secs, unsigned long nanosecs = 0); - // sleeps for the given time. - - static void get_time(unsigned long* abs_sec, unsigned long* abs_nsec, - unsigned long rel_sec = 0, unsigned long rel_nsec=0); - // calculates an absolute time in seconds and nanoseconds, suitable for - // use in timed_waits on condition variables, which is the current time - // plus the given relative offset. - - - static void stacksize(unsigned long sz); - static unsigned long stacksize(); - // Use this value as the stack size when spawning a new thread. - // The default value (0) means that the thread library default is - // to be used. - - - // Per-thread data - // - // These functions allow you to attach additional data to an - // omni_thread. First allocate a key for yourself with - // allocate_key(). Then you can store any object whose class is - // derived from value_t. Any values still stored in the - // omni_thread when the thread exits are deleted. - // - // These functions are NOT thread safe, so you should be very - // careful about setting/getting data in a different thread to the - // current thread. - - typedef unsigned int key_t; - static key_t allocate_key(); - - class value_t { - public: - virtual ~value_t() {} - }; - - value_t* set_value(key_t k, value_t* v); - // Sets a value associated with the given key. The key must - // have been allocated with allocate_key(). If a value has - // already been set with the specified key, the old value_t - // object is deleted and replaced. Returns the value which was - // set, or zero if the key is invalid. - - value_t* get_value(key_t k); - // Returns the value associated with the key. If the key is - // invalid, or there is no value for the key, returns zero. - - value_t* remove_value(key_t k); - // Removes the value associated with the key and returns it. - // If the key is invalid, or there is no value for the key, - // returns zero. - - - // Dummy omni_thread - // - // Sometimes, an application finds itself with threads created - // outside of omnithread which must interact with omnithread - // features such as the per-thread data. In this situation, - // omni_thread::self() would normally return 0. These functions - // allow the application to create a suitable dummy omni_thread - // object. - - static omni_thread* create_dummy(void); - // creates a dummy omni_thread for the calling thread. Future - // calls to self() will return the dummy omni_thread. Throws - // omni_thread_invalid if this thread already has an - // associated omni_thread (real or dummy). - - static void release_dummy(); - // release the dummy omni_thread for this thread. This - // function MUST be called before the thread exits. Throws - // omni_thread_invalid if the calling thread does not have a - // dummy omni_thread. - - // class ensure_self should be created on the stack. If created in - // a thread without an associated omni_thread, it creates a dummy - // thread which is released when the ensure_self object is deleted. - - class ensure_self { - public: - inline ensure_self() : _dummy(0) - { - _self = omni_thread::self(); - if (!_self) { - _dummy = 1; - _self = omni_thread::create_dummy(); - } - } - inline ~ensure_self() - { - if (_dummy) - omni_thread::release_dummy(); - } - inline omni_thread* self() { return _self; } - private: - omni_thread* _self; - int _dummy; - }; - - -private: - - virtual void run(void* /*arg*/) {} - virtual void* run_undetached(void* /*arg*/) { return NULL; } - // can be overridden in a derived class. When constructed using the - // the constructor omni_thread(void*, priority_t), these functions are - // called by start() and start_undetached() respectively. - - void common_constructor(void* arg, priority_t pri, int det); - // implements the common parts of the constructors. - - omni_mutex mutex; - // used to protect any members which can change after construction, - // i.e. the following 2 members. - - state_t _state; - priority_t _priority; - - static omni_mutex* next_id_mutex; - static int next_id; - int _id; - - void (*fn_void)(void*); - void* (*fn_ret)(void*); - void* thread_arg; - int detached; - int _dummy; - value_t** _values; - unsigned long _value_alloc; - - omni_thread(const omni_thread&); - omni_thread& operator=(const omni_thread&); - // Not implemented - -public: - - priority_t priority(void) { - - // return this thread's priority. - - omni_mutex_lock l(mutex); - return _priority; - } - - state_t state(void) { - - // return thread state (invalid, new, running or terminated). - - omni_mutex_lock l(mutex); - return _state; - } - - int id(void) { return _id; } - // return unique thread id within the current process. - - - // This class plus the instance of it declared below allows us to execute - // some initialisation code before main() is called. - - class _OMNITHREAD_NTDLL_ init_t { - public: - init_t(void); - ~init_t(void); - }; - - friend class init_t; - friend class omni_thread_dummy; - -OMNI_THREAD_EXPOSE: - OMNI_THREAD_IMPLEMENTATION -}; - -#ifndef __rtems__ -static omni_thread::init_t omni_thread_init; -#else -// RTEMS calls global Ctor/Dtor in a context that is not -// a posix thread. Calls to functions to pthread_self() in -// that context returns NULL. -// So, for RTEMS we will make the thread initialization at the -// beginning of the Init task that has a posix context. -#endif - -#endif diff --git a/omnithread/gnuradio/ot_VxThread.h b/omnithread/gnuradio/ot_VxThread.h deleted file mode 100644 index e96c036cce..0000000000 --- a/omnithread/gnuradio/ot_VxThread.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef __VXTHREAD_H__ -#define __VXTHREAD_H__ -/* -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Project: omniORB -%% Filename: $Filename$ -%% Author: Guillaume/Bill ARRECKX -%% Copyright Wavetek Wandel & Goltermann, Plymouth. -%% Description: OMNI thread implementation classes for VxWorks threads -%% Notes: -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% $Log$ -%% Revision 1.1 2004/04/10 18:00:52 eb -%% Initial revision -%% -%% Revision 1.1.1.1 2004/03/01 00:20:27 eb -%% initial checkin -%% -%% Revision 1.1 2003/05/25 05:29:04 eb -%% see ChangeLog -%% -%% Revision 1.1.2.1 2003/02/17 02:03:07 dgrisby -%% vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH). -%% -%% Revision 1.1.1.1 2002/11/19 14:55:21 sokcevti -%% OmniOrb4.0.0 VxWorks port -%% -%% Revision 1.2 2002/06/14 12:45:50 engeln -%% unnecessary members in condition removed. -%% --- -%% -%% Revision 1.1.1.1 2002/04/02 10:08:49 sokcevti -%% omniORB4 initial realease -%% -%% Revision 1.1 2001/03/23 16:50:23 hartmut -%% Initial Version 2.8 -%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*/ - - -/////////////////////////////////////////////////////////////////////////// -// Includes -/////////////////////////////////////////////////////////////////////////// -#include <vxWorks.h> -#include <semLib.h> -#include <taskLib.h> - - -/////////////////////////////////////////////////////////////////////////// -// Externs prototypes -/////////////////////////////////////////////////////////////////////////// -extern "C" void omni_thread_wrapper(void* ptr); - - -/////////////////////////////////////////////////////////////////////////// -// Exported macros -// Note: These are added as private members in each class implementation. -/////////////////////////////////////////////////////////////////////////// -#define OMNI_MUTEX_IMPLEMENTATION \ - SEM_ID mutexID; \ - bool m_bConstructed; - -#define OMNI_CONDITION_IMPLEMENTATION \ - long waiters_; \ - SEM_ID waiters_lock_; \ - SEM_ID sema_; - -#define OMNI_SEMAPHORE_IMPLEMENTATION \ - SEM_ID semID; - -#define OMNI_MUTEX_LOCK_IMPLEMENTATION \ - if(semTake(mutexID, WAIT_FOREVER) != OK) \ - { \ - throw omni_thread_fatal(errno); \ - } - -#define OMNI_MUTEX_UNLOCK_IMPLEMENTATION \ - if(semGive(mutexID) != OK) \ - { \ - throw omni_thread_fatal(errno); \ - } - -#define OMNI_THREAD_IMPLEMENTATION \ - friend void omni_thread_wrapper(void* ptr); \ - static int vxworks_priority(priority_t); \ - omni_condition *running_cond; \ - void* return_val; \ - int tid; \ - public: \ - static void attach(void); \ - static void detach(void); \ - static void show(void); - - -/////////////////////////////////////////////////////////////////////////// -// Porting macros -/////////////////////////////////////////////////////////////////////////// -// This is a wrapper function for the 'main' function which does not exists -// as such in VxWorks. The wrapper creates a launch function instead, -// which spawns the application wrapped in a omni_thread. -// Argc will always be null. -/////////////////////////////////////////////////////////////////////////// -#define main( discarded_argc, discarded_argv ) \ - omni_discard_retval() \ - { \ - throw; \ - } \ - int omni_main( int argc, char **argv ); \ - void launch( ) \ - { \ - omni_thread* th = new omni_thread( (void(*)(void*))omni_main );\ - th->start();\ - }\ - int omni_main( int argc, char **argv ) - - -#endif // ndef __VXTHREAD_H__ diff --git a/omnithread/gnuradio/ot_mach.h b/omnithread/gnuradio/ot_mach.h deleted file mode 100644 index 76361926ca..0000000000 --- a/omnithread/gnuradio/ot_mach.h +++ /dev/null @@ -1,51 +0,0 @@ -// Package : omnithread -// omnithread/posix.h Created : 7/97 lars immisch lars@ibp.de -// -// Copyright (C) 1994,1995,1996, 1997 Immisch, becker & Partner -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// -// -// OMNI thread implementation classes for posix threads -// - -#ifndef __omnithread_mach_h_ -#define __omnithread_mach_h_ - -#include <mach/cthreads.h> - -extern "C" void* omni_thread_wrapper(void* ptr); - -#define OMNI_MUTEX_IMPLEMENTATION \ - struct mutex mach_mutex; - -#define OMNI_CONDITION_IMPLEMENTATION \ - struct condition mach_cond; - -#define OMNI_SEMAPHORE_IMPLEMENTATION \ - omni_mutex m; \ - omni_condition c; \ - int value; - - -#define OMNI_THREAD_IMPLEMENTATION \ - cthread_t mach_thread; \ - static int mach_priority(priority_t); \ - friend void* omni_thread_wrapper(void* ptr); - -#endif diff --git a/omnithread/gnuradio/ot_nt.h b/omnithread/gnuradio/ot_nt.h deleted file mode 100644 index 551ccf2f14..0000000000 --- a/omnithread/gnuradio/ot_nt.h +++ /dev/null @@ -1,85 +0,0 @@ -// Package : omnithread -// omnithread/nt.h Created : 6/95 tjr -// -// Copyright (C) 1995, 1996, 1997 Olivetti & Oracle Research Laboratory -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// -// -// OMNI thread implementation classes for NT threads. -// - -#ifndef __omnithread_nt_h_ -#define __omnithread_nt_h_ - -#ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# define OMNI_DEFINED_WIN32_LEAN_AND_MEAN -#endif - -#include <windows.h> - -#ifdef OMNI_DEFINED_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -# undef OMNI_DEFINED_WIN32_LEAN_AND_MEAN -#endif - - -#ifndef __BCPLUSPLUS__ -#define OMNI_THREAD_WRAPPER \ - unsigned __stdcall omni_thread_wrapper(LPVOID ptr); -#else -#define OMNI_THREAD_WRAPPER \ - void _USERENTRY omni_thread_wrapper(void *ptr); -#endif - -extern "C" OMNI_THREAD_WRAPPER; - -#define OMNI_MUTEX_IMPLEMENTATION \ - CRITICAL_SECTION crit; - -#define OMNI_MUTEX_LOCK_IMPLEMENTATION \ - EnterCriticalSection(&crit); - -#define OMNI_MUTEX_TRYLOCK_IMPLEMENTATION \ - TryEnterCriticalSection(&crit); - -#define OMNI_MUTEX_UNLOCK_IMPLEMENTATION \ - LeaveCriticalSection(&crit); - -#define OMNI_CONDITION_IMPLEMENTATION \ - CRITICAL_SECTION crit; \ - omni_thread* waiting_head; \ - omni_thread* waiting_tail; - -#define OMNI_SEMAPHORE_IMPLEMENTATION \ - HANDLE nt_sem; - -#define OMNI_THREAD_IMPLEMENTATION \ - HANDLE handle; \ - DWORD nt_id; \ - void* return_val; \ - HANDLE cond_semaphore; \ - omni_thread* cond_next; \ - omni_thread* cond_prev; \ - BOOL cond_waiting; \ - static int nt_priority(priority_t); \ - friend class omni_condition; \ - friend OMNI_THREAD_WRAPPER; - -#endif diff --git a/omnithread/gnuradio/ot_posix.h b/omnithread/gnuradio/ot_posix.h deleted file mode 100644 index 666ccc0890..0000000000 --- a/omnithread/gnuradio/ot_posix.h +++ /dev/null @@ -1,81 +0,0 @@ -// Package : omnithread -// omnithread/posix.h Created : 7/94 tjr -// -// Copyright (C) 2006 Free Software Foundation, Inc. -// Copyright (C) 1994,1995,1996, 1997 Olivetti & Oracle Research Laboratory -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// -// -// OMNI thread implementation classes for posix threads -// - -#ifndef __omnithread_posix_h_ -#define __omnithread_posix_h_ - -#if defined(__alpha__) && defined(__osf1__) || defined(__hpux__) -// stop unnecessary definitions of TRY, etc on OSF -#ifndef EXC_HANDLING -#define EXC_HANDLING -#endif -#endif - -#ifndef __POSIX_NT__ -# include <pthread.h> -#else -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# define OMNI_DEFINED_WIN32_LEAN_AND_MEAN -# endif -# include <windows.h> -# include "pthread_nt.h" -# ifdef OMNI_DEFINED_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -# undef OMNI_DEFINED_WIN32_LEAN_AND_MEAN -# endif -#endif - -extern "C" void* omni_thread_wrapper(void* ptr); - -#define OMNI_MUTEX_IMPLEMENTATION \ - pthread_mutex_t posix_mutex; - -#define OMNI_MUTEX_LOCK_IMPLEMENTATION \ - pthread_mutex_lock(&posix_mutex); - -#define OMNI_MUTEX_TRYLOCK_IMPLEMENTATION \ - (pthread_mutex_trylock(&posix_mutex)==0); - -#define OMNI_MUTEX_UNLOCK_IMPLEMENTATION \ - pthread_mutex_unlock(&posix_mutex); - -#define OMNI_CONDITION_IMPLEMENTATION \ - pthread_cond_t posix_cond; - -#define OMNI_SEMAPHORE_IMPLEMENTATION \ - omni_mutex m; \ - omni_condition c; \ - int value; \ - int max_count; - -#define OMNI_THREAD_IMPLEMENTATION \ - pthread_t posix_thread; \ - static int posix_priority(priority_t); \ - friend void* omni_thread_wrapper(void* ptr); - -#endif diff --git a/omnithread/gnuradio/ot_pthread_nt.h b/omnithread/gnuradio/ot_pthread_nt.h deleted file mode 100644 index 324b5257f6..0000000000 --- a/omnithread/gnuradio/ot_pthread_nt.h +++ /dev/null @@ -1,186 +0,0 @@ -/* Package : omnithread - omnithread/pthread_nt.h Created : Steven Brenneis <brennes1@rjrt.com> - - Copyright (C) 1998 Steven Brennes - - This file is part of the omnithread library - - The omnithread library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 51 Franklin Street, Boston, MA - 02110-1301, USA - - Posix Threads implementation for Windows NT, version 4.0 -*/ - -#ifndef PTHREAD_NT_H_INCLUDED -#define PTHREAD_NT_H_INCLUDED - -#include <errno.h> - -#ifndef ETIMEDOUT -// May have to be changed if NT starts supporting more errno values -#define ETIMEDOUT 60 -#endif - -#undef PthreadDraftVersion -#define PthreadDraftVersion 10 - -#define NoNanoSleep - -#define PthreadSupportThreadPriority - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _TIMERS_T_ -#define _TIMERS_T_ - typedef struct timespec { - unsigned long tv_sec; - long tv_nsec; - } timespec_t; -#endif - -typedef char* __pthreadLongString_t; -typedef void* __pthreadLongAddr_t; -typedef __pthreadLongAddr_t* __pthreadLongAddr_p; -typedef long __pthreadLongInt_t; -typedef unsigned long __pthreadLongUint_t; -typedef __pthreadLongAddr_p __pthreadTsd_t; - -typedef struct __pthread_mutex_t { - unsigned int lock; /* LOCK, SLOW, TYPE, RECURSIVE */ - unsigned int valid; /* Validation info */ - __pthreadLongString_t name; /* Name of mutex */ - unsigned int arg; /* printf argument for name */ - unsigned int depth; /* Recursive lock depth */ - unsigned long sequence; /* Mutex sequence number */ - unsigned long owner; /* Current owner (if known */ - __pthreadLongAddr_t block; /* Pointer to blocking struct */ -} pthread_mutex_t; - -typedef struct __pthread_mutexattr_t { - long valid; - __pthreadLongUint_t reserved[15]; -} pthread_mutexattr_t; - -typedef struct __pthread_cond_t { - unsigned int state; /* EVENT, SLOW, REFCNT */ - unsigned int valid; /* Validation info */ - __pthreadLongString_t name; /* Name of condition variable */ - unsigned int arg; /* printf argument for name */ - unsigned long sequence; /* Condition variable seq # */ - __pthreadLongAddr_t block; /* Pointer to blocking struct */ -} pthread_cond_t ; - -typedef struct __pthread_condattr_t { - long valid; - __pthreadLongUint_t reserved[13]; -} pthread_condattr_t ; - -typedef struct __pthread_transp_t { - __pthreadLongAddr_t reserved1; /* Reserved to posix_nt */ - __pthreadLongAddr_t reserved2; /* Reserved to posix_nt */ - unsigned short size; /* Size of data structure */ - unsigned char reserved3[2]; /* Reserved to posix_nt */ - __pthreadLongAddr_t reserved4; /* Reserved to posix_nt */ - __pthreadLongUint_t sequence; /* Thread sequence number */ - __pthreadLongUint_t reserved5[2]; /* Reserved to posix_nt */ - __pthreadLongAddr_t per_kt_area; /* Pointer to kernel context */ - __pthreadLongAddr_t stack_base; /* Current stack base */ - __pthreadLongAddr_t stack_reserve; /* Current stack reserve zone */ - __pthreadLongAddr_t stack_yellow; /* Current stack yellow zone */ - __pthreadLongAddr_t stack_guard; /* Current stack guard zone */ - __pthreadLongUint_t stack_size; /* Size of stack */ - __pthreadTsd_t tsd_values; /* TSD array (indexed by key) */ - unsigned long tsd_count; /* Number of TSD cells */ - __pthreadLongAddr_t reserved6; /* Reserved to posix_nt */ - __pthreadLongAddr_t reserved7; /* Reserved to posix_nt */ - unsigned int thread_flags; /* Dynamic external state */ -} pthread_transp_t, *pthread_transp_p; - -typedef pthread_transp_p pthread_t; - -typedef struct __pthread_attr_t { - long valid; - __pthreadLongString_t name; - __pthreadLongUint_t arg; - __pthreadLongUint_t reserved[19]; -} pthread_attr_t ; - -typedef unsigned int pthread_key_t; - -typedef struct sched_param { - int sched_priority; -} sched_param_t; - -/* Function Prototypes */ - -int pthread_create(pthread_t *thread, const pthread_attr_t *attr, - void *(*start_routine)(void*), void *arg); -int pthread_detach(pthread_t thread); -int pthread_join(pthread_t thread, void **value_ptr); -void pthread_exit(void *value_ptr); -int pthread_attr_init(pthread_attr_t *attr); -int pthread_attr_destroy(pthread_attr_t *attr); -int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); -int pthread_attr_getstacksize(const pthread_attr_t *attr, - size_t *stacksize); -int pthread_cond_init(pthread_cond_t *cond, - const pthread_condattr_t *attr); -int pthread_cond_destroy(pthread_cond_t *cond); -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); -int pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - const struct timespec *abstime); -int pthread_cond_signal(pthread_cond_t *cond); -int pthread_cond_broadcast(pthread_cond_t *cond); -int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)); -int pthread_key_delete(pthread_key_t key); -int pthread_mutex_destroy(pthread_mutex_t *mutex); -int pthread_mutex_init(pthread_mutex_t *mutex, - const pthread_mutexattr_t *attr); -int pthread_mutex_lock(pthread_mutex_t *mutex); -int pthread_mutex_trylock(pthread_mutex_t *mutex); -int pthread_mutex_unlock(pthread_mutex_t *mutex); -pthread_t pthread_self(); -int pthread_setspecific(pthread_key_t key, const void *value); -void *pthread_getspecific(pthread_key_t key); -int pthread_getschedparam(pthread_t thread, int *policy, - struct sched_param *param); -int pthread_setschedparam(pthread_t thread, int policy, - const struct sched_param *param); -int pthread_attr_setschedparam(pthread_attr_t *attr, - const struct sched_param *param); -int pthread_attr_getschedparam(const pthread_attr_t *attr, - struct sched_param *param); - -int pthread_delay_np(const struct timespec *interval); -int pthread_get_expiration_np(const struct timespec *delta, - struct timespec *abstime); - -# define SCHED_FIFO 1 -# define SCHED_RR 2 -# define SCHED_OTHER 3 - -int sched_yield(); -int sched_get_priority_max(int policy); -int sched_get_priority_min(int policy); - - -#ifdef __cplusplus -} -#endif - -#endif // PTHREAD_NT_H_INCLUDED diff --git a/omnithread/gnuradio/ot_solaris.h b/omnithread/gnuradio/ot_solaris.h deleted file mode 100644 index f4fea0b112..0000000000 --- a/omnithread/gnuradio/ot_solaris.h +++ /dev/null @@ -1,47 +0,0 @@ -// Package : omnithread -// omnithread/solaris.h Created : 7/94 tjr -// -// Copyright (C) 1994,1995,1996, 1997 Olivetti & Oracle Research Laboratory -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// -// OMNI thread implementation classes for solaris threads. -// - -#ifndef __omnithread_solaris_h_ -#define __omnithread_solaris_h_ - -#include <thread.h> - -extern "C" void* omni_thread_wrapper(void* ptr); - -#define OMNI_MUTEX_IMPLEMENTATION \ - mutex_t sol_mutex; - -#define OMNI_CONDITION_IMPLEMENTATION \ - cond_t sol_cond; - -#define OMNI_SEMAPHORE_IMPLEMENTATION \ - sema_t sol_sem; - -#define OMNI_THREAD_IMPLEMENTATION \ - thread_t sol_thread; \ - static int sol_priority(priority_t); \ - friend void* omni_thread_wrapper(void* ptr); - -#endif diff --git a/omnithread/mach.cc b/omnithread/mach.cc deleted file mode 100644 index aa0465f41e..0000000000 --- a/omnithread/mach.cc +++ /dev/null @@ -1,714 +0,0 @@ -// Package : omnithread -// omnithread/mach.cc Created : 7/97 lars immisch lars@ibp.de -// -// Copyright (C) 1997 Immisch, Becker & Partner -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// - -// -// Implementation of OMNI thread abstraction for mach threads -// -// to the author's pleasure, mach cthreads are very similar to posix threads -// - -#include <stdlib.h> -#include <errno.h> -#include <sys/time.h> -#include <mach/cthreads.h> -#include "gnuradio/omnithread.h" - -#define DB(x) // x -// #include <iostream> or #include <iostream.h> if DB is on. - -#define ERRNO(x) (x) - -// -// static variables -// - -int omni_thread::init_t::count = 0; - -omni_mutex* omni_thread::next_id_mutex; -int omni_thread::next_id = 0; - -static int normal_priority; -static int highest_priority; - -static size_t stack_size = 0; - -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// - - -omni_mutex::omni_mutex(void) -{ - mutex_init(&mach_mutex); -} - - -omni_mutex::~omni_mutex(void) -{ - mutex_clear(&mach_mutex); -} - - -void omni_mutex::lock(void) -{ - mutex_lock(&mach_mutex); -} - - -void omni_mutex::unlock(void) -{ - mutex_unlock(&mach_mutex); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// - - -omni_condition::omni_condition(omni_mutex* m) : mutex(m) -{ - condition_init(&mach_cond); -} - - -omni_condition::~omni_condition(void) -{ - condition_clear(&mach_cond); -} - -void -omni_condition::wait(void) -{ - condition_wait(&mach_cond, &mutex->mach_mutex); -} - -typedef struct alarmclock_args { - unsigned long secs; - unsigned long nsecs; - bool wakeup; - condition_t condition; - mutex_t mutex; -}; - -any_t alarmclock(any_t arg) -{ - alarmclock_args* alarm = (alarmclock_args*)arg; - - omni_thread::sleep(alarm->secs, alarm->nsecs); - - mutex_lock(alarm->mutex); - - alarm->wakeup = TRUE; - - condition_signal(alarm->condition); - - mutex_unlock(alarm->mutex); - - return (any_t)TRUE; -} - -int omni_condition::timedwait(unsigned long abs_secs, unsigned long abs_nsecs) -{ - alarmclock_args alarm; - - omni_thread::get_time(&alarm.secs, &alarm.nsecs, 0, 0); - - if (abs_secs < alarm.secs || (abs_secs == alarm.secs && abs_nsecs <= alarm.nsecs)) - return ETIMEDOUT; - - alarm.secs = abs_secs - alarm.secs; - if (abs_nsecs <= alarm.nsecs) { - alarm.nsecs = 1000000 - alarm.nsecs + abs_nsecs; - alarm.secs--; - } - else { - alarm.nsecs = abs_nsecs - alarm.nsecs; - } - - alarm.mutex = &mutex->mach_mutex; - alarm.condition = &mach_cond; - alarm.wakeup = FALSE; - - cthread_t ct = cthread_fork((cthread_fn_t)alarmclock, (any_t)&alarm); - cthread_detach(ct); - - condition_wait(&mach_cond, &mutex->mach_mutex); - - if (alarm.wakeup) { - return 0; - } - - // interrupt the alarmclock thread sleep - cthread_abort(ct); - - // wait until it has signalled the condition - condition_wait(&mach_cond, &mutex->mach_mutex); - - return 1; -} - - -void omni_condition::signal(void) -{ - condition_signal(&mach_cond); -} - - -void omni_condition::broadcast(void) -{ - condition_signal(&mach_cond); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting semaphore -// -/////////////////////////////////////////////////////////////////////////// - - -omni_semaphore::omni_semaphore(unsigned int initial) : c(&m) -{ - value = initial; -} - - -omni_semaphore::~omni_semaphore(void) -{ -} - - -void -omni_semaphore::wait(void) -{ - omni_mutex_lock l(m); - - while (value == 0) - c.wait(); - - value--; -} - - -int -omni_semaphore::trywait(void) -{ - omni_mutex_lock l(m); - - if (value == 0) - return 0; - - value--; - return 1; -} - - -void -omni_semaphore::post(void) -{ - omni_mutex_lock l(m); - - if (value == 0) - c.signal(); - - value++; -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - - - -// -// Initialisation function (gets called before any user code). -// - -omni_thread::init_t::init_t(void) -{ - if (count++ != 0) // only do it once however many objects get created. - return; - - // - // find base and max priority. - // This is the initial thread, so the max priority of this - // thread also applies to any newly created thread. - // - - kern_return_t error; - struct thread_sched_info info; - unsigned int info_count = THREAD_SCHED_INFO_COUNT; - - error = thread_info(thread_self(), THREAD_SCHED_INFO, (thread_info_t)&info, &info_count); - if (error != KERN_SUCCESS) { - DB(cerr << "omni_thread::init: error determining thread_info" << endl); - ::exit(1); - } - else { - normal_priority = info.base_priority; - highest_priority = info.max_priority; - } - - next_id_mutex = new omni_mutex; - - // - // Create object for this (i.e. initial) thread. - // - - omni_thread* t = new omni_thread; - - if (t->_state != STATE_NEW) { - DB(cerr << "omni_thread::init: problem creating initial thread object\n"); - ::exit(1); - } - - t->_state = STATE_RUNNING; - - t->mach_thread = cthread_self(); - - DB(cerr << "initial thread " << t->id() << endl); - - cthread_set_data(t->mach_thread, (any_t)t); -} - - -// -// Wrapper for thread creation. -// - -extern "C" void* -omni_thread_wrapper(void* ptr) -{ - omni_thread* me = (omni_thread*)ptr; - - DB(cerr << "omni_thread::wrapper: thread " << me->id() - << " started\n"); - - cthread_set_data(cthread_self(), (any_t)me); - - // - // Now invoke the thread function with the given argument. - // - - if (me->fn_void != NULL) { - (*me->fn_void)(me->thread_arg); - omni_thread::exit(); - } - - if (me->fn_ret != NULL) { - void* return_value = (*me->fn_ret)(me->thread_arg); - omni_thread::exit(return_value); - } - - if (me->detached) { - me->run(me->thread_arg); - omni_thread::exit(); - } else { - void* return_value = me->run_undetached(me->thread_arg); - omni_thread::exit(return_value); - } - - // should never get here. - - return NULL; -} - - -// -// Constructors for omni_thread - set up the thread object but don't -// start it running. -// - -// construct a detached thread running a given function. - -omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = fn; - fn_ret = NULL; -} - -// construct an undetached thread running a given function. - -omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 0); - fn_void = NULL; - fn_ret = fn; -} - -// construct a thread which will run either run() or run_undetached(). - -omni_thread::omni_thread(void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = NULL; - fn_ret = NULL; -} - -// common part of all constructors. - -void omni_thread::common_constructor(void* arg, priority_t pri, int det) -{ - _state = STATE_NEW; - _priority = pri; - - next_id_mutex->lock(); - _id = next_id++; - next_id_mutex->unlock(); - - thread_arg = arg; - detached = det; // may be altered in start_undetached() - - _dummy = 0; - _values = 0; - _value_alloc = 0; - // posix_thread is set up in initialisation routine or start(). -} - - -// -// Destructor for omni_thread. -// - -omni_thread::~omni_thread(void) -{ - DB(cerr << "destructor called for thread " << id() << endl); - if (_values) { - for (key_t i=0; i < _value_alloc; i++) { - if (_values[i]) { - delete _values[i]; - } - } - delete [] _values; - } -} - - -// -// Start the thread -// - -void -omni_thread::start(void) -{ - omni_mutex_lock l(mutex); - - int rc; - - if (_state != STATE_NEW) - throw omni_thread_invalid(); - - mach_thread = cthread_fork(omni_thread_wrapper, (any_t)this); - - _state = STATE_RUNNING; - - if (detached) { - cthread_detach(mach_thread); - } -} - -// -// Start a thread which will run the member function run_undetached(). -// - -void -omni_thread::start_undetached(void) -{ - if ((fn_void != NULL) || (fn_ret != NULL)) - throw omni_thread_invalid(); - - detached = 0; - start(); -} - - -// -// join - simply check error conditions & call cthread_join. -// - -void -omni_thread::join(void** status) -{ - mutex.lock(); - - if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { - mutex.unlock(); - throw omni_thread_invalid(); - } - - mutex.unlock(); - - if (this == self()) - throw omni_thread_invalid(); - - if (detached) - throw omni_thread_invalid(); - - DB(cerr << "omni_thread::join: doing cthread_join\n"); - - *status = cthread_join(mach_thread); - - delete this; -} - - -// -// Change this thread's priority. -// - -void -omni_thread::set_priority(priority_t pri) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_RUNNING) - throw omni_thread_invalid(); - - _priority = pri; - - kern_return_t rc = cthread_priority(mach_thread, mach_priority(pri), FALSE); - - if (rc != KERN_SUCCESS) - throw omni_thread_fatal(errno); -} - -// -// create - construct a new thread object and start it running. Returns thread -// object if successful, null pointer if not. -// - -// detached version - -omni_thread* -omni_thread::create(void (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - -// undetached version - -omni_thread* -omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - -// -// exit() _must_ lock the mutex even in the case of a detached thread. This is -// because a thread may run to completion before the thread that created it has -// had a chance to get out of start(). By locking the mutex we ensure that the -// creating thread must have reached the end of start() before we delete the -// thread object. Of course, once the call to start() returns, the user can -// still incorrectly refer to the thread object, but that's their problem. -// - -void omni_thread::exit(void* return_value) -{ - omni_thread* me = self(); - - if (me) - { - me->mutex.lock(); - - if (me->_state != STATE_RUNNING) - DB(cerr << "omni_thread::exit: thread not in \"running\" state\n"); - - me->_state = STATE_TERMINATED; - - me->mutex.unlock(); - - DB(cerr << "omni_thread::exit: thread " << me->id() << " detached " - << me->detached << " return value " << return_value << endl); - - if (me->detached) - delete me; - } - else - { - DB(cerr << "omni_thread::exit: called with a non-omnithread. Exit quietly." << endl); - } - cthread_exit(return_value); -} - -omni_thread* omni_thread::self(void) -{ - omni_thread* me; - - me = (omni_thread*)cthread_data(cthread_self()); - - if (!me) { - // This thread is not created by omni_thread::start because it - // doesn't has a class omni_thread instance attached to its key. - DB(cerr << "omni_thread::self: called with a non-ominthread. NULL is returned." << endl); - } - - return me; -} - -void omni_thread::yield(void) -{ - cthread_yield(); -} - -#define MAX_SLEEP_SECONDS (unsigned)4294966 // (2**32-2)/1000 - -void -omni_thread::sleep(unsigned long secs, unsigned long nanosecs) -{ - if (secs <= MAX_SLEEP_SECONDS) { - thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, secs * 1000 + nanosecs / 1000000); - return; - } - - unsigned no_of_max_sleeps = secs / MAX_SLEEP_SECONDS; - - for (unsigned i = 0; i < no_of_max_sleeps; i++) - thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, MAX_SLEEP_SECONDS * 1000); - - thread_switch(THREAD_NULL, SWITCH_OPTION_WAIT, - (secs % MAX_SLEEP_SECONDS) * 1000 + nanosecs / 1000000); - - return; -} - -void -omni_thread::get_time(unsigned long* abs_sec, unsigned long* abs_nsec, - unsigned long rel_sec, unsigned long rel_nsec) -{ - int rc; - unsigned long tv_sec; - unsigned long tv_nsec; - struct timeval tv; - - rc = gettimeofday(&tv, NULL); - if (rc) throw omni_thread_fatal(rc); - - tv_sec = tv.tv_sec; - tv_nsec = tv.tv_usec * 1000; - - tv_nsec += rel_nsec; - tv_sec += rel_sec + tv_nsec / 1000000000; - tv_nsec = tv_nsec % 1000000000; - - *abs_sec = tv_sec; - *abs_nsec = tv_nsec; -} - - -int -omni_thread::mach_priority(priority_t pri) -{ - switch (pri) { - - case PRIORITY_LOW: - return 0; - - case PRIORITY_NORMAL: - return normal_priority; - - case PRIORITY_HIGH: - return highest_priority; - - default: - return -1; - } -} - -void -omni_thread::stacksize(unsigned long sz) -{ - stack_size = sz; -} - -unsigned long -omni_thread::stacksize() -{ - return stack_size; -} - - -// -// Dummy thread -// - -#error This dummy thread code is not tested. It might work if you're lucky. - -class omni_thread_dummy : public omni_thread { -public: - inline omni_thread_dummy() : omni_thread() - { - _dummy = 1; - _state = STATE_RUNNING; - mach_thread = cthread_self(); - cthread_set_data(mach_thread, (any_t)this)); - } - inline ~omni_thread_dummy() - { - cthread_set_data(mach_thread, (any_t)0)); - } -}; - -omni_thread* -omni_thread::create_dummy() -{ - if (omni_thread::self()) - throw omni_thread_invalid(); - - return new omni_thread_dummy; -} - -void -omni_thread::release_dummy() -{ - omni_thread* self = omni_thread::self(); - if (!self || !self->_dummy) - throw omni_thread_invalid(); - - omni_thread_dummy* dummy = (omni_thread_dummy*)self; - delete dummy; -} - - -#define INSIDE_THREAD_IMPL_CC -#include "threaddata.cc" -#undef INSIDE_THREAD_IMPL_CC diff --git a/omnithread/nt.cc b/omnithread/nt.cc deleted file mode 100644 index 2c97d62139..0000000000 --- a/omnithread/nt.cc +++ /dev/null @@ -1,969 +0,0 @@ -// Package : omnithread -// omnithread/nt.cc Created : 6/95 tjr -// -// Copyright (C) 2006 Free Software Foundation, Inc. -// Copyright (C) 1995-1999 AT&T Laboratories Cambridge -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// - -// -// Implementation of OMNI thread abstraction for NT threads -// - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <errno.h> -#include <WinError.h> -#include <gnuradio/omnithread.h> -#include <process.h> - -#define DB(x) // x -//#include <iostream.h> or #include <iostream> if DB is on. - -static void get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec); - -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// - - -omni_mutex::omni_mutex(void) -{ - InitializeCriticalSection(&crit); -} - -omni_mutex::~omni_mutex(void) -{ - DeleteCriticalSection(&crit); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// - - -// -// Condition variables are tricky to implement using NT synchronisation -// primitives, since none of them have the atomic "release mutex and wait to be -// signalled" which is central to the idea of a condition variable. To get -// around this the solution is to record which threads are waiting and -// explicitly wake up those threads. -// -// Here we implement a condition variable using a list of waiting threads -// (protected by a critical section), and a per-thread semaphore (which -// actually only needs to be a binary semaphore). -// -// To wait on the cv, a thread puts itself on the list of waiting threads for -// that cv, then releases the mutex and waits on its own personal semaphore. A -// signalling thread simply takes a thread from the head of the list and kicks -// that thread's semaphore. Broadcast is simply implemented by kicking the -// semaphore of each waiting thread. -// -// The only other tricky part comes when a thread gets a timeout from a timed -// wait on its semaphore. Between returning with a timeout from the wait and -// entering the critical section, a signalling thread could get in, kick the -// waiting thread's semaphore and remove it from the list. If this happens, -// the waiting thread's semaphore is now out of step so it needs resetting, and -// the thread should indicate that it was signalled rather than that it timed -// out. -// -// It is possible that the thread calling wait or timedwait is not a -// omni_thread. In this case we have to provide a temporary data structure, -// i.e. for the duration of the call, for the thread to link itself on the -// list of waiting threads. _internal_omni_thread_dummy provides such -// a data structure and _internal_omni_thread_helper is a helper class to -// deal with this special case for wait() and timedwait(). Once created, -// the _internal_omni_thread_dummy is cached for use by the next wait() or -// timedwait() call from a non-omni_thread. This is probably worth doing -// because creating a Semaphore is quite heavy weight. - -class _internal_omni_thread_helper; - -class _internal_omni_thread_dummy : public omni_thread { -public: - inline _internal_omni_thread_dummy() : next(0) { } - inline ~_internal_omni_thread_dummy() { } - friend class _internal_omni_thread_helper; -private: - _internal_omni_thread_dummy* next; -}; - -class _internal_omni_thread_helper { -public: - inline _internal_omni_thread_helper() { - d = 0; - t = omni_thread::self(); - if (!t) { - omni_mutex_lock sync(cachelock); - if (cache) { - d = cache; - cache = cache->next; - } - else { - d = new _internal_omni_thread_dummy; - } - t = d; - } - } - inline ~_internal_omni_thread_helper() { - if (d) { - omni_mutex_lock sync(cachelock); - d->next = cache; - cache = d; - } - } - inline operator omni_thread* () { return t; } - inline omni_thread* operator->() { return t; } - - static _internal_omni_thread_dummy* cache; - static omni_mutex cachelock; - -private: - _internal_omni_thread_dummy* d; - omni_thread* t; -}; - -_internal_omni_thread_dummy* _internal_omni_thread_helper::cache = 0; -omni_mutex _internal_omni_thread_helper::cachelock; - - -omni_condition::omni_condition(omni_mutex* m) : mutex(m) -{ - InitializeCriticalSection(&crit); - waiting_head = waiting_tail = NULL; -} - - -omni_condition::~omni_condition(void) -{ - DeleteCriticalSection(&crit); - DB( if (waiting_head != NULL) { - cerr << "omni_condition::~omni_condition: list of waiting threads " - << "is not empty\n"; - } ) -} - - -void -omni_condition::wait(void) -{ - _internal_omni_thread_helper me; - - EnterCriticalSection(&crit); - - me->cond_next = NULL; - me->cond_prev = waiting_tail; - if (waiting_head == NULL) - waiting_head = me; - else - waiting_tail->cond_next = me; - waiting_tail = me; - me->cond_waiting = TRUE; - - LeaveCriticalSection(&crit); - - mutex->unlock(); - - DWORD result = WaitForSingleObject(me->cond_semaphore, INFINITE); - - mutex->lock(); - - if (result != WAIT_OBJECT_0) - throw omni_thread_fatal(GetLastError()); -} - - -int -omni_condition::timedwait(unsigned long abs_sec, unsigned long abs_nsec) -{ - _internal_omni_thread_helper me; - - EnterCriticalSection(&crit); - - me->cond_next = NULL; - me->cond_prev = waiting_tail; - if (waiting_head == NULL) - waiting_head = me; - else - waiting_tail->cond_next = me; - waiting_tail = me; - me->cond_waiting = TRUE; - - LeaveCriticalSection(&crit); - - mutex->unlock(); - - unsigned long now_sec, now_nsec; - - get_time_now(&now_sec, &now_nsec); - - DWORD timeout; - if ((abs_sec <= now_sec) && ((abs_sec < now_sec) || (abs_nsec < now_nsec))) - timeout = 0; - else { - timeout = (abs_sec-now_sec) * 1000; - - if( abs_nsec < now_nsec ) timeout -= (now_nsec-abs_nsec) / 1000000; - else timeout += (abs_nsec-now_nsec) / 1000000; - } - - DWORD result = WaitForSingleObject(me->cond_semaphore, timeout); - - if (result == WAIT_TIMEOUT) { - EnterCriticalSection(&crit); - - if (me->cond_waiting) { - if (me->cond_prev != NULL) - me->cond_prev->cond_next = me->cond_next; - else - waiting_head = me->cond_next; - if (me->cond_next != NULL) - me->cond_next->cond_prev = me->cond_prev; - else - waiting_tail = me->cond_prev; - me->cond_waiting = FALSE; - - LeaveCriticalSection(&crit); - - mutex->lock(); - return 0; - } - - // - // We timed out but another thread still signalled us. Wait for - // the semaphore (it _must_ have been signalled) to decrement it - // again. Return that we were signalled, not that we timed out. - // - - LeaveCriticalSection(&crit); - - result = WaitForSingleObject(me->cond_semaphore, INFINITE); - } - - if (result != WAIT_OBJECT_0) - throw omni_thread_fatal(GetLastError()); - - mutex->lock(); - return 1; -} - - -void -omni_condition::signal(void) -{ - EnterCriticalSection(&crit); - - if (waiting_head != NULL) { - omni_thread* t = waiting_head; - waiting_head = t->cond_next; - if (waiting_head == NULL) - waiting_tail = NULL; - else - waiting_head->cond_prev = NULL; - t->cond_waiting = FALSE; - - if (!ReleaseSemaphore(t->cond_semaphore, 1, NULL)) { - int rc = GetLastError(); - LeaveCriticalSection(&crit); - throw omni_thread_fatal(rc); - } - } - - LeaveCriticalSection(&crit); -} - - -void -omni_condition::broadcast(void) -{ - EnterCriticalSection(&crit); - - while (waiting_head != NULL) { - omni_thread* t = waiting_head; - waiting_head = t->cond_next; - if (waiting_head == NULL) - waiting_tail = NULL; - else - waiting_head->cond_prev = NULL; - t->cond_waiting = FALSE; - - if (!ReleaseSemaphore(t->cond_semaphore, 1, NULL)) { - int rc = GetLastError(); - LeaveCriticalSection(&crit); - throw omni_thread_fatal(rc); - } - } - - LeaveCriticalSection(&crit); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting semaphore -// -/////////////////////////////////////////////////////////////////////////// - - -#define SEMAPHORE_MAX 0x7fffffff - - -omni_semaphore::omni_semaphore(unsigned int initial, unsigned int max_count) -{ - if (max_count > SEMAPHORE_MAX) - max_count= SEMAPHORE_MAX; - - nt_sem = CreateSemaphore(NULL, initial, max_count, NULL); - - if (nt_sem == NULL) { - DB( cerr << "omni_semaphore::omni_semaphore: CreateSemaphore error " - << GetLastError() << endl ); - throw omni_thread_fatal(GetLastError()); - } -} - - -omni_semaphore::~omni_semaphore(void) -{ - if (!CloseHandle(nt_sem)) { - DB( cerr << "omni_semaphore::~omni_semaphore: CloseHandle error " - << GetLastError() << endl ); - throw omni_thread_fatal(GetLastError()); - } -} - - -void -omni_semaphore::wait(void) -{ - if (WaitForSingleObject(nt_sem, INFINITE) != WAIT_OBJECT_0) - throw omni_thread_fatal(GetLastError()); -} - - -int -omni_semaphore::trywait(void) -{ - switch (WaitForSingleObject(nt_sem, 0)) { - - case WAIT_OBJECT_0: - return 1; - case WAIT_TIMEOUT: - return 0; - } - - throw omni_thread_fatal(GetLastError()); - return 0; /* keep msvc++ happy */ -} - - -void -omni_semaphore::post(void) -{ - if (!ReleaseSemaphore(nt_sem, 1, NULL) - && GetLastError() != ERROR_TOO_MANY_POSTS ) // MinGW fix--see ticket:95 in trac - throw omni_thread_fatal(GetLastError()); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - - -// -// Static variables -// - -omni_mutex* omni_thread::next_id_mutex; -int omni_thread::next_id = 0; -static DWORD self_tls_index; - -static unsigned int stack_size = 0; - -// -// Initialisation function (gets called before any user code). -// - -static int& count() { - static int the_count = 0; - return the_count; -} - -omni_thread::init_t::init_t(void) -{ - if (count()++ != 0) // only do it once however many objects get created. - return; - - DB(cerr << "omni_thread::init: NT implementation initialising\n"); - - self_tls_index = TlsAlloc(); - - if (self_tls_index == 0xffffffff) - throw omni_thread_fatal(GetLastError()); - - next_id_mutex = new omni_mutex; - - // - // Create object for this (i.e. initial) thread. - // - - omni_thread* t = new omni_thread; - - t->_state = STATE_RUNNING; - - if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), &t->handle, - 0, FALSE, DUPLICATE_SAME_ACCESS)) - throw omni_thread_fatal(GetLastError()); - - t->nt_id = GetCurrentThreadId(); - - DB(cerr << "initial thread " << t->id() << " NT thread id " << t->nt_id - << endl); - - if (!TlsSetValue(self_tls_index, (LPVOID)t)) - throw omni_thread_fatal(GetLastError()); - - if (!SetThreadPriority(t->handle, nt_priority(PRIORITY_NORMAL))) - throw omni_thread_fatal(GetLastError()); -} - -omni_thread::init_t::~init_t(void) -{ - if (--count() != 0) return; - - omni_thread* self = omni_thread::self(); - if (!self) return; - - TlsSetValue(self_tls_index, (LPVOID)0); - delete self; - - delete next_id_mutex; - - TlsFree(self_tls_index); -} - -// -// Wrapper for thread creation. -// - -extern "C" -#ifndef __BCPLUSPLUS__ -unsigned __stdcall -#else -void _USERENTRY -#endif -omni_thread_wrapper(void* ptr) -{ - omni_thread* me = (omni_thread*)ptr; - - DB(cerr << "omni_thread_wrapper: thread " << me->id() - << " started\n"); - - if (!TlsSetValue(self_tls_index, (LPVOID)me)) - throw omni_thread_fatal(GetLastError()); - - // - // Now invoke the thread function with the given argument. - // - - if (me->fn_void != NULL) { - (*me->fn_void)(me->thread_arg); - omni_thread::exit(); - } - - if (me->fn_ret != NULL) { - void* return_value = (*me->fn_ret)(me->thread_arg); - omni_thread::exit(return_value); - } - - if (me->detached) { - me->run(me->thread_arg); - omni_thread::exit(); - } else { - void* return_value = me->run_undetached(me->thread_arg); - omni_thread::exit(return_value); - } - - // should never get here. -#ifndef __BCPLUSPLUS__ - return 0; -#endif -} - - -// -// Constructors for omni_thread - set up the thread object but don't -// start it running. -// - -// construct a detached thread running a given function. - -omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = fn; - fn_ret = NULL; -} - -// construct an undetached thread running a given function. - -omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 0); - fn_void = NULL; - fn_ret = fn; -} - -// construct a thread which will run either run() or run_undetached(). - -omni_thread::omni_thread(void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = NULL; - fn_ret = NULL; -} - -// common part of all constructors. - -void -omni_thread::common_constructor(void* arg, priority_t pri, int det) -{ - _state = STATE_NEW; - _priority = pri; - - next_id_mutex->lock(); - _id = next_id++; - next_id_mutex->unlock(); - - thread_arg = arg; - detached = det; // may be altered in start_undetached() - - cond_semaphore = CreateSemaphore(NULL, 0, SEMAPHORE_MAX, NULL); - - if (cond_semaphore == NULL) - throw omni_thread_fatal(GetLastError()); - - cond_next = cond_prev = NULL; - cond_waiting = FALSE; - - handle = NULL; - - _dummy = 0; - _values = 0; - _value_alloc = 0; -} - - -// -// Destructor for omni_thread. -// - -omni_thread::~omni_thread(void) -{ - DB(cerr << "destructor called for thread " << id() << endl); - if (_values) { - for (key_t i=0; i < _value_alloc; i++) { - if (_values[i]) { - delete _values[i]; - } - } - delete [] _values; - } - if (handle && !CloseHandle(handle)) - throw omni_thread_fatal(GetLastError()); - if (cond_semaphore && !CloseHandle(cond_semaphore)) - throw omni_thread_fatal(GetLastError()); -} - - -// -// Start the thread -// - -void -omni_thread::start(void) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_NEW) - throw omni_thread_invalid(); - -#ifndef __BCPLUSPLUS__ - // MSVC++ or compatiable - unsigned int t; - handle = (HANDLE)_beginthreadex( - NULL, - stack_size, - omni_thread_wrapper, - (LPVOID)this, - CREATE_SUSPENDED, - &t); - nt_id = t; - if (handle == NULL) - throw omni_thread_fatal(GetLastError()); -#else - // Borland C++ - handle = (HANDLE)_beginthreadNT(omni_thread_wrapper, - stack_size, - (void*)this, - NULL, - CREATE_SUSPENDED, - &nt_id); - if (handle == INVALID_HANDLE_VALUE) - throw omni_thread_fatal(errno); -#endif - - if (!SetThreadPriority(handle, nt_priority(_priority))) - throw omni_thread_fatal(GetLastError()); - - if (ResumeThread(handle) == 0xffffffff) - throw omni_thread_fatal(GetLastError()); - - _state = STATE_RUNNING; -} - - -// -// Start a thread which will run the member function run_undetached(). -// - -void -omni_thread::start_undetached(void) -{ - if ((fn_void != NULL) || (fn_ret != NULL)) - throw omni_thread_invalid(); - - detached = 0; - start(); -} - - -// -// join - simply check error conditions & call WaitForSingleObject. -// - -void -omni_thread::join(void** status) -{ - mutex.lock(); - - if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { - mutex.unlock(); - throw omni_thread_invalid(); - } - - mutex.unlock(); - - if (this == self()) - throw omni_thread_invalid(); - - if (detached) - throw omni_thread_invalid(); - - DB(cerr << "omni_thread::join: doing WaitForSingleObject\n"); - - if (WaitForSingleObject(handle, INFINITE) != WAIT_OBJECT_0) - throw omni_thread_fatal(GetLastError()); - - DB(cerr << "omni_thread::join: WaitForSingleObject succeeded\n"); - - if (status) - *status = return_val; - - delete this; -} - - -// -// Change this thread's priority. -// - -void -omni_thread::set_priority(priority_t pri) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_RUNNING) - throw omni_thread_invalid(); - - _priority = pri; - - if (!SetThreadPriority(handle, nt_priority(pri))) - throw omni_thread_fatal(GetLastError()); -} - - -// -// create - construct a new thread object and start it running. Returns thread -// object if successful, null pointer if not. -// - -// detached version - -omni_thread* -omni_thread::create(void (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - t->start(); - return t; -} - -// undetached version - -omni_thread* -omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - t->start(); - return t; -} - - -// -// exit() _must_ lock the mutex even in the case of a detached thread. This is -// because a thread may run to completion before the thread that created it has -// had a chance to get out of start(). By locking the mutex we ensure that the -// creating thread must have reached the end of start() before we delete the -// thread object. Of course, once the call to start() returns, the user can -// still incorrectly refer to the thread object, but that's their problem. -// - -void -omni_thread::exit(void* return_value) -{ - omni_thread* me = self(); - - if (me) - { - me->mutex.lock(); - - me->_state = STATE_TERMINATED; - - me->mutex.unlock(); - - DB(cerr << "omni_thread::exit: thread " << me->id() << " detached " - << me->detached << " return value " << return_value << endl); - - if (me->detached) { - delete me; - } else { - me->return_val = return_value; - } - } - else - { - DB(cerr << "omni_thread::exit: called with a non-omnithread. Exit quietly." << endl); - } -#ifndef __BCPLUSPLUS__ - // MSVC++ or compatiable - // _endthreadex() does not automatically closes the thread handle. - // The omni_thread dtor closes the thread handle. - _endthreadex(0); -#else - // Borland C++ - // _endthread() does not automatically closes the thread handle. - // _endthreadex() is only available if __MFC_COMPAT__ is defined and - // all it does is to call _endthread(). - _endthread(); -#endif -} - - -omni_thread* -omni_thread::self(void) -{ - LPVOID me; - - me = TlsGetValue(self_tls_index); - - if (me == NULL) { - DB(cerr << "omni_thread::self: called with a non-ominthread. NULL is returned." << endl); - } - return (omni_thread*)me; -} - - -void -omni_thread::yield(void) -{ - Sleep(0); -} - - -#define MAX_SLEEP_SECONDS (DWORD)4294966 // (2**32-2)/1000 - -void -omni_thread::sleep(unsigned long secs, unsigned long nanosecs) -{ - if (secs <= MAX_SLEEP_SECONDS) { - Sleep(secs * 1000 + nanosecs / 1000000); - return; - } - - DWORD no_of_max_sleeps = secs / MAX_SLEEP_SECONDS; - - for (DWORD i = 0; i < no_of_max_sleeps; i++) - Sleep(MAX_SLEEP_SECONDS * 1000); - - Sleep((secs % MAX_SLEEP_SECONDS) * 1000 + nanosecs / 1000000); -} - - -void -omni_thread::get_time(unsigned long* abs_sec, unsigned long* abs_nsec, - unsigned long rel_sec, unsigned long rel_nsec) -{ - get_time_now(abs_sec, abs_nsec); - *abs_nsec += rel_nsec; - *abs_sec += rel_sec + *abs_nsec / 1000000000; - *abs_nsec = *abs_nsec % 1000000000; -} - - -int -omni_thread::nt_priority(priority_t pri) -{ - switch (pri) { - - case PRIORITY_LOW: - return THREAD_PRIORITY_LOWEST; - - case PRIORITY_NORMAL: - return THREAD_PRIORITY_NORMAL; - - case PRIORITY_HIGH: - return THREAD_PRIORITY_HIGHEST; - } - - throw omni_thread_invalid(); - return 0; /* keep msvc++ happy */ -} - - -static void -get_time_now(unsigned long* abs_sec, unsigned long* abs_nsec) -{ - static int days_in_preceding_months[12] - = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; - static int days_in_preceding_months_leap[12] - = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }; - - SYSTEMTIME st; - - GetSystemTime(&st); - *abs_nsec = st.wMilliseconds * 1000000; - - // this formula should work until 1st March 2100 - - DWORD days = ((st.wYear - 1970) * 365 + (st.wYear - 1969) / 4 - + ((st.wYear % 4) - ? days_in_preceding_months[st.wMonth - 1] - : days_in_preceding_months_leap[st.wMonth - 1]) - + st.wDay - 1); - - *abs_sec = st.wSecond + 60 * (st.wMinute + 60 * (st.wHour + 24 * days)); -} - -void -omni_thread::stacksize(unsigned long sz) -{ - stack_size = sz; -} - -unsigned long -omni_thread::stacksize() -{ - return stack_size; -} - -// -// Dummy thread -// - -class omni_thread_dummy : public omni_thread { -public: - inline omni_thread_dummy() : omni_thread() - { - _dummy = 1; - _state = STATE_RUNNING; - - if (!DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), - GetCurrentProcess(), &handle, - 0, FALSE, DUPLICATE_SAME_ACCESS)) - throw omni_thread_fatal(GetLastError()); - - nt_id = GetCurrentThreadId(); - - if (!TlsSetValue(self_tls_index, (LPVOID)this)) - throw omni_thread_fatal(GetLastError()); - } - inline ~omni_thread_dummy() - { - if (!TlsSetValue(self_tls_index, (LPVOID)0)) - throw omni_thread_fatal(GetLastError()); - } -}; - -omni_thread* -omni_thread::create_dummy() -{ - if (omni_thread::self()) - throw omni_thread_invalid(); - - return new omni_thread_dummy; -} - -void -omni_thread::release_dummy() -{ - omni_thread* self = omni_thread::self(); - if (!self || !self->_dummy) - throw omni_thread_invalid(); - - omni_thread_dummy* dummy = (omni_thread_dummy*)self; - delete dummy; -} - - -#if defined(__DMC__) && defined(_WINDLL) -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - return TRUE; -} -#endif - - -#define INSIDE_THREAD_IMPL_CC -#include "threaddata.cc" -#undef INSIDE_THREAD_IMPL_CC diff --git a/omnithread/omni_time.cc b/omnithread/omni_time.cc deleted file mode 100644 index 4920a68399..0000000000 --- a/omnithread/omni_time.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <gnuradio/omni_time.h> -#include <gnuradio/omnithread.h> -#include <math.h> -#include <assert.h> - - -omni_time::omni_time(double real_secs) -{ - double floor_secs = floor(real_secs); - d_secs = (long) floor_secs; - d_nsecs = (long) ((real_secs - floor_secs) * 1e9); // always positive -} - -omni_time -omni_time::time(const omni_time &delta_t) -{ - unsigned long abs_sec, abs_nsec; - unsigned long rel_sec = delta_t.d_secs; - unsigned long rel_nsec = delta_t.d_nsecs; - - omni_thread::get_time(&abs_sec, &abs_nsec, rel_sec, rel_nsec); - return omni_time(abs_sec, abs_nsec); -} - - -omni_time -operator+(const omni_time &x, const omni_time &y) -{ - omni_time r(x.d_secs + y.d_secs, x.d_nsecs + y.d_nsecs); - while (r.d_nsecs >= 1000000000){ - r.d_nsecs -= 1000000000; - r.d_secs++; - } - return r; -} - -omni_time -operator-(const omni_time &x, const omni_time &y) -{ - // assert(!(x < y)); - - omni_time r(x.d_secs - y.d_secs, x.d_nsecs - y.d_nsecs); - while (r.d_nsecs < 0){ - r.d_nsecs += 1000000000; - r.d_secs--; - } - return r; -} - -omni_time -operator+(const omni_time &x, double y) -{ - return x + omni_time(y); -} - -omni_time -operator-(const omni_time &x, double y) -{ - return x - omni_time(y); -} diff --git a/omnithread/posix.cc b/omnithread/posix.cc deleted file mode 100644 index 5574a8a0dd..0000000000 --- a/omnithread/posix.cc +++ /dev/null @@ -1,982 +0,0 @@ -// Package : omnithread -// omnithread/posix.cc Created : 7/94 tjr -// -// Copyright (C) 2006 Free Software Foundation, Inc. -// Copyright (C) 1994-1999 AT&T Laboratories Cambridge -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// - -// -// Implementation of OMNI thread abstraction for posix threads -// -// The source below tests for the definition of the macros: -// PthreadDraftVersion -// PthreadSupportThreadPriority -// NoNanoSleep -// NeedPthreadInit -// -// As different draft versions of the pthread standard P1003.4a/P1003.1c -// define slightly different APIs, the macro 'PthreadDraftVersion' -// identifies the draft version supported by this particular platform. -// -// Some unix variants do not support thread priority unless a real-time -// kernel option is installed. The macro 'PthreadSupportThreadPriority', -// if defined, enables the use of thread priority. If it is not defined, -// setting or changing thread priority will be silently ignored. -// -// nanosleep() is defined in Posix P1003.4 since Draft 9 (?). -// Not all platforms support this standard. The macro 'NoNanoSleep' -// identifies platform that don't. -// - -#include <config.h> -#include <stdlib.h> -#include <errno.h> -#include <time.h> -#include <gnuradio/omnithread.h> - -#if (PthreadDraftVersion == 0) -#error "PthreadDraftVersion not defined. If not sure, define it to 10" -#endif - -#ifdef HAVE_NANOSLEEP -#undef NoNanoSleep -#else -#define NoNanoSleep -#endif - -#ifdef HAVE_SYS_TIME_H -// typedef of struct timeval and gettimeofday(); -#include <sys/time.h> -#include <unistd.h> -#endif - -#if defined(__linux__) && defined(_MIT_POSIX_THREADS) -#include <pthread/mit/sys/timers.h> -#endif - -#if defined(__irix__) && defined(PthreadSupportThreadPriority) -#if _POSIX_THREAD_PRIORITY_SCHEDULING -#include <sched.h> -#endif -#endif - -#if 1 -#define DB(x) // x -#else -#define DB(x) x -#include <iostream> -using std::cerr; -using std::endl; -#endif - -#if (PthreadDraftVersion <= 6) -#define ERRNO(x) (((x) != 0) ? (errno) : 0) -#ifdef __VMS -// pthread_setprio returns old priority on success (draft version 4: -// OpenVms version < 7) -#define THROW_ERRORS(x) { if ((x) == -1) throw omni_thread_fatal(errno); } -#else -#define THROW_ERRORS(x) { if ((x) != 0) throw omni_thread_fatal(errno); } -#endif -#else -#define ERRNO(x) (x) -#define THROW_ERRORS(x) { int rc = (x); \ - if (rc != 0) throw omni_thread_fatal(rc); } -#endif - - - -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// - - -omni_mutex::omni_mutex(void) -{ -#if (PthreadDraftVersion == 4) - THROW_ERRORS(pthread_mutex_init(&posix_mutex, pthread_mutexattr_default)); -#else - THROW_ERRORS(pthread_mutex_init(&posix_mutex, 0)); -#endif -} - -omni_mutex::~omni_mutex(void) -{ - THROW_ERRORS(pthread_mutex_destroy(&posix_mutex)); -} - - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// - - -omni_condition::omni_condition(omni_mutex* m) : mutex(m) -{ -#if (PthreadDraftVersion == 4) - THROW_ERRORS(pthread_cond_init(&posix_cond, pthread_condattr_default)); -#else - THROW_ERRORS(pthread_cond_init(&posix_cond, 0)); -#endif -} - -omni_condition::~omni_condition(void) -{ - THROW_ERRORS(pthread_cond_destroy(&posix_cond)); -} - -void -omni_condition::wait(void) -{ - THROW_ERRORS(pthread_cond_wait(&posix_cond, &mutex->posix_mutex)); -} - -int -omni_condition::timedwait(unsigned long secs, unsigned long nanosecs) -{ - timespec rqts = { secs, nanosecs }; - -again: - int rc = ERRNO(pthread_cond_timedwait(&posix_cond, - &mutex->posix_mutex, &rqts)); - if (rc == 0) - return 1; - -#if (PthreadDraftVersion <= 6) - if (rc == EAGAIN) - return 0; -#endif - - // Some versions of unix produces this errno when the wait was - // interrupted by a unix signal or fork. - // Some versions of the glibc 2.0.x produces this errno when the - // program is debugged under gdb. Straightly speaking this is non-posix - // compliant. We catch this here to make debugging possible. - if (rc == EINTR) - goto again; - - if (rc == ETIMEDOUT) - return 0; - - throw omni_thread_fatal(rc); -#ifdef _MSC_VER - return 0; -#endif -} - -void -omni_condition::signal(void) -{ - THROW_ERRORS(pthread_cond_signal(&posix_cond)); -} - -void -omni_condition::broadcast(void) -{ - THROW_ERRORS(pthread_cond_broadcast(&posix_cond)); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting (or binary) semaphore -// -/////////////////////////////////////////////////////////////////////////// - - -omni_semaphore::omni_semaphore(unsigned int initial, unsigned int _max_count) : c(&m) -{ - value = initial; - max_count = _max_count; - if (value < 0 || max_count < 1) - throw omni_thread_fatal(0); -} - -omni_semaphore::~omni_semaphore(void) -{ -} - -void -omni_semaphore::wait(void) -{ - omni_mutex_lock l(m); - - while (value == 0) - c.wait(); - - value--; -} - -int -omni_semaphore::trywait(void) -{ - omni_mutex_lock l(m); - - if (value == 0) - return 0; - - value--; - return 1; -} - -void -omni_semaphore::post(void) -{ - { - omni_mutex_lock l(m); - if (value < max_count) - value++; - } - - c.signal(); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - - -// -// static variables -// - -omni_mutex* omni_thread::next_id_mutex; -int omni_thread::next_id = 0; - -static pthread_key_t self_key; - -#ifdef PthreadSupportThreadPriority -static int lowest_priority; -static int normal_priority; -static int highest_priority; -#endif - -#if defined(__osf1__) && defined(__alpha__) || defined(__VMS) -// omniORB requires a larger stack size than the default (21120) on OSF/1 -static size_t stack_size = 32768; -#elif defined(__rtems__) -static size_t stack_size = ThreadStackSize; -#elif defined(__aix__) -static size_t stack_size = 262144; -#else -static size_t stack_size = 0; -#endif - -// -// Initialisation function (gets called before any user code). -// - -static int& count() { - static int the_count = 0; - return the_count; -} - -omni_thread::init_t::init_t(void) -{ - if (count()++ != 0) // only do it once however many objects get created. - return; - - DB(cerr << "omni_thread::init: posix 1003.4a/1003.1c (draft " - << PthreadDraftVersion << ") implementation initialising\n"); - -#ifdef NeedPthreadInit - - pthread_init(); - -#endif - -#if (PthreadDraftVersion == 4) - THROW_ERRORS(pthread_keycreate(&self_key, NULL)); -#else - THROW_ERRORS(pthread_key_create(&self_key, NULL)); -#endif - -#ifdef PthreadSupportThreadPriority - -#if defined(__osf1__) && defined(__alpha__) || defined(__VMS) - - lowest_priority = PRI_OTHER_MIN; - highest_priority = PRI_OTHER_MAX; - -#elif defined(__hpux__) - - lowest_priority = PRI_OTHER_MIN; - highest_priority = PRI_OTHER_MAX; - -#elif defined(__sunos__) && (__OSVERSION__ == 5) - - // a bug in pthread_attr_setschedparam means lowest priority is 1 not 0 - - lowest_priority = 1; - highest_priority = 3; - -#else - - lowest_priority = sched_get_priority_min(SCHED_FIFO); - highest_priority = sched_get_priority_max(SCHED_FIFO); - -#endif - - switch (highest_priority - lowest_priority) { - - case 0: - case 1: - normal_priority = lowest_priority; - break; - - default: - normal_priority = lowest_priority + 1; - break; - } - -#endif /* PthreadSupportThreadPriority */ - - next_id_mutex = new omni_mutex; - - // - // Create object for this (i.e. initial) thread. - // - - omni_thread* t = new omni_thread; - - t->_state = STATE_RUNNING; - - t->posix_thread = pthread_self (); - - DB(cerr << "initial thread " << t->id() << endl); - - THROW_ERRORS(pthread_setspecific(self_key, (void*)t)); - -#ifdef PthreadSupportThreadPriority - -#if (PthreadDraftVersion == 4) - - THROW_ERRORS(pthread_setprio(t->posix_thread, - posix_priority(PRIORITY_NORMAL))); - -#elif (PthreadDraftVersion == 6) - - pthread_attr_t attr; - pthread_attr_init(&attr); - - THROW_ERRORS(pthread_attr_setprio(&attr, posix_priority(PRIORITY_NORMAL))); - - THROW_ERRORS(pthread_setschedattr(t->posix_thread, attr)); - -#else - - struct sched_param sparam; - - sparam.sched_priority = posix_priority(PRIORITY_NORMAL); - - THROW_ERRORS(pthread_setschedparam(t->posix_thread, SCHED_OTHER, &sparam)); - -#endif /* PthreadDraftVersion */ - -#endif /* PthreadSupportThreadPriority */ -} - -omni_thread::init_t::~init_t(void) -{ - if (--count() != 0) return; - - omni_thread* self = omni_thread::self(); - if (!self) return; - - pthread_setspecific(self_key, 0); - delete self; - - delete next_id_mutex; -} - -// -// Wrapper for thread creation. -// - -extern "C" void* -omni_thread_wrapper(void* ptr) -{ - omni_thread* me = (omni_thread*)ptr; - - DB(cerr << "omni_thread_wrapper: thread " << me->id() - << " started\n"); - - THROW_ERRORS(pthread_setspecific(self_key, me)); - - // - // Now invoke the thread function with the given argument. - // - - if (me->fn_void != NULL) { - (*me->fn_void)(me->thread_arg); - omni_thread::exit(); - } - - if (me->fn_ret != NULL) { - void* return_value = (*me->fn_ret)(me->thread_arg); - omni_thread::exit(return_value); - } - - if (me->detached) { - me->run(me->thread_arg); - omni_thread::exit(); - } else { - void* return_value = me->run_undetached(me->thread_arg); - omni_thread::exit(return_value); - } - - // should never get here. - - return NULL; -} - - -// -// Constructors for omni_thread - set up the thread object but don't -// start it running. -// - -// construct a detached thread running a given function. - -omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = fn; - fn_ret = NULL; -} - -// construct an undetached thread running a given function. - -omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 0); - fn_void = NULL; - fn_ret = fn; -} - -// construct a thread which will run either run() or run_undetached(). - -omni_thread::omni_thread(void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = NULL; - fn_ret = NULL; -} - -// common part of all constructors. - -void -omni_thread::common_constructor(void* arg, priority_t pri, int det) -{ - _state = STATE_NEW; - _priority = pri; - - next_id_mutex->lock(); - _id = next_id++; - next_id_mutex->unlock(); - - thread_arg = arg; - detached = det; // may be altered in start_undetached() - - _dummy = 0; - _values = 0; - _value_alloc = 0; - // posix_thread is set up in initialisation routine or start(). -} - - -// -// Destructor for omni_thread. -// - -omni_thread::~omni_thread(void) -{ - DB(cerr << "destructor called for thread " << id() << endl); - if (_values) { - for (key_t i=0; i < _value_alloc; i++) { - if (_values[i]) { - delete _values[i]; - } - } - delete [] _values; - } -} - - -// -// Start the thread -// - -void -omni_thread::start(void) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_NEW) - throw omni_thread_invalid(); - - pthread_attr_t attr; - -#if (PthreadDraftVersion == 4) - pthread_attr_create(&attr); -#else - pthread_attr_init(&attr); -#endif - -#if (PthreadDraftVersion == 8) - pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_UNDETACHED); -#endif - -#ifdef PthreadSupportThreadPriority - -#if (PthreadDraftVersion <= 6) - - THROW_ERRORS(pthread_attr_setprio(&attr, posix_priority(_priority))); - -#else - - struct sched_param sparam; - - sparam.sched_priority = posix_priority(_priority); - - THROW_ERRORS(pthread_attr_setschedparam(&attr, &sparam)); - -#endif /* PthreadDraftVersion */ - -#endif /* PthreadSupportThreadPriority */ - -#if !defined(__linux__) - if (stack_size) { - THROW_ERRORS(pthread_attr_setstacksize(&attr, stack_size)); - } -#endif - - -#if (PthreadDraftVersion == 4) - THROW_ERRORS(pthread_create(&posix_thread, attr, omni_thread_wrapper, - (void*)this)); - pthread_attr_delete(&attr); -#else - THROW_ERRORS(pthread_create(&posix_thread, &attr, omni_thread_wrapper, - (void*)this)); - pthread_attr_destroy(&attr); -#endif - - _state = STATE_RUNNING; - - if (detached) { - -#if (PthreadDraftVersion <= 6) - THROW_ERRORS(pthread_detach(&posix_thread)); -#else - THROW_ERRORS(pthread_detach(posix_thread)); -#endif - } -} - - -// -// Start a thread which will run the member function run_undetached(). -// - -void -omni_thread::start_undetached(void) -{ - if ((fn_void != NULL) || (fn_ret != NULL)) - throw omni_thread_invalid(); - - detached = 0; - start(); -} - - -// -// join - simply check error conditions & call pthread_join. -// - -void -omni_thread::join(void** status) -{ - mutex.lock(); - - if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { - mutex.unlock(); - throw omni_thread_invalid(); - } - - mutex.unlock(); - - if (this == self()) - throw omni_thread_invalid(); - - if (detached) - throw omni_thread_invalid(); - - DB(cerr << "omni_thread::join: doing pthread_join\n"); - - THROW_ERRORS(pthread_join(posix_thread, status)); - - DB(cerr << "omni_thread::join: pthread_join succeeded\n"); - -#if (PthreadDraftVersion == 4) - // With draft 4 pthreads implementations (HPUX 10.x and - // Digital Unix 3.2), have to detach the thread after - // join. If not, the storage for the thread will not be - // be reclaimed. - THROW_ERRORS(pthread_detach(&posix_thread)); -#endif - - delete this; -} - - -// -// Change this thread's priority. -// - -void -omni_thread::set_priority(priority_t pri) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_RUNNING) - throw omni_thread_invalid(); - - _priority = pri; - -#ifdef PthreadSupportThreadPriority - -#if (PthreadDraftVersion == 4) - - THROW_ERRORS(pthread_setprio(posix_thread, posix_priority(pri))); - -#elif (PthreadDraftVersion == 6) - - pthread_attr_t attr; - pthread_attr_init(&attr); - - THROW_ERRORS(pthread_attr_setprio(&attr, posix_priority(pri))); - - THROW_ERRORS(pthread_setschedattr(posix_thread, attr)); - -#else - - struct sched_param sparam; - - sparam.sched_priority = posix_priority(pri); - - THROW_ERRORS(pthread_setschedparam(posix_thread, SCHED_OTHER, &sparam)); - -#endif /* PthreadDraftVersion */ - -#endif /* PthreadSupportThreadPriority */ -} - - -// -// create - construct a new thread object and start it running. Returns thread -// object if successful, null pointer if not. -// - -// detached version - -omni_thread* -omni_thread::create(void (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - -// undetached version - -omni_thread* -omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - - -// -// exit() _must_ lock the mutex even in the case of a detached thread. This is -// because a thread may run to completion before the thread that created it has -// had a chance to get out of start(). By locking the mutex we ensure that the -// creating thread must have reached the end of start() before we delete the -// thread object. Of course, once the call to start() returns, the user can -// still incorrectly refer to the thread object, but that's their problem. -// - -void -omni_thread::exit(void* return_value) -{ - omni_thread* me = self(); - - if (me) - { - me->mutex.lock(); - - me->_state = STATE_TERMINATED; - - me->mutex.unlock(); - - DB(cerr << "omni_thread::exit: thread " << me->id() << " detached " - << me->detached << " return value " << return_value << endl); - - if (me->detached) - delete me; - } - else - { - DB(cerr << "omni_thread::exit: called with a non-omnithread. Exit quietly." << endl); - } - - pthread_exit(return_value); -} - - -omni_thread* -omni_thread::self(void) -{ - omni_thread* me; - -#if (PthreadDraftVersion <= 6) - - THROW_ERRORS(pthread_getspecific(self_key, (void**)&me)); - -#else - - me = (omni_thread *)pthread_getspecific(self_key); - -#endif - - if (!me) { - // This thread is not created by omni_thread::start because it - // doesn't has a class omni_thread instance attached to its key. - DB(cerr << "omni_thread::self: called with a non-omnithread. NULL is returned." << endl); - } - - return me; -} - - -void -omni_thread::yield(void) -{ -#if (PthreadDraftVersion == 6) - - pthread_yield(NULL); - -#elif (PthreadDraftVersion < 9) - - pthread_yield(); - -#else - - THROW_ERRORS(sched_yield()); - -#endif -} - - -void -omni_thread::sleep(unsigned long secs, unsigned long nanosecs) -{ - timespec rqts = { secs, nanosecs }; - -#ifndef NoNanoSleep - - timespec remain; - while (nanosleep(&rqts, &remain)) { - if (errno == EINTR) { - rqts.tv_sec = remain.tv_sec; - rqts.tv_nsec = remain.tv_nsec; - continue; - } - else - throw omni_thread_fatal(errno); - } -#else - -#if defined(__osf1__) && defined(__alpha__) || defined(__hpux__) && (__OSVERSION__ == 10) || defined(__VMS) || defined(__SINIX__) || defined (__POSIX_NT__) - - if (pthread_delay_np(&rqts) != 0) - throw omni_thread_fatal(errno); - -#elif defined(__linux__) || defined(__aix__) - - if (secs > 2000) { - while ((secs = ::sleep(secs))) ; - } else { - usleep(secs * 1000000 + (nanosecs / 1000)); - } - -#elif defined(__darwin__) || defined(__macos__) - - // Single UNIX Specification says argument of usleep() must be - // less than 1,000,000. - secs += nanosecs / 1000000000; - nanosecs %= 1000000000; - while ((secs = ::sleep(secs))) ; - usleep(nanosecs / 1000); - -#else - - throw omni_thread_invalid(); - -#endif -#endif /* NoNanoSleep */ -} - - -void -omni_thread::get_time(unsigned long* abs_sec, unsigned long* abs_nsec, - unsigned long rel_sec, unsigned long rel_nsec) -{ - timespec abs; - -#if defined(__osf1__) && defined(__alpha__) || defined(__hpux__) && (__OSVERSION__ == 10) || defined(__VMS) || defined(__SINIX__) || defined(__POSIX_NT__) - - timespec rel; - rel.tv_sec = rel_sec; - rel.tv_nsec = rel_nsec; - THROW_ERRORS(pthread_get_expiration_np(&rel, &abs)); - -#else - -#ifdef HAVE_CLOCK_GETTIME /* __linux__ || __aix__ */ - - clock_gettime(CLOCK_REALTIME, &abs); - -#elif defined(HAVE_GETTIMEOFDAY) /* defined(__linux__) || defined(__aix__) || defined(__SCO_VERSION__) || defined(__darwin__) || defined(__macos__) */ - - struct timeval tv; - gettimeofday(&tv, NULL); - abs.tv_sec = tv.tv_sec; - abs.tv_nsec = tv.tv_usec * 1000; - -#else -#error no get time support -#endif /* __linux__ || __aix__ */ - - abs.tv_nsec += rel_nsec; - abs.tv_sec += rel_sec + abs.tv_nsec / 1000000000; - abs.tv_nsec = abs.tv_nsec % 1000000000; - -#endif /* __osf1__ && __alpha__ */ - - *abs_sec = abs.tv_sec; - *abs_nsec = abs.tv_nsec; -} - - -int -omni_thread::posix_priority(priority_t pri) -{ -#ifdef PthreadSupportThreadPriority - switch (pri) { - - case PRIORITY_LOW: - return lowest_priority; - - case PRIORITY_NORMAL: - return normal_priority; - - case PRIORITY_HIGH: - return highest_priority; - - } -#endif - - throw omni_thread_invalid(); -#ifdef _MSC_VER - return 0; -#endif -} - -void -omni_thread::stacksize(unsigned long sz) -{ - stack_size = sz; -} - -unsigned long -omni_thread::stacksize() -{ - return stack_size; -} - -// -// Dummy thread -// - -class omni_thread_dummy : public omni_thread { -public: - inline omni_thread_dummy() : omni_thread() - { - _dummy = 1; - _state = STATE_RUNNING; - posix_thread = pthread_self(); - THROW_ERRORS(pthread_setspecific(self_key, (void*)this)); - } - inline ~omni_thread_dummy() - { - THROW_ERRORS(pthread_setspecific(self_key, 0)); - } -}; - -omni_thread* -omni_thread::create_dummy() -{ - if (omni_thread::self()) - throw omni_thread_invalid(); - - return new omni_thread_dummy; -} - -void -omni_thread::release_dummy() -{ - omni_thread* self = omni_thread::self(); - if (!self || !self->_dummy) - throw omni_thread_invalid(); - - omni_thread_dummy* dummy = (omni_thread_dummy*)self; - delete dummy; -} - - -#define INSIDE_THREAD_IMPL_CC -#include "threaddata.cc" -#undef INSIDE_THREAD_IMPL_CC diff --git a/omnithread/solaris.cc b/omnithread/solaris.cc deleted file mode 100644 index eedaaa99f6..0000000000 --- a/omnithread/solaris.cc +++ /dev/null @@ -1,615 +0,0 @@ -// Package : omnithread -// omnithread/solaris.cc Created : 7/94 tjr -// -// Copyright (C) 1994-1999 AT&T Laboratories Cambridge -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// -// -// Implementation of OMNI thread abstraction for solaris threads. -// - -#include <stdlib.h> -#include <errno.h> -#include <gnuradio/omnithread.h> - -#define DB(x) // x -// #include <iostream> or #include <iostream.h> if DB is on. - -#define THROW_ERRORS(x) { int rc = (x); \ - if (rc != 0) throw omni_thread_fatal(rc); } - - - -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// - - -omni_mutex::omni_mutex(void) -{ - THROW_ERRORS(mutex_init(&sol_mutex, USYNC_THREAD, 0)); -} - -omni_mutex::~omni_mutex(void) -{ - THROW_ERRORS(mutex_destroy(&sol_mutex)); -} - -void -omni_mutex::lock(void) -{ - THROW_ERRORS(mutex_lock(&sol_mutex)); -} - -void -omni_mutex::unlock(void) -{ - THROW_ERRORS(mutex_unlock(&sol_mutex)); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// - - -omni_condition::omni_condition(omni_mutex* m) : mutex(m) -{ - THROW_ERRORS(cond_init(&sol_cond, USYNC_THREAD, 0)); -} - -omni_condition::~omni_condition(void) -{ - THROW_ERRORS(cond_destroy(&sol_cond)); -} - -void -omni_condition::wait(void) -{ - THROW_ERRORS(cond_wait(&sol_cond, &mutex->sol_mutex)); -} - -int -omni_condition::timedwait(unsigned long secs, unsigned long nanosecs) -{ - timespec rqts = { secs, nanosecs }; - - again: - int rc = cond_timedwait(&sol_cond, &mutex->sol_mutex, &rqts); - - if (rc == 0) - return 1; - - if (rc == EINTR) - goto again; - - if (rc == ETIME) - return 0; - - throw omni_thread_fatal(rc); -} - -void -omni_condition::signal(void) -{ - THROW_ERRORS(cond_signal(&sol_cond)); -} - -void -omni_condition::broadcast(void) -{ - THROW_ERRORS(cond_broadcast(&sol_cond)); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting semaphore -// -/////////////////////////////////////////////////////////////////////////// - - -omni_semaphore::omni_semaphore(unsigned int initial) -{ - THROW_ERRORS(sema_init(&sol_sem, initial, USYNC_THREAD, NULL)); -} - -omni_semaphore::~omni_semaphore(void) -{ - THROW_ERRORS(sema_destroy(&sol_sem)); -} - -void -omni_semaphore::wait(void) -{ - THROW_ERRORS(sema_wait(&sol_sem)); -} - -void -omni_semaphore::post(void) -{ - THROW_ERRORS(sema_post(&sol_sem)); -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - - -// -// Static variables -// - -int omni_thread::init_t::count = 0; - -omni_mutex* omni_thread::next_id_mutex; -int omni_thread::next_id = 0; - -static thread_key_t self_key; - -static size_t stack_size = 0; - -// -// Initialisation function (gets called before any user code). -// - -omni_thread::init_t::init_t(void) -{ - if (count++ != 0) // only do it once however many objects get created. - return; - - DB(cerr << "omni_thread::init: solaris implementation initialising\n"); - - THROW_ERRORS(thr_keycreate(&self_key, NULL)); - - next_id_mutex = new omni_mutex; - - // - // Create object for this (i.e. initial) thread. - // - - omni_thread* t = new omni_thread; - - t->_state = STATE_RUNNING; - - t->sol_thread = thr_self(); - - DB(cerr << "initial thread " << t->id() << " sol_thread " << t->sol_thread - << endl); - - THROW_ERRORS(thr_setspecific(self_key, (void*)t)); - - THROW_ERRORS(thr_setprio(t->sol_thread, sol_priority(PRIORITY_NORMAL))); -} - - -// -// Wrapper for thread creation. -// - -extern "C" void* -omni_thread_wrapper(void* ptr) -{ - omni_thread* me = (omni_thread*)ptr; - - DB(cerr << "omni_thread::wrapper: thread " << me->id() - << " started\n"); - - THROW_ERRORS(thr_setspecific(self_key, me)); - - // - // Now invoke the thread function with the given argument. - // - - if (me->fn_void != NULL) { - (*me->fn_void)(me->thread_arg); - omni_thread::exit(); - } - - if (me->fn_ret != NULL) { - void* return_value = (*me->fn_ret)(me->thread_arg); - omni_thread::exit(return_value); - } - - if (me->detached) { - me->run(me->thread_arg); - omni_thread::exit(); - } else { - void* return_value = me->run_undetached(me->thread_arg); - omni_thread::exit(return_value); - } - - // should never get here. - - return NULL; -} - - -// -// Constructors for omni_thread - set up the thread object but don't -// start it running. -// - -// construct a detached thread running a given function. - -omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = fn; - fn_ret = NULL; -} - -// construct an undetached thread running a given function. - -omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 0); - fn_void = NULL; - fn_ret = fn; -} - -// construct a thread which will run either run() or run_undetached(). - -omni_thread::omni_thread(void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = NULL; - fn_ret = NULL; -} - -// common part of all constructors. - -void -omni_thread::common_constructor(void* arg, priority_t pri, int det) -{ - _state = STATE_NEW; - _priority = pri; - - next_id_mutex->lock(); - _id = next_id++; - next_id_mutex->unlock(); - - thread_arg = arg; - detached = det; // may be altered in start_undetached() - - _dummy = 0; - _values = 0; - _value_alloc = 0; - // sol_thread is set up in initialisation routine or start(). -} - - -// -// Destructor for omni_thread. -// - -omni_thread::~omni_thread(void) -{ - DB(cerr << "destructor called for thread " << id() << endl); - if (_values) { - for (key_t i=0; i < _value_alloc; i++) { - if (_values[i]) { - delete _values[i]; - } - } - delete [] _values; - } -} - - -// -// Start the thread -// - -void -omni_thread::start(void) -{ - long flags = 0; - - if (detached) - flags |= THR_DETACHED; - - omni_mutex_lock l(mutex); - - if (_state != STATE_NEW) - throw omni_thread_invalid(); - - THROW_ERRORS(thr_create(0, stack_size, omni_thread_wrapper, (void*)this, flags, - &sol_thread)); - - _state = STATE_RUNNING; - - THROW_ERRORS(thr_setprio(sol_thread, sol_priority(_priority))); -} - - -// -// Start a thread which will run the member function run_undetached(). -// - -void -omni_thread::start_undetached(void) -{ - if ((fn_void != NULL) || (fn_ret != NULL)) - throw omni_thread_invalid(); - - detached = 0; - start(); -} - - -// -// join - simply check error conditions & call thr_join. -// - -void -omni_thread::join(void** status) -{ - mutex.lock(); - - if ((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) { - mutex.unlock(); - throw omni_thread_invalid(); - } - - mutex.unlock(); - - if (this == self()) - throw omni_thread_invalid(); - - if (detached) - throw omni_thread_invalid(); - - DB(cerr << "omni_thread::join: doing thr_join\n"); - - THROW_ERRORS(thr_join(sol_thread, (thread_t *)NULL, status)); - - DB(cerr << "omni_thread::join: thr_join succeeded\n"); - - delete this; -} - - -// -// Change this thread's priority. -// - -void -omni_thread::set_priority(priority_t pri) -{ - omni_mutex_lock l(mutex); - - if (_state != STATE_RUNNING) - throw omni_thread_invalid(); - - _priority = pri; - - THROW_ERRORS(thr_setprio(sol_thread, sol_priority(pri))); -} - - -// -// create - construct a new thread object and start it running. Returns thread -// object if successful, null pointer if not. -// - -// detached version - -omni_thread* -omni_thread::create(void (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - -// undetached version - -omni_thread* -omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - - -// -// exit() _must_ lock the mutex even in the case of a detached thread. This is -// because a thread may run to completion before the thread that created it has -// had a chance to get out of start(). By locking the mutex we ensure that the -// creating thread must have reached the end of start() before we delete the -// thread object. Of course, once the call to start() returns, the user can -// still incorrectly refer to the thread object, but that's their problem. -// - -void -omni_thread::exit(void* return_value) -{ - omni_thread* me = self(); - - if (me) - { - me->mutex.lock(); - - me->_state = STATE_TERMINATED; - - me->mutex.unlock(); - - DB(cerr << "omni_thread::exit: thread " << me->id() << " detached " - << me->detached << " return value " << return_value << endl); - - if (me->detached) - delete me; - } - else - { - DB(cerr << "omni_thread::exit: called with a non-omnithread. Exit quietly." << endl); - } - - thr_exit(return_value); -} - - -omni_thread* -omni_thread::self(void) -{ - omni_thread* me; - - THROW_ERRORS(thr_getspecific(self_key, (void**)&me)); - - if (!me) { - // This thread is not created by omni_thread::start because it - // doesn't has a class omni_thread instance attached to its key. - DB(cerr << "omni_thread::self: called with a non-ominthread. NULL is returned." << endl); - } - - return me; -} - - -void -omni_thread::yield(void) -{ - thr_yield(); -} - - -void -omni_thread::sleep(unsigned long secs, unsigned long nanosecs) -{ - timespec rqts = { secs, nanosecs }; - timespec remain; - while (nanosleep(&rqts, &remain)) { - if (errno == EINTR) { - rqts.tv_sec = remain.tv_sec; - rqts.tv_nsec = remain.tv_nsec; - continue; - } - else - throw omni_thread_fatal(errno); - } -} - - -void -omni_thread::get_time(unsigned long* abs_sec, unsigned long* abs_nsec, - unsigned long rel_sec, unsigned long rel_nsec) -{ - timespec abs; - clock_gettime(CLOCK_REALTIME, &abs); - abs.tv_nsec += rel_nsec; - abs.tv_sec += rel_sec + abs.tv_nsec / 1000000000; - abs.tv_nsec = abs.tv_nsec % 1000000000; - *abs_sec = abs.tv_sec; - *abs_nsec = abs.tv_nsec; -} - - -int -omni_thread::sol_priority(priority_t pri) -{ - switch (pri) { - - case PRIORITY_LOW: - return 0; - - case PRIORITY_NORMAL: - return 1; - - case PRIORITY_HIGH: - return 2; - } - - throw omni_thread_invalid(); -} - - -void -omni_thread::stacksize(unsigned long sz) -{ - stack_size = sz; -} - -unsigned long -omni_thread::stacksize() -{ - return stack_size; -} - - -// -// Dummy thread -// - -#error This dummy thread code is not tested. It might work if you're lucky. - -class omni_thread_dummy : public omni_thread { -public: - inline omni_thread_dummy() : omni_thread() - { - _dummy = 1; - _state = STATE_RUNNING; - sol_thread = thr_self(); - THROW_ERRORS(thr_setspecific(self_key, (void*)this)); - } - inline ~omni_thread_dummy() - { - THROW_ERRORS(thr_setspecific(self_key, 0)); - } -}; - -omni_thread* -omni_thread::create_dummy() -{ - if (omni_thread::self()) - throw omni_thread_invalid(); - - return new omni_thread_dummy; -} - -void -omni_thread::release_dummy() -{ - omni_thread* self = omni_thread::self(); - if (!self || !self->_dummy) - throw omni_thread_invalid(); - - omni_thread_dummy* dummy = (omni_thread_dummy*)self; - delete dummy; -} - - -#define INSIDE_THREAD_IMPL_CC -#include "threaddata.cc" -#undef INSIDE_THREAD_IMPL_CC diff --git a/omnithread/threaddata.cc b/omnithread/threaddata.cc deleted file mode 100644 index d54c439144..0000000000 --- a/omnithread/threaddata.cc +++ /dev/null @@ -1,83 +0,0 @@ -// Package : omnithread -// omnithread/threaddata.cc Created : 10/2000 dpg1 -// -// Copyright (C) 2000 AT&T Laboratories Cambridge -// -// This file is part of the omnithread library -// -// The omnithread library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library 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 -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free -// Software Foundation, Inc., 51 Franklin Street, Boston, MA -// 02110-1301, USA -// - -// Implementation of per-thread data - -#ifndef INSIDE_THREAD_IMPL_CC -#error "threaddata.cc must be #included by a thread implementation." -#endif - - -static omni_thread::key_t allocated_keys = 0; - -omni_thread::key_t -omni_thread::allocate_key() -{ - omni_mutex_lock l(*next_id_mutex); - return ++allocated_keys; -} - -omni_thread::value_t* -omni_thread::set_value(key_t k, value_t* v) -{ - if (k == 0) return 0; - if (k > _value_alloc) { - next_id_mutex->lock(); - key_t alloc = allocated_keys; - next_id_mutex->unlock(); - - if (k > alloc) return 0; - - value_t** nv = new value_t*[alloc]; - key_t i = 0; - if (_values) { - for (; i < _value_alloc; i++) - nv[i] = _values[i]; - delete [] _values; - } - for (; i < alloc; i++) - nv[i] = 0; - - _values = nv; - _value_alloc = alloc; - } - if (_values[k-1]) delete _values[k-1]; - _values[k-1] = v; - return v; -} - -omni_thread::value_t* -omni_thread::get_value(key_t k) -{ - if (k > _value_alloc) return 0; - return _values[k-1]; -} - -omni_thread::value_t* -omni_thread::remove_value(key_t k) -{ - if (k > _value_alloc) return 0; - value_t* v = _values[k-1]; - _values[k-1] = 0; - return v; -} diff --git a/omnithread/vxWorks.cc b/omnithread/vxWorks.cc deleted file mode 100644 index aaff6cdb20..0000000000 --- a/omnithread/vxWorks.cc +++ /dev/null @@ -1,1160 +0,0 @@ -////////////////////////////////////////////////////////////////////////////// -// Filename: vxWorks.cc -// Author: Tihomir Sokcevic -// Acterna, Eningen. -// Description: vxWorks adaptation of the omnithread wrapper classes -// Notes: Munching strategy is imperative -////////////////////////////////////////////////////////////////////////////// -// $Log$ -// Revision 1.1 2004/04/10 18:00:52 eb -// Initial revision -// -// Revision 1.1.1.1 2004/03/01 00:20:27 eb -// initial checkin -// -// Revision 1.1 2003/05/25 05:29:04 eb -// see ChangeLog -// -// Revision 1.1.2.1 2003/02/17 02:03:11 dgrisby -// vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH). -// -// Revision 1.1.1.1 2002/11/19 14:58:04 sokcevti -// OmniOrb4.0.0 VxWorks port -// -// Revision 1.4 2002/10/15 07:54:09 kuttlest -// change semaphore from SEM_FIFO to SEM_PRIO -// --- -// -// Revision 1.3 2002/07/05 07:38:52 engeln -// made priority redefinable on load time by defining int variables -// omni_thread_prio_low = 220; -// omni_thread_prio_normal = 110; -// omni_thread_prio_high = 55; -// the default priority is prio_normal. -// The normal priority default has been increased from 200 to 110 and the -// high priority from 100 to 55. -// --- -// -// Revision 1.2 2002/06/14 12:44:57 engeln -// replaced possibly unsafe wakeup procedure in broadcast. -// --- -// -// Revision 1.1.1.1 2002/04/02 10:09:34 sokcevti -// omniORB4 initial realease -// -// Revision 1.0 2001/10/23 14:22:45 sokcevti -// Initial Version 4.00 -// --- -// -////////////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////////////////// -// Include files -////////////////////////////////////////////////////////////////////////////// -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> -#include <time.h> -#include <gnuradio/omnithread.h> -#include <sysLib.h> - -#include <assert.h> // assert -#include <intLib.h> // intContext - - -////////////////////////////////////////////////////////////////////////////// -// Local defines -////////////////////////////////////////////////////////////////////////////// -#define ERRNO(x) (((x) != 0) ? (errno) : 0) -#define THROW_ERRORS(x) { if((x) != OK) throw omni_thread_fatal(errno); } -#define OMNI_THREAD_ID 0x7F7155AAl -#define OMNI_STACK_SIZE 32768l - -#ifdef _DEBUG - #include <fstream> - #define DBG_TRACE(X) X -#else // _DEBUG - #define DBG_TRACE(X) -#endif // _DEBUG - -#define DBG_ASSERT(X) - -#define DBG_THROW(X) X - -int omni_thread_prio_low = 220; -int omni_thread_prio_normal = 110; -int omni_thread_prio_high = 55; -/////////////////////////////////////////////////////////////////////////// -// -// Mutex -// -/////////////////////////////////////////////////////////////////////////// -omni_mutex::omni_mutex(void):m_bConstructed(false) -{ - mutexID = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE); - - DBG_ASSERT(assert(mutexID != NULL)); - - if(mutexID==NULL) - { - DBG_TRACE(cout<<"Exception: omni_mutex::omni_mutex() tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(-1)); - } - - m_bConstructed = true; -} - -omni_mutex::~omni_mutex(void) -{ - m_bConstructed = false; - - STATUS status = semDelete(mutexID); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_mutex::~omni_mutex() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - -/* -void omni_mutex::lock(void) -{ - DBG_ASSERT(assert(!intContext())); // not in ISR context - DBG_ASSERT(assert(m_bConstructed)); - - STATUS status = semTake(mutexID, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_mutex::lock() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - -void omni_mutex::unlock(void) -{ - DBG_ASSERT(assert(m_bConstructed)); - - STATUS status = semGive(mutexID); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_mutex::unlock() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} -*/ - -/////////////////////////////////////////////////////////////////////////// -// -// Condition variable -// -/////////////////////////////////////////////////////////////////////////// -omni_condition::omni_condition(omni_mutex* m) : mutex(m) -{ - DBG_TRACE(cout<<"omni_condition::omni_condition mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl); - - waiters_ = 0; - - sema_ = semCCreate(SEM_Q_PRIORITY, 0); - if(sema_ == NULL) - { - DBG_TRACE(cout<<"Exception: omni_condition::omni_condition() tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - waiters_lock_ = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE); - if(waiters_lock_ == NULL) - { - DBG_TRACE(cout<<"Exception: omni_condition::omni_condition() tid: "<<(int)taskIdSelf()<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - -} - -omni_condition::~omni_condition(void) -{ - STATUS status = semDelete(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::~omni_condition"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - status = semDelete(sema_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::~omni_condition"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - -void omni_condition::wait(void) -{ - DBG_TRACE(cout<<"omni_condition::wait mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl); - - // Prevent race conditions on the <waiters_> count. - - STATUS status = semTake(waiters_lock_,WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - ++waiters_; - - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // disable task lock to have an atomic unlock+semTake - taskLock(); - - // We keep the lock held just long enough to increment the count of - // waiters by one. Note that we can't keep it held across the call - // to wait() since that will deadlock other calls to signal(). - mutex->unlock(); - - // Wait to be awakened by a cond_signal() or cond_broadcast(). - status = semTake(sema_,WAIT_FOREVER); - - // reenable task rescheduling - taskUnlock(); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // Reacquire lock to avoid race conditions on the <waiters_> count. - status = semTake(waiters_lock_,WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // We're ready to return, so there's one less waiter. - --waiters_; - - // Release the lock so that other collaborating threads can make - // progress. - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // Bad things happened, so let's just return below. - - // We must always regain the <external_mutex>, even when errors - // occur because that's the guarantee that we give to our callers. - mutex->lock(); -} - - -// The time given is absolute. Return 0 is timeout -int omni_condition::timedwait(unsigned long secs, unsigned long nanosecs) -{ - STATUS result = OK; - timespec now; - unsigned long timeout; - int ticks; - - // Prevent race conditions on the <waiters_> count. - STATUS status = semTake(waiters_lock_, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - ++waiters_; - - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - clock_gettime(CLOCK_REALTIME, &now); - - if(((unsigned long)secs <= (unsigned long)now.tv_sec) && - (((unsigned long)secs < (unsigned long)now.tv_sec) || - (nanosecs < (unsigned long)now.tv_nsec))) - timeout = 0; - else - timeout = (secs-now.tv_sec) * 1000 + (nanosecs-now.tv_nsec) / 1000000l; - - // disable task lock to have an atomic unlock+semTake - taskLock(); - - // We keep the lock held just long enough to increment the count - // of waiters by one. - mutex->unlock(); - - // Wait to be awakened by a signal() or broadcast(). - ticks = (timeout * sysClkRateGet()) / 1000L; - result = semTake(sema_, ticks); - - // reenable task rescheduling - taskUnlock(); - - // Reacquire lock to avoid race conditions. - status = semTake(waiters_lock_, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - --waiters_; - - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // A timeout has occured - fires exception if the origin is other than timeout - if(result!=OK && !(errno == S_objLib_OBJ_TIMEOUT || errno == S_objLib_OBJ_UNAVAILABLE)) - { - DBG_TRACE(cout<<"omni_condition::timedwait! - thread:"<<omni_thread::self()->id()<<" SemID:"<<(int)sema_<<" errno:"<<errno<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - // We must always regain the <external_mutex>, even when errors - // occur because that's the guarantee that we give to our callers. - mutex->lock(); - - if(result!=OK) // timeout - return 0; - - return 1; -} - -void omni_condition::signal(void) -{ - DBG_TRACE(cout<<"omni_condition::signal mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl); - - STATUS status = semTake(waiters_lock_, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - int have_waiters = waiters_ > 0; - - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - if(have_waiters != 0) - { - status = semGive(sema_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - } -} - -void omni_condition::broadcast(void) -{ - DBG_TRACE(cout<<"omni_condition::broadcast mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl); - - int have_waiters = 0; - - // The <external_mutex> must be locked before this call is made. - // This is needed to ensure that <waiters_> and <was_broadcast_> are - // consistent relative to each other. - STATUS status = semTake(waiters_lock_, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - if(waiters_ > 0) - { - // We are broadcasting, even if there is just one waiter... - // Record the fact that we are broadcasting. This helps the - // cond_wait() method know how to optimize itself. Be sure to - // set this with the <waiters_lock_> held. - have_waiters = 1; - } - - status = semGive(waiters_lock_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - if(have_waiters) - { - // Wake up all the waiters. - status = semFlush(sema_); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"omni_condition::broadcast1! - thread:"<<omni_thread::self()->id()<<" SemID:"<<(int)sema_<<" errno:"<<errno<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - - } -} - - -/////////////////////////////////////////////////////////////////////////// -// -// Counting semaphore -// -/////////////////////////////////////////////////////////////////////////// -omni_semaphore::omni_semaphore(unsigned int initial) -{ - - DBG_ASSERT(assert(0 <= (int)initial)); // POSIX expects only unsigned init values - - semID = semCCreate(SEM_Q_PRIORITY, (int)initial); - - DBG_ASSERT(assert(semID!=NULL)); - - if(semID==NULL) - { - DBG_TRACE(cout<<"Exception: omni_semaphore::omni_semaphore"<<endl); - DBG_THROW(throw omni_thread_fatal(-1)); - } -} - -omni_semaphore::~omni_semaphore(void) -{ - STATUS status = semDelete(semID); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_semaphore::~omni_semaphore"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - -void omni_semaphore::wait(void) -{ - DBG_ASSERT(assert(!intContext())); // no wait in ISR - - STATUS status = semTake(semID, WAIT_FOREVER); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_semaphore::wait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - -int omni_semaphore::trywait(void) -{ - STATUS status = semTake(semID, NO_WAIT); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - if(errno == S_objLib_OBJ_UNAVAILABLE) - { - return 0; - } - else - { - DBG_ASSERT(assert(false)); - - DBG_TRACE(cout<<"Exception: omni_semaphore::trywait"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } - } - - return 1; -} - -void omni_semaphore::post(void) -{ - STATUS status = semGive(semID); - - DBG_ASSERT(assert(status == OK)); - - if(status != OK) - { - DBG_TRACE(cout<<"Exception: omni_semaphore::post"<<endl); - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - - - -/////////////////////////////////////////////////////////////////////////// -// -// Thread -// -/////////////////////////////////////////////////////////////////////////// - - -// -// static variables -// -omni_mutex* omni_thread::next_id_mutex = 0; -int omni_thread::next_id = 0; - -// omniORB requires a larger stack size than the default (21120) on OSF/1 -static size_t stack_size = OMNI_STACK_SIZE; - - -// -// Initialisation function (gets called before any user code). -// - -static int& count() { - static int the_count = 0; - return the_count; -} - -omni_thread::init_t::init_t(void) -{ - // Only do it once however many objects get created. - if(count()++ != 0) - return; - - attach(); -} - -omni_thread::init_t::~init_t(void) -{ - if (--count() != 0) return; - - omni_thread* self = omni_thread::self(); - if (!self) return; - - taskTcb(taskIdSelf())->spare1 = 0; - delete self; - - delete next_id_mutex; -} - - -// -// Wrapper for thread creation. -// -extern "C" void omni_thread_wrapper(void* ptr) -{ - omni_thread* me = (omni_thread*)ptr; - - DBG_TRACE(cout<<"omni_thread_wrapper: thread "<<me->id()<<" started\n"); - - // - // We can now tweaked the task info since the tcb exist now - // - me->mutex.lock(); // To ensure that start has had time to finish - taskTcb(me->tid)->spare1 = OMNI_THREAD_ID; - taskTcb(me->tid)->spare2 = (int)ptr; - me->mutex.unlock(); - - // - // Now invoke the thread function with the given argument. - // - if(me->fn_void != NULL) - { - (*me->fn_void)(me->thread_arg); - omni_thread::exit(); - } - - if(me->fn_ret != NULL) - { - void* return_value = (*me->fn_ret)(me->thread_arg); - omni_thread::exit(return_value); - } - - if(me->detached) - { - me->run(me->thread_arg); - omni_thread::exit(); - } - else - { - void* return_value = me->run_undetached(me->thread_arg); - omni_thread::exit(return_value); - } -} - - -// -// Special functions for VxWorks only -// -void omni_thread::attach(void) -{ - DBG_TRACE(cout<<"omni_thread_attach: VxWorks mapping thread initialising\n"); - - int _tid = taskIdSelf(); - - // Check the task is not already attached - if(taskTcb(_tid)->spare1 == OMNI_THREAD_ID) - return; - - // Create the mutex required to lock the threads debugging id (create before the thread!!!) - if(next_id_mutex == 0) - next_id_mutex = new omni_mutex; - - // Create a thread object for THIS running process - omni_thread* t = new omni_thread; - - // Lock its mutex straigh away! - omni_mutex_lock l(t->mutex); - - // Adjust data members of this instance - t->_state = STATE_RUNNING; - t->tid = taskIdSelf(); - - // Set the thread values so it can be recongnised as a omni_thread - // Set the id last can possibly prevent race condition - taskTcb(t->tid)->spare2 = (int)t; - taskTcb(t->tid)->spare1 = OMNI_THREAD_ID; - - // Create the running_mutex at this stage, but leave it empty. We are not running - // in the task context HERE, so taking it would be disastrous. - t->running_cond = new omni_condition(&t->mutex); -} - - -void omni_thread::detach(void) -{ - DBG_TRACE(cout<<"omni_thread_detach: VxWorks detaching thread mapping\n"); - - int _tid = taskIdSelf(); - - // Check the task has a OMNI_THREAD attached - if(taskTcb(_tid)->spare1 != OMNI_THREAD_ID) - return; - - // Invalidate the id NOW ! - taskTcb(_tid)->spare1 = 0; - - // Even if NULL, it is safe to delete the thread - omni_thread* t = (omni_thread*)taskTcb(_tid)->spare2; - // Fininsh cleaning the tcb structure - taskTcb(_tid)->spare2 = 0; - - delete t; -} - - -// -// Constructors for omni_thread - set up the thread object but don't -// start it running. -// - -// construct a detached thread running a given function. -omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = fn; - fn_ret = NULL; -} - -// construct an undetached thread running a given function. -omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri) -{ - common_constructor(arg, pri, 0); - fn_void = NULL; - fn_ret = fn; -} - -// construct a thread which will run either run() or run_undetached(). - -omni_thread::omni_thread(void* arg, priority_t pri) -{ - common_constructor(arg, pri, 1); - fn_void = NULL; - fn_ret = NULL; -} - -// common part of all constructors. -void omni_thread::common_constructor(void* arg, priority_t pri, int det) -{ - _state = STATE_NEW; - _priority = pri; - - // Set the debugging id - next_id_mutex->lock(); - _id = next_id++; - next_id_mutex->unlock(); - - // Note : tid can only be setup when the task is up and running - tid = 0; - - thread_arg = arg; - detached = det; // may be altered in start_undetached() - - _dummy = 0; - _values = 0; - _value_alloc = 0; -} - -// -// Destructor for omni_thread. -// -omni_thread::~omni_thread(void) -{ - DBG_TRACE(cout<<"omni_thread::~omni_thread for thread "<<id()<<endl); - - if (_values) { - for (key_t i=0; i < _value_alloc; i++) { - if (_values[i]) { - delete _values[i]; - } - } - delete [] _values; - } - - delete running_cond; -} - - -// -// Start the thread -// -void omni_thread::start(void) -{ - omni_mutex_lock l(mutex); - - DBG_ASSERT(assert(_state == STATE_NEW)); - - if(_state != STATE_NEW) - DBG_THROW(throw omni_thread_invalid()); - - // Allocate memory for the task. (The returned id cannot be trusted by the task) - tid = taskSpawn( - NULL, // Task name - vxworks_priority(_priority), // Priority - 0, // Option - stack_size, // Stack size - (FUNCPTR)omni_thread_wrapper, // Priority - (int)this, // First argument is this - 0,0,0,0,0,0,0,0,0 // Remaining unused args - ); - - DBG_ASSERT(assert(tid!=ERROR)); - - if(tid==ERROR) - DBG_THROW(throw omni_thread_invalid()); - - _state = STATE_RUNNING; - - // Create the running_mutex at this stage, but leave it empty. We are not running - // in the task context HERE, so taking it would be disastrous. - running_cond = new omni_condition(&mutex); -} - - -// -// Start a thread which will run the member function run_undetached(). -// -void omni_thread::start_undetached(void) -{ - DBG_ASSERT(assert(!((fn_void != NULL) || (fn_ret != NULL)))); - - if((fn_void != NULL) || (fn_ret != NULL)) - DBG_THROW(throw omni_thread_invalid()); - - detached = 0; - - start(); -} - - -// -// join - Wait for the task to complete before returning to the calling process -// -void omni_thread::join(void** status) -{ - mutex.lock(); - - if((_state != STATE_RUNNING) && (_state != STATE_TERMINATED)) - { - mutex.unlock(); - - DBG_ASSERT(assert(false)); - - DBG_THROW(throw omni_thread_invalid()); - } - - mutex.unlock(); - - DBG_ASSERT(assert(this != self())); - - if(this == self()) - DBG_THROW(throw omni_thread_invalid()); - - DBG_ASSERT(assert(!detached)); - - if(detached) - DBG_THROW(throw omni_thread_invalid()); - - mutex.lock(); - running_cond->wait(); - mutex.unlock(); - - if(status) - *status = return_val; - - delete this; -} - - -// -// Change this thread's priority. -// -void omni_thread::set_priority(priority_t pri) -{ - omni_mutex_lock l(mutex); - - DBG_ASSERT(assert(_state == STATE_RUNNING)); - - if(_state != STATE_RUNNING) - { - DBG_THROW(throw omni_thread_invalid()); - } - - _priority = pri; - - if(taskPrioritySet(tid, vxworks_priority(pri))==ERROR) - { - DBG_ASSERT(assert(false)); - - DBG_THROW(throw omni_thread_fatal(errno)); - } -} - - -// -// create - construct a new thread object and start it running. Returns thread -// object if successful, null pointer if not. -// - -// detached version (the entry point is a void) -omni_thread* omni_thread::create(void (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - -// undetached version (the entry point is a void*) -omni_thread* omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri) -{ - omni_thread* t = new omni_thread(fn, arg, pri); - - t->start(); - - return t; -} - - -// -// exit() _must_ lock the mutex even in the case of a detached thread. This is -// because a thread may run to completion before the thread that created it has -// had a chance to get out of start(). By locking the mutex we ensure that the -// creating thread must have reached the end of start() before we delete the -// thread object. Of course, once the call to start() returns, the user can -// still incorrectly refer to the thread object, but that's their problem. -// -void omni_thread::exit(void* return_value) -{ - omni_thread* me = self(); - - if(me) - { - me->mutex.lock(); - - me->return_val = return_value; - me->_state = STATE_TERMINATED; - me->running_cond->signal(); - - me->mutex.unlock(); - - DBG_TRACE(cout<<"omni_thread::exit: thread "<<me->id()<<" detached "<<me->detached<<" return value "<<(int)return_value<<endl); - - if(me->detached) - delete me; - } - else - DBG_TRACE(cout<<"omni_thread::exit: called with a non-omnithread. Exit quietly."<<endl); - - taskDelete(taskIdSelf()); -} - - -omni_thread* omni_thread::self(void) -{ - if(taskTcb(taskIdSelf())->spare1 != OMNI_THREAD_ID) - return NULL; - - return (omni_thread*)taskTcb(taskIdSelf())->spare2; -} - - -void omni_thread::yield(void) -{ - taskDelay(NO_WAIT); -} - - -void omni_thread::sleep(unsigned long secs, unsigned long nanosecs) -{ - int tps = sysClkRateGet(); - - // Convert to us to avoid overflow in the multiplication - // tps should always be less than 1000 ! - nanosecs /= 1000; - - taskDelay(secs*tps + (nanosecs*tps)/1000000l); -} - - -void omni_thread::get_time( unsigned long* abs_sec, - unsigned long* abs_nsec, - unsigned long rel_sec, - unsigned long rel_nsec) -{ - timespec abs; - clock_gettime(CLOCK_REALTIME, &abs); - abs.tv_nsec += rel_nsec; - abs.tv_sec += rel_sec + abs.tv_nsec / 1000000000; - abs.tv_nsec = abs.tv_nsec % 1000000000; - *abs_sec = abs.tv_sec; - *abs_nsec = abs.tv_nsec; -} - - -int omni_thread::vxworks_priority(priority_t pri) -{ - switch (pri) - { - case PRIORITY_LOW: - return omni_thread_prio_low; - - case PRIORITY_NORMAL: - return omni_thread_prio_normal; - - case PRIORITY_HIGH: - return omni_thread_prio_high; - } - - DBG_ASSERT(assert(false)); - - DBG_THROW(throw omni_thread_invalid()); -} - - -void omni_thread::stacksize(unsigned long sz) -{ - stack_size = sz; -} - - -unsigned long omni_thread::stacksize() -{ - return stack_size; -} - - -void omni_thread::show(void) -{ - omni_thread *pThread; - int s1, s2; - int tid = taskIdSelf(); - - printf("TaskId is %.8x\n", tid); - - s1 = taskTcb(tid)->spare1; - - if(s1 != OMNI_THREAD_ID) - { - printf("Spare 1 is %.8x, and not recongnized\n", s1); - - return; - } - else - { - printf("Spare 1 indicate an omni_thread.\n"); - } - - s2 = taskTcb(tid)->spare2; - - if(s2 == 0) - { - printf("Spare 2 is NULL! - No thread object attached !!\n"); - - return; - } - else - { - printf("Thread object at %.8x\n", s2); - } - - pThread = (omni_thread *)s2; - - state_t status = pThread->_state; - - printf(" | Thread status is "); - - switch (status) - { - case STATE_NEW: - printf("NEW\n"); break; - case STATE_RUNNING: - printf("STATE_RUNNING\n"); break; - case STATE_TERMINATED: - printf("TERMINATED\n"); break; - default: - printf("Illegal (=%.8x)\n", (unsigned int)status); - - return; - } - - if(pThread->tid != tid) - { - printf(" | Task ID in thread object is different!! (=%.8x)\n", pThread->tid); - - return; - } - else - { - printf(" | Task ID in thread consistent\n"); - } - - printf("\n"); -} - - -// -// Dummy thread -// - -class omni_thread_dummy : public omni_thread { -public: - inline omni_thread_dummy() : omni_thread() - { - _dummy = 1; - _state = STATE_RUNNING; - - // Adjust data members of this instance - tid = taskIdSelf(); - - // Set the thread values so it can be recongnised as a omni_thread - // Set the id last can possibly prevent race condition - taskTcb(tid)->spare2 = (int)this; - taskTcb(tid)->spare1 = OMNI_THREAD_ID; - } - inline ~omni_thread_dummy() - { - taskTcb(taskIdSelf())->spare1 = 0; - } -}; - -omni_thread* -omni_thread::create_dummy() -{ - if (omni_thread::self()) - throw omni_thread_invalid(); - - return new omni_thread_dummy; -} - -void -omni_thread::release_dummy() -{ - omni_thread* self = omni_thread::self(); - if (!self || !self->_dummy) - throw omni_thread_invalid(); - - omni_thread_dummy* dummy = (omni_thread_dummy*)self; - delete dummy; -} - - -#define INSIDE_THREAD_IMPL_CC -#include "threaddata.cc" -#undef INSIDE_THREAD_IMPL_CC diff --git a/run_tests.sh.in b/run_tests.sh.in index ce0d909788..1cb8e170ad 100644 --- a/run_tests.sh.in +++ b/run_tests.sh.in @@ -56,9 +56,6 @@ fi PYTHONPATH="$mylibdir:$mysrcdir:$mypydir:$PYTHONPATH" export PYTHONPATH -# Where to find omnithread library files -gromnidir=@omnithread_LIBDIRPATH@ - # Where to find gruel library files grueldir=@gruel_LIBDIRPATH@ @@ -68,7 +65,7 @@ grcoredir=@gnuradio_core_LIBDIRPATH@ # Construct search path for python modules # Check each one to make sure it's not "" before adding grlibdir="" -for dir in $gromnidir $grcoredir $grueldir +for dir in $grcoredir $grueldir do if [ "$dir" != "" ] then diff --git a/usrp/firmware/include/usrp_ids.h b/usrp/firmware/include/usrp_ids.h index dd5daed012..46a0694349 100644 --- a/usrp/firmware/include/usrp_ids.h +++ b/usrp/firmware/include/usrp_ids.h @@ -55,6 +55,8 @@ #define USB_PID_FSF_BDALE_8 0x0012 // Bdale Garbee <bdale@gag.com> #define USB_PID_FSF_BDALE_9 0x0013 // Bdale Garbee <bdale@gag.com> #define USB_PID_FSF_HPSDR_HERMES 0x0014 // HPSDR Hermes +#define USB_PID_FSF_THINKRF 0x0015 // Catalin Patulea <catalin.patulea@thinkrf.com> +#define USB_PID_FSF_MSA 0x0016 // Hans de Bok <hdbok@dionaea.demon.nl> Scotty's Modular Spectrum Analyzer #define USB_PID_FSF_LBNL_UXO 0x0018 // http://recycle.lbl.gov/~ldoolitt/uxo/ diff --git a/usrp/firmware/src/common/build_eeprom.py b/usrp/firmware/src/common/build_eeprom.py index ed9bb56a48..d73cbbc4f7 100755 --- a/usrp/firmware/src/common/build_eeprom.py +++ b/usrp/firmware/src/common/build_eeprom.py @@ -146,7 +146,7 @@ def build_shell_script (out, ihx_filename, rev, prefix): out.write ('#!/bin/sh\n') out.write ('usrper -x load_firmware ' + prefix + '/share/usrp/rev%d/std.ihx\n' % rev) - out.write ('sleep 1\n') + out.write ('sleep 2\n') # print "len(image) =", len(image) @@ -161,7 +161,7 @@ def build_shell_script (out, ihx_filename, rev, prefix): (i2c_addr, rom_addr, ''.join (hex_image[0:l]))) hex_image = hex_image[l:] rom_addr = rom_addr + l - out.write ('sleep 1\n') + out.write ('sleep 2\n') if __name__ == '__main__': usage = "usage: %prog -p PREFIX -r REV [options] bootfile.ihx" diff --git a/usrp/host/lib/Makefile.am b/usrp/host/lib/Makefile.am index 1fff1548bf..f01ff8a0ad 100644 --- a/usrp/host/lib/Makefile.am +++ b/usrp/host/lib/Makefile.am @@ -1,7 +1,7 @@ # # USRP - Universal Software Radio Peripheral # -# Copyright (C) 2003,2004,2006,2007,2008,2009 Free Software Foundation, Inc. +# Copyright (C) 2003,2004,2006,2007,2008,2009,2010 Free Software Foundation, Inc. # # 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 @@ -31,10 +31,10 @@ libusrp_la_common_LIBADD = \ $(BOOST_THREAD_LIB) \ ../misc/libmisc.la -# darwin fusb requires omnithreads +# darwin fusb requires gruel (for threading) if FUSB_TECH_darwin -AM_CPPFLAGS = $(common_INCLUDES) $(OMNITHREAD_INCLUDES) $(BOOST_CPPFLAGS) $(WITH_INCLUDES) -libusrp_la_LIBADD = $(libusrp_la_common_LIBADD) $(OMNITHREAD_LA) +AM_CPPFLAGS = $(common_INCLUDES) $(GRUEL_INCLUDES) $(BOOST_CPPFLAGS) $(WITH_INCLUDES) +libusrp_la_LIBADD = $(libusrp_la_common_LIBADD) $(GRUEL_LA) libusrp_la_LDFLAGS = $(libusrp_la_common_LDFLAGS) -framework CoreFoundation else AM_CPPFLAGS = $(common_INCLUDES) $(BOOST_CPPFLAGS) $(WITH_INCLUDES) @@ -70,7 +70,6 @@ darwin_CODE = \ circular_buffer.h \ circular_linked_list.h \ darwin_libusb.h \ - mld_threads.h \ usrp_prims_libusb0.cc diff --git a/usrp/host/lib/circular_buffer.h b/usrp/host/lib/circular_buffer.h index 6d491fb6f0..48758bf878 100644 --- a/usrp/host/lib/circular_buffer.h +++ b/usrp/host/lib/circular_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -23,7 +23,7 @@ #ifndef _CIRCULAR_BUFFER_H_ #define _CIRCULAR_BUFFER_H_ -#include "mld_threads.h" +#include <gruel/thread.h> #include <iostream> #include <stdexcept> @@ -37,7 +37,8 @@ #define DEBUG(X) do{} while(0); #endif -template <class T> class circular_buffer +template <class T> +class circular_buffer { private: // the buffer to use @@ -48,8 +49,9 @@ private: size_t d_n_avail_write_I, d_n_avail_read_I; // stuff to control access to class internals - mld_mutex_ptr d_internal; - mld_condition_ptr d_readBlock, d_writeBlock; + gruel::mutex* d_internal; + gruel::condition_variable* d_readBlock; + gruel::condition_variable* d_writeBlock; // booleans to decide how to control reading, writing, and aborting bool d_doWriteBlock, d_doFullRead, d_doAbort; @@ -94,16 +96,14 @@ public: }; inline size_t n_avail_write_items () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); size_t retVal = d_n_avail_write_I; - d_internal->unlock (); return (retVal); }; inline size_t n_avail_read_items () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); size_t retVal = d_n_avail_read_I; - d_internal->unlock (); return (retVal); }; @@ -120,13 +120,13 @@ public: // create a mutex to handle contention of shared resources; // any routine needed access to shared resources uses lock() // before doing anything, then unlock() when finished. - d_internal = new mld_mutex (); + d_internal = new gruel::mutex (); // link the internal mutex to the read and write conditions; // when wait() is called, the internal mutex will automatically - // be unlock()'ed. Upon return (from a signal() to the condition), + // be unlock()'ed. Upon return (from a notify_one() to the condition), // the internal mutex will be lock()'ed. - d_readBlock = new mld_condition (d_internal); - d_writeBlock = new mld_condition (d_internal); + d_readBlock = new gruel::condition_variable (); + d_writeBlock = new gruel::condition_variable (); }; /* @@ -167,9 +167,8 @@ public: if (!buf) throw std::runtime_error ("circular_buffer::enqueue(): " "input buffer is NULL.\n"); - d_internal->lock (); + gruel::scoped_lock l (*d_internal); if (d_doAbort) { - d_internal->unlock (); return (2); } // set the return value to 1: success; change if needed @@ -178,11 +177,11 @@ public: if (d_doWriteBlock) { while (bufLen_I > d_n_avail_write_I) { DEBUG (std::cerr << "enqueue: #len > #a, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_writeBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_writeBlock->wait (l); + // and auto re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "enqueue: #len > #a, aborting." << std::endl); return (2); } @@ -208,8 +207,7 @@ public: d_writeNdx_I += n_now_I; d_n_avail_read_I += bufLen_I; d_n_avail_write_I -= bufLen_I; - d_readBlock->signal (); - d_internal->unlock (); + d_readBlock->notify_one (); return (retval); }; @@ -255,19 +253,18 @@ public: throw std::runtime_error ("circular_buffer::dequeue()"); } - d_internal->lock (); + gruel::scoped_lock l (*d_internal); if (d_doAbort) { - d_internal->unlock (); return (2); } if (d_doFullRead) { while (d_n_avail_read_I < l_bufLen_I) { DEBUG (std::cerr << "dequeue: #a < #len, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_readBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_readBlock->wait (l); + // and re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "dequeue: #a < #len, aborting." << std::endl); return (2); } @@ -276,11 +273,11 @@ public: } else { while (d_n_avail_read_I == 0) { DEBUG (std::cerr << "dequeue: #a == 0, waiting." << std::endl); - // wait will automatically unlock() the internal mutex - d_readBlock->wait (); - // and lock() it here. + // wait; will automatically unlock() the internal mutex via + // the scoped lock + d_readBlock->wait (l); + // and re-lock() it here. if (d_doAbort) { - d_internal->unlock (); DEBUG (std::cerr << "dequeue: #a == 0, aborting." << std::endl); return (2); } @@ -303,17 +300,15 @@ public: *bufLen_I = l_bufLen_I; d_n_avail_read_I -= l_bufLen_I; d_n_avail_write_I += l_bufLen_I; - d_writeBlock->signal (); - d_internal->unlock (); + d_writeBlock->notify_one (); return (1); }; void abort () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); d_doAbort = true; - d_writeBlock->signal (); - d_readBlock->signal (); - d_internal->unlock (); + d_writeBlock->notify_one (); + d_readBlock->notify_one (); }; }; diff --git a/usrp/host/lib/circular_linked_list.h b/usrp/host/lib/circular_linked_list.h index 97fe2c1a89..bbed5e49bc 100644 --- a/usrp/host/lib/circular_linked_list.h +++ b/usrp/host/lib/circular_linked_list.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -23,7 +23,7 @@ #ifndef _CIRCULAR_LINKED_LIST_H_ #define _CIRCULAR_LINKED_LIST_H_ -#include <mld_threads.h> +#include <gruel/thread.h> #include <stdexcept> #define __INLINE__ inline @@ -110,8 +110,8 @@ template <class T> class circular_linked_list { private: s_node_ptr d_current, d_iterate, d_available, d_inUse; size_t d_n_nodes, d_n_used; - mld_mutex_ptr d_internal; - mld_condition_ptr d_ioBlock; + gruel::mutex* d_internal; + gruel::condition_variable* d_ioBlock; public: circular_linked_list (size_t n_nodes) { @@ -150,8 +150,8 @@ public: } } d_available = d_current = l_prev; - d_ioBlock = new mld_condition (); - d_internal = d_ioBlock->mutex (); + d_ioBlock = new gruel::condition_variable (); + d_internal = new gruel::mutex (); }; ~circular_linked_list () { @@ -163,19 +163,21 @@ public: } delete d_ioBlock; d_ioBlock = NULL; + delete d_internal; + d_internal = NULL; d_available = d_inUse = d_iterate = d_current = NULL; d_n_used = d_n_nodes = 0; }; s_node_ptr find_next_available_node () { - d_internal->lock (); + gruel::scoped_lock l (*d_internal); // find an available node s_node_ptr l_node = d_available; DEBUG (std::cerr << "w "); while (! l_node) { DEBUG (std::cerr << "x" << std::endl); // the ioBlock condition will automatically unlock() d_internal - d_ioBlock->wait (); + d_ioBlock->wait (l); // and lock() is here DEBUG (std::cerr << "y" << std::endl); l_node = d_available; @@ -196,13 +198,12 @@ public: l_node->insert_before (d_inUse); d_n_used++; l_node->set_not_available (); - d_internal->unlock (); return (l_node); }; void make_node_available (s_node_ptr l_node) { if (!l_node) return; - d_internal->lock (); + gruel::scoped_lock l (*d_internal); DEBUG (std::cerr << "::m_n_a: #u = " << num_used() << ", node = " << l_node << std::endl); // remove this node from the inUse list @@ -221,11 +222,8 @@ public: DEBUG (std::cerr << "s" << d_n_used); // signal the condition when new data arrives - d_ioBlock->signal (); + d_ioBlock->notify_one (); DEBUG (std::cerr << "t "); - -// unlock the mutex for thread safety - d_internal->unlock (); }; __INLINE__ void iterate_start () { d_iterate = d_current; }; @@ -233,7 +231,7 @@ public: s_node_ptr iterate_next () { #if 0 // lock the mutex for thread safety - d_internal->lock (); + gruel::scoped_lock l (*d_internal); #endif s_node_ptr l_this = NULL; if (d_iterate) { @@ -242,10 +240,6 @@ public: if (d_iterate == d_current) d_iterate = NULL; } -#if 0 -// unlock the mutex for thread safety - d_internal->unlock (); -#endif return (l_this); }; @@ -261,7 +255,7 @@ public: __INLINE__ void num_used_dec (void) { if (d_n_used != 0) --d_n_used; // signal the condition that new data has arrived - d_ioBlock->signal (); + d_ioBlock->notify_one (); }; __INLINE__ bool in_use () { return (d_n_used != 0); }; }; diff --git a/usrp/host/lib/db_bitshark_rx.cc b/usrp/host/lib/db_bitshark_rx.cc index 9b8ada4a22..5368866d88 100644 --- a/usrp/host/lib/db_bitshark_rx.cc +++ b/usrp/host/lib/db_bitshark_rx.cc @@ -150,6 +150,8 @@ db_bitshark_rx::db_bitshark_rx(usrp_basic_sptr _usrp, int which) // the external clk input on the USRP set_clock_scheme(0,64000000); + set_bw(8e6); // Default IF bandwidth to match USRP1 max host bandwidth + bypass_adc_buffers(true); } @@ -259,7 +261,6 @@ db_bitshark_rx::set_gain(float gain) // @returns True/False std::vector<int> args(NUM_BYTES_IN_I2C_CMD,0); - uint8_t final_gain = (uint8_t)gain; bool result = false; uint8_t try_count = 0; diff --git a/usrp/host/lib/db_wbxng.cc b/usrp/host/lib/db_wbxng.cc index b35a9cb35d..bd836dfe33 100644 --- a/usrp/host/lib/db_wbxng.cc +++ b/usrp/host/lib/db_wbxng.cc @@ -80,7 +80,9 @@ wbxng_base::set_freq(double freq) actual_baseband_freq is the RF frequency that corresponds to DC in the IF. */ - freq_t int_freq = freq_t(freq); + // clamp freq + freq_t int_freq = freq_t(std::max(freq_min(), std::min(freq, freq_max()))); + bool ok = d_common->_set_freq(int_freq*2); double freq_result = (double) d_common->_get_freq()/2.0; struct freq_result_t args = {ok, freq_result}; diff --git a/usrp/host/lib/fusb_darwin.cc b/usrp/host/lib/fusb_darwin.cc index 95c4878aa6..d2966c1151 100644 --- a/usrp/host/lib/fusb_darwin.cc +++ b/usrp/host/lib/fusb_darwin.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -24,9 +24,6 @@ #include "config.h" #endif -// tell mld_threads to NOT use omni_threads, -// but rather Darwin's pthreads -#define _USE_OMNI_THREADS_ #define DO_DEBUG 0 #include <usb.h> @@ -85,10 +82,12 @@ fusb_ephandle_darwin::fusb_ephandle_darwin (fusb_devhandle_darwin* dh, l_buf = NULL; } - d_readRunning = new mld_mutex (); - d_runThreadRunning = new mld_mutex (); - d_runBlock = new mld_condition (); - d_readBlock = new mld_condition (); + d_readRunning = new gruel::mutex (); + d_runThreadRunning = new gruel::mutex (); + d_runBlock = new gruel::condition_variable (); + d_readBlock = new gruel::condition_variable (); + d_runBlock_mutex = new gruel::mutex (); + d_readBlock_mutex = new gruel::mutex (); } fusb_ephandle_darwin::~fusb_ephandle_darwin () @@ -116,6 +115,10 @@ fusb_ephandle_darwin::~fusb_ephandle_darwin () d_readRunning = NULL; delete d_runThreadRunning; d_runThreadRunning = NULL; + delete d_runBlock_mutex; + d_runBlock_mutex = NULL; + delete d_readBlock_mutex; + d_readBlock_mutex = NULL; delete d_runBlock; d_runBlock = NULL; delete d_readBlock; @@ -200,14 +203,14 @@ fusb_ephandle_darwin::start () // lock the runBlock mutex, before creating the run thread. // this guarantees that we can control execution between these 2 threads - d_runBlock->mutex ()->lock (); + gruel::scoped_lock l (*d_runBlock_mutex); // create the run thread, which allows OSX to process I/O separately - d_runThread = new mld_thread (run_thread, this); + d_runThread = new gruel::thread (run_thread, this); // wait until the run thread (and possibky read thread) are -really- // going; this will unlock the mutex before waiting for a signal () - d_runBlock->wait (); + d_runBlock->wait (l); if (usb_debug) { std::cerr << "fusb_ephandle_darwin::start: " << (d_input_p ? "read" : "write") @@ -225,12 +228,12 @@ fusb_ephandle_darwin::run_thread (void* arg) // lock the run thread running mutex; if ::stop() is called, it will // first abort() the pipe then wait for the run thread to finish, // via a lock() on this mutex - mld_mutex_ptr l_runThreadRunning = This->d_runThreadRunning; - l_runThreadRunning->lock (); + gruel::mutex* l_runThreadRunning = This->d_runThreadRunning; + gruel::scoped_lock l0 (*l_runThreadRunning); - mld_mutex_ptr l_readRunning = This->d_readRunning; - mld_condition_ptr l_readBlock = This->d_readBlock; - mld_mutex_ptr l_readBlock_mutex = l_readBlock->mutex (); + gruel::mutex* l_readRunning = This->d_readRunning; + gruel::condition_variable* l_readBlock = This->d_readBlock; + gruel::mutex* l_readBlock_mutex = This->d_readBlock_mutex; bool l_input_p = This->d_input_p; @@ -250,41 +253,39 @@ fusb_ephandle_darwin::run_thread (void* arg) // get run loop reference, to allow other threads to stop This->d_CFRunLoopRef = CFRunLoopGetCurrent (); - mld_thread_ptr l_rwThread = NULL; + gruel::thread* l_rwThread = NULL; if (l_input_p) { // lock the readBlock mutex, before creating the read thread. // this guarantees that we can control execution between these 2 threads - l_readBlock_mutex->lock (); + gruel::scoped_lock l1 (*l_readBlock_mutex); // create the read thread, which just issues all of the starting // async read commands, then returns - l_rwThread = new mld_thread (read_thread, arg); + l_rwThread = new gruel::thread (read_thread, arg); // wait until the the read thread is -really- going; this will // unlock the read block mutex before waiting for a signal () - l_readBlock->wait (); + l_readBlock->wait (l1); } - // now signal the run condition to release and finish ::start(). + { + // now signal the run condition to release and finish ::start(). - // lock the runBlock mutex first; this will force waiting until the - // ->wait() command is issued in ::start() - mld_mutex_ptr l_run_block_mutex = This->d_runBlock->mutex (); - l_run_block_mutex->lock (); + // lock the runBlock mutex first; this will force waiting until the + // ->wait() command is issued in ::start() + gruel::mutex* l_run_block_mutex = This->d_runBlock_mutex; + gruel::scoped_lock l2 (*l_run_block_mutex); - // now that the lock is in place, signal the parent thread that - // things are running - This->d_runBlock->signal (); - - // release the run_block mutex, just in case - l_run_block_mutex->unlock (); + // now that the lock is in place, signal the parent thread that + // things are running + This->d_runBlock->notify_one (); + } // run the loop CFRunLoopRun (); if (l_input_p) { // wait for read_thread () to finish, if needed - l_readRunning->lock (); - l_readRunning->unlock (); + gruel::scoped_lock l3 (*l_readRunning); } // remove run loop stuff @@ -295,9 +296,6 @@ fusb_ephandle_darwin::run_thread (void* arg) std::cerr << "fusb_ephandle_darwin::run_thread: finished for " << (l_input_p ? "read" : "write") << "." << std::endl; } - - // release the run thread running mutex - l_runThreadRunning->unlock (); } void @@ -311,23 +309,23 @@ fusb_ephandle_darwin::read_thread (void* arg) // before doing anything else, lock the read running mutex. this // mutex does flow control between this thread and the run_thread - mld_mutex_ptr l_readRunning = This->d_readRunning; - l_readRunning->lock (); + gruel::mutex* l_readRunning = This->d_readRunning; + gruel::scoped_lock l0 (*l_readRunning); // signal the read condition from run_thread() to continue // lock the readBlock mutex first; this will force waiting until the // ->wait() command is issued in ::run_thread() - mld_condition_ptr l_readBlock = This->d_readBlock; - mld_mutex_ptr l_read_block_mutex = l_readBlock->mutex (); - l_read_block_mutex->lock (); + gruel::condition_variable* l_readBlock = This->d_readBlock; + gruel::mutex* l_read_block_mutex = This->d_readBlock_mutex; - // now that the lock is in place, signal the parent thread that - // things are running here - l_readBlock->signal (); + { + gruel::scoped_lock l1 (*l_read_block_mutex); - // release the run_block mutex, just in case - l_read_block_mutex->unlock (); + // now that the lock is in place, signal the parent thread that + // things are running here + l_readBlock->notify_one (); + } // queue up all of the available read requests s_queue_ptr l_queue = This->d_queue; @@ -341,10 +339,6 @@ fusb_ephandle_darwin::read_thread (void* arg) if (usb_debug) { std::cerr << "fusb_ephandle_darwin::read_thread: finished." << std::endl; } - - // release the read running mutex, to let the parent thread knows - // that this thread is finished - l_readRunning->unlock (); } void @@ -569,8 +563,7 @@ fusb_ephandle_darwin::stop () CFRunLoopStop (d_CFRunLoopRef); // wait for the runThread to stop - d_runThreadRunning->lock (); - d_runThreadRunning->unlock (); + gruel::scoped_lock l (*d_runThreadRunning); if (usb_debug) { std::cerr << "fusb_ephandle_darwin::stop: " << (d_input_p ? "read" : "write") diff --git a/usrp/host/lib/fusb_darwin.h b/usrp/host/lib/fusb_darwin.h index 735e5f16d0..4d18177bee 100644 --- a/usrp/host/lib/fusb_darwin.h +++ b/usrp/host/lib/fusb_darwin.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2009 Free Software Foundation, Inc. + * Copyright 2006,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio. * @@ -150,8 +150,8 @@ class fusb_ephandle_darwin : public fusb_ephandle { private: fusb_devhandle_darwin* d_devhandle; - mld_thread_ptr d_runThread; - mld_mutex_ptr d_runThreadRunning; + gruel::thread* d_runThread; + gruel::mutex* d_runThreadRunning; CFRunLoopRef d_CFRunLoopRef; @@ -174,8 +174,11 @@ public: s_queue_ptr d_queue; circular_buffer<char>* d_buffer; size_t d_bufLenBytes; - mld_mutex_ptr d_readRunning; - mld_condition_ptr d_runBlock, d_readBlock; + gruel::mutex* d_readRunning; + gruel::mutex* d_runBlock_mutex; + gruel::mutex* d_readBlock_mutex; + gruel::condition_variable* d_runBlock; + gruel::condition_variable* d_readBlock; // CREATORS diff --git a/usrp/host/lib/mld_threads.h b/usrp/host/lib/mld_threads.h deleted file mode 100644 index 322f557b60..0000000000 --- a/usrp/host/lib/mld_threads.h +++ /dev/null @@ -1,275 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2006 Free Software Foundation, Inc. - * - * This file is part of GNU Radio. - * - * Primary Author: Michael Dickens, NCIP Lab, University of Notre Dame - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _INCLUDED_MLD_THREADS_H_ -#define _INCLUDED_MLD_THREADS_H_ - -/* classes which allow for either pthreads or omni_threads */ - -#define __macos__ -#ifdef _USE_OMNI_THREADS_ -#include <gnuradio/omnithread.h> -#else -#include <pthread.h> -#endif - -#include <stdexcept> - -#define __INLINE__ inline - -#ifndef DO_DEBUG -#define DO_DEBUG 0 -#endif - -#if DO_DEBUG -#define DEBUG(X) do{X} while(0); -#else -#define DEBUG(X) do{} while(0); -#endif - -class mld_condition_t; - -class mld_mutex_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_mutex l_mutex, *l_mutex_ptr; -#else - typedef pthread_mutex_t l_mutex, *l_mutex_ptr; -#endif - - friend class mld_condition_t; - -private: - l_mutex_ptr d_mutex; - -protected: - inline l_mutex_ptr mutex () { return (d_mutex); }; - -public: - __INLINE__ mld_mutex_t () { -#ifdef _USE_OMNI_THREADS_ - d_mutex = new omni_mutex (); -#else - d_mutex = (l_mutex_ptr) new l_mutex; - int l_ret = pthread_mutex_init (d_mutex, NULL); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating mutex.\n", l_ret); - throw std::runtime_error ("mld_mutex_t::mld_mutex_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_mutex_t () { - unlock (); -#ifndef _USE_OMNI_THREADS_ - int l_ret = pthread_mutex_destroy (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::~mld_mutex_t(): " - "Error %d destroying mutex.\n", l_ret); - } -#endif - delete d_mutex; - d_mutex = NULL; - }; - - __INLINE__ void lock () { -#ifdef _USE_OMNI_THREADS_ - d_mutex->lock (); -#else - int l_ret = pthread_mutex_lock (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::lock(): " - "Error %d locking mutex.\n", l_ret); - } -#endif - }; - - __INLINE__ void unlock () { -#ifdef _USE_OMNI_THREADS_ - d_mutex->unlock (); -#else - int l_ret = pthread_mutex_unlock (d_mutex); - if (l_ret != 0) { - fprintf (stderr, "mld_mutex_t::unlock(): " - "Error %d locking mutex.\n", l_ret); - } -#endif - }; - - __INLINE__ bool trylock () { -#ifdef _USE_OMNI_THREADS_ - int l_ret = d_mutex->trylock (); -#else - int l_ret = pthread_mutex_unlock (d_mutex); -#endif - return (l_ret == 0 ? true : false); - }; - - inline void acquire () { lock(); }; - inline void release () { unlock(); }; - inline void wait () { lock(); }; - inline void post () { unlock(); }; -}; - -typedef mld_mutex_t mld_mutex, *mld_mutex_ptr; - -class mld_condition_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_condition l_condition, *l_condition_ptr; -#else - typedef pthread_cond_t l_condition, *l_condition_ptr; -#endif - -private: - l_condition_ptr d_condition; - mld_mutex_ptr d_mutex; - bool d_i_own_mutex; - -public: - __INLINE__ mld_condition_t (mld_mutex_ptr mutex = NULL) { - if (mutex) { - d_i_own_mutex = false; - d_mutex = mutex; - } else { - d_i_own_mutex = true; - d_mutex = new mld_mutex (); - } -#ifdef _USE_OMNI_THREADS_ - d_condition = new omni_condition (d_mutex->mutex ()); -#else - d_condition = (l_condition_ptr) new l_condition; - int l_ret = pthread_cond_init (d_condition, NULL); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating condition.\n", l_ret); - throw std::runtime_error ("mld_condition_t::mld_condition_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_condition_t () { - signal (); -#ifndef _USE_OMNI_THREADS_ - int l_ret = pthread_cond_destroy (d_condition); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::mld_condition_t(): " - "Error %d destroying condition.\n", l_ret); - } -#endif - delete d_condition; - d_condition = NULL; - if (d_i_own_mutex) - delete d_mutex; - d_mutex = NULL; - }; - - __INLINE__ mld_mutex_ptr mutex () {return (d_mutex);}; - - __INLINE__ void signal () { - DEBUG (fprintf (stderr, "a ");); - -#ifdef _USE_OMNI_THREADS_ - d_condition->signal (); -#else - int l_ret = pthread_cond_signal (d_condition); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::signal(): " - "Error %d.\n", l_ret); - } -#endif - DEBUG (fprintf (stderr, "b ");); - }; - - __INLINE__ void wait () { - DEBUG (fprintf (stderr, "c ");); -#ifdef _USE_OMNI_THREADS_ - d_condition->wait (); -#else - int l_ret = pthread_cond_wait (d_condition, d_mutex->mutex ()); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::wait(): " - "Error %d.\n", l_ret); - } -#endif - DEBUG (fprintf (stderr, "d ");); - }; -}; - -typedef mld_condition_t mld_condition, *mld_condition_ptr; - -class mld_thread_t { -#ifdef _USE_OMNI_THREADS_ - typedef omni_thread l_thread, *l_thread_ptr; -#else - typedef pthread_t l_thread, *l_thread_ptr; -#endif - -private: -#ifndef _USE_OMNI_THREADS_ - l_thread d_thread; - void (*d_start_routine)(void*); - void *d_arg; -#else - l_thread_ptr d_thread; -#endif - -#ifndef _USE_OMNI_THREADS_ - static void* local_start_routine (void *arg) { - mld_thread_t* This = (mld_thread_t*) arg; - (*(This->d_start_routine))(This->d_arg); - return (NULL); - }; -#endif - -public: - __INLINE__ mld_thread_t (void (*start_routine)(void *), void *arg) { -#ifdef _USE_OMNI_THREADS_ - d_thread = new omni_thread (start_routine, arg); - d_thread->start (); -#else - d_start_routine = start_routine; - d_arg = arg; - int l_ret = pthread_create (&d_thread, NULL, local_start_routine, this); - if (l_ret != 0) { - fprintf (stderr, "Error %d creating thread.\n", l_ret); - throw std::runtime_error ("mld_thread_t::mld_thread_t()\n"); - } -#endif - }; - - __INLINE__ ~mld_thread_t () { -#ifdef _USE_OMNI_THREADS_ -// delete d_thread; - d_thread = NULL; -#else - int l_ret = pthread_detach (d_thread); - if (l_ret != 0) { - fprintf (stderr, "Error %d detaching thread.\n", l_ret); - throw std::runtime_error ("mld_thread_t::~mld_thread_t()\n"); - } -#endif - }; -}; - -typedef mld_thread_t mld_thread, *mld_thread_ptr; - -#endif /* _INCLUDED_MLD_THREADS_H_ */ diff --git a/usrp/limbo/apps-inband/.gitignore b/usrp/limbo/apps-inband/.gitignore deleted file mode 100644 index f62d9e1de2..0000000000 --- a/usrp/limbo/apps-inband/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/*.dat -/.*.swp -/usrper -/usrper2 -/test_input -/test_fusb -/test_usrp -/test_usrp0 -/test_usrp_standard_rx -/test_usrp_standard_tx -/test_usrp_standard_2tx -/test_usrp_inband_timestamps -/test_usrp_inband_registers -/test_usrp_inband_rx -/test_usrp_inband_2rx -/test_usrp_inband_tx -/test_usrp_inband_2tx -/test_usrp_basic_rx -/check_order_quickly -/usrp_cal_dc_offset -/test_usrp_inband_cs -/read_packets -/test_usrp_inband_ping -/test_usrp_inband_underrun -/test_usrp_inband_overrun -/gmac_mbh.cc -/test_gmac_tx diff --git a/usrp/limbo/apps-inband/Makefile.am b/usrp/limbo/apps-inband/Makefile.am deleted file mode 100644 index 0a44d81124..0000000000 --- a/usrp/limbo/apps-inband/Makefile.am +++ /dev/null @@ -1,77 +0,0 @@ -# -# Copyright 2003,2006,2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -include $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = \ - $(DEFINES) $(OMNITHREAD_INCLUDES) $(PMT_INCLUDES) $(MBLOCK_INCLUDES) \ - $(USRP_INCLUDES) $(USRP_INBAND_INCLUDES) $(BOOST_CPPFLAGS) \ - $(CPPUNIT_INCLUDES) $(WITH_INCLUDES) -I$(top_srcdir)/mblock/src/lib - - -bin_PROGRAMS = - -noinst_PROGRAMS = \ - test_usrp_inband_ping \ - test_usrp_inband_registers \ - test_usrp_inband_rx \ - test_usrp_inband_2rx \ - test_usrp_inband_tx \ - test_usrp_inband_2tx \ - test_usrp_inband_timestamps \ - test_usrp_inband_overrun \ - test_usrp_inband_underrun \ - read_packets - -noinst_HEADERS = \ - ui_nco.h \ - ui_sincos.h - - -test_usrp_inband_ping_SOURCES = test_usrp_inband_ping.cc -test_usrp_inband_ping_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_tx_SOURCES = test_usrp_inband_tx.cc ui_sincos.c -test_usrp_inband_tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_2tx_SOURCES = test_usrp_inband_2tx.cc ui_sincos.c -test_usrp_inband_2tx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_timestamps_SOURCES = test_usrp_inband_timestamps.cc ui_sincos.c -test_usrp_inband_timestamps_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_registers_SOURCES = test_usrp_inband_registers.cc ui_sincos.c -test_usrp_inband_registers_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_overrun_SOURCES = test_usrp_inband_overrun.cc -test_usrp_inband_overrun_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_underrun_SOURCES = test_usrp_inband_underrun.cc -test_usrp_inband_underrun_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_rx_SOURCES = test_usrp_inband_rx.cc ui_sincos.c -test_usrp_inband_rx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -test_usrp_inband_2rx_SOURCES = test_usrp_inband_2rx.cc ui_sincos.c -test_usrp_inband_2rx_LDADD = $(USRP_LA) $(USRP_INBAND_LA) - -read_packets_SOURCES = read_packets.cc -read_packets_LDADD = $(USRP_LA) $(USRP_INBAND_LA) diff --git a/usrp/limbo/apps-inband/read_packets.cc b/usrp/limbo/apps-inband/read_packets.cc deleted file mode 100644 index 24a1e88b5c..0000000000 --- a/usrp/limbo/apps-inband/read_packets.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <iostream> -#include <usrp_inband_usb_packet.h> -#include <mblock/class_registry.h> -#include <vector> -#include <usrp_usb_interface.h> -#include <fstream> - -typedef usrp_inband_usb_packet transport_pkt; // makes conversion to gigabit easy - -int main(int argc, char *argv[]) { - - if(argc !=2) { - std::cout << "Usage: ./read_packets <data_file>\n"; - return -1; - } - - std::ifstream infile; - std::ofstream outfile; - - unsigned int pkt_size = transport_pkt::max_pkt_size(); - unsigned int pkt_num=0; - - transport_pkt *pkt; - char pkt_data[pkt_size]; // allocate the number of bytes for a single packet - - pkt = (transport_pkt *)pkt_data; // makes operations cleaner to read - - // Open the file and read the packets, dumping information - infile.open(argv[1], std::ios::binary|std::ios::in); - if(!infile.is_open()) - exit(-1); - - //outfile.open("dump.dat",std::ios::out|std::ios::binary); - - // read 1 packet in to the memory - infile.read(pkt_data, pkt_size); - - while(!infile.eof()) { - - printf("Packet %u\n", pkt_num); - - if(pkt->start_of_burst()) - printf("\tstart of burst\n"); - - if(pkt->end_of_burst()) - printf("\tend of burst\n"); - -// if(pkt->carrier_sense()) -// printf("\tcarrier sense\n"); - - if(pkt->underrun()) - printf("\tunderrun\n"); - - if(pkt->overrun()) - printf("\toverrun\n"); - - printf("\tchannel: \t0x%x\n", pkt->chan()); - printf("\ttimestamp: \t0x%x\n", pkt->timestamp()); - //printf("\ttimestamp: \t%u\n", pkt->timestamp()); - printf("\tlength: \t%u\n", pkt->payload_len()); - printf("\trssi: \t%u\n", pkt->rssi()); - - printf("\tpayload: \n"); - for(int i=0; i < pkt->payload_len(); i++) - //for(int i=0; i < pkt->max_payload(); i++) - { - printf("\t%d\t0x%x\n", i, *(pkt->payload()+i)); - //outfile.write((const char*)(pkt->payload()+i),1); - //printf("\t\t0x%x\n", pkt->payload()+i); - - } - printf("\n\n"); - - pkt_num++; - - // read 1 packet in to the memory - infile.read(pkt_data, pkt_size); - - } - - infile.close(); - //outfile.close(); - -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_2rx.cc b/usrp/limbo/apps-inband/test_usrp_inband_2rx.cc deleted file mode 100644 index c210f196a9..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_2rx.cc +++ /dev/null @@ -1,371 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> -#include <fstream> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_rx.h> - -static bool verbose = true; - -class test_usrp_rx : public mb_mblock -{ - mb_port_sptr d_rx; - mb_port_sptr d_cs; - pmt_t d_rx_chan0, d_rx_chan1; - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - RECEIVING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - - std::ofstream d_ofile; - - long d_samples_recvd; - long d_samples_to_recv; - - public: - test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_rx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_receiving(); - void build_and_send_next_frame(); - void handle_response_recv_raw_samples(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_rx_chan0(PMT_NIL), d_rx_chan1(PMT_NIL), - d_samples_recvd(0), - d_samples_to_recv(20e6) -{ - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP - pmt_t usrp_dict = pmt_make_dict(); - - // To test the application without a USRP - bool fake_usrp_p = false; - if(fake_usrp_p) { - pmt_dict_set(usrp_dict, - pmt_intern("fake-usrp"), - PMT_T); - } - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_2rxhb_2tx.rbf")); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(64)); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -test_usrp_rx::~test_usrp_rx() -{ -} - -void -test_usrp_rx::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_rx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - switch(d_state){ - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - //----------------------- ALLOCATING CHANNELS --------------------// - // Allocate an RX channel to perform the overrun test. - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - status = pmt_nth(1, data); - if(pmt_eqv(d_rx_chan0, PMT_NIL)) - d_rx_chan0 = pmt_nth(2, data); - else - d_rx_chan1 = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T) && !pmt_eqv(d_rx_chan1, PMT_NIL)){ - enter_receiving(); - return; - } - else if(pmt_eq(status, PMT_F)){ - error_msg = "failed to allocate channel:"; - goto bail; - } - return; - } - goto unhandled; - - //--------------------------- RECEIVING ------------------------------// - // In the receiving state, we receive samples until the specified amount - // while counting the number of overruns. - case RECEIVING: - if (pmt_eq(event, s_response_recv_raw_samples)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_response_recv_raw_samples(data); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - goto unhandled; - - //------------------------- CLOSING CHANNEL ----------------------------// - // Check deallocation response for the RX channel - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - - // Alternately, we ignore all response recv samples while waiting for the - // channel to actually close - if (pmt_eq(event, s_response_recv_raw_samples)) - return; - - goto unhandled; - - //--------------------------- CLOSING USRP ------------------------------// - // Once we have received a successful USRP close response, we shutdown all - // mblocks and exit. - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - fflush(stdout); - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_rx::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Opening the USRP\n"; -} - -void -test_usrp_rx::close_usrp() -{ - - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Closing the USRP\n"; -} - -void -test_usrp_rx::allocate_channel() -{ - long capacity = (long) 16e6; - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Requesting RX channel allocation\n"; -} - -void -test_usrp_rx::enter_receiving() -{ - d_state = RECEIVING; - - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan0)); - - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan1)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Receiving...\n"; -} - -void -test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t v_samples = pmt_nth(2, data); - pmt_t timestamp = pmt_nth(3, data); - pmt_t channel = pmt_nth(4, data); - pmt_t properties = pmt_nth(5, data); - - d_samples_recvd += pmt_length(v_samples) / 4; - - // Check for overrun - if(!pmt_is_dict(properties)) { - std::cout << "[TEST_USRP_INBAND_RX] Recv samples dictionary is improper\n"; - return; - } - - // Check if the number samples we have received meets the test - if(d_samples_recvd >= d_samples_to_recv) { - d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan0)); - d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan1)); - enter_closing_channel(); - return; - } - -} - -void -test_usrp_rx::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan0)); - d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan1)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Deallocating RX channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_rx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_rx", PMT_F, &result); - -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_2tx.cc b/usrp/limbo/apps-inband/test_usrp_inband_2tx.cc deleted file mode 100644 index 11a1a491c8..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_2tx.cc +++ /dev/null @@ -1,430 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mb_runtime_nop.h> // QA only -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> - -#include <ui_nco.h> -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> - -static bool verbose = true; - -class test_usrp_tx : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_cs; - pmt_t d_tx_chan0, d_tx_chan1; - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - TRANSMITTING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - long d_nsamples_to_send; - long d_nsamples_xmitted; - long d_nframes_xmitted; - long d_samples_per_frame; - bool d_done_sending; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - public: - test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_tx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_transmitting(); - void build_and_send_next_frame(); - void handle_xmit_response(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan0(PMT_NIL), d_tx_chan1(PMT_NIL), - d_state(INIT), d_nsamples_to_send((long) 80e6), - d_nsamples_xmitted(0), - d_nframes_xmitted(0), - d_samples_per_frame((long)(126 * 4)), // full packet - d_done_sending(false), - d_amplitude(16384) -{ - // std::cout << "[TEST_USRP_TX] Initializing...\n"; - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - //bool fake_usrp_p = true; - bool fake_usrp_p = false; - - // Test the TX side - - pmt_t usrp_dict = pmt_make_dict(); - - if(fake_usrp_p) { - pmt_dict_set(usrp_dict, - pmt_intern("fake-usrp"), - PMT_T); - } - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_2rxhb_2tx.rbf")); - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(128)); - -// pmt_dict_set(usrp_dict, -// pmt_intern("rf-freq"), -// pmt_from_long(10e6)); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "tx0", "server", "tx0"); - connect("self", "cs", "server", "cs"); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 128e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); - - // FIXME need to somehow set the interp rate in the USRP. - // for now, we'll have the low-level code hardwire it. -} - -test_usrp_tx::~test_usrp_tx() -{ -} - -void -test_usrp_tx::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_tx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - //std::cout << msg << std::endl; - - switch(d_state){ - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - status = pmt_nth(1, data); - if(pmt_eqv(d_tx_chan0, PMT_NIL)) - d_tx_chan0 = pmt_nth(2, data); - else - d_tx_chan1 = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T) && !pmt_eqv(d_tx_chan1, PMT_NIL)){ - enter_transmitting(); - return; - } - else if(pmt_eq(status, PMT_F)){ - error_msg = "failed to allocate channel:"; - goto bail; - } - return; - } - goto unhandled; - - case TRANSMITTING: - if (pmt_eq(event, s_response_xmit_raw_frame)){ - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - goto unhandled; - - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - goto unhandled; - - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - unhandled: - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_tx::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Opening the USRP\n"; -} - -void -test_usrp_tx::close_usrp() -{ - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Closing the USRP\n"; -} - -void -test_usrp_tx::allocate_channel() -{ - long capacity = (long) 16e6; - - // Send two capacity requests, which will allocate us two channels - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Requesting TX channel allocation\n"; -} - -void -test_usrp_tx::enter_transmitting() -{ - d_state = TRANSMITTING; - d_nsamples_xmitted = 0; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Transmitting...\n"; - - build_and_send_next_frame(); // fire off 4 to start pipeline - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); -} - -void -test_usrp_tx::build_and_send_next_frame() -{ - // allocate the uniform vector for the samples - // FIXME perhaps hold on to this between calls - -#if 1 - long nsamples_this_frame = - std::min(d_nsamples_to_send - d_nsamples_xmitted, - d_samples_per_frame); -#else - long nsamples_this_frame = d_samples_per_frame; -#endif - - if (nsamples_this_frame == 0){ - d_done_sending = true; - return; - } - - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writable_elements(uvec, ignore); - - // fill in the complex sinusoid - - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - pmt_t tx_properties = pmt_make_dict(); - - pmt_t timestamp = pmt_from_long(0xffffffff); // NOW - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list5(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan0, // channel - uvec, // the samples - timestamp, - tx_properties)); - - // Resend on channel 1 - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list5(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan1, // channel - uvec, // the samples - timestamp, - tx_properties)); - - d_nsamples_xmitted += nsamples_this_frame; - d_nframes_xmitted++; - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n"; -} - - -void -test_usrp_tx::handle_xmit_response(pmt_t handle) -{ - if (d_done_sending && - pmt_to_long(handle) == (d_nframes_xmitted - 1)){ - // We're done sending and have received all responses - enter_closing_channel(); - } - - build_and_send_next_frame(); -} - -void -test_usrp_tx::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - // Deallocate both channels - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan0)); - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan1)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_tX] Deallocating TX channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_tx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_tx", PMT_F, &result); -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_overrun.cc b/usrp/limbo/apps-inband/test_usrp_inband_overrun.cc deleted file mode 100644 index cd0fa525a3..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_overrun.cc +++ /dev/null @@ -1,375 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> -#include <fstream> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_rx.h> - -static bool verbose = true; - -class test_usrp_rx : public mb_mblock -{ - mb_port_sptr d_rx; - mb_port_sptr d_cs; - pmt_t d_rx_chan; // returned tx channel handle - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - RECEIVING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - - std::ofstream d_ofile; - - long d_n_overruns; - - long d_samples_recvd; - long d_samples_to_recv; - - public: - test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_rx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_receiving(); - void build_and_send_next_frame(); - void handle_response_recv_raw_samples(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_n_overruns(0), - d_samples_recvd(0), - d_samples_to_recv(10e6) -{ - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP - pmt_t usrp_dict = pmt_make_dict(); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(128)); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -test_usrp_rx::~test_usrp_rx() -{ -} - -void -test_usrp_rx::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_rx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - switch(d_state){ - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - //----------------------- ALLOCATING CHANNELS --------------------// - // Allocate an RX channel to perform the overrun test. - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - status = pmt_nth(1, data); - d_rx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - enter_receiving(); - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } - } - goto unhandled; - - //--------------------------- RECEIVING ------------------------------// - // In the receiving state, we receive samples until the specified amount - // while counting the number of overruns. - case RECEIVING: - if (pmt_eq(event, s_response_recv_raw_samples)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_response_recv_raw_samples(data); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - goto unhandled; - - //------------------------- CLOSING CHANNEL ----------------------------// - // Check deallocation response for the RX channel - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - - // Alternately, we ignore all response recv samples while waiting for the - // channel to actually close - if (pmt_eq(event, s_response_recv_raw_samples)) - return; - - goto unhandled; - - //--------------------------- CLOSING USRP ------------------------------// - // Once we have received a successful USRP close response, we shutdown all - // mblocks and exit. - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - std::cout << "\nOverruns: " << d_n_overruns << std::endl; - fflush(stdout); - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_rx::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Opening the USRP\n"; -} - -void -test_usrp_rx::close_usrp() -{ - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Closing the USRP\n"; -} - -void -test_usrp_rx::allocate_channel() -{ - long capacity = (long) 16e6; - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Requesting RX channel allocation\n"; -} - -void -test_usrp_rx::enter_receiving() -{ - d_state = RECEIVING; - - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Receiving...\n"; -} - -void -test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t v_samples = pmt_nth(2, data); - pmt_t timestamp = pmt_nth(3, data); - pmt_t channel = pmt_nth(4, data); - pmt_t properties = pmt_nth(5, data); - - d_samples_recvd += pmt_length(v_samples) / 4; - - // Check for overrun - if(!pmt_is_dict(properties)) { - std::cout << "[TEST_USRP_INBAND_OVERRUN] Recv samples dictionary is improper\n"; - return; - } - - if(pmt_t overrun = pmt_dict_ref(properties, - pmt_intern("overrun"), - PMT_NIL)) { - if(pmt_eqv(overrun, PMT_T)) { - d_n_overruns++; - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Underrun\n"; - } - else { - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_OVERRUN] No overrun\n" << overrun <<std::endl; - } - } else { - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_OVERRUN] No overrun\n"; - } - - // Check if the number samples we have received meets the test - if(d_samples_recvd >= d_samples_to_recv) { - d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan)); - enter_closing_channel(); - return; - } - -} - -void -test_usrp_rx::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - sleep(2); - - d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_OVERRUN] Deallocating RX channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_rx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_rx", PMT_F, &result); -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_ping.cc b/usrp/limbo/apps-inband/test_usrp_inband_ping.cc deleted file mode 100644 index d779c9a644..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_ping.cc +++ /dev/null @@ -1,374 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <iostream> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> - -static bool verbose = false; - -class test_usrp_inband_ping : public mb_mblock -{ - - mb_port_sptr d_tx; // Ports connected to the USRP server - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - pmt_t d_tx_chan; // Returned channel from TX allocation - pmt_t d_rx_chan; // Returned channel from RX allocation - - pmt_t d_which_usrp; // The USRP to use for the test - - long d_warm_msgs; // The number of messages to 'warm' the USRP - long d_warm_recvd; // The number of msgs received in the 'warm' state - - // Keep track of current state - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNELS, - WARMING_USRP, - PINGING, - CLOSING_CHANNELS, - CLOSING_USRP, - }; - state_t d_state; - - public: - test_usrp_inband_ping(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_inband_ping(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void opening_usrp(); - void allocating_channels(); - void enter_warming_usrp(); - void enter_pinging(); - void build_and_send_ping(); - void closing_channels(); - void closing_usrp(); -}; - - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_inband_ping", PMT_F, &result); -} - - -test_usrp_inband_ping::test_usrp_inband_ping(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan(PMT_NIL), - d_rx_chan(PMT_NIL), - d_which_usrp(pmt_from_long(0)), - d_state(INIT) -{ - - // A dictionary is used to pass parameters to the USRP - pmt_t usrp_dict = pmt_make_dict(); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("fixed1.rbf")); - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(128)); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Create an instance of USRP server and connect ports - define_component("server", "usrp_server", usrp_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -test_usrp_inband_ping::~test_usrp_inband_ping() -{ -} - -void -test_usrp_inband_ping::initial_transition() -{ - opening_usrp(); -} - -// Handle message reads all incoming messages from USRP server which will be -// initialization and ping responses. We perform actions based on the current -// state and the event (ie, ping response) -void -test_usrp_inband_ping::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - // Dispatch based on state - switch(d_state) { - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - - if(pmt_eq(event, s_response_open)) { - - status = pmt_nth(1, data); // failed/succes - - if(pmt_eq(status, PMT_T)) { - allocating_channels(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - - } - - goto unhandled; // all other messages not handled in this state - - - //----------------------- ALLOCATING CHANNELS --------------------// - // When allocating channels, we need to wait for 2 responses from - // USRP server: one for TX and one for RX. Both are initialized to - // NIL so we know to continue to the next state once both are set. - case ALLOCATING_CHANNELS: - - // A TX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_tx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Received TX allocation" - << " on channel " << d_tx_chan << std::endl; - - // If the RX has also been allocated already, we can continue - if(!pmt_eqv(d_rx_chan, PMT_NIL)) - enter_warming_usrp(); - - return; - } - else { // TX allocation failed - error_msg = "failed to allocate TX channel:"; - goto bail; - } - } - - // A RX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_rx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Received RX allocation" - << " on channel " << d_rx_chan << std::endl; - - // If the TX has also been allocated already, we can continue - if(!pmt_eqv(d_tx_chan, PMT_NIL)) - enter_warming_usrp(); - - return; - } - else { // RX allocation failed - error_msg = "failed to allocate RX channel:"; - goto bail; - } - } - - goto unhandled; - - //----------------------- WARMING USRP --------------------// - // The FX2 seems to need some amount of data to be buffered - // before it begins reading. We use this state to simply - // warm up the USRP before benchmarking pings. - case WARMING_USRP: - - // We really don't care about the responses from the - // control channel in the warming stage, but once we receive - // the proper number of responses we switch states. - if(pmt_eq(event, s_response_from_control_channel) - && pmt_eq(d_rx->port_symbol(), port_id)) - { - d_warm_recvd++; - - if(d_warm_recvd > d_warm_msgs) - enter_pinging(); - - return; - } - - goto unhandled; - - case PINGING: - goto unhandled; - - case CLOSING_CHANNELS: - goto unhandled; - - case CLOSING_USRP: - goto unhandled; - - case INIT: - goto unhandled; - - } - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; - -} - - -// Sends a command to USRP server to open up a connection to the -// specified USRP, which is defaulted to USRP 0 on the system -void -test_usrp_inband_ping::opening_usrp() -{ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Opening USRP " - << d_which_usrp << std::endl; - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, d_which_usrp)); - d_state = OPENING_USRP; -} - -// RX and TX channels must be allocated so that the USRP server can -// properly share bandwidth across multiple USRPs. No commands will be -// successful to the USRP through the USRP server on the TX or RX channels until -// a bandwidth allocation has been received. -void -test_usrp_inband_ping::allocating_channels() -{ - d_state = ALLOCATING_CHANNELS; - - long capacity = (long) 16e6; - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); -} - -// The USRP needs some amount of initial data to pass a buffering point such -// that it begins to pull and read data from the FX2. We send an arbitrary -// amount of data to start the pipeline, which are just pings. -void -test_usrp_inband_ping::enter_warming_usrp() -{ - d_state = WARMING_USRP; - - for(int i=0; i < d_warm_msgs; i++) - build_and_send_ping(); -} - -void -test_usrp_inband_ping::enter_pinging() -{ - d_state = PINGING; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Running ping tests\n"; - -} - -// Pings are sent over the TX channel using the signal 'cmd-to-control-channel' -// to the USRP server. Within this message there can be infinite subpackets -// stored as a list (the second parameter) and sent. The only subpacket we send -// is a ping, interpreted by the 'op-ping-fixed' signal. -void -test_usrp_inband_ping::build_and_send_ping() -{ - - d_tx->send(s_cmd_to_control_channel, // USRP server signal - pmt_list2(PMT_NIL, // invocation handle - pmt_list1(pmt_list3(s_op_ping_fixed, - pmt_from_long(0), - pmt_from_long(0))))); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Ping!!" << std::endl; -} - -REGISTER_MBLOCK_CLASS(test_usrp_inband_ping); diff --git a/usrp/limbo/apps-inband/test_usrp_inband_registers.cc b/usrp/limbo/apps-inband/test_usrp_inband_registers.cc deleted file mode 100644 index d9bd2db171..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_registers.cc +++ /dev/null @@ -1,435 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -//#include <mb_mblock_impl.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <iostream> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> - -static bool verbose = true; - -class test_usrp_inband_registers : public mb_mblock -{ - - mb_port_sptr d_tx; // Ports connected to the USRP server - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - pmt_t d_tx_chan; // Returned channel from TX allocation - pmt_t d_rx_chan; // Returned channel from RX allocation - - pmt_t d_which_usrp; // The USRP to use for the test - - long d_warm_msgs; // The number of messages to 'warm' the USRP - long d_warm_recvd; // The number of msgs received in the 'warm' state - - // Keep track of current state - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNELS, - WRITE_REGISTER, - READ_REGISTER, - CLOSING_CHANNELS, - CLOSING_USRP, - }; - state_t d_state; - - public: - test_usrp_inband_registers(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_inband_registers(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void opening_usrp(); - void allocating_channels(); - void write_register(); - void read_register(); - void closing_channels(); - void closing_usrp(); - void enter_receiving(); - void build_and_send_ping(); -}; - - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_inband_registers", PMT_F, &result); -} - - -test_usrp_inband_registers::test_usrp_inband_registers(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan(PMT_NIL), - d_rx_chan(PMT_NIL), - d_which_usrp(pmt_from_long(0)), - d_state(INIT) -{ - - // A dictionary is used to pass parameters to the USRP - pmt_t usrp_dict = pmt_make_dict(); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(128)); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Create an instance of USRP server and connect ports - define_component("server", "usrp_server", usrp_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -test_usrp_inband_registers::~test_usrp_inband_registers() -{ -} - -void -test_usrp_inband_registers::initial_transition() -{ - opening_usrp(); -} - -// Handle message reads all incoming messages from USRP server which will be -// initialization and ping responses. We perform actions based on the current -// state and the event (ie, ping response) -void -test_usrp_inband_registers::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - // Dispatch based on state - switch(d_state) { - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - - if(pmt_eq(event, s_response_open)) { - - status = pmt_nth(1, data); // failed/succes - - if(pmt_eq(status, PMT_T)) { - allocating_channels(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - - } - - goto unhandled; // all other messages not handled in this state - - - //----------------------- ALLOCATING CHANNELS --------------------// - // When allocating channels, we need to wait for 2 responses from - // USRP server: one for TX and one for RX. Both are initialized to - // NIL so we know to continue to the next state once both are set. - case ALLOCATING_CHANNELS: - - // A TX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_tx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Received TX allocation" - << " on channel " << d_tx_chan << std::endl; - - // If the RX has also been allocated already, we can continue - if(!pmt_eqv(d_rx_chan, PMT_NIL)) { - enter_receiving(); - write_register(); - } - - return; - } - else { // TX allocation failed - error_msg = "failed to allocate TX channel:"; - goto bail; - } - } - - // A RX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_rx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Received RX allocation" - << " on channel " << d_rx_chan << std::endl; - - // If the TX has also been allocated already, we can continue - if(!pmt_eqv(d_tx_chan, PMT_NIL)) { - enter_receiving(); - write_register(); - } - - return; - } - else { // RX allocation failed - error_msg = "failed to allocate RX channel:"; - goto bail; - } - } - - goto unhandled; - - //-------------------------- WRITE REGISTER ----------------------------// - // In the write register state, we do not expect to receive any messages - // since the write does not directly generate a response until the USRP - // responds. - case WRITE_REGISTER: - goto unhandled; - - //-------------------------- READ REGISTER ----------------------------// - // In the read register state, we only expect a read register response back - // that has the value we expect to have in it. We read the response, ensure - // that the read was successful and display the register value. - case READ_REGISTER: - - if(pmt_eq(event, s_response_from_control_channel) - && pmt_eq(d_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If the read was successful, we extract the subpacket information - if(pmt_eq(status, PMT_T)) { - - pmt_t subp = pmt_nth(2, data); // subpacket should be the read reg reply - - pmt_t subp_sig = pmt_nth(0, subp); - pmt_t subp_data = pmt_nth(1, subp); - - if(!pmt_eqv(subp_sig, s_op_read_reg_reply)) { - error_msg = "received improper subpacket when expecting reg reply."; - goto bail; - } - - pmt_t rid = pmt_nth(0, subp_data); - pmt_t reg_num = pmt_nth(1, subp_data); - pmt_t reg_val = pmt_nth(2, subp_data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_REGISTERS] Received read reg reply " - << "(" - << "RID: " << rid << ", " - << "Reg: " << reg_num << ", " - << "Val: " << reg_val - << ")\n"; - - // read_register(); FIX ME STATE TRANSITION - return; - - } else { // bail on unsuccessful write - error_msg = "failed to write to register."; - goto bail; - } - } - goto unhandled; - - case CLOSING_CHANNELS: - goto unhandled; - - case CLOSING_USRP: - goto unhandled; - - case INIT: - goto unhandled; - - } - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, s_response_recv_raw_samples)) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; - -} - - -// Sends a command to USRP server to open up a connection to the -// specified USRP, which is defaulted to USRP 0 on the system -void -test_usrp_inband_registers::opening_usrp() -{ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_PING] Opening USRP " - << d_which_usrp << std::endl; - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, d_which_usrp)); - d_state = OPENING_USRP; -} - -// RX and TX channels must be allocated so that the USRP server can -// properly share bandwidth across multiple USRPs. No commands will be -// successful to the USRP through the USRP server on the TX or RX channels until -// a bandwidth allocation has been received. -void -test_usrp_inband_registers::allocating_channels() -{ - d_state = ALLOCATING_CHANNELS; - - long capacity = (long) 16e6; - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); -} - -// After allocating the channels, a write register command will be sent to the -// USRP. -void -test_usrp_inband_registers::write_register() -{ - d_state = WRITE_REGISTER; - - long reg = 0; - - d_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(PMT_NIL, // invoc handle - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(reg), - pmt_from_long(0xbeef)))))); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_REGISTERS] Writing 0xbeef to " - << reg << std::endl; - - read_register(); // immediately transition to read the register -} - -// Temporary: for testing pings -void -test_usrp_inband_registers::build_and_send_ping() -{ - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(PMT_NIL, pmt_list1(pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(0), - pmt_from_long(0)))))); - - std::cout << "[TEST_USRP_INBAND_CS] Ping sent" << std::endl; -} - -// After writing to the register, we want to read the value back and ensure that -// it is the same value that we wrote. -void -test_usrp_inband_registers::read_register() -{ - d_state = READ_REGISTER; - - long reg = 9; - - d_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(PMT_NIL, // invoc handle - pmt_list1( - pmt_list2(s_op_read_reg, - pmt_list2( - pmt_from_long(0), // rid - pmt_from_long(reg)))))); - if(verbose) - std::cout << "[TEST_USRP_INBAND_REGISTERS] Reading from register " - << reg << std::endl; -} - -// Used to enter the receiving state -void -test_usrp_inband_registers::enter_receiving() -{ - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); -} - -REGISTER_MBLOCK_CLASS(test_usrp_inband_registers); diff --git a/usrp/limbo/apps-inband/test_usrp_inband_rx.cc b/usrp/limbo/apps-inband/test_usrp_inband_rx.cc deleted file mode 100644 index 4f21e4afc7..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_rx.cc +++ /dev/null @@ -1,362 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> -#include <fstream> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_rx.h> - -static bool verbose = true; - -class test_usrp_rx : public mb_mblock -{ - mb_port_sptr d_rx; - mb_port_sptr d_cs; - pmt_t d_rx_chan; // returned tx channel handle - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - RECEIVING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - - std::ofstream d_ofile; - - long d_samples_recvd; - long d_samples_to_recv; - - public: - test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_rx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_receiving(); - void build_and_send_next_frame(); - void handle_response_recv_raw_samples(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_samples_recvd(0), - d_samples_to_recv(20e6) -{ - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Pass a dictionary to usrp_server which specifies which interface to use, the stub or USRP - pmt_t usrp_dict = pmt_make_dict(); - - // To test the application without a USRP - bool fake_usrp_p = false; - if(fake_usrp_p) { - pmt_dict_set(usrp_dict, - pmt_intern("fake-usrp"), - PMT_T); - } - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(64)); - -// If unspecified, chooses center frequency from range -// pmt_dict_set(usrp_dict, -// pmt_intern("rf-freq"), -// pmt_from_long(10e6)); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -test_usrp_rx::~test_usrp_rx() -{ -} - -void -test_usrp_rx::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_rx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - switch(d_state){ - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - //----------------------- ALLOCATING CHANNELS --------------------// - // Allocate an RX channel to perform the overrun test. - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - status = pmt_nth(1, data); - d_rx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - enter_receiving(); - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } - } - goto unhandled; - - //--------------------------- RECEIVING ------------------------------// - // In the receiving state, we receive samples until the specified amount - // while counting the number of overruns. - case RECEIVING: - if (pmt_eq(event, s_response_recv_raw_samples)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_response_recv_raw_samples(data); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - goto unhandled; - - //------------------------- CLOSING CHANNEL ----------------------------// - // Check deallocation response for the RX channel - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - - // Alternately, we ignore all response recv samples while waiting for the - // channel to actually close - if (pmt_eq(event, s_response_recv_raw_samples)) - return; - - goto unhandled; - - //--------------------------- CLOSING USRP ------------------------------// - // Once we have received a successful USRP close response, we shutdown all - // mblocks and exit. - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - fflush(stdout); - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_rx::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Opening the USRP\n"; -} - -void -test_usrp_rx::close_usrp() -{ - - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Closing the USRP\n"; -} - -void -test_usrp_rx::allocate_channel() -{ - long capacity = (long) 16e6; - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Requesting RX channel allocation\n"; -} - -void -test_usrp_rx::enter_receiving() -{ - d_state = RECEIVING; - - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Receiving...\n"; -} - -void -test_usrp_rx::handle_response_recv_raw_samples(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t v_samples = pmt_nth(2, data); - pmt_t timestamp = pmt_nth(3, data); - pmt_t channel = pmt_nth(4, data); - pmt_t properties = pmt_nth(5, data); - - d_samples_recvd += pmt_length(v_samples) / 4; - - // Check for overrun - if(!pmt_is_dict(properties)) { - std::cout << "[TEST_USRP_INBAND_RX] Recv samples dictionary is improper\n"; - return; - } - - // Check if the number samples we have received meets the test - if(d_samples_recvd >= d_samples_to_recv) { - d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan)); - enter_closing_channel(); - return; - } - -} - -void -test_usrp_rx::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_RX] Deallocating RX channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_rx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_rx", PMT_F, &result); - -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_timestamps.cc b/usrp/limbo/apps-inband/test_usrp_inband_timestamps.cc deleted file mode 100644 index 3b874d1a5b..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_timestamps.cc +++ /dev/null @@ -1,506 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <iostream> - -#include <ui_nco.h> -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> - -#define NBPING 10 - -static bool verbose = true; -bool bskip = false; -long bstep = 10000; -long bcurr = 0; -long incr = 0x500; -long ptime = 0x000; - -class test_usrp_inband_timestamps : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - pmt_t d_tx_chan; // returned tx channel handle - pmt_t d_rx_chan; // returned tx channel handle - - struct timeval times[NBPING]; - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - TRANSMITTING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - long d_nsamples_to_send; - long d_nsamples_xmitted; - long d_nframes_xmitted; - long d_samples_per_frame; - bool d_done_sending; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - public: - test_usrp_inband_timestamps(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_inband_timestamps(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_receiving(); - void enter_transmitting(); - void build_and_send_ping(); - void build_and_send_next_frame(); - void handle_xmit_response(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_inband_timestamps::test_usrp_inband_timestamps(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan(PMT_NIL), - d_rx_chan(PMT_NIL), - d_state(INIT), d_nsamples_to_send((long) 40e6), - d_nsamples_xmitted(0), - d_nframes_xmitted(0), - //d_samples_per_frame((long)(126)), - d_samples_per_frame((long)(126 * 2)), // non-full packet - //d_samples_per_frame((long)(126 * 3.5)), // non-full packet - //d_samples_per_frame((long)(126 * 4)), // full packet - d_done_sending(false), - d_amplitude(16384) -{ - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Initializing...\n"; - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - bool fake_usrp_p = false; - - // Test the TX side - - pmt_t usrp_dict = pmt_make_dict(); - - if(fake_usrp_p) { - pmt_dict_set(usrp_dict, - pmt_intern("fake-usrp"), - PMT_T); - } - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(128)); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(16)); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 128e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); - -} - -test_usrp_inband_timestamps::~test_usrp_inband_timestamps() -{ -} - -void -test_usrp_inband_timestamps::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_inband_timestamps::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - //std::cout << msg << std::endl; - - switch(d_state){ - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - - if(pmt_eq(d_tx->port_symbol(), port_id)) { - status = pmt_nth(1, data); - d_tx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Received allocation for TX\n"; - - if(!pmt_eqv(d_rx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } - } - - if(pmt_eq(d_rx->port_symbol(), port_id)) { - status = pmt_nth(1, data); - d_rx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Received allocation for TX\n"; - - if(!pmt_eqv(d_tx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } - } - } - goto unhandled; - - case TRANSMITTING: - if (pmt_eq(event, s_response_xmit_raw_frame)){ - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - - if (pmt_eq(event, s_response_from_control_channel)) { - std::cout << "ping response!\n"; - } - goto unhandled; - - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - goto unhandled; - - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - unhandled: - if(verbose && 0) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_inband_timestamps::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; -} - -void -test_usrp_inband_timestamps::close_usrp() -{ - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Closing USRP\n"; -} - -void -test_usrp_inband_timestamps::allocate_channel() -{ - long capacity = (long) 16e6; - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; -} - -void -test_usrp_inband_timestamps::enter_receiving() -{ - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); -} - -void -test_usrp_inband_timestamps::enter_transmitting() -{ - d_state = TRANSMITTING; - d_nsamples_xmitted = 0; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Beginning transmission\n"; - - sleep(1); - - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); - -} - -void -test_usrp_inband_timestamps::build_and_send_ping() -{ - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(PMT_NIL, pmt_list1(pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(0), - pmt_from_long(0)))))); - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Ping sent" << std::endl; -} - -void -test_usrp_inband_timestamps::build_and_send_next_frame() -{ - // allocate the uniform vector for the samples - // FIXME perhaps hold on to this between calls - -#if 0 - long nsamples_this_frame = - std::min(d_nsamples_to_send - d_nsamples_xmitted, - d_samples_per_frame); -#else - long nsamples_this_frame = d_samples_per_frame; -#endif - - if (nsamples_this_frame == 0){ - d_done_sending = true; - return; - } - - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writable_elements(uvec, ignore); - - // fill in the complex sinusoid - - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - pmt_t timestamp; - - if(bskip) { - timestamp = pmt_from_long(0x0); // throw away - bcurr++; - if(bcurr == bstep) { - bskip = false; - bcurr = 0; - } - } else { - timestamp = pmt_from_long(0xffffffff); // NOW - timestamp = pmt_from_long(ptime); - ptime += incr; - bcurr++; - if(bcurr == bstep) { - //bskip = true; - bcurr = 0; - } - } - - std::cout << bskip << " -- " << bcurr << std::endl; - - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan, // channel - uvec, // the samples - timestamp)); - - d_nsamples_xmitted += nsamples_this_frame; - d_nframes_xmitted++; - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Transmitted frame\n"; - - //build_and_send_next_frame(); -} - - -void -test_usrp_inband_timestamps::handle_xmit_response(pmt_t handle) -{ - if (d_done_sending && - pmt_to_long(handle) == (d_nframes_xmitted - 1)){ - // We're done sending and have received all responses - enter_closing_channel(); - } - - build_and_send_next_frame(); - //build_and_send_ping(); -} - -void -test_usrp_inband_timestamps::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TIMESTAMPS] Closing channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_inband_timestamps); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_inband_timestamps", PMT_F, &result); -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_tx.cc b/usrp/limbo/apps-inband/test_usrp_inband_tx.cc deleted file mode 100644 index 9f294e770f..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_tx.cc +++ /dev/null @@ -1,411 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <iostream> - -#include <ui_nco.h> -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> - -static bool verbose = true; - -class test_usrp_tx : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_cs; - pmt_t d_tx_chan; // returned tx channel handle - - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNEL, - TRANSMITTING, - CLOSING_CHANNEL, - CLOSING_USRP, - }; - - state_t d_state; - long d_nsamples_to_send; - long d_nsamples_xmitted; - long d_nframes_xmitted; - long d_samples_per_frame; - bool d_done_sending; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - public: - test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_tx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void open_usrp(); - void close_usrp(); - void allocate_channel(); - void send_packets(); - void enter_transmitting(); - void build_and_send_next_frame(); - void handle_xmit_response(pmt_t invocation_handle); - void enter_closing_channel(); -}; - -test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_state(INIT), d_nsamples_to_send((long) 80e6), - d_nsamples_xmitted(0), - d_nframes_xmitted(0), - d_samples_per_frame((long)(126 * 4)), // full packet - d_done_sending(false), - d_amplitude(16384) -{ - // std::cout << "[TEST_USRP_TX] Initializing...\n"; - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - //bool fake_usrp_p = true; - bool fake_usrp_p = false; - - // Test the TX side - - pmt_t usrp_dict = pmt_make_dict(); - - if(fake_usrp_p) { - pmt_dict_set(usrp_dict, - pmt_intern("fake-usrp"), - PMT_T); - } - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(64)); - -// If unspecified, chooses center frequency from range -// pmt_dict_set(usrp_dict, -// pmt_intern("rf-freq"), -// pmt_from_long(10e6)); - - define_component("server", "usrp_server", usrp_dict); - - connect("self", "tx0", "server", "tx0"); - connect("self", "cs", "server", "cs"); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 128e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); - - // FIXME need to somehow set the interp rate in the USRP. - // for now, we'll have the low-level code hardwire it. -} - -test_usrp_tx::~test_usrp_tx() -{ -} - -void -test_usrp_tx::initial_transition() -{ - open_usrp(); -} - -void -test_usrp_tx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - std::string error_msg; - - //std::cout << msg << std::endl; - - switch(d_state){ - case OPENING_USRP: - if (pmt_eq(event, s_response_open)){ - status = pmt_nth(1, data); - if (pmt_eq(status, PMT_T)){ - allocate_channel(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - } - goto unhandled; - - case ALLOCATING_CHANNEL: - if (pmt_eq(event, s_response_allocate_channel)){ - status = pmt_nth(1, data); - d_tx_chan = pmt_nth(2, data); - - if (pmt_eq(status, PMT_T)){ - enter_transmitting(); - return; - } - else { - error_msg = "failed to allocate channel:"; - goto bail; - } - } - goto unhandled; - - case TRANSMITTING: - if (pmt_eq(event, s_response_xmit_raw_frame)){ - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - goto unhandled; - - case CLOSING_CHANNEL: - if (pmt_eq(event, s_response_deallocate_channel)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - close_usrp(); - return; - } - else { - error_msg = "failed to deallocate channel:"; - goto bail; - } - } - goto unhandled; - - case CLOSING_USRP: - if (pmt_eq(event, s_response_close)){ - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - shutdown_all(PMT_T); - return; - } - else { - error_msg = "failed to close USRP:"; - goto bail; - } - } - goto unhandled; - - default: - goto unhandled; - } - return; - - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - unhandled: - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; -} - - -void -test_usrp_tx::open_usrp() -{ - pmt_t which_usrp = pmt_from_long(0); - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp)); - d_state = OPENING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Opening the USRP\n"; -} - -void -test_usrp_tx::close_usrp() -{ - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); - d_state = CLOSING_USRP; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Closing the USRP\n"; -} - -void -test_usrp_tx::allocate_channel() -{ - long capacity = (long) 16e6; - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_state = ALLOCATING_CHANNEL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Requesting TX channel allocation\n"; -} - -void -test_usrp_tx::enter_transmitting() -{ - d_state = TRANSMITTING; - d_nsamples_xmitted = 0; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Transmitting...\n"; - - build_and_send_next_frame(); // fire off 4 to start pipeline - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); -} - -void -test_usrp_tx::build_and_send_next_frame() -{ - // allocate the uniform vector for the samples - // FIXME perhaps hold on to this between calls - -#if 1 - long nsamples_this_frame = - std::min(d_nsamples_to_send - d_nsamples_xmitted, - d_samples_per_frame); -#else - long nsamples_this_frame = d_samples_per_frame; -#endif - - if (nsamples_this_frame == 0){ - d_done_sending = true; - return; - } - - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writable_elements(uvec, ignore); - - // fill in the complex sinusoid - - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - pmt_t tx_properties = pmt_make_dict(); - - pmt_t timestamp = pmt_from_long(0xffffffff); // NOW - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list5(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan, // channel - uvec, // the samples - timestamp, - tx_properties)); - - d_nsamples_xmitted += nsamples_this_frame; - d_nframes_xmitted++; - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n"; -} - - -void -test_usrp_tx::handle_xmit_response(pmt_t handle) -{ - if (d_done_sending && - pmt_to_long(handle) == (d_nframes_xmitted - 1)){ - // We're done sending and have received all responses - enter_closing_channel(); - } - - build_and_send_next_frame(); -} - -void -test_usrp_tx::enter_closing_channel() -{ - d_state = CLOSING_CHANNEL; - - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_tX] Deallocating TX channel\n"; -} - -REGISTER_MBLOCK_CLASS(test_usrp_tx); - - -// ---------------------------------------------------------------- - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_tx", PMT_F, &result); -} diff --git a/usrp/limbo/apps-inband/test_usrp_inband_underrun.cc b/usrp/limbo/apps-inband/test_usrp_inband_underrun.cc deleted file mode 100644 index 11babb0481..0000000000 --- a/usrp/limbo/apps-inband/test_usrp_inband_underrun.cc +++ /dev/null @@ -1,674 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/exception.h> -#include <mblock/msg_queue.h> -#include <mblock/message.h> -#include <mblock/msg_accepter.h> -#include <mblock/class_registry.h> -#include <pmt.h> -#include <stdio.h> -#include <string.h> -#include <sys/time.h> -#include <iostream> -#include <ui_nco.h> - -// Include the symbols needed for communication with USRP server -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> - -static bool verbose = true; - -class test_usrp_inband_underrun : public mb_mblock -{ - - mb_port_sptr d_tx; // Ports connected to the USRP server - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - pmt_t d_tx_chan; // Returned channel from TX allocation - pmt_t d_rx_chan; // Returned channel from RX allocation - - pmt_t d_which_usrp; // The USRP to use for the test - - long d_warm_msgs; // The number of messages to 'warm' the USRP - long d_warm_recvd; // The number of msgs received in the 'warm' state - - // Keep track of current state - enum state_t { - INIT, - OPENING_USRP, - ALLOCATING_CHANNELS, - WRITE_REGISTER, - READ_REGISTER, - TRANSMITTING, - CLOSING_CHANNELS, - CLOSING_USRP, - }; - state_t d_state; - - long d_nsamples_to_send; - long d_nsamples_xmitted; - long d_nframes_xmitted; - long d_samples_per_frame; - bool d_done_sending; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - long d_n_underruns; - - public: - test_usrp_inband_underrun(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~test_usrp_inband_underrun(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void opening_usrp(); - void allocating_channels(); - void write_register(); - void read_register(); - void closing_channels(); - void closing_usrp(); - void enter_receiving(); - void enter_transmitting(); - void build_and_send_ping(); - void build_and_send_next_frame(); - void handle_xmit_response(pmt_t handle); - void handle_recv_response(pmt_t dict); -}; - - -int -main (int argc, char **argv) -{ - // handle any command line args here - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_NIL; - - rt->run("top", "test_usrp_inband_underrun", PMT_F, &result); -} - - -test_usrp_inband_underrun::test_usrp_inband_underrun(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_tx_chan(PMT_NIL), - d_rx_chan(PMT_NIL), - d_which_usrp(pmt_from_long(0)), - d_state(INIT), - d_nsamples_to_send((long) 27e6), - d_nsamples_xmitted(0), - d_nframes_xmitted(0), - d_samples_per_frame(d_nsamples_to_send), // full packet - - d_done_sending(false), - d_amplitude(16384), - d_n_underruns(0) -{ - - // A dictionary is used to pass parameters to the USRP - pmt_t usrp_dict = pmt_make_dict(); - - // Specify the RBF to use - pmt_dict_set(usrp_dict, - pmt_intern("rbf"), - pmt_intern("inband_1rxhb_1tx.rbf")); - - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("interp-tx"), - pmt_from_long(64)); - - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(128)); - - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Create an instance of USRP server and connect ports - define_component("server", "usrp_server", usrp_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 128e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); -} - -test_usrp_inband_underrun::~test_usrp_inband_underrun() -{ -} - -void -test_usrp_inband_underrun::initial_transition() -{ - opening_usrp(); -} - -// Handle message reads all incoming messages from USRP server which will be -// initialization and ping responses. We perform actions based on the current -// state and the event (ie, ping response) -void -test_usrp_inband_underrun::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t data = msg->data(); - pmt_t port_id = msg->port_id(); - - pmt_t handle = PMT_F; - pmt_t status = PMT_F; - pmt_t dict = PMT_NIL; - std::string error_msg; - - // Check the recv sample responses for underruns and count - if(pmt_eq(event, s_response_recv_raw_samples)) { - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - dict = pmt_nth(4, data); - - if(pmt_eq(status, PMT_T)) { - handle_recv_response(dict); - return; - } - else { - error_msg = "error while receiving samples:"; - goto bail; - } - } - - - // Dispatch based on state - switch(d_state) { - - //----------------------------- OPENING_USRP ----------------------------// - // We only expect a response from opening the USRP which should be succesful - // or failed. - case OPENING_USRP: - - if(pmt_eq(event, s_response_open)) { - - status = pmt_nth(1, data); // failed/succes - - if(pmt_eq(status, PMT_T)) { - allocating_channels(); - return; - } - else { - error_msg = "failed to open usrp:"; - goto bail; - } - - } - - goto unhandled; // all other messages not handled in this state - - - //----------------------- ALLOCATING CHANNELS --------------------// - // When allocating channels, we need to wait for 2 responses from - // USRP server: one for TX and one for RX. Both are initialized to - // NIL so we know to continue to the next state once both are set. - case ALLOCATING_CHANNELS: - - // A TX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_tx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Received TX allocation" - << " on channel " << d_tx_chan << std::endl; - - // If the RX has also been allocated already, we can continue - if(!pmt_eqv(d_rx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - - return; - } - else { // TX allocation failed - error_msg = "failed to allocate TX channel:"; - goto bail; - } - } - - // A RX allocation response - if(pmt_eq(event, s_response_allocate_channel) - && pmt_eq(d_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful response, extract the channel - if(pmt_eq(status, PMT_T)) { - - d_rx_chan = pmt_nth(2, data); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Received RX allocation" - << " on channel " << d_rx_chan << std::endl; - - // If the TX has also been allocated already, we can continue - if(!pmt_eqv(d_tx_chan, PMT_NIL)) { - enter_receiving(); - enter_transmitting(); - } - - return; - } - else { // RX allocation failed - error_msg = "failed to allocate RX channel:"; - goto bail; - } - } - - goto unhandled; - - case WRITE_REGISTER: - goto unhandled; - - case READ_REGISTER: - goto unhandled; - - //-------------------------- TRANSMITTING ----------------------------// - // In the transmit state we count the number of underruns received and - // ballpark the number with an expected count (something >1 for starters) - case TRANSMITTING: - - // Check that the transmits are OK - if (pmt_eq(event, s_response_xmit_raw_frame)){ - handle = pmt_nth(0, data); - status = pmt_nth(1, data); - - if (pmt_eq(status, PMT_T)){ - handle_xmit_response(handle); - return; - } - else { - error_msg = "bad response-xmit-raw-frame:"; - goto bail; - } - } - - goto unhandled; - - //------------------------- CLOSING CHANNELS ----------------------------// - // Check deallocation responses, once the TX and RX channels are both - // deallocated then we close the USRP. - case CLOSING_CHANNELS: - - if (pmt_eq(event, s_response_deallocate_channel) - && pmt_eq(d_tx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful, set the port to NIL - if(pmt_eq(status, PMT_T)) { - d_tx_chan = PMT_NIL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Received TX deallocation\n"; - - // If the RX is also deallocated, we can close the USRP - if(pmt_eq(d_rx_chan, PMT_NIL)) - closing_usrp(); - - return; - - } else { - - error_msg = "failed to deallocate TX channel:"; - goto bail; - - } - } - - if (pmt_eq(event, s_response_deallocate_channel) - && pmt_eq(d_rx->port_symbol(), port_id)) - { - status = pmt_nth(1, data); - - // If successful, set the port to NIL - if(pmt_eq(status, PMT_T)) { - d_rx_chan = PMT_NIL; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Received RX deallocation\n"; - - // If the TX is also deallocated, we can close the USRP - if(pmt_eq(d_tx_chan, PMT_NIL)) - closing_usrp(); - - return; - - } else { - - error_msg = "failed to deallocate RX channel:"; - goto bail; - - } - } - - goto unhandled; - - //--------------------------- CLOSING USRP ------------------------------// - // Once we have received a successful USRP close response, we shutdown all - // mblocks and exit. - case CLOSING_USRP: - - if (pmt_eq(event, s_response_close)) { - - status = pmt_nth(1, data); - - if(pmt_eq(status, PMT_T)) { - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Successfully closed USRP\n"; - - std::cout << "\nUnderruns: " << d_n_underruns << std::endl; - fflush(stdout); - - shutdown_all(PMT_T); - return; - - } else { - - error_msg = "failed to close USRP:"; - goto bail; - } - } - - goto unhandled; - - case INIT: - goto unhandled; - - } - - // An error occured, print it, and shutdown all m-blocks - bail: - std::cerr << error_msg << data - << "status = " << status << std::endl; - shutdown_all(PMT_F); - return; - - // Received an unhandled message for a specific state - unhandled: - if(verbose && !pmt_eq(event, pmt_intern("%shutdown"))) - std::cout << "test_usrp_inband_tx: unhandled msg: " << msg - << "in state "<< d_state << std::endl; - -} - - -// Sends a command to USRP server to open up a connection to the -// specified USRP, which is defaulted to USRP 0 on the system -void -test_usrp_inband_underrun::opening_usrp() -{ - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Opening USRP " - << d_which_usrp << std::endl; - - d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, d_which_usrp)); - d_state = OPENING_USRP; -} - -// RX and TX channels must be allocated so that the USRP server can -// properly share bandwidth across multiple USRPs. No commands will be -// successful to the USRP through the USRP server on the TX or RX channels until -// a bandwidth allocation has been received. -void -test_usrp_inband_underrun::allocating_channels() -{ - d_state = ALLOCATING_CHANNELS; - - long capacity = (long) 16e6; - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(capacity))); -} - -// After allocating the channels, a write register command will be sent to the -// USRP. -void -test_usrp_inband_underrun::write_register() -{ - d_state = WRITE_REGISTER; - - long reg = 0; - - d_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(PMT_NIL, // invoc handle - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(reg), - pmt_from_long(0xbeef)))))); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_REGISTERS] Writing 0xbeef to " - << reg << std::endl; - - read_register(); // immediately transition to read the register -} - -// Temporary: for testing pings -void -test_usrp_inband_underrun::build_and_send_ping() -{ - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(PMT_NIL, pmt_list1(pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(0), - pmt_from_long(0)))))); - - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Ping sent" << std::endl; -} - -// After writing to the register, we want to read the value back and ensure that -// it is the same value that we wrote. -void -test_usrp_inband_underrun::read_register() -{ - d_state = READ_REGISTER; - - long reg = 9; - - d_tx->send(s_cmd_to_control_channel, // C/S packet - pmt_list2(PMT_NIL, // invoc handle - pmt_list1( - pmt_list2(s_op_read_reg, - pmt_list2( - pmt_from_long(0), // rid - pmt_from_long(reg)))))); - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Reading from register " - << reg << std::endl; -} - -// Used to enter the receiving state -void -test_usrp_inband_underrun::enter_receiving() -{ - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_F, - d_rx_chan)); - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Started RX sample stream\n"; -} - -void -test_usrp_inband_underrun::enter_transmitting() -{ - d_state = TRANSMITTING; - d_nsamples_xmitted = 0; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Entering transmit state...\n"; - - build_and_send_next_frame(); // fire off 4 to start pipeline - build_and_send_next_frame(); - build_and_send_next_frame(); - build_and_send_next_frame(); -} - -void -test_usrp_inband_underrun::build_and_send_next_frame() -{ - - long nsamples_this_frame = - std::min(d_nsamples_to_send - d_nsamples_xmitted, - d_samples_per_frame); - - if (nsamples_this_frame == 0){ - d_done_sending = true; - return; - } - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writable_elements(uvec, ignore); - - // fill in the complex sinusoid - - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Transmitting frame...\n"; - - pmt_t timestamp = pmt_from_long(0xffffffff); // NOW - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_from_long(d_nframes_xmitted), // invocation-handle - d_tx_chan, // channel - uvec, // the samples - timestamp)); - - d_nsamples_xmitted += nsamples_this_frame; - d_nframes_xmitted++; - - if(verbose) - std::cout << "[TEST_USRP_INBAND_TX] Transmitted frame\n"; - -} - -void -test_usrp_inband_underrun::handle_xmit_response(pmt_t handle) -{ - if (d_done_sending && - pmt_to_long(handle) == (d_nframes_xmitted - 1)){ - // We're done sending and have received all responses - closing_channels(); - return; - } - - build_and_send_next_frame(); -} - -void -test_usrp_inband_underrun::handle_recv_response(pmt_t dict) -{ - if(!pmt_is_dict(dict)) { - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Recv samples dictionary is improper\n"; - return; - } - - // Read the TX interpolations - if(pmt_t underrun = pmt_dict_ref(dict, - pmt_intern("underrun"), - PMT_NIL)) { - if(pmt_eqv(underrun, PMT_T)) { - d_n_underruns++; - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] Underrun\n"; - } - else { - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] No underrun\n" << underrun <<std::endl; - } - } else { - - if(verbose && 0) - std::cout << "[TEST_USRP_INBAND_UNDERRUN] No underrun\n"; - } - -} - -void -test_usrp_inband_underrun::closing_channels() -{ - d_state = CLOSING_CHANNELS; - - d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_tx_chan)); - d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan)); -} - -void -test_usrp_inband_underrun::closing_usrp() -{ - d_state = CLOSING_USRP; - - d_cs->send(s_cmd_close, pmt_list1(PMT_NIL)); -} - -REGISTER_MBLOCK_CLASS(test_usrp_inband_underrun); diff --git a/usrp/limbo/apps-inband/ui_nco.h b/usrp/limbo/apps-inband/ui_nco.h deleted file mode 100644 index e6d7814ab9..0000000000 --- a/usrp/limbo/apps-inband/ui_nco.h +++ /dev/null @@ -1,202 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2002 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDED_UI_NCO_H -#define INCLUDED_UI_NCO_H - - -#include <vector> -#include <ui_sincos.h> -#include <cmath> - -#include <complex> -typedef std::complex<float> gr_complex; - - -/*! - * \brief base class template for Numerically Controlled Oscillator (NCO) - */ - - -//FIXME Eventually generalize this to fixed point - -template<class o_type, class i_type> -class ui_nco { -public: - ui_nco () : phase (0), phase_inc(0) {} - - virtual ~ui_nco () {} - - // radians - void set_phase (double angle) { - phase = angle; - } - - void adjust_phase (double delta_phase) { - phase += delta_phase; - } - - - // angle_rate is in radians / step - void set_freq (double angle_rate){ - phase_inc = angle_rate; - } - - // angle_rate is a delta in radians / step - void adjust_freq (double delta_angle_rate) - { - phase_inc += delta_angle_rate; - } - - // increment current phase angle - - void step () - { - phase += phase_inc; - if (fabs (phase) > M_PI){ - - while (phase > M_PI) - phase -= 2*M_PI; - - while (phase < -M_PI) - phase += 2*M_PI; - } - } - - void step (int n) - { - phase += phase_inc * n; - if (fabs (phase) > M_PI){ - - while (phase > M_PI) - phase -= 2*M_PI; - - while (phase < -M_PI) - phase += 2*M_PI; - } - } - - // units are radians / step - double get_phase () const { return phase; } - double get_freq () const { return phase_inc; } - - // compute sin and cos for current phase angle - void sincos (float *sinx, float *cosx) const; - - // compute cos or sin for current phase angle - float cos () const { return std::cos (phase); } - float sin () const { return std::sin (phase); } - - // compute a block at a time - void sin (float *output, int noutput_items, double ampl = 1.0); - void cos (float *output, int noutput_items, double ampl = 1.0); - void sincos (gr_complex *output, int noutput_items, double ampl = 1.0); - void sin (short *output, int noutput_items, double ampl = 1.0); - void cos (short *output, int noutput_items, double ampl = 1.0); - void sin (int *output, int noutput_items, double ampl = 1.0); - void cos (int *output, int noutput_items, double ampl = 1.0); - -protected: - double phase; - double phase_inc; -}; - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::sincos (float *sinx, float *cosx) const -{ - ui_sincosf (phase, sinx, cosx); -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::sin (float *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (float)(sin () * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::cos (float *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (float)(cos () * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::sin (short *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (short)(sin() * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::cos (short *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (short)(cos () * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::sin (int *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (int)(sin () * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::cos (int *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - output[i] = (int)(cos () * ampl); - step (); - } -} - -template<class o_type, class i_type> -void -ui_nco<o_type,i_type>::sincos (gr_complex *output, int noutput_items, double ampl) -{ - for (int i = 0; i < noutput_items; i++){ - float cosx, sinx; - sincos (&sinx, &cosx); - output[i] = gr_complex(cosx * ampl, sinx * ampl); - step (); - } -} - -#endif /* INCLUDED_UI_NCO_H */ - diff --git a/usrp/limbo/apps-inband/ui_sincos.c b/usrp/limbo/apps-inband/ui_sincos.c deleted file mode 100644 index 27841f0100..0000000000 --- a/usrp/limbo/apps-inband/ui_sincos.c +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#define _GNU_SOURCE // ask for GNU extensions if available - -#include "ui_sincos.h" -#include <math.h> - -// ---------------------------------------------------------------- - -#if defined (HAVE_SINCOS) - -void -ui_sincos (double x, double *sinx, double *cosx) -{ - sincos (x, sinx, cosx); -} - -#else - -void -ui_sincos (double x, double *sinx, double *cosx) -{ - *sinx = sin (x); - *cosx = cos (x); -} - -#endif - -// ---------------------------------------------------------------- - -#if defined (HAVE_SINCOSF) - -void -ui_sincosf (float x, float *sinx, float *cosx) -{ - sincosf (x, sinx, cosx); -} - -#elif defined (HAVE_SINF) && defined (HAVE_COSF) - -void -ui_sincosf (float x, float *sinx, float *cosx) -{ - *sinx = sinf (x); - *cosx = cosf (x); -} - -#else - -void -ui_sincosf (float x, float *sinx, float *cosx) -{ - *sinx = sin (x); - *cosx = cos (x); -} - -#endif diff --git a/usrp/limbo/apps-inband/ui_sincos.h b/usrp/limbo/apps-inband/ui_sincos.h deleted file mode 100644 index d2d6e4b766..0000000000 --- a/usrp/limbo/apps-inband/ui_sincos.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2002,2004 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_UI_SINCOS_H -#define INCLUDED_UI_SINCOS_H - -#ifdef __cplusplus -extern "C" { -#endif - -// compute sine and cosine at the same time - -void ui_sincos (double x, double *sin, double *cos); -void ui_sincosf (float x, float *sin, float *cos); - -#ifdef __cplusplus -}; -#endif - -#endif /* INCLUDED_UI_SINCOS_H */ diff --git a/usrp/limbo/inband/.gitignore b/usrp/limbo/inband/.gitignore deleted file mode 100644 index a228dcdc10..0000000000 --- a/usrp/limbo/inband/.gitignore +++ /dev/null @@ -1,20 +0,0 @@ -/Makefile -/Makefile.in -/.la -/.lo -/.deps -/.libs -/*.la -/*.lo -/*.swp -/*.dat -/test_fusb -/std_paths.h -/usrp_dbid.py -/usrp_dbid.h -/usrp_dbid.cc -/usrp_server_mbh.cc -/test_inband -/test_usrp_inband -/test_usrp_tx -/*_mbh.cc diff --git a/usrp/limbo/inband/Makefile.am b/usrp/limbo/inband/Makefile.am deleted file mode 100644 index 650a25ff95..0000000000 --- a/usrp/limbo/inband/Makefile.am +++ /dev/null @@ -1,114 +0,0 @@ -# -# Copyright 2007,2008 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -include $(top_srcdir)/Makefile.common - -AM_CPPFLAGS = \ - $(DEFINES) $(OMNITHREAD_INCLUDES) $(PMT_INCLUDES) $(MBLOCK_INCLUDES) \ - $(USRP_INCLUDES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) \ - -I$(srcdir)/../../apps-inband $(WITH_INCLUDES) - -TESTS = test_inband - -EXTRA_DIST = \ - usrp_server.mbh \ - usrp_interface.mbh - -lib_LTLIBRARIES = \ - libusrp-inband.la \ - libusrp-inband-qa.la - -# ------------------------------------------------------------------------ -# Build the inband library - -BUILT_SOURCES = \ - usrp_server_mbh.cc \ - usrp_interface_mbh.cc - -usrp_server_mbh.cc : usrp_server.mbh - $(COMPILE_MBH) $(srcdir)/usrp_server.mbh usrp_server_mbh.cc - -usrp_interface_mbh.cc : usrp_interface.mbh - $(COMPILE_MBH) $(srcdir)/usrp_interface.mbh usrp_interface_mbh.cc - -libusrp_inband_la_SOURCES = \ - $(BUILT_SOURCES) \ - $(srcdir)/../../apps-inband/ui_sincos.c \ - usrp_inband_usb_packet.cc \ - usrp_rx.cc \ - usrp_rx_stub.cc \ - usrp_server.cc \ - usrp_tx.cc \ - usrp_tx_stub.cc \ - usrp_usb_interface.cc - -libusrp_inband_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0 - -libusrp_inband_la_LIBADD = \ - $(MBLOCK_LA) \ - $(USRP_LA) \ - -lstdc++ - -include_HEADERS = \ - usrp_inband_usb_packet.h \ - usrp_rx.h \ - usrp_rx_stub.h \ - usrp_server.h \ - usrp_tx.h \ - usrp_tx_stub.h \ - usrp_usb_interface.h - -noinst_HEADERS = \ - qa_inband.h \ - qa_inband_packet_prims.h \ - qa_inband_usrp_server.h \ - symbols_usrp_channel.h \ - symbols_usrp_interface_cs.h \ - symbols_usrp_low_level_cs.h \ - symbols_usrp_rx.h \ - symbols_usrp_rx_cs.h \ - symbols_usrp_server_cs.h \ - symbols_usrp_tx.h \ - symbols_usrp_tx_cs.h - -# ------------------------------------------------------------------------ -# Build the qa code in its own library - -libusrp_inband_qa_la_SOURCES = \ - qa_inband.cc \ - qa_inband_packet_prims.cc \ - qa_inband_usrp_server.cc - -# magic flags -libusrp_inband_qa_la_LDFLAGS = $(NO_UNDEFINED) -avoid-version - -libusrp_inband_qa_la_LIBADD = \ - libusrp-inband.la \ - $(PMT_LA) \ - $(CPPUNIT_LIBS) \ - -lstdc++ - -# ------------------------------------------------------------------------ - -noinst_PROGRAMS = \ - test_inband - -test_inband_SOURCES = test_inband.cc -test_inband_LDADD = libusrp-inband-qa.la diff --git a/usrp/limbo/inband/dump_packets.py b/usrp/limbo/inband/dump_packets.py deleted file mode 100755 index 2373624060..0000000000 --- a/usrp/limbo/inband/dump_packets.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -import sys -import struct -from optparse import OptionParser - -from usb_packet import * - -def dump_packet(raw_pkt, outfile, dump_payload): - pkt = usb_packet(raw_pkt) - outfile.write(pkt.decoded_flags()) - outfile.write(' chan= %2d len= %3d timestamp= 0x%08x rssi= % 2d tag= %2d\n' % ( - pkt.chan(), pkt.payload_len(), pkt.timestamp(), pkt.rssi(), pkt.tag())) - if dump_payload: - assert pkt.payload_len() % 4 == 0 - shorts = struct.unpack('<%dh' % (pkt.payload_len() // 2), pkt.payload()) - for i in range(0, len(shorts), 2): - outfile.write(' %6d, %6d\n' % (shorts[i], shorts[i+1])) - - -def dump_packets(infile, outfile, dump_payload): - raw_pkt = infile.read(512) - while raw_pkt: - if len(raw_pkt) != 512: - sys.stderr.write("File length is not a multiple of 512 bytes") - raise SystemExit, 1 - - dump_packet(raw_pkt, outfile, dump_payload) - raw_pkt = infile.read(512) - - -def main(): - parser = OptionParser() - parser.add_option('-p', '--dump-payload', action='store_true', default=False, - help='dump payload in decimal and hex') - - (options, files) = parser.parse_args() - if len(files) == 0: - dump_packets(sys.stdin, sys.stdout, options.dump_payload) - else: - for f in files: - dump_packets(open(f, "r"), sys.stdout, options.dump_payload) - - -if __name__ == '__main__': - main() diff --git a/usrp/limbo/inband/gen_test_packets.py b/usrp/limbo/inband/gen_test_packets.py deleted file mode 100755 index 2ee6463847..0000000000 --- a/usrp/limbo/inband/gen_test_packets.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python - -import random -import struct -from pprint import pprint -from usb_packet import * - -MAX_PAYLOAD = 504 -TIME_NOW = 0xffffffff - - -class sequence_generator(object): - def __init__(self): - self.i = 0 - - def __call__(self): - t = self.i - self.i += 1 - return t - -def gen_shuffled_lengths(): - valid_lengths = range(0, MAX_PAYLOAD+1, 4) # [0, 4, 8, ... 504] - random.shuffle(valid_lengths) - return valid_lengths - - -class packet_sequence_generator(object): - def __init__(self, channel, lengths): - self.next = sequence_generator() - self.channel = channel - self.lengths = lengths - - def __call__(self, output_file): - gen_packet(output_file, self.channel, self.next, self.lengths[0]) - del self.lengths[0] - - -def gen_packet(output_file, channel, content_generator, payload_len): - assert (payload_len % 4) == 0 - payload = [] - n_iq = payload_len // 4 - for n in range(n_iq): - payload.append(content_generator()) # I - payload.append(content_generator()) # Q - for n in range(MAX_PAYLOAD // 4 - n_iq): - payload.append(0x0000) - payload.append(0xffff) - - assert (len(payload) == MAX_PAYLOAD // 2) - - #print "\npayload_len =", payload_len - #pprint(payload) - - output_file.write(make_header(FL_START_OF_BURST|FL_END_OF_BURST, - channel, payload_len, TIME_NOW)) - output_file.write(struct.pack('<252h', *payload)) - - -def gen_all_valid_packet_lengths_1_channel(output_file): - lengths = gen_shuffled_lengths() - npkts = len(lengths) # number of packets we'll generator on each stream - pkt_gen_0 = packet_sequence_generator(0, lengths) - for i in range(npkts): - pkt_gen_0(output_file) - - assert pkt_gen_0.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127 - - -def gen_all_valid_packet_lengths_2_channels(output_file): - lengths = gen_shuffled_lengths() - npkts = len(lengths) # number of packets we'll generator on each stream - pkt_gen_0 = packet_sequence_generator(0, lengths) - pkt_gen_1 = packet_sequence_generator(0x1f, gen_shuffled_lengths()) - pkt_gen = (pkt_gen_0, pkt_gen_1) - - which_gen = (npkts * [0]) + (npkts * [1]) - random.shuffle(which_gen) - - for i in which_gen: - pkt_gen[i](output_file) - - assert pkt_gen_0.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127 - assert pkt_gen_1.next() == 16002 # 2*sum(1, 2, ..., 126) == 126 * 127 - -if __name__ == '__main__': - random.seed(0) - gen_all_valid_packet_lengths_1_channel(open("all_valid_packet_lengths_1_channel.dat", "w")) - gen_all_valid_packet_lengths_2_channels(open("all_valid_packet_lengths_2_channels.dat", "w")) diff --git a/usrp/limbo/inband/qa_inband.cc b/usrp/limbo/inband/qa_inband.cc deleted file mode 100644 index 6f33a6eadb..0000000000 --- a/usrp/limbo/inband/qa_inband.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <qa_inband.h> -#include <qa_inband_packet_prims.h> -#include <qa_inband_usrp_server.h> - -CppUnit::TestSuite * -qa_inband::suite() -{ - CppUnit::TestSuite *s = new CppUnit::TestSuite("inband"); - - s->addTest (qa_inband_packet_prims::suite()); - s->addTest (qa_inband_usrp_server::suite()); - - return s; -} diff --git a/usrp/limbo/inband/qa_inband.h b/usrp/limbo/inband/qa_inband.h deleted file mode 100644 index ab8f7f2502..0000000000 --- a/usrp/limbo/inband/qa_inband.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_QA_INBAND_H -#define INCLUDED_QA_INBAND_H - -#include <cppunit/TestSuite.h> - -//! collect all the tests for the user server - -class qa_inband { - public: - //! return suite of tests for all of usrp server - static CppUnit::TestSuite *suite(); -}; - -#endif /* INCLUDED_QA_INBAND_H */ diff --git a/usrp/limbo/inband/qa_inband_packet_prims.cc b/usrp/limbo/inband/qa_inband_packet_prims.cc deleted file mode 100644 index d9bbbec22d..0000000000 --- a/usrp/limbo/inband/qa_inband_packet_prims.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <qa_inband_packet_prims.h> -#include <cppunit/TestAssert.h> -#include <stdio.h> -#include <string.h> -#include <usrp_inband_usb_packet.h> // will change on gigabit crossover - -typedef usrp_inband_usb_packet transport_pkt; - -void -qa_inband_packet_prims::test_flags() -{ - transport_pkt pkt; - - // Test each one of the flags while ensuring no other fields become set in the process - pkt.set_header(pkt.FL_START_OF_BURST,0,0,0); - CPPUNIT_ASSERT_EQUAL(1, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - pkt.set_header(pkt.FL_END_OF_BURST,0,0,0); - CPPUNIT_ASSERT_EQUAL(0, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(1, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - pkt.set_header(pkt.FL_OVERRUN,0,0,0); - CPPUNIT_ASSERT_EQUAL(0, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(1, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - pkt.set_header(pkt.FL_UNDERRUN,0,0,0); - CPPUNIT_ASSERT_EQUAL(0, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(1, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - pkt.set_header(pkt.FL_DROPPED,0,0,0); - CPPUNIT_ASSERT_EQUAL(0, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(1, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - // test of all fields set - pkt.set_header( - pkt.FL_START_OF_BURST | - pkt.FL_END_OF_BURST | - pkt.FL_UNDERRUN | - pkt.FL_OVERRUN | - pkt.FL_DROPPED - ,0,0,0); - CPPUNIT_ASSERT_EQUAL(1, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(1, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(1, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(1, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(1, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - -} -////////////////////////////////////////////////////////////////////// - -void -qa_inband_packet_prims::test_fields() -{ - transport_pkt pkt; - void * payload; - - // test word0 field exclusiveness - // - // I want to test max values of each field to ensure field boundaries - // but these max values could change based on technology? The - // max payload is returned by a private method so the code is not - // technology dependent - pkt.set_header(0,16,0,0); - CPPUNIT_ASSERT_EQUAL(16, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - - pkt.set_header(0,0,8,0); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(8, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0,pkt.payload_len()); - - pkt.set_header(0,0,0,pkt.max_payload()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(pkt.max_payload(), pkt.payload_len()); - - // test timestamp, shouldn't have to test other fields since - // setting the timestamp only has the ability to affect one word - pkt.set_timestamp(54); - CPPUNIT_ASSERT_EQUAL(uint32_t(54), pkt.timestamp()); - - // test the payload, ensure no other fields overwritten - // - // is there a better test for this? - pkt.set_header(0,0,0,0); - payload = malloc(pkt.payload_len()); - memset(payload, 'f', pkt.payload_len()); - memcpy(pkt.payload(), payload, pkt.payload_len()); - CPPUNIT_ASSERT_EQUAL(0, memcmp(pkt.payload(), payload, pkt.payload_len())); - CPPUNIT_ASSERT_EQUAL(0, pkt.start_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.end_of_burst()); - CPPUNIT_ASSERT_EQUAL(0, pkt.overrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.underrun()); - CPPUNIT_ASSERT_EQUAL(0, pkt.dropped()); - CPPUNIT_ASSERT_EQUAL(0, pkt.chan()); - CPPUNIT_ASSERT_EQUAL(0, pkt.tag()); - CPPUNIT_ASSERT_EQUAL(0, pkt.payload_len()); - free(payload); - -} -////////////////////////////////////////////////////////////////////// diff --git a/usrp/limbo/inband/qa_inband_packet_prims.h b/usrp/limbo/inband/qa_inband_packet_prims.h deleted file mode 100644 index 71c0d737db..0000000000 --- a/usrp/limbo/inband/qa_inband_packet_prims.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef QA_INBAND_PACKET_PRIMS_H -#define QA_INBAND_PACKET_PRIMS_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_inband_packet_prims : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_inband_packet_prims); - CPPUNIT_TEST(test_flags); - CPPUNIT_TEST(test_fields); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_flags(); - void test_fields(); - -}; - -#endif /* INCLUDED_QA_INBAND_PACKET_PRIMS_H */ diff --git a/usrp/limbo/inband/qa_inband_usrp_server.cc b/usrp/limbo/inband/qa_inband_usrp_server.cc deleted file mode 100644 index 6049a8a874..0000000000 --- a/usrp/limbo/inband/qa_inband_usrp_server.cc +++ /dev/null @@ -1,1575 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_inband_usb_packet.h> -#include <qa_inband_usrp_server.h> -#include <cppunit/TestAssert.h> -#include <stdio.h> -#include <usrp_server.h> -#include <mblock/mblock.h> -#include <mblock/runtime.h> -#include <mblock/protocol_class.h> -#include <mblock/class_registry.h> -#include <vector> -#include <iostream> -#include <pmt.h> - -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_low_level_cs.h> - -typedef usrp_inband_usb_packet transport_pkt; // makes conversion to gigabit easy - -static bool verbose = false; - -static pmt_t s_timeout = pmt_intern("%timeout"); - -// ---------------------------------------------------------------------------------------------- - -class qa_alloc_top : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_nmsgs_to_recv; - long d_nrecvd; - - long d_max_capacity; - long d_ntx_chan, d_nrx_chan; - - long d_nstatus; - long d_nstatus_to_recv; - - public: - qa_alloc_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_alloc_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_message(mb_message_sptr msg); - void run_tests(); -}; - -qa_alloc_top::qa_alloc_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_nrecvd=0; - d_nmsgs_to_recv = 6; - d_nstatus=0; - d_nstatus_to_recv = 50; - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -qa_alloc_top::~qa_alloc_top(){} - -void -qa_alloc_top::initial_transition() -{ - // Allocations should fail before open - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, - s_err_usrp_not_opened), - pmt_from_long(1))); - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, - s_err_usrp_not_opened), - pmt_from_long(1))); - - // Retrieve information about the USRP, then run tests - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open, PMT_T), - pmt_from_long(0))); - - d_cs->send(s_cmd_max_capacity, - pmt_list1(pmt_list2(s_response_max_capacity, PMT_T))); - - d_cs->send(s_cmd_ntx_chan, - pmt_list1(pmt_list2(s_response_ntx_chan, PMT_T))); - - d_cs->send(s_cmd_nrx_chan, - pmt_list1(pmt_list2(s_response_nrx_chan,PMT_T))); -} - -void -qa_alloc_top::run_tests() -{ - if(verbose) - std::cout << "[qa_alloc_top] Starting tests...\n"; - - // should be able to allocate 1 byte - d_tx->send(s_cmd_allocate_channel, - pmt_list2(PMT_T, pmt_from_long(1))); - - // should not be able to allocate max capacity after 100 bytes were allocated - d_tx->send(s_cmd_allocate_channel, - pmt_list2(s_err_requested_capacity_unavailable, - pmt_from_long(d_max_capacity))); - - // keep allocating a little more until all of the channels are used and test - // the error response we start at 1 since we've already allocated 1 channel - for(int i=1; i < d_ntx_chan; i++) { - - if(verbose) - std::cout << "[qa_alloc_top] Sent allocation request...\n"; - - d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1))); - - d_nmsgs_to_recv++; - } - - // No more channels after allocating all of them is expected - d_tx->send(s_cmd_allocate_channel, - pmt_list2(s_err_channel_unavailable, - pmt_from_long(1))); - - // test out the same on the RX side - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1))); - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(s_err_requested_capacity_unavailable, - pmt_from_long(d_max_capacity))); - - for(int i=1; i < d_nrx_chan; i++) { - - d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1))); - - d_nmsgs_to_recv++; - } - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(s_err_channel_unavailable, - pmt_from_long(1))); - - // when all is said and done, there should be d_ntx_chan+d_ntx_chan bytes - // allocated - d_cs->send(s_cmd_current_capacity_allocation, - pmt_list1(pmt_from_long(d_ntx_chan+d_nrx_chan))); -} - -void -qa_alloc_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - - if ((pmt_eq(msg->port_id(), d_tx->port_symbol()) - || pmt_eq(msg->port_id(), d_rx->port_symbol())) - && pmt_eq(msg->signal(), s_response_allocate_channel)) - check_message(msg); - - if (pmt_eq(msg->port_id(), d_cs->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_max_capacity)) { - d_max_capacity = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_alloc_top] USRP has max capacity of " - << d_max_capacity << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_ntx_chan)) { - d_ntx_chan = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_alloc_top] USRP tx channels: " - << d_ntx_chan << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_nrx_chan)) { - d_nrx_chan = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_alloc_top] USRP rx channels: " - << d_nrx_chan << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) { - check_message(msg); - } - - d_nstatus++; - - check_message(msg); - - if(d_nstatus==d_nstatus_to_recv) - run_tests(); - } -} - -void -qa_alloc_top::check_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - d_nrecvd++; - - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - if(verbose) - std::cout << "Got: " << status << " Expected: " << e_status << "\n"; - shutdown_all(PMT_F); - return; - } else { - if(verbose) - std::cout << "[qa_alloc_top] Received expected response for message " - << d_nrecvd << " (" << event << ")\n"; - } - - if(d_nrecvd == d_nmsgs_to_recv) - shutdown_all(PMT_T); -} - -REGISTER_MBLOCK_CLASS(qa_alloc_top); - -// ---------------------------------------------------------------------------------------------- - -class qa_dealloc_top : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_max_capacity; - long d_ntx_chan, d_nrx_chan; - - long d_nstatus; - long d_nstatus_to_recv; - - long d_nalloc_to_recv; - long d_nalloc_recvd; - - long d_ndealloc_to_recv; - long d_ndealloc_recvd; - - std::vector<long> d_tx_chans; - std::vector<long> d_rx_chans; - - public: - qa_dealloc_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_dealloc_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_allocation(mb_message_sptr msg); - void check_deallocation(mb_message_sptr msg); - void allocate_max(); - void deallocate_all(); -}; - -qa_dealloc_top::qa_dealloc_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_ndealloc_recvd=0; - d_ndealloc_to_recv = 0; - d_nalloc_recvd=0; - d_nalloc_to_recv = 0; // auto-set - d_nstatus=0; - d_nstatus_to_recv = 4; - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); -} - -qa_dealloc_top::~qa_dealloc_top(){} - -void -qa_dealloc_top::initial_transition() -{ - - if(verbose) - std::cout << "[qa_dealloc_top] Initializing...\n"; - - // Retrieve information about the USRP, then run tests - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open,PMT_T), - pmt_from_long(0))); - - d_cs->send(s_cmd_max_capacity, - pmt_list1(pmt_list2(s_response_max_capacity,PMT_T))); - - d_cs->send(s_cmd_ntx_chan, - pmt_list1(pmt_list2(s_response_ntx_chan,PMT_T))); - - d_cs->send(s_cmd_nrx_chan, - pmt_list1(pmt_list2(s_response_nrx_chan,PMT_T))); -} - -void -qa_dealloc_top::allocate_max() -{ - - // Keep allocating until we hit the maximum number of channels - for(int i=0; i < d_ntx_chan; i++) { - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T), - pmt_from_long(1))); // 1 byte is good enough - - d_nalloc_to_recv++; - } - - for(int i=0; i < d_nrx_chan; i++) { - d_rx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T), - pmt_from_long(1))); - - d_nalloc_to_recv++; - } - -} - -void -qa_dealloc_top::deallocate_all() { - - // Deallocate all of the channels that were allocated from allocate_max() - for(int i=0; i < (int)d_tx_chans.size(); i++) { - - if(verbose) - std::cout << "[qa_dealloc_top] Trying to dealloc TX " - << d_tx_chans[i] << std::endl; - - d_tx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T), - pmt_from_long(d_tx_chans[i]))); - - d_ndealloc_to_recv++; - } - - // Deallocate the RX side now - for(int i=0; i < (int)d_rx_chans.size(); i++) { - - if(verbose) - std::cout << "[qa_dealloc_top] Trying to dealloc RX " - << d_tx_chans[i] << std::endl; - - d_rx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel,PMT_T), - pmt_from_long(d_rx_chans[i]))); - - d_ndealloc_to_recv++; - } - - // Should get permission denied errors trying to re-dealloc the channels, as - // we no longer have permission to them after deallocating - for(int i=0; i < (int)d_tx_chans.size(); i++) { - - d_tx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel, - s_err_channel_permission_denied), - pmt_from_long(d_tx_chans[i]))); - - d_ndealloc_to_recv++; - } - - // Same for RX - for(int i=0; i < (int)d_rx_chans.size(); i++) { - - d_rx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel, - s_err_channel_permission_denied), - pmt_from_long(d_rx_chans[i]))); - - d_ndealloc_to_recv++; - } - - // Try to deallocate a channel that doesn't exist on both sides, the last - // element in the vectors is the highest channel number, so we take that plus - // 1 - d_ndealloc_to_recv+=2; - d_tx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel, - s_err_channel_invalid), - pmt_from_long(d_rx_chans.back()+1))); - - d_rx->send(s_cmd_deallocate_channel, - pmt_list2(pmt_list2(s_response_deallocate_channel, - s_err_channel_invalid), - pmt_from_long(d_rx_chans.back()+1))); - - - // The used capacity should be back to 0 now that we've deallocated everything - d_cs->send(s_cmd_current_capacity_allocation, - pmt_list1(pmt_list2(s_response_current_capacity_allocation, - PMT_T))); -} - -void -qa_dealloc_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - if(pmt_eq(event, pmt_intern("%shutdown"))) - return; - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - if(verbose) - std::cout << "Got: " << status << " Expected: " << e_status << "\n"; - shutdown_all(PMT_F); - return; - } else { - if(verbose) - std::cout << "[qa_alloc_top] Received expected response for message " - << d_ndealloc_recvd - << " (" << event << ")\n"; - } - - if (pmt_eq(msg->port_id(), d_tx->port_symbol()) - || pmt_eq(msg->port_id(), d_rx->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_allocate_channel)) { - check_allocation(msg); - } - - } - - if (pmt_eq(msg->port_id(), d_cs->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_max_capacity)) { - d_max_capacity = pmt_to_long(pmt_nth(2, data)); - } - else if(pmt_eq(msg->signal(), s_response_ntx_chan)) { - d_ntx_chan = pmt_to_long(pmt_nth(2, data)); - } - else if(pmt_eq(msg->signal(), s_response_nrx_chan)) { - d_nrx_chan = pmt_to_long(pmt_nth(2, data)); - } - else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) { - // the final command is a capacity check which should be 0, then we - // shutdown - pmt_t expected_result = pmt_from_long(0); - pmt_t result = pmt_nth(2, data); - - if(pmt_eqv(expected_result, result)) { - shutdown_all(PMT_T); - return; - } else { - shutdown_all(PMT_F); - return; - } - } - - d_nstatus++; - - if(d_nstatus==d_nstatus_to_recv) - allocate_max(); - } -} - - -void -qa_dealloc_top::check_allocation(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t channel = pmt_nth(2, data); - - d_nalloc_recvd++; - - if(!pmt_eqv(status, PMT_T)) { - shutdown_all(PMT_F); - return; - } else { - // store all of the allocate channel numbers - if(pmt_eq(msg->port_id(), d_tx->port_symbol())) - d_tx_chans.push_back(pmt_to_long(channel)); - if(pmt_eq(msg->port_id(), d_rx->port_symbol())) - d_rx_chans.push_back(pmt_to_long(channel)); - } - - if(d_nalloc_recvd == d_nalloc_to_recv) { - - if(verbose) { - std::cout << "[qa_dealloc_top] Allocated TX channels: "; - for(int i=0; i < (int)d_tx_chans.size(); i++) - std::cout << d_tx_chans[i] << " "; - - std::cout << "\n[qa_dealloc_top] Allocated RX channels: "; - for(int i=0; i < (int)d_rx_chans.size(); i++) - std::cout << d_rx_chans[i] << " "; - std::cout << "\n"; - } - - deallocate_all(); // once we've allocated all of our channels, try to - // dealloc them - } -} - -REGISTER_MBLOCK_CLASS(qa_dealloc_top); - -// ---------------------------------------------------------------------------------------------- - -class qa_open_close_top : public mb_mblock -{ - mb_port_sptr d_cs; - - long d_max_capacity; - - long d_nmsg_to_recv; - long d_nmsg_recvd; - - public: - qa_open_close_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_open_close_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_cs(mb_message_sptr msg); - void run_tests(); -}; - -qa_open_close_top::qa_open_close_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - - d_nmsg_to_recv=7; - d_nmsg_recvd=0; - - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "cs", "server", "cs"); -} - -qa_open_close_top::~qa_open_close_top(){} - -void -qa_open_close_top::initial_transition() -{ - run_tests(); -} - -void -qa_open_close_top::run_tests() -{ - // std::cout << "[qa_open_close_top] Starting tests\n"; - - // A close before an open should fail - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close, - s_err_usrp_already_closed))); - - // Perform an open, and a second open which should fail - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open,PMT_T), - pmt_from_long(0))); - - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open, - s_err_usrp_already_opened), - pmt_from_long(0))); - - // A close should now be successful since the interface is open - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close,PMT_T))); - - // But, a second close should fail - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close, - s_err_usrp_already_closed))); - - // Just to be thorough, try an open and close again - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open,PMT_T), - pmt_from_long(0))); - - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close,PMT_T))); - -} - - -void -qa_open_close_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - - if (pmt_eq(msg->port_id(), d_cs->port_symbol())) { - check_cs(msg); - } - - d_nmsg_recvd++; - - if(d_nmsg_to_recv == d_nmsg_recvd) - shutdown_all(PMT_T); -} - -void -qa_open_close_top::check_cs(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - - if(verbose) - std::cout << "[qa_open_close_top] FAILED check_cs... Got: " << status - << " Expected: " << e_status - << " for event " << event << "\n"; - - shutdown_all(PMT_F); - } else { - if(verbose) - std::cout << "[qa_open_close_top] Received expected CS response (" - << event << ")\n"; - } - -} - -REGISTER_MBLOCK_CLASS(qa_open_close_top); - -// ---------------------------------------------------------------------------------------------- - -class qa_tx_top : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_max_capacity; - long d_ntx_chan, d_nrx_chan; - - long d_tx_chan; - long d_rx_chan; - - long d_nmsg_to_recv; - long d_nmsg_recvd; - - public: - qa_tx_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_tx_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_allocation(mb_message_sptr msg); - void check_deallocation(mb_message_sptr msg); - void check_xmit(mb_message_sptr msg); - void check_cs(mb_message_sptr msg); - void run_tests(); -}; - -qa_tx_top::qa_tx_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - - d_nmsg_to_recv=10; - d_nmsg_recvd=0; - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); -} - -qa_tx_top::~qa_tx_top(){} - -void -qa_tx_top::initial_transition() -{ - run_tests(); -} - -void -qa_tx_top::run_tests() -{ - if(verbose) - std::cout << "[qa_tx_top] Starting tests\n"; - - // A transmit before an open should fail - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame, - s_err_usrp_not_opened), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - // Now open - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open,PMT_T), - pmt_from_long(0))); - - // Try to transmit on a channel that we have no allocation for - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame, - s_err_channel_permission_denied), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - // Get a channel allocation and send on it, we assume 0 (FIXME) until 'defer' - // is implemented for simplicity - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame, PMT_T), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - // Close should be successful - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close,PMT_T))); - - // After closing, a new transmit raw frame should fail again - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame, - s_err_usrp_not_opened), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - // Reopen and retry before getting an allocation, the first xmit should fail, - // after we allocate it should work again - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open, PMT_T), - pmt_from_long(0))); - - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame, - s_err_channel_permission_denied), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - d_tx->send(s_cmd_xmit_raw_frame, - pmt_list4(pmt_list2(s_response_xmit_raw_frame,PMT_T), - pmt_from_long(0), - pmt_make_u32vector(transport_pkt::max_payload()/4, 0), - pmt_from_long(0))); - - // A final close which should be successful - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close,PMT_T))); - -} - - -void -qa_tx_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - if(pmt_eq(event, pmt_intern("%shutdown"))) - return; - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - if(verbose) - std::cout << "[qa_xmit_top] Got: " << status - << " Expected: " << e_status - << "For signal: " << event << "\n"; - shutdown_all(PMT_F); - return; - } else { - if(verbose) - std::cout << "[qa_xmit_top] Received expected response for message " - << d_nmsg_recvd - << " (" << event << ")\n"; - } - - if (pmt_eq(msg->port_id(), d_tx->port_symbol()) - || pmt_eq(msg->port_id(), d_rx->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_allocate_channel)) - check_allocation(msg); - - } - - d_nmsg_recvd++; - - if(d_nmsg_to_recv == d_nmsg_recvd){ - shutdown_all(PMT_T); - return; - } -} - -void -qa_tx_top::check_allocation(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t channel = pmt_nth(2, data); - - if(pmt_eqv(status, PMT_T)) { - // store all of the allocate channel numbers - if(pmt_eq(msg->port_id(), d_tx->port_symbol())) - d_tx_chan = pmt_to_long(channel); - if(pmt_eq(msg->port_id(), d_rx->port_symbol())) - d_rx_chan = pmt_to_long(channel); - } -} - -REGISTER_MBLOCK_CLASS(qa_tx_top); - -// ---------------------------------------------------------------------------------------------- - -class qa_rx_top : public mb_mblock -{ - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_max_capacity; - long d_ntx_chan, d_nrx_chan; - - long d_rx_chan; - - bool d_got_response_recv; - - mb_time d_t0; - double d_delta_t; - - public: - qa_rx_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_rx_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_allocation(mb_message_sptr msg); - void check_deallocation(mb_message_sptr msg); - void check_xmit(mb_message_sptr msg); - void check_cs(mb_message_sptr msg); - void run_tests(); -}; - -qa_rx_top::qa_rx_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg), - d_got_response_recv(false) -{ - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_dict = pmt_make_dict(); - // Set TX and RX interpolations - pmt_dict_set(usrp_dict, - pmt_intern("decim-rx"), - pmt_from_long(128)); - pmt_dict_set(usrp_dict, pmt_intern("fake-usrp"), PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_dict); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); -} - -qa_rx_top::~qa_rx_top(){} - -void -qa_rx_top::initial_transition() -{ - run_tests(); -} - -void -qa_rx_top::run_tests() -{ - if(verbose) - std::cout << "[qa_rx_top] Starting tests\n"; - - d_cs->send(s_cmd_open, pmt_list2(pmt_list2(s_response_open,PMT_T), pmt_from_long(0))); - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel,PMT_T), - pmt_from_long(1))); - - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_NIL, - pmt_from_long(0))); - - // Schedule a small timeout in which we expect to have received at least one - // packet worth of samples from the stub - d_t0 = mb_time::time(); - schedule_one_shot_timeout(d_t0 + 0.01, PMT_NIL); -} - - -void -qa_rx_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - if(pmt_eq(event, pmt_intern("%shutdown"))) - return; - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - // If we get a timeout we shutdown - if(pmt_eq(event, s_timeout)) { - if(verbose) - std::cout << "[qa_rx_top] Got timeout\n"; - d_rx->send(s_cmd_stop_recv_raw_samples, - pmt_list2(PMT_NIL, - pmt_from_long(0))); - - d_cs->send(s_cmd_close, pmt_list1(pmt_list2(s_response_close,PMT_T))); - return; - } - - // For testing RX, an invocation handle is not generated by the stub, - // therefore the same approach for testing is not used. We simply - // expect all responses to be true. - if(pmt_eq(event, s_response_recv_raw_samples)) { - if(pmt_eqv(status, PMT_T)) { - - if(verbose) - std::cout << "[qa_rx_top] Received expected response for message " - << " (" << event << ")\n"; - - // All we want is 1 response receive! Can't guarantee exact numbers - d_got_response_recv = true; - } - else { - if(verbose) - std::cout << "Got: " << status << " Expected: " << PMT_T << "\n"; - shutdown_all(PMT_F); - } - return; - } - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - if(verbose) - std::cout << "Got: " << status << " Expected: " << e_status << "\n"; - shutdown_all(PMT_F); - return; - } else { - if(verbose) - std::cout << "[qa_rx_top] Received expected response for message " - << " (" << event << ")\n"; - } - - if (pmt_eq(msg->port_id(), d_rx->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_allocate_channel)) - check_allocation(msg); - - } - - // We stop when we get a close, we are successful if we - // got a response from recv, fail if we never got a recv response - if(pmt_eq(msg->signal(), s_response_close)) { - - if(d_got_response_recv) { - shutdown_all(PMT_T); - return; - } - else { - shutdown_all(PMT_F); - if(verbose) - std::cout << "[qa_rx_top] No response message before close\n"; - return; - } - } -} - - -void -qa_rx_top::check_allocation(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t channel = pmt_nth(2, data); - - if(pmt_eqv(status, PMT_T)) { - // store all of the allocate channel numbers - if(pmt_eq(msg->port_id(), d_rx->port_symbol())) - d_rx_chan = pmt_to_long(channel); - } -} - -REGISTER_MBLOCK_CLASS(qa_rx_top); - -// ---------------------------------------------------------------------------------------------- - -class qa_rid_top : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_npongs; - long d_tcycles; - long d_cycles; - long d_max_rid; - - mb_time d_t0; - double d_delta_t; - - public: - qa_rid_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_rid_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void run_tests(); - void send_max_pings(); -}; - -qa_rid_top::qa_rid_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_npongs = 0; - d_tcycles = 3; - d_cycles = d_tcycles; - d_max_rid = usrp_server::D_MAX_RID; - d_delta_t = 0.1; - - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -qa_rid_top::~qa_rid_top(){} - -void -qa_rid_top::initial_transition() -{ - run_tests(); -} - -void -qa_rid_top::run_tests() -{ - if(verbose) - std::cout << "[qa_rid_top] Starting tests...\n"; - - // Retrieve information about the USRP, then run tests - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open, PMT_T), - pmt_from_long(0))); - - // should be able to allocate 1 byte - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - // Need to start receiving to read from the USRP to get C/S responses - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_NIL, - pmt_from_long(0))); - - // Build a subpacket of MAX_RID pings and wait a small amount for all of the - // responses and fire off another MAX_RID. If MAX_RID*2 responses are - // received, the RID recycling is working correctly. - // Schedule a timer in which we expect to have received all of the responses, - // which will send off another MAX_RID worth. - send_max_pings(); - d_t0 = mb_time::time(); - schedule_one_shot_timeout(d_t0 + d_delta_t, PMT_NIL); -} - -void -qa_rid_top::send_max_pings() -{ - pmt_t ping = pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(0), - pmt_from_long(0))); - - pmt_t sub_packets = PMT_NIL; - - for(int i=0; i<d_max_rid; i++) - sub_packets = pmt_list_add(sub_packets, ping); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - sub_packets)); -} - -void -qa_rid_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - // If we get a timeout we ensure we got a maximum RID number of responses. - if(pmt_eq(event, s_timeout)) { - if(verbose) - std::cout << "[qa_rid_top] Got timeout, received so far: " - << d_npongs << "\n"; - - d_cycles--; - - if(d_cycles==0 && d_npongs == d_max_rid*d_tcycles) { - shutdown_all(PMT_T); - } - else if(d_cycles==0) { - - std::cout << "[qa_rid_top] d_npongs: " << d_npongs - << " expected: " << d_max_rid*d_tcycles - << std::endl; - - shutdown_all(PMT_F); - } - else { - send_max_pings(); - d_t0 = mb_time::time(); - schedule_one_shot_timeout(d_t0 + d_delta_t, PMT_NIL); - } - - } - else if(pmt_eq(event, s_response_from_control_channel)) - { - d_npongs++; - } - -} - -REGISTER_MBLOCK_CLASS(qa_rid_top); - - -// ---------------------------------------------------------------------------------------------- - -class qa_cs_top : public mb_mblock -{ - mb_port_sptr d_tx; - mb_port_sptr d_rx; - mb_port_sptr d_cs; - - long d_nmsgs_to_recv; - long d_nrecvd; - - long d_max_capacity; - long d_ntx_chan, d_nrx_chan; - - long d_nstatus; - long d_nstatus_to_recv; - - public: - qa_cs_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg); - ~qa_cs_top(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - protected: - void check_message(mb_message_sptr msg); - void run_tests(); -}; - -qa_cs_top::qa_cs_top(mb_runtime *runtime, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(runtime, instance_name, user_arg) -{ - d_nrecvd=0; - d_nmsgs_to_recv = 8; - d_nstatus=0; - d_nstatus_to_recv = 50; - - d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL); - d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL); - d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL); - - // Use the stub with the usrp_server - pmt_t usrp_server_dict = pmt_make_dict(); - pmt_dict_set(usrp_server_dict, pmt_intern("fake-usrp"),PMT_T); - - // Test the TX side - define_component("server", "usrp_server", usrp_server_dict); - connect("self", "tx0", "server", "tx0"); - connect("self", "rx0", "server", "rx0"); - connect("self", "cs", "server", "cs"); - -} - -qa_cs_top::~qa_cs_top(){} - -void -qa_cs_top::initial_transition() -{ - run_tests(); -} - -void -qa_cs_top::run_tests() -{ - if(verbose) - std::cout << "[qa_cs_top] Starting tests...\n"; - - // Retrieve information about the USRP, then run tests - d_cs->send(s_cmd_open, - pmt_list2(pmt_list2(s_response_open, PMT_T), - pmt_from_long(0))); - - // should be able to allocate 1 byte - d_tx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - d_rx->send(s_cmd_allocate_channel, - pmt_list2(pmt_list2(s_response_allocate_channel, PMT_T), - pmt_from_long(1))); - - // Need to start receiving to read from the USRP to get C/S responses - d_rx->send(s_cmd_start_recv_raw_samples, - pmt_list2(PMT_NIL, - pmt_from_long(0))); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - pmt_list1( - pmt_list2(s_op_ping_fixed, - pmt_list2(pmt_from_long(3), - pmt_from_long(0)))))); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - pmt_list1( - pmt_list2(s_op_write_reg, - pmt_list2( - pmt_from_long(0x3), - pmt_from_long(0x4)))))); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - pmt_list1( - pmt_list2(s_op_write_reg_masked, - pmt_list3( - pmt_from_long(0x3), - pmt_from_long(0x4), - pmt_from_long(0x5)))))); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - pmt_list1( - pmt_list2(s_op_read_reg, - pmt_list2(pmt_from_long(0), - pmt_from_long(0x6)))))); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - pmt_list1( - pmt_list2(s_op_delay, - pmt_list1(pmt_from_long(0x7)))))); - - pmt_t subpackets = pmt_list5( - pmt_list2(s_op_ping_fixed, pmt_list2(pmt_from_long(0), pmt_from_long(0))), - pmt_list2(s_op_delay, pmt_list1(pmt_from_long(0x7))), - pmt_list2(s_op_write_reg_masked, pmt_list3(pmt_from_long(3), - pmt_from_long(4), - pmt_from_long(5))), - pmt_list2(s_op_write_reg, pmt_list2(pmt_from_long(3), - pmt_from_long(4))), - pmt_list2(s_op_read_reg, pmt_list2(pmt_from_long(0), - pmt_from_long(6))) - ); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - subpackets)); - - pmt_t i2c_data = pmt_make_u8vector(8, 0xff); - - subpackets = pmt_list2( - pmt_list2(s_op_i2c_write, - pmt_list2(pmt_from_long(8), i2c_data)), - pmt_list2(s_op_i2c_read, - pmt_list3(pmt_from_long(0), pmt_from_long(9), pmt_from_long(1))) - - ); - - d_tx->send(s_cmd_to_control_channel, - pmt_list2(pmt_list2(s_response_from_control_channel, PMT_T), - subpackets)); - -} - -void -qa_cs_top::handle_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - - if ((pmt_eq(msg->port_id(), d_tx->port_symbol()) - || pmt_eq(msg->port_id(), d_rx->port_symbol())) - && pmt_eq(msg->signal(), s_response_allocate_channel)) - check_message(msg); - - if (pmt_eq(msg->port_id(), d_tx->port_symbol()) - && pmt_eq(msg->signal(), s_response_from_control_channel)) - check_message(msg); - - if (pmt_eq(msg->port_id(), d_cs->port_symbol())) { - - if(pmt_eq(msg->signal(), s_response_max_capacity)) { - d_max_capacity = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_cs_top] USRP has max capacity of " - << d_max_capacity << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_ntx_chan)) { - d_ntx_chan = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_cs_top] USRP tx channels: " - << d_ntx_chan << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_nrx_chan)) { - d_nrx_chan = pmt_to_long(pmt_nth(2, data)); - if(verbose) - std::cout << "[qa_cs_top] USRP rx channels: " - << d_nrx_chan << "\n"; - } - else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) { - check_message(msg); - } - - d_nstatus++; - - check_message(msg); - - if(d_nstatus==d_nstatus_to_recv) - run_tests(); - } -} - -void -qa_cs_top::check_message(mb_message_sptr msg) -{ - pmt_t data = msg->data(); - pmt_t event = msg->signal(); - - pmt_t expected = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - - pmt_t e_event = pmt_nth(0, expected); - pmt_t e_status = pmt_nth(1, expected); - - d_nrecvd++; - - - if(!pmt_eqv(e_status, status) || !pmt_eqv(e_event, event)) { - if(verbose) - std::cout << "[qa_cs_top] Got: " << status << " Expected: " << e_status << "\n"; - shutdown_all(PMT_F); - return; - } else { - if(verbose) - std::cout << "[qa_cs_top] Received expected response for message " - << d_nrecvd << " (" << event << ")\n"; - } - - if(d_nrecvd == d_nmsgs_to_recv) - shutdown_all(PMT_T); -} - -REGISTER_MBLOCK_CLASS(qa_cs_top); - -// ---------------------------------------------------------------------------------------------- - -void -qa_inband_usrp_server::test_open_close() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n----------------------------\n"; - // std::cout << " RUNNING OPEN/CLOSE TESTS \n"; - - rt->run("top", "qa_open_close_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_chan_allocation() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n----------------------------\n"; - // std::cout << " RUNNING ALLOCATION TESTS \n"; - - rt->run("qa_alloc_top", "qa_alloc_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_chan_deallocation() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n----------------------------\n"; - // std::cout << " RUNNING DEALLOCATION TESTS \n"; - - rt->run("qa_dealloc_top", "qa_dealloc_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_tx() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n-----------------\n"; - // std::cout << " RUNNING TX TESTS \n"; - - rt->run("top", "qa_tx_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_rx() -{ - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n-----------------\n"; - // std::cout << " RUNNING RX TESTS \n"; - - rt->run("top", "qa_rx_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_cs() -{ - // FIXME This test is disabled because it hangs with the change to use usrp_standard_*_sptr's - return; - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n-----------------\n"; - // std::cout << " RUNNING CS TESTS \n"; - - rt->run("top", "qa_cs_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} - -void -qa_inband_usrp_server::test_rid() -{ - // FIXME This test is disabled because it hangs with the change to use usrp_standard_*_sptr's - return; - - mb_runtime_sptr rt = mb_make_runtime(); - pmt_t result = PMT_T; - - // std::cout << "\n\n-----------------\n"; - // std::cout << " RUNNING RID TESTS \n"; - - rt->run("top", "qa_rid_top", PMT_F, &result); - - CPPUNIT_ASSERT(pmt_equal(PMT_T, result)); -} diff --git a/usrp/limbo/inband/qa_inband_usrp_server.h b/usrp/limbo/inband/qa_inband_usrp_server.h deleted file mode 100644 index 52a4a0b067..0000000000 --- a/usrp/limbo/inband/qa_inband_usrp_server.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef QA_INBAND_USRP_SERVER_H -#define QA_INBAND_USRP_SERVER_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_inband_usrp_server : public CppUnit::TestCase { - - CPPUNIT_TEST_SUITE(qa_inband_usrp_server); - CPPUNIT_TEST(test_open_close); - CPPUNIT_TEST(test_chan_allocation); - CPPUNIT_TEST(test_chan_deallocation); - CPPUNIT_TEST(test_tx); - CPPUNIT_TEST(test_rx); - CPPUNIT_TEST(test_cs); - CPPUNIT_TEST(test_rid); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_chan_allocation(); - void test_chan_deallocation(); - void test_open_close(); - void test_tx(); - void test_rx(); - void test_cs(); - void test_rid(); -}; - -#endif /* INCLUDED_QA_INBAND_USRP_SERVER_H */ diff --git a/usrp/limbo/inband/symbols_usrp_channel.h b/usrp/limbo/inband/symbols_usrp_channel.h deleted file mode 100644 index a0114cf3c7..0000000000 --- a/usrp/limbo/inband/symbols_usrp_channel.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_CHANNEL_H -#define INCLUDED_SYMBOLS_USRP_CHANNEL_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_allocate_channel = pmt_intern("cmd-allocate-channel"); -static pmt_t s_cmd_deallocate_channel = pmt_intern("cmd-deallocate-channel"); - -// Incoming -static pmt_t s_response_allocate_channel = pmt_intern("response-allocate-channel"); -static pmt_t s_response_deallocate_channel = pmt_intern("response-deallocate-channel"); - -// Errors -static pmt_t s_err_requested_capacity_unavailable = pmt_intern("err-requested-capacity-unavailable"); -static pmt_t s_err_channel_unavailable = pmt_intern("err-channel-unavailable"); -static pmt_t s_err_channel_invalid = pmt_intern("err-channel-invalid"); -static pmt_t s_err_channel_permission_denied = pmt_intern("err-channel-permission-denied"); - -#endif /* INCLUDED_SYMBOLS_USRP_CHANNEL_H */ diff --git a/usrp/limbo/inband/symbols_usrp_interface_cs.h b/usrp/limbo/inband/symbols_usrp_interface_cs.h deleted file mode 100644 index 72c8fcc91d..0000000000 --- a/usrp/limbo/inband/symbols_usrp_interface_cs.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_INTERFACE_CS_H -#define INCLUDED_SYMBOLS_USRP_INTERFACE_CS_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_usrp_open = pmt_intern("cmd-usrp-open"); -static pmt_t s_cmd_usrp_close = pmt_intern("cmd-usrp-close"); -static pmt_t s_cmd_usrp_ntx_chan = pmt_intern("cmd-usrp-ntx-chan"); -static pmt_t s_cmd_usrp_nrx_chan = pmt_intern("cmd-usrp-nrx-chan"); -static pmt_t s_cmd_usrp_write = pmt_intern("cmd-usrp-write"); -static pmt_t s_cmd_usrp_start_reading = pmt_intern("cmd-usrp-start-reading"); -static pmt_t s_cmd_usrp_stop_reading = pmt_intern("cmd-usrp-stop-reading"); - -// Incoming -static pmt_t s_response_usrp_open = pmt_intern("response-usrp-open"); -static pmt_t s_response_usrp_close = pmt_intern("response-usrp-close"); -static pmt_t s_response_usrp_ntx_chan = pmt_intern("response-usrp-ntx-chan"); -static pmt_t s_response_usrp_nrx_chan = pmt_intern("response-usrp-nrx-chan"); -static pmt_t s_response_usrp_write = pmt_intern("response-usrp-write"); -static pmt_t s_response_usrp_read = pmt_intern("response-usrp-read"); - -#endif /* INCLUDED_SYMBOLS_USRP_INTERFACE_CS_H */ diff --git a/usrp/limbo/inband/symbols_usrp_low_level_cs.h b/usrp/limbo/inband/symbols_usrp_low_level_cs.h deleted file mode 100644 index a7260603a6..0000000000 --- a/usrp/limbo/inband/symbols_usrp_low_level_cs.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_LOW_LEVEL_CS_H -#define INCLUDED_SYMBOLS_USRP_LOW_LEVEL_CS_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_to_control_channel = pmt_intern("cmd-to-control-channel"); - -// Incoming -static pmt_t s_response_from_control_channel = pmt_intern("response-from-control-channel"); - -// Subpackets -static pmt_t s_op_ping_fixed = pmt_intern("op-ping-fixed"); -static pmt_t s_op_ping_fixed_reply = pmt_intern("op-ping-fixed-reply"); -static pmt_t s_op_write_reg = pmt_intern("op-write-reg"); -static pmt_t s_op_write_reg_masked = pmt_intern("op-write-reg-masked"); -static pmt_t s_op_read_reg = pmt_intern("op-read-reg"); -static pmt_t s_op_read_reg_reply = pmt_intern("op-read-reg-reply"); -static pmt_t s_op_i2c_write = pmt_intern("op-i2c-write"); -static pmt_t s_op_i2c_read = pmt_intern("op-i2c-read"); -static pmt_t s_op_i2c_read_reply = pmt_intern("op-i2c-read-reply"); -static pmt_t s_op_spi_write = pmt_intern("op-spi-write"); -static pmt_t s_op_spi_read = pmt_intern("op-spi-read"); -static pmt_t s_op_spi_read_reply = pmt_intern("op-spi-read-reply"); -static pmt_t s_op_delay = pmt_intern("op-delay"); - -#endif /* INCLUDED_SYMBOLS_USRP_LOW_LEVEL_CS_H */ diff --git a/usrp/limbo/inband/symbols_usrp_rx.h b/usrp/limbo/inband/symbols_usrp_rx.h deleted file mode 100644 index 07d58a3f56..0000000000 --- a/usrp/limbo/inband/symbols_usrp_rx.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_RX_H -#define INCLUDED_SYMBOLS_USRP_RX_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_start_recv_raw_samples = pmt_intern("cmd-start-recv-raw-samples"); -static pmt_t s_cmd_stop_recv_raw_samples = pmt_intern("cmd-stop-recv-raw-samples"); - -// Incoming -static pmt_t s_response_recv_raw_samples = pmt_intern("response-recv-raw-samples"); - -// Errors -static pmt_t s_err_already_receiving = pmt_intern("err-already-receiving"); - -#endif /* INCLUDED_SYMBOLS_USRP_RX_H */ diff --git a/usrp/limbo/inband/symbols_usrp_rx_cs.h b/usrp/limbo/inband/symbols_usrp_rx_cs.h deleted file mode 100644 index bf4f0338b6..0000000000 --- a/usrp/limbo/inband/symbols_usrp_rx_cs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_RX_CS_H -#define INCLUDED_SYMBOLS_USRP_RX_CS_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_usrp_rx_start_reading = pmt_intern("cmd-usrp-rx-start-reading"); - -// Incoming -static pmt_t s_response_usrp_rx_read = pmt_intern("response-usrp-rx-read"); - -#endif /* INCLUDED_SYMBOLS_USRP_RX_CS_H */ diff --git a/usrp/limbo/inband/symbols_usrp_server_cs.h b/usrp/limbo/inband/symbols_usrp_server_cs.h deleted file mode 100644 index e612e24ea7..0000000000 --- a/usrp/limbo/inband/symbols_usrp_server_cs.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_SERVER_CS_H -#define INCLUDED_SYMBOLS_USRP_SERVER_CS_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_open = pmt_intern("cmd-open"); -static pmt_t s_cmd_close = pmt_intern("cmd-close"); -static pmt_t s_cmd_max_capacity = pmt_intern("cmd-max-capacity"); -static pmt_t s_cmd_ntx_chan = pmt_intern("cmd-ntx-chan"); -static pmt_t s_cmd_nrx_chan = pmt_intern("cmd-nrx-chan"); -static pmt_t s_cmd_current_capacity_allocation = pmt_intern("cmd-current-capacity-allocation"); - -// Incoming -static pmt_t s_response_open = pmt_intern("response-open"); -static pmt_t s_response_close = pmt_intern("response-close"); -static pmt_t s_response_max_capacity = pmt_intern("response-max-capacity"); -static pmt_t s_response_ntx_chan = pmt_intern("response-ntx-chan"); -static pmt_t s_response_nrx_chan = pmt_intern("response-nrx-chan"); -static pmt_t s_response_current_capacity_allocation = pmt_intern("response-current-capacity-allocation"); - -// Errors -static pmt_t s_err_usrp_not_opened = pmt_intern("err-usrp-not-opened"); -static pmt_t s_err_usrp_already_opened = pmt_intern("err-usrp-already-opened"); -static pmt_t s_err_usrp_already_closed = pmt_intern("err-usrp-already-closed"); - -#endif /* INCLUDED_SYMBOLS_USRP_SERVER_CS_H */ diff --git a/usrp/limbo/inband/symbols_usrp_tx.h b/usrp/limbo/inband/symbols_usrp_tx.h deleted file mode 100644 index 4e58e2cf95..0000000000 --- a/usrp/limbo/inband/symbols_usrp_tx.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_TX_H -#define INCLUDED_SYMBOLS_USRP_TX_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_xmit_raw_frame = pmt_intern("cmd-xmit-raw-frame"); - -// Incoming -static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame"); - -#endif /* INCLUDED_SYMBOLS_USRP_TX_H */ diff --git a/usrp/limbo/inband/symbols_usrp_tx_cs.h b/usrp/limbo/inband/symbols_usrp_tx_cs.h deleted file mode 100644 index d02ef1d269..0000000000 --- a/usrp/limbo/inband/symbols_usrp_tx_cs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_SYMBOLS_USRP_TX_CS_H -#define INCLUDED_SYMBOLS_USRP_TX_CS_H - -#include <pmt.h> - -// Outgoing -static pmt_t s_cmd_usrp_tx_write = pmt_intern("cmd-usrp-tx-write"); - -// Incoming -static pmt_t s_response_usrp_tx_write = pmt_intern("response-usrp-tx-write"); - -#endif /* INCLUDED_SYMBOLS_USRP_TX_CS_H */ diff --git a/usrp/limbo/inband/test_inband.cc b/usrp/limbo/inband/test_inband.cc deleted file mode 100644 index 77cdca556f..0000000000 --- a/usrp/limbo/inband/test_inband.cc +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include <cppunit/TextTestRunner.h> -#include <qa_inband.h> - -int -main(int argc, char **argv) -{ - - CppUnit::TextTestRunner runner; - - runner.addTest(qa_inband::suite ()); - - bool was_successful = runner.run("", false); - - return was_successful ? 0 : 1; -} diff --git a/usrp/limbo/inband/usb_packet.py b/usrp/limbo/inband/usb_packet.py deleted file mode 100644 index 6dfcf8638c..0000000000 --- a/usrp/limbo/inband/usb_packet.py +++ /dev/null @@ -1,115 +0,0 @@ -# -# Copyright 2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio 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 3, or (at your option) -# any later version. -# -# GNU Radio 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -import struct - - -FL_OVERRUN = 0x80000000 -FL_UNDERRUN = 0x40000000 -FL_DROPPED = 0x20000000 -FL_END_OF_BURST = 0x10000000 -FL_START_OF_BURST = 0x08000000 - -FL_ALL_FLAGS = 0xf8000000 - -FL_OVERRUN_SHIFT = 31 -FL_UNDERRUN_SHIFT = 30 -FL_DROPPED_SHIFT = 29 -FL_END_OF_BURST_SHIFT = 28 -FL_START_OF_BURST_SHIFT = 27 - -RSSI_MASK = 0x3f -RSSI_SHIFT = 21 - -CHAN_MASK = 0x1f -CHAN_SHIFT = 16 - -TAG_MASK = 0xf -TAG_SHIFT = 9 - -PAYLOAD_LEN_MASK = 0x1ff -PAYLOAD_LEN_SHIFT = 0 - -def make_header(flags, chan, payload_len, timestamp, rssi=0, tag=0): - word0 = ((flags & FL_ALL_FLAGS) - | ((rssi & RSSI_MASK) << RSSI_SHIFT) - | ((chan & CHAN_MASK) << CHAN_SHIFT) - | ((tag & TAG_MASK) << TAG_SHIFT) - | ((payload_len & PAYLOAD_LEN_MASK) << PAYLOAD_LEN_SHIFT)) - word1 = timestamp - return struct.pack('<2I', word0, word1) - - -def _decode(pred, indicator): - if pred: - return indicator - else: - return '-' - - -class usb_packet(object): - def __init__(self, raw_pkt): - assert isinstance(raw_pkt, str) and len(raw_pkt) == 512 - self._raw_pkt = raw_pkt; - (self._word0, self._word1) = struct.unpack('<2I', self._raw_pkt[0:8]) - - def timestamp(self): - return self._word1 - - def rssi(self): - return (self._word0 >> RSSI_SHIFT) & RSSI_MASK - - def chan(self): - return (self._word0 >> CHAN_SHIFT) & CHAN_MASK - - def tag(self): - return (self._word0 >> TAG_SHIFT) & TAG_MASK - - def payload_len(self): - return (self._word0 >> PAYLOAD_LEN_SHIFT) & PAYLOAD_LEN_MASK - - def flags(self): - return self._word0 & FL_ALL_FLAGS - - def overrun(self): - return (self._word0 >> FL_OVERRUN_SHIFT) & 0x1 - - def underrun(self): - return (self._word0 >> FL_UNDERRUN_SHIFT) & 0x1 - - def start_of_burst(self): - return (self._word0 >> FL_START_OF_BURST_SHIFT) & 0x1 - - def end_of_burst(self): - return (self._word0 >> FL_END_OF_BURST_SHIFT) & 0x1 - - def dropped(self): - return (self._word0 >> FL_DROPPED_SHIFT) & 0x1 - - def payload(self): - return self._raw_pkt[8:8+self.payload_len()] - - def decoded_flags(self): - s = (_decode(self.overrun(), 'O') - + _decode(self.underrun(), 'U') - + _decode(self.dropped(), 'D') - + _decode(self.end_of_burst(), 'E') - + _decode(self.start_of_burst(), 'S')) - return s diff --git a/usrp/limbo/inband/usrp_inband_usb_packet.cc b/usrp/limbo/inband/usrp_inband_usb_packet.cc deleted file mode 100644 index 72bc45ccbf..0000000000 --- a/usrp/limbo/inband/usrp_inband_usb_packet.cc +++ /dev/null @@ -1,793 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_inband_usb_packet.h> - -#include <usrp_bytesex.h> -#include <iostream> -#include <stdio.h> -#include <string.h> - -/*! - * \brief Aligns the packet payload on a 32 bit boundary. This is essential to - * all control/status packets so that the inband FPGA code can parse them - * easily. - * - * \returns true if successful or if the packet was already aligned; false if it - * cannot be aligned. - */ -bool usrp_inband_usb_packet::align32() -{ - int p_len = payload_len(); - - int bytes_needed = 4 - (p_len % 4); - - if(bytes_needed == 4) - return true; - - // If the room left in the packet is less than the number of bytes - // needed, return false to indicate no room to align - if((MAX_PAYLOAD - p_len) < bytes_needed) - return false; - - incr_header_len(bytes_needed); - - return true; -} - -/*! - * \brief Adds a ping command to the current control packet. - * - * The \p rid is the rid to be associated with the ping response and \p ping_val - * is currently unused. - * - * \returns true if adding the ping command was successful, false otherwise - * (i.e. no space in the current packet). - */ -bool usrp_inband_usb_packet::cs_ping(long rid, long ping_val) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_PING_LEN + CS_FIXED_LEN)) - return false; - - uint32_t ping = ( - ((OP_PING_FIXED & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_PING_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | (ping_val & CS_PINGVAL_MASK) - - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(ping); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_PING_LEN); - - return true; -} - -/*! - * \brief Adds a ping response to the packet. This is used by the fake USRP - * code to generate fake responses for pings. - * - * The \p rid is the RID to be associated with the response and \p ping_val is - * currently unused. - * - * \returns true if the ping reply was added successfully, false otherwise. - */ -bool usrp_inband_usb_packet::cs_ping_reply(long rid, long ping_val) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_PING_LEN + CS_FIXED_LEN)) - return false; - - uint32_t ping = ( - ((OP_PING_FIXED_REPLY & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_PING_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | ((ping_val & CS_PINGVAL_MASK) << CS_PINGVAL_SHIFT) - - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(ping); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_PING_LEN); - - return true; -} - -/*! - * \brief Adds a write register command to the packet. - * - * The \p reg_num is the register number for which the value \p val will be - * written to. - * - * \returns true if the command was added to the packet successfully, false - * otherwise. - */ -bool usrp_inband_usb_packet::cs_write_reg(long reg_num, long val) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_WRITEREG_LEN + CS_FIXED_LEN)) - return false; - - uint32_t word0 = 0; - - // Build the first word which includes the register number - word0 = ( - ((OP_WRITE_REG & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_WRITEREG_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((reg_num & CS_REGNUM_MASK) << CS_REGNUM_SHIFT) - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // The second word is solely the register value to be written - // FIXME: should this be unsigned? - payload += 1; - *payload = host_to_usrp_u32((uint32_t) val); - - // Rebuild the header to update the payload length - incr_header_len(CS_FIXED_LEN + CS_WRITEREG_LEN); - - return true; -} - -/*! - * \brief Adds a write register masked command to the packet. - * - * The \p reg_num is the register number for which the value \p val will be - * written, masked by \p mask - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_write_reg_masked(long reg_num, long val, long mask) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_WRITEREGMASKED_LEN + CS_FIXED_LEN)) - return false; - - uint32_t word0 = 0; - - // Build the first word which includes the register number - word0 = ( - ((OP_WRITE_REG_MASKED & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_WRITEREGMASKED_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((reg_num & CS_REGNUM_MASK) << CS_REGNUM_SHIFT) - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // Skip over the first word and write the register value - payload += 1; - *payload = host_to_usrp_u32((uint32_t) val); - - // Skip over the register value and write the mask - payload += 1; - *payload = host_to_usrp_u32((uint32_t) mask); - - // Rebuild the header to update the payload length - incr_header_len(CS_FIXED_LEN + CS_WRITEREGMASKED_LEN); - - return true; -} - -/*! - * \brief Adds a read register message to the packet. - * - * The \p rid will be the associated RID returned with the response, and \p - * reg_num is the register to be read. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_read_reg(long rid, long reg_num) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_READREG_LEN + CS_FIXED_LEN)) - return false; - - uint32_t read_reg = ( - ((OP_READ_REG & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_READREG_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | ((reg_num & CS_REGNUM_MASK) << CS_REGNUM_SHIFT) - - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(read_reg); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_READREG_LEN); - - return true; -} - -/*! - * \brief Adds a read register reply response to the current packet. This is - * used by the fake USRP code to generate fake register read responses for - * testing. - * - * The \p rid is the associated RID to be included in the response, \p reg_num - * is the register the read is coming from, and \p reg_val is the value of the - * read. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_read_reg_reply(long rid, long reg_num, long reg_val) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_READREGREPLY_LEN + CS_FIXED_LEN)) - return false; - - uint32_t word0 = ( - ((OP_READ_REG_REPLY & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_READREGREPLY_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | ((reg_num & CS_REGNUM_MASK) << CS_REGNUM_SHIFT) - - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // Hop to the next word and write the reg value - payload += 1; - *payload = host_to_usrp_u32((uint32_t) reg_val); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_READREGREPLY_LEN); - - return true; -} - -/*! - * \brief Adds a delay command to the current packet. - * - * The \p ticks parameter is the number of clock ticks the FPGA should delay - * parsing for, which is added to the packet. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_delay(long ticks) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_DELAY_LEN + CS_FIXED_LEN)) - return false; - - uint32_t delay = ( - ((OP_DELAY & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_DELAY_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((ticks & CS_DELAY_MASK) << CS_DELAY_SHIFT) - - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(delay); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_DELAY_LEN); - - return true; -} - -/*! - * \brief - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_i2c_write(long i2c_addr, uint8_t *i2c_data, size_t data_len) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - int i2c_len = data_len + 2; // 2 bytes between mbz and addr - - if((MAX_PAYLOAD - p_len) < (i2c_len + CS_FIXED_LEN)) - return false; - - uint32_t word0 = 0; - - word0 = ( - ((OP_I2C_WRITE & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((i2c_len & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((i2c_addr & CS_I2CADDR_MASK) << CS_I2CADDR_SHIFT) - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // Jump over the first word and write the data - // FIXME: Should the data be changed to usrp byte order? - payload += 1; - memcpy(payload, i2c_data, data_len); - - // Update payload length - incr_header_len(CS_FIXED_LEN + i2c_len); - - return true; -} - -/*! - * \brief Adds an I2C read command to the current packet. - * - * The \p rid is the associated RID to return with the read response, \p - * i2c_addr is the address to read from on the I2C bus, and \p n_bytes is the - * number of bytes to be read from the bus. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_i2c_read(long rid, long i2c_addr, long n_bytes) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_I2CREAD_LEN + CS_FIXED_LEN)) - return false; - - uint32_t word0 = 0; - - word0 = ( - ((OP_I2C_READ & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_I2CREAD_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | ((i2c_addr & CS_I2CADDR_MASK) << CS_I2CADDR_SHIFT) - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // Jump a word and write the number of bytes to read - payload += 1; - uint32_t word1 = - (n_bytes & CS_I2CREADBYTES_MASK) << CS_I2CREADBYTES_SHIFT; - *payload = host_to_usrp_u32(word1); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_I2CREAD_LEN); - - return true; -} - -/*! - * \brief Adds an I2C read reply response to the current packet. This is used - * by the fake USRP code to generate fake I2C responses. - * - * The \p rid is the RID to be associated with the response, \p i2c_addr is the - * address on the I2C bus that the \p i2c_data of \p i2c_data_len was read from. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_i2c_read_reply(long rid, long i2c_addr, uint8_t *i2c_data, long i2c_data_len) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - int i2c_len = i2c_data_len + 2; - - if((MAX_PAYLOAD - p_len) < (i2c_len + CS_FIXED_LEN)) - return false; - - uint32_t word0 = 0; - - word0 = ( - ((OP_I2C_READ_REPLY & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((i2c_len & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - | ((i2c_addr & CS_I2CADDR_MASK) << CS_I2CADDR_SHIFT) - ); - - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word0); - - // Jump a word and write the actual data - payload += 1; - memcpy(payload, i2c_data, i2c_data_len); - - // Update payload length - incr_header_len(CS_FIXED_LEN + i2c_len); - - return true; -} - -/*! - * \brief Adds a SPI write command to the current packet. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_spi_write(long enables, long format, long opt_header_bytes, uint8_t *spi_data, long spi_data_len) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - int spi_len = spi_data_len + 6; - - if((MAX_PAYLOAD - p_len) < (spi_len + CS_FIXED_LEN)) - return false; - - uint32_t word = 0; - - // First word contains the opcode and length, then mbz - word = ( - ((OP_SPI_WRITE & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((spi_len & CS_LEN_MASK) << CS_LEN_SHIFT) - ); - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - payload += 1; - - // Second word contains the enables, format, and optional tx bytes - word = 0; - word = ( - ((enables & CS_SPIENABLES_MASK) << CS_SPIENABLES_SHIFT) - | ((format & CS_SPIFORMAT_MASK) << CS_SPIFORMAT_SHIFT) - | ((opt_header_bytes & CS_SPIOPT_MASK) << CS_SPIOPT_SHIFT) - ); - payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - payload += 1; - memcpy(payload, spi_data, spi_data_len); - - // Update payload length - incr_header_len(CS_FIXED_LEN + spi_len); - - return true; -} - -/*! - * \brief Adds a SPI bus read command to the packet. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_spi_read(long rid, long enables, long format, long opt_header_bytes, long n_bytes) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - if((MAX_PAYLOAD - p_len) < (CS_SPIREAD_LEN + CS_FIXED_LEN)) - return false; - - uint32_t word = 0; - - // First word contains the opcode, length, and RID - word = ( - ((OP_SPI_READ & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((CS_SPIREAD_LEN & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - ); - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - payload += 1; - - // Second word contains the enables, format, and optional tx bytes - word = 0; - word = ( - ((enables & CS_SPIENABLES_MASK) << CS_SPIENABLES_SHIFT) - | ((format & CS_SPIFORMAT_MASK) << CS_SPIFORMAT_SHIFT) - | ((opt_header_bytes & CS_SPIOPT_MASK) << CS_SPIOPT_SHIFT) - ); - payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - payload += 1; - - // The third word contains the number of bytes - word = 0; - word = ( - ((n_bytes & CS_SPINBYTES_MASK) << CS_SPINBYTES_SHIFT) - ); - payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - // Update payload length - incr_header_len(CS_FIXED_LEN + CS_SPIREAD_LEN); - - return true; -} - -/*! - * \brief Adds an SPI read reply to the current packet. This is used by the - * fake USRP code to generate fake responses for SPI reads. - * - * \returns true if the command was added to the packet, false otherwise. - */ -bool usrp_inband_usb_packet::cs_spi_read_reply(long rid, uint8_t *spi_data, long spi_data_len) -{ - if(!align32()) - return false; - - int p_len = payload_len(); - - int spi_len = spi_data_len + 2; - - if((MAX_PAYLOAD - p_len) < (spi_len + CS_FIXED_LEN)) - return false; - - uint32_t word = 0; - - // First word contains the opcode, length, and RID - word = ( - ((OP_SPI_READ_REPLY & CS_OPCODE_MASK) << CS_OPCODE_SHIFT) - | ((spi_len & CS_LEN_MASK) << CS_LEN_SHIFT) - | ((rid & CS_RID_MASK) << CS_RID_SHIFT) - ); - uint32_t *payload = (uint32_t *) (d_payload + p_len); - *payload = host_to_usrp_u32(word); - - // Jump a word and write the actual data - payload += 1; - memcpy(payload, spi_data, spi_data_len); - - // Update payload length - incr_header_len(CS_FIXED_LEN + spi_len); - - return true; -} - -/*! - * \brief Since all control packets contain subpackets which have the length of - * the subpacket at a uniform location in the subpacket, this will return the - * subpacket length given a byte offset of the start of the subpacket from the beginning of the packet. - * - * \returns the length of the subpacket - */ -int usrp_inband_usb_packet::cs_len(int payload_offset) { - uint32_t subpkt = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset))); - return (subpkt >> CS_LEN_SHIFT) & CS_LEN_MASK; -} - -/*! - * \brief The following method takes an offset within the packet payload to - * extract a control/status subpacket and constructs a pmt response which - * includes the proper signal and arguments specified by usrp-low-level-cs. The - * USRP server could therefore use this to read subpackets and pass them - * responses back up to the application. It's arguable that only reply packets - * should be parsed here, however we parse others for use in debugging or - * failure reporting on the transmit side of packets. - */ -pmt_t usrp_inband_usb_packet::read_subpacket(int payload_offset) { - - uint32_t subpkt = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset))); - uint32_t opcode = (subpkt >> CS_OPCODE_SHIFT) & CS_OPCODE_MASK; - uint32_t len = (subpkt >> CS_LEN_SHIFT) & CS_LEN_MASK; - - switch(opcode) { - - case OP_PING_FIXED_REPLY: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t pingval = pmt_from_long((subpkt >> CS_PINGVAL_SHIFT) & CS_PINGVAL_MASK); - return pmt_list3(s_op_ping_fixed_reply, rid, pingval); - } - - case OP_READ_REG_REPLY: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t reg_num = pmt_from_long((subpkt >> CS_REGNUM_SHIFT) & CS_REGNUM_MASK); - - // To get the register value we just read the next 32 bits - uint32_t val = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - pmt_t reg_val = pmt_from_long(val); - - return pmt_list4(s_op_read_reg_reply, rid, reg_num, reg_val); - } - - case OP_I2C_READ_REPLY: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t i2c_addr = pmt_from_long((subpkt >> CS_I2CADDR_SHIFT) & CS_I2CADDR_MASK); - - // Make a u8 vector to dump the data from the packet into - size_t i2c_data_len; - pmt_t i2c_data = pmt_make_u8vector(len - 2, 0); // skip rid+mbz+addr = 2 bytes - uint8_t *w_data = - (uint8_t *) pmt_u8vector_writable_elements(i2c_data, i2c_data_len); - - memcpy(w_data, d_payload + payload_offset + 4, i2c_data_len); // skip first word - - return pmt_list4(s_op_i2c_read_reply, rid, i2c_addr, i2c_data); - } - - case OP_SPI_READ_REPLY: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - - // Make a u8 vector to dump the data from the packet into - size_t spi_data_len; - pmt_t spi_data = pmt_make_u8vector(len - 2, 0); // skip rid+mbz+addr = 2 bytes - uint8_t *w_data = - (uint8_t *) pmt_u8vector_writable_elements(spi_data, spi_data_len); - - memcpy(w_data, d_payload + payload_offset + 4, spi_data_len); // skip first word - - return pmt_list3(s_op_spi_read_reply, rid, spi_data); - } - - case OP_PING_FIXED: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t pingval = pmt_from_long((subpkt >> CS_PINGVAL_SHIFT) & CS_PINGVAL_MASK); - return pmt_list3(s_op_ping_fixed, rid, pingval); - } - - case OP_WRITE_REG: - { - pmt_t reg_num = pmt_from_long((subpkt >> CS_REGNUM_SHIFT) & CS_REGNUM_MASK); - - // To get the register value we just read the next 32 bits - uint32_t val = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - pmt_t reg_val = pmt_from_long(val); - - return pmt_list3(s_op_write_reg, reg_num, reg_val); - } - - case OP_WRITE_REG_MASKED: - { - pmt_t reg_num = pmt_from_long((subpkt >> CS_REGNUM_SHIFT) & CS_REGNUM_MASK); - - // To get the register value we just read the next 32 bits - uint32_t val = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - pmt_t reg_val = pmt_from_long(val); - - // The mask is the next 32 bits - uint32_t mask = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 8))); - pmt_t reg_mask = pmt_from_long(mask); - - return pmt_list4(s_op_write_reg_masked, reg_num, reg_val, reg_mask); - } - - case OP_READ_REG: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t reg_num = pmt_from_long((subpkt >> CS_REGNUM_SHIFT) & CS_REGNUM_MASK); - - return pmt_list3(s_op_read_reg, rid, reg_num); - } - - case OP_I2C_WRITE: - { - pmt_t i2c_addr = pmt_from_long((subpkt >> CS_I2CADDR_SHIFT) & CS_I2CADDR_MASK); - - // The length includes an extra 2 bytes for storing the mbz and addr - pmt_t i2c_data = pmt_make_u8vector(len-2, 0); - - // Get a writable address to copy the data from the packet - size_t ignore; - uint8_t *w_data = (uint8_t *) pmt_u8vector_writable_elements(i2c_data, ignore); - memcpy(w_data, d_payload + payload_offset + 4, len-2); - - - return pmt_list3(s_op_i2c_write, i2c_addr, i2c_data); - } - - case OP_I2C_READ: - { - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - pmt_t i2c_addr = pmt_from_long((subpkt >> CS_I2CADDR_SHIFT) & CS_I2CADDR_MASK); - - // The number of bytes is in the next word - uint32_t bytes = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - bytes = (bytes >> CS_I2CREADBYTES_SHIFT) & CS_I2CREADBYTES_MASK; - pmt_t i2c_bytes = pmt_from_long(bytes); - - return pmt_list4(s_op_i2c_read, rid, i2c_addr, i2c_bytes); - } - - case OP_SPI_WRITE: - { - // Nothing interesting in the first word, skip to the next - uint32_t word = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - pmt_t enables = pmt_from_long((word >> CS_SPIENABLES_SHIFT) & CS_SPIENABLES_MASK); - pmt_t format = pmt_from_long((word >> CS_SPIFORMAT_SHIFT) & CS_SPIFORMAT_MASK); - pmt_t opt = pmt_from_long((word >> CS_SPIOPT_SHIFT) & CS_SPIOPT_MASK); - - // From the next word and on is data - size_t spi_data_len; - pmt_t spi_data = pmt_make_u8vector(len - 6, 0); // skip rid+mbz+addr = 2 bytes - uint8_t *w_data = - (uint8_t *) pmt_u8vector_writable_elements(spi_data, spi_data_len); - - memcpy(w_data, d_payload + payload_offset + 8, spi_data_len); // skip first 2 words - - return pmt_list5(s_op_spi_write, enables, format, opt, spi_data); - } - - case OP_SPI_READ: - { - // Read the RID from the first word, the rest is mbz - pmt_t rid = pmt_from_long((subpkt >> CS_RID_SHIFT) & CS_RID_MASK); - - // Continue at the next word... - uint32_t word = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 4))); - pmt_t enables = pmt_from_long((word >> CS_SPIENABLES_SHIFT) & CS_SPIENABLES_MASK); - pmt_t format = pmt_from_long((word >> CS_SPIFORMAT_SHIFT) & CS_SPIFORMAT_MASK); - pmt_t opt = pmt_from_long((word >> CS_SPIOPT_SHIFT) & CS_SPIOPT_MASK); - - // The number of bytes is the only thing to read in the next word - word = usrp_to_host_u32(*((uint32_t *)(d_payload + payload_offset + 8))); - pmt_t n_bytes = pmt_from_long((word >> CS_SPINBYTES_SHIFT) & CS_SPINBYTES_MASK); - - return pmt_list6(s_op_spi_read, rid, enables, format, opt, n_bytes); - } - - case OP_DELAY: - { - pmt_t ticks = pmt_from_long((subpkt >> CS_DELAY_SHIFT) & CS_DELAY_MASK); - - return pmt_list2(s_op_delay, ticks); - } - - default: - return PMT_NIL; - - } -} - diff --git a/usrp/limbo/inband/usrp_inband_usb_packet.h b/usrp/limbo/inband/usrp_inband_usb_packet.h deleted file mode 100644 index 6f1a3feb3e..0000000000 --- a/usrp/limbo/inband/usrp_inband_usb_packet.h +++ /dev/null @@ -1,240 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef INCLUDED_USRP_INBAND_USB_PACKET_H_ -#define INCLUDED_USRP_INBAND_USB_PACKET_H_ - -#include <usrp_bytesex.h> -#include <mblock/mblock.h> -#include <pmt.h> -#include <iostream> - -#include <symbols_usrp_low_level_cs.h> - -static const int USB_PKT_SIZE = 512; // bytes -static const int MAX_PAYLOAD = USB_PKT_SIZE-2*sizeof(uint32_t); -static const int CONTROL_CHAN = 0x1f; - -class usrp_inband_usb_packet { - // - // keep raw packet in USRP-endian order - // - uint32_t d_word0; - uint32_t d_timestamp; - unsigned char d_payload[MAX_PAYLOAD]; - -public: - - enum opcodes { - OP_PING_FIXED = 0x00, - OP_PING_FIXED_REPLY = 0x01, - OP_WRITE_REG = 0x02, - OP_WRITE_REG_MASKED = 0x03, - OP_READ_REG = 0x04, - OP_READ_REG_REPLY = 0x05, - OP_I2C_WRITE = 0x06, - OP_I2C_READ = 0x07, - OP_I2C_READ_REPLY = 0x08, - OP_SPI_WRITE = 0x09, - OP_SPI_READ = 0x0a, - OP_SPI_READ_REPLY = 0x0b, - OP_DELAY = 0x0c - }; - - enum flags { - FL_OVERRUN = 0x80000000, - FL_UNDERRUN = 0x40000000, - FL_DROPPED = 0x20000000, - FL_START_OF_BURST = 0x10000000, - FL_END_OF_BURST = 0x08000000, - FL_CARRIER_SENSE = 0x04000000, - - FL_ALL_FLAGS = 0xfc000000 - }; - - static const int FL_OVERRUN_SHIFT = 31; - static const int FL_UNDERRUN_SHIFT = 30; - static const int FL_DROPPED_SHIFT = 29; - static const int FL_END_OF_BURST_SHIFT = 27; - static const int FL_START_OF_BURST_SHIFT = 28; - - static const int RSSI_MASK = 0x3f; - static const int RSSI_SHIFT = 21; - - static const int CHAN_MASK = 0x1f; - static const int CHAN_SHIFT = 16; - - static const int TAG_MASK = 0xf; - static const int TAG_SHIFT = 9; - - static const int PAYLOAD_LEN_MASK = 0x1ff; - static const int PAYLOAD_LEN_SHIFT = 0; - - // Fixed size for opcode and length fields - static const int CS_FIXED_LEN = 2; - - static const int CS_OPCODE_MASK = 0xff; - static const int CS_OPCODE_SHIFT = 24; - - static const int CS_LEN_MASK = 0xff; - static const int CS_LEN_SHIFT = 16; - - static const int CS_RID_MASK = 0x3f; - static const int CS_RID_SHIFT = 10; - - static const int CS_PING_LEN = 2; - static const int CS_PINGVAL_MASK = 0x3ff; - static const int CS_PINGVAL_SHIFT = 0; - - static const int CS_WRITEREG_LEN = 6; - static const int CS_WRITEREGMASKED_LEN = 10; - static const int CS_READREG_LEN = 2; - static const int CS_READREGREPLY_LEN = 6; - static const int CS_REGNUM_MASK = 0x3ff; - static const int CS_REGNUM_SHIFT = 0; - - static const int CS_DELAY_LEN = 2; - static const int CS_DELAY_MASK = 0xffff; - static const int CS_DELAY_SHIFT = 0; - - static const int CS_I2CADDR_MASK = 0x7f; - static const int CS_I2CADDR_SHIFT = 0; - - static const int CS_I2CREAD_LEN = 3; - static const int CS_I2CREADBYTES_MASK = 0x7f; - static const int CS_I2CREADBYTES_SHIFT = 24; - - static const int CS_SPIOPT_MASK = 0xffff; - static const int CS_SPIOPT_SHIFT = 0; - static const int CS_SPIFORMAT_MASK = 0xff; - static const int CS_SPIFORMAT_SHIFT = 16; - static const int CS_SPIENABLES_MASK = 0xff; - static const int CS_SPIENABLES_SHIFT = 24; - static const int CS_SPIREAD_LEN = 7; - static const int CS_SPINBYTES_MASK = 0xff; - static const int CS_SPINBYTES_SHIFT = 24; - -public: - - void set_timestamp(uint32_t timestamp){ - d_timestamp = host_to_usrp_u32(timestamp); - } - - void set_end_of_burst() { - uint32_t word0 = usrp_to_host_u32(d_word0); - word0 |= 1<<FL_END_OF_BURST_SHIFT; - d_word0 = host_to_usrp_u32(word0); - } - - void set_header(int flags, int chan, int tag, int payload_len){ - uint32_t word0 = ((flags & FL_ALL_FLAGS) - | ((chan & CHAN_MASK) << CHAN_SHIFT) - | ((tag & TAG_MASK) << TAG_SHIFT) - | ((payload_len & PAYLOAD_LEN_MASK) << PAYLOAD_LEN_SHIFT)); - d_word0 = host_to_usrp_u32(word0); - } - - void incr_header_len(int val) { - set_header(flags(), chan(), tag(), payload_len() + val); - } - - uint32_t timestamp() const { - return usrp_to_host_u32(d_timestamp); - } - - int rssi() const { - uint32_t word0 = usrp_to_host_u32(d_word0); - return (word0 >> RSSI_SHIFT) & RSSI_MASK; - } - - int chan() const { - uint32_t word0 = usrp_to_host_u32(d_word0); - return (word0 >> CHAN_SHIFT) & CHAN_MASK; - } - - int tag() const { - uint32_t word0 = usrp_to_host_u32(d_word0); - return (word0 >> TAG_SHIFT) & TAG_MASK; - } - - int payload_len() const { - uint32_t word0 = usrp_to_host_u32(d_word0); - return (word0 >> PAYLOAD_LEN_SHIFT) & PAYLOAD_LEN_MASK; - } - - int flags() const { - return usrp_to_host_u32(d_word0) & FL_ALL_FLAGS; - } - - int overrun() const { - return (usrp_to_host_u32(d_word0) & FL_OVERRUN) >> FL_OVERRUN_SHIFT; - } - - - int underrun() const { - return (usrp_to_host_u32(d_word0) & FL_UNDERRUN) >> FL_UNDERRUN_SHIFT; - } - - - int start_of_burst() const { - return (usrp_to_host_u32(d_word0) & FL_START_OF_BURST) >> FL_START_OF_BURST_SHIFT; - } - - int end_of_burst() const { - return (usrp_to_host_u32(d_word0) & FL_END_OF_BURST) >> FL_END_OF_BURST_SHIFT; - } - - int dropped() const { - return (usrp_to_host_u32(d_word0) & FL_DROPPED) >> FL_DROPPED_SHIFT; - } - - unsigned char *payload() { - return d_payload; - } - - static int max_payload() { - return MAX_PAYLOAD; - } - - static int max_pkt_size() { - return USB_PKT_SIZE; - } - - // C/S methods - bool align32(); - bool cs_ping(long rid, long ping_val); - bool cs_ping_reply(long rid, long ping_val); - bool cs_write_reg(long reg_num, long val); - bool cs_write_reg_masked(long reg_num, long val, long mask); - bool cs_read_reg(long rid, long reg_num); - bool cs_read_reg_reply(long rid, long reg_num, long reg_val); - bool cs_delay(long ticks); - bool cs_i2c_write(long i2c_addr, uint8_t *i2c_data, size_t data_len); - bool cs_i2c_read(long rid, long i2c_addr, long n_bytes); - bool cs_i2c_read_reply(long rid, long i2c_addr, uint8_t *i2c_data, long i2c_data_len); - bool cs_spi_write(long enables, long format, long opt_header_bytes, uint8_t *spi_data, long spi_data_len); - bool cs_spi_read(long rid, long enables, long format, long opt_header_bytes, long n_bytes); - bool cs_spi_read_reply(long rid, uint8_t *spi_data, long spi_data_len); - int cs_len(int payload_offset); - pmt_t read_subpacket(int payload_offset); -}; - -#endif diff --git a/usrp/limbo/inband/usrp_interface.mbh b/usrp/limbo/inband/usrp_interface.mbh deleted file mode 100644 index ad0f78b4e1..0000000000 --- a/usrp/limbo/inband/usrp_interface.mbh +++ /dev/null @@ -1,88 +0,0 @@ -;; -*- scheme -*- ; not really, but tells emacs how to format this -;; -;; Copyright 2007 Free Software Foundation, Inc. -;; -;; This file is part of GNU Radio -;; -;; GNU Radio 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, or (at your option) -;; any later version. -;; -;; GNU Radio 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., -;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -;; - -;; ---------------------------------------------------------------- -;; This is an mblock header file -;; -;; The format is very much a work-in-progress. -;; It'll be compiled to C++. -;; ---------------------------------------------------------------- - -;; ---------------------------------------------------------------- -;; usrp-interface-cs -;; -;; Handles interaction between the usrp_sever and the USB interface - -(define-protocol-class usrp-interface-cs - - (:outgoing - (cmd-usrp-open invocation-handle which-usrp) - (cmd-usrp-close invocation-handle) - (cmd-usrp-ntx-chan invocation-handle) - (cmd-usrp-nrx-chan invocation-handle) - (cmd-usrp-write invocation-handle channel data) - (cmd-usrp-start-reading invocation-handle channel) - ) - - (:incoming - (response-usrp-open invocation-handle status) - (response-usrp-close invocation-handle status) - (response-usrp-ntx-chan invocation-handle ntx-chan) - (response-usrp-nrx-chan invocation-handle nrx-chan) - (response-usrp-write invocation-handle status channel) - (response-usrp-read invocation-handle status data) - ) - ) - -;; ---------------------------------------------------------------- -;; usrp-tx-cs -;; -;; Handles interaction between the USB interface and TX interface - -(define-protocol-class usrp-tx-cs - - (:outgoing - (cmd-usrp-tx-write invocation-handle channel data tx-handle) - ) - - (:incoming - (response-usrp-tx-write invocation-handle status channel) - ) - ) - -;; ---------------------------------------------------------------- -;; usrp-rx-cs -;; -;; Handles interaction between the USB interface and RX interface - -(define-protocol-class usrp-rx-cs - - (:outgoing - (cmd-usrp-rx-start-reading invocation-handle rx-handle) - (cmd-usrp-rx-stop-reading invocation-handle) - ) - - (:incoming - (response-usrp-rx-read invocation-handle status data) - - ;; There is currently no response to a stop reading - ) - ) diff --git a/usrp/limbo/inband/usrp_rx.cc b/usrp/limbo/inband/usrp_rx.cc deleted file mode 100644 index fe9486cf66..0000000000 --- a/usrp/limbo/inband/usrp_rx.cc +++ /dev/null @@ -1,184 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_rx.h> - -#include <usrp_standard.h> -#include <iostream> -#include <vector> -#include <usb.h> -#include <mblock/class_registry.h> -#include <usrp_inband_usb_packet.h> -#include <fpga_regs_common.h> -#include <stdio.h> - -#include <symbols_usrp_rx_cs.h> - -typedef usrp_inband_usb_packet transport_pkt; - -static const bool verbose = false; - -bool usrp_rx_stop; - -usrp_rx::usrp_rx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_disk_write(false), - d_disk_write_pkt(false) // if true, writes full packet, else just the payload -{ - d_cs = define_port("cs", "usrp-rx-cs", true, mb_port::EXTERNAL); - - if(d_disk_write) { - d_ofile0.open("rx_data_chan0.dat",std::ios::binary|std::ios::out); - d_ofile1.open("rx_data_chan1.dat",std::ios::binary|std::ios::out); - d_cs_ofile.open("rx_cs.dat",std::ios::binary|std::ios::out); - } - - usrp_rx_stop = false; - -} - -usrp_rx::~usrp_rx() -{ - if(d_disk_write) { - d_ofile0.close(); - d_ofile1.close(); - d_cs_ofile.close(); - } -} - -void -usrp_rx::initial_transition() -{ - -} - -/*! - * \brief Handles incoming signals to to the m-block, wihch should only ever be - * a single message: cmd-usrrp-rx-start-reading. There is no signal to stop - * reading as the m-block goes in to a forever loop to read inband packets from - * the bus. - */ -void -usrp_rx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t port_id = msg->port_id(); - pmt_t data = msg->data(); - - // Theoretically only have 1 message to ever expect, but - // want to make sure its at least what we want - if(pmt_eq(port_id, d_cs->port_symbol())) { - - if(pmt_eqv(event, s_cmd_usrp_rx_start_reading)) - read_and_respond(data); - } -} - -/*! - * \brief Performs the actual reading of data from the USB bus, called by - * handle_message() when a cmd-usrp-rx-start-reading signal is received. - * - * The method enters a forever loop where it continues to read data from the bus - * and generate read responses to the higher layer. Currently, shared memory is - * used to exit this loop. - * - * The \p data parameter is a PMT list which contains only a single element, an - * invocation handle which will be returned with all read respones. - */ -void -usrp_rx::read_and_respond(pmt_t data) -{ - size_t ignore; - bool underrun; - unsigned int n_read; - unsigned int pkt_size = sizeof(transport_pkt); - - pmt_t invocation_handle = pmt_nth(0, data); - - // Need the handle to the RX port to send responses, this is passed - // by the USRP interface m-block - pmt_t handle = pmt_nth(1, data); - d_urx = - boost::any_cast<usrp_standard_rx_sptr>(pmt_any_ref(handle)); - - if(verbose) - std::cout << "[usrp_rx] Waiting for packets..\n"; - - // Read by 512 which is packet size and send them back up - while(!usrp_rx_stop) { - - pmt_t v_pkt = pmt_make_u8vector(pkt_size, 0); - transport_pkt *pkt = - (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, ignore); - - n_read = d_urx->read(pkt, pkt_size, &underrun); - - if(n_read != pkt_size) { - std::cerr << "[usrp_rx] Error reading packet, shutting down\n"; - d_cs->send(s_response_usrp_rx_read, - pmt_list3(PMT_NIL, PMT_F, PMT_NIL)); - return; - } - - if(underrun && verbose && 0) - std::cout << "[usrp_rx] Underrun\n"; - - d_cs->send(s_response_usrp_rx_read, - pmt_list3(PMT_NIL, PMT_T, v_pkt)); - if(verbose && 0) - std::cout << "[usrp_rx] Read 1 packet\n"; - - if(d_disk_write) { - if(pkt->chan() == CONTROL_CHAN) - d_cs_ofile.write((const char *)pkt, transport_pkt::max_pkt_size()); - else { - if(d_disk_write_pkt) { - if(pkt->chan() == 0) - d_ofile0.write((const char *)pkt, transport_pkt::max_pkt_size()); - else if(pkt->chan() == 1) - d_ofile1.write((const char *)pkt, transport_pkt::max_pkt_size()); - } else { - if(pkt->chan() == 0) - d_ofile0.write((const char *)pkt->payload(), transport_pkt::max_payload()); - else if(pkt->chan() == 1) - d_ofile1.write((const char *)pkt->payload(), transport_pkt::max_payload()); - } - } - - d_cs_ofile.flush(); - d_ofile0.flush(); - d_ofile1.flush(); - } - } - - usrp_rx_stop = false; - - if(verbose) { - std::cout << "[USRP_RX] Stopping...\n"; - fflush(stdout); - } -} - -REGISTER_MBLOCK_CLASS(usrp_rx); diff --git a/usrp/limbo/inband/usrp_rx.h b/usrp/limbo/inband/usrp_rx.h deleted file mode 100644 index 1006235bf2..0000000000 --- a/usrp/limbo/inband/usrp_rx.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_RX_H -#define INCLUDED_USRP_RX_H - -#include <mblock/mblock.h> -#include <fstream> -#include "usrp_standard.h" - -extern bool usrp_rx_stop; // used to communicate a 'stop' to the RX stub - -/*! - * \brief Implements the low level usb interface to the USRP - */ -class usrp_rx : public mb_mblock -{ - mb_port_sptr d_cs; - usrp_standard_rx_sptr d_urx; - - bool d_disk_write; - bool d_disk_write_pkt; - std::ofstream d_ofile0; - std::ofstream d_ofile1; - std::ofstream d_cs_ofile; - - public: - usrp_rx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_rx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - private: - void read_and_respond(pmt_t data); - void read_data(); - -}; - - -#endif /* INCLUDED_USRP_RX_H */ - diff --git a/usrp/limbo/inband/usrp_rx_stub.cc b/usrp/limbo/inband/usrp_rx_stub.cc deleted file mode 100644 index e5c454d24b..0000000000 --- a/usrp/limbo/inband/usrp_rx_stub.cc +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_rx_stub.h> - -#include <iostream> -#include <vector> -#include <usb.h> -#include <mblock/class_registry.h> -#include <usrp_inband_usb_packet.h> -#include <fpga_regs_common.h> -#include "usrp_standard.h" -#include <stdio.h> -#include <string.h> -#include <ui_nco.h> -#include <fstream> - -#include <symbols_usrp_rx_cs.h> - -typedef usrp_inband_usb_packet transport_pkt; - -static const bool verbose = false; - -bool usrp_rx_stop_stub; - -// Used for the fake control packet response code to send the responses back up -// the RX. The TX stub dumps responses in to this queue. -std::queue<pmt_t> d_cs_queue; - -usrp_rx_stub::usrp_rx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_samples_per_frame((long)(126)), - d_decim_rx(128), - d_amplitude(16384), - d_disk_write(false) -{ - - // Information about the rates are passed all the way from the app in the form - // of a dictionary. We use this to read the RX decimation rate and compute - // the approximate number of MS/s as a form of flow control for the stub. - pmt_t usrp_dict = user_arg; - - if (pmt_is_dict(usrp_dict)) { - // Read the RX decimation rate - if(pmt_t decim_rx = pmt_dict_ref(usrp_dict, - pmt_intern("decim-rx"), - PMT_NIL)) { - if(!pmt_eqv(decim_rx, PMT_NIL)) - d_decim_rx = pmt_to_long(decim_rx); - } - } - - d_cs = define_port("cs", "usrp-rx-cs", true, mb_port::EXTERNAL); - - // initialize NCO - double freq = 100e3; - int interp = 32; // 32 -> 4MS/s - double sample_rate = 64e6 / interp; - d_nco.set_freq(2*M_PI * freq/sample_rate); - - //d_disk_write = true; - - if(d_disk_write) - d_ofile.open("raw_rx.dat",std::ios::binary|std::ios::out); - - usrp_rx_stop_stub = false; -} - -usrp_rx_stub::~usrp_rx_stub() -{ - if(d_disk_write) - d_ofile.close(); -} - -void -usrp_rx_stub::initial_transition() -{ -} - -void -usrp_rx_stub::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t port_id = msg->port_id(); - pmt_t data = msg->data(); - - if (pmt_eq(msg->signal(), s_timeout) - && !pmt_eq(msg->data(), s_done)) { - - if(!usrp_rx_stop_stub) - read_and_respond(); - else { // requested to stop - cancel_timeout(msg->metadata()); - usrp_rx_stop_stub=false; - if(verbose) - std::cout << "[USRP_RX_STUB] Stopping RX stub\n"; - } - - } - - // Theoretically only have 1 message to ever expect, but - // want to make sure its at least what we want - if(pmt_eq(port_id, d_cs->port_symbol()) - && pmt_eqv(event, s_cmd_usrp_rx_start_reading)) { - - if(verbose) - std::cout << "[USRP_RX_STUB] Starting with decim @ " - << d_decim_rx << std::endl; - - start_packet_timer(); - } -} - -// Setup a periodic timer which will drive packet generation -void -usrp_rx_stub::start_packet_timer() -{ - d_t0 = mb_time::time(); // current time - - // Calculate the inter-packet arrival time. - double samples_per_sec = (64.0/(double)d_decim_rx)*1000000.0; - double frames_per_sec = samples_per_sec / (double)d_samples_per_frame; - double frame_rate = 1.0 / frames_per_sec; - - if(verbose) { - std::cout << "[USRP_RX_STUB] Scheduling periodic packet generator\n"; - std::cout << "\tsamples_per_sec: " << samples_per_sec << std::endl; - std::cout << "\tframes_per_sec: " << frames_per_sec << std::endl; - std::cout << "\tframe_rate: " << frame_rate << std::endl; - } - - schedule_periodic_timeout(d_t0 + frame_rate, mb_time(frame_rate), PMT_T); -} - -void -usrp_rx_stub::read_and_respond() -{ - - long nsamples_this_frame = d_samples_per_frame; - - size_t nshorts = 2 * nsamples_this_frame; // 16-bit I & Q - long channel = 0; - long n_bytes = nshorts*2; - pmt_t uvec = pmt_make_s16vector(nshorts, 0); - size_t ignore; - int16_t *samples = pmt_s16vector_writable_elements(uvec, ignore); - - // fill in the complex sinusoid - - for (int i = 0; i < nsamples_this_frame; i++){ - - if (1){ - gr_complex s; - d_nco.sincos(&s, 1, d_amplitude); - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - else { - gr_complex s(d_amplitude, d_amplitude); - - // write 16-bit i & q - samples[2*i] = (int16_t) s.real(); - samples[2*i+1] = (int16_t) s.imag(); - } - } - - if(d_disk_write) - d_ofile.write((const char *)samples, n_bytes); - - pmt_t v_pkt = pmt_make_u8vector(sizeof(transport_pkt), 0); - transport_pkt *pkt = - (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, ignore); - - pkt->set_header(0, channel, 0, n_bytes); - pkt->set_timestamp(0xffffffff); - memcpy(pkt->payload(), samples, n_bytes); - - d_cs->send(s_response_usrp_rx_read, pmt_list3(PMT_NIL, PMT_T, v_pkt)); - - // Now lets check the shared CS queue between the TX and RX stub. Each - // element in a queue is a list where the first element is an invocation - // handle and the second element is a PMT u8 vect representation of the - // CS packet response which can just be passed transparently. - while(!d_cs_queue.empty()) { - - pmt_t cs_pkt = d_cs_queue.front(); - d_cs_queue.pop(); - - pmt_t invocation_handle = pmt_nth(0, cs_pkt); - pmt_t v_pkt = pmt_nth(1, cs_pkt); - - d_cs->send(s_response_usrp_rx_read, - pmt_list3(invocation_handle, - PMT_T, - v_pkt)); // Take the front CS pkt - - - if(verbose) - std::cout << "[USRP_RX_STUB] Received CS response from TX stub\n"; - } - -} - -REGISTER_MBLOCK_CLASS(usrp_rx_stub); diff --git a/usrp/limbo/inband/usrp_rx_stub.h b/usrp/limbo/inband/usrp_rx_stub.h deleted file mode 100644 index 238b4568f6..0000000000 --- a/usrp/limbo/inband/usrp_rx_stub.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_RX_STUB_H -#define INCLUDED_USRP_RX_STUB_H - -#include <mblock/mblock.h> -#include <vector> -#include "usrp_standard.h" -#include <ui_nco.h> -#include <fstream> -#include <queue> -#include <usrp_inband_usb_packet.h> - -typedef usrp_inband_usb_packet transport_pkt; - -extern bool usrp_rx_stop_stub; // used to communicate a 'stop' to the RX stub -extern std::queue<pmt_t> d_cs_queue; - -static pmt_t s_timeout = pmt_intern("%timeout"); -static pmt_t s_done = pmt_intern("done"); - -/*! - * \brief Implements the low level usb interface to the USRP - */ -class usrp_rx_stub : public mb_mblock -{ - public: - - mb_port_sptr d_cs; - usrp_standard_rx* d_urx; - - long d_samples_per_frame; - long d_decim_rx; - - mb_time d_t0; - double d_delta_t; - - // for generating sine wave output - ui_nco<float,float> d_nco; - double d_amplitude; - - bool d_disk_write; - - std::ofstream d_ofile; - - public: - usrp_rx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_rx_stub(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - private: - void read_and_respond(); - void read_data(); - void start_packet_timer(); - -}; - - -#endif /* INCLUDED_USRP_RX_H */ - diff --git a/usrp/limbo/inband/usrp_server.cc b/usrp/limbo/inband/usrp_server.cc deleted file mode 100644 index 4f5f396b44..0000000000 --- a/usrp/limbo/inband/usrp_server.cc +++ /dev/null @@ -1,1861 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <usrp_server.h> -#include <iostream> -#include <usrp_inband_usb_packet.h> -#include <mblock/class_registry.h> -#include <vector> -#include <usrp_usb_interface.h> -#include <string.h> -#include <fpga_regs_common.h> -#include <fpga_regs_standard.h> - -#include <symbols_usrp_server_cs.h> -#include <symbols_usrp_channel.h> -#include <symbols_usrp_tx.h> -#include <symbols_usrp_rx.h> -#include <symbols_usrp_low_level_cs.h> -#include <symbols_usrp_interface_cs.h> - -static pmt_t s_shutdown = pmt_intern("%shutdown"); - -typedef usrp_inband_usb_packet transport_pkt; // makes conversion to gigabit easy - -const static bool verbose = false; - -static std::string -str(long x) -{ - std::ostringstream s; - s << x; - return s.str(); -} - -usrp_server::usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_fpga_debug(false), - d_interp_tx(128), // these should match the lower level defaults (rx also) - d_decim_rx(128), - d_fake_rx(false) -{ - if(verbose) - std::cout << "[USRP_SERVER] Initializing...\n"; - - // Dictionary for arguments to all of the components - d_usrp_dict = user_arg; - - if (pmt_is_dict(d_usrp_dict)) { - - if(pmt_t fpga_debug = pmt_dict_ref(d_usrp_dict, - pmt_intern("fpga-debug"), - PMT_NIL)) { - if(pmt_eqv(fpga_debug, PMT_T)) - d_fpga_debug=true; - } - - // Read the TX interpolations - if(pmt_t interp_tx = pmt_dict_ref(d_usrp_dict, - pmt_intern("interp-tx"), - PMT_NIL)) { - if(!pmt_eqv(interp_tx, PMT_NIL)) - d_interp_tx = pmt_to_long(interp_tx); - } - - // Read the RX decimation rate - if(pmt_t decim_rx = pmt_dict_ref(d_usrp_dict, - pmt_intern("decim-rx"), - PMT_NIL)) { - if(!pmt_eqv(decim_rx, PMT_NIL)) - d_decim_rx = pmt_to_long(decim_rx); - } - } - - // control & status port - d_cs = define_port("cs", "usrp-server-cs", true, mb_port::EXTERNAL); - d_cs_usrp = define_port("cs_usrp", "usrp-interface-cs", false, mb_port::INTERNAL); - - // ports - // - // (if/when we do replicated ports, these will be replaced by a - // single replicated port) - for(int port=0; port < N_PORTS; port++) { - - d_tx.push_back(define_port("tx"+str(port), - "usrp-tx", - true, - mb_port::EXTERNAL)); - - d_rx.push_back(define_port("rx"+str(port), - "usrp-rx", - true, - mb_port::EXTERNAL)); - } - - define_component("usrp", "usrp_usb_interface", d_usrp_dict); - connect("self", "cs_usrp", "usrp", "cs"); - - d_defer=false; - d_opened=false; - - // FIXME: needs to be returned from open, if we want to use this - d_nrx_chan = 2; - d_ntx_chan = 2; - - // Initialize capacity on each channel to 0 and to no owner - // Also initialize the USRP standard tx/rx pointers to NULL - for(int chan=0; chan < d_ntx_chan; chan++) - d_chaninfo_tx.push_back(channel_info()); - - for(int chan=0; chan < d_nrx_chan; chan++) - d_chaninfo_rx.push_back(channel_info()); - - d_rx_chan_mask = 0; - - for(int i=0; i < D_MAX_RID; i++) - d_rids.push_back(rid_info()); - - //d_fake_rx=true; -} - -/*! - * \brief resets the assigned capacity and owners of each RX and TX channel from - * allocations. - */ -void -usrp_server::reset_channels() -{ - - for(int chan=0; chan < d_ntx_chan; chan++) { - d_chaninfo_tx[chan].assigned_capacity = 0; - d_chaninfo_tx[chan].owner = PMT_NIL; - } - - for(int chan=0; chan < d_nrx_chan; chan++) { - d_chaninfo_rx[chan].assigned_capacity = 0; - d_chaninfo_rx[chan].owner = PMT_NIL; - } - - d_rx_chan_mask = 0; -} - -usrp_server::~usrp_server() -{ -} - - -void -usrp_server::initial_transition() -{ - // the initial transition -} - -/*! - * \brief Reads all incoming messages to USRP server from the TX, RX, and the CS - * ports. This drives the state of USRP server and dispatches based on the - * message. - */ -void -usrp_server::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); // the "name" of the message - pmt_t port_id = msg->port_id(); // which port it came in on - pmt_t data = msg->data(); - pmt_t invocation_handle; - pmt_t metadata = msg->metadata(); - pmt_t status; - - long port; - - if (pmt_eq(event, s_shutdown)) // ignore (for now) - return; - - invocation_handle = pmt_nth(0, data); - - if (0){ - std::cout << "[USRP_SERVER] event: " << event << std::endl; - std::cout << "[USRP_SERVER] port_id: " << port_id << std::endl; - } - - // It would be nice if this were all table driven, and we could compute our - // state transition as f(current_state, port_id, signal) - - // A message from the USRP CS, which should *only* be responses - // - // It is important that this set come before checking messages of any other - // components. This is since we always want to listen to the low level USRP - // server, even if we aren't initialized we are waiting for responses to - // become initialized. Likewise, after the usrp_server is "closed", we still - // want to pass responses back from the low level. - - //---------------- USRP RESPONSE ---------------// - if (pmt_eq(port_id, d_cs_usrp->port_symbol())) { - - //-------------- USRP OPEN ------------------// - if(pmt_eq(event, s_response_usrp_open)) { - // pass the response back over the regular CS port - pmt_t status = pmt_nth(1, data); - d_cs->send(s_response_open, pmt_list2(invocation_handle, status)); - - //reset_all_registers(); - //initialize_registers(); - - if(pmt_eqv(status,PMT_T)) { - d_opened = true; - d_defer = false; - recall_defer_queue(); - } - - return; - } - //------------- USRP CLOSE -------------------// - else if (pmt_eq(event, s_response_usrp_close)) { - pmt_t status = pmt_nth(1, data); - d_cs->send(s_response_close, pmt_list2(invocation_handle, status)); - - if(pmt_eqv(status,PMT_T)) { - d_opened = false; - d_defer = false; - reset_channels(); - recall_defer_queue(); - } - - return; - } - //--------------- USRP WRITE --------------// - else if (pmt_eq(event, s_response_usrp_write)) { - - pmt_t status = pmt_nth(1, data); - long channel = pmt_to_long(pmt_nth(2, data)); - long port; - - // Do not report back responses if they were generated from a - // command packet - if(channel == CONTROL_CHAN) - return; - - // Find the port through the owner of the channel - if((port = tx_port_index(d_chaninfo_tx[channel].owner)) !=-1 ){ - d_tx[port]->send(s_response_xmit_raw_frame, - pmt_list2(invocation_handle, status)); - return; - } - } - //--------------- USRP READ ---------------// - else if (pmt_eq(event, s_response_usrp_read)) { - - pmt_t status = pmt_nth(1, data); - - if(!pmt_eqv(status, PMT_T)) { - std::cerr << "[USRP_SERVER] Error receiving packet\n"; - return; - } - else { - handle_response_usrp_read(data); - return; - } - } - - goto unhandled; - } - - // Checking for defer on all other messages - if(d_defer) { - if (verbose) - std::cout << "[USRP_SERVER] Received msg while deferring (" - << msg->signal() << ")\n"; - d_defer_queue.push(msg); - return; - } - - //--------- CONTROL / STATUS ------------// - if (pmt_eq(port_id, d_cs->port_symbol())){ - - //----------- OPEN -----------// - if (pmt_eq(event, s_cmd_open)){ - - // Reject if already open - if(d_opened) { - d_cs->send(s_response_open, pmt_list2(invocation_handle, s_err_usrp_already_opened)); - return; - } - - // the parameters are the same to the low level interface, so we just pass 'data' along - d_cs_usrp->send(s_cmd_usrp_open, data); - - d_defer = true; - - return; - } - //---------- CLOSE -----------// - else if (pmt_eq(event, s_cmd_close)){ - - if(!d_opened) { - d_cs->send(s_response_close, pmt_list2(invocation_handle, s_err_usrp_already_closed)); - return; - } - - d_defer = true; - d_cs_usrp->send(s_cmd_usrp_close, pmt_list1(invocation_handle)); - - return; - } - //---------- MAX CAPACITY ----------// - else if (pmt_eq(event, s_cmd_max_capacity)) { - - if(!d_opened) { - d_cs->send(s_response_max_capacity, - pmt_list3(invocation_handle, s_err_usrp_not_opened, pmt_from_long(0))); - return; - } - - d_cs->send(s_response_max_capacity, - pmt_list3(invocation_handle, - PMT_T, - pmt_from_long(max_capacity()))); - return; - } - //---------- NTX CHAN --------------// - else if (pmt_eq(event, s_cmd_ntx_chan)) { - - if(!d_opened) { - d_cs->send(s_response_ntx_chan, - pmt_list3(invocation_handle, s_err_usrp_not_opened, pmt_from_long(0))); - return; - } - - d_cs->send(s_response_ntx_chan, - pmt_list3(invocation_handle, - PMT_T, - pmt_from_long(d_ntx_chan))); - return; - } - //---------- NRX CHAN -----------// - else if (pmt_eq(event, s_cmd_nrx_chan)) { - - if(!d_opened) { - d_cs->send(s_response_nrx_chan, - pmt_list3(invocation_handle, s_err_usrp_not_opened, pmt_from_long(0))); - return; - } - - d_cs->send(s_response_nrx_chan, - pmt_list3(invocation_handle, - PMT_T, - pmt_from_long(d_nrx_chan))); - return; - } - //--------- ALLOCATION? -----------// - else if (pmt_eq(event, s_cmd_current_capacity_allocation)) { - - if(!d_opened) { - d_cs->send(s_response_current_capacity_allocation, - pmt_list3(invocation_handle, - s_err_usrp_not_opened, - pmt_from_long(0))); - return; - } - - d_cs->send(s_response_current_capacity_allocation, - pmt_list3(invocation_handle, - PMT_T, - pmt_from_long(current_capacity_allocation()))); - return; - } - goto unhandled; - } - - //-------------- TX ---------------// - if ((port = tx_port_index(port_id)) != -1) { - - //------------ ALLOCATE (TX) ----------------// - if (pmt_eq(event, s_cmd_allocate_channel)){ - - if(!d_opened) { - d_tx[port]->send(s_response_allocate_channel, - pmt_list3(invocation_handle, - s_err_usrp_not_opened, - pmt_from_long(0))); - return; - } - - handle_cmd_allocate_channel(d_tx[port], d_chaninfo_tx, data); - return; - } - - //----------- DEALLOCATE (TX) ---------------// - if (pmt_eq(event, s_cmd_deallocate_channel)) { - - if(!d_opened) { - d_tx[port]->send(s_response_deallocate_channel, - pmt_list3(invocation_handle, - s_err_usrp_not_opened, - pmt_from_long(0))); - return; - } - - handle_cmd_deallocate_channel(d_tx[port], d_chaninfo_tx, data); - return; - } - - //-------------- XMIT RAW FRAME -----------------/ - if (pmt_eq(event, s_cmd_xmit_raw_frame)){ - - if(!d_opened) { - d_tx[port]->send(s_response_xmit_raw_frame, - pmt_list2(invocation_handle, s_err_usrp_not_opened)); - return; - } - - handle_cmd_xmit_raw_frame(d_tx[port], d_chaninfo_tx, data); - return; - } - - //-------------- CONTROL PACKET -----------------/ - if (pmt_eq(event, s_cmd_to_control_channel)) { - - if(!d_opened) { - d_tx[port]->send(s_response_xmit_raw_frame, - pmt_list2(invocation_handle, s_err_usrp_not_opened)); - return; - } - - handle_cmd_to_control_channel(d_tx[port], d_chaninfo_tx, data); - return; - - } - - goto unhandled; - } - - //-------------- RX ---------------// - if ((port = rx_port_index(port_id)) != -1) { - - //------------ ALLOCATE (RX) ----------------// - if (pmt_eq(event, s_cmd_allocate_channel)) { - - if(!d_opened) { - d_rx[port]->send(s_response_allocate_channel, - pmt_list3(invocation_handle, - s_err_usrp_not_opened, - pmt_from_long(0))); - return; - } - - handle_cmd_allocate_channel(d_rx[port], d_chaninfo_rx, data); - return; - } - - //----------- DEALLOCATE (RX) ---------------// - if (pmt_eq(event, s_cmd_deallocate_channel)) { - - if(!d_opened) { - d_rx[port]->send(s_response_deallocate_channel, - pmt_list3(invocation_handle, - s_err_usrp_not_opened, - pmt_from_long(0))); - return; - } - - handle_cmd_deallocate_channel(d_rx[port], d_chaninfo_rx, data); - return; - } - - //-------------- START RECV ----------------// - if (pmt_eq(event, s_cmd_start_recv_raw_samples)) { - - if(!d_opened) { - d_rx[port]->send(s_response_recv_raw_samples, - pmt_list2(invocation_handle, s_err_usrp_not_opened)); - return; - } - - handle_cmd_start_recv_raw_samples(d_rx[port], d_chaninfo_rx, data); - return; - } - - //-------------- STOP RECV ----------------// - if (pmt_eq(event, s_cmd_stop_recv_raw_samples)) { - - if(!d_opened) - return; - - // FIX ME : no response for stopping? even if error? (permissions) - handle_cmd_stop_recv_raw_samples(d_rx[port], d_chaninfo_rx, data); - - return; - } - - goto unhandled; - } - - unhandled: - std::cout << "[USRP_SERVER] unhandled msg: " << msg << std::endl; -} - -/*! - * \brief Takes a port_symbol() as parameter \p port_id and is used to determine - * if the port is a TX port, or to find an index in the d_tx vector which stores - * the port. - * - * \returns -1 if \p port_id is not in the d_tx vector (i.e., it's not a TX - * port), otherwise returns an index in the d_tx vector which stores the port. - */ -int usrp_server::tx_port_index(pmt_t port_id) { - - for(int i=0; i < (int) d_tx.size(); i++) - if(pmt_eq(d_tx[i]->port_symbol(), port_id)) - return i; - - return -1; -} - -/*! - * \brief Takes a port_symbol() as parameter \p port_id and is used to determine - * if the port is an RX port, or to find an index in the d_rx vector which - * stores the port. - * - * \returns -1 if \p port_id is not in the d_rx vector (i.e., it's not an RX - * port), otherwise returns an index in the d_rx vector which stores the port. - */ -int usrp_server::rx_port_index(pmt_t port_id) { - - for(int i=0; i < (int) d_rx.size(); i++) - if(pmt_eq(d_rx[i]->port_symbol(), port_id)) - return i; - - return -1; -} - -/*! - * \brief Determines the current total capacity allocated by all RX and TX - * channels. - * - * \returns the total allocated capacity - */ -long usrp_server::current_capacity_allocation() { - long capacity = 0; - - for(int chan=0; chan < d_ntx_chan; chan++) - capacity += d_chaninfo_tx[chan].assigned_capacity; - - for(int chan=0; chan < d_nrx_chan; chan++) - capacity += d_chaninfo_rx[chan].assigned_capacity; - - return capacity; -} - - -/*! - * \brief Called by the handle_message() method if the incoming message to - * usrp_server is to allocate a channel (cmd-allocate-channel). The method - * checks if the requested capacity exists and if so it will reserve it for the - * caller on the channel that is returned via a response-allocate-channel - * signal. - */ -void -usrp_server::handle_cmd_allocate_channel( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - long rqstd_capacity = pmt_to_long(pmt_nth(1, data)); - long chan; - - // Check capacity exists - if((D_USB_CAPACITY - current_capacity_allocation()) < rqstd_capacity) { - - // no capacity available - port->send(s_response_allocate_channel, - pmt_list3(invocation_handle, - s_err_requested_capacity_unavailable, - PMT_NIL)); - return; - } - - // Find a free channel, assign the capacity and respond - for(chan=0; chan < (long)chan_info.size(); chan++) { - - if(verbose) - std::cout << "[USRP_SERVER] Checking chan: " << chan - << " owner " << chan_info[chan].owner - << " size " << chan_info.size() - << std::endl; - - if(chan_info[chan].owner == PMT_NIL) { - - chan_info[chan].owner = port->port_symbol(); - chan_info[chan].assigned_capacity = rqstd_capacity; - - port->send(s_response_allocate_channel, - pmt_list3(invocation_handle, - PMT_T, - pmt_from_long(chan))); - - if(verbose) - std::cout << "[USRP_SERVER] Assigning channel: " << chan - << " to " << chan_info[chan].owner - << std::endl; - return; - } - - } - - if (verbose) - std::cout << "[USRP_SERVER] Couldnt find a TX chan\n"; - - // no free TX chan found - port->send(s_response_allocate_channel, - pmt_list3(invocation_handle, - s_err_channel_unavailable, - PMT_NIL)); - return; -} - -/*! - * \brief Called by the handle_message() method if the incoming message to - * usrp_server is to deallocate a channel (cmd-deallocate-channel). The method - * ensures that the sender of the signal owns the channel and that the channel - * number is valid. A response-deallocate-channel signal is sent back with the - * result of the deallocation. - */ -void -usrp_server::handle_cmd_deallocate_channel( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - - pmt_t invocation_handle = pmt_nth(0, data); - long channel = pmt_to_long(pmt_nth(1, data)); - - // Ensure the channel is valid and the caller owns the port - if(!check_valid(port, channel, chan_info, - pmt_list2(s_response_deallocate_channel, invocation_handle))) - return; - - chan_info[channel].assigned_capacity = 0; - chan_info[channel].owner = PMT_NIL; - - port->send(s_response_deallocate_channel, - pmt_list2(invocation_handle, - PMT_T)); - return; -} - -/*! - * \brief Called by the handle_message() method if the incoming message to - * usrp_server is to transmit a frame (cmd-xmit-raw-frame). The method - * allocates enough memory to support a burst of packets which contain the frame - * over the bus of the frame, sets the packet headers, and sends a signal to the - * lower block for the data (packets) to be written to the bus. - * - * The \p port the command was sent on and the channel info (\p chan_info) of - * the channel the frame is to be transmitted on are passed to ensure that the - * caller owns the channel. - * - * The \p data parameter is in the format of a cmd-xmit-raw-frame signal. - * - * The properties - */ -void usrp_server::handle_cmd_xmit_raw_frame( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - size_t n_bytes, psize; - long max_payload_len = transport_pkt::max_payload(); - - pmt_t invocation_handle = pmt_nth(0, data); - long channel = pmt_to_long(pmt_nth(1, data)); - const void *samples = pmt_uniform_vector_elements(pmt_nth(2, data), n_bytes); - long timestamp = pmt_to_long(pmt_nth(3, data)); - pmt_t properties = pmt_nth(4, data); - - // Ensure the channel is valid and the caller owns the port - if(!check_valid(port, channel, chan_info, - pmt_list2(s_response_xmit_raw_frame, invocation_handle))) - return; - - // Read information from the properties of the packet - bool carrier_sense = false; - if(pmt_is_dict(properties)) { - - // Check if carrier sense is enabled for the frame - if(pmt_t p_carrier_sense = pmt_dict_ref(properties, - pmt_intern("carrier-sense"), - PMT_NIL)) { - if(pmt_eqv(p_carrier_sense, PMT_T)) - carrier_sense = true; - } - } - - - // Determine the number of packets to allocate contiguous memory for - // bursting over the USB and get a pointer to the memory to be used in - // building the packets - long n_packets = - static_cast<long>(std::ceil(n_bytes / (double)max_payload_len)); - - pmt_t v_packets = pmt_make_u8vector(sizeof(transport_pkt) * n_packets, 0); - - transport_pkt *pkts = - (transport_pkt *) pmt_u8vector_writable_elements(v_packets, psize); - - for(int n=0; n < n_packets; n++) { - - long payload_len = - std::min((long)(n_bytes-(n*max_payload_len)), (long)max_payload_len); - - if(n == 0) { // first packet gets start of burst flag and timestamp - - if(carrier_sense) - pkts[n].set_header(pkts[n].FL_START_OF_BURST - | pkts[n].FL_CARRIER_SENSE, - channel, 0, payload_len); - else - pkts[n].set_header(pkts[n].FL_START_OF_BURST, channel, 0, payload_len); - - pkts[n].set_timestamp(timestamp); - - } else { - pkts[n].set_header(0, channel, 0, payload_len); - pkts[n].set_timestamp(0xffffffff); - } - - memcpy(pkts[n].payload(), - (uint8_t *)samples+(max_payload_len * n), - payload_len); - - } - - - pkts[n_packets-1].set_end_of_burst(); // set the last packet's end of burst - - if (verbose && 0) - std::cout << "[USRP_SERVER] Received raw frame invocation: " - << invocation_handle << std::endl; - - // The actual response to the write will be generated by a - // s_response_usrp_write since we cannot determine whether to transmit was - // successful until we hear from the lower layers. - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packets)); - - return; -} - -/*! - * \brief Called by the handle_message() method to parse incoming control/status - * signals (cmd-to-control-channel). - * - * The \p port the command was sent on and the channel info (\p chan_info) of - * the channel are passed to ensure that the caller owns the channel. - * - * The \p data parameter is in the format of a PMT list, where each element - * follows the format of a control/status signal (i.e. op-ping-fixed). - * - * The method will parse all of the C/S commands included in \p data and place - * the commands in to a lower level packet sent to the control channel. The - * method will pack as many commands as possible in t oa single packet, and once - * it is fill generate as many lower level packets as needed. - * - * Anything that needs to be returned to the sender of the signal (i.e. the - * value of a register) will be generated by the parse_control_pkt() method as - * the responses to the commands are read back from the USRP. - */ -void usrp_server::handle_cmd_to_control_channel( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t subpackets = pmt_nth(1, data); - - long n_subpkts = pmt_length(subpackets); - long curr_subpkt = 0; - - size_t psize; - long payload_len = 0; - long channel = CONTROL_CHAN; - - if(verbose) - std::cout << "[USRP_SERVER] Handling " << n_subpkts << " commands\n"; - - // The design of the following code is optimized for simplicity, not - // performance. To performance optimize this code, the total size in bytes - // needed for all of the CS packets is needed to allocate contiguous memory - // which contains the USB packets for bursting over the bus. However to do - // this the packets subpackets would need to be parsed twice and their sizes - // would need to be determined. - // - // The approach taken is to keep parsing the subpackets and putting them in to - // USB packets. Once the USB packet is full, a write is sent for it and - // another packet is created. - // - // The subpacket creation methods will return false if the subpacket will not - // fit in to the current USB packet. In these cases a new USB packet is - // created and the old is sent. - - new_packet: - // This code needs to become "smart" and only make a new packet when full - pmt_t v_packet = pmt_make_u8vector(sizeof(transport_pkt), 0); - transport_pkt *pkt = (transport_pkt *) pmt_u8vector_writable_elements(v_packet, psize); - payload_len = 0; - - pkt->set_header(0, channel, 0, payload_len); - pkt->set_timestamp(0xffffffff); - - while(curr_subpkt < n_subpkts) { - - pmt_t subp = pmt_nth(curr_subpkt, subpackets); - pmt_t subp_cmd = pmt_nth(0, subp); - pmt_t subp_data = pmt_nth(1, subp); - - //--------- PING FIXED --------------// - if(pmt_eq(subp_cmd, s_op_ping_fixed)) { - - long urid = pmt_to_long(pmt_nth(0, subp_data)); - long pingval = pmt_to_long(pmt_nth(1, subp_data)); - - // USRP server sets request ID's to keep track of which application gets - // what response back. To allow a full 6-bits for an RID to the user, we - // keep a mapping and replace the RID's as the packets go in and out. If - // there are no RID's available, the command is thrown away silently. - long srid; - if((srid = next_rid()) == -1) - goto subpkt_bail; - - // We use a vector to store the owner of the ping request and will use it - // to send the request on any RX port they own. - d_rids[srid].owner = port->port_symbol(); - d_rids[srid].user_rid = urid; - - // Adds a ping after the previous command in the pkt - if(!pkt->cs_ping(srid, pingval)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - // Return the RID - d_rids[srid].owner = PMT_NIL; - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received ping command request" - << " assigning RID " << srid << std::endl; - - } - - //----------- WRITE REG ---------------// - if(pmt_eq(subp_cmd, s_op_write_reg)) { - - long reg_num = pmt_to_long(pmt_nth(0, subp_data)); - long val = pmt_to_long(pmt_nth(1, subp_data)); - - if(!pkt->cs_write_reg(reg_num, val)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received write register request " - << "(" - << "Reg: " << reg_num << ", " - << "Val: " << val - << ")\n"; - } - - //------- WRITE REG MASKED ----------// - if(pmt_eq(subp_cmd, s_op_write_reg_masked)) { - - long reg_num = pmt_to_long(pmt_nth(0, subp_data)); - long val = pmt_to_long(pmt_nth(1, subp_data)); - long mask = pmt_to_long(pmt_nth(2, subp_data)); - - if(!pkt->cs_write_reg_masked(reg_num, val, mask)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received write register masked request\n"; - } - - //------------ READ REG --------------// - if(pmt_eq(subp_cmd, s_op_read_reg)) { - - long urid = pmt_to_long(pmt_nth(0, subp_data)); - long reg_num = pmt_to_long(pmt_nth(1, subp_data)); - - long srid; - if((srid = next_rid()) == -1) - goto subpkt_bail; - - d_rids[srid].owner = port->port_symbol(); - d_rids[srid].user_rid = urid; - - if(!pkt->cs_read_reg(srid, reg_num)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - // Return the rid - d_rids[srid].owner = PMT_NIL; - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received read register request" - << " assigning RID " << srid << std::endl; - } - - //------------ DELAY --------------// - if(pmt_eq(subp_cmd, s_op_delay)) { - - long ticks = pmt_to_long(pmt_nth(0, subp_data)); - - if(!pkt->cs_delay(ticks)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received delay request of " - << ticks << " ticks\n"; - } - - //--------- I2C WRITE -----------// - // FIXME: could check that byte count does not exceed 2^8 which - // is the max length in the subpacket for # of bytes to read. - if(pmt_eq(subp_cmd, s_op_i2c_write)) { - - long i2c_addr = pmt_to_long(pmt_nth(0, subp_data)); - pmt_t data = pmt_nth(1, subp_data); - - // Get a readable address to the data which also gives us the length - size_t data_len; - uint8_t *i2c_data = (uint8_t *) pmt_u8vector_writable_elements(data, data_len); - - // Make the USB packet - if(!pkt->cs_i2c_write(i2c_addr, i2c_data, data_len)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received I2C write\n"; - } - - //----------- I2C Read -------------// - if(pmt_eq(subp_cmd, s_op_i2c_read)) { - - long urid = pmt_to_long(pmt_nth(0, subp_data)); - long i2c_addr = pmt_to_long(pmt_nth(1, subp_data)); - long i2c_bytes = pmt_to_long(pmt_nth(2, subp_data)); - - long srid; - if((srid = next_rid()) == -1) - goto subpkt_bail; - - d_rids[srid].owner = port->port_symbol(); - d_rids[srid].user_rid = urid; - - if(!pkt->cs_i2c_read(srid, i2c_addr, i2c_bytes)) - { - - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - d_rids[srid].owner = PMT_NIL; - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received I2C read\n"; - } - - //--------- SPI WRITE -----------// - if(pmt_eq(subp_cmd, s_op_spi_write)) { - - long enables = pmt_to_long(pmt_nth(0, subp_data)); - long format = pmt_to_long(pmt_nth(1, subp_data)); - long opt = pmt_to_long(pmt_nth(2, subp_data)); - pmt_t data = pmt_nth(3, subp_data); - - // Get a readable address to the data which also gives us the length - size_t data_len; - uint8_t *spi_data = (uint8_t *) pmt_u8vector_writable_elements(data, data_len); - - // Make the USB packet - if(!pkt->cs_spi_write(enables, format, opt, spi_data, data_len)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received SPI write\n"; - } - - //--------- SPI READ -----------// - if(pmt_eq(subp_cmd, s_op_spi_read)) { - - long urid = pmt_to_long(pmt_nth(0, subp_data)); - long enables = pmt_to_long(pmt_nth(1, subp_data)); - long format = pmt_to_long(pmt_nth(2, subp_data)); - long opt = pmt_to_long(pmt_nth(3, subp_data)); - long n_bytes = pmt_to_long(pmt_nth(4, subp_data)); - - long srid; - if((srid = next_rid()) == -1) - goto subpkt_bail; - - d_rids[srid].owner = port->port_symbol(); - d_rids[srid].user_rid = urid; - - // Make the USB packet - if(!pkt->cs_spi_read(srid, enables, format, opt, n_bytes)) - { - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - // Return the rid - d_rids[srid].owner = PMT_NIL; - - goto new_packet; - } - - if(verbose) - std::cout << "[USRP_SERVER] Received SPI read\n"; - } - - subpkt_bail: - curr_subpkt++; - - } - - - // If the current packets length is > 0, we know there are subpackets that - // need to be sent out still. - if(pkt->payload_len() > 0) - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(invocation_handle, - pmt_from_long(channel), - v_packet)); - - return; -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is a - * command to start reading samples from the USRP (cmd-start-recv-raw-samples). - * - * The \p port the command was sent on and the channel info (\p chan_info) of - * the channel are passed to ensure that the caller owns the channel. - * - * The \p data parameter should be in the format of a cmd-start-recv-raw-samples - * command where the first element in the list is an invocation handle, and the - * second is the channel the signal generator wants to receive the samples on. - */ -void -usrp_server::handle_cmd_start_recv_raw_samples( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - long channel = pmt_to_long(pmt_nth(1, data)); - - // Ensure the channel is valid and the caller owns the port - if(!check_valid(port, channel, chan_info, - pmt_list2(s_response_xmit_raw_frame, invocation_handle))) - return; - - // Already started receiving samples? (another start before a stop) - // Check the RX channel bitmask. - if(d_rx_chan_mask & (1 << channel)) { - port->send(s_response_recv_raw_samples, - pmt_list5(invocation_handle, - s_err_already_receiving, - PMT_NIL, - PMT_NIL, - PMT_NIL)); - return; - } - - // We only need to generate a 'start reading' command down to the - // low level interface if no other channel is already reading - // - // We carry this over the CS interface because the lower level - // interface does not care about the channel, we only demux it - // at the usrp_server on responses. - if(d_rx_chan_mask == 0) { - - if(verbose) - std::cout << "[USRP_SERVER] Sending read request down to start recv\n"; - - d_cs_usrp->send(s_cmd_usrp_start_reading, pmt_list1(invocation_handle)); - } - - d_rx_chan_mask |= 1<<channel; - - return; -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * stop receiving samples from the USRP (cmd-stop-recv-raw-samples). - * - * The \p port the command was sent on and the channel info (\p chan_info) of - * the channel are passed to ensure that the caller owns the channel. - * - * The \p data parameter should be in the format of a cmd-stop-recv-raw-samples - * command where the first element in the list is an invocation handle, and the - * second is the channel the signal generator wants to stop receiving the - * samples from. - */ -void -usrp_server::handle_cmd_stop_recv_raw_samples( - mb_port_sptr port, - std::vector<struct channel_info> &chan_info, - pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - long channel = pmt_to_long(pmt_nth(1, data)); - - // FIX ME : we have no responses to send an error... - // Ensure the channel is valid and the caller owns the port - //if(!check_valid(port, channel, chan_info, - // pmt_list2(s_response_xmit_raw_frame, invocation_handle))) - // return; - - // Remove this hosts bit from the receiver mask - d_rx_chan_mask &= ~(1<<channel); - - // We only need to generate a 'start reading' command down to the - // low level interface if no other channel is already reading - // - // We carry this over the CS interface because the lower level - // interface does not care about the channel, we only demux it - // at the usrp_server on responses. - if(d_rx_chan_mask == 0) { - - if(verbose) - std::cout << "[USRP_SERVER] Sending stop reading request down\n"; - - d_cs_usrp->send(s_cmd_usrp_stop_reading, pmt_list1(invocation_handle)); - } - - return; -} - -/*! - * \brief Called by the handle_message() method when an incoming signal is - * generated to USRP server that contains raw samples from the USRP. This - * method generates the response-recv-raw-samples signals that are the result of - * a cmd-start-recv-raw-samples signal. - * - * The raw lower-level packet is extracted from \p data, where the format for \p - * data is a PMT list. The PMT \p data list should contain an invocation handle - * as the first element, the status of the lower-level read as the second - * element, and a uniform vector representation of the packets as the third - * element. - * - * The packet contains a channel field that the samples are destined to, and the - * method determines where to send the samples based on this channel since each - * channel has an associated port which allocated it. - */ -void -usrp_server::handle_response_usrp_read(pmt_t data) -{ - - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t v_pkt = pmt_nth(2, data); - - size_t n_bytes; - size_t ignore; - - if (d_fake_rx) { - - pmt_t pkt = pmt_nth(2, data); - - d_rx[0]->send(s_response_recv_raw_samples, - pmt_list5(PMT_F, - PMT_T, - pkt, - pmt_from_long(0xffff), - PMT_NIL)); - - return; - } - - // Extract the packet and return appropriately - transport_pkt *pkt = (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, n_bytes); - - // The channel is used to find the port to pass the samples on - long channel = pkt->chan(); - long payload_len = pkt->payload_len(); - long port; - - // Ignore packets which seem to have incorrect size or size 0 - if(payload_len > pkt->max_payload() || payload_len == 0) - return; - - // If the packet is a C/S packet, parse it separately - if(channel == CONTROL_CHAN) { - parse_control_pkt(invocation_handle, pkt); - return; - } - - if((port = rx_port_index(d_chaninfo_rx[channel].owner)) == -1) - return; // Don't know where to send the sample... possibility on abrupt close - - pmt_t v_samples = pmt_make_u8vector(payload_len, 0); - uint8_t *samples = pmt_u8vector_writable_elements(v_samples, ignore); - - memcpy(samples, pkt->payload(), payload_len); - - // Build a properties dictionary to store things such as the RSSI - pmt_t properties = pmt_make_dict(); - - pmt_dict_set(properties, - pmt_intern("rssi"), - pmt_from_long(pkt->rssi())); - - if(pkt->overrun()) - pmt_dict_set(properties, - pmt_intern("overrun"), - PMT_T); - - if(pkt->underrun()) - pmt_dict_set(properties, - pmt_intern("underrun"), - PMT_T); - - d_rx[port]->send(s_response_recv_raw_samples, - pmt_list6(invocation_handle, - status, - v_samples, - pmt_from_long(pkt->timestamp()), - pmt_from_long(channel), - properties)); - return; -} - -/*! - * \brief Called by handle_response_usrp_read() when the incoming packet has a - * channel of CONTROL_CHAN. This means that the incoming packet contains a - * response for a command sent to the control channel, which this method will - * parse. - * - * The \p pkt parameter is a pointer to the full packet (transport_pkt) in - * memory. - * - * Given that all commands sent to the control channel that require responses - * will carry an RID (request ID), the method will use the RID passed back with - * the response to determine which port the response should be sent on. - */ -void -usrp_server::parse_control_pkt(pmt_t invocation_handle, transport_pkt *pkt) -{ - - long payload_len = pkt->payload_len(); - long curr_payload = 0; - long port; - - // We dispatch based on the control packet type, however we can extract the - // opcode and the length immediately which is consistent in all responses. - // - // Since each control packet can have multiple responses, we keep reading the - // lengths of each subpacket until we reach the payload length. - while(curr_payload < payload_len) { - - pmt_t sub_packet = pkt->read_subpacket(curr_payload); - pmt_t op_symbol = pmt_nth(0, sub_packet); - - int len = pkt->cs_len(curr_payload); - - if(verbose) - std::cout << "[USRP_SERVER] Parsing subpacket " - << op_symbol << " ... length " << len << std::endl; - - //----------------- PING RESPONSE ------------------// - if(pmt_eq(op_symbol, s_op_ping_fixed_reply)) { - - long srid = pmt_to_long(pmt_nth(1, sub_packet)); - pmt_t pingval = pmt_nth(2, sub_packet); - - long urid = d_rids[srid].user_rid; - - if(verbose) - std::cout << "[USRP_SERVER] Found ping response " - << "(" - << "URID: " << urid << ", " - << "SRID: " << srid << ", " - << "VAL: " << pingval - << ")\n"; - - // Do some bounds checking incase of bogus/corrupt responses - if(srid > D_MAX_RID) - return; - - pmt_t owner = d_rids[srid].owner; - - // Return the RID - d_rids[srid].owner = PMT_NIL; - - // FIXME: should be 1 response for all subpackets here ? - if((port = tx_port_index(owner)) != -1) - d_tx[port]->send(s_response_from_control_channel, - pmt_list4(invocation_handle, - PMT_T, - pmt_list2(s_op_ping_fixed_reply, // subp - pmt_list2(pmt_from_long(urid), - pingval)), - pmt_from_long(pkt->timestamp()))); - } - - //----------------- READ REG RESPONSE ------------------// - else if(pmt_eq(op_symbol, s_op_read_reg_reply)) { - - long srid = pmt_to_long(pmt_nth(1, sub_packet)); - pmt_t reg_num = pmt_nth(2, sub_packet); - pmt_t reg_val = pmt_nth(3, sub_packet); - - long urid = d_rids[srid].user_rid; - - if(verbose) - std::cout << "[USRP_SERVER] Found read register response " - << "(" - << "URID: " << urid << ", " - << "SRID: " << srid << ", " - << "REG: " << reg_num << ", " - << "VAL: " << reg_val - << ")\n"; - - // Do some bounds checking to avoid seg faults - if(srid > D_MAX_RID) - return; - - pmt_t owner = d_rids[srid].owner; - - // Return the RID - d_rids[srid].owner = PMT_NIL; - - // FIXME: should be 1 response for all subpackets here ? - if((port = tx_port_index(owner)) != -1) - d_tx[port]->send(s_response_from_control_channel, - pmt_list4(invocation_handle, - PMT_T, - pmt_list2(s_op_read_reg_reply, // subp - pmt_list3(pmt_from_long(urid), - reg_num, - reg_val)), - pmt_from_long(pkt->timestamp()))); - } - - //------------------ I2C READ REPLY -------------------// - else if(pmt_eq(op_symbol, s_op_i2c_read_reply)) { - - long srid = pmt_to_long(pmt_nth(1, sub_packet)); - pmt_t i2c_addr = pmt_nth(2, sub_packet); - pmt_t i2c_data = pmt_nth(3, sub_packet); - - long urid = d_rids[srid].user_rid; - - if(verbose) - std::cout << "[USRP_SERVER] Found i2c read reply " - << "(" - << "URID: " << urid << ", " - << "SRID: " << srid << ", " - << "Addr: " << i2c_addr << ", " - << "Data: " << i2c_data - << ")\n"; - - // Do some bounds checking to avoid seg faults - if(srid > D_MAX_RID) - return; - - pmt_t owner = d_rids[srid].owner; - - // Return the RID - d_rids[srid].owner = PMT_NIL; - - if((port = tx_port_index(owner)) != -1) - d_tx[port]->send(s_response_from_control_channel, - pmt_list4(invocation_handle, - PMT_T, - pmt_list2(s_op_i2c_read_reply, - pmt_list3(pmt_from_long(urid), - i2c_addr, - i2c_data)), - pmt_from_long(pkt->timestamp()))); - } - - //------------------ SPI READ REPLY -------------------// - else if(pmt_eq(op_symbol, s_op_spi_read_reply)) { - - long srid = pmt_to_long(pmt_nth(1, sub_packet)); - pmt_t spi_data = pmt_nth(2, sub_packet); - - long urid = d_rids[srid].user_rid; - - if(verbose) - std::cout << "[USRP_SERVER] Found SPI read reply " - << "(" - << "URID: " << urid << ", " - << "SRID: " << srid << ", " - << "Data: " << spi_data - << ")\n"; - - // Bounds check the RID - if(srid > D_MAX_RID) - return; - - pmt_t owner = d_rids[srid].owner; - - // Return the RID - d_rids[srid].owner = PMT_NIL; - - if((port = tx_port_index(owner)) != -1) - d_tx[port]->send(s_response_from_control_channel, - pmt_list4(invocation_handle, - PMT_T, - pmt_list2(s_op_spi_read_reply, - pmt_list2(pmt_from_long(urid), - spi_data)), - pmt_from_long(pkt->timestamp()))); - } - - // Each subpacket has an unaccounted for 2 bytes which is the opcode - // and the length field - curr_payload += len + 2; - - // All subpackets are 32-bit aligned - int align_offset = 4 - (curr_payload % 4); - - if(align_offset != 4) - curr_payload += align_offset; - } -} - -/*! - * \brief Used to recall all incoming signals that were deferred when USRP - * server was in the initialization state. - */ -void -usrp_server::recall_defer_queue() -{ - - std::vector<mb_message_sptr> recall; - - while(!d_defer_queue.empty()) { - recall.push_back(d_defer_queue.front()); - d_defer_queue.pop(); - } - - // Parse the messages that were queued while waiting for an open response - for(int i=0; i < (int)recall.size(); i++) - handle_message(recall[i]); - - return; -} - -/*! - * \brief Commonly called by any method which handles outgoing frames or control - * packets to the USRP to check if the port on which the signal was sent owns - * the channel the outgoing packet will be associated with. This helps ensure - * that applications do not send data on other application's ports. - * - * The \p port parameter is the port symbol that the caller wishes to determine - * owns the channel specified by \p chan_info. - * - * The \p signal_info parameter is a PMT list containing two elements: the - * response signal to use if the permissions are invalid, and the invocation - * handle that was passed. This allows the method to generate detailed failure - * responses to signals without having to return some sort of structured - * information which the caller must then parse and interpret to determine the - * failure type. - * - * \returns true if \p port owns the channel specified by \p chan_info, false - * otherwise. - */ -bool -usrp_server::check_valid(mb_port_sptr port, - long channel, - std::vector<struct channel_info> &chan_info, - pmt_t signal_info) -{ - - pmt_t response_signal = pmt_nth(0, signal_info); - pmt_t invocation_handle = pmt_nth(1, signal_info); - - // not a valid channel number? - if(channel >= (long)chan_info.size() && channel != CONTROL_CHAN) { - port->send(response_signal, - pmt_list2(invocation_handle, - s_err_channel_invalid)); - - if(verbose) - std::cout << "[USRP_SERVER] Invalid channel number for event " - << response_signal << std::endl; - return false; - } - - // not the owner of the port? - if(chan_info[channel].owner != port->port_symbol()) { - port->send(response_signal, - pmt_list2(invocation_handle, - s_err_channel_permission_denied)); - - if(verbose) - std::cout << "[USRP_SERVER] Invalid permissions" - << " for " << response_signal - << " from " << port->port_symbol() - << " proper owner is " << chan_info[channel].owner - << " on channel " << channel - << " invocation " << invocation_handle - << std::endl; - return false; - } - - return true; -} - -/*! - * \brief Finds the next available RID for internal USRP server use with control - * and status packets. - * - * \returns the next valid RID or -1 if no more RIDs are available. - */ -long -usrp_server::next_rid() -{ - for(int i = 0; i < D_MAX_RID; i++) - if(pmt_eqv(d_rids[i].owner, PMT_NIL)) - return i; - - if(verbose) - std::cout << "[USRP_SERVER] No RIDs left\n"; - return -1; -} - -/*! - * \brief Called by handle_message() when USRP server gets a response that the - * USRP was opened successfully to initialize the registers using the new - * register read/write control packets. - */ -void -usrp_server::initialize_registers() -{ - // We use handle_cmd_to_control_channel() to create the register writes using - // PMT_NIL as the response port to tell usrp_server not to pass the response - // up to any application. - if(verbose) - std::cout << "[USRP_SERVER] Initializing registers...\n"; - - // RX mode to normal (0) - set_register(FR_MODE, 0); - - // FPGA debugging? - if(d_fpga_debug) { - set_register(FR_DEBUG_EN, 1); - // FIXME: need to figure out exact register writes to control daughterboard - // pins that need to be written to - } else { - set_register(FR_DEBUG_EN, 0); - } - - // Set the transmit sample rate divisor, which is 4-1 - set_register(FR_TX_SAMPLE_RATE_DIV, 3); - - // Dboard IO buffer and register settings - set_register(FR_OE_0, (0xffff << 16) | 0x0000); - set_register(FR_IO_0, (0xffff << 16) | 0x0000); - set_register(FR_OE_1, (0xffff << 16) | 0x0000); - set_register(FR_IO_1, (0xffff << 16) | 0x0000); - set_register(FR_OE_2, (0xffff << 16) | 0x0000); - set_register(FR_IO_2, (0xffff << 16) | 0x0000); - set_register(FR_OE_3, (0xffff << 16) | 0x0000); - set_register(FR_IO_3, (0xffff << 16) | 0x0000); - - // zero Tx side Auto Transmit/Receive regs - set_register(FR_ATR_MASK_0, 0); - set_register(FR_ATR_TXVAL_0, 0); - set_register(FR_ATR_RXVAL_0, 0); - set_register(FR_ATR_MASK_1, 0); - set_register(FR_ATR_TXVAL_1, 0); - set_register(FR_ATR_RXVAL_1, 0); - set_register(FR_ATR_MASK_2, 0); - set_register(FR_ATR_TXVAL_2, 0); - set_register(FR_ATR_RXVAL_2, 0); - set_register(FR_ATR_MASK_3, 0); - set_register(FR_ATR_TXVAL_3, 0); - set_register(FR_ATR_RXVAL_3, 0); - - // Configure TX mux, this is a hacked value - set_register(FR_TX_MUX, 0x00000081); - - // Set the interpolation rate, which is the rate divided by 4, minus 1 - set_register(FR_INTERP_RATE, (d_interp_tx/4)-1); - - // Apparently this register changes again - set_register(FR_TX_MUX, 0x00000981); - - // Set the receive sample rate divisor, which is 2-1 - set_register(FR_RX_SAMPLE_RATE_DIV, 1); - - // DC offset - set_register(FR_DC_OFFSET_CL_EN, 0x0000000f); - - // Reset the DC correction offsets - set_register(FR_ADC_OFFSET_0, 0); - set_register(FR_ADC_OFFSET_1, 0); - - // Some hard-coded RX configuration - set_register(FR_RX_FORMAT, 0x00000300); - set_register(FR_RX_MUX, 1); - - // RX decimation rate is divided by two, then subtract 1 - set_register(FR_DECIM_RATE, (d_decim_rx/2)-1); - - // More hard coding - set_register(FR_RX_MUX, 0x000e4e41); - - // Resetting RX registers - set_register(FR_RX_PHASE_0, 0); - set_register(FR_RX_PHASE_1, 0); - set_register(FR_RX_PHASE_2, 0); - set_register(FR_RX_PHASE_3, 0); - set_register(FR_RX_FREQ_0, 0x28000000); - set_register(FR_RX_FREQ_1, 0); - set_register(FR_RX_FREQ_2, 0); - set_register(FR_RX_FREQ_3, 0); - - // Enable debug bus - set_register(FR_DEBUG_EN, 0xf); - set_register(FR_OE_0, -1); - set_register(FR_OE_1, -1); - set_register(FR_OE_2, -1); - set_register(FR_OE_3, -1); - - // DEBUGGING - //check_register_initialization(); -} - -// FIXME: used for debugging to determine if all the registers are actually -// being set correctly -void -usrp_server::check_register_initialization() -{ - // RX mode to normal (0) - read_register(FR_MODE); - - // FPGA debugging? - if(d_fpga_debug) { - read_register(FR_DEBUG_EN); - // FIXME: need to figure out exact register writes to control daughterboard - // pins that need to be written to - } else { - read_register(FR_DEBUG_EN); - } - - // Set the transmit sample rate divisor, which is 4-1 - read_register(FR_TX_SAMPLE_RATE_DIV); - - // Dboard IO buffer and register settings - read_register(FR_OE_0); - read_register(FR_IO_0); - read_register(FR_OE_1); - read_register(FR_IO_1); - read_register(FR_OE_2); - read_register(FR_IO_2); - read_register(FR_OE_3); - read_register(FR_IO_3); - - // zero Tx side Auto Transmit/Receive regs - read_register(FR_ATR_MASK_0); - read_register(FR_ATR_TXVAL_0); - read_register(FR_ATR_RXVAL_0); - read_register(FR_ATR_MASK_1); - read_register(FR_ATR_TXVAL_1); - read_register(FR_ATR_RXVAL_1); - read_register(FR_ATR_MASK_2); - read_register(FR_ATR_TXVAL_2); - read_register(FR_ATR_RXVAL_2); - read_register(FR_ATR_MASK_3); - read_register(FR_ATR_TXVAL_3); - read_register(FR_ATR_RXVAL_3); - - // Configure TX mux, this is a hacked value - read_register(FR_TX_MUX); - - // Set the interpolation rate, which is the rate divided by 4, minus 1 - read_register(FR_INTERP_RATE); - - // Apparently this register changes again - read_register(FR_TX_MUX); - - // Set the receive sample rate divisor, which is 2-1 - read_register(FR_RX_SAMPLE_RATE_DIV); - - // DC offset - read_register(FR_DC_OFFSET_CL_EN); - - // Reset the DC correction offsets - read_register(FR_ADC_OFFSET_0); - read_register(FR_ADC_OFFSET_1); - - // Some hard-coded RX configuration - read_register(FR_RX_FORMAT); - read_register(FR_RX_MUX); - - // RX decimation rate is divided by two, then subtract 1 - read_register(FR_DECIM_RATE); - - // More hard coding - read_register(FR_RX_MUX); - - // Resetting RX registers - read_register(FR_RX_PHASE_0); - read_register(FR_RX_PHASE_1); - read_register(FR_RX_PHASE_2); - read_register(FR_RX_PHASE_3); - read_register(FR_RX_FREQ_0); - read_register(FR_RX_FREQ_1); - read_register(FR_RX_FREQ_2); - read_register(FR_RX_FREQ_3); -} - -/*! - * \brief Used to generate FPGA register write commands to reset all of the FPGA - * registers to a value of 0. - */ -void -usrp_server::reset_all_registers() -{ - for(int i=0; i<64; i++) - set_register(i, 0); -} - -/*! - * \brief Used internally by USRP server to generate a control/status packet - * which contains a register write. - * - * The \p reg parameter is the register number that the value \p val will be - * written to. - */ -void -usrp_server::set_register(long reg, long val) -{ - size_t psize; - long payload_len = 0; - - pmt_t v_packet = pmt_make_u8vector(sizeof(transport_pkt), 0); - transport_pkt *pkt = (transport_pkt *) pmt_u8vector_writable_elements(v_packet, psize); - - pkt->set_header(0, CONTROL_CHAN, 0, payload_len); - pkt->set_timestamp(0xffffffff); - - pkt->cs_write_reg(reg, val); - - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(PMT_NIL, - pmt_from_long(CONTROL_CHAN), - v_packet)); -} - -/*! - * \brief Used internally by USRP server to generate a control/status packet - * which contains a register read. This is important to use internally so that - * USRP server can bypass the use of RIDs with register reads, as they are not - * needed and it would use up the finite number of RIDs available for use for - * applications to receive responses. - * - * The \p reg parameter is the register number that the value should be read - * from. - */ -void -usrp_server::read_register(long reg) -{ - size_t psize; - long payload_len = 0; - - pmt_t v_packet = pmt_make_u8vector(sizeof(transport_pkt), 0); - transport_pkt *pkt = (transport_pkt *) pmt_u8vector_writable_elements(v_packet, psize); - - pkt->set_header(0, CONTROL_CHAN, 0, payload_len); - pkt->set_timestamp(0xffffffff); - - pkt->cs_read_reg(0, reg); - - d_cs_usrp->send(s_cmd_usrp_write, - pmt_list3(PMT_NIL, - pmt_from_long(CONTROL_CHAN), - v_packet)); -} - -REGISTER_MBLOCK_CLASS(usrp_server); diff --git a/usrp/limbo/inband/usrp_server.h b/usrp/limbo/inband/usrp_server.h deleted file mode 100644 index dd1825d571..0000000000 --- a/usrp/limbo/inband/usrp_server.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_SERVER_H -#define INCLUDED_USRP_SERVER_H - -#include <mblock/mblock.h> -#include <vector> -#include <queue> -#include <fstream> -#include <usrp_inband_usb_packet.h> - -typedef usrp_inband_usb_packet transport_pkt; // makes conversion to gigabit easy - -/*! - * \brief Implements the lowest-level mblock usb_interface to the USRP - */ -class usrp_server : public mb_mblock -{ -public: - - // our ports - enum port_types { - RX_PORT = 0, - TX_PORT = 1 - }; - static const int N_PORTS = 4; - std::vector<mb_port_sptr> d_tx, d_rx; - mb_port_sptr d_cs; - mb_port_sptr d_cs_usrp; - - static const int D_USB_CAPACITY = 32 * 1024 * 1024; - static const int D_MAX_CHANNELS = 16; - long d_ntx_chan; - long d_nrx_chan; - - pmt_t d_usrp_dict; - - bool d_fpga_debug; - - long d_interp_tx; - long d_decim_rx; - - // Keep track of the request IDs - struct rid_info { - pmt_t owner; - long user_rid; - - rid_info() { - owner = PMT_NIL; - user_rid = 0; - } - }; - - static const long D_MAX_RID = 64; - std::vector<rid_info> d_rids; - - struct channel_info { - long assigned_capacity; // the capacity currently assignedby the channel - pmt_t owner; // port ID of the owner of the channel - - channel_info() { - assigned_capacity = 0; - owner = PMT_NIL; - } - }; - - long d_rx_chan_mask; // A bitmask representing the channels in the - // receiving state - - std::vector<struct channel_info> d_chaninfo_tx; - std::vector<struct channel_info> d_chaninfo_rx; - - std::queue<mb_message_sptr> d_defer_queue; - - bool d_defer; - bool d_opened; - - bool d_fake_rx; - -public: - usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_server(); - - void initial_transition(); - void handle_message(mb_message_sptr msg); - -protected: - static int max_capacity() { return D_USB_CAPACITY; } - -private: - void handle_cmd_allocate_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - void handle_cmd_deallocate_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - void handle_cmd_xmit_raw_frame(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - void handle_cmd_to_control_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - void handle_cmd_start_recv_raw_samples(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - void handle_cmd_stop_recv_raw_samples(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data); - int rx_port_index(pmt_t port_id); - int tx_port_index(pmt_t port_id); - long current_capacity_allocation(); - void recall_defer_queue(); - void reset_channels(); - void handle_response_usrp_read(pmt_t data); - bool check_valid(mb_port_sptr port, long channel, std::vector<struct channel_info> &chan_info, pmt_t signal_info); - void parse_control_pkt(pmt_t invocation_handle, transport_pkt *pkt); - long next_rid(); - void initialize_registers(); - void set_register(long reg, long val); - void read_register(long reg); - void check_register_initialization(); - void reset_all_registers(); -}; - -#endif /* INCLUDED_USRP_SERVER_H */ diff --git a/usrp/limbo/inband/usrp_server.mbh b/usrp/limbo/inband/usrp_server.mbh deleted file mode 100644 index ed7943fc37..0000000000 --- a/usrp/limbo/inband/usrp_server.mbh +++ /dev/null @@ -1,255 +0,0 @@ -;; -*- scheme -*- ; not really, but tells emacs how to format this -;; -;; Copyright 2007 Free Software Foundation, Inc. -;; -;; This file is part of GNU Radio -;; -;; GNU Radio 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 3, or (at your option) -;; any later version. -;; -;; GNU Radio 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., -;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -;; - -;; ---------------------------------------------------------------- -;; This is an mblock header file -;; -;; The format is very much a work-in-progress. -;; It'll be compiled to C++. -;; ---------------------------------------------------------------- - -;; In the outgoing messages described below, invocation-handle is an -;; identifier provided by the client to tag the method invocation. -;; The identifier will be returned with the response, to provide the -;; client with a mechanism to match asynchronous responses with the -;; commands that generate them. The value of the invocation-handle is -;; opaque the the server, and is not required by the server to be -;; unique. -;; -;; In the incoming messages described below, invocation-handle is the -;; identifier provided by the client in the prompting invocation. The -;; identifier is returned with the response, so that the client has a -;; mechanism to match asynchronous responses with the commands that -;; generated them. -;; -;; status is either #t, indicating success, or a symbol indicating an error. -;; All symbol's names shall begin with %error- - - -;; ---------------------------------------------------------------- -;; usrp-channel -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class usrp-channel - - (:outgoing - - (cmd-allocate-channel invocation-handle capacity-reservation) - - ;; The cmd-allocate-channel message requests that the server - ;; allocates a logical channel in the FPGA for use. - ;; capacity-reservation specifies the number of bytes/s of - ;; interconnect capacity (USB or ethernet) to reserve for this - ;; channel. (The reservation is just a sanity check, no OS - ;; specific mechanism is used.) - - (cmd-deallocate-channel invocation-handle channel) - - ;; The integer channel specifies the channel to deallocate. - - ) - - (:incoming - - - (response-allocate-channel invocation-handle status channel) - - ;; If successful, a channel the specified capacity was allocated. - ;; channel, an integer, indicates which channel was allocated. - - (response-deallocate-channel invocation-handle status) - - ;; If successful, the specified channel and associated interconnect - ;; capacity were deallocated. - - ) - ) - -;; ---------------------------------------------------------------- -;; usrp-low-level-cs -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) -;; -;; This defines a low level control and status interface to the usrp. -;; This will probably be replaced (or at least augmented) with a -;; higher level interface. For now, this will allow us to get on -;; the air. -;; -;; The subpackets are lists containing the relevant parameters. The -;; server will marshall them appropriately. Below is a list of -;; subpackets. See inband-signaling-usb for details. The opcodes are -;; symbols; unless otherwise indicated the remaining parameters are -;; integers. rid values are limited to 3-bits. -;; -;; (op-ping-fixed rid ping-value) -;; (op-ping-fixed-reply rid ping-value) -;; (op-write-reg reg-number reg-value) -;; (op-write-reg-masked reg-number reg-value mask-value) -;; (op-read-reg rid reg-number) -;; (op-read-reg-reply rid reg-number reg-value) -;; (op-i2c-write i2c-addr u8-vec) -;; (op-i2c-read rid i2c-addr nbytes) -;; (op-i2c-read-reply rid i2c-addr u8-vec) -;; (op-spi-write enables format opt-header-bytes u8-vec) -;; (op-spi-read rid enables format opt-header-bytes nbytes) -;; (op-spi-read-reply rid u8-vec) -;; (op-delay ticks) - - -(define-protocol-class usrp-low-level-cs - - (:outgoing - - (cmd-to-control-channel invocation-handle list-of-subpackets) - - ) - - (:incoming - - (response-from-control-channel invocation-handle status list-of-subpackets timestamp) - - ) - ) - -;; ---------------------------------------------------------------- -;; usrp-tx -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class usrp-tx - (:include usrp-channel) - (:include usrp-low-level-cs) - - (:outgoing - - (cmd-xmit-raw-frame invocation-handle channel samples timestamp properties) - - ;; The argument channel must be an integer. It specifies the - ;; channel on which the frame of samples will be be sent. - ;; - ;; samples must be a uniform numeric vector. The contents of the - ;; sample vector is treated as opaque and is passed on to the FPGA - ;; unmodified. It is the responsibility of the sender to ensure - ;; that the binary format is sensible for the current FPGA - ;; configuration. - ;; - ;; timestamp is a 32-bit integer that specifies the time at which - ;; the first sample in samples shall be sent to the D/A converter. - ;; The format and interpration of time is specified in the file - ;; inband-signaling-usb - ) - - (:incoming - - (response-xmit-raw-frame invocation-handle status) - - ;; If successful, the samples of the associated frame have been - ;; transmitted to the USRP. This message may be used to implement - ;; Tx flow control. The client could for example implement a - ;; policy of never having more than 4 unacknowledged - ;; cmd-xmit-raw-frame's outstanding. - - ) - ) - -;; ---------------------------------------------------------------- -;; usrp-rx -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class usrp-rx - (:include usrp-channel) - (:include usrp-low-level-cs) - - (:outgoing - - (cmd-start-recv-raw-samples invocation-handle channel) - - ;; The argument channel must be an integer. It specifies the - ;; channel from which frames of samples will be be received. The - ;; server will return response-recv-raw-samples messages until a - ;; cmd-stop-recv-raw-samples message is received. - - (cmd-stop-recv-raw-samples invocation-handle channel) - - ;; The argument channel must be an integer. There is no reply to - ;; this message. - - ) - - (:incoming - - (response-recv-raw-samples invocation-handle status samples timestamp channel properties) - - ;; samples is a uniform numeric vector. The contents of the sample - ;; vector is treated as opaque and is passed from the FPGA - ;; unmodified. It is the responsibility of the receiver to decode - ;; the binary format as appropriate for the current FPGA - ;; configuration. - ;; - ;; timestamp is a 32-bit integer that specifies the time at which - ;; the first sample in samples was received from the A/D converter. - ;; The format and interpretation of time is as specified in the - ;; file inband-signaling-usb. - ;; - ;; properties is a dictionary containing additional (key, value) - ;; pairs associated with the reception of these samples. In - ;; particular, the map may contain the Received Signal Strength - ;; Indication (RSSI) reported by the front end at the time the - ;; first sample was received from the A/D. - - ) - ) - - -;; ---------------------------------------------------------------- -;; usrp-server-cs -;; -;; Control and status port for usrp-server -;; -;; The protocol class is defined from the client's point-of-view. -;; (The client port is unconjugated, the server port is conjugated.) - -(define-protocol-class usrp-server-cs - - (:outgoing - (cmd-open invocation-handle which-usrp) - (cmd-close invocation-handle) - (cmd-max-capacity invocation-handle) - (cmd-ntx-chan invocation-handle) - (cmd-nrx-chan invocation-handle) - (cmd-current-capacity-allocation invocation-handle) - ) - - (:incoming - (response-open invocation-handle status) - (response-close invocation-handle status) - (response-max-capacity invocation-handle status capacity) - (response-ntx-chan invocation-handle status ntx-chan) - (response-nrx-chan invocation-handle status nrx-chan) - (response-current-capacity-allocation invocation-handle status capacity) - ) - ) diff --git a/usrp/limbo/inband/usrp_tx.cc b/usrp/limbo/inband/usrp_tx.cc deleted file mode 100644 index 0d4a846191..0000000000 --- a/usrp/limbo/inband/usrp_tx.cc +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_tx.h> -#include <iostream> -#include <usb.h> -#include <mblock/class_registry.h> -#include <usrp_inband_usb_packet.h> -#include <fpga_regs_common.h> -#include <usrp_standard.h> -#include <stdio.h> - -#include <symbols_usrp_tx_cs.h> - -typedef usrp_inband_usb_packet transport_pkt; - -static const bool verbose = false; - -usrp_tx::usrp_tx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_disk_write(false) -{ - d_cs = define_port("cs", "usrp-tx-cs", true, mb_port::EXTERNAL); - - //d_disk_write=true; - - if(d_disk_write) { - d_ofile.open("tx_data.dat",std::ios::binary|std::ios::out); - d_cs_ofile.open("tx_cs.dat",std::ios::binary|std::ios::out); - } -} - -usrp_tx::~usrp_tx() -{ - if(d_disk_write) { - d_ofile.close(); - d_cs_ofile.close(); - } -} - -void -usrp_tx::initial_transition() -{ - -} - -/*! - * \brief Handles incoming signals to to the m-block, wihch should only ever be - * a single message: cmd-usrp-tx-write. - */ -void -usrp_tx::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t port_id = msg->port_id(); - pmt_t data = msg->data(); - - // Theoretically only have 1 message to ever expect, but - // want to make sure its at least what we want - if(pmt_eq(port_id, d_cs->port_symbol())) { - - if(pmt_eqv(event, s_cmd_usrp_tx_write)) - write(data); - } -} - -/*! - * \brief Performs the actual writing of data to the USB bus, called by - * handle_message() when a cmd-usrp-tx-write signal is received. - * - * The \p data parameter is a PMT list which contains three mandatory elements, - * in the following order: an invocation handle, a channel, and a uniform vector - * of memory which contains the packets to be written to the bus. - */ -void -usrp_tx::write(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t channel = pmt_nth(1, data); - pmt_t v_packets = pmt_nth(2, data); - d_utx = boost::any_cast<usrp_standard_tx_sptr>(pmt_any_ref(pmt_nth(3, data))); - - size_t n_bytes; - bool underrun; // this will need to go, as it is taken care of in the packet headers - - transport_pkt *pkts = (transport_pkt *) pmt_u8vector_writable_elements(v_packets, n_bytes); - - int ret = d_utx->write (pkts, n_bytes, &underrun); - - if (0 && underrun) - fprintf(stderr, "uU"); - - if (ret == (int) n_bytes) { - if (verbose) - std::cout << "[usrp_server] Write of " << n_bytes << " successful\n"; - // need to respond with the channel so the USRP server knows who to forward the result of - // the write to by looking up the owner of the channel - d_cs->send(s_response_usrp_tx_write, - pmt_list3(invocation_handle, PMT_T, channel)); - } - else { - if (verbose) - std::cout << "[usrp_server] Error writing " << n_bytes << " bytes to USB bus\n"; - d_cs->send(s_response_usrp_tx_write, - pmt_list3(invocation_handle, PMT_F, channel)); - } - - long n_packets = - static_cast<long>(std::ceil(n_bytes / (double)transport_pkt::max_pkt_size())); - - for(int i=0; i < n_packets; i++) { - - if(d_disk_write) { - if(pkts[i].chan() == CONTROL_CHAN) - d_cs_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size()); - else - d_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size()); - - d_cs_ofile.flush(); - d_ofile.flush(); - } - } - - - return; -} - -REGISTER_MBLOCK_CLASS(usrp_tx); diff --git a/usrp/limbo/inband/usrp_tx.h b/usrp/limbo/inband/usrp_tx.h deleted file mode 100644 index d3a6f8b54e..0000000000 --- a/usrp/limbo/inband/usrp_tx.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_TX_H -#define INCLUDED_USRP_TX_H - -#include <mblock/mblock.h> -#include <fstream> -#include "usrp_standard.h" - -/*! - * \brief Implements the low level usb interface to the USRP - */ -class usrp_tx : public mb_mblock -{ - mb_port_sptr d_cs; - usrp_standard_tx_sptr d_utx; - - bool d_disk_write; - std::ofstream d_ofile; - std::ofstream d_cs_ofile; - - public: - usrp_tx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_tx(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - private: - void write(pmt_t data); -}; - - -#endif /* INCLUDED_USRP_TX_H */ - diff --git a/usrp/limbo/inband/usrp_tx_stub.cc b/usrp/limbo/inband/usrp_tx_stub.cc deleted file mode 100644 index c78b1a7b89..0000000000 --- a/usrp/limbo/inband/usrp_tx_stub.cc +++ /dev/null @@ -1,344 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <iostream> -#include <vector> -#include <usb.h> -#include <mblock/class_registry.h> -#include <usrp_tx_stub.h> -#include <usrp_inband_usb_packet.h> -#include <fpga_regs_common.h> -#include "usrp_standard.h" -#include <stdio.h> -#include <fstream> -#include <usrp_rx_stub.h> - -#include <symbols_usrp_tx_cs.h> - -typedef usrp_inband_usb_packet transport_pkt; - -static const bool verbose = false; - -usrp_tx_stub::usrp_tx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_disk_write(false) -{ - d_cs = define_port("cs", "usrp-tx-cs", true, mb_port::EXTERNAL); - - //d_disk_write=true; - - if(d_disk_write) { - d_ofile.open("tx_stub_data.dat",std::ios::binary|std::ios::out); - d_cs_ofile.open("tx_stub_cs.dat",std::ios::binary|std::ios::out); - } -} - -usrp_tx_stub::~usrp_tx_stub() -{ - if(d_disk_write) { - d_ofile.close(); - d_cs_ofile.close(); - } -} - -void -usrp_tx_stub::initial_transition() -{ - -} - -void -usrp_tx_stub::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); - pmt_t port_id = msg->port_id(); - pmt_t data = msg->data(); - - // Theoretically only have 1 message to ever expect, but - // want to make sure its at least what we want - if(pmt_eq(port_id, d_cs->port_symbol())) { - - if(pmt_eqv(event, s_cmd_usrp_tx_write)) - write(data); - } -} - -void -usrp_tx_stub::write(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t channel = pmt_nth(1, data); - pmt_t v_packets = pmt_nth(2, data); - d_utx = boost::any_cast<usrp_standard_tx *>(pmt_any_ref(pmt_nth(3, data))); - - size_t n_bytes; - - transport_pkt *pkts = (transport_pkt *) pmt_u8vector_writable_elements(v_packets, n_bytes); - long n_packets = static_cast<long>(std::ceil(n_bytes / (double)transport_pkt::max_pkt_size())); - - // Parse the packets looking for C/S packets and dump them to a disk if - // necessary - for(long i=0; i<n_packets; i++) { - - if(d_disk_write) { - if(pkts[i].chan() == CONTROL_CHAN) - d_cs_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size()); - else - d_ofile.write((const char *)&pkts[i], transport_pkt::max_pkt_size()); - - d_cs_ofile.flush(); - d_ofile.flush(); - } - - if(pkts[i].chan() == CONTROL_CHAN) - parse_cs(invocation_handle, pkts[i]); - } - - d_cs->send(s_response_usrp_tx_write, - pmt_list3(invocation_handle, PMT_T, channel)); - - return; -} - -void -usrp_tx_stub::parse_cs(pmt_t invocation_handle, transport_pkt pkt) -{ - - long payload_len = pkt.payload_len(); - long curr_payload = 0; - - size_t ignore; - - // There is the possibility that the responses for a single USB packet full of - // CS packets will not fit back in a single USB packet, considering some - // responses are greater than their commands (read registers). - new_packet: - pmt_t v_pkt = pmt_make_u8vector(sizeof(transport_pkt), 0); - - transport_pkt *q_pkt = - (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, ignore); - - q_pkt->set_header(0, CONTROL_CHAN, 0, 0); - q_pkt->set_timestamp(0xffffffff); - - // We dispatch based on the control packet type, however we can extract the - // opcode and the length immediately which is consistent in all responses. - // - // Since each control packet can have multiple responses, we keep reading the - // lengths of each subpacket until we reach the payload length. - while(curr_payload < payload_len) { - - pmt_t sub_packet = pkt.read_subpacket(curr_payload); - pmt_t op_symbol = pmt_nth(0, sub_packet); - - int len = pkt.cs_len(curr_payload); - - if(verbose) - std::cout << "[USRP_TX_STUB] Parsing subpacket " - << op_symbol << " ... length " << len << std::endl; - - //----------------- PING FIXED ------------------// - if(pmt_eq(op_symbol, s_op_ping_fixed)) { - - long rid = pmt_to_long(pmt_nth(1, sub_packet)); - long pingval = pmt_to_long(pmt_nth(2, sub_packet)); - - // Generate a reply and put it in the queue for the RX stub to read - if(!q_pkt->cs_ping_reply(rid, pingval)) - goto new_packet; - - if(verbose) - std::cout << "[USRP_TX_STUB] Generated ping response " - << "(" - << "RID: " << rid << ", " - << "VAL: " << pingval - << ")\n"; - } - - //----------------- READ REG ------------------// - if(pmt_eq(op_symbol, s_op_read_reg)) { - - long rid = pmt_to_long(pmt_nth(1, sub_packet)); - long reg_num = pmt_to_long(pmt_nth(2, sub_packet)); - long reg_val = 0xdeef; - - // Generate a reply and put it in the queue for the RX stub to read - if(!q_pkt->cs_read_reg_reply(rid, reg_num, reg_val)) - goto new_packet; - - if(verbose) - std::cout << "[USRP_TX_STUB] Generated read register response " - << "(" - << "RID: " << rid << ", " - << "REG: " << reg_num << ", " - << "VAL: " << reg_val - << ")\n"; - } - - //----------------- DELAY ------------------// - if(pmt_eq(op_symbol, s_op_delay)) { - - long ticks = pmt_to_long(pmt_nth(1, sub_packet)); - - if(verbose) - std::cout << "[USRP_TX_STUB] Received delay command " - << "(" - << "Ticks: " << ticks - << ")\n"; - } - - //----------------- WRITE REG ------------------// - if(pmt_eq(op_symbol, s_op_write_reg)) { - - pmt_t reg_num = pmt_nth(1, sub_packet); - pmt_t reg_val = pmt_nth(2, sub_packet); - - if(verbose) - std::cout << "[USRP_TX_STUB] Received write register command " - << "(" - << "RegNum: " << reg_num << ", " - << "Val: " << reg_val - << ")\n"; - } - - //----------------- WRITE REG MASK ---------------// - if(pmt_eq(op_symbol, s_op_write_reg_masked)) { - - pmt_t reg_num = pmt_nth(1, sub_packet); - pmt_t reg_val = pmt_nth(2, sub_packet); - pmt_t mask = pmt_nth(3, sub_packet); - - if(verbose) - std::cout << "[USRP_TX_STUB] Received write register command " - << "(" - << "RegNum: " << reg_num << ", " - << "Val: " << reg_val << ", " - << "Mask: " << mask - << ")\n"; - } - - //---------------- I2C WRITE ------------------// - if(pmt_eq(op_symbol, s_op_i2c_write)) { - pmt_t i2c_addr = pmt_nth(1, sub_packet); - pmt_t i2c_data = pmt_nth(2, sub_packet); - - if(verbose) - std::cout << "[USRP_TX_STUB] Received i2c write command " - << "(" - << "Addr: " << i2c_addr << ", " - << "Data: " << i2c_data - << ")\n"; - } - - //---------------- I2C READ ------------------// - if(pmt_eq(op_symbol, s_op_i2c_read)) { - long rid = pmt_to_long(pmt_nth(1, sub_packet)); - long i2c_addr = pmt_to_long(pmt_nth(2, sub_packet)); - long i2c_bytes = pmt_to_long(pmt_nth(3, sub_packet)); - - // Create data to place as a response, filled with 0xff - size_t ignore; - pmt_t i2c_data = pmt_make_u8vector(i2c_bytes, 0xff); - uint8_t *w_data = (uint8_t *) pmt_u8vector_writable_elements(i2c_data, ignore); - - // Generate a reply and put it in the queue for the RX stub to read - if(!q_pkt->cs_i2c_read_reply(rid, i2c_addr, w_data, i2c_bytes)) - goto new_packet; - - if(verbose) - std::cout << "[USRP_TX_STUB] Received i2c read " - << "(" - << "RID: " << rid << ", " - << "Addr: " << i2c_addr << ", " - << "Bytes: " << i2c_bytes - << ")\n"; - } - - //---------------- SPI WRITE ------------------// - if(pmt_eq(op_symbol, s_op_spi_write)) { - long enables = pmt_to_long(pmt_nth(1, sub_packet)); - long format = pmt_to_long(pmt_nth(2, sub_packet)); - long opt = pmt_to_long(pmt_nth(3, sub_packet)); - pmt_t data = pmt_nth(4, sub_packet); - - if(verbose) - std::cout << "[USRP_TX_STUB] Received spi write command " - << "(" - << "Enables: " << enables << ", " - << "Format: " << format << ", " - << "Options: " << opt << ", " - << "Data: " << data - << ")\n"; - } - - //---------------- SPI READ ------------------// - if(pmt_eq(op_symbol, s_op_spi_read)) { - long rid = pmt_to_long(pmt_nth(1, sub_packet)); - long enables = pmt_to_long(pmt_nth(2, sub_packet)); - long format = pmt_to_long(pmt_nth(3, sub_packet)); - long opt = pmt_to_long(pmt_nth(4, sub_packet)); - long n_bytes = pmt_to_long(pmt_nth(5, sub_packet)); - - // Create data to place as a fake response - size_t ignore; - pmt_t spi_data = pmt_make_u8vector(n_bytes, 0xff); - uint8_t *w_data = (uint8_t *) pmt_u8vector_writable_elements(spi_data, ignore); - - // Generate a reply and put it in the queue for the RX stub to read - if(!q_pkt->cs_spi_read_reply(rid, w_data, n_bytes)) - goto new_packet; - - if(verbose) - std::cout << "[USRP_TX_STUB] Received spi read command " - << "(" - << "RID: " << rid << ", " - << "Enables: " << enables << ", " - << "Format: " << format << ", " - << "Options: " << opt << ", " - << "Bytes: " << n_bytes - << ")\n"; - - } - - // Each subpacket has an unaccounted for 2 bytes which is the opcode - // and the length field - curr_payload += len + 2; - - // All subpackets are 32-bit aligned - int align_offset = 4 - (curr_payload % 4); - - if(align_offset != 4) - curr_payload += align_offset; - - } - - // If the packet has data in the payload, it needs queued - if(q_pkt->payload_len() > 0) - d_cs_queue.push(pmt_list2(invocation_handle, v_pkt)); - - return; -} - -REGISTER_MBLOCK_CLASS(usrp_tx_stub); diff --git a/usrp/limbo/inband/usrp_tx_stub.h b/usrp/limbo/inband/usrp_tx_stub.h deleted file mode 100644 index b81037ad71..0000000000 --- a/usrp/limbo/inband/usrp_tx_stub.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_TX_STUB_H -#define INCLUDED_USRP_TX_STUB_H - -#include <mblock/mblock.h> -#include <vector> -#include "usrp_standard.h" -#include <fstream> -#include <usrp_inband_usb_packet.h> - -typedef usrp_inband_usb_packet transport_pkt; - -/*! - * \brief Implements the low level usb interface to the USRP - */ -class usrp_tx_stub : public mb_mblock -{ - public: - - mb_port_sptr d_cs; - usrp_standard_tx* d_utx; - - std::ofstream d_ofile; - std::ofstream d_cs_ofile; - - bool d_disk_write; - - public: - usrp_tx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_tx_stub(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - - private: - void write(pmt_t data); - void parse_cs(pmt_t invocation_handle, transport_pkt pkt); - -}; - - -#endif /* INCLUDED_USRP_TX_STUB_H */ - diff --git a/usrp/limbo/inband/usrp_usb_interface.cc b/usrp/limbo/inband/usrp_usb_interface.cc deleted file mode 100644 index fb7109a5a5..0000000000 --- a/usrp/limbo/inband/usrp_usb_interface.cc +++ /dev/null @@ -1,601 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <usrp_usb_interface.h> - -#include <iostream> -#include <vector> -#include <usb.h> -#include <mblock/class_registry.h> -#include <usrp_inband_usb_packet.h> -#include <fpga_regs_common.h> -#include "usrp_rx.h" -#include <usrp_rx_stub.h> -#include "usrp_tx.h" -#include "usrp_standard.h" -#include <stdio.h> -#include <usrp_dbid.h> - -typedef usrp_inband_usb_packet transport_pkt; - -#include <symbols_usrp_interface_cs.h> -#include <symbols_usrp_tx_cs.h> -#include <symbols_usrp_rx_cs.h> -static pmt_t s_shutdown = pmt_intern("%shutdown"); - -static const bool verbose = false; - - -/*! - * \brief Initializes the USB interface m-block. - * - * The \p user_arg should be a PMT dictionary which can contain optional - * arguments for the block, such as the decimatoin and interpolation rate. - */ -usrp_usb_interface::usrp_usb_interface(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg) - : mb_mblock(rt, instance_name, user_arg), - d_fake_usrp(false), - d_rx_reading(false), - d_interp_tx(128), - d_decim_rx(128), - d_rf_freq(-1), - d_rbf("inband_tx_rx.rbf") -{ - // Dictionary for arguments to all of the components - pmt_t usrp_dict = user_arg; - - // Default TX/RX interface - std::string tx_interface = "usrp_tx"; - std::string rx_interface = "usrp_rx"; - - if (pmt_is_dict(usrp_dict)) { - - // The 'fake-usrp' key enables the TX and RX stubs if PMT_T - if(pmt_t fake_usrp = pmt_dict_ref(usrp_dict, - pmt_intern("fake-usrp"), - PMT_NIL)) { - if(pmt_eqv(fake_usrp, PMT_T)) { - tx_interface = "usrp_tx_stub"; - rx_interface = "usrp_rx_stub"; - d_fake_usrp=true; - } - } - - // Read the TX interpolations - if(pmt_t interp_tx = pmt_dict_ref(usrp_dict, - pmt_intern("interp-tx"), - PMT_NIL)) { - if(!pmt_eqv(interp_tx, PMT_NIL)) - d_interp_tx = pmt_to_long(interp_tx); - } - - // Read the RX decimation rate - if(pmt_t decim_rx = pmt_dict_ref(usrp_dict, - pmt_intern("decim-rx"), - PMT_NIL)) { - if(!pmt_eqv(decim_rx, PMT_NIL)) - d_decim_rx = pmt_to_long(decim_rx); - } - - // Read the RBF - if(pmt_t rbf = pmt_dict_ref(usrp_dict, - pmt_intern("rbf"), - PMT_NIL)) { - if(!pmt_eqv(rbf, PMT_NIL)) - d_rbf = pmt_symbol_to_string(rbf); - } - - // The RF center frequency - if(pmt_t rf_freq = pmt_dict_ref(usrp_dict, - pmt_intern("rf-freq"), - PMT_NIL)) { - if(!pmt_eqv(rf_freq, PMT_NIL)) - d_rf_freq = pmt_to_double(rf_freq); - } - } - - if (verbose) { - std::cout << "[USRP_USB_INTERFACE] Setting USRP RBF to " - << d_rbf << std::endl; - - std::cout << "[USRP_USB_INTERFACE] Setting TX interpolation to " - << d_interp_tx << std::endl; - - std::cout << "[USRP_USB_INTERFACE] Setting RX interpolation to " - << d_decim_rx << std::endl; - - std::cout << "[USRP_USB_INTERFACE] Using TX interface: " - << tx_interface << "\n"; - - std::cout << "[USRP_USB_INTERFACE] Using RX interface: " - << rx_interface << "\n"; - - } - - d_cs = define_port("cs", "usrp-interface-cs", true, mb_port::EXTERNAL); - d_rx_cs = define_port("rx_cs", "usrp-rx-cs", false, mb_port::INTERNAL); - d_tx_cs = define_port("tx_cs", "usrp-tx-cs", false, mb_port::INTERNAL); - - // Connect to TX and RX - define_component("tx", tx_interface, usrp_dict); - define_component("rx", rx_interface, usrp_dict); - connect("self", "rx_cs", "rx", "cs"); - connect("self", "tx_cs", "tx", "cs"); - - // FIXME: the code should query the FPGA to retrieve the number of channels and such - d_ntx_chan = 2; - d_nrx_chan = 2; -} - -usrp_usb_interface::~usrp_usb_interface() -{ - -} - -void -usrp_usb_interface::initial_transition() -{ - -} - -/*! - * \brief Handles all incoming signals to the block from the lowest m-blocks - * which read/write to the bus, or the higher m-block which is the USRP server. - */ -void -usrp_usb_interface::handle_message(mb_message_sptr msg) -{ - pmt_t event = msg->signal(); // the "name" of the message - pmt_t port_id = msg->port_id(); // which port it came in on - pmt_t data = msg->data(); - pmt_t invocation_handle; - - if (pmt_eq(event, s_shutdown)) // ignore (for now) - return; - - //------------- CONTROL / STATUS -------------// - if (pmt_eq(port_id, d_cs->port_symbol())) { - - //------------ OPEN --------------// - if (pmt_eq(event, s_cmd_usrp_open)){ - handle_cmd_open(data); - return; - } - //----------- CLOSE -------------// - else if (pmt_eq(event, s_cmd_usrp_close)) { - handle_cmd_close(data); - return; - } - //---------- NTX CHAN ----------// - else if (pmt_eq(event, s_cmd_usrp_ntx_chan)) { - invocation_handle = pmt_nth(0, data); - d_cs->send(s_response_usrp_ntx_chan, - pmt_list2(invocation_handle, - pmt_from_long(d_ntx_chan))); - return; - } - //---------- NRX CHAN ----------// - else if (pmt_eq(event, s_cmd_usrp_nrx_chan)) { - invocation_handle = pmt_nth(0, data); - d_cs->send(s_response_usrp_nrx_chan, - pmt_list2(invocation_handle, - pmt_from_long(d_nrx_chan))); - return; - } - //------------ WRITE -----------// - else if(pmt_eq(event, s_cmd_usrp_write)) { - handle_cmd_write(data); - return; - } - //-------- START READING --------// - else if(pmt_eq(event, s_cmd_usrp_start_reading)) { - handle_cmd_start_reading(data); - return; - } - //-------- STOP READING --------// - else if(pmt_eq(event, s_cmd_usrp_stop_reading)) { - handle_cmd_stop_reading(data); - return; - } - - goto unhandled; - } - - //---------------- RX ------------------// - if (pmt_eq(port_id, d_rx_cs->port_symbol())) { - - // Relay reads back up - if(pmt_eq(event, s_response_usrp_rx_read)) { - d_cs->send(s_response_usrp_read, data); - return; - } - - goto unhandled; - } - - //---------------- TX ------------------// - if (pmt_eq(port_id, d_tx_cs->port_symbol())) { - - if(pmt_eq(event, s_response_usrp_tx_write)) { - - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t status = pmt_nth(1, data); - pmt_t channel = pmt_nth(2, data); - - d_cs->send(s_response_usrp_write, - pmt_list3(invocation_handle, - status, - channel)); - - return; - } - - goto unhandled; - } - - unhandled: - std::cout << "[USRP_USB_INTERFACE] unhandled msg: " << msg << std::endl; -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * open a USB connection to the USRP (cmd-usrp-open). - * - * The \p data parameter is a PMT list, where the elements are an invocation - * handle and the USRP number. - */ -void -usrp_usb_interface::handle_cmd_open(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - long which_usrp = pmt_to_long(pmt_nth(1, data)); - pmt_t reply_data; - - if(d_fake_usrp) { - d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T)); - return; - } - - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Handling open request for USRP " << which_usrp << "\n"; - - // Open up a standard RX and TX for communication with the USRP - - d_utx = usrp_standard_tx::make(which_usrp, - d_interp_tx, - 1, // 1 channel - -1, // mux - 4096, // USB block size - 16, // nblocks for async transfers - d_rbf - ); - - if(d_utx==0) { - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Failed to open TX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; - } - - // Perform TX daughterboard tuning - double target_freq; - unsigned int mux; - int tgain, rgain; - float input_rate; - bool ok; - usrp_tune_result r; - - // Cast to usrp_basic and then detect daughterboards - d_ub_tx = d_utx; - usrp_subdev_spec tspec = pick_tx_subdevice(); - db_base_sptr tsubdev = d_ub_tx->selected_subdev(tspec); - - // Set the TX mux value - mux = d_utx->determine_tx_mux_value(tspec); - d_utx->set_mux(mux); - - // Set the TX gain and determine rate - tgain = tsubdev->gain_max(); - tsubdev->set_gain(tgain); - input_rate = d_ub_tx->converter_rate() / d_utx->interp_rate(); - - // Perform the actual tuning, if no frequency specified then pick - if(d_rf_freq==-1) - target_freq = tsubdev->freq_min()+((tsubdev->freq_max()-tsubdev->freq_min())/2.0); - else - target_freq = d_rf_freq; - ok = d_utx->tune(tsubdev->which(), tsubdev, target_freq, &r); - tsubdev->set_enable(true); - - if(verbose) { - printf("TX Subdevice name is %s\n", tsubdev->name().c_str()); - printf("TX Subdevice freq range: (%g, %g)\n", - tsubdev->freq_min(), tsubdev->freq_max()); - printf("mux: %#08x\n", mux); - printf("target_freq: %f\n", target_freq); - printf("ok: %s\n", ok ? "true" : "false"); - printf("gain: %d\n", tgain); - printf("r.baseband_freq: %f\n", r.baseband_freq); - printf("r.dxc_freq: %f\n", r.dxc_freq); - printf("r.residual_freq: %f\n", r.residual_freq); - printf("r.inverted: %d\n", r.inverted); - } - - if(!ok) { - std::cerr << "[USRP_USB_INTERFACE] Failed to set center frequency on TX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; - } - - d_utx->start(); - - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Setup TX channel\n"; - - d_urx = - usrp_standard_rx::make (which_usrp, - d_decim_rx, - 1, // nchan - -1, // mux - 0, // set blank mode to start - 4096, // USB block size - 16, // number of blocks for async transfers - d_rbf); - - if(!d_urx) { - if (verbose) - std::cout << "[usrp_server] Failed to open RX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; - } - - // Cast to usrp_basic and then detect daughterboards - d_ub_rx = d_urx; - usrp_subdev_spec rspec = pick_rx_subdevice(); - db_base_sptr rsubdev = d_ub_rx->selected_subdev(rspec); - - // Set the RX mux value - mux = d_urx->determine_rx_mux_value(rspec); - d_urx->set_mux(mux); - - // Set the RX gain and determine rate - rgain = rsubdev->gain_max()/2.0; - rsubdev->set_gain(rgain); - input_rate = d_ub_rx->converter_rate() / d_urx->decim_rate(); - - ok = d_urx->tune(rsubdev->which(), rsubdev, target_freq, &r); - rsubdev->set_enable(true); - - if(verbose) { - printf("RX Subdevice name is %s\n", rsubdev->name().c_str()); - printf("RX Subdevice freq range: (%g, %g)\n", - rsubdev->freq_min(), rsubdev->freq_max()); - printf("mux: %#08x\n", mux); - printf("target_freq: %f\n", target_freq); - printf("ok: %s\n", ok ? "true" : "false"); - printf("gain: %d\n", rgain); - printf("r.baseband_freq: %f\n", r.baseband_freq); - printf("r.dxc_freq: %f\n", r.dxc_freq); - printf("r.residual_freq: %f\n", r.residual_freq); - printf("r.inverted: %d\n", r.inverted); - } - - if(!ok) { - std::cerr << "[USRP_USB_INTERFACE] Failed to set center frequency on RX\n"; - reply_data = pmt_list2(invocation_handle, PMT_F); - d_cs->send(s_response_usrp_open, reply_data); - return; - } - - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Setup RX channel\n"; - -// d_utx->_write_fpga_reg(FR_DEBUG_EN,0xf); -// d_utx->_write_oe(0, 0xffff, 0xffff); -// d_urx->_write_oe(0, 0xffff, 0xffff); -// d_utx->_write_oe(1, 0xffff, 0xffff); -// d_urx->_write_oe(1, 0xffff, 0xffff); - - d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T)); -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * write data to the USB bus (cmd-usrp-write). - * - * The \p data parameter is a PMT list containing 3 mandatory elements in the - * following order: an invocation handle, channel, and a uniform vector - * representation of the packets. - */ -void -usrp_usb_interface::handle_cmd_write(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - pmt_t channel = pmt_nth(1, data); - pmt_t pkts = pmt_nth(2, data); - - pmt_t tx_handle = pmt_make_any(d_utx); - - d_tx_cs->send(s_cmd_usrp_tx_write, - pmt_list4(invocation_handle, - channel, - pkts, - tx_handle)); -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * start reading data from the USB bus (cmd-usrp-start-reading). - * - * The \p data parameter is a PMT list with a single element: an invocation - * handle which can be returned with the response. - */ -void -usrp_usb_interface::handle_cmd_start_reading(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - - if(verbose) - std::cout << "[USRP_USB_INTERFACE] Starting RX...\n"; - - if(!d_fake_usrp) - d_urx->start(); - - pmt_t rx_handle = pmt_make_any(d_urx); - - d_rx_cs->send(s_cmd_usrp_rx_start_reading, pmt_list2(PMT_NIL, rx_handle)); - - d_rx_reading = true; - - return; -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * stop reading data from the USB bus (cmd-usrp-stop-reading). - * - * The \p data parameter is a PMT list with a single element: an invocation - * handle which can be returned with the response. - */ -void -usrp_usb_interface::handle_cmd_stop_reading(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - - if(!d_fake_usrp) { - if(verbose) - std::cout << "[USRP_USB_INTERFACE] Stopping RX...\n"; - usrp_rx_stop = true; - - // Used to allow a read() being called by a lower layer to complete before - // stopping, else there can be partial data left on the bus and can generate - // errors. - while(usrp_rx_stop) {usleep(1);} - d_urx->stop(); - } - else { - if(verbose) - std::cout << "[USRP_USB_INTERFACE] Stopping fake RX...\n"; - usrp_rx_stop_stub = true; // extern to communicate with stub to wait - } - - d_rx_reading = false; - - return; -} - -/*! - * \brief Called by the handle_message() method when the incoming signal is to - * close the USB connection to the USRP. - * - * The \p data parameter is a PMT list with a single element: an invocation - * handle which can be returned with the response. - */ -void -usrp_usb_interface::handle_cmd_close(pmt_t data) -{ - pmt_t invocation_handle = pmt_nth(0, data); - - if(d_rx_reading) - handle_cmd_stop_reading(PMT_NIL); - - if(d_fake_usrp) { - d_cs->send(s_response_usrp_close, pmt_list2(invocation_handle, PMT_T)); - return; - } - - if (verbose) - std::cout << "[USRP_USB_INTERFACE] Handling close request for USRP\n"; - - d_utx.reset(); - d_urx.reset(); - - d_cs->send(s_response_usrp_close, pmt_list2(invocation_handle, PMT_T)); - - // FIXME This seems like a _very_ strange place to be calling shutdown_all. - // That decision should be left to high-level code, not low-level code like this. - shutdown_all(PMT_T); -} - -usrp_subdev_spec -usrp_usb_interface::pick_rx_subdevice() -{ - int dbids[] = { - USRP_DBID_FLEX_400_RX, - USRP_DBID_FLEX_900_RX, - USRP_DBID_FLEX_1200_RX, - USRP_DBID_FLEX_2400_RX, - USRP_DBID_TV_RX, - USRP_DBID_TV_RX_REV_2, - USRP_DBID_DBS_RX, - USRP_DBID_BASIC_RX - }; - - std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int))); - return pick_subdev(d_ub_rx, candidates); -} - -usrp_subdev_spec -usrp_usb_interface::pick_tx_subdevice() -{ - int dbids[] = { - USRP_DBID_FLEX_400_TX, - USRP_DBID_FLEX_900_TX, - USRP_DBID_FLEX_1200_TX, - USRP_DBID_FLEX_2400_TX, - USRP_DBID_BASIC_TX - }; - - std::vector<int> candidates(dbids, dbids+(sizeof(dbids)/sizeof(int))); - return pick_subdev(d_ub_tx, candidates); -} - -usrp_subdev_spec -usrp_usb_interface::pick_subdev(boost::shared_ptr<usrp_basic> d_usrp_basic, std::vector<int> candidates) -{ - int dbid0 = d_usrp_basic->selected_subdev(usrp_subdev_spec(0, 0))->dbid(); - int dbid1 = d_usrp_basic->selected_subdev(usrp_subdev_spec(1, 0))->dbid(); - - for (int i = 0; i < candidates.size(); i++) { - int dbid = candidates[i]; - if (dbid0 == dbid) - return usrp_subdev_spec(0, 0); - if (dbid1 == dbid) - return usrp_subdev_spec(1, 0); - } - - if (dbid0 >= 0) - return usrp_subdev_spec(0, 0); - if (dbid1 >= 0) - return usrp_subdev_spec(1, 0); - - throw std::runtime_error("No suitable daughterboard found!"); -} - - -REGISTER_MBLOCK_CLASS(usrp_usb_interface); diff --git a/usrp/limbo/inband/usrp_usb_interface.h b/usrp/limbo/inband/usrp_usb_interface.h deleted file mode 100644 index 4d7750a7d6..0000000000 --- a/usrp/limbo/inband/usrp_usb_interface.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2007,2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ -#ifndef INCLUDED_USRP_USB_INTERFACE_H -#define INCLUDED_USRP_USB_INTERFACE_H - -#include <mblock/mblock.h> -#include <vector> -#include "usrp_standard.h" - -/*! - * \brief Implements the low level usb interface to the USRP - */ -class usrp_usb_interface : public mb_mblock -{ - public: - - usrp_standard_tx_sptr d_utx; - usrp_standard_rx_sptr d_urx; - - boost::shared_ptr<usrp_basic> d_ub_tx; - boost::shared_ptr<usrp_basic> d_ub_rx; - - mb_port_sptr d_cs; - mb_port_sptr d_rx_cs; - mb_port_sptr d_tx_cs; - - long d_ntx_chan; - long d_nrx_chan; - - bool d_fake_usrp; - - bool d_rx_reading; - - long d_interp_tx; - long d_decim_rx; - - double d_rf_freq; - - std::string d_rbf; - - public: - usrp_usb_interface(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg); - ~usrp_usb_interface(); - void initial_transition(); - void handle_message(mb_message_sptr msg); - usrp_subdev_spec pick_rx_subdevice(); - usrp_subdev_spec pick_tx_subdevice(); - usrp_subdev_spec pick_subdev(boost::shared_ptr<usrp_basic> d_usrp_basic, std::vector<int> candidates); - - private: - void handle_cmd_open(pmt_t data); - void handle_cmd_close(pmt_t data); - void handle_cmd_write(pmt_t data); - void handle_cmd_start_reading(pmt_t data); - void handle_cmd_stop_reading(pmt_t data); - -}; - - -#endif /* INCLUDED_USRP_USB_INTERFACE_H */ diff --git a/usrp/usrp.pc.in b/usrp/usrp.pc.in index 2a15a05fda..d4794aa6fe 100644 --- a/usrp/usrp.pc.in +++ b/usrp/usrp.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: usrp Description: USRP Client Side C++ interface -Requires: @LIBUSB_PKG_CONFIG_NAME@ @usrp_darwin_omnithread_pc_requires@ +Requires: @LIBUSB_PKG_CONFIG_NAME@ Version: @VERSION@ Libs: -L${libdir} -lusrp Cflags: -I${includedir} diff --git a/usrp2/firmware/lib/adf4350.c b/usrp2/firmware/lib/adf4350.c index 0725c93379..dbab654ea3 100644 --- a/usrp2/firmware/lib/adf4350.c +++ b/usrp2/firmware/lib/adf4350.c @@ -30,7 +30,7 @@ #define MIN_VCO_FREQ U2_DOUBLE_TO_FXPT_FREQ(2.2e9) /* minimum vco freq */ #define MAX_VCO_FREQ U2_DOUBLE_TO_FXPT_FREQ(4.4e9) /* minimum vco freq */ #define MAX_FREQ MAX_VCO_FREQ /* upper bound freq (rf div = 1) */ -#define MIN_FREQ DIV_ROUND(MIN_VCO_FREQ, MAX_RF_DIV) /* calculated lower bound freq */ +#define MIN_FREQ U2_DOUBLE_TO_FXPT_FREQ(68.75e6) /* lower bound freq (rf div = 16) */ u2_fxpt_freq_t adf4350_get_max_freq(void){ return MAX_FREQ; @@ -170,7 +170,7 @@ bool adf4350_set_freq(u2_fxpt_freq_t freq, struct db_base *dbb){ adf4350_load_register(2, dbb); adf4350_load_register(4, dbb); adf4350_load_register(0, dbb); /* register 0 must be last */ - return true; + return adf4350_get_locked(dbb); } u2_fxpt_freq_t adf4350_get_freq(struct db_base *dbb){ diff --git a/usrp2/firmware/lib/db_bitshark_rx.c b/usrp2/firmware/lib/db_bitshark_rx.c index 669bb7c49d..72cafa2e9a 100644 --- a/usrp2/firmware/lib/db_bitshark_rx.c +++ b/usrp2/firmware/lib/db_bitshark_rx.c @@ -186,6 +186,7 @@ bitshark_rx_init(struct db_base *dbb) application. */ db->extra.set_bw(dbb, 25000); /* 25 MHz channel bw */ mdelay(5); + return true; } diff --git a/usrp2/firmware/lib/db_wbxng.c b/usrp2/firmware/lib/db_wbxng.c index 115ac8a246..954633da24 100644 --- a/usrp2/firmware/lib/db_wbxng.c +++ b/usrp2/firmware/lib/db_wbxng.c @@ -29,6 +29,9 @@ #include <stdio.h> #include <stdint.h> +#define min(X,Y) ((X) < (Y) ? (X) : (Y)) +#define max(X,Y) ((X) > (Y) ? (X) : (Y)) + bool wbxng_init_rx(struct db_base *dbb); bool wbxng_init_tx(struct db_base *dbb); bool wbxng_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc); @@ -45,7 +48,7 @@ struct db_wbxng_rx db_wbxng_rx = { .base.is_tx = false, .base.output_enables = RX2_RX1N|RXBB_EN|ATTN_MASK|ENABLE_33|ENABLE_5|PLL_CE|PLL_PDBRF|ATTN_MASK, .base.used_pins = 0xFFFF, - .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(67.5e6), + .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(68.75e6), .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2200e6), .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0), .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(31.5), @@ -81,7 +84,7 @@ struct db_wbxng_tx db_wbxng_tx = { .base.is_tx = true, .base.output_enables = RX_TXN|TXMOD_EN|ENABLE_33|ENABLE_5|PLL_CE|PLL_PDBRF, .base.used_pins = 0xFFFF, - .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(67.5e6), + .base.freq_min = U2_DOUBLE_TO_FXPT_FREQ(68.75e6), .base.freq_max = U2_DOUBLE_TO_FXPT_FREQ(2200e6), .base.gain_min = U2_DOUBLE_TO_FXPT_GAIN(0), .base.gain_max = U2_DOUBLE_TO_FXPT_GAIN(25), @@ -149,8 +152,11 @@ wbxng_init_rx(struct db_base *dbb) bool wbxng_set_freq(struct db_base *dbb, u2_fxpt_freq_t freq, u2_fxpt_freq_t *dc) { - bool ok = adf4350_set_freq(2*freq,dbb); - *dc = adf4350_get_freq(dbb)/2; + // clamp freq + u2_fxpt_freq_t clamp_freq = max(dbb->freq_min, min(freq, dbb->freq_max)); + //printf("Requested LO freq = %u", (uint32_t) ((clamp_freq >> U2_FPF_RP)/1000)); + bool ok = adf4350_set_freq(clamp_freq<<1,dbb); + *dc = adf4350_get_freq(dbb)>>1; return ok; } diff --git a/usrp2/host/apps/Makefile.am b/usrp2/host/apps/Makefile.am index db76601967..4a26898fa7 100644 --- a/usrp2/host/apps/Makefile.am +++ b/usrp2/host/apps/Makefile.am @@ -24,9 +24,8 @@ AM_CPPFLAGS = \ $(GRUEL_INCLUDES) LDADD = \ - $(USRP2_LA) \ - $(GRUEL_LA) \ - $(OMNITHREAD_LA) + $(USRP2_LA) \ + $(GRUEL_LA) bin_PROGRAMS = \ find_usrps \ diff --git a/usrp2/host/apps/tx_samples.cc b/usrp2/host/apps/tx_samples.cc index 5c3728fb15..3e41bbf8d0 100644 --- a/usrp2/host/apps/tx_samples.cc +++ b/usrp2/host/apps/tx_samples.cc @@ -150,6 +150,10 @@ main(int argc, char **argv) interp = strtol(optarg, 0, 0); break; + case 'g': + gain = strtod(optarg, 0); + break; + case 'S': if (!strtod_si(optarg, &tmp)){ std::cerr << "invalid number: " << optarg << std::endl; diff --git a/usrp2/host/lib/Makefile.am b/usrp2/host/lib/Makefile.am index 772cf1446d..cda051bb07 100644 --- a/usrp2/host/lib/Makefile.am +++ b/usrp2/host/lib/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2010 Free Software Foundation, Inc. # # 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 @@ -45,11 +45,9 @@ libusrp2_la_SOURCES = \ rx_sample_handler.cc \ strtod_si.c \ usrp2.cc \ - usrp2_impl.cc \ - usrp2_thread.cc + usrp2_impl.cc libusrp2_la_LIBADD = \ - $(OMNITHREAD_LA) \ $(GRUEL_LA) \ $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) @@ -63,5 +61,4 @@ noinst_HEADERS = \ pktfilter.h \ ring.h \ usrp2_bytesex.h \ - usrp2_impl.h \ - usrp2_thread.h + usrp2_impl.h
\ No newline at end of file diff --git a/usrp2/host/lib/control.cc b/usrp2/host/lib/control.cc index bb71f79c27..33a95c0787 100644 --- a/usrp2/host/lib/control.cc +++ b/usrp2/host/lib/control.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,14 +23,14 @@ #include <config.h> #endif -#include <gnuradio/omni_time.h> #include "control.h" #include <iostream> +#include <gruel/thread.h> namespace usrp2 { pending_reply::pending_reply(unsigned int rid, void *buffer, size_t len) - : d_rid(rid), d_buffer(buffer), d_len(len), d_mutex(), d_cond(&d_mutex), + : d_rid(rid), d_buffer(buffer), d_len(len), d_mutex(), d_cond(), d_complete(false) { } @@ -43,22 +43,23 @@ namespace usrp2 { int pending_reply::wait_for_completion(double secs) { - omni_time abs_timeout = omni_time::time(omni_time(secs)); - omni_mutex_lock l(d_mutex); - while (!d_complete){ - int r = d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs); - if (r == 0) // timed out - return 0; + gruel::scoped_lock l(d_mutex); + boost::system_time to(gruel::get_new_timeout(secs)); + + while (!d_complete) { + if (!d_cond.timed_wait(l, to)) + return 0; // timed out } + return 1; } void pending_reply::notify_completion() { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock l(d_mutex); d_complete = true; - d_cond.signal(); + d_cond.notify_one(); } } // namespace usrp2 diff --git a/usrp2/host/lib/control.h b/usrp2/host/lib/control.h index 46ce791ea3..3515ba10fe 100644 --- a/usrp2/host/lib/control.h +++ b/usrp2/host/lib/control.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009 Free Software Foundation, Inc. + * Copyright 2008,2009,2010 Free Software Foundation, Inc. * * 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 @@ -19,7 +19,7 @@ #ifndef INCLUDED_CONTROL_H #define INCLUDED_CONTROL_H -#include <gnuradio/omnithread.h> +#include <gruel/thread.h> #include <usrp2_eth_packet.h> namespace usrp2 { @@ -130,8 +130,8 @@ namespace usrp2 { size_t d_len; // d_mutex is used with d_cond and also protects d_complete - omni_mutex d_mutex; - omni_condition d_cond; + gruel::mutex d_mutex; + gruel::condition_variable d_cond; bool d_complete; public: diff --git a/usrp2/host/lib/ring.cc b/usrp2/host/lib/ring.cc index 3c45821f84..d0048418cf 100644 --- a/usrp2/host/lib/ring.cc +++ b/usrp2/host/lib/ring.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -29,7 +29,7 @@ namespace usrp2 { ring::ring(unsigned int entries) : d_max(entries), d_read_ind(0), d_write_ind(0), d_ring(entries), - d_mutex(), d_not_empty(&d_mutex) + d_mutex(), d_not_empty() { for (unsigned int i = 0; i < entries; i++) { d_ring[i].d_base = 0; @@ -40,15 +40,15 @@ namespace usrp2 { void ring::wait_for_not_empty() { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock l(d_mutex); while (empty()) - d_not_empty.wait(); + d_not_empty.wait(l); } bool ring::enqueue(void *p, size_t len) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock l(d_mutex); if (full()) return false; @@ -56,14 +56,14 @@ namespace usrp2 { d_ring[d_write_ind].d_base = p; inc_write_ind(); - d_not_empty.signal(); + d_not_empty.notify_one(); return true; } bool ring::dequeue(void **p, size_t *len) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock l(d_mutex); if (empty()) return false; diff --git a/usrp2/host/lib/ring.h b/usrp2/host/lib/ring.h index 19ae9ae972..fd0ad0a9f3 100644 --- a/usrp2/host/lib/ring.h +++ b/usrp2/host/lib/ring.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,10 +21,10 @@ #ifndef INCLUDED_RING_H #define INCLUDED_RING_H -#include <gnuradio/omnithread.h> #include <stddef.h> #include <vector> #include <boost/shared_ptr.hpp> +#include <gruel/thread.h> namespace usrp2 { @@ -46,8 +46,8 @@ namespace usrp2 { }; std::vector<ring_desc> d_ring; - omni_mutex d_mutex; - omni_condition d_not_empty; + gruel::mutex d_mutex; + gruel::condition_variable d_not_empty; void inc_read_ind() { diff --git a/usrp2/host/lib/usrp2_impl.cc b/usrp2/host/lib/usrp2_impl.cc index d4f29baf0e..333e2d1e78 100644 --- a/usrp2/host/lib/usrp2_impl.cc +++ b/usrp2/host/lib/usrp2_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009 Free Software Foundation, Inc. + * Copyright 2008,2009,2010 Free Software Foundation, Inc. * * 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 @@ -24,9 +24,10 @@ #include <usrp2/tune_result.h> #include <usrp2/copiers.h> #include <gruel/inet.h> +#include <gruel/realtime.h> +#include <boost/bind.hpp> #include <usrp2_types.h> #include "usrp2_impl.h" -#include "usrp2_thread.h" #include "eth_buffer.h" #include "pktfilter.h" #include "control.h" @@ -129,10 +130,10 @@ namespace usrp2 { usrp2::impl::impl(const std::string &ifc, props *p, size_t rx_bufsize) - : d_eth_buf(new eth_buffer(rx_bufsize)), d_interface_name(ifc), d_pf(0), d_bg_thread(0), + : d_eth_buf(new eth_buffer(rx_bufsize)), d_interface_name(ifc), d_pf(0), d_bg_running(false), d_rx_seqno(-1), d_tx_seqno(0), d_next_rid(0), d_num_rx_frames(0), d_num_rx_missing(0), d_num_rx_overruns(0), d_num_rx_bytes(0), - d_num_enqueued(0), d_enqueued_mutex(), d_bg_pending_cond(&d_enqueued_mutex), + d_num_enqueued(0), d_enqueued_mutex(), d_bg_pending_cond(), d_channel_rings(NCHANS), d_tx_interp(0), d_rx_decim(0), d_dont_enqueue(true) { if (!d_eth_buf->open(ifc, htons(U2_ETHERTYPE))) @@ -152,8 +153,8 @@ namespace usrp2 { memset(d_pending_replies, 0, sizeof(d_pending_replies)); - d_bg_thread = new usrp2_thread(this); - d_bg_thread->start(); + // Kick off receive thread + start_bg(); // In case the USRP2 was left streaming RX // FIXME: only one channel right now @@ -208,7 +209,6 @@ namespace usrp2 { usrp2::impl::~impl() { stop_bg(); - d_bg_thread = 0; // thread class deletes itself delete d_pf; d_eth_buf->close(); delete d_eth_buf; @@ -336,18 +336,24 @@ namespace usrp2 { // ---------------------------------------------------------------- void + usrp2::impl::start_bg() + { + d_rx_tg.create_thread(boost::bind(&usrp2::impl::bg_loop, this)); + } + + void usrp2::impl::stop_bg() { d_bg_running = false; - d_bg_pending_cond.signal(); - - void *dummy_status; - d_bg_thread->join(&dummy_status); + d_bg_pending_cond.notify_one(); // FIXME: check if needed + d_rx_tg.join_all(); } void usrp2::impl::bg_loop() { + gruel::enable_realtime_scheduling(); + d_bg_running = true; while(d_bg_running) { DEBUG_LOG(":"); @@ -362,9 +368,9 @@ namespace usrp2 { // The channel ring thread that decrements d_num_enqueued to zero // will signal this thread to continue. { - omni_mutex_lock l(d_enqueued_mutex); + gruel::scoped_lock l(d_enqueued_mutex); while(d_num_enqueued > 0 && d_bg_running) - d_bg_pending_cond.wait(); + d_bg_pending_cond.wait(l); } } d_bg_running = false; @@ -463,7 +469,7 @@ namespace usrp2 { unsigned int chan = u2p_chan(&pkt->hdrs.fixed); { - omni_mutex_lock l(d_channel_rings_mutex); + gruel::scoped_lock l(d_channel_rings_mutex); if (!d_channel_rings[chan]) { DEBUG_LOG("!"); @@ -650,7 +656,7 @@ namespace usrp2 { } { - omni_mutex_lock l(d_channel_rings_mutex); + gruel::scoped_lock l(d_channel_rings_mutex); if (d_channel_rings[channel]) { std::cerr << "usrp2: channel " << channel << " already streaming" << std::endl; @@ -704,7 +710,7 @@ namespace usrp2 { } { - omni_mutex_lock l(d_channel_rings_mutex); + gruel::scoped_lock guard(d_channel_rings_mutex); if (d_channel_rings[channel]) { std::cerr << "usrp2: channel " << channel << " already streaming" << std::endl; @@ -758,7 +764,7 @@ namespace usrp2 { } { - omni_mutex_lock l(d_channel_rings_mutex); + gruel::scoped_lock guard(d_channel_rings_mutex); if (d_channel_rings[channel]) { std::cerr << "usrp2: channel " << channel << " already streaming" << std::endl; @@ -820,7 +826,7 @@ namespace usrp2 { op_generic_t reply; { - omni_mutex_lock l(d_channel_rings_mutex); + gruel::scoped_lock l(d_channel_rings_mutex); memset(&cmd, 0, sizeof(cmd)); init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1); @@ -835,6 +841,7 @@ namespace usrp2 { success = transmit_cmd_and_wait(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT); success = success && (ntohx(reply.ok) == 1); d_channel_rings[channel].reset(); + d_rx_seqno = -1; //fprintf(stderr, "usrp2::stop_rx_streaming: success = %d\n", success); return success; } diff --git a/usrp2/host/lib/usrp2_impl.h b/usrp2/host/lib/usrp2_impl.h index a75947922f..eee26358ea 100644 --- a/usrp2/host/lib/usrp2_impl.h +++ b/usrp2/host/lib/usrp2_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009 Free Software Foundation, Inc. + * Copyright 2008,2009,2010 Free Software Foundation, Inc. * * 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 @@ -22,6 +22,7 @@ #include <usrp2/usrp2.h> #include <usrp2/data_handler.h> #include <usrp2_eth_packet.h> +#include <gruel/thread.h> #include <boost/scoped_ptr.hpp> #include "control.h" #include "ring.h" @@ -60,7 +61,8 @@ namespace usrp2 { std::string d_interface_name; pktfilter *d_pf; std::string d_addr; // FIXME: use u2_mac_addr_t instead - usrp2_thread *d_bg_thread; + + boost::thread_group d_rx_tg; volatile bool d_bg_running; // TODO: multistate if needed int d_rx_seqno; @@ -72,14 +74,14 @@ namespace usrp2 { unsigned int d_num_rx_bytes; unsigned int d_num_enqueued; - omni_mutex d_enqueued_mutex; - omni_condition d_bg_pending_cond; + gruel::mutex d_enqueued_mutex; + gruel::condition_variable d_bg_pending_cond; // all pending_replies are stack allocated, thus no possibility of leaking these pending_reply *d_pending_replies[NRIDS]; // indexed by 8-bit reply id std::vector<ring_sptr> d_channel_rings; // indexed by 5-bit channel number - omni_mutex d_channel_rings_mutex; + gruel::mutex d_channel_rings_mutex; db_info d_tx_db_info; db_info d_rx_db_info; @@ -90,20 +92,21 @@ namespace usrp2 { bool d_dont_enqueue; void inc_enqueued() { - omni_mutex_lock l(d_enqueued_mutex); + gruel::scoped_lock l(d_enqueued_mutex); d_num_enqueued++; } void dec_enqueued() { - omni_mutex_lock l(d_enqueued_mutex); + gruel::scoped_lock l(d_enqueued_mutex); if (--d_num_enqueued == 0) - d_bg_pending_cond.signal(); + d_bg_pending_cond.notify_one(); } static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p); void init_et_hdrs(u2_eth_packet_t *p, const std::string &dst); void init_etf_hdrs(u2_eth_packet_t *p, const std::string &dst, int word0_flags, int chan, uint32_t timestamp); + void start_bg(); void stop_bg(); void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd); void init_config_tx_v2_cmd(op_config_tx_v2_cmd *cmd); @@ -119,8 +122,6 @@ namespace usrp2 { impl(const std::string &ifc, props *p, size_t rx_bufsize); ~impl(); - void bg_loop(); - std::string mac_addr() const { return d_addr; } // FIXME: convert from u2_mac_addr_t std::string interface_name() const { return d_interface_name; } @@ -199,6 +200,9 @@ namespace usrp2 { bool sync_every_pps(bool enable); std::vector<uint32_t> peek32(uint32_t addr, uint32_t words); bool poke32(uint32_t addr, const std::vector<uint32_t> &data); + + // Receive thread, need to be public for boost::bind + void bg_loop(); }; } // namespace usrp2 diff --git a/usrp2/host/lib/usrp2_thread.cc b/usrp2/host/lib/usrp2_thread.cc deleted file mode 100644 index d147703959..0000000000 --- a/usrp2/host/lib/usrp2_thread.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 Free Software Foundation, Inc. - * - * 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "usrp2_thread.h" -#include "usrp2_impl.h" -#include <gruel/realtime.h> -#include <gruel/sys_pri.h> -#include <iostream> - -#define USRP2_THREAD_DEBUG 1 - -namespace usrp2 { - - usrp2_thread::usrp2_thread(usrp2::impl *u2) : - omni_thread(NULL, PRIORITY_HIGH), - d_u2(u2) - { - } - - usrp2_thread::~usrp2_thread() - { - // we don't own this, just forget it - d_u2 = 0; - } - - void - usrp2_thread::start() - { - start_undetached(); - } - - void * - usrp2_thread::run_undetached(void *arg) - { - if (gruel::enable_realtime_scheduling(gruel::sys_pri::usrp2_backend()) != gruel::RT_OK) - std::cerr << "usrp2: failed to enable realtime scheduling" << std::endl; - - // This is the first code to run in the new thread context. - d_u2->bg_loop(); - - return 0; - } - -} // namespace usrp2 - diff --git a/usrp2/host/lib/usrp2_thread.h b/usrp2/host/lib/usrp2_thread.h deleted file mode 100644 index 12723e9471..0000000000 --- a/usrp2/host/lib/usrp2_thread.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio 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 3, or (at your option) - * any later version. - * - * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_USRP2_THREAD_H -#define INCLUDED_USRP2_THREAD_H - -#include <gnuradio/omnithread.h> -#include <usrp2_impl.h> - -namespace usrp2 { - - class usrp2_thread : public omni_thread - { - private: - usrp2::impl *d_u2; - - public: - usrp2_thread(usrp2::impl *u2); - ~usrp2_thread(); - - void start(); - - virtual void *run_undetached(void *arg); - }; - -} // namespace usrp2 - -#endif /* INCLUDED_USRP2_THREAD_H */ diff --git a/usrp2/host/usrp2.pc.in b/usrp2/host/usrp2.pc.in index eaef5f41d2..e0c2b1986d 100644 --- a/usrp2/host/usrp2.pc.in +++ b/usrp2/host/usrp2.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: usrp2 Description: Universal Software Radio Peripheral 2 -Requires: gnuradio-omnithread gruel +Requires: gruel Version: @VERSION@ Libs: -L${libdir} -lusrp2 Cflags: -I${includedir} @DEFINES@ |