uhd: Use internal UHD tick conversions

UHD handles built in tick and floating point timestamp conversion
since version 003.005.004. This removes the need for separate UHD
timespec to tick conversion.

Signed-off-by: Tom Tsou <tom.tsou@ettus.com>
This commit is contained in:
Tom Tsou 2015-08-21 19:21:28 -07:00
parent c312905f43
commit d4d3daa12e
2 changed files with 11 additions and 27 deletions

View File

@ -212,22 +212,6 @@ static double select_rate(uhd_dev_type type, int sps, bool diversity = false)
return -9999.99; return -9999.99;
} }
/** Timestamp conversion
@param timestamp a UHD or OpenBTS timestamp
@param rate sample rate
@return the converted timestamp
*/
uhd::time_spec_t convert_time(TIMESTAMP ticks, double rate)
{
double secs = (double) ticks / rate;
return uhd::time_spec_t(secs);
}
TIMESTAMP convert_time(uhd::time_spec_t ts, double rate)
{
return (TIMESTAMP)(ts.get_real_secs() * rate + 0.5);
}
/* /*
Sample Buffer - Allows reading and writing of timed samples using OpenBTS Sample Buffer - Allows reading and writing of timed samples using OpenBTS
or UHD style timestamps. Time conversions are handled or UHD style timestamps. Time conversions are handled
@ -864,7 +848,7 @@ bool uhd_device::flush_recv(size_t num_pkts)
} }
} }
ts_initial = convert_time(md.time_spec, rx_rate); ts_initial = md.time_spec.to_ticks(rx_rate);
} }
LOG(INFO) << "Initial timestamp " << ts_initial << std::endl; LOG(INFO) << "Initial timestamp " << ts_initial << std::endl;
@ -1001,7 +985,7 @@ int uhd_device::readSamples(std::vector<short *> &bufs, int len, bool *overrun,
// Shift read time with respect to transmit clock // Shift read time with respect to transmit clock
timestamp += ts_offset; timestamp += ts_offset;
ts = convert_time(timestamp, rx_rate); ts = uhd::time_spec_t::from_ticks(timestamp, rx_rate);
LOG(DEBUG) << "Requested timestamp = " << ts.get_real_secs(); LOG(DEBUG) << "Requested timestamp = " << ts.get_real_secs();
// Check that timestamp is valid // Check that timestamp is valid
@ -1083,7 +1067,7 @@ int uhd_device::writeSamples(std::vector<short *> &bufs, int len, bool *underrun
metadata.has_time_spec = true; metadata.has_time_spec = true;
metadata.start_of_burst = false; metadata.start_of_burst = false;
metadata.end_of_burst = false; metadata.end_of_burst = false;
metadata.time_spec = convert_time(timestamp, tx_rate); metadata.time_spec = uhd::time_spec_t::from_ticks(timestamp, tx_rate);
*underrun = false; *underrun = false;
@ -1397,7 +1381,7 @@ ssize_t smpl_buf::avail_smpls(TIMESTAMP timestamp) const
ssize_t smpl_buf::avail_smpls(uhd::time_spec_t timespec) const ssize_t smpl_buf::avail_smpls(uhd::time_spec_t timespec) const
{ {
return avail_smpls(convert_time(timespec, clk_rt)); return avail_smpls(timespec.to_ticks(clk_rt));
} }
ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp) ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
@ -1443,7 +1427,7 @@ ssize_t smpl_buf::read(void *buf, size_t len, TIMESTAMP timestamp)
ssize_t smpl_buf::read(void *buf, size_t len, uhd::time_spec_t ts) ssize_t smpl_buf::read(void *buf, size_t len, uhd::time_spec_t ts)
{ {
return read(buf, len, convert_time(ts, clk_rt)); return read(buf, len, ts.to_ticks(clk_rt));
} }
ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp) ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
@ -1458,14 +1442,14 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
if (timestamp < time_end) { if (timestamp < time_end) {
LOG(ERR) << "Overwriting old buffer data: timestamp="<<timestamp<<" time_end="<<time_end; LOG(ERR) << "Overwriting old buffer data: timestamp="<<timestamp<<" time_end="<<time_end;
uhd::time_spec_t ts = convert_time(timestamp, clk_rt); uhd::time_spec_t ts = uhd::time_spec_t::from_ticks(timestamp, clk_rt);
LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << convert_time(ts, clk_rt) << ") rate=" << clk_rt; LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << ts.to_ticks(clk_rt) << ") rate=" << clk_rt;
// Do not return error here, because it's a rounding error and is not fatal // Do not return error here, because it's a rounding error and is not fatal
} }
if (timestamp > time_end && time_end != 0) { if (timestamp > time_end && time_end != 0) {
LOG(ERR) << "Skipping buffer data: timestamp="<<timestamp<<" time_end="<<time_end; LOG(ERR) << "Skipping buffer data: timestamp="<<timestamp<<" time_end="<<time_end;
uhd::time_spec_t ts = convert_time(timestamp, clk_rt); uhd::time_spec_t ts = uhd::time_spec_t::from_ticks(timestamp, clk_rt);
LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << convert_time(ts, clk_rt) << ") rate=" << clk_rt; LOG(DEBUG) << "Requested timestamp = " << timestamp << " (real_sec=" << std::fixed << ts.get_real_secs() << " = " << ts.to_ticks(clk_rt) << ") rate=" << clk_rt;
// Do not return error here, because it's a rounding error and is not fatal // Do not return error here, because it's a rounding error and is not fatal
} }
@ -1500,7 +1484,7 @@ ssize_t smpl_buf::write(void *buf, size_t len, TIMESTAMP timestamp)
ssize_t smpl_buf::write(void *buf, size_t len, uhd::time_spec_t ts) ssize_t smpl_buf::write(void *buf, size_t len, uhd::time_spec_t ts)
{ {
return write(buf, len, convert_time(ts, clk_rt)); return write(buf, len, ts.to_ticks(clk_rt));
} }
std::string smpl_buf::str_status(size_t ts) const std::string smpl_buf::str_status(size_t ts) const

View File

@ -99,7 +99,7 @@ AS_IF([test "x$with_usrp1" = "xyes"], [
AS_IF([test "x$with_usrp1" != "xyes"],[ AS_IF([test "x$with_usrp1" != "xyes"],[
PKG_CHECK_MODULES(UHD, uhd >= 003.009, PKG_CHECK_MODULES(UHD, uhd >= 003.009,
[AC_DEFINE(USE_UHD_3_9, 1, UHD version 3.9.0 or higher)], [AC_DEFINE(USE_UHD_3_9, 1, UHD version 3.9.0 or higher)],
[PKG_CHECK_MODULES(UHD, uhd >= 003.004.000)] [PKG_CHECK_MODULES(UHD, uhd >= 003.005.004)]
) )
AC_DEFINE(USE_UHD, 1, All UHD versions) AC_DEFINE(USE_UHD, 1, All UHD versions)
]) ])