From b2add95524de502179abf2bce720793223f581b6 Mon Sep 17 00:00:00 2001 From: yilmazt Date: Sun, 14 Apr 2019 17:38:52 +0200 Subject: [PATCH] Added clean_gNB_ulsch, fully working polartest, and many other minor warning removals. --- cmake_targets/CMakeLists.txt | 4 +- cmake_targets/autotests/test_case_list.xml | 17 +- cmake_targets/build_oai | 2 - openair1/PHY/CODING/TESTBENCH/polartest.c | 473 +++++++----------- .../PHY/CODING/TESTBENCH/smallblocktest.c | 6 +- openair1/PHY/CODING/crc_byte.c | 33 +- .../nrLDPC_decoder/nrLDPC_tools/time_meas.c | 117 ----- .../nrLDPC_decoder/nrLDPC_tools/time_meas.h | 156 ------ .../PHY/CODING/nrLDPC_decoder/nrLDPC_types.h | 2 +- .../nrPolar_tools/nr_bitwise_operations.c | 27 +- .../PHY/CODING/nrPolar_tools/nr_crc_byte.c | 62 +-- .../CODING/nrPolar_tools/nr_polar_decoder.c | 293 +---------- .../PHY/CODING/nrPolar_tools/nr_polar_defs.h | 56 +-- .../CODING/nrPolar_tools/nr_polar_encoder.c | 103 +--- .../CODING/nrSmallBlock/decodeSmallBlock.c | 2 +- openair1/PHY/CODING/nr_polar_init.c | 19 +- openair1/PHY/NR_TRANSPORT/nr_dci.h | 2 - openair1/PHY/NR_TRANSPORT/nr_dlsch.h | 2 + openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 100 +++- .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c | 4 +- openair1/SCHED_NR/fapi_nr_l1.h | 4 +- openair1/SIMULATION/NR_PHY/dlschsim.c | 2 +- openair1/SIMULATION/NR_PHY/dlsim.c | 7 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 16 +- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 8 +- openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h | 4 - 26 files changed, 417 insertions(+), 1104 deletions(-) delete mode 100644 openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c delete mode 100644 openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 253a78726a..f504af1733 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2511,7 +2511,9 @@ add_executable(polartest target_link_libraries(polartest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) -add_executable(smallblocktest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c) +add_executable(smallblocktest + ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/smallblocktest.c + ${OPENAIR_DIR}/common/utils/backtrace.c) target_link_libraries(smallblocktest SIMU PHY PHY_NR PHY_COMMON m ${ATLAS_LIBRARIES}) add_executable(ldpctest diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index c0f8eac447..a970ccbf5d 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1120,16 +1120,15 @@ execution shortblocktest Test cases. (Test1: 3 bits), - (Test2: 6 bits) - (Test3: 7 bits) - (Test4: 11 bits) - + (Test2: 6 bits), + (Test3: 7 bits), + (Test4: 11 bits) $OPENAIR_DIR/targets/bin/smallblocktest.Rel15 - -l 3 - -l 6 - -l 7 - -l 11 - smallblocktest.test1 smallblocktest.test2 smallblocktest.test3 smallblocktest.test3 + -l 3 -s -4 -d 1 -i 10000 + -l 6 -s -4 -d 1 -i 10000 + -l 7 -s -4 -d 1 -i 10000 + -l 11 -s -4 -d 1 -i 10000 + smallblocktest.test1 smallblocktest.test2 smallblocktest.test3 smallblocktest.test4 BLER= 0.000000 segmentation fault|assertion|exiting|fatal 3 diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 4bfa734709..af051abab7 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -80,8 +80,6 @@ function print_help() { This program installs OpenAirInterface Software You should have ubuntu 16.xx or 18.04 updated Options --h - This help -c | --clean Erase all files to make a rebuild from start -C | --clean-all diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index ddcc3ce826..49e71abbc9 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -16,43 +16,11 @@ //#define DEBUG_DCI_POLAR_PARAMS //#define DEBUG_POLAR_TIMING -//#define DEBUG_CRC //#define DEBUG_POLARTEST -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}; - -void nr_init_pbch_interleaver(uint8_t *interleaver) { - uint8_t j_sfn=0, j_hrf=10, j_ssb=11, j_other=14; - memset((void*)interleaver,0, NR_POLAR_PBCH_PAYLOAD_BITS); - - for (uint8_t i=0; i 60) { - printf("Illegal packet bitlength\n",testLength); - exit(-1); - } - - break; + testLength=atoi(optarg); + if (testLength < 12 || testLength > 60) { + printf("Illegal packet bitlength %d \n",testLength); + exit(-1); + } + break; case 'h': - printf("./polartest -s SNRstart -d SNRinc -f SNRstop -m [0=PBCH|1=DCI|2=UCI] -i iterations -l decoderListSize -a pathMetricAppr -L aggregation level (for DCI) -K packet_length (bits) for DCI/UCI\n"); + printf("./polartest\nOptions\n-h Print this help\n-s SNRstart (dB)\n-d SNRinc (dB)\n-f SNRstop (dB)\n-m [0=PBCH|1=DCI|2=UCI]\n" + "-i Number of iterations\n-l decoderListSize\n-a pathMetricAppr\n-q Flag for optimized coders usage\n-F Flag for test results logging\n" + "-L aggregation level (for DCI)\n-K packet_length (bits) for DCI/UCI\n"); exit(-1); break; @@ -140,23 +107,34 @@ int main(int argc, char *argv[]) { break; } + //Initiate timing. (Results depend on CPU Frequency. Therefore, might change due to performance variances during simulation.) + time_stats_t timeEncoder,timeDecoder; + opp_enabled=1; + cpu_freq_GHz = get_cpu_freq_GHz(); + reset_meas(&timeEncoder); + reset_meas(&timeDecoder); + randominit(0); + crcTableInit(); + if (polarMessageType == 0) { //PBCH + aggregation_level = NR_POLAR_PBCH_AGGREGATION_LEVEL; } else if (polarMessageType == 1) { //DCI - coderLength = 108*aggregation_level; + coderLength = 108*aggregation_level; } else if (polarMessageType == -1) { //UCI - printf("UCI testing not supported yet\n"); - exit(-1); + printf("UCI testing not supported yet\n"); + exit(-1); } //Logging time_t currentTime; - time (¤tTime); char fileName[512], currentTimeInfo[25]; char folderName[] = "."; - /* - folderName=getenv("HOME"); - strcat(folderName,"/Desktop/polartestResults"); - */ + FILE *logFile; + /*folderName=getenv("HOME"); + strcat(folderName,"/Desktop/polartestResults");*/ + +if (logFlag){ + time (¤tTime); #ifdef DEBUG_POLAR_TIMING sprintf(fileName,"%s/TIMING_ListSize_%d_pmAppr_%d_Payload_%d_Itr_%d",folderName,decoderListSize,pathMetricAppr,testLength,iterations); #else @@ -165,11 +143,8 @@ int main(int argc, char *argv[]) { strftime(currentTimeInfo, 25, "_%Y-%m-%d-%H-%M-%S.csv", localtime(¤tTime)); strcat(fileName,currentTimeInfo); //Create "~/Desktop/polartestResults" folder if it doesn't already exist. - /* - struct stat folder = {0}; - if (stat(folderName, &folder) == -1) mkdir(folderName, S_IRWXU | S_IRWXG | S_IRWXO); - */ - FILE *logFile; + /*struct stat folder = {0}; + if (stat(folderName, &folder) == -1) mkdir(folderName, S_IRWXU | S_IRWXG | S_IRWXO);*/ logFile = fopen(fileName, "w"); if (logFile==NULL) { @@ -178,11 +153,12 @@ int main(int argc, char *argv[]) { } #ifdef DEBUG_POLAR_TIMING - fprintf(logFile, - ",timeEncoderCRCByte[us],timeEncoderCRCBit[us],timeEncoderInterleaver[us],timeEncoderBitInsertion[us],timeEncoder1[us],timeEncoder2[us],timeEncoderRateMatching[us],timeEncoderByte2Bit[us]\n"); + fprintf(logFile,",timeEncoderCRCByte[us],timeEncoderCRCBit[us],timeEncoderInterleaver[us],timeEncoderBitInsertion[us],timeEncoder1[us],timeEncoder2[us],timeEncoderRateMatching[us],timeEncoderByte2Bit[us]\n"); #else fprintf(logFile,",SNR,nBitError,blockErrorState,t_encoder[us],t_decoder[us]\n"); #endif +} + uint8_t testArrayLength = ceil(testLength / 32.0); uint8_t coderArrayLength = ceil(coderLength / 32.0); uint32_t testInput[testArrayLength]; //generate randomly @@ -196,261 +172,160 @@ int main(int argc, char *argv[]) { double channelOutput[coderLength]; //add noise int16_t channelOutput_int16[coderLength]; t_nrPolar_params *currentPtr = nr_polar_params(polarMessageType, testLength, aggregation_level); + #ifdef DEBUG_DCI_POLAR_PARAMS uint32_t dci_pdu[4]; memset(dci_pdu,0,sizeof(uint32_t)*4); dci_pdu[0]=0x01189400; - printf("dci_pdu: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]); + printf("dci_pdu: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_pdu[0], dci_pdu[1], dci_pdu[2], dci_pdu[3]); + uint16_t size=41; + rnti=3; + aggregation_level=8; uint32_t encoder_output[54]; memset(encoder_output,0,sizeof(uint32_t)*54); - uint16_t size=41; - uint16_t rnti=3; - aggregation_level=8; t_nrPolar_params *currentPtrDCI=nr_polar_params(1, size, aggregation_level); - polar_encoder_dci(dci_pdu, encoder_output, currentPtrDCI, rnti); - for (int i=0; i<54; i++) - printf("encoder_output: [%2d]->0x%08x \n",i, encoder_output[i]); + polar_encoder_dci(dci_pdu, encoder_output, currentPtrDCI, rnti); + for (int i=0; i<54; i++) printf("encoder_output: [%2d]->0x%08x \n", i, encoder_output[i]); uint8_t *encoder_outputByte = malloc(sizeof(uint8_t) * currentPtrDCI->encoderLength); - double *channel_output = malloc (sizeof(double) * currentPtrDCI->encoderLength); - uint32_t dci_estimation[4]; - memset(dci_estimation,0,sizeof(uint32_t)*4); - printf("dci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]); + double *modulated_input = malloc (sizeof(double) * currentPtrDCI->encoderLength); + double *channel_output = malloc (sizeof(double) * currentPtrDCI->encoderLength); + uint32_t dci_est[4]; + memset(dci_est,0,sizeof(uint32_t)*4); + printf("dci_est: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_est[0], dci_est[1], dci_est[2], dci_est[3]); nr_bit2byte_uint32_8(encoder_output, currentPtrDCI->encoderLength, encoder_outputByte); printf("[polartest] encoder_outputByte: "); + for (int i = 0; i < currentPtrDCI->encoderLength; i++) printf("%d-", encoder_outputByte[i]); printf("\n"); - for (int i = 0; i < currentPtrDCI->encoderLength; i++) printf("%d-", encoder_outputByte[i]); - - printf("\n"); - + SNR_lin = pow(10, 0/10); //SNR = 0 dB for(int i=0; iencoderLength; i++) { - if (encoder_outputByte[i] == 0) { - channel_output[i]=1/sqrt(2); - } else { - channel_output[i]=(-1)/sqrt(2); - } + if (encoder_outputByte[i] == 0) + modulated_input[i]=1/sqrt(2); + else + modulated_input[i]=(-1)/sqrt(2); + channel_output[i] = modulated_input[i] + (gaussdouble(0.0,1.0) * (1/sqrt(2*SNR_lin))); } - - decoderState = polar_decoder_dci(channel_output, - dci_estimation, - currentPtrDCI, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - rnti); - printf("dci_estimation: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - dci_estimation[0], dci_estimation[1], dci_estimation[2], dci_estimation[3]); + decoderState = polar_decoder_dci(channel_output, dci_est, currentPtrDCI, NR_POLAR_DECODER_LISTSIZE, NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, rnti); + printf("dci_est: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", dci_est[0], dci_est[1], dci_est[2], dci_est[3]); free(encoder_outputByte); free(channel_output); + free(modulated_input); return 0; #endif -#ifdef DEBUG_CRC - uint32_t crc; - unsigned int poly24c = 0xb2b11700; - uint32_t testInputCRC[4]; - testInputCRC[0]=0x00291880; - //testInputCRC[0]=0x01189400; - testInputCRC[1]=0x00000000; - testInputCRC[2]=0x00000000; - testInputCRC[3]=0x00000000; - uint32_t testInputcrc=0x01189400; - uint32_t testInputcrc2=0x00291880; - uint8_t testInputCRC2[8]; - nr_crc_bit2bit_uint32_8(testInputCRC, 32, testInputCRC2); - printf("testInputCRC2: [0]->%x \t [1]->%x \t [2]->%x \t [3]->%x\n" - " [4]->%x \t [5]->%x \t [6]->%x \t [7]->%x\n", - testInputCRC2[0], testInputCRC2[1], testInputCRC2[2], testInputCRC2[3], - testInputCRC2[4], testInputCRC2[5], testInputCRC2[6], testInputCRC2[7]); - unsigned int crc41 = crc24c(testInputCRC, 32); - unsigned int crc65 = crc24c(testInputCRC, 56); - printf("crc41: [0]->0x%08x\tcrc65: [0]->0x%08x\n",crc41, crc65); - for (int i=0; i<32; i++) printf("crc41[%d]=%d\tcrc65[%d]=%d\n",i,(crc41>>i)&1,i,(crc65>>i)&1); - - crc = crc24c(testInputCRC, testLength)>>8; - - for (int i=0; i<24; i++) printf("[i]=%d\n",(crc>>i)&1); - - printf("crc: [0]->0x%08x\n",crc); - //crcbit(testInputCRC, sizeof(test) - 1, poly24c)); - testInputCRC[testLength>>3] = ((uint8_t *)&crc)[2]; - testInputCRC[1+(testLength>>3)] = ((uint8_t *)&crc)[1]; - testInputCRC[2+(testLength>>3)] = ((uint8_t *)&crc)[0]; - printf("testInputCRC: [0]->0x%08x \t [1]->0x%08x \t [2]->0x%08x \t [3]->0x%08x\n", - testInputCRC[0], testInputCRC[1], testInputCRC[2], testInputCRC[3]); - //uint32_t trial32 = 0xffffffff; - uint32_t trial32 = 0xf10fffff; - uint8_t a[4]; - //memcpy(a, &trial32, sizeof(trial32)); - *(uint32_t *)a = trial32; - unsigned char trial[4]; - trial[0]=0xff; - trial[1]=0xff; - trial[2]=0x0f; - trial[3]=0xf1; - uint32_t trialcrc = crc24c(trial, 32); - uint32_t trialcrc32 = crc24c((uint8_t *)&trial32, 32); - //uint32_t trialcrc32 = crc24c(a, 32); - printf("crcbit(trial = %x\n", crcbit(trial, 4, poly24c)); - printf("trialcrc = %x\n", trialcrc); - printf("trialcrc32 = %x\n", trialcrc32); - - for (int i=0; i<32; i++) printf("trialcrc[%2d]=%d\ttrialcrc32[%2d]=%d\n",i,(trialcrc>>i)&1,i,(trialcrc32>>i)&1); - - //uint8_t nr_polar_A[32] = {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}; - uint8_t nr_polar_A[32] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,1}; - uint8_t nr_polar_crc[24]; - uint8_t **crc_generator_matrix = crc24c_generator_matrix(32); - nr_matrix_multiplication_uint8_1D_uint8_2D(nr_polar_A, - crc_generator_matrix, - nr_polar_crc, - 32, - 24); - - for (uint8_t i = 0; i < 24; i++) { - nr_polar_crc[i] = (nr_polar_crc[i] % 2); - printf("nr_polar_crc[%d]=%d\n",i,nr_polar_crc[i]); - } - - return 0; -#endif -#ifdef DEBUG_POLAR_TIMING - for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { - SNR_lin = pow(10, SNR / 10); - - for (itr = 1; itr <= iterations; itr++) { - for (int j=0; j0x%08x \n", testInput[0]); - polar_encoder_timing(testInput, encoderOutput, currentPtr, cpu_freq_GHz, logFile); - } - } - - fclose(logFile); - free(testInput); - free(encoderOutput); - free(modulatedInput); - free(channelOutput); - free(estimatedOutput); - return (0); -#endif // We assume no a priori knowledge available about the payload. double aPrioriArray[currentPtr->payloadBits]; for (int i=0; ipayloadBits; i++) aPrioriArray[i] = NAN; for (SNR = SNRstart; SNR <= SNRstop; SNR += SNRinc) { - printf("SNR %f\n",SNR); - SNR_lin = pow(10, SNR/10); + printf("SNR %f\n",SNR); + SNR_lin = pow(10, SNR/10); - for (itr = 1; itr <= iterations; itr++) { - for (int i = 0; i < testArrayLength; i++) { - for (int j = 0; j < (sizeof(testInput[0])*8)-1; j++) { - testInput[i] |= ( ((uint32_t) (rand()%2)) &1); - testInput[i]<<=1; - } + for (itr = 1; itr <= iterations; itr++) { + //Generate random values for all the bits of "testInput", not just as much as "currentPtr->payloadBits". + for (int i = 0; i < testArrayLength; i++) { + for (int j = 0; j < (sizeof(testInput[0])*8)-1; j++) { + testInput[i] |= ( ((uint32_t) (rand()%2)) &1); + testInput[i]<<=1; + } + testInput[i] |= ( ((uint32_t) (rand()%2)) &1); + } +#ifdef DEBUG_POLARTEST + //testInput[0] = 0x360f8a5c; + printf("testInput: [0]->0x%08x\n", testInput[0]); + //for (int i=0; i<32; i++) printf("%d-",(testInput[0]>>i)&1); printf("\n"); +#endif + int len_mod64=currentPtr->payloadBits&63; + ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)< PBCH, 1 --> DCI, -1 --> UCI + if (polarMessageType == 0) + polar_encoder(testInput, encoderOutput, currentPtr); + else if (polarMessageType == 1) + polar_encoder_dci(testInput, encoderOutput, currentPtr, rnti); + } + stop_meas(&timeEncoder); - /*printf("testInput: [0]->0x%08x\n", testInput[0]); - for (int i=0; i<32; i++) - printf("%d\n",(testInput[0]>>i)&1);*/ - int len_mod64=currentPtr->payloadBits&63; - ((uint64_t *)testInput)[currentPtr->payloadBits/64]&=((((uint64_t)1)<0x%08x\n", encoderOutput[0]); + //for (int i=1;i0x%08x\n", i, encoderOutput[1]); +#endif - if (decoder_int16==0) { - if (polarMessageType == 0) polar_encoder(testInput, encoderOutput, currentPtr); - else polar_encoder_dci(testInput, encoderOutput, currentPtr, 0); - } - else - polar_encoder_fast((uint64_t *)testInput, encoderOutput,0, currentPtr); - - //polar_encoder_fast((uint64_t*)testInput, (uint64_t*)encoderOutput,0, currentPtr); - stop_meas(&timeEncoder); - /*printf("encoderOutput: [0]->0x%08x\n", encoderOutput[0]); - printf("encoderOutput: [1]->0x%08x\n", encoderOutput[1]);*/ //Bit-to-byte: nr_bit2byte_uint32_8(encoderOutput, coderLength, encoderOutputByte); //BPSK modulation for(int i=0; i 15) channelOutput_int16[i] = 127; - else if (channelOutput[i] < -16) channelOutput_int16[i] = -128; - else channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); - } + if (decoder_int16==1) { + if (channelOutput[i] > 15) channelOutput_int16[i] = 127; + else if (channelOutput[i] < -16) channelOutput_int16[i] = -128; + else channelOutput_int16[i] = (int16_t) (8*channelOutput[i]); + } } start_meas(&timeDecoder); - /*decoderState = polar_decoder(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - aPrioriArray, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION);*/ - if (decoder_int16==0) { - if (polarMessageType == 0) - decoderState = polar_decoder_aPriori(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - aPrioriArray); - else if (polarMessageType == 1) - decoderState = polar_decoder_dci(channelOutput, - estimatedOutput, - currentPtr, - NR_POLAR_DECODER_LISTSIZE, - NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, - 0); + if (decoder_int16==1) { + decoderState = polar_decoder_int16(channelOutput_int16, (uint64_t *)estimatedOutput, currentPtr); + } else { //0 --> PBCH, 1 --> DCI, -1 --> UCI + if (polarMessageType == 0) + decoderState = polar_decoder(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION); + else if (polarMessageType == 1) + decoderState = polar_decoder_dci(channelOutput, + estimatedOutput, + currentPtr, + decoderListSize, + NR_POLAR_DECODER_PATH_METRIC_APPROXIMATION, + rnti); } - else decoderState = polar_decoder_int16(channelOutput_int16, - (uint64_t *)estimatedOutput, - currentPtr); - stop_meas(&timeDecoder); - /*printf("testInput: [0]->0x%08x\n", testInput[0]); - printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]);*/ + +#ifdef DEBUG_POLARTEST + printf("estimatedOutput: [0]->0x%08x\n", estimatedOutput[0]); +#endif //calculate errors if (decoderState!=0) { - blockErrorState=-1; - nBitError=-1; + blockErrorState=-1; + nBitError=-1; } else { - for (int j = 0; j < currentPtr->payloadBits; j++) { - if (((estimatedOutput[0]>>j) & 1) != ((testInput[0]>>j) & 1)) nBitError++; - - // printf("bit %d: %d => %d\n",j,(testInput[0]>>j)&1,(estimatedOutput[0]>>j)&1); - } - - if (nBitError>0) { - blockErrorState=1; - // printf("Error: Input %x, Output %x\n",testInput[0],estimatedOutput[0]); - } + for (int i = 0; i < (testArrayLength-1); i++) { + for (int j = 0; j < 32; j++) { + if ( ((estimatedOutput[i]>>j) & 1) != ((testInput[i]>>j) & 1) ) + nBitError++; + } + } + for (int j = 0; j < testLength - ((testArrayLength-1) * 32); j++) + if ( ((estimatedOutput[(testArrayLength-1)]>>j) & 1) != ((testInput[(testArrayLength-1)]>>j) & 1) ) + nBitError++; } + if (nBitError>0) blockErrorState=1; +#ifdef DEBUG_POLARTEST + for (int i = 0; i < testArrayLength; i++) + printf("[polartest/decoderState=%d] testInput[%d]=0x%08x, estimatedOutput[%d]=0x%08x\n",decoderState, i, testInput[i], i, estimatedOutput[i]); +#endif //Iteration times are in microseconds. timeEncoderCumulative+=(timeEncoder.diff/(cpu_freq_GHz*1000.0)); timeDecoderCumulative+=(timeDecoder.diff/(cpu_freq_GHz*1000.0)); - fprintf(logFile,",%f,%d,%d,%f,%f\n", SNR, nBitError, blockErrorState, - (timeEncoder.diff/(cpu_freq_GHz*1000.0)), (timeDecoder.diff/(cpu_freq_GHz*1000.0))); + if (logFlag) fprintf(logFile,",%f,%d,%d,%f,%f\n", SNR, nBitError, blockErrorState, (timeEncoder.diff/(cpu_freq_GHz*1000.0)), (timeDecoder.diff/(cpu_freq_GHz*1000.0))); if (nBitError<0) { blockErrorCumulative++; @@ -463,6 +338,9 @@ int main(int argc, char *argv[]) { decoderState=0; nBitError=0; blockErrorState=0; + memset(testInput,0,sizeof(uint32_t) * testArrayLength); + memset(encoderOutput,0,sizeof(uint32_t) * coderArrayLength); + memset(estimatedOutput,0,sizeof(uint32_t) * testArrayLength); } //Calculate error statistics for the SNR. @@ -472,8 +350,7 @@ int main(int argc, char *argv[]) { (double)timeEncoder.diff/timeEncoder.trials/(cpu_freq_GHz*1000.0),(double)timeDecoder.diff/timeDecoder.trials/(cpu_freq_GHz*1000.0)); //(timeEncoderCumulative/iterations),timeDecoderCumulative/iterations); - if (blockErrorCumulative==0 && bitErrorCumulative==0) - break; + if (blockErrorCumulative==0 && bitErrorCumulative==0) break; blockErrorCumulative = 0; bitErrorCumulative = 0; @@ -483,6 +360,6 @@ int main(int argc, char *argv[]) { print_meas(&timeEncoder,"polar_encoder",NULL,NULL); print_meas(&timeDecoder,"polar_decoder",NULL,NULL); - fclose(logFile); + if (logFlag) fclose(logFile); return (0); } diff --git a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c index 0b863d2cbf..6278420d8a 100644 --- a/openair1/PHY/CODING/TESTBENCH/smallblocktest.c +++ b/openair1/PHY/CODING/TESTBENCH/smallblocktest.c @@ -127,17 +127,13 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_SMALLBLOCKTEST printf("[smallblocktest] Input = 0x%x, Output = 0x%x, DecoderOutput = 0x%x\n", testInput, encoderOutput, estimatedOutput); for (int i=0;i<32;i++) - printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, Mask[%d] = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (mask>>i)&1); + printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, codingDifference[%d]=%d, Mask[%d] = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (codingDifference>>i)&1, i, (mask>>i)&1); #endif //Error Calculation estimatedOutput &= mask; codingDifference = ((uint32_t)estimatedOutput) ^ testInput; // Count the # of 1's in codingDifference by Brian Kernighan’s algorithm. - //for (int i=0;i<32;i++) - //printf("[smallblocktest] Input[%d] = %d, Output[%d] = %d, codingDifference[%d]=%d, Mask[%d] = %d, bitError = %d\n", i, (testInput>>i)&1, i, (estimatedOutput>>i)&1, i, (codingDifference>>i)&1, i, (mask>>i)&1, nBitError); - - for (nBitError = 0; codingDifference; nBitError++) codingDifference &= codingDifference - 1; diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index bf8d63fb39..9ca5355ab4 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -106,17 +106,6 @@ void crcTableInit (void) } while (++c); } -//Generic version -void crcTable256Init (uint32_t poly, uint32_t* crc256Table) -{ - unsigned char c = 0; - - do { - crc256Table[c] = crcbit(&c, 1, poly); - } while (++c); - -} - /********************************************************* Byte by byte implementations, @@ -236,26 +225,6 @@ crc8 (unsigned char * inptr, int bitlen) return crc; } -//Generic version -unsigned int crcPayload(unsigned char * inptr, int bitlen, uint32_t* crc256Table) -{ - int octetlen, resbit; - unsigned int crc = 0; - octetlen = bitlen/8; // Change in bytes - resbit = (bitlen % 8); - - while (octetlen-- > 0) - { - crc = (crc << 8) ^ crc256Table[(*inptr++) ^ (crc >> 24)]; - } - - if (resbit > 0) - { - crc = (crc << resbit) ^ crc256Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))]; - } - return crc; -} - int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type) { uint32_t crc=0,oldcrc=0; @@ -335,7 +304,7 @@ main() { unsigned char test[] = "Thebigredfox"; crcTableInit(); - printf("%x\n", crcbit(test, sizeof(test) - 1, poly24)); + printf("%x\n", crcbit(test, sizeof(test) - 1, poly24a)); printf("%x\n", crc24(test, (sizeof(test) - 1)*8)); printf("%x\n", crcbit(test, sizeof(test) - 1, poly8)); printf("%x\n", crc8(test, (sizeof(test) - 1)*8)); diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c deleted file mode 100644 index c784188071..0000000000 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#include -#include "time_meas.h" -#include -#include - -// global var for openair performance profiler -extern int opp_enabled; - - -double get_cpu_freq_GHz(void) { - - time_stats_t ts = {0}; - reset_meas(&ts); - ts.trials++; - ts.in = rdtsc_oai(); - sleep(1); - ts.diff = (rdtsc_oai()-ts.in); - cpu_freq_GHz = (double)ts.diff/1000000000; - printf("CPU Freq is %f \n", cpu_freq_GHz); - return cpu_freq_GHz; -} - -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name){ - - if (opp_enabled) { - - //static double cpu_freq_GHz = 3.2; - - //if (cpu_freq_GHz == 0.0) - //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow - - if (ts->trials>0) { - - //fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->diff_now/(cpu_freq_GHz*1000000.0)),subframe,ts->diff_now); - fprintf(file_name,"%15.3f ms, diff_now %15.3f \n",(ts->diff_now/(cpu_freq_GHz*1000000.0)),(double)ts->diff_now); - - } - } -} - -void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time) -{ - - if (opp_enabled) { - - static int first_time = 0; - static double cpu_freq_GHz = 0.0; - - if (cpu_freq_GHz == 0.0) - cpu_freq_GHz = get_cpu_freq_GHz(); - - if (first_time == 0) { - first_time=1; - - if ((total_exec_time == NULL) || (sf_exec_time== NULL)) - fprintf(stderr, "%25s %25s %25s %25s %25s %6f\n","Name","Total","Per Trials", "Num Trials","CPU_F_GHz", cpu_freq_GHz); - else - fprintf(stderr, "%25s %25s %25s %20s %15s %6f\n","Name","Total","Average/Frame","Trials", "CPU_F_GHz", cpu_freq_GHz); - } - - if (ts->trials>0) { - //printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials); - - if ((total_exec_time == NULL) || (sf_exec_time== NULL)) { - fprintf(stderr, "%25s: %15.3f ms ; %15.3f us; %15d;\n", - name, - (ts->diff/cpu_freq_GHz/1000000.0), - (ts->diff/ts->trials/cpu_freq_GHz/1000.0), - ts->trials); - } else { - fprintf(stderr, "%25s: %15.3f ms (%5.2f%%); %15.3f us (%5.2f%%); %15d;\n", - name, - (ts->diff/cpu_freq_GHz/1000000.0), - ((ts->diff/cpu_freq_GHz/1000000.0)/(total_exec_time->diff/cpu_freq_GHz/1000000.0))*100, // percentage - (ts->diff/ts->trials/cpu_freq_GHz/1000.0), - ((ts->diff/ts->trials/cpu_freq_GHz/1000.0)/(sf_exec_time->diff/sf_exec_time->trials/cpu_freq_GHz/1000.0))*100, // percentage - ts->trials); - } - } - } - -} - -double get_time_meas_us(time_stats_t *ts) -{ - - static double cpu_freq_GHz = 0.0; - - if (cpu_freq_GHz == 0.0) - cpu_freq_GHz = get_cpu_freq_GHz(); - - if (ts->trials>0) - return (ts->diff/ts->trials/cpu_freq_GHz/1000.0); - - return 0; -} diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h deleted file mode 100644 index e6bec31176..0000000000 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_tools/time_meas.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -#ifndef __TIME_MEAS_DEFS__H__ -#define __TIME_MEAS_DEFS__H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// global var to enable openair performance profiler -static int opp_enabled = 1; -double cpu_freq_GHz; -#if defined(__x86_64__) || defined(__i386__) - -typedef struct { - - long long in; - long long diff; - long long diff_now; - long long p_time; /*!< \brief absolute process duration */ - long long diff_square; /*!< \brief process duration square */ - long long max; - int trials; - int meas_flag; -} time_stats_t; -#elif defined(__arm__) -typedef struct { - uint32_t in; - uint32_t diff_now; - uint32_t diff; - uint32_t p_time; /*!< \brief absolute process duration */ - uint32_t diff_square; /*!< \brief process duration square */ - uint32_t max; - int trials; -} time_stats_t; - -#endif -static inline void start_meas(time_stats_t *ts) __attribute__((always_inline)); -static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline)); - - -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name); -//void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time); -double get_time_meas_us(time_stats_t *ts); -double get_cpu_freq_GHz(void); - -#if defined(__i386__) -static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ - unsigned long long int x; - __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); - return x; -} -#elif defined(__x86_64__) -static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ - unsigned long long a, d; - __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); - return (d<<32) | a; -} - -#elif defined(__arm__) -static inline uint32_t rdtsc_oai(void) __attribute__((always_inline)); -static inline uint32_t rdtsc_oai(void) -{ - uint32_t r = 0; - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) ); - return r; -} -#endif - -static inline void start_meas(time_stats_t *ts) -{ - - if (opp_enabled) { - if (ts->meas_flag==0) { - ts->trials++; - ts->in = rdtsc_oai(); - ts->meas_flag=1; - } - else { - ts->in = rdtsc_oai(); - } - } -} - -static inline void stop_meas(time_stats_t *ts) -{ - - if (opp_enabled) { - long long out = rdtsc_oai(); - - ts->diff_now = (out-ts->in); - - ts->diff_now = (out-ts->in); - ts->diff += (out-ts->in); - /// process duration is the difference between two clock points - ts->p_time = (out-ts->in); - ts->diff_square += (out-ts->in)*(out-ts->in); - - if ((out-ts->in) > ts->max) - ts->max = out-ts->in; - - ts->meas_flag=0; - } -} - -static inline void reset_meas(time_stats_t *ts) { - - ts->trials=0; - ts->diff=0; - ts->diff_now=0; - ts->p_time=0; - ts->diff_square=0; - ts->max=0; - ts->meas_flag=0; - -} - -static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) -{ - - if (opp_enabled) { - dst_ts->trials=src_ts->trials; - dst_ts->diff=src_ts->diff; - dst_ts->max=src_ts->max; - } -} - -#endif diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h index ae32f6ffb6..a61a15459c 100644 --- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h +++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h @@ -31,7 +31,7 @@ #ifndef __NR_LDPC_TYPES__H__ #define __NR_LDPC_TYPES__H__ -#include "./nrLDPC_tools/time_meas.h" +#include "PHY/TOOLS/time_meas.h" // ============================================================================== // TYPES diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c index a5e78b6f2b..fdba4e1b65 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_bitwise_operations.c @@ -19,6 +19,17 @@ * contact@openairinterface.org */ +/*!\file PHY/CODING/nrPolar_tools/nr_bitwise_operations.c + * \brief + * \author Turker Yilmaz + * \date 2018 + * \version 0.1 + * \company EURECOM + * \email turker.yilmaz@eurecom.fr + * \note + * \warning +*/ + #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { @@ -29,7 +40,8 @@ void nr_bit2byte_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { } } - for (int j = 0; j < arraySize - ((arrayInd-1) * 32); j++) out[j + ((arrayInd-1) * 32)] = (in[(arrayInd-1)] >> j) & 1; + for (int j = 0; j < arraySize - ((arrayInd-1) * 32); j++) + out[j + ((arrayInd-1) * 32)] = (in[(arrayInd-1)] >> j) & 1; } void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out) { @@ -43,16 +55,3 @@ void nr_byte2bit_uint8_32(uint8_t *in, uint16_t arraySize, uint32_t *out) { out[i]|=in[(i*32)]; } } - -void nr_crc_bit2bit_uint32_8(uint32_t *in, uint16_t arraySize, uint8_t *out) { - out[0]=0xff; - out[1]=0xff; - out[2]=0xff; - uint8_t arrayInd = ceil(arraySize / 32.0); - for (int i = 0; i < arrayInd; i++) { - out[3+i*4] = ((in[i] & (0x0000000f))<<4) | ((in[i] & (0x000000f0))>>4); - out[4+i*4] = (((in[i] & (0x00000f00))<<4) | ((in[i] & (0x0000f000))>>4))>>8; - out[5+i*4] = (((in[i] & (0x000f0000))<<4) | ((in[i] & (0x00f00000))>>4))>>16; - out[6+i*4] = (((in[i] & (0x0f000000))<<4) | ((in[i] & (0xf0000000))>>4))>>24; - } -} diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c index ef329b3aaa..461eb7d6f6 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c @@ -21,43 +21,36 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" - // ----- Old implementation ---- uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits){ uint8_t crcPolynomialPattern[25] = {1,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,0,0,0,1,0,1,1,1}; // 1011 0010 1011 0001 0001 0111 D^24 + D^23 + D^21 + D^20 + D^17 + D^15 + D^13 + D^12 + D^8 + D^4 + D^2 + D + 1 - uint8_t crcPolynomialSize = 24;// 24 because crc24c + uint8_t crcPolynomialSize = 24; uint8_t temp1[crcPolynomialSize], temp2[crcPolynomialSize]; uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); if (crc_generator_matrix) - { for (int i = 0; i < payloadSizeBits; i++) - { crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; + temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } - return crc_generator_matrix; } @@ -70,30 +63,26 @@ uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits){ uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); if (crc_generator_matrix) - { for (int i = 0; i < payloadSizeBits; i++) - { crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ + for (int j = 0; j < crcPolynomialSize-1; j++) + temp1[j]=crc_generator_matrix[i+1][j+1]; - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } return crc_generator_matrix; @@ -105,33 +94,30 @@ uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits){ // 0110 0001 D^6 + D^5 + 1 uint8_t crcPolynomialSize = 6; uint8_t temp1[crcPolynomialSize], temp2[crcPolynomialSize]; - uint8_t **crc_generator_matrix = malloc(payloadSizeBits * sizeof(uint8_t *)); - if (crc_generator_matrix) - { - for (int i = 0; i < payloadSizeBits; i++) - { - crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); - } - } - for (int i = 0; i < crcPolynomialSize; i++) crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; + if (crc_generator_matrix) + for (int i = 0; i < payloadSizeBits; i++) + crc_generator_matrix[i] = malloc(crcPolynomialSize * sizeof(uint8_t)); + + for (int i = 0; i < crcPolynomialSize; i++) + crc_generator_matrix[payloadSizeBits-1][i]=crcPolynomialPattern[i+1]; for (int i = payloadSizeBits-2; i >= 0; i--){ + for (int j = 0; j < crcPolynomialSize-1; j++) + temp1[j]=crc_generator_matrix[i+1][j+1]; - for (int j = 0; j < crcPolynomialSize-1; j++) temp1[j]=crc_generator_matrix[i+1][j+1]; temp1[crcPolynomialSize-1]=0; - for (int j = 0; j < crcPolynomialSize; j++) temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; + for (int j = 0; j < crcPolynomialSize; j++) + temp2[j]=crc_generator_matrix[i+1][0]*crcPolynomialPattern[j+1]; for (int j = 0; j < crcPolynomialSize; j++){ - if(temp1[j]+temp2[j] == 1){ + if(temp1[j]+temp2[j] == 1) crc_generator_matrix[i][j]=1; - } else { + else crc_generator_matrix[i][j]=0; - } } - } return crc_generator_matrix; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 5cf044309e..3c32de916e 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -21,11 +21,11 @@ /*!\file PHY/CODING/nrPolar_tools/nr_polar_decoder.c * \brief - * \author Turker Yilmaz + * \author Raymond Knopp, Turker Yilmaz * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email raymond.knopp@eurecom.fr, turker.yilmaz@eurecom.fr * \note * \warning */ @@ -39,12 +39,11 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "assertions.h" -int8_t polar_decoder( - double *input, - uint8_t *out, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr) { +int8_t polar_decoder(double *input, + uint32_t *out, + t_nrPolar_params *polarParams, + uint8_t listSize, + uint8_t pathMetricAppr) { //Assumes no a priori knowledge. uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True @@ -293,7 +292,7 @@ int8_t polar_decoder( /* * Return bits. */ - //nr_byte2bit_uint8_32_t(polarParams->nr_polar_A, polarParams->payloadBits, out); + nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); return(0); } @@ -572,282 +571,6 @@ int8_t polar_decoder_aPriori(double *input, } - -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *out, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE *logFile) { - uint8_t ***bit = nr_alloc_uint8_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **bitUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - uint8_t **llrUpdated = nr_alloc_uint8_2D_array(polarParams->N, (polarParams->n+1)); //0=False, 1=True - double ***llr = nr_alloc_double_3D_array(polarParams->N, (polarParams->n+1), 2*listSize); - uint8_t **crcChecksum = nr_alloc_uint8_2D_array(polarParams->crcParityBits, 2*listSize); - double *pathMetric = malloc(sizeof(double)*(2*listSize)); - uint8_t *crcState = malloc(sizeof(uint8_t)*(2*listSize)); //0=False, 1=True - - for (int i=0; i<(2*listSize); i++) { - pathMetric[i] = 0; - crcState[i]=1; - } - - for (int i=0; iN; i++) { - llrUpdated[i][polarParams->n]=1; - bitUpdated[i][0]=((polarParams->information_bit_pattern[i]+1) % 2); - } - - uint8_t **extended_crc_generator_matrix = malloc(polarParams->K * sizeof(uint8_t *)); //G_P3 - uint8_t **tempECGM = malloc(polarParams->K * sizeof(uint8_t *)); //G_P2 - - for (int i = 0; i < polarParams->K; i++) { - extended_crc_generator_matrix[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - tempECGM[i] = malloc(polarParams->crcParityBits * sizeof(uint8_t)); - } - - for (int i=0; ipayloadBits; i++) { - for (int j=0; jcrcParityBits; j++) { - tempECGM[i][j]=polarParams->crc_generator_matrix[i][j]; - } - } - - for (int i=polarParams->payloadBits; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - if( (i-polarParams->payloadBits) == j ) { - tempECGM[i][j]=1; - } else { - tempECGM[i][j]=0; - } - } - } - - for (int i=0; iK; i++) { - for (int j=0; jcrcParityBits; j++) { - extended_crc_generator_matrix[i][j]=tempECGM[polarParams->interleaving_pattern[i]][j]; - } - } - - //The index of the last 1-valued bit that appears in each column. - uint16_t last1ind[polarParams->crcParityBits]; - - for (int j=0; jcrcParityBits; j++) { - for (int i=0; iK; i++) { - if (extended_crc_generator_matrix[i][j]==1) last1ind[j]=i; - } - } - - double *d_tilde = malloc(sizeof(double) * polarParams->N); - nr_polar_rate_matching(input, d_tilde, polarParams->rate_matching_pattern, polarParams->K, polarParams->N, polarParams->encoderLength); - - for (int j = 0; j < polarParams->N; j++) llr[j][polarParams->n][0]=d_tilde[j]; - - /* - * SCL polar decoder. - */ - uint32_t nonFrozenBit=0; - uint8_t currentListSize=1; - uint8_t decoderIterationCheck=0; - int16_t checkCrcBits=-1; - uint8_t listIndex[2*listSize], copyIndex; - - for (uint16_t currentBit=0; currentBitN; currentBit++) { - updateLLR(llr, llrUpdated, bit, bitUpdated, currentListSize, currentBit, 0, polarParams->N, (polarParams->n+1), pathMetricAppr); - - if (polarParams->information_bit_pattern[currentBit]==0) { //Frozen bit. - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); //approximation=0 --> 11b, approximation=1 --> 12 - } else { //Information or CRC bit. - if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 0) ) { - //Information bit with known value of "0". - updatePathMetric(pathMetric, llr, currentListSize, 0, currentBit, pathMetricAppr); - bitUpdated[currentBit][0]=1; //0=False, 1=True - } else if ( (polarParams->interleaving_pattern[nonFrozenBit] <= polarParams->payloadBits) && - (aPrioriPayload[polarParams->interleaving_pattern[nonFrozenBit]] == 1) ) { - //Information bit with known value of "1". - updatePathMetric(pathMetric, llr, currentListSize, 1, currentBit, pathMetricAppr); - - for (uint8_t i=0; icrcParityBits); - } else { - updatePathMetric2(pathMetric, llr, currentListSize, currentBit, pathMetricAppr); - - for (int i = 0; i < currentListSize; i++) { - for (int j = 0; j < polarParams->N; j++) { - for (int k = 0; k < (polarParams->n+1); k++) { - bit[j][k][i+currentListSize]=bit[j][k][i]; - llr[j][k][i+currentListSize]=llr[j][k][i]; - } - } - } - - for (int i = 0; i < currentListSize; i++) { - bit[currentBit][0][i]=0; - crcState[i+currentListSize]=crcState[i]; - } - - for (int i = currentListSize; i < 2*currentListSize; i++) bit[currentBit][0][i]=1; - - bitUpdated[currentBit][0]=1; - updateCrcChecksum2(crcChecksum, extended_crc_generator_matrix, currentListSize, nonFrozenBit, polarParams->crcParityBits); - currentListSize*=2; - - //Keep only the best "listSize" number of entries. - if (currentListSize > listSize) { - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - //sort listIndex[listSize, ..., 2*listSize-1] in descending order. - uint8_t swaps, tempInd; - - for (uint8_t i = 0; i < listSize; i++) { - swaps = 0; - - for (uint8_t j = listSize; j < (2*listSize - i) - 1; j++) { - if (listIndex[j+1] > listIndex[j]) { - tempInd = listIndex[j]; - listIndex[j] = listIndex[j + 1]; - listIndex[j + 1] = tempInd; - swaps++; - } - } - - if (swaps == 0) - break; - } - - //First, backup the best "listSize" number of entries. - for (int k=(listSize-1); k>0; k--) { - for (int i=0; iN; i++) { - for (int j=0; j<(polarParams->n+1); j++) { - bit[i][j][listIndex[(2*listSize-1)-k]]=bit[i][j][listIndex[k]]; - llr[i][j][listIndex[(2*listSize-1)-k]]=llr[i][j][listIndex[k]]; - } - } - } - - for (int k=(listSize-1); k>0; k--) { - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][listIndex[(2*listSize-1)-k]] = crcChecksum[i][listIndex[k]]; - } - } - - for (int k=(listSize-1); k>0; k--) crcState[listIndex[(2*listSize-1)-k]]=crcState[listIndex[k]]; - - //Copy the best "listSize" number of entries to the first indices. - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->N; i++) { - for (int j = 0; j < (polarParams->n + 1); j++) { - bit[i][j][k] = bit[i][j][copyIndex]; - llr[i][j][k] = llr[i][j][copyIndex]; - } - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - for (int i = 0; i < polarParams->crcParityBits; i++) { - crcChecksum[i][k]=crcChecksum[i][copyIndex]; - } - } - - for (int k = 0; k < listSize; k++) { - if (k > listIndex[k]) { - copyIndex = listIndex[(2*listSize-1)-k]; - } else { //Use the backup. - copyIndex = listIndex[k]; - } - - crcState[k]=crcState[copyIndex]; - } - - currentListSize = listSize; - } - } - - for (int i=0; icrcParityBits; i++) { - if (last1ind[i]==nonFrozenBit) { - checkCrcBits=i; - break; - } - } - - if ( checkCrcBits > (-1) ) { - for (uint8_t i = 0; i < currentListSize; i++) { - if (crcChecksum[checkCrcBits][i]==1) { - crcState[i]=0; //0=False, 1=True - } - } - } - - for (uint8_t i = 0; i < currentListSize; i++) decoderIterationCheck+=crcState[i]; - - if (decoderIterationCheck==0) { - //perror("[SCL polar decoder] All list entries have failed the CRC checks."); - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - return(-1); - } - - nonFrozenBit++; - decoderIterationCheck=0; - checkCrcBits=-1; - } - } - - for (uint8_t i = 0; i < 2*listSize; i++) listIndex[i]=i; - - nr_sort_asc_double_1D_array_ind(pathMetric, listIndex, currentListSize); - - for (uint8_t i = 0; i < fmin(listSize, (pow(2,polarParams->crcCorrectionBits)) ); i++) { - if ( crcState[listIndex[i]] == 1 ) { - for (int j = 0; j < polarParams->N; j++) polarParams->nr_polar_U[j]=bit[j][0][listIndex[i]]; - - //Extract the information bits (û to ĉ) - nr_polar_info_bit_extraction(polarParams->nr_polar_U, polarParams->nr_polar_CPrime, polarParams->information_bit_pattern, polarParams->N); - //Deinterleaving (ĉ to b) - nr_polar_deinterleaver(polarParams->nr_polar_CPrime, polarParams->nr_polar_B, polarParams->interleaving_pattern, polarParams->K); - - //Remove the CRC (â) - for (int j = 0; j < polarParams->payloadBits; j++) polarParams->nr_polar_A[j]=polarParams->nr_polar_B[j]; - - break; - } - } - - free(d_tilde); - free(pathMetric); - free(crcState); - nr_free_uint8_3D_array(bit, polarParams->N, (polarParams->n+1)); - nr_free_double_3D_array(llr, polarParams->N, (polarParams->n+1)); - nr_free_uint8_2D_array(crcChecksum, polarParams->crcParityBits); - nr_free_uint8_2D_array(extended_crc_generator_matrix, polarParams->K); - nr_free_uint8_2D_array(tempECGM, polarParams->K); - /* - * Return bits. - */ - nr_byte2bit_uint8_32(polarParams->nr_polar_A, polarParams->payloadBits, out); - return(0); -} - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h index f6c66e89dc..675015a712 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_defs.h @@ -21,11 +21,11 @@ /*!\file PHY/CODING/nrPolar_tools/nr_polar_defs.h * \brief - * \author Turker Yilmaz + * \author Raymond Knopp, Turker Yilmaz * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email raymond.knopp@eurecom.fr, turker.yilmaz@eurecom.fr * \note * \warning */ @@ -105,7 +105,7 @@ struct nrPolar_params { int16_t *Q_PC_N; uint8_t *information_bit_pattern; uint16_t *channel_interleaver_pattern; - uint32_t crc_polynomial; + //uint32_t crc_polynomial; uint8_t **crc_generator_matrix; //G_P uint8_t **G_N; @@ -116,7 +116,6 @@ struct nrPolar_params { uint64_t cprime_tab1[32][256]; uint64_t B_tab0[32][256]; uint64_t B_tab1[32][256]; - uint32_t *crc256Table; uint8_t **extended_crc_generator_matrix; //lowercase: bits, Uppercase: Bits stored in bytes //polar_encoder vectors @@ -151,7 +150,7 @@ void polar_encoder_fast(uint64_t *A, t_nrPolar_params *polarParams); int8_t polar_decoder(double *input, - uint8_t *output, + uint32_t *output, t_nrPolar_params *polarParams, uint8_t listSize, uint8_t pathMetricAppr); @@ -167,15 +166,6 @@ int8_t polar_decoder_aPriori(double *input, uint8_t pathMetricAppr, double *aPrioriPayload); -int8_t polar_decoder_aPriori_timing(double *input, - uint32_t *output, - t_nrPolar_params *polarParams, - uint8_t listSize, - uint8_t pathMetricAppr, - double *aPrioriPayload, - double cpuFreqGHz, - FILE *logFile); - int8_t polar_decoder_dci(double *input, uint32_t *out, t_nrPolar_params *polarParams, @@ -192,9 +182,9 @@ void init_polar_deinterleaver_table(t_nrPolar_params *polarParams); void nr_polar_print_polarParams(t_nrPolar_params *polarParams); -t_nrPolar_params *nr_polar_params ( int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level); +t_nrPolar_params *nr_polar_params (int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level); uint16_t nr_polar_aggregation_prime (uint8_t aggregation_level); @@ -256,16 +246,18 @@ void nr_polar_info_bit_extraction(uint8_t *input, uint16_t size); void nr_bit2byte_uint32_8(uint32_t *in, - uint16_t arraySize, - uint8_t *out); + uint16_t arraySize, + uint8_t *out); void nr_byte2bit_uint8_32(uint8_t *in, - uint16_t arraySize, - uint32_t *out); + uint16_t arraySize, + uint32_t *out); -void nr_crc_bit2bit_uint32_8(uint32_t *in, - uint16_t arraySize, - uint8_t *out); +uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits); + +uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits); + +uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits); void nr_polar_bit_insertion(uint8_t *input, uint8_t *output, @@ -370,12 +362,6 @@ void updateCrcChecksum2(uint8_t **crcChecksum, uint32_t i2, uint8_t len); -uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits); - -uint8_t **crc11_generator_matrix(uint16_t payloadSizeBits); - -uint8_t **crc6_generator_matrix(uint16_t payloadSizeBits); - //Also nr_polar_rate_matcher static inline void nr_polar_interleaver(uint8_t *input, uint8_t *output, @@ -385,12 +371,10 @@ static inline void nr_polar_interleaver(uint8_t *input, } static inline void nr_polar_deinterleaver(uint8_t *input, - uint8_t *output, - uint16_t *pattern, - uint16_t size) { - for (int i=0; ipayloadBits)>>8); #endif nr_bit2byte_uint32_8_t((uint32_t*)&B, polarParams->K, polarParams->nr_polar_B);*/ - nr_bit2byte_uint32_8((uint32_t *)in, polarParams->payloadBits, polarParams->nr_polar_A); + nr_bit2byte_uint32_8(in, polarParams->payloadBits, polarParams->nr_polar_A); /* * Bytewise operations */ //Calculate CRC. nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_A, - polarParams->crc_generator_matrix, - polarParams->nr_polar_crc, - polarParams->payloadBits, - polarParams->crcParityBits); + polarParams->crc_generator_matrix, + polarParams->nr_polar_crc, + polarParams->payloadBits, + polarParams->crcParityBits); for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2); @@ -78,6 +77,8 @@ void polar_encoder(uint32_t *in, for (int i = 0; iK; i++) B2 = B2 | ((uint64_t)polarParams->nr_polar_B[i] << i); printf("polar_B %llx\n",B2); + for (int i=0; i< polarParams->payloadBits; i++) printf("a[%d]=%d\n", i, polarParams->nr_polar_A[i]); + for (int i=0; i< polarParams->K; i++) printf("b[%d]=%d\n", i, polarParams->nr_polar_B[i]); #endif /* for (int j=0;jcrcParityBits;j++) { for (int i=0;ipayloadBits;i++) @@ -116,10 +117,10 @@ void polar_encoder(uint32_t *in, polarParams->nr_polar_U[247]=1; polarParams->nr_polar_U[253]=1;*/ nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_U, - polarParams->G_N, - polarParams->nr_polar_D, - polarParams->N, - polarParams->N); + polarParams->G_N, + polarParams->nr_polar_D, + polarParams->N, + polarParams->N); for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); @@ -169,35 +170,29 @@ void polar_encoder_dci(uint32_t *in, #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] A: "); - for (int i=0; ipayloadBits; i++) printf("%d-", polarParams->nr_polar_A[i]); - printf("\n"); + printf("[polar_encoder_dci] APrime: "); - for (int i=0; iK; i++) printf("%d-", polarParams->nr_polar_APrime[i]); - printf("\n"); + printf("[polar_encoder_dci] GP: "); - for (int i=0; icrcParityBits; i++) printf("%d-", polarParams->crc_generator_matrix[0][i]); - printf("\n"); #endif //Calculate CRC. nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_APrime, - polarParams->crc_generator_matrix, - polarParams->nr_polar_crc, - polarParams->K, - polarParams->crcParityBits); + polarParams->crc_generator_matrix, + polarParams->nr_polar_crc, + polarParams->K, + polarParams->crcParityBits); for (uint8_t i = 0; i < polarParams->crcParityBits; i++) polarParams->nr_polar_crc[i] = (polarParams->nr_polar_crc[i] % 2); #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] CRC: "); - for (int i=0; icrcParityBits; i++) printf("%d-", polarParams->nr_polar_crc[i]); - printf("\n"); #endif @@ -209,55 +204,16 @@ void polar_encoder_dci(uint32_t *in, polarParams->nr_polar_B[i]= polarParams->nr_polar_crc[i-(polarParams->payloadBits)]; //Scrambling (b to c) - for (int i=0; i<16; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+8+i] = - ( polarParams->nr_polar_B[polarParams->payloadBits+8+i] + ((n_RNTI>>(15-i))&1) ) % 2; - } + for (int i=0; i<16; i++) + polarParams->nr_polar_B[polarParams->payloadBits+8+i]=( polarParams->nr_polar_B[polarParams->payloadBits+8+i] + ((n_RNTI>>(15-i))&1) ) % 2; - /* //(a to a') - nr_crc_bit2bit_uint32_8_t(in, polarParams->payloadBits, polarParams->nr_polar_aPrime); - //Parity bits computation (p) - polarParams->crcBit = crc24c(polarParams->nr_polar_aPrime, (polarParams->payloadBits+polarParams->crcParityBits)); - #ifdef DEBUG_POLAR_ENCODER_DCI - printf("[polar_encoder_dci] crc: 0x%08x\n", polarParams->crcBit); - for (int i=0; i<32; i++) - { - printf("%d\n",((polarParams->crcBit)>>i)&1); - } - #endif - //(a to b) - // - // Bytewise operations - // - uint8_t arrayInd = ceil(polarParams->payloadBits / 8.0); - for (int i=0; inr_polar_B[j+(i*8)] = ((polarParams->nr_polar_aPrime[3+i]>>(7-j)) & 1); - } - } - for (int i=0; i<((polarParams->payloadBits)%8); i++) { - polarParams->nr_polar_B[i+(arrayInd-1)*8] = ((polarParams->nr_polar_aPrime[3+(arrayInd-1)]>>(7-i)) & 1); - } - for (int i=0; i<8; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+i] = ((polarParams->crcBit)>>(31-i))&1; - } - //Scrambling (b to c) - for (int i=0; i<16; i++) { - polarParams->nr_polar_B[polarParams->payloadBits+8+i] = - ( (((polarParams->crcBit)>>(23-i))&1) + ((n_RNTI>>(15-i))&1) ) % 2; - }*/ #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] B: "); - for (int i = 0; i < polarParams->K; i++) printf("%d-", polarParams->nr_polar_B[i]); - printf("\n"); #endif //Interleaving (c to c') - nr_polar_interleaver(polarParams->nr_polar_B, - polarParams->nr_polar_CPrime, - polarParams->interleaving_pattern, - polarParams->K); + nr_polar_interleaver(polarParams->nr_polar_B, polarParams->nr_polar_CPrime, polarParams->interleaving_pattern, polarParams->K); //Bit insertion (c' to u) nr_polar_bit_insertion(polarParams->nr_polar_CPrime, polarParams->nr_polar_U, @@ -268,13 +224,11 @@ void polar_encoder_dci(uint32_t *in, polarParams->n_pc); //Encoding (u to d) nr_matrix_multiplication_uint8_1D_uint8_2D(polarParams->nr_polar_U, - polarParams->G_N, - polarParams->nr_polar_D, - polarParams->N, - polarParams->N); - - for (uint16_t i = 0; i < polarParams->N; i++) - polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); + polarParams->G_N, + polarParams->nr_polar_D, + polarParams->N, + polarParams->N); + for (uint16_t i = 0; i < polarParams->N; i++) polarParams->nr_polar_D[i] = (polarParams->nr_polar_D[i] % 2); //Rate matching //Sub-block interleaving (d to y) and Bit selection (y to e) @@ -288,16 +242,11 @@ void polar_encoder_dci(uint32_t *in, nr_byte2bit_uint8_32(polarParams->nr_polar_E, polarParams->encoderLength, out); #ifdef DEBUG_POLAR_ENCODER_DCI printf("[polar_encoder_dci] E: "); - for (int i = 0; i < polarParams->encoderLength; i++) printf("%d-", polarParams->nr_polar_E[i]); uint8_t outputInd = ceil(polarParams->encoderLength / 32.0); printf("\n[polar_encoder_dci] out: "); - - for (int i = 0; i < outputInd; i++) { - printf("[%d]->0x%08x\t", i, out[i]); - } - + for (int i = 0; i < outputInd; i++) printf("[%d]->0x%08x\t", i, out[i]); #endif } diff --git a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c index 8b53944455..3dd570cc18 100644 --- a/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c +++ b/openair1/PHY/CODING/nrSmallBlock/decodeSmallBlock.c @@ -48,7 +48,7 @@ uint16_t decodeSmallBlock(int8_t *in, uint8_t len){ int16_t Rhat[NR_SMALL_BLOCK_CODED_BITS] = {0}, Rhatabs[NR_SMALL_BLOCK_CODED_BITS] = {0}; uint16_t maxVal; uint8_t maxInd = 0; - int jmax = (1<<(len-1)); + uint8_t jmax = (1<<(len-1)); for (int j = 0; j < jmax; ++j) for (int k = 0; k < NR_SMALL_BLOCK_CODED_BITS; ++k) Rhat[j] += in[k] * hadamard32InterleavedTransposed[j][k]; diff --git a/openair1/PHY/CODING/nr_polar_init.c b/openair1/PHY/CODING/nr_polar_init.c index dd0056b3b5..f158d44303 100644 --- a/openair1/PHY/CODING/nr_polar_init.c +++ b/openair1/PHY/CODING/nr_polar_init.c @@ -21,19 +21,16 @@ /*!\file PHY/CODING/nr_polar_init.h * \brief - * \author Turker Yilmaz + * \author Turker Yilmaz, Raymond Knopp * \date 2018 * \version 0.1 * \company EURECOM - * \email turker.yilmaz@eurecom.fr + * \email turker.yilmaz@eurecom.fr, raymond.knopp@eurecom.fr * \note * \warning */ -#include "nrPolar_tools/nr_polar_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h" -#include "PHY/CODING/nrPolar_tools/nr_polar_pbch_defs.h" +#include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" #include "PHY/NR_TRANSPORT/nr_dci.h" static int intcmp(const void *p1,const void *p2) { @@ -95,7 +92,9 @@ static void nr_polar_init(t_nrPolar_params * *polarParams, } newPolarInitNode->K = newPolarInitNode->payloadBits + newPolarInitNode->crcParityBits; // Number of bits to encode. - newPolarInitNode->N = nr_polar_output_length(newPolarInitNode->K, newPolarInitNode->encoderLength, newPolarInitNode->n_max); + newPolarInitNode->N = nr_polar_output_length(newPolarInitNode->K, + newPolarInitNode->encoderLength, + newPolarInitNode->n_max); newPolarInitNode->n = log2(newPolarInitNode->N); newPolarInitNode->G_N = nr_polar_kronecker_power_matrices(newPolarInitNode->n); //polar_encoder vectors: @@ -182,9 +181,9 @@ void nr_polar_print_polarParams(t_nrPolar_params *polarParams) { return; } -t_nrPolar_params *nr_polar_params ( int8_t messageType, - uint16_t messageLength, - uint8_t aggregation_level) { +t_nrPolar_params *nr_polar_params (int8_t messageType, + uint16_t messageLength, + uint8_t aggregation_level) { static t_nrPolar_params *polarList = NULL; nr_polar_init(&polarList, messageType,messageLength,aggregation_level); t_nrPolar_params *polarParams=polarList; diff --git a/openair1/PHY/NR_TRANSPORT/nr_dci.h b/openair1/PHY/NR_TRANSPORT/nr_dci.h index 21fcd06c09..f53f5be282 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dci.h +++ b/openair1/PHY/NR_TRANSPORT/nr_dci.h @@ -25,8 +25,6 @@ #include "PHY/defs_gNB.h" #include "PHY/NR_REFSIG/nr_refsig.h" -typedef unsigned __int128 uint128_t; - uint16_t nr_get_dci_size(nfapi_nr_dci_format_e format, nfapi_nr_rnti_type_e rnti_type, uint16_t N_RB, diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h index 06969eded0..102062f698 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.h +++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.h @@ -96,6 +96,8 @@ void free_gNB_dlsch(NR_gNB_DLSCH_t *dlsch); void clean_gNB_dlsch(NR_gNB_DLSCH_t *dlsch); +void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch); + int nr_dlsch_encoding(unsigned char *a, uint8_t subframe, NR_gNB_DLSCH_t *dlsch, diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index ace93e4ee3..bd6acb16d3 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -171,6 +171,104 @@ NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint8_t N_RB_UL, uint8 return(NULL); } +void clean_gNB_ulsch(NR_gNB_ULSCH_t *ulsch) +{ + unsigned char i, j; + + if (ulsch) { + ulsch->harq_mask = 0; + ulsch->bundling = 0; + ulsch->beta_offset_cqi_times8 = 0; + ulsch->beta_offset_ri_times8 = 0; + ulsch->beta_offset_harqack_times8 = 0; + ulsch->Msg3_active = 0; + ulsch->Msg3_flag = 0; + ulsch->Msg3_subframe = 0; + ulsch->Msg3_frame = 0; + ulsch->rnti = 0; + ulsch->rnti_type = 0; + ulsch->cyclicShift = 0; + ulsch->cooperation_flag = 0; + ulsch->Mlimit = 0; + ulsch->max_ldpc_iterations = 0; + ulsch->last_iteration_cnt = 0; + ulsch->num_active_cba_groups = 0; + for (i=0;icba_rnti[i] = 0; + for (i=0;iharq_process_id[i] = 0; + + for (i=0; iharq_processes[i]){ + /// Nfapi ULSCH PDU + //nfapi_nr_ul_config_ulsch_pdu ulsch_pdu; + ulsch->harq_processes[i]->frame=0; + ulsch->harq_processes[i]->subframe=0; + ulsch->harq_processes[i]->round=0; + ulsch->harq_processes[i]->TPC=0; + ulsch->harq_processes[i]->mimo_mode=0; + ulsch->harq_processes[i]->dci_alloc=0; + ulsch->harq_processes[i]->rar_alloc=0; + ulsch->harq_processes[i]->status=0; + ulsch->harq_processes[i]->subframe_scheduling_flag=0; + ulsch->harq_processes[i]->subframe_cba_scheduling_flag=0; + ulsch->harq_processes[i]->phich_active=0; + ulsch->harq_processes[i]->phich_ACK=0; + ulsch->harq_processes[i]->previous_first_rb=0; + ulsch->harq_processes[i]->handled=0; + ulsch->harq_processes[i]->delta_TF=0; + + ulsch->harq_processes[i]->TBS=0; + /// Pointer to the payload (38.212 V15.4.0 section 5.1) + //uint8_t *b; + ulsch->harq_processes[i]->B=0; + /// Pointers to code blocks after code block segmentation and CRC attachment (38.212 V15.4.0 section 5.2.2) + //uint8_t *c[MAX_NUM_NR_ULSCH_SEGMENTS]; + ulsch->harq_processes[i]->K=0; + ulsch->harq_processes[i]->F=0; + ulsch->harq_processes[i]->C=0; + /// Pointers to code blocks after LDPC coding (38.212 V15.4.0 section 5.3.2) + //int16_t *d[MAX_NUM_NR_ULSCH_SEGMENTS]; + /// LDPC processing buffer + //t_nrLDPC_procBuf* p_nrLDPC_procBuf[MAX_NUM_NR_ULSCH_SEGMENTS]; + ulsch->harq_processes[i]->Z=0; + /// code blocks after bit selection in rate matching for LDPC code (38.212 V15.4.0 section 5.4.2.1) + //int16_t e[MAX_NUM_NR_DLSCH_SEGMENTS][3*8448]; + ulsch->harq_processes[i]->E; + ulsch->harq_processes[i]->G; + + + ulsch->harq_processes[i]->n_DMRS=0; + ulsch->harq_processes[i]->n_DMRS2=0; + ulsch->harq_processes[i]->previous_n_DMRS=0; + + + ulsch->harq_processes[i]->cqi_crc_status=0; + for (j=0;jharq_processes[i]->o[j]=0; + ulsch->harq_processes[i]->uci_format=0; + ulsch->harq_processes[i]->Or1=0; + ulsch->harq_processes[i]->Or2=0; + ulsch->harq_processes[i]->o_RI[0]=0; ulsch->harq_processes[i]->o_RI[1]=0; + ulsch->harq_processes[i]->O_RI=0; + ulsch->harq_processes[i]->o_ACK[0]=0; ulsch->harq_processes[i]->o_ACK[1]=0; + ulsch->harq_processes[i]->o_ACK[2]=0; ulsch->harq_processes[i]->o_ACK[3]=0; + ulsch->harq_processes[i]->O_ACK=0; + ulsch->harq_processes[i]->V_UL_DAI=0; + /// "q" sequences for CQI/PMI (for definition see 36-212 V8.6 2009-03, p.27) + //int8_t q[MAX_CQI_PAYLOAD]; + ulsch->harq_processes[i]->o_RCC=0; + /// coded and interleaved CQI bits + //int8_t o_w[(MAX_CQI_BITS+8)*3]; + /// coded CQI bits + //int8_t o_d[96+((MAX_CQI_BITS+8)*3)]; + for (j=0;jharq_processes[i]->q_ACK[j]=0; + for (j=0;jharq_processes[i]->q_RI[j]=0; + /// Temporary h sequence to flag PUSCH_x/PUSCH_y symbols which are not scrambled + //uint8_t h[MAX_NUM_CHANNEL_BITS]; + /// soft bits for each received segment ("w"-sequence)(for definition see 36-212 V8.6 2009-03, p.15) + //int16_t w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)]; + } + } + } +} uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, uint8_t UE_id, @@ -608,4 +706,4 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, ulsch->last_iteration_cnt = ret; return(ret); -} \ No newline at end of file +} diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c index 70a34f2c66..7abca59014 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c @@ -39,6 +39,7 @@ #include "PHY/CODING/nrLDPC_encoder/defs.h" #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h" #include "common/utils/LOG/vcd_signal_dumper.h" +#include "PHY/NR_TRANSPORT/nr_dlsch.h" @@ -92,7 +93,7 @@ NR_UE_ULSCH_t *new_nr_ue_ulsch(unsigned char N_RB_UL, int number_of_harq_pids, u { NR_UE_ULSCH_t *ulsch; - unsigned char exit_flag = 0,i,j,r; + unsigned char exit_flag = 0,i,r; unsigned char bw_scaling =1; switch (N_RB_UL) { @@ -211,7 +212,6 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch, uint32_t Tbslbrm; uint8_t nb_re_dmrs; uint16_t length_dmrs; - int i; float Coderate; /////////// diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 66eb0fada7..1cd268c3eb 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -32,7 +32,9 @@ #include "PHY/defs_gNB.h" #include "PHY/phy_extern.h" -#include "PHY/LTE_TRANSPORT/transport_proto.h" +//#include "PHY/LTE_TRANSPORT/transport_proto.h" +//#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" #include "SCHED/sched_eNB.h" #include "SCHED/sched_common.h" #include "SCHED_NR/sched_nr.h" diff --git a/openair1/SIMULATION/NR_PHY/dlschsim.c b/openair1/SIMULATION/NR_PHY/dlschsim.c index 1404fb79f4..b1502c7852 100644 --- a/openair1/SIMULATION/NR_PHY/dlschsim.c +++ b/openair1/SIMULATION/NR_PHY/dlschsim.c @@ -494,7 +494,7 @@ int main(int argc, char **argv) { unsigned char *test_input_bit = malloc16(sizeof(unsigned char) * 16 * 68 * 384); unsigned int errors_bit = 0; test_input_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); - estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); + //estimated_output = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); estimated_output_bit = (unsigned char *) malloc16(sizeof(unsigned char) * 16 * 68 * 384); NR_UE_DLSCH_t *dlsch0_ue = UE->dlsch[0][0][0]; NR_DL_UE_HARQ_t *harq_process = dlsch0_ue->harq_processes[harq_pid]; diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index c9a8d58b04..4cdf4bed38 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -42,11 +42,13 @@ #include "PHY/MODULATION/modulation_UE.h" #include "PHY/INIT/phy_init.h" #include "PHY/NR_TRANSPORT/nr_transport.h" -//#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +#include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h" +//openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h #include "SCHED_NR/sched_nr.h" #include "SCHED_NR_UE/fapi_nr_ue_l1.h" #include "SCHED_NR/fapi_nr_l1.h" +#include "SCHED_NR_UE/defs.h" #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h" #include "LAYER2/NR_MAC_UE/mac_defs.h" @@ -58,6 +60,7 @@ #include "LAYER2/NR_MAC_UE/mac_proto.h" //#include "LAYER2/NR_MAC_gNB/mac_proto.h" //#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h" +#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h" #include "RRC/NR/MESSAGES/asn1_msg.h" @@ -515,7 +518,7 @@ int main(int argc, char **argv) gNB_mac = RC.nrmac[0]; config_common(0,0,Nid_cell,78,ssb_pattern,(uint64_t)3640000000L,N_RB_DL); - config_nr_mib(0,0,1,kHz30,0,0,0,0); + config_nr_mib(0,0,1,kHz30,0,0,0,0,0); nr_l2_init_ue(); UE_mac = get_mac_inst(0); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index f9d157ace5..e485b4ba41 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -387,20 +387,20 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, // Note: This should not be done in the MAC! for (int ii=0; iiulsch[ii]; + NR_gNB_ULSCH_t *ulsch = RC.gNB[module_idP][CC_id]->ulsch[ii][0]; if((ulsch != NULL) && (ulsch->rnti == rnti)){ LOG_I(MAC, "clean_eNb_ulsch UE %x \n", rnti); - clean_eNb_ulsch(ulsch); + clean_gNB_ulsch(ulsch); } } for (int ii=0; iidlsch[ii][0]; - if((dlsch != NULL) && (dlsch->rnti == rnti)){ - LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); - LOG_E(PHY,"Calling with wrong paramter type\n"); - clean_eNb_dlsch(dlsch); - } + NR_gNB_DLSCH_t *dlsch = RC.gNB[module_idP][CC_id]->dlsch[ii][0]; + if((dlsch != NULL) && (dlsch->rnti == rnti)){ + LOG_I(MAC, "clean_eNb_dlsch UE %x \n", rnti); + LOG_E(PHY,"Calling with wrong parameter type\n"); + clean_gNB_dlsch(dlsch); + } } for(int j = 0; j < 10; j++){ diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 99452c4c7a..6d55ec8139 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -53,10 +53,12 @@ void config_nr_mib(int Mod_idP, void config_common(int Mod_idP, int CC_idP, + int Nid_cell, int nr_bandP, + uint64_t ssb_pattern, uint64_t dl_CarrierFreqP, uint32_t dl_BandwidthP - ); + ); int rrc_mac_config_req_gNB(module_id_t Mod_idP, int CC_id, @@ -89,6 +91,10 @@ void nr_schedule_css_dlsch_phytest(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP); +void nr_schedule_uss_dlsch_phytest(module_id_t module_idP, + frame_t frameP, + sub_frame_t slotP); + void nr_configure_css_dci_initial(nfapi_nr_dl_config_pdcch_parameters_rel15_t* pdcch_params, nr_scs_e scs_common, diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h index 6cd15fd32b..456f06a5ed 100644 --- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h @@ -171,8 +171,4 @@ typedef struct gNB_MAC_INST_s { time_stats_t schedule_pch; } gNB_MAC_INST; -void nr_schedule_css_dlsch_phytest(module_id_t module_idP, - frame_t frameP, - sub_frame_t subframeP); - #endif /*__LAYER2_NR_MAC_GNB_H__ */