commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4957 - in gnuradio/branches/developers/gnychis/inband


From: gnychis
Subject: [Commit-gnuradio] r4957 - in gnuradio/branches/developers/gnychis/inband/usrp/host/lib: inband legacy
Date: Wed, 11 Apr 2007 17:50:47 -0600 (MDT)

Author: gnychis
Date: 2007-04-11 17:50:47 -0600 (Wed, 11 Apr 2007)
New Revision: 4957

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
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/legacy/usrp_bytesex.h
Log:
pushing back in my changes as of last night

checked compilation and everything was as is, with the feature branch changes 
merged


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-11 22:40:38 UTC (rev 4956)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-04-11 23:50:47 UTC (rev 4957)
@@ -24,6 +24,7 @@
 #endif
 #include <usrp_server.h>
 #include <iostream>
+#include <usrp_inband_usb_packet.h>
 
 
 // FIXME We should machine generate these by a simple preprocessor run over 
this file
@@ -58,24 +59,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));
+  }
+
+  // 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()
@@ -133,14 +139,185 @@
   }
 
   if (pmt_eq(event, s_cmd_allocate_channel)){
-    // blah blah blah, do something here
+    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_allocate_channel)){
-    // ...
+
+  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;
+//  }
 
  unhandled:
   std::cout << "unhandled msg: " << msg << std::endl;
 }
+
+// Return -1 if it is not an RX port, or an index
+long usrp_server::is_tx_port(pmt_t port_id) {
+
+  for(int port=0; port < D_MAX_PORTS; port++) 
+    if(pmt_eq(pmt_intern(d_tx.at(port)->port_name()), port_id))
+      return port;
+
+  return -1;
+}
+
+// Return -1 if it is not an RX port, or an index
+long usrp_server::is_rx_port(pmt_t port_id) {
+
+  for(int port=0; port < D_MAX_PORTS; port++) 
+    if(pmt_eq(pmt_intern(d_rx.at(port)->port_name()), port_id))
+      return port;
+
+  return -1;
+}
+
+// Return one of two predicates for TX or RX ... -1 on error
+long usrp_server::get_port_type(pmt_t port_id) {
+
+  if(is_tx_port(port_id) != -1)
+    return D_PORT_TYPE_TX;
+
+  if(is_rx_port(port_id) != -1)
+    return D_PORT_TYPE_RX;
+
+  return -1;
+}
+
+// Go through all TX and RX channels, sum up the assigned capacity
+// and return it
+long usrp_server::current_capacity_allocation() {
+  long capacity = 0;
+
+  for(int chan=0; chan < d_in_tx_chan; chan++) 
+    capacity += chaninfo_tx[chan].d_assigned_capacity;
+
+  for(int chan=0; chan < d_in_rx_chan; chan++)
+    capacity += chaninfo_rx[chan].d_assigned_capacity;
+
+  return capacity;
+}
+    
+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 chan, port_type;
+
+  // Regardless of port type, need to ensure the capacity exists, then we
+  // will worry about finding a channel depending on type
+  if((D_USB_CAPACITY - current_capacity_allocation()) < assigned_capacity)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no capacity 
available
+  
+  // Get the type of port sending the command which will be used to
+  // assign the capacity in the correct channel pool
+  if((port_type = get_port_type(port_id)) == -1)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // unknown port type
+
+  if(port_type == D_PORT_TYPE_TX) {
+
+    // Find a free channel
+    for(chan=0; chan < d_in_tx_chan; chan++) 
+      if(chaninfo_tx[chan].d_owner == PMT_NIL) 
+        break;
+
+    // If we found a free channel, set the owner of the channel and assigned 
capacity
+    if(chan < d_in_tx_chan) {
+      chaninfo_tx[chan].d_owner = port_id;
+      chaninfo_tx[chan].d_assigned_capacity = assigned_capacity;
+      return pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
+    }
+
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no free TX chan 
found
+  }
+  
+  if(port_type == D_PORT_TYPE_RX) {
+
+    for(chan=0; chan < d_in_tx_chan; chan++) 
+      if(chaninfo_tx[chan].d_owner == PMT_NIL) 
+        break;
+
+    if(chan < d_in_tx_chan) {
+      chaninfo_tx[chan].d_owner = port_id;
+      chaninfo_tx[chan].d_assigned_capacity = assigned_capacity;
+      return pmt_list3(invocation_handle, PMT_T, pmt_from_long(chan));
+    }
+
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // no free RX chan 
found
+  }
+}
+
+// Check the port type and deallocate assigned capacity based on this, ensuring
+// that the owner of the method invocation is the owner of the port and that
+// the channel number is valid.
+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 = pmt_to_long(pmt_nth(1, data));
+  long port_type;
+  
+  if((port_type = get_port_type(port_id)) == -1)
+    return pmt_list3(invocation_handle, PMT_F, PMT_NIL);  // unknown port type
+
+  if(port_type == D_PORT_TYPE_TX) {
+  
+    if(channel >= d_in_tx_chan) 
+      return pmt_list2(invocation_handle, PMT_F);   // not a legit channel 
number
+
+    if(chaninfo_tx[channel].d_owner != port_id) 
+      return pmt_list2(invocation_handle, PMT_F);   // not the owner of the 
port
+
+    chaninfo_tx[channel].d_assigned_capacity = 0;
+    chaninfo_tx[channel].d_owner = PMT_NIL;
+
+    return pmt_list2(invocation_handle, PMT_T);
+  }
+
+  if(port_type == D_PORT_TYPE_RX) {
+  
+    if(channel >= d_in_rx_chan) 
+      return pmt_list2(invocation_handle, PMT_F);   // not a legit channel 
number
+
+    if(chaninfo_rx[channel].d_owner != port_id) 
+      return pmt_list2(invocation_handle, PMT_F);   // not the owner of the 
port
+
+    chaninfo_rx[channel].d_assigned_capacity = 0;
+    chaninfo_rx[channel].d_owner = PMT_NIL;
+
+    return pmt_list2(invocation_handle, PMT_T);
+  }
+
+}
+
+//  
+//pmt_t usrp_server::handle_cmd_xmit_raw_frame(pmt_t data) {
+//  pmt_t invocation_handle = pmt_nth(0, data);
+//  long channel = 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, 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);
+//}
+

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-11 22:40:38 UTC (rev 4956)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-04-11 23:50:47 UTC (rev 4957)
@@ -22,31 +22,50 @@
 #define INCLUDED_USRP_SERVER_H
 
 #include <mb_mblock.h>
+#include <vector>
 
 /*!
  * \brief Implements the lowest-level mblock interface to the USRP
  */
 class usrp_server : public mb_mblock
 {
+public:
   // 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;
+  
 
-  // add more stuff here...
+  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 {
+    long d_assigned_capacity;  // the capacity currently assignedby the channel
+    pmt_t d_owner;              // port ID of the owner of the channel
+  };
+
+  struct channel_info chaninfo_tx[D_MAX_CHANNELS];
+  struct channel_info chaninfo_rx[D_MAX_CHANNELS];
+
 public:
   usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t 
user_arg);
   ~usrp_server();
 
   void initial_transition();
   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);
+  long is_rx_port(pmt_t port_id);
+  long is_tx_port(pmt_t port_id);
+  long current_capacity_allocation();
+  long get_port_type(pmt_t port_id);
 };
 
 #endif /* INCLUDED_USRP_SERVER_H */

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/legacy/usrp_bytesex.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/legacy/usrp_bytesex.h 
    2007-04-11 22:40:38 UTC (rev 4956)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/legacy/usrp_bytesex.h 
    2007-04-11 23:50:47 UTC (rev 4957)
@@ -38,11 +38,30 @@
 {
   return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8));
 }
+
+static inline unsigned int
+bswap32 (unsigned int x)
+{
+  return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) \
+        | (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24));
+}
 #endif
 
 
 #ifdef WORDS_BIGENDIAN
 
+static inline unsigned int
+host_to_usrp_u32 (unsigned int x)
+{
+  return bswap_32(x);
+}
+
+static inline unsigned int
+usrp_to_host_u32 (unsigned int x)
+{
+  return bswap_32(x);
+}
+
 static inline short int
 host_to_usrp_short (short int x)
 {
@@ -57,6 +76,18 @@
 
 #else
 
+static inline unsigned int
+host_to_usrp_u32 (unsigned int x)
+{
+  return x;
+}
+
+static inline unsigned int
+usrp_to_host_u32 (unsigned int x)
+{
+  return x;
+}
+
 static inline short int
 host_to_usrp_short (short int x)
 {





reply via email to

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