lte_Isc_NB_IoT.c 4.4 KB
Newer Older
Vincent Savaux's avatar
Vincent Savaux committed
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.0  (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 PHY/LTE_TRANSPORT/lte_mcs_NB_IoT.c
* \brief Some support routines for subcarrier start into UL RB for ULSCH
Matthieu Kanj's avatar
Matthieu Kanj committed
24
* \author M. KANJ
Vincent Savaux's avatar
Vincent Savaux committed
25 26 27 28 29 30 31 32 33 34 35 36
* \date 2017
* \version 0.1
* \company b<>com
* \email: 
* \note
* \warning
*/

//#include "PHY/defs.h"
//#include "PHY/extern.h"
#include "PHY/LTE_TRANSPORT/proto_NB_IoT.h"

Matthieu Kanj's avatar
Matthieu Kanj committed
37 38 39 40 41
uint8_t tab_ack_15khz[16]= {0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3};
uint8_t tab_ack_3_75khz[16]= {38,39,40,41,42,43,44,45,38,39,40,41,42,43,44,45};
uint8_t tab_I_ru_N_ru_UL[8]= {1,2,3,4,5,6,8,10};
uint8_t tab_I_rep_N_rep_UL[8]={1,2,4,8,16,32,64,128};

Vincent Savaux's avatar
Vincent Savaux committed
42 43 44 45
// Section 16.5.1.1 in 36.213
uint16_t get_UL_sc_start_NB_IoT(uint16_t I_sc)
{

Matthieu Kanj's avatar
Matthieu Kanj committed
46 47 48 49 50 51
	if (0<=I_sc && I_sc<=11)
	{
		return I_sc;

	} else if (12<=I_sc && I_sc<=15) {

Vincent Savaux's avatar
Vincent Savaux committed
52
		return 3*(I_sc-12); 
Matthieu Kanj's avatar
Matthieu Kanj committed
53 54 55 56 57 58 59

	}  else if (16<=I_sc && I_sc<=17) {

		return 6*(I_sc-16);

	} else if (I_sc==18){

Vincent Savaux's avatar
Vincent Savaux committed
60
		return 0; 
Matthieu Kanj's avatar
Matthieu Kanj committed
61 62 63 64 65

	} else if (I_sc>18 || I_sc<0){

		return -1;   /// error msg is needed for this case

66 67
	} else {

Matthieu Kanj's avatar
Matthieu Kanj committed
68
		return -1;   /// error msg is needed for this case
Vincent Savaux's avatar
Vincent Savaux committed
69 70 71 72
	}

}

Matthieu Kanj's avatar
Matthieu Kanj committed
73 74 75 76 77 78 79 80 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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
uint16_t get_UL_N_rep_NB_IoT(uint8_t I_rep)
{
   return tab_I_rep_N_rep_UL[I_rep];
}

uint16_t get_UL_N_ru_NB_IoT(uint8_t I_mcs, uint8_t I_ru, uint8_t flag_msg3)
{

	if(flag_msg3 ==1)      // msg3
	{

		if(I_mcs == 0)
		{
			return 4;

		} else if(I_mcs == 1) {

			return 3;

		} else if(I_mcs == 2) {

			return 1;
		} else {
			printf("error in I_mcs value from nfapi");
			return 0;
		}

	} else {      // other NPUSCH

		return tab_I_ru_N_ru_UL[I_ru];

	}

}




uint16_t get_UL_sc_index_start_NB_IoT(uint8_t subcarrier_spacing, uint16_t I_sc, uint8_t npush_format)
{

	if(npush_format == 1)
	{

		if(subcarrier_spacing == 0)  ////////// 15 KHz
		{

			if (0<=I_sc && I_sc<12)
			{
				return I_sc;

			} else if (12<=I_sc && I_sc<16) {

				return 3*(I_sc-12); 

			}  else if (16<=I_sc && I_sc<18) {

				return 6*(I_sc-16);

			} else if (I_sc==18){

				return 0; 

			} else {

				return -1;  
				printf("Error in passed nfapi parameters (I_sc)");

			} 

		} else {      //////////// 3.75 KHz

			return I_sc;       /// values 0-47
		}

	} else {       /////////////////////////////////////// format 2

		if(subcarrier_spacing == 0)  ////////// 15 KHz
		{
			
			return(tab_ack_15khz[I_sc]);   

		} else {      //////////// 3.75 KHz

            return(tab_ack_3_75khz[I_sc]);
		}

	}

}

///////////////////////////////////////////////
uint8_t get_numb_UL_sc_NB_IoT(uint8_t subcarrier_spacing, uint8_t I_sc, uint8_t npush_format) 
{
			
	if(npush_format == 1)
	{
		if(subcarrier_spacing == 0)  // 15 KHz
		{

			if(I_sc >= 0 && I_sc < 12)
			{
				return 1;
			} else if (I_sc >= 12 && I_sc < 16) {
				return 3;
			} else if (I_sc >= 16 && I_sc < 18) {
				return 6;
			} else if (I_sc == 18) {
				return 12;
			} else {
				return 0;
			}
		} else {
			return 1;
		}

	} else {
		return 1;
	}

}

////////////////////////////////////////////////////
uint8_t get_UL_slots_per_RU_NB_IoT(uint8_t subcarrier_spacing, uint8_t subcarrier_indcation, uint8_t UL_format)
{
	uint8_t subcarrier_number = get_numb_UL_sc_NB_IoT(subcarrier_spacing, subcarrier_indcation, UL_format);

	if(UL_format == 1) // format 1
	{
		if(subcarrier_spacing == 0) // 15 KHz
		{
			if (subcarrier_number == 1 )
			{
				return 16;

			} else if (subcarrier_number == 3) {

				return 8;

			} else if (subcarrier_number == 6) {

				return 4;

			} else {

				return 2;
			}

		} else {         // 3.75 KHz

			return 16;
		}

	} else {   // format 2

		return 4;

	}

}