main.c 5.51 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
/*
 * 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 main.c
 * \brief top init of Layer 2
ChenWeiTai's avatar
ChenWeiTai committed
24 25
 * \author  Navid Nikaein and Raymond Knopp, WEI-TAI CHEN
 * \date 2010 - 2014, 2018
26
 * \version 1.0
ChenWeiTai's avatar
ChenWeiTai committed
27 28
 * \company Eurecom, NTUST
 * \email: navid.nikaein@eurecom.fr, kroempa@gmail.com
29 30 31 32 33 34 35 36 37 38
 * @ingroup _mac

 */

#include "mac_proto.h"
#include "LAYER2/MAC/mac_extern.h" //temporary
#include "assertions.h"

#include "LAYER2/PDCP_v10.1.0/pdcp.h"
#include "RRC/NR/nr_rrc_defs.h"
knopp's avatar
knopp committed
39
#include "common/utils/LOG/log.h"
40 41 42 43 44 45 46
//#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"

#include "common/ran_context.h"

extern RAN_CONTEXT_t RC;


47 48 49
void nr_init_coreset(nfapi_nr_coreset_t *coreset) {

  coreset->coreset_id = 1;
50
  coreset->frequency_domain_resources = 0x1E0000000000;//0x1FFFE0000000; // 96 RB starting from CRB0
51 52
  coreset->duration = 2;
  coreset->cce_reg_mapping_type = NFAPI_NR_CCE_REG_MAPPING_NON_INTERLEAVED;
Guy De Souza's avatar
Guy De Souza committed
53 54
  coreset->reg_bundle_size = 6;
  coreset->interleaver_size = 2;
55
  coreset->precoder_granularity = NFAPI_NR_CSET_SAME_AS_REG_BUNDLE;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  coreset->tci_present_in_dci = 0;
  coreset->dmrs_scrambling_id = 0;
}

void nr_init_search_space(nfapi_nr_search_space_t *search_space) {

  search_space->search_space_id = 1;
  search_space->coreset_id = 1;
  search_space->search_space_type = NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC;
  search_space->duration = 5;
  search_space->slot_monitoring_periodicity = NFAPI_NR_SS_PERIODICITY_SL10;
  search_space->slot_monitoring_offset = 1;
  search_space->monitoring_symbols_in_slot = 0xC0000000; // first 2 ofdm symbols
  search_space->css_formats_0_0_and_1_0 = 1;
  search_space->uss_dci_formats = 0; // enum to be defined-- formats 0.0 and 1.0
  for (int i=0; i<NFAPI_NR_MAX_NB_CCE_AGGREGATION_LEVELS; i++)
    search_space->number_of_candidates[i] = 4; // TODO
}

75 76
void mac_top_init_gNB(void)
{
ChenWeiTai's avatar
ChenWeiTai committed
77
  module_id_t     i,j;
78 79 80 81 82 83 84 85 86
  int             list_el;
  UE_list_t       *UE_list;
  gNB_MAC_INST    *nrmac;

  LOG_I(MAC, "[MAIN] Init function start:nb_nr_macrlc_inst=%d\n",RC.nb_nr_macrlc_inst);

  if (RC.nb_nr_macrlc_inst > 0) {
    
    RC.nrmac = (gNB_MAC_INST **) malloc16(RC.nb_nr_macrlc_inst *sizeof(gNB_MAC_INST *));
87

88 89 90 91 92 93
    AssertFatal(RC.nrmac != NULL,"can't ALLOCATE %zu Bytes for %d gNB_MAC_INST with size %zu \n",
                RC.nb_nr_macrlc_inst * sizeof(gNB_MAC_INST *),
                RC.nb_nr_macrlc_inst, sizeof(gNB_MAC_INST));
  
    for (i = 0; i < RC.nb_nr_macrlc_inst; i++) {
        RC.nrmac[i] = (gNB_MAC_INST *) malloc16(sizeof(gNB_MAC_INST));
94

95 96 97 98 99
        AssertFatal(RC.nrmac != NULL,"can't ALLOCATE %zu Bytes for %d gNB_MAC_INST with size %zu \n",
                    RC.nb_nr_macrlc_inst * sizeof(gNB_MAC_INST *),
                    RC.nb_nr_macrlc_inst, sizeof(gNB_MAC_INST));
        
        LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d gNB_MAC_INST @ %p\n",sizeof(gNB_MAC_INST), RC.nb_nr_macrlc_inst, RC.mac);
100

101
        bzero(RC.nrmac[i], sizeof(gNB_MAC_INST));
102

103
        RC.nrmac[i]->Mod_id = i;
104

ChenWeiTai's avatar
ChenWeiTai committed
105
        
106 107 108 109 110 111 112 113 114
        for (j = 0; j < MAX_NUM_CCs; j++) {
          RC.nrmac[i]->DL_req[j].dl_config_request_body.dl_config_pdu_list = RC.nrmac[i]->dl_config_pdu_list[j];
          RC.nrmac[i]->UL_req[j].ul_config_request_body.ul_config_pdu_list = RC.nrmac[i]->ul_config_pdu_list[j];
          
          for (int k = 0; k < 10; k++)
            RC.nrmac[i]->UL_req_tmp[j][k].ul_config_request_body.ul_config_pdu_list =RC.nrmac[i]->ul_config_pdu_list_tmp[j][k];
        
        RC.nrmac[i]->HI_DCI0_req[j].hi_dci0_request_body.hi_dci0_pdu_list = RC.nrmac[i]->hi_dci0_pdu_list[j];
        RC.nrmac[i]->TX_req[j].tx_request_body.tx_pdu_list =                RC.nrmac[i]->tx_request_pdu[j];
115 116 117 118 119
        RC.nrmac[i]->ul_handle = 0;

        // Init PDCCH structures
        nr_init_coreset(&RC.nrmac[i]->coreset[j][1]);
        nr_init_search_space(&RC.nrmac[i]->search_space[j][1]);
120
        }
ChenWeiTai's avatar
ChenWeiTai committed
121
        
122 123 124 125 126 127 128 129

    }//END for (i = 0; i < RC.nb_nr_macrlc_inst; i++)

  AssertFatal(rlc_module_init() == 0,"Could not initialize RLC layer\n");

  // These should be out of here later
  pdcp_layer_init();

130
  rrc_init_nr_global_param();
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

  }else {
    RC.nrmac = NULL;
  }

  // Initialize Linked-List for Active UEs
  for (i = 0; i < RC.nb_nr_macrlc_inst; i++) {
    
    nrmac = RC.nrmac[i];
    nrmac->if_inst = NR_IF_Module_init(i);

    UE_list = &nrmac->UE_list;
    UE_list->num_UEs = 0;
    UE_list->head = -1;
    UE_list->head_ul = -1;
    UE_list->avail = 0;

    for (list_el = 0; list_el < MAX_MOBILES_PER_ENB - 1; list_el++) {
      UE_list->next[list_el] = list_el + 1;
      UE_list->next_ul[list_el] = list_el + 1;
    }

    UE_list->next[list_el] = -1;
    UE_list->next_ul[list_el] = -1;
  }

knopp's avatar
knopp committed
157
}