nr_polar_defs.h 9.85 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
 */

22 23 24 25 26 27 28 29 30 31
/*!\file PHY/CODING/nrPolar_tools/nr_polar_defs.h
 * \brief
 * \author Turker Yilmaz
 * \date 2018
 * \version 0.1
 * \company EURECOM
 * \email turker.yilmaz@eurecom.fr
 * \note
 * \warning
*/
32

Guy De Souza's avatar
Guy De Souza committed
33 34 35 36 37 38 39 40 41
#ifndef __NR_POLAR_DEFS__H__
#define __NR_POLAR_DEFS__H__

#include <math.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

42 43 44
#include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
yilmazt's avatar
yilmazt committed
45
#include "PHY/CODING/coding_defs.h"
46
//#include "SIMULATION/TOOLS/sim.h"
47

48 49 50
#define NR_POLAR_DECODER_LISTSIZE 8 //uint8_t
#define NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION 0 //uint8_t; 0 --> eq. (8a) and (11b), 1 --> eq. (9) and (12)

yilmazt's avatar
yilmazt committed
51 52 53 54 55
#define NR_POLAR_AGGREGATION_LEVEL_1_PRIME 149 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_2_PRIME 151 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_4_PRIME 157 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_8_PRIME 163 //uint16_t
#define NR_POLAR_AGGREGATION_LEVEL_16_PRIME 167 //uint16_t
56

Guy De Souza's avatar
Guy De Souza committed
57 58
static const uint8_t nr_polar_subblock_interleaver_pattern[32] = { 0, 1, 2, 4, 3, 5, 6, 7, 8, 16, 9, 17, 10, 18, 11, 19, 12, 20, 13, 21, 14, 22, 15, 23, 24, 25, 26, 28, 27, 29, 30, 31 };

59 60 61 62 63 64 65 66 67 68 69 70 71

#define Nmax 1024
#define nmax 10

typedef struct decoder_node_t_s {
  struct decoder_node_t_s *left;
  struct decoder_node_t_s *right;
  int level;
  int leaf;
  int Nv;
  int first_leaf_index;
  int all_frozen;
  int16_t *alpha;
knopp's avatar
knopp committed
72
  int16_t *beta;
73 74 75 76 77 78 79
} decoder_node_t;

typedef struct decoder_tree_t_s {
  decoder_node_t *root;
  int num_nodes;
} decoder_tree_t;

80
struct nrPolar_params {
yilmazt's avatar
yilmazt committed
81
	//messageType: 0=PBCH, 1=DCI, -1=UCI
yilmazt's avatar
yilmazt committed
82
	int idx; //idx = (messageType * messageLength * aggregation_prime);
yilmazt's avatar
yilmazt committed
83 84
	struct nrPolar_params *nextPtr;

Guy De Souza's avatar
Guy De Souza committed
85 86
	uint8_t n_max;
	uint8_t i_il;
87
	uint8_t i_seg;
Guy De Souza's avatar
Guy De Souza committed
88 89 90 91 92 93 94 95 96 97
	uint8_t n_pc;
	uint8_t n_pc_wm;
	uint8_t i_bil;
	uint16_t payloadBits;
	uint16_t encoderLength;
	uint8_t crcParityBits;
	uint8_t crcCorrectionBits;
	uint16_t K;
	uint16_t N;
	uint8_t n;
yilmazt's avatar
yilmazt committed
98
	uint32_t crcBit;
Guy De Souza's avatar
Guy De Souza committed
99 100 101

	uint16_t *interleaving_pattern;
	uint16_t *rate_matching_pattern;
102
	const uint16_t *Q_0_Nminus1;
Guy De Souza's avatar
Guy De Souza committed
103 104 105 106 107
	int16_t *Q_I_N;
	int16_t *Q_F_N;
	int16_t *Q_PC_N;
	uint8_t *information_bit_pattern;
	uint16_t *channel_interleaver_pattern;
108
	uint32_t crc_polynomial;
Guy De Souza's avatar
Guy De Souza committed
109 110 111

	uint8_t **crc_generator_matrix; //G_P
	uint8_t **G_N;
112
	uint32_t* crc256Table;
113
  uint8_t **extended_crc_generator_matrix;
yilmazt's avatar
yilmazt committed
114
	//lowercase: bits, Uppercase: Bits stored in bytes
115
	//polar_encoder vectors
116
	uint8_t *nr_polar_crc;
yilmazt's avatar
yilmazt committed
117
	uint8_t *nr_polar_aPrime;
118
	uint8_t *nr_polar_APrime;
yilmazt's avatar
yilmazt committed
119 120
	uint8_t *nr_polar_D;
	uint8_t *nr_polar_E;
121 122

	//Polar Coding vectors
yilmazt's avatar
yilmazt committed
123 124 125 126
	uint8_t *nr_polar_A;
	uint8_t *nr_polar_CPrime;
	uint8_t *nr_polar_B;
	uint8_t *nr_polar_U;
127 128

decoder_tree_t tree;
129 130
} __attribute__ ((__packed__));
typedef struct nrPolar_params t_nrPolar_params;
yilmazt's avatar
yilmazt committed
131
typedef t_nrPolar_params *t_nrPolar_paramsPtr;
132

yilmazt's avatar
yilmazt committed
133 134 135 136 137 138 139
void polar_encoder(uint32_t *input,
				   uint32_t *output,
				   t_nrPolar_paramsPtr polarParams);

void polar_encoder_dci(uint32_t *in,
					   uint32_t *out,
					   t_nrPolar_paramsPtr polarParams,
yilmazt's avatar
yilmazt committed
140
					   uint16_t n_RNTI);
141

yilmazt's avatar
yilmazt committed
142 143 144 145 146 147
void polar_encoder_timing(uint32_t *in,
						  uint32_t *out,
						  t_nrPolar_paramsPtr polarParams,
						  double cpuFreqGHz,
						  FILE* logFile);

148
int8_t polar_decoder(double *input,
hongzhi wang's avatar
hongzhi wang committed
149
		 	 	 	 uint8_t *output,
150 151 152
					 t_nrPolar_paramsPtr polarParams,
					 uint8_t listSize,
					 uint8_t pathMetricAppr);
yilmazt's avatar
yilmazt committed
153

154 155 156 157 158 159
int8_t polar_decoder_aPriori(double *input,
							 uint32_t *output,
							 t_nrPolar_paramsPtr polarParams,
							 uint8_t listSize,
							 uint8_t pathMetricAppr,
							 double *aPrioriPayload);
Guy De Souza's avatar
Guy De Souza committed
160

yilmazt's avatar
yilmazt committed
161 162 163 164 165 166 167 168 169
int8_t polar_decoder_aPriori_timing(double *input,
									uint32_t *output,
									t_nrPolar_paramsPtr polarParams,
									uint8_t listSize,
									uint8_t pathMetricAppr,
									double *aPrioriPayload,
									double cpuFreqGHz,
									FILE* logFile);

170 171 172 173 174 175
int8_t polar_decoder_dci(double *input,
						 uint32_t *out,
						 t_nrPolar_paramsPtr polarParams,
						 uint8_t listSize,
						 uint8_t pathMetricAppr,
						 uint16_t n_RNTI);
176

knopp's avatar
knopp committed
177 178
void generic_polar_decoder(t_nrPolar_params *,decoder_node_t *);

179 180 181 182
void nr_polar_init(t_nrPolar_paramsPtr *polarParams,
				   int8_t messageType,
				   uint16_t messageLength,
				   uint8_t aggregation_level);
183

184
void nr_polar_print_polarParams(t_nrPolar_paramsPtr polarParams);
185

186 187
t_nrPolar_paramsPtr nr_polar_params (t_nrPolar_paramsPtr polarParams,
									 int8_t messageType,
yilmazt's avatar
yilmazt committed
188 189
									 uint16_t messageLength,
									 uint8_t aggregation_level);
Guy De Souza's avatar
Guy De Souza committed
190

yilmazt's avatar
yilmazt committed
191
uint16_t nr_polar_aggregation_prime (uint8_t aggregation_level);
Guy De Souza's avatar
Guy De Souza committed
192 193 194

uint8_t** nr_polar_kronecker_power_matrices(uint8_t n);

195
const uint16_t* nr_polar_sequence_pattern(uint8_t n);
Guy De Souza's avatar
Guy De Souza committed
196

yilmazt's avatar
yilmazt committed
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
/*!@fn uint32_t nr_polar_output_length(uint16_t K, uint16_t E, uint8_t n_max)
 * @brief Computes...
 * @param K Number of bits to encode (=payloadBits+crcParityBits)
 * @param E
 * @param n_max */
uint32_t nr_polar_output_length(uint16_t K,
								uint16_t E,
								uint8_t n_max);

void nr_polar_channel_interleaver_pattern(uint16_t *cip,
										  uint8_t I_BIL,
										  uint16_t E);

void nr_polar_rate_matching_pattern(uint16_t *rmp,
									uint16_t *J,
									const uint8_t *P_i_,
									uint16_t K,
									uint16_t N,
									uint16_t E);

void nr_polar_rate_matching(double *input,
							double *output,
							uint16_t *rmp,
							uint16_t K,
							uint16_t N,
							uint16_t E);

224 225
void nr_polar_rate_matching_int16(int16_t *input, int16_t *output, uint16_t *rmp, uint16_t K, uint16_t N, uint16_t E);

yilmazt's avatar
yilmazt committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
void nr_polar_interleaving_pattern(uint16_t K,
								   uint8_t I_IL,
								   uint16_t *PI_k_);

void nr_polar_info_bit_pattern(uint8_t *ibp,
							   int16_t *Q_I_N,
							   int16_t *Q_F_N,
							   uint16_t *J,
							   const uint16_t *Q_0_Nminus1,
							   uint16_t K,
							   uint16_t N,
							   uint16_t E,
							   uint8_t n_PC);

void nr_polar_info_bit_extraction(uint8_t *input,
								  uint8_t *output,
								  uint8_t *pattern,
								  uint16_t size);

void nr_bit2byte_uint32_8_t(uint32_t *in,
							uint16_t arraySize,
							uint8_t *out);

void nr_byte2bit_uint8_32_t(uint8_t *in,
							uint16_t arraySize,
							uint32_t *out);

void nr_crc_bit2bit_uint32_8_t(uint32_t *in,
							   uint16_t arraySize,
							   uint8_t *out);

void nr_polar_bit_insertion(uint8_t *input,
							uint8_t *output,
							uint16_t N,
							uint16_t K,
							int16_t *Q_I_N,
							int16_t *Q_PC_N,
							uint8_t n_PC);

void nr_matrix_multiplication_uint8_t_1D_uint8_t_2D(uint8_t *matrix1,
													uint8_t **matrix2,
													uint8_t *output,
													uint16_t row,
													uint16_t col);

uint8_t ***nr_alloc_uint8_t_3D_array(uint16_t xlen,
									 uint16_t ylen,
									 uint16_t zlen);

uint8_t **nr_alloc_uint8_t_2D_array(uint16_t xlen,
									uint16_t ylen);

double ***nr_alloc_double_3D_array(uint16_t xlen,
								   uint16_t ylen,
								   uint16_t zlen);

void nr_free_uint8_t_3D_array(uint8_t ***input,
							  uint16_t xlen,
							  uint16_t ylen);

void nr_free_uint8_t_2D_array(uint8_t **input,
							  uint16_t xlen);

void nr_free_double_3D_array(double ***input,
							 uint16_t xlen,
							 uint16_t ylen);

void updateLLR(double ***llr,
			   uint8_t **llrU,
			   uint8_t ***bit,
			   uint8_t **bitU,
			   uint8_t listSize,
			   uint16_t row,
			   uint16_t col,
			   uint16_t xlen,
			   uint8_t ylen,
			   uint8_t approximation);

void updateBit(uint8_t ***bit,
			   uint8_t **bitU,
			   uint8_t listSize,
			   uint16_t row,
			   uint16_t col,
			   uint16_t xlen,
			   uint8_t ylen);

void updatePathMetric(double *pathMetric,
					  double ***llr,
					  uint8_t listSize,
					  uint8_t bitValue,
					  uint16_t row,
					  uint8_t approximation);

void updatePathMetric2(double *pathMetric,
					   double ***llr,
					   uint8_t listSize,
					   uint16_t row,
					   uint8_t approximation);

void computeLLR(double ***llr,
				uint16_t row,
				uint16_t col,
				uint8_t i,
				uint16_t offset,
				uint8_t approximation);

void updateCrcChecksum(uint8_t **crcChecksum,
					   uint8_t **crcGen,
					   uint8_t listSize,
					   uint32_t i2,
					   uint8_t len);

void updateCrcChecksum2(uint8_t **crcChecksum,
						uint8_t **crcGen,
						uint8_t listSize,
						uint32_t i2,
						uint8_t len);

void nr_sort_asc_double_1D_array_ind(double *matrix,
									 uint8_t *ind,
									 uint8_t len);
347

348 349 350
uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits);

uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits);
351

352 353
uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits);

yilmazt's avatar
yilmazt committed
354
//Also nr_polar_rate_matcher
yilmazt's avatar
yilmazt committed
355 356 357 358 359
static inline void nr_polar_interleaver(uint8_t *input,
										uint8_t *output,
										uint16_t *pattern,
										uint16_t size)
{
360 361 362
	for (int i=0; i<size; i++) output[i]=input[pattern[i]];
}

yilmazt's avatar
yilmazt committed
363
static inline void nr_polar_deinterleaver(uint8_t *input,
364 365 366
					  uint8_t *output,
					  uint16_t *pattern,
					  uint16_t size)
yilmazt's avatar
yilmazt committed
367
{
368 369 370
  for (int i=0; i<size; i++) {
    output[pattern[i]]=input[i];
  }
371 372
}

Guy De Souza's avatar
Guy De Souza committed
373
#endif