nr_prach_procedures.c 4.92 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
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file nr_prach_procedures.c
 * \brief Implementation of gNB prach procedures from 38.213 LTE specifications
 * \author R. Knopp, 
 * \date 2019
 * \version 0.1
 * \company Eurecom
 * \email: knopp@eurecom.fr
 * \note
 * \warning
 */

33
#include "PHY/defs_gNB.h"
34
#include "PHY/phy_extern.h"
35
#include "PHY/NR_TRANSPORT/nr_transport_proto.h"
36
#include "nfapi_nr_interface_scf.h"
37 38 39 40 41 42 43 44 45 46 47 48 49
#include "fapi_nr_l1.h"
#include "nfapi_pnf.h"
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"


#include "assertions.h"
#include "msc.h"

#include <time.h>

#include "intertask_interface.h"

50
extern uint8_t nfapi_mode;
51 52 53 54

extern int oai_nfapi_nr_rach_ind(nfapi_rach_indication_t *rach_ind);


55 56 57
void L1_nr_prach_procedures(PHY_VARS_gNB *gNB,int frame,int slot,
			    nfapi_nr_prach_pdu_t *prach_pdu) {

laurent's avatar
laurent committed
58
  uint16_t max_preamble[4]={0},max_preamble_energy[4]={0},max_preamble_delay[4]={0};
59 60 61
  uint16_t i;


62
  gNB->UL_INFO.rach_ind.number_of_pdus=0;
63 64 65 66 67 68 69 70 71 72 73 74 75

  RU_t *ru;
  int aa=0;
  int ru_aa;

 
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,1);



  for (i=0;i<gNB->num_RU;i++) {
    ru=gNB->RU_list[i];
    for (ru_aa=0,aa=0;ru_aa<ru->nb_rx;ru_aa++,aa++) {
76
      gNB->prach_vars.rxsigF[aa] = gNB->RU_list[i]->prach_rxsigF[ru_aa];
77 78 79
    }
  }

80
  rx_nr_prach(gNB,
81
	      prach_pdu,
82
	      frame,
83
	      slot,
84 85 86
	      &max_preamble[0],
	      &max_preamble_energy[0],
	      &max_preamble_delay[0]
87
	      );
88

89 90
  LOG_D(PHY,"[RAPROC] Frame %d, slot %d : Most likely preamble %d, energy %d dB delay %d (prach_energy counter %d)\n",
        frame,slot,
91 92 93 94 95 96 97 98
        max_preamble[0],
        max_preamble_energy[0]/10,
        max_preamble_delay[0],
	gNB->prach_energy_counter);

  if ((gNB->prach_energy_counter == 100) && 
      (max_preamble_energy[0] > gNB->measurements.prach_I0+100)) {
    
99
    LOG_I(PHY,"[gNB %d][RAPROC] Frame %d, slot %d Initiating RA procedure with preamble %d, energy %d.%d dB, delay %d\n",
100 101
	  gNB->Mod_id,
	  frame,
102
	  slot,
103 104 105 106 107
	  max_preamble[0],
	  max_preamble_energy[0]/10,
	  max_preamble_energy[0]%10,
	  max_preamble_delay[0]);
    
108
    T(T_ENB_PHY_INITIATE_RA_PROCEDURE, T_INT(gNB->Mod_id), T_INT(frame), T_INT(slot),
109 110 111
      T_INT(max_preamble[0]), T_INT(max_preamble_energy[0]), T_INT(max_preamble_delay[0]));
    
    
112 113 114 115
    gNB->UL_INFO.rach_ind.number_of_pdus  = 1;
    gNB->UL_INFO.rach_ind.pdu_list        = &gNB->prach_pdu_indication_list[0];
    gNB->UL_INFO.rach_ind.sfn                                    = frame;
    gNB->UL_INFO.rach_ind.slot            = slot;
116
    
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    gNB->prach_pdu_indication_list[0].phy_cell_id  = gNB->gNB_config.cell_config.phy_cell_id.value;
    gNB->prach_pdu_indication_list[0].symbol_index = prach_pdu->prach_start_symbol;  // FIXME to be changed for multi-ssb (this is only the start symbol of first occasion)
    gNB->prach_pdu_indication_list[0].slot_index   = slot;
    gNB->prach_pdu_indication_list[0].freq_index   = prach_pdu->num_ra;
    gNB->prach_pdu_indication_list[0].avg_rssi     = (max_preamble_energy[0]<631) ? (128+(max_preamble_energy[0]/5)) : 254;
    gNB->prach_pdu_indication_list[0].avg_snr      = 0xff; // invalid for now


    gNB->prach_pdu_indication_list[0].num_preamble                        = 1;
    gNB->prach_pdu_indication_list[0].preamble_list                       = gNB->preamble_list;
    gNB->prach_pdu_indication_list[0].preamble_list[0].preamble_index     = max_preamble[0];
    gNB->prach_pdu_indication_list[0].preamble_list[0].timing_advance     = max_preamble_delay[0];
    gNB->prach_pdu_indication_list[0].preamble_list[0].preamble_pwr       = 0xffffffff;
  }    
  gNB->measurements.prach_I0 = ((gNB->measurements.prach_I0*900)>>10) + ((max_preamble_energy[0]*124)>>10); 
  if (frame==0) LOG_I(PHY,"prach_I0 = %d.%d dB\n",gNB->measurements.prach_I0/10,gNB->measurements.prach_I0%10);
  if (gNB->prach_energy_counter < 100) gNB->prach_energy_counter++;
  
135 136 137

  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PRACH_RX,0);
}
138