root / host / lib / usrp / usrp1 / dboard_impl.cpp @ 5c0d3d30
History | View | Annotate | Download (6.99 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include "usrp1_impl.hpp" |
| 19 |
#include "usrp_i2c_addr.h" |
| 20 |
#include "../dsp_utils.hpp" |
| 21 |
#include "../misc_utils.hpp" |
| 22 |
#include <uhd/utils/assert.hpp> |
| 23 |
#include <uhd/usrp/dboard_props.hpp> |
| 24 |
#include <uhd/usrp/subdev_props.hpp> |
| 25 |
#include <boost/bind.hpp> |
| 26 |
#include <boost/foreach.hpp> |
| 27 |
#include <boost/format.hpp> |
| 28 |
#include <iostream> |
| 29 |
|
| 30 |
using namespace uhd; |
| 31 |
using namespace uhd::usrp; |
| 32 |
|
| 33 |
/***********************************************************************
|
| 34 |
* Helper Functions
|
| 35 |
**********************************************************************/
|
| 36 |
static boost::uint8_t get_rx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){
|
| 37 |
switch(dboard_slot){
|
| 38 |
case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_RX_A; |
| 39 |
case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_RX_B; |
| 40 |
default: UHD_THROW_INVALID_CODE_PATH();
|
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
static boost::uint8_t get_tx_ee_addr(usrp1_impl::dboard_slot_t dboard_slot){
|
| 45 |
switch(dboard_slot){
|
| 46 |
case usrp1_impl::DBOARD_SLOT_A: return I2C_ADDR_TX_A; |
| 47 |
case usrp1_impl::DBOARD_SLOT_B: return I2C_ADDR_TX_B; |
| 48 |
default: UHD_THROW_INVALID_CODE_PATH();
|
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/***********************************************************************
|
| 53 |
* Dboard Initialization
|
| 54 |
**********************************************************************/
|
| 55 |
void usrp1_impl::dboard_init(void) |
| 56 |
{
|
| 57 |
BOOST_FOREACH(dboard_slot_t dboard_slot, _dboard_slots){
|
| 58 |
|
| 59 |
//read the tx and rx dboard eeproms
|
| 60 |
_rx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( |
| 61 |
get_rx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes()
|
| 62 |
)); |
| 63 |
|
| 64 |
_tx_db_eeproms[dboard_slot] = dboard_eeprom_t(_iface->read_eeprom( |
| 65 |
get_tx_ee_addr(dboard_slot), 0, dboard_eeprom_t::num_bytes()
|
| 66 |
)); |
| 67 |
|
| 68 |
//create a new dboard interface and manager
|
| 69 |
_dboard_ifaces[dboard_slot] = make_dboard_iface( |
| 70 |
_iface, _clock_ctrl, _codec_ctrls[dboard_slot], dboard_slot |
| 71 |
); |
| 72 |
|
| 73 |
_dboard_managers[dboard_slot] = dboard_manager::make( |
| 74 |
_rx_db_eeproms[dboard_slot].id, |
| 75 |
_tx_db_eeproms[dboard_slot].id, |
| 76 |
_dboard_ifaces[dboard_slot] |
| 77 |
); |
| 78 |
|
| 79 |
//setup the dboard proxies
|
| 80 |
_rx_dboard_proxies[dboard_slot] = wax_obj_proxy::make( |
| 81 |
boost::bind(&usrp1_impl::rx_dboard_get, this, _1, _2, dboard_slot),
|
| 82 |
boost::bind(&usrp1_impl::rx_dboard_set, this, _1, _2, dboard_slot));
|
| 83 |
|
| 84 |
_tx_dboard_proxies[dboard_slot] = wax_obj_proxy::make( |
| 85 |
boost::bind(&usrp1_impl::tx_dboard_get, this, _1, _2, dboard_slot),
|
| 86 |
boost::bind(&usrp1_impl::tx_dboard_set, this, _1, _2, dboard_slot));
|
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
/***********************************************************************
|
| 92 |
* RX Dboard Get
|
| 93 |
**********************************************************************/
|
| 94 |
void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) |
| 95 |
{
|
| 96 |
named_prop_t key = named_prop_t::extract(key_); |
| 97 |
|
| 98 |
//handle the get request conditioned on the key
|
| 99 |
switch(key.as<dboard_prop_t>()){
|
| 100 |
case DBOARD_PROP_NAME:
|
| 101 |
val = str(boost::format("usrp1 dboard (rx unit) - %c") % dboard_slot);
|
| 102 |
return;
|
| 103 |
|
| 104 |
case DBOARD_PROP_SUBDEV:
|
| 105 |
val = _dboard_managers[dboard_slot]->get_rx_subdev(key.name); |
| 106 |
return;
|
| 107 |
|
| 108 |
case DBOARD_PROP_SUBDEV_NAMES:
|
| 109 |
val = _dboard_managers[dboard_slot]->get_rx_subdev_names(); |
| 110 |
return;
|
| 111 |
|
| 112 |
case DBOARD_PROP_DBOARD_ID:
|
| 113 |
val = _rx_db_eeproms[dboard_slot].id; |
| 114 |
return;
|
| 115 |
|
| 116 |
case DBOARD_PROP_DBOARD_IFACE:
|
| 117 |
val = _dboard_ifaces[dboard_slot]; |
| 118 |
return;
|
| 119 |
|
| 120 |
case DBOARD_PROP_CODEC:
|
| 121 |
val = _rx_codec_proxies[dboard_slot]->get_link(); |
| 122 |
return;
|
| 123 |
|
| 124 |
case DBOARD_PROP_GAIN_GROUP:
|
| 125 |
val = make_gain_group(_dboard_managers[dboard_slot]->get_rx_subdev(key.name), |
| 126 |
_rx_codec_proxies[dboard_slot]->get_link()); |
| 127 |
return;
|
| 128 |
|
| 129 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/***********************************************************************
|
| 134 |
* RX Dboard Set
|
| 135 |
**********************************************************************/
|
| 136 |
void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot) |
| 137 |
{
|
| 138 |
switch(key.as<dboard_prop_t>()) {
|
| 139 |
case DBOARD_PROP_DBOARD_ID:
|
| 140 |
_rx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>(); |
| 141 |
_iface->write_eeprom( |
| 142 |
get_rx_ee_addr(dboard_slot), 0,
|
| 143 |
_rx_db_eeproms[dboard_slot].get_eeprom_bytes() |
| 144 |
); |
| 145 |
return;
|
| 146 |
|
| 147 |
default:
|
| 148 |
UHD_THROW_PROP_SET_ERROR(); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
/***********************************************************************
|
| 153 |
* TX Dboard Get
|
| 154 |
**********************************************************************/
|
| 155 |
void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val, dboard_slot_t dboard_slot) |
| 156 |
{
|
| 157 |
named_prop_t key = named_prop_t::extract(key_); |
| 158 |
|
| 159 |
//handle the get request conditioned on the key
|
| 160 |
switch(key.as<dboard_prop_t>()){
|
| 161 |
case DBOARD_PROP_NAME:
|
| 162 |
val = str(boost::format("usrp1 dboard (tx unit) - %c") % dboard_slot);
|
| 163 |
return;
|
| 164 |
|
| 165 |
case DBOARD_PROP_SUBDEV:
|
| 166 |
val = _dboard_managers[dboard_slot]->get_tx_subdev(key.name); |
| 167 |
return;
|
| 168 |
|
| 169 |
case DBOARD_PROP_SUBDEV_NAMES:
|
| 170 |
val = _dboard_managers[dboard_slot]->get_tx_subdev_names(); |
| 171 |
return;
|
| 172 |
|
| 173 |
case DBOARD_PROP_DBOARD_ID:
|
| 174 |
val = _tx_db_eeproms[dboard_slot].id; |
| 175 |
return;
|
| 176 |
|
| 177 |
case DBOARD_PROP_DBOARD_IFACE:
|
| 178 |
val = _dboard_ifaces[dboard_slot]; |
| 179 |
return;
|
| 180 |
|
| 181 |
case DBOARD_PROP_CODEC:
|
| 182 |
val = _tx_codec_proxies[dboard_slot]->get_link(); |
| 183 |
return;
|
| 184 |
|
| 185 |
case DBOARD_PROP_GAIN_GROUP:
|
| 186 |
val = make_gain_group(_dboard_managers[dboard_slot]->get_tx_subdev(key.name), |
| 187 |
_tx_codec_proxies[dboard_slot]->get_link()); |
| 188 |
return;
|
| 189 |
|
| 190 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
/***********************************************************************
|
| 195 |
* TX Dboard Set
|
| 196 |
**********************************************************************/
|
| 197 |
void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val, dboard_slot_t dboard_slot) |
| 198 |
{
|
| 199 |
switch(key.as<dboard_prop_t>()) {
|
| 200 |
case DBOARD_PROP_DBOARD_ID:
|
| 201 |
_tx_db_eeproms[dboard_slot].id = val.as<dboard_id_t>(); |
| 202 |
_iface->write_eeprom( |
| 203 |
get_tx_ee_addr(dboard_slot), 0,
|
| 204 |
_tx_db_eeproms[dboard_slot].get_eeprom_bytes() |
| 205 |
); |
| 206 |
return;
|
| 207 |
|
| 208 |
default: UHD_THROW_PROP_SET_ERROR();
|
| 209 |
} |
| 210 |
} |