Commit 48f92bdf authored by Francesco Mani's avatar Francesco Mani

Merge branch 'nr_pdcch_crc_fix' into nr-interdigital-test

parents 5eb7621f 2a5109d6
...@@ -241,8 +241,8 @@ if (logFlag){ ...@@ -241,8 +241,8 @@ if (logFlag){
start_meas(&timeEncoder); start_meas(&timeEncoder);
if (decoder_int16==1) { if (decoder_int16==1) {
polar_encoder_fast((uint64_t *)testInput, encoderOutput, 0, currentPtr); polar_encoder_fast((uint64_t *)testInput, encoderOutput, 0, 0, currentPtr);
//polar_encoder_fast((uint64_t*)testInput, (uint64_t*)encoderOutput,0, currentPtr); //polar_encoder_fast((uint64_t*)testInput, (uint64_t*)encoderOutput,0,0,currentPtr);
} else { //0 --> PBCH, 1 --> DCI, -1 --> UCI } else { //0 --> PBCH, 1 --> DCI, -1 --> UCI
if (polarMessageType == 0) if (polarMessageType == 0)
polar_encoder(testInput, encoderOutput, currentPtr); polar_encoder(testInput, encoderOutput, currentPtr);
...@@ -278,7 +278,7 @@ if (logFlag){ ...@@ -278,7 +278,7 @@ if (logFlag){
start_meas(&timeDecoder); start_meas(&timeDecoder);
if (decoder_int16==1) { if (decoder_int16==1) {
decoderState = polar_decoder_int16(channelOutput_int16, (uint64_t *)estimatedOutput, currentPtr); decoderState = polar_decoder_int16(channelOutput_int16, (uint64_t *)estimatedOutput, 0, currentPtr);
} else { //0 --> PBCH, 1 --> DCI, -1 --> UCI } else { //0 --> PBCH, 1 --> DCI, -1 --> UCI
if (polarMessageType == 0) { if (polarMessageType == 0) {
decoderState = polar_decoder(channelOutput, decoderState = polar_decoder(channelOutput,
......
...@@ -601,6 +601,7 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) { ...@@ -601,6 +601,7 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) {
uint32_t polar_decoder_int16(int16_t *input, uint32_t polar_decoder_int16(int16_t *input,
uint64_t *out, uint64_t *out,
uint8_t ones_flag,
const t_nrPolar_params *polarParams) const t_nrPolar_params *polarParams)
{ {
int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N); int16_t d_tilde[polarParams->N];// = malloc(sizeof(double) * polarParams->N);
...@@ -650,28 +651,42 @@ uint32_t polar_decoder_int16(int16_t *input, ...@@ -650,28 +651,42 @@ uint32_t polar_decoder_int16(int16_t *input,
uint64_t Ar = 0; uint64_t Ar = 0;
AssertFatal(len<65,"A must be less than 65 bits\n"); AssertFatal(len<65,"A must be less than 65 bits\n");
// appending 24 ones before a0 for DCI as stated in 38.212 7.3.2
uint8_t offset = 0;
if (ones_flag) offset = 3;
if (len<=32) { if (len<=32) {
Ar = (uint32_t)(B[0]>>crclen); Ar = (uint32_t)(B[0]>>crclen);
uint8_t A32_flip[4]; uint8_t A32_flip[4+offset];
if (ones_flag) {
A32_flip[0] = 0xff;
A32_flip[1] = 0xff;
A32_flip[2] = 0xff;
}
uint32_t Aprime= (uint32_t)(Ar<<(32-len)); uint32_t Aprime= (uint32_t)(Ar<<(32-len));
A32_flip[0]=((uint8_t *)&Aprime)[3]; A32_flip[0+offset]=((uint8_t *)&Aprime)[3];
A32_flip[1]=((uint8_t *)&Aprime)[2]; A32_flip[1+offset]=((uint8_t *)&Aprime)[2];
A32_flip[2]=((uint8_t *)&Aprime)[1]; A32_flip[2+offset]=((uint8_t *)&Aprime)[1];
A32_flip[3]=((uint8_t *)&Aprime)[0]; A32_flip[3+offset]=((uint8_t *)&Aprime)[0];
crc = (uint64_t)(crc24c(A32_flip,len)>>8); crc = (uint64_t)(crc24c(A32_flip,8*offset+len)>>8);
} else if (len<=64) { } else if (len<=64) {
Ar = (B[0]>>crclen) | (B[1]<<(64-crclen));; Ar = (B[0]>>crclen) | (B[1]<<(64-crclen));;
uint8_t A64_flip[8]; uint8_t A64_flip[8+offset];
uint64_t Aprime= (uint32_t)(Ar<<(64-len)); if (ones_flag) {
A64_flip[0]=((uint8_t *)&Aprime)[7]; A64_flip[0] = 0xff;
A64_flip[1]=((uint8_t *)&Aprime)[6]; A64_flip[1] = 0xff;
A64_flip[2]=((uint8_t *)&Aprime)[5]; A64_flip[2] = 0xff;
A64_flip[3]=((uint8_t *)&Aprime)[4]; }
A64_flip[4]=((uint8_t *)&Aprime)[3]; uint64_t Aprime= (uint64_t)(Ar<<(64-len));
A64_flip[5]=((uint8_t *)&Aprime)[2]; A64_flip[0+offset]=((uint8_t *)&Aprime)[7];
A64_flip[6]=((uint8_t *)&Aprime)[1]; A64_flip[1+offset]=((uint8_t *)&Aprime)[6];
A64_flip[7]=((uint8_t *)&Aprime)[0]; A64_flip[2+offset]=((uint8_t *)&Aprime)[5];
crc = (uint64_t)(crc24c(A64_flip,len)>>8); A64_flip[3+offset]=((uint8_t *)&Aprime)[4];
A64_flip[4+offset]=((uint8_t *)&Aprime)[3];
A64_flip[5+offset]=((uint8_t *)&Aprime)[2];
A64_flip[6+offset]=((uint8_t *)&Aprime)[1];
A64_flip[7+offset]=((uint8_t *)&Aprime)[0];
crc = (uint64_t)(crc24c(A64_flip,8*offset+len)>>8);
} }
#if 0 #if 0
......
...@@ -148,6 +148,7 @@ void polar_encoder_dci(uint32_t *in, ...@@ -148,6 +148,7 @@ void polar_encoder_dci(uint32_t *in,
void polar_encoder_fast(uint64_t *A, void polar_encoder_fast(uint64_t *A,
uint32_t *out, uint32_t *out,
int32_t crcmask, int32_t crcmask,
uint8_t ones_flag,
t_nrPolar_params *polarParams); t_nrPolar_params *polarParams);
int8_t polar_decoder(double *input, int8_t polar_decoder(double *input,
...@@ -157,6 +158,7 @@ int8_t polar_decoder(double *input, ...@@ -157,6 +158,7 @@ int8_t polar_decoder(double *input,
uint32_t polar_decoder_int16(int16_t *input, uint32_t polar_decoder_int16(int16_t *input,
uint64_t *out, uint64_t *out,
uint8_t ones_flag,
const t_nrPolar_params *polarParams); const t_nrPolar_params *polarParams);
int8_t polar_decoder_dci(double *input, int8_t polar_decoder_dci(double *input,
......
...@@ -410,6 +410,7 @@ void build_polar_tables(t_nrPolar_params *polarParams) { ...@@ -410,6 +410,7 @@ void build_polar_tables(t_nrPolar_params *polarParams) {
void polar_encoder_fast(uint64_t *A, void polar_encoder_fast(uint64_t *A,
uint32_t *out, uint32_t *out,
int32_t crcmask, int32_t crcmask,
uint8_t ones_flag,
t_nrPolar_params *polarParams) { t_nrPolar_params *polarParams) {
AssertFatal(polarParams->K > 32, "K = %d < 33, is not supported yet\n",polarParams->K); AssertFatal(polarParams->K > 32, "K = %d < 33, is not supported yet\n",polarParams->K);
AssertFatal(polarParams->K < 129, "K = %d > 128, is not supported yet\n",polarParams->K); AssertFatal(polarParams->K < 129, "K = %d > 128, is not supported yet\n",polarParams->K);
...@@ -421,6 +422,10 @@ void polar_encoder_fast(uint64_t *A, ...@@ -421,6 +422,10 @@ void polar_encoder_fast(uint64_t *A,
AssertFatal(polarParams->crcParityBits == 24,"support for 24-bit crc only for now\n"); AssertFatal(polarParams->crcParityBits == 24,"support for 24-bit crc only for now\n");
//int bitlen0=bitlen; //int bitlen0=bitlen;
uint64_t tcrc=0; uint64_t tcrc=0;
uint8_t offset = 0;
// appending 24 ones before a0 for DCI as stated in 38.212 7.3.2
if (ones_flag) offset = 3;
// A bit string should be stored as 0, 0, ..., 0, a'_0, a'_1, ..., a'_A-1, // A bit string should be stored as 0, 0, ..., 0, a'_0, a'_1, ..., a'_A-1,
//???a'_{N-1} a'_{N-2} ... a'_{N-A} 0 .... 0, where N=64,128,192,..., N is smallest multiple of 64 greater than or equal to A //???a'_{N-1} a'_{N-2} ... a'_{N-A} 0 .... 0, where N=64,128,192,..., N is smallest multiple of 64 greater than or equal to A
...@@ -428,38 +433,53 @@ void polar_encoder_fast(uint64_t *A, ...@@ -428,38 +433,53 @@ void polar_encoder_fast(uint64_t *A,
// First flip A bitstring byte endian for CRC routines (optimized for DLSCH/ULSCH, not PBCH/PDCCH) // First flip A bitstring byte endian for CRC routines (optimized for DLSCH/ULSCH, not PBCH/PDCCH)
// CRC reads in each byte in bit positions 7 down to 0, for PBCH/PDCCH we need to read in a_{A-1} down to a_{0}, A = length of bit string (e.g. 32 for PBCH) // CRC reads in each byte in bit positions 7 down to 0, for PBCH/PDCCH we need to read in a_{A-1} down to a_{0}, A = length of bit string (e.g. 32 for PBCH)
if (bitlen<=32) { if (bitlen<=32) {
uint8_t A32_flip[4]; uint8_t A32_flip[4+offset];
if (ones_flag) {
A32_flip[0] = 0xff;
A32_flip[1] = 0xff;
A32_flip[2] = 0xff;
}
uint32_t Aprime= (uint32_t)(((uint32_t)*A)<<(32-bitlen)); uint32_t Aprime= (uint32_t)(((uint32_t)*A)<<(32-bitlen));
A32_flip[0]=((uint8_t *)&Aprime)[3]; A32_flip[0+offset]=((uint8_t *)&Aprime)[3];
A32_flip[1]=((uint8_t *)&Aprime)[2]; A32_flip[1+offset]=((uint8_t *)&Aprime)[2];
A32_flip[2]=((uint8_t *)&Aprime)[1]; A32_flip[2+offset]=((uint8_t *)&Aprime)[1];
A32_flip[3]=((uint8_t *)&Aprime)[0]; A32_flip[3+offset]=((uint8_t *)&Aprime)[0];
tcrc = (uint64_t)((crcmask^(crc24c(A32_flip,bitlen)>>8))); tcrc = (uint64_t)((crcmask^(crc24c(A32_flip,8*offset+bitlen)>>8)));
} else if (bitlen<=64) { } else if (bitlen<=64) {
uint8_t A64_flip[8]; uint8_t A64_flip[8+offset];
uint64_t Aprime= (uint32_t)(((uint64_t)*A)<<(64-bitlen)); if (ones_flag) {
A64_flip[0]=((uint8_t *)&Aprime)[7]; A64_flip[0] = 0xff;
A64_flip[1]=((uint8_t *)&Aprime)[6]; A64_flip[1] = 0xff;
A64_flip[2]=((uint8_t *)&Aprime)[5]; A64_flip[2] = 0xff;
A64_flip[3]=((uint8_t *)&Aprime)[4]; }
A64_flip[4]=((uint8_t *)&Aprime)[3]; uint64_t Aprime= (uint64_t)(((uint64_t)*A)<<(64-bitlen));
A64_flip[5]=((uint8_t *)&Aprime)[2]; A64_flip[0+offset]=((uint8_t *)&Aprime)[7];
A64_flip[6]=((uint8_t *)&Aprime)[1]; A64_flip[1+offset]=((uint8_t *)&Aprime)[6];
A64_flip[7]=((uint8_t *)&Aprime)[0]; A64_flip[2+offset]=((uint8_t *)&Aprime)[5];
tcrc = (uint64_t)((crcmask^(crc24c(A64_flip,bitlen)>>8))); A64_flip[3+offset]=((uint8_t *)&Aprime)[4];
A64_flip[4+offset]=((uint8_t *)&Aprime)[3];
A64_flip[5+offset]=((uint8_t *)&Aprime)[2];
A64_flip[6+offset]=((uint8_t *)&Aprime)[1];
A64_flip[7+offset]=((uint8_t *)&Aprime)[0];
tcrc = (uint64_t)((crcmask^(crc24c(A64_flip,8*offset+bitlen)>>8)));
} }
else if (bitlen<=128) { else if (bitlen<=128) {
uint8_t A128_flip[16]; uint8_t A128_flip[16+offset];
uint128_t Aprime= (uint32_t)(((uint128_t)*A)<<(128-bitlen)); if (ones_flag) {
A128_flip[0]=((uint8_t*)&Aprime)[15]; A128_flip[1]=((uint8_t*)&Aprime)[14]; A128_flip[0] = 0xff;
A128_flip[2]=((uint8_t*)&Aprime)[13]; A128_flip[3]=((uint8_t*)&Aprime)[12]; A128_flip[1] = 0xff;
A128_flip[4]=((uint8_t*)&Aprime)[11]; A128_flip[5]=((uint8_t*)&Aprime)[10]; A128_flip[2] = 0xff;
A128_flip[6] =((uint8_t*)&Aprime)[9]; A128_flip[7] =((uint8_t*)&Aprime)[8]; }
A128_flip[8] =((uint8_t*)&Aprime)[7]; A128_flip[9] =((uint8_t*)&Aprime)[6]; uint128_t Aprime= (uint128_t)(((uint128_t)*A)<<(128-bitlen));
A128_flip[10]=((uint8_t*)&Aprime)[5]; A128_flip[11]=((uint8_t*)&Aprime)[4]; A128_flip[0+offset]=((uint8_t*)&Aprime)[15]; A128_flip[1+offset]=((uint8_t*)&Aprime)[14];
A128_flip[12]=((uint8_t*)&Aprime)[3]; A128_flip[13]=((uint8_t*)&Aprime)[2]; A128_flip[2+offset]=((uint8_t*)&Aprime)[13]; A128_flip[3+offset]=((uint8_t*)&Aprime)[12];
A128_flip[14]=((uint8_t*)&Aprime)[1]; A128_flip[15]=((uint8_t*)&Aprime)[0]; A128_flip[4+offset]=((uint8_t*)&Aprime)[11]; A128_flip[5+offset]=((uint8_t*)&Aprime)[10];
tcrc = (uint64_t)((crcmask^(crc24c(A128_flip,bitlen)>>8))); A128_flip[6+offset] =((uint8_t*)&Aprime)[9]; A128_flip[7+offset] =((uint8_t*)&Aprime)[8];
A128_flip[8+offset] =((uint8_t*)&Aprime)[7]; A128_flip[9+offset] =((uint8_t*)&Aprime)[6];
A128_flip[10+offset]=((uint8_t*)&Aprime)[5]; A128_flip[11+offset]=((uint8_t*)&Aprime)[4];
A128_flip[12+offset]=((uint8_t*)&Aprime)[3]; A128_flip[13+offset]=((uint8_t*)&Aprime)[2];
A128_flip[14+offset]=((uint8_t*)&Aprime)[1]; A128_flip[15+offset]=((uint8_t*)&Aprime)[0];
tcrc = (uint64_t)((crcmask^(crc24c(A128_flip,8*offset+bitlen)>>8)));
} }
int n; int n;
...@@ -473,7 +493,6 @@ void polar_encoder_fast(uint64_t *A, ...@@ -473,7 +493,6 @@ void polar_encoder_fast(uint64_t *A,
//??? b_{N'-1} b_{N'-2} ... b_{N'-A} b_{N'-A-1} ... b_{N'-A-Nparity} = a_{N-1} a_{N-2} ... a_{N-A} p_{N_parity-1} ... p_0 //??? b_{N'-1} b_{N'-2} ... b_{N'-A} b_{N'-A-1} ... b_{N'-A-Nparity} = a_{N-1} a_{N-2} ... a_{N-A} p_{N_parity-1} ... p_0
for (n=0; n<quadwlen; n++) if (n==0) B[n] = (A[n] << polarParams->crcParityBits) | tcrc; for (n=0; n<quadwlen; n++) if (n==0) B[n] = (A[n] << polarParams->crcParityBits) | tcrc;
else B[n] = (A[n] << polarParams->crcParityBits) | (A[n-1]>>(64-polarParams->crcParityBits)); else B[n] = (A[n] << polarParams->crcParityBits) | (A[n-1]>>(64-polarParams->crcParityBits));
......
...@@ -214,7 +214,7 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars, ...@@ -214,7 +214,7 @@ uint8_t nr_generate_dci_top(NR_gNB_PDCCH pdcch_vars,
uint16_t Nid = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)? uint16_t Nid = (pdcch_params.search_space_type == NFAPI_NR_SEARCH_SPACE_TYPE_UE_SPECIFIC)?
pdcch_params.scrambling_id : config.sch_config.physical_cell_id.value; pdcch_params.scrambling_id : config.sch_config.physical_cell_id.value;
t_nrPolar_params *currentPtr = nr_polar_params(NR_POLAR_DCI_MESSAGE_TYPE, dci_alloc.size, dci_alloc.L); t_nrPolar_params *currentPtr = nr_polar_params(NR_POLAR_DCI_MESSAGE_TYPE, dci_alloc.size, dci_alloc.L);
polar_encoder_fast(dci_alloc.dci_pdu, encoder_output, pdcch_params.rnti,currentPtr); polar_encoder_fast(dci_alloc.dci_pdu, encoder_output, pdcch_params.rnti, 1, currentPtr);
#ifdef DEBUG_CHANNEL_CODING #ifdef DEBUG_CHANNEL_CODING
printf("polar rnti %d\n",pdcch_params.rnti); printf("polar rnti %d\n",pdcch_params.rnti);
printf("DCI PDU: [0]->0x%lx \t [1]->0x%lx\n", printf("DCI PDU: [0]->0x%lx \t [1]->0x%lx\n",
......
...@@ -298,7 +298,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch, ...@@ -298,7 +298,7 @@ int nr_generate_pbch(NR_gNB_PBCH *pbch,
a_reversed |= (((uint64_t)pbch->pbch_a_prime>>i)&1)<<(31-i); a_reversed |= (((uint64_t)pbch->pbch_a_prime>>i)&1)<<(31-i);
/// CRC, coding and rate matching /// CRC, coding and rate matching
polar_encoder_fast (&a_reversed, (uint32_t *)pbch->pbch_e, 0, polar_encoder_fast (&a_reversed, (uint32_t *)pbch->pbch_e, 0, 0,
nr_polar_params( NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL) nr_polar_params( NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL)
); );
#ifdef DEBUG_PBCH_ENCODING #ifdef DEBUG_PBCH_ENCODING
......
...@@ -1338,6 +1338,7 @@ void nr_dci_decoding_procedure0(int s, ...@@ -1338,6 +1338,7 @@ void nr_dci_decoding_procedure0(int s,
const t_nrPolar_params *currentPtrDCI=nr_polar_params(1, sizeof_bits, L2); const t_nrPolar_params *currentPtrDCI=nr_polar_params(1, sizeof_bits, L2);
decoderState = polar_decoder_int16(&pdcch_vars[eNB_id]->e_rx[CCEind*9*6*2], decoderState = polar_decoder_int16(&pdcch_vars[eNB_id]->e_rx[CCEind*9*6*2],
dci_estimation, dci_estimation,
1,
currentPtrDCI); currentPtrDCI);
crc = decoderState; crc = decoderState;
//crc = (crc16(&dci_decoded_output[current_thread_id][0], sizeof_bits) >> 16) ^ extract_crc(&dci_decoded_output[current_thread_id][0], sizeof_bits); //crc = (crc16(&dci_decoded_output[current_thread_id][0], sizeof_bits) >> 16) ^ extract_crc(&dci_decoded_output[current_thread_id][0], sizeof_bits);
......
...@@ -538,7 +538,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, ...@@ -538,7 +538,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue,
nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0,0); nr_pbch_unscrambling(nr_ue_pbch_vars,frame_parms->Nid_cell,nushift,M,NR_POLAR_PBCH_E,0,0);
//polar decoding de-rate matching //polar decoding de-rate matching
const t_nrPolar_params *currentPtr = nr_polar_params( NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL); const t_nrPolar_params *currentPtr = nr_polar_params( NR_POLAR_PBCH_MESSAGE_TYPE, NR_POLAR_PBCH_PAYLOAD_BITS, NR_POLAR_PBCH_AGGREGATION_LEVEL);
decoderState = polar_decoder_int16(pbch_e_rx,(uint64_t *)&nr_ue_pbch_vars->pbch_a_prime,currentPtr); decoderState = polar_decoder_int16(pbch_e_rx,(uint64_t *)&nr_ue_pbch_vars->pbch_a_prime,0,currentPtr);
if(decoderState) return(decoderState); if(decoderState) return(decoderState);
......
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