diff --git a/CMakeLists.txt b/CMakeLists.txt index c77a24fc6..fd5dc5631 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,15 @@ if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-write-strings -Wno-format-extra-args -Winline -Wno-unused-result -Wno-format -std=c99 -D_GNU_SOURCE -g") if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0") + find_package(SSE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0") + if(HAVE_AVX) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mfpmath=sse -mavx -DLV_HAVE_AVX -DLV_HAVE_SSE") + elseif(HAVE_SSE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mfpmath=sse -msse4.1 -DLV_HAVE_SSE") + endif(HAVE_AVX) else(${CMAKE_BUILD_TYPE} STREQUAL "Debug") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") find_package(SSE) if(HAVE_AVX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -mfpmath=sse -mavx -DLV_HAVE_AVX -DLV_HAVE_SSE") diff --git a/matlab/tests/prach_detect_test.m b/matlab/tests/prach_detect_test.m index 7a2fc1802..51bda6c21 100644 --- a/matlab/tests/prach_detect_test.m +++ b/matlab/tests/prach_detect_test.m @@ -1,13 +1,13 @@ %% PRACH Detection Conformance Test %clear -d=50;%linspace(4,14,6); +d=80;%linspace(4,14,6); pDetection2 = zeros(2,length(d)); for dd=1:length(d) detect_factor=d(dd); numSubframes = 1; % Number of subframes frames to simulate at each SNR -SNRdB = 10;%linspace(-14,10,8); % SNR points to simulate +SNRdB = 50;%linspace(-14,10,8); % SNR points to simulate foffset = 0.0; % Frequency offset in Hertz delay=0; add_fading=false; @@ -26,7 +26,7 @@ ue.NTxAnts = 1; % Number of transmission antennas prach.Format = 0; % PRACH format: TS36.104, Table 8.4.2.1-1 prach.HighSpeed = 0; % Normal mode: TS36.104, Table 8.4.2.1-1 -prach.FreqOffset = 4; % Default frequency location +prach.FreqOffset = 2; % Default frequency location info = ltePRACHInfo(ue, prach); % PRACH information %% Propagation Channel Configuration @@ -67,9 +67,10 @@ for nSNR = 1:length(SNRdB) % Loop for each subframe for nsf = 1:numSubframes - prach.SeqIdx = 0;%randi(838,1,1)-1; % Logical sequence index: TS36.141, Table A.6-1 + prach.SeqIdx = 41;%randi(838,1,1)-1; % Logical sequence index: TS36.141, Table A.6-1 prach.CyclicShiftIdx = 11;%randi(16,1,1)-1; % Cyclic shift index: TS36.141, Table A.6-1 prach.PreambleIdx = 1;%randi(64,1,1)-1; % Preamble index: TS36.141, Table A.6-1 + prach.TimingOffset = 0; info = ltePRACHInfo(ue, prach); % PRACH information % PRACH transmission @@ -99,7 +100,7 @@ for nSNR = 1:length(SNRdB) rxwave = rxwave((fadinginfo.ChannelFilterDelay + 1):end, :); end - rxwave=x; + rxwave=lteFrequencyCorrect(ue, x, -20); % rxwave=[zeros(delay,1); txwave(1:end-delay)]; % Apply frequency offset diff --git a/srslte/lib/ch_estimation/chest_ul.c b/srslte/lib/ch_estimation/chest_ul.c index a75d2a7a3..75d816702 100644 --- a/srslte/lib/ch_estimation/chest_ul.c +++ b/srslte/lib/ch_estimation/chest_ul.c @@ -269,8 +269,12 @@ int srslte_chest_ul_estimate_pucch(srslte_chest_ul_t *q, cf_t *input, cf_t *ce, return SRSLTE_ERROR; } - int n_rs = srslte_refsignal_dmrs_N_rs(format, q->cell.cp); - int nrefs_sf = SRSLTE_NRE*n_rs*2; + int n_rs = srslte_refsignal_dmrs_N_rs(format, q->cell.cp); + if (!n_rs) { + fprintf(stderr, "Error computing N_rs\n"); + return SRSLTE_ERROR; + } + int nrefs_sf = SRSLTE_NRE*n_rs*2; /* Get references from the input signal */ srslte_refsignal_dmrs_pucch_get(&q->dmrs_signal, format, n_pucch, input, q->pilot_recv_signal); diff --git a/srslte/lib/ch_estimation/refsignal_ul.c b/srslte/lib/ch_estimation/refsignal_ul.c index f85b33c19..f203d6250 100644 --- a/srslte/lib/ch_estimation/refsignal_ul.c +++ b/srslte/lib/ch_estimation/refsignal_ul.c @@ -471,6 +471,9 @@ uint32_t srslte_refsignal_dmrs_N_rs(srslte_pucch_format_t format, srslte_cp_t cp case SRSLTE_PUCCH_FORMAT_2A: case SRSLTE_PUCCH_FORMAT_2B: return 2; + default: + fprintf(stderr, "Unsupported format %d\n", format); + return 0; } return 0; } @@ -575,6 +578,9 @@ int srslte_refsignal_dmrs_pucch_gen(srslte_refsignal_ul_t *q, srslte_pucch_forma case SRSLTE_PUCCH_FORMAT_2B: w=w_arg_pucch_format2_cpnorm; break; + default: + fprintf(stderr, "Unsupported format %d\n", format); + return SRSLTE_ERROR; } cf_t z_m = 1.0; if (m == 1) { diff --git a/srslte/lib/enb/enb_ul.c b/srslte/lib/enb/enb_ul.c index 7732b30ed..146d36830 100644 --- a/srslte/lib/enb/enb_ul.c +++ b/srslte/lib/enb/enb_ul.c @@ -190,7 +190,6 @@ int srslte_enb_ul_cfg_ue(srslte_enb_ul_t *q, uint32_t idx, q->uci_cfg_en[idx] = false; } if (pucch_sched) { - printf("saving sched for idx=%d, N_pucch_1=%d\n", idx, pucch_sched->N_pucch_1); memcpy(&q->pucch_sched[idx], pucch_sched, sizeof(srslte_pucch_sched_t)); } if (srs_cfg) { @@ -216,39 +215,59 @@ void srslte_enb_ul_fft(srslte_enb_ul_t *q, cf_t *signal_buffer) srslte_ofdm_rx_sf(&q->fft, signal_buffer, q->sf_symbols); } +int get_pucch(srslte_enb_ul_t *q, uint32_t rnti_idx, + uint32_t pdcch_n_cce, uint32_t sf_rx, + srslte_uci_data_t *uci_data, uint8_t bits[SRSLTE_PUCCH_MAX_BITS]) +{ + float noise_power = srslte_chest_ul_get_noise_estimate(&q->chest); + + srslte_pucch_format_t format = srslte_pucch_get_format(uci_data, q->cell.cp); + + uint32_t n_pucch = srslte_pucch_get_npucch(pdcch_n_cce, format, uci_data->scheduling_request, &q->pucch_sched[rnti_idx]); + + if (srslte_chest_ul_estimate_pucch(&q->chest, q->sf_symbols, q->ce, format, n_pucch, sf_rx)) { + fprintf(stderr,"Error estimating PUCCH DMRS\n"); + return SRSLTE_ERROR; + } + + + int ret_val = srslte_pucch_decode(&q->pucch, format, n_pucch, sf_rx, q->sf_symbols, q->ce, noise_power, bits); + if (ret_val < 0) { + fprintf(stderr,"Error decoding PUCCH\n"); + return SRSLTE_ERROR; + } + return ret_val; +} + int srslte_enb_ul_get_pucch(srslte_enb_ul_t *q, uint32_t rnti_idx, uint32_t pdcch_n_cce, uint32_t sf_rx, srslte_uci_data_t *uci_data) { - + uint8_t bits[SRSLTE_PUCCH_MAX_BITS]; + if (rnti_idx < q->nof_rnti) { - - srslte_pucch_format_t format = srslte_pucch_get_format(uci_data, q->cell.cp); - - uint32_t n_pucch = srslte_pucch_get_npucch(pdcch_n_cce, format, uci_data->scheduling_request, &q->pucch_sched[rnti_idx]); - - if (srslte_chest_ul_estimate_pucch(&q->chest, q->sf_symbols, q->ce, format, n_pucch, sf_rx)) { - fprintf(stderr,"Error estimating PUCCH DMRS\n"); - return SRSLTE_ERROR; - } - - float noise_power = srslte_chest_ul_get_noise_estimate(&q->chest); - - uint8_t bits[SRSLTE_PUCCH_MAX_BITS]; - int ret_val = srslte_pucch_decode(&q->pucch, format, n_pucch, sf_rx, q->sf_symbols, q->ce, noise_power, bits); - if (ret_val < 0) { - fprintf(stderr,"Error decoding PUCCH\n"); - return SRSLTE_ERROR; + + int ret_val = get_pucch(q, rnti_idx, pdcch_n_cce, sf_rx, uci_data, bits); + + // If we are looking for SR and ACK at the same time and ret=0, means there is no SR. + // try again to decode ACK only + if (uci_data->scheduling_request && uci_data->uci_ack_len && ret_val != 1) { + uci_data->scheduling_request = false; + ret_val = get_pucch(q, rnti_idx, pdcch_n_cce, sf_rx, uci_data, bits); } - + // update schedulign request if (uci_data->scheduling_request) { - uci_data->scheduling_request = ret_val; + uci_data->scheduling_request = (ret_val==1); } // Save ACK bits if (uci_data->uci_ack_len > 0) { - uci_data->uci_ack = bits[0]; + if (ret_val > 0) { + uci_data->uci_ack = bits[0]; + } else { + uci_data->uci_ack = 0; + } } return SRSLTE_SUCCESS; } else { diff --git a/srslte/lib/phch/dci.c b/srslte/lib/phch/dci.c index fbe7d6b45..66a1b218f 100644 --- a/srslte/lib/phch/dci.c +++ b/srslte/lib/phch/dci.c @@ -65,7 +65,7 @@ int srslte_dci_msg_to_dl_grant(srslte_dci_msg_t *msg, uint16_t msg_rnti, srslte_dci_format_t tmp = msg->format; ret = srslte_dci_msg_unpack_pdsch(msg, dl_dci, nof_prb, nof_ports, crc_is_crnti); if (ret) { - fprintf(stderr, "Can't unpack DCI message %s (%d)\n", srslte_dci_format_string(tmp), tmp); + //fprintf(stderr, "Can't unpack DCI message %s (%d)\n", srslte_dci_format_string(tmp), tmp); return ret; } @@ -754,13 +754,13 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 while(inof_bits-1 && y[i] == 0) { i++; } if (i == msg->nof_bits-1) { - printf("Received a Format1A RA PDCCH order. Not implemented!\n"); + //printf("Received a Format1A RA PDCCH order. Not implemented!\n"); return SRSLTE_ERROR; } } diff --git a/srslte/lib/phch/prach.c b/srslte/lib/phch/prach.c index 4406297c2..1cfedd3c6 100644 --- a/srslte/lib/phch/prach.c +++ b/srslte/lib/phch/prach.c @@ -600,6 +600,7 @@ int srslte_prach_detect_offset(srslte_prach_t *p, for (int j=0;jpeak_values[j] > p->detect_factor*corr_ave) { + //printf("saving prach correlation\n"); //memcpy(save_corr, p->corr, p->N_zc*sizeof(float)); if (indices) { indices[*n_indices] = (i*n_wins)+j; diff --git a/srslte/lib/phch/pucch.c b/srslte/lib/phch/pucch.c index 86e8bbcda..cce37fc38 100644 --- a/srslte/lib/phch/pucch.c +++ b/srslte/lib/phch/pucch.c @@ -99,8 +99,10 @@ uint32_t get_N_sf(srslte_pucch_format_t format, uint32_t slot_idx, bool shortene } case SRSLTE_PUCCH_FORMAT_2: case SRSLTE_PUCCH_FORMAT_2A: - case SRSLTE_PUCCH_FORMAT_2B: + case SRSLTE_PUCCH_FORMAT_2B: return 5; + default: + return 0; } return 0; } @@ -128,6 +130,8 @@ uint32_t srslte_pucch_nbits_format(srslte_pucch_format_t format) { return 21; case SRSLTE_PUCCH_FORMAT_2B: return 22; + default: + return 0; } return 0; } @@ -156,6 +160,8 @@ uint32_t get_pucch_symbol(uint32_t m, srslte_pucch_format_t format, srslte_cp_t } } break; + default: + return 0; } return 0; } @@ -216,6 +222,7 @@ uint32_t srslte_pucch_get_npucch(uint32_t n_cce, srslte_pucch_format_t format, b } else { n_pucch = pucch_sched->n_pucch_2; } + return n_pucch; } uint32_t srslte_pucch_n_prb(srslte_pucch_cfg_t *cfg, srslte_pucch_format_t format, uint32_t n_pucch, @@ -248,7 +255,10 @@ uint32_t srslte_pucch_m(srslte_pucch_cfg_t *cfg, srslte_pucch_format_t format, u case SRSLTE_PUCCH_FORMAT_2: case SRSLTE_PUCCH_FORMAT_2A: case SRSLTE_PUCCH_FORMAT_2B: - m = n_pucch/SRSLTE_NRE; + m = n_pucch/SRSLTE_NRE; + break; + default: + m = 0; break; } return m; @@ -729,6 +739,8 @@ int srslte_pucch_decode(srslte_pucch_t* q, srslte_pucch_format_t format, if (corr > corr_max && corr >= q->threshold_format1a) { corr_max = corr; b_max = b; + } + if (corr_max > q->threshold_format1a) { ret = 1; } DEBUG("format1a b=%d, corr=%f, nof_re=%d, th=%f\n", b, corr, nof_re, q->threshold_format1a); @@ -740,7 +752,6 @@ int srslte_pucch_decode(srslte_pucch_t* q, srslte_pucch_format_t format, ret = SRSLTE_ERROR; break; } - ret = SRSLTE_SUCCESS; } return ret; diff --git a/srslte/lib/ue/ue_ul.c b/srslte/lib/ue/ue_ul.c index d4a97aaa9..40a0e3adc 100644 --- a/srslte/lib/ue/ue_ul.c +++ b/srslte/lib/ue/ue_ul.c @@ -265,6 +265,7 @@ int srslte_ue_ul_pucch_encode(srslte_ue_ul_t *q, srslte_uci_data_t uci_data, // Choose n_pucch uint32_t n_pucch = srslte_pucch_get_npucch(pdcch_n_cce, format, uci_data.scheduling_request, &q->pucch_sched); + if (srslte_pucch_encode(&q->pucch, format, n_pucch, sf_idx, pucch_bits, q->sf_symbols)) { fprintf(stderr, "Error encoding TB\n"); return ret;