* update bladerf interface

* update the runtime and deadline calcualtion 
* fix the isse with LIB_NAS_UE
* add additional testcases and fix the issues with autotest 


git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7736 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
navid
2015-07-23 17:38:53 +00:00
parent 23fd8953ea
commit 5a04f9696c
11 changed files with 469 additions and 92 deletions
@@ -46,8 +46,6 @@ int trx_brf_init(openair0_device *openair0) {
}
openair0_timestamp trx_get_timestamp(openair0_device *device) {
int status;
@@ -68,23 +66,44 @@ int trx_brf_start(openair0_device *openair0) {
return 0;
}
static void trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, void **buff, int nsamps, int cc) {
static void trx_brf_stats(openair0_device *device){
}
static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, void **buff, int nsamps, int cc) {
int status;
int status, i;
brf_state_t *brf = (brf_state_t*)device->priv;
/* BRF has only 1 rx/tx chaine : is it correct? */
void *samples = (void*)buff[0];
brf->meta_tx.timestamp= ptimestamp;
//brf->meta_tx.flags |= BLADERF_META_FLAG_TX_NOW;
status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, brf->timeout_ms);
//brf->meta_tx.flags &= ~BLADERF_META_FLAG_TX_NOW;
brf->meta_tx.flags = BLADERF_META_FLAG_TX_BURST_START |
BLADERF_META_FLAG_TX_NOW |
BLADERF_META_FLAG_TX_BURST_END;
brf->meta_tx.timestamp= (uint64_t) ptimestamp;
status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms);
if (status != 0) {
fprintf(stderr, "Failed to TX sample: %s\n", bladerf_strerror(status));
fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status));
brf->num_tx_errors++;
brf_error(status);
}
} else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN){
/* libbladeRF does not report this status. It is here for future use. */
fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n", brf->meta_tx.actual_count);
brf->num_underflows++;
}
// printf("tx status %d \n",brf->meta_tx.status);
brf->tx_current_ts=brf->meta_tx.timestamp;
brf->tx_actual_nsamps+=brf->meta_tx.actual_count;
brf->tx_nsamps+=nsamps;
brf->tx_count++;
return(0);
}
static int trx_brf_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) {
@@ -95,22 +114,26 @@ static int trx_brf_read(openair0_device *device, openair0_timestamp *ptimestamp,
// BRF has only one rx/tx chain
void *samples = (void*)buff[0];
brf->meta_rx.flags |= BLADERF_META_FLAG_RX_NOW;
status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, brf->timeout_ms);
status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms);
if (status != 0) {
fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status));
brf->num_rx_errors++;
} else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) {
brf->num_overflows++;
fprintf(stderr, "RX overrun (%d) in read @ t=0x%"PRIu64". Got %u samples. nsymps %d\n",
fprintf(stderr, "RX overrun (%d) is detected. t=0x%"PRIu64". Got %u samples. nsymps %d\n",
brf->num_overflows,brf->meta_rx.timestamp, brf->meta_rx.actual_count, nsamps);
//brf->meta_rx.timestamp=(unsigned int)(nsamps-brf->meta_rx.actual_count);
} //else printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status));
}
//printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status));
brf->rx_current_ts=brf->meta_rx.timestamp;
brf->rx_actual_nsamps+=brf->meta_rx.actual_count;
brf->rx_nsamps+=nsamps;
brf->rx_count++;
brf->rx_actual_count+=brf->meta_rx.actual_count;
brf->rx_count+=nsamps;
*ptimestamp = brf->meta_rx.timestamp;
return brf->meta_rx.actual_count;
@@ -162,7 +185,6 @@ int trx_brf_set_gains(openair0_device* device) {
}
int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
int status;
@@ -171,16 +193,16 @@ int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cf
brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t));
memset(brf, 0, sizeof(brf_state_t));
// init required params for BRF
//brf->dev_model = ;
brf->num_buffers = 128;
brf->buffer_size = (unsigned int)openair0_cfg[card].samples_per_packet*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024
brf->num_transfers = 16;
brf->timeout_ms = 0;
brf->num_buffers = 128;
brf->buffer_size = (unsigned int) openair0_cfg[card].samples_per_packet*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024
brf->num_transfers = 16;
brf->rx_timeout_ms = 0;
brf->tx_timeout_ms = 0;
brf->sample_rate=(unsigned int)openair0_cfg[card].sample_rate;
printf("\n[BRF] sampling_rate %d, num_buffers %d, buffer_size %d, num transfer %d, timeout_ms %d\n",
brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->timeout_ms);
printf("\n[BRF] sampling_rate %d, num_buffers %d, buffer_size %d, num transfer %d, timeout_ms (rx %d, tx %d)\n",
brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms);
if ((status=bladerf_open(&brf->dev, "")) != 0 ) {
fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status));
@@ -225,7 +247,7 @@ int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cf
/* Configure the device's RX module for use with the sync interface.
* SC16 Q11 samples *with* metadata are used. */
if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->timeout_ms)) != 0 ) {
if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) {
fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status));
brf_error(status);
}else
@@ -267,7 +289,7 @@ int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cf
/* Configure the device's TX module for use with the sync interface.
* SC16 Q11 samples *with* metadata are used. */
if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->timeout_ms)) != 0 ) {
if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) {
fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status));
brf_error(status);
}else
@@ -279,7 +301,7 @@ int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cf
fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status));
brf_error(status);
} else
printf("[BRF] RX module enabled \n");
printf("[BRF] TX module enabled \n");
bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg[card].log_level));
@@ -302,14 +324,11 @@ int openair0_device_init(openair0_device *device, openair0_config_t *openair0_cf
int brf_error(int status) {
exit(-1);
//exit(-1);
//return 1; // or status error code
}
int openair0_set_rx_frequencies(openair0_device* device, openair0_config_t *openair0_cfg) {
return 0;
}
struct bladerf * open_bladerf_from_serial(const char *serial) {
@@ -340,7 +359,7 @@ struct bladerf * open_bladerf_from_serial(const char *serial) {
int get_brf_log_level(int log_level){
int level=BLADERF_LOG_LEVEL_INFO;
return BLADERF_LOG_LEVEL_DEBUG;
//return BLADERF_LOG_LEVEL_DEBUG;
switch(log_level) {
case LOG_DEBUG:
level=BLADERF_LOG_LEVEL_DEBUG;
@@ -46,7 +46,8 @@ typedef struct {
unsigned int num_buffers;
unsigned int buffer_size;
unsigned int num_transfers;
unsigned int timeout_ms;
unsigned int rx_timeout_ms;
unsigned int tx_timeout_ms;
struct bladerf_metadata meta_rx;
struct bladerf_metadata meta_tx;
@@ -67,8 +68,12 @@ typedef struct {
int num_rx_errors;
int num_tx_errors;
uint64_t tx_actual_count;
uint64_t rx_actual_count;
uint64_t tx_current_ts;
uint64_t rx_current_ts;
uint64_t tx_actual_nsamps;
uint64_t rx_actual_nsamps;
uint64_t tx_nsamps;
uint64_t rx_nsamps;
uint64_t tx_count;
uint64_t rx_count;
openair0_timestamp rx_timestamp;
+5 -4
View File
@@ -118,10 +118,11 @@ static void trx_usrp_end(openair0_device *device)
s->rx_stream->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS);
//send a mini EOB packet
s->tx_md.end_of_burst = true;
s->tx_stream->send("", 0, s->tx_md);
s->tx_md.end_of_burst = false;
//send a mini EOB packet
s->tx_md.end_of_burst = true;
s->tx_stream->send("", 0, s->tx_md);
s->tx_md.end_of_burst = false;
}
static int trx_usrp_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags)
@@ -28,7 +28,7 @@ eNBs =
tdd_config_s = 0;
prefix_type = "NORMAL";
eutra_band = 7;
downlink_frequency = 2660000000L;
downlink_frequency = 2680000000L;
uplink_frequency_offset = -120000000;
Nid_cell = 0;
N_RB_DL = 25;
+50 -34
View File
@@ -1026,24 +1026,30 @@ static void* eNB_thread_tx( void* param )
#ifdef LOWLATENCY
struct sched_attr attr;
unsigned int flags = 0;
uint64_t runtime = (uint64_t) (get_runtime_tx(proc->subframe, runtime_phy_tx, target_dl_mcs,frame_parms[0]->N_RB_DL,cpuf,PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_tx) * 1000000);
uint64_t deadline = 1 * 1000000; // each tx thread will finish within 1ms
uint64_t period = 1 * 10000000; // each tx thread has a period of 10ms from the starting point
if (runtime > 1000000 ){
LOG_W(HW,"estimated runtime %d is larger than 1ms, adjusting\n",runtime);
runtime = (0.97 * 100) * 10000;
}
attr.size = sizeof(attr);
attr.sched_flags = 0;
attr.sched_nice = 0;
attr.sched_priority = 0;
attr.sched_policy = SCHED_DEADLINE;
//attr.sched_runtime = 0.9 * 1000000; // each tx thread requires 1ms to finish its job
attr.sched_runtime = (uint64_t) (get_runtime_tx(proc->subframe, runtime_phy_tx, target_dl_mcs,frame_parms[0]->N_RB_DL,cpuf,PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_tx) * 1000000); // each tx thread requires 1ms to finish its job
attr.sched_deadline = 1 * 1000000; // each tx thread will finish within 1ms
attr.sched_period = 1 * 10000000; // each tx thread has a period of 10ms from the starting point
attr.sched_policy = SCHED_DEADLINE;
attr.sched_runtime = runtime;
attr.sched_deadline = deadline;
attr.sched_period = period;
if (sched_setattr(0, &attr, flags) < 0 ) {
perror("[SCHED] eNB tx thread: sched_setattr failed\n");
return &eNB_thread_tx_status[proc->subframe];
}
LOG_I( HW, "[SCHED] eNB TX deadline thread %d(Tid %ld) started on CPU %d\n", proc->subframe, gettid(), sched_getcpu() );
LOG_I( HW, "[SCHED] eNB TX deadline thread %d(TID %ld) started on CPU %d\n", proc->subframe, gettid(), sched_getcpu() );
#else
LOG_I( HW, "[SCHED][eNB] TX thread %d started on CPU %d TID %d\n", proc->subframe, sched_getcpu(),gettid() );
#endif
@@ -1227,17 +1233,24 @@ static void* eNB_thread_rx( void* param )
#ifdef LOWLATENCY
struct sched_attr attr;
unsigned int flags = 0;
uint64_t runtime = get_runtime_rx(proc->subframe, runtime_phy_rx, target_ul_mcs,frame_parms[0]->N_RB_DL,cpuf,PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_rx) * 1000000;
uint64_t deadline = 1 * 1000000;
uint64_t period = 1 * 10000000; // each rx thread has a period of 10ms from the starting point
if (runtime > 2300000 ) {
LOG_W(HW,"estimated rx runtime %d is larger than expected, adjusting\n",runtime);
runtime = 2300000;
deadline = runtime + 100000;
}
attr.size = sizeof(attr);
attr.sched_flags = 0;
attr.sched_nice = 0;
attr.sched_priority = 0;
/* This creates a 2ms reservation every 10ms period*/
attr.sched_policy = SCHED_DEADLINE;
attr.sched_runtime = (uint64_t)(get_runtime_rx(proc->subframe, runtime_phy_rx, target_ul_mcs,frame_parms[0]->N_RB_DL,cpuf,PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_rx) * 1000000); // each tx thread requires 1ms to finish its job
attr.sched_deadline = 1 * 1000000; // each rx thread will finish within 2ms
attr.sched_period = 1 * 10000000; // each rx thread has a period of 10ms from the starting point
attr.sched_runtime = runtime;
attr.sched_deadline = deadline;
attr.sched_period = period;
if (sched_setattr(0, &attr, flags) < 0 ) {
perror("[SCHED] eNB RX sched_setattr failed\n");
@@ -1354,17 +1367,18 @@ void init_eNB_proc(void)
for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
for (i=0; i<NUM_ENB_THREADS; i++) {
// set the stack size
pthread_attr_init( &attr_eNB_proc_tx[CC_id][i] );
/*
if (pthread_attr_setstacksize( &attr_eNB_proc_tx[CC_id][i], PTHREAD_STACK_MIN ) != 0)
#ifndef LOWLATENCY
/*
pthread_attr_init( &attr_eNB_proc_tx[CC_id][i] );
if (pthread_attr_setstacksize( &attr_eNB_proc_tx[CC_id][i], 64 *PTHREAD_STACK_MIN ) != 0)
perror("[ENB_PROC_TX] setting thread stack size failed\n");
pthread_attr_init( &attr_eNB_proc_rx[CC_id][i] );
if (pthread_attr_setstacksize( &attr_eNB_proc_rx[CC_id][i], PTHREAD_STACK_MIN ) != 0)
if (pthread_attr_setstacksize( &attr_eNB_proc_rx[CC_id][i], 64 * PTHREAD_STACK_MIN ) != 0)
perror("[ENB_PROC_RX] setting thread stack size failed\n");
*/
#ifndef LOWLATENCY
// set the kernel scheduling policy and priority
sched_param_eNB_proc_tx[CC_id][i].sched_priority = sched_get_priority_max(SCHED_FIFO)-1; //OPENAIR_THREAD_PRIORITY;
pthread_attr_setschedparam (&attr_eNB_proc_tx[CC_id][i], &sched_param_eNB_proc_tx[CC_id][i]);
@@ -1562,7 +1576,7 @@ static void* eNB_thread( void* arg )
/* This creates a .2 ms reservation */
attr.sched_policy = SCHED_DEADLINE;
attr.sched_runtime = (0.2 * 100) * 10000;
attr.sched_runtime = (0.3 * 100) * 10000;
attr.sched_deadline = (0.9 * 100) * 10000;
attr.sched_period = 1 * 1000000;
@@ -1761,7 +1775,7 @@ static void* eNB_thread( void* arg )
stop_meas( &softmodem_stats_hw );
clock_gettime( CLOCK_MONOTONIC, &trx_time1 );
if (frame > 10){
if (frame > 20){
if (rxs != spp)
exit_fun( "problem receiving samples" );
}
@@ -1770,22 +1784,22 @@ static void* eNB_thread( void* arg )
// Transmit TX buffer based on timestamp from RX
if (frame > 50) {
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );
// prepare tx buffer pointers
for (i=0; i<PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_tx; i++){
txp[i] = (void*)&rxdata[i][tx_pos];
//printf("tx_pos %d ts %d, ts_offset %d txp[i] %p, ap %d\n", tx_pos, timestamp, (timestamp+(tx_delay*spp)-tx_forward_nsamps),txp[i], i);
if (frame > 50) {
VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_TRX_WRITE, 1 );
// prepare tx buffer pointers
for (i=0; i<PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_tx; i++){
txp[i] = (void*)&rxdata[i][tx_pos];
//printf("tx_pos %d ts %d, ts_offset %d txp[i] %p, ap %d\n", tx_pos, timestamp, (timestamp+(tx_delay*spp)-tx_forward_nsamps),txp[i], i);
// if symb_written < spp ==> error
openair0.trx_write_func(&openair0,
(timestamp+(openair0_cfg[card].tx_delay*spp)-openair0_cfg[card].tx_forward_nsamps),
txp,
spp,
i,
1);
(timestamp+(openair0_cfg[card].tx_delay*spp)-openair0_cfg[card].tx_forward_nsamps),
txp,
spp,
i,
1);
}
}
}
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TS, timestamp&0xffffffff );
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TRX_TST, (timestamp+(openair0_cfg[card].tx_delay*spp)-openair0_cfg[card].tx_forward_nsamps)&0xffffffff );
@@ -2857,8 +2871,8 @@ int main( int argc, char **argv )
openair0_cfg[card].tx_forward_nsamps = 70;
openair0_cfg[card].tx_delay = 6;
#elif OAI_BLADERF
openair0_cfg[card].tx_forward_nsamps = 70;
openair0_cfg[card].tx_delay = 6;
openair0_cfg[card].tx_forward_nsamps = 0;
openair0_cfg[card].tx_delay = 8;
#endif
#endif
} else if (frame_parms[0]->N_RB_DL == 6) {
@@ -3426,6 +3440,8 @@ openair0_cfg[card].num_rb_dl=frame_parms[0]->N_RB_DL;
openair0_stop(0);
printf("closing openair0_lib\n");
openair0_close();
#else
openair0.trx_end_func(&openair0);
#endif
#ifdef EMOS