summaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/CMakeLists.txt1
-rw-r--r--host/include/uhd/device.hpp40
-rw-r--r--host/include/uhd/device.ipp55
-rw-r--r--host/include/uhd/transport/bounded_buffer.hpp50
-rw-r--r--host/include/uhd/transport/bounded_buffer.ipp40
-rw-r--r--host/include/uhd/transport/zero_copy.hpp63
-rw-r--r--host/include/uhd/types/CMakeLists.txt1
-rw-r--r--host/include/uhd/types/io_type.hpp2
-rw-r--r--host/include/uhd/types/ref_vector.hpp69
-rw-r--r--host/include/uhd/types/time_spec.hpp7
10 files changed, 166 insertions, 162 deletions
diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt
index fee1270e9..b7a22cf0b 100644
--- a/host/include/uhd/CMakeLists.txt
+++ b/host/include/uhd/CMakeLists.txt
@@ -25,7 +25,6 @@ INSTALL(FILES
config.hpp
convert.hpp
device.hpp
- device.ipp
version.hpp
wax.hpp
DESTINATION ${INCLUDE_DIR}/uhd
diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp
index 992276928..50237472b 100644
--- a/host/include/uhd/device.hpp
+++ b/host/include/uhd/device.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// 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
@@ -22,11 +22,11 @@
#include <uhd/types/device_addr.hpp>
#include <uhd/types/metadata.hpp>
#include <uhd/types/io_type.hpp>
+#include <uhd/types/ref_vector.hpp>
#include <uhd/wax.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
-#include <vector>
namespace uhd{
@@ -96,6 +96,12 @@ public:
RECV_MODE_ONE_PACKET = 1
};
+ //! Typedef for a pointer to a single, or a collection of send buffers
+ typedef ref_vector<const void *> send_buffs_type;
+
+ //! Typedef for a pointer to a single, or a collection of recv buffers
+ typedef ref_vector<void *> recv_buffs_type;
+
/*!
* Send buffers containing IF data described by the metadata.
*
@@ -121,7 +127,7 @@ public:
* \return the number of samples sent
*/
virtual size_t send(
- const std::vector<const void *> &buffs,
+ const send_buffs_type &buffs,
size_t nsamps_per_buff,
const tx_metadata_t &metadata,
const io_type_t &io_type,
@@ -130,18 +136,6 @@ public:
) = 0;
/*!
- * Convenience wrapper for send that takes a single buffer.
- */
- size_t send(
- const void *buff,
- size_t nsamps_per_buff,
- const tx_metadata_t &metadata,
- const io_type_t &io_type,
- send_mode_t send_mode,
- double timeout = 0.1
- );
-
- /*!
* Receive buffers containing IF data described by the metadata.
*
* Receive handles fragmentation as follows:
@@ -173,7 +167,7 @@ public:
* \return the number of samples received or 0 on error
*/
virtual size_t recv(
- const std::vector<void *> &buffs,
+ const recv_buffs_type &buffs,
size_t nsamps_per_buff,
rx_metadata_t &metadata,
const io_type_t &io_type,
@@ -182,18 +176,6 @@ public:
) = 0;
/*!
- * Convenience wrapper for recv that takes a single buffer.
- */
- size_t recv(
- void *buff,
- size_t nsamps_per_buff,
- rx_metadata_t &metadata,
- const io_type_t &io_type,
- recv_mode_t recv_mode,
- double timeout = 0.1
- );
-
- /*!
* Get the maximum number of samples per packet on send.
* \return the number of samples
*/
@@ -219,6 +201,4 @@ public:
} //namespace uhd
-#include <uhd/device.ipp>
-
#endif /* INCLUDED_UHD_DEVICE_HPP */
diff --git a/host/include/uhd/device.ipp b/host/include/uhd/device.ipp
deleted file mode 100644
index e2e51ecd0..000000000
--- a/host/include/uhd/device.ipp
+++ /dev/null
@@ -1,55 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// 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_UHD_DEVICE_IPP
-#define INCLUDED_UHD_DEVICE_IPP
-
-namespace uhd{
-
- UHD_INLINE size_t device::send(
- const void *buff,
- size_t nsamps_per_buff,
- const tx_metadata_t &metadata,
- const io_type_t &io_type,
- send_mode_t send_mode,
- double timeout
- ){
- return this->send(
- std::vector<const void *>(1, buff),
- nsamps_per_buff, metadata,
- io_type, send_mode, timeout
- );
- }
-
- UHD_INLINE size_t device::recv(
- void *buff,
- size_t nsamps_per_buff,
- rx_metadata_t &metadata,
- const io_type_t &io_type,
- recv_mode_t recv_mode,
- double timeout
- ){
- return this->recv(
- std::vector<void *>(1, buff),
- nsamps_per_buff, metadata,
- io_type, recv_mode, timeout
- );
- }
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_DEVICE_IPP */
diff --git a/host/include/uhd/transport/bounded_buffer.hpp b/host/include/uhd/transport/bounded_buffer.hpp
index aca93b071..412d73f17 100644
--- a/host/include/uhd/transport/bounded_buffer.hpp
+++ b/host/include/uhd/transport/bounded_buffer.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// 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
@@ -18,8 +18,7 @@
#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP
#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP
-#include <uhd/config.hpp>
-#include <boost/shared_ptr.hpp>
+#include <uhd/transport/bounded_buffer.ipp> //detail
namespace uhd{ namespace transport{
@@ -32,13 +31,16 @@ namespace uhd{ namespace transport{
*/
template <typename elem_type> class bounded_buffer{
public:
- typedef boost::shared_ptr<bounded_buffer<elem_type> > sptr;
/*!
- * Make a new bounded buffer object.
+ * Create a new bounded buffer object.
* \param capacity the bounded_buffer capacity
*/
- static sptr make(size_t capacity);
+ bounded_buffer(size_t capacity):
+ _detail(capacity)
+ {
+ /* NOP */
+ }
/*!
* Push a new element into the bounded buffer.
@@ -47,14 +49,18 @@ namespace uhd{ namespace transport{
* \param elem the new element to push
* \return true if the element fit without popping for space
*/
- virtual bool push_with_pop_on_full(const elem_type &elem) = 0;
+ bool push_with_pop_on_full(const elem_type &elem){
+ return _detail.push_with_pop_on_full(elem);
+ }
/*!
* Push a new element into the bounded_buffer.
* Wait until the bounded_buffer becomes non-full.
* \param elem the new element to push
*/
- virtual void push_with_wait(const elem_type &elem) = 0;
+ void push_with_wait(const elem_type &elem){
+ return _detail.push_with_wait(elem);
+ }
/*!
* Push a new element into the bounded_buffer.
@@ -63,14 +69,27 @@ namespace uhd{ namespace transport{
* \param timeout the timeout in seconds
* \return false when the operation times out
*/
- virtual bool push_with_timed_wait(const elem_type &elem, double timeout) = 0;
+ bool push_with_timed_wait(const elem_type &elem, double timeout){
+ return _detail.push_with_timed_wait(elem, timeout);
+ }
+
+ /*!
+ * Pop an element from the bounded_buffer immediately.
+ * \param elem the element reference pop to
+ * \return false when the bounded_buffer is empty
+ */
+ bool pop_with_haste(elem_type &elem){
+ return _detail.pop_with_haste(elem);
+ }
/*!
* Pop an element from the bounded_buffer.
* Wait until the bounded_buffer becomes non-empty.
* \param elem the element reference pop to
*/
- virtual void pop_with_wait(elem_type &elem) = 0;
+ void pop_with_wait(elem_type &elem){
+ return _detail.pop_with_wait(elem);
+ }
/*!
* Pop an element from the bounded_buffer.
@@ -79,16 +98,13 @@ namespace uhd{ namespace transport{
* \param timeout the timeout in seconds
* \return false when the operation times out
*/
- virtual bool pop_with_timed_wait(elem_type &elem, double timeout) = 0;
+ bool pop_with_timed_wait(elem_type &elem, double timeout){
+ return _detail.pop_with_timed_wait(elem, timeout);
+ }
- /*!
- * Clear all elements from the bounded_buffer.
- */
- virtual void clear(void) = 0;
+ private: bounded_buffer_detail<elem_type> _detail;
};
}} //namespace
-#include <uhd/transport/bounded_buffer.ipp>
-
#endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_HPP */
diff --git a/host/include/uhd/transport/bounded_buffer.ipp b/host/include/uhd/transport/bounded_buffer.ipp
index 4fbe3f085..7be2f987c 100644
--- a/host/include/uhd/transport/bounded_buffer.ipp
+++ b/host/include/uhd/transport/bounded_buffer.ipp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// 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
@@ -18,22 +18,23 @@
#ifndef INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
#define INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP
+#include <uhd/config.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/locks.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
namespace uhd{ namespace transport{ namespace{ /*anon*/
- template <typename elem_type>
- class bounded_buffer_impl : public bounded_buffer<elem_type>{
+ template <typename elem_type> class bounded_buffer_detail{
public:
- bounded_buffer_impl(size_t capacity) : _buffer(capacity){
- _not_full_fcn = boost::bind(&bounded_buffer_impl<elem_type>::not_full, this);
- _not_empty_fcn = boost::bind(&bounded_buffer_impl<elem_type>::not_empty, this);
+ bounded_buffer_detail(size_t capacity):
+ _buffer(capacity)
+ {
+ _not_full_fcn = boost::bind(&bounded_buffer_detail<elem_type>::not_full, this);
+ _not_empty_fcn = boost::bind(&bounded_buffer_detail<elem_type>::not_empty, this);
}
UHD_INLINE bool push_with_pop_on_full(const elem_type &elem){
@@ -72,6 +73,15 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
return true;
}
+ UHD_INLINE bool pop_with_haste(elem_type &elem){
+ boost::mutex::scoped_lock lock(_mutex);
+ if(_buffer.empty()) return false;
+ elem = this->pop_back();
+ lock.unlock();
+ _full_cond.notify_one();
+ return true;
+ }
+
UHD_INLINE void pop_with_wait(elem_type &elem){
boost::mutex::scoped_lock lock(_mutex);
_empty_cond.wait(lock, _not_empty_fcn);
@@ -91,13 +101,6 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
return true;
}
- UHD_INLINE void clear(void){
- boost::mutex::scoped_lock lock(_mutex);
- while (not_empty()) this->pop_back();
- lock.unlock();
- _full_cond.notify_one();
- }
-
private:
boost::mutex _mutex;
boost::condition _empty_cond, _full_cond;
@@ -128,13 +131,4 @@ namespace uhd{ namespace transport{ namespace{ /*anon*/
};
}}} //namespace
-namespace uhd{ namespace transport{
-
- template <typename elem_type> typename bounded_buffer<elem_type>::sptr
- bounded_buffer<elem_type>::make(size_t capacity){
- return typename bounded_buffer<elem_type>::sptr(new bounded_buffer_impl<elem_type>(capacity));
- }
-
-}} //namespace
-
#endif /* INCLUDED_UHD_TRANSPORT_BOUNDED_BUFFER_IPP */
diff --git a/host/include/uhd/transport/zero_copy.hpp b/host/include/uhd/transport/zero_copy.hpp
index 7d8fb4b83..d5a536b27 100644
--- a/host/include/uhd/transport/zero_copy.hpp
+++ b/host/include/uhd/transport/zero_copy.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010 Ettus Research LLC
+// Copyright 2010-2011 Ettus Research LLC
//
// 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
@@ -19,7 +19,6 @@
#define INCLUDED_UHD_TRANSPORT_ZERO_COPY_HPP
#include <uhd/config.hpp>
-#include <boost/asio/buffer.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
@@ -40,13 +39,13 @@ namespace uhd{ namespace transport{
* Make a safe managed receive buffer:
* A safe managed buffer ensures that release is called once,
* either by the user or automatically upon deconstruction.
- * \param buff a reference to the constant buffer
+ * \param buff a pointer into read-only memory
+ * \param size the length of the buffer in bytes
* \param release_fcn callback to release the memory
* \return a new managed receive buffer
*/
static sptr make_safe(
- const boost::asio::const_buffer &buff,
- const release_fcn_t &release_fcn
+ const void *buff, size_t size, const release_fcn_t &release_fcn
);
/*!
@@ -57,28 +56,24 @@ namespace uhd{ namespace transport{
virtual void release(void) = 0;
/*!
- * Get the size of the underlying buffer.
- * \return the number of bytes
- */
- inline size_t size(void) const{
- return boost::asio::buffer_size(this->get());
- }
-
- /*!
* Get a pointer to the underlying buffer.
* \return a pointer into memory
*/
template <class T> inline T cast(void) const{
- return boost::asio::buffer_cast<T>(this->get());
+ return static_cast<T>(this->get_buff());
}
- private:
/*!
- * Get a reference to the internal const buffer.
- * The buffer has a reference to memory and a size.
- * \return a boost asio const buffer
+ * Get the size of the underlying buffer.
+ * \return the number of bytes
*/
- virtual const boost::asio::const_buffer &get(void) const = 0;
+ inline size_t size(void) const{
+ return this->get_size();
+ }
+
+ private:
+ virtual const void *get_buff(void) const = 0;
+ virtual size_t get_size(void) const = 0;
};
/*!
@@ -96,13 +91,13 @@ namespace uhd{ namespace transport{
* A safe managed buffer ensures that commit is called once,
* either by the user or automatically upon deconstruction.
* In the later case, the deconstructor will call commit(0).
- * \param buff a reference to the mutable buffer
+ * \param buff a pointer into writable memory
+ * \param size the length of the buffer in bytes
* \param commit_fcn callback to commit the memory
* \return a new managed send buffer
*/
static sptr make_safe(
- const boost::asio::mutable_buffer &buff,
- const commit_fcn_t &commit_fcn
+ void *buff, size_t size, const commit_fcn_t &commit_fcn
);
/*!
@@ -114,28 +109,24 @@ namespace uhd{ namespace transport{
virtual void commit(size_t num_bytes) = 0;
/*!
- * Get the size of the underlying buffer.
- * \return the number of bytes
- */
- inline size_t size(void) const{
- return boost::asio::buffer_size(this->get());
- }
-
- /*!
* Get a pointer to the underlying buffer.
* \return a pointer into memory
*/
template <class T> inline T cast(void) const{
- return boost::asio::buffer_cast<T>(this->get());
+ return static_cast<T>(this->get_buff());
}
- private:
/*!
- * Get a reference to the internal mutable buffer.
- * The buffer has a reference to memory and a size.
- * \return a boost asio mutable buffer
+ * Get the size of the underlying buffer.
+ * \return the number of bytes
*/
- virtual const boost::asio::mutable_buffer &get(void) const = 0;
+ inline size_t size(void) const{
+ return this->get_size();
+ }
+
+ private:
+ virtual void *get_buff(void) const = 0;
+ virtual size_t get_size(void) const = 0;
};
/*!
diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt
index 51be164aa..c856e5568 100644
--- a/host/include/uhd/types/CMakeLists.txt
+++ b/host/include/uhd/types/CMakeLists.txt
@@ -26,6 +26,7 @@ INSTALL(FILES
metadata.hpp
otw_type.hpp
ranges.hpp
+ ref_vector.hpp
sensors.hpp
serial.hpp
stream_cmd.hpp
diff --git a/host/include/uhd/types/io_type.hpp b/host/include/uhd/types/io_type.hpp
index ec1b9c056..990d701f9 100644
--- a/host/include/uhd/types/io_type.hpp
+++ b/host/include/uhd/types/io_type.hpp
@@ -35,6 +35,8 @@ namespace uhd{
enum tid_t{
//! Custom type (technically unsupported by implementation)
CUSTOM_TYPE = '?',
+ //! Complex floating point (64-bit floats) range [-1.0, +1.0]
+ COMPLEX_FLOAT64 = 'd',
//! Complex floating point (32-bit floats) range [-1.0, +1.0]
COMPLEX_FLOAT32 = 'f',
//! Complex signed integer (16-bit integers) range [-32768, +32767]
diff --git a/host/include/uhd/types/ref_vector.hpp b/host/include/uhd/types/ref_vector.hpp
new file mode 100644
index 000000000..ef970802f
--- /dev/null
+++ b/host/include/uhd/types/ref_vector.hpp
@@ -0,0 +1,69 @@
+//
+// Copyright 2011 Ettus Research LLC
+//
+// 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_UHD_TYPES_REF_VECTOR_HPP
+#define INCLUDED_UHD_TYPES_REF_VECTOR_HPP
+
+#include <uhd/config.hpp>
+
+namespace uhd{
+
+/*!
+ * Reference vector:
+ * - Provides a std::vector-like interface for an array.
+ * - Statically sized, and does not manage the memory.
+ */
+template <typename T> class ref_vector{
+public:
+ //! Create a reference vector of length one from a pointer
+ template <typename Ptr> ref_vector(Ptr *ptr):
+ _mem(memp_t(&ptr)), _size(1)
+ {
+ /* NOP */
+ }
+
+ //! Create a reference vector from a std::vector container
+ template <typename Range> ref_vector(const Range &range):
+ _mem(memp_t(&range[0])), _size(range.size())
+ {
+ /* NOP */
+ }
+
+ //! Create a reference vector from a memory pointer and size
+ ref_vector(T *mem, size_t size):
+ _mem(mem), _size(size)
+ {
+ /* NOP */
+ }
+
+ T &operator[](size_t index) const{
+ return _mem[index];
+ }
+
+ size_t size(void) const{
+ return _size;
+ }
+
+private:
+ typedef T* memp_t;
+ const memp_t _mem;
+ const size_t _size;
+};
+
+} //namespace uhd
+
+#endif /* INCLUDED_UHD_TYPES_REF_VECTOR_HPP */
diff --git a/host/include/uhd/types/time_spec.hpp b/host/include/uhd/types/time_spec.hpp
index 57d002d48..2046fbd3f 100644
--- a/host/include/uhd/types/time_spec.hpp
+++ b/host/include/uhd/types/time_spec.hpp
@@ -40,6 +40,13 @@ namespace uhd{
public:
/*!
+ * Get the system time in time_spec_t format.
+ * Uses the highest precision clock available.
+ * \return the system time as a time_spec_t
+ */
+ static time_spec_t get_system_time(void);
+
+ /*!
* Create a time_spec_t from a real-valued seconds count.
* \param secs the real-valued seconds count (default = 0)
*/