From 8e858831e03c2a4d384cabaabfe7c5bd5937d201 Mon Sep 17 00:00:00 2001 From: ismagom Date: Thu, 3 Dec 2015 18:40:35 +0000 Subject: [PATCH] Removed recv_frame_size from uhd_open() and set symbol size at runtime depending on master clock to support X300 --- matlab/tests/pdsch_bler.m | 21 +-- mex/lib/mexutils.c | 2 +- srslte/include/srslte/common/phy_common.h | 2 + srslte/include/srslte/cuhd/cuhd.h | 2 + srslte/lib/common/src/phy_common.c | 149 +++++++++++----------- srslte/lib/cuhd/src/cuhd_handler.hpp | 1 + srslte/lib/cuhd/src/cuhd_imp.cpp | 50 ++++++-- srslte/lib/phch/test/CMakeLists.txt | 2 +- srslte/lib/phch/test/pdsch_test_mex.c | 5 +- 9 files changed, 136 insertions(+), 98 deletions(-) diff --git a/matlab/tests/pdsch_bler.m b/matlab/tests/pdsch_bler.m index 364c7976e..0418c764e 100644 --- a/matlab/tests/pdsch_bler.m +++ b/matlab/tests/pdsch_bler.m @@ -6,28 +6,29 @@ recordedSignal=[]; -Npackets = 3; -SNR_values = linspace(12,16,4); +Npackets = 1; +SNR_values = 25; %% Choose RMC [waveform,rgrid,rmccFgOut] = lteRMCDLTool('R.9',[1;0;0;1]); waveform = sum(waveform,2); if ~isempty(recordedSignal) - rmccFgOut = struct('NCellID',1,'CellRefP',1,'CFI',1,'NDLRB',50,'SamplingRate',3.84e6,'Nfft',256,'DuplexMode','FDD','CyclicPrefix','Normal'); + rmccFgOut = struct('NCellID',1,'CellRefP',1,'CFI',1,'NDLRB',100,'DuplexMode','FDD','CyclicPrefix','Normal'); rmccFgOut.PDSCH.RNTI = 1234; rmccFgOut.PDSCH.PRBSet = repmat(transpose(0:rmccFgOut.NDLRB-1),1,2); rmccFgOut.PDSCH.TxScheme = 'Port0'; rmccFgOut.PDSCH.NLayers = 1; rmccFgOut.PDSCH.NTurboDecIts = 5; rmccFgOut.PDSCH.Modulation = {'64QAM'}; - rmccFgOut.PDSCH.TrBlkSizes = [0 5992*ones(1,4) 0 5992*ones(1,4)]; + trblklen=75376; + rmccFgOut.PDSCH.TrBlkSizes = trblklen*ones(10,1); rmccFgOut.PDSCH.RV = 0; end flen=rmccFgOut.SamplingRate/1000; -Nsf = 9; +Nsf = 10; %% Setup Fading channel model cfg.Seed = 8; % Random channel seed @@ -78,8 +79,8 @@ for snr_idx=1:length(SNR_values) %% Demodulate frame_rx = lteOFDMDemodulate(rmccFgOut, rxWaveform); - for sf_idx=0:Nsf - %sf_idx=9; + %for sf_idx=0:Nsf-1 + sf_idx=9; subframe_rx=frame_rx(:,sf_idx*14+1:(sf_idx+1)*14); rmccFgOut.NSubframe=sf_idx; rmccFgOut.TotSubframes=1; @@ -96,9 +97,9 @@ for snr_idx=1:length(SNR_values) %% Same with srsLTE if (rmccFgOut.PDSCH.TrBlkSizes(sf_idx+1) > 0) - [dec2, data, pdschRx, pdschSymbols2, cws2, cb9, temp] = srslte_pdsch(rmccFgOut, rmccFgOut.PDSCH, ... + [dec2, data, pdschRx, pdschSymbols2, cws2] = srslte_pdsch(rmccFgOut, rmccFgOut.PDSCH, ... rmccFgOut.PDSCH.TrBlkSizes(sf_idx+1), ... - subframe_rx); + subframe_rx, hest, nest); else dec2 = 1; end @@ -106,7 +107,7 @@ for snr_idx=1:length(SNR_values) fprintf('Error in sf=%d\n',sf_idx); end decoded_srslte(snr_idx) = decoded_srslte(snr_idx)+dec2; - end + %end if ~isempty(recordedSignal) recordedSignal = recordedSignal(flen*10+1:end); diff --git a/mex/lib/mexutils.c b/mex/lib/mexutils.c index bdb87d70f..618994c15 100644 --- a/mex/lib/mexutils.c +++ b/mex/lib/mexutils.c @@ -142,7 +142,7 @@ int mexutils_read_uint64(const mxArray *ptr, uint64_t **buffer) { int numelems = mxGetNumberOfElements(ptr); uint64_t *tmp = srslte_vec_malloc(numelems * sizeof(uint64_t)); if (tmp) { - uint64_t *inr=mxGetPr(ptr); + uint64_t *inr=(uint64_t*) mxGetPr(ptr); for (int i=0;iusrp = uhd::usrp::multi_usrp::make(_args + ", recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64"); - handler->usrp->set_clock_source("internal"); + handler->usrp = uhd::usrp::multi_usrp::make(_args);// + ", recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64"); + /* Initialize rx and tx stremers */ std::string otw, cpu; otw = "sc16"; cpu = "fc32"; uhd::stream_args_t stream_args(cpu, otw); handler->rx_stream = handler->usrp->get_rx_stream(stream_args); handler->tx_stream = handler->usrp->get_tx_stream(stream_args); - + handler->rx_nof_samples = handler->rx_stream->get_max_num_samps(); handler->tx_nof_samples = handler->tx_stream->get_max_num_samps(); @@ -240,9 +245,7 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ handler->rx_gain_range = handler->usrp->get_rx_gain_range(); handler->tx_gain_range = handler->usrp->get_tx_gain_range(); - - *h = handler; - + /* Create auxiliary thread and mutexes for AGC */ if (create_thread_gain) { if (pthread_mutex_init(&handler->mutex, NULL)) { return -1; @@ -257,6 +260,26 @@ int cuhd_open_(char *args, void **h, bool create_thread_gain, bool tx_gain_same_ } } + /* Find out if the master clock rate is configurable */ + double cur_clock = handler->usrp->get_master_clock_rate(); + handler->usrp->set_master_clock_rate(cur_clock/2); + if (handler->usrp->get_master_clock_rate() == cur_clock) { + handler->dynamic_rate = false; + /* Master clock rate is not configurable. Check if it is compatible with LTE */ + int cur_clock_i = (int) cur_clock; + if (cur_clock_i % 1920000) { + fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6); + return -1; + } else { + printf("Master clock rate is not configurable. Using default LTE sampling rates.\n"); + srslte_use_standard_symbol_size(true); + } + } else { + handler->dynamic_rate = true; + } + + *h = handler; + return 0; } @@ -278,7 +301,14 @@ int cuhd_close(void *h) void cuhd_set_master_clock_rate(void *h, double rate) { cuhd_handler *handler = static_cast < cuhd_handler * >(h); - handler->usrp->set_master_clock_rate(rate); + if (handler->dynamic_rate) { + handler->usrp->set_master_clock_rate(rate); + } +} + +bool cuhd_is_master_clock_dynamic(void *h) { + cuhd_handler *handler = static_cast < cuhd_handler * >(h); + return handler->dynamic_rate; } double cuhd_set_rx_srate(void *h, double freq) diff --git a/srslte/lib/phch/test/CMakeLists.txt b/srslte/lib/phch/test/CMakeLists.txt index 9d922e3fe..ffec88c08 100644 --- a/srslte/lib/phch/test/CMakeLists.txt +++ b/srslte/lib/phch/test/CMakeLists.txt @@ -195,5 +195,5 @@ BuildMex(MEXNAME prach SOURCES prach_test_mex.c LIBRARIES srslte srslte_mex) IF(UHD_FOUND) ADD_EXECUTABLE(prach_test_usrp prach_test_usrp.c) - TARGET_LINK_LIBRARIES(prach_test_usrp srslte srslte_uhd) + TARGET_LINK_LIBRARIES(prach_test_usrp srslte_uhd srslte) ENDIF(UHD_FOUND) diff --git a/srslte/lib/phch/test/pdsch_test_mex.c b/srslte/lib/phch/test/pdsch_test_mex.c index a73309d63..3b9f29845 100644 --- a/srslte/lib/phch/test/pdsch_test_mex.c +++ b/srslte/lib/phch/test/pdsch_test_mex.c @@ -211,7 +211,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (!data_bytes) { return; } - + srslte_softbuffer_rx_reset(&softbuffer); int r = srslte_pdsch_decode(&pdsch, &cfg, &softbuffer, input_fft, ce, noise_power, data_bytes); free(data_bytes); @@ -234,9 +234,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) if (nlhs >= 5) { mexutils_write_s(pdsch.e, &plhs[4], cfg.nbits.nof_bits, 1); } - if (nlhs >= 6) { - mexutils_write_int(indices, &plhs[5], cfg.nbits.nof_re, 1); - } srslte_chest_dl_free(&chest); srslte_pdsch_free(&pdsch);