gNB_scheduler_bch.c 9.27 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 gNB_scheduler_bch.c
23
 * \brief procedures related to eNB for the BCH transport channel
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
24 25 26
 * \author  Navid Nikaein and Raymond Knopp, WEI-TAI CHEN
 * \date 2010 - 2014, 2018
 * \email: navid.nikaein@eurecom.fr, kroempa@gmail.com
27
 * \version 1.0
WEI-TAI CHEN's avatar
WEI-TAI CHEN committed
28
 * \company Eurecom, NTUST
29 30 31 32 33
 * @ingroup _mac

 */

#include "assertions.h"
34 35 36
#include "NR_MAC_gNB/nr_mac_gNB.h"
#include "NR_MAC_gNB/mac_proto.h"
#include "NR_MAC_COMMON/nr_mac_extern.h"
Raymond Knopp's avatar
Raymond Knopp committed
37 38
#include "common/utils/LOG/log.h"
#include "common/utils/LOG/vcd_signal_dumper.h"
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#include "UTIL/OPT/opt.h"
#include "OCG.h"
#include "OCG_extern.h"

#include "RRC/NR/nr_rrc_extern.h"


//#include "LAYER2/MAC/pre_processor.c"
#include "pdcp.h"

#include "intertask_interface.h"

#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_eNB_SCHEDULER 1

#include "common/ran_context.h"

extern RAN_CONTEXT_t RC;
57
extern uint8_t SSB_Table[38];
58

59
void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP, uint8_t slots_per_frame){
60 61 62 63

  gNB_MAC_INST *gNB = RC.nrmac[module_idP];
  NR_COMMON_channels_t *cc;
  
Raymond Knopp's avatar
Raymond Knopp committed
64 65 66
  nfapi_nr_dl_tti_request_t      *dl_tti_request;
  nfapi_nr_dl_tti_request_body_t *dl_req;
  nfapi_nr_dl_tti_request_pdu_t  *dl_config_pdu;
67 68 69 70 71 72

  int mib_sdu_length;
  int CC_id;

  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
    cc = &gNB->common_channels[CC_id];
73 74 75 76 77
    const long band = *cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0];
    const uint32_t ssb_offset0 = *cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencySSB - cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencyPointA;
    int ratio;
    switch (*cc->ServingCellConfigCommon->ssbSubcarrierSpacing) {
    case NR_SubcarrierSpacing_kHz15:
Robert Schmidt's avatar
Robert Schmidt committed
78 79 80 81 82
      AssertFatal(band <= 79,
                  "Band %ld is not possible for SSB with 15 kHz SCS\n",
                  band);
      if (band < 77)  // below 3GHz
        ratio = 3;    // NRARFCN step is 5 kHz
83
      else
Robert Schmidt's avatar
Robert Schmidt committed
84
        ratio = 1;  // NRARFCN step is 15 kHz
85 86
      break;
    case NR_SubcarrierSpacing_kHz30:
Robert Schmidt's avatar
Robert Schmidt committed
87 88 89 90 91
      AssertFatal(band <= 79,
                  "Band %ld is not possible for SSB with 15 kHz SCS\n",
                  band);
      if (band < 77)  // below 3GHz
        ratio = 6;    // NRARFCN step is 5 kHz
92
      else
Robert Schmidt's avatar
Robert Schmidt committed
93
        ratio = 2;  // NRARFCN step is 15 kHz
94 95
      break;
    case NR_SubcarrierSpacing_kHz120:
Robert Schmidt's avatar
Robert Schmidt committed
96 97 98 99
      AssertFatal(band >= 257,
                  "Band %ld is not possible for SSB with 120 kHz SCS\n",
                  band);
      ratio = 2;  // NRARFCN step is 15 kHz
100 101
      break;
    case NR_SubcarrierSpacing_kHz240:
Robert Schmidt's avatar
Robert Schmidt committed
102 103 104 105
      AssertFatal(band >= 257,
                  "Band %ld is not possible for SSB with 240 kHz SCS\n",
                  band);
      ratio = 4;  // NRARFCN step is 15 kHz
106 107
      break;
    default:
Robert Schmidt's avatar
Robert Schmidt committed
108 109
      AssertFatal(1 == 0, "SCS %ld not allowed for SSB \n",
                  *cc->ServingCellConfigCommon->ssbSubcarrierSpacing);
110
    }
111

112 113 114 115 116
    // scheduling MIB every 8 frames, PHY repeats it in between
    if((slotP == 0) && (frameP & 7) == 0) {
      dl_tti_request = &gNB->DL_req[CC_id];
      dl_req = &dl_tti_request->dl_tti_request_body;

Robert Schmidt's avatar
Robert Schmidt committed
117
      mib_sdu_length = mac_rrc_nr_data_req(module_idP, CC_id, frameP, MIBCH, 1, &cc->MIB_pdu.payload[0]);
118 119 120 121

      LOG_D(MAC, "Frame %d, slot %d: BCH PDU length %d\n", frameP, slotP, mib_sdu_length);

      if (mib_sdu_length > 0) {
Robert Schmidt's avatar
Robert Schmidt committed
122 123 124 125 126 127
        LOG_D(MAC,
              "Frame %d, slot %d: Adding BCH PDU in position %d (length %d)\n",
              frameP,
              slotP,
              dl_req->nPDUs,
              mib_sdu_length);
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

        if ((frameP & 1023) < 80){
          LOG_I(MAC,"[gNB %d] Frame %d : MIB->BCH  CC_id %d, Received %d bytes\n",module_idP, frameP, CC_id, mib_sdu_length);
        }

        dl_config_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
        memset((void *) dl_config_pdu, 0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
        dl_config_pdu->PDUType      = NFAPI_NR_DL_TTI_SSB_PDU_TYPE;
        dl_config_pdu->PDUSize      =2 + sizeof(nfapi_nr_dl_tti_ssb_pdu_rel15_t);

        AssertFatal(cc->ServingCellConfigCommon->physCellId!=NULL,"cc->ServingCellConfigCommon->physCellId is null\n");
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.PhysCellId          = *cc->ServingCellConfigCommon->physCellId;
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.BetaPss             = 0;
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.SsbBlockIndex       = 0;
        AssertFatal(cc->ServingCellConfigCommon->downlinkConfigCommon!=NULL,"scc->downlinkConfigCommonL is null\n");
        AssertFatal(cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL!=NULL,"scc->downlinkConfigCommon->frequencyInfoDL is null\n");
        AssertFatal(cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencySSB!=NULL,"scc->downlinkConfigCommon->frequencyInfoDL->absoluteFrequencySSB is null\n");
        AssertFatal(cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.count==1,"Frequency Band list does not have 1 element (%d)\n",cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.count);
        AssertFatal(cc->ServingCellConfigCommon->ssbSubcarrierSpacing,"ssbSubcarrierSpacing is null\n");
        AssertFatal(cc->ServingCellConfigCommon->downlinkConfigCommon->frequencyInfoDL->frequencyBandList.list.array[0],"band is null\n");

        const nfapi_nr_config_request_scf_t *cfg = &RC.nrmac[module_idP]->config[0];
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.SsbSubcarrierOffset = cfg->ssb_table.ssb_subcarrier_offset.value; //kSSB
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.ssbOffsetPointA     = ssb_offset0/(ratio*12) - 10; // absoluteFrequencySSB is the center of SSB
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.bchPayloadFlag      = 1;
        dl_config_pdu->ssb_pdu.ssb_pdu_rel15.bchPayload          = (*(uint32_t*)cc->MIB_pdu.payload) & ((1<<24)-1);
        dl_req->nPDUs++;
155
      }
156
    }
157

158 159 160 161
    // checking if there is any SSB in slot
    const int abs_slot = (slots_per_frame * frameP) + slotP;
    const int slot_per_period = (slots_per_frame>>1)<<(*cc->ServingCellConfigCommon->ssb_periodicityServingCell);
    int eff_120_slot;
Robert Schmidt's avatar
Robert Schmidt committed
162 163
    const BIT_STRING_t *mediumBitmap = &cc->ServingCellConfigCommon->ssb_PositionsInBurst->choice.mediumBitmap;
    uint8_t buf = 0;
164
    switch (cc->ServingCellConfigCommon->ssb_PositionsInBurst->present) {
Robert Schmidt's avatar
Robert Schmidt committed
165
      case 1:
166
        // presence of ssbs possible in the first 2 slots of ssb period
Robert Schmidt's avatar
Robert Schmidt committed
167 168 169
        if ((abs_slot % slot_per_period) < 2 &&
            (((mediumBitmap->buf[0]) >> (6 - (slotP << 1))) & 3) != 0)
          fill_ssb_vrb_map(cc, (ssb_offset0 / (ratio * 12) - 10), CC_id);
170
        break;
Robert Schmidt's avatar
Robert Schmidt committed
171
      case 2:
172
        // presence of ssbs possible in the first 4 slots of ssb period
Robert Schmidt's avatar
Robert Schmidt committed
173 174 175
        if ((abs_slot % slot_per_period) < 4 &&
            (((mediumBitmap->buf[0]) >> (6 - (slotP << 1))) & 3) != 0)
          fill_ssb_vrb_map(cc, (ssb_offset0 / (ratio * 12) - 10), CC_id);
176
        break;
Robert Schmidt's avatar
Robert Schmidt committed
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
      case 3:
        AssertFatal(*cc->ServingCellConfigCommon->ssbSubcarrierSpacing ==
                      NR_SubcarrierSpacing_kHz120,
                    "240kHZ subcarrier spacing currently not supported for SSBs\n");
        if ((abs_slot % slot_per_period) < 8) {
          eff_120_slot = slotP;
          buf = mediumBitmap->buf[0];
        } else if ((abs_slot % slot_per_period) < 17) {
          eff_120_slot = slotP - 9;
          buf = mediumBitmap->buf[1];
        } else if ((abs_slot % slot_per_period) < 26) {
          eff_120_slot = slotP - 18;
          buf = mediumBitmap->buf[2];
        } else if ((abs_slot % slot_per_period) < 35) {
          eff_120_slot = slotP - 27;
          buf = mediumBitmap->buf[3];
193
        }
Robert Schmidt's avatar
Robert Schmidt committed
194 195
        if (((buf >> (6 - (eff_120_slot << 1))) & 3) != 0)
          fill_ssb_vrb_map(cc, ssb_offset0 / (ratio * 12) - 10, CC_id);
196 197
        break;
    default:
Robert Schmidt's avatar
Robert Schmidt committed
198 199 200
      AssertFatal(0,
                  "SSB bitmap size value %d undefined (allowed values 1,2,3)\n",
                  cc->ServingCellConfigCommon->ssb_PositionsInBurst->present);
201 202 203 204 205
    }
  }
}


206 207
void schedule_nr_SI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP) {
//----------------------------------------  
208
}
209

210
void fill_ssb_vrb_map (NR_COMMON_channels_t *cc, int rbStart, int CC_id) {
211
  uint16_t *vrb_map = cc[CC_id].vrb_map;
212
  for (int rb = 0; rb < 20; rb++)
213
    vrb_map[rbStart + rb] = 1;
214
}