diff --git a/lte/phy/lib/fec/src/turbodecoder.c b/lte/phy/lib/fec/src/turbodecoder.c index 87ff32b50..89c784966 100644 --- a/lte/phy/lib/fec/src/turbodecoder.c +++ b/lte/phy/lib/fec/src/turbodecoder.c @@ -33,6 +33,7 @@ #include #include "liblte/phy/fec/turbodecoder.h" +#include "liblte/phy/utils/vector.h" /************************************************ * @@ -157,9 +158,9 @@ void map_gen_alpha(map_gen_t * s, llr_t * input, llr_t * parity, llr_t * output, int map_gen_init(map_gen_t * h, int max_long_cb) { bzero(h, sizeof(map_gen_t)); - h->beta = malloc(sizeof(llr_t) * (max_long_cb + TOTALTAIL + 1) * NUMSTATES); + h->beta = vec_malloc(sizeof(llr_t) * (max_long_cb + TOTALTAIL + 1) * NUMSTATES); if (!h->beta) { - perror("malloc"); + perror("vec_malloc"); return -1; } h->max_long_cb = max_long_cb; @@ -200,29 +201,29 @@ int tdec_init(tdec_t * h, uint32_t max_long_cb) h->max_long_cb = max_long_cb; - h->llr1 = malloc(sizeof(llr_t) * len); + h->llr1 = vec_malloc(sizeof(llr_t) * len); if (!h->llr1) { - perror("malloc"); + perror("vec_malloc"); goto clean_and_exit; } - h->llr2 = malloc(sizeof(llr_t) * len); + h->llr2 = vec_malloc(sizeof(llr_t) * len); if (!h->llr2) { - perror("malloc"); + perror("vec_malloc"); goto clean_and_exit; } - h->w = malloc(sizeof(llr_t) * len); + h->w = vec_malloc(sizeof(llr_t) * len); if (!h->w) { - perror("malloc"); + perror("vec_malloc"); goto clean_and_exit; } - h->syst = malloc(sizeof(llr_t) * len); + h->syst = vec_malloc(sizeof(llr_t) * len); if (!h->syst) { - perror("malloc"); + perror("vec_malloc"); goto clean_and_exit; } - h->parity = malloc(sizeof(llr_t) * len); + h->parity = vec_malloc(sizeof(llr_t) * len); if (!h->parity) { - perror("malloc"); + perror("vec_malloc"); goto clean_and_exit; } diff --git a/lte/phy/lib/phch/src/pbch.c b/lte/phy/lib/phch/src/pbch.c index 4e0965e61..4dd07bae9 100644 --- a/lte/phy/lib/phch/src/pbch.c +++ b/lte/phy/lib/phch/src/pbch.c @@ -166,34 +166,34 @@ int pbch_init(pbch_t *q, lte_cell_t cell) { q->encoder.tail_biting = true; memcpy(q->encoder.poly, poly, 3 * sizeof(int)); - q->pbch_d = malloc(sizeof(cf_t) * q->nof_symbols); + q->pbch_d = vec_malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_d) { goto clean; } int i; for (i = 0; i < q->cell.nof_ports; i++) { - q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols); + q->ce[i] = vec_malloc(sizeof(cf_t) * q->nof_symbols); if (!q->ce[i]) { goto clean; } - q->pbch_x[i] = malloc(sizeof(cf_t) * q->nof_symbols); + q->pbch_x[i] = vec_malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_x[i]) { goto clean; } - q->pbch_symbols[i] = malloc(sizeof(cf_t) * q->nof_symbols); + q->pbch_symbols[i] = vec_malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_symbols[i]) { goto clean; } } - q->pbch_llr = malloc(sizeof(float) * q->nof_symbols * 4 * 2); + q->pbch_llr = vec_malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_llr) { goto clean; } - q->temp = malloc(sizeof(float) * q->nof_symbols * 4 * 2); + q->temp = vec_malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->temp) { goto clean; } - q->pbch_rm_b = malloc(sizeof(float) * q->nof_symbols * 4 * 2); + q->pbch_rm_b = vec_malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_rm_b) { goto clean; } diff --git a/lte/phy/lib/phch/src/pdsch.c b/lte/phy/lib/phch/src/pdsch.c index d2f3f10e8..8f7184819 100644 --- a/lte/phy/lib/phch/src/pdsch.c +++ b/lte/phy/lib/phch/src/pdsch.c @@ -232,26 +232,26 @@ int pdsch_init(pdsch_t *q, lte_cell_t cell) { q->rnti_is_set = false; // Allocate floats for reception (LLRs) - q->pdsch_e = malloc(sizeof(float) * q->max_symbols * lte_mod_bits_x_symbol(LTE_QAM64)); + q->pdsch_e = vec_malloc(sizeof(float) * q->max_symbols * lte_mod_bits_x_symbol(LTE_QAM64)); if (!q->pdsch_e) { goto clean; } - q->pdsch_d = malloc(sizeof(cf_t) * q->max_symbols); + q->pdsch_d = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pdsch_d) { goto clean; } for (i = 0; i < q->cell.nof_ports; i++) { - q->ce[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->ce[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->ce[i]) { goto clean; } - q->pdsch_x[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->pdsch_x[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pdsch_x[i]) { goto clean; } - q->pdsch_symbols[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->pdsch_symbols[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pdsch_symbols[i]) { goto clean; } diff --git a/lte/phy/lib/phch/src/pusch.c b/lte/phy/lib/phch/src/pusch.c index 2d94f3949..a14d2bf1d 100644 --- a/lte/phy/lib/phch/src/pusch.c +++ b/lte/phy/lib/phch/src/pusch.c @@ -121,42 +121,42 @@ int pusch_init(pusch_t *q, lte_cell_t cell) { q->rnti_is_set = false; // 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)); + q->pusch_q = vec_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)); + q->pusch_g = vec_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_g_ack = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); + q->pusch_g_ack = vec_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_g_ri = malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); + q->pusch_g_ri = vec_malloc(sizeof(uint8_t) * 4 * q->cell.nof_prb * lte_mod_bits_x_symbol(LTE_QAM64)); if (!q->pusch_g_ri) { goto clean; } - q->pusch_d = malloc(sizeof(cf_t) * q->max_symbols); + q->pusch_d = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pusch_d) { goto clean; } for (i = 0; i < q->cell.nof_ports; i++) { - q->ce[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->ce[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->ce[i]) { goto clean; } - q->pusch_x[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->pusch_x[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pusch_x[i]) { goto clean; } - q->pusch_symbols[i] = malloc(sizeof(cf_t) * q->max_symbols); + q->pusch_symbols[i] = vec_malloc(sizeof(cf_t) * q->max_symbols); if (!q->pusch_symbols[i]) { goto clean; } @@ -180,6 +180,9 @@ void pusch_free(pusch_t *q) { if (q->pusch_d) { free(q->pusch_d); } + if (q->pusch_g) { + free(q->pusch_g); + } if (q->pusch_g_ack) { free(q->pusch_g_ack); } diff --git a/lte/phy/lib/phch/src/sch.c b/lte/phy/lib/phch/src/sch.c index 1788655c4..e46aa11ef 100644 --- a/lte/phy/lib/phch/src/sch.c +++ b/lte/phy/lib/phch/src/sch.c @@ -67,12 +67,12 @@ int sch_init(sch_t *q) { } // Allocate floats for reception (LLRs) - q->cb_in = malloc(sizeof(uint8_t) * MAX_LONG_CB); + q->cb_in = vec_malloc(sizeof(uint8_t) * MAX_LONG_CB); if (!q->cb_in) { goto clean; } - q->cb_out = malloc(sizeof(float) * (3 * MAX_LONG_CB + 12)); + q->cb_out = vec_malloc(sizeof(float) * (3 * MAX_LONG_CB + 12)); if (!q->cb_out) { goto clean; } @@ -407,7 +407,7 @@ uint8_t ulsch_y_idx[10000]; uint8_t ulsch_y_mat[10000]; /* UL-SCH channel interleaver according to 5.5.2.8 of 36.212 */ -void ulsch_interleave(uint8_t *q_bits, uint32_t nb_q, +void ulsch_interleave2(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, uint8_t *g_bits) @@ -505,6 +505,92 @@ void ulsch_interleave(uint8_t *q_bits, uint32_t nb_q, } +/* UL-SCH channel interleaver according to 5.5.2.8 of 36.212 */ +void ulsch_interleave(uint8_t *g_bits, uint32_t nb_q, + uint8_t g_bits_ack[6], uint32_t Q_prime_ack, + uint8_t g_bits_ri[6], uint32_t Q_prime_ri, + uint32_t Q_m, + uint8_t *q_bits) +{ + uint32_t C_mux; + uint32_t H_prime; + uint32_t H_prime_total; + uint32_t R_mux; + uint32_t R_prime_mux; + uint32_t i; + uint32_t j; + uint32_t k; + uint32_t r; + uint32_t idx; + uint32_t ri_column_set[4] = {1, 4, 7, 10}; + uint32_t ack_column_set[4] = {2, 3, 8, 9}; + uint32_t C_ri; + uint32_t C_ack; + uint32_t N_pusch_symbs = 12; + + // Step 1: Define C_mux + C_mux = N_pusch_symbs; + + // Step 2: Define R_mux and R_prime_mux + H_prime = nb_q; + H_prime_total = H_prime + Q_prime_ri; + R_mux = (H_prime_total*Q_m)/C_mux; + R_prime_mux = R_mux/Q_m; + + + + // ACK insertion can be done at uci.c + + // Step 5: Interleave the ACK control bits + i = 0; + j = 0; + r = R_prime_mux-1; + while(i < Q_prime_ack) { + C_ack = ack_column_set[j]; + for(k=0; k= 10) { + printf("10 at %d is %d\n",idx, q_bits[idx]); + //q_bits[idx] -= 10; + } else { + printf("reading %d\n", j*C_mux*Q_m + i*Q_m + k); + q_bits[idx] = g_bits[j*C_mux*Q_m + i*Q_m + k]; + } + idx++; + } + } + } + + +} + int ulsch_encode(sch_t *q, uint8_t *data, uint8_t *g_bits, harq_t *harq_process, uint32_t rv_idx, uint8_t *q_bits) { diff --git a/lte/phy/lib/phch/test/pusch_test.c b/lte/phy/lib/phch/test/pusch_test.c index c0184e938..06e4ffe53 100644 --- a/lte/phy/lib/phch/test/pusch_test.c +++ b/lte/phy/lib/phch/test/pusch_test.c @@ -207,6 +207,9 @@ int main(int argc, char **argv) { 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)); + + 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)) {