fapi_nr_l1.c 7.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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
 */

WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
22
/*! \file fapi_nr_l1.c
23
 * \brief functions for FAPI L1 interface
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
24 25
 * \author R. Knopp, WEI-TAI CHEN
 * \date 2017, 2018
26
 * \version 0.1
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
27 28
 * \company Eurecom, NTUST
 * \email: knopp@eurecom.fr, kroempa@gmail.com
29 30 31 32
 * \note
 * \warning
 */
#include "fapi_nr_l1.h"
33
#include "PHY/NR_TRANSPORT/nr_transport_proto.h"
34 35
#include "PHY/NR_TRANSPORT/nr_dlsch.h"
#include "PHY/NR_TRANSPORT/nr_dci.h"
36

37

38 39
extern uint8_t nfapi_mode;

40
void handle_nr_nfapi_ssb_pdu(PHY_VARS_gNB *gNB,int frame,int slot,
Raymond Knopp's avatar
Raymond Knopp committed
41
                             nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdu)
42 43
{

Raymond Knopp's avatar
Raymond Knopp committed
44 45
  AssertFatal(dl_tti_pdu->ssb_pdu.ssb_pdu_rel15.bchPayloadFlag== 1, "bchPayloadFlat %d != 1\n",
              dl_tti_pdu->ssb_pdu.ssb_pdu_rel15.bchPayloadFlag);
46

47
  LOG_I(PHY,"%d.%d : pbch_pdu: %x\n",frame,slot,dl_tti_pdu->ssb_pdu.ssb_pdu_rel15.bchPayload);
Raymond Knopp's avatar
Raymond Knopp committed
48
  gNB->ssb_pdu = &dl_tti_pdu->ssb_pdu;
49 50
}

51
/*void handle_nr_nfapi_pdsch_pdu(PHY_VARS_gNB *gNB,int frame,int subframe,gNB_L1_rxtx_proc_t *proc,
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
                            uint8_t codeword_index,
                            uint8_t *sdu)
{

	int UE_id = 0; //Hardcode UE_id for now
	int harq_pid;

	NR_gNB_DLSCH_t *dlsch0=NULL, *dlsch1=NULL;
	NR_DL_gNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;

    // Based on nr_fill_dci_and_dlsch only gNB->dlsch[0][0] gets filled now. So maybe we do not need dlsch1.
	dlsch0 = gNB->dlsch[UE_id][0];
	dlsch1 = gNB->dlsch[UE_id][1];

	harq_pid        = dlsch0->harq_ids[subframe];
	dlsch0_harq     = dlsch0->harq_processes[harq_pid];
	dlsch1_harq     = dlsch1->harq_processes[harq_pid];


	//if (dlsch0_harq->round==0) {  //get pointer to SDU if this a new SDU
    if(sdu == NULL) {
      LOG_E(PHY,"NFAPI: SFN/SF:%04d%d proc:TX:[frame %d subframe %d]: programming dlsch for round 0 \n",
            frame,subframe,
            proc->frame_tx,proc->slot_tx);
      return;
    }
    //AssertFatal(sdu!=NULL,"NFAPI: SFN/SF:%04d%d proc:TX:[frame %d subframe %d]: programming dlsch for round 0, rnti %x, UE_id %d, harq_pid %d : sdu is null for pdu_index %d dlsch0_harq[round:%d SFN/SF:%d%d pdu:%p mcs:%d ndi:%d pdschstart:%d]\n",
    //            frame,subframe,
    //            proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid,
Raymond Knopp's avatar
Raymond Knopp committed
81
    //            dl_tti_pdu->pdsch_pdu.pdsch_pdu_rel8.pdu_index,dlsch0_harq->round,dlsch0_harq->frame,dlsch0_harq->subframe,dlsch0_harq->pdu,dlsch0_harq->mcs,dlsch0_harq->ndi,dlsch0_harq->pdsch_start);
82 83
    if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
    else                     dlsch1_harq->pdu                    = sdu;
84
    LOG_I(PHY, "SFN/SF: %d/%d DLSCH PDU filled \n",frame, subframe);
85 86
//  }

87
}*/
88

89

90 91
void handle_nfapi_nr_pdcch_pdu(PHY_VARS_gNB *gNB,
			       int frame, int slot,
Raymond Knopp's avatar
Raymond Knopp committed
92
			       nfapi_nr_dl_tti_pdcch_pdu *pdcch_pdu) {
93

94
  LOG_D(PHY,"Frame %d, Slot %d: DCI processing - proc:slot_tx:%d pdcch_pdu_rel15->numDlDci:%d\n",frame,slot, slot, pdcch_pdu->pdcch_pdu_rel15.numDlDci);
95 96

  // copy dci configuration into gNB structure
97 98 99 100
  gNB->pdcch_pdu = pdcch_pdu;

  nr_fill_dci(gNB,frame,slot);

101

102 103 104

}

105 106 107 108 109 110 111 112 113 114 115 116 117 118
void handle_nfapi_nr_ul_dci_pdu(PHY_VARS_gNB *gNB,
			       int frame, int slot,
			       nfapi_nr_ul_dci_request_pdus_t *ul_dci_request_pdu) {

  LOG_D(PHY,"Frame %d, Slot %d: UL DCI processing - proc:slot_tx:%d pdcch_pdu_rel15->numDlDci:%d\n",frame,slot, slot, ul_dci_request_pdu->pdcch_pdu.pdcch_pdu_rel15.numDlDci);

  // copy dci configuration into gNB structure
  gNB->ul_dci_pdu = ul_dci_request_pdu;

  nr_fill_ul_dci(gNB,frame,slot);



}
119

120
void handle_nr_nfapi_pdsch_pdu(PHY_VARS_gNB *gNB,int frame,int slot,
Raymond Knopp's avatar
Raymond Knopp committed
121
                            nfapi_nr_dl_tti_pdsch_pdu *pdsch_pdu,
122 123 124 125
                            uint8_t *sdu)
{


126
  nr_fill_dlsch(gNB,frame,slot,pdsch_pdu,sdu);
127 128 129

}

130
void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO){
131

132 133 134 135
  PHY_VARS_gNB *gNB;
  // copy data from L2 interface into L1 structures
  module_id_t                   Mod_id       = Sched_INFO->module_id;
  uint8_t                       CC_id        = Sched_INFO->CC_id;
Raymond Knopp's avatar
Raymond Knopp committed
136 137
  nfapi_nr_dl_tti_request_t     *DL_req      = Sched_INFO->DL_req;
  nfapi_nr_tx_data_request_t    *TX_req      = Sched_INFO->TX_req;
138
  nfapi_nr_ul_tti_request_t     *UL_tti_req  = Sched_INFO->UL_tti_req;
139
  nfapi_nr_ul_dci_request_t     *UL_dci_req  = Sched_INFO->UL_dci_req;
140
  frame_t                       frame        = Sched_INFO->frame;
141
  sub_frame_t                   slot         = Sched_INFO->slot;
142 143 144 145

  AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");
  AssertFatal(RC.gNB[Mod_id]!=NULL,"RC.gNB[%d] is null\n",Mod_id);

146
  gNB         = RC.gNB[Mod_id];
147

Raymond Knopp's avatar
Raymond Knopp committed
148
  uint8_t number_dl_pdu             = DL_req->dl_tti_request_body.nPDUs;
149
  uint8_t number_ul_pdu             = 0;
150
  uint8_t number_ul_dci_pdu         = UL_dci_req->numPdus;
151

152 153
  if (UL_tti_req != NULL) number_ul_pdu = UL_tti_req->n_pdus;

Raymond Knopp's avatar
Raymond Knopp committed
154
  LOG_D(PHY,"NFAPI: Sched_INFO:SFN/SLOT:%04d%d DL_req:SFN/SLO:%04d%d:dl_pdu:%d tx_req:SFN/SLOT:%04d%d:pdus:%d \n",
155
        frame,slot,
Raymond Knopp's avatar
Raymond Knopp committed
156 157
        DL_req->SFN,DL_req->Slot,number_dl_pdu,
        TX_req->SFN,TX_req->Slot,TX_req->Number_of_PDUs);
158 159 160

  int do_oai =0;
  int dont_send =0;
161 162 163
  int pdcch_received=0;
  gNB->num_pdsch_rnti=0;
  gNB->pdcch_pdu = NULL;
164
  gNB->pbch_configured=0;
165

Raymond Knopp's avatar
Raymond Knopp committed
166
  for (int i=0;i<number_dl_pdu;i++) {
Raymond Knopp's avatar
Raymond Knopp committed
167 168 169 170
    nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdu = &DL_req->dl_tti_request_body.dl_tti_pdu_list[i];
    LOG_D(PHY,"NFAPI: dl_pdu %d : type %d\n",i,dl_tti_pdu->PDUType);
    switch (dl_tti_pdu->PDUType) {
      case NFAPI_NR_DL_TTI_SSB_PDU_TYPE:
171
	gNB->pbch_configured=1;
172 173
        do_oai=1;

174
        handle_nr_nfapi_ssb_pdu(gNB,frame,slot,
Raymond Knopp's avatar
Raymond Knopp committed
175 176
                                dl_tti_pdu);

177
      break;
178

Raymond Knopp's avatar
Raymond Knopp committed
179
      case NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE:
180
	AssertFatal(pdcch_received == 0, "pdcch_received is not 0, we can only handle one PDCCH PDU per slot\n");
181 182
        handle_nfapi_nr_pdcch_pdu(gNB,
				  frame, slot,
Raymond Knopp's avatar
Raymond Knopp committed
183 184
				  &dl_tti_pdu->pdcch_pdu);
 
185
	pdcch_received = 1;
186 187
        do_oai=1;
      break;
Raymond Knopp's avatar
Raymond Knopp committed
188
      case NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE:
189 190

      {
Raymond Knopp's avatar
Raymond Knopp committed
191
        nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdu->pdsch_pdu.pdsch_pdu_rel15;
192
        uint16_t pduIndex = pdsch_pdu_rel15->pduIndex;
Raymond Knopp's avatar
Raymond Knopp committed
193 194 195 196 197
        uint16_t tx_pdus = TX_req->Number_of_PDUs;
	AssertFatal(TX_req->pdu_list[pduIndex].num_TLV == 1, "TX_req->pdu_list[%d].num_TLV %d != 1\n",
		    pduIndex,TX_req->pdu_list[pduIndex].num_TLV);
        uint8_t *sdu = TX_req->pdu_list[pduIndex].TLVs[0].value.direct;
        handle_nr_nfapi_pdsch_pdu(gNB,frame,slot,&dl_tti_pdu->pdsch_pdu, sdu);
198 199
        do_oai=1;
      }
200 201
    }
  }
202

203
  if (UL_tti_req!=NULL) memcpy(&gNB->UL_tti_req,UL_tti_req,sizeof(nfapi_nr_ul_tti_request_t));
204
  
205 206 207 208
  for (int i=0;i<number_ul_dci_pdu;i++) {
    handle_nfapi_nr_ul_dci_pdu(gNB,
			      frame, slot,
			      &UL_dci_req->ul_dci_pdu_list[i]);
209
  }
210 211


212
}