[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4963 - gnuradio/branches/developers/eb/ibu/mblock/src
From: |
eb |
Subject: |
[Commit-gnuradio] r4963 - gnuradio/branches/developers/eb/ibu/mblock/src/lib |
Date: |
Wed, 11 Apr 2007 19:49:24 -0600 (MDT) |
Author: eb
Date: 2007-04-11 19:49:24 -0600 (Wed, 11 Apr 2007)
New Revision: 4963
Added:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.mbh
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/
gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
Log:
work-in-progress on mblock QA
Property changes on: gnuradio/branches/developers/eb/ibu/mblock/src/lib
___________________________________________________________________
Name: svn:ignore
- Makefile
Makefile.in
.la
.lo
.deps
.libs
*.la
*.lo
test_mblock
+ Makefile
Makefile.in
.la
.lo
.deps
.libs
*.la
*.lo
test_mblock
qa_bitset_mbh.cc
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-12 01:34:22 UTC (rev 4962)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-12 01:49:24 UTC (rev 4963)
@@ -31,6 +31,12 @@
README.locking
+BUILT_SOURCES = \
+ qa_bitset_mbh.cc
+
+qa_bitset_mbh.cc : qa_bitset.mbh
+ $(COMPILE_MBH) 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 \
@@ -95,6 +101,8 @@
# Build the qa code into its own library
libmblock_qa_la_SOURCES = \
+ qa_bitset.cc \
+ qa_bitset_mbh.cc \
qa_mblock.cc \
qa_mblock_prims.cc \
qa_mblock_send.cc \
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.cc
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.cc
2007-04-12 01:49:24 UTC (rev 4963)
@@ -0,0 +1,385 @@
+/* -*- 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 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <mb_mblock.h>
+#include <mb_protocol_class.h>
+#include <mb_message.h>
+#include <mb_class_registry.h>
+#include <iostream>
+#include <bitset>
+
+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);
+
+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);
+
+// ------------------------------------------------------------------------
+
+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);
+
+// ------------------------------------------------------------------------
+
+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);
+
+// ------------------------------------------------------------------------
+
+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);
+
+// ------------------------------------------------------------------------
+
+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);
+
+// ------------------------------------------------------------------------
+
+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_cs0;
+ mb_port_sptr d_cs1;
+
+ 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_cs0 = define_port("cs0", "qa-bitset-cs", true, mb_port::EXTERNAL);
+ d_cs1 = define_port("cs1", "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_cs0->port_symbol())
+ || pmt_eq(msg->port_id(), d_cs1->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()));
+
+ 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);
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.mbh
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.mbh
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_bitset.mbh
2007-04-12 01:49:24 UTC (rev 4963)
@@ -0,0 +1,42 @@
+;; -*- 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.
+;;
+
+;; ----------------------------------------------------------------
+;; 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)
+
+ )
+ )
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4963 - gnuradio/branches/developers/eb/ibu/mblock/src/lib,
eb <=