if4_tools.c 10.5 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 S. Sandeep Kumar, Raymond Knopp
33 34 35
* \date 2016
* \version 0.1
* \company Eurecom
36
* \email: ee13b1025@iith.ac.in, knopp@eurecom.fr 
37 38 39 40
* \note
* \warning
*/

41
#include "PHY/defs.h"
42
#include "PHY/TOOLS/alaw_lut.h"
43

44 45 46
#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"


47
void send_IF4(PHY_VARS_eNB *eNB, int frame, int subframe, uint16_t packet_type, int k) {
48 49
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
50
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
51
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
52
  void *tx_buffer = eNB->ifbuffer.tx;
53
      
54
  uint16_t symbol_id=0, element_id=0;
55
  uint16_t db_fulllength, db_halflength; 
56
  int slotoffsetF=0, blockoffsetF=0; 
57

58
  uint16_t *data_block=NULL, *i=NULL;
59

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

Sandeep Kumar's avatar
Sandeep Kumar committed
66
    IF4_header_t *dl_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
67
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
68

69
    gen_IF4_dl_header(dl_header, frame, subframe);
70 71
		    
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
72
      
73
      for (element_id=0; element_id<db_halflength; element_id++) {
74 75 76 77 78
        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);        
79 80
      }
				 		
81 82
      dl_header->frame_status &= ~(0x000f<<26);
      dl_header->frame_status |= (symbol_id&0x000f)<<26; 
83
			
84
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
85
                                        symbol_id,
86
                                        &tx_buffer,
87 88 89 90
                                        db_fulllength,
      			                            1,
                                        IF4_PDLFFT)) < 0) {
        perror("ETHERNET write for IF4_PDLFFT\n");
91
      }
92 93 94
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
95
    }
96
  } else if (packet_type == IF4_PULFFT) {
97 98
    db_fulllength = 12*fp->N_RB_UL;
    db_halflength = (db_fulllength)>>1;
99
    slotoffsetF = (subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
100
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
101

Sandeep Kumar's avatar
Sandeep Kumar committed
102
    IF4_header_t *ul_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
103
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
104

105
    gen_IF4_ul_header(ul_header, frame, subframe);
106

107
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
108

109
      for (element_id=0; element_id<db_halflength; element_id++) {
110 111 112 113 114
        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);        
115 116
      }
       			
117 118
      ul_header->frame_status &= ~(0x000f<<26);
      ul_header->frame_status |= (symbol_id&0x000f)<<26; 
119
			
120
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
121
                                        symbol_id,
122
                                        &tx_buffer,
123 124 125 126 127
                                        db_fulllength,
      			                            1,
                                        IF4_PULFFT)) < 0) {
        perror("ETHERNET write for IF4_PULFFT\n");
      }
128

129 130
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
131
    }		
132
  } else if (packet_type == IF4_PRACH) {
133
    // FIX: hard coded prach samples length
134
    db_fulllength = 839*2;
135

Sandeep Kumar's avatar
Sandeep Kumar committed
136
    IF4_header_t *prach_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
137
    data_block = (uint16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
138

139
    gen_IF4_prach_header(prach_header, frame, subframe);
140
		    
141 142 143 144
    memcpy((int16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t),
           (&rxsigF[0][0]+k), 
           db_fulllength*sizeof(int16_t));
    			              
145
    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
146
                                      symbol_id,
147
                                      &tx_buffer,
148 149 150 151 152
                                      db_fulllength,
                                      1,
                                      IF4_PRACH)) < 0) {
      perror("ETHERNET write for IF4_PRACH\n");
    }      
153 154 155 156 157
  } else {    
    AssertFatal(1==0, "send_IF4 - Unknown packet_type %x", packet_type);     
  }
  
  return;  		    
158
}
159

160

161
void recv_IF4(PHY_VARS_eNB *eNB, int *frame, int *subframe, uint16_t *packet_type, uint32_t *symbol_number) {
162 163 164
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
165
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
166
  void *rx_buffer = eNB->ifbuffer.rx;
167 168

  uint16_t element_id;
169
  uint16_t db_fulllength, db_halflength; 
170
  int slotoffsetF=0, blockoffsetF=0; 
171
  
172
  if (eNB->node_function == NGFI_RRU_IF4) {
173
    db_fulllength = (12*fp->N_RB_DL); 
174
  } else {
175
    db_fulllength = (12*fp->N_RB_UL);     
176 177 178
  }  
  db_halflength = db_fulllength>>1;

179
  IF4_header_t *packet_header=NULL;
180
  uint16_t *data_block=NULL, *i=NULL;
181
     
182
  if (eNB->ifdevice.trx_read_func(&eNB->ifdevice,
183
                                  (int64_t*) packet_type,
184 185
                                  &rx_buffer,
                                  db_fulllength,
186
                                  0) < 0) {
187 188
    perror("ETHERNET read");
  }
189
  
190
  packet_header = (IF4_header_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES);
191
  data_block = (uint16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4_header_t);
192 193 194

  *frame = ((packet_header->frame_status)>>6)&0xffff;
  *subframe = ((packet_header->frame_status)>>22)&0x000f; 
195
  
Sandeep Kumar's avatar
Sandeep Kumar committed
196
  if (*packet_type == IF4_PDLFFT) {          
Sandeep Kumar's avatar
Sandeep Kumar committed
197 198 199
    *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;
200 201
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
        
202
    for (element_id=0; element_id<db_halflength; element_id++) {
203 204 205
      i = (uint16_t*) &txdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
206

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

    slotoffsetF = (*symbol_number)*(fp->ofdm_symbol_size) + (*subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
216
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength - 1; 
217 218
    
    for (element_id=0; element_id<db_halflength; element_id++) {
219 220 221
      i = (uint16_t*) &rxdataF[0][blockoffsetF+element_id];
      *i = alaw2lin[ (data_block[element_id] & 0xff) ]; 
      *(i+1) = alaw2lin[ (data_block[element_id]>>8) ];
222

223 224 225
      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) ];
226 227
    }
		
Sandeep Kumar's avatar
Sandeep Kumar committed
228
  } else if (*packet_type == IF4_PRACH) {    
229 230
    // FIX: hard coded prach samples length
    db_fulllength = 839*2;
231
		
232 233 234
    memcpy((&rxsigF[0][0]), 
           (int16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4_header_t), 
           db_fulllength*sizeof(int16_t));
235 236 237 238
       
  } else {
    AssertFatal(1==0, "recv_IF4 - Unknown packet_type %x", *packet_type);            
  }
239
  
240
  return;   
241 242
}

243

Sandeep Kumar's avatar
Sandeep Kumar committed
244
void gen_IF4_dl_header(IF4_header_t *dl_packet, int frame, int subframe) {      
245
  dl_packet->type = IF4_PACKET_TYPE; 
246
  dl_packet->sub_type = IF4_PDLFFT;
247

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

256

Sandeep Kumar's avatar
Sandeep Kumar committed
257
void gen_IF4_ul_header(IF4_header_t *ul_packet, int frame, int subframe) {  
258
  ul_packet->type = IF4_PACKET_TYPE; 
259
  ul_packet->sub_type = IF4_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

Sandeep Kumar's avatar
Sandeep Kumar committed
270
void gen_IF4_prach_header(IF4_header_t *prach_packet, int frame, int subframe) {
271
  prach_packet->type = IF4_PACKET_TYPE; 
272
  prach_packet->sub_type = IF4_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 284 285 286 287


void malloc_IF4_buffer(PHY_VARS_eNB *eNB) {
  // Keep the size large enough 
  eNB->ifbuffer.tx = malloc(RAW_IF4_PRACH_SIZE_BYTES);
  eNB->ifbuffer.rx = malloc(RAW_IF4_PRACH_SIZE_BYTES);      
}