start_rx_stream delays the start to avoid filling buffers. Started adapting pdsch_ue to 2 antennas

master
Ismael Gomez 8 years ago
parent eb110f26c6
commit b2389efe47

@ -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;i<prog_args.rf_nof_rx_ant;i++) {
sf_buffer[i] = srslte_vec_malloc(3*sizeof(cf_t)*SRSLTE_SF_LEN_PRB(cell.nof_prb));
}
/* Configure downlink receiver for the SI-RNTI since will be the only one we'll use */
srslte_ue_dl_set_rnti(&ue_dl, prog_args.rnti);
@ -458,11 +471,11 @@ int main(int argc, char **argv) {
srslte_pbch_decode_reset(&ue_mib.pbch);
INFO("\nEntering main loop...\n\n", 0);
printf("\nEntering main loop...\n\n", 0);
/* Main loop */
while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) {
ret = srslte_ue_sync_get_buffer(&ue_sync, &sf_buffer);
ret = srslte_ue_sync_zerocopy(&ue_sync, sf_buffer[0]);
if (ret < 0) {
fprintf(stderr, "Error calling srslte_ue_sync_work()\n");
}
@ -477,7 +490,7 @@ int main(int argc, char **argv) {
switch (state) {
case DECODE_MIB:
if (srslte_ue_sync_get_sfidx(&ue_sync) == 0) {
n = srslte_ue_mib_decode(&ue_mib, sf_buffer, bch_payload, NULL, &sfn_offset);
n = srslte_ue_mib_decode(&ue_mib, sf_buffer[0], bch_payload, NULL, &sfn_offset);
if (n < 0) {
fprintf(stderr, "Error decoding UE MIB\n");
exit(-1);
@ -504,7 +517,7 @@ int main(int argc, char **argv) {
if (decode_pdsch) {
INFO("Attempting DL decode SFN=%d\n", sfn);
n = srslte_ue_dl_decode(&ue_dl,
&sf_buffer[prog_args.time_offset],
sf_buffer[0],
data,
sfn*10+srslte_ue_sync_get_sfidx(&ue_sync));

@ -71,7 +71,15 @@ typedef void (*srslte_rf_error_handler_t)(srslte_rf_error_t error);
SRSLTE_API int srslte_rf_open(srslte_rf_t *h,
char *args);
SRSLTE_API int srslte_rf_open_multi(srslte_rf_t *h,
char *args,
uint32_t nof_rx_antennas);
SRSLTE_API int srslte_rf_open_devname(srslte_rf_t *h,
char *devname,
char *args);
SRSLTE_API int srslte_rf_open_devname_multi(srslte_rf_t *h,
char *devname,
char *args,
uint32_t nof_rx_antennas);

@ -98,7 +98,11 @@ const char* srslte_rf_get_devname(srslte_rf_t *rf) {
return ((rf_dev_t*) rf->dev)->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)

@ -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;
@ -530,20 +542,20 @@ int rf_uhd_recv_with_time_multi(void *h,
cf_t *data_c = (cf_t*) data[i];
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);
uhd_error error = uhd_rx_streamer_recv(handler->rx_stream, buffs_ptr,
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);

@ -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) {

Loading…
Cancel
Save