if4_tools.c 11.9 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
*/

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

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


48
// --- Careful to handle buffer memory --- RAW/UDP modes --- PRACH variables and data
Sandeep Kumar's avatar
Sandeep Kumar committed
49
void send_IF4(PHY_VARS_eNB *eNB, int frame, int subframe, uint16_t packet_type, int k) {
50
51
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
52
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
Sandeep Kumar's avatar
Sandeep Kumar committed
53
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
54
      
Sandeep Kumar's avatar
Sandeep Kumar committed
55
  uint16_t symbol_id=0, element_id=0;
56
  uint16_t db_fulllength, db_halflength; 
57
  int slotoffsetF=0, blockoffsetF=0; 
58

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

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

Sandeep Kumar's avatar
Sandeep Kumar committed
68
69
70
    tx_buffer = malloc(MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t + db_fulllength*sizeof(int16_t));
    IF4_header_t *dl_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (int16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
71

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

Sandeep Kumar's avatar
Sandeep Kumar committed
107
108
109
    tx_buffer = malloc(MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t + db_fulllength*sizeof(int16_t));
    IF4_header_t *ul_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (int16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
110

111
    gen_IF4_ul_header(ul_header, frame, subframe);
112

113
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
114
      // Do compression of the two parts and generate data blocks - rxdataF		
115
      for (element_id=0; element_id<db_halflength; element_id++) {
116
117
        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;  
118
        
119
120
        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;  
121
122
      }
       			
123
      // Update information in generated packet
Sandeep Kumar's avatar
Sandeep Kumar committed
124
125
      ul_header->frame_status &= ~(0x000f<<26);
      ul_header->frame_status |= (symbol_id&0x000f)<<26; 
126
127
			
      // Write the packet(s) to the fronthaul 
128
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
129
                                        symbol_id,
Sandeep Kumar's avatar
Sandeep Kumar committed
130
                                        &tx_buffer,
131
132
133
134
135
                                        db_fulllength,
      			                            1,
                                        IF4_PULFFT)) < 0) {
        perror("ETHERNET write for IF4_PULFFT\n");
      }
136

137
138
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
139
    }		
140
  } else if (packet_type == IF4_PRACH) {
141
    // FIX: hard coded prach samples length
Sandeep Kumar's avatar
Sandeep Kumar committed
142
    db_fulllength = 839*2;
143

Sandeep Kumar's avatar
Sandeep Kumar committed
144
145
146
    tx_buffer = malloc(MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t + db_fulllength*sizeof(int16_t));
    IF4_header_t *prach_header = (IF4_header_t *)(tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block = (int16_t*)(tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF4_header_t);
147

148
    gen_IF4_prach_header(prach_header, frame, subframe);
149
		    
Sandeep Kumar's avatar
Sandeep Kumar committed
150
151
152
153
154
155
156
157
    // Generate uncompressed data blocks
    memcpy(data_block, (rxsigF[0]+k), db_fulllength*sizeof(int16_t));
    			
    //for (element_id=0; element_id<db_fulllength; element_id++) {
    //  data_block[element_id]  = rxsigF[0][prachoffsetF];          
    //  data_block[element_id] |= rxsigF[0][prachoffsetF+1]<<16;
    //  prachoffsetF += 2;  
    //}
158
159
160
              
    // Write the packet to the fronthaul
    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
161
                                      symbol_id,
Sandeep Kumar's avatar
Sandeep Kumar committed
162
                                      &tx_buffer,
163
164
165
166
167
                                      db_fulllength,
                                      1,
                                      IF4_PRACH)) < 0) {
      perror("ETHERNET write for IF4_PRACH\n");
    }      
168
169
170
171
  } else {    
    AssertFatal(1==0, "send_IF4 - Unknown packet_type %x", packet_type);     
  }
  
172
  free(tx_buffer);
173
  return;  		    
174
}
175

176

177
void recv_IF4(PHY_VARS_eNB *eNB, int *frame, int *subframe, uint16_t *packet_type, uint32_t *symbol_number) {
178
179
180
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
Sandeep Kumar's avatar
Sandeep Kumar committed
181
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
182
183

  uint16_t element_id;
184
  uint16_t db_fulllength, db_halflength; 
Sandeep Kumar's avatar
Sandeep Kumar committed
185
  int slotoffsetF=0, blockoffsetF=0; 
186
  
Sandeep Kumar's avatar
Sandeep Kumar committed
187
  if (eNB->node_function == NGFI_RRU_IF4) {
Sandeep Kumar's avatar
Sandeep Kumar committed
188
    db_fulllength = (12*fp->N_RB_DL); 
189
  } else {
Sandeep Kumar's avatar
Sandeep Kumar committed
190
    db_fulllength = (12*fp->N_RB_UL);     
191
192
193
  }  
  db_halflength = db_fulllength>>1;

194
  void *rx_buffer=NULL;
195
  IF4_header_t *packet_header=NULL;
196
  int16_t *data_block=NULL;
197
     
198
  // Read packet(s) from the fronthaul    
199
  if (eNB->ifdevice.trx_read_func(&eNB->ifdevice,
200
                                  (int64_t*) packet_type,
201
202
                                  &rx_buffer,
                                  db_fulllength,
203
                                  0) < 0) {
204
205
    perror("ETHERNET read");
  }
206
  
207
208
  packet_header = (IF4_header_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES);
  data_block = (int16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4_header_t);
209
210
211

  *frame = ((packet_header->frame_status)>>6)&0xffff;
  *subframe = ((packet_header->frame_status)>>22)&0x000f; 
212
  
Sandeep Kumar's avatar
Sandeep Kumar committed
213
  if (*packet_type == IF4_PDLFFT) {          
214
    // Calculate from received packet
215
    slotoffsetF = (*subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
216
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
Sandeep Kumar's avatar
Sandeep Kumar committed
217
    
218
    // Do decompression of the two parts and generate txdataF			
219
220
221
222
223
224
225
226
227
    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		 		
228
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         
229
        
Sandeep Kumar's avatar
Sandeep Kumar committed
230
  } else if (*packet_type == IF4_PULFFT) {         
231
    // Calculate from received packet
232
    slotoffsetF = (*subframe)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
233
234
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
    
235
    // Do decompression of the two parts and generate rxdataF
236
237
238
239
240
241
242
243
244
    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		 		
245
    *symbol_number = ((packet_header->frame_status)>>26)&0x000f;         
246
    
Sandeep Kumar's avatar
Sandeep Kumar committed
247
  } else if (*packet_type == IF4_PRACH) {    
Sandeep Kumar's avatar
Sandeep Kumar committed
248
249
    // FIX: hard coded prach samples length
    db_fulllength = 839*2;
250
		
Sandeep Kumar's avatar
Sandeep Kumar committed
251
252
    // Generate uncompressed data blocks
    memcpy((rxsigF[0]+slotoffsetF), data_block, db_fulllength*sizeof(int16_t));
253
254
255
256
       
  } else {
    AssertFatal(1==0, "recv_IF4 - Unknown packet_type %x", *packet_type);            
  }
257
258
  
  free(rx_buffer);
259
  return;   
260
261
}

262

Sandeep Kumar's avatar
Sandeep Kumar committed
263
void gen_IF4_dl_header(IF4_header_t *dl_packet, int frame, int subframe) {      
Sandeep Kumar's avatar
Sandeep Kumar committed
264
  // Set Type and Sub-Type
265
  dl_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
266
  dl_packet->sub_type = IF4_PDLFFT;
Sandeep Kumar's avatar
Sandeep Kumar committed
267

Sandeep Kumar's avatar
Sandeep Kumar committed
268
  // Reset frame status 
269
  dl_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
270
271
  
  // Set frame status
Sandeep Kumar's avatar
Sandeep Kumar committed
272
273
274
  dl_packet->frame_status = 0;
  dl_packet->frame_status |= (frame&0xffff)<<6;
  dl_packet->frame_status |= (subframe&0x000f)<<22;
275

276
277
}

278

Sandeep Kumar's avatar
Sandeep Kumar committed
279
void gen_IF4_ul_header(IF4_header_t *ul_packet, int frame, int subframe) {  
Sandeep Kumar's avatar
Sandeep Kumar committed
280
  // Set Type and Sub-Type
281
  ul_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
282
  ul_packet->sub_type = IF4_PULFFT;
Sandeep Kumar's avatar
Sandeep Kumar committed
283
284

  // Leave reserved as it is 
285
  ul_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
286
287
  
  // Set frame status
Sandeep Kumar's avatar
Sandeep Kumar committed
288
289
290
  ul_packet->frame_status = 0;
  ul_packet->frame_status |= (frame&0xffff)<<6;
  ul_packet->frame_status |= (subframe&0x000f)<<22;
291
    
292
293
}

294

Sandeep Kumar's avatar
Sandeep Kumar committed
295
void gen_IF4_prach_header(IF4_header_t *prach_packet, int frame, int subframe) {
Sandeep Kumar's avatar
Sandeep Kumar committed
296
  // Set Type and Sub-Type
297
  prach_packet->type = IF4_PACKET_TYPE; 
Sandeep Kumar's avatar
Sandeep Kumar committed
298
  prach_packet->sub_type = IF4_PRACH;
Sandeep Kumar's avatar
Sandeep Kumar committed
299
300

  // Leave reserved as it is 
301
  prach_packet->rsvd = 0;
Sandeep Kumar's avatar
Sandeep Kumar committed
302
303
  
  // Set LTE Prach configuration
Sandeep Kumar's avatar
Sandeep Kumar committed
304
305
306
  prach_packet->frame_status = 0;
  prach_packet->frame_status |= (frame&0xffff)<<6;
  prach_packet->frame_status |= (subframe&0x000f)<<22;
307
        
308
}