| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE USRP_UHD Device. |
|---|
| 6 | |
|---|
| 7 | OSSIE USRP_UHD Device is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE USRP_UHD Device is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE USRP_UHD Device; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | ****************************************************************************/ |
|---|
| 23 | |
|---|
| 24 | #include <vector> |
|---|
| 25 | #include <complex> |
|---|
| 26 | #include <omnithread.h> |
|---|
| 27 | #include <string.h> //Just for debug |
|---|
| 28 | #include <stdexcept> //Just for debug |
|---|
| 29 | #include <fstream> |
|---|
| 30 | |
|---|
| 31 | #include <uhd/usrp/multi_usrp.hpp> |
|---|
| 32 | #include <uhd/property_tree.hpp> |
|---|
| 33 | #include <uhd/usrp/dboard_id.hpp> |
|---|
| 34 | #include <uhd/usrp/mboard_eeprom.hpp> |
|---|
| 35 | #include <uhd/usrp/subdev_spec.hpp> |
|---|
| 36 | #include <uhd/usrp/dboard_eeprom.hpp> |
|---|
| 37 | #include <uhd/usrp/dboard_manager.hpp> |
|---|
| 38 | |
|---|
| 39 | #include "ossie/cf.h" |
|---|
| 40 | #include "ossie/PortTypes.h" |
|---|
| 41 | |
|---|
| 42 | #include "standardinterfaces/complexShort_u.h" |
|---|
| 43 | #include "standardinterfaces/complexShort_p.h" |
|---|
| 44 | #include "standardinterfaces/Radio_Control_p.h" |
|---|
| 45 | |
|---|
| 46 | #include "ossie/Device_impl.h" |
|---|
| 47 | |
|---|
| 48 | #define DAC_RATE 100e6 |
|---|
| 49 | #define ADC_RATE 100e6 |
|---|
| 50 | #define USRP_UHD_MAX_TX_SAMPLES 4192 |
|---|
| 51 | #define MAX_TX_CHANNEL 2 |
|---|
| 52 | #define MAX_RX_CHANNEL 2 |
|---|
| 53 | |
|---|
| 54 | // Definitions for provides ports |
|---|
| 55 | class USRP_UHD_i; |
|---|
| 56 | |
|---|
| 57 | class USRP_UHD_RX_Control_i : public standardInterfaces_i::RX_Control_p, |
|---|
| 58 | boost::noncopyable |
|---|
| 59 | { |
|---|
| 60 | public: |
|---|
| 61 | USRP_UHD_RX_Control_i(USRP_UHD_i *_usrp_uhd, const char* _name, const char* _domain); |
|---|
| 62 | |
|---|
| 63 | void set_number_of_channels(CORBA::ULong num); |
|---|
| 64 | void get_number_of_channels(CORBA::ULong &num); |
|---|
| 65 | void get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, |
|---|
| 66 | CORBA::Float &gmax, CORBA::Float &gstep); |
|---|
| 67 | void set_gain(CORBA::ULong channel, CORBA::Float gain); |
|---|
| 68 | void get_gain(CORBA::ULong channel, CORBA::Float &gain); |
|---|
| 69 | void get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, |
|---|
| 70 | CORBA::Float &fmax, CORBA::Float &fstep); |
|---|
| 71 | void set_frequency(CORBA::ULong channel, CORBA::Float f); |
|---|
| 72 | void get_frequency(CORBA::ULong channel, CORBA::Float &f); |
|---|
| 73 | |
|---|
| 74 | void start(CORBA::ULong channel); |
|---|
| 75 | void stop(CORBA::ULong channel); |
|---|
| 76 | |
|---|
| 77 | void set_values(const CF::Properties &values); |
|---|
| 78 | void set_decimation_rate(CORBA::ULong channel, CORBA::ULong M); |
|---|
| 79 | void get_decimation_range(CORBA::ULong channel, CORBA::ULong &dmin, |
|---|
| 80 | CORBA::ULong &dmax, CORBA::ULong &dstep); |
|---|
| 81 | void set_data_packet_size(CORBA::ULong channel, CORBA::ULong N); |
|---|
| 82 | |
|---|
| 83 | private: |
|---|
| 84 | USRP_UHD_RX_Control_i(); // No default constructor |
|---|
| 85 | USRP_UHD_i *usrp_uhd; |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | class USRP_UHD_TX_Control_i : public standardInterfaces_i::TX_Control_p, |
|---|
| 89 | boost::noncopyable |
|---|
| 90 | { |
|---|
| 91 | public: |
|---|
| 92 | USRP_UHD_TX_Control_i(USRP_UHD_i *_usrp_uhd, const char* _name, const char* _domain); |
|---|
| 93 | |
|---|
| 94 | void set_number_of_channels(CORBA::ULong num); |
|---|
| 95 | void get_number_of_channels(CORBA::ULong &num); |
|---|
| 96 | void get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, |
|---|
| 97 | CORBA::Float &gmax, CORBA::Float &gstep); |
|---|
| 98 | void set_gain(CORBA::ULong channel, CORBA::Float gain); |
|---|
| 99 | void get_gain(CORBA::ULong channel, CORBA::Float &gain); |
|---|
| 100 | void get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, |
|---|
| 101 | CORBA::Float &fmax, CORBA::Float &fstep); |
|---|
| 102 | void set_frequency(CORBA::ULong channel, CORBA::Float f); |
|---|
| 103 | void get_frequency(CORBA::ULong channel, CORBA::Float &f); |
|---|
| 104 | |
|---|
| 105 | void start(CORBA::ULong channel); |
|---|
| 106 | void stop(CORBA::ULong channel); |
|---|
| 107 | |
|---|
| 108 | void set_values(const CF::Properties &values); |
|---|
| 109 | void set_interpolation_rate(CORBA::ULong channel, CORBA::ULong I); |
|---|
| 110 | void get_interpolation_range(CORBA::ULong channel, CORBA::ULong &imin, |
|---|
| 111 | CORBA::ULong &imax, CORBA::ULong &istep); |
|---|
| 112 | |
|---|
| 113 | private: |
|---|
| 114 | USRP_UHD_TX_Control_i(); // No default constructor |
|---|
| 115 | USRP_UHD_i *usrp_uhd; |
|---|
| 116 | }; |
|---|
| 117 | |
|---|
| 118 | class TX_data_i : public POA_standardInterfaces::complexShort |
|---|
| 119 | { |
|---|
| 120 | public: |
|---|
| 121 | TX_data_i(USRP_UHD_i *_usrp_uhd); |
|---|
| 122 | ~TX_data_i(); |
|---|
| 123 | |
|---|
| 124 | void pushPacket(const PortTypes::ShortSequence &I, |
|---|
| 125 | const PortTypes::ShortSequence &Q); |
|---|
| 126 | |
|---|
| 127 | private: |
|---|
| 128 | USRP_UHD_i *usrp_uhd; |
|---|
| 129 | |
|---|
| 130 | short *tx_buf; |
|---|
| 131 | unsigned int tx_buf_idx; |
|---|
| 132 | int tx_buf_len; |
|---|
| 133 | unsigned int tx_underruns; |
|---|
| 134 | }; |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | class USRP_UHD_i : public virtual Device_impl, boost::noncopyable |
|---|
| 139 | { |
|---|
| 140 | friend class USRP_UHD_RX_Control_i; |
|---|
| 141 | friend class USRP_UHD_TX_Control_i; |
|---|
| 142 | |
|---|
| 143 | public: |
|---|
| 144 | USRP_UHD_i(char *id, char *label, char *profile); |
|---|
| 145 | |
|---|
| 146 | static void do_rx_data_process(void *u) { |
|---|
| 147 | ((USRP_UHD_i *)u)->rx_data_process(); |
|---|
| 148 | }; |
|---|
| 149 | static void do_tx_data_process(void *u) { |
|---|
| 150 | ((USRP_UHD_i *)u)->tx_data_process(); |
|---|
| 151 | }; |
|---|
| 152 | |
|---|
| 153 | // Methods from the SCA definition |
|---|
| 154 | void start() |
|---|
| 155 | throw (CF::Resource::StartError, CORBA::SystemException); |
|---|
| 156 | void stop() |
|---|
| 157 | throw (CF::Resource::StopError, CORBA::SystemException); |
|---|
| 158 | CORBA::Object_ptr getPort(const char* portName) |
|---|
| 159 | throw(CF::PortSupplier::UnknownPort, CORBA::SystemException); |
|---|
| 160 | void initialize() |
|---|
| 161 | throw (CF::LifeCycle::InitializeError, CORBA::SystemException); |
|---|
| 162 | void configure(const CF::Properties &configProperties) |
|---|
| 163 | throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, |
|---|
| 164 | CF::PropertySet::PartialConfiguration); |
|---|
| 165 | void query(CF::Properties &configProperties) |
|---|
| 166 | throw (CORBA::SystemException, CF::UnknownProperties); |
|---|
| 167 | void releaseObject() |
|---|
| 168 | throw (CF::LifeCycle::ReleaseError, CORBA::SystemException); |
|---|
| 169 | |
|---|
| 170 | omni_mutex rx_run; |
|---|
| 171 | |
|---|
| 172 | // These mutex's protect port and usrp_uhd config operations |
|---|
| 173 | omni_mutex rx_control_access; |
|---|
| 174 | omni_mutex tx_control_access; |
|---|
| 175 | |
|---|
| 176 | private: |
|---|
| 177 | USRP_UHD_i(); // No default constructor |
|---|
| 178 | |
|---|
| 179 | // Port objects |
|---|
| 180 | USRP_UHD_RX_Control_i* rx_control_port; |
|---|
| 181 | USRP_UHD_TX_Control_i* tx_control_port; |
|---|
| 182 | |
|---|
| 183 | standardInterfaces_i::complexShort_u* rx_data_ports[MAX_RX_CHANNEL]; |
|---|
| 184 | standardInterfaces_i::complexShort_p* tx_data_ports[MAX_TX_CHANNEL]; |
|---|
| 185 | |
|---|
| 186 | // usrp_uhd variables |
|---|
| 187 | uhd::usrp::multi_usrp::sptr sdev; |
|---|
| 188 | uhd::device::sptr dev; |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | omni_thread *rx_thread; |
|---|
| 192 | omni_thread *tx_thread; |
|---|
| 193 | |
|---|
| 194 | void rx_error_helper(uhd::rx_metadata_t::error_code_t error); |
|---|
| 195 | void rx_data_process(); |
|---|
| 196 | void tx_data_process(); |
|---|
| 197 | void probe_usrp(); |
|---|
| 198 | |
|---|
| 199 | long set_rx_packet_count; |
|---|
| 200 | long rx_packet_count; ///< Number of packets to collect from USRP_UHD, -1 is forever |
|---|
| 201 | unsigned int rx_packet_size; ///< Number of samples to send to clients |
|---|
| 202 | unsigned int rx_data_size; ///< Size of words coming from USRP_UHD |
|---|
| 203 | unsigned int number_of_channels; |
|---|
| 204 | bool complex; ///< True for complex data from USRP_UHD |
|---|
| 205 | unsigned int rx_overruns; |
|---|
| 206 | unsigned int rx_missing; |
|---|
| 207 | |
|---|
| 208 | volatile bool rx_active; |
|---|
| 209 | volatile bool tx_active; |
|---|
| 210 | ///When full duplex mode is true the USRP2 will continue to load the Rx buffer when transmitting. |
|---|
| 211 | ///when full duplex mode is false the USRP2 will not load the Rx buffer when transmitting. |
|---|
| 212 | bool full_duplex; |
|---|
| 213 | bool did_rx; |
|---|
| 214 | |
|---|
| 215 | size_t mb_count; |
|---|
| 216 | size_t db_count; |
|---|
| 217 | size_t tx_channels; |
|---|
| 218 | size_t rx_channels; |
|---|
| 219 | |
|---|
| 220 | |
|---|
| 221 | }; |
|---|