commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r4939 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Mon, 9 Apr 2007 18:48:09 -0600 (MDT)

Author: gnychis
Date: 2007-04-09 18:48:09 -0600 (Mon, 09 Apr 2007)
New Revision: 4939

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
Log:
Adding functionality for channel allocation and deallocation to the usrp server


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-04-09 20:49:18 UTC (rev 4938)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-04-10 00:48:09 UTC (rev 4939)
@@ -48,7 +48,6 @@
 static pmt_t s_response_recv_raw_samples = 
pmt_intern("response-recv-raw-samples");
 static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
 
-
 usrp_server::usrp_server()
 {
   // define our ports
@@ -73,6 +72,14 @@
   d_tx1 = define_port("tx1", "usrp-tx", true, mb_port::EXTERNAL);
   d_tx2 = define_port("tx2", "usrp-tx", true, mb_port::EXTERNAL);
   d_tx3 = define_port("tx3", "usrp-tx", true, mb_port::EXTERNAL);
+
+  // keep track of the current capacity
+  capacity = pmt_from_long(USB_MAX_CAPACITY);
+  // Initialize all channel capacities to 0
+  for(int channel_current=0; channel_current < USB_MAX_TX_CHANNELS; 
channel_current++) {
+    capacity_tx[channel_current].reserved_capacity = PMT_NIL;
+    capacity_tx[channel_current].owner = PMT_NIL;   // no original owner
+  }
   
 }
 
@@ -131,11 +138,63 @@
   }
 
   if (pmt_eq(event, s_cmd_allocate_channel)){
-    // blah blah blah, do something here
+
+    invocation_handle = pmt_nth(0, data);                         // get the 
invocation handle to pass back to client
+    long capacity_reservation = pmt_to_long(pmt_nth(1, data));    // the 
requested capacity
+    long capacity_current = pmt_to_long(capacity);                // our 
current capacity as 'long'
+    long channel_number;
+
+    // Does the capacity exist
+    if(capacity_current >= capacity_reservation) {
+      
+      // Find a free channel
+      for(channel_number=0; channel_number < USB_MAX_TX_CHANNELS; 
channel_number++) 
+        if(capacity_tx[channel_number].owner == PMT_NIL) 
+          break;
+
+      // If we found a free channel, channel_number will not be 
USB_MAX_TX_CHANNELS
+      if(channel_number < USB_MAX_TX_CHANNELS) {
+        capacity_tx[channel_number].owner = port_id;    // set the owner
+        capacity_tx[channel_number].reserved_capacity = 
pmt_from_long(capacity_reservation);  // set port capacity
+        capacity = pmt_from_long(capacity_current + capacity_reservation);     
               // increase overall capacity
+      }
+      else {  // no free channels found
+        reply_data = pmt_list3(invocation_handle, PMT_F, PMT_NIL); 
+      } 
+      
+    } else {  // the capacity is not available
+      reply_data = pmt_list3(invocation_handle, PMT_F, PMT_NIL);
+    }
+
+    d_cs->send(s_response_allocate_channel, reply_data);  // send response back
     return;
-  }
-  if (pmt_eq(event, s_cmd_allocate_channel)){
-    // ...
+  } // end of s_cmd_allocate_channel
+
+  if (pmt_eq(event, s_cmd_deallocate_channel)) {
+    
+    invocation_handle = pmt_nth(0, data);                   // get the 
invocation handle to pass back to client
+    long channel_number = pmt_to_long(pmt_nth(1, data));    // the channel to 
deallocate
+    long capacity_current = pmt_to_long(capacity);          // our current 
capacity as 'long'
+    
+    // Check that this is a legit channel number, else bail immediately
+    if(channel_number >= USB_MAX_TX_CHANNELS) {
+      reply_data = pmt_list2(invocation_handle, PMT_F);
+      d_cs->send(s_response_deallocate_channel, reply_data);
+      return;
+    }
+
+    // Check that the port is the owner of the channel
+    if(capacity_tx[channel_number].owner == port_id) {
+      // give back the capacity
+      capacity = pmt_from_long(capacity_current + 
pmt_to_long(capacity_tx[channel_number].reserved_capacity));
+      capacity_tx[channel_number].reserved_capacity = PMT_NIL;
+      capacity_tx[channel_number].owner = PMT_NIL;
+      reply_data = pmt_list2(invocation_handle, PMT_T);
+    } else { // not the owner
+      reply_data = pmt_list2(invocation_handle, PMT_F);
+    }
+
+    d_cs->send(s_response_deallocate_channel, reply_data);  // respond
     return;
   }
 

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-04-09 20:49:18 UTC (rev 4938)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-04-10 00:48:09 UTC (rev 4939)
@@ -23,6 +23,10 @@
 
 #include <mb_mblock.h>
 
+#define USB_MAX_CAPACITY 33554432   // about 32MB/s
+#define USB_MAX_TX_CHANNELS 2
+#define USB_MAX_RX_CHANNELS 2
+
 /*!
  * \brief Implements the lowest-level mblock interface to the USRP
  */
@@ -39,8 +43,15 @@
   mb_port_sptr d_tx2;
   mb_port_sptr d_tx3;
 
-  // add more stuff here...
+  struct channel_info {
+    pmt_t reserved_capacity;  // the capacity currently reserved by the channel
+    pmt_t owner;              // port ID of the owner of the channel
+  };
 
+  // capacity of usb
+  pmt_t capacity;
+  struct channel_info capacity_tx[USB_MAX_TX_CHANNELS];
+
 public:
   usrp_server();
   ~usrp_server();





reply via email to

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