if4_tools.c 7.92 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 26 27 28 29 30 31
/*******************************************************************************
    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@lists.eurecom.fr

  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE

 *******************************************************************************/

/*! \file PHY/LTE_TRANSPORT/if4_tools.c
* \brief 
32
* \author Fredrik Skretteberg, Tobias Schuster, Mauricio Gunther, S. Sandeep Kumar, Raymond Knopp
33 34 35
* \date 2016
* \version 0.1
* \company Eurecom
Sandeep Kumar's avatar
Sandeep Kumar committed
36
* \email: knopp@eurecom.fr 
37 38 39 40
* \note
* \warning
*/

Sandeep Kumar's avatar
Sandeep Kumar committed
41
#include <stdint.h>
42

43
#include "PHY/defs.h"
44
#include "PHY/LTE_TRANSPORT/if4_tools.h"
45
#include "PHY/TOOLS/ALAW/alaw_lut.h"
46

Sandeep Kumar's avatar
Sandeep Kumar committed
47
// Get device information
48 49
void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc) {
	LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
50 51 52 53 54
	int32_t **txdataF = eNB->common_vars.txdataF[0];
  
	uint16_t symbol_id, element_id;
  uint16_t db_fulllength = 12*fp->N_RB_DL;
  uint16_t db_halflength = db_fulllength>>1;
55
  int slotoffsetF = (proc->subframe_tx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
56 57 58
  int blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
  
  int16_t *data_block = (int16_t*)malloc(db_fulllength*sizeof(int16_t));  
59 60 61 62 63 64 65 66

  // Caller: RCC - DL *** handle RRU case - UL and PRACH *** 
  if (eNB->node_function == NGFI_RCC_IF4) {
    IF4_dl_packet_t *dl_packet = (IF4_dl_packet_t*)malloc(sizeof_IF4_dl_packet_t);
    gen_IF4_dl_packet(dl_packet, proc);
		
    dl_packet->data_block = data_block;

67
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
68 69
      
      printf("\n Send IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);
70

71 72
      // Do compression of the two parts and generate data blocks			
      for (element_id=0; element_id<db_halflength; element_id++) {
73 74
        data_block[element_id]  = lin2alaw[ (txdataF[0][blockoffsetF+element_id] & 0xffff) + 32768 ];          
        data_block[element_id] |= lin2alaw[ (txdataF[0][blockoffsetF+element_id]>>16) + 32768 ]<<8;  
75
        
76 77
        data_block[element_id+db_halflength]  = lin2alaw[ (txdataF[0][slotoffsetF+element_id] & 0xffff) + 32768 ];     
        data_block[element_id+db_halflength] |= lin2alaw[ (txdataF[0][slotoffsetF+element_id]>>16) + 32768 ]<<8;  
78 79
      }
				 		
80
      // Update information in generated packet
81
      dl_packet->frame_status.sym_num = symbol_id; 
82
			
Sandeep Kumar's avatar
Sandeep Kumar committed
83
      // Write the packet(s) to the fronthaul
84 85 86 87 88 89 90 91
    //  if ((bytes_sent = eNB->ifdevice.trx_write_func(&eNB->ifdevice,
    //                                                (proc->timestamp_tx-eNB->ifdevice.openair0_cfg.tx_sample_advance),
    //  			                                         dl_packet,
    //  			                                         eNB->frame_parms.samples_per_tti,
    //  			                                         eNB->frame_parms.nb_antennas_tx,
    //                                                 0)) < 0) {
    //    perror("RCC : ETHERNET write");
    //}
92 93 94
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
95 96 97 98 99 100 101
    }
  }else {
    IF4_ul_packet_t *ul_packet = (IF4_ul_packet_t*)malloc(sizeof_IF4_ul_packet_t);
    gen_IF4_ul_packet(ul_packet, proc);
		
    ul_packet->data_block = data_block;

102
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
103

104
      // Do compression of the two parts and generate data blocks	- rxdataF		
105
      for (element_id=0; element_id<db_halflength; element_id++) {
106 107
        data_block[element_id]  = lin2alaw[ (rxdataF[0][blockoffsetF+element_id] & 0xffff) + 32768 ];          
        data_block[element_id] |= lin2alaw[ (rxdataF[0][blockoffsetF+element_id]>>16) + 32768 ]<<8;  
108
        
109 110
        data_block[element_id+db_halflength]  = lin2alaw[ (txdataF[0][slotoffsetF+element_id] & 0xffff) + 32768 ];     
        data_block[element_id+db_halflength] |= lin2alaw[ (txdataF[0][slotoffsetF+element_id]>>16) + 32768 ]<<8;  
111 112
      }
       			
113
      // Update information in generated packet
114
      ul_packet->frame_status.sym_num = symbol_id; 
115 116 117
			
      // Write the packet(s) to the fronthaul 

118 119
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
120 121
    }		
	}
Sandeep Kumar's avatar
Sandeep Kumar committed
122
  		    
123
}
124

125
void recv_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t *packet_type, uint32_t *symbol_number) {
Sandeep Kumar's avatar
Sandeep Kumar committed
126

Sandeep Kumar's avatar
Sandeep Kumar committed
127 128
  // Caller: RRU - DL *** handle RCC case - UL and PRACH *** 
  if (eNB->node_function == NGFI_RRU_IF4) {
Sandeep Kumar's avatar
Sandeep Kumar committed
129
  
130 131
    printf("\n Recv IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);
  
132
//    for(i=0; i<fp->symbols_per_tti; i++) {  
Sandeep Kumar's avatar
Sandeep Kumar committed
133
      // Read packet(s) from the fronthaul    
134 135 136 137 138 139 140 141
//      if (dev->eth_dev.trx_read_func (&dev->eth_dev,
//                                      timestamp_rx,
//                                    rx_eNB,
//                                      spp_eth,
//                                      dev->eth_dev.openair0_cfg->rx_num_channels
//                                      ) < 0) {
//        perror("RRU : ETHERNET read");
//      }
Sandeep Kumar's avatar
Sandeep Kumar committed
142 143 144 145 146
      
      // Apply reverse processing - decompression
      // txAlawtolinear( Datablock )
      
      // Generate and return the OFDM symbols (txdataF)
147 148
      //txDataF 
    //}
Sandeep Kumar's avatar
Sandeep Kumar committed
149 150 151
  }else {
    
  }  
152 153
}

154
void gen_IF4_dl_packet(IF4_dl_packet_t *dl_packet, eNB_rxtx_proc_t *proc) {      
Sandeep Kumar's avatar
Sandeep Kumar committed
155
  // Set Type and Sub-Type
156
  dl_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
157
  dl_packet->sub_type = IF4_PDLFFT;
Sandeep Kumar's avatar
Sandeep Kumar committed
158 159

  // Leave reserved as it is 
160
  dl_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
161 162
  
  // Set frame status
163 164 165 166 167 168 169
  dl_packet->frame_status.ant_num = 0;
  dl_packet->frame_status.ant_start = 0;
  dl_packet->frame_status.rf_num = proc->frame_tx;
  dl_packet->frame_status.sf_num = proc->subframe_tx;
  dl_packet->frame_status.sym_num = 0;
  dl_packet->frame_status.rsvd = 0;

Sandeep Kumar's avatar
Sandeep Kumar committed
170
  // Set frame check sequence
171
  dl_packet->fcs = 0;
172 173
}

174
void gen_IF4_ul_packet(IF4_ul_packet_t *ul_packet, eNB_rxtx_proc_t *proc) {  
Sandeep Kumar's avatar
Sandeep Kumar committed
175
  // Set Type and Sub-Type
176
  ul_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
177
  ul_packet->sub_type = IF4_PULFFT;
Sandeep Kumar's avatar
Sandeep Kumar committed
178 179

  // Leave reserved as it is 
180
  ul_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
181 182
  
  // Set frame status
183 184 185 186 187 188 189 190 191 192
  ul_packet->frame_status.ant_num = 0;
  ul_packet->frame_status.ant_start = 0;
  ul_packet->frame_status.rf_num = proc->frame_rx;
  ul_packet->frame_status.sf_num = proc->subframe_rx;
  ul_packet->frame_status.sym_num = 0;
  ul_packet->frame_status.rsvd = 0;
    
  // Set antenna specific gain *** set other antenna gain ***
  ul_packet->gain0.exponent = 0;
  ul_packet->gain0.rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
193 194
    
  // Set frame check sequence
195
  ul_packet->fcs = 0;
196 197
}

198
void gen_IF4_prach_packet(IF4_prach_packet_t *prach_packet, eNB_rxtx_proc_t *proc) {
Sandeep Kumar's avatar
Sandeep Kumar committed
199
  // Set Type and Sub-Type
200
  prach_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
201
  prach_packet->sub_type = IF4_PRACH;
Sandeep Kumar's avatar
Sandeep Kumar committed
202 203

  // Leave reserved as it is 
204
  prach_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
205 206
  
  // Set LTE Prach configuration
207 208 209 210 211 212
  prach_packet->prach_conf.rsvd = 0;
  prach_packet->prach_conf.ant = 0;
  prach_packet->prach_conf.rf_num = proc->frame_rx;
  prach_packet->prach_conf.sf_num = proc->subframe_rx;
  prach_packet->prach_conf.exponent = 0;  
        
Sandeep Kumar's avatar
Sandeep Kumar committed
213
  // Set frame check sequence
214
  prach_packet->fcs = 0;
215
}