Merge remote-tracking branch 'origin/develop-SA-CBRA' into integration_2020_wk15

Conflicts:
	openair1/PHY/TOOLS/nr_phy_scope.c
	targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
This commit is contained in:
hardy
2021-04-14 15:14:03 +02:00
59 changed files with 2128 additions and 1108 deletions
+15 -9
View File
@@ -68,8 +68,10 @@ int read_recplayconfig(recplay_conf_t **recplay_conf, recplay_state_t **recplay_
*recplay_conf=NULL;
}
if (u_sf_replay == 1) return RECPLAY_REPLAYMODE;
else if (u_sf_record == 1) return RECPLAY_RECORDMODE;
if (u_sf_replay == 1)
return RECPLAY_REPLAYMODE;
else if (u_sf_record == 1)
return RECPLAY_RECORDMODE;
return 0;
}
@@ -80,7 +82,7 @@ int read_recplayconfig(recplay_conf_t **recplay_conf, recplay_state_t **recplay_
*/
void iqrecorder_end(openair0_device *device) {
if (device->recplay_state != NULL) { // subframes store
iqfile_header_t fh = {device->type,device->openair0_cfg->tx_sample_advance, device->openair0_cfg->rx_bw,OAIIQFILE_ID};
iqfile_header_t fh = {device->type,device->openair0_cfg->tx_sample_advance, device->openair0_cfg->rx_bw,0,OAIIQFILE_ID};
recplay_state_t *rs = device->recplay_state;
recplay_conf_t *rc = device->openair0_cfg[0].recplay_conf;
rs->pFile = fopen (rc->u_sf_filename,"wb+");
@@ -91,16 +93,20 @@ void iqrecorder_end(openair0_device *device) {
unsigned int i = 0;
unsigned int modu = 0;
if ((modu = rs->nb_samples % 10) != 0) {
rs->nb_samples -= modu; // store entire number of frames
if ((modu = rs->nbSamplesBlocks % 10) != 0) {
rs->nbSamplesBlocks -= modu; // store entire number of frames
}
fh.nbSamplesBlocks=rs->nbSamplesBlocks;
LOG_I(HW,"Writing file header to %s \n", rc->u_sf_filename );
fwrite(&fh, sizeof(fh), 1, rs->pFile);
LOG_UI(HW,"Writing %u subframes to %s \n",rs->nb_samples, rc->u_sf_filename );
LOG_UI(HW,"Writing %u subframes to %s \n",rs->nbSamplesBlocks, rc->u_sf_filename );
uint8_t *ptr=(uint8_t *)rs->ms_sample;
for (i = 0; i < rs->nb_samples; i++) {
fwrite(rs->ms_sample+i, sizeof(unsigned char), sizeof(iqrec_t), rs->pFile);
for (i = 0; i < rs->nbSamplesBlocks; i++) {
int blockBytes=sizeof(iqrec_t)+((iqrec_t *)ptr)->nbBytes;
fwrite(ptr, sizeof(unsigned char), blockBytes, rs->pFile);
ptr+=blockBytes;
}
fclose (rs->pFile);
@@ -112,4 +118,4 @@ void iqrecorder_end(openair0_device *device) {
rs->ms_sample = NULL;
}
}
}
}
+11 -8
View File
@@ -46,21 +46,22 @@ extern "C"
#define BELL_LABS_IQ_HEADER 0xabababababababab
#define BELL_LABS_IQ_PER_SF 7680 // Up to 5MHz bw for now
#define BELL_LABS_IQ_BYTES_PER_SF (BELL_LABS_IQ_PER_SF * 4)
#define MAX_BELL_LABS_IQ_BYTES_PER_SF BELL_LABS_IQ_BYTES_PER_SF*10
#define OAIIQFILE_ID "OIQF"
#define OAIIQFILE_ID {'O', 'I','Q','F'}
typedef struct {
uint64_t devtype;
uint64_t tx_sample_advance;
double bw;
unsigned int nbSamplesBlocks;
char oaiid[4];
} iqfile_header_t;
typedef struct {
int64_t header;
int64_t ts;
int64_t rfu1;
int64_t nbBytes;
int64_t rfu2; // pad for 256 bits alignement required by AVX2
unsigned char samples[BELL_LABS_IQ_BYTES_PER_SF]; // iq's for one subframe
} iqrec_t;
#define DEF_NB_SF 120000 // default nb of sf or ms to capture (2 minutes at 5MHz)
#define DEF_SF_FILE "/tmp/iqfile" // default subframes file name
@@ -114,14 +115,16 @@ typedef struct {
int use_mmap; // default is to use mmap
size_t mapsize;
FILE *pFile;
int mmapfd;
int iqfd;
int fd;
iqrec_t *ms_sample; // memory for all subframes
unsigned int nb_samples;
unsigned int nbSamplesBlocks;
uint8_t *currentPtr;
uint64_t currentTs;
unsigned int curSamplesBlock;
int64_t wrap_count;
size_t maxSizeBytes;
} recplay_state_t;
#ifdef __cplusplus
}
#endif
+90 -80
View File
@@ -276,7 +276,7 @@ static int trx_usrp_start(openair0_device *device) {
// setup GPIO for TDD, GPIO(4) = ATR_RX
//set data direction register (DDR) to output
s->usrp->set_gpio_attr("FP0", "DDR", 0xfff, 0xfff);
//set lower 7 bits to be controlled automatically by ATR (the rest 5 bits are controlled manually)
//set lower 7 bits to be controlled automatically by ATR (the rest 5 bits are controlled manually)
s->usrp->set_gpio_attr("FP0", "CTRL", 0x7f,0xfff);
//set pins 4 (RX_TX_Switch) and 6 (Shutdown PA) to 1 when the radio is only receiving (ATR_RX)
s->usrp->set_gpio_attr("FP0", "ATR_RX", (1<<4)|(1<<6), 0x7f);
@@ -301,7 +301,7 @@ static int trx_usrp_start(openair0_device *device) {
}
uhd::stream_cmd_t cmd(uhd::stream_cmd_t::STREAM_MODE_START_CONTINUOUS);
cmd.time_spec = uhd::time_spec_t(1.0);
cmd.time_spec = uhd::time_spec_t(1.0);
cmd.stream_now = false; // start at constant delay
s->rx_stream->issue_stream_cmd(cmd);
@@ -315,7 +315,7 @@ static void trx_usrp_end(openair0_device *device) {
return;
usrp_state_t *s = (usrp_state_t *)device->priv;
if (s == NULL)
return;
iqrecorder_end(device);
@@ -436,7 +436,7 @@ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHI
buff_ptrs.push_back(&(((int16_t *)buff_tx[i])[0]));
ret = (int)s->tx_stream->send(buff_ptrs, nsamps, s->tx_md);
}
}
else {
ret = (int)s->tx_stream->send(&(((int16_t *)buff_tx[0])[0]), nsamps, s->tx_md);
}
@@ -480,7 +480,7 @@ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_BEAM_SWITCHI
@param antenna_id index of the antenna if the device has multiple antennas
@param flags flags must be set to TRUE if timestamp parameter needs to be applied
*/
void *trx_usrp_write_thread(void * arg){
void *trx_usrp_write_thread(void * arg){
int ret=0;
openair0_device *device=(openair0_device *)arg;
openair0_thread_t *write_thread = &device->write_thread;
@@ -549,7 +549,7 @@ void *trx_usrp_write_thread(void * arg){
}
}
s->tx_md.has_time_spec = true;
s->tx_md.start_of_burst = (s->tx_count==0) ? true : first_packet;
s->tx_md.end_of_burst = last_packet;
@@ -572,7 +572,7 @@ void *trx_usrp_write_thread(void * arg){
buff_ptrs.push_back(&(((int16_t *)buff_tx[i])[0]));
ret = (int)s->tx_stream->send(buff_ptrs, nsamps, s->tx_md);
}
}
else {
ret = (int)s->tx_stream->send(&(((int16_t *)buff_tx[0])[0]), nsamps, s->tx_md);
}
@@ -697,15 +697,23 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp
s->usrp->set_gpio_attr("FP0", "OUT", gpio789<<7, 0x380);
s->usrp->clear_command_time();
gpio789 = (gpio789+1)&7;*/
recplay_state_t *recPlay=device->recplay_state;
if (device->recplay_state != NULL) { // record mode
if ( recPlay != NULL) { // record mode
// Copy subframes to memory (later dump on a file)
if (device->recplay_state->nb_samples < device->openair0_cfg->recplay_conf->u_sf_max) {
(device->recplay_state->ms_sample+device->recplay_state->nb_samples)->header = BELL_LABS_IQ_HEADER;
(device->recplay_state->ms_sample+device->recplay_state->nb_samples)->ts = *ptimestamp;
memcpy((device->recplay_state->ms_sample+device->recplay_state->nb_samples)->samples, buff[0], nsamps*4);
device->recplay_state->nb_samples++;
} else exit_function(__FILE__, __FUNCTION__, __LINE__,"Recording reaches max iq limit\n");
if (recPlay->nbSamplesBlocks < device->openair0_cfg->recplay_conf->u_sf_max &&
recPlay->maxSizeBytes > (recPlay->currentPtr-(uint8_t *)recPlay->ms_sample) +
sizeof(iqrec_t) + nsamps*4 ) {
iqrec_t *hdr=(iqrec_t *)recPlay->currentPtr;
hdr->header = BELL_LABS_IQ_HEADER;
hdr->ts = *ptimestamp;
hdr->nbBytes=nsamps*4;
memcpy(hdr+1, buff[0], nsamps*4);
recPlay->currentPtr+=sizeof(iqrec_t)+nsamps*4;
recPlay->nbSamplesBlocks++;
LOG_D(HW,"recorded %d samples, for TS %lu, shift in buffer %ld\n", nsamps, hdr->ts, recPlay->currentPtr-(uint8_t *)recPlay->ms_sample);
} else
exit_function(__FILE__, __FUNCTION__, __LINE__,"Recording reaches max iq limit\n");
}
return samples_received;
@@ -944,25 +952,25 @@ extern "C" {
// Initialize USRP device
int vers=0,subvers=0,subsubvers=0;
int bw_gain_adjust=0;
if (device->openair0_cfg->recplay_mode == RECPLAY_RECORDMODE) {
std::cerr << "USRP device initialized in subframes record mode" << std::endl;
}
sscanf(uhd::get_version_string().c_str(),"%d.%d.%d",&vers,&subvers,&subsubvers);
LOG_I(HW,"UHD version %s (%d.%d.%d)\n",
uhd::get_version_string().c_str(),vers,subvers,subsubvers);
std::string args;
if (openair0_cfg[0].sdr_addrs == NULL) {
args = "type=b200";
} else {
args = openair0_cfg[0].sdr_addrs;
LOG_I(HW,"Checking for USRP with args %s\n",openair0_cfg[0].sdr_addrs);
}
uhd::device_addrs_t device_adds = uhd::device::find(args);
if (device_adds.size() == 0) {
LOG_E(HW,"No USRP Device Found.\n ");
free(s);
@@ -972,38 +980,38 @@ extern "C" {
free(s);
return -1;
}
LOG_I(HW,"Found USRP %s\n", device_adds[0].get("type").c_str());
double usrp_master_clock;
if (device_adds[0].get("type") == "b200") {
device->type = USRP_B200_DEV;
usrp_master_clock = 30.72e6;
args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock);
args += ",num_send_frames=256,num_recv_frames=256, send_frame_size=7680, recv_frame_size=7680" ;
}
if (device_adds[0].get("type") == "n3xx") {
printf("Found USRP n300\n");
device->type=USRP_N300_DEV;
device->type=USRP_N300_DEV;
usrp_master_clock = 122.88e6;
args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock);
//args += ", send_buff_size=33554432";
}
if (device_adds[0].get("type") == "x300") {
printf("Found USRP x300\n");
device->type=USRP_X300_DEV;
usrp_master_clock = 184.32e6;
args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock);
// USRP recommended: https://files.ettus.com/manual/page_usrp_x3x0_config.html
if ( 0 != system("sysctl -w net.core.rmem_max=33554432 net.core.wmem_max=33554432") )
LOG_W(HW,"Can't set kernel parameters for X3xx\n");
}
s->usrp = uhd::usrp::multi_usrp::make(args);
if (args.find("clock_source")==std::string::npos) {
if (openair0_cfg[0].clock_source == internal) {
s->usrp->set_clock_source("internal");
@@ -1017,7 +1025,7 @@ extern "C" {
s->usrp->set_clock_source("gpsdo");
LOG_D(HW,"Setting clock source to gpsdo\n");
}
else {
else {
LOG_W(HW,"Clock source set neither in usrp_args nor on command line, using default!\n");
}
}
@@ -1040,7 +1048,7 @@ extern "C" {
s->usrp->set_time_source("gpsdo");
LOG_D(HW,"Setting time source to gpsdo\n");
}
else {
else {
LOG_W(HW,"Time source set neither in usrp_args nor on command line, using default!\n");
}
}
@@ -1050,10 +1058,10 @@ extern "C" {
}
}
if (s->usrp->get_clock_source(0) == "gpsdo") {
s->use_gps = 1;
if (sync_to_gps(device)==EXIT_SUCCESS) {
LOG_I(HW,"USRP synced with GPS!\n");
} else {
@@ -1068,15 +1076,15 @@ extern "C" {
exit(EXIT_FAILURE);
}
}
if (device->type==USRP_X300_DEV) {
openair0_cfg[0].rx_gain_calib_table = calib_table_x310;
std::cerr << "-- Using calibration table: calib_table_x310" << std::endl;
std::cerr << "-- Using calibration table: calib_table_x310" << std::endl;
}
if (device->type==USRP_N300_DEV) {
openair0_cfg[0].rx_gain_calib_table = calib_table_n310;
std::cerr << "-- Using calibration table: calib_table_n310" << std::endl;
std::cerr << "-- Using calibration table: calib_table_n310" << std::endl;
}
@@ -1091,7 +1099,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 80e6;
openair0_cfg[0].rx_bw = 80e6;
break;
case 92160000:
// from usrp_time_offset
//openair0_cfg[0].samples_per_packet = 2048;
@@ -1099,7 +1107,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 80e6;
openair0_cfg[0].rx_bw = 80e6;
break;
case 61440000:
// from usrp_time_offset
//openair0_cfg[0].samples_per_packet = 2048;
@@ -1107,14 +1115,14 @@ extern "C" {
openair0_cfg[0].tx_bw = 40e6;
openair0_cfg[0].rx_bw = 40e6;
break;
case 46080000:
//openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 65;
openair0_cfg[0].tx_sample_advance = 15;
openair0_cfg[0].tx_bw = 40e6;
openair0_cfg[0].rx_bw = 40e6;
break;
case 30720000:
// from usrp_time_offset
//openair0_cfg[0].samples_per_packet = 2048;
@@ -1122,35 +1130,35 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
case 15360000:
//openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 40;
openair0_cfg[0].tx_sample_advance = 45;
openair0_cfg[0].tx_bw = 10e6;
openair0_cfg[0].rx_bw = 10e6;
break;
case 7680000:
//openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 50;
openair0_cfg[0].tx_bw = 5e6;
openair0_cfg[0].rx_bw = 5e6;
break;
case 1920000:
//openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 50;
openair0_cfg[0].tx_bw = 1.25e6;
openair0_cfg[0].rx_bw = 1.25e6;
break;
default:
LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate);
exit(-1);
break;
}
}
if (device->type == USRP_B200_DEV) {
if ((vers == 3) && (subvers == 9) && (subsubvers>=2)) {
openair0_cfg[0].rx_gain_calib_table = calib_table_b210;
@@ -1161,7 +1169,7 @@ extern "C" {
bw_gain_adjust=1;
std::cerr << "-- Using calibration table: calib_table_b210_38" << std::endl; // Bell Labs info
}
switch ((int)openair0_cfg[0].sample_rate) {
case 46080000:
s->usrp->set_master_clock_rate(46.08e6);
@@ -1170,7 +1178,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 40e6;
openair0_cfg[0].rx_bw = 40e6;
break;
case 30720000:
s->usrp->set_master_clock_rate(30.72e6);
//openair0_cfg[0].samples_per_packet = 1024;
@@ -1178,7 +1186,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
case 23040000:
s->usrp->set_master_clock_rate(23.04e6); //to be checked
//openair0_cfg[0].samples_per_packet = 1024;
@@ -1186,7 +1194,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
case 15360000:
s->usrp->set_master_clock_rate(30.72e06);
//openair0_cfg[0].samples_per_packet = 1024;
@@ -1194,7 +1202,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
case 7680000:
s->usrp->set_master_clock_rate(30.72e6);
//openair0_cfg[0].samples_per_packet = 1024;
@@ -1202,7 +1210,7 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
case 1920000:
s->usrp->set_master_clock_rate(30.72e6);
//openair0_cfg[0].samples_per_packet = 1024;
@@ -1210,20 +1218,20 @@ extern "C" {
openair0_cfg[0].tx_bw = 20e6;
openair0_cfg[0].rx_bw = 20e6;
break;
default:
LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate);
exit(-1);
break;
}
}
/* device specific */
//openair0_cfg[0].txlaunch_wait = 1;//manage when TX processing is triggered
//openair0_cfg[0].txlaunch_wait_slotcount = 1; //manage when TX processing is triggered
openair0_cfg[0].iq_txshift = 4;//shift
openair0_cfg[0].iq_rxrescale = 15;//rescale iqs
for(int i=0; i<((int) s->usrp->get_rx_num_channels()); i++) {
if (i<openair0_cfg[0].rx_num_channels) {
s->usrp->set_rx_rate(openair0_cfg[0].sample_rate,i);
@@ -1240,13 +1248,13 @@ extern "C" {
openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i],gain_range.stop());
}
}
LOG_D(HW, "usrp->get_tx_num_channels() == %zd\n", s->usrp->get_tx_num_channels());
LOG_D(HW, "openair0_cfg[0].tx_num_channels == %d\n", openair0_cfg[0].tx_num_channels);
for(int i=0; i<((int) s->usrp->get_tx_num_channels()); i++) {
::uhd::gain_range_t gain_range_tx = s->usrp->get_tx_gain_range(i);
if (i<openair0_cfg[0].tx_num_channels) {
s->usrp->set_tx_rate(openair0_cfg[0].sample_rate,i);
s->usrp->set_tx_freq(openair0_cfg[0].tx_freq[i],i);
@@ -1254,7 +1262,7 @@ extern "C" {
LOG_I(HW,"USRP TX_GAIN:%3.2lf gain_range:%3.2lf tx_gain:%3.2lf\n", gain_range_tx.stop()-openair0_cfg[0].tx_gain[i], gain_range_tx.stop(), openair0_cfg[0].tx_gain[i]);
}
}
//s->usrp->set_clock_source("external");
//s->usrp->set_time_source("external");
// display USRP settings
@@ -1268,32 +1276,32 @@ extern "C" {
int max=s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps();
samples/=10000;
LOG_I(HW,"RF board max packet size %u, size for 100µs jitter %d \n", max, samples);
if ( samples < max ) {
stream_args_rx.args["spp"] = str(boost::format("%d") % samples );
}
LOG_I(HW,"rx_max_num_samps %zu\n",
s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps());
for (int i = 0; i<openair0_cfg[0].rx_num_channels; i++)
stream_args_rx.channels.push_back(i);
s->rx_stream = s->usrp->get_rx_stream(stream_args_rx);
uhd::stream_args_t stream_args_tx("sc16", "sc16");
for (int i = 0; i<openair0_cfg[0].tx_num_channels; i++)
stream_args_tx.channels.push_back(i);
s->tx_stream = s->usrp->get_tx_stream(stream_args_tx);
/* Setting TX/RX BW after streamers are created due to USRP calibration issue */
for(int i=0; i<((int) s->usrp->get_tx_num_channels()) && i<openair0_cfg[0].tx_num_channels; i++)
s->usrp->set_tx_bandwidth(openair0_cfg[0].tx_bw,i);
for(int i=0; i<((int) s->usrp->get_rx_num_channels()) && i<openair0_cfg[0].rx_num_channels; i++)
s->usrp->set_rx_bandwidth(openair0_cfg[0].rx_bw,i);
for (int i=0; i<openair0_cfg[0].rx_num_channels; i++) {
LOG_I(HW,"RX Channel %d\n",i);
LOG_I(HW," Actual RX sample rate: %fMSps...\n",s->usrp->get_rx_rate(i)/1e6);
@@ -1302,7 +1310,7 @@ extern "C" {
LOG_I(HW," Actual RX bandwidth: %fM...\n", s->usrp->get_rx_bandwidth(i)/1e6);
LOG_I(HW," Actual RX antenna: %s...\n", s->usrp->get_rx_antenna(i).c_str());
}
for (int i=0; i<openair0_cfg[0].tx_num_channels; i++) {
LOG_I(HW,"TX Channel %d\n",i);
LOG_I(HW," Actual TX sample rate: %fMSps...\n", s->usrp->get_tx_rate(i)/1e6);
@@ -1312,33 +1320,35 @@ extern "C" {
LOG_I(HW," Actual TX antenna: %s...\n", s->usrp->get_tx_antenna(i).c_str());
LOG_I(HW," Actual TX packet size: %lu\n",s->tx_stream->get_max_num_samps());
}
LOG_I(HW,"Device timestamp: %f...\n", s->usrp->get_time_now().get_real_secs());
device->trx_write_func = trx_usrp_write;
device->trx_read_func = trx_usrp_read;
s->sample_rate = openair0_cfg[0].sample_rate;
// TODO:
// init tx_forward_nsamps based usrp_time_offset ex
if(is_equal(s->sample_rate, (double)30.72e6))
s->tx_forward_nsamps = 176;
if(is_equal(s->sample_rate, (double)15.36e6))
s->tx_forward_nsamps = 90;
if(is_equal(s->sample_rate, (double)7.68e6))
s->tx_forward_nsamps = 50;
if (device->recplay_state != NULL) { // record mode
device->recplay_state->ms_sample = (iqrec_t *) malloc(openair0_cfg[0].recplay_conf->u_sf_max * sizeof(iqrec_t));
if (device->recplay_state->ms_sample == NULL) {
recplay_state_t *recPlay=device->recplay_state;
if (recPlay != NULL) { // record mode
recPlay->maxSizeBytes=openair0_cfg[0].recplay_conf->u_sf_max *
(sizeof(iqrec_t)+BELL_LABS_IQ_BYTES_PER_SF);
recPlay->ms_sample = (iqrec_t *) malloc(recPlay->maxSizeBytes);
recPlay->currentPtr= (uint8_t *)recPlay->ms_sample;
if (recPlay->ms_sample == NULL) {
std::cerr<< "Memory allocation failed for subframe record or replay mode." << std::endl;
exit(-1);
}
memset(device->recplay_state->ms_sample, 0, openair0_cfg[0].recplay_conf->u_sf_max * BELL_LABS_IQ_BYTES_PER_SF);
}
return 0;
}
+77 -128
View File
@@ -39,18 +39,15 @@
#include "assertions.h"
#include "common/utils/LOG/log.h"
static void parse_iqfile_header(openair0_device *device, iqfile_header_t *iq_fh) {
AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),
"iqfile doesn't seem to be compatible with oai (invalid id %.4s in header)\n",
iq_fh->oaiid);
char tmp[4]=OAIIQFILE_ID;
AssertFatal((memcmp(iq_fh->oaiid,tmp,sizeof(iq_fh->oaiid)) == 0),
"iqfile doesn't seem to be compatible with oai (invalid id %.4s in header)\n",
iq_fh->oaiid);
device->type = iq_fh->devtype;
device->openair0_cfg[0].tx_sample_advance=iq_fh->tx_sample_advance;
device->openair0_cfg[0].tx_bw = device->openair0_cfg[0].rx_bw = iq_fh->bw;
device->recplay_state->nbSamplesBlocks=iq_fh->nbSamplesBlocks;
LOG_UI(HW,"Replay iqs from %s device, bandwidth %e\n",get_devname(iq_fh->devtype),iq_fh->bw);
}
@@ -62,89 +59,73 @@ static int iqplayer_loadfile(openair0_device *device, openair0_config_t *openair
recplay_state_t *s = device->recplay_state;
recplay_conf_t *c = openair0_cfg->recplay_conf;
struct stat sb;
s->fd = open(c->u_sf_filename, O_RDONLY );
if (s->fd >= 0 ) {
fstat(s->fd, &sb);
} else {
LOG_E( HW,"Cannot open %s exiting.\n", c->u_sf_filename );
exit(-1);
}
if (s->use_mmap) {
// use mmap
s->mmapfd = open(c->u_sf_filename, O_RDONLY );
if (s->mmapfd != 0) {
struct stat sb;
fstat(s->mmapfd, &sb);
s->mapsize=sb.st_size;
LOG_I(HW,"Loading subframes using mmap() from %s size=%lu bytes ...\n",c->u_sf_filename, (uint64_t)sb.st_size );
void *mptr = mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->mmapfd, 0) ;
s->ms_sample = (iqrec_t *) ( mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->mmapfd, 0) + sizeof(iqfile_header_t));
void *mptr = mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->fd, 0) ;
s->ms_sample = (iqrec_t *) ( mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->fd, 0) + sizeof(iqfile_header_t));
if (mptr != MAP_FAILED) {
parse_iqfile_header(device, (iqfile_header_t *)mptr);
s->ms_sample = (iqrec_t *)((char *)mptr + sizeof(iqfile_header_t));
s->nb_samples = ((sb.st_size-sizeof(iqfile_header_t)) / sizeof(iqrec_t));
int aligned = (((unsigned long)s->ms_sample & 31) == 0)? 1:0;
LOG_I(HW,"Loaded %u subframes.\n",s->nb_samples );
if (aligned == 0) {
LOG_E(HW, "mmap address is not 32 bytes aligned, exiting.\n" );
close(s->mmapfd);
exit(-1);
}
LOG_I(HW,"Loaded %u subframes.\n",s->nbSamplesBlocks );
} else {
LOG_E(HW,"Cannot mmap file, exiting.\n");
close(s->mmapfd);
close(s->fd);
exit(-1);
}
} else {
LOG_E( HW,"Cannot open %s exiting.\n", c->u_sf_filename );
exit(-1);
}
} else {
s->iqfd = open(c->u_sf_filename, O_RDONLY);
iqfile_header_t fh;
size_t hs = read(s->fd,&fh,sizeof(fh));
if (s->iqfd != 0) {
struct stat sb;
iqfile_header_t fh;
size_t hs = read(s->iqfd,&fh,sizeof(fh));
if (hs == sizeof(fh)) {
parse_iqfile_header(device, &fh);
fstat(s->iqfd, &sb);
if (hs == sizeof(fh)) {
parse_iqfile_header(device, &fh);
fstat(s->fd, &sb);
s->mapsize=sb.st_size;
s->nb_samples = ((sb.st_size-sizeof(iqfile_header_t))/ sizeof(iqrec_t));
LOG_I(HW, "Loading %u subframes from %s,size=%lu bytes ...\n",s->nb_samples, c->u_sf_filename,(uint64_t)sb.st_size);
LOG_I(HW, "Loading %u subframes from %s,size=%lu bytes ...\n",s->nbSamplesBlocks, c->u_sf_filename,(uint64_t)sb.st_size);
// allocate buffer for 1 sample at a time
s->ms_sample = (iqrec_t *) malloc(sizeof(iqrec_t));
s->ms_sample = (iqrec_t *) malloc(sizeof(iqrec_t)+MAX_BELL_LABS_IQ_BYTES_PER_SF*4);
if (s->ms_sample == NULL) {
LOG_E(HW,"Memory allocation failed for individual subframe replay mode.\n" );
close(s->iqfd);
close(s->fd);
exit(-1);
}
memset(s->ms_sample, 0, sizeof(iqrec_t));
// point at beginning of iqs in file
if (lseek(s->iqfd,sizeof(iqfile_header_t), SEEK_SET) == 0) {
if (lseek(s->fd,sizeof(iqfile_header_t), SEEK_SET) == 0) {
LOG_I(HW,"Initial seek at beginning of the file\n" );
} else {
LOG_I(HW,"Problem initial seek at beginning of the file\n");
}
} else {
LOG_E(HW,"Cannot read header in %s exiting.\n",c->u_sf_filename );
close(s->iqfd);
close(s->fd);
exit(-1);
}
} else {
LOG_E(HW,"Cannot open %s exiting.\n",c->u_sf_filename );
exit(-1);
}
}
s->currentPtr=(uint8_t *)s->ms_sample;
return 0;
}
/*! \brief start the oai iq player
* \param device, the hardware used
*/
static int trx_iqplayer_start(openair0_device *device){
return 0;
static int trx_iqplayer_start(openair0_device *device) {
return 0;
}
/*! \brief Terminate operation of the oai iq player
@@ -156,28 +137,22 @@ static void trx_iqplayer_end(openair0_device *device) {
if (device->recplay_state == NULL)
return;
if (device->recplay_state->use_mmap) {
if (device->recplay_state->ms_sample != MAP_FAILED) {
munmap(device->recplay_state->ms_sample, device->recplay_state->mapsize);
device->recplay_state->ms_sample = NULL;
}
if (device->recplay_state->mmapfd != 0) {
close(device->recplay_state->mmapfd);
device->recplay_state->mmapfd = 0;
}
}
} else {
if (device->recplay_state->ms_sample != NULL) {
free(device->recplay_state->ms_sample);
device->recplay_state->ms_sample = NULL;
}
if (device->recplay_state->iqfd != 0) {
close(device->recplay_state->iqfd);
device->recplay_state->iqfd = 0;
}
}
}
device->recplay_state->ms_sample = NULL;
if (device->recplay_state->fd >= 0) {
close(device->recplay_state->fd);
device->recplay_state->fd = -1;
}
}
/*! \brief Write iqs function when in replay mode, just introduce a delay, as configured at init time,
@param device pointer to the device structure specific to the RF hardware target
@@ -207,93 +182,68 @@ static int trx_iqplayer_write(openair0_device *device, openair0_timestamp timest
* \returns the number of sample read
*/
static int trx_iqplayer_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) {
int samples_received=0;
static unsigned int cur_samples;
static int64_t wrap_count;
static int64_t wrap_ts;
recplay_state_t *s = device->recplay_state;
if (cur_samples == s->nb_samples) {
cur_samples = 0;
wrap_count++;
if (s->curSamplesBlock==0 && s->wrap_count==0 )
s->currentTs=s->ms_sample->ts;
if (s->curSamplesBlock == s->nbSamplesBlocks) {
LOG_I(HW, "wrapping on iq file (%ld)\n", s->wrap_count);
s->curSamplesBlock = 0;
s->wrap_count++;
if (wrap_count == device->openair0_cfg->recplay_conf->u_sf_loops) {
LOG_W(HW, "iqplayer device terminating subframes replay after %u iteration\n",device->openair0_cfg->recplay_conf->u_sf_loops);
if (s->wrap_count == device->openair0_cfg->recplay_conf->u_sf_loops) {
LOG_W(HW, "iqplayer device terminating subframes replay after %u iteration\n",
device->openair0_cfg->recplay_conf->u_sf_loops);
exit_function(__FILE__, __FUNCTION__, __LINE__,"replay ended, triggering process termination\n");
}
wrap_ts = wrap_count * (s->nb_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000));
LOG_I(HW,"go back at the beginning of IQ file");
device->recplay_state->currentPtr=(uint8_t *)device->recplay_state->ms_sample;
if (!device->recplay_state->use_mmap) {
if (lseek(device->recplay_state->iqfd, 0, SEEK_SET) == 0) {
LOG_I(HW,"Seeking at the beginning of IQ file");
} else {
LOG_I(HW, "Problem seeking at the beginning of IQ file");
if (!s->use_mmap) {
if (lseek(device->recplay_state->fd, 0, SEEK_SET) != 0) {
LOG_E(HW, "Problem seeking at the beginning of IQ file");
}
}
}
if (s->use_mmap) {
if (cur_samples < s->nb_samples) {
*ptimestamp = (s->ms_sample[0].ts + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000))) + wrap_ts;
if (cur_samples == 0) {
LOG_I(HW,"starting subframes file with wrap_count=%lu wrap_ts=%lu ts=%lu\n", wrap_count,wrap_ts,*ptimestamp);
}
memcpy(buff[0], &s->ms_sample[cur_samples].samples[0], nsamps*4);
cur_samples++;
}
} else {
if (!s->use_mmap) {
// read sample from file
if (read(s->iqfd, s->ms_sample, sizeof(iqrec_t)) != sizeof(iqrec_t)) {
LOG_E(HW,"pb reading iqfile at index %lu\n",sizeof(iqrec_t)*cur_samples );
close(s->iqfd);
free(s->ms_sample);
s->ms_sample = NULL;
s->iqfd = 0;
if (read(s->fd, s->ms_sample, sizeof(iqrec_t)) != sizeof(iqrec_t)) {
LOG_E(HW,"pb reading iqfile at index %lu\n",sizeof(iqrec_t)*s->curSamplesBlock );
exit(-1);
}
if (cur_samples < s->nb_samples) {
static int64_t ts0 = 0;
if ((cur_samples == 0) && (wrap_count == 0)) {
ts0 = s->ms_sample->ts;
}
*ptimestamp = ts0 + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000)) + wrap_ts;
if (cur_samples == 0) {
LOG_I(HW, "starting subframes file with wrap_count=%lu wrap_ts=%lu ts=%lu ",wrap_count,wrap_ts, *ptimestamp);
}
memcpy(buff[0], &s->ms_sample->samples[0], nsamps*4);
cur_samples++;
// Prepare for next read
off_t where = lseek(s->iqfd, cur_samples * sizeof(iqrec_t), SEEK_SET);
if (where < 0) {
LOG_E(HW,"Cannot lseek in iqfile: %s\n",strerror(errno));
} else {
if (read(s->fd, s->ms_sample+1, s->ms_sample->nbBytes) != s->ms_sample->nbBytes) {
LOG_E(HW,"pb reading iqfile at index %lu\n",sizeof(iqrec_t)*s->curSamplesBlock );
exit(-1);
}
}
}
iqrec_t *curHeader=(iqrec_t *)s->currentPtr;
AssertFatal(curHeader->header==BELL_LABS_IQ_HEADER,"" );
// the current timestamp is the stored timestamp until we wrap on input
// USRP shifts 1 sample time to time
AssertFatal(s->wrap_count !=0 || abs(curHeader->ts-s->currentTs) < 5 ,"");
AssertFatal(nsamps*4==curHeader->nbBytes,"");
*ptimestamp = s->currentTs;
memcpy(buff[0], curHeader+1, nsamps*4);
s->curSamplesBlock++;
// Prepare for next read
s->currentTs+=nsamps;
if (s->use_mmap)
s->currentPtr+=sizeof(iqrec_t)+s->ms_sample->nbBytes;
struct timespec req;
req.tv_sec = 0;
req.tv_nsec = (device->openair0_cfg[0].recplay_conf->u_sf_read_delay) * 1000;
nanosleep(&req, NULL);
LOG_D(HW, "returning %d samples at ts %lu\n", nsamps, *ptimestamp);
return nsamps;
return samples_received;
}
int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
device->openair0_cfg = openair0_cfg;
device->trx_start_func = trx_iqplayer_start;
@@ -312,5 +262,4 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
LOG_UI(HW,"iqplayer device initialized, replay %s for %i iterations",openair0_cfg->recplay_conf->u_sf_filename,openair0_cfg->recplay_conf->u_sf_loops);
return 0;
}
/*@}*/
+2 -2
View File
@@ -186,14 +186,14 @@ int main(int argc, char *argv[]) {
serviceSock=client_start(argv[2],atoi(argv[3]));
}
uint64_t typeStamp=ENB_MAGICDL_FDD;
uint64_t typeStamp=ENB_MAGICDL;
boolean_t raw=false;
if ( argc == 5 ) {
raw=true;
if (strcmp(argv[4],"UL") == 0 )
typeStamp=UE_MAGICDL_FDD;
typeStamp=UE_MAGICDL;
}
samplesBlockHeader_t header;
@@ -13,7 +13,7 @@ gNBs =
// Tracking area code, 0x0000 and 0xfffe are reserved values
tracking_area_code = 1;
plmn_list = ({mcc = 222; mnc = 93; mnc_length = 2;});
plmn_list = ({mcc = 208; mnc = 92; mnc_length = 2;});
tr_s_preference = "local_mac"
@@ -21,6 +21,7 @@ gNBs =
ssb_SubcarrierOffset = 0;
pdsch_AntennaPorts = 1;
pusch_AntennaPorts = 1;
pdcch_ConfigSIB1 = (
{
@@ -51,7 +52,7 @@ gNBs =
#initialDownlinkBWP
#genericParameters
# this is RBstart=41,L=24 (275*(L-1))+RBstart
initialDLBWPlocationAndBandwidth = 6368;
initialDLBWPlocationAndBandwidth = 12952; # 6366 12925 12956 28875
# subcarrierSpacing
# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
initialDLBWPsubcarrierSpacing = 1;
@@ -64,28 +65,23 @@ gNBs =
#initialULBWPmappingType
#0=typeA,1=typeB
initialDLBWPmappingType_0 = 0;
#this is SS=2,L=12
initialDLBWPstartSymbolAndLength_0 = 53;
#this is SS=1,L=13
initialDLBWPstartSymbolAndLength_0 = 40;
initialDLBWPk0_1 = 0;
initialDLBWPmappingType_1 = 0;
#this is SS=2,L=10
initialDLBWPstartSymbolAndLength_1 = 81;
#this is SS=2,L=12
initialDLBWPstartSymbolAndLength_1 = 53;
initialDLBWPk0_2 = 0;
initialDLBWPmappingType_2 = 0;
#this is SS=1,L=12
initialDLBWPstartSymbolAndLength_2 = 95;
initialDLBWPstartSymbolAndLength_2 = 54;
initialDLBWPk0_3 = 0;
initialDLBWPmappingType_3 = 0;
#this is SS=2,L=7
initialDLBWPstartSymbolAndLength_3 = 86;
initialDLBWPk0_4 = 0;
initialDLBWPmappingType_4 = 0;
#this is SS=2,L=5
initialDLBWPstartSymbolAndLength_4 = 58;
#this is SS=1,L=5
initialDLBWPstartSymbolAndLength_3 = 57;
#uplinkConfigCommon
#frequencyInfoUL
@@ -99,7 +95,7 @@ gNBs =
pMax = 20;
#initialUplinkBWP
#genericParameters
initialULBWPlocationAndBandwidth = 6368;
initialULBWPlocationAndBandwidth = 12952;
# subcarrierSpacing
# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
initialULBWPsubcarrierSpacing = 1;
@@ -111,7 +107,7 @@ gNBs =
prach_msg1_FDM = 0;
prach_msg1_FrequencyStart = 0;
zeroCorrelationZoneConfig = 13;
preambleReceivedTargetPower = -100;
preambleReceivedTargetPower = -96;
#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
preambleTransMax = 6;
#powerRampingStep
@@ -196,7 +192,7 @@ gNBs =
nrofUplinkSlots = 2;
nrofUplinkSymbols = 4;
ssPBCH_BlockPower = 10;
ssPBCH_BlockPower = -25;
}
);
@@ -255,10 +251,11 @@ MACRLCs = (
);
L1s = (
{
{
num_cc = 1;
tr_n_preference = "local_mac";
}
pusch_proc_threads = 8;
}
);
RUs = (
@@ -13,7 +13,7 @@ gNBs =
// Tracking area code, 0x0000 and 0xfffe are reserved values
tracking_area_code = 1;
plmn_list = ({mcc = 222; mnc = 93; mnc_length = 2;});
plmn_list = ({mcc = 208; mnc = 92; mnc_length = 2;});
tr_s_preference = "local_mac"
@@ -21,6 +21,7 @@ gNBs =
ssb_SubcarrierOffset = 0;
pdsch_AntennaPorts = 1;
pusch_AntennaPorts = 1;
pdcch_ConfigSIB1 = (
{
@@ -50,8 +51,8 @@ gNBs =
dl_carrierBandwidth = 106;
#initialDownlinkBWP
#genericParameters
# this is RBstart=41,L=24 (275*(L-1))+RBstart
initialDLBWPlocationAndBandwidth = 6368;
# this is RBstart=27,L=48 (275*(L-1))+RBstart
initialDLBWPlocationAndBandwidth = 12952; # 6366 12925 12956 28875 12952
# subcarrierSpacing
# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
initialDLBWPsubcarrierSpacing = 1;
@@ -64,13 +65,13 @@ gNBs =
#initialULBWPmappingType
#0=typeA,1=typeB
initialDLBWPmappingType_0 = 0;
#this is SS=2,L=12
initialDLBWPstartSymbolAndLength_0 = 53;
#this is SS=1,L=13
initialDLBWPstartSymbolAndLength_0 = 40;
initialDLBWPk0_1 = 0;
initialDLBWPmappingType_1 = 0;
#this is SS=2,L=10
initialDLBWPstartSymbolAndLength_1 = 81;
#this is SS=2,L=12
initialDLBWPstartSymbolAndLength_1 = 53;
initialDLBWPk0_2 = 0;
initialDLBWPmappingType_2 = 0;
@@ -94,7 +95,7 @@ gNBs =
pMax = 20;
#initialUplinkBWP
#genericParameters
initialULBWPlocationAndBandwidth = 6368;
initialULBWPlocationAndBandwidth = 12952;
# subcarrierSpacing
# 0=kHz15, 1=kHz30, 2=kHz60, 3=kHz120
initialULBWPsubcarrierSpacing = 1;
@@ -106,7 +107,7 @@ gNBs =
prach_msg1_FDM = 0;
prach_msg1_FrequencyStart = 0;
zeroCorrelationZoneConfig = 13;
preambleReceivedTargetPower = -100;
preambleReceivedTargetPower = -96;
#preamblTransMax (0...10) = (3,4,5,6,7,8,10,20,50,100,200)
preambleTransMax = 6;
#powerRampingStep
@@ -191,7 +192,7 @@ gNBs =
nrofUplinkSlots = 2;
nrofUplinkSymbols = 4;
ssPBCH_BlockPower = 10;
ssPBCH_BlockPower = -25;
}
);
@@ -250,10 +251,11 @@ MACRLCs = (
);
L1s = (
{
{
num_cc = 1;
tr_n_preference = "local_mac";
}
pusch_proc_threads = 8;
}
);
RUs = (