void base_free() { pbch_free(&pbch); lte_ifft_free(&ifft); if (slot_buffer) { free(slot_buffer); } if (output_buffer) { free(output_buffer); } if (output_file_name) { filesink_free(&fsink); } else { #ifndef DISABLE_UHD cuhd_close(&uhd); #endif } }
void base_free() { int i; filesource_free(&fsrc); if (fmatlab) { fclose(fmatlab); } free(input_buffer); free(fft_buffer); filesource_free(&fsrc); for (i=0;i<cell.nof_ports;i++) { free(ce[i]); } chest_free(&chest); lte_fft_free(&fft); pbch_free(&pbch); }
void base_free() { pdsch_harq_free(&harq_process); pdsch_free(&pdsch); pdcch_free(&pdcch); regs_free(®s); pbch_free(&pbch); lte_ifft_free(&ifft); if (sf_buffer) { free(sf_buffer); } if (output_buffer) { free(output_buffer); } if (output_file_name) { filesink_free(&fsink); } else { #ifndef DISABLE_UHD cuhd_close(&uhd); #endif } }
/** Initializes the PBCH transmitter and receiver. * At the receiver, the field nof_ports in the cell structure indicates the * maximum number of BS transmitter ports to look for. */ int pbch_init(pbch_t *q, lte_cell_t cell) { int ret = LIBLTE_ERROR_INVALID_INPUTS; if (q != NULL && lte_cell_isvalid(&cell)) { ret = LIBLTE_ERROR; bzero(q, sizeof(pbch_t)); q->cell = cell; if (modem_table_lte(&q->mod, LTE_QPSK, true)) { goto clean; } demod_soft_init(&q->demod); demod_soft_table_set(&q->demod, &q->mod); demod_soft_alg_set(&q->demod, APPROX); if (sequence_pbch(&q->seq_pbch, q->cell.cp, q->cell.id)) { goto clean; } uint32_t poly[3] = { 0x6D, 0x4F, 0x57 }; if (viterbi_init(&q->decoder, viterbi_37, poly, 40, true)) { goto clean; } if (crc_init(&q->crc, LTE_CRC16, 16)) { goto clean; } q->encoder.K = 7; q->encoder.R = 3; q->encoder.tail_biting = true; memcpy(q->encoder.poly, poly, 3 * sizeof(int)); q->nof_symbols = (CP_ISNORM(q->cell.cp)) ? PBCH_RE_CPNORM : PBCH_RE_CPEXT; q->pbch_d = 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); if (!q->ce[i]) { goto clean; } q->pbch_x[i] = 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); if (!q->pbch_symbols[i]) { goto clean; } } q->pbch_llr = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_llr) { goto clean; } q->temp = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->temp) { goto clean; } q->pbch_rm_f = malloc(sizeof(float) * 120); if (!q->pbch_rm_f) { goto clean; } q->pbch_rm_b = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_rm_b) { goto clean; } q->data = malloc(sizeof(char) * 40); if (!q->data) { goto clean; } q->data_enc = malloc(sizeof(char) * 120); if (!q->data_enc) { goto clean; } ret = LIBLTE_SUCCESS; } clean: if (ret == LIBLTE_ERROR) { pbch_free(q); } return ret; }
/** Initializes the PBCH transmitter and receiver */ int pbch_init(pbch_t *q, int nof_prb, int cell_id, lte_cp_t cp) { int ret = -1; if (cell_id < 0) { return -1; } bzero(q, sizeof(pbch_t)); q->cell_id = cell_id; q->cp = cp; q->nof_prb = nof_prb; if (modem_table_std(&q->mod, LTE_QPSK, true)) { goto clean; } demod_soft_init(&q->demod); demod_soft_table_set(&q->demod, &q->mod); demod_soft_alg_set(&q->demod, APPROX); if (sequence_pbch(&q->seq_pbch, q->cp, q->cell_id)) { goto clean; } int poly[3] = { 0x6D, 0x4F, 0x57 }; if (viterbi_init(&q->decoder, viterbi_37, poly, 40, true)) { goto clean; } if (crc_init(&q->crc, LTE_CRC16, 16)) { goto clean; } q->encoder.K = 7; q->encoder.R = 3; q->encoder.tail_biting = true; memcpy(q->encoder.poly, poly, 3 * sizeof(int)); q->nof_symbols = (CP_ISNORM(q->cp)) ? PBCH_RE_CPNORM : PBCH_RE_CPEXT; q->pbch_d = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->pbch_d) { goto clean; } int i; for (i = 0; i < MAX_PORTS_CTRL; i++) { q->ce[i] = malloc(sizeof(cf_t) * q->nof_symbols); if (!q->ce[i]) { goto clean; } q->pbch_x[i] = 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); if (!q->pbch_symbols[i]) { goto clean; } } q->pbch_llr = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_llr) { goto clean; } q->temp = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->temp) { goto clean; } q->pbch_rm_f = malloc(sizeof(float) * 120); if (!q->pbch_rm_f) { goto clean; } q->pbch_rm_b = malloc(sizeof(float) * q->nof_symbols * 4 * 2); if (!q->pbch_rm_b) { goto clean; } q->data = malloc(sizeof(char) * 40); if (!q->data) { goto clean; } q->data_enc = malloc(sizeof(char) * 120); if (!q->data_enc) { goto clean; } ret = 0; clean: if (ret == -1) { pbch_free(q); } return ret; }
int main(int argc, char **argv) { pbch_t pbch; pbch_mib_t mib_tx, mib_rx; int i, j; cf_t *ce[MAX_PORTS]; int nof_re; cf_t *sf_symbols[MAX_PORTS]; parse_args(argc,argv); nof_re = 2 * CPNORM_NSYMB * cell.nof_prb * RE_X_RB; /* init memory */ for (i=0;i<cell.nof_ports;i++) { ce[i] = malloc(sizeof(cf_t) * nof_re); if (!ce[i]) { perror("malloc"); exit(-1); } for (j=0;j<nof_re;j++) { ce[i][j] = 1; } sf_symbols[i] = malloc(sizeof(cf_t) * nof_re); if (!sf_symbols[i]) { perror("malloc"); exit(-1); } } if (pbch_init(&pbch, cell)) { fprintf(stderr, "Error creating PBCH object\n"); exit(-1); } mib_tx.nof_ports = cell.nof_ports; mib_tx.nof_prb = 50; mib_tx.phich_length = PHICH_EXT; mib_tx.phich_resources = R_1_6; mib_tx.sfn = 124; pbch_encode(&pbch, &mib_tx, sf_symbols); /* combine outputs */ for (i=1;i<cell.nof_ports;i++) { for (j=0;j<nof_re;j++) { sf_symbols[0][j] += sf_symbols[i][j]; } } pbch_decode_reset(&pbch); if (1 != pbch_decode(&pbch, sf_symbols[0], ce, &mib_rx)) { printf("Error decoding\n"); exit(-1); } pbch_free(&pbch); for (i=0;i<cell.nof_ports;i++) { free(ce[i]); free(sf_symbols[i]); } if (!memcmp(&mib_tx, &mib_rx, sizeof(pbch_mib_t))) { printf("OK\n"); exit(0); } else { pbch_mib_fprint(stdout, &mib_rx); exit(-1); } }