int base_init() { int i; if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) { fprintf(stderr, "Error opening file %s\n", input_file_name); exit(-1); } flen = 2 * (SLOT_LEN(lte_symbol_sz(cell.nof_prb))); input_buffer = malloc(flen * sizeof(cf_t)); if (!input_buffer) { perror("malloc"); exit(-1); } fft_buffer = malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!fft_buffer) { perror("malloc"); return -1; } for (i=0;i<MAX_PORTS;i++) { ce[i] = malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!ce[i]) { perror("malloc"); return -1; } } if (chest_dl_init(&chest, cell)) { fprintf(stderr, "Error initializing equalizer\n"); return -1; } if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) { fprintf(stderr, "Error initializing FFT\n"); return -1; } if (regs_init(®s, cell)) { fprintf(stderr, "Error initiating regs\n"); return -1; } if (regs_set_cfi(®s, cfi)) { fprintf(stderr, "Error setting CFI %d\n", cfi); return -1; } if (pdcch_init(&pdcch, ®s, cell)) { fprintf(stderr, "Error creating PDCCH object\n"); exit(-1); } DEBUG("Memory init OK\n",0); return 0; }
int main(int argc, char **argv) { int nf, sf_idx, N_id_2; cf_t pss_signal[PSS_LEN]; float sss_signal0[SSS_LEN]; // for subframe 0 float sss_signal5[SSS_LEN]; // for subframe 5 pbch_mib_t mib; ra_pdsch_t ra_dl; ra_prb_t prb_alloc; refsignal_t refs[NSLOTS_X_FRAME]; int i, n; char *data; cf_t *sf_symbols[MAX_PORTS]; dci_msg_t dci_msg; dci_location_t locations[NSUBFRAMES_X_FRAME][10]; #ifdef DISABLE_UHD if (argc < 3) { usage(argv[0]); exit(-1); } #endif parse_args(argc, argv); N_id_2 = cell.id % 3; sf_n_re = 2 * CPNORM_NSYMB * cell.nof_prb * RE_X_RB; sf_n_samples = 2 * SLOT_LEN(lte_symbol_sz(cell.nof_prb)); /* this *must* be called after setting slot_len_* */ base_init(); /* Generate PSS/SSS signals */ pss_generate(pss_signal, N_id_2); sss_generate(sss_signal0, sss_signal5, cell.id); /* Generate CRS signals */ for (i = 0; i < NSLOTS_X_FRAME; i++) { if (refsignal_init_LTEDL(&refs[i], 0, i, cell)) { fprintf(stderr, "Error initiating CRS slot=%d\n", i); return -1; } } mib.nof_ports = cell.nof_ports; mib.nof_prb = cell.nof_prb; mib.phich_length = PHICH_NORM; mib.phich_resources = R_1; mib.sfn = 0; for (i = 0; i < MAX_PORTS; i++) { // now there's only 1 port sf_symbols[i] = sf_buffer; } #ifndef DISABLE_UHD if (!output_file_name) { printf("Set TX rate: %.2f MHz\n", cuhd_set_tx_srate(uhd, lte_sampling_freq_hz(cell.nof_prb)) / 1000000); printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain)); printf("Set TX freq: %.2f MHz\n", cuhd_set_tx_freq(uhd, uhd_freq) / 1000000); } #endif bzero(&ra_dl, sizeof(ra_pdsch_t)); ra_dl.harq_process = 0; ra_dl.mcs_idx = mcs_idx; ra_dl.ndi = 0; ra_dl.rv_idx = 0; ra_dl.alloc_type = alloc_type0; ra_dl.type0_alloc.rbg_bitmask = 0xffffffff; dci_msg_pack_pdsch(&ra_dl, &dci_msg, Format1, cell.nof_prb, false); ra_prb_get_dl(&prb_alloc, &ra_dl, cell.nof_prb); ra_prb_get_re_dl(&prb_alloc, cell.nof_prb, 1, cell.nof_prb<10?(cfi+1):cfi, CPNORM); ra_mcs_from_idx_dl(mcs_idx, cell.nof_prb, &ra_dl.mcs); ra_pdsch_fprint(stdout, &ra_dl, cell.nof_prb); /* Initiate valid DCI locations */ for (i=0;i<NSUBFRAMES_X_FRAME;i++) { pdcch_ue_locations(&pdcch, locations[i], 10, i, cfi, 1234); } data = malloc(sizeof(char) * ra_dl.mcs.tbs); if (!data) { perror("malloc"); exit(-1); } nf = 0; if (pdsch_harq_setup(&harq_process, ra_dl.mcs, &prb_alloc)) { fprintf(stderr, "Error configuring HARQ process\n"); exit(-1); } while (nf < nof_frames || nof_frames == -1) { for (sf_idx = 0; sf_idx < NSUBFRAMES_X_FRAME && (nf < nof_frames || nof_frames == -1); sf_idx++) { bzero(sf_buffer, sizeof(cf_t) * sf_n_re); if (sf_idx == 0 || sf_idx == 5) { pss_put_slot(pss_signal, sf_buffer, cell.nof_prb, CPNORM); sss_put_slot(sf_idx ? sss_signal5 : sss_signal0, sf_buffer, cell.nof_prb, CPNORM); } if (sf_idx == 0) { pbch_encode(&pbch, &mib, sf_symbols); } for (n=0;n<2;n++) { refsignal_put(&refs[2*sf_idx+n], &sf_buffer[n*sf_n_re/2]); } pcfich_encode(&pcfich, cfi, sf_symbols, sf_idx); INFO("SF: %d, Generating %d random bits\n", sf_idx, ra_dl.mcs.tbs); for (i=0;i<ra_dl.mcs.tbs;i++) { data[i] = rand()%2; } INFO("Puttting DCI to location: n=%d, L=%d\n", locations[sf_idx][0].ncce, locations[sf_idx][0].L); if (pdcch_encode(&pdcch, &dci_msg, locations[sf_idx][0], 1234, sf_symbols, sf_idx, cfi)) { fprintf(stderr, "Error encoding DCI message\n"); exit(-1); } if (pdsch_encode(&pdsch, data, sf_symbols, sf_idx, &harq_process, ra_dl.rv_idx)) { fprintf(stderr, "Error encoding PDSCH\n"); exit(-1); } /* Transform to OFDM symbols */ lte_ifft_run_sf(&ifft, sf_buffer, output_buffer); /* send to file or usrp */ if (output_file_name) { filesink_write(&fsink, output_buffer, sf_n_samples); usleep(5000); } else { #ifndef DISABLE_UHD vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, sf_n_samples); cuhd_send(uhd, output_buffer, sf_n_samples, true); #endif } nf++; } mib.sfn = (mib.sfn + 1) % 1024; printf("SFN: %4d\r", mib.sfn); fflush(stdout); } base_free(); printf("Done\n"); exit(0); }
int main(int argc, char **argv) { cf_t *input_buffer, *sf_symbols = NULL; int frame_cnt; ue_sync_t s; int pos; pss_synch_t pss; float peak; struct timeval t[3]; float mean_ce_time=0; bool signal_detected; lte_fft_t fft; lte_cell_t cell; bzero(&cell, sizeof(lte_cell_t)); parse_args(argc, argv); #ifndef DISABLE_GRAPHICS if (!disable_plots) { init_plots(); } #endif input_init(); if (ue_sync_init(&s, cuhd_set_rx_srate, cuhd_recv_wrapper, uhd)) { fprintf(stderr, "Error initiating UE sync module\n"); exit(-1); } ue_sync_pbch_enable(&s, true); signal_detected = true; frame_cnt = 0; mean_ce_time=0; uint32_t valid_frames=0; //uint32_t unaligned = 0; while (frame_cnt < nof_frames || nof_frames == -1) { int n = ue_sync_get_buffer(&s, &input_buffer); if (n < 0) { fprintf(stderr, "Error calling sync work()\n"); exit(-1); } if (n == 1 && ue_sync_get_sfidx(&s) == 0) { if (signal_detected) { cell = ue_sync_get_cell(&s); pss_synch_init_fft(&pss, SF_LEN(lte_symbol_sz(cell.nof_prb), cell.cp), lte_symbol_sz(cell.nof_prb)); pss_synch_set_N_id_2(&pss, cell.id%3); sf_symbols = vec_malloc(SLOT_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!sf_symbols) { perror("malloc"); exit(-1); } lte_fft_init(&fft, cell.cp, cell.nof_prb); signal_detected = false; } mean_ce_time = (float) (mean_ce_time + (float) t[0].tv_usec * valid_frames) / (valid_frames+1); valid_frames++; #ifndef DISABLE_GRAPHICS if (!disable_plots && !(valid_frames % 5) && sf_symbols) { /* Run FFT for the second slot */ lte_fft_run_slot(&fft, input_buffer, sf_symbols); int i; int nof_re = SLOT_LEN_RE(cell.nof_prb, cell.cp); for (i = 0; i < nof_re; i++) { tmp_plot[i] = 10 * log10f(cabsf(sf_symbols[i])); if (isinf(tmp_plot[i])) { tmp_plot[i] = -80; } } plot_real_setNewData(&poutfft, tmp_plot, nof_re); } #endif pos = pss_synch_find_pss(&pss, input_buffer, &peak, NULL); /*if (pos > 962 || pos < 958) { unaligned++; } */ printf("CELL_ID: %3d CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Exec: %3.2f\r", cell.id, ue_sync_get_cfo(&s)/1000, ue_sync_get_sfo(&s)/1000, pos, s.mean_exec_time); fflush(stdout); if (VERBOSE_ISINFO()) { printf("\n"); } } frame_cnt++; } printf("\nBye\n"); exit(0); }
int base_init() { int i; if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) { fprintf(stderr, "Error opening file %s\n", input_file_name); exit(-1); } if (matlab_file_name) { fmatlab = fopen(matlab_file_name, "w"); if (!fmatlab) { perror("fopen"); return -1; } } else { fmatlab = NULL; } flen = SLOT_LEN(lte_symbol_sz(cell.nof_prb)); input_buffer = malloc(flen * sizeof(cf_t)); if (!input_buffer) { perror("malloc"); exit(-1); } fft_buffer = malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!fft_buffer) { perror("malloc"); return -1; } for (i=0;i<MAX_PORTS;i++) { ce[i] = malloc(SF_LEN_RE(cell.nof_prb, cell.cp) * sizeof(cf_t)); if (!ce[i]) { perror("malloc"); return -1; } } if (chest_dl_init(&chest, cell)) { fprintf(stderr, "Error initializing equalizer\n"); return -1; } if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) { fprintf(stderr, "Error initializing FFT\n"); return -1; } if (regs_init(®s, cell)) { fprintf(stderr, "Error initiating REGs\n"); return -1; } if (pcfich_init(&pcfich, ®s, cell)) { fprintf(stderr, "Error creating PBCH object\n"); return -1; } DEBUG("Memory init OK\n",0); return 0; }
int main(int argc, char **argv) { int nf, ns, N_id_2; cf_t pss_signal[PSS_LEN]; float sss_signal0[SSS_LEN]; // for subframe 0 float sss_signal5[SSS_LEN]; // for subframe 5 pbch_mib_t mib; refsignal_t refs[NSLOTS_X_FRAME]; int i; cf_t *slot1_symbols[MAX_PORTS_CTRL]; #ifdef DISABLE_UHD if (argc < 3) { usage(argv[0]); exit(-1); } #endif parse_args(argc,argv); N_id_2 = cell_id%3; slot_n_re = CPNORM_NSYMB * nof_prb * RE_X_RB; slot_n_samples = SLOT_LEN_CPNORM(lte_symbol_sz(nof_prb)); /* this *must* be called after setting slot_len_* */ base_init(); /* Generate PSS/SSS signals */ pss_generate(pss_signal, N_id_2); sss_generate(sss_signal0, sss_signal5, cell_id); /* Generate CRS signals */ for (i=0;i<NSLOTS_X_FRAME;i++) { if (refsignal_init_LTEDL(&refs[i], 0, i, cell_id, CPNORM, nof_prb)) { fprintf(stderr, "Error initiating CRS slot=%d\n", i); return -1; } } mib.nof_ports = 1; mib.nof_prb = 6; mib.phich_length = PHICH_NORM; mib.phich_resources = R_1; mib.sfn = 0; for (i=0;i<MAX_PORTS_CTRL;i++) { // now there's only 1 port slot1_symbols[i] = slot_buffer; } #ifndef DISABLE_UHD if (!output_file_name) { printf("Set TX rate: %.2f MHz\n", cuhd_set_tx_srate(uhd, UHD_SAMP_FREQ)/1000000); printf("Set TX gain: %.1f dB\n", cuhd_set_tx_gain(uhd, uhd_gain)); printf("Set TX freq: %.2f MHz\n", cuhd_set_tx_freq(uhd, uhd_freq)/1000000); } #endif nf = 0; while(nf<nof_frames || nof_frames == -1) { for (ns=0;ns<NSLOTS_X_FRAME;ns++) { bzero(slot_buffer, sizeof(cf_t) * slot_n_re); switch(ns) { case 0: // tx pss/sss case 10: // tx pss/sss pss_put_slot(pss_signal, slot_buffer, nof_prb, CPNORM); sss_put_slot(ns?sss_signal5:sss_signal0, slot_buffer, nof_prb, CPNORM); break; case 1: // tx pbch pbch_encode(&pbch, &mib, slot1_symbols, 1); break; default: // transmit zeros break; } refsignal_put(&refs[ns], slot_buffer); /* Transform to OFDM symbols */ lte_ifft_run(&ifft, slot_buffer, output_buffer); /* send to file or usrp */ if (output_file_name) { filesink_write(&fsink, output_buffer, slot_n_samples); usleep(5000); } else { #ifndef DISABLE_UHD vec_sc_prod_cfc(output_buffer, uhd_amp, output_buffer, slot_n_samples); cuhd_send(uhd, output_buffer, slot_n_samples, 1); #endif } } mib.sfn=(mib.sfn+1)%1024; printf("SFN: %4d\r", mib.sfn);fflush(stdout); nf++; } base_free(); printf("Done\n"); exit(0); }
int base_init() { int i; if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) { fprintf(stderr, "Error opening file %s\n", input_file_name); exit(-1); } if (matlab_file_name) { fmatlab = fopen(matlab_file_name, "w"); if (!fmatlab) { perror("fopen"); return -1; } } else { fmatlab = NULL; } flen = 2 * (SLOT_LEN(lte_symbol_sz(cell.nof_prb))); input_buffer = malloc(flen * sizeof(cf_t)); if (!input_buffer) { perror("malloc"); exit(-1); } fft_buffer = malloc(2 * CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB * sizeof(cf_t)); if (!fft_buffer) { perror("malloc"); return -1; } for (i=0;i<MAX_PORTS;i++) { ce[i] = malloc(2 * CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB * sizeof(cf_t)); if (!ce[i]) { perror("malloc"); return -1; } } if (chest_init_LTEDL(&chest, cell)) { fprintf(stderr, "Error initializing equalizer\n"); return -1; } if (lte_fft_init(&fft, cell.cp, cell.nof_prb)) { fprintf(stderr, "Error initializing FFT\n"); return -1; } if (regs_init(®s, R_1, PHICH_NORM, cell)) { fprintf(stderr, "Error initiating regs\n"); return -1; } if (regs_set_cfi(®s, cfi)) { fprintf(stderr, "Error setting CFI %d\n", cfi); return -1; } if (pdcch_init(&pdcch, ®s, cell)) { fprintf(stderr, "Error creating PDCCH object\n"); exit(-1); } if (pdsch_init(&pdsch, cell)) { fprintf(stderr, "Error creating PDSCH object\n"); exit(-1); } pdsch_set_rnti(&pdsch, rnti); if (pdsch_harq_init(&harq_process, &pdsch)) { fprintf(stderr, "Error initiating HARQ process\n"); exit(-1); } DEBUG("Memory init OK\n",0); return 0; }
int base_init() { int i; if (filesource_init(&fsrc, input_file_name, COMPLEX_FLOAT_BIN)) { fprintf(stderr, "Error opening file %s\n", input_file_name); exit(-1); } if (matlab_file_name) { fmatlab = fopen(matlab_file_name, "w"); if (!fmatlab) { perror("fopen"); return -1; } } else { fmatlab = NULL; } flen = SLOT_LEN(lte_symbol_sz(nof_prb), cp); input_buffer = malloc(flen * sizeof(cf_t)); if (!input_buffer) { perror("malloc"); exit(-1); } fft_buffer = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t)); if (!fft_buffer) { perror("malloc"); return -1; } for (i=0;i<MAX_PORTS_CTRL;i++) { ce[i] = malloc(CP_NSYMB(cp) * nof_prb * RE_X_RB * sizeof(cf_t)); if (!ce[i]) { perror("malloc"); return -1; } } if (chest_init(&chest, LINEAR, cp, nof_prb, nof_ports)) { fprintf(stderr, "Error initializing equalizer\n"); return -1; } if (chest_ref_LTEDL(&chest, cell_id)) { fprintf(stderr, "Error initializing reference signal\n"); return -1; } if (lte_fft_init(&fft, cp, nof_prb)) { fprintf(stderr, "Error initializing FFT\n"); return -1; } if (regs_init(®s, cell_id, nof_prb, nof_ports, phich_res, phich_length, cp)) { fprintf(stderr, "Error initiating regs\n"); return -1; } if (phich_init(&phich, ®s, cell_id, nof_prb, nof_ports, cp)) { fprintf(stderr, "Error creating PBCH object\n"); return -1; } DEBUG("Memory init OK\n",0); return 0; }
/* Setup USRP or input file */ int iodev_init(iodev_t *q, iodev_cfg_t *config, lte_cell_t *cell, pbch_mib_t *mib) { if (config->input_file_name) { mib->phich_resources = R_1; mib->phich_length = PHICH_NORM; cell->id = config->cell_id_file; cell->cp = CPNORM; cell->nof_ports = config->nof_ports_file; cell->nof_prb = config->nof_prb_file; if (filesource_init(&q->fsrc, config->input_file_name, COMPLEX_FLOAT_BIN)) { return LIBLTE_ERROR; } q->mode = FILESOURCE; int symbol_sz = lte_symbol_sz(cell->nof_prb); if (symbol_sz > 0) { q->sf_len = SF_LEN(symbol_sz); } else { fprintf(stderr, "Invalid number of PRB %d\n", cell->nof_prb); return LIBLTE_ERROR; } q->input_buffer_file = vec_malloc(q->sf_len * sizeof(cf_t)); if (!q->input_buffer_file) { perror("malloc"); return LIBLTE_ERROR; } q->sf_idx = 9; } else { #ifndef DISABLE_UHD printf("Opening UHD device...\n"); if (cuhd_open(config->uhd_args, &q->uhd)) { fprintf(stderr, "Error opening uhd\n"); return LIBLTE_ERROR; } cuhd_set_rx_gain(q->uhd, config->uhd_gain); /* set receiver frequency */ cuhd_set_rx_freq(q->uhd, (double) config->uhd_freq); cuhd_rx_wait_lo_locked(q->uhd); DEBUG("Set uhd_freq to %.3f MHz\n", (double ) config->uhd_freq); int n; ue_celldetect_t cd; ue_celldetect_result_t found_cells[3]; cf_t *buffer = vec_malloc(sizeof(cf_t) * 96000); if (!buffer) { perror("malloc"); return LIBLTE_ERROR; } if (ue_celldetect_init(&cd)) { fprintf(stderr, "Error initiating UE cell detect\n"); exit(-1); } n = find_cell(q->uhd, &cd, buffer, found_cells); if (n < 0) { fprintf(stderr, "Error searching cell\n"); exit(-1); } int max_peak_cell = 0; float max_peak_value = -1.0; if (n > 0) { for (int i=0;i<3;i++) { if (found_cells[i].peak > max_peak_value) { max_peak_value = found_cells[i].peak; max_peak_cell = i; } } if (decode_pbch(q->uhd, buffer, &found_cells[max_peak_cell], 400, mib)) { fprintf(stderr, "Could not decode PBCH from CELL ID %d\n", found_cells[max_peak_cell].cell_id); return LIBLTE_ERROR; } } else { fprintf(stderr, "Could not find any cell in this frequency\n"); return LIBLTE_ERROR; } free(buffer); cell->cp = found_cells[max_peak_cell].cp; cell->id = found_cells[max_peak_cell].cell_id; cell->nof_prb = mib->nof_prb; cell->nof_ports = mib->nof_ports; /* set sampling frequency */ int srate = lte_sampling_freq_hz(cell->nof_prb); if (srate != -1) { cuhd_set_rx_srate(q->uhd, (double) srate); } else { fprintf(stderr, "Invalid number of PRB %d\n", cell->nof_prb); return LIBLTE_ERROR; } DEBUG("Starting receiver...\n", 0); cuhd_start_rx_stream(q->uhd); if (ue_sync_init(&q->sframe, *cell, cuhd_recv_wrapper, q->uhd)) { fprintf(stderr, "Error initiating ue_sync\n"); return LIBLTE_ERROR; } /* Decodes the SSS signal during the tracking phase. Extra overhead, but makes sure we are in the correct subframe */ ue_sync_decode_sss_on_track(&q->sframe, true); // Here, the subframe length and input buffer is managed by ue_sync q->mode = UHD; #else printf("Error UHD not available. Select an input file\n"); return LIBLTE_ERROR; #endif } memcpy(&q->config, config, sizeof(iodev_cfg_t)); return LIBLTE_SUCCESS; }