phy_procedures_nr_gNB.c 7.47 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

#include "T.h"

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

#include <time.h>

#if defined(ENABLE_ITTI)
42
  #include "intertask_interface.h"
Guy De Souza's avatar
Guy De Souza committed
43
44
#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

  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;

}*/

79

Guy De Souza's avatar
Guy De Souza committed
80
81
// First SSB starting symbol candidate is used and type B is chosen for 30kHz SCS

82
int nr_get_ssb_start_symbol(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp, uint8_t i_ssb)
Guy De Souza's avatar
Guy De Souza committed
83
84
85
86
{

  int mu = cfg->subframe_config.numerology_index_mu.value;
  int symbol = 0;
87
88
89
90
91
92
  uint8_t n, n_temp;
  nr_ssb_type_e type = fp->ssb_type;
  int case_AC[2] = {2,8};
  int case_BD[4] = {4,8,16,20};
  int case_E[8] = {8, 12, 16, 20, 32, 36, 40, 44};

Guy De Souza's avatar
Guy De Souza committed
93
94
95

  switch(mu) {

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	case NR_MU_0: // case A
	    n = i_ssb >> 1;
	    symbol = case_AC[i_ssb % 2] + 14*n;
	break;

	case NR_MU_1: 
	    if (type == 1){ // case B
		n = i_ssb >> 2;
	    	symbol = case_BD[i_ssb % 4] + 28*n;
	    }
	    if (type == 2){ // case C
		n = i_ssb >> 1;
		symbol = case_AC[i_ssb % 2] + 14*n;
	    }
	 break;

	 case NR_MU_3: // case D
	    n_temp = i_ssb >> 2; 
	    n = n_temp + (n_temp >> 2);
	    symbol = case_BD[i_ssb % 4] + 28*n;
	 break;

	 case NR_MU_4:  // case E
	    n_temp = i_ssb >> 3; 
	    n = n_temp + (n_temp >> 2);
	    symbol = case_E[i_ssb % 8] + 56*n;
	 break;


	 default:
	      AssertFatal(0==1, "Invalid numerology index %d for the synchronization block\n", mu);
Guy De Souza's avatar
Guy De Souza committed
127
128
129
130
131
132
133
134
  }

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

  return symbol;
}

135
void nr_set_ssb_first_subcarrier(nfapi_nr_config_request_t *cfg, NR_DL_FRAME_PARMS *fp) {
136
137
  fp->ssb_start_subcarrier = (12 * cfg->sch_config.n_ssb_crb.value + cfg->sch_config.ssb_subcarrier_offset.value)/(1<<cfg->subframe_config.numerology_index_mu.value);
  LOG_D(PHY, "SSB first subcarrier %d (%d,%d)\n", fp->ssb_start_subcarrier,cfg->sch_config.n_ssb_crb.value,cfg->sch_config.ssb_subcarrier_offset.value);
Guy De Souza's avatar
Guy De Souza committed
138
}
Guy De Souza's avatar
Guy De Souza committed
139

140
void nr_common_signal_procedures (PHY_VARS_gNB *gNB,int frame, int slot) {
Guy De Souza's avatar
Guy De Souza committed
141
  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
ChenWeiTai's avatar
ChenWeiTai committed
142
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
143
144
  int **txdataF = gNB->common_vars.txdataF;
  uint8_t *pbch_pdu=&gNB->pbch_pdu[0];
145
  uint8_t ssb_index, n_hf;
146
  int ssb_start_symbol, rel_slot;
Guy De Souza's avatar
Guy De Souza committed
147

148
  n_hf = cfg->sch_config.half_frame_index.value;
149
  // to set a effective slot number between 0 to 9 in the half frame where the SSB is supposed to be
150
  rel_slot = (n_hf)? (slot-10) : slot; 
151

152
153
  
  LOG_D(PHY,"common_signal_procedures: frame %d, slot %d\n",frame,slot);
Guy De Souza's avatar
Guy De Souza committed
154

155
156
157
  if(rel_slot<10 && rel_slot>=0)  {
     for (int i=0; i<2; i++)  {  // max two SSB per frame
     
158
	ssb_index = i + 2*rel_slot; // computing the ssb_index
159
160
	if ((fp->L_ssb >> ssb_index) & 0x01)  { // generating the ssb only if the bit of L_ssb at current ssb index is 1
	
161
162
163
	  int ssb_start_symbol_abs = nr_get_ssb_start_symbol(cfg, fp, ssb_index); // computing the starting symbol for current ssb
	  ssb_start_symbol = ssb_start_symbol_abs % 14;  // start symbol wrt slot

164
	  nr_set_ssb_first_subcarrier(cfg, fp);  // setting the first subcarrier
165
166
167
168
169
170
171
172
	  
    	  LOG_D(PHY,"SS TX: frame %d, slot %d, start_symbol %d\n",frame,slot, ssb_start_symbol);
    	  nr_generate_pss(gNB->d_pss, txdataF[0], AMP, ssb_start_symbol, cfg, fp);
    	  nr_generate_sss(gNB->d_sss, txdataF[0], AMP, ssb_start_symbol, cfg, fp);

	  nr_generate_pbch_dmrs(gNB->nr_gold_pbch_dmrs[n_hf][ssb_index],txdataF[0], AMP, ssb_start_symbol, cfg, fp);

    	  nr_generate_pbch(&gNB->pbch,
Guy De Souza's avatar
Guy De Souza committed
173
174
                      pbch_pdu,
                      gNB->nr_pbch_interleaver,
175
                      txdataF[0],
176
                      AMP,
Guy De Souza's avatar
Guy De Souza committed
177
                      ssb_start_symbol,
178
                      n_hf,fp->Lmax,ssb_index,
Guy De Souza's avatar
Guy De Souza committed
179
                      frame, cfg, fp);
180
181
	}
     }
182
  }
Guy De Souza's avatar
Guy De Souza committed
183
184
185
}

void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB,
186
187
                           gNB_L1_rxtx_proc_t *proc,
                           int do_meas) {
Guy De Souza's avatar
Guy De Souza committed
188
189
  int aa;
  int frame=proc->frame_tx;
190
  int slot=proc->slot_tx;
191
  uint8_t num_dci=0,num_pdsch_rnti;
Guy De Souza's avatar
Guy De Souza committed
192
  NR_DL_FRAME_PARMS *fp=&gNB->frame_parms;
ChenWeiTai's avatar
ChenWeiTai committed
193
  nfapi_nr_config_request_t *cfg = &gNB->gNB_config;
Guy De Souza's avatar
Guy De Souza committed
194
195
  int offset = gNB->CC_id;

196
  if ((cfg->subframe_config.duplex_mode.value == TDD) && (nr_slot_select(cfg,slot)==SF_UL)) return;
Guy De Souza's avatar
Guy De Souza committed
197

198
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
199

200
  if (do_meas==1) start_meas(&gNB->phy_proc_tx);
Guy De Souza's avatar
Guy De Souza committed
201
202

  // clear the transmit data array for the current subframe
203
  for (aa=0; aa<1/*15*/; aa++) {
204
    memset(gNB->common_vars.txdataF[aa],0,fp->samples_per_slot_wCP*sizeof(int32_t));
Guy De Souza's avatar
Guy De Souza committed
205
206
207
  }

  if (nfapi_mode == 0 || nfapi_mode == 1) {
208
    nr_common_signal_procedures(gNB,frame, slot);
Guy De Souza's avatar
Guy De Souza committed
209
    //if (frame == 9)
210
    //write_output("txdataF.m","txdataF",gNB->common_vars.txdataF[aa],fp->samples_per_frame_wCP, 1, 1);
211
212
213
  }

  num_dci = gNB->pdcch_vars.num_dci;
214
  num_pdsch_rnti = gNB->pdcch_vars.num_pdsch_rnti;
215

216
  if (num_dci) {
217
218
    LOG_I(PHY, "[gNB %d] Frame %d slot %d \
    Calling nr_generate_dci_top (number of DCI %d)\n", gNB->Mod_id, frame, slot, num_dci);
Guy De Souza's avatar
Guy De Souza committed
219

220
    if (nfapi_mode == 0 || nfapi_mode == 1) {
221
      nr_generate_dci_top(gNB->pdcch_vars,
222
                          gNB->nr_gold_pdcch_dmrs[slot],
223
                          gNB->common_vars.txdataF[0],
224
                          AMP, *fp, *cfg);
225

Guy De Souza's avatar
Guy De Souza committed
226
227
      if (num_pdsch_rnti) {
        LOG_I(PHY, "PDSCH generation started (%d)\n", num_pdsch_rnti);
Guy De Souza's avatar
Guy De Souza committed
228
        nr_generate_pdsch(*gNB->dlsch[0][0],
Guy De Souza's avatar
Guy De Souza committed
229
                          gNB->pdcch_vars.dci_alloc[0],
230
                          gNB->nr_gold_pdsch_dmrs[slot],
Guy De Souza's avatar
Guy De Souza committed
231
                          gNB->common_vars.txdataF,
232
                          AMP, slot, *fp, *cfg);
Guy De Souza's avatar
Guy De Souza committed
233
234
      }
    }
235
  }
236

237
  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0);
Guy De Souza's avatar
Guy De Souza committed
238
}