phy_procedures_nr_gNB.c 6.9 KB
Newer Older
Guy De Souza's avatar
Guy De Souza committed
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
 */

22
23
#include "PHY/phy_extern.h"
#include "PHY/defs_gNB.h"
Guy De Souza's avatar
Guy De Souza committed
24
#include "sched_nr.h"
Guy De Souza's avatar
Guy De Souza committed
25
#include "PHY/NR_TRANSPORT/nr_transport.h"
Guy De Souza's avatar
Guy De Souza committed
26
#include "PHY/NR_TRANSPORT/nr_dlsch.h"
27
28
#include "SCHED/sched_eNB.h"
#include "SCHED/sched_common_extern.h"
29
#include "nfapi_interface.h"
Guy De Souza's avatar
Guy De Souza committed
30
#include "SCHED/fapi_l1.h"
31
32
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
Guy De Souza's avatar
Guy De Souza committed
33
34
35
36
37
38
39
40
41
42
43
44

#include "T.h"

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

#include <time.h>

#if defined(ENABLE_ITTI)
#   include "intertask_interface.h"
#endif

Guy De Souza's avatar
Guy De Souza committed
45
extern uint8_t nfapi_mode;
Guy De Souza's avatar
Guy De Souza committed
46
47
48
49
/*
int return_ssb_type(nfapi_config_request_t *cfg)
{
  int mu = cfg->subframe_config.numerology_index_mu.value;
50
  nr_ssb_type_e ssb_type;
Guy De Souza's avatar
Guy De Souza committed
51
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

  switch(mu) {

  case NR_MU_0:
    ssb_type = nr_ssb_type_A;
    break;

  case NR_MU_1:
    ssb_type = nr_ssb_type_B;
    break;

  case NR_MU_3:
    ssb_type = nr_ssb_type_D;
    break;

  case NR_MU_4:
    ssb_type = nr_ssb_type_E;
    break;

  default:
    AssertFatal(0==1, "Invalid numerology index %d for the synchronization block\n", mu);
  }

  LOG_D(PHY, "SSB type %d\n", ssb_type);
  return ssb_type;

}*/

// First SSB starting symbol candidate is used and type B is chosen for 30kHz SCS
ChenWeiTai's avatar
ChenWeiTai committed
80
int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp)
Guy De Souza's avatar
Guy De Souza committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{
  int mu = cfg->subframe_config.numerology_index_mu.value;
  int symbol = 0;

  switch(mu) {

  case NR_MU_0:
    symbol = 2;
    break;

  case NR_MU_1: // case B
    symbol = 4;
    break;

  case NR_MU_3:
    symbol = 4;
    break;

  case NR_MU_4:
    symbol = 8;
    break;

  default:
    AssertFatal(0==1, "Invalid numerology index %d for the synchronization block\n", mu);
  }

  if (cfg->sch_config.half_frame_index.value)
    symbol += (5 * fp->symbols_per_slot * fp->slots_per_subframe);

  return symbol;
}

113
void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp)
Guy De Souza's avatar
Guy De Souza committed
114
{
knopp's avatar
knopp committed
115
  int start_rb = cfg->sch_config.n_ssb_crb.value / (1<<cfg->subframe_config.numerology_index_mu.value);
Guy De Souza's avatar
Guy De Souza committed
116
  fp->ssb_start_subcarrier = 12 * start_rb + cfg->sch_config.ssb_subcarrier_offset.value;
117
  LOG_D(PHY, "SSB first subcarrier %d (%d,%d)\n", fp->ssb_start_subcarrier,start_rb,cfg->sch_config.ssb_subcarrier_offset.value);
Guy De Souza's avatar
Guy De Souza committed
118
}
Guy De Souza's avatar
Guy De Souza committed
119
120
121

void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int subframe) {

Guy De Souza's avatar
Guy De Souza committed
122
  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
ChenWeiTai's avatar
ChenWeiTai committed
123
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
124
125
  int **txdataF = gNB->common_vars.txdataF;
  uint8_t *pbch_pdu=&gNB->pbch_pdu[0];
Guy De Souza's avatar
Guy De Souza committed
126
  int ss_subframe = (cfg->sch_config.half_frame_index.value)? 5 : 0;
Guy De Souza's avatar
Guy De Souza committed
127
  uint8_t Lmax, ssb_index=0, n_hf=0;
Guy De Souza's avatar
Guy De Souza committed
128

Guy De Souza's avatar
Guy De Souza committed
129
  LOG_D(PHY,"common_signal_procedures: frame %d, subframe %d\n",frame,subframe);
130
131

  int ssb_start_symbol = nr_get_ssb_start_symbol(cfg, fp);
Guy De Souza's avatar
Guy De Souza committed
132
  nr_set_ssb_first_subcarrier(cfg, fp);
Guy De Souza's avatar
Guy De Souza committed
133
  Lmax = (fp->dl_CarrierFreq < 3e9)? 4:8;
134

Guy De Souza's avatar
Guy De Souza committed
135

Guy De Souza's avatar
Guy De Souza committed
136
  if (subframe == ss_subframe)
137
  {
Guy De Souza's avatar
Guy De Souza committed
138
    // Current implementation is based on SSB in first half frame, first candidate
139
    LOG_D(PHY,"SS TX: frame %d, subframe %d, start_symbol %d\n",frame,subframe, ssb_start_symbol);
140

141
142
    nr_generate_pss(gNB->d_pss, txdataF, AMP, ssb_start_symbol, cfg, fp);
    nr_generate_sss(gNB->d_sss, txdataF, AMP_OVER_2, ssb_start_symbol, cfg, fp);
143

Guy De Souza's avatar
Guy De Souza committed
144
    if (!(frame&7)){
145
      LOG_D(PHY,"%d.%d : pbch_configured %d\n",frame,subframe,gNB->pbch_configured);
146
147
      if (gNB->pbch_configured != 1)return;
      gNB->pbch_configured = 0;
Guy De Souza's avatar
Guy De Souza committed
148
    }
Guy De Souza's avatar
Guy De Souza committed
149
    nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF, AMP_OVER_2, ssb_start_symbol, cfg, fp);
Guy De Souza's avatar
Guy De Souza committed
150
151
152
153
154
155
156
157
158
    nr_generate_pbch(&gNB->pbch,
                      gNB->nrPolar_params,
                      pbch_pdu,
                      gNB->nr_pbch_interleaver,
                      txdataF,
                      AMP_OVER_2,
                      ssb_start_symbol,
                      n_hf,Lmax,ssb_index,
                      frame, cfg, fp);
159
  }
Guy De Souza's avatar
Guy De Souza committed
160
161
162
163

}

void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB,
Wang Tsu-Han's avatar
Wang Tsu-Han committed
164
						   gNB_L1_rxtx_proc_t *proc,
165
						   int do_meas)
Guy De Souza's avatar
Guy De Souza committed
166
167
168
169
{
  int aa;
  int frame=proc->frame_tx;
  int subframe=proc->subframe_tx;
Guy De Souza's avatar
Guy De Souza committed
170
  uint8_t num_dci=0, num_pdsch_rnti;
Guy De Souza's avatar
Guy De Souza committed
171
172

  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
ChenWeiTai's avatar
ChenWeiTai committed
173
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
174
175
176
177
178

  int offset = gNB->CC_id;

  if ((cfg->subframe_config.duplex_mode.value == TDD) && (nr_subframe_select(cfg,subframe)==SF_UL)) return;

179
180
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
  if (do_meas==1) start_meas(&gNB->phy_proc_tx);
Guy De Souza's avatar
Guy De Souza committed
181
182
183

  // clear the transmit data array for the current subframe
  for (aa=0; aa<cfg->rf_config.tx_antenna_ports.value; aa++) {      
Guy De Souza's avatar
Guy De Souza committed
184
    memset(gNB->common_vars.txdataF[aa],0,fp->samples_per_subframe_wCP*sizeof(int32_t));
Guy De Souza's avatar
Guy De Souza committed
185
186
187
  }

  if (nfapi_mode == 0 || nfapi_mode == 1) {
Guy De Souza's avatar
Guy De Souza committed
188
    nr_common_signal_procedures(gNB,frame, subframe);
Guy De Souza's avatar
Guy De Souza committed
189
190
    //if (frame == 9)
      //write_output("txdataF.m","txdataF",gNB->common_vars.txdataF[aa],fp->samples_per_frame_wCP, 1, 1);
191
192
193
  }

  num_dci = gNB->pdcch_vars.num_dci;
Guy De Souza's avatar
Guy De Souza committed
194
  num_pdsch_rnti = gNB->pdcch_vars.num_pdsch_rnti;
Florian Kaltenberger's avatar
WIP2    
Florian Kaltenberger committed
195
  if (num_dci) {
196
197
    LOG_I(PHY, "[gNB %d] Frame %d subframe %d \
    Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, subframe, num_dci);
198

Guy De Souza's avatar
Guy De Souza committed
199
    uint8_t slot_idx = gNB->pdcch_vars.dci_alloc[0].pdcch_params.first_slot + subframe*fp->slots_per_subframe;
Guy De Souza's avatar
Guy De Souza committed
200

Guy De Souza's avatar
Guy De Souza committed
201
    if (nfapi_mode == 0 || nfapi_mode == 1){
202
      nr_generate_dci_top(gNB->pdcch_vars,
203
                          &gNB->nrPolar_params,
Guy De Souza's avatar
Guy De Souza committed
204
                          gNB->nr_gold_pdcch_dmrs[slot_idx],
205
206
                          gNB->common_vars.txdataF,
                          AMP, *fp, *cfg);
Guy De Souza's avatar
Guy De Souza committed
207
208
      if (num_pdsch_rnti) {
        LOG_I(PHY, "PDSCH generation started (%d)\n", num_pdsch_rnti);
Guy De Souza's avatar
Guy De Souza committed
209
        nr_generate_pdsch(*gNB->dlsch[0][0],
Guy De Souza's avatar
Guy De Souza committed
210
                          gNB->pdcch_vars.dci_alloc[0],
Guy De Souza's avatar
Guy De Souza committed
211
212
213
214
215
                          gNB->nr_gold_pdsch_dmrs[slot_idx],
                          gNB->common_vars.txdataF,
                          AMP, subframe, *fp, *cfg);
      }
    }
Guy De Souza's avatar
Guy De Souza committed
216
  }
217
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0);
218

Guy De Souza's avatar
Guy De Souza committed
219
}