commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4992 - gnuradio/branches/features/inband-usb/mblock/s


From: eb
Subject: [Commit-gnuradio] r4992 - gnuradio/branches/features/inband-usb/mblock/src/lib
Date: Fri, 13 Apr 2007 13:28:08 -0600 (MDT)

Author: eb
Date: 2007-04-13 13:28:08 -0600 (Fri, 13 Apr 2007)
New Revision: 4992

Added:
   gnuradio/branches/features/inband-usb/mblock/src/lib/qa_disconnect.cc
Modified:
   gnuradio/branches/features/inband-usb/mblock/src/lib/Makefile.am
   gnuradio/branches/features/inband-usb/mblock/src/lib/mb_mblock_impl.cc
   gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
   gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
   gnuradio/branches/features/inband-usb/mblock/src/lib/mb_port.h
   gnuradio/branches/features/inband-usb/mblock/src/lib/mb_worker.cc
   gnuradio/branches/features/inband-usb/mblock/src/lib/qa_bitset.mbh
   gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.cc
   gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.h
Log:
Merged eb/ibu -r4982:4990 into features/inband-usb.  mblocks are now
basically working!  connect, disconnect and mblock composition work.
Still need to add timer messages and address malloc related
performance issues.



Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/Makefile.am    
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/Makefile.am    
2007-04-13 19:28:08 UTC (rev 4992)
@@ -105,6 +105,7 @@
 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               \

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_mblock_impl.cc
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_mblock_impl.cc      
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_mblock_impl.cc      
2007-04-13 19:28:08 UTC (rev 4992)
@@ -319,19 +319,9 @@
     }
   };
 
-  class nop : public mb_visitor
-  {
-  public:
-    bool operator()(mb_mblock *mblock)
-    {
-      return true;
-    }
-  };
-
   invalidator visitor;
-  nop visitor2;
 
   // Always true, except in early QA code
   if (runtime()->top())
-    runtime()->top()->walk_tree(&visitor2);
+    runtime()->top()->walk_tree(&visitor);
 }

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc  
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.cc  
2007-04-13 19:28:08 UTC (rev 4992)
@@ -40,3 +40,16 @@
 {
   // 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;
+}

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h   
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_message.h   
2007-04-13 19:28:08 UTC (rev 4992)
@@ -22,6 +22,7 @@
 #define INCLUDED_MB_MESSAGE_H
 
 #include <mb_common.h>
+#include <iosfwd>
 
 class mb_message;
 typedef boost::shared_ptr<mb_message> mb_message_sptr;
@@ -68,4 +69,13 @@
   void set_port_id(pmt_t port_id){ d_port_id = port_id; }
 };
 
+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 */

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_port.h
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_port.h      
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_port.h      
2007-04-13 19:28:08 UTC (rev 4992)
@@ -79,8 +79,8 @@
    */
   virtual void
   send(pmt_t signal,
-       pmt_t data = PMT_NIL,
-       pmt_t metadata = PMT_NIL,
+       pmt_t data = PMT_F,
+       pmt_t metadata = PMT_F,
        mb_pri_t priority = MB_PRI_DEFAULT) = 0;
 
   /*

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/mb_worker.cc
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/mb_worker.cc   
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/mb_worker.cc   
2007-04-13 19:28:08 UTC (rev 4992)
@@ -56,7 +56,7 @@
 static void
 set_affinity(const std::string &instance_name, const std::string &class_name)
 {
-  static int   counter = 0;
+  //static int counter = 0;
   cpu_set_t    mask;
   CPU_ZERO(&mask);
 

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/qa_bitset.mbh
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/qa_bitset.mbh  
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/qa_bitset.mbh  
2007-04-13 19:28:08 UTC (rev 4992)
@@ -40,3 +40,22 @@
 
    )
   )
+
+;; ----------------------------------------------------------------
+;; qa-disconnect -- interface to mblock QA code
+;;
+
+(define-protocol-class qa-disconnect-cs
+
+  (:outgoing
+
+   (select-pipe n)
+
+   )
+
+  (:incoming
+
+   (ack n)
+
+   )
+  )

Copied: gnuradio/branches/features/inband-usb/mblock/src/lib/qa_disconnect.cc 
(from rev 4990, 
gnuradio/branches/developers/eb/ibu/mblock/src/lib/qa_disconnect.cc)
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/qa_disconnect.cc       
                        (rev 0)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/qa_disconnect.cc       
2007-04-13 19:28:08 UTC (rev 4992)
@@ -0,0 +1,238 @@
+/* -*- 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 <sstream>
+#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_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);

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.cc
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.cc       
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.cc       
2007-04-13 19:28:08 UTC (rev 4992)
@@ -250,3 +250,22 @@
   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));
+}

Modified: gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.h
===================================================================
--- gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.h        
2007-04-13 19:18:02 UTC (rev 4991)
+++ gnuradio/branches/features/inband-usb/mblock/src/lib/qa_mblock_sys.h        
2007-04-13 19:28:08 UTC (rev 4992)
@@ -31,12 +31,14 @@
   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 */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]