diff options
Diffstat (limited to 'host/lib')
26 files changed, 992 insertions, 531 deletions
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index a0b2d67fc..3e5ec9c95 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -57,8 +57,9 @@ SET(libuhd_sources transport/udp_simple.cpp usrp/dboard_base.cpp usrp/dboard_eeprom.cpp - usrp/simple_usrp.cpp + usrp/dboard_id.cpp usrp/dboard_manager.cpp + usrp/simple_usrp.cpp usrp/tune_helper.cpp ) @@ -123,6 +124,16 @@ UHD_PYTHON_GEN_SOURCE_FILE( ${CMAKE_CURRENT_BINARY_DIR}/ic_reg_maps/max2829_regs.hpp ) +UHD_PYTHON_GEN_SOURCE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/ic_reg_maps/gen_ad9862_regs.py + ${CMAKE_CURRENT_BINARY_DIR}/ic_reg_maps/ad9862_regs.hpp +) + +UHD_PYTHON_GEN_SOURCE_FILE( + ${CMAKE_CURRENT_SOURCE_DIR}/ic_reg_maps/gen_ad9522_regs.py + ${CMAKE_CURRENT_BINARY_DIR}/ic_reg_maps/ad9522_regs.hpp +) + ######################################################################## # Add dboard sources ######################################################################## diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 706f64951..f139ecb20 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -97,11 +97,6 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ BOOST_FOREACH(device_addr_t dev_addr, fcn.get<0>()(hint)){ - //copy keys that were in hint but not in dev_addr - //this way, we can pass additional transport arguments - BOOST_FOREACH(const std::string &key, hint.keys()){ - if (not dev_addr.has_key(key)) dev_addr[key] = hint[key]; - } //append the discovered address and its factory function dev_addr_makers.push_back(dev_addr_make_t(dev_addr, fcn.get<1>())); } @@ -110,14 +105,14 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ //check that we found any devices if (dev_addr_makers.size() == 0){ throw std::runtime_error(str( - boost::format("No devices found for ----->\n%s") % hint.to_string() + boost::format("No devices found for ----->\n%s") % hint.to_pp_string() )); } //check that the which index is valid if (dev_addr_makers.size() <= which){ throw std::runtime_error(str( - boost::format("No device at index %d for ----->\n%s") % which % hint.to_string() + boost::format("No device at index %d for ----->\n%s") % which % hint.to_pp_string() )); } @@ -127,6 +122,12 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ size_t dev_hash = hash_device_addr(dev_addr); //std::cout << boost::format("Hash: %u") % dev_hash << std::endl; + //copy keys that were in hint but not in dev_addr + //this way, we can pass additional transport arguments + BOOST_FOREACH(const std::string &key, hint.keys()){ + if (not dev_addr.has_key(key)) dev_addr[key] = hint[key]; + } + //map device address hash to created devices static uhd::dict<size_t, boost::weak_ptr<device> > hash_to_device; diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py index d05470706..4aa1ef35e 100644 --- a/host/lib/ic_reg_maps/common.py +++ b/host/lib/ic_reg_maps/common.py @@ -16,23 +16,69 @@ # import re +import sys import math from Cheetah.Template import Template +COMMON_TMPL = """\ +#import time +/*********************************************************************** + * This file was generated by $file on $time.strftime("%c") + **********************************************************************/ + +\#ifndef INCLUDED_$(name.upper())_HPP +\#define INCLUDED_$(name.upper())_HPP + +\#include <boost/cstdint.hpp> + +struct $(name)_t{ + + #for $reg in $regs + #if $reg.get_enums() + enum $reg.get_type(){ + #for $i, $enum in enumerate($reg.get_enums()) + #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' + $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma + #end for + }; + #end if + $reg.get_type() $reg.get_name(); + #end for + + $(name)_t(void){ + #for $reg in $regs + $reg.get_name() = $reg.get_default(); + #end for + } + +$body + +}; + +\#endif /* INCLUDED_$(name.upper())_HPP */ +""" + def parse_tmpl(_tmpl_text, **kwargs): return str(Template(_tmpl_text, kwargs)) +def to_num(arg): return eval(arg) + class reg: def __init__(self, reg_des): + try: self.parse(reg_des) + except Exception, e: + raise Exception, 'Error parsing register description: "%s"\nWhat: %s'%(reg_des, e) + + def parse(self, reg_des): x = re.match('^(\w*)\s*(\w*)\[(.*)\]\s*(\w*)\s*(.*)$', reg_des) name, addr, bit_range, default, enums = x.groups() #store variables self._name = name - self._addr = int(addr, 16) + self._addr = to_num(addr) if ':' in bit_range: self._addr_spec = sorted(map(int, bit_range.split(':'))) else: self._addr_spec = int(bit_range), int(bit_range) - self._default = int(default, 16) + self._default = to_num(default) #extract enum self._enums = list() @@ -41,7 +87,7 @@ class reg: for enum_str in map(str.strip, enums.split(',')): if '=' in enum_str: enum_name, enum_val = enum_str.split('=') - enum_val = int(enum_val) + enum_val = to_num(enum_val) else: enum_name = enum_str self._enums.append((enum_name, enum_val)) enum_val += 1 @@ -53,8 +99,20 @@ class reg: for key, val in self.get_enums(): if val == self._default: return str.upper('%s_%s'%(self.get_name(), key)) return self._default - def get_stdint_type(self):\ - return 'uint%d_t'%max(2**math.ceil(math.log(self.get_bit_width(), 2)), 8) + def get_type(self): + if self.get_enums(): return '%s_t'%self.get_name() + return 'boost::uint%d_t'%max(2**math.ceil(math.log(self.get_bit_width(), 2)), 8) def get_shift(self): return self._addr_spec[0] def get_mask(self): return hex(int('1'*self.get_bit_width(), 2)) def get_bit_width(self): return self._addr_spec[1] - self._addr_spec[0] + 1 + +def generate(name, regs_tmpl, body_tmpl='', file=__file__): + regs = map(reg, parse_tmpl(regs_tmpl).splitlines()) + body = parse_tmpl(body_tmpl, regs=regs).replace('\n', '\n ').strip() + code = parse_tmpl(COMMON_TMPL, + name=name, + regs=regs, + body=body, + file=file, + ) + open(sys.argv[1], 'w').write(code) diff --git a/host/lib/ic_reg_maps/gen_ad5624_regs.py b/host/lib/ic_reg_maps/gen_ad5624_regs.py index 9e8ae5be5..24401b878 100755 --- a/host/lib/ic_reg_maps/gen_ad5624_regs.py +++ b/host/lib/ic_reg_maps/gen_ad5624_regs.py @@ -16,67 +16,33 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ data 0[4:15] 0 addr 0[16:18] 0 DAC_A=0, DAC_B=1, DAC_C=2, DAC_D=3, ALL=7 cmd 0[19:21] 0 wr_input_n, up_dac_n, wr_input_n_up_all, wr_up_dac_chan_n, power_down, reset, load_ldac """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_AD5624_REGS_HPP -\#define INCLUDED_AD5624_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct ad5624_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma - #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - ad5624_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - boost::uint32_t get_reg(void){ - boost::uint32_t reg = 0; - #for $reg in filter(lambda r: r.get_addr() == 0, $regs) - reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - return reg; - } - -}; - -\#endif /* INCLUDED_AD5624_REGS_HPP */ +BODY_TMPL="""\ +boost::uint32_t get_reg(void){ + boost::uint32_t reg = 0; + #for $reg in filter(lambda r: r.get_addr() == 0, $regs) + reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); + #end for + return reg; +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='ad5624_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_ad7922_regs.py b/host/lib/ic_reg_maps/gen_ad7922_regs.py index 23f28c0da..5cec1924a 100755 --- a/host/lib/ic_reg_maps/gen_ad7922_regs.py +++ b/host/lib/ic_reg_maps/gen_ad7922_regs.py @@ -16,73 +16,39 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ result 0[0:11] 0 mod 0[12] 0 chn 0[13] 0 """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_AD7922_REGS_HPP -\#define INCLUDED_AD7922_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct ad7922_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma - #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - ad7922_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - boost::uint16_t get_reg(void){ - boost::uint16_t reg = 0; - #for $reg in filter(lambda r: r.get_addr() == 0, $regs) - reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - return reg; - } - - void set_reg(boost::uint16_t reg){ - #for $reg in filter(lambda r: r.get_addr() == 0, $regs) - $reg.get_name() = (reg >> $reg.get_shift()) & $reg.get_mask(); - #end for - } - -}; - -\#endif /* INCLUDED_AD7922_REGS_HPP */ +BODY_TMPL="""\ +boost::uint16_t get_reg(void){ + boost::uint16_t reg = 0; + #for $reg in filter(lambda r: r.get_addr() == 0, $regs) + reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); + #end for + return reg; +} + +void set_reg(boost::uint16_t reg){ + #for $reg in filter(lambda r: r.get_addr() == 0, $regs) + $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); + #end for +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='ad7922_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_ad9510_regs.py b/host/lib/ic_reg_maps/gen_ad9510_regs.py index 2dc19c691..83236c921 100755 --- a/host/lib/ic_reg_maps/gen_ad9510_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9510_regs.py @@ -16,14 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ ######################################################################## ## serial control port config ######################################################################## @@ -46,14 +43,14 @@ reset_all_counters 9[0] 0 ncounter_reset 9[1] 0 rcounter_reset 9[2] 0 cp_current_setting 9[4:6] 0 0_60ma, 1_2ma, 1_8ma, 2_4ma, 3_0ma, 3_6ma, 4_2ma, 4_8ma -pll_power_down A[0:1] 0 normal=0, async_pd=1, sync_pd=3 -prescaler_value A[2:4] 0 div1, div2, 2_3, 4_5, 8_9, 16_17, 32_33, div3 -b_counter_bypass A[6] 0 -ref_counter_msb B[0:5] 0 -ref_counter_lsb C[0:7] 0 -antibacklash_pw D[0:1] 0 1_3ns, 2_9ns, 6_0ns -dld_window D[5] 0 9_5ns, 3_5ns -lock_detect_disable D[6] 0 enb, dis +pll_power_down 0xA[0:1] 0 normal=0, async_pd=1, sync_pd=3 +prescaler_value 0xA[2:4] 0 div1, div2, 2_3, 4_5, 8_9, 16_17, 32_33, div3 +b_counter_bypass 0xA[6] 0 +ref_counter_msb 0xB[0:5] 0 +ref_counter_lsb 0xC[0:7] 0 +antibacklash_pw 0xD[0:1] 0 1_3ns, 2_9ns, 6_0ns +dld_window 0xD[5] 0 9_5ns, 3_5ns +lock_detect_disable 0xD[6] 0 enb, dis ######################################################################## ## fine delay adjust ######################################################################## @@ -103,71 +100,40 @@ soft_sync 58[2] 0 dist_power_down 58[3] 0 sync_power_down 58[4] 0 function_pin_select 58[5:6] 0 resetb, syncb, test, pdb -update_registers 5A[0] 0 +update_registers 0x5A[0] 0 """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_AD9510_REGS_HPP -\#define INCLUDED_AD9510_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct ad9510_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma +BODY_TMPL="""\ +boost::uint8_t get_reg(boost::uint16_t addr){ + boost::uint8_t reg = 0; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - ad9510_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - boost::uint8_t get_reg(boost::uint16_t addr){ - boost::uint8_t reg = 0; - switch(addr){ - #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) - case $addr: - #for $reg in filter(lambda r: r.get_addr() == addr, $regs) - reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; - #end for - } - return reg; - } - - boost::uint32_t get_write_reg(boost::uint16_t addr){ - return (boost::uint32_t(addr) << 8) | get_reg(addr); - } - - boost::uint32_t get_read_reg(boost::uint16_t addr){ - return (boost::uint32_t(addr) << 8) | (1 << 15); + break; + #end for } + return reg; +} -}; +boost::uint32_t get_write_reg(boost::uint16_t addr){ + return (boost::uint32_t(addr) << 8) | get_reg(addr); +} -\#endif /* INCLUDED_AD9510_REGS_HPP */ +boost::uint32_t get_read_reg(boost::uint16_t addr){ + return (boost::uint32_t(addr) << 8) | (1 << 23); +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='ad9510_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_ad9522_regs.py b/host/lib/ic_reg_maps/gen_ad9522_regs.py new file mode 100755 index 000000000..9da51205b --- /dev/null +++ b/host/lib/ic_reg_maps/gen_ad9522_regs.py @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# 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/>. +# + +######################################################################## +# Template for raw text data describing registers +# name addr[bit range inclusive] default optional enums +######################################################################## +REGS_TMPL="""\ +sdo_active 0x000[7] 0 sdio, sdo_sdio +lsb_first_addr_incr 0x000[6] 0 msb, lsb +soft_reset 0x000[5] 0 +mirror 0x000[3:0] 0 +readback_active_registers 0x004[0] 0 buffer, active +pfd_polarity 0x010[7] 0 pos, neg +cp_current 0x010[6:4] 7 0_6ma, 1_2ma, 1_8ma, 2_4ma, 3_0ma, 3_6ma, 4_2ma, 4_8ma +cp_mode 0x010[3:2] 3 high_imp, force_source, force_sink, normal +pll_power_down 0x010[1:0] 1 normal=0, async=1, sync=3 +r_counter_lsb 0x011[7:0] 1 +r_counter_msb 0x012[5:0] 0 +a_counter 0x013[5:0] 0 +b_counter_lsb 0x014[7:0] 3 +b_counter_msb 0x015[4:0] 0 +set_cp_pin_to_vcp_2 0x016[7] 0 normal, vcp_2 +reset_r_counter 0x016[6] 0 +reset_a_and_b_counters 0x016[5] 0 +reset_all_counters 0x016[4] 0 +b_counter_bypass 0x016[3] 0 normal, div1 +prescaler_p 0x016[2:0] 6 div1, div2, div2_3, div4_5, div8_9, div16_17, div32_33, div3 +status_pin_control 0x017[7:2] 0 +antibacklash_pulse_width 0x017[1:0] 0 2_9ns, 1_3ns, 6_0ns +enb_cmos_ref_input_dc_off 0x018[7] 0 +lock_detect_counter 0x018[6:5] 0 5cyc, 16cyc, 64cyc, 255cyc +digital_lock_detect_window 0x018[4] 0 high_range, low_range +disable_digital_lock_detect 0x018[3] 0 normal, disabled +vco_calibration_divider 0x018[2:1] 3 div2, div4, div8, div16 +vco_calibration_now 0x018[0] 0 +r_a_b_counters_sync_pin_rst 0x019[7:6] 0 nothing, async, sync +r_path_delay 0x019[5:3] 0 +n_path_delay 0x019[2:0] 0 +enable_status_pin_divider 0x01A[7] 0 +ref_freq_monitor_threshold 0x01A[6] 0 1_02mhz, 6khz +ld_pin_control 0x01A[5:0] 0 +enable_vco_freq_monitor 0x01B[7] 0 +enable_ref2_freq_monitor 0x01B[6] 0 +enable_ref1_freq_monitor 0x01B[5] 0 +refmon_pin_control 0x01B[4:0] 0 +disable_switchover_deglitch 0x01C[7] 0 +select_ref 0x01C[6] 0 ref1, ref2 +use_ref_sel_pin 0x01C[5] 0 register, ref_sel +enb_auto_ref_switchover 0x01C[4] 0 manual, auto +stay_on_ref2 0x01C[3] 0 return_ref1, stay_ref2 +enable_ref2 0x01C[2] 0 +enable_ref1 0x01C[1] 0 +enable_differential_ref 0x01C[0] 0 +enb_stat_eeprom_at_stat_pin 0x01D[7] 1 +enable_xtal_osc 0x01D[6] 0 +enable_clock_doubler 0x01D[5] 0 +disable_pll_status_reg 0x01D[4] 0 +enable_ld_pin_comparator 0x01D[3] 0 +enable_external_holdover 0x01D[1] 0 +enable_holdover 0x01D[0] 0 +external_zero_delay_fcds 0x01E[4:3] 0 +enable_external_zero_delay 0x01E[2] 0 +enable_zero_delay 0x01E[1] 0 +######################################################################## +#for $i in range(12) +#set $addr = ($i + 0x0F0) +out$(i)_format $(addr)[7] 0 lvds, cmos +out$(i)_cmos_configuration $(addr)[6:5] 3 off, a_on, b_on, ab_on +out$(i)_polarity $(addr)[4:3] 0 lvds_a_non_b_inv=0, lvds_a_inv_b_non=1, cmos_ab_non=0, cmos_ab_inv=1, cmos_a_non_b_inv=2, cmos_a_inv_b_non=3 +out$(i)_lvds_diff_voltage $(addr)[2:1] 1 1_75ma, 3_5ma, 5_25ma, 7_0ma +out$(i)_lvds_power_down $(addr)[0] 0 +#end for +######################################################################## +#for $i in reversed(range(8)) +csdld_en_out_$i 0x0FC[$i] 0 ignore, async +#end for +######################################################################## +#for $i in reversed(range(4)) +csdld_en_out_$(8 + $i) 0x0FD[$i] 0 ignore, async +#end for +######################################################################## +#set $default_val = 0x7 +#for $i in range(4) +#set $addr0 = hex($i*3 + 0x190) +#set $addr1 = hex($i*3 + 0x191) +#set $addr2 = hex($i*3 + 0x192) +divider$(i)_low_cycles $(addr0)[7:4] $default_val +divider$(i)_high_cycles $(addr0)[3:0] $default_val +divider$(i)_bypass $(addr1)[7] 0 +divider$(i)_ignore_sync $(addr1)[6] 0 +divider$(i)_force_high $(addr1)[5] 0 +divider$(i)_start_high $(addr1)[4] 0 +divider$(i)_phase_offset $(addr1)[3:0] 0 +channel$(i)_power_down $(addr2)[2] 0 +disable_divider$(i)_ddc $(addr2)[0] 0 +#set $default_val /= 2 +#end for +######################################################################## +vco_divider 0x1E0[2:0] 2 div2, div3, div4, div5, div6, static, div1 +power_down_clock_input_sel 0x1E1[4] 0 +power_down_vco_clock_ifc 0x1E1[3] 0 +power_down_vco_and_clock 0x1E1[2] 0 +select_vco_or_clock 0x1E1[1] 0 external, vco +bypass_vco_divider 0x1E1[0] 0 +disable_power_on_sync 0x230[3] 0 +power_down_sync 0x230[2] 0 +power_down_dist_ref 0x230[1] 0 +soft_sync 0x230[0] 0 +io_update 0x232[0] 0 +soft_eeprom 0xB02[1] 0 +enable_eeprom_write 0xB02[0] 0 +reg2eeprom 0xB03[0] 0 +""" + +######################################################################## +# Template for methods in the body of the struct +######################################################################## +BODY_TMPL="""\ +boost::uint8_t get_reg(boost::uint16_t addr){ + boost::uint8_t reg = 0; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint8_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); + #end for + break; + #end for + } + if (addr == 0){ //mirror 4 bits in register 0 + reg |= ((reg >> 7) & 0x1) << 0; + reg |= ((reg >> 6) & 0x1) << 1; + reg |= ((reg >> 5) & 0x1) << 2; + reg |= ((reg >> 4) & 0x1) << 3; + } + return reg; +} + +void set_reg(boost::uint8_t addr, boost::uint32_t reg){ + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); + #end for + break; + #end for + } +} + +boost::uint32_t get_write_reg(boost::uint16_t addr){ + return (boost::uint32_t(addr) << 8) | get_reg(addr); +} + +boost::uint32_t get_read_reg(boost::uint16_t addr){ + return (boost::uint32_t(addr) << 8) | (1 << 23); +} + +""" + +if __name__ == '__main__': + import common; common.generate( + name='ad9522_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_ad9777_regs.py b/host/lib/ic_reg_maps/gen_ad9777_regs.py index 2ac73efcf..abb839f0f 100755 --- a/host/lib/ic_reg_maps/gen_ad9777_regs.py +++ b/host/lib/ic_reg_maps/gen_ad9777_regs.py @@ -16,14 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ ######################################################################## ## address 0 ######################################################################## @@ -73,79 +70,49 @@ qdac_fine_gain_adjust 9[0:7] 0 ## address 6 and A ######################################################################## idac_coarse_gain_adjust 6[0:3] 0 -qdac_coarse_gain_adjust A[0:3] 0 +qdac_coarse_gain_adjust 0xA[0:3] 0 ######################################################################## ## address 7, 8 and B, C ######################################################################## idac_offset_adjust_msb 7[0:7] 0 idac_offset_adjust_lsb 8[0:1] 0 idac_ioffset_direction 8[7] 0 out_a, out_b -qdac_offset_adjust_msb B[0:7] 0 -qdac_offset_adjust_lsb C[0:1] 0 -qdac_ioffset_direction C[7] 0 out_a, out_b +qdac_offset_adjust_msb 0xB[0:7] 0 +qdac_offset_adjust_lsb 0xC[0:1] 0 +qdac_ioffset_direction 0xC[7] 0 out_a, out_b """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_AD9777_REGS_HPP -\#define INCLUDED_AD9777_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct ad9777_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma - #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - ad9777_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - boost::uint8_t get_reg(boost::uint8_t addr){ - boost::uint8_t reg = 0; - switch(addr){ - #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) - case $addr: - #for $reg in filter(lambda r: r.get_addr() == addr, $regs) - reg |= (boost::uint8_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; +BODY_TMPL="""\ +boost::uint8_t get_reg(boost::uint8_t addr){ + boost::uint8_t reg = 0; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint8_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } - return reg; + break; + #end for } + return reg; +} - boost::uint16_t get_write_reg(boost::uint8_t addr){ - return (boost::uint16_t(addr) << 8) | get_reg(addr); - } - - boost::uint16_t get_read_reg(boost::uint8_t addr){ - return (boost::uint16_t(addr) << 8) | (1 << 7); - } -}; +boost::uint16_t get_write_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | get_reg(addr); +} -\#endif /* INCLUDED_AD9777_REGS_HPP */ +boost::uint16_t get_read_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | (1 << 7); +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='ad9777_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_ad9862_regs.py b/host/lib/ic_reg_maps/gen_ad9862_regs.py new file mode 100755 index 000000000..fdbea5828 --- /dev/null +++ b/host/lib/ic_reg_maps/gen_ad9862_regs.py @@ -0,0 +1,246 @@ +#!/usr/bin/env python +# +# 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/>. +# + +######################################################################## +# Template for raw text data describing registers +# name addr[bit range inclusive] default optional enums +######################################################################## +REGS_TMPL="""\ +######################################################################## +## General +######################################################################## +sdio_bidir 0[7] 0 sdio_sdo, sdio +lsb_first 0[6] 0 msb, lsb +soft_reset 0[5] 0 +######################################################################## +## Rx Power Down +######################################################################## +pd_vref_diff 1[7] 0 +pd_vref 1[6] 0 +pd_rx_digital 1[5] 0 +pd_rx_channel_b 1[4] 0 +pd_rx_channel_a 1[3] 0 +pd_buffer_b 1[2] 0 +pd_buffer_a 1[1] 0 +pd_all_rx 1[0] 0 +######################################################################## +## Rx A and B +######################################################################## +#for $x, $i in (('a', 2), ('b', 3)) +byp_buffer_$x $(i)[7] 0 +rx_pga_$x $(i)[0:4] 0 +#end for +######################################################################## +## Rx Misc +######################################################################## +hs_duty_cycle 4[2] 0 +shared_ref 4[1] 0 +clk_duty 4[0] 0 +######################################################################## +## RX I/F (INTERFACE) +######################################################################## +three_state 5[4] 0 +rx_retime 5[3] 0 clkout1, clkout2 +rx_twos_comp 5[2] 0 +inv_rxsync 5[1] 0 +mux_out 5[0] 0 rx_mux_mode=1, dual_port_mode=0 +######################################################################## +## RX Digital +######################################################################## +two_channel 6[3] 1 rx_b_dis, both_enb +rx_keep_ve 6[2] 0 pass_pos, pass_neg +rx_hilbert 6[1] 0 dis, enb +decimate 6[0] 0 dis, enb +######################################################################## +## TX Power Down +######################################################################## +alt_timing_mode 8[5] 0 +txoff_enable 8[4] 0 +tx_digital_pd 8[3] 0 +tx_analog_pd 8[0:2] 0 none=0, txb=4, txa=2, both=7 +######################################################################## +## Tx Offset and Gain +######################################################################## +#for $x, $i, $j, $k in (('a', 10, 11, 14), ('b', 12, 13, 15)) +dac_$(x)_offset_1_0 $(i)[6:7] 0 +dac_$(x)_offset_dir $(i)[0] 0 neg_diff, pos_dif +dac_$(x)_offset_9_2 $(j)[0:7] 0 +dac_$(x)_coarse_gain $(k)[6:7] 0 +dac_$(x)_fine_gain $(k)[0:5] 0 +#end for +tx_pga_gain 16[0:7] 0 +######################################################################## +## Tx Misc +######################################################################## +tx_slave_enable 17[1] 0 +tx_pga_mode 17[0] 0 normal, fast +######################################################################## +## Tx IF (INTERFACE) +######################################################################## +tx_retime 18[6] 1 clkout1=1, clkout2=0 +qi_order 18[5] 0 iq, qi +inv_txsync 18[4] 0 +tx_twos_comp 18[3] 0 +inverse_samp 18[2] 0 rise, fall +edges 18[1] 0 normal, both +interleaved 18[0] 0 single, interleaved +######################################################################## +## TX Digital +######################################################################## +two_data_paths 19[4] 0 single, both +tx_keep_ve 19[3] 0 pass_pos, pass_neg +tx_hilbert 19[2] 0 dis, enb +interp 19[0:1] 0 1, 2, 4 +######################################################################## +## TX Modulator +######################################################################## +neg_fine_tune 20[5] 0 pos_shift, neg_shift +fine_mode 20[4] 0 bypass, nco +real_mix_mode 20[3] 0 complex, real +neg_coarse_tune 20[2] 0 pos_shift, neg_shift +coarse_mod 20[0:1] 0 bypass, fdac_4, fdac_8 +######################################################################## +## NCO Tuning Word +######################################################################## +ftw_7_0 21[0:7] 0 +ftw_15_8 22[0:7] 0 +ftw_23_16 23[0:7] 0 +######################################################################## +## DLL +######################################################################## +input_clk_ctrl 24[6] 0 external, internal +adc_div2 24[5] 0 normal, div2 +dll_mult 24[3:4] 0 1, 2, 4 +dll_pd 24[2] 0 +dll_mode 24[0] 0 slow, fast +######################################################################## +## Clock Out +######################################################################## +clkout2_div_factor 25[6:7] 0 1, 2, 4, 8 +inv2 25[5] 0 normal, inverted +inv1 25[1] 0 normal, inverted +dis2 25[4] 0 enb, dis +dis1 25[0] 0 enb, dis +######################################################################## +## Aux ADC +######################################################################## +#for $x, $i in (('a2', 26), ('a1', 28), ('b2', 30), ('b1', 32)) +aux_adc_$(x)_1_0 $(i)[6:7] 0 +aux_adc_$(x)_9_2 $int(1+$i)[0:7] 0 +#end for +######################################################################## +## Aux ADC Control +######################################################################## +aux_spi 34[7] 0 dis, enb +sel_bnota 34[6] 0 adc_a, adc_b +#for $x, $i in (('b', 5), ('a', 2)) +refsel_$(x) 34[$i] 0 external, internal +select_$(x) 34[$int($i-1)] 0 aux_adc2, aux_adc1 +start_$(x) 34[$int($i-2)] 0 +#end for +######################################################################## +## Aux ADC Clock +######################################################################## +clk_4 35[0] 0 1_2, 1_4 +######################################################################## +## Aux DAC +######################################################################## +#for $x, $i in (('a', 36), ('b', 37), ('c', 38)) +aux_dac_$x $(i)[0:7] 0 +#end for +######################################################################## +## Aux DAC Update +######################################################################## +aux_dac_slave_enable 39[7] 0 +aux_dacupdate_c 39[2] 0 +aux_dacupdate_b 39[1] 0 +aux_dacupdate_a 39[0] 0 +######################################################################## +## AUX DAC Power Down +######################################################################## +aux_dac_pd_a 40[2] 0 +aux_dac_pd_b 40[1] 0 +aux_dac_pd_c 40[0] 0 +######################################################################## +## AUX DAC Control +######################################################################## +aux_dac_invert_a 41[2] 0 +aux_dac_invert_b 41[1] 0 +aux_dac_invert_c 41[0] 0 +######################################################################## +## Sig Delt +######################################################################## +sig_delt_3_0 42[4:7] 0 +sig_delt_11_4 43[0:7] 0 +######################################################################## +## ADC Low Power +######################################################################## +rx_low_power_mode_r49 49[0:7] 0 +rx_low_power_mode_r50 50[0:7] 0 +######################################################################## +## Chip ID +######################################################################## +chip_id 63[0:7] 0 +""" + +######################################################################## +# Header and Source templates below +######################################################################## +BODY_TMPL=""" +boost::uint8_t get_reg(boost::uint8_t addr){ + boost::uint8_t reg = 0; + switch(addr){ + #for $addr in range(0, 63+1) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); + #end for + break; + #end for + } + return reg; +} + +void set_reg(boost::uint8_t addr, boost::uint16_t reg){ + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + $reg.get_name() = $(reg.get_type())((reg >> $reg.get_shift()) & $reg.get_mask()); + #end for + break; + #end for + } +} + +boost::uint16_t get_write_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | get_reg(addr); +} + +boost::uint16_t get_read_reg(boost::uint8_t addr){ + return (boost::uint16_t(addr) << 8) | (1 << 7); +} +""" + +if __name__ == '__main__': + import common; common.generate( + name='ad9862_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_adf4360_regs.py b/host/lib/ic_reg_maps/gen_adf4360_regs.py index 478e471a3..3fd8707a7 100755 --- a/host/lib/ic_reg_maps/gen_adf4360_regs.py +++ b/host/lib/ic_reg_maps/gen_adf4360_regs.py @@ -16,14 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ ######################################################################## ## address 0 ######################################################################## @@ -59,64 +56,34 @@ band_select_clock_div 1[20:21] 0 1, 2, 4, 8 """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_ADF4360_REGS_HPP -\#define INCLUDED_ADF4360_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct adf4360_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma - #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - adf4360_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for - } - - enum addr_t{ - ADDR_CONTROL = 0, - ADDR_NCOUNTER = 2, - ADDR_RCOUNTER = 1 - }; +BODY_TMPL="""\ +enum addr_t{ + ADDR_CONTROL = 0, + ADDR_NCOUNTER = 2, + ADDR_RCOUNTER = 1 +}; - boost::uint32_t get_reg(addr_t addr){ - boost::uint32_t reg = addr & 0x3; - switch(addr){ - #for $addr in (0, 1, 2) - case $addr: - #for $reg in filter(lambda r: r.get_addr() == addr, $regs) - reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; +boost::uint32_t get_reg(addr_t addr){ + boost::uint32_t reg = addr & 0x3; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint32_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } - return reg; + break; + #end for } -}; - -\#endif /* INCLUDED_ADF4360_REGS_HPP */ + return reg; +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='adf4360_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/ic_reg_maps/gen_max2829_regs.py b/host/lib/ic_reg_maps/gen_max2829_regs.py index 7fef302a8..383131c18 100755 --- a/host/lib/ic_reg_maps/gen_max2829_regs.py +++ b/host/lib/ic_reg_maps/gen_max2829_regs.py @@ -16,14 +16,11 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import sys -from common import * - ######################################################################## # Template for raw text data describing registers # name addr[bit range inclusive] default optional enums ######################################################################## -REGS_DATA_TMPL="""\ +REGS_TMPL="""\ ######################################################################## ## Note: offsets given from perspective of data bits (excludes address) ######################################################################## @@ -41,7 +38,7 @@ mimo_select 2[13] 0 normal, mimo ######################################################################## ## Integer Divider Ratio (3) ######################################################################## -int_div_ratio_word 3[0:7] a2 +int_div_ratio_word 3[0:7] 0xa2 frac_div_ratio_lsb 3[12:13] 0 ######################################################################## ## Fractional Divider Ratio (4) @@ -95,72 +92,42 @@ tx_vga_gain_spi 9[10] 0 io, spi ######################################################################## ## PA Bias DAC (10) ######################################################################## -pa_bias_dac_out_curr a[0:5] 0 -pa_bias_dac_delay a[6:9] f +pa_bias_dac_out_curr 10[0:5] 0 +pa_bias_dac_delay 10[6:9] 0xf ######################################################################## ## Rx Gain (11) ######################################################################## -rx_vga_gain b[0:4] 1f -rx_lna_gain b[5:6] 3 +rx_vga_gain 11[0:4] 0x1f +rx_lna_gain 11[5:6] 3 ######################################################################## ## Tx VGA Gain (12) ######################################################################## -tx_vga_gain c[0:5] 0 +tx_vga_gain 12[0:5] 0 """ ######################################################################## -# Header and Source templates below +# Template for methods in the body of the struct ######################################################################## -HEADER_TEXT=""" -#import time - -/*********************************************************************** - * This file was generated by $file on $time.strftime("%c") - **********************************************************************/ - -\#ifndef INCLUDED_MAX2829_REGS_HPP -\#define INCLUDED_MAX2829_REGS_HPP - -\#include <boost/cstdint.hpp> - -struct max2829_regs_t{ -#for $reg in $regs - #if $reg.get_enums() - enum $(reg.get_name())_t{ - #for $i, $enum in enumerate($reg.get_enums()) - #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' - $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma +BODY_TMPL="""\ +boost::uint32_t get_reg(boost::uint8_t addr){ + boost::uint16_t reg = 0; + switch(addr){ + #for $addr in sorted(set(map(lambda r: r.get_addr(), $regs))) + case $addr: + #for $reg in filter(lambda r: r.get_addr() == addr, $regs) + reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); #end for - } $reg.get_name(); - #else - boost::$reg.get_stdint_type() $reg.get_name(); - #end if -#end for - - max2829_regs_t(void){ -#for $reg in $regs - $reg.get_name() = $reg.get_default(); -#end for + break; + #end for } - - boost::uint32_t get_reg(boost::uint8_t addr){ - boost::uint16_t reg = 0; - switch(addr){ - #for $addr in range(2, 12+1) - case $addr: - #for $reg in filter(lambda r: r.get_addr() == addr, $regs) - reg |= (boost::uint16_t($reg.get_name()) & $reg.get_mask()) << $reg.get_shift(); - #end for - break; - #end for - } - return (boost::uint32_t(reg) << 4) | (addr & 0xf); - } -}; - -\#endif /* INCLUDED_MAX2829_REGS_HPP */ + return (boost::uint32_t(reg) << 4) | (addr & 0xf); +} """ if __name__ == '__main__': - regs = map(reg, parse_tmpl(REGS_DATA_TMPL).splitlines()) - open(sys.argv[1], 'w').write(parse_tmpl(HEADER_TEXT, regs=regs, file=__file__)) + import common; common.generate( + name='max2829_regs', + regs_tmpl=REGS_TMPL, + body_tmpl=BODY_TMPL, + file=__file__, + ) diff --git a/host/lib/load_modules.cpp b/host/lib/load_modules.cpp index ef633325d..d6bfe1369 100644 --- a/host/lib/load_modules.cpp +++ b/host/lib/load_modules.cpp @@ -20,10 +20,11 @@ #include <boost/foreach.hpp> #include <boost/algorithm/string.hpp> #include <boost/filesystem.hpp> +#include <boost/program_options.hpp> #include <iostream> #include <stdexcept> -#include <cstdlib> +namespace po = boost::program_options; namespace fs = boost::filesystem; /*********************************************************************** @@ -100,14 +101,39 @@ static void load_path(const fs::path &path){ } } +//! The string constant for the module path environment variable +static const std::string MODULE_PATH_KEY = "UHD_MODULE_PATH"; + +/*! + * Name mapper function for the environment variable parser. + * Map environment variable names (that we use) to option names. + * \param the variable name + * \return the option name or blank string + */ +static std::string name_mapper(const std::string &var_name){ + if (var_name == MODULE_PATH_KEY) return var_name; + return ""; +} + /*! * Load all the modules given by the module path enviroment variable. * The path variable may be several paths split by path separators. */ UHD_STATIC_BLOCK(load_modules){ - //get the environment variable module path - char *env_module_path = std::getenv("UHD_MODULE_PATH"); - if (env_module_path == NULL) return; + //register the options + std::string env_module_path; + po::options_description desc("UHD Module Options"); + desc.add_options() + (MODULE_PATH_KEY.c_str(), po::value<std::string>(&env_module_path)->default_value("")) + ; + + //parse environment variables + po::variables_map vm; + po::store(po::parse_environment(desc, &name_mapper), vm); + po::notify(vm); + + if (env_module_path == "") return; + //std::cout << "env_module_path: " << env_module_path << std::endl; //split the path at the path separators std::vector<std::string> module_paths; diff --git a/host/lib/transport/gen_vrt.py b/host/lib/transport/gen_vrt.py index 38a394dee..9a57c83c3 100755 --- a/host/lib/transport/gen_vrt.py +++ b/host/lib/transport/gen_vrt.py @@ -200,15 +200,11 @@ void vrt::unpack( } """ -import os import sys from Cheetah.Template import Template def parse_tmpl(_tmpl_text, **kwargs): return str(Template(_tmpl_text, kwargs)) -def safe_makedirs(path): - not os.path.isdir(path) and os.makedirs(path) if __name__ == '__main__': - safe_makedirs(os.path.dirname(sys.argv[1])) open(sys.argv[1], 'w').write(parse_tmpl(TMPL_TEXT, file=__file__)) diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 7e643abad..ee44803f4 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -104,12 +104,23 @@ public: managed_recv_buffer::sptr get_recv_buff(void); managed_send_buffer::sptr get_send_buff(void); + //resize + size_t resize_recv_buff(size_t num_bytes){ + boost::asio::socket_base::receive_buffer_size option(num_bytes); + _socket->set_option(option); + _socket->get_option(option); + return option.value(); + } + size_t resize_send_buff(size_t num_bytes){ + boost::asio::socket_base::send_buffer_size option(num_bytes); + _socket->set_option(option); + _socket->get_option(option); + return option.value(); + } + private: boost::asio::ip::udp::socket *_socket; boost::asio::io_service _io_service; - - size_t get_recv_buff_size(void); - void set_recv_buff_size(size_t); }; udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::string &port){ @@ -124,18 +135,6 @@ udp_zero_copy_impl::udp_zero_copy_impl(const std::string &addr, const std::strin _socket = new boost::asio::ip::udp::socket(_io_service); _socket->open(boost::asio::ip::udp::v4()); _socket->connect(receiver_endpoint); - - // set the rx socket buffer size: - // pick a huge size, and deal with whatever we get - set_recv_buff_size(size_t(54321e3)); //some big number! - size_t current_buff_size = get_recv_buff_size(); - std::cout << boost::format( - "Current rx socket buffer size: %d\n" - ) % current_buff_size; - if (current_buff_size < size_t(.1e6)) std::cout << boost::format( - "Adjust max rx socket buffer size (linux only):\n" - " sysctl -w net.core.rmem_max=VALUE\n" - ); } udp_zero_copy_impl::~udp_zero_copy_impl(void){ @@ -170,22 +169,34 @@ managed_send_buffer::sptr udp_zero_copy_impl::get_send_buff(void){ ); } -size_t udp_zero_copy_impl::get_recv_buff_size(void){ - boost::asio::socket_base::receive_buffer_size option; - _socket->get_option(option); - return option.value(); -} - -void udp_zero_copy_impl::set_recv_buff_size(size_t new_size){ - boost::asio::socket_base::receive_buffer_size option(new_size); - _socket->set_option(option); -} - /*********************************************************************** * UDP zero copy make function **********************************************************************/ udp_zero_copy::sptr udp_zero_copy::make( - const std::string &addr, const std::string &port + const std::string &addr, + const std::string &port, + size_t recv_buff_size, + size_t send_buff_size ){ - return sptr(new udp_zero_copy_impl(addr, port)); + boost::shared_ptr<udp_zero_copy_impl> udp_trans(new udp_zero_copy_impl(addr, port)); + + //resize the recv buffer if size was provided + if (recv_buff_size > 0){ + size_t actual_bytes = udp_trans->resize_recv_buff(recv_buff_size); + if (recv_buff_size != actual_bytes) std::cout << boost::format( + "Target recv buffer size: %d\n" + "Actual recv byffer size: %d" + ) % recv_buff_size % actual_bytes << std::endl; + } + + //resize the send buffer if size was provided + if (send_buff_size > 0){ + size_t actual_bytes = udp_trans->resize_send_buff(send_buff_size); + if (send_buff_size != actual_bytes) std::cout << boost::format( + "Target send buffer size: %d\n" + "Actual send byffer size: %d" + ) % send_buff_size % actual_bytes << std::endl; + } + + return udp_trans; } diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 08e41b62f..ec9c8ac01 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -105,9 +105,9 @@ tx_metadata_t::tx_metadata_t(void){ /*********************************************************************** * time spec **********************************************************************/ -time_spec_t::time_spec_t(boost::uint32_t new_secs, double new_nsecs){ - secs = new_secs; - nsecs = new_nsecs; +time_spec_t::time_spec_t(boost::uint32_t secs_, double nsecs_){ + secs = secs_; + nsecs = nsecs_; } boost::uint32_t time_spec_t::get_ticks(double tick_rate) const{ @@ -143,7 +143,7 @@ device_addr_t::device_addr_t(const std::string &args){ } } -std::string device_addr_t::to_string(void) const{ +std::string device_addr_t::to_pp_string(void) const{ if (this->size() == 0) return "Empty Device Address"; std::stringstream ss; @@ -153,7 +153,7 @@ std::string device_addr_t::to_string(void) const{ return ss.str(); } -std::string device_addr_t::to_args_str(void) const{ +std::string device_addr_t::to_string(void) const{ std::string args_str; BOOST_FOREACH(const std::string &key, this->keys()){ args_str += key + pair_delim + (*this)[key] + arg_delim; diff --git a/host/lib/usrp/dboard/db_basic_and_lf.cpp b/host/lib/usrp/dboard/db_basic_and_lf.cpp index b0fbbd2ec..23ac98872 100644 --- a/host/lib/usrp/dboard/db_basic_and_lf.cpp +++ b/host/lib/usrp/dboard/db_basic_and_lf.cpp @@ -34,7 +34,7 @@ using namespace boost::assign; **********************************************************************/ class basic_rx : public rx_dboard_base{ public: - basic_rx(ctor_args_t const& args, double max_freq); + basic_rx(ctor_args_t args, double max_freq); ~basic_rx(void); void rx_get(const wax::obj &key, wax::obj &val); @@ -46,7 +46,7 @@ private: class basic_tx : public tx_dboard_base{ public: - basic_tx(ctor_args_t const& args, double max_freq); + basic_tx(ctor_args_t args, double max_freq); ~basic_tx(void); void tx_get(const wax::obj &key, wax::obj &val); @@ -59,19 +59,19 @@ private: /*********************************************************************** * Register the basic and LF dboards **********************************************************************/ -static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_basic_rx(dboard_base::ctor_args_t args){ return dboard_base::sptr(new basic_rx(args, 90e9)); } -static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_basic_tx(dboard_base::ctor_args_t args){ return dboard_base::sptr(new basic_tx(args, 90e9)); } -static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_lf_rx(dboard_base::ctor_args_t args){ return dboard_base::sptr(new basic_rx(args, 32e6)); } -static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_lf_tx(dboard_base::ctor_args_t args){ return dboard_base::sptr(new basic_tx(args, 32e6)); } @@ -85,7 +85,7 @@ UHD_STATIC_BLOCK(reg_basic_and_lf_dboards){ /*********************************************************************** * Basic and LF RX dboard **********************************************************************/ -basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){ +basic_rx::basic_rx(ctor_args_t args, double max_freq) : rx_dboard_base(args){ _max_freq = max_freq; } @@ -101,7 +101,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: val = std::string(str(boost::format("%s - %s") - % dboard_id::to_string(get_rx_id()) + % get_rx_id().to_pp_string() % get_subdev_name() )); return; @@ -187,7 +187,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ /*********************************************************************** * Basic and LF TX dboard **********************************************************************/ -basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){ +basic_tx::basic_tx(ctor_args_t args, double max_freq) : tx_dboard_base(args){ _max_freq = max_freq; } @@ -202,7 +202,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: - val = dboard_id::to_string(get_tx_id()); + val = get_tx_id().to_pp_string(); return; case SUBDEV_PROP_OTHERS: diff --git a/host/lib/usrp/dboard/db_rfx.cpp b/host/lib/usrp/dboard/db_rfx.cpp index 175f55eab..bbc9716b1 100644 --- a/host/lib/usrp/dboard/db_rfx.cpp +++ b/host/lib/usrp/dboard/db_rfx.cpp @@ -63,7 +63,7 @@ static const float _max_rx_pga0_gain = 45; class rfx_xcvr : public xcvr_dboard_base{ public: rfx_xcvr( - ctor_args_t const& args, + ctor_args_t args, const freq_range_t &freq_range, bool rx_div2, bool tx_div2 ); @@ -108,23 +108,23 @@ private: /*********************************************************************** * Register the RFX dboards (min freq, max freq, rx div2, tx div2) **********************************************************************/ -static dboard_base::sptr make_rfx_flex400(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_rfx_flex400(dboard_base::ctor_args_t args){ return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(400e6, 500e6), false, true)); } -static dboard_base::sptr make_rfx_flex900(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_rfx_flex900(dboard_base::ctor_args_t args){ return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(750e6, 1050e6), true, true)); } -static dboard_base::sptr make_rfx_flex1800(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_rfx_flex1800(dboard_base::ctor_args_t args){ return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1500e6, 2100e6), false, false)); } -static dboard_base::sptr make_rfx_flex1200(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_rfx_flex1200(dboard_base::ctor_args_t args){ return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(1150e6, 1450e6), true, true)); } -static dboard_base::sptr make_rfx_flex2400(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_rfx_flex2400(dboard_base::ctor_args_t args){ return dboard_base::sptr(new rfx_xcvr(args, freq_range_t(2300e6, 2900e6), false, false)); } @@ -149,7 +149,7 @@ UHD_STATIC_BLOCK(reg_rfx_dboards){ * Structors **********************************************************************/ rfx_xcvr::rfx_xcvr( - ctor_args_t const& args, + ctor_args_t args, const freq_range_t &freq_range, bool rx_div2, bool tx_div2 ) : xcvr_dboard_base(args){ @@ -351,7 +351,7 @@ void rfx_xcvr::rx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: - val = dboard_id::to_string(get_rx_id()); + val = get_rx_id().to_pp_string(); return; case SUBDEV_PROP_OTHERS: @@ -448,7 +448,7 @@ void rfx_xcvr::tx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: - val = dboard_id::to_string(get_tx_id()); + val = get_tx_id().to_pp_string(); return; case SUBDEV_PROP_OTHERS: diff --git a/host/lib/usrp/dboard/db_xcvr2450.cpp b/host/lib/usrp/dboard/db_xcvr2450.cpp index efe7687c2..3bf866fc8 100644 --- a/host/lib/usrp/dboard/db_xcvr2450.cpp +++ b/host/lib/usrp/dboard/db_xcvr2450.cpp @@ -89,7 +89,7 @@ static const uhd::dict<std::string, gain_range_t> xcvr_rx_gain_ranges = map_list **********************************************************************/ class xcvr2450 : public xcvr_dboard_base{ public: - xcvr2450(ctor_args_t const& args); + xcvr2450(ctor_args_t args); ~xcvr2450(void); void rx_get(const wax::obj &key, wax::obj &val); @@ -152,7 +152,7 @@ private: /*********************************************************************** * Register the XCVR 2450 dboard **********************************************************************/ -static dboard_base::sptr make_xcvr2450(dboard_base::ctor_args_t const& args){ +static dboard_base::sptr make_xcvr2450(dboard_base::ctor_args_t args){ return dboard_base::sptr(new xcvr2450(args)); } @@ -165,7 +165,7 @@ UHD_STATIC_BLOCK(reg_xcvr2450_dboard){ /*********************************************************************** * Structors **********************************************************************/ -xcvr2450::xcvr2450(ctor_args_t const& args) : xcvr_dboard_base(args){ +xcvr2450::xcvr2450(ctor_args_t args) : xcvr_dboard_base(args){ //enable only the clocks we need this->get_iface()->set_clock_enabled(dboard_iface::UNIT_TX, true); @@ -263,7 +263,7 @@ void xcvr2450::set_lo_freq(double target_freq){ for(R = 1; R <= 7; R++){ double N = (target_freq*scaler*R*_ad9515div)/ref_freq; intdiv = int(std::floor(N)); - fracdiv = (N - intdiv)*double(1 << 16); + fracdiv = boost::math::iround((N - intdiv)*double(1 << 16)); //actual minimum is 128, but most chips seems to require higher to lock if (intdiv < 131 or intdiv > 255) continue; //constraints met: exit loop @@ -344,8 +344,8 @@ static int gain_to_tx_vga_reg(float &gain){ //calculate the actual gain value if (reg < 4) gain = 0; - else if (reg < 48) gain = reg/2 - 1; - else gain = reg/2.0 - 1.5; + else if (reg < 48) gain = float(reg/2 - 1); + else gain = float(reg/2.0 - 1.5); //return register value return reg; @@ -385,7 +385,7 @@ static max2829_regs_t::tx_baseband_gain_t gain_to_tx_bb_reg(float &gain){ */ static int gain_to_rx_vga_reg(float &gain){ int reg = std::clip(boost::math::iround(gain/2.0), 0, 31); - gain = reg*2; + gain = float(reg*2); return reg; } @@ -444,7 +444,7 @@ void xcvr2450::rx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: - val = dboard_id::to_string(get_rx_id()); + val = get_rx_id().to_pp_string(); return; case SUBDEV_PROP_OTHERS: @@ -542,7 +542,7 @@ void xcvr2450::tx_get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<subdev_prop_t>()){ case SUBDEV_PROP_NAME: - val = dboard_id::to_string(get_tx_id()); + val = get_tx_id().to_pp_string(); return; case SUBDEV_PROP_OTHERS: diff --git a/host/lib/usrp/dboard_base.cpp b/host/lib/usrp/dboard_base.cpp index 68e4743d1..bd4b37ef3 100644 --- a/host/lib/usrp/dboard_base.cpp +++ b/host/lib/usrp/dboard_base.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "dboard_ctor_args.hpp" #include <uhd/usrp/dboard_base.hpp> #include <boost/format.hpp> #include <stdexcept> @@ -24,43 +25,48 @@ using namespace uhd::usrp; /*********************************************************************** * dboard_base dboard dboard_base class **********************************************************************/ -dboard_base::dboard_base(ctor_args_t const& args){ - boost::tie(_subdev_name, _dboard_iface, _rx_id, _tx_id) = args; +struct dboard_base::dboard_base_impl{ + ctor_args_impl args; + dboard_base_impl(ctor_args_t args) : args(*args){} +}; + +dboard_base::dboard_base(ctor_args_t args){ + _impl = new dboard_base_impl(args); } dboard_base::~dboard_base(void){ - /* NOP */ + delete _impl; } std::string dboard_base::get_subdev_name(void){ - return _subdev_name; + return _impl->args.sd_name; } dboard_iface::sptr dboard_base::get_iface(void){ - return _dboard_iface; + return _impl->args.db_iface; } dboard_id_t dboard_base::get_rx_id(void){ - return _rx_id; + return _impl->args.rx_id; } dboard_id_t dboard_base::get_tx_id(void){ - return _tx_id; + return _impl->args.tx_id; } /*********************************************************************** * xcvr dboard dboard_base class **********************************************************************/ -xcvr_dboard_base::xcvr_dboard_base(ctor_args_t const& args) : dboard_base(args){ - if (get_rx_id() == dboard_id::NONE){ +xcvr_dboard_base::xcvr_dboard_base(ctor_args_t args) : dboard_base(args){ + if (get_rx_id() == dboard_id_t::none()){ throw std::runtime_error(str(boost::format( "cannot create xcvr board when the rx id is \"%s\"" - ) % dboard_id::to_string(dboard_id::NONE))); + ) % dboard_id_t::none().to_pp_string())); } - if (get_tx_id() == dboard_id::NONE){ + if (get_tx_id() == dboard_id_t::none()){ throw std::runtime_error(str(boost::format( "cannot create xcvr board when the tx id is \"%s\"" - ) % dboard_id::to_string(dboard_id::NONE))); + ) % dboard_id_t::none().to_pp_string())); } } @@ -71,12 +77,12 @@ xcvr_dboard_base::~xcvr_dboard_base(void){ /*********************************************************************** * rx dboard dboard_base class **********************************************************************/ -rx_dboard_base::rx_dboard_base(ctor_args_t const& args) : dboard_base(args){ - if (get_tx_id() != dboard_id::NONE){ +rx_dboard_base::rx_dboard_base(ctor_args_t args) : dboard_base(args){ + if (get_tx_id() != dboard_id_t::none()){ throw std::runtime_error(str(boost::format( "cannot create rx board when the tx id is \"%s\"" " -> expected a tx id of \"%s\"" - ) % dboard_id::to_string(get_tx_id()) % dboard_id::to_string(dboard_id::NONE))); + ) % get_tx_id().to_pp_string() % dboard_id_t::none().to_pp_string())); } } @@ -95,12 +101,12 @@ void rx_dboard_base::tx_set(const wax::obj &, const wax::obj &){ /*********************************************************************** * tx dboard dboard_base class **********************************************************************/ -tx_dboard_base::tx_dboard_base(ctor_args_t const& args) : dboard_base(args){ - if (get_rx_id() != dboard_id::NONE){ +tx_dboard_base::tx_dboard_base(ctor_args_t args) : dboard_base(args){ + if (get_rx_id() != dboard_id_t::none()){ throw std::runtime_error(str(boost::format( "cannot create tx board when the rx id is \"%s\"" " -> expected a rx id of \"%s\"" - ) % dboard_id::to_string(get_rx_id()) % dboard_id::to_string(dboard_id::NONE))); + ) % get_rx_id().to_pp_string() % dboard_id_t::none().to_pp_string())); } } diff --git a/host/lib/usrp/dboard_ctor_args.hpp b/host/lib/usrp/dboard_ctor_args.hpp new file mode 100644 index 000000000..13abe79e8 --- /dev/null +++ b/host/lib/usrp/dboard_ctor_args.hpp @@ -0,0 +1,32 @@ +// +// 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_DBOARD_CTOR_ARGS_HPP +#define INCLUDED_DBOARD_CTOR_ARGS_HPP + +#include <uhd/usrp/dboard_id.hpp> +#include <uhd/usrp/dboard_base.hpp> +#include <uhd/usrp/dboard_iface.hpp> +#include <string> + +struct uhd::usrp::dboard_base::ctor_args_impl{ + std::string sd_name; + dboard_iface::sptr db_iface; + dboard_id_t rx_id, tx_id; +}; + +#endif /* INCLUDED_DBOARD_CTOR_ARGS_HPP */ diff --git a/host/lib/usrp/dboard_eeprom.cpp b/host/lib/usrp/dboard_eeprom.cpp index 1404ed1e6..fa3631948 100644 --- a/host/lib/usrp/dboard_eeprom.cpp +++ b/host/lib/usrp/dboard_eeprom.cpp @@ -80,19 +80,20 @@ dboard_eeprom_t::dboard_eeprom_t(const byte_vector_t &bytes){ UHD_ASSERT_THROW(bytes.size() >= DB_EEPROM_CLEN); UHD_ASSERT_THROW(bytes[DB_EEPROM_MAGIC] == DB_EEPROM_MAGIC_VALUE); UHD_ASSERT_THROW(bytes[DB_EEPROM_CHKSUM] == checksum(bytes)); - id = \ - (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) | - (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) ; - }catch(const uhd::assert_error &e){ - id = dboard_id::NONE; + id = dboard_id_t::from_uint16(0 + | (boost::uint16_t(bytes[DB_EEPROM_ID_LSB]) << 0) + | (boost::uint16_t(bytes[DB_EEPROM_ID_MSB]) << 8) + ); + }catch(const uhd::assert_error &){ + id = dboard_id_t::none(); } } byte_vector_t dboard_eeprom_t::get_eeprom_bytes(void){ byte_vector_t bytes(DB_EEPROM_CLEN, 0); //defaults to all zeros bytes[DB_EEPROM_MAGIC] = DB_EEPROM_MAGIC_VALUE; - bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id >> 0); - bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id >> 8); + bytes[DB_EEPROM_ID_LSB] = boost::uint8_t(id.to_uint16() >> 0); + bytes[DB_EEPROM_ID_MSB] = boost::uint8_t(id.to_uint16() >> 8); bytes[DB_EEPROM_CHKSUM] = checksum(bytes); return bytes; } diff --git a/host/lib/usrp/dboard_id.cpp b/host/lib/usrp/dboard_id.cpp new file mode 100644 index 000000000..3028d2a3b --- /dev/null +++ b/host/lib/usrp/dboard_id.cpp @@ -0,0 +1,68 @@ +// +// 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/>. +// + +#include <uhd/usrp/dboard_id.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/format.hpp> +#include <sstream> +#include <iostream> + +using namespace uhd::usrp; + +dboard_id_t::dboard_id_t(boost::uint16_t id){ + _id = id; +} + +dboard_id_t dboard_id_t::none(void){ + return dboard_id_t(); +} + +dboard_id_t dboard_id_t::from_uint16(boost::uint16_t uint16){ + return dboard_id_t(uint16); +} + +boost::uint16_t dboard_id_t::to_uint16(void) const{ + return _id; +} + +//used with lexical cast to parse a hex string +template <class T> struct to_hex{ + T value; + operator T() const {return value;} + friend std::istream& operator>>(std::istream& in, to_hex& out){ + in >> std::hex >> out.value; + return in; + } +}; + +dboard_id_t dboard_id_t::from_string(const std::string &string){ + if (string.substr(0, 2) == "0x"){ + return dboard_id_t::from_uint16(boost::lexical_cast<to_hex<boost::uint16_t> >(string)); + } + return dboard_id_t::from_uint16(boost::lexical_cast<boost::uint16_t>(string)); +} + +std::string dboard_id_t::to_string(void) const{ + return str(boost::format("0x%04x") % this->to_uint16()); +} + +//Note: to_pp_string is implemented in the dboard manager +//because it needs access to the dboard registration table + +bool uhd::usrp::operator==(const dboard_id_t &lhs, const dboard_id_t &rhs){ + return lhs.to_uint16() == rhs.to_uint16(); +} diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 390c1d3c9..8161727e5 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // +#include "dboard_ctor_args.hpp" #include <uhd/usrp/dboard_manager.hpp> #include <uhd/usrp/subdev_props.hpp> #include <uhd/utils/gain_handler.hpp> @@ -26,6 +27,7 @@ #include <boost/bind.hpp> #include <boost/foreach.hpp> #include <boost/assign/list_of.hpp> +#include <iostream> using namespace uhd; using namespace uhd::usrp; @@ -49,15 +51,18 @@ void dboard_manager::register_dboard( //std::cout << "registering: " << name << std::endl; if (get_id_to_args_map().has_key(dboard_id)){ throw std::runtime_error(str(boost::format( - "The dboard id 0x%04x is already registered to %s." - ) % dboard_id % dboard_id::to_string(dboard_id))); + "The dboard id %s is already registered to %s." + ) % dboard_id.to_string() % dboard_id.to_pp_string())); } get_id_to_args_map()[dboard_id] = args_t(dboard_ctor, name, subdev_names); } -std::string dboard_id::to_string(const dboard_id_t &id){ - std::string name = (get_id_to_args_map().has_key(id))? get_id_to_args_map()[id].get<1>() : "unknown"; - return str(boost::format("%s (0x%04x)") % name % id); +std::string dboard_id_t::to_pp_string(void) const{ + std::string name = "unknown"; + if (get_id_to_args_map().has_key(*this)){ + name = get_id_to_args_map()[*this].get<1>(); + } + return str(boost::format("%s (%s)") % name % this->to_string()); } /*********************************************************************** @@ -162,26 +167,27 @@ dboard_manager::sptr dboard_manager::make( * implementation class methods **********************************************************************/ static args_t get_dboard_args( - dboard_id_t dboard_id, - std::string const& xx_type + dboard_iface::unit_t unit, + dboard_id_t dboard_id ){ - //special case, its rx and the none id (0xffff) - if (xx_type == "rx" and dboard_id == dboard_id::NONE){ - return get_dboard_args(0x0001, xx_type); - } - - //special case, its tx and the none id (0xffff) - if (xx_type == "tx" and dboard_id == dboard_id::NONE){ - return get_dboard_args(0x0000, xx_type); + //special case, the none id was provided, use the following ids + if (dboard_id == dboard_id_t::none()){ + std::cerr << boost::format( + "Warning: unregistered dboard id: %s" + " -> defaulting to a basic board" + ) % dboard_id.to_pp_string() << std::endl; + UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0001)); + UHD_ASSERT_THROW(get_id_to_args_map().has_key(0x0000)); + switch(unit){ + case dboard_iface::UNIT_RX: return get_dboard_args(unit, 0x0001); + case dboard_iface::UNIT_TX: return get_dboard_args(unit, 0x0000); + default: UHD_ASSERT_THROW(false); + } } //verify that there is a registered constructor for this id if (not get_id_to_args_map().has_key(dboard_id)){ - /*throw std::runtime_error(str( - boost::format("Unregistered %s dboard id: %s") - % xx_type % dboard_id::to_string(dboard_id) - ));*/ - return get_dboard_args(dboard_id::NONE, xx_type); + return get_dboard_args(unit, dboard_id_t::none()); } //return the dboard args for this id @@ -196,21 +202,26 @@ dboard_manager_impl::dboard_manager_impl( _iface = iface; dboard_ctor_t rx_dboard_ctor; std::string rx_name; prop_names_t rx_subdevs; - boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx"); + boost::tie(rx_dboard_ctor, rx_name, rx_subdevs) = get_dboard_args(dboard_iface::UNIT_RX, rx_dboard_id); dboard_ctor_t tx_dboard_ctor; std::string tx_name; prop_names_t tx_subdevs; - boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx"); + boost::tie(tx_dboard_ctor, tx_name, tx_subdevs) = get_dboard_args(dboard_iface::UNIT_TX, tx_dboard_id); //initialize the gpio pins before creating subdevs set_nice_dboard_if(); + //dboard constructor args + dboard_base::ctor_args_impl db_ctor_args; + db_ctor_args.db_iface = iface; + //make xcvr subdevs (make one subdev for both rx and tx dboards) if (rx_dboard_ctor == tx_dboard_ctor){ UHD_ASSERT_THROW(rx_subdevs == tx_subdevs); BOOST_FOREACH(const std::string &subdev, rx_subdevs){ - dboard_base::sptr xcvr_dboard = rx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, tx_dboard_id) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = rx_dboard_id; + db_ctor_args.tx_id = tx_dboard_id; + dboard_base::sptr xcvr_dboard = rx_dboard_ctor(&db_ctor_args); //create a rx proxy for this xcvr board _rx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(xcvr_dboard, subdev_proxy::RX_TYPE) @@ -226,9 +237,10 @@ dboard_manager_impl::dboard_manager_impl( else{ //make the rx subdevs BOOST_FOREACH(const std::string &subdev, rx_subdevs){ - dboard_base::sptr rx_dboard = rx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, rx_dboard_id, dboard_id::NONE) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = rx_dboard_id; + db_ctor_args.tx_id = dboard_id_t::none(); + dboard_base::sptr rx_dboard = rx_dboard_ctor(&db_ctor_args); //create a rx proxy for this rx board _rx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(rx_dboard, subdev_proxy::RX_TYPE) @@ -236,9 +248,10 @@ dboard_manager_impl::dboard_manager_impl( } //make the tx subdevs BOOST_FOREACH(const std::string &subdev, tx_subdevs){ - dboard_base::sptr tx_dboard = tx_dboard_ctor( - dboard_base::ctor_args_t(subdev, iface, dboard_id::NONE, tx_dboard_id) - ); + db_ctor_args.sd_name = subdev; + db_ctor_args.rx_id = dboard_id_t::none(); + db_ctor_args.tx_id = tx_dboard_id; + dboard_base::sptr tx_dboard = tx_dboard_ctor(&db_ctor_args); //create a tx proxy for this tx board _tx_dboards[subdev] = subdev_proxy::sptr( new subdev_proxy(tx_dboard, subdev_proxy::TX_TYPE) diff --git a/host/lib/usrp/simple_usrp.cpp b/host/lib/usrp/simple_usrp.cpp index 321d66a4a..a8c104485 100644 --- a/host/lib/usrp/simple_usrp.cpp +++ b/host/lib/usrp/simple_usrp.cpp @@ -102,6 +102,10 @@ public: _mboard[MBOARD_PROP_CLOCK_CONFIG] = clock_config; } + float read_rssi(void){ + return _rx_subdev[SUBDEV_PROP_RSSI].as<float>(); + } + /******************************************************************* * RX methods ******************************************************************/ @@ -145,6 +149,10 @@ public: return _rx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>(); } + bool get_rx_lo_locked(void){ + return _rx_subdev[SUBDEV_PROP_LO_LOCKED].as<bool>(); + } + /******************************************************************* * TX methods ******************************************************************/ @@ -188,6 +196,10 @@ public: return _tx_subdev[SUBDEV_PROP_ANTENNA_NAMES].as<prop_names_t>(); } + bool get_tx_lo_locked(void){ + return _tx_subdev[SUBDEV_PROP_LO_LOCKED].as<bool>(); + } + private: device::sptr _dev; wax::obj _mboard; diff --git a/host/lib/usrp/usrp2/dboard_iface.cpp b/host/lib/usrp/usrp2/dboard_iface.cpp index 74d80163c..372a5af07 100644 --- a/host/lib/usrp/usrp2/dboard_iface.cpp +++ b/host/lib/usrp/usrp2/dboard_iface.cpp @@ -29,6 +29,7 @@ using namespace uhd; using namespace uhd::usrp; +using namespace boost::assign; class usrp2_dboard_iface : public dboard_iface{ public: @@ -122,49 +123,42 @@ double usrp2_dboard_iface::get_clock_rate(unit_t){ void usrp2_dboard_iface::set_clock_enabled(unit_t unit, bool enb){ switch(unit){ - case UNIT_RX: - _clk_ctrl->enable_rx_dboard_clock(enb); - return; - case UNIT_TX: - _clk_ctrl->enable_tx_dboard_clock(enb); - return; + case UNIT_RX: _clk_ctrl->enable_rx_dboard_clock(enb); return; + case UNIT_TX: _clk_ctrl->enable_tx_dboard_clock(enb); return; } } /*********************************************************************** * GPIO **********************************************************************/ -static int unit_to_shift(dboard_iface::unit_t unit){ - switch(unit){ - case dboard_iface::UNIT_RX: return 0; - case dboard_iface::UNIT_TX: return 16; - } - throw std::runtime_error("unknown unit type"); -} +static const uhd::dict<dboard_iface::unit_t, int> unit_to_shift = map_list_of + (dboard_iface::UNIT_RX, 0) + (dboard_iface::UNIT_TX, 16) +; void usrp2_dboard_iface::set_gpio_ddr(unit_t unit, boost::uint16_t value){ _ddr_shadow = \ - (_ddr_shadow & ~(0xffff << unit_to_shift(unit))) | - (boost::uint32_t(value) << unit_to_shift(unit)); + (_ddr_shadow & ~(0xffff << unit_to_shift[unit])) | + (boost::uint32_t(value) << unit_to_shift[unit]); _iface->poke32(FR_GPIO_DDR, _ddr_shadow); } boost::uint16_t usrp2_dboard_iface::read_gpio(unit_t unit){ - return boost::uint16_t(_iface->peek32(FR_GPIO_IO) >> unit_to_shift(unit)); + return boost::uint16_t(_iface->peek32(FR_GPIO_IO) >> unit_to_shift[unit]); } void usrp2_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t value){ //define mapping of unit to atr regs to register address static const uhd::dict< unit_t, uhd::dict<atr_reg_t, boost::uint32_t> - > unit_to_atr_to_addr = boost::assign::map_list_of - (UNIT_RX, boost::assign::map_list_of + > unit_to_atr_to_addr = map_list_of + (UNIT_RX, map_list_of (ATR_REG_IDLE, FR_ATR_IDLE_RXSIDE) (ATR_REG_TX_ONLY, FR_ATR_INTX_RXSIDE) (ATR_REG_RX_ONLY, FR_ATR_INRX_RXSIDE) (ATR_REG_FULL_DUPLEX, FR_ATR_FULL_RXSIDE) ) - (UNIT_TX, boost::assign::map_list_of + (UNIT_TX, map_list_of (ATR_REG_IDLE, FR_ATR_IDLE_TXSIDE) (ATR_REG_TX_ONLY, FR_ATR_INTX_TXSIDE) (ATR_REG_RX_ONLY, FR_ATR_INRX_TXSIDE) @@ -177,19 +171,10 @@ void usrp2_dboard_iface::set_atr_reg(unit_t unit, atr_reg_t atr, boost::uint16_t /*********************************************************************** * SPI **********************************************************************/ -/*! - * Static function to convert a unit type enum - * to an over-the-wire value for the spi device. - * \param unit the dboard interface unit type enum - * \return an over the wire representation - */ -static boost::uint8_t unit_to_otw_spi_dev(dboard_iface::unit_t unit){ - switch(unit){ - case dboard_iface::UNIT_TX: return SPI_SS_TX_DB; - case dboard_iface::UNIT_RX: return SPI_SS_RX_DB; - } - throw std::invalid_argument("unknown unit type"); -} +static const uhd::dict<dboard_iface::unit_t, int> unit_to_spi_dev = map_list_of + (dboard_iface::UNIT_TX, SPI_SS_TX_DB) + (dboard_iface::UNIT_RX, SPI_SS_RX_DB) +; void usrp2_dboard_iface::write_spi( unit_t unit, @@ -197,7 +182,7 @@ void usrp2_dboard_iface::write_spi( boost::uint32_t data, size_t num_bits ){ - _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, false /*no rb*/); + _iface->transact_spi(unit_to_spi_dev[unit], config, data, num_bits, false /*no rb*/); } boost::uint32_t usrp2_dboard_iface::read_write_spi( @@ -206,7 +191,7 @@ boost::uint32_t usrp2_dboard_iface::read_write_spi( boost::uint32_t data, size_t num_bits ){ - return _iface->transact_spi(unit_to_otw_spi_dev(unit), config, data, num_bits, true /*rb*/); + return _iface->transact_spi(unit_to_spi_dev[unit], config, data, num_bits, true /*rb*/); } /*********************************************************************** @@ -224,7 +209,7 @@ byte_vector_t usrp2_dboard_iface::read_i2c(boost::uint8_t addr, size_t num_bytes * Aux DAX/ADC **********************************************************************/ void usrp2_dboard_iface::_write_aux_dac(unit_t unit){ - static const uhd::dict<unit_t, int> unit_to_spi_dac = boost::assign::map_list_of + static const uhd::dict<unit_t, int> unit_to_spi_dac = map_list_of (UNIT_RX, SPI_SS_RX_DAC) (UNIT_TX, SPI_SS_TX_DAC) ; @@ -248,7 +233,7 @@ void usrp2_dboard_iface::write_aux_dac(unit_t unit, int which, float value){ } float usrp2_dboard_iface::read_aux_adc(unit_t unit, int which){ - static const uhd::dict<unit_t, int> unit_to_spi_adc = boost::assign::map_list_of + static const uhd::dict<unit_t, int> unit_to_spi_adc = map_list_of (UNIT_RX, SPI_SS_RX_ADC) (UNIT_TX, SPI_SS_TX_ADC) ; diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 4079357f9..1dde8c054 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -24,6 +24,7 @@ #include <boost/assign/list_of.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> +#include <boost/lexical_cast.hpp> #include <boost/bind.hpp> #include <boost/asio.hpp> //htonl and ntohl #include <iostream> @@ -50,7 +51,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ if (if_addrs.inet == asio::ip::address_v4::loopback().to_string()) continue; //create a new hint with this broadcast address - device_addr_t new_hint = hint; + device_addr_t new_hint; new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results @@ -112,9 +113,21 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ device_addr["addr"], num2str(USRP2_UDP_CTRL_PORT) ); + //extract the receive and send buffer sizes + size_t recv_buff_size = 0, send_buff_size= 0 ; + if (device_addr.has_key("recv_buff_size")){ + recv_buff_size = size_t(boost::lexical_cast<double>(device_addr["recv_buff_size"])); + } + if (device_addr.has_key("send_buff_size")){ + send_buff_size = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"])); + } + //create a data transport udp_zero_copy::sptr data_transport = udp_zero_copy::make( - device_addr["addr"], num2str(USRP2_UDP_DATA_PORT) + device_addr["addr"], + num2str(USRP2_UDP_DATA_PORT), + recv_buff_size, + send_buff_size ); //create the usrp2 implementation guts |