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

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
48
49
#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"


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

61
  void *tx_buffer=NULL;
62
  int16_t *data_block=NULL;
63

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

Sandeep Kumar's avatar
Sandeep Kumar committed
70
71
72
    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);
73

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

Sandeep Kumar's avatar
Sandeep Kumar committed
109
110
111
    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);
112

113
    gen_IF4_ul_header(ul_header, frame, subframe);
114

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

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

Sandeep Kumar's avatar
Sandeep Kumar committed
146
147
148
    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);
149

150
    gen_IF4_prach_header(prach_header, frame, subframe);
151
		    
Sandeep Kumar's avatar
Sandeep Kumar committed
152
153
154
155
156
157
158
159
    // 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;  
    //}
160
161
162
              
    // Write the packet to the fronthaul
    if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
163
                                      symbol_id,
Sandeep Kumar's avatar
Sandeep Kumar committed
164
                                      &tx_buffer,
165
166
167
168
169
                                      db_fulllength,
                                      1,
                                      IF4_PRACH)) < 0) {
      perror("ETHERNET write for IF4_PRACH\n");
    }      
170
171
172
173
  } else {    
    AssertFatal(1==0, "send_IF4 - Unknown packet_type %x", packet_type);     
  }
  
174
  free(tx_buffer);
175
  return;  		    
176
}
177

178

Sandeep Kumar's avatar
Sandeep Kumar committed
179
void recv_IF4(PHY_VARS_eNB *eNB, int frame, int subframe, uint16_t *packet_type, uint32_t *symbol_number) {
180
181
182
  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
183
  int16_t **rxsigF = eNB->prach_vars.rxsigF;  
184
185

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

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

261

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

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

275
276
}

277

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

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

293

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

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