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

#include "PHY/defs.h"

#include "targets/ARCH/ETHERNET/USERSPACE/LIB/if_defs.h"
44
#include "UTIL/LOG/vcd_signal_dumper.h"
45

Sandeep Kumar's avatar
Sandeep Kumar committed
46
void send_IF5(PHY_VARS_eNB *eNB, openair0_timestamp proc_timestamp, int subframe, uint8_t *seqno, uint16_t packet_type) {      
47 48
  
  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
49 50
  int32_t *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 
  int32_t *tx_buffer=NULL;
51 52

  uint16_t packet_id=0, i=0;
Sandeep Kumar's avatar
Sandeep Kumar committed
53 54 55

  uint32_t spp_eth  = (uint32_t) eNB->ifdevice.openair0_cfg->samples_per_packet;
  uint32_t spsf     = (uint32_t) eNB->ifdevice.openair0_cfg->samples_per_frame/10;
56
  
57 58
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 1 );  

Sandeep Kumar's avatar
Sandeep Kumar committed
59 60
  if (packet_type == IF5_RRH_GW_DL) {    

61
    for (i=0; i < fp->nb_antennas_tx; i++)
Sandeep Kumar's avatar
Sandeep Kumar committed
62
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
63 64
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Raymond Knopp's avatar
Raymond Knopp committed
65 66

      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 1 );            
67
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
Sandeep Kumar's avatar
Sandeep Kumar committed
68
                                   (proc_timestamp + packet_id*spp_eth),
69
                                   (void**)txp,
70 71 72
                                   spp_eth,
                                   fp->nb_antennas_tx,
                                   0);
Raymond Knopp's avatar
Raymond Knopp committed
73
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 0 );  
Sandeep Kumar's avatar
Sandeep Kumar committed
74 75 76
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += spp_eth;

77 78
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
79
  } else if (packet_type == IF5_RRH_GW_UL) {
Sandeep Kumar's avatar
Sandeep Kumar committed
80
        
Sandeep Kumar's avatar
Sandeep Kumar committed
81 82 83 84
    for (i=0; i < fp->nb_antennas_rx; i++)
      rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
85

Raymond Knopp's avatar
Raymond Knopp committed
86
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 1 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
87 88
      eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                   (proc_timestamp + packet_id*spp_eth),
89
                                   (void**)rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
90 91 92
                                   spp_eth,
                                   fp->nb_antennas_rx,
                                   0);
Raymond Knopp's avatar
Raymond Knopp committed
93
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE_IF, 0 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
94 95 96
      for (i=0; i < fp->nb_antennas_rx; i++)
        rxp[i] += spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
97
    }    
98
    
Sandeep Kumar's avatar
Sandeep Kumar committed
99
  } else if (packet_type == IF5_MOBIPASS) {    
100 101 102 103 104 105 106 107
    uint16_t db_fulllength=640;
    
    __m128i *data_block=NULL, *data_block_head=NULL;

    __m128i *txp128;
    __m128i t0, t1;

    tx_buffer = memalign(16, MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + db_fulllength*sizeof(int16_t));
108 109
    IF5_mobipass_header_t *header = (IF5_mobipass_header_t *)((uint8_t *)tx_buffer + MAC_HEADER_SIZE_BYTES);
    data_block_head = (__m128i *)((uint8_t *)tx_buffer + MAC_HEADER_SIZE_BYTES + sizeof_IF5_mobipass_header_t + 4);
110 111 112 113 114 115 116
    
    header->flags = 0;
    header->fifo_status = 0;  
    header->seqno = *seqno;
    header->ack = 0;
    header->word0 = 0;  
    
Sandeep Kumar's avatar
Sandeep Kumar committed
117
    txp[0] = (void*)&eNB->common_vars.txdata[0][0][subframe*eNB->frame_parms.samples_per_tti];
118 119
    txp128 = (__m128i *) txp[0];
              
120 121
    for (packet_id=0; packet_id<fp->samples_per_tti/db_fulllength; packet_id++) {
      header->time_stamp = (uint32_t)(proc_timestamp + packet_id*db_fulllength);
122 123
      data_block = data_block_head; 
    
124
      for (i=0; i<db_fulllength>>2; i+=2) {
125 126
        t0 = _mm_srai_epi16(*txp128++, 4);
        t1 = _mm_srai_epi16(*txp128++, 4);   
127 128 129 130 131 132 133
        
        *data_block++ = _mm_packs_epi16(t0, t1);     
      }
      
      // Write the packet to the fronthaul
      if ((eNB->ifdevice.trx_write_func(&eNB->ifdevice,
                                        packet_id,
134
                                        (void**)&tx_buffer,
135 136 137 138 139 140 141 142 143
                                        db_fulllength,
                                        1,
                                        IF5_MOBIPASS)) < 0) {
        perror("ETHERNET write for IF5_MOBIPASS\n");
      }
    
      header->seqno += 1;    
    }  
    *seqno = header->seqno;
Sandeep Kumar's avatar
Sandeep Kumar committed
144
    
145 146 147 148 149
  } else {    
    AssertFatal(1==0, "send_IF5 - Unknown packet_type %x", packet_type);     
  }  
  
  free(tx_buffer);
150 151
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_SEND_IF5, 0 );  

152 153 154 155
  return;  		    
}


Sandeep Kumar's avatar
Sandeep Kumar committed
156
void recv_IF5(PHY_VARS_eNB *eNB, openair0_timestamp *proc_timestamp, int subframe, uint16_t packet_type) {
157 158

  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
159 160
  int32_t *txp[fp->nb_antennas_tx], *rxp[fp->nb_antennas_rx]; 

161
  uint16_t packet_id=0, i=0;
Sandeep Kumar's avatar
Sandeep Kumar committed
162 163 164 165 166

  int32_t spp_eth  = (int32_t) eNB->ifdevice.openair0_cfg->samples_per_packet;
  int32_t spsf     = (int32_t) eNB->ifdevice.openair0_cfg->samples_per_frame/10;

  openair0_timestamp timestamp[spsf / spp_eth];
167 168

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF5, 1 );  
169
  
Sandeep Kumar's avatar
Sandeep Kumar committed
170
  if (packet_type == IF5_RRH_GW_DL) {
Sandeep Kumar's avatar
Sandeep Kumar committed
171
        
Sandeep Kumar's avatar
Sandeep Kumar committed
172 173
    for (i=0; i < fp->nb_antennas_tx; i++)
      txp[i] = (void*)&eNB->common_vars.txdata[0][i][subframe*fp->samples_per_tti];
174 175
    
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Sandeep Kumar's avatar
Sandeep Kumar committed
176

Raymond Knopp's avatar
Raymond Knopp committed
177
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 1 );  
178 179
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
180
                                  (void**)txp,
181
                                  spp_eth,
Sandeep Kumar's avatar
Sandeep Kumar committed
182
                                  fp->nb_antennas_tx);
Raymond Knopp's avatar
Raymond Knopp committed
183
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 0 );  
Sandeep Kumar's avatar
Sandeep Kumar committed
184 185 186
      for (i=0; i < fp->nb_antennas_tx; i++)
        txp[i] += spp_eth;

187 188
    }
    
Sandeep Kumar's avatar
Sandeep Kumar committed
189 190
    *proc_timestamp = timestamp[0];
    
Sandeep Kumar's avatar
Sandeep Kumar committed
191
  } else if (packet_type == IF5_RRH_GW_UL) { 
Sandeep Kumar's avatar
Sandeep Kumar committed
192 193 194
    
    for (i=0; i < fp->nb_antennas_rx; i++)
      rxp[i] = (void*)&eNB->common_vars.rxdata[0][i][subframe*fp->samples_per_tti];
195
    
Sandeep Kumar's avatar
Sandeep Kumar committed
196
    for (packet_id=0; packet_id < spsf / spp_eth; packet_id++) {
Raymond Knopp's avatar
Raymond Knopp committed
197
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 1 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
198 199
      eNB->ifdevice.trx_read_func(&eNB->ifdevice,
                                  &timestamp[packet_id],
200
                                  (void**)rxp,
Sandeep Kumar's avatar
Sandeep Kumar committed
201 202
                                  spp_eth,
                                  fp->nb_antennas_rx);
Raymond Knopp's avatar
Raymond Knopp committed
203
      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_READ_IF, 0 );            
Sandeep Kumar's avatar
Sandeep Kumar committed
204 205 206
      for (i=0; i < fp->nb_antennas_rx; i++)
        rxp[i] += spp_eth;

Sandeep Kumar's avatar
Sandeep Kumar committed
207 208 209 210
    }

    *proc_timestamp = timestamp[0];
      
211 212 213 214 215 216
  } else if (packet_type == IF5_MOBIPASS) {
    
    
  } else {
    AssertFatal(1==0, "recv_IF5 - Unknown packet_type %x", packet_type);     
  }  
217 218

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF5, 0 );  
219 220 221
  
  return;  
}