Commit e54882ce authored by HOAI SON DANG's avatar HOAI SON DANG

Fixing astyle formatting

Signed-off-by: default avatarHOAI SON DANG <danghoaison91@gmail.com>
parent 11553594
...@@ -43,21 +43,20 @@ ...@@ -43,21 +43,20 @@
#include "PHY/NR_REFSIG/nr_mod_table.h" #include "PHY/NR_REFSIG/nr_mod_table.h"
uint8_t nr_pbch_payload_interleaving_pattern[32] = {16, 23, 18, 17, 8, 30, 10, 6, 24, 7, 0, 5, 3, 2, 1, 4, uint8_t nr_pbch_payload_interleaving_pattern[32] = {16, 23, 18, 17, 8, 30, 10, 6, 24, 7, 0, 5, 3, 2, 1, 4,
9, 11, 12, 13, 14, 15, 19, 20, 21, 22, 25, 26, 27, 28, 29, 31}; 9, 11, 12, 13, 14, 15, 19, 20, 21, 22, 25, 26, 27, 28, 29, 31
};
int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
int32_t **txdataF, int32_t **txdataF,
int16_t amp, int16_t amp,
uint8_t ssb_start_symbol, uint8_t ssb_start_symbol,
nfapi_nr_config_request_t* config, nfapi_nr_config_request_t *config,
NR_DL_FRAME_PARMS *frame_parms) NR_DL_FRAME_PARMS *frame_parms) {
{
int k,l; int k,l;
int16_t a; int16_t a;
int16_t mod_dmrs[NR_PBCH_DMRS_LENGTH<<1]; int16_t mod_dmrs[NR_PBCH_DMRS_LENGTH<<1];
uint8_t idx=0; uint8_t idx=0;
uint8_t nushift = config->sch_config.physical_cell_id.value &3; uint8_t nushift = config->sch_config.physical_cell_id.value &3;
LOG_D(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift); LOG_D(PHY, "PBCH DMRS mapping started at symbol %d shift %d\n", ssb_start_symbol+1, nushift);
/// QPSK modulation /// QPSK modulation
...@@ -66,32 +65,30 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, ...@@ -66,32 +65,30 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
mod_dmrs[m<<1] = nr_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1]; mod_dmrs[m<<1] = nr_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
mod_dmrs[(m<<1)+1] = nr_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1]; mod_dmrs[(m<<1)+1] = nr_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1) + 1];
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("m %d idx %d gold seq %d b0-b1 %d-%d mod_dmrs %d %d\n", m, idx, gold_pbch_dmrs[(m<<1)>>5], (((gold_pbch_dmrs[(m<<1)>>5])>>((m<<1)&0x1f))&1), printf("m %d idx %d gold seq %d b0-b1 %d-%d mod_dmrs %d %d\n", m, idx, gold_pbch_dmrs[(m<<1)>>5], (((gold_pbch_dmrs[(m<<1)>>5])>>((m<<1)&0x1f))&1),
(((gold_pbch_dmrs[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1), mod_dmrs[(m<<1)], mod_dmrs[(m<<1)+1]); (((gold_pbch_dmrs[((m<<1)+1)>>5])>>(((m<<1)+1)&0x1f))&1), mod_dmrs[(m<<1)], mod_dmrs[(m<<1)+1]);
#endif #endif
} }
/// Resource mapping /// Resource mapping
a = (config->rf_config.tx_antenna_ports.value == 1) ? amp : (amp*ONE_OVER_SQRT2_Q15)>>15; a = (config->rf_config.tx_antenna_ports.value == 1) ? amp : (amp*ONE_OVER_SQRT2_Q15)>>15;
for (int aa = 0; aa < config->rf_config.tx_antenna_ports.value; aa++) for (int aa = 0; aa < config->rf_config.tx_antenna_ports.value; aa++) {
{
// PBCH DMRS are mapped within the SSB block on every fourth subcarrier starting from nushift of symbols 1, 2, 3 // PBCH DMRS are mapped within the SSB block on every fourth subcarrier starting from nushift of symbols 1, 2, 3
///symbol 1 [0+nushift:4:236+nushift] -- 60 mod symbols ///symbol 1 [0+nushift:4:236+nushift] -- 60 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift;
l = ssb_start_symbol + 1; l = ssb_start_symbol + 1;
for (int m = 0; m < 60; m++) { for (int m = 0; m < 60; m++) {
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("m %d at k %d of l %d\n", m, k, l); printf("m %d at k %d of l %d\n", m, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("(%d,%d)\n", printf("(%d,%d)\n",
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1], ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]); ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
#endif #endif
k+=4; k+=4;
...@@ -99,20 +96,20 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, ...@@ -99,20 +96,20 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
///symbol 2 [0+u:4:44+nushift ; 192+nu:4:236+nushift] -- 24 mod symbols ///symbol 2 [0+u:4:44+nushift ; 192+nu:4:236+nushift] -- 24 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift;
l++; l++;
for (int m = 60; m < 84; m++) { for (int m = 60; m < 84; m++) {
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("m %d at k %d of l %d\n", m, k, l); printf("m %d at k %d of l %d\n", m, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("(%d,%d)\n", printf("(%d,%d)\n",
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1], ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]); ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
#endif #endif
k+=(m==71)?148:4; // Jump from 44+nu to 192+nu k+=(m==71)?148:4; // Jump from 44+nu to 192+nu
...@@ -120,30 +117,28 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs, ...@@ -120,30 +117,28 @@ int nr_generate_pbch_dmrs(uint32_t *gold_pbch_dmrs,
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
///symbol 3 [0+nushift:4:236+nushift] -- 60 mod symbols ///symbol 3 [0+nushift:4:236+nushift] -- 60 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier + nushift;
l++; l++;
for (int m = 84; m < NR_PBCH_DMRS_LENGTH; m++) { for (int m = 84; m < NR_PBCH_DMRS_LENGTH; m++) {
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("m %d at k %d of l %d\n", m, k, l); printf("m %d at k %d of l %d\n", m, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_dmrs[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_dmrs[(m<<1) + 1]) >> 15;
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
printf("(%d,%d)\n", printf("(%d,%d)\n",
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1], ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1],
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]); ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1)+1]);
#endif #endif
k+=4; k+=4;
if (k >= frame_parms->ofdm_symbol_size) if (k >= frame_parms->ofdm_symbol_size)
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
} }
#ifdef DEBUG_PBCH_DMRS #ifdef DEBUG_PBCH_DMRS
write_output("txdataF_pbch_dmrs.m", "txdataF_pbch_dmrs", txdataF[0], frame_parms->samples_per_frame_wCP>>1, 1, 1); write_output("txdataF_pbch_dmrs.m", "txdataF_pbch_dmrs", txdataF[0], frame_parms->samples_per_frame_wCP>>1, 1, 1);
#endif #endif
...@@ -156,68 +151,67 @@ void nr_pbch_scrambling(NR_gNB_PBCH *pbch, ...@@ -156,68 +151,67 @@ void nr_pbch_scrambling(NR_gNB_PBCH *pbch,
uint16_t M, uint16_t M,
uint8_t Lmax, uint8_t Lmax,
uint16_t length, uint16_t length,
uint8_t encoded) uint8_t encoded) {
{
uint8_t reset, offset; uint8_t reset, offset;
uint32_t x1, x2, s=0; uint32_t x1, x2, s=0;
uint32_t *pbch_e = pbch->pbch_e; uint32_t *pbch_e = pbch->pbch_e;
uint32_t unscrambling_mask = (Lmax == 64) ? 0x100006D: 0x1000041; uint32_t unscrambling_mask = (Lmax == 64) ? 0x100006D: 0x1000041;
reset = 1; reset = 1;
// x1 is set in lte_gold_generic // x1 is set in lte_gold_generic
x2 = Nid; x2 = Nid;
// The Gold sequence is shifted by nushift* M, so we skip (nushift*M /32) double words // The Gold sequence is shifted by nushift* M, so we skip (nushift*M /32) double words
for (int i=0; i<(uint16_t)ceil(((float)nushift*M)/32); i++) { for (int i=0; i<(uint16_t)ceil(((float)nushift*M)/32); i++) {
s = lte_gold_generic(&x1, &x2, reset); s = lte_gold_generic(&x1, &x2, reset);
reset = 0; reset = 0;
} }
// Scrambling is now done with offset (nushift*M)%32 // Scrambling is now done with offset (nushift*M)%32
offset = (nushift*M)&0x1f; offset = (nushift*M)&0x1f;
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("Scrambling params: nushift %d M %d length %d encoded %d offset %d\n", nushift, M, length, encoded, offset); printf("Scrambling params: nushift %d M %d length %d encoded %d offset %d\n", nushift, M, length, encoded, offset);
#endif #endif
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("s: %04x\t", s); printf("s: %04x\t", s);
#endif #endif
int k = 0; int k = 0;
if (!encoded)
{ if (!encoded) {
/// 1st Scrambling /// 1st Scrambling
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i) {
{
if ((unscrambling_mask>>i)&1) if ((unscrambling_mask>>i)&1)
pbch->pbch_a_prime ^= ((pbch->pbch_a_interleaved>>i)&1)<<i; pbch->pbch_a_prime ^= ((pbch->pbch_a_interleaved>>i)&1)<<i;
else{ else {
if (((k+offset)&0x1f)==0) { if (((k+offset)&0x1f)==0) {
s = lte_gold_generic(&x1, &x2, reset); s = lte_gold_generic(&x1, &x2, reset);
reset = 0; reset = 0;
} }
pbch->pbch_a_prime ^= (((pbch->pbch_a_interleaved>>i)&1) ^ ((s>>((k+offset)&0x1f))&1))<<i; pbch->pbch_a_prime ^= (((pbch->pbch_a_interleaved>>i)&1) ^ ((s>>((k+offset)&0x1f))&1))<<i;
k++; /// k increase only when payload bit is not special bit k++; /// k increase only when payload bit is not special bit
} }
} }
}else{ } else {
/// 2nd Scrambling /// 2nd Scrambling
for (int i = 0; i < length; ++i) for (int i = 0; i < length; ++i) {
{ if (((i+offset)&0x1f)==0) {
if (((i+offset)&0x1f)==0) {
s = lte_gold_generic(&x1, &x2, reset); s = lte_gold_generic(&x1, &x2, reset);
reset = 0; reset = 0;
} }
pbch_e[i>>5] ^= (((s>>((i+offset)&0x1f))&1)<<(i&0x1f)); pbch_e[i>>5] ^= (((s>>((i+offset)&0x1f))&1)<<(i&0x1f));
} }
} }
} }
uint8_t nr_init_pbch_interleaver(uint8_t *interleaver) { uint8_t nr_init_pbch_interleaver(uint8_t *interleaver) {
uint8_t j_sfn=0, j_hrf=10, j_ssb=11, j_other=14; uint8_t j_sfn=0, j_hrf=10, j_ssb=11, j_other=14;
memset((void*)interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS); memset((void *)interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS);
uint8_t *pre_interleaver_pattern = (uint8_t *) malloc(NR_POLAR_PBCH_PAYLOAD_BITS*sizeof(uint8_t));
uint8_t *pre_interleaver_pattern = (uint8_t*) malloc(NR_POLAR_PBCH_PAYLOAD_BITS*sizeof(uint8_t)); memset((uint8_t *)pre_interleaver_pattern,0, NR_POLAR_PBCH_PAYLOAD_BITS);
memset((uint8_t*)pre_interleaver_pattern,0, NR_POLAR_PBCH_PAYLOAD_BITS);
/// Re-arrange pbch payload index prior interleaving /// Re-arrange pbch payload index prior interleaving
for (uint8_t i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++){ for (uint8_t i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++) {
if (i==0) // Type bit - other if (i==0) // Type bit - other
*(pre_interleaver_pattern+j_other++) = i; *(pre_interleaver_pattern+j_other++) = i;
else if (i<7) //Sfn bits:6 else if (i<7) //Sfn bits:6
...@@ -230,30 +224,25 @@ uint8_t nr_init_pbch_interleaver(uint8_t *interleaver) { ...@@ -230,30 +224,25 @@ uint8_t nr_init_pbch_interleaver(uint8_t *interleaver) {
*(pre_interleaver_pattern+j_hrf) = i; *(pre_interleaver_pattern+j_hrf) = i;
else // Ssb bits else // Ssb bits
*(pre_interleaver_pattern+j_ssb++) = i; *(pre_interleaver_pattern+j_ssb++) = i;
} }
for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; i++) for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; i++)
{
*(interleaver+nr_pbch_payload_interleaving_pattern[i]) = *(pre_interleaver_pattern+i); *(interleaver+nr_pbch_payload_interleaving_pattern[i]) = *(pre_interleaver_pattern+i);
}
#ifdef DEBUG_ITL #ifdef DEBUG_ITL
printf("nr_init_pbch_interleaver: Pre-Interleaving Pattern: "); printf("nr_init_pbch_interleaver: Pre-Interleaving Pattern: ");
for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; ++i) for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; ++i)
{
printf("%d ,",*(pre_interleaver_pattern+i)); printf("%d ,",*(pre_interleaver_pattern+i));
}
printf("\n");
printf("\n");
printf("nr_init_pbch_interleaver: Combine Interleaving Pattern: "); printf("nr_init_pbch_interleaver: Combine Interleaving Pattern: ");
for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; ++i) for (uint8_t i = 0; i < NR_POLAR_PBCH_PAYLOAD_BITS; ++i)
{
printf("%d ,",*(interleaver+i)); printf("%d ,",*(interleaver+i));
}
printf("\n"); printf("\n");
#endif #endif
} }
int nr_generate_pbch(NR_gNB_PBCH *pbch, int nr_generate_pbch(NR_gNB_PBCH *pbch,
...@@ -267,10 +256,8 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -267,10 +256,8 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
uint8_t Lmax, uint8_t Lmax,
uint8_t ssb_index, uint8_t ssb_index,
int sfn, int sfn,
nfapi_nr_config_request_t* config, nfapi_nr_config_request_t *config,
NR_DL_FRAME_PARMS *frame_parms) NR_DL_FRAME_PARMS *frame_parms) {
{
int k,l,m; int k,l,m;
int16_t a; int16_t a;
int16_t mod_pbch_e[NR_POLAR_PBCH_E]; int16_t mod_pbch_e[NR_POLAR_PBCH_E];
...@@ -278,26 +265,28 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -278,26 +265,28 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
uint16_t M; uint16_t M;
uint8_t nushift; uint8_t nushift;
uint8_t *xbyte = pbch->pbch_a; uint8_t *xbyte = pbch->pbch_a;
memset((void*) xbyte, 0, 1); memset((void *) xbyte, 0, 1);
//uint8_t pbch_a_b[32]; //uint8_t pbch_a_b[32];
// LOG_D(PHY, "PBCH generation started\n"); // LOG_D(PHY, "PBCH generation started\n");
memset((void *)pbch, 0, sizeof(NR_gNB_PBCH));
memset((void*)pbch, 0, sizeof(NR_gNB_PBCH));
///Payload generation ///Payload generation
// Fix byte endian // Fix byte endian
if (!(sfn&7)) if (!(sfn&7))
for (int i=0; i<(NR_PBCH_PDU_BITS>>3); i++) for (int i=0; i<(NR_PBCH_PDU_BITS>>3); i++)
pbch->pbch_a[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_pdu[i]; pbch->pbch_a[(NR_POLAR_PBCH_PAYLOAD_BITS>>3)-i-1] = pbch_pdu[i];
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("Byte endian fix:\n"); printf("Byte endian fix:\n");
for (int i=0; i<4; i++) for (int i=0; i<4; i++)
printf("pbch_a[%d]: 0x%02x\n", i, pbch->pbch_a[i]); printf("pbch_a[%d]: 0x%02x\n", i, pbch->pbch_a[i]);
#endif #endif
// Extra byte generation // Extra byte generation
for (int i=0; i<4; i++) for (int i=0; i<4; i++)
(*xbyte) ^= ((sfn>>(3-i))&1)<<i; // 4 lsb of sfn (*xbyte) ^= ((sfn>>(3-i))&1)<<i; // 4 lsb of sfn
(*xbyte) ^= n_hf<<4; // half frame index bit (*xbyte) ^= n_hf<<4; // half frame index bit
...@@ -306,21 +295,24 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -306,21 +295,24 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
(*xbyte) ^= ((ssb_index>>(3+i))&1)<<(5+i); // resp. 4th, 5th and 6th bits of ssb_index (*xbyte) ^= ((ssb_index>>(3+i))&1)<<(5+i); // resp. 4th, 5th and 6th bits of ssb_index
else else
(*xbyte) ^= ((config->sch_config.ssb_subcarrier_offset.value>>5)&1)<<5; //MSB of k_SSB (*xbyte) ^= ((config->sch_config.ssb_subcarrier_offset.value>>5)&1)<<5; //MSB of k_SSB
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("Extra byte:\n"); printf("Extra byte:\n");
for (int i=0; i<4; i++) for (int i=0; i<4; i++)
printf("pbch_a[%d]: 0x%02x\n", i, pbch->pbch_a[i]); printf("pbch_a[%d]: 0x%02x\n", i, pbch->pbch_a[i]);
#endif
// Payload interleaving #endif
// Payload interleaving
uint32_t in=0; uint32_t in=0;
for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS>>3; i++) for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS>>3; i++)
in |= (uint32_t)(pbch->pbch_a[i]<<((3-i)<<3)); in |= (uint32_t)(pbch->pbch_a[i]<<((3-i)<<3));
for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++) { for (int i=0; i<NR_POLAR_PBCH_PAYLOAD_BITS; i++) {
pbch->pbch_a_interleaved |= ((in>>(*(interleaver+i)))&1)<<i; pbch->pbch_a_interleaved |= ((in>>(*(interleaver+i)))&1)<<i;
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) %d\n", i, in, pbch->pbch_a_interleaved, *(interleaver+i), (in>>i)&1); printf("i %d in 0x%08x out 0x%08x ilv %d (in>>i)&1) %d\n", i, in, pbch->pbch_a_interleaved, *(interleaver+i), (in>>i)&1);
#endif #endif
} }
...@@ -328,8 +320,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -328,8 +320,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
printf("Interleaving:\n"); printf("Interleaving:\n");
printf("pbch_a_interleaved: 0x%08x\n", pbch->pbch_a_interleaved); printf("pbch_a_interleaved: 0x%08x\n", pbch->pbch_a_interleaved);
#endif #endif
// Scrambling
// Scrambling
M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3); M = (Lmax == 64)? (NR_POLAR_PBCH_PAYLOAD_BITS - 6) : (NR_POLAR_PBCH_PAYLOAD_BITS - 3);
nushift = (((sfn>>2)&1)<<1) ^ ((sfn>>1)&1); nushift = (((sfn>>2)&1)<<1) ^ ((sfn>>1)&1);
pbch->pbch_a_prime = 0; pbch->pbch_a_prime = 0;
...@@ -338,35 +329,36 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -338,35 +329,36 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
printf("Payload scrambling: nushift %d M %d sfn3 %d sfn2 %d\n", nushift, M, (sfn>>2)&1, (sfn>>1)&1); printf("Payload scrambling: nushift %d M %d sfn3 %d sfn2 %d\n", nushift, M, (sfn>>2)&1, (sfn>>1)&1);
printf("pbch_a_prime: 0x%08x\n", pbch->pbch_a_prime); printf("pbch_a_prime: 0x%08x\n", pbch->pbch_a_prime);
#endif #endif
/// CRC, coding and rate matching /// CRC, coding and rate matching
polar_encoder (&pbch->pbch_a_prime, pbch->pbch_e, polar_params); polar_encoder (&pbch->pbch_a_prime, pbch->pbch_e, polar_params);
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("Channel coding:\n"); printf("Channel coding:\n");
for (int i=0; i<NR_POLAR_PBCH_E_DWORD; i++) for (int i=0; i<NR_POLAR_PBCH_E_DWORD; i++)
printf("pbch_e[%d]: 0x%08x\t", i, pbch->pbch_e[i]); printf("pbch_e[%d]: 0x%08x\t", i, pbch->pbch_e[i]);
printf("\n"); printf("\n");
#endif #endif
/// Scrambling /// Scrambling
M = NR_POLAR_PBCH_E; M = NR_POLAR_PBCH_E;
nushift = (Lmax==4)? ssb_index&3 : ssb_index&7; nushift = (Lmax==4)? ssb_index&3 : ssb_index&7;
nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, Lmax, NR_POLAR_PBCH_E, 1); nr_pbch_scrambling(pbch, (uint32_t)config->sch_config.physical_cell_id.value, nushift, M, Lmax, NR_POLAR_PBCH_E, 1);
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
printf("Scrambling:\n"); printf("Scrambling:\n");
for (int i=0; i<NR_POLAR_PBCH_E_DWORD; i++) for (int i=0; i<NR_POLAR_PBCH_E_DWORD; i++)
printf("pbch_e[%d]: 0x%08x\t", i, pbch->pbch_e[i]); printf("pbch_e[%d]: 0x%08x\t", i, pbch->pbch_e[i]);
printf("\n"); printf("\n");
#endif #endif
/// QPSK modulation /// QPSK modulation
for (int i=0; i<NR_POLAR_PBCH_E>>1; i++){ for (int i=0; i<NR_POLAR_PBCH_E>>1; i++) {
idx = (((pbch->pbch_e[(i<<1)>>5]>>((i<<1)&0x1f))&1)<<1) ^ ((pbch->pbch_e[((i<<1)+1)>>5]>>(((i<<1)+1)&0x1f))&1); idx = (((pbch->pbch_e[(i<<1)>>5]>>((i<<1)&0x1f))&1)<<1) ^ ((pbch->pbch_e[((i<<1)+1)>>5]>>(((i<<1)+1)&0x1f))&1);
mod_pbch_e[i<<1] = nr_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1]; mod_pbch_e[i<<1] = nr_mod_table[(NR_MOD_TABLE_QPSK_OFFSET + idx)<<1];
mod_pbch_e[(i<<1)+1] = nr_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1)+1]; mod_pbch_e[(i<<1)+1] = nr_mod_table[((NR_MOD_TABLE_QPSK_OFFSET + idx)<<1)+1];
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
printf("i %d idx %d mod_pbch %d %d\n", i, idx, mod_pbch_e[2*i], mod_pbch_e[2*i+1]); printf("i %d idx %d mod_pbch %d %d\n", i, idx, mod_pbch_e[2*i], mod_pbch_e[2*i+1]);
#endif #endif
} }
...@@ -374,27 +366,23 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -374,27 +366,23 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
nushift = config->sch_config.physical_cell_id.value &3; nushift = config->sch_config.physical_cell_id.value &3;
a = (config->rf_config.tx_antenna_ports.value == 1) ? amp : (amp*ONE_OVER_SQRT2_Q15)>>15; a = (config->rf_config.tx_antenna_ports.value == 1) ? amp : (amp*ONE_OVER_SQRT2_Q15)>>15;
for (int aa = 0; aa < config->rf_config.tx_antenna_ports.value; aa++) for (int aa = 0; aa < config->rf_config.tx_antenna_ports.value; aa++) {
{
// PBCH modulated symbols are mapped within the SSB block on symbols 1, 2, 3 excluding the subcarriers used for the PBCH DMRS // PBCH modulated symbols are mapped within the SSB block on symbols 1, 2, 3 excluding the subcarriers used for the PBCH DMRS
///symbol 1 [0:239] -- 180 mod symbols ///symbol 1 [0:239] -- 180 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier;
l = ssb_start_symbol + 1; l = ssb_start_symbol + 1;
m = 0; m = 0;
for (int ssb_sc_idx = 0; ssb_sc_idx < 240; ssb_sc_idx++) { for (int ssb_sc_idx = 0; ssb_sc_idx < 240; ssb_sc_idx++) {
if ((ssb_sc_idx&3) == nushift) { //skip DMRS if ((ssb_sc_idx&3) == nushift) { //skip DMRS
k++; k++;
continue; continue;
} } else {
else {
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l); printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15;
k++; k++;
m++; m++;
} }
...@@ -403,23 +391,21 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -403,23 +391,21 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
///symbol 2 [0:47 ; 192:239] -- 72 mod symbols ///symbol 2 [0:47 ; 192:239] -- 72 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier;
l++; l++;
m=180; m=180;
for (int ssb_sc_idx = 0; ssb_sc_idx < 48; ssb_sc_idx++) { for (int ssb_sc_idx = 0; ssb_sc_idx < 48; ssb_sc_idx++) {
if ((ssb_sc_idx&3) == nushift) { if ((ssb_sc_idx&3) == nushift) {
k++; k++;
continue; continue;
} } else {
else {
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l); printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15;
k++; k++;
m++; m++;
} }
...@@ -429,23 +415,22 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -429,23 +415,22 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
} }
k += 144; k += 144;
if (k >= frame_parms->ofdm_symbol_size) if (k >= frame_parms->ofdm_symbol_size)
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
m=216; m=216;
for (int ssb_sc_idx = 192; ssb_sc_idx < 240; ssb_sc_idx++) { for (int ssb_sc_idx = 192; ssb_sc_idx < 240; ssb_sc_idx++) {
if ((ssb_sc_idx&3) == nushift) { if ((ssb_sc_idx&3) == nushift) {
k++; k++;
continue; continue;
} } else {
else {
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l); printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15;
k++; k++;
m++; m++;
} }
...@@ -454,23 +439,21 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -454,23 +439,21 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
///symbol 3 [0:239] -- 180 mod symbols ///symbol 3 [0:239] -- 180 mod symbols
k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier; k = frame_parms->first_carrier_offset + frame_parms->ssb_start_subcarrier;
l++; l++;
m=252; m=252;
for (int ssb_sc_idx = 0; ssb_sc_idx < 240; ssb_sc_idx++) { for (int ssb_sc_idx = 0; ssb_sc_idx < 240; ssb_sc_idx++) {
if ((ssb_sc_idx&3) == nushift) { if ((ssb_sc_idx&3) == nushift) {
k++; k++;
continue; continue;
} } else {
else {
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l); printf("m %d ssb_sc_idx %d at k %d of l %d\n", m, ssb_sc_idx, k, l);
#endif #endif
((int16_t*)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15; ((int16_t *)txdataF[aa])[(l*frame_parms->ofdm_symbol_size + k)<<1] = (a * mod_pbch_e[m<<1]) >> 15;
((int16_t*)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15; ((int16_t *)txdataF[aa])[((l*frame_parms->ofdm_symbol_size + k)<<1) + 1] = (a * mod_pbch_e[(m<<1) + 1]) >> 15;
k++; k++;
m++; m++;
} }
...@@ -478,14 +461,10 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -478,14 +461,10 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
if (k >= frame_parms->ofdm_symbol_size) if (k >= frame_parms->ofdm_symbol_size)
k-=frame_parms->ofdm_symbol_size; k-=frame_parms->ofdm_symbol_size;
} }
} }
#ifdef DEBUG_PBCH #ifdef DEBUG_PBCH
write_output("txdataF_pbch.m", "txdataF_pbch", txdataF[0], frame_parms->samples_per_frame_wCP>>1, 1, 1); write_output("txdataF_pbch.m", "txdataF_pbch", txdataF[0], frame_parms->samples_per_frame_wCP>>1, 1, 1);
#endif #endif
return 0; return 0;
} }
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