Replaced malloc by vec_malloc

master
ismagom 10 years ago
parent c33c75c48d
commit 300633bc59

@ -33,6 +33,7 @@
#include <math.h> #include <math.h>
#include "liblte/phy/fec/turbodecoder.h" #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) int map_gen_init(map_gen_t * h, int max_long_cb)
{ {
bzero(h, sizeof(map_gen_t)); 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) { if (!h->beta) {
perror("malloc"); perror("vec_malloc");
return -1; return -1;
} }
h->max_long_cb = max_long_cb; 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->max_long_cb = max_long_cb;
h->llr1 = malloc(sizeof(llr_t) * len); h->llr1 = vec_malloc(sizeof(llr_t) * len);
if (!h->llr1) { if (!h->llr1) {
perror("malloc"); perror("vec_malloc");
goto clean_and_exit; goto clean_and_exit;
} }
h->llr2 = malloc(sizeof(llr_t) * len); h->llr2 = vec_malloc(sizeof(llr_t) * len);
if (!h->llr2) { if (!h->llr2) {
perror("malloc"); perror("vec_malloc");
goto clean_and_exit; goto clean_and_exit;
} }
h->w = malloc(sizeof(llr_t) * len); h->w = vec_malloc(sizeof(llr_t) * len);
if (!h->w) { if (!h->w) {
perror("malloc"); perror("vec_malloc");
goto clean_and_exit; goto clean_and_exit;
} }
h->syst = malloc(sizeof(llr_t) * len); h->syst = vec_malloc(sizeof(llr_t) * len);
if (!h->syst) { if (!h->syst) {
perror("malloc"); perror("vec_malloc");
goto clean_and_exit; goto clean_and_exit;
} }
h->parity = malloc(sizeof(llr_t) * len); h->parity = vec_malloc(sizeof(llr_t) * len);
if (!h->parity) { if (!h->parity) {
perror("malloc"); perror("vec_malloc");
goto clean_and_exit; goto clean_and_exit;
} }

@ -166,34 +166,34 @@ int pbch_init(pbch_t *q, lte_cell_t cell) {
q->encoder.tail_biting = true; q->encoder.tail_biting = true;
memcpy(q->encoder.poly, poly, 3 * sizeof(int)); 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) { if (!q->pbch_d) {
goto clean; goto clean;
} }
int i; int i;
for (i = 0; i < q->cell.nof_ports; 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]) { if (!q->ce[i]) {
goto clean; 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]) { if (!q->pbch_x[i]) {
goto clean; 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]) { if (!q->pbch_symbols[i]) {
goto clean; 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) { if (!q->pbch_llr) {
goto clean; 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) { if (!q->temp) {
goto clean; 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) { if (!q->pbch_rm_b) {
goto clean; goto clean;
} }

@ -232,26 +232,26 @@ int pdsch_init(pdsch_t *q, lte_cell_t cell) {
q->rnti_is_set = false; q->rnti_is_set = false;
// Allocate floats for reception (LLRs) // 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) { if (!q->pdsch_e) {
goto clean; 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) { if (!q->pdsch_d) {
goto clean; goto clean;
} }
for (i = 0; i < q->cell.nof_ports; i++) { 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]) { if (!q->ce[i]) {
goto clean; 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]) { if (!q->pdsch_x[i]) {
goto clean; 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]) { if (!q->pdsch_symbols[i]) {
goto clean; goto clean;
} }

@ -121,42 +121,42 @@ int pusch_init(pusch_t *q, lte_cell_t cell) {
q->rnti_is_set = false; q->rnti_is_set = false;
// Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission // 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) { if (!q->pusch_q) {
goto clean; goto clean;
} }
// Allocate floats for reception (LLRs). Buffer casted to uint8_t for transmission // 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) { if (!q->pusch_g) {
goto clean; goto clean;
} }
// Allocate buffers for q bits for coded RI and ACK bits // 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) { if (!q->pusch_g_ack) {
goto clean; 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) { if (!q->pusch_g_ri) {
goto clean; 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) { if (!q->pusch_d) {
goto clean; goto clean;
} }
for (i = 0; i < q->cell.nof_ports; i++) { 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]) { if (!q->ce[i]) {
goto clean; 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]) { if (!q->pusch_x[i]) {
goto clean; 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]) { if (!q->pusch_symbols[i]) {
goto clean; goto clean;
} }
@ -180,6 +180,9 @@ void pusch_free(pusch_t *q) {
if (q->pusch_d) { if (q->pusch_d) {
free(q->pusch_d); free(q->pusch_d);
} }
if (q->pusch_g) {
free(q->pusch_g);
}
if (q->pusch_g_ack) { if (q->pusch_g_ack) {
free(q->pusch_g_ack); free(q->pusch_g_ack);
} }

@ -67,12 +67,12 @@ int sch_init(sch_t *q) {
} }
// Allocate floats for reception (LLRs) // 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) { if (!q->cb_in) {
goto clean; 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) { if (!q->cb_out) {
goto clean; goto clean;
} }
@ -407,7 +407,7 @@ uint8_t ulsch_y_idx[10000];
uint8_t ulsch_y_mat[10000]; uint8_t ulsch_y_mat[10000];
/* UL-SCH channel interleaver according to 5.5.2.8 of 36.212 */ /* 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_ack[6], uint32_t Q_prime_ack,
uint8_t q_bits_ri[6], uint32_t Q_prime_ri, uint8_t q_bits_ri[6], uint32_t Q_prime_ri,
uint32_t Q_m, uint8_t *g_bits) 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<Q_m; k++) {
g_bits[(C_mux*r*Q_m) + C_ack*Q_m + k] = g_bits_ack[Q_m*i+k];
}
i++;
r = R_prime_mux - 1 - i/4;
j = (j + 3) % 4;
}
// Step 3: Interleave the RI control bits
i = 0;
j = 0;
r = R_prime_mux-1;
while(i < Q_prime_ri) {
C_ri = ri_column_set[j];
ulsch_y_idx[r*C_mux + C_ri] = 1;
for(k=0; k<Q_m; k++) {
q_bits[(r*Q_m) + C_mux*C_ri*Q_m + k] = 10+g_bits_ri[Q_m*i+k];
}
i++;
r = R_prime_mux - 1 - i/4;
j = (j + 3) % 4;
}
// Step 6: Read out the bits
idx = 0;
printf("go for C_mux: %d, R_prime: %d, Q_m: %d\n", C_mux, R_prime_mux, Q_m);
for(i=0; i<C_mux; i++) {
for(j=0; j<R_prime_mux; j++) {
for(k=0; k<Q_m; k++) {
if (q_bits[idx] >= 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, 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) harq_t *harq_process, uint32_t rv_idx, uint8_t *q_bits)
{ {

@ -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_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); 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, 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)) pusch.pusch_g_ack, pusch.pusch_g_ri, &harq_process, rv, pusch.pusch_q))
{ {

Loading…
Cancel
Save