Added prach detection to prach_test_usrp. Added full device names to RF objects

master
Ismael Gomez 8 years ago
parent c58f1c9edc
commit 60e77144ca

@ -155,7 +155,7 @@ SRSLTE_API int srslte_prach_detect_offset(srslte_prach_t *p,
uint32_t sig_len, uint32_t sig_len,
uint32_t *indices, uint32_t *indices,
float *t_offsets, float *t_offsets,
float *peak_to_avg, float *peak_to_avg,
uint32_t *ind_len); uint32_t *ind_len);
SRSLTE_API void srslte_prach_set_detect_factor(srslte_prach_t *p, SRSLTE_API void srslte_prach_set_detect_factor(srslte_prach_t *p,

@ -45,10 +45,10 @@ uint32_t root_seq_idx = 0;
uint32_t seq_idx = 0; uint32_t seq_idx = 0;
uint32_t frequency_offset = 0; uint32_t frequency_offset = 0;
uint32_t zero_corr_zone = 11; uint32_t zero_corr_zone = 11;
uint32_t timeadv = 0; float timeadv = 0;
uint32_t nof_frames = 20; uint32_t nof_frames = 20;
float uhd_gain=40, uhd_freq=2.4e9; float uhd_rx_gain=40, uhd_tx_gain=60, uhd_freq=2.4e9;
char *uhd_args=""; char *uhd_args="";
char *output_filename = "prach_rx"; char *output_filename = "prach_rx";
@ -56,20 +56,21 @@ void usage(char *prog) {
printf("Usage: %s \n", prog); printf("Usage: %s \n", prog);
printf("\t-a UHD args [Default %s]\n", uhd_args); printf("\t-a UHD args [Default %s]\n", uhd_args);
printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6); printf("\t-f UHD TX/RX frequency [Default %.2f MHz]\n", uhd_freq/1e6);
printf("\t-g UHD TX/RX gain [Default %.1f dB]\n", uhd_gain); printf("\t-g UHD RX gain [Default %.1f dB]\n", uhd_rx_gain);
printf("\t-G UHD TX gain [Default %.1f dB]\n", uhd_tx_gain);
printf("\t-p Number of UL RB [Default %d]\n", nof_prb); printf("\t-p Number of UL RB [Default %d]\n", nof_prb);
printf("\t-F Preamble format [Default %d]\n", preamble_format); printf("\t-F Preamble format [Default %d]\n", preamble_format);
printf("\t-O Frequency offset [Default %d]\n", frequency_offset); printf("\t-O Frequency offset [Default %d]\n", frequency_offset);
printf("\t-s sequence index [Default %d]\n", seq_idx); printf("\t-s sequence index [Default %d]\n", seq_idx);
printf("\t-r Root sequence index [Default %d]\n", root_seq_idx); printf("\t-r Root sequence index [Default %d]\n", root_seq_idx);
printf("\t-t Time advance (us) [Default %d]\n", timeadv); printf("\t-t Time advance (us) [Default %.1f us]\n", timeadv);
printf("\t-z Zero correlation zone config [Default %d]\n", zero_corr_zone); printf("\t-z Zero correlation zone config [Default %d]\n", zero_corr_zone);
printf("\t-o Save transmitted PRACH in file [Default no]\n"); printf("\t-o Save transmitted PRACH in file [Default no]\n");
} }
void parse_args(int argc, char **argv) { void parse_args(int argc, char **argv) {
int opt; int opt;
while ((opt = getopt(argc, argv, "apfFgrstoPOz")) != -1) { while ((opt = getopt(argc, argv, "apfFgGrstoPOz")) != -1) {
switch (opt) { switch (opt) {
case 'a': case 'a':
uhd_args = argv[optind]; uhd_args = argv[optind];
@ -81,7 +82,10 @@ void parse_args(int argc, char **argv) {
uhd_freq = atof(argv[optind]); uhd_freq = atof(argv[optind]);
break; break;
case 'g': case 'g':
uhd_gain = atof(argv[optind]); uhd_rx_gain = atof(argv[optind]);
break;
case 'G':
uhd_tx_gain = atof(argv[optind]);
break; break;
case 'P': case 'P':
preamble_format = atoi(argv[optind]); preamble_format = atoi(argv[optind]);
@ -90,7 +94,7 @@ void parse_args(int argc, char **argv) {
frequency_offset = atoi(argv[optind]); frequency_offset = atoi(argv[optind]);
break; break;
case 't': case 't':
timeadv = atoi(argv[optind]); timeadv = atof(argv[optind]);
break; break;
case 'p': case 'p':
nof_prb = atoi(argv[optind]); nof_prb = atoi(argv[optind]);
@ -129,11 +133,11 @@ int main(int argc, char **argv) {
memset(preamble, 0, sizeof(cf_t)*MAX_LEN); memset(preamble, 0, sizeof(cf_t)*MAX_LEN);
srslte_prach_init(p, srslte_prach_init(p,
srslte_symbol_sz(nof_prb), srslte_symbol_sz(nof_prb),
preamble_format, preamble_format,
root_seq_idx, root_seq_idx,
high_speed_flag, high_speed_flag,
zero_corr_zone); zero_corr_zone);
int srate = srslte_sampling_freq_hz(nof_prb); int srate = srslte_sampling_freq_hz(nof_prb);
uint32_t flen = srate/1000; uint32_t flen = srate/1000;
@ -153,71 +157,73 @@ int main(int argc, char **argv) {
cf_t *buffer = malloc(sizeof(cf_t)*flen*nof_frames); cf_t *buffer = malloc(sizeof(cf_t)*flen*nof_frames);
// Send through UHD // Send through UHD
srslte_rf_t uhd; srslte_rf_t rf;
printf("Opening UHD device...\n"); printf("Opening RF device...\n");
if (srslte_rf_open(&uhd, uhd_args)) { if (srslte_rf_open(&rf, uhd_args)) {
fprintf(stderr, "Error opening &uhd\n"); fprintf(stderr, "Error opening &uhd\n");
exit(-1); exit(-1);
} }
printf("Subframe len: %d samples\n", flen); printf("Subframe len: %d samples\n", flen);
printf("Set RX gain: %.1f dB\n", uhd_gain); printf("Set RX gain: %.1f dB\n", uhd_rx_gain);
printf("Set TX gain: %.1f dB\n", 20+uhd_gain); printf("Set TX gain: %.1f dB\n", uhd_tx_gain);
printf("Set TX/RX freq: %.2f MHz\n", uhd_freq/ 1000000); printf("Set TX/RX freq: %.2f MHz\n", uhd_freq/ 1000000);
srslte_rf_set_rx_gain(&uhd, uhd_gain); srslte_rf_set_rx_gain(&rf, uhd_rx_gain);
srslte_rf_set_tx_gain(&uhd, 10+uhd_gain); srslte_rf_set_tx_gain(&rf, uhd_tx_gain);
srslte_rf_set_rx_freq(&uhd, uhd_freq); srslte_rf_set_rx_freq(&rf, uhd_freq);
srslte_rf_set_tx_freq(&uhd, uhd_freq); srslte_rf_set_tx_freq(&rf, uhd_freq);
if (srate < 10e6) { if (30720%((int) srate/1000) == 0) {
srslte_rf_set_master_clock_rate(&uhd, 4*srate); srslte_rf_set_master_clock_rate(&rf, 30.72e6);
} else { } else {
srslte_rf_set_master_clock_rate(&uhd, srate); srslte_rf_set_master_clock_rate(&rf, 23.04e6);
} }
printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000); printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000);
float srate_rf = srslte_rf_set_rx_srate(&uhd, (double) srate); float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate);
if (srate_rf != srate) { if (srate_rf != srate) {
fprintf(stderr, "Could not set sampling rate\n"); fprintf(stderr, "Could not set sampling rate\n");
exit(-1); exit(-1);
} }
srslte_rf_set_tx_srate(&uhd, (double) srate); srslte_rf_set_tx_srate(&rf, (double) srate);
sleep(1); sleep(1);
cf_t *zeros = calloc(sizeof(cf_t),flen); cf_t *zeros = calloc(sizeof(cf_t),flen);
FILE *f = NULL;
if (output_filename) {
f = fopen(output_filename, "w");
}
srslte_timestamp_t tstamp; srslte_timestamp_t tstamp;
srslte_rf_start_rx_stream(&uhd); srslte_rf_start_rx_stream(&rf);
uint32_t nframe=0; uint32_t nframe=0;
while(nframe<nof_frames) { while(nframe<nof_frames) {
printf("Rx subframe %d\n", nframe); printf("Rx subframe %d\n", nframe);
srslte_rf_recv_with_time(&uhd, &buffer[flen*nframe], flen, true, &tstamp.full_secs, &tstamp.frac_secs); srslte_rf_recv_with_time(&rf, &buffer[flen*nframe], flen, true, &tstamp.full_secs, &tstamp.frac_secs);
nframe++; nframe++;
if (nframe==9 || nframe==8) { if (nframe==9 || nframe==8) {
srslte_timestamp_add(&tstamp, 0, 2e-3-timeadv*1e-6); srslte_timestamp_add(&tstamp, 0, 2e-3-timeadv*1e-6);
if (nframe==8) { if (nframe==8) {
srslte_rf_send_timed2(&uhd, zeros, flen, tstamp.full_secs, tstamp.frac_secs, true, false); srslte_rf_send_timed2(&rf, zeros, flen, tstamp.full_secs, tstamp.frac_secs, true, false);
printf("Transmitting zeros\n"); printf("Transmitting zeros\n");
} else { } else {
srslte_rf_send_timed2(&uhd, preamble, flen, tstamp.full_secs, tstamp.frac_secs, true, true); srslte_rf_send_timed2(&rf, preamble, flen, tstamp.full_secs, tstamp.frac_secs, false, true);
printf("Transmitting PRACH\n"); printf("Transmitting PRACH\n");
} }
} }
} }
if (f) {
fwrite(buffer, 11*flen*sizeof(cf_t), 1, f); uint32_t indices[1024];
float offsets[1024];
uint32_t nof_detected;
if (srslte_prach_detect_offset(p, frequency_offset, &buffer[flen*10+p->N_cp], flen, indices, offsets, NULL, &nof_detected)) {
printf("Error detecting prach\n");
} }
if (f) { printf("Nof detected PRACHs: %d\n", nof_detected);
fclose(f); for (int i=0;i<nof_detected;i++) {
printf("%d/%d index=%d, offset=%.2f us (%d samples)\n",
i, nof_detected, indices[i], offsets[i]*1e6, (int) (offsets[i]*srate));
} }
srslte_vec_save_file(output_filename,buffer,11*flen*sizeof(cf_t));
srslte_prach_free(p); srslte_prach_free(p);
free(p); free(p);

@ -71,6 +71,11 @@ const unsigned int num_transfers = 32;
const unsigned int timeout_ms = 4000; const unsigned int timeout_ms = 4000;
char* rf_blade_devname(void* h)
{
return DEVNAME;
}
int rf_blade_start_tx_stream(void *h) int rf_blade_start_tx_stream(void *h)
{ {
int status; int status;

@ -28,9 +28,14 @@
#include "srslte/config.h" #include "srslte/config.h"
#include "srslte/rf/rf.h" #include "srslte/rf/rf.h"
#define DEVNAME "bladerf"
SRSLTE_API int rf_blade_open(char *args, SRSLTE_API int rf_blade_open(char *args,
void **handler); void **handler);
SRSLTE_API char* rf_blade_devname(void *h);
SRSLTE_API int rf_blade_close(void *h); SRSLTE_API int rf_blade_close(void *h);
SRSLTE_API void rf_blade_set_tx_cal(void *h, srslte_rf_cal_t *cal); SRSLTE_API void rf_blade_set_tx_cal(void *h, srslte_rf_cal_t *cal);

@ -28,7 +28,8 @@
/* RF frontend API */ /* RF frontend API */
typedef struct { typedef struct {
const char *name; const char *name;
bool (*srslte_rf_rx_wait_lo_locked) (void*); char* (*srslte_rf_devname) (void *h);
bool (*srslte_rf_rx_wait_lo_locked) (void *h);
int (*srslte_rf_start_rx_stream)(void *h); int (*srslte_rf_start_rx_stream)(void *h);
int (*srslte_rf_stop_rx_stream)(void *h); int (*srslte_rf_stop_rx_stream)(void *h);
void (*srslte_rf_flush_buffer)(void *h); void (*srslte_rf_flush_buffer)(void *h);
@ -67,6 +68,7 @@ typedef struct {
static rf_dev_t dev_uhd = { static rf_dev_t dev_uhd = {
"UHD", "UHD",
rf_uhd_devname,
rf_uhd_rx_wait_lo_locked, rf_uhd_rx_wait_lo_locked,
rf_uhd_start_rx_stream, rf_uhd_start_rx_stream,
rf_uhd_stop_rx_stream, rf_uhd_stop_rx_stream,
@ -102,6 +104,7 @@ static rf_dev_t dev_uhd = {
static rf_dev_t dev_blade = { static rf_dev_t dev_blade = {
"bladeRF", "bladeRF",
rf_blade_devname,
rf_blade_rx_wait_lo_locked, rf_blade_rx_wait_lo_locked,
rf_blade_start_rx_stream, rf_blade_start_rx_stream,
rf_blade_stop_rx_stream, rf_blade_stop_rx_stream,
@ -164,6 +167,7 @@ static rf_dev_t dev_dummy = {
dummy_fnc, dummy_fnc,
dummy_fnc, dummy_fnc,
dummy_fnc, dummy_fnc,
dummy_fnc,
dummy_rcv, dummy_rcv,
dummy_fnc, dummy_fnc,
dummy_fnc, dummy_fnc,

@ -137,7 +137,7 @@ void srslte_rf_set_rx_cal(srslte_rf_t *rf, srslte_rf_cal_t *cal) {
const char* srslte_rf_name(srslte_rf_t *rf) { const char* srslte_rf_name(srslte_rf_t *rf) {
return ((rf_dev_t*) rf->dev)->name; return ((rf_dev_t*) rf->dev)->srslte_rf_devname(rf->handler);
} }
bool srslte_rf_rx_wait_lo_locked(srslte_rf_t *rf) bool srslte_rf_rx_wait_lo_locked(srslte_rf_t *rf)

@ -36,6 +36,7 @@
#include "uhd_c_api.h" #include "uhd_c_api.h"
typedef struct { typedef struct {
char *devname;
uhd_usrp_handle usrp; uhd_usrp_handle usrp;
uhd_rx_streamer_handle rx_stream; uhd_rx_streamer_handle rx_stream;
uhd_tx_streamer_handle tx_stream; uhd_tx_streamer_handle tx_stream;
@ -117,6 +118,12 @@ static bool isLocked(rf_uhd_handler_t *handler, char *sensor_name, uhd_sensor_va
return val_out; return val_out;
} }
char* rf_uhd_devname(void* h)
{
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
return handler->devname;
}
bool rf_uhd_rx_wait_lo_locked(void *h) bool rf_uhd_rx_wait_lo_locked(void *h)
{ {
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h; rf_uhd_handler_t *handler = (rf_uhd_handler_t*) h;
@ -251,15 +258,19 @@ int rf_uhd_open(char *args, void **h)
if (args == NULL) { if (args == NULL) {
args = ""; args = "";
} }
handler->devname = "uhd_unknown";
/* If device type or name not given in args, choose a B200 */ /* If device type or name not given in args, choose a B200 */
if (args[0]=='\0') { if (args[0]=='\0') {
if (find_string(devices_str, "type=b200") && !strstr(args, "recv_frame_size")) { if (find_string(devices_str, "type=b200") && !strstr(args, "recv_frame_size")) {
// If B200 is available, use it // If B200 is available, use it
args = "type=b200,recv_frame_size=9232,send_frame_size=9232"; args = "type=b200,recv_frame_size=9232,send_frame_size=9232";
handler->devname = DEVNAME_B200;
} else if (find_string(devices_str, "type=x300")) { } else if (find_string(devices_str, "type=x300")) {
// Else if X300 is available, set master clock rate now (can't be changed later) // Else if X300 is available, set master clock rate now (can't be changed later)
args = "type=x300,master_clock_rate=184.32e6"; args = "type=x300,master_clock_rate=184.32e6";
handler->dynamic_rate = false; handler->dynamic_rate = false;
handler->devname = DEVNAME_X300;
} }
} else { } else {
// If args is set and x300 type is specified, make sure master_clock_rate is defined // If args is set and x300 type is specified, make sure master_clock_rate is defined
@ -267,6 +278,9 @@ int rf_uhd_open(char *args, void **h)
sprintf(args2, "%s,master_clock_rate=184.32e6",args); sprintf(args2, "%s,master_clock_rate=184.32e6",args);
args = args2; args = args2;
handler->dynamic_rate = false; handler->dynamic_rate = false;
handler->devname = DEVNAME_X300;
} else if (strstr(args, "type=b200")) {
handler->devname = DEVNAME_B200;
} }
} }

@ -30,9 +30,15 @@
#include "srslte/config.h" #include "srslte/config.h"
#include "srslte/rf/rf.h" #include "srslte/rf/rf.h"
#define DEVNAME_B200 "uhd_b200"
#define DEVNAME_X300 "uhd_x300"
SRSLTE_API int rf_uhd_open(char *args, SRSLTE_API int rf_uhd_open(char *args,
void **handler); void **handler);
SRSLTE_API char* rf_uhd_devname(void *h);
SRSLTE_API int rf_uhd_close(void *h); SRSLTE_API int rf_uhd_close(void *h);
SRSLTE_API void rf_uhd_set_tx_cal(void *h, srslte_rf_cal_t *cal); SRSLTE_API void rf_uhd_set_tx_cal(void *h, srslte_rf_cal_t *cal);

Loading…
Cancel
Save