void base_free() { int i; for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { srslte_softbuffer_tx_free(softbuffers[i]); if (softbuffers[i]) { free(softbuffers[i]); } } srslte_pdsch_free(&pdsch); srslte_pdcch_free(&pdcch); srslte_regs_free(®s); srslte_pbch_free(&pbch); if(mbsfn_area_id > -1){ srslte_pmch_free(&pmch); } srslte_ofdm_tx_free(&ifft_mbsfn); for (i = 0; i < cell.nof_ports; i++) { srslte_ofdm_tx_free(&ifft[i]); } for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { if (data[i]) { free(data[i]); } } for (i = 0; i < SRSLTE_MAX_PORTS; i++) { if (sf_buffer[i]) { free(sf_buffer[i]); } if (output_buffer[i]) { free(output_buffer[i]); } } if (output_file_name) { if (!null_file_sink) { srslte_filesink_free(&fsink); } } else { #ifndef DISABLE_RF srslte_rf_close(&rf); #endif } if (net_port > 0) { srslte_netsource_free(&net_source); sem_close(&net_sem); } }
int main(int argc, char **argv) { uint32_t i, j, k; int ret = -1; struct timeval t[3]; srslte_softbuffer_tx_t *softbuffers_tx[SRSLTE_MAX_CODEWORDS]; int M=1; parse_args(argc,argv); /* Initialise to zeros */ bzero(&pmch_tx, sizeof(srslte_pmch_t)); bzero(&pmch_rx, sizeof(srslte_pmch_t)); bzero(&pmch_cfg, sizeof(srslte_pdsch_cfg_t)); bzero(ce, sizeof(cf_t*)*SRSLTE_MAX_PORTS); bzero(tx_slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS); bzero(rx_slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS); cell.nof_ports = 1; srslte_ra_dl_dci_t dci; bzero(&dci, sizeof(srslte_ra_dl_dci_t)); dci.type0_alloc.rbg_bitmask = 0xffffffff; /* If transport block 0 is enabled */ grant.tb_en[0] = true; grant.tb_en[1] = false; grant.mcs[0].idx = mcs_idx; grant.nof_prb = cell.nof_prb; grant.sf_type = SRSLTE_SF_MBSFN; srslte_dl_fill_ra_mcs(&grant.mcs[0], cell.nof_prb); grant.Qm[0] = srslte_mod_bits_x_symbol(grant.mcs[0].mod); for(int i = 0; i < 2; i++){ for(int j = 0; j < grant.nof_prb; j++){ grant.prb_idx[i][j] = true; } } /* init memory */ for (i=0;i<SRSLTE_MAX_PORTS;i++) { for (j = 0; j < SRSLTE_MAX_PORTS; j++) { ce[i][j] = srslte_vec_malloc(sizeof(cf_t) * NOF_CE_SYMBOLS); if (!ce[i][j]) { perror("srslte_vec_malloc"); goto quit; } for (k = 0; k < NOF_CE_SYMBOLS; k++) { ce[i][j][k] = (i == j) ? 1.0f : 0.0f; } } rx_slot_symbols[i] = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp)); if (!rx_slot_symbols[i]) { perror("srslte_vec_malloc"); goto quit; } } for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { softbuffers_tx[i] = calloc(sizeof(srslte_softbuffer_tx_t), 1); if (!softbuffers_tx[i]) { fprintf(stderr, "Error allocating TX soft buffer\n"); } if (srslte_softbuffer_tx_init(softbuffers_tx[i], cell.nof_prb)) { fprintf(stderr, "Error initiating TX soft buffer\n"); goto quit; } } for (i = 0; i < cell.nof_ports; i++) { tx_slot_symbols[i] = calloc(SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp), sizeof(cf_t)); if (!tx_slot_symbols[i]) { perror("srslte_vec_malloc"); goto quit; } } for (int i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { if (grant.tb_en[i]) { data_tx[i] = srslte_vec_malloc(sizeof(uint8_t) * grant.mcs[i].tbs); if (!data_tx[i]) { perror("srslte_vec_malloc"); goto quit; } bzero(data_tx[i], sizeof(uint8_t) * grant.mcs[i].tbs); data_rx[i] = srslte_vec_malloc(sizeof(uint8_t) * grant.mcs[i].tbs); if (!data_rx[i]) { perror("srslte_vec_malloc"); goto quit; } bzero(data_rx[i], sizeof(uint8_t) * grant.mcs[i].tbs); } } for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { softbuffers_rx[i] = calloc(sizeof(srslte_softbuffer_rx_t), 1); if (!softbuffers_rx[i]) { fprintf(stderr, "Error allocating RX soft buffer\n"); goto quit; } if (srslte_softbuffer_rx_init(softbuffers_rx[i], cell.nof_prb)) { fprintf(stderr, "Error initiating RX soft buffer\n"); goto quit; } } #ifdef DO_OFDM for (i = 0; i < cell.nof_ports; i++) { tx_sf_symbols[i] = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb)); if (srslte_ofdm_tx_init_mbsfn(&ifft_mbsfn[i], SRSLTE_CP_EXT, tx_slot_symbols[i], tx_sf_symbols[i], cell.nof_prb)) { fprintf(stderr, "Error creating iFFT object\n"); exit(-1); } srslte_ofdm_set_non_mbsfn_region(&ifft_mbsfn[i], non_mbsfn_region); srslte_ofdm_set_normalize(&ifft_mbsfn[i], true); } for (i = 0; i < nof_rx_antennas; i++) { rx_sf_symbols[i] = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_PRB(cell.nof_prb)); if (srslte_ofdm_rx_init_mbsfn(&fft_mbsfn[i], SRSLTE_CP_EXT, rx_sf_symbols[i], rx_slot_symbols[i], cell.nof_prb)) { fprintf(stderr, "Error creating iFFT object\n"); exit(-1); } srslte_ofdm_set_non_mbsfn_region(&fft_mbsfn[i], non_mbsfn_region); srslte_ofdm_set_normalize(&fft_mbsfn[i], true); } #endif /* DO_OFDM */ /* Configure PDSCH */ if (srslte_pmch_cfg(&pmch_cfg, cell, &grant, cfi, subframe)) { fprintf(stderr, "Error configuring PMCH\n"); exit(-1); } if (srslte_pmch_cfg(&pmch_cfg, cell, &grant, cfi, subframe)) { fprintf(stderr, "Error configuring PMCH\n"); exit(-1); } INFO(" Global:\n"); INFO(" nof_prb=%d\n", cell.nof_prb); INFO(" nof_ports=%d\n", cell.nof_ports); INFO(" id=%d\n", cell.id); INFO(" cp=%s\n", srslte_cp_string(cell.cp)); INFO(" phich_length=%d\n", (int) cell.phich_length); INFO(" phich_resources=%d\n", (int) cell.phich_resources); INFO(" nof_prb=%d\n", pmch_cfg.grant.nof_prb); INFO(" sf_idx=%d\n", pmch_cfg.sf_idx); INFO(" mimo_type=%s\n", srslte_mimotype2str(pmch_cfg.mimo_type)); INFO(" nof_layers=%d\n", pmch_cfg.nof_layers); INFO(" nof_tb=%d\n", SRSLTE_RA_DL_GRANT_NOF_TB(&pmch_cfg.grant)); INFO(" Qm=%d\n", pmch_cfg.grant.Qm[0]); INFO(" mcs.idx=0x%X\n", pmch_cfg.grant.mcs[0].idx); INFO(" mcs.tbs=%d\n", pmch_cfg.grant.mcs[0].tbs); INFO(" mcs.mod=%s\n", srslte_mod_string(pmch_cfg.grant.mcs[0].mod)); INFO(" rv=%d\n", pmch_cfg.rv[0]); INFO(" lstart=%d\n", pmch_cfg.nbits[0].lstart); INFO(" nof_bits=%d\n", pmch_cfg.nbits[0].nof_bits); INFO(" nof_re=%d\n", pmch_cfg.nbits[0].nof_re); INFO(" nof_symb=%d\n", pmch_cfg.nbits[0].nof_symb); if (srslte_pmch_init(&pmch_tx, cell.nof_prb)) { fprintf(stderr, "Error creating PMCH object\n"); } srslte_pmch_set_area_id(&pmch_tx, mbsfn_area_id); if (srslte_pmch_init(&pmch_rx, cell.nof_prb)) { fprintf(stderr, "Error creating PMCH object\n"); } srslte_pmch_set_area_id(&pmch_rx, mbsfn_area_id); for (int tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { if (grant.tb_en[tb]) { for (int byte = 0; byte < grant.mcs[tb].tbs / 8; byte++) { data_tx[tb][byte] = (uint8_t) (rand() % 256); } } } if (srslte_pmch_encode(&pmch_tx, &pmch_cfg, softbuffers_tx[0], data_tx[0], mbsfn_area_id, tx_slot_symbols)) { fprintf(stderr, "Error encoding PDSCH\n"); exit(-1); } gettimeofday(&t[2], NULL); get_time_interval(t); printf("ENCODED in %.2f (PHY bitrate=%.2f Mbps. Processing bitrate=%.2f Mbps)\n", (float) t[0].tv_usec/M, (float) (grant.mcs[0].tbs + grant.mcs[1].tbs)/1000.0f, (float) (grant.mcs[0].tbs + grant.mcs[1].tbs)*M/t[0].tv_usec); #ifdef DO_OFDM for (i = 0; i < cell.nof_ports; i++) { /* For each Tx antenna modulate OFDM */ srslte_ofdm_tx_sf(&ifft_mbsfn[i]); } /* combine outputs */ for (j = 0; j < nof_rx_antennas; j++) { for (k = 0; k < NOF_CE_SYMBOLS; k++) { rx_sf_symbols[j][k] = 0.0f; for (i = 0; i < cell.nof_ports; i++) { rx_sf_symbols[j][k] += tx_sf_symbols[i][k] * ce[i][j][k]; } } } #else /* combine outputs */ for (j = 0; j < nof_rx_antennas; j++) { for (k = 0; k < SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp); k++) { rx_slot_symbols[j][k] = 0.0f; for (i = 0; i < cell.nof_ports; i++) { rx_slot_symbols[j][k] += tx_slot_symbols[i][k] * ce[i][j][k]; } } } #endif int r=0; gettimeofday(&t[1], NULL); #ifdef DO_OFDM /* For each Rx antenna demodulate OFDM */ for (i = 0; i < nof_rx_antennas; i++) { srslte_ofdm_rx_sf(&fft_mbsfn[i]); } #endif for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { if (grant.tb_en[i]) { srslte_softbuffer_rx_reset_tbs(softbuffers_rx[i], (uint32_t) grant.mcs[i].tbs); } } r = srslte_pmch_decode(&pmch_rx, &pmch_cfg, softbuffers_rx[0],rx_slot_symbols[0], ce[0],0,mbsfn_area_id, data_rx[0]); gettimeofday(&t[2], NULL); get_time_interval(t); printf("DECODED %s in %.2f (PHY bitrate=%.2f Mbps. Processing bitrate=%.2f Mbps)\n", r?"Error":"OK", (float) t[0].tv_usec/M, (float) (grant.mcs[0].tbs + grant.mcs[1].tbs)/1000.0f, (float) (grant.mcs[0].tbs + grant.mcs[1].tbs)*M/t[0].tv_usec); /* If there is an error in PDSCH decode */ if (r) { ret = -1; goto quit; } /* Check Tx and Rx bytes */ for (int tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) { if (grant.tb_en[tb]) { for (int byte = 0; byte < grant.mcs[tb].tbs / 8; byte++) { if (data_tx[tb][byte] != data_rx[tb][byte]) { ERROR("Found BYTE error in TB %d (%02X != %02X), quiting...", tb, data_tx[tb][byte], data_rx[tb][byte]); ret = SRSLTE_ERROR; goto quit; } } } } ret = SRSLTE_SUCCESS; quit: srslte_pmch_free(&pmch_tx); srslte_pmch_free(&pmch_rx); for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { srslte_softbuffer_tx_free(softbuffers_tx[i]); if (softbuffers_tx[i]) { free(softbuffers_tx[i]); } srslte_softbuffer_rx_free(softbuffers_rx[i]); if (softbuffers_rx[i]) { free(softbuffers_rx[i]); } if (data_tx[i]) { free(data_tx[i]); } if (data_rx[i]) { free(data_rx[i]); } } for (i=0;i<SRSLTE_MAX_PORTS;i++) { for (j = 0; j < SRSLTE_MAX_PORTS; j++) { if (ce[i][j]) { free(ce[i][j]); } } if (tx_slot_symbols[i]) { free(tx_slot_symbols[i]); } if (rx_slot_symbols[i]) { free(rx_slot_symbols[i]); } } if (ret) { printf("Error\n"); } else { printf("Ok\n"); } exit(ret); }
int main(int argc, char **argv) { srslte_pdsch_t pdsch; uint32_t i, j; uint8_t *data = NULL; cf_t *ce[SRSLTE_MAX_PORTS]; cf_t *slot_symbols[SRSLTE_MAX_PORTS]; int ret = -1; struct timeval t[3]; srslte_pdsch_cfg_t pdsch_cfg; srslte_softbuffer_tx_t softbuffer_tx; srslte_softbuffer_rx_t softbuffer_rx; uint32_t rv; parse_args(argc,argv); bzero(&pdsch, sizeof(srslte_pdsch_t)); bzero(&pdsch_cfg, sizeof(srslte_pdsch_cfg_t)); bzero(ce, sizeof(cf_t*)*SRSLTE_MAX_PORTS); bzero(slot_symbols, sizeof(cf_t*)*SRSLTE_MAX_PORTS); bzero(&softbuffer_rx, sizeof(srslte_softbuffer_rx_t)); bzero(&softbuffer_tx, sizeof(srslte_softbuffer_tx_t)); srslte_ra_dl_grant_t grant; grant.mcs.tbs = tbs; grant.mcs.mod = modulation; grant.Qm = srslte_mod_bits_x_symbol(grant.mcs.mod); grant.nof_prb = cell.nof_prb; // Allocate all PRB for (i=0;i<grant.nof_prb;i++) { grant.prb_idx[0][i] = true; } memcpy(&grant.prb_idx[1], &grant.prb_idx[0], SRSLTE_MAX_PRB * sizeof(bool)); /* Configure PDSCH */ if (srslte_pdsch_cfg(&pdsch_cfg, cell, &grant, cfi, subframe, 1234, 0)) { fprintf(stderr, "Error configuring PDSCH\n"); exit(-1); } /* init memory */ for (i=0;i<cell.nof_ports;i++) { ce[i] = malloc(sizeof(cf_t) * SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp)); if (!ce[i]) { perror("malloc"); goto quit; } for (j=0;j<SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp);j++) { ce[i][j] = 1; } slot_symbols[i] = calloc(sizeof(cf_t) , SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp)); if (!slot_symbols[i]) { perror("malloc"); goto quit; } } data = malloc(sizeof(uint8_t) * tbs/8); if (!data) { perror("malloc"); goto quit; } if (srslte_pdsch_init(&pdsch, cell)) { fprintf(stderr, "Error creating PDSCH object\n"); goto quit; } srslte_pdsch_set_rnti(&pdsch, 1234); if (srslte_softbuffer_tx_init(&softbuffer_tx, cell.nof_prb)) { fprintf(stderr, "Error initiating TX soft buffer\n"); goto quit; } if (srslte_softbuffer_rx_init(&softbuffer_rx, cell.nof_prb)) { fprintf(stderr, "Error initiating RX soft buffer\n"); goto quit; } if (SRSLTE_VERBOSE_ISNONE()) { printf("Decoding TBS: %d\r",grant.mcs.tbs); } for (i=0;i<grant.mcs.tbs/8;i++) { data[i] = rand()%256; } for (rv=0;rv<=rv_idx;rv++) { pdsch_cfg.rv = rv; if (srslte_pdsch_encode(&pdsch, &pdsch_cfg, &softbuffer_tx, data, slot_symbols)) { fprintf(stderr, "Error encoding PDSCH\n"); goto quit; } /* combine outputs */ for (i=0;i<cell.nof_ports;i++) { for (j=0;j<SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp);j++) { if (i > 0) { slot_symbols[0][j] += slot_symbols[i][j]; } ce[i][j] = 1; } } gettimeofday(&t[1], NULL); int r = srslte_pdsch_decode(&pdsch, &pdsch_cfg, &softbuffer_rx, slot_symbols[0], ce, 0, data); gettimeofday(&t[2], NULL); get_time_interval(t); if (r) { printf("Error decoding TBS: %d\n", grant.mcs.tbs); 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) grant.mcs.tbs/t[0].tv_usec); } } ret = 0; quit: srslte_pdsch_free(&pdsch); srslte_softbuffer_tx_free(&softbuffer_tx); srslte_softbuffer_rx_free(&softbuffer_rx); for (i=0;i<cell.nof_ports;i++) { if (ce[i]) { free(ce[i]); } if (slot_symbols[i]) { free(slot_symbols[i]); } } if (data) { free(data); } if (ret) { printf("Error\n"); } else { printf("Ok\n"); } exit(ret); }
/* the gateway function */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { srslte_sch_t ulsch; srslte_pusch_cfg_t cfg; srslte_softbuffer_tx_t softbuffer; srslte_uci_data_t uci_data; bzero(&uci_data, sizeof(srslte_uci_data_t)); uint32_t rv; if (nrhs < NOF_INPUTS) { help(); return; } bzero(&cfg, sizeof(srslte_pusch_cfg_t)); if (srslte_sch_init(&ulsch)) { mexErrMsgTxt("Error initiating ULSCH\n"); return; } srslte_cell_t cell; cell.nof_prb = 100; cell.id=1; cell.cp=SRSLTE_CP_NORM; if (srslte_softbuffer_tx_init(&softbuffer, cell.nof_prb)) { mexErrMsgTxt("Error initiating HARQ\n"); return; } uint8_t *trblkin_bits = NULL; cfg.grant.mcs.tbs = mexutils_read_uint8(TRBLKIN, &trblkin_bits); uint8_t *trblkin = srslte_vec_malloc(cfg.grant.mcs.tbs/8); srslte_bit_unpack_vector(trblkin_bits, trblkin, cfg.grant.mcs.tbs); free(trblkin_bits); uint8_t *tmp; uci_data.uci_cqi_len = mexutils_read_uint8(CQI, &tmp); memcpy(uci_data.uci_cqi, tmp, uci_data.uci_cqi_len); free(tmp); uci_data.uci_ri_len = mexutils_read_uint8(RI, &tmp); if (uci_data.uci_ri_len > 0) { uci_data.uci_ri = *tmp; } free(tmp); uci_data.uci_ack_len = mexutils_read_uint8(ACK, &tmp); if (uci_data.uci_ack_len > 0) { uci_data.uci_ack = *tmp; } free(tmp); mexPrintf("TRBL_len: %d, CQI_len: %d, ACK_len: %d, RI_len: %d\n", cfg.grant.mcs.tbs, uci_data.uci_cqi_len, uci_data.uci_ack_len, uci_data.uci_ri_len); if (mexutils_read_uint32_struct(PUSCHCFG, "RV", &rv)) { mexErrMsgTxt("Field RV not found in pdsch config\n"); return; } float beta; if (mexutils_read_float_struct(PUSCHCFG, "BetaCQI", &beta)) { cfg.uci_cfg.I_offset_cqi = 7; } else { cfg.uci_cfg.I_offset_cqi = srslte_sch_find_Ioffset_cqi(beta); } if (mexutils_read_float_struct(PUSCHCFG, "BetaRI", &beta)) { cfg.uci_cfg.I_offset_ri = 2; } else { cfg.uci_cfg.I_offset_ri = srslte_sch_find_Ioffset_ri(beta); } if (mexutils_read_float_struct(PUSCHCFG, "BetaACK", &beta)) { cfg.uci_cfg.I_offset_ack = 0; } else { cfg.uci_cfg.I_offset_ack = srslte_sch_find_Ioffset_ack(beta); } char *mod_str = mexutils_get_char_struct(PUSCHCFG, "Modulation"); if (!strcmp(mod_str, "QPSK")) { cfg.grant.mcs.mod = SRSLTE_MOD_QPSK; } else if (!strcmp(mod_str, "16QAM")) { cfg.grant.mcs.mod = SRSLTE_MOD_16QAM; } else if (!strcmp(mod_str, "64QAM")) { cfg.grant.mcs.mod = SRSLTE_MOD_64QAM; } else { mexErrMsgTxt("Unknown modulation\n"); return; } mxFree(mod_str); float *prbset; mxArray *p; p = mxGetField(PUSCHCFG, 0, "PRBSet"); if (!p) { mexErrMsgTxt("Error field PRBSet not found\n"); return; } uint32_t N_srs = 0; mexutils_read_uint32_struct(PUSCHCFG, "Shortened", &N_srs); cfg.grant.L_prb = mexutils_read_f(p, &prbset); cfg.grant.n_prb[0] = prbset[0]; cfg.grant.n_prb[1] = prbset[0]; free(prbset); cfg.grant.L_prb = mexutils_read_f(p, &prbset); cfg.grant.n_prb[0] = prbset[0]; cfg.grant.n_prb[1] = prbset[0]; cfg.nbits.lstart = 0; cfg.nbits.nof_symb = 2*(SRSLTE_CP_NSYMB(cell.cp)-1) - N_srs; cfg.grant.M_sc = cfg.grant.L_prb*SRSLTE_NRE; cfg.grant.M_sc_init = cfg.grant.M_sc; // FIXME: What should M_sc_init be? cfg.nbits.nof_re = cfg.nbits.nof_symb*cfg.grant.M_sc; cfg.grant.Qm = srslte_mod_bits_x_symbol(cfg.grant.mcs.mod); cfg.nbits.nof_bits = cfg.nbits.nof_re * cfg.grant.Qm; mexPrintf("Q_m: %d, NPRB: %d, RV: %d, Nsrs=%d\n", srslte_mod_bits_x_symbol(cfg.grant.mcs.mod), cfg.grant.L_prb, cfg.rv, N_srs); mexPrintf("I_cqi: %d, I_ri: %d, I_ack=%d\n", cfg.uci_cfg.I_offset_cqi, cfg.uci_cfg.I_offset_ri, cfg.uci_cfg.I_offset_ack); if (srslte_cbsegm(&cfg.cb_segm, cfg.grant.mcs.tbs)) { mexErrMsgTxt("Error configuring HARQ process\n"); return; } uint8_t *q_bits = srslte_vec_malloc(cfg.nbits.nof_bits * sizeof(uint8_t)); if (!q_bits) { return; } uint8_t *g_bits = srslte_vec_malloc(cfg.nbits.nof_bits * sizeof(uint8_t)); if (!g_bits) { return; } if (srslte_ulsch_uci_encode(&ulsch, &cfg, &softbuffer, trblkin, uci_data, g_bits, q_bits)) { mexErrMsgTxt("Error encoding TB\n"); return; } if (rv > 0) { cfg.rv = rv; if (srslte_ulsch_uci_encode(&ulsch, &cfg, &softbuffer, trblkin, uci_data, g_bits, q_bits)) { mexErrMsgTxt("Error encoding TB\n"); return; } } if (nlhs >= 1) { mexutils_write_uint8(q_bits, &plhs[0], cfg.nbits.nof_bits, 1); } srslte_sch_free(&ulsch); srslte_softbuffer_tx_free(&softbuffer); free(trblkin); free(g_bits); free(q_bits); return; }
int main(int argc, char **argv) { srslte_pusch_t pusch; uint8_t *data = NULL; cf_t *sf_symbols = NULL; cf_t *ce = NULL; int ret = -1; struct timeval t[3]; srslte_pusch_cfg_t cfg; srslte_softbuffer_tx_t softbuffer_tx; srslte_softbuffer_rx_t softbuffer_rx; parse_args(argc,argv); bzero(&cfg, sizeof(srslte_pusch_cfg_t)); srslte_ra_ul_dci_t dci; dci.freq_hop_fl = freq_hop; if (riv < 0) { dci.type2_alloc.L_crb = L_prb; dci.type2_alloc.RB_start = n_prb; } else { dci.type2_alloc.riv = riv; } dci.mcs_idx = mcs_idx; srslte_ra_ul_grant_t grant; if (srslte_ra_ul_dci_to_grant(&dci, cell.nof_prb, 0, &grant, 0)) { fprintf(stderr, "Error computing resource allocation\n"); return ret; } srslte_pusch_hopping_cfg_t ul_hopping; ul_hopping.n_sb = 1; ul_hopping.hopping_offset = 0; ul_hopping.hop_mode = SRSLTE_PUSCH_HOP_MODE_INTER_SF; if (srslte_pusch_init(&pusch, cell)) { fprintf(stderr, "Error creating PDSCH object\n"); goto quit; } /* Configure PUSCH */ printf("Encoding rv_idx=%d\n",rv_idx); srslte_uci_cfg_t uci_cfg; uci_cfg.I_offset_cqi = 6; uci_cfg.I_offset_ri = 2; uci_cfg.I_offset_ack = 4; if (srslte_pusch_cfg(&pusch, &cfg, &grant, &uci_cfg, &ul_hopping, NULL, subframe, 0, 0)) { fprintf(stderr, "Error configuring PDSCH\n"); exit(-1); } srslte_pusch_set_rnti(&pusch, 1234); srslte_uci_data_t uci_data_tx; srslte_uci_data_t uci_data_rx; bzero(&uci_data_tx, sizeof(srslte_uci_data_t)); uci_data_tx.uci_cqi_len = 4; uci_data_tx.uci_ri_len = 0; uci_data_tx.uci_ack_len = 0; memcpy(&uci_data_rx, &uci_data_tx, sizeof(srslte_uci_data_t)); for (uint32_t i=0;i<20;i++) { uci_data_tx.uci_cqi [i] = 1; } uci_data_tx.uci_ri = 1; uci_data_tx.uci_ack = 1; uint32_t nof_re = SRSLTE_NRE*cell.nof_prb*2*SRSLTE_CP_NSYMB(cell.cp); sf_symbols = srslte_vec_malloc(sizeof(cf_t) * nof_re); if (!sf_symbols) { perror("malloc"); exit(-1); } data = srslte_vec_malloc(sizeof(uint8_t) * cfg.grant.mcs.tbs); if (!data) { perror("malloc"); exit(-1); } for (uint32_t i=0;i<cfg.grant.mcs.tbs/8;i++) { data[i] = 1; } if (srslte_softbuffer_tx_init(&softbuffer_tx, 100)) { fprintf(stderr, "Error initiating soft buffer\n"); goto quit; } if (srslte_softbuffer_rx_init(&softbuffer_rx, 100)) { fprintf(stderr, "Error initiating soft buffer\n"); goto quit; } uint32_t ntrials = 100; if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer_tx, data, uci_data_tx, sf_symbols)) { fprintf(stderr, "Error encoding TB\n"); exit(-1); } if (rv_idx > 0) { cfg.rv = rv_idx; if (srslte_pusch_uci_encode(&pusch, &cfg, &softbuffer_tx, data, uci_data_tx, sf_symbols)) { fprintf(stderr, "Error encoding TB\n"); exit(-1); } } ce = srslte_vec_malloc(sizeof(cf_t) * SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp)); if (!ce) { perror("srslte_vec_malloc"); goto quit; } for (int j=0;j<SRSLTE_SF_LEN_RE(cell.nof_prb, cell.cp);j++) { ce[j] = 1; } gettimeofday(&t[1], NULL); int r = srslte_pusch_uci_decode(&pusch, &cfg, &softbuffer_rx, sf_symbols, ce, 0, data, &uci_data_rx); gettimeofday(&t[2], NULL); get_time_interval(t); if (r) { printf("Error decoding\n"); ret = -1; } else { ret = 0; printf("DECODED OK in %d:%d (TBS: %d bits, TX: %.2f Mbps, Processing: %.2f Mbps)\n", (int) t[0].tv_sec, (int) t[0].tv_usec/ntrials, cfg.grant.mcs.tbs, (float) cfg.grant.mcs.tbs/1000, (float) cfg.grant.mcs.tbs/t[0].tv_usec*ntrials); } if (uci_data_tx.uci_ack_len) { if (uci_data_tx.uci_ack != uci_data_rx.uci_ack) { printf("UCI ACK bit error: %d != %d\n", uci_data_tx.uci_ack, uci_data_rx.uci_ack); } } if (uci_data_tx.uci_ri_len) { if (uci_data_tx.uci_ri != uci_data_rx.uci_ri) { printf("UCI RI bit error: %d != %d\n", uci_data_tx.uci_ri, uci_data_rx.uci_ri); } } if (uci_data_tx.uci_cqi_len) { printf("cqi_tx="); srslte_vec_fprint_b(stdout, uci_data_tx.uci_cqi, uci_data_tx.uci_cqi_len); printf("cqi_rx="); srslte_vec_fprint_b(stdout, uci_data_rx.uci_cqi, uci_data_rx.uci_cqi_len); } quit: srslte_pusch_free(&pusch); srslte_softbuffer_tx_free(&softbuffer_tx); if (sf_symbols) { free(sf_symbols); } if (data) { free(data); } if (ce) { free(ce); } if (ret) { printf("Error\n"); } else { printf("Ok\n"); } exit(ret); }