PHY class always transmitting

This commit is contained in:
ismagom 2015-06-05 14:13:58 +01:00
parent 851790e33c
commit 3f871a14a3
6 changed files with 55 additions and 22 deletions

View File

@ -72,6 +72,7 @@ namespace srslte {
private:
void *uhd;
bool is_first;
};
}

View File

@ -57,6 +57,7 @@ void radio_uhd::set_tx_rx_gain_offset(float offset) {
bool radio_uhd::init_agc(char *args)
{
is_first = true;
printf("Opening UHD device with threaded RX Gain control ...\n");
if (cuhd_open_th(args, &uhd, true)) {
fprintf(stderr, "Error opening uhd\n");
@ -87,7 +88,8 @@ void radio_uhd::get_time(srslte_timestamp_t *now) {
bool radio_uhd::tx(void* buffer, uint32_t nof_samples, srslte_timestamp_t tx_time)
{
if (cuhd_send_timed(uhd, buffer, nof_samples, tx_time.full_secs, tx_time.frac_secs) > 0) {
if (cuhd_send_timed2(uhd, buffer, nof_samples, tx_time.full_secs, tx_time.frac_secs, is_first, false) > 0) {
is_first = false;
return true;
} else {
return false;

View File

@ -59,7 +59,9 @@ namespace ue {
bool generate_data();
bool generate_data(ul_sched_grant *pusch_grant, uint8_t *payload);
bool generate_data(ul_sched_grant *pusch_grant, srslte_softbuffer_tx_t *softbuffer, uint8_t *payload);
bool send(radio* radio_handler, float time_adv_sec, float cfo, srslte_timestamp_t rx_time, bool normalize_amp);
bool send(radio* radio_handler, float time_adv_sec, float cfo, srslte_timestamp_t rx_time);
bool send_zeros(radio* radio_handler, float time_adv_sec, srslte_timestamp_t rx_time);
static const uint32_t tx_advance_sf = 1; // Number of subframes to advance transmission
private:

View File

@ -518,28 +518,41 @@ void phy::run_rx_tx_state()
log_h->step(current_tti);
float cfo = srslte_ue_sync_get_cfo(&ue_sync)/15000;
bool tx_zeros = true;
// Prepare transmission for the next tti
srslte_timestamp_add(&last_rx_time, 0, 1e-3);
// send prach if we have to
if (prach_buffer.is_ready_to_send(current_tti)) {
prach_buffer.send(radio_handler, cfo, last_rx_time);
radio_handler->set_tx_gain(old_gain);
srslte_agc_lock(&ue_sync.agc, false);
Info("Restoring AGC. Set TX gain to %.1f dB\n", old_gain);
}
// Generate scheduling request if we have to
if (sr_is_ready_to_send(current_tti+ul_buffer::tx_advance_sf)) {
get_ul_buffer_adv(current_tti)->generate_sr();
}
// send ul buffer if we have to
if (get_ul_buffer_adv(current_tti)->is_released() || get_ul_buffer_adv(current_tti)->uci_ready()) {
// Generate PUCCH if no UL grant
// Every subframe, TX a PRACH or a PUSCH/PUCCH
if (prach_buffer.is_ready_to_send(current_tti)) {
// send prach if we have to
prach_buffer.send(radio_handler, cfo, last_rx_time);
radio_handler->set_tx_gain(old_gain);
srslte_agc_lock(&ue_sync.agc, false);
Info("Restoring AGC. Set TX gain to %.1f dB\n", old_gain);
// If we don't transmit PRACH, check if need to transmit PUSCH/PUCCH
} else if (get_ul_buffer_adv(current_tti)->is_released() || get_ul_buffer_adv(current_tti)->uci_ready()) {
// If the packet was not generated by a call from MAC, means it's PUCCH. Generate now the signal
if (!get_ul_buffer_adv(current_tti)->is_released()) {
get_ul_buffer_adv(current_tti)->generate_data();
}
// And transmit
get_ul_buffer_adv(current_tti)->send(radio_handler, time_adv_sec, cfo, last_rx_time);
}
} else {
// Transmit zeros to avoid transitions.
// FIXME: This keeps the TX RF chain always on. Should transmit zeros only before a true transmission
get_ul_buffer_adv(current_tti)->send_zeros(radio_handler, time_adv_sec, last_rx_time);
}
// send ul buffer if we have to
// Generate PUCCH if no UL grant
// Receive alligned buffer for the current tti
get_dl_buffer(current_tti)->recv_ue_sync(&ue_sync, &last_rx_time);

View File

@ -218,7 +218,18 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof
int nof_tx = 0;
bool ul_buffer::send_zeros(srslte::radio* radio_handler, float time_adv_sec, srslte_timestamp_t rx_time)
{
bzero(signal_buffer, sizeof(cf_t)*SRSLTE_SF_LEN_PRB(cell.nof_prb));
send(radio_handler, time_adv_sec, 0, rx_time, false);
}
bool ul_buffer::send(srslte::radio* radio_handler, float time_adv_sec, float cfo, srslte_timestamp_t rx_time)
{
send(radio_handler, time_adv_sec, cfo, rx_time, true);
}
bool ul_buffer::send(srslte::radio* radio_handler, float time_adv_sec, float cfo, srslte_timestamp_t rx_time, bool normalize_amp)
{
// send packet through usrp
@ -227,20 +238,24 @@ bool ul_buffer::send(srslte::radio* radio_handler, float time_adv_sec, float cfo
srslte_timestamp_add(&tx_time, 0, tx_advance_sf*1e-3 - time_adv_sec);
// Correct CFO before transmission
srslte_cfo_correct(&ue_ul.cfo, signal_buffer, signal_buffer, cfo / srslte_symbol_sz(cell.nof_prb));
if (cfo != 0) {
srslte_cfo_correct(&ue_ul.cfo, signal_buffer, signal_buffer, cfo / srslte_symbol_sz(cell.nof_prb));
}
// Compute peak
float max = 0;
float *t = (float*) signal_buffer;
for (int i=0;i<2*SRSLTE_SF_LEN_PRB(cell.nof_prb);i++) {
if (fabsf(t[i]) > max) {
max = fabsf(t[i]);
if (normalize_amp) {
float *t = (float*) signal_buffer;
for (int i=0;i<2*SRSLTE_SF_LEN_PRB(cell.nof_prb);i++) {
if (fabsf(t[i]) > max) {
max = fabsf(t[i]);
}
}
// Normalize before TX
srslte_vec_sc_prod_cfc(signal_buffer, 0.9/max, signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
}
// Normalize before TX
srslte_vec_sc_prod_cfc(signal_buffer, 0.9/max, signal_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
Info("TX CFO: %f, len=%d, rx_time= %.6f tx_time = %.6f TA: %.1f us PeakAmplitude=%.2f PKT#%d\n",
cfo*15000, SRSLTE_SF_LEN_PRB(cell.nof_prb),
srslte_timestamp_real(&rx_time),

View File

@ -71,7 +71,7 @@ bool cuhd_rx_wait_lo_locked(void *h)
{
double report = 0.0;
while (isLocked(h) && report < 3000.0) {
while (isLocked(h) && report < 20.0) {
report += 0.1;
usleep(1000);
}