commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r4945 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Wed, 11 Apr 2007 00:17:05 -0600 (MDT)

Author: gnychis
Date: 2007-04-11 00:17:05 -0600 (Wed, 11 Apr 2007)
New Revision: 4945

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 port checking and assigning capacity on both tx and rx

this code is extremely unstable and may not compile, checking in to move 
development to another machine


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-10 22:58:11 UTC (rev 4944)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-04-11 06:17:05 UTC (rev 4945)
@@ -56,32 +56,29 @@
   // control & status port
   d_cs = define_port("cs", "usrp-server-cs", true, mb_port::EXTERNAL); 
 
-  // rx ports
+  // ports
   //
   // (if/when we do replicated ports, these will be replaced by a
   //  single replicated port)
-  d_rx0 = define_port("rx0", "usrp-rx", true, mb_port::EXTERNAL);
-  d_rx1 = define_port("rx1", "usrp-rx", true, mb_port::EXTERNAL);
-  d_rx2 = define_port("rx2", "usrp-rx", true, mb_port::EXTERNAL);
-  d_rx3 = define_port("rx3", "usrp-rx", true, mb_port::EXTERNAL);
-  
-  // tx ports
-  //
-  // (if/when we do replicated ports, these will be replaced by a
-  //  single replicated port)
-  d_tx0 = define_port("tx0", "usrp-tx", true, mb_port::EXTERNAL);
-  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);
+  for(int port=0; port < D_MAX_PORTS; port++) {
+    d_tx.push_back(define_port("rx"+port, "usrp-tx", true, mb_port::EXTERNAL));
+    d_rx.push_back(define_port("tx"+port, "usrp-rx", 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
+  // FIXME ... initializing to 2 channels on each for now, eventually we should
+  // query the FPGA to get these values
+  d_in_tx_chan = 2;
+  d_in_rx_chan = 2;
+
+  // Initialize capacity on each channel to 0 and to no owner
+  for(int chan=0; chan < d_in_tx_chan; chan++) {
+    chaninfo_tx[chan].d_assigned_capacity = 0;
+    chaninfo_tx[chan].d_owner = PMT_NIL;
   }
-  
+  for(int chan=0; chan < d_in_rx_chan; chan++) {
+    chaninfo_rx[chan].d_assigned_capacity = 0;
+    chaninfo_rx[chan].d_owner = PMT_NIL;
+  }
 }
 
 usrp_server::~usrp_server()
@@ -139,91 +136,123 @@
   }
 
   if (pmt_eq(event, s_cmd_allocate_channel)){
+    reply_data = handle_cmd_allocate_channel(port_id, data);
+    d_cs->send(s_response_allocate_channel, reply_data);
+    return;
+  }
+//
+//  if (pmt_eq(event, s_cmd_deallocate_channel)) {
+//    reply_data = handle_cmd_deallocate_channel(port_id, data);
+//    d_cs->send(s_response_allocate_channel, reply_data);
+//    return;
+//  }
+//    
+//  if (pmt_eq(event, s_cmd_xmit_raw_frame)){
+//    reply_data = handle_cmd_xmit_raw_frame(data);
+//    d_cs->send(s_response_allocate_channel, reply_data);
+//    return;
+//  }
 
-    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;
+ unhandled:
+  std::cout << "unhandled msg: " << msg << std::endl;
+}
 
-    // 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;
+int usrp_server::get_port_type(pmt_t port_id) {
 
-      // 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);
-    }
+  // Go through all of the ports and determine if it is
+  // TX or RX
+  for(int port=0; port < D_MAX_PORTS; port++) {
 
-    d_cs->send(s_response_allocate_channel, reply_data);  // send response back
-    return;
-  } // end of s_cmd_allocate_channel
+    if(pmt_eq(pmt_intern(d_tx.at(port)->port_name()), port_id))
+      return D_PORT_TYPE_TX;
 
-  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;
-    }
+    if(pmt_eq(pmt_intern(d_rx.at(port)->port_name()), port_id))
+      return D_PORT_TYPE_RX;
+  }
 
-    // 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);
-    }
+  return -1;  // couldn't find the port, -1 for error
+}
 
-    d_cs->send(s_response_deallocate_channel, reply_data);  // respond
-    return;
-  }
-  
-  if (pmt_eq(event, s_cmd_xmit_raw_frame)){
-    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 usrp_server::current_capacity_allocation() {
+  long capacity = 0;
 
-    // Read the samples, which are in a uniform numeric vector and find the 
number of samples
-    size_t num_samples;
-    uint32_t *samples = (uint32_t *) pmt_uniform_vector_elements(pmt_nth(2, 
data), num_samples);
-    long payload_len = num_samples * sizeof(uint32_t);
+  for(int chan=0; chan < d_in_tx_chan; chan++) 
+    capacity += chaninfo_tx[chan].d_assigned_capacity;
 
-    long timestamp = pmt_to_long(pmt_nth(3, data));       // the timestamp to 
send the samples to the D/A converter
-   
-    usrp_inband_usb_packet usb_packet;                    // lets make a 
packet!
+  for(int chan=0; chan < d_in_rx_chan; chan++)
+    capacity += chaninfo_rx[chan].d_assigned_capacity;
+}
     
-    // Set the header of the packet... what should 'tag' be set to here?
-    usb_packet.set_header(0, channel_number, 0, payload_len);
-    usb_packet.set_timestamp(timestamp);
-    memcpy(usb_packet.payload(), samples, payload_len);
+//pmt_t usrp_server::handle_cmd_allocate_channel(pmt_t port_id, pmt_t data) {
+//
+//  pmt_t invocation_handle = pmt_nth(0, data);
+//  long assigned_capacity = pmt_to_long(pmt_nth(1, data));
+//  long channel_number;
+//
+//  // Does the capacity exist?
+//  if(capacity_current >= assigned_capacity) {
+//    
+//    // Find a free channel
+//    for(channel_number=0; channel_number < d_in_tx_chan; channel_number++) 
+//      if(capacity_tx[channel_number].owner == PMT_NIL) 
+//        break;
+//
+//    // If we found a free channel, set the owner of the channel and the 
assigned capacity
+//    if(channel_number < d_in_tx_chan) {
+//      capacity_tx[channel_number].owner = port_id;
+//      capacity_tx[channel_number].reserved_capacity = 
pmt_from_long(assigned_capacity);  // set port capacity
+//      capacity = pmt_from_long(capacity_current + assigned_capacity);        
            // increase overall capacity
+//      return pmt_list3(invocation_handle, PMT_T, 
pmt_from_long(channel_number));
+//    }
+//    // no free channels found
+//    return pmt_list3(invocation_handle, PMT_F, PMT_NIL); 
+//  }
+//  // the capacity is not available
+//  return pmt_list3(invocation_handle, PMT_F, PMT_NIL);
+//}
 
-    // interface with the USRP to send the USB packet
-    
-    reply_data = pmt_list2(invocation_handle, PMT_T);
-    d_cs->send(s_response_xmit_raw_frame, reply_data);  // respond
-    return;
-  }
+//pmt_t usrp_server::handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data) {
+//  pmt_t invocation_handle = pmt_nth(0, data); 
+//  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 >= d_in_tx_chan) 
+//    return pmt_list2(invocation_handle, PMT_F);
+//
+//  // 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;
+//    return pmt_list2(invocation_handle, PMT_T);
+//  }
+//
+//  // not the owner
+//  return pmt_list2(invocation_handle, PMT_F);
+//}
+//  
+//pmt_t usrp_server::handle_cmd_xmit_raw_frame(pmt_t data) {
+//  pmt_t invocation_handle = pmt_nth(0, data);
+//  long channel_number = pmt_to_long(pmt_nth(1, data));  // the channel to 
deallocate
+//
+//  // Read the samples, which are in a uniform numeric vector and find the 
number of samples
+//  size_t num_samples;
+//  uint32_t *samples = (uint32_t *) pmt_uniform_vector_elements(pmt_nth(2, 
data), num_samples);
+//  long payload_len = num_samples * sizeof(uint32_t);
+//
+//  long timestamp = pmt_to_long(pmt_nth(3, data));       // the timestamp to 
send the samples to the D/A converter
+// 
+//  usrp_inband_usb_packet usb_packet;                    // lets make a 
packet!
+//  
+//  // Set the header of the packet... what should 'tag' be set to here?
+//  usb_packet.set_header(0, channel_number, 0, payload_len);
+//  usb_packet.set_timestamp(timestamp);
+//  memcpy(usb_packet.payload(), samples, payload_len);
+//
+//  // interface with the USRP to send the USB packet
+//  
+//  return pmt_list2(invocation_handle, PMT_T);
+//}
 
- unhandled:
-  std::cout << "unhandled msg: " << msg << std::endl;
-}

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-10 22:58:11 UTC (rev 4944)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-04-11 06:17:05 UTC (rev 4945)
@@ -22,35 +22,33 @@
 #define INCLUDED_USRP_SERVER_H
 
 #include <mb_mblock.h>
+#include <vector>
 
-#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
  */
 class usrp_server : public mb_mblock
 {
   // our ports
+  static const int D_PORT_TYPE_RX = 0;
+  static const int D_PORT_TYPE_TX = 1;
+  static const int D_MAX_PORTS = 4;
+  std::vector<mb_port_sptr> d_tx, d_rx;
   mb_port_sptr d_cs;
-  mb_port_sptr d_rx0;
-  mb_port_sptr d_rx1;
-  mb_port_sptr d_rx2;
-  mb_port_sptr d_rx3;
-  mb_port_sptr d_tx0;
-  mb_port_sptr d_tx1;
-  mb_port_sptr d_tx2;
-  mb_port_sptr d_tx3;
+  
 
+  static const int D_USB_CAPACITY = 32 * 1024 * 1024;
+  static const int D_MAX_CHANNELS = 16;
+  long d_in_tx_chan;
+  long d_in_rx_chan;
+
   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
+    long d_assigned_capacity;  // the capacity currently assignedby the channel
+    pmt_t d_owner;              // port ID of the owner of the channel
   };
 
-  // capacity of usb
-  pmt_t capacity;
-  struct channel_info capacity_tx[USB_MAX_TX_CHANNELS];
+  struct channel_info chaninfo_tx[D_MAX_CHANNELS];
+  struct channel_info chaninfo_rx[D_MAX_CHANNELS];
 
 public:
   usrp_server();
@@ -58,6 +56,13 @@
 
   void init_fsm();
   void handle_message(mb_message_sptr msg);
+
+private:
+  pmt_t handle_cmd_allocate_channel(pmt_t port_id, pmt_t data);
+  pmt_t handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data);
+  pmt_t handle_cmd_xmit_raw_frame(pmt_t data);
+  int get_port_type(pmt_t port_id);
+  long current_capacity_allocation();
 };
 
 #endif /* INCLUDED_USRP_SERVER_H */





reply via email to

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