if4_tools.c 8.56 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
36
* \email: knopp@eurecom.fr 
37 38 39 40
* \note
* \warning
*/

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
// Get device information
48 49 50
void send_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t packet_type) {
  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
  int32_t **txdataF = eNB->common_vars.txdataF[0];
51
  int32_t **rxdataF = eNB->common_vars.rxdataF[0];
52
  
53 54 55
  IF4_dl_header_t *dl_header=NULL;
  IF4_ul_header_t *ul_header=NULL;
  IF4_prach_header_t *prach_header=NULL;   
56
  
57 58 59 60 61 62
  uint16_t symbol_id, element_id;
  uint16_t db_halflength; 
  int slotoffsetF, blockoffsetF; 

  int16_t *data_block=NULL;
//  int16_t *txbuffer = (int16_t*)malloc(db_halflength*sizeof(int16_t));
63

64
  if (packet_type == IF4_PDLFFT) {
65 66
    dl_header = (IF4_dl_header_t*)malloc(sizeof_IF4_dl_header_t);
    gen_IF4_dl_header(dl_header, proc);
67
		
68 69 70 71 72 73
    db_halflength = (12*fp->N_RB_DL)>>1;
    slotoffsetF = (proc->subframe_tx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
    
    printf("Problem here - db_half %d\n", db_halflength);
    data_block = (int16_t*)malloc(db_halflength*sizeof(int16_t));
74

75
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {
76 77
      
      printf("\n Send IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);
78

79 80
      // Do compression of the two parts and generate data blocks			
      for (element_id=0; element_id<db_halflength; element_id++) {
81 82
        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;  
83
        
84 85
        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;  
86 87
      }
				 		
88
      // Update information in generated packet
89
      dl_header->frame_status.sym_num = symbol_id; 
90
			
91
      printf("\n Not even here !!\n");
92
      // Write the packet(s) to the fronthaul
93 94 95 96 97 98 99 100
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                                     symbol_id,
      			                                         &data_block,
      			                                         1,
      			                                         1,
                                                     0)) < 0) {
        perror("RCC : ETHERNET write");
      }
101 102 103
      
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
104
    }
105
  } else if (packet_type == IF4_PULFFT) {
106 107 108 109 110 111
    ul_header = (IF4_ul_header_t*)malloc(sizeof_IF4_ul_header_t);
    gen_IF4_ul_header(ul_header, proc);

    db_halflength = (12*fp->N_RB_UL)>>1;
    slotoffsetF = (proc->subframe_rx)*(fp->ofdm_symbol_size)*((fp->Ncp==1) ? 12 : 14) + 1;
    blockoffsetF = slotoffsetF + fp->ofdm_symbol_size - db_halflength; 
112
		
113
    data_block = (int16_t*)malloc(db_halflength*sizeof(int16_t));
114

115
    for (symbol_id=0; symbol_id<fp->symbols_per_tti; symbol_id++) {			
116

117
      // Do compression of the two parts and generate data blocks - rxdataF		
118
      for (element_id=0; element_id<db_halflength; element_id++) {
119 120
        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;  
121
        
122 123
        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;  
124 125
      }
       			
126
      // Update information in generated packet
127
      ul_header->frame_status.sym_num = symbol_id; 
128 129 130
			
      // Write the packet(s) to the fronthaul 

131 132
      slotoffsetF  += fp->ofdm_symbol_size;
      blockoffsetF += fp->ofdm_symbol_size;    
133
    }		
134 135 136 137 138 139 140 141
  } else if (packet_type == IF4_PRACH) {
       
       
  } else {    
    AssertFatal(1==0, "send_IF4 - Unknown packet_type %x", packet_type);     
  }
  
  return;  		    
142
}
143

144
void recv_IF4(PHY_VARS_eNB *eNB, eNB_rxtx_proc_t *proc, uint16_t *packet_type, uint32_t *symbol_number) {
145

146
  *packet_type = 0;
147
  //int16_t *data_block=NULL;
148 149
   
  // Read packet(s) from the fronthaul    
150 151 152 153 154 155 156 157 158
//    for(i=0; i<fp->symbols_per_tti; i++) {  
//      if (dev->eth_dev.trx_read_func (&dev->eth_dev,
//                                      timestamp_rx,
//                                    rx_eNB,
//                                      spp_eth,
//                                      dev->eth_dev.openair0_cfg->rx_num_channels
//                                      ) < 0) {
//        perror("RRU : ETHERNET read");
//      }
159 160 161 162 163
//  printf("\n Recv IF4 for frame %d, subframe %d and symbol %d\n", proc->frame_tx, proc->subframe_tx, symbol_id);

  //*packet_type = ;  
  
  if (*packet_type == IF4_PDLFFT) {
164 165 166 167 168
      
      // Apply reverse processing - decompression
      // txAlawtolinear( Datablock )
      
      // Generate and return the OFDM symbols (txdataF)
169
      // txDataF 
170
    
171 172 173 174 175 176 177 178 179
  } else if (*packet_type == IF4_PULFFT) {
    
  } else if (*packet_type == IF4_PRACH) {
       
  } else {
    AssertFatal(1==0, "recv_IF4 - Unknown packet_type %x", *packet_type);            
  }

  return;   
180 181
}

182
void gen_IF4_dl_header(IF4_dl_header_t *dl_packet, eNB_rxtx_proc_t *proc) {      
183
  // Set Type and Sub-Type
184
  dl_packet->type = IF4_PACKET_TYPE; 
185
  dl_packet->sub_type = IF4_PDLFFT;
186 187

  // Leave reserved as it is 
188
  dl_packet->rsvd = 0;
189 190
  
  // Set frame status
191 192 193 194 195 196 197
  dl_packet->frame_status.ant_num = 0;
  dl_packet->frame_status.ant_start = 0;
  dl_packet->frame_status.rf_num = proc->frame_tx;
  dl_packet->frame_status.sf_num = proc->subframe_tx;
  dl_packet->frame_status.sym_num = 0;
  dl_packet->frame_status.rsvd = 0;

198
  // Set frame check sequence
199

200 201
}

202
void gen_IF4_ul_header(IF4_ul_header_t *ul_packet, eNB_rxtx_proc_t *proc) {  
203
  // Set Type and Sub-Type
204
  ul_packet->type = IF4_PACKET_TYPE; 
205
  ul_packet->sub_type = IF4_PULFFT;
206 207

  // Leave reserved as it is 
208
  ul_packet->rsvd = 0;
209 210
  
  // Set frame status
211 212 213 214 215 216 217 218 219 220
  ul_packet->frame_status.ant_num = 0;
  ul_packet->frame_status.ant_start = 0;
  ul_packet->frame_status.rf_num = proc->frame_rx;
  ul_packet->frame_status.sf_num = proc->subframe_rx;
  ul_packet->frame_status.sym_num = 0;
  ul_packet->frame_status.rsvd = 0;
    
  // Set antenna specific gain *** set other antenna gain ***
  ul_packet->gain0.exponent = 0;
  ul_packet->gain0.rsvd = 0;
221 222
    
  // Set frame check sequence
223

224 225
}

226
void gen_IF4_prach_header(IF4_prach_header_t *prach_packet, eNB_rxtx_proc_t *proc) {
227
  // Set Type and Sub-Type
228
  prach_packet->type = IF4_PACKET_TYPE; 
229
  prach_packet->sub_type = IF4_PRACH;
230 231

  // Leave reserved as it is 
232
  prach_packet->rsvd = 0;
233 234
  
  // Set LTE Prach configuration
235 236 237 238 239 240
  prach_packet->prach_conf.rsvd = 0;
  prach_packet->prach_conf.ant = 0;
  prach_packet->prach_conf.rf_num = proc->frame_rx;
  prach_packet->prach_conf.sf_num = proc->subframe_rx;
  prach_packet->prach_conf.exponent = 0;  
        
241
  // Set frame check sequence
242

243
}