root/ossiedev/branches/june/trunk/platform/USRP_UHD/src/USRP_UHD.h @ 11014

Revision 10608, 7.0 KB (checked in by drdepoy, 2 years ago)

UHD device for 0.8.2

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