Revision 15268898
| b/host/include/uhd/utils/algorithm.hpp | ||
|---|---|---|
| 21 | 21 |
#include <algorithm> |
| 22 | 22 |
#include <boost/range/begin.hpp> |
| 23 | 23 |
#include <boost/range/end.hpp> |
| 24 |
#include <boost/range/size.hpp> |
|
| 25 | 24 |
|
| 26 |
/*! \file algorithm.hpp
|
|
| 25 |
/*! |
|
| 27 | 26 |
* Useful templated functions and classes that I like to pretend are part of stl. |
| 28 | 27 |
* Many of the range wrapper functions come with recent versions of boost (1.43). |
| 29 | 28 |
*/ |
| 30 |
namespace std{
|
|
| 31 |
|
|
| 32 |
/*! |
|
| 33 |
* A wrapper around std::sort that takes a range instead of an iterator. |
|
| 34 |
* |
|
| 35 |
* The elements are sorted into ascending order using the less-than operator. |
|
| 36 |
* |
|
| 37 |
* \param range the range of elements to be sorted |
|
| 38 |
*/ |
|
| 39 |
template<typename Range> inline void sort(Range &range){
|
|
| 40 |
return std::sort(boost::begin(range), boost::end(range)); |
|
| 41 |
} |
|
| 29 |
namespace uhd{
|
|
| 42 | 30 |
|
| 43 | 31 |
/*! |
| 44 | 32 |
* A wrapper around std::sort that takes a range instead of an iterator. |
| ... | ... | |
| 51 | 39 |
* \return a new range with the elements sorted |
| 52 | 40 |
*/ |
| 53 | 41 |
template<typename Range> inline Range sorted(const Range &range){
|
| 54 |
Range srange(range); std::sort(srange); return srange; |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/*! |
|
| 58 |
* A wrapper around std::reverse that takes a range instead of an iterator. |
|
| 59 |
* |
|
| 60 |
* The elements are reversed into descending order using the less-than operator. |
|
| 61 |
* |
|
| 62 |
* \param range the range of elements to be reversed |
|
| 63 |
*/ |
|
| 64 |
template<typename Range> inline void reverse(Range &range){
|
|
| 65 |
return std::reverse(boost::begin(range), boost::end(range)); |
|
| 42 |
Range r(range); std::sort(boost::begin(r), boost::end(r)); return r; |
|
| 66 | 43 |
} |
| 67 | 44 |
|
| 68 | 45 |
/*! |
| ... | ... | |
| 76 | 53 |
* \return a new range with the elements reversed |
| 77 | 54 |
*/ |
| 78 | 55 |
template<typename Range> inline Range reversed(const Range &range){
|
| 79 |
Range srange(range); std::reverse(srange); return srange;
|
|
| 56 |
Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
|
|
| 80 | 57 |
} |
| 81 | 58 |
|
| 82 | 59 |
/*! |
| ... | ... | |
| 94 | 71 |
} |
| 95 | 72 |
|
| 96 | 73 |
/*! |
| 97 |
* Count the number of appearances of a value in a range. |
|
| 98 |
* |
|
| 99 |
* Uses std::count to count the appearances in the range. |
|
| 100 |
* |
|
| 101 |
* \param range the elements to iterate through |
|
| 102 |
* \param value the value to count in the range |
|
| 103 |
* \return the number of appearances of the value |
|
| 104 |
*/ |
|
| 105 |
template<typename Range, typename T> inline |
|
| 106 |
size_t count(const Range &range, const T &value){
|
|
| 107 |
return std::count(boost::begin(range), boost::end(range), value); |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/*! |
|
| 111 |
* Are the ranges equal (are their elements equivalent)? |
|
| 112 |
* |
|
| 113 |
* Uses std::equal to search the iterable for an element. |
|
| 114 |
* |
|
| 115 |
* \param range1 the first range of elements |
|
| 116 |
* \param range2 the second range of elements |
|
| 117 |
* \return true when the elements are equivalent |
|
| 118 |
*/ |
|
| 119 |
template<typename Range> inline |
|
| 120 |
bool equal(const Range &range1, const Range &range2){
|
|
| 121 |
return (boost::size(range1) == boost::size(range2)) and |
|
| 122 |
std::equal(boost::begin(range1), boost::end(range1), boost::begin(range2)); |
|
| 123 |
} |
|
| 124 |
|
|
| 125 |
/*! |
|
| 126 | 74 |
* A templated clip implementation. |
| 127 | 75 |
* \param val the value to clip between an upper and lower limit |
| 128 | 76 |
* \param bound1 the upper or lower bound |
| ... | ... | |
| 137 | 85 |
return val; |
| 138 | 86 |
} |
| 139 | 87 |
|
| 140 |
}//namespace std
|
|
| 88 |
} //namespace uhd
|
|
| 141 | 89 |
|
| 142 | 90 |
#endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */ |
| b/host/include/uhd/utils/assert_has.ipp | ||
|---|---|---|
| 31 | 31 |
const T &value, |
| 32 | 32 |
const std::string &what |
| 33 | 33 |
){
|
| 34 |
if (std::has(range, value)) return;
|
|
| 34 |
if (uhd::has(range, value)) return;
|
|
| 35 | 35 |
std::string possible_values = ""; |
| 36 | 36 |
size_t i = 0; |
| 37 | 37 |
BOOST_FOREACH(const T &v, range){
|
| b/host/lib/device.cpp | ||
|---|---|---|
| 43 | 43 |
){
|
| 44 | 44 |
//combine the hashes of sorted keys/value pairs |
| 45 | 45 |
size_t hash = 0; |
| 46 |
BOOST_FOREACH(const std::string &key, std::sorted(dev_addr.keys())){
|
|
| 46 |
BOOST_FOREACH(const std::string &key, uhd::sorted(dev_addr.keys())){
|
|
| 47 | 47 |
boost::hash_combine(hash, key); |
| 48 | 48 |
boost::hash_combine(hash, dev_addr[key]); |
| 49 | 49 |
} |
| b/host/lib/usrp/dboard/db_dbsrx.cpp | ||
|---|---|---|
| 83 | 83 |
void set_bandwidth(double bandwidth); |
| 84 | 84 |
|
| 85 | 85 |
void send_reg(boost::uint8_t start_reg, boost::uint8_t stop_reg){
|
| 86 |
start_reg = boost::uint8_t(std::clip(int(start_reg), 0x0, 0x5));
|
|
| 87 |
stop_reg = boost::uint8_t(std::clip(int(stop_reg), 0x0, 0x5));
|
|
| 86 |
start_reg = boost::uint8_t(uhd::clip(int(start_reg), 0x0, 0x5));
|
|
| 87 |
stop_reg = boost::uint8_t(uhd::clip(int(stop_reg), 0x0, 0x5));
|
|
| 88 | 88 |
|
| 89 | 89 |
for(boost::uint8_t start_addr=start_reg; start_addr <= stop_reg; start_addr += sizeof(boost::uint32_t) - 1){
|
| 90 | 90 |
int num_bytes = int(stop_reg - start_addr + 1) > int(sizeof(boost::uint32_t)) - 1 ? sizeof(boost::uint32_t) - 1 : stop_reg - start_addr + 1; |
| ... | ... | |
| 112 | 112 |
|
| 113 | 113 |
void read_reg(boost::uint8_t start_reg, boost::uint8_t stop_reg){
|
| 114 | 114 |
static const boost::uint8_t status_addr = 0x0; |
| 115 |
start_reg = boost::uint8_t(std::clip(int(start_reg), 0x0, 0x1));
|
|
| 116 |
stop_reg = boost::uint8_t(std::clip(int(stop_reg), 0x0, 0x1));
|
|
| 115 |
start_reg = boost::uint8_t(uhd::clip(int(start_reg), 0x0, 0x1));
|
|
| 116 |
stop_reg = boost::uint8_t(uhd::clip(int(stop_reg), 0x0, 0x1));
|
|
| 117 | 117 |
|
| 118 | 118 |
for(boost::uint8_t start_addr=start_reg; start_addr <= stop_reg; start_addr += sizeof(boost::uint32_t)){
|
| 119 | 119 |
int num_bytes = int(stop_reg - start_addr + 1) > int(sizeof(boost::uint32_t)) ? sizeof(boost::uint32_t) : stop_reg - start_addr + 1; |
| ... | ... | |
| 237 | 237 |
bool update_filter_settings = false; |
| 238 | 238 |
//choose refclock |
| 239 | 239 |
std::vector<double> clock_rates = this->get_iface()->get_clock_rates(dboard_iface::UNIT_RX); |
| 240 |
const double max_clock_rate = std::sorted(clock_rates).back();
|
|
| 241 |
BOOST_FOREACH(ref_clock, std::reversed(std::sorted(clock_rates))){
|
|
| 240 |
const double max_clock_rate = uhd::sorted(clock_rates).back();
|
|
| 241 |
BOOST_FOREACH(ref_clock, uhd::reversed(uhd::sorted(clock_rates))){
|
|
| 242 | 242 |
if (ref_clock > 27.0e6) continue; |
| 243 | 243 |
if (size_t(max_clock_rate/ref_clock)%2 == 1) continue; //reject asymmetric clocks (odd divisors) |
| 244 | 244 |
|
| ... | ... | |
| 485 | 485 |
**********************************************************************/ |
| 486 | 486 |
void dbsrx::set_bandwidth(double bandwidth){
|
| 487 | 487 |
//clip the input |
| 488 |
bandwidth = std::clip<double>(bandwidth, 4e6, 33e6);
|
|
| 488 |
bandwidth = uhd::clip<double>(bandwidth, 4e6, 33e6);
|
|
| 489 | 489 |
|
| 490 | 490 |
double ref_clock = this->get_iface()->get_clock_rate(dboard_iface::UNIT_RX); |
| 491 | 491 |
|
| 492 | 492 |
//NOTE: _max2118_write_regs.m_divider set in set_lo_freq |
| 493 | 493 |
|
| 494 | 494 |
//compute f_dac setting |
| 495 |
_max2118_write_regs.f_dac = std::clip<int>(int((((bandwidth*_max2118_write_regs.m_divider)/ref_clock) - 4)/0.145),0,127);
|
|
| 495 |
_max2118_write_regs.f_dac = uhd::clip<int>(int((((bandwidth*_max2118_write_regs.m_divider)/ref_clock) - 4)/0.145),0,127);
|
|
| 496 | 496 |
|
| 497 | 497 |
//determine actual bandwidth |
| 498 | 498 |
_bandwidth = double((ref_clock/(_max2118_write_regs.m_divider))*(4+0.145*_max2118_write_regs.f_dac)); |
| b/host/lib/usrp/dboard/db_dbsrx2.cpp | ||
|---|---|---|
| 79 | 79 |
void set_bandwidth(double bandwidth); |
| 80 | 80 |
|
| 81 | 81 |
void send_reg(boost::uint8_t start_reg, boost::uint8_t stop_reg){
|
| 82 |
start_reg = boost::uint8_t(std::clip(int(start_reg), 0x0, 0xB));
|
|
| 83 |
stop_reg = boost::uint8_t(std::clip(int(stop_reg), 0x0, 0xB));
|
|
| 82 |
start_reg = boost::uint8_t(uhd::clip(int(start_reg), 0x0, 0xB));
|
|
| 83 |
stop_reg = boost::uint8_t(uhd::clip(int(stop_reg), 0x0, 0xB));
|
|
| 84 | 84 |
|
| 85 | 85 |
for(boost::uint8_t start_addr=start_reg; start_addr <= stop_reg; start_addr += sizeof(boost::uint32_t) - 1){
|
| 86 | 86 |
int num_bytes = int(stop_reg - start_addr + 1) > int(sizeof(boost::uint32_t)) - 1 ? sizeof(boost::uint32_t) - 1 : stop_reg - start_addr + 1; |
| ... | ... | |
| 108 | 108 |
|
| 109 | 109 |
void read_reg(boost::uint8_t start_reg, boost::uint8_t stop_reg){
|
| 110 | 110 |
static const boost::uint8_t status_addr = 0xC; |
| 111 |
start_reg = boost::uint8_t(std::clip(int(start_reg), 0x0, 0xD));
|
|
| 112 |
stop_reg = boost::uint8_t(std::clip(int(stop_reg), 0x0, 0xD));
|
|
| 111 |
start_reg = boost::uint8_t(uhd::clip(int(start_reg), 0x0, 0xD));
|
|
| 112 |
stop_reg = boost::uint8_t(uhd::clip(int(stop_reg), 0x0, 0xD));
|
|
| 113 | 113 |
|
| 114 | 114 |
for(boost::uint8_t start_addr=start_reg; start_addr <= stop_reg; start_addr += sizeof(boost::uint32_t)){
|
| 115 | 115 |
int num_bytes = int(stop_reg - start_addr + 1) > int(sizeof(boost::uint32_t)) ? sizeof(boost::uint32_t) : stop_reg - start_addr + 1; |
| ... | ... | |
| 216 | 216 |
* Tuning |
| 217 | 217 |
**********************************************************************/ |
| 218 | 218 |
void dbsrx2::set_lo_freq(double target_freq){
|
| 219 |
//target_freq = std::clip(target_freq, dbsrx2_freq_range.min, dbsrx2_freq_range.max);
|
|
| 219 |
//target_freq = uhd::clip(target_freq, dbsrx2_freq_range.min, dbsrx2_freq_range.max);
|
|
| 220 | 220 |
|
| 221 | 221 |
//variables used in the calculation below |
| 222 | 222 |
int scaler = target_freq > 1125e6 ? 2 : 4; |
| ... | ... | |
| 330 | 330 |
**********************************************************************/ |
| 331 | 331 |
void dbsrx2::set_bandwidth(double bandwidth){
|
| 332 | 332 |
//clip the input |
| 333 |
bandwidth = std::clip<double>(bandwidth, 4e6, 40e6);
|
|
| 333 |
bandwidth = uhd::clip<double>(bandwidth, 4e6, 40e6);
|
|
| 334 | 334 |
|
| 335 | 335 |
_max2112_write_regs.lp = int((bandwidth/1e6 - 4)/0.29 + 12); |
| 336 | 336 |
_bandwidth = double(4 + (_max2112_write_regs.lp - 12) * 0.29)*1e6; |
| b/host/lib/usrp/dboard/db_rfx.cpp | ||
|---|---|---|
| 245 | 245 |
static const double slope = (max_volts-min_volts)/(range); |
| 246 | 246 |
|
| 247 | 247 |
//calculate the voltage for the aux dac |
| 248 |
double dac_volts = std::clip<double>(gain*slope + min_volts, max_volts, min_volts);
|
|
| 248 |
double dac_volts = uhd::clip<double>(gain*slope + min_volts, max_volts, min_volts);
|
|
| 249 | 249 |
|
| 250 | 250 |
//the actual gain setting |
| 251 | 251 |
gain = (dac_volts - min_volts)/slope; |
| b/host/lib/usrp/dboard/db_tvrx.cpp | ||
|---|---|---|
| 241 | 241 |
|
| 242 | 242 |
static double gain_interp(double gain, boost::array<double, 17> db_vector, boost::array<double, 17> volts_vector) {
|
| 243 | 243 |
double volts; |
| 244 |
gain = std::clip<double>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
|
|
| 244 |
gain = uhd::clip<double>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
|
|
| 245 | 245 |
|
| 246 | 246 |
boost::uint8_t gain_step = 0; |
| 247 | 247 |
//find which bin we're in |
| ... | ... | |
| 288 | 288 |
//this is the voltage at the USRP DAC output |
| 289 | 289 |
double dac_volts = gain_volts / opamp_gain; |
| 290 | 290 |
|
| 291 |
dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
|
|
| 291 |
dac_volts = uhd::clip<double>(dac_volts, 0.0, 3.3);
|
|
| 292 | 292 |
|
| 293 | 293 |
if (tvrx_debug) std::cerr << boost::format( |
| 294 | 294 |
"tvrx RF AGC gain: %f dB, dac_volts: %f V" |
| ... | ... | |
| 311 | 311 |
double gain_volts = gain_interp(gain, tvrx_if_gains_db, tvrx_gains_volts); |
| 312 | 312 |
double dac_volts = gain_volts / opamp_gain; |
| 313 | 313 |
|
| 314 |
dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
|
|
| 314 |
dac_volts = uhd::clip<double>(dac_volts, 0.0, 3.3);
|
|
| 315 | 315 |
|
| 316 | 316 |
if (tvrx_debug) std::cerr << boost::format( |
| 317 | 317 |
"tvrx IF AGC gain: %f dB, dac_volts: %f V" |
| b/host/lib/usrp/dboard/db_xcvr2450.cpp | ||
|---|---|---|
| 358 | 358 |
*/ |
| 359 | 359 |
static int gain_to_tx_vga_reg(double &gain){
|
| 360 | 360 |
//calculate the register value |
| 361 |
int reg = std::clip(boost::math::iround(gain*60/30.0) + 3, 0, 63);
|
|
| 361 |
int reg = uhd::clip(boost::math::iround(gain*60/30.0) + 3, 0, 63);
|
|
| 362 | 362 |
|
| 363 | 363 |
//calculate the actual gain value |
| 364 | 364 |
if (reg < 4) gain = 0; |
| ... | ... | |
| 376 | 376 |
* \return gain enum value |
| 377 | 377 |
*/ |
| 378 | 378 |
static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(double &gain){
|
| 379 |
int reg = std::clip(boost::math::iround(gain*3/5.0), 0, 3);
|
|
| 379 |
int reg = uhd::clip(boost::math::iround(gain*3/5.0), 0, 3);
|
|
| 380 | 380 |
switch(reg){
|
| 381 | 381 |
case 0: |
| 382 | 382 |
gain = 0; |
| ... | ... | |
| 401 | 401 |
* \return 5 bit the register value |
| 402 | 402 |
*/ |
| 403 | 403 |
static int gain_to_rx_vga_reg(double &gain){
|
| 404 |
int reg = std::clip(boost::math::iround(gain/2.0), 0, 31);
|
|
| 404 |
int reg = uhd::clip(boost::math::iround(gain/2.0), 0, 31);
|
|
| 405 | 405 |
gain = double(reg*2); |
| 406 | 406 |
return reg; |
| 407 | 407 |
} |
| ... | ... | |
| 413 | 413 |
* \return 2 bit the register value |
| 414 | 414 |
*/ |
| 415 | 415 |
static int gain_to_rx_lna_reg(double &gain){
|
| 416 |
int reg = std::clip(boost::math::iround(gain*2/30.5) + 1, 0, 3);
|
|
| 416 |
int reg = uhd::clip(boost::math::iround(gain*2/30.5) + 1, 0, 3);
|
|
| 417 | 417 |
switch(reg){
|
| 418 | 418 |
case 0: |
| 419 | 419 |
case 1: gain = 0; break; |
| ... | ... | |
| 456 | 456 |
* Bandwidth Handling |
| 457 | 457 |
**********************************************************************/ |
| 458 | 458 |
static max2829_regs_t::tx_lpf_coarse_adj_t bandwidth_to_tx_lpf_coarse_reg(double &bandwidth){
|
| 459 |
int reg = std::clip(boost::math::iround((bandwidth-6.0e6)/6.0e6), 1, 3);
|
|
| 459 |
int reg = uhd::clip(boost::math::iround((bandwidth-6.0e6)/6.0e6), 1, 3);
|
|
| 460 | 460 |
|
| 461 | 461 |
switch(reg){
|
| 462 | 462 |
case 1: // bandwidth < 15MHz |
| ... | ... | |
| 473 | 473 |
} |
| 474 | 474 |
|
| 475 | 475 |
static max2829_regs_t::rx_lpf_fine_adj_t bandwidth_to_rx_lpf_fine_reg(double &bandwidth, double requested_bandwidth){
|
| 476 |
int reg = std::clip(boost::math::iround((requested_bandwidth/bandwidth)/0.05), 18, 22);
|
|
| 476 |
int reg = uhd::clip(boost::math::iround((requested_bandwidth/bandwidth)/0.05), 18, 22);
|
|
| 477 | 477 |
|
| 478 | 478 |
switch(reg){
|
| 479 | 479 |
case 18: // requested_bandwidth < 92.5% |
| ... | ... | |
| 496 | 496 |
} |
| 497 | 497 |
|
| 498 | 498 |
static max2829_regs_t::rx_lpf_coarse_adj_t bandwidth_to_rx_lpf_coarse_reg(double &bandwidth){
|
| 499 |
int reg = std::clip(boost::math::iround((bandwidth-7.0e6)/1.0e6), 0, 11);
|
|
| 499 |
int reg = uhd::clip(boost::math::iround((bandwidth-7.0e6)/1.0e6), 0, 11);
|
|
| 500 | 500 |
|
| 501 | 501 |
switch(reg){
|
| 502 | 502 |
case 0: // bandwidth < 7.5MHz |
| b/host/lib/usrp/misc_utils.cpp | ||
|---|---|---|
| 196 | 196 |
wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; |
| 197 | 197 |
BOOST_FOREACH(const std::string &sd_name, dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>()){
|
| 198 | 198 |
try{
|
| 199 |
bool enable = std::has(subdev_spec, subdev_spec_pair_t(db_name, sd_name));
|
|
| 199 |
bool enable = uhd::has(subdev_spec, subdev_spec_pair_t(db_name, sd_name));
|
|
| 200 | 200 |
dboard[named_prop_t(DBOARD_PROP_SUBDEV, sd_name)][SUBDEV_PROP_ENABLED] = enable; |
| 201 | 201 |
} |
| 202 | 202 |
catch(const std::exception &e){
|
| b/host/lib/usrp/usrp1/codec_ctrl.cpp | ||
|---|---|---|
| 162 | 162 |
|
| 163 | 163 |
void usrp1_codec_ctrl_impl::set_tx_pga_gain(double gain){
|
| 164 | 164 |
int gain_word = int(mtpgw*(gain - tx_pga_gain_range.start())/(tx_pga_gain_range.stop() - tx_pga_gain_range.start())); |
| 165 |
_ad9862_regs.tx_pga_gain = std::clip(gain_word, 0, mtpgw);
|
|
| 165 |
_ad9862_regs.tx_pga_gain = uhd::clip(gain_word, 0, mtpgw);
|
|
| 166 | 166 |
this->send_reg(16); |
| 167 | 167 |
} |
| 168 | 168 |
|
| ... | ... | |
| 174 | 174 |
|
| 175 | 175 |
void usrp1_codec_ctrl_impl::set_rx_pga_gain(double gain, char which){
|
| 176 | 176 |
int gain_word = int(mrpgw*(gain - rx_pga_gain_range.start())/(rx_pga_gain_range.stop() - rx_pga_gain_range.start())); |
| 177 |
gain_word = std::clip(gain_word, 0, mrpgw);
|
|
| 177 |
gain_word = uhd::clip(gain_word, 0, mrpgw);
|
|
| 178 | 178 |
switch(which){
|
| 179 | 179 |
case 'A': |
| 180 | 180 |
_ad9862_regs.rx_pga_a = gain_word; |
| ... | ... | |
| 264 | 264 |
{
|
| 265 | 265 |
//special case for aux dac d (aka sigma delta word) |
| 266 | 266 |
if (which == AUX_DAC_D) {
|
| 267 |
boost::uint16_t dac_word = std::clip(boost::math::iround(volts*0xfff/3.3), 0, 0xfff);
|
|
| 267 |
boost::uint16_t dac_word = uhd::clip(boost::math::iround(volts*0xfff/3.3), 0, 0xfff);
|
|
| 268 | 268 |
_ad9862_regs.sig_delt_11_4 = boost::uint8_t(dac_word >> 4); |
| 269 | 269 |
_ad9862_regs.sig_delt_3_0 = boost::uint8_t(dac_word & 0xf); |
| 270 | 270 |
this->send_reg(42); |
| ... | ... | |
| 273 | 273 |
} |
| 274 | 274 |
|
| 275 | 275 |
//calculate the dac word for aux dac a, b, c |
| 276 |
boost::uint8_t dac_word = std::clip(boost::math::iround(volts*0xff/3.3), 0, 0xff);
|
|
| 276 |
boost::uint8_t dac_word = uhd::clip(boost::math::iround(volts*0xff/3.3), 0, 0xff);
|
|
| 277 | 277 |
|
| 278 | 278 |
//setup a lookup table for the aux dac params (reg ref, reg addr) |
| 279 | 279 |
typedef boost::tuple<boost::uint8_t*, boost::uint8_t> dac_params_t; |
| b/host/lib/usrp/usrp_e100/codec_ctrl.cpp | ||
|---|---|---|
| 137 | 137 |
|
| 138 | 138 |
void usrp_e100_codec_ctrl_impl::set_tx_pga_gain(double gain){
|
| 139 | 139 |
int gain_word = int(mtpgw*(gain - tx_pga_gain_range.start())/(tx_pga_gain_range.stop() - tx_pga_gain_range.start())); |
| 140 |
_ad9862_regs.tx_pga_gain = std::clip(gain_word, 0, mtpgw);
|
|
| 140 |
_ad9862_regs.tx_pga_gain = uhd::clip(gain_word, 0, mtpgw);
|
|
| 141 | 141 |
this->send_reg(16); |
| 142 | 142 |
} |
| 143 | 143 |
|
| ... | ... | |
| 149 | 149 |
|
| 150 | 150 |
void usrp_e100_codec_ctrl_impl::set_rx_pga_gain(double gain, char which){
|
| 151 | 151 |
int gain_word = int(mrpgw*(gain - rx_pga_gain_range.start())/(rx_pga_gain_range.stop() - rx_pga_gain_range.start())); |
| 152 |
gain_word = std::clip(gain_word, 0, mrpgw);
|
|
| 152 |
gain_word = uhd::clip(gain_word, 0, mrpgw);
|
|
| 153 | 153 |
switch(which){
|
| 154 | 154 |
case 'A': |
| 155 | 155 |
_ad9862_regs.rx_pga_a = gain_word; |
| ... | ... | |
| 236 | 236 |
void usrp_e100_codec_ctrl_impl::write_aux_dac(aux_dac_t which, double volts){
|
| 237 | 237 |
//special case for aux dac d (aka sigma delta word) |
| 238 | 238 |
if (which == AUX_DAC_D){
|
| 239 |
boost::uint16_t dac_word = std::clip(boost::math::iround(volts*0xfff/3.3), 0, 0xfff);
|
|
| 239 |
boost::uint16_t dac_word = uhd::clip(boost::math::iround(volts*0xfff/3.3), 0, 0xfff);
|
|
| 240 | 240 |
_ad9862_regs.sig_delt_11_4 = boost::uint8_t(dac_word >> 4); |
| 241 | 241 |
_ad9862_regs.sig_delt_3_0 = boost::uint8_t(dac_word & 0xf); |
| 242 | 242 |
this->send_reg(42); |
| ... | ... | |
| 245 | 245 |
} |
| 246 | 246 |
|
| 247 | 247 |
//calculate the dac word for aux dac a, b, c |
| 248 |
boost::uint8_t dac_word = std::clip(boost::math::iround(volts*0xff/3.3), 0, 0xff);
|
|
| 248 |
boost::uint8_t dac_word = uhd::clip(boost::math::iround(volts*0xff/3.3), 0, 0xff);
|
|
| 249 | 249 |
|
| 250 | 250 |
//setup a lookup table for the aux dac params (reg ref, reg addr) |
| 251 | 251 |
typedef boost::tuple<boost::uint8_t*, boost::uint8_t> dac_params_t; |
| b/host/lib/utils/gain_group.cpp | ||
|---|---|---|
| 107 | 107 |
double gain_left_to_distribute = gain; |
| 108 | 108 |
BOOST_FOREACH(const gain_fcns_t &fcns, all_fcns){
|
| 109 | 109 |
const gain_range_t range = fcns.get_range(); |
| 110 |
gain_bucket.push_back(floor_step(std::clip(
|
|
| 110 |
gain_bucket.push_back(floor_step(uhd::clip(
|
|
| 111 | 111 |
gain_left_to_distribute, range.start(), range.stop() |
| 112 | 112 |
), max_step)); |
| 113 | 113 |
gain_left_to_distribute -= gain_bucket.back(); |
| ... | ... | |
| 131 | 131 |
//fill in the largest step sizes first that are less than the remainder |
| 132 | 132 |
BOOST_FOREACH(size_t i, indexes_step_size_dec){
|
| 133 | 133 |
const gain_range_t range = all_fcns.at(i).get_range(); |
| 134 |
double additional_gain = floor_step(std::clip(
|
|
| 134 |
double additional_gain = floor_step(uhd::clip(
|
|
| 135 | 135 |
gain_bucket.at(i) + gain_left_to_distribute, range.start(), range.stop() |
| 136 | 136 |
), range.step()) - gain_bucket.at(i); |
| 137 | 137 |
gain_bucket.at(i) += additional_gain; |
| ... | ... | |
| 167 | 167 |
//! get the gain function sets in order (highest priority first) |
| 168 | 168 |
std::vector<gain_fcns_t> get_all_fcns(void){
|
| 169 | 169 |
std::vector<gain_fcns_t> all_fcns; |
| 170 |
BOOST_FOREACH(size_t key, std::sorted(_registry.keys())){
|
|
| 170 |
BOOST_FOREACH(size_t key, uhd::sorted(_registry.keys())){
|
|
| 171 | 171 |
const std::vector<gain_fcns_t> &fcns = _registry[key]; |
| 172 | 172 |
all_fcns.insert(all_fcns.begin(), fcns.begin(), fcns.end()); |
| 173 | 173 |
} |
| b/host/tests/error_test.cpp | ||
|---|---|---|
| 37 | 37 |
vec.push_back(3); |
| 38 | 38 |
vec.push_back(5); |
| 39 | 39 |
|
| 40 |
//verify the std::has utility
|
|
| 41 |
BOOST_CHECK(std::has(vec, 2));
|
|
| 42 |
BOOST_CHECK(not std::has(vec, 1));
|
|
| 40 |
//verify the uhd::has utility
|
|
| 41 |
BOOST_CHECK(uhd::has(vec, 2));
|
|
| 42 |
BOOST_CHECK(not uhd::has(vec, 1));
|
|
| 43 | 43 |
|
| 44 | 44 |
std::cout << "The output of the assert_has error:" << std::endl; |
| 45 | 45 |
try{
|
Also available in: Unified diff