Commit 1ecb0062 authored by Hongzhi Wang's avatar Hongzhi Wang

ue adding nr polar decoder

parent fbbb2e03
...@@ -1292,6 +1292,7 @@ set(PHY_SRC_UE ...@@ -1292,6 +1292,7 @@ set(PHY_SRC_UE
${OPENAIR1_DIR}/PHY/TOOLS/time_meas.c ${OPENAIR1_DIR}/PHY/TOOLS/time_meas.c
${OPENAIR1_DIR}/PHY/TOOLS/lut.c ${OPENAIR1_DIR}/PHY/TOOLS/lut.c
${OPENAIR1_DIR}/PHY/INIT/nr_init_ue.c ${OPENAIR1_DIR}/PHY/INIT/nr_init_ue.c
${PHY_POLARSRC}
) )
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
#include "PHY/LTE_REFSIG/lte_refsig.h" #include "PHY/LTE_REFSIG/lte_refsig.h"
#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h"
//uint8_t dmrs1_tab_ue[8] = {0,2,3,4,6,8,9,10}; //uint8_t dmrs1_tab_ue[8] = {0,2,3,4,6,8,9,10};
...@@ -955,6 +956,9 @@ void phy_init_nr_top(NR_DL_FRAME_PARMS *frame_parms) ...@@ -955,6 +956,9 @@ void phy_init_nr_top(NR_DL_FRAME_PARMS *frame_parms)
generate_ul_reference_signal_sequences(SHRT_MAX); generate_ul_reference_signal_sequences(SHRT_MAX);
// Polar encoder init for PBCH
nr_polar_init(&frame_parms->pbch_polar_params, 1);
//lte_sync_time_init(frame_parms); //lte_sync_time_init(frame_parms);
//generate_ul_ref_sigs(); //generate_ul_ref_sigs();
......
...@@ -31,20 +31,11 @@ ...@@ -31,20 +31,11 @@
*/ */
#include "PHY/defs_nr_UE.h" #include "PHY/defs_nr_UE.h"
#include "PHY/CODING/coding_extern.h" #include "PHY/CODING/coding_extern.h"
#include "PHY/CODING/lte_interleaver_inline.h"
//#include "defs.h"
//#include "extern.h"
#include "PHY/phy_extern_nr_ue.h" #include "PHY/phy_extern_nr_ue.h"
#include "PHY/sse_intrin.h" #include "PHY/sse_intrin.h"
#ifdef PHY_ABSTRACTION
#include "SIMULATION/TOOLS/defs.h"
#endif
//#define DEBUG_PBCH 1 //#define DEBUG_PBCH 1
//#define DEBUG_PBCH_ENCODING //#define DEBUG_PBCH_ENCODING
//#define INTERFERENCE_MITIGATION 1
#ifdef OPENAIR2 #ifdef OPENAIR2
//#include "PHY_INTERFACE/defs.h" //#include "PHY_INTERFACE/defs.h"
...@@ -255,8 +246,8 @@ void nr_pbch_channel_compensation(int **rxdataF_ext, ...@@ -255,8 +246,8 @@ void nr_pbch_channel_compensation(int **rxdataF_ext,
uint8_t output_shift) uint8_t output_shift)
{ {
uint16_t rb,nb_rb=20; uint16_t rb,nb_rb=15;
uint8_t aatx,aarx,symbol_mod; uint8_t aatx,aarx;
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
__m128i *dl_ch128,*rxdataF128,*rxdataF_comp128; __m128i *dl_ch128,*rxdataF128,*rxdataF_comp128;
#elif defined(__arm__) #elif defined(__arm__)
...@@ -394,35 +385,9 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms, ...@@ -394,35 +385,9 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
#endif #endif
} }
void nr_pbch_scrambling(NR_DL_FRAME_PARMS *frame_parms,
uint8_t *pbch_e,
uint32_t length)
{
int i;
uint8_t reset;
uint32_t x1, x2, s=0;
reset = 1;
// x1 is set in lte_gold_generic
x2 = frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.6.1
// msg("pbch_scrambling: Nid_cell = %d\n",x2);
for (i=0; i<length; i++) {
if ((i&0x1f)==0) {
s = lte_gold_generic(&x1, &x2, reset);
// printf("lte_gold[%d]=%x\n",i,s);
reset = 0;
}
pbch_e[i] = (pbch_e[i]&1) ^ ((s>>(i&0x1f))&1);
}
}
void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms, void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms,
int8_t* llr, int8_t* llr,
uint32_t length, uint32_t length)
uint8_t frame_mod4)
{ {
int i; int i;
uint8_t reset; uint8_t reset;
...@@ -440,13 +405,8 @@ void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms, ...@@ -440,13 +405,8 @@ void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms,
reset = 0; reset = 0;
} }
// take the quarter of the PBCH that corresponds to this frame if (((s>>(i%32))&1)==0)
if ((i>=(frame_mod4*(length>>2))) && (i<((1+frame_mod4)*(length>>2)))) { llr[i] = -llr[i];
// if (((s>>(i%32))&1)==1)
if (((s>>(i%32))&1)==0)
llr[i] = -llr[i];
}
} }
} }
...@@ -488,7 +448,7 @@ void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms, ...@@ -488,7 +448,7 @@ void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms,
} }
void nr_pbch_quantize(int8_t *pbch_llr8, void nr_pbch_quantize(int16_t *pbch_llr16,
int16_t *pbch_llr, int16_t *pbch_llr,
uint16_t len) uint16_t len)
{ {
...@@ -496,20 +456,16 @@ void nr_pbch_quantize(int8_t *pbch_llr8, ...@@ -496,20 +456,16 @@ void nr_pbch_quantize(int8_t *pbch_llr8,
uint16_t i; uint16_t i;
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
if (pbch_llr[i]>7) /*if (pbch_llr[i]>7)
pbch_llr8[i]=7; pbch_llr8[i]=7;
else if (pbch_llr[i]<-8) else if (pbch_llr[i]<-8)
pbch_llr8[i]=-8; pbch_llr8[i]=-8;
else else*/
pbch_llr8[i] = (char)(pbch_llr[i]); pbch_llr16[i] = (char)(pbch_llr[i]);
} }
} }
static unsigned char dummy_w_rx[3*3*(16+PBCH_A)];
static int8_t pbch_w_rx[3*3*(16+PBCH_A)],pbch_d_rx[96+(3*(16+PBCH_A))];
uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
UE_nr_rxtx_proc_t *proc, UE_nr_rxtx_proc_t *proc,
NR_UE_PBCH *nr_ue_pbch_vars, NR_UE_PBCH *nr_ue_pbch_vars,
...@@ -522,38 +478,28 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -522,38 +478,28 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
NR_UE_COMMON *nr_ue_common_vars = &ue->common_vars; NR_UE_COMMON *nr_ue_common_vars = &ue->common_vars;
uint8_t log2_maxh;//,aatx,aarx; uint8_t log2_maxh;
int max_h=0; int max_h=0;
int symbol,i; int symbol,i;
uint32_t nsymb = (frame_parms->Ncp==0) ? 14:12;
uint16_t pbch_E;
uint8_t pbch_a[8]; uint8_t pbch_a[8];
uint8_t RCC;
int8_t *pbch_e_rx; int16_t *pbch_e_rx;
uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output;
uint16_t crc; uint16_t crc;
int8_t decoderState=0;
uint8_t decoderListSize = 8, pathMetricAppr = 0;
double aPrioriArray[frame_parms->pbch_polar_params.payloadBits]; // assume no a priori knowledge available about the payload.
int subframe_rx = proc->subframe_rx; int subframe_rx = proc->subframe_rx;
// pbch_D = 16+PBCH_A; pbch_e_rx = &nr_ue_pbch_vars->llr[0];
pbch_E = (frame_parms->Ncp==0) ? 1920 : 1728; //RE/RB * #RB * bits/RB (QPSK)
pbch_e_rx = &nr_ue_pbch_vars->llr[frame_mod4*(pbch_E>>2)];
#ifdef DEBUG_PBCH
msg("[PBCH] starting symbol loop (Ncp %d, frame_mod4 %d,mimo_mode %d\n",frame_parms->Ncp,frame_mod4,mimo_mode);
#endif
// clear LLR buffer // clear LLR buffer
memset(nr_ue_pbch_vars->llr,0,pbch_E); memset(nr_ue_pbch_vars->llr,0,NR_POLAR_PBCH_PAYLOAD_BITS);
for (symbol=1; symbol<4; symbol++) { for (symbol=1; symbol<4; symbol++) {
#ifdef DEBUG_PBCH
msg("[PBCH] starting extract ofdm size %d\n",frame_parms->ofdm_symbol_size );
#endif
//printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF); //printf("address dataf %p",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF);
//write_output("rxdataF0_pbch.m","rxF0pbch",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,frame_parms->ofdm_symbol_size*4,2,1); //write_output("rxdataF0_pbch.m","rxF0pbch",nr_ue_common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe_rx]].rxdataF,frame_parms->ofdm_symbol_size*4,2,1);
...@@ -565,7 +511,7 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -565,7 +511,7 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
high_speed_flag, high_speed_flag,
frame_parms); frame_parms);
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
msg("[PHY] PBCH Symbol %d\n",symbol); msg("[PHY] PBCH Symbol %d ofdm size %d\n",symbol, frame_parms->ofdm_symbol_size );
msg("[PHY] PBCH starting channel_level\n"); msg("[PHY] PBCH starting channel_level\n");
#endif #endif
...@@ -595,31 +541,30 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -595,31 +541,30 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
if (mimo_mode == ALAMOUTI) { if (mimo_mode == ALAMOUTI) {
nr_pbch_alamouti(frame_parms,nr_ue_pbch_vars->rxdataF_comp,symbol); nr_pbch_alamouti(frame_parms,nr_ue_pbch_vars->rxdataF_comp,symbol);
// msg("[PBCH][RX] Alamouti receiver not yet implemented!\n");
// return(-1);
} else if (mimo_mode != SISO) { } else if (mimo_mode != SISO) {
msg("[PBCH][RX] Unsupported MIMO mode\n"); msg("[PBCH][RX] Unsupported MIMO mode\n");
return(-1); return(-1);
} }
if (symbol>(nsymb>>1)+1) { if (symbol==2) {
nr_pbch_quantize(pbch_e_rx, nr_pbch_quantize(pbch_e_rx,
(short*)&(nr_ue_pbch_vars->rxdataF_comp[0][(symbol%(nsymb>>1))*240]), (short*)&(nr_ue_pbch_vars->rxdataF_comp[0][symbol*240]),
144); 108);
pbch_e_rx+=144; pbch_e_rx+=108;
} else { } else {
nr_pbch_quantize(pbch_e_rx, nr_pbch_quantize(pbch_e_rx,
(short*)&(nr_ue_pbch_vars->rxdataF_comp[0][(symbol%(nsymb>>1))*240]), (short*)&(nr_ue_pbch_vars->rxdataF_comp[0][symbol*240]),
96); 360);
pbch_e_rx+=96; pbch_e_rx+=360;
} }
} }
pbch_e_rx = nr_ue_pbch_vars->llr; pbch_e_rx = nr_ue_pbch_vars->llr;
//#ifdef DEBUG_PBCH //#ifdef DEBUG_PBCH
//pbch_e_rx = &nr_ue_pbch_vars->llr[0]; //pbch_e_rx = &nr_ue_pbch_vars->llr[0];
...@@ -628,53 +573,25 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -628,53 +573,25 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
printf("pbch rx llr %d rxdata_comp %d addr %p\n",*(pbch_e_rx+cnt), p[cnt], &p[0]); printf("pbch rx llr %d rxdata_comp %d addr %p\n",*(pbch_e_rx+cnt), p[cnt], &p[0]);
//#endif //#endif
//un-scrambling //polar decoding de-rate matching
#ifdef DEBUG_PBCH decoderState = polar_decoder(pbch_e_rx, pbch_a, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr);
msg("[PBCH] doing unscrambling\n");
#endif
memset(pbch_a,0,((16+NR_POLAR_PBCH_PAYLOAD_BITS)>>3));
//un-scrambling
nr_pbch_unscrambling(frame_parms, nr_pbch_unscrambling(frame_parms,
pbch_e_rx, pbch_a,
pbch_E, NR_POLAR_PBCH_PAYLOAD_BITS);
frame_mod4);
// Fix byte endian
for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++)
decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i];
//un-rate matching
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
msg("[PBCH] doing un-rate-matching\n");
#endif
memset(dummy_w_rx,0,3*3*(16+PBCH_A));
RCC = generate_dummy_w_cc(16+PBCH_A,
dummy_w_rx);
lte_rate_matching_cc_rx(RCC,pbch_E,pbch_w_rx,dummy_w_rx,pbch_e_rx);
sub_block_deinterleaving_cc((unsigned int)(PBCH_A+16),
&pbch_d_rx[96],
&pbch_w_rx[0]);
memset(pbch_a,0,((16+PBCH_A)>>3));
phy_viterbi_lte_sse2(pbch_d_rx+96,pbch_a,16+PBCH_A);
// Fix byte endian of PBCH (bit 23 goes in first)
for (i=0; i<(PBCH_A>>3); i++)
decoded_output[(PBCH_A>>3)-i-1] = pbch_a[i];
#ifdef DEBUG_PBCH for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++)
for (i=0; i<(PBCH_A>>3); i++)
msg("[PBCH] pbch_a[%d] = %x\n",i,decoded_output[i]); msg("[PBCH] pbch_a[%d] = %x\n",i,decoded_output[i]);
#endif //DEBUG_PBCH #endif
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
msg("PBCH CRC %x : %x\n", msg("PBCH CRC %x : %x\n",
...@@ -694,46 +611,4 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -694,46 +611,4 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
else else
return(-1); return(-1);
}
#ifdef PHY_ABSTRACTION
uint16_t rx_pbch_emul(PHY_VARS_UE *phy_vars_ue,
uint8_t eNB_id,
uint8_t pbch_phase)
{
double bler=0.0;//, x=0.0;
double sinr=0.0;
uint16_t nb_rb = phy_vars_ue->frame_parms.N_RB_DL;
int16_t f;
uint8_t CC_id=phy_vars_ue->CC_id;
int frame_rx = phy_vars_ue->proc.proc_rxtx[0].frame_rx;
// compute effective sinr
// TODO: adapt this to varible bandwidth
for (f=(nb_rb*6-3*12); f<(nb_rb*6+3*12); f++) {
if (f!=0) //skip DC
sinr += pow(10, 0.1*(phy_vars_ue->sinr_dB[f]));
}
sinr = 10*log10(sinr/(6*12));
bler = pbch_bler(sinr);
LOG_D(PHY,"EMUL UE rx_pbch_emul: eNB_id %d, pbch_phase %d, sinr %f dB, bler %f \n",
eNB_id,
pbch_phase,
sinr,
bler);
if (pbch_phase == (frame_rx % 4)) {
if (uniformrandom() >= bler) {
memcpy(phy_vars_ue->pbch_vars[eNB_id]->decoded_output,PHY_vars_eNB_g[eNB_id][CC_id]->pbch_pdu,PBCH_PDU_SIZE);
return(PHY_vars_eNB_g[eNB_id][CC_id]->frame_parms.nb_antenna_ports_eNB);
} else
return(-1);
} else
return(-1);
} }
#endif
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include "defs_nr_common.h" #include "defs_nr_common.h"
#include "CODING/nrPolar_tools/nr_polar_pbch_defs.h"
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
...@@ -110,8 +112,8 @@ ...@@ -110,8 +112,8 @@
#define openair_sched_exit() exit(-1) #define openair_sched_exit() exit(-1)
#define max(a,b) ((a)>(b) ? (a) : (b)) //#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b)) //#define min(a,b) ((a)<(b) ? (a) : (b))
#define bzero(s,n) (memset((s),0,(n))) #define bzero(s,n) (memset((s),0,(n)))
...@@ -640,7 +642,7 @@ typedef struct { ...@@ -640,7 +642,7 @@ typedef struct {
int32_t **dl_ch_estimates_ext; int32_t **dl_ch_estimates_ext;
/// \brief Pointer to PBCH llrs. /// \brief Pointer to PBCH llrs.
/// - first index: ? [0..1919] (hard coded) /// - first index: ? [0..1919] (hard coded)
int8_t *llr; int16_t *llr;
/// \brief Pointer to PBCH decoded output. /// \brief Pointer to PBCH decoded output.
/// - first index: ? [0..63] (hard coded) /// - first index: ? [0..63] (hard coded)
uint8_t *decoded_output; uint8_t *decoded_output;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment