diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index ce23ac73a3..e66710f1bb 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1091,7 +1091,7 @@ set(PHY_POLARSRC ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_crc_byte.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_bit_insertion.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_channel_interleaver_pattern.c - ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_crc.c + # ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_crc.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_decoding_tools.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_info_bit_pattern.c ${OPENAIR1_DIR}/PHY/CODING/nrPolar_tools/nr_polar_interleaving_pattern.c @@ -2367,7 +2367,7 @@ target_link_libraries (dlsim_tm4 ) add_executable(polartest ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/polartest.c) -target_link_libraries(polartest m SIMU PHY PHY_NR -lm ${ATLAS_LIBRARIES}) +target_link_libraries(polartest m SIMU PHY PHY_NR PHY_COMMON -lm ${ATLAS_LIBRARIES}) foreach(myExe dlsim dlsim_tm7 ulsim pbchsim scansim mbmssim pdcchsim pucchsim prachsim syncsim) diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index 0e1f0e065f..505ced5e71 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -33,14 +33,17 @@ #include "coding_defs.h" - /*ref 36-212 v8.6.0 , pp 8-9 */ /* the highest degree is set by default */ unsigned int poly24a = 0x864cfb00; //1000 0110 0100 1100 1111 1011 D^24 + D^23 + D^18 + D^17 + D^14 + D^11 + D^10 + D^7 + D^6 + D^5 + D^4 + D^3 + D + 1 unsigned int poly24b = 0x80006300; // 1000 0000 0000 0000 0110 0011 D^24 + D^23 + D^6 + D^5 + D + 1 +uint32_t poly24c = 0xB2B11700; //101100101011000100010111 unsigned int poly16 = 0x10210000; // 0001 0000 0010 0001 D^16 + D^12 + D^5 + 1 unsigned int poly12 = 0x80F00000; // 1000 0000 1111 D^12 + D^11 + D^3 + D^2 + D + 1 unsigned int poly8 = 0x9B000000; // 1001 1011 D^8 + D^7 + D^4 + D^3 + D + 1 +uint32_t poly6 = 0x84000000; // 10000100000... -> D^6+D^5+1 +uint32_t poly11 = 0xc4200000; //11000100001000... -> D^11+D^10+D^9+D^5+1 + /********************************************************* For initialization && verification purposes, @@ -93,6 +96,18 @@ void crcTableInit (void) crc8Table[c] = (unsigned char) (crcbit (&c, 1, poly8) >> 24); } 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, @@ -193,6 +208,71 @@ 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; +} + +void nr_crc_computation(uint8_t* input, uint8_t* output, uint16_t payloadBits, uint16_t crcParityBits, uint32_t* crc256Table) +{ + //Create payload in bit + uint8_t* input2 = (uint8_t*)malloc(payloadBits); //divided by 8 (in bits) + uint8_t mask = 128; // 10000000 + + for(uint8_t ind=0; ind<(payloadBits/8); ind++) + { + input2[ind]=0; + for(uint8_t ind2=0; ind2<8; ind2++) + { + if(input[8*ind+ind2]) + { + input2[ind] = input2[ind] | mask; + } + mask= mask >> 1; + } + mask=128; + } + + //crcTable256Init(poly); + + unsigned int crcBits; + crcBits = crcPayload(input2, payloadBits, crc256Table); + + //create crc in byte + unsigned int mask2=0x80000000; //100... + output = (uint8_t*)malloc(sizeof(uint8_t)*crcParityBits); + + for(uint8_t ind=0; ind> 1; + } + +} + + + + + #ifdef DEBUG_CRC /*******************************************************************/ /** diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c index a12bb33413..7b5a1c922a 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_crc_byte.c @@ -21,10 +21,11 @@ #include "PHY/CODING/nrPolar_tools/nr_polar_defs.h" +/* // ----- New implementation ---- -uint32_t poly6 = 0x84000000; // 1000100000... -> D^6+D^5+1 -uint32_t poly11 = 0x63200000; //11000100001000... -> D^11+D^10+D^9+D^5+1 -uint32_t poly16 = 0x81080000; //100000010000100... - > D^16+D^12+D^5+1 +uint32_t poly6 = 0x84000000; // 10000100000... -> D^6+D^5+1 +uint32_t poly11 = 0xc4200000; //11000100001000... -> D^11+D^10+D^9+D^5+1 +uint32_t poly16 = 0x10210000; //00100000010000100... - > D^16+D^12+D^5+1 uint32_t poly24a = 0x864cfb00; //100001100100110011111011 -> D^24+D^23+D^18+D^17+D^14+D^11+D^10+D^7+D^6+D^5+D^4+D^3+D+1 uint32_t poly24b = 0x80006300; //100000000000000001100011 -> D^24+D^23+D^6+D^5+D+1 uint32_t poly24c = 0xB2B11700; //101100101011000100010111 -> D^24... @@ -91,7 +92,7 @@ unsigned int crcbit (unsigned char* inputptr, int octetlen, unsigned int poly) return crc; } -/* + void crcTableInit (void) { unsigned char c = 0; @@ -106,7 +107,7 @@ void crcTableInit (void) } while (++c); } -*/ + void crcTable256Init (uint32_t poly, uint32_t* crc256Table) { unsigned char c = 0; @@ -114,14 +115,14 @@ void crcTable256Init (uint32_t poly, uint32_t* crc256Table) do { crc256Table[c] = crcbit(&c, 1, poly); -/* - crc6Table[c] = crcbit(&c, 1, poly6); - crc11Table[c]= crcbit(&c, 1, poly11); - crc16Table[c] =crcbit(&c, 1, poly16); - crc24aTable[c]=crcbit(&c, 1, poly24a); - crc24bTable[c]=crcbit(&c, 1, poly24b); - crc24cTable[c]=crcbit(&c, 1, poly24c); -*/ + +// crc6Table[c] = crcbit(&c, 1, poly6); + // crc11Table[c]= crcbit(&c, 1, poly11); +// crc16Table[c] =crcbit(&c, 1, poly16); +// crc24aTable[c]=crcbit(&c, 1, poly24a); +// crc24bTable[c]=crcbit(&c, 1, poly24b); +// crc24cTable[c]=crcbit(&c, 1, poly24c); + } while (++c); //return crc256Table; @@ -145,7 +146,7 @@ unsigned int crcPayload(unsigned char * inptr, int bitlen, uint32_t* crc256Table } return crc; } - +*/ // ----- Old implementation ---- uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits){ diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_kernal_operation.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_kernal_operation.c index 489cf8fe6e..f9117cdaa4 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_kernal_operation.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_kernal_operation.c @@ -16,10 +16,10 @@ void nr_polar_kernal_operation(uint8_t *u, uint8_t *d, uint16_t N) d[i]=0; for(j=0; j