if4_tools.c 10.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

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

36
#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
37
#include "UTIL/LOG/vcd_signal_dumper.h"
38

39
void send_IF4p5(PHY_VARS_eNB *eNB, int frame, int subframe, uint16_t packet_type, int k) {
40 41
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
42
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
43
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
44
  void *tx_buffer = eNB->ifbuffer.tx;
45
      
46
  uint16_t symbol_id=0, element_id=0;
47
  uint16_t db_fulllength, db_halflength; 
48
  int slotoffsetF=0, blockoffsetF=0; 
49

50
  uint16_t *data_block=NULL, *i=NULL;
51

52 53 54
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF4, 1 );   

  if (packet_type == IF4p5_PDLFFT) {
55 56
    db_fulllength = 12*fp->N_RB_DL;
    db_halflength = (db_fulllength)>>1;
57
    slotoffsetF = (subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
58
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
59

60 61
    IF4p5_header_t *dl_header = (IF4p5_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
62

63
    gen_IF4p5_dl_header(dl_header, frame, subframe);
64 65
		    
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
66
      
67
      for (element_id=0; element_id<db_halflength; element_id++) {
68 69 70 71 72
        i = (uint16_t*) &txdataF[0][blockoffsetF+element_id];
        data_block[element_id] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);

        i = (uint16_t*) &txdataF[0][slotoffsetF+element_id];
        data_block[element_id+db_halflength] = ((uint16_t) lin2alaw[*i]) | (lin2alaw[*(i+1)]<<8);        
73 74
      }
				 		
75 76
      dl_header->frame_status &= ~(0x000f<<26);
      dl_header->frame_status |= (symbol_id&0x000f)<<26; 
77
			
78
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
79
                                        symbol_id,
80
                                        &tx_buffer,
81 82
                                        db_fulllength,
      			                            1,
83 84
                                        IF4p5_PDLFFT)) < 0) {
        perror("ETHERNET write for IF4p5_PDLFFT\n");
85
      }
86 87 88
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
89
    }
90
  } else if (packet_type == IF4p5_PULFFT) {
91 92
    db_fulllength = 12*fp->N_RB_UL;
    db_halflength = (db_fulllength)>>1;
Sandeep Kumar's avatar
Sandeep Kumar committed
93
    slotoffsetF = 1;
94
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
95

96 97
    IF4p5_header_t *ul_header = (IF4p5_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
98

99
    gen_IF4p5_ul_header(ul_header, frame, subframe);
100

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

103
      for (element_id=0; element_id<db_halflength; element_id++) {
104 105 106 107 108
        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);        
109 110
      }
       			
111 112
      ul_header->frame_status &= ~(0x000f<<26);
      ul_header->frame_status |= (symbol_id&0x000f)<<26; 
113
			
114
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
115
                                        symbol_id,
116
                                        &tx_buffer,
117 118
                                        db_fulllength,
      			                            1,
119 120
                                        IF4p5_PULFFT)) < 0) {
        perror("ETHERNET write for IF4p5_PULFFT\n");
121
      }
122

123 124
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
125
    }		
126
  } else if (packet_type == IF4p5_PRACH) {
127
    // FIX: hard coded prach samples length
knopp's avatar
knopp committed
128
    db_fulllength = 840*2;
129

130 131
    IF4p5_header_t *prach_header = (IF4p5_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t);
132

133
    gen_IF4p5_prach_header(prach_header, frame, subframe);
134
		    
135
    memcpy((int16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t),
136
           (&rxsigF[0][k]), 
137 138
           db_fulllength*sizeof(int16_t));
    			              
139
    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
140
                                      symbol_id,
141
                                      &tx_buffer,
142 143
                                      db_fulllength,
                                      1,
144 145
                                      IF4p5_PRACH)) < 0) {
      perror("ETHERNET write for IF4p5_PRACH\n");
146
    }      
147
  } else {    
148
    AssertFatal(1==0, "send_IF4p5 - Unknown packet_type %x", packet_type);     
149
  }
150 151

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF4, 0 );  
152
  return;  		    
153
}
154

155

156
void recv_IF4p5(PHY_VARS_eNB *eNB, int *frame, int *subframe, uint16_t *packet_type, uint32_t *symbol_number) {
157 158 159
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
160
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
161
  void *rx_buffer = eNB->ifbuffer.rx;
162 163

  uint16_t element_id;
164
  uint16_t db_fulllength, db_halflength; 
165
  int slotoffsetF=0, blockoffsetF=0; 
166 167

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 1 );   
168
  
169
  if (eNB->node_function == NGFI_RRU_IF4p5) {
170
    db_fulllength = (12*fp->N_RB_DL); 
171
  } else {
172
    db_fulllength = (12*fp->N_RB_UL);     
173 174 175
  }  
  db_halflength = db_fulllength>>1;

176
  IF4p5_header_t *packet_header=NULL;
177
  uint16_t *data_block=NULL, *i=NULL;
178
     
179
  if (eNB->ifdevice.trx_read_func(&eNB->ifdevice,
180
                                  (int64_t*) packet_type,
181 182
                                  &rx_buffer,
                                  db_fulllength,
183
                                  0) < 0) {
184 185
    perror("ETHERNET read");
  }
186
  
187 188
  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);
189 190 191

  *frame = ((packet_header->frame_status)>>6)&0xffff;
  *subframe = ((packet_header->frame_status)>>22)&0x000f; 
Raymond Knopp's avatar
Raymond Knopp committed
192 193


194
  if (*packet_type == IF4p5_PDLFFT) {          
Sandeep Kumar's avatar
Sandeep Kumar committed
195 196 197
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         

    slotoffsetF = (*symbol_number)*(fp->ofdm_symbol_size) + (*subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
198 199
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
        
200
    for (element_id=0; element_id<db_halflength; element_id++) {
201 202 203
      i = (uint16_t*) &txdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
204

205 206 207
      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) ];
208
    }
Sandeep Kumar's avatar
Sandeep Kumar committed
209
		        
210
  } else if (*packet_type == IF4p5_PULFFT) {         
211
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         
Sandeep Kumar's avatar
Sandeep Kumar committed
212

Sandeep Kumar's avatar
Sandeep Kumar committed
213
    slotoffsetF = (*symbol_number)*(fp->ofdm_symbol_size) + 1;
214
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
215 216
    
    for (element_id=0; element_id<db_halflength; element_id++) {
217 218 219
      i = (uint16_t*) &rxdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
220

221 222 223
      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) ];
224 225
    }
		
226
  } else if (*packet_type == IF4p5_PRACH) {    
227
    // FIX: hard coded prach samples length
228
    db_fulllength = 840*2;
229
		
230
    memcpy((&rxsigF[0][0]), 
231
           (int16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4p5_header_t), 
232
           db_fulllength*sizeof(int16_t));
233 234
       
  } else {
235
    AssertFatal(1==0, "recv_IF4p5 - Unknown packet_type %x", *packet_type);            
236
  }
237 238

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 0 );     
239
  return;   
240 241
}

242

243 244 245
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;
246

247
  dl_packet->rsvd = 0;
248 249
  
  // Set frame status
250 251 252
  dl_packet->frame_status = 0;
  dl_packet->frame_status |= (frame&0xffff)<<6;
  dl_packet->frame_status |= (subframe&0x000f)<<22;
253 254
}

255

256
void gen_IF4p5_ul_header(IF4p5_header_t *ul_packet, int frame, int subframe) {  
knopp's avatar
knopp committed
257

258 259
  ul_packet->type = IF4p5_PACKET_TYPE; 
  ul_packet->sub_type = IF4p5_PULFFT;
260

261
  ul_packet->rsvd = 0;
262 263
  
  // Set frame status
264 265 266
  ul_packet->frame_status = 0;
  ul_packet->frame_status |= (frame&0xffff)<<6;
  ul_packet->frame_status |= (subframe&0x000f)<<22;
267 268
}

269

270 271 272
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;
273

274
  prach_packet->rsvd = 0;
275 276
  
  // Set LTE Prach configuration
Sandeep Kumar's avatar
Sandeep Kumar committed
277 278 279
  prach_packet->frame_status = 0;
  prach_packet->frame_status |= (frame&0xffff)<<6;
  prach_packet->frame_status |= (subframe&0x000f)<<22;
280
} 
281 282


283
void malloc_IF4p5_buffer(PHY_VARS_eNB *eNB) {
284
  // Keep the size large enough 
285 286
  eNB->ifbuffer.tx = malloc(RAW_IF4p5_PRACH_SIZE_BYTES);
  eNB->ifbuffer.rx = malloc(RAW_IF4p5_PRACH_SIZE_BYTES);      
287
}