diff --git a/lte/phy/lib/phch/src/harq.c b/lte/phy/lib/phch/src/harq.c index db86f79cd..9fee0b20b 100644 --- a/lte/phy/lib/phch/src/harq.c +++ b/lte/phy/lib/phch/src/harq.c @@ -131,6 +131,7 @@ int harq_init(harq_t *q, lte_cell_t cell) { perror("malloc"); return LIBLTE_ERROR; } + bzero(q->pdsch_w_buff_c[i], sizeof(uint8_t) * q->w_buff_size); } ret = LIBLTE_SUCCESS; } diff --git a/lte/phy/lib/phch/src/uci.c b/lte/phy/lib/phch/src/uci.c index 750cd9543..f2cbe056c 100644 --- a/lte/phy/lib/phch/src/uci.c +++ b/lte/phy/lib/phch/src/uci.c @@ -203,7 +203,7 @@ static int uci_ulsch_interleave_ack(uint8_t ack_coded_bits[6], uint32_t ack_q_bi const uint32_t ack_column_set_norm[4] = {2, 3, 8, 9}; const uint32_t ack_column_set_ext[4] = {1, 2, 6, 7}; - if (H_prime_total/N_pusch_symbs > 1+ack_q_bit_idx/4) { + if (H_prime_total/N_pusch_symbs >= 1+ack_q_bit_idx/4) { uint32_t row = H_prime_total/N_pusch_symbs-1-ack_q_bit_idx/4; uint32_t colidx = (3*ack_q_bit_idx)%4; uint32_t col = CP_ISNORM(cp)?ack_column_set_norm[colidx]:ack_column_set_ext[colidx]; @@ -227,7 +227,7 @@ static int uci_ulsch_interleave_ri(uint8_t ri_coded_bits[6], uint32_t ri_q_bit_i static uint32_t ri_column_set_norm[4] = {1, 4, 7, 10}; static uint32_t ri_column_set_ext[4] = {0, 3, 5, 8}; - if (H_prime_total/N_pusch_symbs > 1+ri_q_bit_idx/4) { + if (H_prime_total/N_pusch_symbs >= 1+ri_q_bit_idx/4) { uint32_t row = H_prime_total/N_pusch_symbs-1-ri_q_bit_idx/4; uint32_t colidx = (3*ri_q_bit_idx)%4; uint32_t col = CP_ISNORM(cp)?ri_column_set_norm[colidx]:ri_column_set_ext[colidx]; diff --git a/lte/phy/lib/phch/test/pusch_test.c b/lte/phy/lib/phch/test/pusch_test.c index 87231ab6c..af3cb35d7 100644 --- a/lte/phy/lib/phch/test/pusch_test.c +++ b/lte/phy/lib/phch/test/pusch_test.c @@ -125,7 +125,6 @@ int main(int argc, char **argv) { ra_mcs_t mcs; ra_prb_t prb_alloc; harq_t harq_process; - uint32_t rv = 0; parse_args(argc,argv); @@ -186,63 +185,71 @@ int main(int argc, char **argv) { printf("INPUT: "); vec_fprint_b(stdout, data, mcs.tbs); - for (rv=0;rv<=rv_idx;rv++) { - printf("Encoding rv_idx=%d\n",rv); - - uint8_t tmp[20]; - for (i=0;i<20;i++) { - tmp[i] = 1; - } - uci_data_t uci_data; - bzero(&uci_data, sizeof(uci_data_t)); - uci_data.beta_cqi = 2.0; - uci_data.beta_ri = 2.0; - uci_data.beta_ack = 2.0; - uci_data.uci_cqi = tmp; - uci_data.uci_cqi_len = 0; - uci_data.uci_ri_len = 1; - uci_data.uci_ri = 1; - uci_data.uci_ack_len = 1; - uci_data.uci_ack = 1; - - uint32_t nof_symbols = 12*harq_process.prb_alloc.slot[0].nof_prb*RE_X_RB; - uint32_t nof_bits_e = nof_symbols * lte_mod_bits_x_symbol(harq_process.mcs.mod); + printf("Encoding rv_idx=%d\n",rv_idx); + + uint8_t tmp[20]; + for (i=0;i<20;i++) { + tmp[i] = 1; + } + uci_data_t uci_data; + bzero(&uci_data, sizeof(uci_data_t)); + uci_data.beta_cqi = 2.0; + uci_data.beta_ri = 2.0; + uci_data.beta_ack = 2.0; + + uci_data.uci_cqi_len = 0; + uci_data.uci_ri_len = 0; + uci_data.uci_ack_len = 0; + + uci_data.uci_cqi = tmp; + uci_data.uci_ri = 1; + uci_data.uci_ack = 1; + + uint32_t nof_symbols = 12*harq_process.prb_alloc.slot[0].nof_prb*RE_X_RB; + uint32_t nof_bits_e = nof_symbols * lte_mod_bits_x_symbol(harq_process.mcs.mod); - bzero(pusch.pusch_q, nof_bits_e*sizeof(uint8_t)); - + bzero(pusch.pusch_q, nof_bits_e*sizeof(uint8_t)); + - if (ulsch_uci_encode(&pusch.dl_sch, data, uci_data, pusch.pusch_g, &harq_process, rv, pusch.pusch_q)) + if (ulsch_uci_encode(&pusch.dl_sch, data, uci_data, pusch.pusch_g, &harq_process, 0, pusch.pusch_q)) + { + fprintf(stderr, "Error encoding TB\n"); + exit(-1); + } + + if (rv_idx > 0) { + if (ulsch_uci_encode(&pusch.dl_sch, data, uci_data, pusch.pusch_g, &harq_process, rv_idx, pusch.pusch_q)) { fprintf(stderr, "Error encoding TB\n"); exit(-1); } - vec_fprint_b(stdout, pusch.pusch_q, nof_bits_e); + } + vec_fprint_b(stdout, pusch.pusch_q, nof_bits_e); - /* combine outputs */ - for (i=0;i 0) { - slot_symbols[0][j] += slot_symbols[i][j]; - } - ce[i][j] = 1; + /* combine outputs */ + for (i=0;i 0) { + slot_symbols[0][j] += slot_symbols[i][j]; } + ce[i][j] = 1; } - - gettimeofday(&t[1], NULL); - //int r = pusch_decode(&pusch, slot_symbols[0], ce, 0, data, subframe, &harq_process, rv); - int r = 0; - gettimeofday(&t[2], NULL); - get_time_interval(t); - if (r) { - printf("Error decoding\n"); - ret = -1; - goto quit; - } else { - printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec); - } - } + + gettimeofday(&t[1], NULL); + //int r = pusch_decode(&pusch, slot_symbols[0], ce, 0, data, subframe, &harq_process, rv); + int r = 0; + gettimeofday(&t[2], NULL); + get_time_interval(t); + if (r) { + printf("Error decoding\n"); + ret = -1; + goto quit; + } else { + printf("DECODED OK in %d:%d (%.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec, (float) mcs.tbs/t[0].tv_usec); + } + ret = 0; quit: pusch_free(&pusch); diff --git a/lte/phy/lib/phch/test/ulsch_encode_test_mex.c b/lte/phy/lib/phch/test/ulsch_encode_test_mex.c index 8507f672d..53b402bc9 100644 --- a/lte/phy/lib/phch/test/ulsch_encode_test_mex.c +++ b/lte/phy/lib/phch/test/ulsch_encode_test_mex.c @@ -144,7 +144,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) free(prbset); - printf("Q_m: %d, NPRB: %d, RV: %d\n", lte_mod_bits_x_symbol(mcs.mod), prb_alloc.slot[0].nof_prb, rv); + mexPrintf("Q_m: %d, NPRB: %d, RV: %d\n", lte_mod_bits_x_symbol(mcs.mod), prb_alloc.slot[0].nof_prb, rv); if (harq_setup(&harq_process, mcs, &prb_alloc)) { mexErrMsgTxt("Error configuring HARQ process\n"); @@ -163,24 +163,30 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) return; } - if (ulsch_uci_encode(&ulsch, trblkin, uci_data, g_bits, &harq_process, rv, q_bits)) + if (ulsch_uci_encode(&ulsch, trblkin, uci_data, g_bits, &harq_process, 0, q_bits)) { mexErrMsgTxt("Error encoding TB\n"); return; + } + if (rv > 0) { + if (ulsch_uci_encode(&ulsch, trblkin, uci_data, g_bits, &harq_process, rv, q_bits)) + { + mexErrMsgTxt("Error encoding TB\n"); + return; + } } if (nlhs >= 1) { mexutils_write_uint8(q_bits, &plhs[0], nof_q_bits, 1); } - sch_free(&ulsch); + sch_free(&ulsch); + harq_free(&harq_process); free(trblkin); - free(g_bits); - - if (uci_data.uci_cqi_len > 0) { - free(uci_data.uci_cqi); - } + free(g_bits); + free(q_bits); + free(uci_data.uci_cqi); return; } diff --git a/matlab/tests/ulsch_test.m b/matlab/tests/ulsch_test.m index e1aa28c83..d59cbfd55 100644 --- a/matlab/tests/ulsch_test.m +++ b/matlab/tests/ulsch_test.m @@ -1,26 +1,58 @@ +clear ueConfig=struct('NCellID',1,'CyclicPrefixUL','Normal','NTxAnts',1); -puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',(0:1)','Modulation','16QAM','RV',0,'Shortened',0); +puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',0,'Modulation','16QAM','RV',0,'Shortened',0); addpath('../../debug/lte/phy/lib/phch/test') -TBs=200; -error=zeros(size(TBs)); -for i=1:length(error) - trblkin=randi(2,TBs(i),1)-1; - %trblkin=ones(TBs(i),1); - %trblkin=[]; +TBs=0:13:222; +cqilen=[0, 8, 17]; +mods={'QPSK','16QAM','64QAM'}; +rvs=[0, 3]; +betas=0:3:11; + +for i=1:length(TBs) + for m=1:length(mods) + for r=1:length(rvs) + for bcqi=1:length(betas) + for bri=1:length(betas) + for back=1:length(betas) + for c=1:length(cqilen) + + trblkin=randi(2,TBs(i),1)-1; - puschConfig.BetaCQI = 2.0; - puschConfig.BetaRI = 2.0; - puschConfig.BetaACK = 2.0; + puschConfig.Modulation = mods{m}; + puschConfig.RV = rvs(r); + puschConfig.BetaCQI = 2+betas(bcqi); + puschConfig.BetaRI = 2+betas(bri); + puschConfig.BetaACK = 2+betas(back); - [mat, info]=lteULSCH(ueConfig,puschConfig,trblkin,[ones(1,20)],[1],[1],[]); - mat(mat==-2)=2; - mat(mat==-1)=3; - [lib]=liblte_ulsch_encode(ueConfig,puschConfig,trblkin,[ones(1,20)],[1],[1]); - error(i)=sum(abs(double(mat)-double(lib))); - if (length(TBs) == 1) - disp(error(i)) + if (betas(bri)>0) + ri_bit=randi(2,1,1)-1; + else + ri_bit=[]; + end + if (betas(back)>0) + ack_bit=randi(2,1,1)-1; + else + ack_bit=[]; + end + + if (cqilen(c)>0 || TBs(i)>0) + [mat, info]=lteULSCH(ueConfig,puschConfig,trblkin,ones(1,cqilen(c)),ri_bit,ack_bit,[]); + mat(mat==-2)=2; + mat(mat==-1)=3; + [lib]=liblte_ulsch_encode(ueConfig,puschConfig,trblkin,ones(1,cqilen(c)),ri_bit,ack_bit); + err=sum(abs(double(mat)-double(lib))); + if (err > 0) + disp(err) + error('Error!'); + end + end + end + end + end + end + end end end @@ -29,7 +61,4 @@ if (length(TBs) == 1) n=1:length(mat); %plot(abs(double(mat)-double(lib))) plot(n,lib(n),n,mat(n)) -else - plot(error) - disp(sum(error)) end