common_lib.h 9.55 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
    see <http://www.gnu.org/licenses/>.

   Contact Information
   OpenAirInterface Admin: openair_admin@eurecom.fr
   OpenAirInterface Tech : openair_tech@eurecom.fr
24
   OpenAirInterface Dev  : openair4g-devel@lists.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 34 35 36 37 38
/*! \file common_lib.h 
 * \brief common APIs for different RF frontend device 
 * \author HongliangXU, Navid Nikaein
 * \date 2015
 * \version 0.2
 * \company Eurecom
 * \maintainer:  navid.nikaein@eurecom.fr
 * \note
 * \warning
 */
39

Raymond Knopp's avatar
 
Raymond Knopp committed
40 41 42
#ifndef COMMON_LIB_H
#define COMMON_LIB_H
#include <stdint.h>
43
#include <sys/types.h>
Raymond Knopp's avatar
 
Raymond Knopp committed
44 45

typedef int64_t openair0_timestamp;
46
typedef volatile int64_t openair0_vtimestamp;
47

48 49
 
/* structrue holds the parameters to configure USRP devices*/
Raymond Knopp's avatar
 
Raymond Knopp committed
50
typedef struct openair0_device_t openair0_device;
51

Raymond Knopp's avatar
 
Raymond Knopp committed
52

53
#ifndef EXMIMO
54 55 56
#define MAX_CARDS 1
#endif

57
//#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
58

Raymond Knopp's avatar
 
Raymond Knopp committed
59 60 61 62
typedef enum {
  max_gain=0,med_gain,byp_gain
} rx_gain_t;

63 64 65 66
/** @addtogroup _PHY_RF_INTERFACE_
 * @{
 */
 
67 68 69 70 71 72
typedef struct {
  //! Frequency for which RX chain was calibrated
  double freq;
  //! Offset to be applied to RX gain
  double offset;
} rx_gain_calib_table_t;
Raymond Knopp's avatar
 
Raymond Knopp committed
73

Raymond Knopp's avatar
 
Raymond Knopp committed
74
typedef struct {
75
  //! Module ID for this configuration
76
  int Mod_id;
77 78
  // device log level
  int log_level;
79 80 81 82
  //! number of downlink resource blocks
  int num_rb_dl;
  //! number of samples per frame 
  unsigned int  samples_per_frame;
83
  //! the sample rate for both transmit and receive.
Raymond Knopp's avatar
 
Raymond Knopp committed
84
  double sample_rate;
85
  //! number of samples per RX/TX packet (USRP + Ethernet)
Raymond Knopp's avatar
Raymond Knopp committed
86
  int samples_per_packet;
87
  // delay in sending samples (write)  due to hardware access, softmodem processing and fronthaul delay if exist
88
  int tx_delay;
89 90
  //! adjust the position of the samples after delay when sending   
  unsigned int	tx_forward_nsamps;
91
  //! number of RX channels (=RX antennas)
Raymond Knopp's avatar
 
Raymond Knopp committed
92
  int rx_num_channels;
93
  //! number of TX channels (=TX antennas)
Raymond Knopp's avatar
 
Raymond Knopp committed
94
  int tx_num_channels;
95 96
  //! \brief Center frequency in Hz for RX.
  //! index: [0..rx_num_channels[
Raymond Knopp's avatar
 
Raymond Knopp committed
97
  double rx_freq[4];
98 99
  //! \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
100
  double tx_freq[4];
101
  //! mode for rxgain (ExpressMIMO2) 
Raymond Knopp's avatar
 
Raymond Knopp committed
102
  rx_gain_t rxg_mode[4];
103
  //! \brief Gain for RX in dB.
104
  //! index: [0..rx_num_channels]
Raymond Knopp's avatar
 
Raymond Knopp committed
105
  double rx_gain[4];
106 107 108
  //! \brief Gain offset (for calibration) in dB
  //! index: [0..rx_num_channels]
  double rx_gain_offset[4];
109
  //! gain for TX in dB
Raymond Knopp's avatar
 
Raymond Knopp committed
110
  double tx_gain[4];
111
  //! RX bandwidth in Hz
Raymond Knopp's avatar
 
Raymond Knopp committed
112
  double rx_bw;
113
  //! TX bandwidth in Hz
Raymond Knopp's avatar
 
Raymond Knopp committed
114
  double tx_bw;
115 116
  //! Auto calibration flag
  int autocal[4];
117
  //! RRH IP addr for Ethernet interface
118
  char *remote_ip;
119
  //! RRH port number for Ethernet interface
120 121 122 123 124 125
  int remote_port;
  //! my IP addr for Ethernet interface (eNB/BBU, UE)
  char *my_ip;
  //! my port number for Ethernet interface (eNB/BBU, UE)
  int my_port;

Raymond Knopp's avatar
 
Raymond Knopp committed
126 127
} openair0_config_t;

128 129 130 131 132 133 134 135 136
typedef struct {
  /* card id */
  int card;
  /* rf chain id */
  int chain;
} openair0_rf_map;



137 138 139 140 141 142 143
/*!\brief interface types that apply to modules (RRH_BBU/RRH_UE) created in RRH (rrh_gw.c)
          and are defined with respect to the RF device that is present in RRH
          -RRH_BBU modules have two devices, one is by default ETHERNET (will have ETH_IF) and the other one is a
	  RF device (EXMIMO,USRP,BLADERF) or no device (NONE_IF).
          -RRH_UE modules have two devices one is by default ETHERNET (will have ETH_IF) 
	  and the other one by default not present so it will have NONE_IF
 */
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
typedef enum {
  MIN_DEV_TYPE = 0,
  /*!\brief device is ETH */
  ETH_IF,
  /*!\brief device is ExpressMIMO */
  EXMIMO_IF,
  /*!\brief device is USRP*/
  USRP_IF,
  /*!\brief device is BLADE RF*/
  BLADERF_IF,
  /*!\brief device is NONE*/
  NONE_IF,
  MAX_DEV_TYPE

} dev_type_t;

160

161
/*!\brief  openair0 device host type */
162 163
typedef enum {
  MIN_FUNC_TYPE = 0,
164
 /*!\brief device functions within a BBU */
165
  BBU_FUNC,
166
 /*!\brief device functions within a RRH */
167 168 169 170 171
  RRH_FUNC,
  MAX_FUNC_TYPE

}func_type_t;

Raymond Knopp's avatar
 
Raymond Knopp committed
172
struct openair0_device_t {
173 174
  /* Module ID of this device */
  int Mod_id;
175 176 177 178
  
  /* Type of this device */
  dev_type_t type;

179 180 181
   /* Type of the device's host (BBU/RRH) */
  func_type_t func_type;

182 183
  /* RF frontend parameters set by application */
  openair0_config_t openair0_cfg;
184

Raymond Knopp's avatar
 
Raymond Knopp committed
185 186 187 188 189
  /* Can be used by driver to hold internal structure*/
  void *priv;

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

190 191 192
  /*! \brief Called to start the transceiver. Return 0 if OK, < 0 if error
      @param device pointer to the device structure specific to the RF hardware target
  */
Raymond Knopp's avatar
 
Raymond Knopp committed
193 194
  int (*trx_start_func)(openair0_device *device);

195 196 197 198 199
  /*! \brief Called to send a request message between BBU-RRH
      @param device pointer to the device structure specific to the RF hardware target
      @param msg pointer to the message structure passed between BBU-RRH
      @param msg_len length of the message  
  */  
200
  int (*trx_request_func)(openair0_device *device, void *msg, ssize_t msg_len);
201

202 203 204 205 206
  /*! \brief Called to send a reply  message between BBU-RRH
      @param device pointer to the device structure specific to the RF hardware target
      @param msg pointer to the message structure passed between BBU-RRH
      @param msg_len length of the message  
  */  
207
  int (*trx_reply_func)(openair0_device *openair0, void *msg, ssize_t msg_len);
208

209 210 211 212 213 214 215 216
  /*! \brief Called to send samples to the RF target
      @param device pointer to the device structure specific to the RF hardware target
      @param timestamp The timestamp at whicch the first sample MUST be sent 
      @param buff Buffer which holds the samples
      @param nsamps number of samples to be sent
      @param antenna_id index of the antenna if the device has multiple anteannas
      @param flags flags must be set to TRUE if timestamp parameter needs to be applied
  */   
217
  int (*trx_write_func)(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps,int antenna_id, int flags);
Raymond Knopp's avatar
 
Raymond Knopp committed
218

219 220
  /*! \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
221 222
   * the first channel. *ptimestamp is the time at which the first sample
   * was received.
223 224 225 226 227 228 229
   * \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
   */
230 231 232 233 234 235 236 237 238 239 240 241 242
  int (*trx_read_func)(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps,int antenna_id);

  /*! \brief print the device statistics  
   * \param device the hardware to use
   * \returns  0 on success
   */
  int (*trx_get_stats_func)(openair0_device *device);

  /*! \brief Reset device statistics  
   * \param device the hardware to use
   * \returns 0 in success 
   */
  int (*trx_reset_stats_func)(openair0_device *device);
Raymond Knopp's avatar
 
Raymond Knopp committed
243

244
  /*! \brief Terminate operation of the transceiver -- free all associated resources */
Raymond Knopp's avatar
 
Raymond Knopp committed
245
  void (*trx_end_func)(openair0_device *device);
246 247 248 249 250 251 252 253 254 255 256

  /* Terminate operation  */
  int (*trx_stop_func)(int card);

  /* Functions API related to UE*/

  /*! \brief Set RX feaquencies 
   * \param 
   * \returns 0 in success 
   */
  int (*trx_set_freq_func)(openair0_device* device, openair0_config_t *openair0_cfg,int exmimo_dump_config);
257
  
258 259 260 261 262 263
  /*! \brief Set gains
   * \param 
   * \returns 0 in success 
   */
  int (*trx_set_gains_func)(openair0_device* device, openair0_config_t *openair0_cfg);

Raymond Knopp's avatar
 
Raymond Knopp committed
264 265 266 267 268 269
};


#ifdef __cplusplus
extern "C"
{
270 271
#endif

272
/*! \brief Initialize Openair RF target. It returns 0 if OK */
273 274 275
  int openair0_device_init(openair0_device* device, openair0_config_t *openair0_cfg);
  
  //USRP
276
/*! \brief Get the current timestamp of USRP */
277
  openair0_timestamp get_usrp_time(openair0_device *device);
278
/*! \brief Set the RX frequency of USRP RF TARGET */
279 280 281 282 283 284 285 286
  int openair0_set_rx_frequencies(openair0_device* device, openair0_config_t *openair0_cfg);
  
//extern
/*! \brief Initialize Openair ETHERNET target. It returns 0 if OK */
  int openair0_dev_init_eth(openair0_device *device, openair0_config_t *openair0_cfg);
  int openair0_dev_init_bladerf(openair0_device *device, openair0_config_t *openair0_cfg);
  int openair0_dev_init_usrp(openair0_device* device, openair0_config_t *openair0_cfg);
  int openair0_dev_init_exmimo(openair0_device *device, openair0_config_t *openair0_cfg);
287
/*@}*/
288

289
#ifdef __cplusplus
Raymond Knopp's avatar
 
Raymond Knopp committed
290 291 292
}
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
293
#endif // COMMON_LIB_H
294