root / host / lib / usrp / usrp1 / dboard_impl.cpp @ 9cb9e7d5
History | View | Annotate | Download (6 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 <iostream> |
| 27 |
|
| 28 |
using namespace uhd; |
| 29 |
using namespace uhd::usrp; |
| 30 |
|
| 31 |
/***********************************************************************
|
| 32 |
* Dboard Initialization
|
| 33 |
**********************************************************************/
|
| 34 |
void usrp1_impl::dboard_init(void) |
| 35 |
{
|
| 36 |
_rx_db_eeprom = dboard_eeprom_t( |
| 37 |
_iface->read_eeprom(I2C_ADDR_RX_A, 0, dboard_eeprom_t::num_bytes()));
|
| 38 |
|
| 39 |
_tx_db_eeprom = dboard_eeprom_t( |
| 40 |
_iface->read_eeprom(I2C_ADDR_TX_A, 0, dboard_eeprom_t::num_bytes()));
|
| 41 |
|
| 42 |
|
| 43 |
//create a new dboard interface and manager
|
| 44 |
_dboard_iface = make_usrp1_dboard_iface(_iface, _clock_ctrl, _codec_ctrl); |
| 45 |
|
| 46 |
_dboard_manager = dboard_manager::make(_rx_db_eeprom.id, |
| 47 |
_tx_db_eeprom.id, |
| 48 |
_dboard_iface); |
| 49 |
|
| 50 |
//setup the dboard proxies
|
| 51 |
_rx_dboard_proxy = wax_obj_proxy::make( |
| 52 |
boost::bind(&usrp1_impl::rx_dboard_get, this, _1, _2),
|
| 53 |
boost::bind(&usrp1_impl::rx_dboard_set, this, _1, _2));
|
| 54 |
|
| 55 |
_tx_dboard_proxy = wax_obj_proxy::make( |
| 56 |
boost::bind(&usrp1_impl::tx_dboard_get, this, _1, _2),
|
| 57 |
boost::bind(&usrp1_impl::tx_dboard_set, this, _1, _2));
|
| 58 |
|
| 59 |
} |
| 60 |
/***********************************************************************
|
| 61 |
* Helper functions
|
| 62 |
**********************************************************************/
|
| 63 |
//static int slot_to_i2c_addr (int slot)
|
| 64 |
//{
|
| 65 |
// switch (slot) {
|
| 66 |
// case SLOT_TX_A:
|
| 67 |
// return I2C_ADDR_TX_A;
|
| 68 |
// case SLOT_RX_A:
|
| 69 |
// return I2C_ADDR_RX_A;
|
| 70 |
// case SLOT_TX_B:
|
| 71 |
// return I2C_ADDR_TX_B;
|
| 72 |
// case SLOT_RX_B:
|
| 73 |
// return I2C_ADDR_RX_B;
|
| 74 |
// default:
|
| 75 |
// return -1;
|
| 76 |
// }
|
| 77 |
//}
|
| 78 |
|
| 79 |
|
| 80 |
/***********************************************************************
|
| 81 |
* RX Dboard Get
|
| 82 |
**********************************************************************/
|
| 83 |
void usrp1_impl::rx_dboard_get(const wax::obj &key_, wax::obj &val) |
| 84 |
{
|
| 85 |
wax::obj key; std::string name;
|
| 86 |
boost::tie(key, name) = extract_named_prop(key_); |
| 87 |
|
| 88 |
//handle the get request conditioned on the key
|
| 89 |
switch(key.as<dboard_prop_t>()){
|
| 90 |
case DBOARD_PROP_NAME:
|
| 91 |
val = std::string("usrp1 dboard (rx unit)"); |
| 92 |
return;
|
| 93 |
|
| 94 |
case DBOARD_PROP_SUBDEV:
|
| 95 |
val = _dboard_manager->get_rx_subdev(name); |
| 96 |
return;
|
| 97 |
|
| 98 |
case DBOARD_PROP_SUBDEV_NAMES:
|
| 99 |
val = _dboard_manager->get_rx_subdev_names(); |
| 100 |
return;
|
| 101 |
|
| 102 |
case DBOARD_PROP_DBOARD_ID:
|
| 103 |
val = _rx_db_eeprom.id; |
| 104 |
return;
|
| 105 |
|
| 106 |
case DBOARD_PROP_DBOARD_IFACE:
|
| 107 |
val = _dboard_iface; |
| 108 |
return;
|
| 109 |
|
| 110 |
case DBOARD_PROP_CODEC:
|
| 111 |
val = _rx_codec_proxy->get_link(); |
| 112 |
return;
|
| 113 |
|
| 114 |
case DBOARD_PROP_GAIN_GROUP:
|
| 115 |
val = make_gain_group(_dboard_manager->get_rx_subdev(name), |
| 116 |
_rx_codec_proxy->get_link()); |
| 117 |
return;
|
| 118 |
|
| 119 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/***********************************************************************
|
| 124 |
* RX Dboard Set
|
| 125 |
**********************************************************************/
|
| 126 |
void usrp1_impl::rx_dboard_set(const wax::obj &key, const wax::obj &val) |
| 127 |
{
|
| 128 |
switch(key.as<dboard_prop_t>()) {
|
| 129 |
case DBOARD_PROP_DBOARD_ID:
|
| 130 |
_rx_db_eeprom.id = val.as<dboard_id_t>(); |
| 131 |
_iface->write_eeprom(I2C_ADDR_RX_A, 0,
|
| 132 |
_rx_db_eeprom.get_eeprom_bytes()); |
| 133 |
return;
|
| 134 |
|
| 135 |
default:
|
| 136 |
UHD_THROW_PROP_SET_ERROR(); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
/***********************************************************************
|
| 141 |
* TX Dboard Get
|
| 142 |
**********************************************************************/
|
| 143 |
void usrp1_impl::tx_dboard_get(const wax::obj &key_, wax::obj &val) |
| 144 |
{
|
| 145 |
wax::obj key; std::string name;
|
| 146 |
boost::tie(key, name) = extract_named_prop(key_); |
| 147 |
|
| 148 |
//handle the get request conditioned on the key
|
| 149 |
switch(key.as<dboard_prop_t>()){
|
| 150 |
case DBOARD_PROP_NAME:
|
| 151 |
val = std::string("usrp1 dboard (tx unit)"); |
| 152 |
return;
|
| 153 |
|
| 154 |
case DBOARD_PROP_SUBDEV:
|
| 155 |
val = _dboard_manager->get_tx_subdev(name); |
| 156 |
return;
|
| 157 |
|
| 158 |
case DBOARD_PROP_SUBDEV_NAMES:
|
| 159 |
val = _dboard_manager->get_tx_subdev_names(); |
| 160 |
return;
|
| 161 |
|
| 162 |
case DBOARD_PROP_DBOARD_ID:
|
| 163 |
val = _tx_db_eeprom.id; |
| 164 |
return;
|
| 165 |
|
| 166 |
case DBOARD_PROP_DBOARD_IFACE:
|
| 167 |
val = _dboard_iface; |
| 168 |
return;
|
| 169 |
|
| 170 |
case DBOARD_PROP_CODEC:
|
| 171 |
val = _tx_codec_proxy->get_link(); |
| 172 |
return;
|
| 173 |
|
| 174 |
case DBOARD_PROP_GAIN_GROUP:
|
| 175 |
val = make_gain_group(_dboard_manager->get_tx_subdev(name), |
| 176 |
_tx_codec_proxy->get_link()); |
| 177 |
return;
|
| 178 |
|
| 179 |
default: UHD_THROW_PROP_GET_ERROR();
|
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
/***********************************************************************
|
| 184 |
* TX Dboard Set
|
| 185 |
**********************************************************************/
|
| 186 |
void usrp1_impl::tx_dboard_set(const wax::obj &key, const wax::obj &val) |
| 187 |
{
|
| 188 |
switch(key.as<dboard_prop_t>()) {
|
| 189 |
case DBOARD_PROP_DBOARD_ID:
|
| 190 |
_tx_db_eeprom.id = val.as<dboard_id_t>(); |
| 191 |
_iface->write_eeprom(I2C_ADDR_TX_A, 0, _tx_db_eeprom.get_eeprom_bytes());
|
| 192 |
return;
|
| 193 |
|
| 194 |
default: UHD_THROW_PROP_SET_ERROR();
|
| 195 |
} |
| 196 |
} |