commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8469 - usrp2/branches/developers/jcorgan/u2/host/lib


From: jcorgan
Subject: [Commit-gnuradio] r8469 - usrp2/branches/developers/jcorgan/u2/host/lib
Date: Tue, 20 May 2008 19:36:30 -0600 (MDT)

Author: jcorgan
Date: 2008-05-20 19:36:28 -0600 (Tue, 20 May 2008)
New Revision: 8469

Added:
   usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h
   usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
   usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
Removed:
   usrp2/branches/developers/jcorgan/u2/host/lib/ringbuffer.cc
   usrp2/branches/developers/jcorgan/u2/host/lib/ringbuffer.h
Modified:
   usrp2/branches/developers/jcorgan/u2/host/lib/Makefile.am
   usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
   usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
Log:
wip

Modified: usrp2/branches/developers/jcorgan/u2/host/lib/Makefile.am
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/Makefile.am   2008-05-20 
23:17:31 UTC (rev 8468)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/Makefile.am   2008-05-21 
01:36:28 UTC (rev 8469)
@@ -31,7 +31,7 @@
        gri_ethernet_pfring.cc \
        gri_if_stats.cc \
        gri_pktfilter.cc \
-       ringbuffer.cc \
+       sample_buffer.cc \
        strtod_si.c \
        usrp2_basic.cc \
        usrp2_basic_thread.cc
@@ -48,9 +48,11 @@
        gri_ethernet_pfring.h \
        gri_if_stats.h \
        gri_pktfilter.h \
-       ringbuffer.h \
+       ring_buffer.h \
+       sample_buffer.h \
        strtod_si.h \
        usrp2_tune_result.h \
        usrp2_basic.h \
        usrp2_basic_thread.h
 
+MOSTLYCLEANFILES = *~ *.loT

Copied: usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h (from rev 
8458, usrp2/branches/developers/jcorgan/u2/host/lib/ringbuffer.h)
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h                 
        (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/ring_buffer.h 2008-05-21 
01:36:28 UTC (rev 8469)
@@ -0,0 +1,88 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 3, 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 GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_RING_BUFFER_H
+#define INCLUDED_RING_BUFFER_H
+
+#include <vector>
+#include <cmath>
+
+template <class T> 
+class ring_buffer
+{
+public:
+  ring_buffer(size_t nitems);
+
+  size_t space_available() const;
+  size_t items_available() const;
+  
+  void write(size_t nitems, const T *items);
+  void read(size_t nitems, T *items);
+  
+private:
+  size_t d_size;
+  size_t d_read_index;
+  size_t d_write_index;
+
+  std::vector<T> d_items;
+};
+
+template<class T>
+ring_buffer<T>::ring_buffer(size_t nitems) 
+  : d_size((int)pow(2, ceil(log2((double)nitems + 1)))),
+    d_read_index(0),
+    d_write_index(0),
+    d_items(d_size)
+{
+}
+
+template<class T>
+size_t ring_buffer<T>::items_available() const
+{
+  return (d_size+d_write_index-d_read_index) & (d_size-1);
+}
+
+template<class T>
+size_t ring_buffer<T>::space_available() const
+{
+  return d_size-items_available()-1;
+}
+
+template<class T>
+void ring_buffer<T>::read(size_t nitems, T *items)
+{
+  for (size_t i=0; i < nitems; i++) {
+    items[i] = d_items[d_read_index++];
+    d_read_index &= (d_size-1);
+  }
+}
+
+template<class T>
+void ring_buffer<T>::write(size_t nitems, const T *items)
+{
+  for (size_t i=0; i < nitems; i++) {
+    d_items[d_write_index++] = items[i];
+    d_write_index &= (d_size-1);
+  }
+}
+
+#endif /* INCLUDED_RING_BUFFER_H */

Deleted: usrp2/branches/developers/jcorgan/u2/host/lib/ringbuffer.cc

Deleted: usrp2/branches/developers/jcorgan/u2/host/lib/ringbuffer.h

Added: usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc              
                (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.cc      
2008-05-21 01:36:28 UTC (rev 8469)
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "sample_buffer.h"
+#include <cstdio>
+
+#define SAMPLE_BUFFER_DEBUG 1
+
+sample_buffer::sample_buffer(size_t nsamples, size_t ndescs)
+  : d_samples(nsamples), d_descs(ndescs),
+    d_not_empty(&d_mutex), d_not_full(&d_mutex)
+{
+}
+
+void
+write(size_t nsamples, const uint32_t *samples, uint32_t flags)
+{
+  if (SAMPLE_BUFFER_DEBUG)
+    printf("sample_buffer::write(%li, %0X, %08X)", nsamples, samples, flags);
+}
+
+size_t
+read(uint32_t *samples, size_t nmax, uint32_t *flags)
+{
+  if (SAMPLE_BUFFER_DEBUG)
+    printf("sample_buffer::read(%0X, %li, %08X)", samples, nmax, flags);
+}

Added: usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h               
                (rev 0)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/sample_buffer.h       
2008-05-21 01:36:28 UTC (rev 8469)
@@ -0,0 +1,80 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_SAMPLE_BUFFER_H
+#define INCLUDED_SAMPLE_BUFFER_H
+
+#include "ring_buffer.h"
+#include <omnithread.h>
+
+typedef struct sample_desc
+{
+  size_t nsamples;
+  uint32_t flags;
+}
+sample_desc_t;
+
+typedef class sample_buffer
+{
+private:
+  ring_buffer<uint32_t> d_samples;
+  ring_buffer<sample_desc_t> d_descs;
+
+  omni_mutex d_mutex;
+  omni_condition d_not_empty;
+  omni_condition d_not_full;
+
+public:
+  /*!
+   * Create a sample buffer that can hold at least nsamples of data and
+   * ndescs of descriptors.
+   */ 
+  sample_buffer(size_t nsamples, size_t ndescs);
+
+  /*!
+   * Write nsamples of data into buffer and associate flags with this range.
+   * If space is not available, calling thread will block until it is.
+   */  
+  void write(size_t nsamples, const uint32_t *samples, uint32_t flags);
+
+  /*!
+   * Read no more than nsamples of data from buffer.  If samples are available,
+   * read as many as possible until either a) nsamples is reached, or b) the
+   * associated flags for the range has U2P_TX_END_OF_BURST set.  If no 
samples at
+   * all are available, the calling thread will block until they are.
+   *
+   * Returns number of samples read and places the OR of the associated flags
+   * into the 'flags' parameter, if not NULL.
+   */
+  size_t read(uint32_t *samples, size_t nmax, uint32_t *flags);
+
+  /*!
+   * Returns true if there are no samples available for reading.
+   */
+  bool is_empty_p() { return d_descs.items_available() == 0; }
+  
+  /*!
+   * Returns true if there is either no space available for samples OR there
+   * is no space available for enqueuing descriptors.
+   */
+  bool is_full_p() { return d_descs.space_available() == 0 |
+                            d_samples.space_available() == 0; }
+}
+sample_buffer_t;
+
+#endif /* INCLUDED_SAMPLE_BUFFER_H */

Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc        
2008-05-20 23:17:31 UTC (rev 8468)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.cc        
2008-05-21 01:36:28 UTC (rev 8469)
@@ -67,7 +67,7 @@
 
 usrp2_basic::usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
   : d_ethernet(new GRI_ETHERNET()), d_pf(0), d_seqno(0), d_next_rid(0),
-    d_thread(0)
+    d_thread(0), d_rx_samples(65535, 255), d_tx_samples(65535, 255)
 {
   if (USRP2_BASIC_DEBUG)
     std::cout << "usrp2_basic: constructor" << std::endl;

Modified: usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-20 
23:17:31 UTC (rev 8468)
+++ usrp2/branches/developers/jcorgan/u2/host/lib/usrp2_basic.h 2008-05-21 
01:36:28 UTC (rev 8469)
@@ -24,6 +24,7 @@
 #include <vector>
 #include "usrp2_eth_packet.h"
 #include "usrp2_tune_result.h"
+#include "sample_buffer.h"
 
 class gri_ethernet;
 class gri_ethernet_pfring;
@@ -52,6 +53,8 @@
   u2_mac_addr_t  d_addr;
   int            d_rx_decim;
   usrp2_basic_thread *d_thread;
+  sample_buffer_t d_rx_samples;
+  sample_buffer_t d_tx_samples;
   
   void init_et_hdrs(u2_eth_packet_t *p, const u2_mac_addr_t &dst);
 





reply via email to

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