if4_tools.c 13.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.0  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22 23

/*! \file PHY/LTE_TRANSPORT/if4_tools.c
* \brief 
24
* \author S. Sandeep Kumar, Raymond Knopp
25 26 27
* \date 2016
* \version 0.1
* \company Eurecom
28
* \email: ee13b1025@iith.ac.in, knopp@eurecom.fr 
29 30 31 32
* \note
* \warning
*/

33
#include "PHY/defs.h"
34
#include "PHY/TOOLS/alaw_lut.h"
35
#include "PHY/extern.h"
36
#include "SCHED/defs.h"
37

38 39
//#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
#include "targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.h"
40
#include "UTIL/LOG/vcd_signal_dumper.h"
41

42
void send_IF4p5(PHY_VARS_eNB *eNB, int frame, int subframe, uint16_t packet_type, int k) {
43
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
44 45 46
  int32_t **txdataF      = (eNB->CC_id==0) ? eNB->common_vars.txdataF[0] : PHY_vars_eNB_g[0][0]->common_vars.txdataF[0];
  int32_t **rxdataF      = eNB->common_vars.rxdataF[0];
  int16_t **rxsigF       = eNB->prach_vars.rxsigF;  
47
  void *tx_buffer        = eNB->ifbuffer.tx[subframe&1];
48
  void *tx_buffer_prach  = eNB->ifbuffer.tx_prach;
49
      
50
  uint16_t symbol_id=0, element_id=0;
51
  uint16_t db_fulllength, db_halflength; 
52
  int slotoffsetF=0, blockoffsetF=0; 
53

54
  uint16_t *data_block=NULL, *i=NULL;
55

56 57
  IF4p5_header_t *packet_header=NULL;
  eth_state_t *eth = (eth_state_t*) (eNB->ifdevice.priv);
58
  int nsym = fp->symbols_per_tti;
59 60
  
  if (eNB->CC_id==0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF4, 1 );   
61 62

  if (packet_type == IF4p5_PDLFFT) {
63 64 65
    if (subframe_select(fp,subframe)==SF_S)
      nsym=fp->dl_symbols_in_S_subframe;

66 67
    db_fulllength = 12*fp->N_RB_DL;
    db_halflength = (db_fulllength)>>1;
68
    slotoffsetF = (subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
69
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
70

71

72 73 74 75 76 77 78 79
    if (eth->flags == ETH_RAW_IF4p5_MODE) {
      packet_header = (IF4p5_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
      data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
    } else {
      packet_header = (IF4p5_header_t *)(tx_buffer);
      data_block = (uint16_t*)(tx_buffer + sizeof_IF4p5_header_t);
    }    
    gen_IF4p5_dl_header(packet_header, frame, subframe);
80
		    
81
    for (symbol_id=0; symbol_id<nsym; symbol_id++) {
82
      if (eNB->CC_id==1) LOG_I(PHY,"DL_IF4p5: CC_id %d : frame %d, subframe %d, symbol %d\n",eNB->CC_id,frame,subframe,symbol_id);
83
      
84
      for (element_id=0; element_id<db_halflength; element_id++) {
85
        i = (uint16_t*) &txdataF[eNB->CC_id][blockoffsetF+element_id];
86 87
        data_block[element_id] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);

88
        i = (uint16_t*) &txdataF[eNB->CC_id][slotoffsetF+element_id];
89
        data_block[element_id+db_halflength] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);        
90 91
      }
				 		
92 93
      packet_header->frame_status &= ~(0x000f<<26);
      packet_header->frame_status |= (symbol_id&0x000f)<<26; 
94
			
95
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
96
                                        symbol_id,
97
                                        &tx_buffer,
98 99
                                        db_fulllength,
      			                            1,
100 101
                                        IF4p5_PDLFFT)) < 0) {
        perror("ETHERNET write for IF4p5_PDLFFT\n");
102
      }
103 104 105
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
106
    }
107 108
  } else if ((packet_type == IF4p5_PULFFT)||
	     (packet_type == IF4p5_PULTICK)){
109 110
    db_fulllength = 12*fp->N_RB_UL;
    db_halflength = (db_fulllength)>>1;
Sandeep Kumar's avatar
Sandeep Kumar committed
111
    slotoffsetF = 1;
112
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
113

114 115 116 117 118 119
    if (subframe_select(fp,subframe)==SF_S) {
      nsym=fp->ul_symbols_in_S_subframe;
      slotoffsetF  += (fp->ofdm_symbol_size*(fp->symbols_per_tti-nsym));
      blockoffsetF += (fp->ofdm_symbol_size*(fp->symbols_per_tti-nsym));
    }

120 121 122 123 124 125 126
    if (eth->flags == ETH_RAW_IF4p5_MODE) {
      packet_header = (IF4p5_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
      data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
    } else {
      packet_header = (IF4p5_header_t *)(tx_buffer);
      data_block = (uint16_t*)(tx_buffer + sizeof_IF4p5_header_t);
    }
127 128 129
    gen_IF4p5_ul_header(packet_header, packet_type, frame, subframe);

    if (packet_type == IF4p5_PULFFT) {
130
      for (symbol_id=fp->symbols_per_tti-nsym; symbol_id<fp->symbols_per_tti; symbol_id++) {			
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
	LOG_D(PHY,"IF4p5_PULFFT: frame %d, subframe %d, symbol %d\n",frame,subframe,symbol_id);
	for (element_id=0; element_id<db_halflength; element_id++) {
	  i = (uint16_t*) &rxdataF[0][blockoffsetF+element_id];
	  data_block[element_id] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);
	  
	  i = (uint16_t*) &rxdataF[0][slotoffsetF+element_id];
	  data_block[element_id+db_halflength] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);        
	}
       	
	packet_header->frame_status &= ~(0x000f<<26);
	packet_header->frame_status |= (symbol_id&0x000f)<<26; 
	
	if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
					  symbol_id,
					  &tx_buffer,
					  db_fulllength,
					  1,
					  IF4p5_PULFFT)) < 0) {
	  perror("ETHERNET write for IF4p5_PULFFT\n");
	}
	
	slotoffsetF  += fp->ofdm_symbol_size;
	blockoffsetF += fp->ofdm_symbol_size;
      }    
    }
    else {
157
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
158 159 160
					0,
					&tx_buffer,
					0,
161
					1,
162 163
					IF4p5_PULTICK)) < 0) {
	perror("ETHERNET write for IF4p5_PULFFT\n");
164
      }
165
    }
166
  } else if (packet_type == IF4p5_PRACH) {
167
    // FIX: hard coded prach samples length
168
    LOG_D(PHY,"IF4p5_PRACH: frame %d, subframe %d\n",frame,subframe);
169 170
    db_fulllength = PRACH_HARD_CODED_NUM_SAMPLES;
    
171
    if (eth->flags == ETH_RAW_IF4p5_MODE) {
172
      packet_header = (IF4p5_header_t *)(tx_buffer_prach + MAC_HEADER_SIZE_BYTES);
173 174
      data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
    } else {
175 176
      packet_header = (IF4p5_header_t *)(tx_buffer_prach);
      data_block = (uint16_t*)(tx_buffer_prach + sizeof_IF4p5_header_t);
177 178 179 180
    }  
    gen_IF4p5_prach_header(packet_header, frame, subframe);

    if (eth->flags == ETH_RAW_IF4p5_MODE) {
181
      memcpy((int16_t*)(tx_buffer_prach + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t),
182
             (&rxsigF[0][k]), 
183
             PRACH_BLOCK_SIZE_BYTES);
184
    } else {
185
      memcpy((int16_t*)(tx_buffer_prach + sizeof_IF4p5_header_t),
186
             (&rxsigF[0][k]),
187
             PRACH_BLOCK_SIZE_BYTES);
188
    }
189 190

    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
191
                                      symbol_id,
192
                                      &tx_buffer_prach,
193 194
                                      db_fulllength,
                                      1,
195 196
                                      IF4p5_PRACH)) < 0) {
      perror("ETHERNET write for IF4p5_PRACH\n");
197
    }      
198
  } else {    
199
    AssertFatal(1==0, "send_IF4p5 - Unknown packet_type %x", packet_type);     
200
  }
201

202
  if (eNB->CC_id==0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF4, 0 );  
203
  return;  		    
204
}
205

206

207
void recv_IF4p5(PHY_VARS_eNB *eNB, int *frame, int *subframe, uint16_t *packet_type, uint32_t *symbol_number) {
208 209 210
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
211
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
212
  void *rx_buffer = eNB->ifbuffer.rx;
213 214

  uint16_t element_id;
215
  uint16_t db_fulllength, db_halflength; 
216
  int slotoffsetF=0, blockoffsetF=0; 
217
  eth_state_t *eth = (eth_state_t*) (eNB->ifdevice.priv);
218

219
  if (eNB->CC_id==0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 1 );   
220
  
221
  if (eNB->node_function == NGFI_RRU_IF4p5) {
222
    db_fulllength = (12*fp->N_RB_DL); 
223
  } else {
224
    db_fulllength = (12*fp->N_RB_UL);     
225 226 227
  }  
  db_halflength = db_fulllength>>1;

228
  IF4p5_header_t *packet_header=NULL;
229
  uint16_t *data_block=NULL, *i=NULL;
230
     
231
  if (eNB->ifdevice.trx_read_func(&eNB->ifdevice,
232
                                  (int64_t*) packet_type,
233 234
                                  &rx_buffer,
                                  db_fulllength,
235
                                  0) < 0) {
236 237
    perror("ETHERNET read");
  }
238 239 240 241 242 243 244 245

  if (eth->flags == ETH_RAW_IF4p5_MODE) {
    packet_header = (IF4p5_header_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES);
    data_block = (uint16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4p5_header_t);
  } else {
    packet_header = (IF4p5_header_t*) (rx_buffer);
    data_block = (uint16_t*) (rx_buffer+sizeof_IF4p5_header_t);
  }
246

wluhan's avatar
wluhan committed
247 248

  
249
  *frame = ((packet_header->frame_status)>>6)&0xffff;
250
  *subframe = ((packet_header->frame_status)>>22)&0x000f;
wluhan's avatar
wluhan committed
251

252
  *packet_type = packet_header->sub_type; 
Raymond Knopp's avatar
Raymond Knopp committed
253 254


255
  if (*packet_type == IF4p5_PDLFFT) {          
Sandeep Kumar's avatar
Sandeep Kumar committed
256 257
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         

258
    LOG_D(PHY,"DL_IF4p5: CC_id %d : frame %d, subframe %d, symbol %d\n",eNB->CC_id,*frame,*subframe,*symbol_number);
knopp's avatar
knopp committed
259

Sandeep Kumar's avatar
Sandeep Kumar committed
260
    slotoffsetF = (*symbol_number)*(fp->ofdm_symbol_size) + (*subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
261 262
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
        
263
    for (element_id=0; element_id<db_halflength; element_id++) {
264 265 266
      i = (uint16_t*) &txdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
267

268 269 270
      i = (uint16_t*) &txdataF[0][slotoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id+db_halflength] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id+db_halflength]>>8) ];
271
    }
Sandeep Kumar's avatar
Sandeep Kumar committed
272
		        
273
  } else if (*packet_type == IF4p5_PULFFT) {         
274
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         
Sandeep Kumar's avatar
Sandeep Kumar committed
275

276 277
    if (eNB->CC_id==1) LOG_I(PHY,"UL_IF4p5: CC_id %d : frame %d, subframe %d, symbol %d\n",eNB->CC_id,*frame,*subframe,*symbol_number);

Sandeep Kumar's avatar
Sandeep Kumar committed
278
    slotoffsetF = (*symbol_number)*(fp->ofdm_symbol_size) + 1;
279
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
280 281
    
    for (element_id=0; element_id<db_halflength; element_id++) {
282 283 284
      i = (uint16_t*) &rxdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
285

286 287 288
      i = (uint16_t*) &rxdataF[0][slotoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id+db_halflength] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id+db_halflength]>>8) ];
289 290
    }
		
291
  } else if (*packet_type == IF4p5_PRACH) {    
knopp's avatar
knopp committed
292 293
    if (eNB->CC_id==1) LOG_I(PHY,"PRACH_IF4p5: CC_id %d : frame %d, subframe %d, symbol %d\n",eNB->CC_id,*frame,*subframe);

294
    // FIX: hard coded prach samples length
295
    db_fulllength = PRACH_HARD_CODED_NUM_SAMPLES;
296 297 298 299

    if (eth->flags == ETH_RAW_IF4p5_MODE) {		
      memcpy((&rxsigF[0][0]), 
             (int16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4p5_header_t), 
300
             PRACH_BLOCK_SIZE_BYTES);
301 302 303
    } else {
      memcpy((&rxsigF[0][0]),
             (int16_t*) (rx_buffer+sizeof_IF4p5_header_t),
304
             PRACH_BLOCK_SIZE_BYTES);
305
    }
306
  } else if (*packet_type == IF4p5_PULTICK) {
307

308
  } else {
309
    AssertFatal(1==0, "recv_IF4p5 - Unknown packet_type %x", *packet_type);            
310
  }
311

312
  if (eNB->CC_id==0) VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 0 );     
313
  return;   
314 315
}

316

317 318 319
void gen_IF4p5_dl_header(IF4p5_header_t *dl_packet, int frame, int subframe) {      
  dl_packet->type = IF4p5_PACKET_TYPE; 
  dl_packet->sub_type = IF4p5_PDLFFT;
320

321
  dl_packet->rsvd = 0;
322 323
  
  // Set frame status
324 325 326
  dl_packet->frame_status = 0;
  dl_packet->frame_status |= (frame&0xffff)<<6;
  dl_packet->frame_status |= (subframe&0x000f)<<22;
327 328
}

329

330
void gen_IF4p5_ul_header(IF4p5_header_t *ul_packet, uint16_t packet_subtype, int frame, int subframe) {  
knopp's avatar
knopp committed
331

332
  ul_packet->type = IF4p5_PACKET_TYPE; 
333
  ul_packet->sub_type = packet_subtype;
334

335
  ul_packet->rsvd = 0;
336 337
  
  // Set frame status
338 339 340
  ul_packet->frame_status = 0;
  ul_packet->frame_status |= (frame&0xffff)<<6;
  ul_packet->frame_status |= (subframe&0x000f)<<22;
341 342
}

343

344 345 346
void gen_IF4p5_prach_header(IF4p5_header_t *prach_packet, int frame, int subframe) {
  prach_packet->type = IF4p5_PACKET_TYPE; 
  prach_packet->sub_type = IF4p5_PRACH;
347

348
  prach_packet->rsvd = 0;
349 350
  
  // Set LTE Prach configuration
Sandeep Kumar's avatar
Sandeep Kumar committed
351 352 353
  prach_packet->frame_status = 0;
  prach_packet->frame_status |= (frame&0xffff)<<6;
  prach_packet->frame_status |= (subframe&0x000f)<<22;
354
} 
355 356


357
void malloc_IF4p5_buffer(PHY_VARS_eNB *eNB) {
358
  // Keep the size large enough 
359
  eth_state_t *eth = (eth_state_t*) (eNB->ifdevice.priv);
360 361
  int i;

362
  if (eth->flags == ETH_RAW_IF4p5_MODE) {
363 364
    for (i=0;i<10;i++)
      eNB->ifbuffer.tx[i]       = malloc(RAW_IF4p5_PRACH_SIZE_BYTES);
365 366
    eNB->ifbuffer.tx_prach = malloc(RAW_IF4p5_PRACH_SIZE_BYTES);
    eNB->ifbuffer.rx       = malloc(RAW_IF4p5_PRACH_SIZE_BYTES); 
367 368 369
  } else {
    for (i=0;i<10;i++)
      eNB->ifbuffer.tx[i]       = malloc(UDP_IF4p5_PRACH_SIZE_BYTES);
370 371
    eNB->ifbuffer.tx_prach = malloc(UDP_IF4p5_PRACH_SIZE_BYTES);
    eNB->ifbuffer.rx       = malloc(UDP_IF4p5_PRACH_SIZE_BYTES);
372
  }
373
}