Commit 4269152f authored by Nick Ho's avatar Nick Ho

MAC LAYER NB-IoT function first added

parent 5da7305f
This diff is collapsed.
......@@ -229,7 +229,7 @@ typedef struct sibs_NB_IoT_sched_s{
si_periodicity_t si_periodicity;
si_repetition_pattern_t si_repetition_pattern;
sib_MappingInfo_NB_IoT sib_mapping_info; //bit vector
si_tb_t si_tb;
si_TB_NB_IoT si_tb;
} sibs_NB_IoT_sched_t;
......
......@@ -15,7 +15,7 @@
#endif
//#include "COMMON/openair_defs.h"
#include "COMMON/platform_constants.h"
#include "COMMON/mac_rrc_primitives.h"
//#include "COMMON/mac_rrc_primitives.h"
#include "PHY/NBIoT_TRANSPORT/defs_NB_IoT.h"
//#include "PHY/defs.h"
#include "PHY/defs_L1_NB_IoT.h"
......
This diff is collapsed.
This diff is collapsed.
/*! \file eNB_scheduler_bch_NB_IoT.c
* \brief schedule functions for SIBs transmission in NB-IoT
* \author NTUST BMW Lab./
* \date 2017
* \email:
* \version 1.0
*
*/
#include "defs_NB_IoT.h"
#include "proto_NB_IoT.h"
#include "extern_NB_IoT.h"
#include "openair2/RRC/NBIOT/proto_NB_IoT.h"
char str[6][7] = { "SIBs_1", "SIBs_2", "SIBs_3", "SIBs_4", "SIBs_5", "SIBs_6" };
#define num_flags 2
extern int extend_space[num_flags];
extern int extend_alpha_offset[num_flags];
uint32_t get_SIB23_size(void)
{
rrc_config_NB_IoT_t *mac_config = &mac_inst->rrc_config;
uint32_t size_SIB23_in_MAC = 0;
switch(mac_config->sibs_NB_IoT_sched[0].si_tb)
{
case si_TB_56:
size_SIB23_in_MAC = 56;
break;
case si_TB_120:
size_SIB23_in_MAC = 120;
break;
case si_TB_208:
size_SIB23_in_MAC = 208;
break;
case si_TB_256:
size_SIB23_in_MAC = 256;
break;
case si_TB_328:
size_SIB23_in_MAC = 328;
break;
case si_TB_440:
size_SIB23_in_MAC = 440;
break;
case si_TB_552:
size_SIB23_in_MAC = 552;
break;
case si_TB_680:
size_SIB23_in_MAC = 680;
break;
default:
LOG_E(MAC,"No index for SIB23 size from SIB1!\n");
break;
}
return size_SIB23_in_MAC;
}
void schedule_sibs(eNB_MAC_INST_NB_IoT *mac_inst, uint32_t sibs_order, int start_subframe1){
available_resource_DL_t *pt[8] = { (available_resource_DL_t *)0 };
int first_subframe[8] = { -1 };
//uint32_t end_subframe[8] = { -1 };
schedule_result_t *new_node;
DCIFormatN1_t *sibs_dci;
uint32_t j, i, k;
uint32_t SIB23_size = 0;
uint8_t *SIB23_pdu = get_NB_IoT_SIB23();
int residual_subframe, num_subframe, last_subframe;
uint8_t num_subframe_per_SIB = 0;
SIB23_size = get_SIB23_size();
if(SIB23_size > 0 && SIB23_size <= 120)
num_subframe_per_SIB = 2;
else if(SIB23_size > 120 && SIB23_size <= 680)
num_subframe_per_SIB = 8;
else
LOG_E(MAC,"Invalid SIB size\n");
num_subframe = num_subframe_per_SIB *4;
int rmax = mac_inst->rrc_config.mac_NPRACH_ConfigSIB[0].mac_npdcch_NumRepetitions_RA_NB_IoT;
rmax = (rmax * 10) >> 3; // x1.25
for(k=0, i=start_subframe1; i<(start_subframe1+mac_inst->rrc_config.si_window_length); i+=si_repetition_pattern[mac_inst->rrc_config.sibs_NB_IoT_sched[sibs_order].si_repetition_pattern], ++k){
LOG_D(MAC,"[debug][sibs%d] subframe: %d, check %d", sibs_order, i, num_subframe);
LOG_D(MAC,"[%d][%d][%d] [%d][%d]\n", i, start_subframe1, mac_inst->rrc_config.si_window_length, sibs_order, si_repetition_pattern[mac_inst->rrc_config.sibs_NB_IoT_sched[sibs_order].si_repetition_pattern]);
//system("pause");
#if 0 //disable new feature
// avoid to occupied others searching space. TODO: css, uss connect with configuration module
// start start+rmax
// i i+9
int continue_flag=0;
for(l=0; l<num_flags; ++l){
if((extend_space[l]>>extend_alpha_offset[l] <= i%extend_space[l] && ((extend_space[l]>>extend_alpha_offset[l])+rmax) >= i%extend_space[l]) ||
(extend_space[l]>>extend_alpha_offset[l] <= (i+9)%extend_space[l] && ((extend_space[l]>>extend_alpha_offset[l])+rmax) >= (i+9)%extend_space[l])){
continue_flag = 1;
}
}
if(continue_flag == 1)
continue;
#endif
pt[k] = (available_resource_DL_t *)check_sibs_resource(mac_inst, i, i+9, num_subframe, &residual_subframe, &last_subframe, &first_subframe[k]);
num_subframe = residual_subframe;
LOG_D(MAC,"-- rest: %d, last: %d start: %d\n", num_subframe, last_subframe, start_subframe1);
if(0==residual_subframe){LOG_D(MAC,"output\n\n");
sibs_dci = (DCIFormatN1_t *)malloc(sizeof(DCIFormatN1_t));
sibs_dci->type = 1;
sibs_dci->orderIndicator = 0;
sibs_dci->Scheddly = 0;
sibs_dci->ResAssign = 8;
sibs_dci->mcs = 2;
sibs_dci->RepNum = 0;
sibs_dci->ndi = 0;
sibs_dci->HARQackRes = 0;
sibs_dci->DCIRep = 0;
for(k=0, j=start_subframe1;j<=i;++k, j+=si_repetition_pattern[mac_inst->rrc_config.sibs_NB_IoT_sched[sibs_order].si_repetition_pattern]){
LOG_D(MAC,"for1 k=%d j=%d i=%d rep=%d\n", k, j, i, si_repetition_pattern[mac_inst->rrc_config.sibs_NB_IoT_sched[sibs_order].si_repetition_pattern]);
if((available_resource_DL_t *)0 != pt[k]){
new_node = (schedule_result_t *)malloc(sizeof(schedule_result_t));
// fill new node
new_node->output_subframe = first_subframe[k];
new_node->end_subframe = (j==i)?last_subframe:j+9;
new_node->sdu_length = SIB23_size;
new_node->DLSCH_pdu = SIB23_pdu;
new_node->direction = DL;
new_node->DCI_release = (j==i);
new_node->channel = NPDSCH;
new_node->rnti = 65535;
new_node->rnti_type = 1;
new_node->npusch_format = 0; // useless
new_node->R_harq = 0; // useless
new_node->next = (schedule_result_t *)0;
new_node->DCI_pdu = (void *)sibs_dci;
//new_node->debug_str = str[sibs_order];
LOG_D(MAC,"debug: pt[k]->start_subframe:%d output_subframe:%d end_subframe:%d rep:%d\n", pt[k]->start_subframe, first_subframe[k], (j==i)?last_subframe:j+9,si_repetition_pattern[mac_inst->rrc_config.sibs_NB_IoT_sched[sibs_order].si_repetition_pattern]);
fill_resource_DL(mac_inst, pt[k], first_subframe[k], (j==i)?last_subframe:j+9, new_node);
LOG_D(MAC,"for*2\n");
}
LOG_D(MAC,"for2\n");
}
return ;
}
}
return ;
}
This diff is collapsed.
This diff is collapsed.
......@@ -30,7 +30,7 @@
#ifndef __MAC_EXTERN_NB_IOT_H__
#define __MAC_EXTERN_NB_IOT_H__
#include "openair2/PHY_INTERFACE/defs_NB_IoT.h"
//#include "openair2/PHY_INTERFACE/defs_NB_IoT.h"
......
/*! \file main_NB_IoT.c
* \brief top init of Layer 2
* \author NTUST BMW LAB./
* \date 2017
* \version 1.0
* \email:
*/
//#include "asn1_constants.h"
#include "LAYER2/MAC/defs_NB_IoT.h"
#include "LAYER2/MAC/proto_NB_IoT.h"
#include "LAYER2/MAC/extern_NB_IoT.h"
#include "vars_NB_IoT.h"
#include "RRC/NBIOT/proto_NB_IoT.h"
#define NUM_USS_PP 3
#define USER_NUM_USS 10
int mac_init_global_param_NB_IoT(void)
{
///// removed since already called by mac_init_global_param //////////////
/*
if (rlc_module_init()!=0) {
return(-1);
}
*/
/////////////////////////////////////////////////////////////////////////////
// LOG_I(MAC,"[MAIN] RRC NB-IoT initialization of global params\n");
// rrc_init_global_param_NB_IoT();
///// removed since already called by mac_init_global_param //////////////
/*
LOG_I(MAC,"[MAIN] PDCP layer init\n");
#ifdef USER_MODE
pdcp_layer_init ();
#else
pdcp_module_init ();
#endif
*/
////////////////////////////////////////////////////////////////////////
return 0;
}
// Initial function of the intialization for NB-IoT MAC
void init_mac_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst)
{
int32_t i, j, k;
LOG_I(MAC,"[NB-IoT] MAC start initialization\n");
mac_inst->current_subframe = 0;
for(i=0;i<64;++i)
{
mac_inst->sib1_flag[i] = 0;
mac_inst->sib1_count[i] = 0;
}
init_tool_sib1(mac_inst);
// output handler
// RA
mac_inst->RA_msg2_list.head = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_msg3_list.head = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_msg4_list.head = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_msg2_list.tail = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_msg3_list.tail = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_msg4_list.tail = (RA_TEMPLATE_NB_IoT *)0;
sib1_NB_IoT_sched_t *config = &mac_inst->rrc_config.sib1_NB_IoT_sched_config;
// DLSF Table
init_dlsf_info(mac_inst, &DLSF_information);
// init sib1 tool
//int repetition_pattern = 1;// 1:every2frame, 2:every4frame, 3:every8frame, 4:every16frame
for(i=0;i<8;++i){
mac_inst->sib1_flag[(i<<1)+config->starting_rf] = 1;
}
for(i=0, j=0;i<64;++i){
if(mac_inst->sib1_flag[i]==1){
++j;
}
mac_inst->sib1_count[i]=j;
}
//printf("%d", mac_inst->sib1_period);
for(i=0, j=0;i<640;++i){
//printf("*%d", i);
if(is_dlsf(mac_inst, i)){
++j;
}
//printf("-");
if(i%10==9){
mac_inst->dlsf_table[i/10] = j;
}
}
for(i=0;i<256;++i){
mac_inst->sibs_table[i] = -1;
}
mac_inst->rrc_config.si_window_length = ms160;
mac_inst->rrc_config.sibs_NB_IoT_sched[0].si_periodicity = rf64;
mac_inst->rrc_config.si_radio_frame_offset = 1;
for(j=0;j<6;++j){
if(0x0 != mac_inst->rrc_config.sibs_NB_IoT_sched[j].sib_mapping_info){
k = mac_inst->rrc_config.sibs_NB_IoT_sched[j].si_periodicity / mac_inst->rrc_config.si_window_length;
for(i=0;i<(256/k);++i){
mac_inst->sibs_table[(i*k)+j] = j;
}
}
}
mac_inst->schedule_subframe_DL = 0;
//mac_inst->schedule_subframe_UL = 0;
available_resource_DL = available_resource_DL_last = (available_resource_DL_t *)0;
// init downlink list 0-100
init_dl_list(mac_inst);
for(i=0; i<MAX_NUMBER_OF_UE_MAX_NB_IoT; ++i){
mac_inst->RA_template[i].active = 0;
mac_inst->RA_template[i].msg3_retransmit_count = 0;
mac_inst->RA_template[i].msg4_retransmit_count = 0;
mac_inst->RA_template[i].ta = 0;
mac_inst->RA_template[i].preamble_index = 0;
mac_inst->RA_template[i].ue_rnti = 0x0;
mac_inst->RA_template[i].ra_rnti = 0x0;
mac_inst->RA_template[i].next = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_template[i].prev = (RA_TEMPLATE_NB_IoT *)0;
mac_inst->RA_template[i].wait_msg4_ack = 0;
mac_inst->RA_template[i].wait_msg3_ack = 0;
}
//3 CE level USS list
mac_inst->UE_list_spec = (UE_list_NB_IoT_t*)malloc(NUM_USS_PP*sizeof(UE_list_NB_IoT_t));
//initial UE list
LOG_I(MAC,"[init_mac_NB_IoT] Initial UE list\n");
mac_inst->num_uss_list = NUM_USS_PP;
for(i=0;i<NUM_USS_PP;++i)
{
//rrc_mac_config_req(&mac_inst->rrc_config, 0, 0, 1, i);
(mac_inst->UE_list_spec+i)->head = -1;
(mac_inst->UE_list_spec+i)->tail = -1;
//(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max = mac_inst->rrc_config.npdcch_ConfigDedicated[i].R_max;
//(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G = mac_inst->rrc_config.npdcch_ConfigDedicated[i].G;
//(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset = mac_inst->rrc_config.npdcch_ConfigDedicated[i].a_offset;
(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max = 16;
(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G = 4;
(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset = 0;
(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T = (uint32_t)((double)(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max * (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G);
(mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss = (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T * (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset;
//SCHEDULE_LOG("[init_mac_NB_IoT][CE%d] Rmax %d G %d, a_offset %d, PP %d search space start %d\n", i, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss);
for(j=0;j<MAX_NUMBER_OF_UE_MAX_NB_IoT;++j)
{
(mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].active=0;
(mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].RRC_connected=0;
(mac_inst->UE_list_spec+i)->UE_template_NB_IoT[j].direction = -1;
}
LOG_I(MAC,"[init_mac_NB_IoT] List_number %d R_max %d G %.1f a_offset %.1f T %d SS_start %d\n", i, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.R_max, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.G, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.a_offset, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.T, (mac_inst->UE_list_spec+i)->NPDCCH_config_dedicated.ss_start_uss);
}
//UL initial
//Setting nprach configuration
setting_nprach();
//Initialize uplink resource from nprach configuration
Initialize_Resource();
//add_UL_Resource(mac_inst);
extend_available_resource_DL(mac_inst, mac_inst->current_subframe + 1 + 160);
}
void mac_top_init_eNB_NB_IoT(void)
{
// can be an input of this function, but now fix to 0
module_id_t i = 0;
//UE_list_t *UE_list;
//eNB_MAC_INST_NB_IoT *mac;
int nb_inst_NB_IOT_MAC= 1;
LOG_I(MAC,"[NB-IoT MAIN] Init function start:nb_nbiot_macrlc_inst=%d\n",nb_inst_NB_IOT_MAC);
if (nb_inst_NB_IOT_MAC>0) {
// only one inst exit in legacy OAI
mac_inst->Mod_id = i;
// IF Module Initialization linking
mac_inst->if_inst_NB_IoT = IF_Module_init_NB_IoT(i);
mac_inst->if_inst_NB_IoT->PHY_config_req = PHY_config_req_NB_IoT;
mac_inst->if_inst_NB_IoT->schedule_response = schedule_response_NB_IoT;
//reserve for fapi structure initializati
} else {
mac_inst = NULL;
}
// for NB-IoT UE list initialization will be in init_mac_NB_IoT
}
int l2_init_eNB_NB_IoT(void)
{
LOG_I(MAC,"[MAIN] MAC_INIT_GLOBAL_PARAM NB-IoT IN...\n");
mac_inst = (eNB_MAC_INST_NB_IoT *) malloc (sizeof(eNB_MAC_INST_NB_IoT));
memset(mac_inst,0,sizeof(eNB_MAC_INST_NB_IoT));
Is_rrc_registered_NB_IoT=0;
mac_init_global_param_NB_IoT();
Is_rrc_registered_NB_IoT=1;
//init_mac_NB_IoT(mac_inst);
return(1);
}
This diff is collapsed.
......@@ -44,7 +44,7 @@
#include "COMMON/platform_constants.h"
#include "COMMON/platform_types.h"
#include "COMMON/mac_rrc_primitives.h"
//#include "COMMON/mac_rrc_primitives.h"
//#include "LAYER2/MAC/defs.h"
//#include "COMMON/openair_defs.h"
......@@ -476,7 +476,7 @@ typedef struct OAI_UECapability_NB_IoT_s {
#define RRC_BUFFER_SIZE_MAX_NB_IoT 1024
#if 0
typedef struct UE_RRC_INST_NB_IoT_s {
Rrc_State_NB_IoT_t RrcState;
......@@ -571,7 +571,7 @@ typedef struct UE_RRC_INST_NB_IoT_s {
*/
} UE_RRC_INST_NB_IoT;
#endif
#include "proto_NB_IoT.h" //should be put here otherwise compilation error
#endif
......
......@@ -44,7 +44,7 @@ extern eNB_MAC_INST_NB_IoT *mac_inst;
//MP: NOTE:XXX some of the parameters defined in vars_nb_iot are called by the extern.h file so not replicated here
extern UE_RRC_INST_NB_IoT *UE_rrc_inst_NB_IoT;
//extern UE_RRC_INST_NB_IoT *UE_rrc_inst_NB_IoT;
extern eNB_RRC_INST_NB_IoT *eNB_rrc_inst_NB_IoT;
......
......@@ -42,7 +42,7 @@
//------------------------------------------------------------------------
UE_RRC_INST_NB_IoT *UE_rrc_inst_NB_IoT; //MP: may not used for the moment
//UE_RRC_INST_NB_IoT *UE_rrc_inst_NB_IoT; //MP: may not used for the moment
#ifndef USER_MODE
#ifndef NO_RRM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment