Merge pull request #6 from libLTE/master

Merge from liblte
master
suttonpd 11 years ago
commit 243ccc823c

@ -0,0 +1,283 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "lte.h"
#ifndef DISABLE_UHD
#include "cuhd.h"
void *uhd;
#endif
char *output_file_name = NULL;
int nof_frames=-1;
int cell_id = 1;
int nof_prb = 6;
char *uhd_args = "";
float uhd_amp=0.25, uhd_gain=10.0, uhd_freq=2400000000;
filesink_t fsink;
lte_fft_t ifft;
pbch_t pbch;
cf_t *slot_buffer = NULL, *output_buffer = NULL;
int slot_n_re, slot_n_samples;
#define UHD_SAMP_FREQ 1920000
void usage(char *prog) {
printf("Usage: %s [agmfoncvp]\n", prog);
#ifndef DISABLE_UHD
printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-g UHD TX gain [Default %.2f dB]\n", uhd_gain);
printf("\t-m UHD signal amplitude [Default %.2f]\n", uhd_amp);
printf("\t-f UHD TX frequency [Default %.1f MHz]\n", uhd_freq/1000000);
#else
printf("\t UHD is disabled. CUHD library not available\n");
#endif
printf("\t-o output_file [Default USRP]\n");
printf("\t-n number of frames [Default %d]\n", nof_frames);
printf("\t-c cell id [Default %d]\n", cell_id);
printf("\t-p nof_prb [Default %d]\n", nof_prb);
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "agfmoncpv")) != -1) {
switch(opt) {
case 'a':
uhd_args = argv[optind];
break;
case 'g':
uhd_gain = atof(argv[optind]);
break;
case 'm':
uhd_amp = atof(argv[optind]);
break;
case 'f':
uhd_freq = atof(argv[optind]);
break;
case 'o':
output_file_name = argv[optind];
break;
case 'n':
nof_frames = atoi(argv[optind]);
break;
case 'p':
nof_prb = atoi(argv[optind]);
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
#ifdef DISABLE_UHD
if (!output_file_name) {
usage(argv[0]);
exit(-1);
}
#endif
}
void base_init() {
/* init memory */
slot_buffer = malloc(sizeof(cf_t) * slot_n_re);
if (!slot_buffer) {
perror("malloc");
exit(-1);
}
output_buffer = malloc(sizeof(cf_t) * slot_n_samples);
if (!output_buffer) {
perror("malloc");
exit(-1);
}
/* open file or USRP */
if (output_file_name) {
if (filesink_init(&fsink, output_file_name, COMPLEX_FLOAT_BIN)) {
fprintf(stderr, "Error opening file %s\n", output_file_name);
exit(-1);
}
} else {
#ifndef DISABLE_UHD
printf("Opening UHD device...\n");
if (cuhd_open(uhd_args,&uhd)) {
fprintf(stderr, "Error opening uhd\n");
exit(-1);
}
#else
printf("Error UHD not available. Select an output file\n");
exit(-1);
#endif
}
/* create ifft object */
if (lte_ifft_init(&ifft, CPNORM, nof_prb)) {
fprintf(stderr, "Error creating iFFT object\n");
exit(-1);
}
if (pbch_init(&pbch, 6, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PBCH object\n");
exit(-1);
}
}
void base_free() {
pbch_free(&pbch);
lte_ifft_free(&ifft);
if (slot_buffer) {
free(slot_buffer);
}
if (output_buffer) {
free(output_buffer);
}
if (output_file_name) {
filesink_free(&fsink);
} else {
#ifndef DISABLE_UHD
cuhd_close(&uhd);
#endif
}
}
int main(int argc, char **argv) {
int nf, ns, N_id_2;
cf_t pss_signal[PSS_LEN];
float sss_signal0[SSS_LEN]; // for subframe 0
float sss_signal5[SSS_LEN]; // for subframe 5
pbch_mib_t mib;
refsignal_t refs[NSLOTS_X_FRAME];
int i;
cf_t *slot1_symbols[MAX_PORTS_CTRL];
#ifdef DISABLE_UHD
if (argc < 3) {
usage(argv[0]);
exit(-1);
}
#endif
parse_args(argc,argv);
N_id_2 = cell_id%3;
slot_n_re = CPNORM_NSYMB * nof_prb * RE_X_RB;
slot_n_samples = SLOT_LEN_CPNORM(lte_symbol_sz(nof_prb));
/* this *must* be called after setting slot_len_* */
base_init();
/* Generate PSS/SSS signals */
pss_generate(pss_signal, N_id_2);
sss_generate(sss_signal0, sss_signal5, cell_id);
/* Generate CRS signals */
for (i=0;i<NSLOTS_X_FRAME;i++) {
if (refsignal_init_LTEDL(&refs[i], 0, i, cell_id, CPNORM, nof_prb)) {
fprintf(stderr, "Error initiating CRS slot=%d\n", i);
return -1;
}
}
mib.nof_ports = 1;
mib.nof_prb = 6;
mib.phich_length = PHICH_NORM;
mib.phich_resources = R_1;
mib.sfn = 0;
for (i=0;i<MAX_PORTS_CTRL;i++) { // now there's only 1 port
slot1_symbols[i] = slot_buffer;
}
#ifndef DISABLE_UHD
if (!output_file_name) {
printf("Set TX rate: %.2f MHz\n", cuhd_set_tx_srate(uhd, UHD_SAMP_FREQ)/1000000);
printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain));
printf("Set TX freq: %.2f MHz\n", cuhd_set_tx_freq(uhd, uhd_freq)/1000000);
}
#endif
nf = 0;
while(nf<nof_frames || nof_frames == -1) {
for (ns=0;ns<NSLOTS_X_FRAME;ns++) {
bzero(slot_buffer, sizeof(cf_t) * slot_n_re);
switch(ns) {
case 0: // tx pss/sss
case 10: // tx pss/sss
pss_put_slot(pss_signal, slot_buffer, nof_prb, CPNORM);
sss_put_slot(ns?sss_signal5:sss_signal0, slot_buffer, nof_prb, CPNORM);
break;
case 1: // tx pbch
pbch_encode(&pbch, &mib, slot1_symbols, 1);
break;
default: // transmit zeros
break;
}
refsignal_put(&refs[ns], slot_buffer);
/* Transform to OFDM symbols */
lte_ifft_run(&ifft, slot_buffer, output_buffer);
/* send to file or usrp */
if (output_file_name) {
filesink_write(&fsink, output_buffer, slot_n_samples);
usleep(5000);
} else {
#ifndef DISABLE_UHD
vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, slot_n_samples);
cuhd_send(uhd, output_buffer, slot_n_samples, 1);
#endif
}
}
mib.sfn=(mib.sfn+1)%1024;
printf("SFN: %4d\r", mib.sfn);fflush(stdout);
nf++;
}
base_free();
printf("Done\n");
exit(0);
}

@ -85,6 +85,7 @@
#include "lte/phch/regs.h" #include "lte/phch/regs.h"
#include "lte/phch/dci.h" #include "lte/phch/dci.h"
#include "lte/phch/pdcch.h" #include "lte/phch/pdcch.h"
#include "lte/phch/pdsch.h"
#include "lte/phch/pbch.h" #include "lte/phch/pbch.h"
#include "lte/phch/pcfich.h" #include "lte/phch/pcfich.h"
#include "lte/phch/phich.h" #include "lte/phch/phich.h"

@ -34,6 +34,10 @@
#define NSUBFRAMES_X_FRAME 10 #define NSUBFRAMES_X_FRAME 10
#define NSLOTS_X_FRAME (2*NSUBFRAMES_X_FRAME) #define NSLOTS_X_FRAME (2*NSUBFRAMES_X_FRAME)
#define LTE_NSOFT_BITS 250368 // Soft buffer size for Category 1 UE
#define LTE_NULL_BIT 0
#define LTE_NULL_SYMBOL 2
#define LTE_NIL_SYMBOL 2 #define LTE_NIL_SYMBOL 2
#define MAX_PORTS 4 #define MAX_PORTS 4
@ -83,6 +87,8 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define SLOT_IDX_CPNORM(idx, symbol_sz) (idx==0?(CP(symbol_sz, CPNORM_0_LEN)):(CP(symbol_sz, CPNORM_0_LEN)+idx*(symbol_sz+CP(symbol_sz, CPNORM_LEN)))) #define SLOT_IDX_CPNORM(idx, symbol_sz) (idx==0?(CP(symbol_sz, CPNORM_0_LEN)):(CP(symbol_sz, CPNORM_0_LEN)+idx*(symbol_sz+CP(symbol_sz, CPNORM_LEN))))
#define SLOT_IDX_CPEXT(idx, symbol_sz) (idx*(symbol_sz+CP(symbol_sz, CPEXT_LEN))) #define SLOT_IDX_CPEXT(idx, symbol_sz) (idx*(symbol_sz+CP(symbol_sz, CPEXT_LEN)))
#define SAMPLE_IDX(nof_prb, symbol_idx, sample_idx) (symbol_idx*nof_prb*RE_X_RB + sample_idx)
#define MAX_PRB 110 #define MAX_PRB 110
#define RE_X_RB 12 #define RE_X_RB 12
@ -90,7 +96,6 @@ typedef enum {CPNORM, CPEXT} lte_cp_t;
#define GUARD_RE(nof_prb) ((lte_symbol_sz(nof_prb)-nof_prb*RE_X_RB)/2) #define GUARD_RE(nof_prb) ((lte_symbol_sz(nof_prb)-nof_prb*RE_X_RB)/2)
#define SAMPLE_IDX(nof_prb, symbol_idx, sample_idx) (symbol_idx*nof_prb*RE_X_RB + sample_idx)
LIBLTE_API const int lte_symbol_sz(int nof_prb); LIBLTE_API const int lte_symbol_sz(int nof_prb);
LIBLTE_API int lte_re_x_prb(int ns, int symbol, int nof_ports, int nof_symbols); LIBLTE_API int lte_re_x_prb(int ns, int symbol, int nof_ports, int nof_symbols);
@ -101,12 +106,12 @@ LIBLTE_API int lte_voffset(int symbol_id, int cell_id, int nof_ports);
#define NOF_TC_CB_SIZES 188 #define NOF_TC_CB_SIZES 188
typedef enum { typedef enum LIBLTE_API {
SINGLE_ANTENNA,TX_DIVERSITY, SPATIAL_MULTIPLEX SINGLE_ANTENNA,TX_DIVERSITY, SPATIAL_MULTIPLEX
} lte_mimo_type_t; } lte_mimo_type_t;
typedef enum { PHICH_NORM, PHICH_EXT} phich_length_t; typedef enum LIBLTE_API { PHICH_NORM, PHICH_EXT} phich_length_t;
typedef enum { R_1_6, R_1_2, R_1, R_2} phich_resources_t; typedef enum LIBLTE_API { R_1_6, R_1_2, R_1, R_2} phich_resources_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
@ -114,7 +119,7 @@ typedef struct LIBLTE_API{
float fd; float fd;
}lte_earfcn_t; }lte_earfcn_t;
enum band_geographical_area { LIBLTE_API enum band_geographical_area {
ALL, NAR, APAC, EMEA, JAPAN, CALA, NA ALL, NAR, APAC, EMEA, JAPAN, CALA, NA
}; };

@ -25,11 +25,9 @@
* *
*/ */
#ifndef LTESEQ_ #ifndef LTESEQ_
#define LTESEQ_ #define LTESEQ_
#include "lte/config.h"
#include "lte/common/base.h" #include "lte/common/base.h"
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
@ -46,5 +44,7 @@ LIBLTE_API int sequence_pbch(sequence_t *seq, lte_cp_t cp, int cell_id);
LIBLTE_API int sequence_pcfich(sequence_t *seq, int nslot, int cell_id); LIBLTE_API int sequence_pcfich(sequence_t *seq, int nslot, int cell_id);
LIBLTE_API int sequence_phich(sequence_t *seq, int nslot, int cell_id); LIBLTE_API int sequence_phich(sequence_t *seq, int nslot, int cell_id);
LIBLTE_API int sequence_pdcch(sequence_t *seq, int nslot, int cell_id, int len); LIBLTE_API int sequence_pdcch(sequence_t *seq, int nslot, int cell_id, int len);
LIBLTE_API int sequence_pdsch(sequence_t *seq, unsigned short rnti, int q,
int nslot, int cell_id, int len);
#endif #endif

@ -25,7 +25,6 @@
* *
*/ */
#ifndef RM_CONV_ #ifndef RM_CONV_
#define RM_CONV_ #define RM_CONV_
@ -34,13 +33,12 @@
#define RX_NULL 10000 #define RX_NULL 10000
#define TX_NULL 80 #define TX_NULL 80
LIBLTE_API int rm_conv_tx(char *input, int in_len, char *output, int out_len); LIBLTE_API int rm_conv_tx(char *input, int in_len, char *output, int out_len);
LIBLTE_API int rm_conv_rx(float *input, int in_len, float *output, int out_len); LIBLTE_API int rm_conv_rx(float *input, int in_len, float *output, int out_len);
/* High-level API */ /* High-level API */
typedef struct LIBLTE_API { typedef struct
LIBLTE_API {
struct rm_conv_init { struct rm_conv_init {
int direction; int direction;
} init; } init;

@ -25,31 +25,30 @@
* *
*/ */
#ifndef RM_TURBO_ #ifndef RM_TURBO_
#define RM_TURBO_ #define RM_TURBO_
#include "lte/config.h"
#ifndef RX_NULL #ifndef RX_NULL
#define RX_NULL 10000 #define RX_NULL 10000
#endif #endif
#ifndef TX_NULL #ifndef TX_NULL
#define TX_NULL 80 #define TX_NULL 100
#endif #endif
#include "lte/config.h"
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
int buffer_len; int buffer_len;
char *buffer; char *buffer;
int *d2_perm;
} rm_turbo_t; } rm_turbo_t;
LIBLTE_API int rm_turbo_init(rm_turbo_t *q, int max_codeblock_len); LIBLTE_API int rm_turbo_init(rm_turbo_t *q, int max_codeblock_len);
LIBLTE_API void rm_turbo_free(rm_turbo_t *q); LIBLTE_API void rm_turbo_free(rm_turbo_t *q);
LIBLTE_API int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_len, int rv_idx); LIBLTE_API int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output,
LIBLTE_API int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_len, int rv_idx); int out_len, int rv_idx);
LIBLTE_API int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len,
float *output, int out_len, int rv_idx);
/* High-level API */ /* High-level API */
typedef struct LIBLTE_API { typedef struct LIBLTE_API {

@ -25,19 +25,21 @@
* *
*/ */
#ifndef TC_INTERL_H #ifndef _TC_INTERL_H
#define TC_INTERL_H #define _TC_INTERL_H
#include "lte/config.h" #include "lte/config.h"
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
int *forward; int *forward;
int *reverse; int *reverse;
int max_long_cb;
} tc_interl_t; } tc_interl_t;
LIBLTE_API int tc_interl_LTE_init(tc_interl_t *h, int long_cb); LIBLTE_API int tc_interl_LTE_gen(tc_interl_t *h, int long_cb);
LIBLTE_API int tc_interl_UMTS_init(tc_interl_t *h, int long_cb); LIBLTE_API int tc_interl_UMTS_gen(tc_interl_t *h, int long_cb);
LIBLTE_API int tc_interl_init(tc_interl_t *h, int max_long_cb);
LIBLTE_API void tc_interl_free(tc_interl_t *h); LIBLTE_API void tc_interl_free(tc_interl_t *h);
#endif // TC_INTERL_H #endif

@ -25,9 +25,10 @@
* *
*/ */
#ifndef TURBOCODER_H #ifndef TURBOCODER_
#define TURBOCODER_H #define TURBOCODER_
#include "lte/fec/tc_interl.h"
#include "lte/config.h" #include "lte/config.h"
#define NUMREGS 3 #define NUMREGS 3
@ -36,13 +37,13 @@
#define TOTALTAIL 12 #define TOTALTAIL 12
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
int long_cb; int max_long_cb;
tc_interl_t interl; tc_interl_t interl;
} tcod_t; } tcod_t;
LIBLTE_API int tcod_init(tcod_t *h, int long_cb); LIBLTE_API int tcod_init(tcod_t *h, int max_long_cb);
LIBLTE_API void tcod_free(tcod_t *h); LIBLTE_API void tcod_free(tcod_t *h);
LIBLTE_API void tcod_encode(tcod_t *h, char *input, char *output); LIBLTE_API int tcod_encode(tcod_t *h, char *input, char *output, int long_cb);
#endif
#endif // TURBOCODER_H

@ -1,6 +1,34 @@
#ifndef TURBODECODER_H /**
#define TURBODECODER_H *
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef TURBODECODER_
#define TURBODECODER_
#include "lte/fec/tc_interl.h"
#include "lte/config.h" #include "lte/config.h"
#define RATE 3 #define RATE 3
@ -22,12 +50,12 @@
typedef float llr_t; typedef float llr_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
int long_cb; int max_long_cb;
llr_t *beta; llr_t *beta;
} map_gen_t; } map_gen_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
int long_cb; int max_long_cb;
map_gen_t dec; map_gen_t dec;
@ -40,12 +68,13 @@ typedef struct LIBLTE_API{
tc_interl_t interleaver; tc_interl_t interleaver;
} tdec_t; } tdec_t;
LIBLTE_API int tdec_init(tdec_t *h, int long_cb); LIBLTE_API int tdec_init(tdec_t *h, int max_long_cb);
LIBLTE_API void tdec_free(tdec_t *h); LIBLTE_API void tdec_free(tdec_t *h);
LIBLTE_API void tdec_reset(tdec_t *h); LIBLTE_API int tdec_reset(tdec_t *h, int long_cb);
LIBLTE_API void tdec_iteration(tdec_t *h, llr_t *input); LIBLTE_API void tdec_iteration(tdec_t *h, llr_t *input, int long_cb);
LIBLTE_API void tdec_decision(tdec_t *h, char *output); LIBLTE_API void tdec_decision(tdec_t *h, char *output, int long_cb);
LIBLTE_API void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations); LIBLTE_API void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations,
int long_cb);
#endif // TURBODECODER_H #endif

@ -25,12 +25,9 @@
* *
*/ */
#ifndef PRECODING_H_ #ifndef PRECODING_H_
#define PRECODING_H_ #define PRECODING_H_
#include "lte/config.h"
typedef _Complex float cf_t; typedef _Complex float cf_t;
/** The precoder takes as input nlayers vectors "x" from the /** The precoder takes as input nlayers vectors "x" from the
@ -41,18 +38,17 @@ typedef _Complex float cf_t;
/* Generates the vector "y" from the input vector "x" /* Generates the vector "y" from the input vector "x"
*/ */
LIBLTE_API int precoding_single(cf_t *x, cf_t *y, int nof_symbols); LIBLTE_API int precoding_single(cf_t *x, cf_t *y, int nof_symbols);
LIBLTE_API int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports, int nof_symbols); LIBLTE_API int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
LIBLTE_API int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int nof_ports, int nof_symbols);
int nof_symbols, lte_mimo_type_t type); LIBLTE_API int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers,
int nof_ports, int nof_symbols, lte_mimo_type_t type);
/* Estimates the vector "x" based on the received signal "y" and the channel estimates "ce" /* Estimates the vector "x" based on the received signal "y" and the channel estimates "ce"
*/ */
LIBLTE_API int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols); LIBLTE_API int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols);
LIBLTE_API int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS], LIBLTE_API int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_symbols); int nof_ports, int nof_symbols);
LIBLTE_API int predecoding_type(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS], LIBLTE_API int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_layers, int nof_symbols, int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type);
lte_mimo_type_t type);
#endif // PRECODING_H_ #endif /* PRECODING_H_ */

@ -25,11 +25,9 @@
* *
*/ */
#ifndef PCFICH_ #ifndef PCFICH_
#define PCFICH_ #define PCFICH_
#include "lte/config.h"
#include "lte/common/base.h" #include "lte/common/base.h"
#include "lte/mimo/precoding.h" #include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h" #include "lte/mimo/layermap.h"
@ -50,7 +48,7 @@ typedef struct LIBLTE_API {
lte_cp_t cp; lte_cp_t cp;
int nof_symbols; int nof_symbols;
int nof_prb; int nof_prb;
int nof_tx_ports; int nof_ports;
/* handler to REGs resource mapper */ /* handler to REGs resource mapper */
regs_t *regs; regs_t *regs;
@ -71,13 +69,16 @@ typedef struct LIBLTE_API {
} pcfich_t; } pcfich_t;
LIBLTE_API int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_ports, lte_cp_t cp); LIBLTE_API int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb,
int nof_tx_ports, lte_cp_t cp);
LIBLTE_API void pcfich_free(pcfich_t *q); LIBLTE_API void pcfich_free(pcfich_t *q);
LIBLTE_API int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int nsubframe, int *cfi, int *distance); LIBLTE_API int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
LIBLTE_API int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int nsubframe); int nsubframe, int *cfi, int *distance);
LIBLTE_API int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe);
LIBLTE_API bool pcfich_exists(int nframe, int nslot); LIBLTE_API bool pcfich_exists(int nframe, int nslot);
LIBLTE_API int pcfich_put(regs_t *h, cf_t *pcfich, cf_t *slot_data); LIBLTE_API int pcfich_put(regs_t *h, cf_t *pcfich, cf_t *slot_data);
LIBLTE_API int pcfich_get(regs_t *h, cf_t *pcfich, cf_t *slot_data); LIBLTE_API int pcfich_get(regs_t *h, cf_t *pcfich, cf_t *slot_data);
#endif // PCFICH_ #endif

@ -25,11 +25,9 @@
* *
*/ */
#ifndef PDCCH_ #ifndef PDCCH_
#define PDCCH_ #define PDCCH_
#include "lte/config.h"
#include "lte/common/base.h" #include "lte/common/base.h"
#include "lte/mimo/precoding.h" #include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h" #include "lte/mimo/layermap.h"
@ -47,7 +45,7 @@ typedef _Complex float cf_t;
#define PDCCH_NOF_SEARCH_MODES 3 #define PDCCH_NOF_SEARCH_MODES 3
typedef enum { typedef enum LIBLTE_API {
SEARCH_NONE = 3, SEARCH_SI = 0, SEARCH_RA = 1, SEARCH_UE = 2 SEARCH_NONE = 3, SEARCH_SI = 0, SEARCH_RA = 1, SEARCH_UE = 2
} pdcch_search_mode_t; } pdcch_search_mode_t;
@ -92,12 +90,13 @@ typedef struct LIBLTE_API {
crc_t crc; crc_t crc;
} pdcch_t; } pdcch_t;
LIBLTE_API int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports, int cell_id, lte_cp_t cp); LIBLTE_API int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
int cell_id, lte_cp_t cp);
LIBLTE_API void pdcch_free(pdcch_t *q); LIBLTE_API void pdcch_free(pdcch_t *q);
/* Encoding functions */ /* Encoding functions */
LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot1_symbols[MAX_PORTS_CTRL], int nsubframe); LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe);
/* Decoding functions */ /* Decoding functions */
@ -106,10 +105,10 @@ LIBLTE_API int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot1_symbols[MAX_PORT
* b) call pdcch_extract_llr() and then call pdcch_decode_si/ue/ra * b) call pdcch_extract_llr() and then call pdcch_decode_si/ue/ra
*/ */
LIBLTE_API int pdcch_decode(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], LIBLTE_API int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
dci_t *dci, int nsubframe, float ebno); dci_t *dci, int nsubframe, float ebno);
LIBLTE_API int pdcch_extract_llr(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float *llr, LIBLTE_API int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int nsubframe, float ebno); float *llr, int nsubframe, float ebno);
LIBLTE_API void pdcch_init_search_si(pdcch_t *q); LIBLTE_API void pdcch_init_search_si(pdcch_t *q);
LIBLTE_API void pdcch_set_search_si(pdcch_t *q); LIBLTE_API void pdcch_set_search_si(pdcch_t *q);
@ -123,5 +122,4 @@ LIBLTE_API void pdcch_init_search_ra(pdcch_t *q, unsigned short ra_rnti);
LIBLTE_API void pdcch_set_search_ra(pdcch_t *q); LIBLTE_API void pdcch_set_search_ra(pdcch_t *q);
LIBLTE_API int pdcch_decode_ra(pdcch_t *q, float *llr, dci_t *dci); LIBLTE_API int pdcch_decode_ra(pdcch_t *q, float *llr, dci_t *dci);
#endif #endif

@ -0,0 +1,91 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef PDSCH_
#define PDSCH_
#include "lte/config.h"
#include "lte/common/base.h"
#include "lte/mimo/precoding.h"
#include "lte/mimo/layermap.h"
#include "lte/modem/mod.h"
#include "lte/modem/demod_soft.h"
#include "lte/scrambling/scrambling.h"
#include "lte/fec/rm_turbo.h"
#include "lte/fec/turbocoder.h"
#include "lte/fec/turbodecoder.h"
#include "lte/fec/crc.h"
#include "lte/phch/dci.h"
#include "lte/phch/regs.h"
#define TDEC_ITERATIONS 1
typedef _Complex float cf_t;
/* PDSCH object */
typedef struct LIBLTE_API {
int cell_id;
lte_cp_t cp;
int nof_prb;
int nof_ports;
int max_symbols;
unsigned short rnti;
/* buffers */
cf_t *ce[MAX_PORTS];
cf_t *pdsch_symbols[MAX_PORTS];
cf_t *pdsch_x[MAX_PORTS];
cf_t *pdsch_d;
char *pdsch_e_bits;
char *cb_in_b;
char *cb_out_b;
float *pdsch_llr;
float *pdsch_rm_f;
/* tx & rx objects */
modem_table_t mod[4];
demod_soft_t demod;
sequence_t seq_pdsch[NSUBFRAMES_X_FRAME];
tcod_t encoder;
tdec_t decoder;
rm_turbo_t rm_turbo;
crc_t crc_tb;
crc_t crc_cb;
}pdsch_t;
LIBLTE_API int pdsch_init(pdsch_t *q, unsigned short user_rnti, int nof_prb,
int nof_ports, int cell_id, lte_cp_t cp);
LIBLTE_API void pdsch_free(pdsch_t *q);
LIBLTE_API int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
LIBLTE_API int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS],
char *data, int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc);
#endif

@ -31,14 +31,12 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "lte/config.h"
/** Structures and utility functions for DL/UL resource /** Structures and utility functions for DL/UL resource
* allocation. * allocation.
*/ */
typedef enum { typedef enum LIBLTE_API {
MOD_NULL = 0, BPSK = 1, QPSK = 2, QAM16 = 4, QAM64 = 16 MOD_NULL = 0, BPSK = 1, QPSK = 2, QAM16 = 3, QAM64 = 4
} ra_mod_t; } ra_mod_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
@ -50,8 +48,7 @@ typedef struct LIBLTE_API {
// message. Otherwise the tbs_idx corresponding to the lower nearest TBS is taken. // message. Otherwise the tbs_idx corresponding to the lower nearest TBS is taken.
} ra_mcs_t; } ra_mcs_t;
typedef enum LIBLTE_API {
typedef enum {
alloc_type0 = 0, alloc_type1 = 1, alloc_type2 = 2 alloc_type0 = 0, alloc_type1 = 1, alloc_type2 = 2
} ra_type_t; } ra_type_t;
@ -61,17 +58,22 @@ typedef struct LIBLTE_API {
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
uint32_t vrb_bitmask; uint32_t vrb_bitmask;
uint8_t rbg_subset; uint8_t rbg_subset;bool shift;
bool shift;
} ra_type1_t; } ra_type1_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
uint32_t riv; // if L_crb==0, DCI message packer will take this value directly uint32_t riv; // if L_crb==0, DCI message packer will take this value directly
uint16_t L_crb; uint16_t L_crb;
uint16_t RB_start; uint16_t RB_start;
enum {nprb1a_2 = 0, nprb1a_3 = 1} n_prb1a; enum {
enum {t2_ng1 = 0, t2_ng2 = 1} n_gap; nprb1a_2 = 0, nprb1a_3 = 1
enum {t2_loc = 0, t2_dist = 1} mode; } n_prb1a;
enum {
t2_ng1 = 0, t2_ng2 = 1
} n_gap;
enum {
t2_loc = 0, t2_dist = 1
} mode;
} ra_type2_t; } ra_type2_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
@ -84,8 +86,7 @@ typedef struct LIBLTE_API {
}; };
ra_mcs_t mcs; ra_mcs_t mcs;
uint8_t harq_process; uint8_t harq_process;
uint8_t rv_idx; uint8_t rv_idx;bool ndi;
bool ndi;
} ra_pdsch_t; } ra_pdsch_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
@ -104,8 +105,7 @@ typedef struct LIBLTE_API {
ra_mcs_t mcs; ra_mcs_t mcs;
uint8_t rv_idx; // If set to non-zero, a retransmission is requested with the same modulation uint8_t rv_idx; // If set to non-zero, a retransmission is requested with the same modulation
// than before (Format0 message, see also 8.6.1 in 36.2313). // than before (Format0 message, see also 8.6.1 in 36.2313).
bool ndi; bool ndi;bool cqi_request;
bool cqi_request;
} ra_pusch_t; } ra_pusch_t;
@ -115,17 +115,22 @@ typedef struct LIBLTE_API {
} ra_prb_slot_t; } ra_prb_slot_t;
typedef struct LIBLTE_API { typedef struct LIBLTE_API {
ra_prb_slot_t slot1; ra_prb_slot_t slot[2];
ra_prb_slot_t slot2; int lstart;
bool is_dist; int re_sf[NSUBFRAMES_X_FRAME];
} ra_prb_t; } ra_prb_t;
LIBLTE_API void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb); LIBLTE_API void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb);
LIBLTE_API int ra_prb_get_dl(ra_prb_t *prb, ra_pdsch_t *ra, int nof_prb); LIBLTE_API int ra_prb_get_dl(ra_prb_t *prb, ra_pdsch_t *ra, int nof_prb);
LIBLTE_API int ra_prb_get_ul(ra_prb_slot_t *prb, ra_pusch_t *ra, int nof_prb); LIBLTE_API int ra_prb_get_ul(ra_prb_slot_t *prb, ra_pusch_t *ra, int nof_prb);
LIBLTE_API void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports,
int nof_ctrl_symbols, lte_cp_t cp);
LIBLTE_API int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb); LIBLTE_API int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb);
LIBLTE_API int ra_nprb_ul(ra_pusch_t *ra, int nof_prb); LIBLTE_API int ra_nprb_ul(ra_pusch_t *ra, int nof_prb);
LIBLTE_API int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb,
int nof_ports, int nof_ctrl_symbols, lte_cp_t cp);
LIBLTE_API uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs); LIBLTE_API uint8_t ra_mcs_to_table_idx(ra_mcs_t *mcs);
LIBLTE_API int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs); LIBLTE_API int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs);
@ -144,7 +149,8 @@ LIBLTE_API char *ra_mod_string(ra_mod_t mod);
LIBLTE_API int ra_type0_P(int nof_prb); LIBLTE_API int ra_type0_P(int nof_prb);
LIBLTE_API uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb); LIBLTE_API uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb);
LIBLTE_API void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start, int nof_prb, int nof_vrb); LIBLTE_API void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start,
int nof_prb, int nof_vrb);
LIBLTE_API int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1); LIBLTE_API int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1);
LIBLTE_API int ra_type2_n_rb_step(int nof_prb); LIBLTE_API int ra_type2_n_rb_step(int nof_prb);
LIBLTE_API int ra_type2_ngap(int nof_prb, bool ngap_is_1); LIBLTE_API int ra_type2_ngap(int nof_prb, bool ngap_is_1);
@ -155,4 +161,4 @@ LIBLTE_API void ra_pdsch_set_mcs(ra_pdsch_t *ra, ra_mod_t mod, uint8_t tbs_idx);
LIBLTE_API void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb); LIBLTE_API void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb);
LIBLTE_API void ra_pusch_fprint(FILE *f, ra_pusch_t *ra, int nof_prb); LIBLTE_API void ra_pusch_fprint(FILE *f, ra_pusch_t *ra, int nof_prb);
#endif // RB_ALLOC_H_ #endif /* RB_ALLOC_H_ */

@ -50,6 +50,9 @@ const int tc_cb_sizes[NOF_TC_CB_SIZES] = { 40, 48, 56, 64, 72, 80, 88, 96, 104,
4800, 4864, 4928, 4992, 5056, 5120, 5184, 5248, 5312, 5376, 5440, 5504, 4800, 4864, 4928, 4992, 5056, 5120, 5184, 5248, 5312, 5376, 5440, 5504,
5568, 5632, 5696, 5760, 5824, 5888, 5952, 6016, 6080, 6144 }; 5568, 5632, 5696, 5760, 5824, 5888, 5952, 6016, 6080, 6144 };
/*
* Returns Turbo coder interleaver size for Table 5.1.3-3 (36.212) index
*/
int lte_cb_size(int index) { int lte_cb_size(int index) {
if (index >= 0 && index < NOF_TC_CB_SIZES) { if (index >= 0 && index < NOF_TC_CB_SIZES) {
return tc_cb_sizes[index]; return tc_cb_sizes[index];
@ -58,6 +61,9 @@ int lte_cb_size(int index) {
} }
} }
/*
* Finds index of minimum K>=long_cb in Table 5.1.3-3 of 36.212
*/
int lte_find_cb_index(int long_cb) { int lte_find_cb_index(int long_cb) {
int j = 0; int j = 0;
while (j < NOF_TC_CB_SIZES && tc_cb_sizes[j] < long_cb) { while (j < NOF_TC_CB_SIZES && tc_cb_sizes[j] < long_cb) {

@ -0,0 +1,29 @@
/*
* Copyright 2004, Phil Karn, KA9Q
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
#include <stdio.h>
unsigned char Partab[256];
int P_init;
/* Create 256-entry odd-parity lookup table
* Needed only on non-ia32 machines
*/
void partab_init(void) {
int i, cnt, ti;
/* Initialize parity lookup table */
for (i = 0; i < 256; i++) {
cnt = 0;
ti = i;
while (ti) {
if (ti & 1)
cnt++;
ti >>= 1;
}
Partab[i] = cnt & 1;
}
P_init = 1;
}

@ -25,37 +25,34 @@
* *
*/ */
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include "lte/fec/rm_conv.h" #include "lte/fec/rm_conv.h"
#define NCOLS 32 #define NCOLS 32
#define NROWS_MAX NCOLS #define NROWS_MAX NCOLS
#define RATE 3
unsigned char RM_CONV_PERM_TC[NCOLS] = unsigned char RM_PERM_CC[NCOLS] = { 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27,
{ 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31, 0, 16, 8, 7, 23, 15, 31, 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 };
24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30 }; unsigned char RM_PERM_CC_INV[NCOLS] =
unsigned char RM_CONV_PERM_TC_INV[NCOLS] = { 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, { 16, 0, 24, 8, 20, 4, 28, 12, 18, 2, 26, 10, 22, 6, 30, 14, 17, 1, 25, 9,
10, 22, 6, 30, 14, 17, 1, 25, 9, 21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 21, 5, 29, 13, 19, 3, 27, 11, 23, 7, 31, 15 };
31, 15 };
int rm_conv_tx(char *input, int in_len, char *output, int out_len) { int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
char tmp[RATE * NCOLS * NROWS_MAX]; char tmp[3 * NCOLS * NROWS_MAX];
int nrows, ndummy, K_p; int nrows, ndummy, K_p;
int i, j, k, s; int i, j, k, s;
nrows = (int) (in_len / RATE - 1) / NCOLS + 1; nrows = (int) (in_len / 3 - 1) / NCOLS + 1;
if (nrows > NROWS_MAX) { if (nrows > NROWS_MAX) {
fprintf(stderr, "Input too large. Max input length is %d\n", fprintf(stderr, "Input too large. Max input length is %d\n",
RATE * NCOLS * NROWS_MAX); 3 * NCOLS * NROWS_MAX);
return -1; return -1;
} }
K_p = nrows * NCOLS; K_p = nrows * NCOLS;
ndummy = K_p - in_len / RATE; ndummy = K_p - in_len / 3;
if (ndummy < 0) { if (ndummy < 0) {
ndummy = 0; ndummy = 0;
} }
@ -64,10 +61,10 @@ int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
for (s = 0; s < 3; s++) { for (s = 0; s < 3; s++) {
for (j = 0; j < NCOLS; j++) { for (j = 0; j < NCOLS; j++) {
for (i = 0; i < nrows; i++) { for (i = 0; i < nrows; i++) {
if (i*NCOLS + RM_CONV_PERM_TC[j] < ndummy) { if (i * NCOLS + RM_PERM_CC[j] < ndummy) {
tmp[k] = TX_NULL; tmp[k] = TX_NULL;
} else { } else {
tmp[k] = input[(i*NCOLS + RM_CONV_PERM_TC[j]-ndummy)*3+s]; tmp[k] = input[(i * NCOLS + RM_PERM_CC[j] - ndummy) * 3 + s];
} }
k++; k++;
} }
@ -82,14 +79,13 @@ int rm_conv_tx(char *input, int in_len, char *output, int out_len) {
k++; k++;
} }
j++; j++;
if (j == RATE * K_p) { if (j == 3 * K_p) {
j = 0; j = 0;
} }
} }
return 0; return 0;
} }
/* Undoes Convolutional Code Rate Matching. /* Undoes Convolutional Code Rate Matching.
* 3GPP TS 36.212 v10.1.0 section 5.1.4.2 * 3GPP TS 36.212 v10.1.0 section 5.1.4.2
*/ */
@ -99,22 +95,22 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
int i, j, k; int i, j, k;
int d_i, d_j; int d_i, d_j;
float tmp[RATE * NCOLS * NROWS_MAX]; float tmp[3 * NCOLS * NROWS_MAX];
nrows = (int) (out_len / RATE - 1) / NCOLS + 1; nrows = (int) (out_len / 3 - 1) / NCOLS + 1;
if (nrows > NROWS_MAX) { if (nrows > NROWS_MAX) {
fprintf(stderr, "Output too large. Max output length is %d\n", fprintf(stderr, "Output too large. Max output length is %d\n",
RATE * NCOLS * NROWS_MAX); 3 * NCOLS * NROWS_MAX);
return -1; return -1;
} }
K_p = nrows * NCOLS; K_p = nrows * NCOLS;
ndummy = K_p - out_len / RATE; ndummy = K_p - out_len / 3;
if (ndummy < 0) { if (ndummy < 0) {
ndummy = 0; ndummy = 0;
} }
for (i = 0; i < RATE * K_p; i++) { for (i = 0; i < 3 * K_p; i++) {
tmp[i] = RX_NULL; tmp[i] = RX_NULL;
} }
@ -125,7 +121,7 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
d_i = (j % K_p) / nrows; d_i = (j % K_p) / nrows;
d_j = (j % K_p) % nrows; d_j = (j % K_p) % nrows;
if (d_j * NCOLS + RM_CONV_PERM_TC[d_i] >= ndummy) { if (d_j * NCOLS + RM_PERM_CC[d_i] >= ndummy) {
if (tmp[j] == RX_NULL) { if (tmp[j] == RX_NULL) {
tmp[j] = input[k]; tmp[j] = input[k];
} else if (input[k] != RX_NULL) { } else if (input[k] != RX_NULL) {
@ -134,22 +130,21 @@ int rm_conv_rx(float *input, int in_len, float *output, int out_len) {
k++; k++;
} }
j++; j++;
if (j == RATE * K_p) { if (j == 3 * K_p) {
j = 0; j = 0;
} }
} }
/* interleaving and bit selection */ /* interleaving and bit selection */
for (i = 0; i < out_len / RATE; i++) { for (i = 0; i < out_len / 3; i++) {
d_i = (i + ndummy) / NCOLS; d_i = (i + ndummy) / NCOLS;
d_j = (i + ndummy) % NCOLS; d_j = (i + ndummy) % NCOLS;
for (j = 0; j < RATE; j++) { for (j = 0; j < 3; j++) {
float o = tmp[K_p * j + RM_CONV_PERM_TC_INV[d_j] * nrows float o = tmp[K_p * j + RM_PERM_CC_INV[d_j] * nrows + d_i];
+ d_i];
if (o != RX_NULL) { if (o != RX_NULL) {
output[i * RATE + j] = o; output[i * 3 + j] = o;
} else { } else {
output[i * RATE + j] = 0; output[i * 3 + j] = 0;
} }
} }
} }
@ -166,11 +161,11 @@ int rm_conv_initialize(rm_conv_hl* h) {
/** This function can be called in a subframe (1ms) basis */ /** This function can be called in a subframe (1ms) basis */
int rm_conv_work(rm_conv_hl* hl) { int rm_conv_work(rm_conv_hl* hl) {
if (hl->init.direction) { if (hl->init.direction) {
//rm_conv_tx(hl->input, hl->output, hl->in_len, hl->ctrl_in.S); rm_conv_tx(hl->input, hl->in_len, hl->output, hl->ctrl_in.E);
hl->out_len = hl->ctrl_in.S;
} else {
rm_conv_rx(hl->input, hl->output, hl->in_len, hl->ctrl_in.E);
hl->out_len = hl->ctrl_in.E; hl->out_len = hl->ctrl_in.E;
} else {
rm_conv_rx(hl->input, hl->in_len, hl->output, hl->ctrl_in.S);
hl->out_len = hl->ctrl_in.S;
} }
return 0; return 0;
} }

@ -35,11 +35,9 @@
#define NCOLS 32 #define NCOLS 32
#define NROWS_MAX NCOLS #define NROWS_MAX NCOLS
#define RATE 3
unsigned char RM_PERM_TC[NCOLS] = unsigned char RM_PERM_TC[NCOLS] = { 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26,
{ 0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, 1, 17, 9, 6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31 };
25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23, 15, 31 };
int rm_turbo_init(rm_turbo_t *q, int buffer_len) { int rm_turbo_init(rm_turbo_t *q, int buffer_len) {
q->buffer_len = buffer_len; q->buffer_len = buffer_len;
@ -48,11 +46,6 @@ int rm_turbo_init(rm_turbo_t *q, int buffer_len) {
perror("malloc"); perror("malloc");
return -1; return -1;
} }
q->d2_perm = malloc(buffer_len * sizeof(int) / 3 + 1);
if (!q->d2_perm) {
perror("malloc");
return -1;
}
return 0; return 0;
} }
@ -67,23 +60,24 @@ void rm_turbo_free(rm_turbo_t *q) {
* *
* TODO: Soft buffer size limitation according to UE category * TODO: Soft buffer size limitation according to UE category
*/ */
int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_len, int rv_idx) { int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output,
int out_len, int rv_idx) {
char *tmp = (char*) q->buffer; char *tmp = (char*) q->buffer;
int nrows, ndummy, K_p; int nrows, ndummy, K_p;
int i, j, k, s, kidx, N_cb, k0; int i, j, k, s, kidx, N_cb, k0;
nrows = (int) (in_len / RATE - 1) / NCOLS + 1; nrows = (int) (in_len / 3 - 1) / NCOLS + 1;
K_p = nrows * NCOLS; K_p = nrows * NCOLS;
if (3 * K_p > q->buffer_len) { if (3 * K_p > q->buffer_len) {
fprintf(stderr, fprintf(stderr,
"Input too large. Max input length including dummy bits is %d\n", "Input too large. Max input length including dummy bits is %d (3x%dx32, in_len %d)\n",
q->buffer_len); q->buffer_len, nrows, in_len);
return -1; return -1;
} }
ndummy = K_p - in_len / RATE; ndummy = K_p - in_len / 3;
if (ndummy < 0) { if (ndummy < 0) {
ndummy = 0; ndummy = 0;
} }
@ -121,8 +115,8 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
/* Bit selection and transmission 5.1.4.1.2 */ /* Bit selection and transmission 5.1.4.1.2 */
N_cb = 3 * K_p; // TODO: Soft buffer size limitation N_cb = 3 * K_p; // TODO: Soft buffer size limitation
k0 = nrows * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) k0 = nrows
* rv_idx + 2); * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2);
k = 0; k = 0;
j = 0; j = 0;
@ -139,7 +133,8 @@ int rm_turbo_tx(rm_turbo_t *q, char *input, int in_len, char *output, int out_le
/* Undoes Turbo Code Rate Matching. /* Undoes Turbo Code Rate Matching.
* 3GPP TS 36.212 v10.1.0 section 5.1.4.1 * 3GPP TS 36.212 v10.1.0 section 5.1.4.1
*/ */
int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_len, int rv_idx) { int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output,
int out_len, int rv_idx) {
int nrows, ndummy, K_p, k0, N_cb, jp, kidx; int nrows, ndummy, K_p, k0, N_cb, jp, kidx;
int i, j, k; int i, j, k;
@ -148,37 +143,34 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
float *tmp = (float*) q->buffer; float *tmp = (float*) q->buffer;
nrows = (int) (out_len / RATE - 1) / NCOLS + 1; nrows = (int) (out_len / 3 - 1) / NCOLS + 1;
K_p = nrows * NCOLS; K_p = nrows * NCOLS;
if (3 * K_p > q->buffer_len) { if (3 * K_p > q->buffer_len) {
fprintf(stderr, fprintf(stderr,
"Input too large. Max input length including dummy bits is %d\n", "Input too large. Max output length including dummy bits is %d (3x%dx32, in_len %d)\n",
q->buffer_len); q->buffer_len, nrows, out_len);
return -1; return -1;
} }
ndummy = K_p - out_len / RATE; ndummy = K_p - out_len / 3;
if (ndummy < 0) { if (ndummy < 0) {
ndummy = 0; ndummy = 0;
} }
for (i = 0; i < RATE * K_p; i++) { for (i = 0; i < 3 * K_p; i++) {
tmp[i] = RX_NULL; tmp[i] = RX_NULL;
} }
/* Undo bit collection. Account for dummy bits */ /* Undo bit collection. Account for dummy bits */
N_cb = 3 * K_p; // TODO: Soft buffer size limitation N_cb = 3 * K_p; // TODO: Soft buffer size limitation
k0 = nrows * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) k0 = nrows
* rv_idx + 2); * (2 * (int) ceilf((float) N_cb / (float) (8 * nrows)) * rv_idx + 2);
k = 0; k = 0;
j = 0; j = 0;
while (k < in_len) { while (k < in_len) {
jp = (k0 + j) % N_cb; jp = (k0 + j) % N_cb;
if (jp == 32 || jp == 95 || jp == 0) {
i=0;
}
if (jp < K_p || !(jp % 2)) { if (jp < K_p || !(jp % 2)) {
if (jp >= K_p) { if (jp >= K_p) {
d_i = ((jp - K_p) / 2) / nrows; d_i = ((jp - K_p) / 2) / nrows;
@ -195,7 +187,6 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
} else { } else {
int jpp = (jp - K_p - 1) / 2; int jpp = (jp - K_p - 1) / 2;
kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p; kidx = (RM_PERM_TC[jpp / nrows] + NCOLS * (jpp % nrows) + 1) % K_p;
q->d2_perm[kidx] = jpp; // save the permutation in a temporary buffer
if ((kidx - ndummy) < 0) { if ((kidx - ndummy) < 0) {
isdummy = true; isdummy = true;
} else { } else {
@ -215,28 +206,30 @@ int rm_turbo_rx(rm_turbo_t *q, float *input, int in_len, float *output, int out_
} }
/* interleaving and bit selection */ /* interleaving and bit selection */
for (i = 0; i < out_len / RATE; i++) { for (i = 0; i < out_len / 3; i++) {
d_i = (i + ndummy) / NCOLS; d_i = (i + ndummy) / NCOLS;
d_j = (i + ndummy) % NCOLS; d_j = (i + ndummy) % NCOLS;
for (j = 0; j < RATE; j++) { for (j = 0; j < 3; j++) {
if (j != 2) { if (j != 2) {
kidx = K_p * j + (j + 1) * (RM_PERM_TC[d_j] * nrows + d_i); kidx = K_p * j + (j + 1) * (RM_PERM_TC[d_j] * nrows + d_i);
} else { } else {
// use the saved permuatation function to avoid computing the inverse
kidx = 2*q->d2_perm[(i+ndummy)%K_p]+K_p+1; k = (i + ndummy - 1) % K_p;
if (k < 0)
k += K_p;
kidx = (k / NCOLS + nrows * RM_PERM_TC[k % NCOLS]) % K_p;
kidx = 2 * kidx + K_p + 1;
} }
float o = tmp[kidx]; if (tmp[kidx] != RX_NULL) {
if (o != RX_NULL) { output[i * 3 + j] = tmp[kidx];
output[i * RATE + j] = o;
} else { } else {
output[i * RATE + j] = 0; output[i * 3 + j] = 0;
} }
} }
} }
return 0; return 0;
} }
/** High-level API */ /** High-level API */
int rm_turbo_initialize(rm_turbo_hl* h) { int rm_turbo_initialize(rm_turbo_hl* h) {
@ -246,10 +239,12 @@ int rm_turbo_initialize(rm_turbo_hl* h) {
/** This function can be called in a subframe (1ms) basis */ /** This function can be called in a subframe (1ms) basis */
int rm_turbo_work(rm_turbo_hl* hl) { int rm_turbo_work(rm_turbo_hl* hl) {
if (hl->init.direction) { if (hl->init.direction) {
rm_turbo_tx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.E, hl->ctrl_in.rv_idx); rm_turbo_tx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.E,
hl->ctrl_in.rv_idx);
hl->out_len = hl->ctrl_in.E; hl->out_len = hl->ctrl_in.E;
} else { } else {
rm_turbo_rx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.S, hl->ctrl_in.rv_idx); rm_turbo_rx(&hl->q, hl->input, hl->in_len, hl->output, hl->ctrl_in.S,
hl->ctrl_in.rv_idx);
hl->out_len = hl->ctrl_in.S; hl->out_len = hl->ctrl_in.S;
} }
return 0; return 0;

@ -39,53 +39,45 @@
* *
************************************************/ ************************************************/
const int f1_list[NOF_TC_CB_SIZES] = { 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103, 15, 9, 17, const int f1_list[NOF_TC_CB_SIZES] = { 3, 7, 19, 7, 7, 11, 5, 11, 7, 41, 103,
9, 21, 101, 21, 57, 23, 13, 27, 11, 27, 85, 29, 33, 15, 17, 33, 103, 19, 15, 9, 17, 9, 21, 101, 21, 57, 23, 13, 27, 11, 27, 85, 29, 33, 15, 17, 33,
19, 37, 19, 21, 21, 115, 193, 21, 133, 81, 45, 23, 243, 151, 155, 25, 103, 19, 19, 37, 19, 21, 21, 115, 193, 21, 133, 81, 45, 23, 243, 151, 155,
51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, 65, 19, 25, 51, 47, 91, 29, 29, 247, 29, 89, 91, 157, 55, 31, 17, 35, 227, 65, 19,
37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239, 37, 41, 39, 185, 43, 21, 155, 79, 139, 23, 217, 25, 17, 127, 25, 239, 17,
17, 137, 215, 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39, 137, 215, 29, 15, 147, 29, 59, 65, 55, 31, 17, 171, 67, 35, 19, 39, 19, 199,
19, 199, 21, 211, 21, 43, 149, 45, 49, 71, 13, 17, 25, 183, 55, 127, 27, 21, 211, 21, 43, 149, 45, 49, 71, 13, 17, 25, 183, 55, 127, 27, 29, 29, 57,
29, 29, 57, 45, 31, 59, 185, 113, 31, 17, 171, 209, 253, 367, 265, 181, 45, 31, 59, 185, 113, 31, 17, 171, 209, 253, 367, 265, 181, 39, 27, 127,
39, 27, 127, 143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257, 143, 43, 29, 45, 157, 47, 13, 111, 443, 51, 51, 451, 257, 57, 313, 271, 179,
57, 313, 271, 179, 331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233, 331, 363, 375, 127, 31, 33, 43, 33, 477, 35, 233, 357, 337, 37, 71, 71, 37,
357, 337, 37, 71, 71, 37, 39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43, 39, 127, 39, 39, 31, 113, 41, 251, 43, 21, 43, 45, 45, 161, 89, 323, 47, 23,
45, 45, 161, 89, 323, 47, 23, 47, 263 }; 47, 263 };
const int f2_list[NOF_TC_CB_SIZES] = { 10, 12, 42, 16, 18, 20, 22, 24, 26, 84, 90, 32, const int f2_list[NOF_TC_CB_SIZES] = { 10, 12, 42, 16, 18, 20, 22, 24, 26, 84,
34, 108, 38, 120, 84, 44, 46, 48, 50, 52, 36, 56, 58, 60, 62, 32, 198, 90, 32, 34, 108, 38, 120, 84, 44, 46, 48, 50, 52, 36, 56, 58, 60, 62, 32,
68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, 94, 48, 98, 40, 198, 68, 210, 36, 74, 76, 78, 120, 82, 84, 86, 44, 90, 46, 94, 48, 98, 40,
102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68, 102, 52, 106, 72, 110, 168, 114, 58, 118, 180, 122, 62, 84, 64, 66, 68, 420,
420, 96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102, 96, 74, 76, 234, 80, 82, 252, 86, 44, 120, 92, 94, 48, 98, 80, 102, 52, 106,
52, 106, 48, 110, 112, 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140, 48, 110, 112, 114, 58, 118, 60, 122, 124, 84, 64, 66, 204, 140, 72, 74, 76,
72, 74, 76, 78, 240, 82, 252, 86, 88, 60, 92, 846, 48, 28, 80, 102, 104, 78, 240, 82, 252, 86, 88, 60, 92, 846, 48, 28, 80, 102, 104, 954, 96, 110,
954, 96, 110, 112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, 420, 112, 114, 116, 354, 120, 610, 124, 420, 64, 66, 136, 420, 216, 444, 456,
216, 444, 456, 468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240, 468, 80, 164, 504, 172, 88, 300, 92, 188, 96, 28, 240, 204, 104, 212, 192,
204, 104, 212, 192, 220, 336, 228, 232, 236, 120, 244, 248, 168, 64, 220, 336, 228, 232, 236, 120, 244, 248, 168, 64, 130, 264, 134, 408, 138,
130, 264, 134, 408, 138, 280, 142, 480, 146, 444, 120, 152, 462, 234, 280, 142, 480, 146, 444, 120, 152, 462, 234, 158, 80, 96, 902, 166, 336,
158, 80, 96, 902, 166, 336, 170, 86, 174, 176, 178, 120, 182, 184, 186, 170, 86, 174, 176, 178, 120, 182, 184, 186, 94, 190, 480 };
94, 190, 480 };
int tc_interl_LTE_gen(tc_interl_t *h, int long_cb) {
int tc_interl_LTE_init(tc_interl_t *h, int long_cb) {
int cb_table_idx, f1, f2; int cb_table_idx, f1, f2;
unsigned long long i, j; unsigned long long i, j;
cb_table_idx = lte_find_cb_index(long_cb); if (long_cb > h->max_long_cb) {
if (cb_table_idx == -1) { fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",
fprintf(stderr, "Can't find long_cb=%d in valid TC CB table\n", long_cb); h->max_long_cb);
return -1; return -1;
} }
h->forward = h->reverse = NULL; cb_table_idx = lte_find_cb_index(long_cb);
h->forward = malloc(sizeof(int) * (long_cb)); if (cb_table_idx == -1) {
if (!h->forward) { fprintf(stderr, "Can't find long_cb=%d in valid TC CB table\n", long_cb);
return -1;
}
h->reverse = malloc(sizeof(int) * (long_cb));
if (!h->reverse) {
perror("malloc");
free(h->forward);
h->forward = h->reverse = NULL;
return -1; return -1;
} }
@ -105,13 +97,3 @@ int tc_interl_LTE_init(tc_interl_t *h, int long_cb) {
} }

@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <strings.h>
#include "lte/fec/tc_interl.h" #include "lte/fec/tc_interl.h"
#include "lte/fec/turbocoder.h" #include "lte/fec/turbocoder.h"
@ -45,12 +46,32 @@ int mcd(int x, int y);
#define MAX_COLS 256 #define MAX_COLS 256
const unsigned short table_p[52] = { 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, const unsigned short table_p[52] = { 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257 }; 211, 223, 227, 229, 233, 239, 241, 251, 257 };
const unsigned char table_v[52] = { 3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2, const unsigned char table_v[52] = { 3, 2, 2, 3, 2, 5, 2, 3, 2, 6, 3, 5, 2, 2, 2,
2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2, 2, 7, 5, 3, 2, 3, 5, 2, 5, 2, 6, 3, 3, 2, 3, 2, 2, 6, 5, 2, 5, 2, 2, 2, 19,
19, 5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3 }; 5, 2, 3, 2, 3, 2, 6, 3, 7, 7, 6, 3 };
int tc_interl_init(tc_interl_t *h, int max_long_cb) {
int ret = -1;
h->forward = malloc(sizeof(int) * max_long_cb);
if (!h->forward) {
perror("malloc");
goto clean_exit;
}
h->reverse = malloc(sizeof(int) * max_long_cb);
if (!h->reverse) {
perror("malloc");
goto clean_exit;
}
h->max_long_cb = max_long_cb;
ret = 0;
clean_exit: if (ret == -1) {
tc_interl_free(h);
}
return ret;
}
void tc_interl_free(tc_interl_t *h) { void tc_interl_free(tc_interl_t *h) {
if (h->forward) { if (h->forward) {
@ -59,10 +80,10 @@ void tc_interl_free(tc_interl_t *h) {
if (h->reverse) { if (h->reverse) {
free(h->reverse); free(h->reverse);
} }
h->forward = h->reverse = NULL; bzero(h, sizeof(tc_interl_t));
} }
int tc_interl_UMTS_init(tc_interl_t *h, int long_cb) { int tc_interl_UMTS_gen(tc_interl_t *h, int long_cb) {
int i, j; int i, j;
int res, prim, aux; int res, prim, aux;
@ -74,19 +95,13 @@ int tc_interl_UMTS_init(tc_interl_t *h, int long_cb) {
unsigned short U[MAX_COLS * MAX_ROWS]; unsigned short U[MAX_COLS * MAX_ROWS];
int M_Rows, M_Cols, M_long; int M_Rows, M_Cols, M_long;
h->forward = h->reverse = NULL; M_long = long_cb;
h->forward = malloc(sizeof(int) * (long_cb));
if (!h->forward) { if (long_cb > h->max_long_cb) {
return -1; fprintf(stderr, "Interleaver initiated for max_long_cb=%d\n",
} h->max_long_cb);
h->reverse = malloc(sizeof(int) * (long_cb));
if (!h->reverse) {
perror("malloc");
free(h->forward);
h->forward = h->reverse = NULL;
return -1; return -1;
} }
M_long = long_cb;
/* Find R*/ /* Find R*/
if ((40 <= M_long) && (M_long <= 159)) if ((40 <= M_long) && (M_long <= 159))

@ -25,27 +25,27 @@
* *
*/ */
#include "lte/fec/tc_interl.h"
#include "lte/fec/turbocoder.h" #include "lte/fec/turbocoder.h"
#include <stdio.h>
#define NOF_REGS 3 #define NOF_REGS 3
int tcod_init(tcod_t *h, int long_cb) { int tcod_init(tcod_t *h, int max_long_cb) {
if (tc_interl_LTE_init(&h->interl, long_cb)) { if (tc_interl_init(&h->interl, max_long_cb)) {
return -1; return -1;
} }
h->long_cb = long_cb; h->max_long_cb = max_long_cb;
return 0; return 0;
} }
void tcod_free(tcod_t *h) { void tcod_free(tcod_t *h) {
tc_interl_free(&h->interl); tc_interl_free(&h->interl);
h->long_cb = 0; h->max_long_cb = 0;
} }
void tcod_encode(tcod_t *h, char *input, char *output) { int tcod_encode(tcod_t *h, char *input, char *output, int long_cb) {
char reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2; char reg1_0, reg1_1, reg1_2, reg2_0, reg2_1, reg2_2;
int i, k = 0, j; int i, k = 0, j;
@ -53,6 +53,17 @@ void tcod_encode(tcod_t *h, char *input, char *output) {
char in, out; char in, out;
int *per; int *per;
if (long_cb > h->max_long_cb) {
fprintf(stderr, "Turbo coder initiated for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}
if (tc_interl_LTE_gen(&h->interl, long_cb)) {
fprintf(stderr, "Error initiating TC interleaver\n");
return -1;
}
per = h->interl.forward; per = h->interl.forward;
reg1_0 = 0; reg1_0 = 0;
@ -64,7 +75,7 @@ void tcod_encode(tcod_t *h, char *input, char *output) {
reg2_2 = 0; reg2_2 = 0;
k = 0; k = 0;
for (i=0;i<h->long_cb;i++) { for (i = 0; i < long_cb; i++) {
bit = input[i]; bit = input[i];
output[k] = bit; output[k] = bit;
@ -93,7 +104,7 @@ void tcod_encode(tcod_t *h, char *input, char *output) {
k++; k++;
} }
k=3*h->long_cb; k = 3 * long_cb;
/* TAILING CODER #1 */ /* TAILING CODER #1 */
for (j = 0; j < NOF_REGS; j++) { for (j = 0; j < NOF_REGS; j++) {
@ -130,5 +141,6 @@ void tcod_encode(tcod_t *h, char *input, char *output) {
output[k] = out; output[k] = out;
k++; k++;
} }
return 0;
} }

@ -1,9 +1,35 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include "lte/fec/tc_interl.h"
#include "lte/fec/turbodecoder.h" #include "lte/fec/turbodecoder.h"
/************************************************ /************************************************
@ -12,11 +38,11 @@
* Decoder * Decoder
* *
************************************************/ ************************************************/
void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity) { void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity, int long_cb) {
llr_t m_b[8], new[8], old[8]; llr_t m_b[8], new[8], old[8];
llr_t x, y, xy; llr_t x, y, xy;
int k; int k;
int end = s->long_cb + RATE; int end = long_cb + RATE;
llr_t *beta = s->beta; llr_t *beta = s->beta;
int i; int i;
@ -57,13 +83,14 @@ void map_gen_beta(map_gen_t *s, llr_t *input, llr_t *parity) {
} }
} }
void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output) { void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output,
int long_cb) {
llr_t m_b[8], new[8], old[8], max1[8], max0[8]; llr_t m_b[8], new[8], old[8], max1[8], max0[8];
llr_t m1, m0; llr_t m1, m0;
llr_t x, y, xy; llr_t x, y, xy;
llr_t out; llr_t out;
int k; int k;
int end = s->long_cb; int end = long_cb;
llr_t *beta = s->beta; llr_t *beta = s->beta;
int i; int i;
@ -122,14 +149,14 @@ void map_gen_alpha(map_gen_t *s, llr_t *input, llr_t *parity, llr_t *output) {
} }
} }
int map_gen_init(map_gen_t *h, int long_cb) { int map_gen_init(map_gen_t *h, int max_long_cb) {
bzero(h, sizeof(map_gen_t)); bzero(h, sizeof(map_gen_t));
h->beta = malloc(sizeof(llr_t) * (long_cb + TOTALTAIL + 1)* NUMSTATES); h->beta = malloc(sizeof(llr_t) * (max_long_cb + TOTALTAIL + 1) * NUMSTATES);
if (!h->beta) { if (!h->beta) {
perror("malloc"); perror("malloc");
return -1; return -1;
} }
h->long_cb = long_cb; h->max_long_cb = max_long_cb;
return 0; return 0;
} }
@ -140,34 +167,29 @@ void map_gen_free(map_gen_t *h) {
bzero(h, sizeof(map_gen_t)); bzero(h, sizeof(map_gen_t));
} }
void map_gen_dec(map_gen_t *h, llr_t *input, llr_t *parity, llr_t *output) { void map_gen_dec(map_gen_t *h, llr_t *input, llr_t *parity, llr_t *output,
int long_cb) {
int k; int k;
h->beta[(h->long_cb + TAIL) * NUMSTATES] = 0; h->beta[(long_cb + TAIL) * NUMSTATES] = 0;
for (k = 1; k < NUMSTATES; k++) for (k = 1; k < NUMSTATES; k++)
h->beta[(h->long_cb + TAIL) * NUMSTATES + k] = -INF; h->beta[(long_cb + TAIL) * NUMSTATES + k] = -INF;
map_gen_beta(h, input, parity); map_gen_beta(h, input, parity, long_cb);
map_gen_alpha(h, input, parity, output); map_gen_alpha(h, input, parity, output, long_cb);
} }
/************************************************ /************************************************
* *
* TURBO DECODER INTERFACE * TURBO DECODER INTERFACE
* *
************************************************/ ************************************************/
int tdec_init(tdec_t *h, int long_cb) { int tdec_init(tdec_t *h, int max_long_cb) {
int ret = -1; int ret = -1;
bzero(h, sizeof(tdec_t)); bzero(h, sizeof(tdec_t));
int len = long_cb + TOTALTAIL; int len = max_long_cb + TOTALTAIL;
h->max_long_cb = max_long_cb;
h->llr1 = malloc(sizeof(llr_t) * len); h->llr1 = malloc(sizeof(llr_t) * len);
if (!h->llr1) { if (!h->llr1) {
@ -195,19 +217,16 @@ int tdec_init(tdec_t *h, int long_cb) {
goto clean_and_exit; goto clean_and_exit;
} }
if (map_gen_init(&h->dec, long_cb)) { if (map_gen_init(&h->dec, h->max_long_cb)) {
goto clean_and_exit; goto clean_and_exit;
} }
h->long_cb = long_cb; if (tc_interl_init(&h->interleaver, h->max_long_cb) < 0) {
if (tc_interl_LTE_init(&h->interleaver, h->long_cb) < 0) {
goto clean_and_exit; goto clean_and_exit;
} }
ret = 0; ret = 0;
clean_and_exit: clean_and_exit: if (ret == -1) {
if (ret == -1) {
tdec_free(h); tdec_free(h);
} }
return ret; return ret;
@ -237,63 +256,73 @@ void tdec_free(tdec_t *h) {
bzero(h, sizeof(tdec_t)); bzero(h, sizeof(tdec_t));
} }
void tdec_iteration(tdec_t *h, llr_t *input) { void tdec_iteration(tdec_t *h, llr_t *input, int long_cb) {
int i; int i;
// Prepare systematic and parity bits for MAP DEC #1 // Prepare systematic and parity bits for MAP DEC #1
for (i = 0; i < h->long_cb; i++) { for (i = 0; i < long_cb; i++) {
h->syst[i] = input[RATE * i] + h->w[i]; h->syst[i] = input[RATE * i] + h->w[i];
h->parity[i] = input[RATE * i + 1]; h->parity[i] = input[RATE * i + 1];
} }
for (i=h->long_cb;i<h->long_cb+RATE;i++) { for (i = long_cb; i < long_cb + RATE; i++) {
h->syst[i] = input[RATE * h->long_cb + NINPUTS * (i - h->long_cb)]; h->syst[i] = input[RATE * long_cb + NINPUTS * (i - long_cb)];
h->parity[i] = input[RATE * h->long_cb + NINPUTS * (i - h->long_cb) + 1]; h->parity[i] = input[RATE * long_cb + NINPUTS * (i - long_cb) + 1];
} }
// Run MAP DEC #1 // Run MAP DEC #1
map_gen_dec(&h->dec, h->syst, h->parity, h->llr1); map_gen_dec(&h->dec, h->syst, h->parity, h->llr1, long_cb);
// Prepare systematic and parity bits for MAP DEC #1 // Prepare systematic and parity bits for MAP DEC #1
for (i = 0; i < h->long_cb; i++) { for (i = 0; i < long_cb; i++) {
h->syst[i] = h->llr1[h->interleaver.forward[i]] - h->w[h->interleaver.forward[i]]; h->syst[i] = h->llr1[h->interleaver.forward[i]]
- h->w[h->interleaver.forward[i]];
h->parity[i] = input[RATE * i + 2]; h->parity[i] = input[RATE * i + 2];
} }
for (i=h->long_cb;i<h->long_cb+RATE;i++) { for (i = long_cb; i < long_cb + RATE; i++) {
h->syst[i] = input[RATE * h->long_cb + NINPUTS * RATE + NINPUTS * (i - h->long_cb)]; h->syst[i] =
h->parity[i] = input[RATE * h->long_cb + NINPUTS * RATE + NINPUTS * (i - h->long_cb) + 1]; input[RATE * long_cb + NINPUTS * RATE + NINPUTS * (i - long_cb)];
h->parity[i] = input[RATE * long_cb + NINPUTS * RATE
+ NINPUTS * (i - long_cb) + 1];
} }
// Run MAP DEC #1 // Run MAP DEC #1
map_gen_dec(&h->dec, h->syst, h->parity, h->llr2); map_gen_dec(&h->dec, h->syst, h->parity, h->llr2, long_cb);
// Update a-priori LLR from the last iteration // Update a-priori LLR from the last iteration
for (i = 0; i < h->long_cb; i++) { for (i = 0; i < long_cb; i++) {
h->w[i] += h->llr2[h->interleaver.reverse[i]] - h->llr1[i]; h->w[i] += h->llr2[h->interleaver.reverse[i]] - h->llr1[i];
} }
} }
void tdec_reset(tdec_t *h) { int tdec_reset(tdec_t *h, int long_cb) {
memset(h->w, 0, sizeof(llr_t) * h->long_cb); memset(h->w, 0, sizeof(llr_t) * long_cb);
if (long_cb > h->max_long_cb) {
fprintf(stderr, "TDEC was initialized for max_long_cb=%d\n",
h->max_long_cb);
return -1;
}
return tc_interl_LTE_gen(&h->interleaver, long_cb);
} }
void tdec_decision(tdec_t *h, char *output) { void tdec_decision(tdec_t *h, char *output, int long_cb) {
int i; int i;
for (i = 0; i < h->long_cb; i++) { for (i = 0; i < long_cb; i++) {
output[i] = (h->llr2[h->interleaver.reverse[i]] > 0) ? 1 : 0; output[i] = (h->llr2[h->interleaver.reverse[i]] > 0) ? 1 : 0;
} }
} }
void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations) { void tdec_run_all(tdec_t *h, llr_t *input, char *output, int nof_iterations,
int long_cb) {
int iter = 0; int iter = 0;
tdec_reset(h); tdec_reset(h, long_cb);
do { do {
tdec_iteration(h, input); tdec_iteration(h, input, long_cb);
iter++; iter++;
} while (iter < nof_iterations); } while (iter < nof_iterations);
tdec_decision(h, output); tdec_decision(h, output, long_cb);
} }

@ -33,6 +33,11 @@ TARGET_LINK_LIBRARIES(rm_turbo_test lte)
ADD_TEST(rm_conv_test_1 rm_conv_test -t 480 -r 1920) ADD_TEST(rm_conv_test_1 rm_conv_test -t 480 -r 1920)
ADD_TEST(rm_conv_test_2 rm_conv_test -t 1920 -r 480) ADD_TEST(rm_conv_test_2 rm_conv_test -t 1920 -r 480)
ADD_TEST(rm_turbo_test_1 rm_turbo_test -t 480 -r 1920 -i 0)
ADD_TEST(rm_turbo_test_2 rm_turbo_test -t 1920 -r 480 -i 1)
ADD_TEST(rm_turbo_test_1 rm_turbo_test -t 480 -r 1920 -i 2)
ADD_TEST(rm_turbo_test_2 rm_turbo_test -t 1920 -r 480 -i 3)
######################################################################## ########################################################################
# Turbo Coder TEST # Turbo Coder TEST

@ -105,7 +105,7 @@ int main(int argc, char **argv) {
bits[i] = rand() % 2; bits[i] = rand() % 2;
} }
rm_turbo_init(&rm_turbo, 1000); rm_turbo_init(&rm_turbo, 2000);
rm_turbo_tx(&rm_turbo, bits, nof_tx_bits, rm_bits, nof_rx_bits, rv_idx); rm_turbo_tx(&rm_turbo, bits, nof_tx_bits, rm_bits, nof_rx_bits, rv_idx);
@ -113,13 +113,13 @@ int main(int argc, char **argv) {
rm_symbols[i] = (float) rm_bits[i] ? 1 : -1; rm_symbols[i] = (float) rm_bits[i] ? 1 : -1;
} }
rm_turbo_rx(&rm_turbo, rm_symbols, nof_rx_bits, unrm_symbols, nof_tx_bits, rv_idx); rm_turbo_rx(&rm_turbo, rm_symbols, nof_rx_bits, unrm_symbols, nof_tx_bits,
rv_idx);
nof_errors = 0; nof_errors = 0;
for (i = 0; i < nof_tx_bits; i++) { for (i = 0; i < nof_tx_bits; i++) {
if ((unrm_symbols[i] > 0) != bits[i]) { if (unrm_symbols[i] > 0 && ((unrm_symbols[i] > 0) != bits[i])) {
nof_errors++; nof_errors++;
printf("%.2f != %d\n", unrm_symbols[i], bits[i]);
} }
} }
@ -130,12 +130,10 @@ int main(int argc, char **argv) {
free(rm_symbols); free(rm_symbols);
free(unrm_symbols); free(unrm_symbols);
if (nof_tx_bits >= nof_rx_bits) {
if (nof_errors) { if (nof_errors) {
printf("nof_errors=%d\n", nof_errors); printf("nof_errors=%d\n", nof_errors);
exit(-1); exit(-1);
} }
}
printf("Ok\n"); printf("Ok\n");
exit(0); exit(0);

@ -57,7 +57,8 @@ int test_errors = 0;
void usage(char *prog) { void usage(char *prog) {
printf("Usage: %s [nlesv]\n", prog); printf("Usage: %s [nlesv]\n", prog);
printf("\t-k Test with known data (ignores frame_length) [Default disabled]\n"); printf(
"\t-k Test with known data (ignores frame_length) [Default disabled]\n");
printf("\t-i nof_iterations [Default %d]\n", nof_iterations); printf("\t-i nof_iterations [Default %d]\n", nof_iterations);
printf("\t-n nof_frames [Default %d]\n", nof_frames); printf("\t-n nof_frames [Default %d]\n", nof_frames);
printf("\t-l frame_length [Default %d]\n", frame_length); printf("\t-l frame_length [Default %d]\n", frame_length);
@ -119,7 +120,8 @@ void output_matlab(float ber[MAX_ITERATIONS][SNR_POINTS], int snr_points) {
fprintf(f, "snr=linspace(%g,%g-%g/%d,%d);\n", SNR_MIN, SNR_MAX, SNR_MAX, fprintf(f, "snr=linspace(%g,%g-%g/%d,%d);\n", SNR_MIN, SNR_MAX, SNR_MAX,
snr_points, snr_points); snr_points, snr_points);
fprintf(f, "semilogy(snr,ber,snr,0.5*erfc(sqrt(10.^(snr/10))));\n"); fprintf(f, "semilogy(snr,ber,snr,0.5*erfc(sqrt(10.^(snr/10))));\n");
fprintf(f, "legend('1 iter','2 iter', '3 iter', '4 iter', 'theory-uncoded');"); fprintf(f,
"legend('1 iter','2 iter', '3 iter', '4 iter', 'theory-uncoded');");
fprintf(f, "grid on;\n"); fprintf(f, "grid on;\n");
fclose(f); fclose(f);
} }
@ -233,7 +235,7 @@ int main(int argc, char **argv) {
symbols[j] = known_data_encoded[j]; symbols[j] = known_data_encoded[j];
} }
} else { } else {
tcod_encode(&tcod, data_tx, symbols); tcod_encode(&tcod, data_tx, symbols, frame_length);
} }
for (j = 0; j < coded_length; j++) { for (j = 0; j < coded_length; j++) {
@ -243,7 +245,7 @@ int main(int argc, char **argv) {
ch_awgn_f(llr, llr, var[i], coded_length); ch_awgn_f(llr, llr, var[i], coded_length);
/* decoder */ /* decoder */
tdec_reset(&tdec); tdec_reset(&tdec, frame_length);
int t; int t;
if (nof_iterations == -1) { if (nof_iterations == -1) {
@ -253,12 +255,16 @@ int main(int argc, char **argv) {
} }
for (j = 0; j < t; j++) { for (j = 0; j < t; j++) {
if (!j) gettimeofday(&tdata[1],NULL); // Only measure 1 iteration if (!j)
tdec_iteration(&tdec, llr); gettimeofday(&tdata[1], NULL); // Only measure 1 iteration
tdec_decision(&tdec, data_rx); tdec_iteration(&tdec, llr, frame_length);
if (!j) gettimeofday(&tdata[2],NULL); tdec_decision(&tdec, data_rx, frame_length);
if (!j) get_time_interval(tdata); if (!j)
if (!j) mean_usec = (float) mean_usec*0.9+(float) tdata[0].tv_usec*0.1; gettimeofday(&tdata[2], NULL);
if (!j)
get_time_interval(tdata);
if (!j)
mean_usec = (float) mean_usec * 0.9 + (float) tdata[0].tv_usec * 0.1;
/* check errors */ /* check errors */
errors[j] += bit_diff(data_tx, data_rx, frame_length); errors[j] += bit_diff(data_tx, data_rx, frame_length);
@ -270,7 +276,8 @@ int main(int argc, char **argv) {
printf("Eb/No: %3.2f %10d/%d ", printf("Eb/No: %3.2f %10d/%d ",
SNR_MIN + i * ebno_inc, frame_cnt, nof_frames); SNR_MIN + i * ebno_inc, frame_cnt, nof_frames);
printf("BER: %.2e ", (float) errors[j - 1] / (frame_cnt * frame_length)); printf("BER: %.2e ", (float) errors[j - 1] / (frame_cnt * frame_length));
printf("%3.1f Mbps (%6.2f usec)", (float) frame_length/mean_usec, mean_usec); printf("%3.1f Mbps (%6.2f usec)", (float) frame_length / mean_usec,
mean_usec);
printf("\r"); printf("\r");
} }
@ -278,8 +285,7 @@ int main(int argc, char **argv) {
if (snr_points == 1) { if (snr_points == 1) {
if (test_known_data && seed == KNOWN_DATA_SEED if (test_known_data && seed == KNOWN_DATA_SEED
&& ebno_db == KNOWN_DATA_EBNO && ebno_db == KNOWN_DATA_EBNO && frame_cnt == KNOWN_DATA_NFRAMES) {
&& frame_cnt == KNOWN_DATA_NFRAMES) {
for (j = 0; j < MAX_ITERATIONS; j++) { for (j = 0; j < MAX_ITERATIONS; j++) {
if (errors[j] > known_data_errors[j]) { if (errors[j] > known_data_errors[j]) {
fprintf(stderr, "Expected %d errors but got %d\n", fprintf(stderr, "Expected %d errors but got %d\n",
@ -294,10 +300,12 @@ int main(int argc, char **argv) {
printf("BER: %g\t%u errors\n", printf("BER: %g\t%u errors\n",
(float) errors[j] / (frame_cnt * frame_length), errors[j]); (float) errors[j] / (frame_cnt * frame_length), errors[j]);
if (test_errors) { if (test_errors) {
if (errors[j] > get_expected_errors(frame_cnt, seed, j+1, frame_length, ebno_db)) { if (errors[j]
> get_expected_errors(frame_cnt, seed, j + 1, frame_length,
ebno_db)) {
fprintf(stderr, "Expected %d errors but got %d\n", fprintf(stderr, "Expected %d errors but got %d\n",
get_expected_errors(frame_cnt, seed, j+1, frame_length, ebno_db), get_expected_errors(frame_cnt, seed, j + 1, frame_length,
errors[j]); ebno_db), errors[j]);
exit(-1); exit(-1);
} else { } else {
printf("Iter %d ok\n", j + 1); printf("Iter %d ok\n", j + 1);

@ -25,8 +25,6 @@
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <complex.h> #include <complex.h>
@ -41,7 +39,8 @@ int precoding_single(cf_t *x, cf_t *y, int nof_symbols) {
memcpy(y, x, nof_symbols * sizeof(cf_t)); memcpy(y, x, nof_symbols * sizeof(cf_t));
return nof_symbols; return nof_symbols;
} }
int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports, int nof_symbols) { int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
int nof_symbols) {
int i; int i;
if (nof_ports == 2) { if (nof_ports == 2) {
/* FIXME: Use VOLK here */ /* FIXME: Use VOLK here */
@ -84,15 +83,17 @@ int precoding_diversity(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_ports,
} }
/* 36.211 v10.3.0 Section 6.3.4 */ /* 36.211 v10.3.0 Section 6.3.4 */
int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int nof_ports, int nof_symbols, int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers,
lte_mimo_type_t type) { int nof_ports, int nof_symbols, lte_mimo_type_t type) {
if (nof_ports > MAX_PORTS) { if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS, nof_ports); fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS,
nof_ports);
return -1; return -1;
} }
if (nof_layers > MAX_LAYERS) { if (nof_layers > MAX_LAYERS) {
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n", MAX_LAYERS, nof_layers); fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n",
MAX_LAYERS, nof_layers);
return -1; return -1;
} }
@ -101,7 +102,8 @@ int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int
if (nof_ports == 1 && nof_layers == 1) { if (nof_ports == 1 && nof_layers == 1) {
return precoding_single(x[0], y[0], nof_symbols); return precoding_single(x[0], y[0], nof_symbols);
} else { } else {
fprintf(stderr, "Number of ports and layers must be 1 for transmission on single antenna ports\n"); fprintf(stderr,
"Number of ports and layers must be 1 for transmission on single antenna ports\n");
return -1; return -1;
} }
break; break;
@ -109,7 +111,8 @@ int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int
if (nof_ports == nof_layers) { if (nof_ports == nof_layers) {
return precoding_diversity(x, y, nof_ports, nof_symbols); return precoding_diversity(x, y, nof_ports, nof_symbols);
} else { } else {
fprintf(stderr, "Error number of layers must equal number of ports in transmit diversity\n"); fprintf(stderr,
"Error number of layers must equal number of ports in transmit diversity\n");
return -1; return -1;
} }
case SPATIAL_MULTIPLEX: case SPATIAL_MULTIPLEX:
@ -119,7 +122,6 @@ int precoding_type(cf_t *x[MAX_LAYERS], cf_t *y[MAX_PORTS], int nof_layers, int
return 0; return 0;
} }
/* ZF detector */ /* ZF detector */
int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) { int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) {
vec_div_ccc(y, ce, x, nof_symbols); vec_div_ccc(y, ce, x, nof_symbols);
@ -127,8 +129,8 @@ int predecoding_single_zf(cf_t *y, cf_t *ce, cf_t *x, int nof_symbols) {
} }
/* ZF detector */ /* ZF detector */
int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS], int predecoding_diversity_zf(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_symbols) { int nof_ports, int nof_symbols) {
int i; int i;
cf_t h0, h1, h2, h3, r0, r1, r2, r3; cf_t h0, h1, h2, h3, r0, r1, r2, r3;
float hh, hh02, hh13; float hh, hh02, hh13;
@ -137,10 +139,10 @@ int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
for (i = 0; i < nof_symbols / 2; i++) { for (i = 0; i < nof_symbols / 2; i++) {
h0 = ce[0][2 * i]; h0 = ce[0][2 * i];
h1 = ce[1][2 * i]; h1 = ce[1][2 * i];
hh = crealf(h0)*crealf(h0)+cimagf(h0)*cimagf(h0)+ hh = crealf(h0) * crealf(h0) + cimagf(h0) * cimagf(h0)
crealf(h1)*crealf(h1)+cimagf(h1)*cimagf(h1); + crealf(h1) * crealf(h1) + cimagf(h1) * cimagf(h1);
r0 = y[0][2*i]; r0 = y[2 * i];
r1 = y[0][2*i+1]; r1 = y[2 * i + 1];
x[0][i] = (conjf(h0) * r0 + h1 * conjf(r1)) / hh * sqrt(2); x[0][i] = (conjf(h0) * r0 + h1 * conjf(r1)) / hh * sqrt(2);
x[1][i] = (-h1 * conj(r0) + conj(h0) * r1) / hh * sqrt(2); x[1][i] = (-h1 * conj(r0) + conj(h0) * r1) / hh * sqrt(2);
} }
@ -157,10 +159,10 @@ int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
+ crealf(h2) * crealf(h2) + cimagf(h2) * cimagf(h2); + crealf(h2) * crealf(h2) + cimagf(h2) * cimagf(h2);
hh13 = crealf(h1) * crealf(h1) + cimagf(h1) * cimagf(h1) hh13 = crealf(h1) * crealf(h1) + cimagf(h1) * cimagf(h1)
+ crealf(h3) * crealf(h3) + cimagf(h3) * cimagf(h3); + crealf(h3) * crealf(h3) + cimagf(h3) * cimagf(h3);
r0 = y[0][4*i]; r0 = y[4 * i];
r1 = y[0][4*i+1]; r1 = y[4 * i + 1];
r2 = y[0][4*i+2]; r2 = y[4 * i + 2];
r3 = y[0][4*i+3]; r3 = y[4 * i + 3];
x[0][i] = (conjf(h0) * r0 + h2 * conjf(r1)) / hh02 * sqrt(2); x[0][i] = (conjf(h0) * r0 + h2 * conjf(r1)) / hh02 * sqrt(2);
x[1][i] = (-h2 * conjf(r0) + conjf(h0) * r1) / hh02 * sqrt(2); x[1][i] = (-h2 * conjf(r0) + conjf(h0) * r1) / hh02 * sqrt(2);
@ -176,25 +178,27 @@ int predecoding_diversity_zf(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
} }
/* 36.211 v10.3.0 Section 6.3.4 */ /* 36.211 v10.3.0 Section 6.3.4 */
int predecoding_type(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS], int predecoding_type(cf_t *y, cf_t *ce[MAX_PORTS], cf_t *x[MAX_LAYERS],
cf_t *x[MAX_LAYERS], int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type) { int nof_ports, int nof_layers, int nof_symbols, lte_mimo_type_t type) {
if (nof_ports > MAX_PORTS) { if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS, nof_ports); fprintf(stderr, "Maximum number of ports is %d (nof_ports=%d)\n", MAX_PORTS,
nof_ports);
return -1; return -1;
} }
if (nof_layers > MAX_LAYERS) { if (nof_layers > MAX_LAYERS) {
fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n", MAX_LAYERS, nof_layers); fprintf(stderr, "Maximum number of layers is %d (nof_layers=%d)\n",
MAX_LAYERS, nof_layers);
return -1; return -1;
} }
switch (type) { switch (type) {
case SINGLE_ANTENNA: case SINGLE_ANTENNA:
if (nof_ports == 1 && nof_layers == 1) { if (nof_ports == 1 && nof_layers == 1) {
return predecoding_single_zf(y[0], ce[0], x[0], nof_symbols); return predecoding_single_zf(y, ce[0], x[0], nof_symbols);
} else { } else {
fprintf(stderr, "Number of ports and layers must be 1 for transmission on single antenna ports\n"); fprintf(stderr,
"Number of ports and layers must be 1 for transmission on single antenna ports\n");
return -1; return -1;
} }
break; break;
@ -202,7 +206,8 @@ int predecoding_type(cf_t *y[MAX_PORTS], cf_t *ce[MAX_PORTS],
if (nof_ports == nof_layers) { if (nof_ports == nof_layers) {
return predecoding_diversity_zf(y, ce, x, nof_ports, nof_symbols); return predecoding_diversity_zf(y, ce, x, nof_ports, nof_symbols);
} else { } else {
fprintf(stderr, "Error number of layers must equal number of ports in transmit diversity\n"); fprintf(stderr,
"Error number of layers must equal number of ports in transmit diversity\n");
return -1; return -1;
} }
break; break;

@ -43,7 +43,9 @@ int nof_layers = 1, nof_ports = 1;
char *mimo_type_name = NULL; char *mimo_type_name = NULL;
void usage(char *prog) { void usage(char *prog) {
printf("Usage: %s -m [single|diversity|multiplex] -l [nof_layers] -p [nof_ports]\n", prog); printf(
"Usage: %s -m [single|diversity|multiplex] -l [nof_layers] -p [nof_ports]\n",
prog);
printf("\t-n num_symbols [Default %d]\n", nof_symbols); printf("\t-n num_symbols [Default %d]\n", nof_symbols);
} }
@ -77,7 +79,8 @@ void parse_args(int argc, char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i, j; int i, j;
float mse; float mse;
cf_t *x[MAX_LAYERS], *r[MAX_PORTS], *y[MAX_PORTS], *h[MAX_PORTS], *xr[MAX_LAYERS]; cf_t *x[MAX_LAYERS], *r[MAX_PORTS], *y[MAX_PORTS], *h[MAX_PORTS],
*xr[MAX_LAYERS];
lte_mimo_type_t type; lte_mimo_type_t type;
parse_args(argc, argv); parse_args(argc, argv);
@ -128,7 +131,8 @@ int main(int argc, char **argv) {
/* generate random data */ /* generate random data */
for (i = 0; i < nof_layers; i++) { for (i = 0; i < nof_layers; i++) {
for (j = 0; j < nof_symbols; j++) { for (j = 0; j < nof_symbols; j++) {
x[i][j] = 100 * ((float) rand()/RAND_MAX + (float) I*rand()/RAND_MAX); x[i][j] = 100
* ((float) rand() / RAND_MAX + (float) I * rand() / RAND_MAX);
} }
} }
@ -159,7 +163,8 @@ int main(int argc, char **argv) {
} }
/* predecoding / equalization */ /* predecoding / equalization */
if (predecoding_type(r, h, xr, nof_ports, nof_layers, nof_symbols * nof_layers, type) < 0) { if (predecoding_type(r[0], h, xr, nof_ports, nof_layers,
nof_symbols * nof_layers, type) < 0) {
fprintf(stderr, "Error layer mapper encoder\n"); fprintf(stderr, "Error layer mapper encoder\n");
exit(-1); exit(-1);
} }

@ -25,7 +25,6 @@
* *
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -59,8 +58,8 @@ void dci_free(dci_t *q) {
} }
void dci_candidate_fprint(FILE *f, dci_candidate_t *q) { void dci_candidate_fprint(FILE *f, dci_candidate_t *q) {
fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n", fprintf(f, "L: %d, nCCE: %d, RNTI: 0x%x, nBits: %d\n", q->L, q->ncce, q->rnti,
q->L, q->ncce, q->rnti, q->nof_bits); q->nof_bits);
} }
int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti) { int dci_msg_candidate_set(dci_msg_t *msg, int L, int nCCE, unsigned short rnti) {
@ -96,8 +95,6 @@ bool is_ambiguous_size(int size) {
return false; return false;
} }
/********************************** /**********************************
* PAYLOAD sizeof functions * PAYLOAD sizeof functions
* ********************************/ * ********************************/
@ -105,7 +102,6 @@ int dci_format0_sizeof_(int nof_prb) {
return 1 + 1 + riv_nbits(nof_prb) + 5 + 1 + 2 + 3 + 1; return 1 + 1 + riv_nbits(nof_prb) + 5 + 1 + 2 + 3 + 1;
} }
int dci_format1A_sizeof(int nof_prb) { int dci_format1A_sizeof(int nof_prb) {
int n; int n;
n = 1 + 1 + riv_nbits(nof_prb) + 5 + 3 + 1 + 2 + 2; n = 1 + 1 + riv_nbits(nof_prb) + 5 + 3 + 1 + 2 + 2;
@ -118,7 +114,6 @@ int dci_format1A_sizeof(int nof_prb) {
return n; return n;
} }
int dci_format0_sizeof(int nof_prb) { int dci_format0_sizeof(int nof_prb) {
int n = dci_format0_sizeof_(nof_prb); int n = dci_format0_sizeof_(nof_prb);
while (n < dci_format1A_sizeof(nof_prb)) { while (n < dci_format1A_sizeof(nof_prb)) {
@ -129,12 +124,12 @@ int dci_format0_sizeof(int nof_prb) {
int dci_format1_sizeof(int nof_prb) { int dci_format1_sizeof(int nof_prb) {
int n = (int) ceilf((float) nof_prb/ra_type0_P(nof_prb))+5+3+1+2+2; int n = (int) ceilf((float) nof_prb / ra_type0_P(nof_prb)) + 5 + 3 + 1 + 2
+ 2;
if (nof_prb > 10) { if (nof_prb > 10) {
n++; n++;
} }
while(n == dci_format0_sizeof(nof_prb) while (n == dci_format0_sizeof(nof_prb) || n == dci_format1A_sizeof(nof_prb)
|| n == dci_format1A_sizeof(nof_prb)
|| is_ambiguous_size(n)) { || is_ambiguous_size(n)) {
n++; n++;
} }
@ -166,13 +161,10 @@ int dci_format_sizeof(dci_format_t format, int nof_prb) {
} }
} }
/********************************** /**********************************
* DCI Resource Allocation functions * DCI Resource Allocation functions
* ********************************/ * ********************************/
/* Packs DCI format 0 data to a sequence of bits and store them in msg according /* Packs DCI format 0 data to a sequence of bits and store them in msg according
* to 36.212 5.3.3.1.1 * to 36.212 5.3.3.1.1
* *
@ -203,7 +195,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
/* pack RIV according to 8.1 of 36.213 */ /* pack RIV according to 8.1 of 36.213 */
uint32_t riv; uint32_t riv;
if (data->type2_alloc.L_crb) { if (data->type2_alloc.L_crb) {
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb); riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
nof_prb);
} else { } else {
riv = data->type2_alloc.riv; riv = data->type2_alloc.riv;
} }
@ -222,7 +215,8 @@ int dci_format0_pack(ra_pusch_t *data, dci_msg_t *msg, int nof_prb) {
} else { } else {
if (data->mcs.tbs) { if (data->mcs.tbs) {
if (data->mcs.tbs) { if (data->mcs.tbs) {
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_ul(data, nof_prb)); data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
ra_nprb_ul(data, nof_prb));
} }
} }
mcs = ra_mcs_to_table_idx(&data->mcs); mcs = ra_mcs_to_table_idx(&data->mcs);
@ -271,7 +265,8 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
return -1; return -1;
} }
if (*y++ != 0) { if (*y++ != 0) {
fprintf(stderr, "Invalid format differentiation field value. This is Format1A\n"); fprintf(stderr,
"Invalid format differentiation field value. This is Format1A\n");
return -1; return -1;
} }
if (*y++ == 0) { if (*y++ == 0) {
@ -289,7 +284,8 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
} }
/* unpack RIV according to 8.1 of 36.213 */ /* unpack RIV according to 8.1 of 36.213 */
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop); uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - n_ul_hop);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_prb); ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_prb);
bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop); bit_pack(riv, &y, riv_nbits(nof_prb) - n_ul_hop);
data->type2_alloc.riv = riv; data->type2_alloc.riv = riv;
@ -307,7 +303,8 @@ int dci_format0_unpack(dci_msg_t *msg, ra_pusch_t *data, int nof_prb) {
// 8.6.2 First paragraph // 8.6.2 First paragraph
if (mcs <= 28) { if (mcs <= 28) {
ra_mcs_from_idx_ul(mcs, &data->mcs); ra_mcs_from_idx_ul(mcs, &data->mcs);
data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx, ra_nprb_ul(data, nof_prb)); data->mcs.tbs = ra_tbs_from_idx(data->mcs.tbs_idx,
ra_nprb_ul(data, nof_prb));
} }
// 8.6.1 and 8.6.2 36.213 second paragraph // 8.6.1 and 8.6.2 36.213 second paragraph
@ -348,10 +345,12 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
case alloc_type1: case alloc_type1:
bit_pack(data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P))); bit_pack(data->type1_alloc.rbg_subset, &y, (int) ceilf(log2f(P)));
*y++ = data->type1_alloc.shift ? 1 : 0; *y++ = data->type1_alloc.shift ? 1 : 0;
bit_pack(data->type1_alloc.vrb_bitmask, &y, alloc_size - (int) ceilf(log2f(P)) - 1); bit_pack(data->type1_alloc.vrb_bitmask, &y,
alloc_size - (int) ceilf(log2f(P)) - 1);
break; break;
default: default:
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n"); fprintf(stderr,
"Format 1 accepts type0 or type1 resource allocation only\n");
return -1; return -1;
} }
@ -361,7 +360,8 @@ int dci_format1_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
mcs = data->mcs.mcs_idx; mcs = data->mcs.mcs_idx;
} else { } else {
if (data->mcs.tbs) { if (data->mcs.tbs) {
data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs, ra_nprb_dl(data, nof_prb)); data->mcs.tbs_idx = ra_tbs_to_table_idx(data->mcs.tbs,
ra_nprb_dl(data, nof_prb));
} }
mcs = ra_mcs_to_table_idx(&data->mcs); mcs = ra_mcs_to_table_idx(&data->mcs);
} }
@ -416,10 +416,12 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
case alloc_type1: case alloc_type1:
data->type1_alloc.rbg_subset = bit_unpack(&y, (int) ceilf(log2f(P))); data->type1_alloc.rbg_subset = bit_unpack(&y, (int) ceilf(log2f(P)));
data->type1_alloc.shift = *y++ ? true : false; data->type1_alloc.shift = *y++ ? true : false;
data->type1_alloc.vrb_bitmask = bit_unpack(&y, alloc_size - (int) ceilf(log2f(P)) - 1); data->type1_alloc.vrb_bitmask = bit_unpack(&y,
alloc_size - (int) ceilf(log2f(P)) - 1);
break; break;
default: default:
fprintf(stderr, "Format 1 accepts type0 or type1 resource allocation only\n"); fprintf(stderr,
"Format 1 accepts type0 or type1 resource allocation only\n");
return -1; return -1;
} }
@ -439,16 +441,15 @@ int dci_format1_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
// TPC not implemented // TPC not implemented
return 0; return 0;
} }
/* Packs DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3 /* Packs DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
* *
* TODO: RA procedure initiated by PDCCH, TPC commands * TODO: RA procedure initiated by PDCCH, TPC commands
*/ */
int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_is_crnti) { int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb,
bool crc_is_crnti) {
/* pack bits */ /* pack bits */
char *y = msg->data; char *y = msg->data;
@ -464,7 +465,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
if (data->type2_alloc.mode == t2_loc) { if (data->type2_alloc.mode == t2_loc) {
if (data->type2_alloc.L_crb > nof_prb) { if (data->type2_alloc.L_crb > nof_prb) {
fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n", data->type2_alloc.L_crb); fprintf(stderr, "L_CRB=%d can not exceed system BW for localized type2\n",
data->type2_alloc.L_crb);
return -1; return -1;
} }
} else { } else {
@ -475,14 +477,17 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1); n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
} }
if (data->type2_alloc.L_crb > n_vrb_dl) { if (data->type2_alloc.L_crb > n_vrb_dl) {
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb, n_vrb_dl); fprintf(stderr,
"L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
data->type2_alloc.L_crb, n_vrb_dl);
return -1; return -1;
} }
} }
/* pack RIV according to 7.1.6.3 of 36.213 */ /* pack RIV according to 7.1.6.3 of 36.213 */
uint32_t riv; uint32_t riv;
if (data->type2_alloc.L_crb) { if (data->type2_alloc.L_crb) {
riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start, nof_prb); riv = ra_type2_to_riv(data->type2_alloc.L_crb, data->type2_alloc.RB_start,
nof_prb);
} else { } else {
riv = data->type2_alloc.riv; riv = data->type2_alloc.riv;
} }
@ -545,7 +550,8 @@ int dci_format1As_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb, bool crc_i
/* Unpacks DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3 /* Unpacks DCI format 1A for compact scheduling of PDSCH words according to 36.212 5.3.3.1.3
* *
*/ */
int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) { int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
bool crc_is_crnti) {
/* pack bits */ /* pack bits */
char *y = msg->data; char *y = msg->data;
@ -555,8 +561,10 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
fprintf(stderr, "Invalid message length for format 1A\n"); fprintf(stderr, "Invalid message length for format 1A\n");
return -1; return -1;
} }
if (*y++ != 1) { if (*y++ != 1) {
fprintf(stderr, "Invalid format differentiation field value. This is Format0\n"); fprintf(stderr,
"Invalid format differentiation field value. This is Format0\n");
return -1; return -1;
} }
@ -579,7 +587,8 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
nof_vrb = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1); nof_vrb = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
} }
uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - nb_gap); uint32_t riv = bit_unpack(&y, riv_nbits(nof_prb) - nb_gap);
ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start, nof_prb, nof_vrb); ra_type2_from_riv(riv, &data->type2_alloc.L_crb, &data->type2_alloc.RB_start,
nof_prb, nof_vrb);
data->type2_alloc.riv = riv; data->type2_alloc.riv = riv;
// unpack MCS // unpack MCS
@ -602,7 +611,7 @@ int dci_format1As_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc
y++; y++;
} else { } else {
y++; // MSB of TPC is reserved y++; // MSB of TPC is reserved
*y++ = data->type2_alloc.n_prb1a; // LSB indicates N_prb_1a for TBS data->type2_alloc.n_prb1a = *y++; // LSB indicates N_prb_1a for TBS
} }
data->mcs.tbs_idx = data->mcs.mcs_idx; data->mcs.tbs_idx = data->mcs.mcs_idx;
int n_prb; int n_prb;
@ -626,7 +635,8 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
char *y = msg->data; char *y = msg->data;
if (data->alloc_type != alloc_type2 || data->type2_alloc.mode != t2_dist) { if (data->alloc_type != alloc_type2 || data->type2_alloc.mode != t2_dist) {
fprintf(stderr, "Format 1C accepts distributed type2 resource allocation only\n"); fprintf(stderr,
"Format 1C accepts distributed type2 resource allocation only\n");
return -1; return -1;
} }
@ -637,8 +647,9 @@ int dci_format1Cs_pack(ra_pdsch_t *data, dci_msg_t *msg, int nof_prb) {
int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1); int n_vrb_dl = ra_type2_n_vrb_dl(nof_prb, data->type2_alloc.n_gap == t2_ng1);
if (data->type2_alloc.L_crb > ((int) n_vrb_dl / n_step) * n_step) { if (data->type2_alloc.L_crb > ((int) n_vrb_dl / n_step) * n_step) {
fprintf(stderr, "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n", data->type2_alloc.L_crb, fprintf(stderr,
((int) n_vrb_dl/n_step)*n_step); "L_CRB=%d can not exceed N_vrb_dl=%d for distributed type2\n",
data->type2_alloc.L_crb, ((int) n_vrb_dl / n_step) * n_step);
return -1; return -1;
} }
if (data->type2_alloc.L_crb % n_step) { if (data->type2_alloc.L_crb % n_step) {
@ -714,7 +725,8 @@ int dci_format1Cs_unpack(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb) {
return 0; return 0;
} }
int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, int nof_prb, bool crc_is_crnti) { int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format,
int nof_prb, bool crc_is_crnti) {
switch (format) { switch (format) {
case Format1: case Format1:
return dci_format1_pack(data, msg, nof_prb); return dci_format1_pack(data, msg, nof_prb);
@ -723,12 +735,14 @@ int dci_msg_pack_pdsch(ra_pdsch_t *data, dci_msg_t *msg, dci_format_t format, in
case Format1C: case Format1C:
return dci_format1Cs_pack(data, msg, nof_prb); return dci_format1Cs_pack(data, msg, nof_prb);
default: default:
fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n", dci_format_string(format)); fprintf(stderr, "Invalid DCI format %s for PDSCH resource allocation\n",
dci_format_string(format));
return -1; return -1;
} }
} }
int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb, bool crc_is_crnti) { int dci_msg_unpack_pdsch(dci_msg_t *msg, ra_pdsch_t *data, int nof_prb,
bool crc_is_crnti) {
if (msg->location.nof_bits == dci_format_sizeof(Format1, nof_prb)) { if (msg->location.nof_bits == dci_format_sizeof(Format1, nof_prb)) {
return dci_format1_unpack(msg, data, nof_prb); return dci_format1_unpack(msg, data, nof_prb);
} else if (msg->location.nof_bits == dci_format_sizeof(Format1A, nof_prb)) { } else if (msg->location.nof_bits == dci_format_sizeof(Format1A, nof_prb)) {
@ -772,7 +786,8 @@ void dci_msg_type_fprint(FILE *f, dci_msg_type_t type) {
fprintf(f, "%s PDSCH Scheduling\n", dci_format_string(type.format)); fprintf(f, "%s PDSCH Scheduling\n", dci_format_string(type.format));
break; break;
case RA_PROC_PDCCH: case RA_PROC_PDCCH:
fprintf(f,"%s Random access initiated by PDCCH\n", dci_format_string(type.format)); fprintf(f, "%s Random access initiated by PDCCH\n",
dci_format_string(type.format));
break; break;
case MCCH_CHANGE: case MCCH_CHANGE:
fprintf(f, "%s MCCH change notification\n", dci_format_string(type.format)); fprintf(f, "%s MCCH change notification\n", dci_format_string(type.format));
@ -783,7 +798,8 @@ void dci_msg_type_fprint(FILE *f, dci_msg_type_t type) {
} }
} }
int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb, unsigned short crnti) { int dci_msg_get_type(dci_msg_t *msg, dci_msg_type_t *type, int nof_prb,
unsigned short crnti) {
if (msg->location.nof_bits == dci_format_sizeof(Format0, nof_prb) if (msg->location.nof_bits == dci_format_sizeof(Format0, nof_prb)
&& !msg->data[0]) { && !msg->data[0]) {
type->type = PUSCH_SCHED; type->type = PUSCH_SCHED;

@ -25,7 +25,6 @@
* *
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -43,18 +42,16 @@
#include "lte/utils/debug.h" #include "lte/utils/debug.h"
const char crc_mask[4][16] = { const char crc_mask[4][16] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 1, 1, 1, 1, 1, 1, 1,
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 0, 0 }, { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 } };
{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}
};
bool pbch_exists(int nframe, int nslot) { bool pbch_exists(int nframe, int nslot) {
return (!(nframe % 5) && nslot == 1); return (!(nframe % 5) && nslot == 1);
} }
int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bool put) { int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id,
bool put) {
int i; int i;
cf_t *ptr; cf_t *ptr;
assert(cell_id >= 0); assert(cell_id >= 0);
@ -93,7 +90,8 @@ int pbch_cp(cf_t *input, cf_t *output, int nof_prb, lte_cp_t cp, int cell_id, bo
* *
* 36.211 10.3 section 6.6.4 * 36.211 10.3 section 6.6.4
*/ */
int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id) { int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp,
int cell_id) {
return pbch_cp(pbch, slot1_data, nof_prb, cp, cell_id, true); return pbch_cp(pbch, slot1_data, nof_prb, cp, cell_id, true);
} }
@ -104,7 +102,8 @@ int pbch_put(cf_t *pbch, cf_t *slot1_data, int nof_prb, lte_cp_t cp, int cell_id
* *
* 36.211 10.3 section 6.6.4 * 36.211 10.3 section 6.6.4
*/ */
int pbch_get(cf_t *slot1_data, cf_t *pbch, int nof_prb, lte_cp_t cp, int cell_id) { int pbch_get(cf_t *slot1_data, cf_t *pbch, int nof_prb, lte_cp_t cp,
int cell_id) {
return pbch_cp(slot1_data, pbch, nof_prb, cp, cell_id, false); return pbch_cp(slot1_data, pbch, nof_prb, cp, cell_id, false);
} }
@ -188,8 +187,7 @@ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) {
} }
ret = 0; ret = 0;
clean: clean: if (ret == -1) {
if (ret == -1) {
pbch_free(q); pbch_free(q);
} }
return ret; return ret;
@ -277,7 +275,6 @@ void pbch_mib_unpack(char *msg, pbch_mib_t *mib) {
mib->sfn = bit_unpack(&msg, 8) << 2; mib->sfn = bit_unpack(&msg, 8) << 2;
} }
/** Unpacks MIB from PBCH message. /** Unpacks MIB from PBCH message.
* msg buffer must be 24 byte length at least * msg buffer must be 24 byte length at least
*/ */
@ -319,7 +316,8 @@ void pbch_mib_pack(pbch_mib_t *mib, char *msg) {
void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib) { void pbch_mib_fprint(FILE *stream, pbch_mib_t *mib) {
printf(" - Nof ports: %d\n", mib->nof_ports); printf(" - Nof ports: %d\n", mib->nof_ports);
printf(" - PRB: %d\n", mib->nof_prb); printf(" - PRB: %d\n", mib->nof_prb);
printf(" - PHICH Length: %s\n", mib->phich_length==PHICH_EXT?"Extended":"Normal"); printf(" - PHICH Length: %s\n",
mib->phich_length == PHICH_EXT ? "Extended" : "Normal");
printf(" - PHICH Resources: "); printf(" - PHICH Resources: ");
switch (mib->phich_resources) { switch (mib->phich_resources) {
case R_1_6: case R_1_6:
@ -343,7 +341,6 @@ void pbch_decode_reset(pbch_t *q) {
q->frame_idx = 0; q->frame_idx = 0;
} }
void crc_set_mask(char *data, int nof_ports) { void crc_set_mask(char *data, int nof_ports) {
int i; int i;
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
@ -352,7 +349,6 @@ void crc_set_mask(char *data, int nof_ports) {
} }
/* Checks CRC after applying the mask for the given number of ports. /* Checks CRC after applying the mask for the given number of ports.
* *
* The bits buffer size must be at least 40 bytes. * The bits buffer size must be at least 40 bytes.
@ -366,13 +362,16 @@ int pbch_crc_check(pbch_t *q, char *bits, int nof_ports) {
return crc_checksum(&q->crc, data, 40); return crc_checksum(&q->crc, data, 40);
} }
int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int nof_bits, int nof_ports) { int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n,
int nof_bits, int nof_ports) {
int j; int j;
memcpy(&q->temp[dst*nof_bits], &q->pbch_llr[src*nof_bits], n*nof_bits*sizeof(float)); memcpy(&q->temp[dst * nof_bits], &q->pbch_llr[src * nof_bits],
n * nof_bits * sizeof(float));
/* descramble */ /* descramble */
scrambling_f_offset(&q->seq_pbch, &q->temp[dst*nof_bits], dst*nof_bits, n*nof_bits); scrambling_f_offset(&q->seq_pbch, &q->temp[dst * nof_bits], dst * nof_bits,
n * nof_bits);
for (j = 0; j < dst * nof_bits; j++) { for (j = 0; j < dst * nof_bits; j++) {
q->temp[j] = RX_NULL; q->temp[j] = RX_NULL;
@ -423,7 +422,8 @@ int pbch_decode_frame(pbch_t *q, pbch_mib_t *mib, int src, int dst, int n, int n
* *
* Returns 1 if successfully decoded MIB, 0 if not and -1 on error * Returns 1 if successfully decoded MIB, 0 if not and -1 on error
*/ */
int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float ebno, pbch_mib_t *mib) { int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
float ebno, pbch_mib_t *mib) {
int src, dst, res, nb; int src, dst, res, nb;
int nant_[3] = { 1, 2, 4 }; int nant_[3] = { 1, 2, 4 };
int na, nant; int na, nant;
@ -440,16 +440,17 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
memset(&x[MAX_PORTS_CTRL], 0, sizeof(cf_t*) * (MAX_LAYERS - MAX_PORTS_CTRL)); memset(&x[MAX_PORTS_CTRL], 0, sizeof(cf_t*) * (MAX_LAYERS - MAX_PORTS_CTRL));
/* extract symbols */ /* extract symbols */
if (q->nof_symbols != pbch_get(slot1_symbols, q->pbch_symbols[0], q->nof_prb, if (q->nof_symbols
q->cp, q->cell_id)) { != pbch_get(slot1_symbols, q->pbch_symbols[0], q->nof_prb, q->cp,
q->cell_id)) {
fprintf(stderr, "There was an error getting the PBCH symbols\n"); fprintf(stderr, "There was an error getting the PBCH symbols\n");
return -1; return -1;
} }
/* extract channel estimates */ /* extract channel estimates */
for (i = 0; i < MAX_PORTS_CTRL; i++) { for (i = 0; i < MAX_PORTS_CTRL; i++) {
if (q->nof_symbols != pbch_get(ce[i], q->ce[i], q->nof_prb, if (q->nof_symbols
q->cp, q->cell_id)) { != pbch_get(ce[i], q->ce[i], q->nof_prb, q->cp, q->cell_id)) {
fprintf(stderr, "There was an error getting the PBCH symbols\n"); fprintf(stderr, "There was an error getting the PBCH symbols\n");
return -1; return -1;
} }
@ -467,9 +468,11 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
/* in conctrol channels, only diversity is supported */ /* in conctrol channels, only diversity is supported */
if (nant == 1) { if (nant == 1) {
/* no need for layer demapping */ /* no need for layer demapping */
predecoding_single_zf(q->pbch_symbols[0], q->ce[0], q->pbch_d, q->nof_symbols); predecoding_single_zf(q->pbch_symbols[0], q->ce[0], q->pbch_d,
q->nof_symbols);
} else { } else {
predecoding_diversity_zf(q->pbch_symbols, q->ce, x, nant, q->nof_symbols); predecoding_diversity_zf(q->pbch_symbols[0], q->ce, x, nant,
q->nof_symbols);
layerdemap_diversity(x, q->pbch_d, nant, q->nof_symbols / nant); layerdemap_diversity(x, q->pbch_d, nant, q->nof_symbols / nant);
} }
@ -488,7 +491,8 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
for (nb = 0; nb < q->frame_idx && !res; nb++) { for (nb = 0; nb < q->frame_idx && !res; nb++) {
for (dst = 0; (dst < 4 - nb) && !res; dst++) { for (dst = 0; (dst < 4 - nb) && !res; dst++) {
for (src = 0; src < q->frame_idx - nb && !res; src++) { for (src = 0; src < q->frame_idx - nb && !res; src++) {
DEBUG("Trying %d blocks at offset %d as subframe mod4 number %d\n", nb+1, src, dst); DEBUG("Trying %d blocks at offset %d as subframe mod4 number %d\n",
nb + 1, src, dst);
res = pbch_decode_frame(q, mib, src, dst, nb + 1, nof_bits, nant); res = pbch_decode_frame(q, mib, src, dst, nb + 1, nof_bits, nant);
} }
} }
@ -503,10 +507,10 @@ int pbch_decode(pbch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], float
return res; return res;
} }
/** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission /** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission
*/ */
void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports) { void pbch_encode(pbch_t *q, pbch_mib_t *mib,
cf_t *slot1_symbols[MAX_PORTS_CTRL], int nof_ports) {
int i; int i;
int nof_bits = 2 * q->nof_symbols; int nof_bits = 2 * q->nof_symbols;
@ -537,21 +541,22 @@ void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL]
scrambling_b_offset(&q->seq_pbch, &q->pbch_rm_b[q->frame_idx * nof_bits], scrambling_b_offset(&q->seq_pbch, &q->pbch_rm_b[q->frame_idx * nof_bits],
q->frame_idx * nof_bits, nof_bits); q->frame_idx * nof_bits, nof_bits);
mod_modulate(&q->mod, &q->pbch_rm_b[q->frame_idx * nof_bits], q->pbch_d, nof_bits); mod_modulate(&q->mod, &q->pbch_rm_b[q->frame_idx * nof_bits], q->pbch_d,
nof_bits);
/* layer mapping & precoding */ /* layer mapping & precoding */
if (nof_ports > 1) { if (nof_ports > 1) {
layermap_diversity(q->pbch_d, x, nof_ports, q->nof_symbols); layermap_diversity(q->pbch_d, x, nof_ports, q->nof_symbols);
precoding_diversity(x, q->pbch_symbols, nof_ports, q->nof_symbols/nof_ports); precoding_diversity(x, q->pbch_symbols, nof_ports,
q->nof_symbols / nof_ports);
} else { } else {
memcpy(q->pbch_symbols[0], q->pbch_d, q->nof_symbols * sizeof(cf_t)); memcpy(q->pbch_symbols[0], q->pbch_d, q->nof_symbols * sizeof(cf_t));
} }
/* mapping to resource elements */ /* mapping to resource elements */
for (i = 0; i < nof_ports; i++) { for (i = 0; i < nof_ports; i++) {
pbch_put(q->pbch_symbols[i], slot1_symbols[i], q->nof_prb, q->cp, q->cell_id); pbch_put(q->pbch_symbols[i], slot1_symbols[i], q->nof_prb, q->cp,
q->cell_id);
} }
q->frame_idx++; q->frame_idx++;
if (q->frame_idx == 4) { if (q->frame_idx == 4) {
@ -559,5 +564,3 @@ void pbch_encode(pbch_t *q, pbch_mib_t *mib, cf_t *slot1_symbols[MAX_PORTS_CTRL]
} }
} }

@ -25,7 +25,6 @@
* *
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -42,23 +41,22 @@
#include "lte/utils/vector.h" #include "lte/utils/vector.h"
#include "lte/utils/debug.h" #include "lte/utils/debug.h"
// Table 5.3.4-1 // Table 5.3.4-1
static char cfi_table[4][PCFICH_CFI_LEN] = { static char cfi_table[4][PCFICH_CFI_LEN] = { { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
{0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1}, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1 }, { 1, 0, 1,
{1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0}, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
{1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1}, 0, 1, 1, 0 }, { 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} // reserved 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } // reserved
}; };
bool pcfich_exists(int nframe, int nslot) { bool pcfich_exists(int nframe, int nslot) {
return true; return true;
} }
/** Initializes the pcfich channel receiver */ /** Initializes the pcfich channel receiver */
int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_ports, lte_cp_t cp) { int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb,
int nof_ports, lte_cp_t cp) {
int ret = -1; int ret = -1;
if (cell_id < 0) { if (cell_id < 0) {
return -1; return -1;
@ -68,7 +66,7 @@ int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_
q->cp = cp; q->cp = cp;
q->regs = regs; q->regs = regs;
q->nof_prb = nof_prb; q->nof_prb = nof_prb;
q->nof_tx_ports = nof_tx_ports; q->nof_ports = nof_ports;
if (modem_table_std(&q->mod, LTE_QPSK, false)) { if (modem_table_std(&q->mod, LTE_QPSK, false)) {
goto clean; goto clean;
@ -86,8 +84,7 @@ int pcfich_init(pcfich_t *q, regs_t *regs, int cell_id, int nof_prb, int nof_tx_
q->nof_symbols = PCFICH_RE; q->nof_symbols = PCFICH_RE;
ret = 0; ret = 0;
clean: clean: if (ret == -1) {
if (ret == -1) {
pcfich_free(q); pcfich_free(q);
} }
return ret; return ret;
@ -126,7 +123,6 @@ int pcfich_cfi_decode(char bits[PCFICH_CFI_LEN], int *cfi) {
} }
/** Encodes the CFI producing a vector of 32 bits. /** Encodes the CFI producing a vector of 32 bits.
* 36.211 10.3 section 5.3.4 * 36.211 10.3 section 5.3.4
*/ */
@ -139,19 +135,18 @@ int pcfich_cfi_encode(int cfi, char bits[PCFICH_CFI_LEN]) {
return 0; return 0;
} }
/* Decodes the PCFICH channel and saves the CFI in the cfi pointer. /* Decodes the PCFICH channel and saves the CFI in the cfi pointer.
* *
* Returns 1 if successfully decoded the CFI, 0 if not and -1 on error * Returns 1 if successfully decoded the CFI, 0 if not and -1 on error
*/ */
int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int nsubframe, int *cfi, int *distance) { int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int nsubframe, int *cfi, int *distance) {
int dist; int dist;
/* Set pointers for layermapping & precoding */ /* Set pointers for layermapping & precoding */
int i; int i;
cf_t *x[MAX_LAYERS]; cf_t *x[MAX_LAYERS];
cf_t *ce_precoding[MAX_PORTS]; cf_t *ce_precoding[MAX_PORTS];
cf_t *symbols_precoding[MAX_PORTS];
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) { if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid nslot %d\n", nsubframe); fprintf(stderr, "Invalid nslot %d\n", nsubframe);
@ -164,17 +159,17 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
} }
for (i = 0; i < MAX_PORTS; i++) { for (i = 0; i < MAX_PORTS; i++) {
ce_precoding[i] = q->ce[i]; ce_precoding[i] = q->ce[i];
symbols_precoding[i] = q->pcfich_symbols[i];
} }
/* extract symbols */ /* extract symbols */
if (q->nof_symbols != regs_pcfich_get(q->regs, slot_symbols, q->pcfich_symbols[0])) { if (q->nof_symbols
!= regs_pcfich_get(q->regs, slot_symbols, q->pcfich_symbols[0])) {
fprintf(stderr, "There was an error getting the PCFICH symbols\n"); fprintf(stderr, "There was an error getting the PCFICH symbols\n");
return -1; return -1;
} }
/* extract channel estimates */ /* extract channel estimates */
for (i=0;i<q->nof_tx_ports;i++) { for (i = 0; i < q->nof_ports; i++) {
if (q->nof_symbols != regs_pcfich_get(q->regs, ce[i], q->ce[i])) { if (q->nof_symbols != regs_pcfich_get(q->regs, ce[i], q->ce[i])) {
fprintf(stderr, "There was an error getting the PCFICH symbols\n"); fprintf(stderr, "There was an error getting the PCFICH symbols\n");
return -1; return -1;
@ -182,12 +177,15 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
} }
/* in control channels, only diversity is supported */ /* in control channels, only diversity is supported */
if (q->nof_tx_ports == 1) { if (q->nof_ports == 1) {
/* no need for layer demapping */ /* no need for layer demapping */
predecoding_single_zf(q->pcfich_symbols[0], q->ce[0], q->pcfich_d, q->nof_symbols); predecoding_single_zf(q->pcfich_symbols[0], q->ce[0], q->pcfich_d,
q->nof_symbols);
} else { } else {
predecoding_diversity_zf(symbols_precoding, ce_precoding, x, q->nof_tx_ports, q->nof_symbols); predecoding_diversity_zf(q->pcfich_symbols[0], ce_precoding, x,
layerdemap_diversity(x, q->pcfich_d, q->nof_tx_ports, q->nof_symbols/q->nof_tx_ports); q->nof_ports, q->nof_symbols);
layerdemap_diversity(x, q->pcfich_d, q->nof_ports,
q->nof_symbols / q->nof_ports);
} }
/* demodulate symbols */ /* demodulate symbols */
@ -208,10 +206,10 @@ int pcfich_decode(pcfich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL], int
} }
} }
/** Encodes CFI and maps symbols to the slot /** Encodes CFI and maps symbols to the slot
*/ */
int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int nsubframe) { int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe) {
int i; int i;
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) { if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
@ -224,7 +222,7 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
cf_t *symbols_precoding[MAX_PORTS]; cf_t *symbols_precoding[MAX_PORTS];
/* number of layers equals number of ports */ /* number of layers equals number of ports */
for (i=0;i<q->nof_tx_ports;i++) { for (i = 0; i < q->nof_ports; i++) {
x[i] = q->pcfich_x[i]; x[i] = q->pcfich_x[i];
} }
for (i = 0; i < MAX_PORTS; i++) { for (i = 0; i < MAX_PORTS; i++) {
@ -240,15 +238,16 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
mod_modulate(&q->mod, q->data, q->pcfich_d, PCFICH_CFI_LEN); mod_modulate(&q->mod, q->data, q->pcfich_d, PCFICH_CFI_LEN);
/* layer mapping & precoding */ /* layer mapping & precoding */
if (q->nof_tx_ports > 1) { if (q->nof_ports > 1) {
layermap_diversity(q->pcfich_d, x, q->nof_tx_ports, q->nof_symbols); layermap_diversity(q->pcfich_d, x, q->nof_ports, q->nof_symbols);
precoding_diversity(x, symbols_precoding, q->nof_tx_ports, q->nof_symbols/q->nof_tx_ports); precoding_diversity(x, symbols_precoding, q->nof_ports,
q->nof_symbols / q->nof_ports);
} else { } else {
memcpy(q->pcfich_symbols[0], q->pcfich_d, q->nof_symbols * sizeof(cf_t)); memcpy(q->pcfich_symbols[0], q->pcfich_d, q->nof_symbols * sizeof(cf_t));
} }
/* mapping to resource elements */ /* mapping to resource elements */
for (i=0;i<q->nof_tx_ports;i++) { for (i = 0; i < q->nof_ports; i++) {
if (regs_pcfich_put(q->regs, q->pcfich_symbols[i], slot_symbols[i]) < 0) { if (regs_pcfich_put(q->regs, q->pcfich_symbols[i], slot_symbols[i]) < 0) {
fprintf(stderr, "Error putting PCHICH resource elements\n"); fprintf(stderr, "Error putting PCHICH resource elements\n");
return -1; return -1;
@ -258,4 +257,3 @@ int pcfich_encode(pcfich_t *q, int cfi, cf_t *slot_symbols[MAX_PORTS_CTRL], int
return 0; return 0;
} }

@ -58,7 +58,8 @@ const dci_format_t ue_formats[NOF_UE_FORMATS] = {Format0, Format1}; // 1A has th
/** /**
* 36.213 9.1 * 36.213 9.1
*/ */
int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short rnti) { int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits,
unsigned short rnti) {
int i, l, L, k; int i, l, L, k;
k = 0; k = 0;
for (l = 3; l > 1; l--) { for (l = 3; l > 1; l--) {
@ -79,7 +80,8 @@ int gen_common_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned sh
/** /**
* 36.213 9.1 * 36.213 9.1
*/ */
int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short rnti, int subframe) { int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits,
unsigned short rnti, int subframe) {
int i, l, L, k, m; int i, l, L, k, m;
unsigned int Yk; unsigned int Yk;
const int S[4] = { 6, 12, 8, 16 }; const int S[4] = { 6, 12, 8, 16 };
@ -87,7 +89,8 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short
if (!subframe) { if (!subframe) {
INFO("UE-specific candidates for RNTI: 0x%x, NofBits: %d, NofCCE: %d\n", INFO("UE-specific candidates for RNTI: 0x%x, NofBits: %d, NofCCE: %d\n",
rnti, nof_bits, nof_cce); rnti, nof_bits, nof_cce);
if (VERBOSE_ISINFO()) printf("[INFO]: "); if (VERBOSE_ISINFO())
printf("[INFO]: ");
} }
for (l = 3; l >= 0; l--) { for (l = 3; l >= 0; l--) {
L = (1 << l); L = (1 << l);
@ -109,14 +112,16 @@ int gen_ue_search(dci_candidate_t *c, int nof_cce, int nof_bits, unsigned short
} }
} }
if (!subframe) { if (!subframe) {
if (VERBOSE_ISINFO()) printf("\n"); if (VERBOSE_ISINFO())
printf("\n");
} }
return k; return k;
} }
void pdcch_init_common(pdcch_t *q, pdcch_search_t *s, unsigned short rnti) { void pdcch_init_common(pdcch_t *q, pdcch_search_t *s, unsigned short rnti) {
int k, i; int k, i;
s->nof_candidates = NOF_COMMON_FORMATS*(MIN(q->nof_cce,16) / 4 + MIN(q->nof_cce,16) / 8); s->nof_candidates = NOF_COMMON_FORMATS
* (MIN(q->nof_cce,16) / 4 + MIN(q->nof_cce,16) / 8);
if (s->nof_candidates) { if (s->nof_candidates) {
s->candidates[0] = malloc(sizeof(dci_candidate_t) * s->nof_candidates); s->candidates[0] = malloc(sizeof(dci_candidate_t) * s->nof_candidates);
dci_candidate_t *c = s->candidates[0]; dci_candidate_t *c = s->candidates[0];
@ -152,7 +157,9 @@ void pdcch_init_search_ue(pdcch_t *q, unsigned short c_rnti) {
for (l = 0; l < 3; l++) { for (l = 0; l < 3; l++) {
s->nof_candidates += NOF_UE_FORMATS * (MIN(q->nof_cce,16) / (1 << l)); s->nof_candidates += NOF_UE_FORMATS * (MIN(q->nof_cce,16) / (1 << l));
} }
INFO("Initiating %d candidate(s) in the UE-specific search space for C-RNTI: 0x%x\n", s->nof_candidates, c_rnti); INFO(
"Initiating %d candidate(s) in the UE-specific search space for C-RNTI: 0x%x\n",
s->nof_candidates, c_rnti);
if (s->nof_candidates) { if (s->nof_candidates) {
for (n = 0; n < NSUBFRAMES_X_FRAME; n++) { for (n = 0; n < NSUBFRAMES_X_FRAME; n++) {
s->candidates[n] = malloc(sizeof(dci_candidate_t) * s->nof_candidates); s->candidates[n] = malloc(sizeof(dci_candidate_t) * s->nof_candidates);
@ -215,8 +222,8 @@ int pdcch_init(pdcch_t *q, regs_t *regs, int nof_prb, int nof_ports,
q->nof_symbols = 4 * q->nof_regs; q->nof_symbols = 4 * q->nof_regs;
q->nof_bits = 2 * q->nof_symbols; q->nof_bits = 2 * q->nof_symbols;
INFO("Init PDCCH: %d CCEs (%d REGs), %d bits, %d symbols, %d ports\n", q->nof_cce, INFO("Init PDCCH: %d CCEs (%d REGs), %d bits, %d symbols, %d ports\n",
q->nof_regs, q->nof_bits, q->nof_symbols, q->nof_ports); q->nof_cce, q->nof_regs, q->nof_bits, q->nof_symbols, q->nof_ports);
if (modem_table_std(&q->mod, LTE_QPSK, true)) { if (modem_table_std(&q->mod, LTE_QPSK, true)) {
goto clean; goto clean;
@ -321,8 +328,7 @@ void pdcch_free(pdcch_t *q) {
* *
* TODO: UE transmit antenna selection CRC mask * TODO: UE transmit antenna selection CRC mask
*/ */
unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E, unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E, int nof_bits) {
int nof_bits) {
float tmp[3 * (DCI_MAX_BITS + 16)]; float tmp[3 * (DCI_MAX_BITS + 16)];
unsigned short p_bits, crc_res; unsigned short p_bits, crc_res;
@ -330,13 +336,6 @@ unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E,
assert(nof_bits < DCI_MAX_BITS); assert(nof_bits < DCI_MAX_BITS);
/* char a[] = {1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,0,0,1,1,0,0,1,0,1,1,1,0,0,1,1,0,1,0,1,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,1,0,0,0,1,0,0,1,1,1,1,0,1,0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,1,0,0,0,0};
float *b = malloc(sizeof(E));
for (int i=0;i<E;i++) {
b[i] = a[i]?1:-1;
}
*/
/* unrate matching */ /* unrate matching */
rm_conv_rx(e, E, tmp, 3 * (nof_bits + 16)); rm_conv_rx(e, E, tmp, 3 * (nof_bits + 16));
@ -355,7 +354,8 @@ unsigned short dci_decode(pdcch_t *q, float *e, char *data, int E,
x = &data[nof_bits]; x = &data[nof_bits];
p_bits = (unsigned short) bit_unpack(&x, 16); p_bits = (unsigned short) bit_unpack(&x, 16);
crc_res = ((unsigned short) crc_checksum(&q->crc, data, nof_bits) & 0xffff); crc_res = ((unsigned short) crc_checksum(&q->crc, data, nof_bits) & 0xffff);
DEBUG("p_bits: 0x%x, crc_res: 0x%x, tot: 0x%x\n", p_bits, crc_res, p_bits ^ crc_res); DEBUG("p_bits: 0x%x, crc_res: 0x%x, tot: 0x%x\n", p_bits, crc_res,
p_bits ^ crc_res);
return (p_bits ^ crc_res); return (p_bits ^ crc_res);
} }
@ -363,23 +363,20 @@ int pdcch_decode_candidate(pdcch_t *q, float *llr, dci_candidate_t *c,
dci_msg_t *msg) { dci_msg_t *msg) {
unsigned short crc_res; unsigned short crc_res;
DEBUG("Trying Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n", DEBUG("Trying Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L, c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L, c->rnti);
c->rnti);
crc_res = dci_decode(q, &llr[72 * c->ncce], msg->data, crc_res = dci_decode(q, &llr[72 * c->ncce], msg->data,
PDCCH_FORMAT_NOF_BITS(c->L), c->nof_bits); PDCCH_FORMAT_NOF_BITS(c->L), c->nof_bits);
if (c->rnti == crc_res) { if (c->rnti == crc_res) {
memcpy(&msg->location, c, sizeof(dci_candidate_t)); memcpy(&msg->location, c, sizeof(dci_candidate_t));
INFO( INFO("FOUND Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n",
"FOUND Candidate: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n", c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L, c->rnti);
c->nof_bits, PDCCH_FORMAT_NOF_BITS(c->L), c->ncce, c->L,
c->rnti);
return 1; return 1;
} }
return 0; return 0;
} }
int pdcch_extract_llr(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], int pdcch_extract_llr(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
float *llr, int nsubframe, float ebno) { float *llr, int nsubframe, float ebno) {
/* Set pointers for layermapping & precoding */ /* Set pointers for layermapping & precoding */
@ -403,9 +400,10 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
memset(&x[q->nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->nof_ports)); memset(&x[q->nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->nof_ports));
/* extract symbols */ /* extract symbols */
int n = regs_pdcch_get(q->regs, slot1_symbols, q->pdcch_symbols[0]); int n = regs_pdcch_get(q->regs, slot_symbols, q->pdcch_symbols[0]);
if (q->nof_symbols != n) { if (q->nof_symbols != n) {
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n", q->nof_symbols, n); fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n",
q->nof_symbols, n);
return -1; return -1;
} }
@ -413,7 +411,8 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
for (i = 0; i < q->nof_ports; i++) { for (i = 0; i < q->nof_ports; i++) {
n = regs_pdcch_get(q->regs, ce[i], q->ce[i]); n = regs_pdcch_get(q->regs, ce[i], q->ce[i]);
if (q->nof_symbols != n) { if (q->nof_symbols != n) {
fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n", q->nof_symbols, n); fprintf(stderr, "Expected %d PDCCH symbols but got %d symbols\n",
q->nof_symbols, n);
return -1; return -1;
} }
} }
@ -424,7 +423,7 @@ int pdcch_extract_llr(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL],
predecoding_single_zf(q->pdcch_symbols[0], q->ce[0], q->pdcch_d, predecoding_single_zf(q->pdcch_symbols[0], q->ce[0], q->pdcch_d,
q->nof_symbols); q->nof_symbols);
} else { } else {
predecoding_diversity_zf(q->pdcch_symbols, q->ce, x, q->nof_ports, predecoding_diversity_zf(q->pdcch_symbols[0], q->ce, x, q->nof_ports,
q->nof_symbols); q->nof_symbols);
layerdemap_diversity(x, q->pdcch_d, q->nof_ports, layerdemap_diversity(x, q->pdcch_d, q->nof_ports,
q->nof_symbols / q->nof_ports); q->nof_symbols / q->nof_ports);
@ -459,7 +458,8 @@ int pdcch_decode_current_mode(pdcch_t *q, float *llr, dci_t *dci, int subframe)
k = 0; k = 0;
} }
for (i = 0; i < q->search_mode[q->current_search_mode].nof_candidates for (i = 0;
i < q->search_mode[q->current_search_mode].nof_candidates
&& dci->nof_dcis < dci->max_dcis; i++) { && dci->nof_dcis < dci->max_dcis; i++) {
if (pdcch_decode_candidate(q, q->pdcch_llr, if (pdcch_decode_candidate(q, q->pdcch_llr,
&q->search_mode[q->current_search_mode].candidates[k][i], &q->search_mode[q->current_search_mode].candidates[k][i],
@ -483,18 +483,16 @@ int pdcch_decode_ue(pdcch_t *q, float *llr, dci_t *dci, int nsubframe) {
return pdcch_decode_current_mode(q, llr, dci, nsubframe); return pdcch_decode_current_mode(q, llr, dci, nsubframe);
} }
/* Decodes PDCCH channels /* Decodes PDCCH channels
* *
* dci->nof_dcis is the size of the dci->msg buffer (ie max number of messages) * dci->nof_dcis is the size of the dci->msg buffer (ie max number of messages)
* *
* Returns number of messages stored in dci * Returns number of messages stored in dci
*/ */
int pdcch_decode(pdcch_t *q, cf_t *slot1_symbols, cf_t *ce[MAX_PORTS_CTRL], int pdcch_decode(pdcch_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
dci_t *dci, int nsubframe, float ebno) { dci_t *dci, int nsubframe, float ebno) {
if (pdcch_extract_llr(q, slot1_symbols, ce, q->pdcch_llr, nsubframe, if (pdcch_extract_llr(q, slot_symbols, ce, q->pdcch_llr, nsubframe, ebno)) {
ebno)) {
return -1; return -1;
} }
@ -521,7 +519,8 @@ void crc_set_mask_rnti(char *crc, unsigned short rnti) {
/** 36.212 5.3.3.2 to 5.3.3.4 /** 36.212 5.3.3.2 to 5.3.3.4
* TODO: UE transmit antenna selection CRC mask * TODO: UE transmit antenna selection CRC mask
*/ */
void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E, unsigned short rnti) { void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E,
unsigned short rnti) {
convcoder_t encoder; convcoder_t encoder;
char tmp[3 * (DCI_MAX_BITS + 16)]; char tmp[3 * (DCI_MAX_BITS + 16)];
@ -546,9 +545,9 @@ void dci_encode(pdcch_t *q, char *data, char *e, int nof_bits, int E, unsigned s
rm_conv_tx(tmp, 3 * (nof_bits + 16), e, E); rm_conv_tx(tmp, 3 * (nof_bits + 16), e, E);
} }
/** Converts the MIB message to symbols mapped to SLOT #1 ready for transmission /** Converts the set of DCI messages to symbols mapped to the slot ready for transmission
*/ */
int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot1_symbols[MAX_PORTS_CTRL], int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot_symbols[MAX_PORTS_CTRL],
int nsubframe) { int nsubframe) {
int i; int i;
/* Set pointers for layermapping & precoding */ /* Set pointers for layermapping & precoding */
@ -571,18 +570,21 @@ int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot1_symbols[MAX_PORTS_CTRL],
/* Encode DCIs */ /* Encode DCIs */
for (i = 0; i < dci->nof_dcis; i++) { for (i = 0; i < dci->nof_dcis; i++) {
/* do some sanity checks */ /* do some sanity checks */
if (dci->msg[i].location.ncce + PDCCH_FORMAT_NOF_CCE(dci->msg[i].location.L) > q->nof_cce if (dci->msg[i].location.ncce + PDCCH_FORMAT_NOF_CCE(dci->msg[i].location.L)
|| dci->msg[i].location.L > 3 > q->nof_cce || dci->msg[i].location.L > 3
|| dci->msg[i].location.nof_bits > DCI_MAX_BITS) { || dci->msg[i].location.nof_bits > DCI_MAX_BITS) {
fprintf(stderr, "Illegal DCI message %d\n", i); fprintf(stderr, "Illegal DCI message %d\n", i);
return -1; return -1;
} }
INFO("Encoding DCI %d: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n", INFO("Encoding DCI %d: Nbits: %d, E: %d, nCCE: %d, L: %d, RNTI: 0x%x\n", i,
i, dci->msg[i].location.nof_bits, PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L), dci->msg[i].location.nof_bits,
dci->msg[i].location.ncce, dci->msg[i].location.L, dci->msg[i].location.rnti); PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.ncce, dci->msg[i].location.L,
dci->msg[i].location.rnti);
dci_encode(q, dci->msg[i].data, &q->pdcch_e[72 * dci->msg[i].location.ncce], dci_encode(q, dci->msg[i].data, &q->pdcch_e[72 * dci->msg[i].location.ncce],
dci->msg[i].location.nof_bits, PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L), dci->msg[i].location.nof_bits,
PDCCH_FORMAT_NOF_BITS(dci->msg[i].location.L),
dci->msg[i].location.rnti); dci->msg[i].location.rnti);
} }
@ -601,7 +603,7 @@ int pdcch_encode(pdcch_t *q, dci_t *dci, cf_t *slot1_symbols[MAX_PORTS_CTRL],
/* mapping to resource elements */ /* mapping to resource elements */
for (i = 0; i < q->nof_ports; i++) { for (i = 0; i < q->nof_ports; i++) {
regs_pdcch_put(q->regs, q->pdcch_symbols[i], slot1_symbols[i]); regs_pdcch_put(q->regs, q->pdcch_symbols[i], slot_symbols[i]);
} }
return 0; return 0;
} }

@ -0,0 +1,698 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <math.h>
#include "prb.h"
#include "lte/phch/pdsch.h"
#include "lte/common/base.h"
#include "lte/utils/bit.h"
#include "lte/utils/debug.h"
#include "lte/utils/vector.h"
const enum modem_std modulations[4] =
{ LTE_BPSK, LTE_QPSK, LTE_QAM16, LTE_QAM64 };
#define MAX_PDSCH_RE(cp) (2 * (CP_NSYMB(cp) - 1) * 12 - 6)
#define HAS_REF(l, cp, nof_ports) ((l == 1 && nof_ports == 4) \
|| l == 0 \
|| l == CP_NSYMB(cp) - 3)
int pdsch_cp(pdsch_t *q, cf_t *input, cf_t *output, ra_prb_t *prb_alloc,
int nsubframe, bool put) {
int s, n, l, lp, lstart, lend, nof_refs;
bool is_pbch, is_sss;
cf_t *in_ptr = input, *out_ptr = output;
int offset;
assert(q->cell_id >= 0);
INFO("%s %d RE from %d PRB\n", put ? "Putting" : "Getting",
prb_alloc->re_sf[nsubframe], prb_alloc->slot[0].nof_prb);
if (q->nof_ports == 1) {
nof_refs = 2;
} else {
nof_refs = 4;
}
for (s = 0; s < 2; s++) {
if (s == 0) {
lstart = prb_alloc->lstart;
} else {
lstart = 0;
}
for (l = lstart; l < CP_NSYMB(q->cp); l++) {
for (n = 0; n < prb_alloc->slot[s].nof_prb; n++) {
lend = CP_NSYMB(q->cp);
is_pbch = is_sss = false;
// Skip PSS/SSS signals
if (s == 0 && (nsubframe == 0 || nsubframe == 5)) {
if (prb_alloc->slot[s].prb_idx[n] >= q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] <= q->nof_prb / 2 + 3) {
lend = CP_NSYMB(q->cp) - 2;
is_sss = true;
}
}
// Skip PBCH
if (s == 1 && nsubframe == 0) {
if (prb_alloc->slot[s].prb_idx[n] >= q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] <= q->nof_prb / 2 + 3) {
lstart = 4;
is_pbch = true;
}
}
lp = l + s * CP_NSYMB(q->cp);
if (put) {
out_ptr = &output[(lp * q->nof_prb + prb_alloc->slot[s].prb_idx[n])
* RE_X_RB];
} else {
in_ptr = &input[(lp * q->nof_prb + prb_alloc->slot[s].prb_idx[n])
* RE_X_RB];
}
if (is_pbch && (q->nof_prb % 2)
&& (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 + 3)) {
if (l < lstart) {
prb_cp_half(&in_ptr, &out_ptr, 1);
}
}
if (l >= lstart && l < lend) {
if (HAS_REF(l, q->cp, q->nof_ports)) {
if (nof_refs == 2 && l != 0) {
offset = q->cell_id % 3 + 3;
} else {
offset = q->cell_id % 3;
}
prb_cp_ref(&in_ptr, &out_ptr, offset, nof_refs, 1, put);
} else {
prb_cp(&in_ptr, &out_ptr, 1);
}
}
if (is_sss && (q->nof_prb % 2)
&& (prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 - 3
&& prb_alloc->slot[s].prb_idx[n] == q->nof_prb / 2 + 3)) {
if (l >= lend) {
prb_cp_half(&in_ptr, &out_ptr, 1);
}
}
}
}
}
if (put) {
return (int) (input - in_ptr);
} else {
return (int) (output - out_ptr);
}
}
/**
* Puts PDSCH in slot number 1
*
* Returns the number of symbols written to sf_symbols
*
* 36.211 10.3 section 6.3.5
*/
int pdsch_put(pdsch_t *q, cf_t *pdsch_symbols, cf_t *sf_symbols,
ra_prb_t *prb_alloc, int nsubframe) {
return pdsch_cp(q, pdsch_symbols, sf_symbols, prb_alloc, nsubframe, true);
}
/**
* Extracts PDSCH from slot number 1
*
* Returns the number of symbols written to PDSCH
*
* 36.211 10.3 section 6.3.5
*/
int pdsch_get(pdsch_t *q, cf_t *sf_symbols, cf_t *pdsch_symbols,
ra_prb_t *prb_alloc, int nsubframe) {
return pdsch_cp(q, sf_symbols, pdsch_symbols, prb_alloc, nsubframe, false);
}
/** Initializes the PDCCH transmitter and receiver */
int pdsch_init(pdsch_t *q, unsigned short user_rnti, int nof_prb, int nof_ports,
int cell_id, lte_cp_t cp) {
int ret = -1;
int i;
if (cell_id < 0) {
return -1;
}
if (nof_ports > MAX_PORTS) {
fprintf(stderr, "Invalid number of ports %d\n", nof_ports);
return -1;
}
bzero(q, sizeof(pdsch_t));
q->cell_id = cell_id;
q->cp = cp;
q->nof_ports = nof_ports;
q->nof_prb = nof_prb;
q->rnti = user_rnti;
q->max_symbols = nof_prb * MAX_PDSCH_RE(cp);
INFO("Init PDSCH: %d ports %d PRBs, max_symbols: %d\n", q->nof_ports,
q->nof_prb, q->max_symbols);
for (i = 0; i < 4; i++) {
if (modem_table_std(&q->mod[i], modulations[i], true)) {
goto clean;
}
}
if (crc_init(&q->crc_tb, LTE_CRC24A, 24)) {
goto clean;
}
if (crc_init(&q->crc_cb, LTE_CRC24B, 24)) {
goto clean;
}
demod_soft_init(&q->demod);
demod_soft_alg_set(&q->demod, APPROX);
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
if (sequence_pdsch(&q->seq_pdsch[i], q->rnti, 0, 2 * i, q->cell_id,
q->max_symbols * q->mod[3].nbits_x_symbol)) {
goto clean;
}
}
if (tcod_init(&q->encoder, MAX_LONG_CB)) {
goto clean;
}
if (tdec_init(&q->decoder, MAX_LONG_CB)) {
goto clean;
}
if (rm_turbo_init(&q->rm_turbo, 3 * MAX_LONG_CB)) {
goto clean;
}
q->cb_in_b = malloc(sizeof(char) * MAX_LONG_CB);
if (!q->cb_in_b) {
goto clean;
}
q->cb_out_b = malloc(sizeof(char) * (3 * MAX_LONG_CB + 12));
if (!q->cb_out_b) {
goto clean;
}
q->pdsch_rm_f = malloc(sizeof(float) * (3 * MAX_LONG_CB + 12));
if (!q->pdsch_rm_f) {
goto clean;
}
q->pdsch_e_bits = malloc(
sizeof(char) * q->max_symbols * q->mod[3].nbits_x_symbol);
if (!q->pdsch_e_bits) {
goto clean;
}
q->pdsch_llr = malloc(
sizeof(float) * q->max_symbols * q->mod[3].nbits_x_symbol);
if (!q->pdsch_llr) {
goto clean;
}
q->pdsch_d = malloc(sizeof(cf_t) * q->max_symbols);
if (!q->pdsch_d) {
goto clean;
}
for (i = 0; i < nof_ports; i++) {
q->ce[i] = malloc(sizeof(cf_t) * q->max_symbols);
if (!q->ce[i]) {
goto clean;
}
q->pdsch_x[i] = malloc(sizeof(cf_t) * q->max_symbols);
if (!q->pdsch_x[i]) {
goto clean;
}
q->pdsch_symbols[i] = malloc(sizeof(cf_t) * q->max_symbols);
if (!q->pdsch_symbols[i]) {
goto clean;
}
}
ret = 0;
clean: if (ret == -1) {
pdsch_free(q);
}
return ret;
}
void pdsch_free(pdsch_t *q) {
int i;
if (q->cb_in_b) {
free(q->cb_in_b);
}
if (q->cb_out_b) {
free(q->cb_out_b);
}
if (q->pdsch_e_bits) {
free(q->pdsch_e_bits);
}
if (q->pdsch_rm_f) {
free(q->pdsch_rm_f);
}
if (q->pdsch_llr) {
free(q->pdsch_llr);
}
if (q->pdsch_d) {
free(q->pdsch_d);
}
for (i = 0; i < q->nof_ports; i++) {
if (q->ce[i]) {
free(q->ce[i]);
}
if (q->pdsch_x[i]) {
free(q->pdsch_x[i]);
}
if (q->pdsch_symbols[i]) {
free(q->pdsch_symbols[i]);
}
}
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
sequence_free(&q->seq_pdsch[i]);
}
for (i = 0; i < 4; i++) {
modem_table_free(&q->mod[i]);
}
tdec_free(&q->decoder);
tcod_free(&q->encoder);
rm_turbo_free(&q->rm_turbo);
}
struct cb_segm {
int F;
int C;
int K1;
int K2;
int C1;
int C2;
};
/* Calculate Codeblock Segmentation as in Section 5.1.2 of 36.212 */
void codeblock_segmentation(struct cb_segm *s, int tbs) {
int Bp, B, idx1;
B = tbs + 24;
/* Calculate CB sizes */
if (B < 6114) {
s->C = 1;
Bp = B;
} else {
s->C = (int) ceilf((float) B / (6114 - 24));
Bp = B + 24 * s->C;
}
idx1 = lte_find_cb_index(Bp / s->C);
s->K1 = lte_cb_size(idx1);
if (s->C == 1) {
s->K2 = 0;
s->C2 = 0;
s->C1 = 1;
} else {
s->K2 = lte_cb_size(idx1 - 1);
s->C2 = (s->C * s->K1 - Bp) / (s->K1 - s->K2);
s->C1 = s->C - s->C2;
}
s->F = s->C1 * s->K1 + s->C2 * s->K2 - Bp;
INFO(
"CB Segmentation: TBS: %d, C=%d, C+=%d K+=%d, C-=%d, K-=%d, F=%d, Bp=%d\n",
tbs, s->C, s->C1, s->K1, s->C2, s->K2, s->F, Bp);
}
/* Decode a transport block according to 36.212 5.3.2
*
*/
int pdsch_decode_tb(pdsch_t *q, char *data, int tbs, int nb_e, int rv_idx) {
char parity[24];
char *p_parity = parity;
unsigned int par_rx, par_tx;
int i;
int cb_len, rp, wp, rlen, F, n_e;
struct cb_segm cbs;
/* Compute CB segmentation for this TBS */
codeblock_segmentation(&cbs, tbs);
rp = 0;
rp = 0;
wp = 0;
for (i = 0; i < cbs.C; i++) {
/* Get read/write lengths */
if (i < cbs.C - cbs.C2) {
cb_len = cbs.K1;
} else {
cb_len = cbs.K2;
}
if (cbs.C == 1) {
rlen = cb_len;
} else {
rlen = cb_len - 24;
}
if (i == 0) {
F = cbs.F;
} else {
F = 0;
}
if (i < cbs.C - 1) {
n_e = nb_e / cbs.C;
} else {
n_e = nb_e - rp;
}
INFO("CB#%d: cb_len: %d, rlen: %d, wp: %d, rp: %d, F: %d, E: %d\n", i,
cb_len, rlen - F, wp, rp, F, n_e);
/* Rate Unmatching */
rm_turbo_rx(&q->rm_turbo, &q->pdsch_llr[rp], n_e, q->pdsch_rm_f,
3 * cb_len + 12, rv_idx);
/* Turbo Decoding */
tdec_run_all(&q->decoder, q->pdsch_rm_f, q->cb_in_b, TDEC_ITERATIONS,
cb_len);
if (cbs.C > 1) {
/* Check Codeblock CRC */
//crc_attach(&q->crc_cb, q->pdsch_b[wp], cb_len);
}
if (VERBOSE_ISDEBUG()) {
DEBUG("CB#%d Len=%d: ", i, cb_len);
vec_fprint_b(stdout, q->cb_in_b, cb_len);
}
/* Copy data to another buffer, removing the Codeblock CRC */
if (i < cbs.C - 1) {
memcpy(&data[wp], &q->cb_in_b[F], (rlen - F) * sizeof(char));
} else {
INFO("Last CB, appending parity: %d to %d from %d and 24 from %d\n",
rlen - F - 24, wp, F, rlen - 24);
/* Append Transport Block parity bits to the last CB */
memcpy(&data[wp], &q->cb_in_b[F], (rlen - F - 24) * sizeof(char));
memcpy(parity, &q->cb_in_b[rlen - 24], 24 * sizeof(char));
}
/* Set read/write pointers */
wp += (rlen - F);
rp += n_e;
}
INFO("END CB#%d: wp: %d, rp: %d\n", i, wp, rp);
// Compute transport block CRC
par_rx = crc_checksum(&q->crc_tb, data, tbs);
// check parity bits
par_tx = bit_unpack(&p_parity, 24);
if (VERBOSE_ISDEBUG()) {
DEBUG("DATA: ", 0);
vec_fprint_b(stdout, data, tbs);
DEBUG("PARITY: ", 0);
vec_fprint_b(stdout, parity, 24);
}
if (!par_rx) {
printf("\n\tCAUTION!! Received all-zero transport block\n\n");
}
return (par_rx != par_tx);
}
/** Decodes the PDSCH from the received symbols
*/
int pdsch_decode(pdsch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], char *data,
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc) {
/* Set pointers for layermapping & precoding */
int i;
cf_t *x[MAX_LAYERS];
int nof_symbols, nof_bits, nof_bits_e;
nof_bits = mcs.tbs;
nof_symbols = prb_alloc->re_sf[nsubframe];
nof_bits_e = nof_symbols * q->mod[mcs.mod - 1].nbits_x_symbol;
if (nof_bits > nof_bits_e) {
fprintf(stderr, "Invalid code rate %.2f\n", (float) nof_bits / nof_bits_e);
return -1;
}
if (nof_symbols > q->max_symbols) {
fprintf(stderr,
"Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
nof_symbols, q->max_symbols, q->nof_prb);
return -1;
}
INFO(
"Decoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
nsubframe, mcs.mod, nof_bits, nof_symbols, nof_bits_e);
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid subframe %d\n", nsubframe);
return -1;
}
/* number of layers equals number of ports */
for (i = 0; i < q->nof_ports; i++) {
x[i] = q->pdsch_x[i];
}
memset(&x[q->nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->nof_ports));
/* extract symbols */
pdsch_get(q, sf_symbols, q->pdsch_symbols[0], prb_alloc, nsubframe);
/* extract channel estimates */
for (i = 0; i < q->nof_ports; i++) {
pdsch_get(q, ce[i], q->ce[i], prb_alloc, nsubframe);
}
/* TODO: only diversity is supported */
if (q->nof_ports == 1) {
/* no need for layer demapping */
predecoding_single_zf(q->pdsch_symbols[0], q->ce[0], q->pdsch_d,
nof_symbols);
} else {
predecoding_diversity_zf(q->pdsch_symbols[0], q->ce, x, q->nof_ports,
nof_symbols);
layerdemap_diversity(x, q->pdsch_d, q->nof_ports,
nof_symbols / q->nof_ports);
}
/* demodulate symbols */
demod_soft_sigma_set(&q->demod, 2.0 / q->mod[mcs.mod - 1].nbits_x_symbol);
demod_soft_table_set(&q->demod, &q->mod[mcs.mod - 1]);
demod_soft_demodulate(&q->demod, q->pdsch_d, q->pdsch_llr, nof_symbols);
/* descramble */
scrambling_f_offset(&q->seq_pdsch[nsubframe], q->pdsch_llr, 0, nof_bits_e);
return pdsch_decode_tb(q, data, nof_bits, nof_bits_e, 0);
}
/* Encode a transport block according to 36.212 5.3.2
*
*/
void pdsch_encode_tb(pdsch_t *q, char *data, int tbs, int nb_e, int rv_idx) {
char parity[24];
char *p_parity = parity;
unsigned int par;
int i;
int cb_len, rp, wp, rlen, F, n_e;
struct cb_segm cbs;
/* Compute CB segmentation */
codeblock_segmentation(&cbs, tbs);
/* Compute transport block CRC */
par = crc_checksum(&q->crc_tb, data, tbs);
/* parity bits will be appended later */
bit_pack(par, &p_parity, 24);
if (VERBOSE_ISDEBUG()) {
DEBUG("DATA: ", 0);
vec_fprint_b(stdout, data, tbs);
DEBUG("PARITY: ", 0);
vec_fprint_b(stdout, parity, 24);
}
/* Add filler bits to the new data buffer */
for (i = 0; i < cbs.F; i++) {
q->cb_in_b[i] = LTE_NULL_BIT;
}
wp = 0;
rp = 0;
for (i = 0; i < cbs.C; i++) {
/* Get read lengths */
if (i < cbs.C - cbs.C2) {
cb_len = cbs.K1;
} else {
cb_len = cbs.K2;
}
if (cbs.C > 1) {
rlen = cb_len - 24;
} else {
rlen = cb_len;
}
if (i == 0) {
F = cbs.F;
} else {
F = 0;
}
if (i < cbs.C - 1) {
n_e = nb_e / cbs.C;
} else {
n_e = nb_e - wp;
}
INFO("CB#%d: cb_len: %d, rlen: %d, wp: %d, rp: %d, F: %d, E: %d\n", i,
cb_len, rlen - F, wp, rp, F, n_e);
/* Copy data to another buffer, making space for the Codeblock CRC */
if (i < cbs.C - 1) {
memcpy(&q->cb_in_b[F], &data[rp], (rlen - F) * sizeof(char));
} else {
INFO("Last CB, appending parity: %d from %d and 24 to %d\n",
rlen - F - 24, rp, rlen - 24);
/* Append Transport Block parity bits to the last CB */
memcpy(&q->cb_in_b[F], &data[rp], (rlen - F - 24) * sizeof(char));
memcpy(&q->cb_in_b[rlen - 24], parity, 24 * sizeof(char));
}
if (cbs.C > 1) {
/* Attach Codeblock CRC */
crc_attach(&q->crc_cb, q->cb_in_b, rlen);
}
if (VERBOSE_ISDEBUG()) {
DEBUG("CB#%d Len=%d: ", i, cb_len);
vec_fprint_b(stdout, q->cb_in_b, cb_len);
}
/* Turbo Encoding */
tcod_encode(&q->encoder, q->cb_in_b, q->cb_out_b, cb_len);
/* Rate matching */
rm_turbo_tx(&q->rm_turbo, q->cb_out_b, 3 * cb_len + 12,
&q->pdsch_e_bits[wp], n_e, rv_idx);
/* Set read/write pointers */
rp += (rlen - F);
wp += n_e;
}
INFO("END CB#%d: wp: %d, rp: %d\n", i, wp, rp);
}
/** Converts the PDSCH data bits to symbols mapped to the slot ready for transmission
*/
int pdsch_encode(pdsch_t *q, char *data, cf_t *sf_symbols[MAX_PORTS],
int nsubframe, ra_mcs_t mcs, ra_prb_t *prb_alloc) {
int i;
int nof_symbols, nof_bits, nof_bits_e;
/* Set pointers for layermapping & precoding */
cf_t *x[MAX_LAYERS];
if (nsubframe < 0 || nsubframe > NSUBFRAMES_X_FRAME) {
fprintf(stderr, "Invalid subframe %d\n", nsubframe);
return -1;
}
nof_bits = mcs.tbs;
nof_symbols = prb_alloc->re_sf[nsubframe];
nof_bits_e = nof_symbols * q->mod[mcs.mod - 1].nbits_x_symbol;
if (nof_bits > nof_bits_e) {
fprintf(stderr, "Invalid code rate %.2f\n", (float) nof_bits / nof_bits_e);
return -1;
}
if (nof_symbols > q->max_symbols) {
fprintf(stderr,
"Error too many RE per subframe (%d). PDSCH configured for %d RE (%d PRB)\n",
nof_symbols, q->max_symbols, q->nof_prb);
return -1;
}
INFO(
"Encoding PDSCH SF: %d, Mod %d, NofBits: %d, NofSymbols: %d, NofBitsE: %d\n",
nsubframe, mcs.mod, nof_bits, nof_symbols, nof_bits_e);
/* number of layers equals number of ports */
for (i = 0; i < q->nof_ports; i++) {
x[i] = q->pdsch_x[i];
}
memset(&x[q->nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->nof_ports));
pdsch_encode_tb(q, data, nof_bits, nof_bits_e, 0);
scrambling_b_offset(&q->seq_pdsch[nsubframe], q->pdsch_e_bits, 0, nof_bits_e);
mod_modulate(&q->mod[mcs.mod - 1], q->pdsch_e_bits, q->pdsch_d, nof_bits_e);
/* TODO: only diversity supported */
if (q->nof_ports > 1) {
layermap_diversity(q->pdsch_d, x, q->nof_ports, nof_symbols);
precoding_diversity(x, q->pdsch_symbols, q->nof_ports,
nof_symbols / q->nof_ports);
} else {
memcpy(q->pdsch_symbols[0], q->pdsch_d, nof_symbols * sizeof(cf_t));
}
/* mapping to resource elements */
for (i = 0; i < q->nof_ports; i++) {
pdsch_put(q, q->pdsch_symbols[i], sf_symbols[i], prb_alloc, nsubframe);
}
return 0;
}

@ -143,7 +143,6 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
int i, j; int i, j;
cf_t *x[MAX_LAYERS]; cf_t *x[MAX_LAYERS];
cf_t *ce_precoding[MAX_PORTS]; cf_t *ce_precoding[MAX_PORTS];
cf_t *symbols_precoding[MAX_PORTS];
DEBUG("Decoding PHICH Ngroup: %d, Nseq: %d\n", ngroup, nseq); DEBUG("Decoding PHICH Ngroup: %d, Nseq: %d\n", ngroup, nseq);
@ -174,21 +173,18 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
} }
for (i = 0; i < MAX_PORTS; i++) { for (i = 0; i < MAX_PORTS; i++) {
ce_precoding[i] = q->ce[i]; ce_precoding[i] = q->ce[i];
symbols_precoding[i] = q->phich_symbols[i];
} }
/* extract symbols */ /* extract symbols */
if (PHICH_MAX_NSYMB if (PHICH_MAX_NSYMB
!= regs_phich_get(q->regs, slot_symbols, q->phich_symbols[0], != regs_phich_get(q->regs, slot_symbols, q->phich_symbols[0], ngroup)) {
ngroup)) {
fprintf(stderr, "There was an error getting the phich symbols\n"); fprintf(stderr, "There was an error getting the phich symbols\n");
return -1; return -1;
} }
/* extract channel estimates */ /* extract channel estimates */
for (i = 0; i < q->nof_tx_ports; i++) { for (i = 0; i < q->nof_tx_ports; i++) {
if (PHICH_MAX_NSYMB if (PHICH_MAX_NSYMB != regs_phich_get(q->regs, ce[i], q->ce[i], ngroup)) {
!= regs_phich_get(q->regs, ce[i], q->ce[i], ngroup)) {
fprintf(stderr, "There was an error getting the phich symbols\n"); fprintf(stderr, "There was an error getting the phich symbols\n");
return -1; return -1;
} }
@ -200,14 +196,15 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
predecoding_single_zf(q->phich_symbols[0], q->ce[0], q->phich_d0, predecoding_single_zf(q->phich_symbols[0], q->ce[0], q->phich_d0,
PHICH_MAX_NSYMB); PHICH_MAX_NSYMB);
} else { } else {
predecoding_diversity_zf(symbols_precoding, ce_precoding, x, predecoding_diversity_zf(q->phich_symbols[0], ce_precoding, x,
q->nof_tx_ports, PHICH_MAX_NSYMB); q->nof_tx_ports, PHICH_MAX_NSYMB);
layerdemap_diversity(x, q->phich_d0, q->nof_tx_ports, layerdemap_diversity(x, q->phich_d0, q->nof_tx_ports,
PHICH_MAX_NSYMB / q->nof_tx_ports); PHICH_MAX_NSYMB / q->nof_tx_ports);
} }
DEBUG("Recv!!: \n", 0); DEBUG("Recv!!: \n", 0);
DEBUG("d0: ", 0); DEBUG("d0: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB);
if (CP_ISEXT(q->cp)) { if (CP_ISEXT(q->cp)) {
if (ngroup % 2) { if (ngroup % 2) {
@ -226,7 +223,8 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
} }
DEBUG("d: ", 0); DEBUG("d: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
scrambling_c(&q->seq_phich[nsubframe], q->phich_d); scrambling_c(&q->seq_phich[nsubframe], q->phich_d);
@ -235,22 +233,23 @@ int phich_decode(phich_t *q, cf_t *slot_symbols, cf_t *ce[MAX_PORTS_CTRL],
for (i = 0; i < PHICH_NBITS; i++) { for (i = 0; i < PHICH_NBITS; i++) {
q->phich_z[i] = 0; q->phich_z[i] = 0;
for (j = 0; j < PHICH_EXT_NSF; j++) { for (j = 0; j < PHICH_EXT_NSF; j++) {
q->phich_z[i] += conjf(w_ext[nseq][j]) * q->phich_z[i] += conjf(w_ext[nseq][j])
q->phich_d[i*PHICH_EXT_NSF+j]/PHICH_EXT_NSF; * q->phich_d[i * PHICH_EXT_NSF + j] / PHICH_EXT_NSF;
} }
} }
} else { } else {
for (i = 0; i < PHICH_NBITS; i++) { for (i = 0; i < PHICH_NBITS; i++) {
q->phich_z[i] = 0; q->phich_z[i] = 0;
for (j = 0; j < PHICH_NORM_NSF; j++) { for (j = 0; j < PHICH_NORM_NSF; j++) {
q->phich_z[i] += conjf(w_normal[nseq][j]) * q->phich_z[i] += conjf(w_normal[nseq][j])
q->phich_d[i*PHICH_NORM_NSF+j]/PHICH_NORM_NSF; * q->phich_d[i * PHICH_NORM_NSF + j] / PHICH_NORM_NSF;
} }
} }
} }
DEBUG("z: ", 0); DEBUG("z: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_z, PHICH_NBITS); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
demod_hard_demodulate(&q->demod, q->phich_z, q->data, PHICH_NBITS); demod_hard_demodulate(&q->demod, q->phich_z, q->data, PHICH_NBITS);
@ -307,7 +306,8 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
mod_modulate(&q->mod, q->data, q->phich_z, PHICH_NBITS); mod_modulate(&q->mod, q->data, q->phich_z, PHICH_NBITS);
DEBUG("data: ", 0); DEBUG("data: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_z, PHICH_NBITS); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_z, PHICH_NBITS);
/* Spread with w */ /* Spread with w */
if (CP_ISEXT(q->cp)) { if (CP_ISEXT(q->cp)) {
@ -323,7 +323,8 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
} }
DEBUG("d: ", 0); DEBUG("d: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d, PHICH_EXT_MSYMB);
scrambling_c(&q->seq_phich[nsubframe], q->phich_d); scrambling_c(&q->seq_phich[nsubframe], q->phich_d);
@ -349,8 +350,8 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
} }
DEBUG("d0: ", 0); DEBUG("d0: ", 0);
if (VERBOSE_ISDEBUG()) vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB); if (VERBOSE_ISDEBUG())
vec_fprint_c(stdout, q->phich_d0, PHICH_MAX_NSYMB);
/* layer mapping & precoding */ /* layer mapping & precoding */
if (q->nof_tx_ports > 1) { if (q->nof_tx_ports > 1) {
@ -364,8 +365,8 @@ int phich_encode(phich_t *q, char ack, int ngroup, int nseq, int nsubframe,
/* mapping to resource elements */ /* mapping to resource elements */
for (i = 0; i < q->nof_tx_ports; i++) { for (i = 0; i < q->nof_tx_ports; i++) {
if (regs_phich_add(q->regs, q->phich_symbols[i], ngroup, if (regs_phich_add(q->regs, q->phich_symbols[i], ngroup, slot_symbols[i])
slot_symbols[i]) < 0) { < 0) {
fprintf(stderr, "Error putting PCHICH resource elements\n"); fprintf(stderr, "Error putting PCHICH resource elements\n");
return -1; return -1;
} }

@ -68,6 +68,13 @@ void prb_cp(cf_t **input, cf_t **output, int nof_prb) {
*output += nof_prb * RE_X_RB; *output += nof_prb * RE_X_RB;
} }
void prb_cp_half(cf_t **input, cf_t **output, int nof_prb) {
memcpy(*output, *input, sizeof(cf_t) * RE_X_RB * nof_prb / 2);
*input += nof_prb * RE_X_RB / 2;
*output += nof_prb * RE_X_RB / 2;
}
void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs, void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb) { int nof_prb) {
prb_cp_ref(input, output, offset, nof_refs, nof_prb, false); prb_cp_ref(input, output, offset, nof_refs, nof_prb, false);

@ -31,6 +31,7 @@ typedef _Complex float cf_t;
void prb_cp_ref(cf_t **input, cf_t **output, int offset, int nof_refs, void prb_cp_ref(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb, bool advance_input); int nof_prb, bool advance_input);
void prb_cp(cf_t **input, cf_t **output, int nof_prb); void prb_cp(cf_t **input, cf_t **output, int nof_prb);
void prb_cp_half(cf_t **input, cf_t **output, int nof_prb);
void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs, void prb_put_ref_(cf_t **input, cf_t **output, int offset, int nof_refs,
int nof_prb); int nof_prb);
void phch_get_prb_ref(cf_t **input, cf_t **output, int offset, int nof_refs, void phch_get_prb_ref(cf_t **input, cf_t **output, int offset, int nof_refs,

@ -26,6 +26,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <strings.h> #include <strings.h>
#include <math.h> #include <math.h>
#include "lte/common/base.h" #include "lte/common/base.h"
@ -39,6 +40,91 @@
#define min(a,b) (a<b?a:b) #define min(a,b) (a<b?a:b)
/* Returns the number of RE in a PRB in a slot and subframe */
int ra_re_x_prb(int nsubframe, int nslot, int prb_idx, int nof_prb,
int nof_ports, int nof_ctrl_symbols, lte_cp_t cp) {
int re;
bool skip_refs = false;
if (nslot == 0) {
re = (CP_NSYMB(cp) - nof_ctrl_symbols) * RE_X_RB;
} else {
re = CP_NSYMB(cp) * RE_X_RB;
}
/* if it's the prb in the middle, there are less RE due to PBCH and PSS/SSS */
if ((nsubframe == 0 || nsubframe == 5)
&& (prb_idx >= nof_prb / 2 - 3 && prb_idx <= nof_prb / 2 + 3)) {
if (nsubframe == 0) {
if (nslot == 0) {
re = (CP_NSYMB(cp) - nof_ctrl_symbols - 2) * RE_X_RB;
} else {
if (CP_ISEXT(cp)) {
re = (CP_NSYMB(cp) - 4) * RE_X_RB;
skip_refs = true;
} else {
re = (CP_NSYMB(cp) - 4) * RE_X_RB + 2 * nof_ports;
}
}
} else if (nsubframe == 5) {
if (nslot == 0) {
re = (CP_NSYMB(cp) - nof_ctrl_symbols - 2) * RE_X_RB;
}
}
if ((nof_prb % 2)
&& (prb_idx == nof_prb / 2 - 3 || prb_idx == nof_prb / 2 + 3)) {
if (nslot == 0) {
re += 2 * RE_X_RB / 2;
} else if (nsubframe == 0) {
re += 4 * RE_X_RB / 2 - nof_ports;
if (CP_ISEXT(cp)) {
re -= nof_ports > 2 ? 2 : nof_ports;
}
}
}
}
// remove references
if (!skip_refs) {
switch (nof_ports) {
case 1:
case 2:
re -= 2 * (nslot + 1) * nof_ports;
break;
case 4:
if (nslot == 1) {
re -= 12;
} else {
re -= 4;
if (nof_ctrl_symbols == 1) {
re -= 4;
}
}
break;
}
}
return re;
}
/* Computes the number of RE for each PRB in the prb_dist structure */
void ra_prb_get_re(ra_prb_t *prb_dist, int nof_prb, int nof_ports,
int nof_ctrl_symbols, lte_cp_t cp) {
int i, j, s;
/* Set start symbol according to Section 7.1.6.4 in 36.213 */
prb_dist->lstart = nof_ctrl_symbols;
// Compute number of RE per subframe
for (i = 0; i < NSUBFRAMES_X_FRAME; i++) {
for (s = 0; s < 2; s++) {
for (j = 0; j < prb_dist->slot[s].nof_prb; j++) {
prb_dist->re_sf[i] += ra_re_x_prb(i, s, prb_dist->slot[s].prb_idx[j],
nof_prb, nof_ports, nof_ctrl_symbols, cp);
}
}
}
}
void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb) { void ra_prb_fprint(FILE *f, ra_prb_slot_t *prb) {
int i, j, nrows; int i, j, nrows;
@ -70,29 +156,25 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
int i, j; int i, j;
uint32_t bitmask; uint32_t bitmask;
int P = ra_type0_P(nof_prb); int P = ra_type0_P(nof_prb);
ra_prb_slot_t *prb; int n_rb_rbg_subset, n_rb_type1;
bzero(prb_dist, sizeof(ra_prb_t)); bzero(prb_dist, sizeof(ra_prb_t));
switch (ra->alloc_type) { switch (ra->alloc_type) {
case alloc_type0: case alloc_type0:
prb = &prb_dist->slot1;
prb_dist->is_dist = false;
bitmask = ra->type0_alloc.rbg_bitmask; bitmask = ra->type0_alloc.rbg_bitmask;
int nb = (int) ceilf((float) nof_prb / P); int nb = (int) ceilf((float) nof_prb / P);
for (i = 0; i < nb; i++) { for (i = 0; i < nb; i++) {
if (bitmask & (1 << (nb - i - 1))) { if (bitmask & (1 << (nb - i - 1))) {
for (j = 0; j < P; j++) { for (j = 0; j < P; j++) {
prb->prb_idx[prb->nof_prb] = i*P+j; prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = i * P + j;
prb->nof_prb++; prb_dist->slot[0].nof_prb++;
} }
} }
} }
memcpy(&prb_dist->slot[1], &prb_dist->slot[0], sizeof(ra_prb_slot_t));
break; break;
case alloc_type1: case alloc_type1:
prb = &prb_dist->slot1; n_rb_type1 = ra_type1_N_rb(nof_prb);
prb_dist->is_dist = false;
int n_rb_type1 = ra_type1_N_rb(nof_prb);
int n_rb_rbg_subset;
if (ra->type1_alloc.rbg_subset < (nof_prb / P) % P) { if (ra->type1_alloc.rbg_subset < (nof_prb / P) % P) {
n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + P; n_rb_rbg_subset = ((nof_prb - 1) / (P * P)) * P + P;
} else if (ra->type1_alloc.rbg_subset == ((nof_prb / P) % P)) { } else if (ra->type1_alloc.rbg_subset == ((nof_prb / P) % P)) {
@ -104,26 +186,26 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
bitmask = ra->type1_alloc.vrb_bitmask; bitmask = ra->type1_alloc.vrb_bitmask;
for (i = 0; i < n_rb_type1; i++) { for (i = 0; i < n_rb_type1; i++) {
if (bitmask & (1 << (n_rb_type1 - i - 1))) { if (bitmask & (1 << (n_rb_type1 - i - 1))) {
prb->prb_idx[prb->nof_prb] = ((i+shift)/P)*P*P+ prb_dist->slot[0].prb_idx[prb_dist->slot[0].nof_prb] = ((i + shift) / P)
ra->type1_alloc.rbg_subset*P+(i+shift)%P; * P * P + ra->type1_alloc.rbg_subset * P + (i + shift) % P;
prb->nof_prb++; prb_dist->slot[0].nof_prb++;
} }
} }
memcpy(&prb_dist->slot[1], &prb_dist->slot[0], sizeof(ra_prb_slot_t));
break; break;
case alloc_type2: case alloc_type2:
if (ra->type2_alloc.mode == t2_loc) { if (ra->type2_alloc.mode == t2_loc) {
prb = &prb_dist->slot1;
prb_dist->is_dist = false;
for (i = 0; i < ra->type2_alloc.L_crb; i++) { for (i = 0; i < ra->type2_alloc.L_crb; i++) {
prb->prb_idx[i] = i+ra->type2_alloc.RB_start; prb_dist->slot[0].prb_idx[i] = i + ra->type2_alloc.RB_start;
prb->nof_prb++; prb_dist->slot[0].nof_prb++;
} }
memcpy(&prb_dist->slot[1], &prb_dist->slot[0], sizeof(ra_prb_slot_t));
} else { } else {
/* Mapping of Virtual to Physical RB for distributed type is defined in /* Mapping of Virtual to Physical RB for distributed type is defined in
* 6.2.3.2 of 36.211 * 6.2.3.2 of 36.211
*/ */
prb_dist->is_dist = true; int N_gap, N_tilde_vrb, n_tilde_vrb, n_tilde_prb, n_tilde2_prb, N_null,
int N_gap, N_tilde_vrb, n_tilde_vrb, n_tilde_prb, n_tilde2_prb, N_null, N_row, n_vrb; N_row, n_vrb;
int n_tilde_prb_odd, n_tilde_prb_even; int n_tilde_prb_odd, n_tilde_prb_even;
if (ra->type2_alloc.n_gap == t2_ng1) { if (ra->type2_alloc.n_gap == t2_ng1) {
N_tilde_vrb = nof_prb; N_tilde_vrb = nof_prb;
@ -137,38 +219,47 @@ int ra_prb_get_dl(ra_prb_t *prb_dist, ra_pdsch_t *ra, int nof_prb) {
for (i = 0; i < ra->type2_alloc.L_crb; i++) { for (i = 0; i < ra->type2_alloc.L_crb; i++) {
n_vrb = i + ra->type2_alloc.RB_start; n_vrb = i + ra->type2_alloc.RB_start;
n_tilde_vrb = n_vrb % N_tilde_vrb; n_tilde_vrb = n_vrb % N_tilde_vrb;
n_tilde_prb = 2*N_row*(n_tilde_vrb % 2)+n_tilde_vrb/2+N_tilde_vrb*(n_vrb/N_tilde_vrb); n_tilde_prb = 2 * N_row * (n_tilde_vrb % 2) + n_tilde_vrb / 2
n_tilde2_prb = N_row*(n_tilde_vrb % 4)+n_tilde_vrb/4+N_tilde_vrb*(n_vrb/N_tilde_vrb); + N_tilde_vrb * (n_vrb / N_tilde_vrb);
n_tilde2_prb = N_row * (n_tilde_vrb % 4) + n_tilde_vrb / 4
+ N_tilde_vrb * (n_vrb / N_tilde_vrb);
if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null) && (n_tilde_vrb%2) == 1) { if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 2) == 1) {
n_tilde_prb_odd = n_tilde_prb - N_row; n_tilde_prb_odd = n_tilde_prb - N_row;
} else if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null) && (n_tilde_vrb%2) == 0) { } else if (N_null != 0 && n_tilde_vrb >= (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 2) == 0) {
n_tilde_prb_odd = n_tilde_prb - N_row + N_null / 2; n_tilde_prb_odd = n_tilde_prb - N_row + N_null / 2;
} else if (N_null != 0 && n_tilde_vrb < (N_tilde_vrb - N_null) && (n_tilde_vrb%4) >= 2) { } else if (N_null != 0 && n_tilde_vrb < (N_tilde_vrb - N_null)
&& (n_tilde_vrb % 4) >= 2) {
n_tilde_prb_odd = n_tilde2_prb - N_null / 2; n_tilde_prb_odd = n_tilde2_prb - N_null / 2;
} else { } else {
n_tilde_prb_odd = n_tilde2_prb; n_tilde_prb_odd = n_tilde2_prb;
} }
n_tilde_prb_even = (n_tilde_prb_odd+N_tilde_vrb/2)%N_tilde_vrb+N_tilde_vrb*(n_vrb/N_tilde_vrb); n_tilde_prb_even = (n_tilde_prb_odd + N_tilde_vrb / 2) % N_tilde_vrb
+ N_tilde_vrb * (n_vrb / N_tilde_vrb);
if (n_tilde_prb_odd < N_tilde_vrb / 2) { if (n_tilde_prb_odd < N_tilde_vrb / 2) {
prb_dist->slot1.prb_idx[i] = n_tilde_prb_odd; prb_dist->slot[0].prb_idx[i] = n_tilde_prb_odd;
} else { } else {
prb_dist->slot1.prb_idx[i] = n_tilde_prb_odd+N_gap-N_tilde_vrb/2; prb_dist->slot[0].prb_idx[i] = n_tilde_prb_odd + N_gap
- N_tilde_vrb / 2;
} }
prb_dist->slot1.nof_prb++; prb_dist->slot[0].nof_prb++;
if (n_tilde_prb_even < N_tilde_vrb / 2) { if (n_tilde_prb_even < N_tilde_vrb / 2) {
prb_dist->slot2.prb_idx[i] = n_tilde_prb_even; prb_dist->slot[1].prb_idx[i] = n_tilde_prb_even;
} else { } else {
prb_dist->slot2.prb_idx[i] = n_tilde_prb_even+N_gap-N_tilde_vrb/2; prb_dist->slot[1].prb_idx[i] = n_tilde_prb_even + N_gap
- N_tilde_vrb / 2;
} }
prb_dist->slot2.nof_prb++; prb_dist->slot[1].nof_prb++;
} }
} }
break; break;
default: default:
return -1; return -1;
} }
return 0; return 0;
} }
@ -195,7 +286,8 @@ int ra_nprb_dl(ra_pdsch_t *ra, int nof_prb) {
// last RBG may have smaller size. Add if set // last RBG may have smaller size. Add if set
int P_last = (nof_prb % P); int P_last = (nof_prb % P);
if (!P_last) P_last = P; if (!P_last)
P_last = P;
nprb += P_last * (ra->type0_alloc.rbg_bitmask & 1); nprb += P_last * (ra->type0_alloc.rbg_bitmask & 1);
break; break;
case alloc_type1: case alloc_type1:
@ -246,7 +338,8 @@ uint32_t ra_type2_to_riv(uint16_t L_crb, uint16_t RB_start, int nof_prb) {
} }
/* Convert Type2 scheduling RIV value to L_crb and RB_start values */ /* Convert Type2 scheduling RIV value to L_crb and RB_start values */
void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start, int nof_prb, int nof_vrb) { void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start,
int nof_prb, int nof_vrb) {
*L_crb = (int) (riv / nof_prb) + 1; *L_crb = (int) (riv / nof_prb) + 1;
*RB_start = riv % nof_prb; *RB_start = riv % nof_prb;
if (*L_crb > nof_vrb - *RB_start) { if (*L_crb > nof_vrb - *RB_start) {
@ -255,7 +348,6 @@ void ra_type2_from_riv(uint32_t riv, uint16_t *L_crb, uint16_t *RB_start, int no
} }
} }
/* Table 6.2.3.2-1 in 36.211 */ /* Table 6.2.3.2-1 in 36.211 */
int ra_type2_ngap(int nof_prb, bool ngap_is_1) { int ra_type2_ngap(int nof_prb, bool ngap_is_1) {
if (nof_prb <= 10) { if (nof_prb <= 10) {
@ -279,7 +371,6 @@ int ra_type2_ngap(int nof_prb, bool ngap_is_1) {
} }
} }
/* Table 7.1.6.3-1 in 36.213 */ /* Table 7.1.6.3-1 in 36.213 */
int ra_type2_n_rb_step(int nof_prb) { int ra_type2_n_rb_step(int nof_prb) {
if (nof_prb < 50) { if (nof_prb < 50) {
@ -289,7 +380,6 @@ int ra_type2_n_rb_step(int nof_prb) {
} }
} }
/* as defined in 6.2.3.2 of 36.211 */ /* as defined in 6.2.3.2 of 36.211 */
int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1) { int ra_type2_n_vrb_dl(int nof_prb, bool ngap_is_1) {
int ngap = ra_type2_ngap(nof_prb, ngap_is_1); int ngap = ra_type2_ngap(nof_prb, ngap_is_1);
@ -342,7 +432,6 @@ int ra_mcs_from_idx_dl(uint8_t idx, ra_mcs_t *mcs) {
return 0; return 0;
} }
/* Converts MCS index to ra_mcs_t structure for Uplink as defined in Table 8.6.1-1 on 36.213 */ /* Converts MCS index to ra_mcs_t structure for Uplink as defined in Table 8.6.1-1 on 36.213 */
int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs) { int ra_mcs_from_idx_ul(uint8_t idx, ra_mcs_t *mcs) {
if (idx < 11) { if (idx < 11) {
@ -380,8 +469,7 @@ int ra_tbs_to_table_idx_format1c(int tbs) {
return -1; return -1;
} }
for (idx = 1; idx < 32; idx++) { for (idx = 1; idx < 32; idx++) {
if (tbs_format1c_table[idx-1] <= tbs && if (tbs_format1c_table[idx - 1] <= tbs && tbs_format1c_table[idx] >= tbs) {
tbs_format1c_table[idx] >= tbs) {
return idx; return idx;
} }
} }
@ -409,8 +497,7 @@ int ra_tbs_to_table_idx(int tbs, int n_prb) {
return -1; return -1;
} }
for (idx = 1; idx < 28; idx++) { for (idx = 1; idx < 28; idx++) {
if (tbs_table[idx-1][n_prb] <= tbs && if (tbs_table[idx - 1][n_prb] <= tbs && tbs_table[idx][n_prb] >= tbs) {
tbs_table[idx][n_prb] >= tbs) {
return idx; return idx;
} }
} }
@ -462,9 +549,9 @@ void ra_pdsch_set_mcs(ra_pdsch_t *ra, ra_mod_t mod, uint8_t tbs_idx) {
ra->mcs.tbs_idx = tbs_idx; ra->mcs.tbs_idx = tbs_idx;
} }
void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) { void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
fprintf(f, " - Resource Allocation Type:\t\t%s\n",ra_type_string(ra->alloc_type)); fprintf(f, " - Resource Allocation Type:\t\t%s\n",
ra_type_string(ra->alloc_type));
switch (ra->alloc_type) { switch (ra->alloc_type) {
case alloc_type0: case alloc_type0:
fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb)); fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb));
@ -474,7 +561,8 @@ void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb)); fprintf(f, " + Resource Block Group Size:\t\t%d\n", ra_type0_P(nof_prb));
fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n", ra->type1_alloc.vrb_bitmask); fprintf(f, " + RBG Bitmap:\t\t\t0x%x\n", ra->type1_alloc.vrb_bitmask);
fprintf(f, " + RBG Subset:\t\t\t%d\n", ra->type1_alloc.rbg_subset); fprintf(f, " + RBG Subset:\t\t\t%d\n", ra->type1_alloc.rbg_subset);
fprintf(f, " + RBG Shift:\t\t\t\t%s\n",ra->type1_alloc.shift?"Yes":"No"); fprintf(f, " + RBG Shift:\t\t\t\t%s\n",
ra->type1_alloc.shift ? "Yes" : "No");
break; break;
case alloc_type2: case alloc_type2:
fprintf(f, " + Type:\t\t\t\t%s\n", fprintf(f, " + Type:\t\t\t\t%s\n",
@ -496,14 +584,9 @@ void ra_pdsch_fprint(FILE *f, ra_pdsch_t *ra, int nof_prb) {
ra_prb_t alloc; ra_prb_t alloc;
ra_prb_get_dl(&alloc, ra, nof_prb); ra_prb_get_dl(&alloc, ra, nof_prb);
if (alloc.is_dist) { for (int s = 0; s < 2; s++) {
fprintf(f, " - PRB Bitmap Assignment 1st slot:\n"); fprintf(f, " - PRB Bitmap Assignment %dst slot:\n", s);
ra_prb_fprint(f, &alloc.slot1); ra_prb_fprint(f, &alloc.slot[s]);
fprintf(f, " - PRB Bitmap Assignment 2nd slot:\n");
ra_prb_fprint(f, &alloc.slot2);
} else {
fprintf(f, " - PRB Bitmap Assignment:\n");
ra_prb_fprint(f, &alloc.slot1);
} }
fprintf(f, " - Number of PRBs:\t\t\t%d\n", ra_nprb_dl(ra, nof_prb)); fprintf(f, " - Number of PRBs:\t\t\t%d\n", ra_nprb_dl(ra, nof_prb));

@ -62,3 +62,11 @@ int sequence_pdcch(sequence_t *seq, int nslot, int cell_id, int len) {
bzero(seq, sizeof(sequence_t)); bzero(seq, sizeof(sequence_t));
return sequence_LTEPRS(seq, len, (nslot/2) * 512 + cell_id); return sequence_LTEPRS(seq, len, (nslot/2) * 512 + cell_id);
} }
/**
* 36.211 6.3.1
*/
int sequence_pdsch(sequence_t *seq, unsigned short rnti, int q, int nslot, int cell_id, int len) {
bzero(seq, sizeof(sequence_t));
return sequence_LTEPRS(seq, len, (rnti<<14) + (q<<13) + ((nslot/2)<<9) + cell_id);
}

@ -80,6 +80,19 @@ ADD_TEST(pdcch_test pdcch_test)
ADD_EXECUTABLE(dci_unpacking dci_unpacking.c) ADD_EXECUTABLE(dci_unpacking dci_unpacking.c)
TARGET_LINK_LIBRARIES(dci_unpacking lte) TARGET_LINK_LIBRARIES(dci_unpacking lte)
########################################################################
# PDSCH TEST
########################################################################
ADD_EXECUTABLE(pdsch_test pdsch_test.c)
TARGET_LINK_LIBRARIES(pdsch_test lte)
ADD_EXECUTABLE(pdsch_re_test pdsch_re_test.c)
TARGET_LINK_LIBRARIES(pdsch_re_test lte)
ADD_TEST(pdsch_re_test pdsch_re_test)
ADD_TEST(pdsch_test pdsch_test -l 50000 -m 4 -n 110)
######################################################################## ########################################################################
# FILE TEST # FILE TEST
######################################################################## ########################################################################
@ -96,8 +109,14 @@ TARGET_LINK_LIBRARIES(phich_file_test lte)
ADD_EXECUTABLE(pdcch_file_test pdcch_file_test.c) ADD_EXECUTABLE(pdcch_file_test pdcch_file_test.c)
TARGET_LINK_LIBRARIES(pdcch_file_test lte) TARGET_LINK_LIBRARIES(pdcch_file_test lte)
ADD_EXECUTABLE(pdsch_file_test pdsch_file_test.c)
TARGET_LINK_LIBRARIES(pdsch_file_test lte)
ADD_TEST(pbch_file_test pbch_file_test -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.1.92M.dat) ADD_TEST(pbch_file_test pbch_file_test -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.1.92M.dat)
ADD_TEST(pcfich_file_test pcfich_file_test -c 150 -n 50 -p 2 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.10M.dat) ADD_TEST(pcfich_file_test pcfich_file_test -c 150 -n 50 -p 2 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.10M.dat)
ADD_TEST(phich_file_test phich_file_test -c 150 -n 50 -p 2 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.10M.dat) ADD_TEST(phich_file_test phich_file_test -c 150 -n 50 -p 2 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.10M.dat)
ADD_TEST(pdcch_file_test pdcch_file_test -c 1 -f 3 -n 6 -p 1 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.1.92M.amar.dat) ADD_TEST(pdcch_file_test pdcch_file_test -c 1 -f 3 -n 6 -p 1 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.1.92M.amar.dat)
ADD_TEST(pdsch_file_test pdsch_file_test -c 1 -f 3 -n 6 -p 1 -i ${CMAKE_CURRENT_SOURCE_DIR}/signal.1.92M.amar.dat)

@ -40,7 +40,6 @@ void usage(char *prog) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
dci_msg_t msg; dci_msg_t msg;
ra_pdsch_t ra_dl; ra_pdsch_t ra_dl;
ra_pdsch_t ra_ul;
int len, rlen; int len, rlen;
int nof_prb; int nof_prb;
int nwords; int nwords;

@ -73,20 +73,13 @@ void parse_args(int argc, char **argv) {
} }
} }
int test_dci_payload_size() { int test_dci_payload_size() {
int i, j; int i, j;
int x[4]; int x[4];
const dci_format_t formats[4] = { Format0, Format1, Format1A, Format1C }; const dci_format_t formats[4] = { Format0, Format1, Format1A, Format1C };
const int prb[6] = { 6, 15, 25, 50, 75, 100 }; const int prb[6] = { 6, 15, 25, 50, 75, 100 };
const int dci_sz[6][5] = { const int dci_sz[6][5] = { { 21, 19, 21, 8 }, { 22, 23, 22, 10 }, { 25, 27,
{21, 19, 21, 8}, 25, 12 }, { 27, 31, 27, 13 }, { 27, 33, 27, 14 }, { 28, 39, 28, 15 } };
{22, 23, 22, 10},
{25, 27, 25, 12},
{27, 31, 27, 13},
{27, 33, 27, 14},
{28, 39, 28, 15}
};
printf("Testing DCI payload sizes...\n"); printf("Testing DCI payload sizes...\n");
printf(" PRB\t0\t1\t1A\t1C\n"); printf(" PRB\t0\t1\t1A\t1C\n");
@ -95,7 +88,8 @@ int test_dci_payload_size() {
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
x[j] = dci_format_sizeof(formats[j], n); x[j] = dci_format_sizeof(formats[j], n);
if (x[j] != dci_sz[i][j]) { if (x[j] != dci_sz[i][j]) {
fprintf(stderr, "Invalid DCI payload size for %s\n", dci_format_string(formats[j])); fprintf(stderr, "Invalid DCI payload size for %s\n",
dci_format_string(formats[j]));
return -1; return -1;
} }
} }
@ -113,7 +107,7 @@ int main(int argc, char **argv) {
int i, j; int i, j;
cf_t *ce[MAX_PORTS_CTRL]; cf_t *ce[MAX_PORTS_CTRL];
int nof_re; int nof_re;
cf_t *slot1_symbols[MAX_PORTS_CTRL]; cf_t *slot_symbols[MAX_PORTS_CTRL];
int nof_dcis; int nof_dcis;
int ret = -1; int ret = -1;
@ -135,8 +129,8 @@ int main(int argc, char **argv) {
for (j = 0; j < nof_re; j++) { for (j = 0; j < nof_re; j++) {
ce[i][j] = 1; ce[i][j] = 1;
} }
slot1_symbols[i] = malloc(sizeof(cf_t) * nof_re); slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
if (!slot1_symbols[i]) { if (!slot_symbols[i]) {
perror("malloc"); perror("malloc");
exit(-1); exit(-1);
} }
@ -176,19 +170,19 @@ int main(int argc, char **argv) {
dci_msg_candidate_set(&dci_tx.msg[1], 0, 1, 1234); dci_msg_candidate_set(&dci_tx.msg[1], 0, 1, 1234);
dci_tx.nof_dcis++; dci_tx.nof_dcis++;
pdcch_encode(&pdcch, &dci_tx, slot1_symbols, 0); pdcch_encode(&pdcch, &dci_tx, slot_symbols, 0);
/* combine outputs */ /* combine outputs */
for (i = 1; i < nof_ports; i++) { for (i = 1; i < nof_ports; i++) {
for (j = 0; j < nof_re; j++) { for (j = 0; j < nof_re; j++) {
slot1_symbols[0][j] += slot1_symbols[i][j]; slot_symbols[0][j] += slot_symbols[i][j];
} }
} }
pdcch_init_search_ue(&pdcch, 1234); pdcch_init_search_ue(&pdcch, 1234);
dci_init(&dci_rx, 2); dci_init(&dci_rx, 2);
nof_dcis = pdcch_decode(&pdcch, slot1_symbols[0], ce, &dci_rx, 0, 1); nof_dcis = pdcch_decode(&pdcch, slot_symbols[0], ce, &dci_rx, 0, 1);
if (nof_dcis < 0) { if (nof_dcis < 0) {
printf("Error decoding\n"); printf("Error decoding\n");
} else if (nof_dcis == dci_tx.nof_dcis) { } else if (nof_dcis == dci_tx.nof_dcis) {
@ -203,7 +197,8 @@ int main(int argc, char **argv) {
goto quit; goto quit;
} }
if (memcmp(dci_tx.msg[i].data, dci_rx.msg[i].data, dci_tx.msg[i].location.nof_bits)) { if (memcmp(dci_tx.msg[i].data, dci_rx.msg[i].data,
dci_tx.msg[i].location.nof_bits)) {
printf("Error in DCI %d: Received data does not match\n", i); printf("Error in DCI %d: Received data does not match\n", i);
goto quit; goto quit;
} }
@ -213,15 +208,14 @@ int main(int argc, char **argv) {
goto quit; goto quit;
} }
ret = 0; ret = 0;
quit: quit: pdcch_free(&pdcch);
pdcch_free(&pdcch);
regs_free(&regs); regs_free(&regs);
dci_free(&dci_tx); dci_free(&dci_tx);
dci_free(&dci_rx); dci_free(&dci_rx);
for (i = 0; i < MAX_PORTS_CTRL; i++) { for (i = 0; i < MAX_PORTS_CTRL; i++) {
free(ce[i]); free(ce[i]);
free(slot1_symbols[i]); free(slot_symbols[i]);
} }
if (ret) { if (ret) {
printf("Error\n"); printf("Error\n");

@ -0,0 +1,334 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "lte.h"
char *input_file_name = NULL;
char *matlab_file_name = NULL;
int cell_id = 0;
int cfi = 2;
lte_cp_t cp = CPNORM;
int nof_prb = 6;
int nof_ports = 1;
int flen;
unsigned short rnti = SIRNTI;
int max_frames = 10;
FILE *fmatlab = NULL;
filesource_t fsrc;
pdcch_t pdcch;
pdsch_t pdsch;
cf_t *input_buffer, *fft_buffer, *ce[MAX_PORTS_CTRL];
regs_t regs;
lte_fft_t fft;
chest_t chest;
dci_t dci_rx;
void usage(char *prog) {
printf("Usage: %s [vcfoe] -i input_file\n", prog);
printf("\t-o output matlab file name [Default Disabled]\n");
printf("\t-c cell_id [Default %d]\n", cell_id);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-r rnti [Default SI-RNTI]\n");
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-m max_frames [Default %d]\n", max_frames);
printf("\t-e Set extended prefix [Default Normal]\n");
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "irovfcenmp")) != -1) {
switch(opt) {
case 'i':
input_file_name = argv[optind];
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'r':
rnti = strtoul(argv[optind], NULL, 0);
break;
case 'm':
max_frames = strtoul(argv[optind], NULL, 0);
break;
case 'f':
cfi = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'o':
matlab_file_name = argv[optind];
break;
case 'v':
verbose++;
break;
case 'e':
cp = CPEXT;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (!input_file_name) {
usage(argv[0]);
exit(-1);
}
}
int base_init() {
int i;
if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) {
fprintf(stderr, "Error opening file %s\n", input_file_name);
exit(-1);
}
if (matlab_file_name) {
fmatlab = fopen(matlab_file_name, "w");
if (!fmatlab) {
perror("fopen");
return -1;
}
} else {
fmatlab = NULL;
}
flen = 2 * (SLOT_LEN(lte_symbol_sz(nof_prb), cp));
input_buffer = malloc(flen * sizeof(cf_t));
if (!input_buffer) {
perror("malloc");
exit(-1);
}
fft_buffer = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!fft_buffer) {
perror("malloc");
return -1;
}
for (i=0;i<MAX_PORTS_CTRL;i++) {
ce[i] = malloc(2 * CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t));
if (!ce[i]) {
perror("malloc");
return -1;
}
}
if (chest_init(&chest, LINEAR, cp, nof_prb, nof_ports)) {
fprintf(stderr, "Error initializing equalizer\n");
return -1;
}
if (chest_ref_LTEDL(&chest, cell_id)) {
fprintf(stderr, "Error initializing reference signal\n");
return -1;
}
if (lte_fft_init(&fft, cp, nof_prb)) {
fprintf(stderr, "Error initializing FFT\n");
return -1;
}
if (regs_init(&regs, cell_id, nof_prb, nof_ports, R_1, PHICH_NORM, cp)) {
fprintf(stderr, "Error initiating regs\n");
return -1;
}
if (regs_set_cfi(&regs, cfi)) {
fprintf(stderr, "Error setting CFI %d\n", cfi);
return -1;
}
if (pdcch_init(&pdcch, &regs, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
dci_init(&dci_rx, 10);
if (pdsch_init(&pdsch, rnti, nof_prb, nof_ports, cell_id, cp)) {
fprintf(stderr, "Error creating PDCCH object\n");
exit(-1);
}
DEBUG("Memory init OK\n",0);
return 0;
}
void base_free() {
int i;
filesource_free(&fsrc);
if (fmatlab) {
fclose(fmatlab);
}
free(input_buffer);
free(fft_buffer);
filesource_free(&fsrc);
for (i=0;i<MAX_PORTS_CTRL;i++) {
free(ce[i]);
}
chest_free(&chest);
lte_fft_free(&fft);
dci_free(&dci_rx);
pdcch_free(&pdcch);
pdsch_free(&pdsch);
regs_free(&regs);
}
int main(int argc, char **argv) {
ra_pdsch_t ra_dl;
ra_prb_t prb_alloc;
int i;
int nof_dcis;
int nof_frames;
int ret;
char *data;
data = malloc(10000);
if (argc < 3) {
usage(argv[0]);
exit(-1);
}
parse_args(argc,argv);
if (base_init()) {
fprintf(stderr, "Error initializing memory\n");
exit(-1);
}
if (rnti == SIRNTI) {
INFO("Initializing common search space for SI-RNTI\n",0);
pdcch_init_search_si(&pdcch);
} else {
INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti);
pdcch_init_search_ue(&pdcch, rnti);
}
ret = -1;
nof_frames = 0;
do {
filesource_read(&fsrc, input_buffer, flen);
if (nof_frames == 5) {
INFO("Reading %d samples sub-frame %d\n", flen, nof_frames);
lte_fft_run(&fft, input_buffer, fft_buffer);
lte_fft_run(&fft, &input_buffer[flen/2], &fft_buffer[CP_NSYMB(cp) * nof_prb * RE_X_RB]);
if (fmatlab) {
fprintf(fmatlab, "infft%d=", nof_frames);
vec_fprint_c(fmatlab, input_buffer, flen);
fprintf(fmatlab, ";\n");
fprintf(fmatlab, "outfft%d=", nof_frames);
vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
fprintf(fmatlab, ";\n");
vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB);
}
/* Get channel estimates for each port */
for (i=0;i<nof_ports;i++) {
chest_ce_slot_port(&chest, fft_buffer, ce[i], 2*nof_frames, i);
chest_ce_slot_port(&chest, &fft_buffer[CP_NSYMB(cp) * nof_prb * RE_X_RB],
&ce[i][CP_NSYMB(cp) * nof_prb * RE_X_RB], 2*nof_frames+1, i);
if (fmatlab) {
chest_fprint(&chest, fmatlab, 2*nof_frames+1, i);
}
}
nof_dcis = pdcch_decode(&pdcch, fft_buffer, ce, &dci_rx, nof_frames%10, 1);
INFO("Received %d DCI messages\n", nof_dcis);
for (i=0;i<nof_dcis;i++) {
dci_msg_type_t type;
if (dci_msg_get_type(&dci_rx.msg[i], &type, nof_prb, 1234)) {
fprintf(stderr, "Can't get DCI message type\n");
goto goout;
}
printf("MSG %d: ",i);
dci_msg_type_fprint(stdout, type);
switch(type.type) {
case PDSCH_SCHED:
bzero(&ra_dl, sizeof(ra_pdsch_t));
if (dci_msg_unpack_pdsch(&dci_rx.msg[i], &ra_dl, nof_prb, rnti != SIRNTI)) {
fprintf(stderr, "Can't unpack PDSCH message\n");
} else {
ra_pdsch_fprint(stdout, &ra_dl, nof_prb);
if (ra_dl.alloc_type == alloc_type2 && ra_dl.type2_alloc.mode == t2_loc
&& ra_dl.type2_alloc.riv == 11 && ra_dl.rv_idx == 0
&& ra_dl.harq_process == 0 && ra_dl.mcs.mcs_idx == 2) {
printf("This is the file signal.1.92M.amar.dat\n");
ret = 0;
}
}
break;
default:
fprintf(stderr, "Unsupported message type\n");
break;
}
if (ra_prb_get_dl(&prb_alloc, &ra_dl, nof_prb)) {
fprintf(stderr, "Error computing resource allocation\n");
goto goout;
}
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, nof_prb<10?(cfi+1):cfi, cp);
if (pdsch_decode(&pdsch, fft_buffer, ce, data, nof_frames%10, ra_dl.mcs, &prb_alloc)) {
fprintf(stderr, "Error decoding PDSCH\n");
goto goout;
} else {
printf("PDSCH Decoded OK!\n");
}
}
}
nof_frames++;
} while (nof_frames <= max_frames);
goout:
base_free();
fftwf_cleanup();
exit(ret);
}

@ -0,0 +1,103 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <stdbool.h>
#include "lte.h"
#define N_TESTS 10
const lte_cp_t test_re_cp[N_TESTS] = {CPNORM, CPNORM, CPNORM, CPNORM, CPNORM, CPNORM, CPEXT, CPEXT, CPEXT, CPEXT};
const int test_re_ports[N_TESTS] = {1, 1, 1, 2, 4, 4, 1, 4, 1, 4};
const int test_re_csymb[N_TESTS] = {2, 1, 3, 3, 1, 3, 2, 2, 1, 2};
const int test_re_prb[N_TESTS] = {6, 15, 15, 15, 15, 15, 6, 6, 15, 15};
const int test_re_num[N_TESTS][3] = {
{408, 684, 828 }, // sf 0, 5 and the rest
{1830, 2106, 2250},
{1470, 1746, 1890},
{1392, 1656, 1800},
{1656, 1896, 2040},
{1356, 1596, 1740},
{276, 540, 684},
{264, 480, 624},
{1482, 1746, 1890},
{1200, 1416, 1560}
};
int main(int argc, char **argv) {
int i, n, np;
ra_prb_t prb_alloc;
int ret = -1;
while (getopt(argc, argv, "v") == 'v') {
verbose++;
}
for (i=0;i<110;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
prb_alloc.slot[1].prb_idx[i] = i;
}
for (i=0;i<N_TESTS;i++) {
memset(prb_alloc.re_sf, 0, sizeof(int) * 10);
prb_alloc.slot[0].nof_prb = test_re_prb[i];
prb_alloc.slot[1].nof_prb = test_re_prb[i];
ra_prb_get_re(&prb_alloc, test_re_prb[i], test_re_ports[i], test_re_csymb[i], test_re_cp[i]);
for (n=0;n<10;n++) {
switch(n) {
case 0:
np = 0;
break;
case 5:
np = 1;
break;
default:
np = 2;
break;
}
if (prb_alloc.re_sf[n] != test_re_num[i][np]) {
goto go_out;
}
}
}
ret = 0;
go_out:
if (ret) {
printf("Error in SF %d test %d. %d PRB, %d ports, RE is %d and should be %d\n",
n, i, test_re_prb[i], test_re_ports[i], prb_alloc.re_sf[n], test_re_num[i][np]);
} else {
printf("Ok\n");
}
exit(ret);
}

@ -0,0 +1,207 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2014 The libLTE Developers. See the
* COPYRIGHT file at the top-level directory of this distribution.
*
* \section LICENSE
*
* This file is part of the libLTE library.
*
* libLTE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* libLTE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* A copy of the GNU Lesser General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <sys/time.h>
#include "lte.h"
int cell_id = 1;
int nof_prb = 6;
int nof_ports = 1;
int cfi = 1;
int tbs = -1;
int subframe = 1;
ra_mod_t modulation = BPSK;
void usage(char *prog) {
printf("Usage: %s [cpnfvmt] -l TBS \n", prog);
printf("\t-m modulation (1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64) [Default BPSK]\n");
printf("\t-c cell id [Default %d]\n", cell_id);
printf("\t-s subframe [Default %d]\n", subframe);
printf("\t-f cfi [Default %d]\n", cfi);
printf("\t-p nof_ports [Default %d]\n", nof_ports);
printf("\t-n nof_prb [Default %d]\n", nof_prb);
printf("\t-v [set verbose to debug, default none]\n");
}
void parse_args(int argc, char **argv) {
int opt;
while ((opt = getopt(argc, argv, "lcpnfvmt")) != -1) {
switch(opt) {
case 'm':
switch(atoi(argv[optind])) {
case 1:
modulation = BPSK;
break;
case 2:
modulation = QPSK;
break;
case 4:
modulation = QAM16;
break;
case 6:
modulation = QAM64;
break;
default:
fprintf(stderr, "Invalid modulation %d. Possible values: "
"(1: BPSK, 2: QPSK, 3: QAM16, 4: QAM64)\n", atoi(argv[optind]));
break;
}
break;
case 'l':
tbs = atoi(argv[optind]);
break;
case 'p':
nof_ports = atoi(argv[optind]);
break;
case 'n':
nof_prb = atoi(argv[optind]);
break;
case 'c':
cell_id = atoi(argv[optind]);
break;
case 'v':
verbose++;
break;
default:
usage(argv[0]);
exit(-1);
}
}
if (tbs == -1) {
usage(argv[0]);
exit(-1);
}
}
int main(int argc, char **argv) {
pdsch_t pdsch;
int i, j;
char *data = NULL;
cf_t *ce[MAX_PORTS_CTRL];
int nof_re;
cf_t *slot_symbols[MAX_PORTS_CTRL];
int ret = -1;
struct timeval t[3];
ra_mcs_t mcs;
ra_prb_t prb_alloc;
parse_args(argc,argv);
nof_re = 2 * CPNORM_NSYMB * nof_prb * RE_X_RB;
mcs.tbs = tbs;
mcs.mod = modulation;
prb_alloc.slot[0].nof_prb = nof_prb;
for (i=0;i<prb_alloc.slot[0].nof_prb;i++) {
prb_alloc.slot[0].prb_idx[i] = i;
}
memcpy(&prb_alloc.slot[1], &prb_alloc.slot[0], sizeof(ra_prb_slot_t));
ra_prb_get_re(&prb_alloc, nof_prb, nof_ports, 2, CPNORM);
/* init memory */
for (i=0;i<nof_ports;i++) {
ce[i] = malloc(sizeof(cf_t) * nof_re);
if (!ce[i]) {
perror("malloc");
goto quit;
}
for (j=0;j<nof_re;j++) {
ce[i][j] = 1;
}
slot_symbols[i] = malloc(sizeof(cf_t) * nof_re);
if (!slot_symbols[i]) {
perror("malloc");
goto quit;
}
}
data = malloc(sizeof(char) * mcs.tbs);
if (!data) {
perror("malloc");
goto quit;
}
if (pdsch_init(&pdsch, 1234, nof_prb, nof_ports, cell_id, CPNORM)) {
fprintf(stderr, "Error creating PDSCH object\n");
goto quit;
}
for (i=0;i<mcs.tbs;i++) {
data[i] = rand()%2;
}
pdsch_encode(&pdsch, data, slot_symbols, subframe, mcs, &prb_alloc);
/* combine outputs */
for (i=0;i<nof_ports;i++) {
for (j=0;j<nof_re;j++) {
if (i > 0) {
slot_symbols[0][j] += slot_symbols[i][j];
}
ce[i][j] = 1;
}
}
gettimeofday(&t[1], NULL);
int r = pdsch_decode(&pdsch, slot_symbols[0], ce, data, subframe, mcs, &prb_alloc);
gettimeofday(&t[2], NULL);
get_time_interval(t);
if (r) {
printf("Error decoding\n");
ret = -1;
} else {
printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec);
}
ret = 0;
quit:
pdsch_free(&pdsch);
for (i=0;i<nof_ports;i++) {
if (ce[i]) {
free(ce[i]);
}
if (slot_symbols[i]) {
free(slot_symbols[i]);
}
}
if (data) {
free(data);
}
if (ret) {
printf("Error\n");
} else {
printf("Ok\n");
}
exit(ret);
}

@ -25,7 +25,6 @@
* *
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -80,15 +79,24 @@ int compute_sequences(scrambling_hl* h) {
switch (h->init.channel) { switch (h->init.channel) {
case SCRAMBLING_PBCH: case SCRAMBLING_PBCH:
return sequence_pbch(&h->obj.seq[0], h->init.nof_symbols == CPNORM_NSYMB?CPNORM:CPEXT, return sequence_pbch(&h->obj.seq[0],
h->init.cell_id); h->init.nof_symbols == CPNORM_NSYMB ? CPNORM : CPEXT, h->init.cell_id);
case SCRAMBLING_PDSCH: case SCRAMBLING_PDSCH:
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pdsch(&h->obj.seq[ns], h->init.nrnti, 0, 2 * ns, h->init.cell_id,
LTE_NSOFT_BITS);
}
return 0;
case SCRAMBLING_PCFICH: case SCRAMBLING_PCFICH:
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) { for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pcfich(&h->obj.seq[ns], 2 * ns, h->init.cell_id); sequence_pcfich(&h->obj.seq[ns], 2 * ns, h->init.cell_id);
} }
return 0; return 0;
case SCRAMBLING_PDCCH: case SCRAMBLING_PDCCH:
for (int ns = 0; ns < NSUBFRAMES_X_FRAME; ns++) {
sequence_pdcch(&h->obj.seq[ns], 2 * ns, h->init.cell_id, LTE_NSOFT_BITS);
}
return 0;
case SCRAMBLING_PMCH: case SCRAMBLING_PMCH:
case SCRAMBLING_PUCCH: case SCRAMBLING_PUCCH:
fprintf(stderr, "Not implemented\n"); fprintf(stderr, "Not implemented\n");

Loading…
Cancel
Save