Commit c4bef81e authored by Hongzhi Wang's avatar Hongzhi Wang

ue adding 2nd decrambling and deinterleaving

parent f68d124d
...@@ -386,31 +386,53 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms, ...@@ -386,31 +386,53 @@ void nr_pbch_detection_mrc(NR_DL_FRAME_PARMS *frame_parms,
#endif #endif
} }
void nr_pbch_unscrambling(NR_DL_FRAME_PARMS *frame_parms, void nr_pbch_unscrambling(NR_UE_PBCH *pbch,
uint8_t* pbch_a, uint16_t Nid,
uint32_t length) uint8_t nushift,
uint16_t M,
uint16_t length,
uint8_t bitwise)
{ {
int i; int i;
uint8_t reset; uint8_t reset, offset;
uint32_t x1, x2, s=0; uint32_t x1, x2, s=0;
uint8_t *pbch_e = pbch->pbch_e;
uint32_t *pbch_a_prime = (uint32_t*)pbch->pbch_a_prime;
uint32_t *pbch_a_interleaved = (uint32_t*)pbch->pbch_a_interleaved;
uint32_t unscrambling_mask = 0x100006D;
//printf("unscramb nid_cell %d\n",frame_parms->Nid_cell); //printf("unscramb nid_cell %d\n",frame_parms->Nid_cell);
reset = 1; reset = 1;
// x1 is set in first call to lte_gold_generic // x1 is set in first call to lte_gold_generic
x2 = frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.6.1 x2 = Nid; //this is c_init
for (i=0; i<length; i++) { // The Gold sequence is shifted by nushift* M, so we skip (nushift*M /32) double words
if (i%32==0) { for (int i=0; i<(uint16_t)ceil((nushift*M)/32); i++) {
s = lte_gold_generic(&x1, &x2, reset); s = lte_gold_generic(&x1, &x2, reset);
//printf("lte_gold[%d]=%x\n",i,s);
reset = 0; reset = 0;
} }
// Scrambling is now done with offset (nushift*M)%32
offset = (nushift*M)&0x1f;
//printf("s = %d\n",((s>>(i%32))&1) ); for (int i=0; i<length; i++) {
if (((s>>(i%32))&1)==1) if (((i+offset)&0x1f)==0) {
pbch_a[i] = 1-pbch_a[i]; s = lte_gold_generic(&x1, &x2, reset);
reset = 0;
}
#ifdef DEBUG_PBCH_ENCODING
printf("s: %04x\t", s);
#endif
if (bitwise) {
(*pbch_a_interleaved) ^= ((unscrambling_mask>>i)&1)? (((*pbch_a_prime)>>i)&1)<<i : ((((*pbch_a_prime)>>i)&1) ^ ((s>>((i+offset)&0x1f))&1))<<i;
}
else {
if (((s>>((i+offset)&0x1f))&1)==1)
pbch_e[i] = -pbch_e[i];
} }
}
} }
void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms, void nr_pbch_alamouti(NR_DL_FRAME_PARMS *frame_parms,
...@@ -473,6 +495,8 @@ unsigned char sign(int8_t x) { ...@@ -473,6 +495,8 @@ unsigned char sign(int8_t x) {
return (unsigned char)x >> 7; return (unsigned char)x >> 7;
} }
uint8_t pbch_deinterleaving_pattern[32] = {28,0,31,30,1,29,25,27,22,2,24,3,4,5,6,7,18,21,20,8,9,10,11,19,26,12,13,14,15,16,23,17};
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,
...@@ -490,10 +514,14 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -490,10 +514,14 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
int symbol,i; int symbol,i;
//uint8_t pbch_a[64]; //uint8_t pbch_a[64];
uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32); ; uint8_t *pbch_a = malloc(sizeof(uint8_t) * 32);
uint8_t *pbch_a_prime;
int8_t *pbch_e_rx; int8_t *pbch_e_rx;
uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output; uint8_t *decoded_output = nr_ue_pbch_vars->decoded_output;
uint8_t nushift;
uint16_t M;
uint8_t Lmax=8; //to update
uint8_t ssb_index=0;
//uint16_t crc; //uint16_t crc;
//short nr_demod_table[8] = {0,0,0,1,1,0,1,1}; //short nr_demod_table[8] = {0,0,0,1,1,0,1,1};
double nr_demod_table[8] = {0.707,0.707,-0.707,0.707,0.707,-0.707,-0.707,-0.707}; double nr_demod_table[8] = {0.707,0.707,-0.707,0.707,0.707,-0.707,-0.707,-0.707};
...@@ -582,6 +610,9 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -582,6 +610,9 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
} }
pbch_e_rx = nr_ue_pbch_vars->llr; pbch_e_rx = nr_ue_pbch_vars->llr;
demod_pbch_e = nr_ue_pbch_vars->demod_pbch_e;
pbch_a = nr_ue_pbch_vars->pbch_a;
pbch_a_prime = nr_ue_pbch_vars->pbch_a_prime;
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
//pbch_e_rx = &nr_ue_pbch_vars->llr[0]; //pbch_e_rx = &nr_ue_pbch_vars->llr[0];
...@@ -603,19 +634,40 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -603,19 +634,40 @@ uint16_t nr_rx_pbch( PHY_VARS_NR_UE *ue,
#endif #endif
} }
//un-scrambling
M = NR_POLAR_PBCH_E;
nushift = (Lmax==4)? ssb_index&3 : ssb_index&7;
nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0);
//polar decoding de-rate matching //polar decoding de-rate matching
decoderState = polar_decoder(demod_pbch_e, pbch_a, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr); decoderState = polar_decoder(demod_pbch_e, pbch_a_prime, &frame_parms->pbch_polar_params, decoderListSize, aPrioriArray, pathMetricAppr);
for (i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++) for (i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++)
printf("pbch_a[%d] = %u \n", i,pbch_a[i]); printf("pbch_a_prime[%d] = %u \n", i,pbch_a_prime[i]);
//un-scrambling //payload un-scrambling
nr_pbch_unscrambling(frame_parms,pbch_a,NR_POLAR_PBCH_PAYLOAD_BITS); M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3);
nushift = (((pbch_a_prime[0]>>6)&1)<<1) ^ ((pbch_a_prime[3])&1);
nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_PAYLOAD_BITS,1);
//payload deinterleaving
uint32_t in=0, out=0;
for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS>>3; i++)
in |= (uint32_t)(nr_ue_pbch_vars->pbch_a_interleaved[i]<<((3-i)<<3));
for (int i=0; i<32; i++) {
out |= ((in>>i)&1)<<(pbch_deinterleaving_pattern[i]);
#ifdef DEBUG_PBCH
printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) 0x%08x\n", i, in, out, pbch_deinterleaver_pattern[i], (in>>i)&1);
#endif
}
for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS>>3; i++)
nr_ue_pbch_vars->pbch_a[i] = (uint8_t)((out>>(i<<3))&0xff);
// Fix byte endian // Fix byte endian
for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++) for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS>>3); i++)
decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS)-i-1] = pbch_a[i]; decoded_output[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_a[i];
//#ifdef DEBUG_PBCH //#ifdef DEBUG_PBCH
for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++) for (i=0; i<(NR_POLAR_PBCH_PAYLOAD_BITS); i++)
......
...@@ -149,8 +149,6 @@ ...@@ -149,8 +149,6 @@
#include "targets/ARCH/COMMON/common_lib.h" #include "targets/ARCH/COMMON/common_lib.h"
/// Context data structure for RX/TX portion of subframe processing /// Context data structure for RX/TX portion of subframe processing
typedef struct { typedef struct {
/// index of the current UE RX/TX proc /// index of the current UE RX/TX proc
...@@ -850,6 +848,11 @@ typedef struct { ...@@ -850,6 +848,11 @@ typedef struct {
/// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
/// - second index: ? [0..287] (hard coded) /// - second index: ? [0..287] (hard coded)
int32_t **dl_ch_estimates_ext; int32_t **dl_ch_estimates_ext;
uint8_t pbch_a[NR_POLAR_PBCH_PAYLOAD_BITS>>3];
uint8_t pbch_a_interleaved[NR_POLAR_PBCH_PAYLOAD_BITS>>3];
uint8_t pbch_a_prime[NR_POLAR_PBCH_PAYLOAD_BITS>>3];
uint8_t pbch_e[NR_POLAR_PBCH_E];
double demod_pbch_e[NR_POLAR_PBCH_E];
/// \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; int8_t *llr;
......
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