diff --git a/srslte/examples/pdsch_ue.c b/srslte/examples/pdsch_ue.c index a9f48b941..24ffc50a5 100644 --- a/srslte/examples/pdsch_ue.c +++ b/srslte/examples/pdsch_ue.c @@ -89,6 +89,7 @@ typedef struct { uint32_t file_nof_ports; uint32_t file_cell_id; char *rf_args; + uint32_t rf_nof_rx_ant; double rf_freq; float rf_gain; int net_port; @@ -113,6 +114,7 @@ void args_default(prog_args_t *args) { args->file_offset_freq = 0; args->rf_args = ""; args->rf_freq = -1.0; + args->rf_nof_rx_ant = 1; #ifdef ENABLE_AGC_DEFAULT args->rf_gain = -1.0; #else @@ -163,7 +165,7 @@ void usage(prog_args_t *args, char *prog) { void parse_args(prog_args_t *args, int argc, char **argv) { int opt; args_default(args); - while ((opt = getopt(argc, argv, "aoglipPcOCtdDnvrfuUsS")) != -1) { + while ((opt = getopt(argc, argv, "aAoglipPcOCtdDnvrfuUsS")) != -1) { switch (opt) { case 'i': args->input_file_name = argv[optind]; @@ -186,6 +188,9 @@ void parse_args(prog_args_t *args, int argc, char **argv) { case 'a': args->rf_args = argv[optind]; break; + case 'A': + args->rf_nof_rx_ant = atoi(argv[optind]); + break; case 'g': args->rf_gain = atof(argv[optind]); break; @@ -252,10 +257,13 @@ void sig_int_handler(int signo) } } +cf_t *sf_buffer[2] = {NULL, NULL}; + #ifndef DISABLE_RF int srslte_rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return srslte_rf_recv(h, data, nsamples, 1); + void *d[2] = {data, sf_buffer[1]}; + return srslte_rf_recv_with_time_multi(h, d, nsamples, true, NULL, NULL); } double srslte_rf_set_rx_gain_th_wrapper_(void *h, double f) { @@ -273,7 +281,6 @@ srslte_ue_sync_t ue_sync; prog_args_t prog_args; uint32_t sfn = 0; // system frame number -cf_t *sf_buffer = NULL; srslte_netsink_t net_sink, net_sink_signal; int main(int argc, char **argv) { @@ -311,8 +318,8 @@ int main(int argc, char **argv) { #ifndef DISABLE_RF if (!prog_args.input_file_name) { - printf("Opening RF device...\n"); - if (srslte_rf_open(&rf, prog_args.rf_args)) { + printf("Opening RF device with %d RX antennas...\n", prog_args.rf_nof_rx_ant); + if (srslte_rf_open_multi(&rf, prog_args.rf_args, prog_args.rf_nof_rx_ant)) { fprintf(stderr, "Error opening rf\n"); exit(-1); } @@ -356,6 +363,10 @@ int main(int argc, char **argv) { if (go_exit) { exit(0); } + + srslte_rf_stop_rx_stream(&rf); + srslte_rf_flush_buffer(&rf); + /* set sampling frequency */ int srate = srslte_sampling_freq_hz(cell.nof_prb); if (srate != -1) { @@ -375,9 +386,7 @@ int main(int argc, char **argv) { exit(-1); } - INFO("Stopping RF and flushing buffer...\r",0); - srslte_rf_stop_rx_stream(&rf); - srslte_rf_flush_buffer(&rf); + printf("Stopping RF and flushing buffer...\r",0); } #endif @@ -416,6 +425,10 @@ int main(int argc, char **argv) { exit(-1); } + for (int i=0;idev)->name; } -int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args, uint32_t nof_rx_antennas) { +int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args) { + return srslte_rf_open_devname_multi(rf, devname, args, 1); +} + +int srslte_rf_open_devname_multi(srslte_rf_t *rf, char *devname, char *args, uint32_t nof_rx_antennas) { /* Try to open the device if name is provided */ if (devname) { if (devname[0] != '\0') { @@ -117,7 +121,7 @@ int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args, uint32_t /* If in auto mode or provided device not found, try to open in order of apperance in available_devices[] array */ int i=0; while(available_devices[i] != NULL) { - if (!available_devices[i]->srslte_rf_open(args, &rf->handler)) { + if (!available_devices[i]->srslte_rf_open_multi(args, &rf->handler, nof_rx_antennas)) { rf->dev = available_devices[i]; return 0; } @@ -182,12 +186,12 @@ void srslte_rf_register_error_handler(srslte_rf_t *rf, srslte_rf_error_handler_t int srslte_rf_open(srslte_rf_t *h, char *args) { - return srslte_rf_open_devname(h, NULL, args, 1); + return srslte_rf_open_devname_multi(h, NULL, args, 1); } int srslte_rf_open_multi(srslte_rf_t *h, char *args, uint32_t nof_rx_antennas) { - return srslte_rf_open_devname(h, NULL, args, nof_rx_antennas); + return srslte_rf_open_devname_multi(h, NULL, args, nof_rx_antennas); } int srslte_rf_close(srslte_rf_t *rf) diff --git a/srslte/lib/rf/rf_uhd_imp.c b/srslte/lib/rf/rf_uhd_imp.c index ba02db6c8..cc237370a 100644 --- a/srslte/lib/rf/rf_uhd_imp.c +++ b/srslte/lib/rf/rf_uhd_imp.c @@ -177,10 +177,17 @@ void rf_uhd_set_rx_cal(void *h, srslte_rf_cal_t *cal) int rf_uhd_start_rx_stream(void *h) { rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; + uhd_stream_cmd_t stream_cmd = { .stream_mode = UHD_STREAM_MODE_START_CONTINUOUS, - .stream_now = true - }; + .stream_now = false + }; + uhd_usrp_get_time_now(handler->usrp, 0, &stream_cmd.time_spec_full_secs, &stream_cmd.time_spec_frac_secs); + stream_cmd.time_spec_frac_secs += 0.5; + if (stream_cmd.time_spec_frac_secs > 1) { + stream_cmd.time_spec_frac_secs -= 1; + stream_cmd.time_spec_full_secs += 1; + } uhd_rx_streamer_issue_stream_cmd(handler->rx_stream, &stream_cmd); return 0; } @@ -199,9 +206,11 @@ int rf_uhd_stop_rx_stream(void *h) void rf_uhd_flush_buffer(void *h) { int n; - cf_t tmp[1024]; + cf_t tmp1[1024]; + cf_t tmp2[1024]; + void *data[2] = {tmp1, tmp2}; do { - n = rf_uhd_recv_with_time(h, tmp, 1024, 0, NULL, NULL); + n = rf_uhd_recv_with_time_multi(h, data, 1024, 0, NULL, NULL); } while (n > 0); } @@ -505,6 +514,9 @@ int rf_uhd_recv_with_time(void *h, return rf_uhd_recv_with_time_multi(h, &data, nsamples, blocking, secs, frac_secs); } +cf_t data1[1024*100]; +cf_t data2[1024*100]; + int rf_uhd_recv_with_time_multi(void *h, void **data, uint32_t nsamples, @@ -514,13 +526,13 @@ int rf_uhd_recv_with_time_multi(void *h, { rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; - size_t rxd_samples[4]; + size_t rxd_samples; uhd_rx_metadata_handle *md = &handler->rx_md_first; int trials = 0; if (blocking) { int n = 0; do { - size_t rx_samples = handler->rx_nof_samples; + size_t rx_samples = nsamples; if (rx_samples > nsamples - n) { rx_samples = nsamples - n; @@ -528,22 +540,22 @@ int rf_uhd_recv_with_time_multi(void *h, void *buffs_ptr[4]; for (int i=0;inof_rx_channels;i++) { cf_t *data_c = (cf_t*) data[i]; - buffs_ptr[i] = &data_c[n]; + buffs_ptr[i] = &data_c[n]; } + uhd_error error = uhd_rx_streamer_recv(handler->rx_stream, buffs_ptr, - rx_samples, md, 1.0, false, rxd_samples); - + rx_samples, md, 1.0, false, &rxd_samples); if (error) { fprintf(stderr, "Error receiving from UHD: %d\n", error); return -1; } md = &handler->rx_md; - n += rxd_samples[0]; + n += rxd_samples; trials++; } while (n < nsamples && trials < 100); } else { return uhd_rx_streamer_recv(handler->rx_stream, data, - nsamples, md, 0.0, false, rxd_samples); + nsamples, md, 0.0, false, &rxd_samples); } if (secs && frac_secs) { uhd_rx_metadata_time_spec(handler->rx_md_first, secs, frac_secs); diff --git a/srslte/lib/rf/rf_utils.c b/srslte/lib/rf/rf_utils.c index 066b9a2b3..0d5c8a529 100644 --- a/srslte/lib/rf/rf_utils.c +++ b/srslte/lib/rf/rf_utils.c @@ -82,10 +82,11 @@ free_and_exit: return ret; } - +cf_t data2[1920*160]; int srslte_rf_recv_wrapper_cs(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) { DEBUG(" ---- Receive %d samples ---- \n", nsamples); - return srslte_rf_recv(h, data, nsamples, 1); + void *d[2] = {data, data2}; + return srslte_rf_recv_with_time_multi(h, d, nsamples, 1, NULL, NULL); } double srslte_rf_set_rx_gain_th_wrapper(void *h, double f) {