if4_tools.c 12.1 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
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

47
// --- Careful to handle buffer memory --- RAW/UDP modes --- PRACH variables and data
48
void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t packet_type) {
49 50
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
51
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
52 53
  int16_t *prachF = eNB->prach_vars.prachF;  
      
54
  uint16_t symbol_id, element_id;
55
  uint16_t db_fulllength, db_halflength; 
56 57
  int slotoffsetF, blockoffsetF; 

58
  void *tx_buffer=NULL;
59
  int16_t *data_block=NULL;
60

61
  if (packet_type == IF4_PDLFFT) {
62 63
    db_fulllength = 12*fp->N_RB_DL;
    db_halflength = (db_fulllength)>>1;
64 65
    slotoffsetF = (proc->subframe_tx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
66

67 68 69
    tx_buffer = malloc(/*SIZE_OF_MAC_BYTES +*/ sizeof_IF4_dl_header_t + db_fulllength*sizeof(int16_t));
    IF4_dl_header_t *dl_header = (IF4_dl_header_t *)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/);
    data_block = (int16_t*)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/ + sizeof_IF4_dl_header_t);
70

71 72 73
    gen_IF4_dl_header(dl_header, proc);
		    
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
74 75
      // Do compression of the two parts and generate data blocks			
      for (element_id=0; element_id<db_halflength; element_id++) {
76 77
        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;  
78
        
79 80
        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;  
81 82
      }
				 		
83
      // Update information in generated packet
84
      dl_header->frame_status.sym_num = symbol_id; 
85
			
86
      // Write the packet to the fronthaul
87
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
88 89 90 91 92 93
                                        symbol_id,
                                        tx_buffer,
                                        db_fulllength,
      			                            1,
                                        IF4_PDLFFT)) < 0) {
        perror("ETHERNET write for IF4_PDLFFT\n");
94
      }
95 96 97
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
98
    }
99
  } else if (packet_type == IF4_PULFFT) {
100 101
    db_fulllength = 12*fp->N_RB_UL;
    db_halflength = (db_fulllength)>>1;
102 103
    slotoffsetF = (proc->subframe_rx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
104

105 106 107 108 109
    tx_buffer = malloc(/*SIZE_OF_MAC_BYTES +*/ sizeof_IF4_dl_header_t + db_fulllength*sizeof(int16_t));
    IF4_ul_header_t *ul_header = (IF4_ul_header_t *)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/);
    data_block = (int16_t*)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/ + sizeof_IF4_ul_header_t);

    gen_IF4_ul_header(ul_header, proc);
110

111
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
112
      // Do compression of the two parts and generate data blocks - rxdataF		
113
      for (element_id=0; element_id<db_halflength; element_id++) {
114 115
        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;  
116
        
117 118
        data_block[element_id+db_halflength]  = lin2alaw[ (rxdataF[0][slotoffsetF+element_id] & 0xffff) + 32768 ];     
        data_block[element_id+db_halflength] |= lin2alaw[ (rxdataF[0][slotoffsetF+element_id]>>16) + 32768 ]<<8;  
119 120
      }
       			
121
      // Update information in generated packet
122
      ul_header->frame_status.sym_num = symbol_id; 
123 124
			
      // Write the packet(s) to the fronthaul 
125 126 127 128 129 130 131 132
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                        symbol_id,
                                        tx_buffer,
                                        db_fulllength,
      			                            1,
                                        IF4_PULFFT)) < 0) {
        perror("ETHERNET write for IF4_PULFFT\n");
      }
133

134 135
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
136
    }		
137
  } else if (packet_type == IF4_PRACH) {
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
    // FIX: hard coded prach samples length
    db_fulllength = 839;
    slotoffsetF = (proc->subframe_tx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;

    tx_buffer = malloc(/*SIZE_OF_MAC_BYTES +*/ sizeof_IF4_prach_header_t + db_fulllength*sizeof(int16_t));
    IF4_prach_header_t *prach_header = (IF4_prach_header_t *)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/);
    data_block = (int16_t*)(tx_buffer /*+ MAC_HEADER_SIZE_BYTES*/ + sizeof_IF4_prach_header_t);

    gen_IF4_prach_header(prach_header, proc);
		    
    // Do compression and generate data blocks			
    for (element_id=0; element_id<db_fulllength; element_id++) {
      data_block[element_id]  = lin2alaw[ (prachF[blockoffsetF+element_id] & 0xffff) + 32768 ];          
      data_block[element_id] |= lin2alaw[ (prachF[blockoffsetF+element_id]>>16) + 32768 ]<<8;  
    }
              
    // Write the packet to the fronthaul
    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                      symbol_id,
                                      tx_buffer,
                                      db_fulllength,
                                      1,
                                      IF4_PRACH)) < 0) {
      perror("ETHERNET write for IF4_PRACH\n");
    }      
163 164 165 166
  } else {    
    AssertFatal(1==0, "send_IF4 - Unknown packet_type %x", packet_type);     
  }
  
167
  free(tx_buffer);
168
  return;  		    
169
}
170

171
void recv_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t *packet_type, uint32_t *symbol_number) {
172 173 174 175 176 177 178
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];

  uint16_t element_id;
  uint16_t db_halflength; 
  int slotoffsetF, blockoffsetF; 
179

180
  *packet_type = 0;
181
  void *rx_buffer=NULL;
182
  int16_t *data_block=NULL;
183 184
   
  // Read packet(s) from the fronthaul    
185
  if (eNB->ifdevice.trx_read_func(&eNB->ifdevice,
186
                                  symbol_number,
187 188 189
                                  rx_buffer,
                                  0,
                                  0) < 0) {
190 191 192
    perror("ETHERNET read");
  }

193
  packet_type = (uint16_t*) (rx_buffer+2);  
194 195
  
  if (*packet_type == IF4_PDLFFT) {
196
    data_block = (int16_t*) (rx_buffer+sizeof_IF4_dl_header_t);
197
      
198 199 200 201 202
    db_halflength = (12*fp->N_RB_DL)>>1;
    
    // Calculate from received packet
    slotoffsetF = (proc->subframe_tx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
203
    
204 205 206 207 208 209 210 211 212 213 214 215 216 217
    data_block = (int16_t*)malloc(db_halflength*sizeof(int16_t));

    // Do decompression of the two parts and generate data blocks			
    for (element_id=0; element_id<db_halflength; element_id++) {
      txdataF[0][blockoffsetF+element_id]  = alaw2lin[ (data_block[element_id] & 0xff) ];
      txdataF[0][blockoffsetF+element_id] |= alaw2lin[ (data_block[element_id]>>8) ]<<16;

      txdataF[0][slotoffsetF+element_id]  = alaw2lin[ (data_block[element_id+db_halflength] & 0xff) ];
      txdataF[0][slotoffsetF+element_id] |= alaw2lin[ (data_block[element_id+db_halflength]>>8) ]<<16;
    }
		
    // Find and return symbol_number		 		
    *symbol_number = 0;      
        
218
  } else if (*packet_type == IF4_PULFFT) {
219
    data_block = (int16_t*) (rx_buffer+sizeof_IF4_ul_header_t);
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
      
    db_halflength = (12*fp->N_RB_UL)>>1;
    
    // Calculate from received packet
    slotoffsetF = (proc->subframe_rx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
    
    data_block = (int16_t*)malloc(db_halflength*sizeof(int16_t));

    // Do decompression of the two parts and generate data blocks			
    for (element_id=0; element_id<db_halflength; element_id++) {
      rxdataF[0][blockoffsetF+element_id]  = alaw2lin[ (data_block[element_id] & 0xff) ];
      rxdataF[0][blockoffsetF+element_id] |= alaw2lin[ (data_block[element_id]>>8) ]<<16;

      rxdataF[0][slotoffsetF+element_id]  = alaw2lin[ (data_block[element_id+db_halflength] & 0xff) ];
      rxdataF[0][slotoffsetF+element_id] |= alaw2lin[ (data_block[element_id+db_halflength]>>8) ]<<16;
    }
		
    // Find and return symbol_number		 		
    *symbol_number = 0;      
240 241
    
  } else if (*packet_type == IF4_PRACH) {
242
    data_block = (int16_t*) (rx_buffer+sizeof_IF4_prach_header_t);
243 244 245 246
       
  } else {
    AssertFatal(1==0, "recv_IF4 - Unknown packet_type %x", *packet_type);            
  }
247 248
  
  free(rx_buffer);
249
  return;   
250 251
}

252
void gen_IF4_dl_header(IF4_dl_header_t *dl_packet, eNB_rxtx_proc_t *proc) {      
253
  // Set Type and Sub-Type
254
  dl_packet->type = IF4_PACKET_TYPE; 
255
  dl_packet->sub_type = IF4_PDLFFT;
256 257

  // Leave reserved as it is 
258
  dl_packet->rsvd = 0;
259 260
  
  // Set frame status
261 262 263 264 265 266 267
  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;

268
  // Set frame check sequence
269

270 271
}

272
void gen_IF4_ul_header(IF4_ul_header_t *ul_packet, eNB_rxtx_proc_t *proc) {  
273
  // Set Type and Sub-Type
274
  ul_packet->type = IF4_PACKET_TYPE; 
275
  ul_packet->sub_type = IF4_PULFFT;
276 277

  // Leave reserved as it is 
278
  ul_packet->rsvd = 0;
279 280
  
  // Set frame status
281 282 283 284 285 286 287 288 289 290
  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;
291 292
    
  // Set frame check sequence
293

294 295
}

296
void gen_IF4_prach_header(IF4_prach_header_t *prach_packet, eNB_proc_t *proc) {
297
  // Set Type and Sub-Type
298
  prach_packet->type = IF4_PACKET_TYPE; 
299
  prach_packet->sub_type = IF4_PRACH;
300 301

  // Leave reserved as it is 
302
  prach_packet->rsvd = 0;
303 304
  
  // Set LTE Prach configuration
305 306 307 308 309 310
  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;  
        
311
  // Set frame check sequence
312

313
}