diff --git a/ci-scripts/cppcheck_suppressions.list b/ci-scripts/cppcheck_suppressions.list index cad2aab88b4374811490153c509e941b2a2e4e57..727fd22e745ceb031a0c65938827efc49cab13dc 100644 --- a/ci-scripts/cppcheck_suppressions.list +++ b/ci-scripts/cppcheck_suppressions.list @@ -37,6 +37,7 @@ memleak:openair2/UTIL/OMG/omg_hashtable.c // _emm_as_encode function creates the encoded buffer // memleak:openair3/NAS/UE/EMM/SAP/emm_as.c +memleak:openair1/PHY/INIT/nr_init_ue.c //----------------------------------------------------------------------------- //***************************************************************************** // section for files not used in oai exec's included in CI. diff --git a/ci-scripts/ran.py b/ci-scripts/ran.py index dd2c2915282a5de2b57c3b348bd1f601043f560e..9c66b1863c2659997e734417ae79daa13b0f23a5 100644 --- a/ci-scripts/ran.py +++ b/ci-scripts/ran.py @@ -807,6 +807,8 @@ class RANManagement(): uciStatMsgCount = 0 pdcpFailure = 0 ulschFailure = 0 + ulschAllocateCCEerror = 0 + uplinkSegmentsAborted = 0 ulschReceiveOK = 0 gnbRxTxWakeUpFailure = 0 cdrxActivationMessageCount = 0 @@ -925,6 +927,12 @@ class RANManagement(): result = re.search('ULSCH in error in round|ULSCH 0 in error', str(line)) if result is not None: ulschFailure += 1 + result = re.search('ERROR ALLOCATING CCEs', str(line)) + if result is not None: + ulschAllocateCCEerror += 1 + result = re.search('uplink segment error.*aborted [1-9] segments', str(line)) + if result is not None: + uplinkSegmentsAborted += 1 result = re.search('ULSCH received ok', str(line)) if result is not None: ulschReceiveOK += 1 @@ -968,6 +976,14 @@ class RANManagement(): statMsg = nodeB_prefix + 'NB showed ' + str(ulschFailure) + ' "ULSCH in error in round" message(s)' logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') htmleNBFailureMsg += statMsg + '\n' + if ulschAllocateCCEerror > 0: + statMsg = nodeB_prefix + 'NB showed ' + str(ulschAllocateCCEerror) + ' "eNB_dlsch_ulsch_scheduler(); ERROR ALLOCATING CCEs" message(s)' + logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') + htmleNBFailureMsg += statMsg + '\n' + if uplinkSegmentsAborted > 0: + statMsg = nodeB_prefix + 'NB showed ' + str(uplinkSegmentsAborted) + ' "uplink segment error 0/2, aborted * segments" message(s)' + logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') + htmleNBFailureMsg += statMsg + '\n' if dropNotEnoughRBs > 0: statMsg = 'eNB showed ' + str(dropNotEnoughRBs) + ' "dropping, not enough RBs" message(s)' logging.debug('\u001B[1;30;43m ' + statMsg + ' \u001B[0m') diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml index 7be0d28e33568f00da83335d0aedc8cf7dadabb2..346aa8bfefa15edd9ca47cfd2f4a3cc3ad2267aa 100644 --- a/cmake_targets/autotests/test_case_list.xml +++ b/cmake_targets/autotests/test_case_list.xml @@ -1036,7 +1036,9 @@ <testCase id="015103"> <class>execution</class> <desc>polartest Test cases. (Test1: PBCH polar test), - (Test2: DCI polar test)</desc> + (Test2: DCI polar test), + (Test3: UCI polar test,6-bit CRC), + (Test4: UCI polar test,11-bit CRC)</desc> <pre_compile_prog></pre_compile_prog> <compile_prog>$OPENAIR_DIR/cmake_targets/build_oai</compile_prog> <compile_prog_args> --phy_simulators -c </compile_prog_args> @@ -1044,8 +1046,10 @@ <pre_exec_args></pre_exec_args> <main_exec> $OPENAIR_DIR/targets/bin/polartest.Rel15</main_exec> <main_exec_args>-q -s-10 -f0 - -q -s-10 -f0 -m1</main_exec_args> - <tags>polartest.test1 polartest.test2</tags> + -q -s-10 -f0 -m1 + -q -s-2 -f2 -m2 -k12 + -q -s-2 -f2 -m2 -k20</main_exec_args> + <tags>polartest.test1 polartest.test2 polartest.test3 polartest.test4</tags> <search_expr_true>BLER= 0.000000</search_expr_true> <search_expr_false>segmentation fault|assertion|exiting|fatal</search_expr_false> <nruns>3</nruns> @@ -1186,15 +1190,20 @@ <desc>nr_pucchsim Test cases. (Test1: Format 0 1-bit ACK miss 106 PRB), (Test2: Format 0 2-bit ACK miss 106 PRB), (Test3: Format 0 2-bit ACK miss, 1-bit SR 106 PRB), - (Test4: Format 2 3-bit 106 PRB), - (Test5: Format 2 4-bit 106 PRB), - (Test6: Format 2 5-bit 106 PRB), - (Test7: Format 2 6-bit 106 PRB), - (Test8: Format 2 7-bit 106 PRB), - (Test9: Format 2 8-bit 106 PRB), - (Test10: Format 2 9-bit 106 PRB), - (Test11: Format 2 10-bit 106 PRB), - (Test12: Format 2 11-bit 106 PRB)</desc> + (Test4: Format 2 3-bit 2/106 PRB), + (Test5: Format 2 4-bit 2/106 PRB), + (Test6: Format 2 5-bit 2/106 PRB), + (Test7: Format 2 6-bit 2/106 PRB), + (Test8: Format 2 7-bit 2/106 PRB), + (Test9: Format 2 8-bit 2/106 PRB), + (Test10: Format 2 9-bit 2/106 PRB), + (Test11: Format 2 10-bit 2/106 PRB), + (Test12: Format 2 11-bit 2/106 PRB), + (Test13: Format 2 12-bit 8/106 PRB), + (Test14: Format 2 19-bit 8/106 PRB), + (Test15: Format 2 32-bit 8/106 PRB), + (Test16: Format 2 32-bit 16/106 PRB), + (Test17: Format 2 64-bit 16/106 PRB)</desc> <pre_compile_prog></pre_compile_prog> <compile_prog>$OPENAIR_DIR/cmake_targets/build_oai</compile_prog> <compile_prog_args> --phy_simulators -c </compile_prog_args> @@ -1212,8 +1221,15 @@ -R 106 -i 1 -P 2 -b 8 -s4 -n1000 -R 106 -i 1 -P 2 -b 9 -s5 -n1000 -R 106 -i 1 -P 2 -b 10 -s6 -n1000 - -R 106 -i 1 -P 2 -b 11 -s6 -n1000</main_exec_args> - <tags>nr_pucchsim.test1 nr_pucchsim.test2 nr_pucchsim.test3 nr_pucchsim.test4 nr_pucchsim.test5 nr_pucchsim.test6 nr_pucchsim.test7 nr_pucchsim.test8 nr_pucchsim.test9 nr_pucchsim.test10 nr_pucchsim.test11 nr_pucchsim.test12</tags> + -R 106 -i 1 -P 2 -b 11 -s6 -n1000 + -R 106 -i 1 -P 2 -q8 -b 12 -s-3 -n1000 + -R 106 -i 1 -P 2 -q8 -b 19 -s-3 -n1000 + -R 106 -i 1 -P 2 -q8 -b 19 -s-3 -n1000 + -R 106 -i 1 -P 2 -q8 -b 32 -s-3 -n1000 + -R 106 -i 1 -P 2 -q16 -b 32 -s-3 -n1000 + -R 106 -i 1 -P 2 -q16 -b 64 -s-3 -n1000 + </main_exec_args> + <tags>nr_pucchsim.test1 nr_pucchsim.test2 nr_pucchsim.test3 nr_pucchsim.test4 nr_pucchsim.test5 nr_pucchsim.test6 nr_pucchsim.test7 nr_pucchsim.test8 nr_pucchsim.test9 nr_pucchsim.test10 nr_pucchsim.test11 nr_pucchsim.test12 nr_pucchsim.test13 nr_pucchsim.test14 nr_pucchsim.test15 nr_pucchsim.test16 nr_pucchsim.test17</tags> <search_expr_true>PUCCH test OK</search_expr_true> <search_expr_false>segmentation fault|assertion|exiting|fatal</search_expr_false> <nruns>3</nruns> diff --git a/common/config/libconfig/config_libconfig.c b/common/config/libconfig/config_libconfig.c index b510ca28bc28f430f0a10ad5e81849e240f4f932..2e9fd614c504e286f5eeb728a4b03ab198ec1cf0 100644 --- a/common/config/libconfig/config_libconfig.c +++ b/common/config/libconfig/config_libconfig.c @@ -180,7 +180,7 @@ int config_libconfig_get(paramdef_t *cfgoptions,int numoptions, char *prefix ) { printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long unsigned)(*(cfgoptions[i].u64ptr)) ); } else { *(cfgoptions[i].i64ptr) = llu; - printf_params("[LIBCONFIG] %s: %llu\n", cfgpath,(long long)(*(cfgoptions[i].i64ptr)) ); + printf_params("[LIBCONFIG] %s: %lld\n", cfgpath,(long long)(*(cfgoptions[i].i64ptr)) ); } } else { defval=config_setdefault_int64(&(cfgoptions[i]),prefix); diff --git a/doc/FEATURE_SET.md b/doc/FEATURE_SET.md index eeb953edd1bb389197573cee690241b81f40ccdc..23d32effbbdef58bf8a0d530b4eb7b397a9ae918 100644 --- a/doc/FEATURE_SET.md +++ b/doc/FEATURE_SET.md @@ -309,7 +309,6 @@ The following features are valid for the gNB and the 5G-NR UE. - ACK / NACK handling and HARQ procedures for downlink - **As of May 2020** only DL was validated with COTS phone ; UL in progress, validated with OAI UE in noS1 mode - # OpenAirInterface 5G-NR UE Feature Set # **as of May 2020** only supporting "noS1" mode (DL): @@ -353,11 +352,8 @@ The following features are valid for the gNB and the 5G-NR UE. - Initial sync and MIB detection - MAC -> PHY configuration of PHY via UE FAPI P5 interface - Basic MAC to control PHY via UE FAPI P7 interface -<<<<<<< HEAD - Random access procedure -======= -- Random ccess procedure ->>>>>>> origin/develop + **RLC** diff --git a/doc/RUNMODEM.md b/doc/RUNMODEM.md index 7591111b4b9976a93de70a4a96bdfa7ede7f56a7..37eadd92f34a8de9cbfd9f4867dbea67d74ef7b0 100644 --- a/doc/RUNMODEM.md +++ b/doc/RUNMODEM.md @@ -93,6 +93,14 @@ At the UE the --phy-test flag will ```bash sudo ./nr-uesoftmodem --phy-test [--rrc_config_path ../../../ci-scripts/rrc-files]``` +Some other useful paramters of the UE are + + - --ue-fo-compensation: enables the frequency offset compenstation at the UE. This is useful when running over the air and/or without an external clock/time source + - --usrp-args: this is the equivalend paramter of sdr_addrs field in the gNB config file and can be used to identify the USRP and set some basic paramters (like the clock source) + - --clock-source: sets the clock-source (internal or external). + - --time-source: sets the time-source (internal or external). + + ## noS1 setup with OAI UE Instead of randomly generated payload, in the phy-test mode we can also inject/receive user-plane traffic over a TUN interface. This is the so-called noS1 mode. diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 054b02dd0d045951369ee82006fd19da487fa4e6..2a9b3a070075b491dcc44c86efbe682b48aeed7b 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -963,7 +963,9 @@ if(!IS_SOFTMODEM_NOS1) scopeParms_t p; p.argc=&argc; p.argv=argv; - startScope(&p); + p.gNB=RC.gNB[0]; + p.ru=RC.ru[0]; + gNBinitScope(&p); } if (nfapi_mode != 1 && nfapi_mode != 2) { diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 85e7f911f965d6b688fc3edcd7cb1fd01ee5079d..b96f98e1f2d6fed3be166f420471c04d11b02ae1 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -76,36 +76,11 @@ unsigned short config_frames[4] = {2,9,11,13}; #include <openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h> #include <openair1/SCHED_NR_UE/fapi_nr_ue_l1.h> -#include <forms.h> - - -/* Callbacks, globals and object handlers */ - -extern void reset_stats( FL_OBJECT *, long ); -//extern void initTpool(char *params, tpool_t *pool, bool performanceMeas); - -/* Forms and Objects */ - -typedef struct { - FL_FORM *stats_form; - void *vdata; - char *cdata; - long ldata; - FL_OBJECT *stats_text; - FL_OBJECT *stats_button; -} FD_stats_form; - -extern FD_stats_form *create_form_stats_form( void ); - -#include "PHY/TOOLS/nr_phy_scope.h" //#include "stats.h" // current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0) +#include "PHY/TOOLS/nr_phy_scope.h" // at eNB 0, an UL scope for every UE -FD_phy_scope_nrue *form_nrue[NUMBER_OF_UE_MAX]; //FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX]; -//FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; -char title[255]; -static pthread_t forms_thread; //xforms #include <executables/nr-uesoftmodem.h> #include "executables/softmodem-common.h" @@ -304,35 +279,6 @@ void reset_stats(FL_OBJECT *button, long arg) { }*/ } -static void *scope_thread(void *arg) { - sleep(5); - - while (!oai_exit) { - phy_scope_nrUE(form_nrue[0], - PHY_vars_UE_g[0][0], - 0,0,1); - usleep(100*1000); - } - - pthread_exit((void *)arg); -} - - -void init_scope(void) { - int fl_argc=1; - - if (do_forms==1) { - char *name="5G-UE-scope"; - fl_initialize (&fl_argc, &name, NULL, 0, 0); - int UE_id = 0; - form_nrue[UE_id] = create_phy_scope_nrue(); - sprintf (title, "NR DL SCOPE UE"); - fl_show_form (form_nrue[UE_id]->phy_scope_nrue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); - threadCreate(&forms_thread, scope_thread, NULL, "scope", -1, OAI_PRIORITY_RT_LOW); - } - -} - void *l2l1_task(void *arg) { MessageDef *message_p = NULL; int result; @@ -814,7 +760,8 @@ int main( int argc, char **argv ) { memset (&UE_PF_PO[0][0], 0, sizeof(UE_PF_PO_t)*NUMBER_OF_UE_MAX*MAX_NUM_CCs); configure_linux(); mlockall(MCL_CURRENT | MCL_FUTURE); - init_scope(); + if (do_forms) + nrUEinitScope(PHY_vars_UE_g[0][0]); number_of_cards = 1; for(int CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) { diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h index dd3e2d037f1218595796030b814549072e04f9dd..fea64e3f3e7d07208b19d254ca0062dbdd58b8f7 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h @@ -1492,7 +1492,7 @@ typedef struct //for dci_pusch_pdu typedef struct { - uint8_t pdu_bit_map; + uint8_t pduBitmap; uint32_t handle; uint16_t rnti; uint8_t ul_cqi; @@ -1507,7 +1507,7 @@ typedef struct //for PUCCH PDU Format 0/1 typedef struct { - uint8_t pdu_bit_map; + uint8_t pduBitmap; uint32_t handle; uint16_t rnti; uint8_t pucch_format;//PUCCH format Value: 0 -> 1 0: PUCCH Format0 1: PUCCH Format1 @@ -1523,7 +1523,7 @@ typedef struct //PUCCH PDU Format 2/3/4 typedef struct { - uint8_t pdu_bit_map; + uint8_t pduBitmap; uint32_t handle; uint16_t rnti; uint8_t pucch_format;//PUCCH format Value: 0 -> 2 0: PUCCH Format2 1: PUCCH Format3 2: PUCCH Format4 diff --git a/openair1/PHY/CODING/TESTBENCH/polartest.c b/openair1/PHY/CODING/TESTBENCH/polartest.c index 776409121b2b03753856eac52ca48ef2e4e06a02..d9adf3e24f679b37f80b0643eea4c12c76595d66 100644 --- a/openair1/PHY/CODING/TESTBENCH/polartest.c +++ b/openair1/PHY/CODING/TESTBENCH/polartest.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) { //Default simulation values (Aim for iterations = 1000000.) int decoder_int16=0; - int itr, iterations = 1000, arguments, polarMessageType = 0; //0=PBCH, 1=DCI, -1=UCI + int itr, iterations = 1000, arguments, polarMessageType = 0; //0=PBCH, 1=DCI, 2=UCI double SNRstart = -20.0, SNRstop = 0.0, SNRinc= 0.5; //dB double SNR, SNR_lin; int16_t nBitError = 0; // -1 = Decoding failed (All list entries have failed the CRC checks). @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) switch (arguments) { case 's': SNRstart = atof(optarg); + SNRstop = SNRstart + 2; break; case 'd': @@ -90,7 +91,7 @@ int main(int argc, char *argv[]) case 'k': testLength=atoi(optarg); - if (testLength < 12 || testLength > 60) { + if (testLength < 12 || testLength > 127) { printf("Illegal packet bitlength %d \n",testLength); exit(-1); } @@ -119,12 +120,13 @@ int main(int argc, char *argv[]) crcTableInit(); if (polarMessageType == 0) { //PBCH - aggregation_level = NR_POLAR_PBCH_AGGREGATION_LEVEL; + aggregation_level = NR_POLAR_PBCH_AGGREGATION_LEVEL; } else if (polarMessageType == 1) { //DCI - coderLength = 108*aggregation_level; - } else if (polarMessageType == -1) { //UCI - printf("UCI testing not supported yet\n"); - exit(-1); + coderLength = 108*aggregation_level; + } else if (polarMessageType == 2) { //UCI + //pucch2 parameters, 1 symbol, aggregation_level = NPRB + AssertFatal(aggregation_level>2,"For UCI formats, aggregation (N_RB) should be > 2\n"); + coderLength = 16*aggregation_level; } //Logging diff --git a/openair1/PHY/CODING/coding_defs.h b/openair1/PHY/CODING/coding_defs.h index da19ec40e275aad06bba75dee316f339d9bf4d3b..7f466c709723e476b8afb97c023ee1cb5dcb0410 100644 --- a/openair1/PHY/CODING/coding_defs.h +++ b/openair1/PHY/CODING/coding_defs.h @@ -382,12 +382,24 @@ unsigned int crc16 (unsigned char * inptr, int bitlen); @param bitlen length of inputs in bits*/ unsigned int crc12 (unsigned char * inptr, int bitlen); +/*!\fn uint32_t crc12(uint8_t *inPtr, int32_t bitlen) +\brief This computes an 11-bit crc based on 3GPP NR specifications. +@param inPtr Pointer to input byte stream +@param bitlen length of inputs in bits*/ +unsigned int crc11 (unsigned char * inptr, int bitlen); + /*!\fn uint32_t crc8(uint8_t *inPtr, int32_t bitlen) \brief This computes a 8-bit crc based on 3GPP UMTS specifications. @param inPtr Pointer to input byte stream @param bitlen length of inputs in bits*/ unsigned int crc8 (unsigned char * inptr, int bitlen); +/*!\fn uint32_t crc8(uint8_t *inPtr, int32_t bitlen) +\brief This computes a 6-bit crc based on 3GPP NR specifications. +@param inPtr Pointer to input byte stream +@param bitlen length of inputs in bits*/ +unsigned int crc6 (unsigned char * inptr, int bitlen); + int check_crc(uint8_t* decoded_bytes, uint32_t n, uint32_t F, uint8_t crc_type); /*!\fn void phy_viterbi_dot11_sse2(int8_t *y, uint8_t *decoded_bytes, uint16_t n,int offset,int traceback) diff --git a/openair1/PHY/CODING/crc_byte.c b/openair1/PHY/CODING/crc_byte.c index ee5c302adb03264058bcfcf113deb5ad9719b3c9..0769ab992acafe9f0b090ce15114e3d01f1905a3 100644 --- a/openair1/PHY/CODING/crc_byte.c +++ b/openair1/PHY/CODING/crc_byte.c @@ -90,7 +90,9 @@ static unsigned int crc24bTable[256]; static unsigned int crc24cTable[256]; static unsigned short crc16Table[256]; static unsigned short crc12Table[256]; +static unsigned short crc11Table[256]; static unsigned char crc8Table[256]; +static unsigned char crc6Table[256]; void crcTableInit (void) { @@ -102,7 +104,9 @@ void crcTableInit (void) crc24cTable[c] = crcbit (&c, 1, poly24c); crc16Table[c] = (unsigned short) (crcbit (&c, 1, poly16) >> 16); crc12Table[c] = (unsigned short) (crcbit (&c, 1, poly12) >> 16); + crc11Table[c] = (unsigned short) (crcbit (&c, 1, poly11) >> 16); crc8Table[c] = (unsigned char) (crcbit (&c, 1, poly8) >> 24); + crc6Table[c] = (unsigned char) (crcbit (&c, 1, poly6) >> 24); } while (++c); } @@ -207,6 +211,24 @@ crc12 (unsigned char * inptr, int bitlen) return crc; } +unsigned int +crc11 (unsigned char * inptr, int bitlen) +{ + int octetlen, resbit; + unsigned int crc = 0; + octetlen = bitlen / 8; /* Change in octets */ + resbit = (bitlen % 8); + + while (octetlen-- > 0) { + crc = (crc << 8) ^ (crc11Table[(*inptr++) ^ (crc >> 24)] << 16); + } + + if (resbit > 0) + crc = (crc << resbit) ^ (crc11Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 16); + + return crc; +} + unsigned int crc8 (unsigned char * inptr, int bitlen) { @@ -225,6 +247,24 @@ crc8 (unsigned char * inptr, int bitlen) return crc; } +unsigned int +crc6 (unsigned char * inptr, int bitlen) +{ + int octetlen, resbit; + unsigned int crc = 0; + octetlen = bitlen / 8; /* Change in octets */ + resbit = (bitlen % 8); + + while (octetlen-- > 0) { + crc = crc6Table[(*inptr++) ^ (crc >> 24)] << 24; + } + + if (resbit > 0) + crc = (crc << resbit) ^ (crc8Table[((*inptr) >> (8 - resbit)) ^ (crc >> (32 - resbit))] << 24); + + 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; diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c index 53119a1c2b69b35462a60ebc59f32ab482449be5..18db8a01fbc5b65fb2ab09d442181b67f1b56429 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_decoder.c @@ -569,7 +569,7 @@ int8_t polar_decoder_dci(double *input, } void init_polar_deinterleaver_table(t_nrPolar_params *polarParams) { - AssertFatal(polarParams->K > 32, "K = %d < 33, is not supported yet\n",polarParams->K); + AssertFatal(polarParams->K > 17, "K = %d < 18, is not allowed\n",polarParams->K); AssertFatal(polarParams->K < 129, "K = %d > 128, is not supported yet\n",polarParams->K); int bit_i,ip,ipmod64; int numbytes = polarParams->K>>3; @@ -670,7 +670,9 @@ uint32_t polar_decoder_int16(int16_t *input, A32_flip[1+offset]=((uint8_t *)&Aprime)[2]; A32_flip[2+offset]=((uint8_t *)&Aprime)[1]; A32_flip[3+offset]=((uint8_t *)&Aprime)[0]; - crc = (uint64_t)(crc24c(A32_flip,8*offset+len)>>8); + if (crclen == 24) crc = (uint64_t)((crc24c(A32_flip,8*offset+len)>>8)&0xffffff); + else if (crclen == 11) crc = (uint64_t)((crc11(A32_flip,8*offset+len)>>21)&0x7ff); + else if (crclen == 6) crc = (uint64_t)((crc6(A32_flip,8*offset+len)>>26)&0x3f); } else if (len<=64) { Ar = (B[0]>>crclen) | (B[1]<<(64-crclen));; uint8_t A64_flip[8+offset]; @@ -688,7 +690,9 @@ uint32_t polar_decoder_int16(int16_t *input, 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 (crclen==24) crc = (uint64_t)(crc24c(A64_flip,8*offset+len)>>8)&0xffffff; + else if (crclen==11) crc = (uint64_t)(crc11(A64_flip,8*offset+len)>>21)&0x7ff; + else if (crclen==6) crc = (uint64_t)(crc6(A64_flip,8*offset+len)>>26)&0x3f; } #if 0 diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c index b142022e37ac30e9561febec8eb64e950e1dbf98..70791302cc9299c7afb02d28a201d55da21e971d 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_encoder.c @@ -295,8 +295,8 @@ static inline void polar_rate_matching(t_nrPolar_params *polarParams,void *in,vo void build_polar_tables(t_nrPolar_params *polarParams) { // build table b -> c' - 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 > 17, "K = %d < 18, is not possible\n",polarParams->K); + AssertFatal(polarParams->K < 129, "K = %d > 128, is not supported yet\n",polarParams->K); int bit_i,ip; int numbytes = polarParams->K>>3; int residue = polarParams->K&7; @@ -327,7 +327,7 @@ void build_polar_tables(t_nrPolar_params *polarParams) { AssertFatal(polarParams->N==512 || polarParams->N==256 || polarParams->N==128,"N = %d, not done yet\n",polarParams->N); // build G bit vectors for information bit positions and convert the bit as bytes tables in nr_polar_kronecker_power_matrices.c to 64 bit packed vectors. // keep only rows of G which correspond to information/crc bits - polarParams->G_N_tab = (uint64_t **)malloc(polarParams->K * sizeof(int64_t *)); + polarParams->G_N_tab = (uint64_t **)malloc((polarParams->K + polarParams->n_pc) * sizeof(int64_t *)); int k=0; for (int i=0; i<polarParams->N; i++) { @@ -412,14 +412,14 @@ void polar_encoder_fast(uint64_t *A, int32_t crcmask, uint8_t ones_flag, 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->payloadBits < 65, "payload bits = %d > 64, is not supported yet\n",polarParams->payloadBits); uint64_t B[4]= {0,0,0,0},Cprime[4]= {0,0,0,0}; int bitlen = polarParams->payloadBits; // append crc AssertFatal(bitlen<129,"support for payloads <= 128 bits\n"); - 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; uint64_t tcrc=0; uint8_t offset = 0; @@ -444,7 +444,9 @@ void polar_encoder_fast(uint64_t *A, A32_flip[1+offset]=((uint8_t *)&Aprime)[2]; A32_flip[2+offset]=((uint8_t *)&Aprime)[1]; A32_flip[3+offset]=((uint8_t *)&Aprime)[0]; - tcrc = (uint64_t)((crcmask^(crc24c(A32_flip,8*offset+bitlen)>>8))); + if (polarParams->crcParityBits == 24) tcrc = (uint64_t)(((crcmask^(crc24c(A32_flip,8*offset+bitlen)>>8)))&0xffffff); + else if (polarParams->crcParityBits == 11) tcrc = (uint64_t)(((crcmask^(crc11(A32_flip,bitlen)>>21)))&0x7ff); + else if (polarParams->crcParityBits == 6) tcrc = (uint64_t)(((crcmask^(crc6(A32_flip,bitlen)>>26)))&0x3f); } else if (bitlen<=64) { uint8_t A64_flip[8+offset]; if (ones_flag) { @@ -461,7 +463,8 @@ void polar_encoder_fast(uint64_t *A, 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))); + if (polarParams->crcParityBits == 24) tcrc = (uint64_t)((crcmask^(crc24c(A64_flip,8*offset+bitlen)>>8)))&0xffffff; + else if (polarParams->crcParityBits == 11) tcrc = (uint64_t)((crcmask^(crc11(A64_flip,bitlen)>>21)))&0x7ff; } else if (bitlen<=128) { uint8_t A128_flip[16+offset]; @@ -479,7 +482,8 @@ void polar_encoder_fast(uint64_t *A, 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))); + if (polarParams->crcParityBits == 24) tcrc = (uint64_t)((crcmask^(crc24c(A128_flip,8*offset+bitlen)>>8)))&0xffffff; + else if (polarParams->crcParityBits == 11) tcrc = (uint64_t)((crcmask^(crc11(A128_flip,bitlen)>>21)))&0x7ff; } int n; @@ -522,6 +526,7 @@ void polar_encoder_fast(uint64_t *A, #ifdef DEBUG_POLAR_ENCODER + printf("Polar encoder: (N,K) : (%d,%d)\n",polarParams->N,polarParams->K); if (polarParams->K<65) printf("A %llx B %llx Cprime %llx (payload bits %d,crc %x)\n", (unsigned long long)(A[0]&(((uint64_t)1<<bitlen)-1)), @@ -546,7 +551,7 @@ void polar_encoder_fast(uint64_t *A, crc24c((uint8_t *)A,bitlen)>>8); } -#endif + #endif /* printf("Bbytes : %x.%x.%x.%x.%x.%x.%x.%x\n",Bbyte[0],Bbyte[1],Bbyte[2],Bbyte[3],Bbyte[4],Bbyte[5],Bbyte[6],Bbyte[7]); printf("%llx,%llx,%llx,%llx,%llx,%llx,%llx,%llx\n",polarParams->cprime_tab[0][Bbyte[0]] , polarParams->cprime_tab[1][Bbyte[1]] , diff --git a/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h b/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h index 42051eb1b57c766eb6d2001b6061d113df307ab5..1ab664e5a21da20c9b08de6a95e99e23087d3490 100644 --- a/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h +++ b/openair1/PHY/CODING/nrPolar_tools/nr_polar_uci_defs.h @@ -33,8 +33,8 @@ #ifndef __NR_POLAR_UCI_DEFS__H__ #define __NR_POLAR_UCI_DEFS__H__ -#define NR_POLAR_UCI_MESSAGE_TYPE -1 //int8_t -#define NR_POLAR_UCI_CRC_ERROR_CORRECTION_BITS 3 +#define NR_POLAR_UCI_PUCCH_MESSAGE_TYPE 2 //int8_t +#define NR_POLAR_PUCCH_CRC_ERROR_CORRECTION_BITS 3 #define NR_POLAR_PUCCH_PAYLOAD_BITS 32 #define NR_POLAR_PUCCH_E 32 diff --git a/openair1/PHY/CODING/nr_polar_init.c b/openair1/PHY/CODING/nr_polar_init.c index f6a06b3f7fc830ff77084540ded4f556ccf0426b..f6a700117dd4a4ac9b2b98d2f78ebd1a319dbba1 100644 --- a/openair1/PHY/CODING/nr_polar_init.c +++ b/openair1/PHY/CODING/nr_polar_init.c @@ -43,11 +43,12 @@ static void nr_polar_init(t_nrPolar_params * *polarParams, uint8_t aggregation_level, int decoder_flag) { t_nrPolar_params *currentPtr = *polarParams; - uint16_t aggregation_prime = nr_polar_aggregation_prime(aggregation_level); + uint16_t aggregation_prime = (messageType >= 2) ? aggregation_level : nr_polar_aggregation_prime(aggregation_level); //Parse the list. If the node is already created, return without initialization. while (currentPtr != NULL) { //printf("currentPtr->idx %d, (%d,%d)\n",currentPtr->idx,currentPtr->payloadBits,currentPtr->encoderLength); + //LOG_D(PHY,"Looking for index %d\n",(messageType * messageLength * aggregation_prime)); if (currentPtr->idx == (messageType * messageLength * aggregation_prime)) return; else currentPtr = currentPtr->nextPtr; } @@ -55,8 +56,9 @@ static void nr_polar_init(t_nrPolar_params * *polarParams, // printf("currentPtr %p (polarParams %p)\n",currentPtr,polarParams); //Else, initialize and add node to the end of the linked list. t_nrPolar_params *newPolarInitNode = calloc(sizeof(t_nrPolar_params),1); - + if (newPolarInitNode != NULL) { + // LOG_D(PHY,"Setting new polarParams index %d, messageType %d, messageLength %d, aggregation_prime %d\n",(messageType * messageLength * aggregation_prime),messageType,messageLength,aggregation_prime); newPolarInitNode->idx = (messageType * messageLength * aggregation_prime); newPolarInitNode->nextPtr = NULL; //printf("newPolarInitNode->idx %d, (%d,%d,%d:%d)\n",newPolarInitNode->idx,messageType,messageLength,aggregation_prime,aggregation_level); @@ -87,15 +89,44 @@ static void nr_polar_init(t_nrPolar_params * *polarParams, newPolarInitNode->crcCorrectionBits = NR_POLAR_DCI_CRC_ERROR_CORRECTION_BITS; newPolarInitNode->crc_generator_matrix=crc24c_generator_matrix(newPolarInitNode->payloadBits+newPolarInitNode->crcParityBits);//G_P //printf("Initializing polar parameters for DCI (K %d, E %d, L %d)\n",newPolarInitNode->payloadBits,newPolarInitNode->encoderLength,aggregation_level); - } else if (messageType == -1) { //UCI + } else if (messageType == 2) { //UCI PUCCH2 + AssertFatal(aggregation_level>2,"Aggregation level (%d) for PUCCH 2 encoding is NPRB and should be > 2\n",aggregation_level); + AssertFatal(messageLength>11,"Message length %d is too short for polar encoding of UCI\n",messageLength); + newPolarInitNode->n_max = NR_POLAR_PUCCH_N_MAX; + newPolarInitNode->i_il = NR_POLAR_PUCCH_I_IL; + newPolarInitNode->encoderLength = aggregation_level * 16; + + newPolarInitNode->i_seg = 0; + + if ((messageLength >= 360 && newPolarInitNode->encoderLength >= 1088)|| + (messageLength >= 1013)) newPolarInitNode->i_seg = 1; + + newPolarInitNode->crcParityBits = 11; + newPolarInitNode->n_pc = 0; + newPolarInitNode->n_pc_wm = 0; + + if (messageLength < 20) { + newPolarInitNode->crcParityBits = 6; + newPolarInitNode->n_pc = 3; + if ((newPolarInitNode->encoderLength - messageLength - 6 + 3) < 193) newPolarInitNode->n_pc_wm = 1; + } + + + + newPolarInitNode->i_bil = NR_POLAR_PUCCH_I_BIL; + + newPolarInitNode->payloadBits = messageLength; + newPolarInitNode->crcCorrectionBits = NR_POLAR_PUCCH_CRC_ERROR_CORRECTION_BITS; + //newPolarInitNode->crc_generator_matrix=crc24c_generator_matrix(newPolarInitNode->payloadBits+newPolarInitNode->crcParityBits);//G_P + //LOG_D(PHY,"New polar node, encoderLength %d, aggregation_level %d\n",newPolarInitNode->encoderLength,aggregation_level); } else { AssertFatal(1 == 0, "[nr_polar_init] Incorrect Message Type(%d)", messageType); } 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->encoderLength, + newPolarInitNode->n_max); newPolarInitNode->n = log2(newPolarInitNode->N); newPolarInitNode->G_N = nr_polar_kronecker_power_matrices(newPolarInitNode->n); //polar_encoder vectors: @@ -191,16 +222,19 @@ t_nrPolar_params *nr_polar_params (int8_t messageType, nr_polar_init(polarList_ext != NULL ? polarList_ext : &polarList, messageType,messageLength,aggregation_level,decoding_flag); t_nrPolar_params *polarParams=polarList_ext != NULL ? *polarList_ext : polarList; - const int tag=messageType * messageLength * nr_polar_aggregation_prime(aggregation_level); + const int tag=messageType * messageLength * (messageType>=2 ? aggregation_level : nr_polar_aggregation_prime(aggregation_level)); + + while (polarParams != NULL) { + // LOG_D(PHY,"nr_polar_params : tag %d (from nr_polar_init %d)\n",tag,polarParams->idx); if (polarParams->idx == tag) return polarParams; polarParams = polarParams->nextPtr; } - AssertFatal(false,"Polar Init tables internal failure\n"); + AssertFatal(false,"Polar Init tables internal failure, no polarParams found\n"); return NULL; } diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c index 2fd84f563cce242bff6367c7849ade59866adbdd..556a9f2d237f5e4cbf84dae7541d69b570e0d2a6 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c @@ -821,15 +821,14 @@ int rx_pdsch(PHY_VARS_UE *ue, pllr_symbol_cw0 += llr_offset_symbol; pllr_symbol_cw1 += llr_offset_symbol; - /* - LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p\n", + LOG_D(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p energy: %d\n", frame, subframe,symbol, nb_rb,dlsch0_harq->Qm, pdsch_vars[eNB_id]->llr_length[symbol], pdsch_vars[eNB_id]->llr_offset[symbol], (int16_t*)pdsch_vars[eNB_id]->llr[0], - pllr_symbol_cw0); - */ + pllr_symbol_cw0, + signal_energy(pdsch_vars[eNB_id]->rxdataF_comp0[0], 7*2*frame_parms->N_RB_DL*12)); switch (dlsch0_harq->Qm) { case 2 : if ((rx_type==rx_standard) || (codeword_TB1 == -1)) { diff --git a/openair1/PHY/NR_REFSIG/scrambling_luts.c b/openair1/PHY/NR_REFSIG/scrambling_luts.c index 9d957de0f716f2f6929110c63015b3d6e4a9c970..790d3f771966262ebc8f08287a5ed2cefd427038 100644 --- a/openair1/PHY/NR_REFSIG/scrambling_luts.c +++ b/openair1/PHY/NR_REFSIG/scrambling_luts.c @@ -27,6 +27,7 @@ #include "PHY/impl_defs_nr.h" #include "PHY/sse_intrin.h" +#include <common/utils/LOG/log.h> __m64 byte2m64_re[256]; __m64 byte2m64_im[256]; @@ -42,7 +43,7 @@ void init_byte2m64(void) { byte2m64_im[s] = _mm_insert_pi16(byte2m64_im[s],(1-2*((s>>5)&1)),2); byte2m64_re[s] = _mm_insert_pi16(byte2m64_re[s],(1-2*((s>>6)&1)),3); byte2m64_im[s] = _mm_insert_pi16(byte2m64_im[s],(1-2*((s>>7)&1)),3); - printf("init_scrambling_luts: s %x (%d) ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + LOG_T(PHY,"init_scrambling_luts: s %x (%d) ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", ((uint16_t*)&s)[0], (1-2*(s&1)), ((int16_t*)&byte2m64_re[s])[0],((int16_t*)&byte2m64_im[s])[0], diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach.c b/openair1/PHY/NR_TRANSPORT/nr_prach.c index 289eb51e9d8c305ee07f0bbf62d58ecab45c271b..dc754fb3b04126419393f27725a9d3c6fb19bfa7 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_TRANSPORT/nr_prach.c @@ -168,7 +168,7 @@ void rx_nr_prach_ru(RU_t *ru, int dftlen=0; int mu = fp->numerology_index; - int Ncp; + int Ncp = 0; int16_t *prach2; if (prach_sequence_length == 0) { @@ -568,9 +568,6 @@ void rx_nr_prach(PHY_VARS_gNB *gNB, int16_t prach_ifft_tmp[2048*2] __attribute__((aligned(32))); int32_t *prach_ifft=(int32_t*)NULL; - - AssertFatal(gNB!=NULL,"gNB is null\n"); - fp = &gNB->frame_parms; nb_rx = gNB->gNB_config.carrier_config.num_rx_ant.value; diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c index aa21546ee517f0ff11f834a7619e375d1249719c..a966db5844ad6de4170175655c6dffec5e05ae21 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c @@ -232,7 +232,7 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF, unsigned short start_re, re, nb_re_pusch; unsigned char aarx; - uint8_t K_ptrs; + uint8_t K_ptrs = 0; uint32_t rxF_ext_index = 0; uint32_t ul_ch0_ext_index = 0; uint32_t ul_ch0_index = 0; @@ -1156,8 +1156,8 @@ int nr_rx_pusch(PHY_VARS_gNB *gNB, //---------------------------------------------------------- //-------------------- LLRs computation -------------------- //---------------------------------------------------------- - start_meas(&gNB->ulsch_llr_stats); + AssertFatal(gNB->pusch_vars[ulsch_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order+nb_re_pusch*rel15_ul->qam_mod_order < (8*((3*8*6144)+12)) , "Mysterious llr buffer size check"); nr_ulsch_compute_llr(&gNB->pusch_vars[ulsch_id]->rxdataF_comp[0][symbol * rel15_ul->rb_size * NR_NB_SC_PER_RB], gNB->pusch_vars[ulsch_id]->ul_ch_mag0, gNB->pusch_vars[ulsch_id]->ul_ch_magb0, diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c index ed367b46a6e8af7235d01540a0233febe5512c27..501df8bb357b1d665ea55ff34952091a9cda56f2 100644 --- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c +++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c @@ -20,15 +20,15 @@ */ /*! \file PHY/NR_TRANSPORT/pucch_rx.c -* \brief Top-level routines for decoding the PUCCH physical channel -* \author A. Mico Pereperez, Padarthi Naga Prasanth, Francesco Mani, Raymond Knopp -* \date 2020 -* \version 0.2 -* \company Eurecom -* \email: -* \note -* \warning -*/ + * \brief Top-level routines for decoding the PUCCH physical channel + * \author A. Mico Pereperez, Padarthi Naga Prasanth, Francesco Mani, Raymond Knopp + * \date 2020 + * \version 0.2 + * \company Eurecom + * \email: + * \note + * \warning + */ #include<stdio.h> #include <string.h> #include <math.h> @@ -238,7 +238,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB, int16_t x_n_re[nr_sequences][24],x_n_im[nr_sequences][24]; for(i=0;i<nr_sequences;i++){ - // we proceed to calculate alpha according to TS 38.211 Subclause 6.3.2.2.2 + // we proceed to calculate alpha according to TS 38.211 Subclause 6.3.2.2.2 for (l=0; l<pucch_pdu->nr_of_symbols; l++){ double alpha = nr_cyclic_shift_hopping(pucch_pdu->hopping_id,pucch_pdu->initial_cyclic_shift,mcs[i],l,pucch_pdu->start_symbol_index,slot); #ifdef DEBUG_NR_PUCCH_RX @@ -248,14 +248,14 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB, alpha=0.0; for (n=0; n<12; n++){ x_n_re[i][(12*l)+n] = (int16_t)((int16_t)(((((int32_t)(round(32767*cos(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15) - - (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15)))); // Re part of base sequence shifted by alpha + - (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15)))); // Re part of base sequence shifted by alpha x_n_im[i][(12*l)+n] =(int16_t)((int16_t)(((((int32_t)(round(32767*cos(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15) - + (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15)))); // Im part of base sequence shifted by alpha + + (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15)))); // Im part of base sequence shifted by alpha #ifdef DEBUG_NR_PUCCH_RX - printf("\t [nr_generate_pucch0] sequence generation \tu=%d \tv=%d \talpha=%lf \tx_n(l=%d,n=%d)=(%d,%d) %d,%d\n", - u,v,alpha,l,n,x_n_re[i][(12*l)+n],x_n_im[i][(12*l)+n], - (int32_t)(round(32767*cos(alpha*n))), - (int32_t)(round(32767*sin(alpha*n)))); + printf("\t [nr_generate_pucch0] sequence generation \tu=%d \tv=%d \talpha=%lf \tx_n(l=%d,n=%d)=(%d,%d) %d,%d\n", + u,v,alpha,l,n,x_n_re[i][(12*l)+n],x_n_im[i][(12*l)+n], + (int32_t)(round(32767*cos(alpha*n))), + (int32_t)(round(32767*sin(alpha*n)))); #endif } } @@ -277,12 +277,12 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB, r_re[(12*l)+n]=((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[0]; r_im[(12*l)+n]=((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[1]; - #ifdef DEBUG_NR_PUCCH_RX - printf("\t [nr_generate_pucch0] mapping to RE \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \ttxptr(%d)=(x_n(l=%d,n=%d)=(%d,%d))\n", - frame_parms->ofdm_symbol_size,frame_parms->N_RB_DL,frame_parms->first_carrier_offset,(l2*frame_parms->ofdm_symbol_size)+re_offset, - l,n,((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[0], - ((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[1]); - #endif +#ifdef DEBUG_NR_PUCCH_RX + printf("\t [nr_generate_pucch0] mapping to RE \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \ttxptr(%d)=(x_n(l=%d,n=%d)=(%d,%d))\n", + frame_parms->ofdm_symbol_size,frame_parms->N_RB_DL,frame_parms->first_carrier_offset,(l2*frame_parms->ofdm_symbol_size)+re_offset, + l,n,((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[0], + ((int16_t *)&rxdataF[0][(l2*frame_parms->ofdm_symbol_size)+re_offset])[1]); +#endif re_offset++; if (re_offset>= frame_parms->ofdm_symbol_size) re_offset-=frame_parms->ofdm_symbol_size; @@ -347,7 +347,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB, n2=0; for (l=0;l<pucch_pdu->nr_of_symbols;l++) { - seq_index = (pucch_pdu->initial_cyclic_shift+ + seq_index = (pucch_pdu->initial_cyclic_shift+ mcs[i]+ gNB->pucch0_lut.lut[cs_ind][slot][l+pucch_pdu->start_symbol_index])%12; for (n=0;n<12;n++,n2+=2) { @@ -374,7 +374,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB, index=maxpos; #endif // first bit of bitmap for sr presence and second bit for acknack presence - uci_pdu->pdu_bit_map = pucch_pdu->sr_flag | ((pucch_pdu->bit_len_harq>0)<<1); + uci_pdu->pduBitmap = pucch_pdu->sr_flag | ((pucch_pdu->bit_len_harq>0)<<1); uci_pdu->pucch_format = 0; // format 0 uci_pdu->ul_cqi = 0xff; // currently not valid uci_pdu->timing_advance = 0xffff; // currently not valid @@ -552,13 +552,13 @@ void nr_decode_pucch1( int32_t **rxdataF, if (l%2 == 0) { // mapping DM-RS signal according to TS38.211 subclause 6.4.1.3.1 z_dmrs_re_rx[i+n] = ((int16_t *)&rxdataF[0][re_offset])[0]; z_dmrs_im_rx[i+n] = ((int16_t *)&rxdataF[0][re_offset])[1]; -// printf("%d\t%d\t%d\n",l,z_dmrs_re_rx[i+n],z_dmrs_im_rx[i+n]); + // printf("%d\t%d\t%d\n",l,z_dmrs_re_rx[i+n],z_dmrs_im_rx[i+n]); #ifdef DEBUG_NR_PUCCH_RX printf("\t [nr_generate_pucch1] mapping DM-RS to RE \t amp=%d \tofdm_symbol_size=%d \tN_RB_DL=%d \tfirst_carrier_offset=%d \tz_dm-rs[%d]=txptr(%u)=(x_n(l=%d,n=%d)=(%d,%d))\n", amp,frame_parms->ofdm_symbol_size,frame_parms->N_RB_DL,frame_parms->first_carrier_offset,i+n,re_offset, l,n,((int16_t *)&rxdataF[0][re_offset])[0],((int16_t *)&rxdataF[0][re_offset])[1]); #endif -// printf("l=%d\ti=%d\tre_offset=%d\treceived dmrs re=%d\tim=%d\n",l,i,re_offset,z_dmrs_re_rx[i+n],z_dmrs_im_rx[i+n]); + // printf("l=%d\ti=%d\tre_offset=%d\treceived dmrs re=%d\tim=%d\n",l,i,re_offset,z_dmrs_re_rx[i+n],z_dmrs_im_rx[i+n]); } re_offset++; @@ -577,7 +577,7 @@ void nr_decode_pucch1( int32_t **rxdataF, l,lprime); #endif // y_n contains the complex value d multiplied by the sequence r_u_v - if ((intraSlotFrequencyHopping == 1) && (l >= (int)floor(nrofSymbols/2))) n_hop = 1; // n_hop = 1 for second hop + if ((intraSlotFrequencyHopping == 1) && (l >= (int)floor(nrofSymbols/2))) n_hop = 1; // n_hop = 1 for second hop #ifdef DEBUG_NR_PUCCH_RX printf("\t [nr_generate_pucch1] entering function nr_group_sequence_hopping with n_hop=%d, nr_tti_tx=%d\n", @@ -595,18 +595,18 @@ void nr_decode_pucch1( int32_t **rxdataF, } else{ r_u_v_alpha_delta_dmrs_re[n] = (int16_t)(((((int32_t)(round(32767*cos(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15) - - (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15))); // Re part of DMRS base sequence shifted by alpha + - (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15))); // Re part of DMRS base sequence shifted by alpha r_u_v_alpha_delta_dmrs_im[n] = (int16_t)(((((int32_t)(round(32767*cos(alpha*n))) * table_5_2_2_2_2_Im[u][n])>>15) - + (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15))); // Im part of DMRS base sequence shifted by alpha + + (((int32_t)(round(32767*sin(alpha*n))) * table_5_2_2_2_2_Re[u][n])>>15))); // Im part of DMRS base sequence shifted by alpha r_u_v_alpha_delta_dmrs_re[n] = (int16_t)(((int32_t)(amp*r_u_v_alpha_delta_dmrs_re[n]))>>15); r_u_v_alpha_delta_dmrs_im[n] = (int16_t)(((int32_t)(amp*r_u_v_alpha_delta_dmrs_im[n]))>>15); } -// printf("symbol=%d\tr_u_rx_re=%d\tr_u_rx_im=%d\n",l,r_u_v_alpha_delta_dmrs_re[n], r_u_v_alpha_delta_dmrs_im[n]); + // printf("symbol=%d\tr_u_rx_re=%d\tr_u_rx_im=%d\n",l,r_u_v_alpha_delta_dmrs_re[n], r_u_v_alpha_delta_dmrs_im[n]); // PUCCH sequence = DM-RS sequence multiplied by d(0) -/* y_n_re[n] = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*d_re)>>15) - - (((int32_t)(r_u_v_alpha_delta_im[n])*d_im)>>15))); // Re part of y(n) - y_n_im[n] = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*d_im)>>15) - + (((int32_t)(r_u_v_alpha_delta_im[n])*d_re)>>15))); // Im part of y(n) */ + /* y_n_re[n] = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*d_re)>>15) + - (((int32_t)(r_u_v_alpha_delta_im[n])*d_im)>>15))); // Re part of y(n) + y_n_im[n] = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*d_im)>>15) + + (((int32_t)(r_u_v_alpha_delta_im[n])*d_re)>>15))); // Im part of y(n) */ #ifdef DEBUG_NR_PUCCH_RX printf("\t [nr_generate_pucch1] sequence generation \tu=%d \tv=%d \talpha=%lf \tr_u_v_alpha_delta[n=%d]=(%d,%d) \ty_n[n=%d]=(%d,%d)\n", u,v,alpha,n,r_u_v_alpha_delta_re[n],r_u_v_alpha_delta_im[n],n,y_n_re[n],y_n_im[n]); @@ -656,12 +656,12 @@ void nr_decode_pucch1( int32_t **rxdataF, if(floor(l/2)*12==(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)){ for (int n=0; n<12 ; n++) { z_re_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_im_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]=z_re_temp; z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]=z_im_temp; -// printf("symbol=%d\tz_re_rx=%d\tz_im_rx=%d\t",l,(int)z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); + // printf("symbol=%d\tz_re_rx=%d\tz_im_rx=%d\t",l,(int)z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); #ifdef DEBUG_NR_PUCCH_RX printf("\t [nr_generate_pucch1] block-wise spread with wi(m) (mprime=%d, m=%d, n=%d) z[%d] = ((%d * %d - %d * %d), (%d * %d + %d * %d)) = (%d,%d)\n", mprime, m, n, (mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n, @@ -671,15 +671,15 @@ void nr_decode_pucch1( int32_t **rxdataF, #endif // multiplying with conjugate of low papr sequence z_re_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - + (((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_im_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - - (((int32_t)(r_u_v_alpha_delta_im[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(r_u_v_alpha_delta_im[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_re_temp; z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_im_temp; -/* if(z_re_temp<0){ - printf("\nBug detection %d\t%d\t%d\t%d\n",r_u_v_alpha_delta_re[n],z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(((int32_t)(r_u_v_alpha_delta_re[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15),(((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15)); - } - printf("z1_re_rx=%d\tz1_im_rx=%d\n",(int)z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); */ + /* if(z_re_temp<0){ + printf("\nBug detection %d\t%d\t%d\t%d\n",r_u_v_alpha_delta_re[n],z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(((int32_t)(r_u_v_alpha_delta_re[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15),(((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15)); + } + printf("z1_re_rx=%d\tz1_im_rx=%d\n",(int)z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); */ } } } @@ -690,12 +690,12 @@ void nr_decode_pucch1( int32_t **rxdataF, if(floor(l/2)*12==(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)){ for (int n=0; n<12 ; n++) { z_dmrs_re_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_im_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_re_temp; z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_im_temp; -// printf("symbol=%d\tz_dmrs_re_rx=%d\tz_dmrs_im_rx=%d\t",l,(int)z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); + // printf("symbol=%d\tz_dmrs_re_rx=%d\tz_dmrs_im_rx=%d\t",l,(int)z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); #ifdef DEBUG_NR_PUCCH_RX printf("\t [nr_generate_pucch1] block-wise spread with wi(m) (mprime=%d, m=%d, n=%d) z[%d] = ((%d * %d - %d * %d), (%d * %d + %d * %d)) = (%d,%d)\n", mprime, m, n, (mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n, @@ -705,17 +705,17 @@ void nr_decode_pucch1( int32_t **rxdataF, #endif //finding channel coeffcients by dividing received dmrs with actual dmrs and storing them in z_dmrs_re_rx and z_dmrs_im_rx arrays z_dmrs_re_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - + (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_im_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - - (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); -/* if(z_dmrs_re_temp<0){ - printf("\nBug detection %d\t%d\t%d\t%d\n",r_u_v_alpha_delta_dmrs_re[n],z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15),(((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15)); - }*/ + - (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + /* if(z_dmrs_re_temp<0){ + printf("\nBug detection %d\t%d\t%d\t%d\n",r_u_v_alpha_delta_dmrs_re[n],z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15),(((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15)); + }*/ z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_re_temp; z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_im_temp; -// printf("z1_dmrs_re_rx=%d\tz1_dmrs_im_rx=%d\n",(int)z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); - /* z_dmrs_re_rx[(int)(l/2)*12+n]=z_dmrs_re_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_re[n]; - z_dmrs_im_rx[(int)(l/2)*12+n]=z_dmrs_im_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_im[n]; */ + // printf("z1_dmrs_re_rx=%d\tz1_dmrs_im_rx=%d\n",(int)z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],(int)z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); + /* z_dmrs_re_rx[(int)(l/2)*12+n]=z_dmrs_re_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_re[n]; + z_dmrs_im_rx[(int)(l/2)*12+n]=z_dmrs_im_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_im[n]; */ } } } @@ -742,9 +742,9 @@ void nr_decode_pucch1( int32_t **rxdataF, if(floor(l/2)*12==(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)){ for (int n=0; n<12 ; n++) { z_re_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_im_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_1][w_index][m])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_1][w_index][m])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_re_temp; z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_im_temp; #ifdef DEBUG_NR_PUCCH_RX @@ -755,9 +755,9 @@ void nr_decode_pucch1( int32_t **rxdataF, z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n],z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n]); #endif z_re_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - + (((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(r_u_v_alpha_delta_im[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_im_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_re[n])*z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15) - - (((int32_t)(r_u_v_alpha_delta_im[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(r_u_v_alpha_delta_im[n])*z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n])>>15))>>1); z_re_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_re_temp; z_im_rx[(mprime*12*N_SF_mprime0_PUCCH_1)+(m*12)+n] = z_im_temp; } @@ -770,9 +770,9 @@ void nr_decode_pucch1( int32_t **rxdataF, if(floor(l/2)*12==(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)){ for (int n=0; n<12 ; n++) { z_dmrs_re_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_im_temp = (int16_t)(((((int32_t)(table_6_3_2_4_1_2_Wi_Re[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(table_6_3_2_4_1_2_Wi_Im[N_SF_mprime_PUCCH_DMRS_1][w_index][m])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_re_temp; z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_im_temp; #ifdef DEBUG_NR_PUCCH_RX @@ -784,14 +784,14 @@ void nr_decode_pucch1( int32_t **rxdataF, #endif //finding channel coeffcients by dividing received dmrs with actual dmrs and storing them in z_dmrs_re_rx and z_dmrs_im_rx arrays z_dmrs_re_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - + (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + + (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_im_temp = (int16_t)(((((int32_t)(r_u_v_alpha_delta_dmrs_re[n])*z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15) - - (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); + - (((int32_t)(r_u_v_alpha_delta_dmrs_im[n])*z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n])>>15))>>1); z_dmrs_re_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_re_temp; z_dmrs_im_rx[(mprime*12*N_SF_mprime0_PUCCH_DMRS_1)+(m*12)+n] = z_dmrs_im_temp; - /* z_dmrs_re_rx[(int)(l/2)*12+n]=z_dmrs_re_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_re[n]; - z_dmrs_im_rx[(int)(l/2)*12+n]=z_dmrs_im_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_im[n]; */ + /* z_dmrs_re_rx[(int)(l/2)*12+n]=z_dmrs_re_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_re[n]; + z_dmrs_im_rx[(int)(l/2)*12+n]=z_dmrs_im_rx[(int)(l/2)*12+n]/r_u_v_alpha_delta_dmrs_im[n]; */ } } } @@ -843,8 +843,8 @@ void nr_decode_pucch1( int32_t **rxdataF, for(int n=0;n<12;n++){ y_n_re[n]=round(z_re_rx[l*12+n]/floor(nrofSymbols/4))+y_n_re[n]; y_n_im[n]=round(z_im_rx[l*12+n]/floor(nrofSymbols/4))+y_n_im[n]; - } - } + } + } else{ for(int n=0;n<12;n++){ y1_n_re[n]=round(z_re_rx[l*12+n]/round(nrofSymbols/4))+y1_n_re[n]; @@ -876,12 +876,12 @@ void nr_decode_pucch1( int32_t **rxdataF, } //Decoding QPSK or BPSK symbols to obtain payload bits if(nr_bit==1){ - if((d_re+d_im)>0){ - *payload=0; - } - else{ - *payload=1; - } + if((d_re+d_im)>0){ + *payload=0; + } + else{ + *payload=1; + } } else if(nr_bit==2){ if((d_re>0)&&(d_im>0)){ @@ -919,6 +919,9 @@ __m256i *pucch2_lut[9]={pucch2_3bit, pucch2_10bit, pucch2_11bit}; +__m64 pucch2_polar_4bit[16]; +__m128i pucch2_polar_llr_num_lut[256],pucch2_polar_llr_den_lut[256]; + void init_pucch2_luts() { uint32_t out; @@ -927,7 +930,9 @@ void init_pucch2_luts() { for (int b=3;b<12;b++) { for (uint16_t i=0;i<(1<<b);i++) { out=encodeSmallBlock(&i,b); +#ifdef DEBUG_NR_PUCCH_RX if (b==3) printf("in %d, out %x\n",i,out); +#endif __m256i *lut_i=&pucch2_lut[b-3][i<<1]; __m256i *lut_ip1=&pucch2_lut[b-3][1+(i<<1)]; bit = (out&0x1) > 0 ? -1 : 1; @@ -996,6 +1001,62 @@ void init_pucch2_luts() { *lut_ip1 = _mm256_insert_epi16(*lut_ip1,bit,15); } } + for (uint16_t i=0;i<16;i++) { + __m64 *lut_i=&pucch2_polar_4bit[i]; + + bit = (i&0x1) > 0 ? -1 : 1; + *lut_i = _mm_insert_pi16(*lut_i,bit,0); + bit = (i&0x2) > 0 ? -1 : 1; + *lut_i = _mm_insert_pi16(*lut_i,bit,1); + bit = (i&0x4) > 0 ? -1 : 1; + *lut_i = _mm_insert_pi16(*lut_i,bit,2); + bit = (i&0x8) > 0 ? -1 : 1; + *lut_i = _mm_insert_pi16(*lut_i,bit,3); + } + for (int i=0;i<256;i++) { + __m128i *lut_num_i=&pucch2_polar_llr_num_lut[i]; + __m128i *lut_den_i=&pucch2_polar_llr_den_lut[i]; + bit = (i&0x1) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,0); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,0); + + bit = (i&0x10) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,1); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,1); + + bit = (i&0x2) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,2); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,2); + + bit = (i&0x20) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,3); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,3); + + bit = (i&0x4) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,4); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,4); + + bit = (i&0x40) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,5); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,5); + + bit = (i&0x8) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,6); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,6); + + bit = (i&0x80) > 0 ? 0 : 1; + *lut_num_i = _mm_insert_epi16(*lut_num_i,bit,7); + *lut_den_i = _mm_insert_epi16(*lut_den_i,1-bit,7); + printf("i %d, lut_num (%d,%d,%d,%d,%d,%d,%d,%d)\n",i, + ((int16_t *)lut_num_i)[0], + ((int16_t *)lut_num_i)[1], + ((int16_t *)lut_num_i)[2], + ((int16_t *)lut_num_i)[3], + ((int16_t *)lut_num_i)[4], + ((int16_t *)lut_num_i)[5], + ((int16_t *)lut_num_i)[6], + ((int16_t *)lut_num_i)[7]); + } } @@ -1008,13 +1069,15 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB, NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms; //pucch_GroupHopping_t pucch_GroupHopping = pucch_pdu->group_hop_flag + (pucch_pdu->sequence_hop_flag<<1); + + AssertFatal(pucch_pdu->nr_of_symbols==1 || pucch_pdu->nr_of_symbols==2, "Illegal number of symbols for PUCCH 2 %d\n",pucch_pdu->nr_of_symbols); //extract pucch and dmrs first - int l2=-1; + int l2=pucch_pdu->start_symbol_index; int re_offset = (12*pucch_pdu->prb_start) + (12*pucch_pdu->bwp_start) + frame_parms->first_carrier_offset; if (re_offset>= frame_parms->ofdm_symbol_size) re_offset-=frame_parms->ofdm_symbol_size; @@ -1031,6 +1094,7 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB, int16_t r_im_ext2[Prx2][8*pucch_pdu->nr_of_symbols*pucch_pdu->prb_size] __attribute__((aligned(32))); int16_t rd_re_ext[Prx2][4*pucch_pdu->nr_of_symbols*pucch_pdu->prb_size] __attribute__((aligned(32))); int16_t rd_im_ext[Prx2][4*pucch_pdu->nr_of_symbols*pucch_pdu->prb_size] __attribute__((aligned(32))); + int16_t *r_re_ext_p,*r_im_ext_p,*rd_re_ext_p,*rd_im_ext_p; int16_t *rp[Prx2]; __m64 dmrs_re,dmrs_im; @@ -1047,156 +1111,166 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB, for (int aa=0;aa<Prx;aa++) for (int group=0;group<ngroup;group++) { corr32_re[group][aa]=0; corr32_im[group][aa]=0;} if (pucch_pdu->nr_of_symbols == 1) { - AssertFatal((pucch_pdu->prb_size&1) == 0,"prb_size %d is not a multiple of 2\n",pucch_pdu->prb_size); - // 24 PRBs contains 48x16-bit, so 6x8x16-bit - for (int prb=0;prb<pucch_pdu->prb_size;prb+=2) { - for (int aa=0;aa<Prx;aa++) { - - r_re_ext[aa][0]=rp[aa][0]; - r_im_ext[aa][0]=rp[aa][1]; - rd_re_ext[aa][0]=rp[aa][2]; - rd_im_ext[aa][0]=rp[aa][3]; - r_re_ext[aa][1]=rp[aa][4]; - r_im_ext[aa][1]=rp[aa][5]; - - r_re_ext[aa][2]=rp[aa][6]; - r_im_ext[aa][2]=rp[aa][7]; - rd_re_ext[aa][1]=rp[aa][8]; - rd_im_ext[aa][1]=rp[aa][9]; - r_re_ext[aa][3]=rp[aa][10]; - r_im_ext[aa][3]=rp[aa][11]; - - r_re_ext[aa][4]=rp[aa][12]; - r_im_ext[aa][4]=rp[aa][13]; - rd_re_ext[aa][2]=rp[aa][14]; - rd_im_ext[aa][2]=rp[aa][15]; - r_re_ext[aa][5]=rp[aa][16]; - r_im_ext[aa][5]=rp[aa][17]; - - r_re_ext[aa][6]=rp[aa][18]; - r_im_ext[aa][6]=rp[aa][19]; - rd_re_ext[aa][3]=rp[aa][20]; - rd_im_ext[aa][3]=rp[aa][21]; - r_re_ext[aa][7]=rp[aa][22]; - r_im_ext[aa][7]=rp[aa][23]; - - r_re_ext[aa][8]=rp[aa][24]; - r_im_ext[aa][8]=rp[aa][25]; - rd_re_ext[aa][4]=rp[aa][26]; - rd_im_ext[aa][4]=rp[aa][27]; - r_re_ext[aa][9]=rp[aa][28]; - r_im_ext[aa][9]=rp[aa][29]; - - r_re_ext[aa][10]=rp[aa][30]; - r_im_ext[aa][10]=rp[aa][31]; - rd_re_ext[aa][5]=rp[aa][32]; - rd_im_ext[aa][5]=rp[aa][33]; - r_re_ext[aa][11]=rp[aa][34]; - r_im_ext[aa][11]=rp[aa][35]; - - r_re_ext[aa][12]=rp[aa][36]; - r_im_ext[aa][12]=rp[aa][37]; - rd_re_ext[aa][6]=rp[aa][38]; - rd_im_ext[aa][6]=rp[aa][39]; - r_re_ext[aa][13]=rp[aa][40]; - r_im_ext[aa][13]=rp[aa][41]; - - r_re_ext[aa][14]=rp[aa][42]; - r_im_ext[aa][14]=rp[aa][43]; - rd_re_ext[aa][7]=rp[aa][44]; - rd_im_ext[aa][7]=rp[aa][45]; - r_re_ext[aa][15]=rp[aa][46]; - r_im_ext[aa][15]=rp[aa][47]; + AssertFatal((pucch_pdu->prb_size&1) == 0,"prb_size %d is not a multiple of 2\n",pucch_pdu->prb_size); + // 24 PRBs contains 48x16-bit, so 6x8x16-bit + for (int prb=0;prb<pucch_pdu->prb_size;prb+=2) { + for (int aa=0;aa<Prx;aa++) { + r_re_ext_p=&r_re_ext[aa][8*prb]; + r_im_ext_p=&r_im_ext[aa][8*prb]; + rd_re_ext_p=&rd_re_ext[aa][4*prb]; + rd_im_ext_p=&rd_im_ext[aa][4*prb]; + + r_re_ext_p[0]=rp[aa][0]; + r_im_ext_p[0]=rp[aa][1]; + rd_re_ext_p[0]=rp[aa][2]; + rd_im_ext_p[0]=rp[aa][3]; + r_re_ext_p[1]=rp[aa][4]; + r_im_ext_p[1]=rp[aa][5]; + + r_re_ext_p[2]=rp[aa][6]; + r_im_ext_p[2]=rp[aa][7]; + rd_re_ext_p[1]=rp[aa][8]; + rd_im_ext_p[1]=rp[aa][9]; + r_re_ext_p[3]=rp[aa][10]; + r_im_ext_p[3]=rp[aa][11]; + + r_re_ext_p[4]=rp[aa][12]; + r_im_ext_p[4]=rp[aa][13]; + rd_re_ext_p[2]=rp[aa][14]; + rd_im_ext_p[2]=rp[aa][15]; + r_re_ext_p[5]=rp[aa][16]; + r_im_ext_p[5]=rp[aa][17]; + + r_re_ext_p[6]=rp[aa][18]; + r_im_ext_p[6]=rp[aa][19]; + rd_re_ext_p[3]=rp[aa][20]; + rd_im_ext_p[3]=rp[aa][21]; + r_re_ext_p[7]=rp[aa][22]; + r_im_ext_p[7]=rp[aa][23]; + + r_re_ext_p[8]=rp[aa][24]; + r_im_ext_p[8]=rp[aa][25]; + rd_re_ext_p[4]=rp[aa][26]; + rd_im_ext_p[4]=rp[aa][27]; + r_re_ext_p[9]=rp[aa][28]; + r_im_ext_p[9]=rp[aa][29]; + + r_re_ext_p[10]=rp[aa][30]; + r_im_ext_p[10]=rp[aa][31]; + rd_re_ext_p[5]=rp[aa][32]; + rd_im_ext_p[5]=rp[aa][33]; + r_re_ext_p[11]=rp[aa][34]; + r_im_ext_p[11]=rp[aa][35]; + + r_re_ext_p[12]=rp[aa][36]; + r_im_ext_p[12]=rp[aa][37]; + rd_re_ext_p[6]=rp[aa][38]; + rd_im_ext_p[6]=rp[aa][39]; + r_re_ext_p[13]=rp[aa][40]; + r_im_ext_p[13]=rp[aa][41]; + + r_re_ext_p[14]=rp[aa][42]; + r_im_ext_p[14]=rp[aa][43]; + rd_re_ext_p[7]=rp[aa][44]; + rd_im_ext_p[7]=rp[aa][45]; + r_re_ext_p[15]=rp[aa][46]; + r_im_ext_p[15]=rp[aa][47]; #ifdef DEBUG_NR_PUCCH_RX - for (int i=0;i<8;i++) printf("Ant %d PRB %d dmrs[%d] -> (%d,%d)\n",aa,prb+(i>>2),i,rd_re_ext[aa][i],rd_im_ext[aa]); + for (int i=0;i<8;i++) printf("Ant %d PRB %d dmrs[%d] -> (%d,%d)\n",aa,prb+(i>>2),i,rd_re_ext_p[i],rd_im_ext_p[i]); + for (int i=0;i<16;i++) printf("Ant %d PRB %d data[%d] -> (%d,%d)\n",aa,prb+(i>>3),i,r_re_ext_p[i],r_im_ext_p[i]); #endif - } // aa - } // prb + rp[aa]+=48; + } // aa + } // prb - // first compute DMRS component - uint32_t x1, x2, s=0; - x2 = (((1<<17)*((14*slot) + (pucch_pdu->start_symbol_index) + 1)*((2*pucch_pdu->dmrs_scrambling_id) + 1)) + (2*pucch_pdu->dmrs_scrambling_id))%(1U<<31); // c_init calculation according to TS38.211 subclause + // first compute DMRS component + uint32_t x1, x2, s=0; + x2 = (((1<<17)*((14*slot) + (pucch_pdu->start_symbol_index) + 1)*((2*pucch_pdu->dmrs_scrambling_id) + 1)) + (2*pucch_pdu->dmrs_scrambling_id))%(1U<<31); // c_init calculation according to TS38.211 subclause #ifdef DEBUG_NR_PUCCH_RX - printf("slot %d, start_symbol_index %d, dmrs_scrambling_id %d\n", - slot,pucch_pdu->start_symbol_index,pucch_pdu->dmrs_scrambling_id); + printf("slot %d, start_symbol_index %d, dmrs_scrambling_id %d\n", + slot,pucch_pdu->start_symbol_index,pucch_pdu->dmrs_scrambling_id); #endif - s = lte_gold_generic(&x1, &x2, 1); + s = lte_gold_generic(&x1, &x2, 1); - - for (int group=0;group<ngroup;group++) { - // each group has 8*nc_group_size elements, compute 1 complex correlation with DMRS per group - // non-coherent combining across groups - dmrs_re = byte2m64_re[((uint8_t*)&s)[(group&1)<<1]]; - dmrs_im = byte2m64_im[((uint8_t*)&s)[(group&1)<<1]]; + for (int group=0;group<ngroup;group++) { + // each group has 8*nc_group_size elements, compute 1 complex correlation with DMRS per group + // non-coherent combining across groups + dmrs_re = byte2m64_re[((uint8_t*)&s)[(group&1)<<1]]; + dmrs_im = byte2m64_im[((uint8_t*)&s)[(group&1)<<1]]; #ifdef DEBUG_NR_PUCCH_RX - printf("Group %d: s %x x2 %x ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - group, - ((uint16_t*)&s)[0],x2, - ((int16_t*)&dmrs_re)[0],((int16_t*)&dmrs_im)[0], - ((int16_t*)&dmrs_re)[1],((int16_t*)&dmrs_im)[1], - ((int16_t*)&dmrs_re)[2],((int16_t*)&dmrs_im)[2], - ((int16_t*)&dmrs_re)[3],((int16_t*)&dmrs_im)[3]); + printf("Group %d: s %x x2 %x ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + group, + ((uint16_t*)&s)[0],x2, + ((int16_t*)&dmrs_re)[0],((int16_t*)&dmrs_im)[0], + ((int16_t*)&dmrs_re)[1],((int16_t*)&dmrs_im)[1], + ((int16_t*)&dmrs_re)[2],((int16_t*)&dmrs_im)[2], + ((int16_t*)&dmrs_re)[3],((int16_t*)&dmrs_im)[3]); #endif - for (int aa=0;aa<Prx;aa++) { + for (int aa=0;aa<Prx;aa++) { + rd_re_ext_p=&rd_re_ext[aa][8*group]; + rd_im_ext_p=&rd_im_ext[aa][8*group]; + #ifdef DEBUG_NR_PUCCH_RX - printf("Group %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - group, - rd_re_ext[aa][0],rd_im_ext[aa][0], - rd_re_ext[aa][1],rd_im_ext[aa][1], - rd_re_ext[aa][2],rd_im_ext[aa][2], - rd_re_ext[aa][3],rd_im_ext[aa][3]); + printf("Group %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + group, + rd_re_ext_p[0],rd_im_ext_p[0], + rd_re_ext_p[1],rd_im_ext_p[1], + rd_re_ext_p[2],rd_im_ext_p[2], + rd_re_ext_p[3],rd_im_ext_p[3]); #endif - corr32_re[group][aa]+=(rd_re_ext[aa][0]*((int16_t*)&dmrs_re)[0] + rd_im_ext[aa][0]*((int16_t*)&dmrs_im)[0]); - corr32_im[group][aa]+=(-rd_re_ext[aa][0]*((int16_t*)&dmrs_im)[0] + rd_im_ext[aa][0]*((int16_t*)&dmrs_re)[0]); - corr32_re[group][aa]+=(rd_re_ext[aa][1]*((int16_t*)&dmrs_re)[1] + rd_im_ext[aa][1]*((int16_t*)&dmrs_im)[1]); - corr32_im[group][aa]+=(-rd_re_ext[aa][1]*((int16_t*)&dmrs_im)[1] + rd_im_ext[aa][1]*((int16_t*)&dmrs_re)[1]); - corr32_re[group][aa]+=(rd_re_ext[aa][2]*((int16_t*)&dmrs_re)[2] + rd_im_ext[aa][2]*((int16_t*)&dmrs_im)[2]); - corr32_im[group][aa]+=(-rd_re_ext[aa][2]*((int16_t*)&dmrs_im)[2] + rd_im_ext[aa][2]*((int16_t*)&dmrs_re)[2]); - corr32_re[group][aa]+=(rd_re_ext[aa][3]*((int16_t*)&dmrs_re)[3] + rd_im_ext[aa][3]*((int16_t*)&dmrs_im)[3]); - corr32_im[group][aa]+=(-rd_re_ext[aa][3]*((int16_t*)&dmrs_im)[3] + rd_im_ext[aa][3]*((int16_t*)&dmrs_re)[3]); - } - dmrs_re = byte2m64_re[((uint8_t*)&s)[1+((group&1)<<1)]]; - dmrs_im = byte2m64_im[((uint8_t*)&s)[1+((group&1)<<1)]]; + corr32_re[group][aa]+=(rd_re_ext_p[0]*((int16_t*)&dmrs_re)[0] + rd_im_ext_p[0]*((int16_t*)&dmrs_im)[0]); + corr32_im[group][aa]+=(-rd_re_ext_p[0]*((int16_t*)&dmrs_im)[0] + rd_im_ext_p[0]*((int16_t*)&dmrs_re)[0]); + corr32_re[group][aa]+=(rd_re_ext_p[1]*((int16_t*)&dmrs_re)[1] + rd_im_ext_p[1]*((int16_t*)&dmrs_im)[1]); + corr32_im[group][aa]+=(-rd_re_ext_p[1]*((int16_t*)&dmrs_im)[1] + rd_im_ext_p[1]*((int16_t*)&dmrs_re)[1]); + corr32_re[group][aa]+=(rd_re_ext_p[2]*((int16_t*)&dmrs_re)[2] + rd_im_ext_p[2]*((int16_t*)&dmrs_im)[2]); + corr32_im[group][aa]+=(-rd_re_ext_p[2]*((int16_t*)&dmrs_im)[2] + rd_im_ext_p[2]*((int16_t*)&dmrs_re)[2]); + corr32_re[group][aa]+=(rd_re_ext_p[3]*((int16_t*)&dmrs_re)[3] + rd_im_ext_p[3]*((int16_t*)&dmrs_im)[3]); + corr32_im[group][aa]+=(-rd_re_ext_p[3]*((int16_t*)&dmrs_im)[3] + rd_im_ext_p[3]*((int16_t*)&dmrs_re)[3]); + } + dmrs_re = byte2m64_re[((uint8_t*)&s)[1+((group&1)<<1)]]; + dmrs_im = byte2m64_im[((uint8_t*)&s)[1+((group&1)<<1)]]; #ifdef DEBUG_NR_PUCCH_RX - printf("Group %d: s %x ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - group, - ((uint16_t*)&s)[1], - ((int16_t*)&dmrs_re)[0],((int16_t*)&dmrs_im)[0], - ((int16_t*)&dmrs_re)[1],((int16_t*)&dmrs_im)[1], - ((int16_t*)&dmrs_re)[2],((int16_t*)&dmrs_im)[2], - ((int16_t*)&dmrs_re)[3],((int16_t*)&dmrs_im)[3]); + printf("Group %d: s %x ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + group, + ((uint16_t*)&s)[1], + ((int16_t*)&dmrs_re)[0],((int16_t*)&dmrs_im)[0], + ((int16_t*)&dmrs_re)[1],((int16_t*)&dmrs_im)[1], + ((int16_t*)&dmrs_re)[2],((int16_t*)&dmrs_im)[2], + ((int16_t*)&dmrs_re)[3],((int16_t*)&dmrs_im)[3]); #endif - for (int aa=0;aa<Prx;aa++) { + for (int aa=0;aa<Prx;aa++) { + rd_re_ext_p=&rd_re_ext[aa][8*group]; + rd_im_ext_p=&rd_im_ext[aa][8*group]; #ifdef DEBUG_NR_PUCCH_RX - printf("Group %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - group, - rd_re_ext[aa][4],rd_im_ext[aa][4], - rd_re_ext[aa][5],rd_im_ext[aa][5], - rd_re_ext[aa][6],rd_im_ext[aa][6], - rd_re_ext[aa][7],rd_im_ext[aa][7]); + printf("Group %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + group, + rd_re_ext_p[4],rd_im_ext_p[4], + rd_re_ext_p[5],rd_im_ext_p[5], + rd_re_ext_p[6],rd_im_ext_p[6], + rd_re_ext_p[7],rd_im_ext_p[7]); #endif - corr32_re[group][aa]+=(rd_re_ext[aa][4]*((int16_t*)&dmrs_re)[0] + rd_im_ext[aa][4]*((int16_t*)&dmrs_im)[0]); - corr32_im[group][aa]+=(-rd_re_ext[aa][4]*((int16_t*)&dmrs_im)[0] + rd_im_ext[aa][4]*((int16_t*)&dmrs_re)[0]); - corr32_re[group][aa]+=(rd_re_ext[aa][5]*((int16_t*)&dmrs_re)[1] + rd_im_ext[aa][5]*((int16_t*)&dmrs_im)[1]); - corr32_im[group][aa]+=(-rd_re_ext[aa][5]*((int16_t*)&dmrs_im)[1] + rd_im_ext[aa][5]*((int16_t*)&dmrs_re)[1]); - corr32_re[group][aa]+=(rd_re_ext[aa][6]*((int16_t*)&dmrs_re)[2] + rd_im_ext[aa][6]*((int16_t*)&dmrs_im)[2]); - corr32_im[group][aa]+=(-rd_re_ext[aa][6]*((int16_t*)&dmrs_im)[2] + rd_im_ext[aa][6]*((int16_t*)&dmrs_re)[2]); - corr32_re[group][aa]+=(rd_re_ext[aa][7]*((int16_t*)&dmrs_re)[3] + rd_im_ext[aa][7]*((int16_t*)&dmrs_im)[3]); - corr32_im[group][aa]+=(-rd_re_ext[aa][7]*((int16_t*)&dmrs_im)[3] + rd_im_ext[aa][7]*((int16_t*)&dmrs_re)[3]); - corr32_re[group][aa]>>=5; - corr32_im[group][aa]>>=5; + corr32_re[group][aa]+=(rd_re_ext_p[4]*((int16_t*)&dmrs_re)[0] + rd_im_ext_p[4]*((int16_t*)&dmrs_im)[0]); + corr32_im[group][aa]+=(-rd_re_ext_p[4]*((int16_t*)&dmrs_im)[0] + rd_im_ext_p[4]*((int16_t*)&dmrs_re)[0]); + corr32_re[group][aa]+=(rd_re_ext_p[5]*((int16_t*)&dmrs_re)[1] + rd_im_ext_p[5]*((int16_t*)&dmrs_im)[1]); + corr32_im[group][aa]+=(-rd_re_ext_p[5]*((int16_t*)&dmrs_im)[1] + rd_im_ext_p[5]*((int16_t*)&dmrs_re)[1]); + corr32_re[group][aa]+=(rd_re_ext_p[6]*((int16_t*)&dmrs_re)[2] + rd_im_ext_p[6]*((int16_t*)&dmrs_im)[2]); + corr32_im[group][aa]+=(-rd_re_ext_p[6]*((int16_t*)&dmrs_im)[2] + rd_im_ext_p[6]*((int16_t*)&dmrs_re)[2]); + corr32_re[group][aa]+=(rd_re_ext_p[7]*((int16_t*)&dmrs_re)[3] + rd_im_ext_p[7]*((int16_t*)&dmrs_im)[3]); + corr32_im[group][aa]+=(-rd_re_ext_p[7]*((int16_t*)&dmrs_im)[3] + rd_im_ext_p[7]*((int16_t*)&dmrs_re)[3]); + corr32_re[group][aa]>>=5; + corr32_im[group][aa]>>=5; #ifdef DEBUG_NR_PUCCH_RX - printf("Group %d: corr32 (%d,%d)\n",group,corr32_re[group][aa],corr32_im[group][aa]); + printf("Group %d: corr32 (%d,%d)\n",group,corr32_re[group][aa],corr32_im[group][aa]); #endif - } //aa + } //aa - if ((group&3) == 3) s = lte_gold_generic(&x1, &x2, 0); - } // group + if ((group&1) == 1) s = lte_gold_generic(&x1, &x2, 0); + } // group } else { // 2 symbol case - AssertFatal(1==0, "Fill in 2 symbol PUCCH2 case\n"); + AssertFatal(1==0, "Fill in 2 symbol PUCCH2 case\n"); } uint32_t x1, x2, s=0; @@ -1221,47 +1295,47 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB, for (int aa=0;aa<Prx;aa++) { #ifdef DEBUG_NR_PUCCH_RX printf("prb %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - prb, - r_re_ext[aa][re_offset],r_im_ext[aa][re_offset], - r_re_ext[aa][re_offset+1],r_im_ext[aa][re_offset+1], - r_re_ext[aa][re_offset+2],r_im_ext[aa][re_offset+2], - r_re_ext[aa][re_offset+3],r_im_ext[aa][re_offset+3], - r_re_ext[aa][re_offset+4],r_im_ext[aa][re_offset+4], - r_re_ext[aa][re_offset+5],r_im_ext[aa][re_offset+5], - r_re_ext[aa][re_offset+6],r_im_ext[aa][re_offset+6], - r_re_ext[aa][re_offset+7],r_im_ext[aa][re_offset+7]); - printf("prb %d: c ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - prb, - ((int16_t*)&c_re0)[0],((int16_t*)&c_im0)[0], - ((int16_t*)&c_re0)[1],((int16_t*)&c_im0)[1], - ((int16_t*)&c_re0)[2],((int16_t*)&c_im0)[2], - ((int16_t*)&c_re0)[3],((int16_t*)&c_im0)[3], - ((int16_t*)&c_re1)[0],((int16_t*)&c_im1)[0], - ((int16_t*)&c_re1)[1],((int16_t*)&c_im1)[1], - ((int16_t*)&c_re1)[2],((int16_t*)&c_im1)[2], - ((int16_t*)&c_re1)[3],((int16_t*)&c_im1)[3] - ); + prb, + r_re_ext[aa][re_offset],r_im_ext[aa][re_offset], + r_re_ext[aa][re_offset+1],r_im_ext[aa][re_offset+1], + r_re_ext[aa][re_offset+2],r_im_ext[aa][re_offset+2], + r_re_ext[aa][re_offset+3],r_im_ext[aa][re_offset+3], + r_re_ext[aa][re_offset+4],r_im_ext[aa][re_offset+4], + r_re_ext[aa][re_offset+5],r_im_ext[aa][re_offset+5], + r_re_ext[aa][re_offset+6],r_im_ext[aa][re_offset+6], + r_re_ext[aa][re_offset+7],r_im_ext[aa][re_offset+7]); + printf("prb %d (%x): c ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + prb,s, + ((int16_t*)&c_re0)[0],((int16_t*)&c_im0)[0], + ((int16_t*)&c_re0)[1],((int16_t*)&c_im0)[1], + ((int16_t*)&c_re0)[2],((int16_t*)&c_im0)[2], + ((int16_t*)&c_re0)[3],((int16_t*)&c_im0)[3], + ((int16_t*)&c_re1)[0],((int16_t*)&c_im1)[0], + ((int16_t*)&c_re1)[1],((int16_t*)&c_im1)[1], + ((int16_t*)&c_re1)[2],((int16_t*)&c_im1)[2], + ((int16_t*)&c_re1)[3],((int16_t*)&c_im1)[3] + ); printf("prb %d: rd ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - prb+1, - r_re_ext[aa][re_offset+8],r_im_ext[aa][re_offset+8], - r_re_ext[aa][re_offset+9],r_im_ext[aa][re_offset+9], - r_re_ext[aa][re_offset+10],r_im_ext[aa][re_offset+10], - r_re_ext[aa][re_offset+11],r_im_ext[aa][re_offset+11], - r_re_ext[aa][re_offset+12],r_im_ext[aa][re_offset+12], - r_re_ext[aa][re_offset+13],r_im_ext[aa][re_offset+13], - r_re_ext[aa][re_offset+14],r_im_ext[aa][re_offset+14], - r_re_ext[aa][re_offset+15],r_im_ext[aa][re_offset+15]); - printf("prb %d: c ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", - prb+1, - ((int16_t*)&c_re2)[0],((int16_t*)&c_im2)[0], - ((int16_t*)&c_re2)[1],((int16_t*)&c_im2)[1], - ((int16_t*)&c_re2)[2],((int16_t*)&c_im2)[2], - ((int16_t*)&c_re2)[3],((int16_t*)&c_im2)[3], - ((int16_t*)&c_re3)[0],((int16_t*)&c_im3)[0], - ((int16_t*)&c_re3)[1],((int16_t*)&c_im3)[1], - ((int16_t*)&c_re3)[2],((int16_t*)&c_im3)[2], - ((int16_t*)&c_re3)[3],((int16_t*)&c_im3)[3] - ); + prb+1, + r_re_ext[aa][re_offset+8],r_im_ext[aa][re_offset+8], + r_re_ext[aa][re_offset+9],r_im_ext[aa][re_offset+9], + r_re_ext[aa][re_offset+10],r_im_ext[aa][re_offset+10], + r_re_ext[aa][re_offset+11],r_im_ext[aa][re_offset+11], + r_re_ext[aa][re_offset+12],r_im_ext[aa][re_offset+12], + r_re_ext[aa][re_offset+13],r_im_ext[aa][re_offset+13], + r_re_ext[aa][re_offset+14],r_im_ext[aa][re_offset+14], + r_re_ext[aa][re_offset+15],r_im_ext[aa][re_offset+15]); + printf("prb %d (%x): c ((%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d),(%d,%d))\n", + prb+1,s, + ((int16_t*)&c_re2)[0],((int16_t*)&c_im2)[0], + ((int16_t*)&c_re2)[1],((int16_t*)&c_im2)[1], + ((int16_t*)&c_re2)[2],((int16_t*)&c_im2)[2], + ((int16_t*)&c_re2)[3],((int16_t*)&c_im2)[3], + ((int16_t*)&c_re3)[0],((int16_t*)&c_im3)[0], + ((int16_t*)&c_re3)[1],((int16_t*)&c_im3)[1], + ((int16_t*)&c_re3)[2],((int16_t*)&c_im3)[2], + ((int16_t*)&c_re3)[3],((int16_t*)&c_im3)[3] + ); #endif ((__m64*)&r_re_ext2[aa][re_offset])[0] = _mm_mullo_pi16(((__m64*)&r_re_ext[aa][re_offset])[0],c_im0); @@ -1308,87 +1382,278 @@ void nr_decode_pucch2(PHY_VARS_gNB *gNB, #endif } s = lte_gold_generic(&x1, &x2, 0); - } - AssertFatal(pucch_pdu->bit_len_csi_part1 + pucch_pdu->bit_len_csi_part2 == 0,"no csi for now\n"); - AssertFatal((pucch_pdu->bit_len_harq+pucch_pdu->sr_flag > 2 ) && (pucch_pdu->bit_len_harq+pucch_pdu->sr_flag < 12),"illegal length (%d,%d)\n",pucch_pdu->bit_len_harq,pucch_pdu->sr_flag); - int nb_bit = pucch_pdu->bit_len_harq+pucch_pdu->sr_flag; - __m256i *rp_re[Prx2]; - __m256i *rp2_re[Prx2]; - __m256i *rp_im[Prx2]; - __m256i *rp2_im[Prx2]; - for (int aa=0;aa<Prx;aa++) { - rp_re[aa] = (__m256i*)r_re_ext[aa]; - rp_im[aa] = (__m256i*)r_im_ext[aa]; - rp2_re[aa] = (__m256i*)r_re_ext2[aa]; - rp2_im[aa] = (__m256i*)r_im_ext2[aa]; - } - __m256i prod_re[Prx2],prod_im[Prx2]; - int64_t corr=0; - int cw_ML=0; - - for (int cw=0;cw<1<<nb_bit;cw++) { #ifdef DEBUG_NR_PUCCH_RX - printf("cw %d:",cw); - for (int i=0;i<32;i+=2) { - printf("%d,%d,", - ((int16_t*)&pucch2_lut[nb_bit-3][cw<<1])[i>>1], - ((int16_t*)&pucch2_lut[nb_bit-3][cw<<1])[1+(i>>1)]); - } printf("\n"); #endif - // do complex correlation + } + int nb_bit = pucch_pdu->bit_len_harq+pucch_pdu->sr_flag+pucch_pdu->bit_len_csi_part1+pucch_pdu->bit_len_csi_part2; + AssertFatal(nb_bit > 2 && nb_bit< 65,"illegal length (%d : %d,%d,%d,%d)\n",nb_bit,pucch_pdu->bit_len_harq,pucch_pdu->sr_flag,pucch_pdu->bit_len_csi_part1,pucch_pdu->bit_len_csi_part2); + + uint64_t decodedPayload[2]; + uint8_t corr_dB; + int decoderState=2; + if (nb_bit < 12) { // short blocklength case + __m256i *rp_re[Prx2]; + __m256i *rp2_re[Prx2]; + __m256i *rp_im[Prx2]; + __m256i *rp2_im[Prx2]; for (int aa=0;aa<Prx;aa++) { - prod_re[aa] = _mm256_srai_epi16(_mm256_adds_epi16(_mm256_mullo_epi16(pucch2_lut[nb_bit-3][cw<<1],rp_re[aa][0]), - _mm256_mullo_epi16(pucch2_lut[nb_bit-3][(cw<<1)+1],rp_im[aa][0])),5); - prod_im[aa] = _mm256_srai_epi16(_mm256_subs_epi16(_mm256_mullo_epi16(pucch2_lut[nb_bit-3][cw<<1],rp2_im[aa][0]), - _mm256_mullo_epi16(pucch2_lut[nb_bit-3][(cw<<1)+1],rp2_re[aa][0])),5); - prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1 - prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); - prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3 - prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); - prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3+4+5+6+7 - prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); - prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15 - prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); + rp_re[aa] = (__m256i*)r_re_ext[aa]; + rp_im[aa] = (__m256i*)r_im_ext[aa]; + rp2_re[aa] = (__m256i*)r_re_ext2[aa]; + rp2_im[aa] = (__m256i*)r_im_ext2[aa]; } - int64_t corr_re=0,corr_im=0; + __m256i prod_re[Prx2],prod_im[Prx2]; + int64_t corr=0; + int cw_ML=0; + + + for (int cw=0;cw<1<<nb_bit;cw++) { +#ifdef DEBUG_NR_PUCCH_RX + printf("cw %d:",cw); + for (int i=0;i<32;i+=2) { + printf("%d,%d,", + ((int16_t*)&pucch2_lut[nb_bit-3][cw<<1])[i>>1], + ((int16_t*)&pucch2_lut[nb_bit-3][cw<<1])[1+(i>>1)]); + } + printf("\n"); +#endif + // do complex correlation + for (int aa=0;aa<Prx;aa++) { + prod_re[aa] = _mm256_srai_epi16(_mm256_adds_epi16(_mm256_mullo_epi16(pucch2_lut[nb_bit-3][cw<<1],rp_re[aa][0]), + _mm256_mullo_epi16(pucch2_lut[nb_bit-3][(cw<<1)+1],rp_im[aa][0])),5); + prod_im[aa] = _mm256_srai_epi16(_mm256_subs_epi16(_mm256_mullo_epi16(pucch2_lut[nb_bit-3][cw<<1],rp2_im[aa][0]), + _mm256_mullo_epi16(pucch2_lut[nb_bit-3][(cw<<1)+1],rp2_re[aa][0])),5); +#ifdef DEBUG_NR_PUCCH_RX + printf("prod_re[%d] => (%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",aa, + ((int16_t*)&prod_re[aa])[0],((int16_t*)&prod_re[aa])[1],((int16_t*)&prod_re[aa])[2],((int16_t*)&prod_re[aa])[3], + ((int16_t*)&prod_re[aa])[4],((int16_t*)&prod_re[aa])[5],((int16_t*)&prod_re[aa])[6],((int16_t*)&prod_re[aa])[7], + ((int16_t*)&prod_re[aa])[8],((int16_t*)&prod_re[aa])[9],((int16_t*)&prod_re[aa])[10],((int16_t*)&prod_re[aa])[11], + ((int16_t*)&prod_re[aa])[12],((int16_t*)&prod_re[aa])[13],((int16_t*)&prod_re[aa])[14],((int16_t*)&prod_re[aa])[15]); + printf("prod_im[%d] => (%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",aa, + ((int16_t*)&prod_im[aa])[0],((int16_t*)&prod_im[aa])[1],((int16_t*)&prod_im[aa])[2],((int16_t*)&prod_im[aa])[3], + ((int16_t*)&prod_im[aa])[4],((int16_t*)&prod_im[aa])[5],((int16_t*)&prod_im[aa])[6],((int16_t*)&prod_im[aa])[7], + ((int16_t*)&prod_im[aa])[8],((int16_t*)&prod_im[aa])[9],((int16_t*)&prod_im[aa])[10],((int16_t*)&prod_im[aa])[11], + ((int16_t*)&prod_im[aa])[12],((int16_t*)&prod_im[aa])[13],((int16_t*)&prod_im[aa])[14],((int16_t*)&prod_im[aa])[15]); - for (int aa=0;aa<Prx;aa++) { - LOG_D(PHY,"pucch2 cw %d aa %d: (%d,%d)+(%d,%d) = (%d,%d)\n",cw,aa, - corr32_re[0][aa],corr32_im[0][aa], - ((int16_t*)(&prod_re[aa]))[0], - ((int16_t*)(&prod_im[aa]))[0], - corr32_re[0][aa]+((int16_t*)(&prod_re[0]))[0], - corr32_im[0][aa]+((int16_t*)(&prod_im[0]))[0]); - - corr_re += ( corr32_re[0][aa]+((int16_t*)(&prod_re[0]))[0]); - corr_im += ( corr32_im[0][aa]+((int16_t*)(&prod_im[0]))[0]); +#endif + prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1 + prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); + prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3 + prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); + prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3+4+5+6+7 + prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); + prod_re[aa] = _mm256_hadds_epi16(prod_re[aa],prod_re[aa]);// 0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15 + prod_im[aa] = _mm256_hadds_epi16(prod_im[aa],prod_im[aa]); + } + int64_t corr_re=0,corr_im=0; + + int64_t corr_tmp = 0; + for (int aa=0;aa<Prx;aa++) { + LOG_D(PHY,"pucch2 cw %d aa %d: (%d,%d)+(%d,%d) = (%d,%d)\n",cw,aa, + corr32_re[0][aa],corr32_im[0][aa], + ((int16_t*)(&prod_re[aa]))[0], + ((int16_t*)(&prod_im[aa]))[0], + corr32_re[0][aa]+((int16_t*)(&prod_re[0]))[0], + corr32_im[0][aa]+((int16_t*)(&prod_im[0]))[0]); + + corr_re = ( corr32_re[0][aa]+((int16_t*)(&prod_re[0]))[0]); + corr_im = ( corr32_im[0][aa]+((int16_t*)(&prod_im[0]))[0]); + + corr_tmp += corr_re*corr_re + corr_im*corr_im; + } + if (corr_tmp > corr) { + corr = corr_tmp; + cw_ML=cw; + } } - int64_t corr_tmp = corr_re*corr_re + corr_im*corr_im; - if (corr_tmp > corr) { - corr = corr_tmp; - cw_ML=cw; + corr_dB = dB_fixed64((uint64_t)corr); + LOG_D(PHY,"cw_ML %d, metric %d dB\n",cw_ML,corr_dB); + decodedPayload[0]=(uint64_t)cw_ML; + } + else { // polar coded case + + t_nrPolar_params *currentPtr = nr_polar_params(2,nb_bit,pucch_pdu->prb_size,1,&gNB->uci_polarParams); + __m64 *rp_re[Prx2]; + __m64 *rp2_re[Prx2]; + __m64 *rp_im[Prx2]; + __m64 *rp2_im[Prx2]; + __m128i llrs[pucch_pdu->prb_size*2]; + + for (int aa=0;aa<Prx;aa++) { + rp_re[aa] = (__m64*)r_re_ext[aa]; + rp_im[aa] = (__m64*)r_im_ext[aa]; + rp2_re[aa] = (__m64*)r_re_ext2[aa]; + rp2_im[aa] = (__m64*)r_im_ext2[aa]; } + __m64 prod_re[Prx2],prod_im[Prx2]; + +#ifdef DEBUG_NR_PUCCH_RX + for (int cw=0;cw<16;cw++) { + + printf("cw %d:",cw); + for (int i=0;i<4;i++) { + printf("%d,", + ((int16_t*)&pucch2_polar_4bit[cw])[i>>1]); + } + printf("\n"); + } +#endif + + // non-coherent LLR computation on groups of 4 REs (half-PRBs) + int32_t corr_re,corr_im,corr_tmp; + __m128i corr16,llr_num,llr_den; + uint64_t corr = 0; + + for (int half_prb=0;half_prb<(2*pucch_pdu->prb_size);half_prb++) { + llr_num=_mm_set1_epi16(0);llr_den=_mm_set1_epi16(0); + for (int cw=0;cw<256;cw++) { + corr_tmp=0; + for (int aa=0;aa<Prx;aa++) { + prod_re[aa] = _mm_srai_pi16(_mm_adds_pi16(_mm_mullo_pi16(pucch2_polar_4bit[cw&15],rp_re[aa][half_prb]), + _mm_mullo_pi16(pucch2_polar_4bit[cw>>4],rp_im[aa][half_prb])),5); + prod_im[aa] = _mm_srai_pi16(_mm_subs_pi16(_mm_mullo_pi16(pucch2_polar_4bit[cw&15],rp2_im[aa][half_prb]), + _mm_mullo_pi16(pucch2_polar_4bit[cw>>4],rp2_re[aa][half_prb])),5); + prod_re[aa] = _mm_hadds_pi16(prod_re[aa],prod_re[aa]);// 0+1 + prod_im[aa] = _mm_hadds_pi16(prod_im[aa],prod_im[aa]); + prod_re[aa] = _mm_hadds_pi16(prod_re[aa],prod_re[aa]);// 0+1+2+3 + prod_im[aa] = _mm_hadds_pi16(prod_im[aa],prod_im[aa]); + + // this is for UL CQI measurement + if (cw==0) corr += ((int64_t)corr32_re[half_prb>>2][aa]*corr32_re[half_prb>>2][aa])+ + ((int64_t)corr32_im[half_prb>>2][aa]*corr32_im[half_prb>>2][aa]); + + + corr_re = ( corr32_re[half_prb>>2][aa]/(2*nc_group_size*4/2)+((int16_t*)(&prod_re[aa]))[0]); + corr_im = ( corr32_im[half_prb>>2][aa]/(2*nc_group_size*4/2)+((int16_t*)(&prod_im[aa]))[0]); + corr_tmp += corr_re*corr_re + corr_im*corr_im; + /* + LOG_D(PHY,"pucch2 half_prb %d cw %d (%d,%d) aa %d: (%d,%d,%d,%d,%d,%d,%d,%d)x(%d,%d,%d,%d,%d,%d,%d,%d) (%d,%d)+(%d,%d) = (%d,%d) => %d\n", + half_prb,cw,cw&15,cw>>4,aa, + ((int16_t*)&pucch2_polar_4bit[cw&15])[0],((int16_t*)&pucch2_polar_4bit[cw>>4])[0], + ((int16_t*)&pucch2_polar_4bit[cw&15])[1],((int16_t*)&pucch2_polar_4bit[cw>>4])[1], + ((int16_t*)&pucch2_polar_4bit[cw&15])[2],((int16_t*)&pucch2_polar_4bit[cw>>4])[2], + ((int16_t*)&pucch2_polar_4bit[cw&15])[3],((int16_t*)&pucch2_polar_4bit[cw>>4])[3], + ((int16_t*)&rp_re[aa][half_prb])[0],((int16_t*)&rp_im[aa][half_prb])[0], + ((int16_t*)&rp_re[aa][half_prb])[1],((int16_t*)&rp_im[aa][half_prb])[1], + ((int16_t*)&rp_re[aa][half_prb])[2],((int16_t*)&rp_im[aa][half_prb])[2], + ((int16_t*)&rp_re[aa][half_prb])[3],((int16_t*)&rp_im[aa][half_prb])[3], + corr32_re[half_prb>>2][aa]/(2*nc_group_size*4/2),corr32_im[half_prb>>2][aa]/(2*nc_group_size*4/2), + ((int16_t*)(&prod_re[aa]))[0], + ((int16_t*)(&prod_im[aa]))[0], + corr_re, + corr_im, + corr_tmp); + */ + } + corr16 = _mm_set1_epi16((int16_t)(corr_tmp>>8)); + /* + LOG_D(PHY,"half_prb %d cw %d corr16 %d\n",half_prb,cw,corr_tmp>>8); + */ + llr_num = _mm_max_epi16(_mm_mullo_epi16(corr16,pucch2_polar_llr_num_lut[cw]),llr_num); + llr_den = _mm_max_epi16(_mm_mullo_epi16(corr16,pucch2_polar_llr_den_lut[cw]),llr_den); + /* + LOG_D(PHY,"lut_num (%d,%d,%d,%d,%d,%d,%d,%d)\n", + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[0], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[1], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[2], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[3], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[4], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[5], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[6], + ((int16_t*)&pucch2_polar_llr_num_lut[cw])[7]); + + LOG_D(PHY,"llr_num (%d,%d,%d,%d,%d,%d,%d,%d)\n", + ((int16_t*)&llr_num)[0], + ((int16_t*)&llr_num)[1], + ((int16_t*)&llr_num)[2], + ((int16_t*)&llr_num)[3], + ((int16_t*)&llr_num)[4], + ((int16_t*)&llr_num)[5], + ((int16_t*)&llr_num)[6], + ((int16_t*)&llr_num)[7]); + LOG_D(PHY,"llr_den (%d,%d,%d,%d,%d,%d,%d,%d)\n", + ((int16_t*)&llr_den)[0], + ((int16_t*)&llr_den)[1], + ((int16_t*)&llr_den)[2], + ((int16_t*)&llr_den)[3], + ((int16_t*)&llr_den)[4], + ((int16_t*)&llr_den)[5], + ((int16_t*)&llr_den)[6], + ((int16_t*)&llr_den)[7]); + */ + } + // compute llrs + llrs[half_prb] = _mm_subs_epi16(llr_num,llr_den); + LOG_D(PHY,"llrs[%d] : (%d,%d,%d,%d,%d,%d,%d,%d)\n", + half_prb, + ((int16_t*)&llrs[half_prb])[0], + ((int16_t*)&llrs[half_prb])[1], + ((int16_t*)&llrs[half_prb])[2], + ((int16_t*)&llrs[half_prb])[3], + ((int16_t*)&llrs[half_prb])[4], + ((int16_t*)&llrs[half_prb])[5], + ((int16_t*)&llrs[half_prb])[6], + ((int16_t*)&llrs[half_prb])[7]); + } // half_prb + // run polar decoder on llrs + decoderState = polar_decoder_int16((int16_t*)llrs, decodedPayload, 0, currentPtr); + LOG_D(PHY,"UCI decoderState %d, payload[0] %llux\n",decoderState,(unsigned long long)decodedPayload[0]); + if (decoderState>0) decoderState=1; + corr_dB = dB_fixed64(corr); + LOG_D(PHY,"metric %d dB\n",corr_dB); } - uint8_t corr_dB = dB_fixed64((uint64_t)corr); - LOG_D(PHY,"cw_ML %d, metric %d dB\n",cw_ML,corr_dB); uci_pdu->harq.harq_bit_len = pucch_pdu->bit_len_harq; - - - int harq_bytes=pucch_pdu->bit_len_harq>>3; - if ((pucch_pdu->bit_len_harq&7) > 0) harq_bytes++; - uci_pdu->harq.harq_payload = (uint8_t*)malloc(harq_bytes); - uci_pdu->harq.harq_crc = 2; - for (int i=0;i<harq_bytes;i++) { - uci_pdu->harq.harq_payload[i] = cw_ML & 255; - cw_ML>>=8; + uci_pdu->pduBitmap=0; + uci_pdu->rnti=pucch_pdu->rnti; + uci_pdu->handle=pucch_pdu->handle; + uci_pdu->pucch_format=0; + uci_pdu->ul_cqi=corr_dB; + // need to fill these field! + uci_pdu->timing_advance=31; + uci_pdu->rssi=0; + if (pucch_pdu->bit_len_harq>0) { + int harq_bytes=pucch_pdu->bit_len_harq>>3; + if ((pucch_pdu->bit_len_harq&7) > 0) harq_bytes++; + uci_pdu->pduBitmap|=1; + uci_pdu->harq.harq_payload = (uint8_t*)malloc(harq_bytes); + uci_pdu->harq.harq_crc = decoderState > 0 ? 1 : 0; + int i=0; + for (;i<harq_bytes-1;i++) { + uci_pdu->harq.harq_payload[i] = decodedPayload[0] & 255; + decodedPayload[0]>>=8; + } + uci_pdu->harq.harq_payload[i] = decodedPayload[0] & ((1<<(pucch_pdu->bit_len_harq&7))-1); + decodedPayload[0] >>= pucch_pdu->bit_len_harq; } if (pucch_pdu->sr_flag == 1) { + uci_pdu->pduBitmap|=2; uci_pdu->sr.sr_bit_len = 1; uci_pdu->sr.sr_payload = malloc(1); - uci_pdu->sr.sr_payload[0] = cw_ML; + uci_pdu->sr.sr_payload[0] = decodedPayload[0]&1; + decodedPayload[0] = decodedPayload[0]>>1; } + // csi + if (pucch_pdu->bit_len_csi_part1>0) { + uci_pdu->pduBitmap|=4; + int csi_part1_bytes=pucch_pdu->bit_len_csi_part1>>3; + if ((pucch_pdu->bit_len_csi_part1&7) > 0) csi_part1_bytes++; + uci_pdu->csi_part1.csi_part1_payload = (uint8_t*)malloc(csi_part1_bytes); + uci_pdu->csi_part1.csi_part1_crc = decoderState > 0 ? 1 : 0; + int i=0; + for (;i<csi_part1_bytes-1;i++) { + uci_pdu->csi_part1.csi_part1_payload[i] = decodedPayload[0] & 255; + decodedPayload[0]>>=8; + } + uci_pdu->csi_part1.csi_part1_payload[i] = decodedPayload[0] & ((1<<(pucch_pdu->bit_len_csi_part1&7))-1); + decodedPayload[0] >>= pucch_pdu->bit_len_csi_part1; + } + + if (pucch_pdu->bit_len_csi_part2>0) { + uci_pdu->pduBitmap|=8; + } + } diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c index 04dd321db2f8b33745b36a76fedccdad1e443e92..7cde6e31c16b1f8edaad9b13691b7ad84b562efa 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c @@ -846,7 +846,7 @@ uint8_t nr_dci_decoding_procedure(PHY_VARS_NR_UE *ue, rel15 = &pdcch_vars->pdcch_config[i]; int dci_length = rel15->dci_length; - int gNB_id = 0; + //int gNB_id = 0; int16_t tmp_e[16*108]; rnti_t n_rnti; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c index d9b5650f537224cceeec2c591642003f411e26c4..7f941e55672a40992070b66eb6f2aea8ab20c66a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c @@ -211,7 +211,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, dlsch1_harq = dlsch[1]->harq_processes[codeword_TB1]; #ifdef DEBUG_HARQ - printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword); + printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch1_harq->codeword); #endif AssertFatal(1 == 0, "[UE][FATAL] DLSCH: TB0 not active and TB1 active case is not supported\n"); @@ -230,6 +230,9 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue, } + if (dlsch0_harq == NULL) + AssertFatal(1 == 0, "Done\n"); + dlsch0_harq->Qm = nr_get_Qm_dl(dlsch[0]->harq_processes[harq_pid]->mcs, dlsch[0]->harq_processes[harq_pid]->mcs_table); dlsch0_harq->R = nr_get_code_rate_dl(dlsch[0]->harq_processes[harq_pid]->mcs, dlsch[0]->harq_processes[harq_pid]->mcs_table); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c index 60306d8e53b32b046cfcdceee16041a505cba7b3..612dc6283dbe97c5f5071f023b41af76af8285cf 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_pbch.c @@ -505,7 +505,7 @@ int nr_rx_pbch( PHY_VARS_NR_UE *ue, return(-1); } */ - if (symbol==1) { + if (symbol==2) { nr_pbch_quantize(pbch_e_rx, (short *)&(nr_ue_pbch_vars->rxdataF_comp[0][symbol*240]), 144); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c index 9a4143b88a1ac3730b2b7b4521e2d16d3dd09d79..79c542cd61ba27d5f6ca4cd1af1aa9141e6c4bc5 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_prach.c @@ -80,7 +80,7 @@ int32_t generate_nr_prach(PHY_VARS_NR_UE *ue, uint8_t gNB_id, uint8_t slot){ uint16_t preamble_shift = 0, preamble_index0, n_shift_ra, n_shift_ra_bar, d_start, numshift, N_ZC, u, offset, offset2, first_nonzero_root_idx; int16_t prach_tmp[98304*2*4] __attribute__((aligned(32))); - int16_t Ncp, amp, *prach, *prach2, *prachF, *Xu; + int16_t Ncp = 0, amp, *prach, *prach2, *prachF, *Xu; int32_t Xu_re, Xu_im, samp_count; int prach_start, prach_sequence_length, i, prach_len, dftlen, mu, kbar, K, n_ra_prb, k; //int restricted_Type; diff --git a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c index c8f7268d04cfa2d03886199675f3b6947850e049..e1358602ce835b39613a82e7a1c46df24a4ebc29 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c +++ b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c @@ -799,27 +799,47 @@ void nr_generate_pucch1_old(PHY_VARS_NR_UE *ue, } #endif //0 -inline void nr_pucch2_3_4_scrambling(uint16_t M_bit,uint16_t rnti,uint16_t n_id,uint32_t B,uint8_t *btilde) __attribute__((always_inline)); -inline void nr_pucch2_3_4_scrambling(uint16_t M_bit,uint16_t rnti,uint16_t n_id,uint32_t B,uint8_t *btilde) { +inline void nr_pucch2_3_4_scrambling(uint16_t M_bit,uint16_t rnti,uint16_t n_id,uint64_t *B64,uint8_t *btilde) __attribute__((always_inline)); +inline void nr_pucch2_3_4_scrambling(uint16_t M_bit,uint16_t rnti,uint16_t n_id,uint64_t *B64,uint8_t *btilde) { uint32_t x1, x2, s=0; int i; uint8_t c; // c_init=nRNTI*2^15+n_id according to TS 38.211 Subclause 6.3.2.6.1 //x2 = (rnti) + ((uint32_t)(1+nr_tti_tx)<<16)*(1+(fp->Nid_cell<<1)); x2 = ((rnti)<<15)+n_id; - s = lte_gold_generic(&x1, &x2, 1); #ifdef DEBUG_NR_PUCCH_TX - printf("\t\t [nr_pucch2_3_4_scrambling] gold sequence s=%x\n",s); -#endif - - for (i=0; i<M_bit; i++) { - c = (uint8_t)((s>>i)&1); - btilde[i] = (((B>>i)&1) ^ c); -#ifdef DEBUG_NR_PUCCH_TX - //printf("\t\t\t btilde[%d]=%lx from scrambled bit %d\n",i,btilde[i],((B>>i)&1)); + printf("\t\t [nr_pucch2_3_4_scrambling] gold sequence s=%x, M_bit %d\n",s,M_bit); +#endif + + uint8_t *btildep=btilde; + int M_bit2=M_bit > 31 ? 32 : (M_bit&31), M_bit3=M_bit; + uint32_t B; + for (int iprime=0;iprime<=(M_bit>>5);iprime++,btildep+=32) { + s = lte_gold_generic(&x1, &x2, (iprime==0) ? 1 : 0); + B=((uint32_t*)B64)[iprime]; + for (int n=0;n<M_bit2;n+=8) + LOG_D(PHY,"PUCCH2 encoded %d : %d,%d,%d,%d,%d,%d,%d,%d\n",n, + (B>>n)&1, + (B>>(n+1))&1, + (B>>(n+2))&1, + (B>>(n+3))&1, + (B>>(n+4))&1, + (B>>(n+5))&1, + (B>>(n+6))&1, + (B>>(n+7))&1 + ); + for (i=0; i<M_bit2; i++) { + c = (uint8_t)((s>>i)&1); + btildep[i] = (((B>>i)&1) ^ c); +#ifdef DEBUG_NR_PUCCH_TX + printf("\t\t\t btilde[%d]=%lx from unscrambled bit %d and scrambling %d (%x)\n",i+(iprime<<5),btilde[i],((B>>i)&1),c,s>>i); #endif + } + M_bit3-=32; + M_bit2=M_bit3 > 31 ? 32 : (M_bit3&31); } + #ifdef DEBUG_NR_PUCCH_TX printf("\t\t [nr_pucch2_3_4_scrambling] scrambling M_bit=%d bits\n", M_bit); #endif @@ -909,24 +929,13 @@ void nr_uci_encoding(uint64_t payload, // CRC bits are not attached, and coding small block lengths (subclause 5.3.3) b[0] = encodeSmallBlock((uint16_t*)&payload,A); } else if (A>=12) { - AssertFatal(1==0,"Polar encoding not supported yet for UCI\n"); - // procedure in subclause 6.3.1.2.1 (UCI encoded by Polar code -> subclause 6.3.1.3.1) - /*if ((A>=360 && E>=1088)||(A>=1013)) { - I_seg = 1; - } else { - I_seg = 0; - }*/ - - /*if (A>=20) { - // parity bits (subclause 5.2.1) computed by setting L=11 and using generator polynomial gCRC11(D) (subclause 5.1) - L=11; - } else if (A<=19) { - // parity bits (subclause 5.2.1) computed by setting L=6 and using generator polynomial gCRC6(D) (subclause 5.1) - L=6; - }*/ - - // code block segmentation and CRC attachment is performed according to subclause 5.2.1 - // polar coding subclause 5.3.1 + AssertFatal(A<65,"Polar encoding not supported yet for UCI with more than 64 bits\n"); + t_nrPolar_params *currentPtr = nr_polar_params(NR_POLAR_UCI_PUCCH_MESSAGE_TYPE, + A, + nrofPRB, + 1, + NULL); + polar_encoder_fast(&payload, b, 0,0,currentPtr); } } @@ -950,7 +959,7 @@ void nr_generate_pucch2(PHY_VARS_NR_UE *ue, printf("\t [nr_generate_pucch2] start function at slot(nr_tti_tx)=%d with payload=%lu and nr_bit=%d\n",nr_tti_tx, payload, nr_bit); #endif // b is the block of bits transmitted on the physical channel after payload coding - uint64_t b; + uint64_t b[16]; // limit to 1024-bit encoded length // M_bit is the number of bits of block b (payload after encoding) uint16_t M_bit; nr_uci_encoding(payload,nr_bit,pucch_format2_nr,0,nrofSymbols,nrofPRB,1,0,0,&b,&M_bit); diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c index 8c92214e68b14be8391540257b403bbff79f41e6..45eb66b4e3d8eee757186e5dbf472c13e4492e5c 100644 --- a/openair1/PHY/TOOLS/nr_phy_scope.c +++ b/openair1/PHY/TOOLS/nr_phy_scope.c @@ -9,6 +9,8 @@ * * http://www.openairinterface.org/?page_id=698 * + * Author and copyright: Laurent Thomas, open-cells.com + * * 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. @@ -26,6 +28,7 @@ #include "executables/nr-softmodem-common.h" #define TPUT_WINDOW_LENGTH 100 +#define localBuff(NaMe,SiZe) float NaMe[SiZe]; memset(NaMe,0,sizeof(NaMe)); int otg_enabled; FL_COLOR rx_antenna_colors[4] = {FL_RED,FL_BLUE,FL_GREEN,FL_YELLOW}; @@ -36,10 +39,40 @@ float tput_time_ue[NUMBER_OF_UE_MAX][TPUT_WINDOW_LENGTH] = {{0}}; float tput_ue[NUMBER_OF_UE_MAX][TPUT_WINDOW_LENGTH] = {{0}}; float tput_ue_max[NUMBER_OF_UE_MAX] = {0}; +typedef struct { + int16_t r; + int16_t i; +} scopeSample_t; +#define SquaredNorm(VaR) ((VaR).r*(VaR).r+(VaR).i*(VaR).i) + +typedef struct OAIgraph { + FL_OBJECT *graph; + void (*gNBfunct) (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id); + void (*nrUEfunct) (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id); +} OAIgraph_t; + +/* Forms and Objects */ +typedef struct { + FL_FORM *phy_scope; + OAIgraph_t graph[20]; + FL_OBJECT *button_0; +} FD_phy_scope_t; -static void ia_receiver_on_off( FL_OBJECT *button, long arg) -{ +typedef struct { + FL_FORM *stats_form; + void *vdata; + char *cdata; + long ldata; + FL_OBJECT *stats_text; + FL_OBJECT *stats_button; +} FD_stats_form; + +static void drawsymbol(FL_OBJECT *obj, int id, + FL_POINT *p, int n, int w, int h) { + fl_points( p, n, FL_YELLOW); +} +static void ia_receiver_on_off( FL_OBJECT *button, long arg) { if (fl_get_button(button)) { fl_set_object_label(button, "IA Receiver ON"); // PHY_vars_UE_g[0][0]->use_ia_receiver = 1; @@ -51,9 +84,7 @@ static void ia_receiver_on_off( FL_OBJECT *button, long arg) } } -static void dl_traffic_on_off( FL_OBJECT *button, long arg) -{ - +static void dl_traffic_on_off( FL_OBJECT *button, long arg) { if (fl_get_button(button)) { fl_set_object_label(button, "DL Traffic ON"); otg_enabled = 1; @@ -65,764 +96,643 @@ static void dl_traffic_on_off( FL_OBJECT *button, long arg) } } -FD_phy_scope_gnb *create_phy_scope_gnb( void ) -{ - - FL_OBJECT *obj; - FD_phy_scope_gnb *fdui = fl_malloc( sizeof *fdui ); - - // Define form - fdui->phy_scope_gnb = fl_bgn_form( FL_NO_BOX, 800, 800 ); - - // This the whole UI box - obj = fl_add_box( FL_BORDER_BOX, 0, 0, 800, 800, "" ); - fl_set_object_color( obj, FL_BLACK, FL_BLACK ); - - // Received signal - fdui->rxsig_t = fl_add_xyplot( FL_NORMAL_XYPLOT, 20, 20, 370, 100, "Received Signal (Time-Domain, dB)" ); - fl_set_object_boxtype( fdui->rxsig_t, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->rxsig_t, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->rxsig_t, FL_WHITE ); // Label color - fl_set_xyplot_ybounds(fdui->rxsig_t,10,70); - - // Time-domain channel response - fdui->chest_t = fl_add_xyplot( FL_NORMAL_XYPLOT, 410, 20, 370, 100, "SRS Frequency Response (samples, abs)" ); - fl_set_object_boxtype( fdui->chest_t, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->chest_t, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->chest_t, FL_WHITE ); // Label color - - // Frequency-domain channel response - fdui->chest_f = fl_add_xyplot( FL_IMPULSE_XYPLOT, 20, 140, 760, 100, "Channel Frequency Response (RE, dB)" ); - fl_set_object_boxtype( fdui->chest_f, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->chest_f, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->chest_f, FL_WHITE ); // Label color - fl_set_xyplot_ybounds( fdui->chest_f,30,70); +static FL_OBJECT *commonGraph( int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label, FL_COLOR pointColor) { + FL_OBJECT *graph; + graph=fl_add_xyplot(type, x, y, w, h, label); + fl_set_object_boxtype(graph, FL_EMBOSSED_BOX ); + fl_set_object_lcolor(graph, FL_WHITE ); // Label color + fl_set_xyplot_symbol(graph, 0, drawsymbol); + fl_set_object_color(graph, FL_BLACK, pointColor); + return graph; +} - // LLR of PUSCH - fdui->pusch_llr = fl_add_xyplot( FL_POINTS_XYPLOT, 20, 260, 500, 200, "PUSCH Log-Likelihood Ratios (LLR, mag)" ); - fl_set_object_boxtype( fdui->pusch_llr, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pusch_llr, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pusch_llr, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pusch_llr,2); +static OAIgraph_t gNBcommonGraph( void (*funct) (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id), + int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label, FL_COLOR pointColor) { + OAIgraph_t graph; + graph.graph=commonGraph(type, x, y, w, h, label, pointColor); + graph.gNBfunct=funct; + graph.nrUEfunct=NULL; + return graph; +} - // I/Q PUSCH comp - fdui->pusch_comp = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 260, 240, 200, "PUSCH I/Q of MF Output" ); - fl_set_object_boxtype( fdui->pusch_comp, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pusch_comp, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pusch_comp, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pusch_comp,2); - fl_set_xyplot_xgrid( fdui->pusch_llr,FL_GRID_MAJOR); +static OAIgraph_t nrUEcommonGraph( void (*funct) (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id), + int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label, FL_COLOR pointColor) { + OAIgraph_t graph; + graph.graph=commonGraph(type, x, y, w, h, label, pointColor); + graph.gNBfunct=NULL; + graph.nrUEfunct=funct; + return graph; +} - // I/Q PUCCH comp (format 1) - fdui->pucch_comp1 = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 480, 240, 100, "PUCCH1 Energy (SR)" ); - fl_set_object_boxtype( fdui->pucch_comp1, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pucch_comp1, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pucch_comp1, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pucch_comp1,2); - // fl_set_xyplot_xgrid( fdui->pusch_llr,FL_GRID_MAJOR); +void phy_scope_gNB(FD_phy_scope_t *form, + PHY_VARS_gNB *phy_vars_gnb, + RU_t *phy_vars_ru, + int UE_id) { + static FD_phy_scope_t *remeberForm=NULL; - // I/Q PUCCH comp (fromat 1a/b) - fdui->pucch_comp = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 600, 240, 100, "PUCCH I/Q of MF Output" ); - fl_set_object_boxtype( fdui->pucch_comp, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pucch_comp, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pucch_comp, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pucch_comp,2); - // fl_set_xyplot_xgrid( fdui->pusch_llr,FL_GRID_MAJOR); + if (form==NULL) + form=remeberForm; + else + remeberForm=form; - // Throughput on PUSCH - fdui->pusch_tput = fl_add_xyplot( FL_NORMAL_XYPLOT, 20, 480, 500, 100, "PUSCH Throughput [frame]/[kbit/s]" ); - fl_set_object_boxtype( fdui->pusch_tput, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pusch_tput, FL_BLACK, FL_WHITE ); - fl_set_object_lcolor( fdui->pusch_tput, FL_WHITE ); // Label color + if (form==NULL) return; - // Generic eNB Button - fdui->button_0 = fl_add_button( FL_PUSH_BUTTON, 20, 600, 240, 40, "" ); - fl_set_object_lalign(fdui->button_0, FL_ALIGN_CENTER ); - fl_set_button(fdui->button_0,0); - otg_enabled = 0; - fl_set_object_label(fdui->button_0, "DL Traffic OFF"); - fl_set_object_color(fdui->button_0, FL_RED, FL_RED); - fl_set_object_callback(fdui->button_0, dl_traffic_on_off, 0 ); + int i=0; - fl_end_form( ); - fdui->phy_scope_gnb->fdui = fdui; + while (form->graph[i].graph) { + form->graph[i].gNBfunct(form->graph[i].graph, phy_vars_gnb, phy_vars_ru, UE_id); + i++; + } - return fdui; + fl_check_forms(); } -void phy_scope_gNB(FD_phy_scope_gnb *form, - PHY_VARS_gNB *phy_vars_gnb, - RU_t *phy_vars_ru, - int UE_id) -{ - int i, arx; //int i,i2,arx,atx,ind,k; - NR_DL_FRAME_PARMS *frame_parms = &phy_vars_gnb->frame_parms; - //int nsymb_ce = 12*frame_parms->N_RB_UL*frame_parms->symbols_per_tti; - uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; - //uint8_t nb_antennas_tx = 1; // frame_parms->nb_antennas_tx; // in LTE Rel. 8 and 9 only a single transmit antenna is assumed at the UE - int16_t **rxsig_t, **rxsig_f; - // int16_t **chest_t=NULL; - // int16_t **chest_f=NULL; - // int16_t *pusch_llr=NULL; - // int32_t *pusch_comp=NULL; - // int32_t *pucch1_comp=NULL; - // int32_t *pucch1_thres=NULL; - // int32_t *pucch1ab_comp=NULL; - // float Re,Im,ymax; - float *llr, *bit; - // float I[nsymb_ce*2], Q[nsymb_ce*2]; - // float I_pucch[10240],Q_pucch[10240],A_pucch[10240],B_pucch[10240],C_pucch[10240]; - float *rxsig_t_dB[nb_antennas_rx]; - float *rxsig_f_dB[nb_antennas_rx]; - float time[frame_parms->samples_per_frame]; - // float freq[nsymb_ce*nb_antennas_rx*nb_antennas_tx]; - // uint32_t total_dlsch_bitrate = phy_vars_gnb->total_dlsch_bitrate; - int coded_bits_per_codeword = 0; - // uint8_t harq_pid; // in TDD config 3 it is sf-2, i.e., can be 0,1,2 - int Qm = 2; - - /* - if (!RC.nrmac[0]->UE_info.active[UE_id]) +static void timeSignal (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { + // Received signal in time domain of receive antenna 0 + if (!phy_vars_ru->common.rxdata) return; - - // choose max MCS to compute coded_bits_per_codeword - if (phy_vars_gnb->ulsch[UE_id][0]!=NULL) { - for (harq_pid=0; harq_pid<3; harq_pid++) { - //Qm = cmax(phy_vars_gnb->ulsch[UE_id][0]->harq_processes->Qm,Qm); - } - } - */ - coded_bits_per_codeword = frame_parms->N_RB_UL*12*Qm*frame_parms->symbols_per_tti; - for (arx=0; arx<nb_antennas_rx; arx++) { - rxsig_t_dB[arx] = (float*) calloc(frame_parms->samples_per_frame,sizeof(float)); - rxsig_f_dB[arx] = (float*) calloc(frame_parms->samples_per_slot_wCP,sizeof(float)); - } - llr = (float*) calloc(coded_bits_per_codeword,sizeof(float)); // init to zero - bit = malloc(coded_bits_per_codeword*sizeof(float)); - - rxsig_t = (int16_t**) phy_vars_ru->common.rxdata; - rxsig_f = (int16_t**) phy_vars_ru->common.rxdataF; - //chest_t = (int16_t**) phy_vars_gnb->pusch_vars[UE_id]->drs_ch_estimates_time[eNB_id]; - /* chest_t = (int16_t**) phy_vars_gnb->srs_vars[UE_id].srs_ch_estimates; - chest_f = (int16_t**) phy_vars_gnb->pusch_vars[UE_id]->drs_ch_estimates; - pusch_llr = (int16_t*) phy_vars_gnb->pusch_vars[UE_id]->llr; - pusch_comp = (int32_t*) phy_vars_gnb->pusch_vars[UE_id]->rxdataF_comp; - pucch1_comp = (int32_t*) phy_vars_gnb->pucch1_stats[UE_id]; - pucch1_thres = (int32_t*) phy_vars_gnb->pucch1_stats_thres[UE_id]; - pucch1ab_comp = (int32_t*) phy_vars_gnb->pucch1ab_stats[UE_id]; - */ + NR_DL_FRAME_PARMS *frame_parms=&phy_vars_gnb->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + scopeSample_t **rxsig_t = (scopeSample_t **)phy_vars_ru->common.rxdata; + float rxsig_t_dB[frame_parms->samples_per_frame]; + float time[frame_parms->samples_per_frame]; - // Received signal in time domain of receive antenna 0 - if (rxsig_t != NULL) { - if (rxsig_t[0] != NULL) { - for (i=0; i<frame_parms->samples_per_frame; i++) { - rxsig_t_dB[0][i] = 10*log10(1.0+(float) ((rxsig_t[0][2*i])*(rxsig_t[0][2*i])+(rxsig_t[0][2*i+1])*(rxsig_t[0][2*i+1]))); - time[i] = (float) i; + for (int arx=0; arx<nb_antennas_rx; arx++) { + if (rxsig_t[arx] != NULL) { + for (int i=0; i<frame_parms->samples_per_frame; i++) { + rxsig_t_dB[i] = 10*log10(1.0+SquaredNorm(rxsig_t[arx][i])); + time[i] = i; } - fl_set_xyplot_data(form->rxsig_t,time,rxsig_t_dB[0],frame_parms->samples_per_frame,"","",""); - } - - for (arx=1; arx<nb_antennas_rx; arx++) { - if (rxsig_t[arx] != NULL) { - for (i=0; i<frame_parms->samples_per_frame; i++) { - rxsig_t_dB[arx][i] = 10*log10(1.0+(float) ((rxsig_t[arx][2*i])*(rxsig_t[arx][2*i])+(rxsig_t[arx][2*i+1])*(rxsig_t[arx][2*i+1]))); - } - - fl_add_xyplot_overlay(form->rxsig_t,arx,time,rxsig_t_dB[arx],frame_parms->samples_per_frame,rx_antenna_colors[arx]); - } + if (arx==0) + fl_set_xyplot_data(graph,time,rxsig_t_dB, frame_parms->samples_per_frame,"","",""); + else + fl_add_xyplot_overlay(graph,arx,time,rxsig_t_dB,frame_parms->samples_per_frame,rx_antenna_colors[arx]); } } +} - /* - // Channel Impulse Response - if (chest_t != NULL) { - ymax = 0; - - if (chest_t[0] !=NULL) { - for (i=0; i<(frame_parms->ofdm_symbol_size); i++) { - //i2 = (i+(frame_parms->ofdm_symbol_size>>1))%frame_parms->ofdm_symbol_size; - i2=i; - //time2[i] = (float)(i-(frame_parms->ofdm_symbol_size>>1)); +static void timeResponse (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { + if (!phy_vars_gnb->pusch_vars[UE_id]->ul_ch_estimates_time) + return; + + NR_DL_FRAME_PARMS *frame_parms=&phy_vars_gnb->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + scopeSample_t **chest_t = (scopeSample_t **) phy_vars_gnb->pusch_vars[UE_id]->ul_ch_estimates_time; + int ymax = 0; + float time2[2*frame_parms->ofdm_symbol_size]; + float chest_t_abs[2*frame_parms->ofdm_symbol_size]; + + for (int arx=0; arx<nb_antennas_rx; arx++) { + if (chest_t[arx] !=NULL) { + for (int i=0; i<(2*frame_parms->ofdm_symbol_size); i++) { time2[i] = (float)i; - chest_t_abs[0][i] = 10*log10((float) (1+chest_t[0][2*i2]*chest_t[0][2*i2]+chest_t[0][2*i2+1]*chest_t[0][2*i2+1])); + chest_t_abs[i] = 10*log10(1.0 + SquaredNorm(chest_t[0][i])); - if (chest_t_abs[0][i] > ymax) - ymax = chest_t_abs[0][i]; + if (chest_t_abs[i] > ymax) + ymax = chest_t_abs[i]; } - fl_set_xyplot_data(form->chest_t,time2,chest_t_abs[0],(frame_parms->ofdm_symbol_size),"","",""); + if (arx==0) + fl_set_xyplot_data(graph,time2,chest_t_abs,(2*frame_parms->ofdm_symbol_size),"","",""); + else { + fl_add_xyplot_overlay(graph,arx,time2,chest_t_abs,(frame_parms->ofdm_symbol_size>>3),rx_antenna_colors[arx]); + fl_set_xyplot_overlay_type(graph,arx,FL_DASHED_XYPLOT); + } } + } - for (arx=1; arx<nb_antennas_rx; arx++) { - if (chest_t[arx] !=NULL) { - for (i=0; i<(frame_parms->ofdm_symbol_size>>3); i++) { - chest_t_abs[arx][i] = 10*log10((float) (1+chest_t[arx][2*i]*chest_t[arx][2*i]+chest_t[arx][2*i+1]*chest_t[arx][2*i+1])); + // Avoid flickering effect + // fl_get_xyplot_ybounds(form->chest_t,&ymin,&ymax); + fl_set_xyplot_ybounds(graph,0,ymax); +} - if (chest_t_abs[arx][i] > ymax) - ymax = chest_t_abs[arx][i]; - } +static void frequencyResponse (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { + // Channel Frequency Response + if (!phy_vars_ru->common.rxdataF) + return; - fl_add_xyplot_overlay(form->chest_t,arx,time,chest_t_abs[arx],(frame_parms->ofdm_symbol_size>>3),rx_antenna_colors[arx]); - fl_set_xyplot_overlay_type(form->chest_t,arx,FL_DASHED_XYPLOT); - } + NR_DL_FRAME_PARMS *frame_parms=&phy_vars_gnb->frame_parms; + //uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + scopeSample_t **rxsig_f = (scopeSample_t **) phy_vars_ru->common.rxdataF; + float rxsig_f_dB[frame_parms->samples_per_slot_wCP]; + float time[frame_parms->samples_per_slot_wCP]; + + if (rxsig_f[0] != NULL) { + for (int i=0; i<frame_parms->samples_per_slot_wCP; i++) { + rxsig_f_dB[i] = 10*log10(1.0+ SquaredNorm(rxsig_f[0][i])); + time[i] = (float) i; } - // Avoid flickering effect - // fl_get_xyplot_ybounds(form->chest_t,&ymin,&ymax); - fl_set_xyplot_ybounds(form->chest_t,0,ymax); + fl_set_xyplot_data(graph,time,rxsig_f_dB,frame_parms->samples_per_slot_wCP,"","",""); } - */ - - // Channel Frequency Response - if (rxsig_f != NULL) { - if (rxsig_f[0] != NULL) { - for (i=0; i<frame_parms->samples_per_slot_wCP; i++) { - rxsig_f_dB[0][i] = 10*log10(1.0+(float) ((rxsig_f[0][2*i])*(rxsig_f[0][2*i])+(rxsig_f[0][2*i+1])*(rxsig_f[0][2*i+1]))); - time[i] = (float) i; - } - fl_set_xyplot_data(form->chest_t,time,rxsig_f_dB[0],frame_parms->samples_per_slot_wCP,"","",""); - } - } - /* - - for (arx=0; arx<nb_antennas_rx; arx++) { - if (chest_f[(atx<<1)+arx] != NULL) { - for (k=0; k<nsymb_ce; k++) { - freq[ind] = (float)ind; - Re = (float)(chest_f[(atx<<1)+arx][(2*k)]); - Im = (float)(chest_f[(atx<<1)+arx][(2*k)+1]); - - chest_f_abs[ind] = (short)10*log10(1.0+((double)Re*Re + (double)Im*Im)); - ind++; - } - } + for (int arx=1; arx<nb_antennas_rx; arx++) { + if (chest_f[(atx<<1)+arx] != NULL) { + for (int k=0; k<nsymb_ce; k++) { + time[k] = (float)ind; + chest_f_abs[k] = (short)10*log10(1.0+SquaredNorm(chest_f[(atx<<1)+arx][k])); + ind++; } + fl_add_xyplot_overlay(form->chest_f,1,time,chest_f_abs,nsymb_ce,rx_antenna_colors[arx]); } - + } + */ + /* // tx antenna 0 fl_set_xyplot_xbounds(form->chest_f,0,nb_antennas_rx*nb_antennas_tx*nsymb_ce); fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*frame_parms->symbols_per_tti,3); fl_set_xyplot_xgrid(form->chest_f,FL_GRID_MAJOR); fl_set_xyplot_data(form->chest_f,freq,chest_f_abs,nsymb_ce,"","",""); + */ +} - for (arx=1; arx<nb_antennas_rx; arx++) { - fl_add_xyplot_overlay(form->chest_f,1,&freq[arx*nsymb_ce],&chest_f_abs[arx*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); - } - - // other tx antennas - if (nb_antennas_tx > 1) { - if (nb_antennas_rx > 1) { - for (atx=1; atx<nb_antennas_tx; atx++) { - for (arx=0; arx<nb_antennas_rx; arx++) { - fl_add_xyplot_overlay(form->chest_f,(atx<<1)+arx,&freq[((atx<<1)+arx)*nsymb_ce],&chest_f_abs[((atx<<1)+arx)*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); - } - } - } else { // 1 rx antenna - atx=1; - arx=0; - fl_add_xyplot_overlay(form->chest_f,atx,&freq[atx*nsymb_ce],&chest_f_abs[atx*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); - } - } - } - +static void puschLLR (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { // PUSCH LLRs - if (pusch_llr != NULL) { - for (i=0; i<coded_bits_per_codeword; i++) { - llr[i] = (float) pusch_llr[i]; - bit[i] = (float) i; - } + if (!phy_vars_gnb->pusch_vars[UE_id]->llr) + return; + + //NR_DL_FRAME_PARMS *frame_parms=&phy_vars_gnb->frame_parms; + //int Qm = 2; + int16_t *pusch_llr = (int16_t *) phy_vars_gnb->pusch_vars[UE_id]->llr; + int coded_bits_per_codeword =3*8*6144+12; // (8*((3*8*6144)+12)); // frame_parms->N_RB_UL*12*Qm*frame_parms->symbols_per_tti; + float llr[coded_bits_per_codeword]; + float bit[coded_bits_per_codeword]; - fl_set_xyplot_data(form->pusch_llr,bit,llr,coded_bits_per_codeword,"","",""); + for (int i=0; i<coded_bits_per_codeword; i++) { + llr[i] = (float) pusch_llr[i]; + bit[i] = (float) i; } + fl_set_xyplot_data(graph,bit,llr,coded_bits_per_codeword,"","",""); +} + +static void puschIQ (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { // PUSCH I/Q of MF Output - if (pusch_comp!=NULL) { - ind=0; - - for (k=0; k<frame_parms->symbols_per_tti; k++) { - for (i=0; i<12*frame_parms->N_RB_UL; i++) { - I[ind] = pusch_comp[(2*frame_parms->N_RB_UL*12*k)+2*i]; - Q[ind] = pusch_comp[(2*frame_parms->N_RB_UL*12*k)+2*i+1]; - ind++; - } - } + if (!phy_vars_gnb->pusch_vars[UE_id]->rxdataF_comp) + return; + + NR_DL_FRAME_PARMS *frame_parms=&phy_vars_gnb->frame_parms; + scopeSample_t *pusch_comp = (scopeSample_t *) phy_vars_gnb->pusch_vars[UE_id]->rxdataF_comp[0]; + int sz=frame_parms->N_RB_UL*12*frame_parms->symbols_per_slot; + float I[sz], Q[sz]; - fl_set_xyplot_data(form->pusch_comp,I,Q,ind,"","",""); + for (int k=0; k<sz; k++ ) { + I[k] = pusch_comp[k].r; + Q[k] = pusch_comp[k].i; } - // PUSCH I/Q of MF Output - if (pucch1ab_comp!=NULL) { - for (ind=0; ind<10240; ind++) { + fl_set_xyplot_data(graph,I,Q,sz,"","",""); + // PUSCH I/Q of MF Output +// Code to fixed, disabled for cppcheck +#if 0 + if (NULL) { + int32_t *pucch1ab_comp = (int32_t *) NULL; //phy_vars_gnb->pucch1ab_stats[UE_id]; + int32_t *pucch1_comp = (int32_t *) NULL; //phy_vars_gnb->pucch1_stats[UE_id]; + float I_pucch[10240],Q_pucch[10240],A_pucch[10240],B_pucch[10240],C_pucch[10240]; + + for (int ind=0; ind<10240; ind++) { I_pucch[ind] = (float)pucch1ab_comp[2*(ind)]; Q_pucch[ind] = (float)pucch1ab_comp[2*(ind)+1]; A_pucch[ind] = pucch1_comp?(10*log10(pucch1_comp[ind])):0; B_pucch[ind] = ind; + int32_t *pucch1_thres = (int32_t *) NULL; // phy_vars_gnb->pucch1_stats_thres[UE_id]; C_pucch[ind] = pucch1_thres?(float)pucch1_thres[ind]:0; } - fl_set_xyplot_data(form->pucch_comp,I_pucch,Q_pucch,10240,"","",""); - fl_set_xyplot_data(form->pucch_comp1,B_pucch,A_pucch,1024,"","",""); - fl_add_xyplot_overlay(form->pucch_comp1,1,B_pucch,C_pucch,1024,FL_RED); - fl_set_xyplot_ybounds(form->pucch_comp,-5000,5000); - fl_set_xyplot_xbounds(form->pucch_comp,-5000,5000); - fl_set_xyplot_ybounds(form->pucch_comp1,0,80); + fl_set_xyplot_data(graph,I_pucch,Q_pucch,10240,"","",""); + fl_set_xyplot_data(graph,B_pucch,A_pucch,1024,"","",""); + fl_add_xyplot_overlay(graph,1,B_pucch,C_pucch,1024,FL_RED); + fl_set_xyplot_ybounds(graph,-5000,5000); + fl_set_xyplot_xbounds(graph,-5000,5000); + fl_set_xyplot_ybounds(graph,0,80); } +#endif +} + +static void pucchEnergy (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { +} +static void pucchIQ (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { +} +static void puschThroughtput (FL_OBJECT *graph, PHY_VARS_gNB *phy_vars_gnb, RU_t *phy_vars_ru, int UE_id) { // PUSCH Throughput memmove( tput_time_enb[UE_id], &tput_time_enb[UE_id][1], (TPUT_WINDOW_LENGTH-1)*sizeof(float) ); memmove( tput_enb[UE_id], &tput_enb[UE_id][1], (TPUT_WINDOW_LENGTH-1)*sizeof(float) ); - tput_time_enb[UE_id][TPUT_WINDOW_LENGTH-1] = (float) 0; -// tput_enb[UE_id][TPUT_WINDOW_LENGTH-1] = ((float) total_dlsch_bitrate)/1000.0; - - fl_set_xyplot_data(form->pusch_tput,tput_time_enb[UE_id],tput_enb[UE_id],TPUT_WINDOW_LENGTH,"","",""); - + // tput_enb[UE_id][TPUT_WINDOW_LENGTH-1] = ((float) total_dlsch_bitrate)/1000.0; + fl_set_xyplot_data(graph,tput_time_enb[UE_id],tput_enb[UE_id],TPUT_WINDOW_LENGTH,"","",""); // fl_get_xyplot_ybounds(form->pusch_tput,&ymin,&ymax); // fl_set_xyplot_ybounds(form->pusch_tput,0,ymax); - - */ - - fl_check_forms(); - - free(llr); - free(bit); } -FD_phy_scope_nrue *create_phy_scope_nrue( void ) -{ - +static FD_phy_scope_t *create_phy_scope_gnb(int UE_id ) { FL_OBJECT *obj; - FD_phy_scope_nrue *fdui = fl_malloc( sizeof *fdui ); - + FD_phy_scope_t *fdui = fl_malloc( sizeof *fdui ); // Define form - fdui->phy_scope_nrue = fl_bgn_form( FL_NO_BOX, 800, 900 ); - + fdui->phy_scope = fl_bgn_form( FL_NO_BOX, 800, 800 ); // This the whole UI box - obj = fl_add_box( FL_BORDER_BOX, 0, 0, 800, 900, "" ); + obj = fl_add_box( FL_BORDER_BOX, 0, 0, 800, 800, "" ); fl_set_object_color( obj, FL_BLACK, FL_BLACK ); - // Received signal - fdui->rxsig_t = fl_add_xyplot( FL_NORMAL_XYPLOT, 20, 20, 370, 100, "Received Signal (Time-Domain, dB)" ); - fl_set_object_boxtype( fdui->rxsig_t, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->rxsig_t, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->rxsig_t, FL_WHITE ); // Label color - fl_set_xyplot_ybounds(fdui->rxsig_t,10,70); - + fdui->graph[0] = gNBcommonGraph( timeSignal, FL_IMPULSE_XYPLOT, 20, 20, 370, 100, + "Received Signal (Time-Domain, dB)", FL_RED ); // Time-domain channel response - fdui->chest_t = fl_add_xyplot( FL_NORMAL_XYPLOT, 410, 20, 370, 100, "Channel Impulse Response (samples, abs)" ); - fl_set_object_boxtype( fdui->chest_t, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->chest_t, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->chest_t, FL_WHITE ); // Label color - + fdui->graph[1] = gNBcommonGraph( timeResponse, FL_NORMAL_XYPLOT, 410, 20, 370, 100, + "SRS Frequency Response (samples, abs)", FL_RED ); // Frequency-domain channel response - fdui->chest_f = fl_add_xyplot( FL_IMPULSE_XYPLOT, 20, 140, 760, 100, "Channel Frequency Response (RE, dB)" ); - fl_set_object_boxtype( fdui->chest_f, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->chest_f, FL_BLACK, FL_RED ); - fl_set_object_lcolor( fdui->chest_f, FL_WHITE ); // Label color - fl_set_xyplot_ybounds( fdui->chest_f,30,70); - - // LLR of PBCH - fdui->pbch_llr = fl_add_xyplot( FL_POINTS_XYPLOT, 20, 260, 500, 100, "PBCH Log-Likelihood Ratios (LLR, mag)" ); - fl_set_object_boxtype( fdui->pbch_llr, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pbch_llr, FL_BLACK, FL_GREEN ); - fl_set_object_lcolor( fdui->pbch_llr, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pbch_llr,2); - fl_set_xyplot_xgrid( fdui->pbch_llr,FL_GRID_MAJOR); - //fl_set_xyplot_xbounds( fdui->pbch_llr,0,1920); - - // I/Q PBCH comp - fdui->pbch_comp = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 260, 240, 100, "PBCH I/Q of MF Output" ); - fl_set_object_boxtype( fdui->pbch_comp, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pbch_comp, FL_BLACK, FL_GREEN ); - fl_set_object_lcolor( fdui->pbch_comp, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pbch_comp,2); - // fl_set_xyplot_xbounds( fdui->pbch_comp,-100,100); - // fl_set_xyplot_ybounds( fdui->pbch_comp,-100,100); - - // LLR of PDCCH - fdui->pdcch_llr = fl_add_xyplot( FL_POINTS_XYPLOT, 20, 380, 500, 100, "PDCCH Log-Likelihood Ratios (LLR, mag)" ); - fl_set_object_boxtype( fdui->pdcch_llr, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pdcch_llr, FL_BLACK, FL_CYAN ); - fl_set_object_lcolor( fdui->pdcch_llr, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pdcch_llr,2); - - // I/Q PDCCH comp - fdui->pdcch_comp = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 380, 240, 100, "PDCCH I/Q of MF Output" ); - fl_set_object_boxtype( fdui->pdcch_comp, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pdcch_comp, FL_BLACK, FL_CYAN ); - fl_set_object_lcolor( fdui->pdcch_comp, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pdcch_comp,2); - fl_set_xyplot_xgrid( fdui->pdcch_llr,FL_GRID_MAJOR); - - // LLR of PDSCH - fdui->pdsch_llr = fl_add_xyplot( FL_POINTS_XYPLOT, 20, 500, 500, 200, "PDSCH Log-Likelihood Ratios (LLR, mag)" ); - fl_set_object_boxtype( fdui->pdsch_llr, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pdsch_llr, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pdsch_llr, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pdsch_llr,2); - fl_set_xyplot_xgrid( fdui->pdsch_llr,FL_GRID_MAJOR); - - // I/Q PDSCH comp - fdui->pdsch_comp = fl_add_xyplot( FL_POINTS_XYPLOT, 540, 500, 240, 200, "PDSCH I/Q of MF Output" ); - fl_set_object_boxtype( fdui->pdsch_comp, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pdsch_comp, FL_BLACK, FL_YELLOW ); - fl_set_object_lcolor( fdui->pdsch_comp, FL_WHITE ); // Label color - fl_set_xyplot_symbolsize( fdui->pdsch_comp,2); - - // Throughput on PDSCH - fdui->pdsch_tput = fl_add_xyplot( FL_NORMAL_XYPLOT, 20, 720, 500, 100, "PDSCH Throughput [frame]/[kbit/s]" ); - fl_set_object_boxtype( fdui->pdsch_tput, FL_EMBOSSED_BOX ); - fl_set_object_color( fdui->pdsch_tput, FL_BLACK, FL_WHITE ); - fl_set_object_lcolor( fdui->pdsch_tput, FL_WHITE ); // Label color + fdui->graph[2] = gNBcommonGraph( frequencyResponse, FL_IMPULSE_XYPLOT, 20, 140, 760, 100, + "Channel Frequency Response (RE, dB)", FL_RED ); + // LLR of PUSCH + fdui->graph[3] = gNBcommonGraph( puschLLR, FL_POINTS_XYPLOT, 20, 260, 500, 200, + "PUSCH Log-Likelihood Ratios (LLR, mag)", FL_YELLOW ); + // I/Q PUSCH comp + fdui->graph[4] = gNBcommonGraph( puschIQ, FL_POINTS_XYPLOT, 540, 260, 240, 200, + "PUSCH I/Q of MF Output", FL_YELLOW ); + // I/Q PUCCH comp (format 1) + fdui->graph[5] = gNBcommonGraph( pucchEnergy, FL_POINTS_XYPLOT, 540, 480, 240, 100, + "PUCCH1 Energy (SR)", FL_YELLOW ); + // fl_set_xyplot_xgrid( fdui->pusch_llr,FL_GRID_MAJOR); + // I/Q PUCCH comp (fromat 1a/b) + fdui->graph[6] = gNBcommonGraph( pucchIQ, FL_POINTS_XYPLOT, 540, 600, 240, 100, + "PUCCH I/Q of MF Output", FL_YELLOW ); + // Throughput on PUSCH + fdui->graph[7] = gNBcommonGraph( puschThroughtput, FL_NORMAL_XYPLOT, 20, 480, 500, 100, + "PUSCH Throughput [frame]/[kbit/s]", FL_WHITE ); + fdui->graph[8].graph=NULL; - // Generic UE Button - fdui->button_0 = fl_add_button( FL_PUSH_BUTTON, 540, 720, 240, 40, "" ); - fl_set_object_lalign(fdui->button_0, FL_ALIGN_CENTER ); - //openair_daq_vars.use_ia_receiver = 0; - fl_set_button(fdui->button_0,0); - fl_set_object_label(fdui->button_0, "IA Receiver OFF"); - fl_set_object_color(fdui->button_0, FL_RED, FL_RED); - fl_set_object_callback(fdui->button_0, ia_receiver_on_off, 0 ); - fl_hide_object(fdui->button_0); + // Generic eNB Button + if (0) { // code kept to later add command buttons + fdui->button_0 = fl_add_button( FL_PUSH_BUTTON, 20, 600, 240, 40, "" ); + fl_set_object_lalign(fdui->button_0, FL_ALIGN_CENTER ); + fl_set_button(fdui->button_0,0); + otg_enabled = 0; + fl_set_object_label(fdui->button_0, "DL Traffic OFF"); + fl_set_object_color(fdui->button_0, FL_RED, FL_RED); + fl_set_object_callback(fdui->button_0, dl_traffic_on_off, 0 ); + } fl_end_form( ); - fdui->phy_scope_nrue->fdui = fdui; - + fdui->phy_scope->fdui = fdui; + char title[100]; + sprintf (title, "LTE UL SCOPE eNB for UE %d",UE_id); + fl_show_form (fdui->phy_scope, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); return fdui; } -void phy_scope_nrUE(FD_phy_scope_nrue *form, - PHY_VARS_NR_UE *phy_vars_ue, - int eNB_id, - int UE_id, - uint8_t subframe) -{ - int i,arx,atx,ind,k; - NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; - //int nsymb_ce = frame_parms->ofdm_symbol_size;//*frame_parms->symbols_per_tti; - int samples_per_frame = frame_parms->samples_per_frame; - uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; - uint8_t nb_antennas_tx = frame_parms->nb_antenna_ports_gNB; - int16_t **rxsig_t; - float **rxsig_t_dB; - float *time; - float *corr; - int16_t **chest_t; - int16_t **chest_f; - int16_t *pdsch_llr; - int16_t *pdsch_comp; - //int16_t *pdsch_mag; - int8_t *pdcch_llr; - int16_t *pdcch_comp; - int16_t *pbch_llr; - int16_t *pbch_comp; - float llr_pbch[1920], bit_pbch[1920]; - float *llr, *bit; - float *llr_pdcch, *bit_pdcch; - float *I, *Q; - int num_pdcch_symbols=2; - int num_re = 4500; - int Qm = 2; - int coded_bits_per_codeword = num_re*Qm; - int symbol, first_symbol=2,nb_re; - int nb_rb_pdsch=50,nb_symb_sch=9; - float ymax=1; - float **chest_t_abs; - float Re,Im; - float *chest_f_abs; - float *freq; - static int overlay = 0; - /* - int frame = phy_vars_ue->proc.proc_rxtx[0].frame_rx; - int mcs = 0; - unsigned char harq_pid = 0; - */ - - /* - if (phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]!=NULL) { - harq_pid = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->current_harq_pid; +static FD_phy_scope_t *form_gnb[NUMBER_OF_UE_MAX]= {0}; +static unsigned char scope_enb_num_ue = 1; - if (harq_pid>=8) - return; +static void *scope_thread_gNB(void *arg) { + scopeParms_t *p=(scopeParms_t *) arg; + //# ifdef ENABLE_XFORMS_WRITE_STATS + // FILE *gNB_stats = fopen("gNB_stats.txt", "w"); + //#endif + size_t stksize; + pthread_attr_t atr; + pthread_attr_getstacksize(&atr, &stksize); + pthread_attr_setstacksize(&atr,32*1024*1024 ); + sleep(3); // no clean interthread barriers - mcs = phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->mcs; + while (!oai_exit) { + int ue_cnt=0; - // Button 0 - if(!phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->dl_power_off) { - // we are in TM5 - fl_show_object(form->button_0); + for(int UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) { + if ((ue_cnt<scope_enb_num_ue)) { + //this function needs to be written + phy_scope_gNB(form_gnb[ue_cnt], p->gNB, p->ru, UE_id); + ue_cnt++; + } } - } - - if (phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]!=NULL) { - num_pdcch_symbols = phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->num_pdcch_symbols; - } - - // coded_bits_per_codeword = frame_parms->N_RB_DL*12*get_Qm(mcs)*(frame_parms->symbols_per_tti); - if (phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]!=NULL) { - coded_bits_per_codeword = get_G(frame_parms, - phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->nb_rb, - phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->rb_alloc_even, - get_Qm(mcs), - phy_vars_ue->dlsch[phy_vars_ue->current_thread_id[subframe]][eNB_id][0]->harq_processes[harq_pid]->Nl, - num_pdcch_symbols, - frame, - subframe, - beamforming_mode); - } else { - coded_bits_per_codeword = 0; //frame_parms->N_RB_DL*12*get_Qm(mcs)*(frame_parms->symbols_per_tti); - } - */ - I = (float*) calloc(frame_parms->ofdm_symbol_size*frame_parms->symbols_per_slot*2,sizeof(float)); - Q = (float*) calloc(frame_parms->ofdm_symbol_size*frame_parms->symbols_per_slot*2,sizeof(float)); - chest_t_abs = (float**) malloc(nb_antennas_rx*sizeof(float*)); - - for (arx=0; arx<nb_antennas_rx; arx++) { - chest_t_abs[arx] = (float*) calloc(frame_parms->ofdm_symbol_size,sizeof(float)); + usleep(99*1000); } - chest_f_abs = (float*) calloc(frame_parms->ofdm_symbol_size,sizeof(float)); - freq = (float*) calloc(frame_parms->ofdm_symbol_size,sizeof(float)); - - llr = (float*) calloc(coded_bits_per_codeword,sizeof(float)); // init to zero - bit = malloc(coded_bits_per_codeword*sizeof(float)); + // printf("%s",stats_buffer); + /*#ifdef ENABLE_XFORMS_WRITE_STATS - llr_pdcch = (float*) calloc(12*frame_parms->N_RB_DL*num_pdcch_symbols*2,sizeof(float)); // init to zero - bit_pdcch = (float*) calloc(12*frame_parms->N_RB_DL*num_pdcch_symbols*2,sizeof(float)); + if (eNB_stats) { + rewind (gNB_stats); + fwrite (stats_buffer, 1, len, gNB_stats); + fclose (gNB_stats); + } - rxsig_t = (int16_t**) phy_vars_ue->common_vars.rxdata; - rxsig_t_dB = calloc(nb_antennas_rx,sizeof(float*)); - for (arx=0; arx<nb_antennas_rx; arx++) { - rxsig_t_dB[arx] = (float*) calloc(samples_per_frame,sizeof(float)); - } - time = calloc(samples_per_frame,sizeof(float)); - corr = calloc(samples_per_frame,sizeof(float)); + #endif + pthread_exit((void *)arg); + }*/ + return NULL; +} - chest_t = (int16_t**) phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates_time; - chest_f = (int16_t**) phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates; +void gNBinitScope(scopeParms_t *p) { + //FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; + fl_initialize (p->argc, p->argv, NULL, 0, 0); - pbch_llr = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->llr; - pbch_comp = (int16_t*) phy_vars_ue->pbch_vars[eNB_id]->rxdataF_comp[0]; + /* + form_stats_l2 = create_form_stats_form(); + fl_show_form (form_stats_l2->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "l2 stats"); + form_stats = create_form_stats_form(); + fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); + */ + for(int UE_id=0; UE_id<scope_enb_num_ue; UE_id++) { + form_gnb[UE_id] = create_phy_scope_gnb(UE_id); + } // UE_id - pdcch_llr = (int8_t*) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr; - pdcch_comp = (int16_t*) phy_vars_ue->pdcch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp[0]; - pdsch_llr = (int16_t*) phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->llr[0]; // stream 0 - // pdsch_llr = (int16_t*) phy_vars_ue->lte_ue_pdsch_vars_SI[eNB_id]->llr[0]; // stream 0 - pdsch_comp = (int16_t*) phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp0[0]; - //pdsch_mag = (int16_t*) phy_vars_ue->pdsch_vars[phy_vars_ue->current_thread_id[subframe]][eNB_id]->dl_ch_mag0[0]; + static scopeParms_t parms; + memcpy(&parms,p,sizeof(parms)); + pthread_t forms_thread; + threadCreate(&forms_thread, scope_thread_gNB, &parms, "scope", -1, OAI_PRIORITY_RT_LOW); +} +static void ueTimeResponse (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // Received signal in time domain of receive antenna 0 - if (rxsig_t != NULL) { - if (rxsig_t[0] != NULL) { - for (i=0; i<samples_per_frame; i++) { - rxsig_t_dB[0][i] = 10*log10(1.0+(float) ((rxsig_t[0][2*i])*(rxsig_t[0][2*i])+(rxsig_t[0][2*i+1])*(rxsig_t[0][2*i+1]))); - time[i] = (float) i; - } + if (! phy_vars_ue->common_vars.rxdata) + return; - fl_set_xyplot_data(form->rxsig_t,time,rxsig_t_dB[0],samples_per_frame,"","",""); + NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + int samples_per_frame = frame_parms->samples_per_frame; + scopeSample_t **rxsig_t = (scopeSample_t **) phy_vars_ue->common_vars.rxdata; + float rxsig_t_dB[samples_per_frame]; + float time[samples_per_frame]; + + if (rxsig_t[0] != NULL) { + for (int i=0; i<samples_per_frame; i++) { + rxsig_t_dB[i] = 10*log10(1.0+SquaredNorm(rxsig_t[0][i])); + time[i] = (float) i; } - /* - for (arx=1; arx<nb_antennas_rx; arx++) { - if (rxsig_t[arx] != NULL) { - for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++) { - rxsig_t_dB[arx][i] = 10*log10(1.0+(float) ((rxsig_t[arx][2*i])*(rxsig_t[arx][2*i])+(rxsig_t[arx][2*i+1])*(rxsig_t[arx][2*i+1]))); - } + fl_set_xyplot_data(graph,time,rxsig_t_dB,samples_per_frame,"","",""); + } - fl_add_xyplot_overlay(form->rxsig_t,arx,time,rxsig_t_dB[arx],FRAME_LENGTH_COMPLEX_SAMPLES,rx_antenna_colors[arx]); + for (int arx=1; arx<nb_antennas_rx; arx++) { + if (rxsig_t[arx] != NULL) { + for (int i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++) { + rxsig_t_dB[i] = 10*log10(1.0+SquaredNorm(rxsig_t[arx][i])); } + + fl_add_xyplot_overlay(graph,arx,time,rxsig_t_dB,FRAME_LENGTH_COMPLEX_SAMPLES,rx_antenna_colors[arx]); } - */ } if (phy_vars_ue->is_synchronized==0) { - for (ind=0;ind<3;ind++) { + //float corr[samples_per_frame]; + for (int ind=0; ind<3; ind++) { /* - if (pss_corr_ue[ind]) { - for (i=0; i<samples_per_frame; i++) { - corr[i] = (float) pss_corr_ue[ind][i]; - time[i] = (float) i; - } - - if (ind==0) - fl_set_xyplot_data(form->chest_t,time,corr,samples_per_frame,"","",""); - else - fl_add_xyplot_overlay(form->chest_t,ind,time,corr,samples_per_frame,rx_antenna_colors[ind]); - - overlay = 1; - } + if (pss_corr_ue[ind]) { + for (i=0; i<samples_per_frame; i++) { + corr[i] = (float) pss_corr_ue[ind][i]; + time[i] = (float) i; + } + + if (ind==0) + fl_set_xyplot_data(form->chest_t,time,corr,samples_per_frame,"","",""); + else + fl_add_xyplot_overlay(form->chest_t,ind,time,corr,samples_per_frame,rx_antenna_colors[ind]); + + overlay = 1; + } */ } - } - else { - - if (overlay) { //there was a previous overlay - fl_clear_xyplot(form->chest_t); - overlay = 0; + + // if the UE is not synchronized, we can make only the time*power graph } +} +static void ueChannelResponse (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // Channel Impulse Response - if (chest_t != NULL) { - ymax = 0; + if (!phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates_time) + return; - if (chest_t[0] !=NULL) { - for (i=0; i<(frame_parms->ofdm_symbol_size>>3); i++) { - chest_t_abs[0][i] = (float) (chest_t[0][2*i]*chest_t[0][2*i]+chest_t[0][2*i+1]*chest_t[0][2*i+1]); - time[i] = (float) i; + NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + scopeSample_t **chest_t = (scopeSample_t **) phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates_time; + int ymax = 0; + float chest_t_abs[frame_parms->ofdm_symbol_size]; + float time[frame_parms->ofdm_symbol_size>>3]; + + if (chest_t[0] !=NULL) { + for (int i=0; i<(frame_parms->ofdm_symbol_size>>3); i++) { + chest_t_abs[i] = SquaredNorm(chest_t[0][i]); + time[i] = (float) i; + + if (chest_t_abs[i] > ymax) + ymax = chest_t_abs[i]; + } - if (chest_t_abs[0][i] > ymax) - ymax = chest_t_abs[0][i]; - } + fl_set_xyplot_data(graph,time,chest_t_abs,(frame_parms->ofdm_symbol_size>>3),"","",""); + } - fl_set_xyplot_data(form->chest_t,time,chest_t_abs[0],(frame_parms->ofdm_symbol_size>>3),"","",""); - } - /* - for (arx=1; arx<nb_antennas_rx; arx++) { - if (chest_t[arx] !=NULL) { - for (i=0; i<(frame_parms->ofdm_symbol_size>>3); i++) { - chest_t_abs[arx][i] = (float) (chest_t[arx][4*i]*chest_t[arx][4*i]+chest_t[arx][4*i+1]*chest_t[arx][4*i+1]); - - if (chest_t_abs[arx][i] > ymax) - ymax = chest_t_abs[arx][i]; - } + for (int arx=1; arx<nb_antennas_rx; arx++) { + if (chest_t[arx] !=NULL) { + for (int i=0; i<(frame_parms->ofdm_symbol_size>>3); i++) { + chest_t_abs[i] = SquaredNorm(chest_t[arx][i]); - fl_add_xyplot_overlay(form->chest_t,arx,time,chest_t_abs[arx],(frame_parms->ofdm_symbol_size>>3),rx_antenna_colors[arx]); - fl_set_xyplot_overlay_type(form->chest_t,arx,FL_DASHED_XYPLOT); + if (chest_t_abs[i] > ymax) + ymax = chest_t_abs[i]; } + + fl_add_xyplot_overlay(graph,arx,time,chest_t_abs,(frame_parms->ofdm_symbol_size>>3),rx_antenna_colors[arx]); + fl_set_xyplot_overlay_type(graph,arx,FL_DASHED_XYPLOT); } - */ - // Avoid flickering effect - // fl_get_xyplot_ybounds(form->chest_t,&ymin,&ymax); // Does not always work... - fl_set_xyplot_ybounds(form->chest_t,0,(double) ymax); - } } - // Channel Frequency Response (includes 5 complex sample for filter) - if (chest_f != NULL) { - ind = 0; - - for (atx=0; atx<nb_antennas_tx; atx++) { - for (arx=0; arx<nb_antennas_rx; arx++) { - if (chest_f[(atx<<1)+arx] != NULL) { - for (k=0; k<frame_parms->ofdm_symbol_size; k++) { - freq[ind] = (float)ind; - Re = (float)(chest_f[(atx<<1)+arx][6144+(2*k)]); - Im = (float)(chest_f[(atx<<1)+arx][6144+(2*k)+1]); - - chest_f_abs[ind] = (short)10*log10(1.0+((double)Re*Re + (double)Im*Im)); - ind++; - } - } - } - } + // Avoid flickering effect + // fl_get_xyplot_ybounds(form->chest_t,&ymin,&ymax); // Does not always work... + fl_set_xyplot_ybounds(graph,0,(double) ymax); +} - // tx antenna 0 - //fl_set_xyplot_xbounds(form->chest_f,0,nb_antennas_rx*nb_antennas_tx*nsymb_ce); - //fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*frame_parms->symbols_per_tti,2); - // fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*2,2); - //fl_set_xyplot_xgrid(form->chest_f,FL_GRID_MAJOR); - fl_set_xyplot_data(form->chest_f,freq,chest_f_abs,frame_parms->ofdm_symbol_size,"","",""); - - /* - for (arx=1; arx<nb_antennas_rx; arx++) { - fl_add_xyplot_overlay(form->chest_f,1,&freq[arx*nsymb_ce],&chest_f_abs[arx*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); - } +static void uePbchFrequencyResp (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { + // Channel Frequency Response (includes 5 complex sample for filter) + if (!phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates) + return; - // other tx antennas - if (nb_antennas_tx > 1) { - if (nb_antennas_rx > 1) { - for (atx=1; atx<nb_antennas_tx; atx++) { - for (arx=0; arx<nb_antennas_rx; arx++) { - fl_add_xyplot_overlay(form->chest_f,(atx<<1)+arx,&freq[((atx<<1)+arx)*nsymb_ce],&chest_f_abs[((atx<<1)+arx)*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); - } + NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + uint8_t nb_antennas_tx = frame_parms->nb_antenna_ports_gNB; + scopeSample_t **chest_f = (scopeSample_t **) phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates; + int ind = 0; + float chest_f_abs[frame_parms->ofdm_symbol_size]; + float freq[frame_parms->ofdm_symbol_size]; + + for (int atx=0; atx<nb_antennas_tx; atx++) { + for (int arx=0; arx<nb_antennas_rx; arx++) { + if (chest_f[(atx<<1)+arx] != NULL) { + for (int k=0; k<frame_parms->ofdm_symbol_size; k++) { + freq[ind] = (float)ind; + chest_f_abs[ind] = (short)10*log10(1.0+SquaredNorm(chest_f[(atx<<1)+arx][6144+k])); + ind++; } - } else { // 1 rx antenna - atx=1; - arx=0; - fl_add_xyplot_overlay(form->chest_f,atx,&freq[atx*nsymb_ce],&chest_f_abs[atx*nsymb_ce],nsymb_ce,rx_antenna_colors[arx]); } } - */ } - + + // tx antenna 0 + //fl_set_xyplot_xbounds(form->chest_f,0,nb_antennas_rx*nb_antennas_tx*nsymb_ce); + //fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*frame_parms->symbols_per_tti,2); + // fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*2,2); + //fl_set_xyplot_xgrid(form->chest_f,FL_GRID_MAJOR); + fl_set_xyplot_data(graph,freq,chest_f_abs,frame_parms->ofdm_symbol_size,"","",""); +} + +static void uePbchLLR (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PBCH LLRs - if (pbch_llr != NULL) { - for (i=0; i<864; i++) { - llr_pbch[i] = (float) pbch_llr[i]; - bit_pbch[i] = (float) i; - } + if ( !phy_vars_ue->pbch_vars[eNB_id]->llr) + return; - fl_set_xyplot_data(form->pbch_llr,bit_pbch,llr_pbch,864,"","",""); + int16_t *pbch_llr = (int16_t *) phy_vars_ue->pbch_vars[eNB_id]->llr; + float llr_pbch[864], bit_pbch[864]; + + for (int i=0; i<864; i++) { + llr_pbch[i] = (float) pbch_llr[i]; + bit_pbch[i] = (float) i; } - first_symbol=1; + fl_set_xyplot_data(graph,bit_pbch,llr_pbch,864,"","",""); +} +static void uePbchIQ (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PBCH I/Q of MF Output - if (pbch_comp!=NULL) { - for (symbol=first_symbol; symbol<(first_symbol+3); symbol++) { - if (symbol == 2 || symbol == 6) - nb_re = 72; - else - nb_re = 180; - for (i=0; i<nb_re; i++) { - I[i] = pbch_comp[2*symbol*20*12+2*i]; - Q[i] = pbch_comp[2*symbol*20*12+2*i+1]; - } + if (!phy_vars_ue->pbch_vars[eNB_id]->rxdataF_comp[0]) + return; + + int16_t *pbch_comp = (int16_t *) phy_vars_ue->pbch_vars[eNB_id]->rxdataF_comp[0]; + localBuff(I,180*3); + localBuff(Q,180*3); + int first_symbol=1; + int base=0; + + for (int symbol=first_symbol; symbol<(first_symbol+3); symbol++) { + int nb_re; + + if (symbol == 2 || symbol == 6) + nb_re = 72; + else + nb_re = 180; + + AssertFatal(base+nb_re<180*3,""); + + for (int i=0; i<nb_re; i++) { + I[base+i] = pbch_comp[2*symbol*20*12+2*i]; + Q[base+i] = pbch_comp[2*symbol*20*12+2*i+1]; } - fl_set_xyplot_data(form->pbch_comp,I,Q,432,"","",""); + + base+=nb_re; } + fl_set_xyplot_data(graph,I,Q,base,"","",""); +} + +static void uePcchLLR (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PDCCH LLRs - if (pdcch_llr != NULL) { - for (i=0; i<100; i++) { //12*frame_parms->N_RB_DL*2*num_pdcch_symbols - llr_pdcch[i] = (float) pdcch_llr[2*24*9 +i]; - bit_pdcch[i] = (float) i; - } + if (!phy_vars_ue->pdcch_vars[0][eNB_id]->llr) + return; - fl_set_xyplot_data(form->pdcch_llr,bit_pdcch,llr_pdcch,12*frame_parms->N_RB_DL*num_pdcch_symbols,"","",""); + NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; + uint8_t nb_antennas_rx = frame_parms->nb_antennas_rx; + uint8_t nb_antennas_tx = frame_parms->nb_antennas_tx; + scopeSample_t **chest_f = (scopeSample_t **) phy_vars_ue->pbch_vars[eNB_id]->dl_ch_estimates; + int ind = 0; + float chest_f_abs[frame_parms->ofdm_symbol_size]; + float freq[frame_parms->ofdm_symbol_size]; + + for (int atx=0; atx<nb_antennas_tx; atx++) { + for (int arx=0; arx<nb_antennas_rx; arx++) { + if (chest_f[(atx<<1)+arx] != NULL) { + for (int k=0; k<frame_parms->ofdm_symbol_size; k++) { + freq[ind] = (float)ind; + chest_f_abs[ind] = (short)10*log10(1.0+SquaredNorm(chest_f[(atx<<1)+arx][6144+k])); + ind++; + } + } + } } + // tx antenna 0 + //fl_set_xyplot_xbounds(form->chest_f,0,nb_antennas_rx*nb_antennas_tx*nsymb_ce); + //fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*frame_parms->symbols_per_tti,2); + // fl_set_xyplot_xtics(form->chest_f,nb_antennas_rx*nb_antennas_tx*2,2); + //fl_set_xyplot_xgrid(form->chest_f,FL_GRID_MAJOR); + fl_set_xyplot_data(graph,freq,chest_f_abs,frame_parms->ofdm_symbol_size,"","",""); +} + +static void uePcchIQ (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PDCCH I/Q of MF Output - if (pdcch_comp!=NULL) { - for (i=0; i<100; i++) { - I[i] = pdcch_comp[2*50*12+2*i]; - Q[i] = pdcch_comp[2*50*12+2*i+1]; + if (!phy_vars_ue->pdcch_vars[0][eNB_id]->rxdataF_comp[0]) + return; + + int nb=12*273*4; // 12*frame_parms->N_RB_DL*num_pdcch_symbols + localBuff(I,nb*RX_NB_TH_MAX); + localBuff(Q,nb*RX_NB_TH_MAX); + int base=0; + + for (int thr=0 ; thr < RX_NB_TH_MAX ; thr ++ ) { + int16_t *pdcch_comp = (int16_t *) phy_vars_ue->pdcch_vars[thr][eNB_id]->rxdataF_comp[0]; + + for (int i=0; i< nb; i++) { + I[base+i] = pdcch_comp[i*2]; + Q[base+i] = pdcch_comp[i*2+1]; } - fl_set_xyplot_data(form->pdcch_comp,I,Q,12*frame_parms->N_RB_DL*num_pdcch_symbols,"","",""); + + base+=nb; } + fl_set_xyplot_data(graph,I,Q,base,"","",""); +} + +static void uePdschLLR (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PDSCH LLRs - if (pdsch_llr != NULL) { - for (i=0; i<coded_bits_per_codeword; i++) { - llr[i] = (float) pdsch_llr[i]; - bit[i] = (float) i; + if (!phy_vars_ue->pdsch_vars[0][eNB_id]->llr[0]) + return; + + int num_re = 4500; + int Qm = 2; + int coded_bits_per_codeword = num_re*Qm; + localBuff(llr,coded_bits_per_codeword*RX_NB_TH_MAX); + localBuff(bit,coded_bits_per_codeword*RX_NB_TH_MAX); + int base=0; + + for (int thr=0 ; thr < RX_NB_TH_MAX ; thr ++ ) { + int16_t *pdsch_llr = (int16_t *) phy_vars_ue->pdsch_vars[thr][eNB_id]->llr[0]; // stream 0 + + for (int i=0; i<coded_bits_per_codeword; i++) { + llr[base+i] = (float) pdsch_llr[i]; + bit[base+i] = (float) base+i; } - //fl_set_xyplot_xbounds(form->pdsch_llr,0,coded_bits_per_codeword); - fl_set_xyplot_data(form->pdsch_llr,bit,llr,coded_bits_per_codeword,"","",""); + base+=coded_bits_per_codeword; } - first_symbol = 2; - ind = 0; + //fl_set_xyplot_xbounds(form->pdsch_llr,0,coded_bits_per_codeword); + fl_set_xyplot_data(graph,bit,llr,base,"","",""); +} + +static void uePdschIQ (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { // PDSCH I/Q of MF Output - if (pdsch_comp!=NULL) { - for (symbol=0;symbol<nb_symb_sch;symbol++) { - for (i=0; i<nb_rb_pdsch*12; i++) { - I[ind] = pdsch_comp[2*((first_symbol+symbol)*frame_parms->N_RB_DL*12+i) ]; - Q[ind] = pdsch_comp[2*((first_symbol+symbol)*frame_parms->N_RB_DL*12+i)+1]; - ind++; - } + if (!phy_vars_ue->pdsch_vars[0][eNB_id]->rxdataF_comp0[0]) + return; + + NR_DL_FRAME_PARMS *frame_parms = &phy_vars_ue->frame_parms; + int sz=7*2*frame_parms->N_RB_DL*12; // size of the malloced buffer + localBuff(I,sz*RX_NB_TH_MAX); + localBuff(Q,sz*RX_NB_TH_MAX); + int base=0; + + for (int thr=0 ; thr < RX_NB_TH_MAX ; thr ++ ) { + int16_t *pdsch_comp = (int16_t *) phy_vars_ue->pdsch_vars[thr][eNB_id]->rxdataF_comp0[0]; + + for (int s=0; s<sz; s++) { + I[s+base] += pdsch_comp[2*s]; + Q[s+base] += pdsch_comp[2*s+1]; } - - fl_set_xyplot_data(form->pdsch_comp,I,Q,nb_symb_sch*nb_rb_pdsch*12,"","",""); + + base+=sz; } + + fl_set_xyplot_data(graph,I,Q,base,"","",""); /* // PDSCH Throughput @@ -833,119 +743,155 @@ void phy_scope_nrUE(FD_phy_scope_nrue *form, tput_ue[UE_id][TPUT_WINDOW_LENGTH-1] = ((float) total_dlsch_bitrate)/1000.0; if (tput_ue[UE_id][TPUT_WINDOW_LENGTH-1] > tput_ue_max[UE_id]) { - tput_ue_max[UE_id] = tput_ue[UE_id][TPUT_WINDOW_LENGTH-1]; + tput_ue_max[UE_id] = tput_ue[UE_id][TPUT_WINDOW_LENGTH-1]; } fl_set_xyplot_data(form->pdsch_tput,tput_time_ue[UE_id],tput_ue[UE_id],TPUT_WINDOW_LENGTH,"","",""); fl_set_xyplot_ybounds(form->pdsch_tput,0,tput_ue_max[UE_id]); */ +} - fl_check_forms(); +static void uePdschThroughput (FL_OBJECT *graph, PHY_VARS_NR_UE *phy_vars_ue, int eNB_id, int UE_id) { +} - free(time); - free(corr); - for (arx=0; arx<nb_antennas_rx; arx++) { - free(rxsig_t_dB[arx]); - } - free(rxsig_t_dB); - - free(I); - free(Q); - free(llr); - free(bit); - free(bit_pdcch); - free(llr_pdcch); - free(chest_t_abs); - /* - free(chest_f_abs); - for (arx=0; arx<nb_antennas_rx; arx++) { - free(chest_t_abs[arx]); +static FD_phy_scope_t *create_phy_scope_nrue( int ID ) { + FL_OBJECT *obj; + FD_phy_scope_t *fdui = fl_malloc( sizeof *fdui ); + // Define form + fdui->phy_scope = fl_bgn_form( FL_NO_BOX, 800, 900 ); + // This the whole UI box + obj = fl_add_box( FL_BORDER_BOX, 0, 0, 800, 900, "" ); + fl_set_object_color( obj, FL_BLACK, FL_BLACK ); + // Received signal + fdui->graph[0] = nrUEcommonGraph(ueTimeResponse, + FL_IMPULSE_XYPLOT, 20, 20, 370, 100, "Received Signal (Time-Domain, dB)", FL_RED ); + // Time-domain channel response + fdui->graph[1] = nrUEcommonGraph(ueChannelResponse, + FL_NORMAL_XYPLOT, 410, 20, 370, 100, "Channel Impulse Response (samples, abs)", FL_RED ); + // Frequency-domain channel response + fdui->graph[2] = nrUEcommonGraph(uePbchFrequencyResp, + FL_IMPULSE_XYPLOT, 20, 140, 760, 100, "Channel Frequency data (RE, dB)", FL_RED ); + // LLR of PBCH + fdui->graph[3] = nrUEcommonGraph(uePbchLLR, + FL_POINTS_XYPLOT, 20, 260, 500, 100, "PBCH Log-Likelihood Ratios (LLR, mag)", FL_GREEN ); + fl_set_xyplot_xgrid(fdui->graph[3].graph,FL_GRID_MAJOR); + // I/Q PBCH comp + fdui->graph[4] = nrUEcommonGraph(uePbchIQ, + FL_POINTS_XYPLOT, 540, 260, 240, 100, "PBCH I/Q of MF Output", FL_GREEN ); + // LLR of PDCCH + fdui->graph[5] = nrUEcommonGraph(uePcchLLR, + FL_POINTS_XYPLOT, 20, 380, 500, 100, "PDCCH Log-Likelihood Ratios (LLR, mag)", FL_CYAN ); + // I/Q PDCCH comp + fdui->graph[6] = nrUEcommonGraph(uePcchIQ, + FL_POINTS_XYPLOT, 540, 380, 240, 100, "PDCCH I/Q of MF Output", FL_CYAN ); + // LLR of PDSCH + fdui->graph[7] = nrUEcommonGraph(uePdschLLR, + FL_POINTS_XYPLOT, 20, 500, 500, 200, "PDSCH Log-Likelihood Ratios (LLR, mag)", FL_YELLOW ); + // I/Q PDSCH comp + fdui->graph[8] = nrUEcommonGraph(uePdschIQ, + FL_POINTS_XYPLOT, 540, 500, 240, 200, "PDSCH I/Q of MF Output", FL_YELLOW ); + // Throughput on PDSCH + fdui->graph[9] = nrUEcommonGraph(uePdschThroughput, + FL_NORMAL_XYPLOT, 20, 720, 500, 100, "PDSCH Throughput [frame]/[kbit/s]", FL_WHITE ); + fdui->graph[10].graph=NULL; + // Generic UE Button + fdui->button_0 = fl_add_button( FL_PUSH_BUTTON, 540, 720, 240, 40, "" ); + fl_set_object_lalign(fdui->button_0, FL_ALIGN_CENTER ); + //openair_daq_vars.use_ia_receiver = 0; + fl_set_button(fdui->button_0,0); + fl_set_object_label(fdui->button_0, "IA Receiver OFF"); + fl_set_object_color(fdui->button_0, FL_RED, FL_RED); + fl_set_object_callback(fdui->button_0, ia_receiver_on_off, 0 ); + fl_hide_object(fdui->button_0); + fl_end_form( ); + fdui->phy_scope->fdui = fdui; + char buf[100]; + sprintf(buf,"NR DL SCOPE UE %d", ID); + fl_show_form (fdui->phy_scope, FL_PLACE_HOTSPOT, FL_FULLBORDER, buf); + return fdui; +} + +void phy_scope_nrUE(FD_phy_scope_t *form, + PHY_VARS_NR_UE *phy_vars_ue, + int eNB_id, + int UE_id) { + static FD_phy_scope_t *remeberForm=NULL; + + if (form==NULL) + form=remeberForm; + else + remeberForm=form; + + if (form==NULL) + return; + + int i=0; + + while (form->graph[i].graph) { + form->graph[i].nrUEfunct(form->graph[i].graph, phy_vars_ue, eNB_id, UE_id); + i++; } - free(chest_t_abs); - */ + + fl_check_forms(); } +static FD_phy_scope_t *form_nrue[NUMBER_OF_UE_MAX]; +static pthread_t forms_thread; -typedef struct { - FL_FORM *stats_form; - void *vdata; - char *cdata; - long ldata; - FL_OBJECT *stats_text; - FL_OBJECT *stats_button; -} FD_stats_form; +static void *nrUEscopeThread(void *arg) { + PHY_VARS_NR_UE *ue=(PHY_VARS_NR_UE *)arg; + size_t stksize; + pthread_attr_t atr; + pthread_attr_getstacksize(&atr, &stksize); + pthread_attr_setstacksize(&atr,32*1024*1024 ); + + while (!oai_exit) { + phy_scope_nrUE(form_nrue[0], + ue, + 0,0); + usleep(99*1000); + } + + pthread_exit((void *)arg); +} +void nrUEinitScope(PHY_VARS_NR_UE *ue) { + int fl_argc=1; + char *name="5G-UE-scope"; + fl_initialize (&fl_argc, &name, NULL, 0, 0); + form_nrue[0] = create_phy_scope_nrue(0); + threadCreate(&forms_thread, nrUEscopeThread, ue, "scope", -1, OAI_PRIORITY_RT_LOW); +} -// current status is that every UE has a DL scope for a SINGLE eNB (gnb_id=0) -// at eNB 0, an UL scope for every UE -FD_phy_scope_gnb *form_gnb[NUMBER_OF_UE_MAX]; +// Kept to put back the functionality soon +#if 0 //FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; //char title[255]; -unsigned char scope_enb_num_ue = 1; //static pthread_t forms_thread; //xforms - - -void reset_stats_gNB(FL_OBJECT *button, - long arg) -{ +static void reset_stats_gNB(FL_OBJECT *button, + long arg) { int i,k; //PHY_VARS_gNB *phy_vars_gNB = RC.gNB[0][0]; for (i=0; i<NUMBER_OF_UE_MAX; i++) { for (k=0; k<8; k++) { //harq_processes /* for (j=0; j<phy_vars_gNB->dlsch[i][0]->Mlimit; j++) { - phy_vars_gNB->UE_stats[i].dlsch_NAK[k][j]=0; - phy_vars_gNB->UE_stats[i].dlsch_ACK[k][j]=0; - phy_vars_gNB->UE_stats[i].dlsch_trials[k][j]=0; - } - phy_vars_gNB->UE_stats[i].dlsch_l2_errors[k]=0; - phy_vars_gNB->UE_stats[i].ulsch_errors[k]=0; - phy_vars_gNB->UE_stats[i].ulsch_consecutive_errors=0; - phy_vars_gNB->UE_stats[i].dlsch_sliding_cnt=0; - phy_vars_gNB->UE_stats[i].dlsch_NAK_round0=0; - phy_vars_gNB->UE_stats[i].dlsch_mcs_offset=0;*/ - } - } -} - - -static void *scope_thread_gNB(void *arg) { - scopeParms_t * p=(scopeParms_t *) arg; -//# ifdef ENABLE_XFORMS_WRITE_STATS -// FILE *gNB_stats = fopen("gNB_stats.txt", "w"); -//#endif - - while (!oai_exit) { - int ue_cnt=0; - - for(int UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++) { - if ((ue_cnt<scope_enb_num_ue)) { - //this function needs to be written - phy_scope_gNB(form_gnb[ue_cnt], p->gNB, p->ru, UE_id); - ue_cnt++; + phy_vars_gNB->UE_stats[i].dlsch_NAK[k][j]=0; + phy_vars_gNB->UE_stats[i].dlsch_ACK[k][j]=0; + phy_vars_gNB->UE_stats[i].dlsch_trials[k][j]=0; } + phy_vars_gNB->UE_stats[i].dlsch_l2_errors[k]=0; + phy_vars_gNB->UE_stats[i].ulsch_errors[k]=0; + phy_vars_gNB->UE_stats[i].ulsch_consecutive_errors=0; + phy_vars_gNB->UE_stats[i].dlsch_sliding_cnt=0; + phy_vars_gNB->UE_stats[i].dlsch_NAK_round0=0; + phy_vars_gNB->UE_stats[i].dlsch_mcs_offset=0;*/ } - sleep(1); - } - -// printf("%s",stats_buffer); -/*#ifdef ENABLE_XFORMS_WRITE_STATS - - if (eNB_stats) { - rewind (gNB_stats); - fwrite (stats_buffer, 1, len, gNB_stats); - fclose (gNB_stats); } - -#endif - pthread_exit((void *)arg); -}*/ - - return NULL; } -FD_stats_form * create_form_stats_form( void ) { +static FD_stats_form *create_form_stats_form(int ID) { FL_OBJECT *obj; FD_stats_form *fdui = fl_malloc( sizeof *fdui ); fdui->vdata = fdui->cdata = NULL; @@ -963,24 +909,8 @@ FD_stats_form * create_form_stats_form( void ) { fdui->stats_form->fdui = fdui; return fdui; } +#endif + + -void startScope(scopeParms_t * p) { - //FD_stats_form *form_stats=NULL,*form_stats_l2=NULL; - char title[255]; - fl_initialize (p->argc, p->argv, NULL, 0, 0); - /* - form_stats_l2 = create_form_stats_form(); - fl_show_form (form_stats_l2->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "l2 stats"); - form_stats = create_form_stats_form(); - fl_show_form (form_stats->stats_form, FL_PLACE_HOTSPOT, FL_FULLBORDER, "stats"); - */ - - for(int UE_id=0; UE_id<scope_enb_num_ue; UE_id++) { - form_gnb[UE_id] = create_phy_scope_gnb(); - sprintf (title, "LTE UL SCOPE eNB for UE %d",UE_id); - fl_show_form (form_gnb[UE_id]->phy_scope_gnb, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); - } // UE_id - pthread_t forms_thread; - threadCreate(&forms_thread, scope_thread_gNB, p, "scope", -1, OAI_PRIORITY_RT_LOW); -} diff --git a/openair1/PHY/TOOLS/nr_phy_scope.h b/openair1/PHY/TOOLS/nr_phy_scope.h index fd5436a9d8f90bc2bb9a27febb66b0f84c349a66..cf28680a94edf4e426f600e64abf1b29dd113082 100644 --- a/openair1/PHY/TOOLS/nr_phy_scope.h +++ b/openair1/PHY/TOOLS/nr_phy_scope.h @@ -34,55 +34,15 @@ //#include "PHY/impl_defs_top.h" #include "PHY/defs_nr_UE.h" -/* Forms and Objects */ -typedef struct { - FL_FORM * phy_scope_gnb; - FL_OBJECT * rxsig_t; - FL_OBJECT * chest_f; - FL_OBJECT * chest_t; - FL_OBJECT * pusch_comp; - FL_OBJECT * pucch_comp; - FL_OBJECT * pucch_comp1; - FL_OBJECT * pusch_llr; - FL_OBJECT * pusch_tput; - FL_OBJECT * button_0; -} FD_phy_scope_gnb; - -typedef struct { - FL_FORM * phy_scope_nrue; - FL_OBJECT * rxsig_t; - FL_OBJECT * chest_f; - FL_OBJECT * chest_t; - FL_OBJECT * pbch_comp; - FL_OBJECT * pbch_llr; - FL_OBJECT * pdcch_comp; - FL_OBJECT * pdcch_llr; - FL_OBJECT * pdsch_comp; - FL_OBJECT * pdsch_llr; - FL_OBJECT * pdsch_comp1; - FL_OBJECT * pdsch_llr1; - FL_OBJECT * pdsch_tput; - FL_OBJECT * button_0; -} FD_phy_scope_nrue; - typedef struct { int *argc; char **argv; - RU_t* ru; + RU_t *ru; PHY_VARS_gNB *gNB; } scopeParms_t; -extern unsigned char scope_enb_num_ue; -FD_phy_scope_nrue * create_phy_scope_nrue( void ); - -void phy_scope_nrUE(FD_phy_scope_nrue *form, - PHY_VARS_NR_UE *phy_vars_ue, - int eNB_id, - int UE_id, - uint8_t subframe); - - -void startScope(scopeParms_t * p); +void gNBinitScope(scopeParms_t *p); +void nrUEinitScope(PHY_VARS_NR_UE *ue); extern RAN_CONTEXT_t RC; #endif diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h index 7a050e2cc3c420018323c2ab8c33c811fdbf7655..e2cdebff3ad345c91d5e4144f316e03190694ace 100644 --- a/openair1/PHY/defs_gNB.h +++ b/openair1/PHY/defs_gNB.h @@ -689,6 +689,8 @@ typedef struct PHY_VARS_gNB_s { NR_gNB_ULSCH_t *ulsch[NUMBER_OF_NR_ULSCH_MAX][2]; // [Nusers times][2 codewords] NR_gNB_DLSCH_t *dlsch_SI,*dlsch_ra,*dlsch_p; NR_gNB_DLSCH_t *dlsch_PCH; + t_nrPolar_params *uci_polarParams; + uint8_t pbch_configured; char gNB_generate_rar; diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c index 35cba61c01b3e21badc364d70ae090f756a08136..e41bdd4ccc2ca7199853f048e3cb3efeedeb55dc 100644 --- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c +++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c @@ -53,7 +53,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ // Note: we have to handle the thread IDs for this. To be revisited completely. thread_id = PHY_vars_UE_g[module_id][cc_id]->current_thread_id[slot]; - NR_UE_DLSCH_t *dlsch0; + NR_UE_DLSCH_t *dlsch0 = NULL; NR_UE_PDCCH *pdcch_vars = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0]; NR_UE_ULSCH_t *ulsch0 = PHY_vars_UE_g[module_id][cc_id]->ulsch[thread_id][0][0]; NR_DL_FRAME_PARMS frame_parms = PHY_vars_UE_g[module_id][cc_id]->frame_parms; @@ -131,7 +131,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ uint8_t pdu_type = ul_config->ul_config_list[i].pdu_type, pucch_resource_id, current_harq_pid, format, gNB_id = 0; /* PRACH */ - NR_PRACH_RESOURCES_t *prach_resources; + //NR_PRACH_RESOURCES_t *prach_resources; fapi_nr_ul_config_prach_pdu *prach_config_pdu; /* PUSCH */ nfapi_nr_ue_pusch_pdu_t *pusch_config_pdu; @@ -201,7 +201,7 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response){ case (FAPI_NR_UL_CONFIG_TYPE_PRACH): // prach config pdu - prach_resources = PHY_vars_UE_g[module_id][cc_id]->prach_resources[gNB_id]; + //prach_resources = PHY_vars_UE_g[module_id][cc_id]->prach_resources[gNB_id]; prach_config_pdu = &ul_config->ul_config_list[i].prach_config_pdu; memcpy((void*)&(PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->prach_pdu), (void*)prach_config_pdu, sizeof(fapi_nr_ul_config_prach_pdu)); PHY_vars_UE_g[module_id][cc_id]->prach_vars[gNB_id]->prach_Config_enabled = 1; diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index cca7d0cfbbad68a9edb4616eec1f9a1b8e524bff..1b309438b869770c166e11c0d63942b764e0dabb 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -4130,12 +4130,13 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue, LOG_D(PHY,"[UE %d] Frame %d, nr_tti_rx %d: found %d DCIs\n", ue->Mod_id, frame_rx, nr_tti_rx, dci_cnt); - NR_UE_DLSCH_t *dlsch; + NR_UE_DLSCH_t *dlsch = NULL; if (ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]->active == 1){ dlsch = ue->dlsch[ue->current_thread_id[nr_tti_rx]][eNB_id][0]; } else if (ue->dlsch_ra[0]->active == 1){ dlsch = ue->dlsch_ra[0]; } + AssertFatal(dlsch != NULL, "Unsupported mode\n"); uint8_t harq_pid = dlsch->current_harq_pid; NR_DL_UE_HARQ_t *dlsch0_harq = dlsch->harq_processes[harq_pid]; uint16_t nb_symb_sch = dlsch0_harq->nb_symbols; @@ -4505,7 +4506,7 @@ void nr_ue_prach_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, uint8_t uint8_t mod_id = ue->Mod_id; UE_MODE_t UE_mode = get_nrUE_mode(mod_id, ue->CC_id, gNB_id); NR_PRACH_RESOURCES_t * prach_resources = ue->prach_resources[gNB_id]; - uint8_t nr_prach; + uint8_t nr_prach = 0; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_PRACH, VCD_FUNCTION_IN); diff --git a/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c b/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c index e62155e54e023242e70ccf4a83e891fe9cd4777a..bfb9150868da49fb40a79d0dc42d6a6211ca7248 100644 --- a/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c +++ b/openair1/SIMULATION/NR_PHY/nr_dummy_functions_prach.c @@ -91,7 +91,7 @@ void nr_get_prach_resources(module_id_t mod_id, NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon; // NR_BeamFailureRecoveryConfig_t *beam_failure_recovery_config = &mac->RA_BeamFailureRecoveryConfig; // todo - int messagePowerOffsetGroupB, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3; + int messagePowerOffsetGroupB = 0, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3 = 0; uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, msg1_FDM, prach_ConfigIndex, SFN_nbr, Msg3_size; // NR_RSRP_Range_t rsrp_ThresholdSSB; // todo diff --git a/openair1/SIMULATION/NR_PHY/pucchsim.c b/openair1/SIMULATION/NR_PHY/pucchsim.c index e2dc9d527aee8b41a0105f8d1937e28b4267532b..e1ffe7eb6c2f640ff8217e694b55448ae83b0846 100644 --- a/openair1/SIMULATION/NR_PHY/pucchsim.c +++ b/openair1/SIMULATION/NR_PHY/pucchsim.c @@ -86,7 +86,7 @@ int main(int argc, char **argv) int format=0; //uint8_t extended_prefix_flag=0; FILE *input_fd=NULL; - uint8_t nacktoack_flag=0; + //uint8_t nacktoack_flag=0; int16_t amp=0x7FFF; int nr_tti_tx=0; uint64_t actual_payload=0,payload_received; @@ -285,7 +285,7 @@ int main(int argc, char **argv) actual_payload=atoi(optarg); break; case 'T': - nacktoack_flag=(uint8_t)atoi(optarg); + //nacktoack_flag=(uint8_t)atoi(optarg); target_error_rate=0.001; break; default: @@ -338,7 +338,7 @@ int main(int argc, char **argv) } AssertFatal(((format < 2)&&(nr_bit<3)&&(actual_payload<4)) || - ((format == 2)&&(nr_bit>2)&&(nr_bit<12)),"illegal combination format %d, nr_bit %d\n", + ((format == 2)&&(nr_bit>2)&&(nr_bit<65)),"illegal combination format %d, nr_bit %d\n", format,nr_bit); actual_payload &= ((1<<nr_bit)-1); @@ -459,6 +459,8 @@ int main(int argc, char **argv) pucch_GroupHopping_t PUCCH_GroupHopping=UE->pucch_config_common_nr->pucch_GroupHopping; uint32_t hopping_id=UE->pucch_config_common_nr->hoppingId; uint32_t dmrs_scrambling_id = 0, data_scrambling_id=0; + //t_nrPolar_params *currentPtr; + if(format==0){ // for now we are not considering SR just HARQ-ACK if (nr_bit ==0) @@ -469,7 +471,8 @@ int main(int argc, char **argv) mcs=table2_mcs[actual_payload]; else AssertFatal(1==0,"Either nr_bit %d or sr_flag %d must be non-zero\n", nr_bit, sr_flag); } - + else if (format == 2 && nr_bit > 11) gNB->uci_polarParams = nr_polar_params(2, nr_bit, nrofPRB, 1, NULL); + for(SNR=snr0;SNR<=snr1;SNR=SNR+1){ ack_nack_errors=0; n_errors = 0; @@ -500,7 +503,7 @@ int main(int argc, char **argv) } int rxlev = signal_energy(&rxdataF[aa][startingSymbolIndex*frame_parms->ofdm_symbol_size], frame_parms->ofdm_symbol_size); - // printf("rxlev %d (%d dB), sigma2 %f dB, SNR %f, TX %f\n",rxlev,dB_fixed(rxlev),sigma2_dB,SNR,10*log10((double)txlev*UE->frame_parms.ofdm_symbol_size/12)); + if (n_trials==1) printf("rxlev %d (%d dB), sigma2 %f dB, SNR %f, TX %f\n",rxlev,dB_fixed(rxlev),sigma2_dB,SNR,10*log10((double)txlev*UE->frame_parms.ofdm_symbol_size/12)); if(format==0){ nfapi_nr_uci_pucch_pdu_format_0_1_t uci_pdu; nfapi_nr_pucch_pdu_t pucch_pdu; @@ -508,6 +511,8 @@ int main(int argc, char **argv) pucch_pdu.group_hop_flag = PUCCH_GroupHopping&1; pucch_pdu.sequence_hop_flag = (PUCCH_GroupHopping>>1)&1; pucch_pdu.bit_len_harq = nr_bit; + pucch_pdu.bit_len_csi_part1 = 0; + pucch_pdu.bit_len_csi_part2 = 0; pucch_pdu.sr_flag = sr_flag; pucch_pdu.nr_of_symbols = nrofSymbols; pucch_pdu.hopping_id = hopping_id; @@ -536,7 +541,9 @@ int main(int argc, char **argv) pucch_pdu.subcarrier_spacing = 1; pucch_pdu.group_hop_flag = PUCCH_GroupHopping&1; pucch_pdu.sequence_hop_flag = (PUCCH_GroupHopping>>1)&1; - pucch_pdu.bit_len_harq = nr_bit; + pucch_pdu.bit_len_csi_part1 = nr_bit; + pucch_pdu.bit_len_harq = 0; + pucch_pdu.bit_len_csi_part2 = 0; pucch_pdu.sr_flag = 0; pucch_pdu.nr_of_symbols = nrofSymbols; pucch_pdu.hopping_id = hopping_id; @@ -547,14 +554,15 @@ int main(int argc, char **argv) pucch_pdu.dmrs_scrambling_id = dmrs_scrambling_id; pucch_pdu.data_scrambling_id = data_scrambling_id; nr_decode_pucch2(gNB,nr_tti_tx,&uci_pdu,&pucch_pdu); - int harq_bytes=pucch_pdu.bit_len_harq>>3; - if ((pucch_pdu.bit_len_harq&7) > 0) harq_bytes++; - for (int i=0;i<harq_bytes;i++) - if (uci_pdu.harq.harq_payload[i] != ((int8_t*)&actual_payload)[i]) { + int csi_part1_bytes=pucch_pdu.bit_len_csi_part1>>3; + if ((pucch_pdu.bit_len_csi_part1&7) > 0) csi_part1_bytes++; + for (int i=0;i<csi_part1_bytes;i++) { + if (uci_pdu.csi_part1.csi_part1_payload[i] != ((uint8_t*)&actual_payload)[i]) { ack_nack_errors++; break; } - free(uci_pdu.harq.harq_payload); + } + free(uci_pdu.csi_part1.csi_part1_payload); } n_errors=((actual_payload^payload_received)&1)+(((actual_payload^payload_received)&2)>>1)+(((actual_payload^payload_received)&4)>>2)+n_errors; diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index 098757d9a64d6b516819b31bb518ec24403332e6..76ed96d7a41b795b50c723acfe371543a7b40af1 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -119,7 +119,7 @@ int main(int argc, char **argv) int trial, n_trials = 1, n_errors = 0, n_false_positive = 0, delay = 0; uint8_t n_tx = 1, n_rx = 1; //uint8_t transmission_mode = 1; - uint16_t Nid_cell = 0; + //uint16_t Nid_cell = 0; channel_desc_t *gNB2UE; uint8_t extended_prefix_flag = 0; //int8_t interf1 = -21, interf2 = -21; @@ -130,7 +130,7 @@ int main(int argc, char **argv) int frame_length_complex_samples,frame_length_complex_samples_no_prefix; NR_DL_FRAME_PARMS *frame_parms; int loglvl = OAILOG_WARNING; - uint64_t SSB_positions=0x01; + //uint64_t SSB_positions=0x01; uint16_t nb_symb_sch = 12; int start_symbol = 2; uint16_t nb_rb = 50; @@ -377,6 +377,7 @@ int main(int argc, char **argv) printf("-P Print ULSCH performances\n"); exit(-1); break; + } } diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c index dcf073de54aa3f0036beb829a2698279cbc5a870..9bdd70926241bc8d86765b40e213a45bcfe615b0 100644 --- a/openair2/GNB_APP/gnb_app.c +++ b/openair2/GNB_APP/gnb_app.c @@ -75,12 +75,12 @@ static void configure_nr_rrc(uint32_t gnb_id) static uint32_t gNB_app_register(uint32_t gnb_id_start, uint32_t gnb_id_end)//, const Enb_properties_array_t *enb_properties) { uint32_t gnb_id; - MessageDef *msg_p; + //MessageDef *msg_p; uint32_t register_gnb_pending = 0; for (gnb_id = gnb_id_start; (gnb_id < gnb_id_end) ; gnb_id++) { { - s1ap_register_enb_req_t *s1ap_register_gNB; //Type Temporarily reuse + //s1ap_register_enb_req_t *s1ap_register_gNB; //Type Temporarily reuse // note: there is an implicit relationship between the data structure and the message name /*msg_p = itti_alloc_new_message (TASK_GNB_APP, S1AP_REGISTER_ENB_REQ); //Message Temporarily reuse diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c index 5d99acfc3aa56306c91274f7d1e23f924acc9c1b..9d7f3264c5cb8b8c99e051a3a2f525871d3c5d1e 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c @@ -130,6 +130,7 @@ int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_forma AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, prach_format, prachConfigIndex); } } + return 0; } /* TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration */ @@ -149,4 +150,4 @@ int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t m receivedTargerPower = preambleReceivedTargetPower + delta_preamble + (mac->RA_PREAMBLE_POWER_RAMPING_COUNTER - 1) * prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP; return receivedTargerPower; -} \ No newline at end of file +} diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 2c7db4162030c08cf2cffaaeef64b3633b827130..56ae14f98b8760d0708ebf9684a3b6fa060da999 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -88,7 +88,7 @@ void nr_get_prach_resources(module_id_t mod_id, // NR_BeamFailureRecoveryConfig_t *beam_failure_recovery_config = &mac->RA_BeamFailureRecoveryConfig; // todo - int messagePowerOffsetGroupB, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA, numberOfRA_Preambles, i, deltaPreamble_Msg3; + int messagePowerOffsetGroupB = 0, messageSizeGroupA, PLThreshold, sizeOfRA_PreamblesGroupA = 0, numberOfRA_Preambles, i, deltaPreamble_Msg3 = 0; uint8_t noGroupB = 0, s_id, f_id, ul_carrier_id, prach_ConfigIndex, SFN_nbr, Msg3_size; AssertFatal(scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup != NULL, "[UE %d] FATAL nr_rach_ConfigCommon is NULL !!!\n", mod_id); @@ -345,14 +345,15 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id); uint8_t mac_sdus[MAX_NR_ULSCH_PAYLOAD_BYTES]; - uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, *payload, ra_ResponseWindow; + uint8_t lcid = UL_SCH_LCID_CCCH_MSG3, *payload; + //uint8_t ra_ResponseWindow; uint16_t size_sdu = 0; unsigned short post_padding; - fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; + //fapi_nr_config_request_t *cfg = &mac->phy_config.config_req; NR_ServingCellConfigCommon_t *scc = mac->scc; NR_RACH_ConfigCommon_t *setup = scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup; NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric; - NR_FrequencyInfoDL_t *frequencyInfoDL = scc->downlinkConfigCommon->frequencyInfoDL; + //NR_FrequencyInfoDL_t *frequencyInfoDL = scc->downlinkConfigCommon->frequencyInfoDL; NR_RACH_ConfigDedicated_t *rach_ConfigDedicated = mac->rach_ConfigDedicated; // int32_t frame_diff = 0; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c index 5be0f10731dbad91af544ba55729bb83a950c76a..a79b4083e31429380a0dde40974a1c2a8f61bd92 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c @@ -160,7 +160,7 @@ void ue_dci_configuration(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_request_t *dl if (mac->crnti > 0) { NR_SearchSpace_t *css; - NR_SearchSpace_t *uss; + NR_SearchSpace_t *uss = NULL; NR_ServingCellConfigCommon_t *scc; NR_SearchSpaceId_t ra_SearchSpaceId; rel15 = &dl_config->dl_config_list[dl_config->number_pdus].dci_config_pdu.dci_config_rel15; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 43aaee1bbadb03826c40090f1ad1990e17010d03..163855a093c880ed367c91296cecb54ca42e9beb 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -937,7 +937,7 @@ void nr_ue_msg2_scheduler(module_id_t mod_id, // and if the slot is not among the PDCCH monitored ones (38.213 10.1) while ((*msg2_slot > slot_limit) || ((*msg2_frame*nr_slots_per_frame[mu] + *msg2_slot - monitoring_offset) % monitoring_slot_period != 0)) { if((*msg2_slot % tdd_period_slot) > 0) - *msg2_slot--; + (*msg2_slot)--; else AssertFatal(1 == 0, "No available DL slot to schedule reception of msg2 has been found"); } diff --git a/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c b/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c index e9d3f8c3278a5a2998e9670a0ae447c97deffdb8..bfd2d3dbebee6e44c1a5004bad5998daa22d9600 100644 --- a/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c +++ b/openair2/LAYER2/NR_MAC_UE/rar_tools_nrUE.c @@ -105,7 +105,7 @@ uint16_t nr_ue_process_rar(module_id_t mod_id, NR_MAC_RAR *rar = (NR_MAC_RAR *) (dlsch_buffer + 1); // RAR subPDU pointer uint8_t n_subPDUs = 0; // number of RAR payloads uint8_t n_subheaders = 0; // number of MAC RAR subheaders - uint8_t best_rx_rapid = -1; // the closest RAPID receive from all RARs + //uint8_t best_rx_rapid = -1; // the closest RAPID receive from all RARs unsigned char freq_hopping, msg3_t_alloc, mcs, tpc_command, csi_req; uint16_t ta_command = 0, msg3_f_alloc, bwp_size; int f_alloc, mask; diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c index 3cf835f9a1156be6c046698afe756176e41af3cd..db93734a7ddc11d9315212fd1bc9e4bad3bf1594 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c @@ -221,13 +221,14 @@ void nr_schedule_msg2(uint16_t rach_frame, uint16_t rach_slot, // slot and frame limit to transmit msg2 according to response window uint8_t slot_limit = (rach_slot + slot_window)%nr_slots_per_frame_mac[mu]; - uint8_t frame_limit = (slot_limit>(rach_slot))? rach_frame : (rach_frame +1); + //uint8_t frame_limit = (slot_limit>(rach_slot))? rach_frame : (rach_frame +1); + // go to previous slot if the current scheduled slot is beyond the response window // and if the slot is not among the PDCCH monitored ones (38.213 10.1) while ((*msg2_slot>slot_limit) || ((*msg2_frame*nr_slots_per_frame_mac[mu]+*msg2_slot-monitoring_offset)%monitoring_slot_period !=0)) { if((*msg2_slot%tdd_period_slot) > 0) - *msg2_slot--; + (*msg2_slot)--; else AssertFatal(1==0,"No available DL slot to schedule msg2 has been found"); } @@ -763,7 +764,8 @@ void nr_fill_rar(uint8_t Mod_idP, NR_RA_HEADER_RAPID *rarh = (NR_RA_HEADER_RAPID *) dlsch_buffer; NR_MAC_RAR *rar = (NR_MAC_RAR *) (dlsch_buffer + 1); unsigned char csi_req = 0, tpc_command; - uint8_t N_UL_Hop, valid_bits; + //uint8_t N_UL_Hop; + uint8_t valid_bits; uint32_t ul_grant; uint16_t f_alloc, prb_alloc, bwp_size, truncation=0; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c index 617cb4d313b28bfc190b36fe1b5b94d18e77a9e4..3667af26984326071cc20b7d33fd55c3cc4b5ae7 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c @@ -503,8 +503,6 @@ pdcp_data_ind( //----------------------------------------------------------------------------- { pdcp_t *pdcp_p = NULL; - list_t *sdu_list_p = NULL; - mem_block_t *new_sdu_p = NULL; uint8_t pdcp_header_len = 0; uint8_t pdcp_tailer_len = 0; pdcp_sn_t sequence_number = 0; @@ -576,7 +574,6 @@ pdcp_data_ind( } } - sdu_list_p = &pdcp_sdu_list; if (sdu_buffer_sizeP == 0) { LOG_W(PDCP, "SDU buffer size is zero! Ignoring this chunk!\n"); @@ -974,9 +971,8 @@ pdcp_data_ind( #endif if (FALSE == packet_forwarded) { - new_sdu_p = get_free_mem_block(sdu_buffer_sizeP - payload_offset + sizeof (pdcp_data_ind_header_t), __func__); + notifiedFIFO_elt_t * new_sdu_p = newNotifiedFIFO_elt(sdu_buffer_sizeP - payload_offset + sizeof (pdcp_data_ind_header_t), 0, NULL, NULL); - if (new_sdu_p) { if ((MBMS_flagP == 0) && (pdcp_p->rlc_mode == RLC_MODE_AM)) { pdcp_p->last_submitted_pdcp_rx_sn = sequence_number; } @@ -984,14 +980,15 @@ pdcp_data_ind( /* * Prepend PDCP indication header which is going to be removed at pdcp_fifo_flush_sdus() */ - memset(new_sdu_p->data, 0, sizeof (pdcp_data_ind_header_t)); - ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size = sdu_buffer_sizeP - payload_offset; + pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(new_sdu_p); + memset(pdcpHead, 0, sizeof (pdcp_data_ind_header_t)); + pdcpHead->data_size = sdu_buffer_sizeP - payload_offset; AssertFatal((sdu_buffer_sizeP - payload_offset >= 0), "invalid PDCP SDU size!"); // Here there is no virtualization possible // set ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst for IP layer here if (ctxt_pP->enb_flag == ENB_FLAG_NO) { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id; + pdcpHead->rb_id = rb_id; if (EPC_MODE_ENABLED) { /* for the UE compiled in S1 mode, we need 1 here @@ -1002,45 +999,40 @@ pdcp_data_ind( #ifdef UESIM_EXPANSION if (UE_NAS_USE_TUN) { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; + pdcpHead->inst = ctxt_pP->module_id; } else { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 0; + pdcpHead->inst = 0; } #else - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; + pdcpHead->inst = ctxt_pP->module_id; #endif } else { // nfapi_mode if (UE_NAS_USE_TUN) { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; + pdcpHead->inst = ctxt_pP->module_id; } else { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 1; + pdcpHead->inst = 1; } } // nfapi_mode } } else { - ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB); - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; + pdcpHead->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB); + pdcpHead->inst = ctxt_pP->module_id; } if( LOG_DEBUGFLAG(DEBUG_PDCP) ) { static uint32_t pdcp_inst = 0; - ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = pdcp_inst++; - LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size); + pdcpHead->inst = pdcp_inst++; + LOG_D(PDCP, "inst=%d size=%d\n", pdcpHead->inst, pdcpHead->data_size); } - memcpy(&new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], + memcpy(pdcpHead+1, &sdu_buffer_pP->data[payload_offset], sdu_buffer_sizeP - payload_offset); - - #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) - LOG_I(PDCP, "Printing first bytes of PDCP SDU before adding it to the list: \n"); - for (int i=0; i<30; i++){ - LOG_I(PDCP, "%x", sdu_buffer_pP->data[i]); - } - #endif - list_add_tail_eurecom (new_sdu_p, sdu_list_p); - } + if( LOG_DEBUGFLAG(DEBUG_PDCP) ) + log_dump(PDCP, pdcpHead+1, min(sdu_buffer_sizeP - payload_offset,30) , LOG_DUMP_CHAR, + "Printing first bytes of PDCP SDU before adding it to the list: \n"); + pushNotifiedFIFO(&pdcp_sdu_list, new_sdu_p); /* Print octets of incoming data in hexadecimal form */ LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n", @@ -2467,7 +2459,7 @@ void pdcp_layer_init(void) /* * Initialize SDU list */ - list_init(&pdcp_sdu_list, NULL); + initNotifiedFIFO(&pdcp_sdu_list); pdcp_coll_p = hashtable_create ((LTE_maxDRB + 2) * NUMBER_OF_UE_MAX, NULL, pdcp_free); AssertFatal(pdcp_coll_p != NULL, "UNRECOVERABLE error, PDCP hashtable_create failed"); @@ -2540,7 +2532,8 @@ void pdcp_layer_init(void) void pdcp_layer_cleanup (void) //----------------------------------------------------------------------------- { - list_free (&pdcp_sdu_list); + //list_free (&pdcp_sdu_list); + while(pollNotifiedFIFO(&pdcp_sdu_list)) {}; hashtable_destroy(&pdcp_coll_p); #ifdef MBMS_MULTICAST_OUT diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h index e9ac85866cec5d73e2b0e7dd7efe658981cf7e5e..8e265e8cf1940286fcbac96908d50cf9f5178674 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h @@ -522,7 +522,7 @@ pdcp_mbms_t pdcp_mbms_array_eNB[NUMBER_OF_eNB_MAX][LTE_maxServiceC sdu_size_t pdcp_output_sdu_bytes_to_write; sdu_size_t pdcp_output_header_bytes_to_write; -list_t pdcp_sdu_list; +notifiedFIFO_t pdcp_sdu_list; int pdcp_sent_a_sdu; pdcp_data_req_header_t pdcp_input_header; unsigned char pdcp_input_sdu_buffer[MAX_IP_PACKET_SIZE]; diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c index d203408e5506ca01d51bf32869c042ccecebc545..14d95b15b37ef8de7e730cdcab9cba162c2b1bcd 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c @@ -111,69 +111,59 @@ void debug_pdcp_pc5s_sdu(sidelink_pc5s_element *sl_pc5s_msg, char *title) { } //----------------------------------------------------------------------------- int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { - mem_block_t *sdu_p; + notifiedFIFO_elt_t *sdu_p; int pdcp_nb_sdu_sent = 0; int ret=0; + while ((sdu_p = pollNotifiedFIFO(&pdcp_sdu_list)) != NULL ) { + pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(sdu_p); + AssertFatal(pdcpHead->inst==ctxt_pP->module_id, "To implement correctly multi module id\n"); - while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL && ((pdcp_data_ind_header_t *)(sdu_p->data))->inst == ctxt_pP->module_id) { - ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0; - int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id; + int rb_id = pdcpHead->rb_id; int sizeToWrite= sizeof (pdcp_data_ind_header_t) + - ((pdcp_data_ind_header_t *) sdu_p->data)->data_size; + pdcpHead->data_size; + void * pdcpData=(void*)(pdcpHead+1); if (rb_id == 10) { //hardcoded for PC5-Signaling if( LOG_DEBUGFLAG(DEBUG_PDCP) ) { - debug_pdcp_pc5s_sdu((sidelink_pc5s_element *)&(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), + debug_pdcp_pc5s_sdu((sidelink_pc5s_element *)pdcpData, "pdcp_fifo_flush_sdus sends a aPC5S message"); } - ret = sendto(pdcp_pc5_sockfd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), + ret = sendto(pdcp_pc5_sockfd, pdcpData, sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr,sizeof(prose_pdcp_addr) ); } else if (UE_NAS_USE_TUN) { //ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); if(rb_id == mbms_rab_id){ - ret = write(nas_sock_mbms_fd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); + ret = write(nas_sock_mbms_fd, pdcpData,sizeToWrite ); + LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n", + ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); } else { - #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) - LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); - for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { - printf("%02x ",(unsigned char)sdu_p->data[i]); - } - printf("\n"); - #endif - ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - //LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); + if( LOG_DEBUGFLAG(DEBUG_PDCP) ) + log_dump(PDCP, pdcpData, sizeToWrite, LOG_DUMP_CHAR,"PDCP output to be sent to TUN interface: \n"); + ret = write(nas_sock_fd[ctxt_pP->module_id], pdcpData,sizeToWrite ); + LOG_T(PDCP,"[UE PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n", + ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite); } } else if (ENB_NAS_USE_TUN) { - #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) - LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); - for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { - printf("%02x ",(unsigned char)sdu_p->data[i]); - } - printf("\n"); - #endif - ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), sizeToWrite); - + if( LOG_DEBUGFLAG(DEBUG_PDCP) ) + log_dump(PDCP, pdcpData, sizeToWrite, LOG_DUMP_CHAR,"PDCP output to be sent to TUN interface: \n"); + ret = write(nas_sock_fd[0], pdcpData, sizeToWrite); + LOG_T(PDCP,"[NB PDCP_FIFOS] ret %d TRIED TO PUSH DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[0],sizeToWrite); } else if (PDCP_USE_NETLINK) { - memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeToWrite); + memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) pdcpHead, sizeToWrite); nas_nlh_tx->nlmsg_len = sizeToWrite; ret = sendmsg(nas_sock_fd[0],&nas_msg_tx,0); } // PDCP_USE_NETLINK AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s), nas_sock_fd[0]: %d\n", errno, strerror(errno), nas_sock_fd[0]); - #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) - LOG_I(PDCP, "Printing first bytes of PDCP SDU before removing it from the list: \n"); - for (int i=0; i<30; i++){ - LOG_I(PDCP, "%x", sdu_p->data[i]); - } - #endif - list_remove_head (&pdcp_sdu_list); - free_mem_block (sdu_p, __func__); + if( LOG_DEBUGFLAG(DEBUG_PDCP) ) + log_dump(PDCP, pdcpData, min(sizeToWrite,30) , LOG_DUMP_CHAR, + "Printing first bytes of PDCP SDU before removing it from the list: \n"); + delNotifiedFIFO_elt (sdu_p); pdcp_nb_sdu_sent ++; } @@ -181,12 +171,13 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { } int pdcp_fifo_flush_mbms_sdus(const protocol_ctxt_t *const ctxt_pP) { - mem_block_t *sdu_p; + notifiedFIFO_elt_t *sdu_p; int pdcp_nb_sdu_sent = 0; //int ret=0; - while ((sdu_p = list_get_head (&pdcp_sdu_list)) != NULL && ((pdcp_data_ind_header_t *)(sdu_p->data))->inst == ctxt_pP->module_id) { - ((pdcp_data_ind_header_t *)(sdu_p->data))->inst = 0; + while ((sdu_p = pollNotifiedFIFO(&pdcp_sdu_list)) != NULL ) { + pdcp_data_ind_header_t * pdcpHead=(pdcp_data_ind_header_t *)NotifiedFifoData(sdu_p); + AssertFatal(pdcpHead->inst==ctxt_pP->module_id, "To implement correctly multi module id\n"); //int rb_id = ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id; //int sizeToWrite= sizeof (pdcp_data_ind_header_t) + //((pdcp_data_ind_header_t *) sdu_p->data)->data_size; @@ -212,8 +203,8 @@ int pdcp_fifo_flush_mbms_sdus(const protocol_ctxt_t *const ctxt_pP) { //} // PDCP_USE_NETLINK //AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s)\n", errno, strerror(errno)); - list_remove_head (&pdcp_sdu_list); - free_mem_block (sdu_p, __func__); + //AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s)\n", errno, strerror(errno)); + delNotifiedFIFO_elt (sdu_p); pdcp_nb_sdu_sent ++; } diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 3e1c8f3d4b9d9c7eb5362149daa1cc94aafc3a89..b18831b5468c4ffbc0efda14324af096ca94c0b0 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -118,7 +118,7 @@ int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){ if (is_nr_UL_slot(mac->scc, ul_info->slot_tx) && get_softmodem_params()->do_ra){ nr_ue_prach_scheduler(module_id, ul_info->frame_tx, ul_info->slot_tx); if (mac->generate_nr_prach){ - uint16_t monitoring_slot_period, monitoring_offset; + //uint16_t monitoring_slot_period, monitoring_offset; uint16_t rach_frame = mac->scheduled_response.ul_config->sfn; uint16_t rx_rach_frame = (rach_frame + mac->RA_offset) % MAX_FRAME_NUMBER; // compensate 2 frames offset delay at gNB side uint16_t rach_slot = mac->scheduled_response.ul_config->slot; @@ -244,8 +244,8 @@ int nr_ue_dl_indication(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_ dl_info->rx_ind = NULL; dl_info->dci_ind = NULL; - return 0; } + return 0; } nr_ue_if_module_t *nr_ue_if_module_init(uint32_t module_id){ diff --git a/openair3/GTPV1-U/gtpv1u_gNB.c b/openair3/GTPV1-U/gtpv1u_gNB.c index 1a75214d657a30cd6f1c811ac6fe99109a266631..f13bf13794771324bf32123f84c25c06f5cf370d 100644 --- a/openair3/GTPV1-U/gtpv1u_gNB.c +++ b/openair3/GTPV1-U/gtpv1u_gNB.c @@ -129,14 +129,14 @@ NwGtpv1uRcT gtpv1u_gNB_process_stack_req( case NW_GTPV1U_ULP_API_RECV_TPDU: { uint8_t buffer[4096]; uint32_t buffer_len; - uint16_t msgType = NW_GTP_GPDU; - NwGtpv1uMsgT *pMsg = NULL; + //uint16_t msgType = NW_GTP_GPDU; + //NwGtpv1uMsgT *pMsg = NULL; /* Nw-gptv1u stack has processed a PDU. we can schedule it to PDCP * for transmission. */ teid = pUlpApi->apiInfo.recvMsgInfo.teid; - pMsg = (NwGtpv1uMsgT *) pUlpApi->apiInfo.recvMsgInfo.hMsg; - msgType = pMsg->msgType; + //pMsg = (NwGtpv1uMsgT *) pUlpApi->apiInfo.recvMsgInfo.hMsg; + //msgType = pMsg->msgType; if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg, buffer, &buffer_len)) { diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.c b/openair3/S1AP/s1ap_eNB_nas_procedures.c index b8a4b98fef56385cca421a016ba78363516abc4a..c668e32d1ba912c770bae4b431fd7dfcd163b573 100644 --- a/openair3/S1AP/s1ap_eNB_nas_procedures.c +++ b/openair3/S1AP/s1ap_eNB_nas_procedures.c @@ -1791,8 +1791,8 @@ int s1ap_eNB_generate_E_RAB_Modification_Indication( S1AP_E_RABToBeModifiedItemBearerModInd_t *E_RAB_ToBeModifiedItem_BearerModInd = NULL; S1AP_E_RABToBeModifiedItemBearerModIndIEs_t *E_RAB_ToBeModifiedItem_BearerModInd_IEs = NULL; - S1AP_E_RABNotToBeModifiedItemBearerModInd_t *E_RAB_NotToBeModifiedItem_BearerModInd = NULL; - S1AP_E_RABNotToBeModifiedItemBearerModIndIEs_t *E_RAB_NotToBeModifiedItem_BearerModInd_IEs = NULL; + //S1AP_E_RABNotToBeModifiedItemBearerModInd_t *E_RAB_NotToBeModifiedItem_BearerModInd = NULL; + //S1AP_E_RABNotToBeModifiedItemBearerModIndIEs_t *E_RAB_NotToBeModifiedItem_BearerModInd_IEs = NULL; s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; @@ -1804,10 +1804,10 @@ int s1ap_eNB_generate_E_RAB_Modification_Indication( DevAssert(e_rab_modification_ind != NULL); int num_e_rabs_tobemodified = e_rab_modification_ind->nb_of_e_rabs_tobemodified; - int num_e_rabs_nottobemodified = e_rab_modification_ind->nb_of_e_rabs_nottobemodified; + //int num_e_rabs_nottobemodified = e_rab_modification_ind->nb_of_e_rabs_nottobemodified; - uint32_t CSG_id = 0; - uint32_t pseudo_gtp_teid = 10; + //uint32_t CSG_id = 0; + //uint32_t pseudo_gtp_teid = 10; if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, e_rab_modification_ind->eNB_ue_s1ap_id)) == NULL) { diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c index 45412f9eea9c65b6575632ae84c451b0c1cc7724..ad880e3cbfda167b6031c17b364f7c241cbf0a5f 100644 --- a/targets/ARCH/rfsimulator/simulator.c +++ b/targets/ARCH/rfsimulator/simulator.c @@ -476,14 +476,16 @@ static bool flushInput(rfsimulator_state_t *t, int timeout, int nsamps_for_initi b->trashingPacket=true; } else if ( b->lastReceivedTS < b->th.timestamp) { int nbAnt= b->th.nbAnt; - + if ( b->th.timestamp-b->lastReceivedTS < CirSize ) { for (uint64_t index=b->lastReceivedTS; index < b->th.timestamp; index++ ) { for (int a=0; a < nbAnt; a++) { b->circularBuf[(index*nbAnt+a)%CirSize].r = 0; b->circularBuf[(index*nbAnt+a)%CirSize].i = 0; } } - + } else { + memset(b->circularBuf, 0, sampleToByte(CirSize,1)); + } if (b->lastReceivedTS != 0 && b->th.timestamp-b->lastReceivedTS > 50 ) LOG_W(HW,"UEsock: %d gap of: %ld in reception\n", fd, b->th.timestamp-b->lastReceivedTS ); b->lastReceivedTS=b->th.timestamp; @@ -646,10 +648,11 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo ); else { // no channel modeling sample_t *out=(sample_t *)samplesVoid[a]; - + const int64_t base=t->nextTimestamp*nbAnt+a; for ( int i=0; i < nsamps; i++ ) { - out[i].r+=ptr->circularBuf[((t->nextTimestamp+i)*nbAnt+a)%CirSize].r; - out[i].i+=ptr->circularBuf[((t->nextTimestamp+i)*nbAnt+a)%CirSize].i; + const int idx=(i*nbAnt+base)%CirSize; + out[i].r+=ptr->circularBuf[idx].r; + out[i].i+=ptr->circularBuf[idx].i; } } // end of no channel modeling } // end for a...