From 7f82d289a6f196a6f7b72bc0cff1807870ee8837 Mon Sep 17 00:00:00 2001 From: Jon Szymaniak Date: Sat, 25 Oct 2014 16:23:58 -0400 Subject: [PATCH] bladeRF: Default num_transfers to min(32, num_buffers/2) This avoids inadvertently attempting to use a larger number of transfers than the underlying USB library/interface allows by specifying a large value for num_buffers. Users can specify up to (num_buffers - 1) transfers. However, it is generally recommended to use half as many transfers as buffers. --- lib/bladerf/bladerf_common.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index 3308c13..da57e0e 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -403,10 +403,18 @@ void bladerf_common::init(dict_t &dict, bladerf_module module) } } - - - if (_num_transfers == 0 || _num_transfers > (_num_buffers / 2)) { + /* If the user hasn't specified the desired number of transfers, set it to + * min(32, num_buffers / 2) */ + if (_num_transfers == 0) { _num_transfers = _num_buffers / 2; + if (_num_transfers > 32) { + _num_transfers = 32; + } + } else if (_num_transfers >= _num_buffers) { + _num_transfers = _num_buffers - 1; + std::cerr << _pfx << "Clamping num_tranfers to " << _num_transfers << ". " + << "Try using a smaller num_transfers value if timeouts occur." + << std::endl; } _conv_buf = static_cast(malloc(_conv_buf_size * 2 * sizeof(int16_t)));