common_lib.h 5.23 KB
Newer Older
1
/*******************************************************************************
2
    OpenAirInterface
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    Copyright(c) 1999 - 2014 Eurecom

    OpenAirInterface 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.


    OpenAirInterface 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
17 18
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
19 20 21 22 23 24
    see <http://www.gnu.org/licenses/>.

   Contact Information
   OpenAirInterface Admin: openair_admin@eurecom.fr
   OpenAirInterface Tech : openair_tech@eurecom.fr
   OpenAirInterface Dev  : openair4g-devel@eurecom.fr
25

ghaddab's avatar
ghaddab committed
26
   Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27 28

 *******************************************************************************/
29 30 31 32 33

/** common_lib.h
*
* Author: HongliangXU : hong-liang-xu@agilent.com
*/
Raymond Knopp's avatar
 
Raymond Knopp committed
34 35 36
#ifndef COMMON_LIB_H
#define COMMON_LIB_H
#include <stdint.h>
Raymond Knopp's avatar
 
Raymond Knopp committed
37 38 39 40 41

typedef int64_t openair0_timestamp;
typedef struct openair0_device_t openair0_device;
/* structrue holds the parameters to configure USRP devices
 */
Raymond Knopp's avatar
 
Raymond Knopp committed
42

43
#ifndef EXMIMO
44 45 46
#define MAX_CARDS 1
#endif

47
#define USRP_GAIN_OFFSET (56.0)  // 86 calibrated for USRP B210 @ 2.6 GHz to get equivalent RS EPRE in OAI to SMBV100 output
Raymond Knopp's avatar
 
Raymond Knopp committed
48

Raymond Knopp's avatar
 
Raymond Knopp committed
49 50 51 52 53
typedef enum {
  max_gain=0,med_gain,byp_gain
} rx_gain_t;


Raymond Knopp's avatar
 
Raymond Knopp committed
54
typedef struct {
55
  //! Module ID for this configuration
56
  int Mod_id;
57 58
  // device log level
  int log_level;
59
  //! the sample rate for both transmit and receive.
Raymond Knopp's avatar
 
Raymond Knopp committed
60
  double sample_rate;
61
  //! number of samples per RX/TX packet (USRP + Ethernet)
Raymond Knopp's avatar
Raymond Knopp committed
62
  int samples_per_packet;
63
  //! number of RX channels (=RX antennas)
Raymond Knopp's avatar
 
Raymond Knopp committed
64
  int rx_num_channels;
65
  //! number of TX channels (=TX antennas)
Raymond Knopp's avatar
 
Raymond Knopp committed
66
  int tx_num_channels;
67 68
  //! \brief Center frequency in Hz for RX.
  //! index: [0..rx_num_channels[
Raymond Knopp's avatar
 
Raymond Knopp committed
69
  double rx_freq[4];
70 71
  //! \brief Center frequency in Hz for TX.
  //! index: [0..rx_num_channels[ !!! see lte-ue.c:427 FIXME iterates over rx_num_channels
Raymond Knopp's avatar
 
Raymond Knopp committed
72
  double tx_freq[4];
73
  //! mode for rxgain (ExpressMIMO2)
Raymond Knopp's avatar
 
Raymond Knopp committed
74
  rx_gain_t rxg_mode[4];
75
  //! \brief Gain for RX in dB.
76
  //! index: [0..rx_num_channels]
Raymond Knopp's avatar
 
Raymond Knopp committed
77
  double rx_gain[4];
78
  //! gain for TX in dB
Raymond Knopp's avatar
 
Raymond Knopp committed
79
  double tx_gain[4];
80
  //! RX bandwidth in Hz
Raymond Knopp's avatar
 
Raymond Knopp committed
81
  double rx_bw;
82
  //! TX bandwidth in Hz
Raymond Knopp's avatar
 
Raymond Knopp committed
83
  double tx_bw;
84 85
  //! Auto calibration flag
  int autocal[4];
86
  //! RRH IP addr for Ethernet interface
Raymond Knopp's avatar
 
Raymond Knopp committed
87
  char *rrh_ip;
88
  //! RRH port number for Ethernet interface
89
  int rrh_port;
Raymond Knopp's avatar
 
Raymond Knopp committed
90 91
} openair0_config_t;

92 93 94 95 96 97 98 99 100
typedef struct {
  /* card id */
  int card;
  /* rf chain id */
  int chain;
} openair0_rf_map;



Raymond Knopp's avatar
 
Raymond Knopp committed
101
struct openair0_device_t {
102 103
  /* Module ID of this device */
  int Mod_id;
Raymond Knopp's avatar
 
Raymond Knopp committed
104

105 106
  /* RF frontend parameters set by application */
  openair0_config_t openair0_cfg;
107

Raymond Knopp's avatar
 
Raymond Knopp committed
108 109 110 111 112 113 114 115 116 117 118 119
  /* Can be used by driver to hold internal structure*/
  void *priv;

  /* Functions API, which are called by the application*/

  /* Called to start the transceiver. Return 0 if OK, < 0 if error */
  int (*trx_start_func)(openair0_device *device);

  /* Write 'nsamps' samples on each channel from buffers. buff[0] is the array for
   * the first channel. timestamp if the time (in samples) at which the first sample
   * MUST be sent
   * use flags = 1 to send as timestamp specfied*/
Raymond Knopp's avatar
Raymond Knopp committed
120
  void (*trx_write_func)(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags);
Raymond Knopp's avatar
 
Raymond Knopp committed
121

122 123
  /*! \brief Receive samples from hardware.
   * Read \ref nsamps samples from each channel to buffers. buff[0] is the array for
Raymond Knopp's avatar
 
Raymond Knopp committed
124 125
   * the first channel. *ptimestamp is the time at which the first sample
   * was received.
126 127 128 129 130 131 132
   * \param device the hardware to use
   * \param[out] ptimestamp the time at which the first sample was received.
   * \param[out] An array of pointers to buffers for received samples. The buffers must be large enough to hold the number of samples \ref nsamps.
   * \param nsamps Number of samples. One sample is 2 byte I + 2 byte Q => 4 byte.
   * \param cc Number of channels. If cc == 1, only buff[0] is filled with samples.
   * \returns the number of sample read
   */
Raymond Knopp's avatar
 
Raymond Knopp committed
133
  int (*trx_read_func)(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps,int cc);
Raymond Knopp's avatar
 
Raymond Knopp committed
134 135 136 137 138 139 140 141 142

  /* Terminate operation of the transceiver -- free all associated resources */
  void (*trx_end_func)(openair0_device *device);
};


#ifdef __cplusplus
extern "C"
{
143 144
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
145
/* return 0 if OK, < 0 if error */
146 147 148 149 150 151 152 153
  int openair0_device_init(openair0_device* device, openair0_config_t *openair0_cfg);
  openair0_timestamp get_usrp_time(openair0_device *device);
  int openair0_set_frequencies(openair0_device* device, openair0_config_t *openair0_cfg,int exmimo_dump_config);
  int openair0_set_rx_frequencies(openair0_device* device, openair0_config_t *openair0_cfg);
  
  int openair0_set_gains(openair0_device* device, openair0_config_t *openair0_cfg);
  
  int openair0_stop(int card);
154
#ifdef __cplusplus
Raymond Knopp's avatar
 
Raymond Knopp committed
155 156 157
}
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
158
#endif // COMMON_LIB_H
159