aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp1
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib/usrp/usrp1')
-rw-r--r--host/lib/usrp/usrp1/io_impl.cpp26
-rw-r--r--host/lib/usrp/usrp1/soft_time_ctrl.cpp45
-rw-r--r--host/lib/usrp/usrp1/usrp1_impl.hpp5
3 files changed, 23 insertions, 53 deletions
diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp
index 9fa1b4f72..88cbab073 100644
--- a/host/lib/usrp/usrp1/io_impl.cpp
+++ b/host/lib/usrp/usrp1/io_impl.cpp
@@ -91,7 +91,6 @@ struct usrp1_impl::io_impl{
void commit_send_buff(offset_send_buffer::sptr, offset_send_buffer::sptr, size_t);
void flush_send_buff(void);
bool get_send_buffs(vrt_packet_handler::managed_send_buffs_t &, double);
- bool transmitting_enb;
};
/*!
@@ -133,6 +132,9 @@ void usrp1_impl::io_impl::flush_send_buff(void){
//calculate the number of bytes to alignment
size_t bytes_to_pad = (-1*curr_buff->offset)%alignment_padding;
+ //send at least alignment_padding to guarantee zeros are sent
+ if (bytes_to_pad == 0) bytes_to_pad = alignment_padding;
+
//get the buffer, clear, and commit (really current buffer)
vrt_packet_handler::managed_send_buffs_t buffs(1);
if (this->get_send_buffs(buffs, 0.1)){
@@ -157,10 +159,8 @@ bool usrp1_impl::io_impl::get_send_buffs(
//calculate the buffer pointer and size given the offset
//references to the buffers are held in the bound function
buffs[0] = managed_send_buffer::make_safe(
- boost::asio::buffer(
- curr_buff->buff->cast<char *>() + curr_buff->offset,
- curr_buff->buff->size() - curr_buff->offset
- ),
+ curr_buff->buff->cast<char *>() + curr_buff->offset,
+ curr_buff->buff->size() - curr_buff->offset,
boost::bind(&usrp1_impl::io_impl::commit_send_buff, this, curr_buff, next_buff, _1)
);
@@ -190,7 +190,7 @@ void usrp1_impl::io_init(void){
);
rx_stream_on_off(false);
- tx_stream_on_off(false);
+ _io_impl->flush_send_buff();
}
void usrp1_impl::rx_stream_on_off(bool enb){
@@ -201,13 +201,6 @@ void usrp1_impl::rx_stream_on_off(bool enb){
}
}
-void usrp1_impl::tx_stream_on_off(bool enb){
- if (not enb) _io_impl->flush_send_buff();
- _codec_ctrls[DBOARD_SLOT_A]->enable_tx_digital(enb);
- _codec_ctrls[DBOARD_SLOT_B]->enable_tx_digital(enb);
- _io_impl->transmitting_enb = enb;
-}
-
/***********************************************************************
* Data send + helper functions
**********************************************************************/
@@ -227,12 +220,11 @@ size_t usrp1_impl::get_max_send_samps_per_packet(void) const {
}
size_t usrp1_impl::send(
- const std::vector<const void *> &buffs, size_t num_samps,
+ const send_buffs_type &buffs, size_t num_samps,
const tx_metadata_t &metadata, const io_type_t &io_type,
send_mode_t send_mode, double timeout
){
if (_soft_time_ctrl->send_pre(metadata, timeout)) return num_samps;
- if (not _io_impl->transmitting_enb) tx_stream_on_off(true);
size_t num_samps_sent = vrt_packet_handler::send(
_io_impl->packet_handler_send_state, //last state of the send handler
@@ -250,7 +242,7 @@ size_t usrp1_impl::send(
//handle eob flag (commit the buffer, disable the DACs)
//check num samps sent to avoid flush on incomplete/timeout
if (metadata.end_of_burst and num_samps_sent == num_samps){
- this->tx_stream_on_off(false);
+ _io_impl->flush_send_buff();
}
//handle the polling for underflow conditions
@@ -306,7 +298,7 @@ size_t usrp1_impl::get_max_recv_samps_per_packet(void) const {
}
size_t usrp1_impl::recv(
- const std::vector<void *> &buffs, size_t num_samps,
+ const recv_buffs_type &buffs, size_t num_samps,
rx_metadata_t &metadata, const io_type_t &io_type,
recv_mode_t recv_mode, double timeout
){
diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp
index c91ecc7ed..e1b671811 100644
--- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp
+++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp
@@ -18,7 +18,8 @@
#include "soft_time_ctrl.hpp"
#include <uhd/transport/bounded_buffer.hpp>
#include <boost/any.hpp>
-#include <boost/thread.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/condition_variable.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
@@ -27,30 +28,7 @@ using namespace uhd::usrp;
using namespace uhd::transport;
namespace pt = boost::posix_time;
-static const time_spec_t TWIDDLE(0.0015);
-
-/***********************************************************************
- * Utility helper functions
- **********************************************************************/
-
-//TODO put these in time_spec_t (maybe useful)
-
-static const double time_dur_tps = double(pt::time_duration::ticks_per_second());
-
-time_spec_t time_dur_to_time_spec(const pt::time_duration &time_dur){
- return time_spec_t(
- time_dur.total_seconds(),
- long(time_dur.fractional_seconds()),
- time_dur_tps
- );
-}
-
-pt::time_duration time_spec_to_time_dur(const time_spec_t &time_spec){
- return pt::time_duration(
- 0, 0, long(time_spec.get_full_secs()),
- time_spec.get_tick_count(time_dur_tps)
- );
-}
+static const time_spec_t TWIDDLE(0.0011);
/***********************************************************************
* Soft time control implementation
@@ -61,7 +39,7 @@ public:
soft_time_ctrl_impl(const cb_fcn_type &stream_on_off):
_nsamps_remaining(0),
_stream_mode(stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS),
- _cmd_queue(bounded_buffer<boost::any>::make(2)),
+ _cmd_queue(2),
_stream_on_off(stream_on_off)
{
//synchronously spawn a new thread
@@ -84,7 +62,7 @@ public:
******************************************************************/
void set_time(const time_spec_t &time){
boost::mutex::scoped_lock lock(_update_mutex);
- _time_offset = boost::get_system_time() - time_spec_to_time_dur(time);
+ _time_offset = time_spec_t::get_system_time() - time;
}
time_spec_t get_time(void){
@@ -94,7 +72,7 @@ public:
UHD_INLINE time_spec_t time_now(void){
//internal get time without scoped lock
- return time_dur_to_time_spec(boost::get_system_time() - _time_offset);
+ return time_spec_t::get_system_time() - _time_offset;
}
UHD_INLINE void sleep_until_time(
@@ -102,7 +80,8 @@ public:
){
boost::condition_variable cond;
//use a condition variable to unlock, sleep, lock
- cond.timed_wait(lock, _time_offset + time_spec_to_time_dur(time));
+ double seconds_to_sleep = (time - time_now()).get_real_secs();
+ cond.timed_wait(lock, pt::microseconds(long(seconds_to_sleep*1e6)));
}
/*******************************************************************
@@ -133,7 +112,7 @@ public:
}
void issue_stream_cmd(const stream_cmd_t &cmd){
- _cmd_queue->push_with_wait(cmd);
+ _cmd_queue.push_with_wait(cmd);
}
void stream_on_off(bool enb){
@@ -201,7 +180,7 @@ public:
try{
boost::any cmd;
while (true){
- _cmd_queue->pop_with_wait(cmd);
+ _cmd_queue.pop_with_wait(cmd);
recv_cmd_handle_cmd(boost::any_cast<stream_cmd_t>(cmd));
}
} catch(const boost::thread_interrupted &){}
@@ -211,8 +190,8 @@ private:
boost::mutex _update_mutex;
size_t _nsamps_remaining;
stream_cmd_t::stream_mode_t _stream_mode;
- pt::ptime _time_offset;
- bounded_buffer<boost::any>::sptr _cmd_queue;
+ time_spec_t _time_offset;
+ bounded_buffer<boost::any> _cmd_queue;
const cb_fcn_type _stream_on_off;
boost::thread_group _thread_group;
};
diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp
index 057725394..1d9f6709f 100644
--- a/host/lib/usrp/usrp1/usrp1_impl.hpp
+++ b/host/lib/usrp/usrp1/usrp1_impl.hpp
@@ -80,13 +80,13 @@ public:
~usrp1_impl(void);
//the io interface
- size_t send(const std::vector<const void *> &,
+ size_t send(const send_buffs_type &,
size_t,
const uhd::tx_metadata_t &,
const uhd::io_type_t &,
send_mode_t, double);
- size_t recv(const std::vector<void *> &,
+ size_t recv(const recv_buffs_type &,
size_t, uhd::rx_metadata_t &,
const uhd::io_type_t &,
recv_mode_t, double);
@@ -125,7 +125,6 @@ private:
UHD_PIMPL_DECL(io_impl) _io_impl;
void io_init(void);
void rx_stream_on_off(bool);
- void tx_stream_on_off(bool);
void handle_overrun(size_t);
//underrun and overrun poll intervals