common_lib.h 4.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*******************************************************************************
    OpenAirInterface 
    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
    along with OpenAirInterface.The full GNU General Public License is 
    included in this distribution in the file called "COPYING". If not, 
    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
  
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

 *******************************************************************************/
 
 /** common_lib.h
Raymond Knopp's avatar
 
Raymond Knopp committed
31 32 33
 *
 * 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 44 45 46
#ifdef USRP
#define MAX_CARDS 1
#endif

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


Raymond Knopp's avatar
 
Raymond Knopp committed
52 53 54 55 56 57 58 59
typedef struct {
  /* the sample rate for both transmit and receive. */
  double sample_rate;
  /* number of RX channels (=RX antennas) */
  int rx_num_channels;
  /* number of TX channels (=TX antennas) */
  int tx_num_channels;
  /* center frequency in Hz for RX */
Raymond Knopp's avatar
 
Raymond Knopp committed
60
  double rx_freq[4];
Raymond Knopp's avatar
 
Raymond Knopp committed
61
  /* center frequency in Hz for TX */
Raymond Knopp's avatar
 
Raymond Knopp committed
62 63 64
  double tx_freq[4];
  /* mode for rxgain (ExpressMIMO2)*/
  rx_gain_t rxg_mode[4];
Raymond Knopp's avatar
 
Raymond Knopp committed
65
  /* gain for RX in dB */
Raymond Knopp's avatar
 
Raymond Knopp committed
66
  double rx_gain[4];
Raymond Knopp's avatar
 
Raymond Knopp committed
67
  /* gain for TX in dB */
Raymond Knopp's avatar
 
Raymond Knopp committed
68
  double tx_gain[4];
Raymond Knopp's avatar
 
Raymond Knopp committed
69 70 71 72 73 74
  /* RX bandwidth in Hz */
  double rx_bw;
  /* TX bandwidth in Hz */
  double tx_bw;
} openair0_config_t;

75 76 77 78 79 80 81 82 83
typedef struct {
  /* card id */
  int card;
  /* rf chain id */
  int chain;
} openair0_rf_map;



Raymond Knopp's avatar
 
Raymond Knopp committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
struct openair0_device_t {
  /* USRP RF frontend parameters set by application */
  openair0_config_t openair0_cfg;

  /* 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*/
  void (*trx_write_func)(openair0_device *device, openair0_timestamp timestamp, const void *buff, int nsamps, int flags);

  /* Read 'nsamps' samples from each channel to buffers. buff[0] is the array for
   * the first channel. *ptimestamp is the time at which the first sample
   * was received.
   * Return the number of sample read */
  int (*trx_read_func)(openair0_device *device, openair0_timestamp *ptimestamp, void *buff, int nsamps);

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


#ifdef __cplusplus
extern "C"
{
/* return 0 if OK, < 0 if error */
int openair0_device_init(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
118
openair0_timestamp get_usrp_time(openair0_device *device);
Raymond Knopp's avatar
 
Raymond Knopp committed
119
  int openair0_set_frequencies(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
120 121

int openair0_set_gains(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
122
}
Raymond Knopp's avatar
 
Raymond Knopp committed
123 124
#else
int openair0_device_init(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
125
openair0_timestamp get_usrp_time(openair0_device *device);
Raymond Knopp's avatar
 
Raymond Knopp committed
126
int openair0_set_frequencies(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
127
int openair0_set_gains(openair0_device* device, openair0_config_t *openair0_cfg);
Raymond Knopp's avatar
 
Raymond Knopp committed
128 129
#endif

Raymond Knopp's avatar
 
Raymond Knopp committed
130
#endif // COMMON_LIB_H
Raymond Knopp's avatar
 
Raymond Knopp committed
131