commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6390 - gnuradio/branches/developers/gnychis/inband/us


From: gnychis
Subject: [Commit-gnuradio] r6390 - gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband
Date: Mon, 10 Sep 2007 16:19:12 -0600 (MDT)

Author: gnychis
Date: 2007-09-10 16:19:12 -0600 (Mon, 10 Sep 2007)
New Revision: 6390

Modified:
   gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
   gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
Log:
Intermediate GMAC checkin with code for opening the USRP and allocating the
channels.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc   
2007-09-10 21:16:12 UTC (rev 6389)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.cc   
2007-09-10 22:19:12 UTC (rev 6390)
@@ -45,6 +45,7 @@
 #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;
 
@@ -70,6 +71,150 @@
 {
 }
 
+// The full functionality of GMAC is based on messages passed back and forth
+// between the application and a physical layer and/or usrp_server.  Each
+// message triggers additional events, states, and messages to be sent.
+void gmac::handle_message(mb_message_sptr msg)
+{
+
+  // The MAC functionality is dispatched based on the event, which is the
+  // driving force of the MAC.  The event can be anything from incoming samples
+  // to a message to change the carrier sense threshold.
+  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;
+
+  switch(d_state) {
+    
+    //---------------------------- INIT ------------------------------------//
+    // In the INIT state, there should be no messages across the ports.  It is
+    // used as a state to initialize the MAC protocol.
+    case INIT:
+      error_msg = "no messages should be passed during the INIT state:"; 
+      goto unhandled;
+
+    //-------------------------- OPENING USRP -------------------------------//
+    // In this state we expect a response from usrp_server over the CS channel
+    // as to whether or not the opening of the USRP was successful.  If so, we
+    // switch states to allocating the channels for use.
+    case OPENING_USRP:
+
+      if(pmt_eq(event, s_response_open)) {
+
+        status = pmt_nth(1, data);          // PMT_T or PMT_F
+
+        if(pmt_eq(status, PMT_T)) {         // on success, allocate channels!
+          allocate_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:
+
+      // ************* 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(pmt_eq(status, PMT_T)) {   // extract channel on success
+          d_tx_chan = pmt_nth(2, data);
+
+          if(verbose)
+            std::cout << "[GMAC] 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_idle();
+          }
+
+          return;
+        }
+        else {  // TX allocation failed
+          error_msg = "failed to allocate TX channel:";
+          goto bail;
+        }
+      }
+      
+      // ************* 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(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_idle();
+          }
+
+          return;
+        }
+        else {  // RX allocation failed
+          error_msg = "failed to allocate RX channel:";
+          goto bail;
+        }
+      }
+
+      goto unhandled;
+    
+    //----------------------------- IDLE ------------------------------------//
+    // In the idle state the MAC is not quite 'idle', it is just not doing
+    // anything specific.  It is still being passive with data between the
+    // application and the lower layer.
+    case IDLE:
+      goto unhandled;
+
+    //------------------------ CLOSING CHANNELS -----------------------------//
+    case CLOSING_CHANNELS:
+      goto unhandled;
+
+    //-------------------------- CLOSING USRP -------------------------------//
+    case CLOSING_USRP:
+      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;
+}
+
 // The MAC layer connects to 'usrp_server' which has a control/status channel,
 // a TX, and an RX port.  The MAC layer can then relay TX/RX data back and
 // forth to the application, or a physical layer once available.
@@ -107,7 +252,7 @@
   // Center frequency
   pmt_dict_set(usrp_dict,
                pmt_intern("rf-freq"),
-               pmt_from_long(10e6));
+               pmt_from_long((long)10e6));
   
   define_component("server", "usrp_server", usrp_dict);
 }
@@ -117,6 +262,9 @@
 void gmac::initialize_gmac()
 {
 
+  // The initial state is the INIT state.
+  d_state = INIT;
+
   // Set carrier sense to enabled by default with the specified threshold
   set_carrier_sense(true, 21, PMT_NIL);
 
@@ -141,3 +289,36 @@
                                       pmt_from_long(REG_CS_THRESH), 
                                       pmt_from_long(d_cs_thresh))))));
 }
+
+// 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 gmac::allocate_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)));
+
+  if(verbose)
+    std::cout << "[GMAC] Sending channel allocation requests\n";
+}
+
+// Used to enter the receiving state
+void gmac::enter_receiving()
+{
+  d_rx->send(s_cmd_start_recv_raw_samples,
+             pmt_list2(PMT_F,
+                       d_rx_chan));
+
+  if(verbose)
+    std::cout << "[GMAC] Started RX sample stream\n";
+}
+
+// A simple idle state, nothing more to it.
+void gmac::enter_idle()
+{
+  d_state = IDLE;
+}

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h    
2007-09-10 21:16:12 UTC (rev 6389)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/gmac.h    
2007-09-10 22:19:12 UTC (rev 6390)
@@ -28,11 +28,28 @@
 
 class gmac : public mb_mblock
 {
+  
+  // The state is used to determine how to handle incoming messages and of
+  // course, the state of the MAC protocol.
+  enum state_t {
+    INIT,
+    OPENING_USRP,
+    ALLOCATING_CHANNELS,
+    IDLE,
+    CLOSING_CHANNELS,
+    CLOSING_USRP,
+  };
+  state_t      d_state;
 
+  // Ports used to connect to usrp_server, and the physical layer (in the
+  // future).
   mb_port_sptr           d_cs;
   mb_port_sptr           d_tx;
   mb_port_sptr           d_rx;
 
+  // The channel numbers assigned for use
+  pmt_t d_rx_chan, d_tx_chan;
+
   bool d_carrier_sense;
   long d_cs_thresh;
 
@@ -43,12 +60,16 @@
  public:
   gmac(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg);
   ~gmac();
+  void handle_message(mb_message_sptr msg);
 
  private:
   void define_ports();
   void initialize_usrp();
   void initialize_gmac();
   void set_carrier_sense(bool toggle, long threshold, pmt_t invocation);
+  void allocate_channels();
+  void enter_receiving();
+  void enter_idle();
  
 };
 





reply via email to

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