diff --git a/lte/phy/include/liblte/phy/phch/cqi.h b/lte/phy/include/liblte/phy/phch/cqi.h index fa6d86ca0..2a72c7b74 100644 --- a/lte/phy/include/liblte/phy/phch/cqi.h +++ b/lte/phy/include/liblte/phy/phch/cqi.h @@ -64,7 +64,7 @@ LIBLTE_API void cqi_hl_subband_pack(cqi_hl_subband_t *msg, uint8_t *buff, uint32_t buff_len); -LIBLTE_API void cqi_ue_subband_pack(cqi_hl_subband_t *msg, +LIBLTE_API void cqi_ue_subband_pack(cqi_ue_subband_t *msg, uint32_t L, uint8_t *buff, uint32_t buff_len); diff --git a/lte/phy/include/liblte/phy/phch/pusch.h b/lte/phy/include/liblte/phy/phch/pusch.h index 69ee53c90..ccbb1b386 100644 --- a/lte/phy/include/liblte/phy/phch/pusch.h +++ b/lte/phy/include/liblte/phy/phch/pusch.h @@ -58,10 +58,11 @@ typedef struct LIBLTE_API { cf_t *pusch_symbols[MAX_PORTS]; cf_t *pusch_x[MAX_PORTS]; cf_t *pusch_d; - void *pusch_e; - uint8_t *pusch_q_ri; - uint8_t *pusch_q_ack; + void *pusch_q; + uint8_t *pusch_g_ri; + uint8_t *pusch_g_ack; + void *pusch_g; /* tx & rx objects */ modem_table_t mod[4]; diff --git a/lte/phy/include/liblte/phy/phch/sch.h b/lte/phy/include/liblte/phy/phch/sch.h index 6254fb1c9..519e3eaea 100644 --- a/lte/phy/include/liblte/phy/phch/sch.h +++ b/lte/phy/include/liblte/phy/phch/sch.h @@ -96,18 +96,20 @@ LIBLTE_API int dlsch_decode(sch_t *q, LIBLTE_API int ulsch_encode(sch_t *q, uint8_t *data, - uint8_t *q_bits, + uint8_t *g_bits, harq_t *harq_process, - uint32_t rv_idx); + uint32_t rv_idx, + uint8_t *q_bits); LIBLTE_API int ulsch_uci_encode(sch_t *q, uint8_t *data, uci_data_t uci_data, - uint8_t *q_bits, - uint8_t *q_bits_ack, - uint8_t *q_bits_ri, + uint8_t *g_bits, + uint8_t *g_bits_ack, + uint8_t *g_bits_ri, harq_t *harq_process, - uint32_t rv_idx); + uint32_t rv_idx, + uint8_t *q_bits); LIBLTE_API int ulsch_decode(sch_t *q, float *e_bits, diff --git a/lte/phy/lib/phch/src/pusch.c b/lte/phy/lib/phch/src/pusch.c index a8b5283a4..2d94f3949 100644 --- a/lte/phy/lib/phch/src/pusch.c +++ b/lte/phy/lib/phch/src/pusch.c @@ -120,19 +120,25 @@ int pusch_init(pusch_t *q, lte_cell_t cell) { q->rnti_is_set = false; - // Allocate floats for reception (LLRs) - q->pusch_e = malloc(sizeof(float) * q->max_symbols * lte_mod_bits_x_symbol(LTE_QAM64)); - if (!q->pusch_e) { + // Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission + q->pusch_q = malloc(sizeof(float) * q->max_symbols * lte_mod_bits_x_symbol(LTE_QAM64)); + if (!q->pusch_q) { + goto clean; + } + + // Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission + q->pusch_g = malloc(sizeof(float) * q->max_symbols * lte_mod_bits_x_symbol(LTE_QAM64)); + if (!q->pusch_g) { goto clean; } // Allocate buffers for q bits for coded RI and ACK bits - q->pusch_q_ack = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); - if (!q->pusch_q_ack) { + q->pusch_g_ack = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); + if (!q->pusch_g_ack) { goto clean; } - q->pusch_q_ri = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); - if (!q->pusch_q_ri) { + q->pusch_g_ri = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); + if (!q->pusch_g_ri) { goto clean; } @@ -168,17 +174,17 @@ int pusch_init(pusch_t *q, lte_cell_t cell) { void pusch_free(pusch_t *q) { int i; - if (q->pusch_e) { - free(q->pusch_e); + if (q->pusch_q) { + free(q->pusch_q); } if (q->pusch_d) { free(q->pusch_d); } - if (q->pusch_q_ack) { - free(q->pusch_q_ack); + if (q->pusch_g_ack) { + free(q->pusch_g_ack); } - if (q->pusch_q_ri) { - free(q->pusch_q_ri); + if (q->pusch_g_ri) { + free(q->pusch_g_ri); } for (i = 0; i < q->cell.nof_ports; i++) { if (q->ce[i]) { @@ -276,12 +282,12 @@ int pusch_decode(pusch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], float noise_ */ demod_soft_sigma_set(&q->demod, sqrt(0.5)); demod_soft_table_set(&q->demod, &q->mod[harq_process->mcs.mod]); - demod_soft_demodulate(&q->demod, q->pusch_d, q->pusch_e, nof_symbols); + demod_soft_demodulate(&q->demod, q->pusch_d, q->pusch_q, nof_symbols); /* descramble */ - scrambling_f_offset(&q->seq_pusch[subframe], q->pusch_e, 0, nof_bits_e); + scrambling_f_offset(&q->seq_pusch[subframe], q->pusch_q, 0, nof_bits_e); - return ulsch_decode(&q->dl_sch, q->pusch_e, data, nof_bits, nof_bits_e, harq_process, rv_idx); + return ulsch_decode(&q->dl_sch, q->pusch_q, data, nof_bits, nof_bits_e, harq_process, rv_idx); } else { fprintf(stderr, "Must call pusch_set_rnti() before calling pusch_decode()\n"); return LIBLTE_ERROR; @@ -292,7 +298,7 @@ int pusch_decode(pusch_t *q, cf_t *sf_symbols, cf_t *ce[MAX_PORTS], float noise_ } } -int pusch_encode(pusch_t *q, uint8_t *data, cf_t *sf_symbols[MAX_PORTS], uint32_t subframe, +int pusch_qncode(pusch_t *q, uint8_t *data, cf_t *sf_symbols[MAX_PORTS], uint32_t subframe, harq_t *harq_process, uint32_t rv_idx) { uci_data_t uci_data; @@ -354,16 +360,16 @@ int pusch_uci_encode(pusch_t *q, uint8_t *data, uci_data_t uci_data, } memset(&x[q->cell.nof_ports], 0, sizeof(cf_t*) * (MAX_LAYERS - q->cell.nof_ports)); - if (ulsch_uci_encode(&q->dl_sch, data, uci_data, q->pusch_e, - q->pusch_q_ack, q->pusch_q_ri, harq_process, rv_idx)) + if (ulsch_uci_encode(&q->dl_sch, data, uci_data, q->pusch_g, + q->pusch_g_ack, q->pusch_g_ri, harq_process, rv_idx, q->pusch_q)) { fprintf(stderr, "Error encoding TB\n"); return LIBLTE_ERROR; } - scrambling_b_offset_pusch(&q->seq_pusch[subframe], (uint8_t*) q->pusch_e, 0, nof_bits_e); + scrambling_b_offset_pusch(&q->seq_pusch[subframe], (uint8_t*) q->pusch_q, 0, nof_bits_e); - mod_modulate(&q->mod[harq_process->mcs.mod], (uint8_t*) q->pusch_e, q->pusch_d, nof_bits_e); + mod_modulate(&q->mod[harq_process->mcs.mod], (uint8_t*) q->pusch_q, q->pusch_d, nof_bits_e); /* mapping to resource elements */ diff --git a/lte/phy/lib/phch/src/sch.c b/lte/phy/lib/phch/src/sch.c index 6ddbaa057..1788655c4 100644 --- a/lte/phy/lib/phch/src/sch.c +++ b/lte/phy/lib/phch/src/sch.c @@ -410,7 +410,7 @@ uint8_t ulsch_y_mat[10000]; void ulsch_interleave(uint8_t *q_bits, uint32_t nb_q, uint8_t q_bits_ack[6], uint32_t Q_prime_ack, uint8_t q_bits_ri[6], uint32_t Q_prime_ri, - uint32_t Q_m) + uint32_t Q_m, uint8_t *g_bits) { uint32_t C_mux; uint32_t H_prime; @@ -498,26 +498,25 @@ void ulsch_interleave(uint8_t *q_bits, uint32_t nb_q, for(i=0; imcs.tbs == 0) { beta /= uci_data.beta_cqi; } - ret = uci_encode_ri_ack(uci_data.uci_ack, uci_data.uci_cqi_len, beta, harq_process, q_bits_ack); + ret = uci_encode_ri_ack(uci_data.uci_ack, uci_data.uci_cqi_len, beta, harq_process, g_bits_ack); if (ret < 0) { return ret; } @@ -549,7 +548,7 @@ int ulsch_uci_encode(sch_t *q, uint8_t *data, uci_data_t uci_data, uint8_t *q_bi if (harq_process->mcs.tbs == 0) { beta /= uci_data.beta_cqi; } - ret = uci_encode_ri_ack(uci_data.uci_ri, uci_data.uci_cqi_len, beta, harq_process, q_bits_ri); + ret = uci_encode_ri_ack(uci_data.uci_ri, uci_data.uci_cqi_len, beta, harq_process, g_bits_ri); if (ret < 0) { return ret; } @@ -559,7 +558,7 @@ int ulsch_uci_encode(sch_t *q, uint8_t *data, uci_data_t uci_data, uint8_t *q_bi // Encode CQI if (uci_data.uci_cqi_len > 0) { ret = uci_encode_cqi(&q->uci_cqi, uci_data.uci_cqi, uci_data.uci_cqi_len, uci_data.beta_cqi, - Q_prime_ri, harq_process, q_bits); + Q_prime_ri, harq_process, g_bits); if (ret < 0) { return ret; } @@ -572,7 +571,7 @@ int ulsch_uci_encode(sch_t *q, uint8_t *data, uci_data_t uci_data, uint8_t *q_bi // Encode UL-SCH if (harq_process->mcs.tbs > 0) { uint32_t G = nb_q/Q_m - Q_prime_ri - Q_prime_cqi; - ret = encode_tb(q, data, &q_bits[e_offset], harq_process->mcs.tbs, + ret = encode_tb(q, data, &g_bits[e_offset], harq_process->mcs.tbs, G*Q_m, harq_process, rv_idx); if (ret) { return ret; @@ -580,10 +579,10 @@ int ulsch_uci_encode(sch_t *q, uint8_t *data, uci_data_t uci_data, uint8_t *q_bi } // Multiplexing and Interleaving - ulsch_interleave(q_bits, nb_q/Q_m-Q_prime_ri, - q_bits_ack, Q_prime_ack, - q_bits_ri, Q_prime_ri, - Q_m); + ulsch_interleave(g_bits, nb_q/Q_m-Q_prime_ri, + g_bits_ack, Q_prime_ack, + g_bits_ri, Q_prime_ri, + Q_m, q_bits); diff --git a/lte/phy/lib/phch/test/pusch_test.c b/lte/phy/lib/phch/test/pusch_test.c index 0552cfc96..c0184e938 100644 --- a/lte/phy/lib/phch/test/pusch_test.c +++ b/lte/phy/lib/phch/test/pusch_test.c @@ -199,21 +199,22 @@ int main(int argc, char **argv) { uci_data.beta_ri = 2.0; uci_data.beta_ack = 2.0; uci_data.uci_cqi = tmp; - uci_data.uci_cqi_len = 10; + uci_data.uci_cqi_len = 0; uci_data.uci_ri_len = 1; uci_data.uci_ack_len = 0; + uci_data.uci_ri = 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); - if (ulsch_uci_encode(&pusch.dl_sch, data, uci_data, pusch.pusch_e, - pusch.pusch_q_ack, pusch.pusch_q_ri, &harq_process, rv)) + if (ulsch_uci_encode(&pusch.dl_sch, data, uci_data, pusch.pusch_g, + pusch.pusch_g_ack, pusch.pusch_g_ri, &harq_process, rv, pusch.pusch_q)) { fprintf(stderr, "Error encoding TB\n"); exit(-1); } - vec_fprint_b(stdout, pusch.pusch_e, nof_bits_e); + vec_fprint_b(stdout, pusch.pusch_q, nof_bits_e); /* combine outputs */ for (i=0;i 0) { free(uci_data.uci_cqi); diff --git a/matlab/tests/ulsch_test.m b/matlab/tests/ulsch_test.m index d79a04429..527bd68f7 100644 --- a/matlab/tests/ulsch_test.m +++ b/matlab/tests/ulsch_test.m @@ -3,21 +3,21 @@ puschConfig=struct('NLayers',1,'OrthCover','Off','PRBSet',0,'Modulation','QPSK', addpath('../../debug/lte/phy/lib/phch/test') -TBs=99; +TBs=100; error=zeros(size(TBs)); for i=1:length(error) - trblkin=randi(2,TBs(i),1)-1; - %trblkin=ones(TBs(i),1); + %trblkin=randi(2,TBs(i),1)-1; + trblkin=ones(TBs(i),1); %trblkin=[]; puschConfig.BetaCQI = 2.0; puschConfig.BetaRI = 2.0; puschConfig.BetaACK = 2.0; - [mat, info]=lteULSCH(ueConfig,puschConfig,trblkin,[],[],[],[]); + [mat, info]=lteULSCH(ueConfig,puschConfig,trblkin,[],[1],[],[]); mat(mat==-2)=2; mat(mat==-1)=3; - [lib]=liblte_ulsch_encode(ueConfig,puschConfig,trblkin,[],[],[]); + [lib]=liblte_ulsch_encode(ueConfig,puschConfig,trblkin,[],[1],[]); error(i)=sum(abs(double(mat)-double(lib))); if (length(TBs) == 1) disp(error(i))