Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance idle mode #20

Merged
merged 4 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mac/mac_bs.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,8 @@ void mac_bs_run_scheduler(MacBS mac) {
}

// 4. set slot assignments in PHY
phy_assign_dlctrl_dd(mac->phy, mac->dl_data_assignments[next_sfn]);
phy_assign_dlctrl_dd(mac->phy, next_sfn % 2,
mac->dl_data_assignments[next_sfn]);
phy_assign_dlctrl_ud(mac->phy, next_sfn % 2,
mac->ul_data_assignments[next_sfn]);
phy_assign_dlctrl_uc(mac->phy, next_sfn % 2,
Expand Down
52 changes: 34 additions & 18 deletions src/phy/phy_bs.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ PhyBS phy_bs_init() {
phy->ul_symbol_alloc[0] = calloc(sizeof(uint8_t) * SUBFRAME_LEN, 1);
phy->ul_symbol_alloc[1] = calloc(sizeof(uint8_t) * SUBFRAME_LEN, 1);

phy->dl_symbol_alloc = malloc(sizeof(uint8_t *) * 2);
phy->dl_symbol_alloc[0] = calloc(SUBFRAME_LEN, 1);
phy->dl_symbol_alloc[1] = calloc(SUBFRAME_LEN, 1);
memset(phy->dl_symbol_alloc[0], DATA, DLCTRL_LEN);
memset(phy->dl_symbol_alloc[1], DATA, DLCTRL_LEN);

// allocate memory for rach_buffer
phy->rach_buffer = calloc(sizeof(float complex) * nfft, 1);

Expand Down Expand Up @@ -270,11 +276,20 @@ void phy_map_dlctrl(PhyBS phy, uint subframe) {
}

// Set the assignments of Downlink data slots
void phy_assign_dlctrl_dd(PhyBS phy, uint8_t *slot_assignment) {
void phy_assign_dlctrl_dd(PhyBS phy, uint subframe, uint8_t *slot_assignment) {
for (int i = 0; i < NUM_SLOT; i += 2) {
phy->dlctrl_buf[i / 2].h4 = slot_assignment[i];
phy->dlctrl_buf[i / 2].l4 = slot_assignment[i + 1];
}
// set allocation with ofdm symbol granularity.
memset(&phy->dl_symbol_alloc[subframe][4],
slot_assignment[0] == 0 ? NOT_USED : DATA, SLOT_LEN);
memset(&phy->dl_symbol_alloc[subframe][4 + SLOT_LEN + 1],
slot_assignment[1] == 0 ? NOT_USED : DATA, SLOT_LEN);
memset(&phy->dl_symbol_alloc[subframe][4 + 2 * (SLOT_LEN + 1)],
slot_assignment[2] == 0 ? NOT_USED : DATA, SLOT_LEN);
memset(&phy->dl_symbol_alloc[subframe][4 + 3 * (SLOT_LEN + 1)],
slot_assignment[3] == 0 ? NOT_USED : DATA, SLOT_LEN);
}

// Set the assignments of Uplink data slots
Expand Down Expand Up @@ -541,6 +556,10 @@ void phy_bs_write_symbol(PhyBS phy, float complex *txbuf_time) {
uint tx_symb = common->tx_symbol;
uint sfn = common->tx_subframe % 2;

// reset msequence for pilot generation every slot
if (common->pilot_symbols_tx[tx_symb] == PILOT_RESET)
ofdmframegen_reset(phy->fg);

// check if we have to add synch sequence in this subframe
if (common->tx_subframe == 0 && tx_symb == SUBFRAME_LEN - 1 - SYNC_SYMBOLS) {
ofdmframegen_reset(phy->fg);
Expand All @@ -554,12 +573,16 @@ void phy_bs_write_symbol(PhyBS phy, float complex *txbuf_time) {
} else if (common->tx_subframe == 0 &&
tx_symb == SUBFRAME_LEN - 1 - SYNC_SYMBOLS + 3) {
phy_bs_write_sync_info(phy, txbuf_time);
} else if (common->pilot_symbols_tx[tx_symb] == PILOT) {
ofdmframegen_writesymbol(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
} else if (phy->dl_symbol_alloc[sfn][tx_symb] == DATA) {
if (common->pilot_symbols_tx[tx_symb] == NO_PILOT) {
ofdmframegen_writesymbol_nopilot(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
} else {
ofdmframegen_writesymbol(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
}
} else {
ofdmframegen_writesymbol_nopilot(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
memset(txbuf_time, 0, sizeof(float complex) * (nfft + cp_len));
}

// clear frequency domain memory of the written symbol, to avoid sending
Expand Down Expand Up @@ -628,24 +651,17 @@ void phy_bs_rx_symbol(PhyBS phy, float complex *rxbuf_time) {
uint userid = phy->ul_symbol_alloc[sfn % 2][common->rx_symbol];
ofdmframesync fs = mac_bs_get_receiver(phy->mac, userid);
if (fs != NULL) {
// if this is the first symbol of a slot, soft reset the
// sync object
uint prev_rx_symb = (common->rx_symbol - 1) % SUBFRAME_LEN;
if (common->rx_symbol == 0 ||
phy->ul_symbol_alloc[sfn % 2][prev_rx_symb] == 0) {
// if this is the first symbol of a slot, soft reset the sync object
if (common->pilot_symbols_rx[common->rx_symbol] == PILOT_RESET) {
ofdmframesync_reset_soft(fs);
}

if (common->pilot_symbols_rx[common->rx_symbol] == PILOT) {
ofdmframesync_reset_msequence(fs);
if (common->pilot_symbols_rx[common->rx_symbol] == NO_PILOT) {
ofdmframesync_execute_nopilot(fs, rxbuf_time, rx_sym);
} else {
ofdmframesync_execute(fs, rxbuf_time, rx_sym);
LOG_SFN_PHY(TRACE, "[PHY BS] cfo was: %.3fHz\n",
ofdmframesync_get_cfo(fs) * samplerate / 6.28);
// ofdmframesync_set_cfo(fs,0); // TODO cfo estimation. Currently not
// working since we often receive if no data is sent. -> wrong pilot ->
// wrong cfo
} else {
ofdmframesync_execute_nopilot(fs, rxbuf_time, rx_sym);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/phy/phy_bs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ struct PhyBS_s {
uint8_t **ulslot_assignments;
uint8_t **ulctrl_assignments;

// store uplink resource allocation on OFDM symbol basis
// store resource allocation on OFDM symbol basis
// BS has to pick the correct ofdmframesync object depending on the user
// 1. Index: subframe index: 0 -> even, 1->odd
// 2. Index ofdm symbol idx
uint8_t **ul_symbol_alloc;
uint8_t **dl_symbol_alloc;

dlctrl_alloc_t *dlctrl_buf; // holds DL ctrl slot data

Expand Down Expand Up @@ -81,7 +82,7 @@ void phy_bs_set_rx_slot_th_signal(PhyBS phy, pthread_cond_t *cond);
int phy_map_dlslot(PhyBS phy, LogicalChannel chan, uint subframe,
uint8_t slot_nr, uint userid, uint mcs);
void phy_map_dlctrl(PhyBS phy, uint subframe);
void phy_assign_dlctrl_dd(PhyBS phy, uint8_t *slot_assignment);
void phy_assign_dlctrl_dd(PhyBS phy, uint subframe, uint8_t *slot_assignment);
void phy_assign_dlctrl_ud(PhyBS phy, uint subframe, uint8_t *slot_assignment);
void phy_assign_dlctrl_uc(PhyBS phy, uint subframe, uint8_t *slot_assignment);

Expand Down
17 changes: 14 additions & 3 deletions src/phy/phy_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ void gen_pilot_symbols(PhyCommon phy, uint is_bs) {
memset(pilot_ul, NO_PILOT, SUBFRAME_LEN);

// DL: dlctrl slot uses pilots
memset(&pilot_dl[0], PILOT, DLCTRL_LEN);
pilot_dl[0] = PILOT_RESET;
pilot_dl[1] = PILOT;

// replicate slot allocation for one slot over the subframe
for (int slot_nr = 0; slot_nr < NUM_SLOT; slot_nr++) {
int slot_start = DLCTRL_LEN + 2 * SLOT_GUARD_INTERVAL +
slot_nr * (SLOT_LEN + SLOT_GUARD_INTERVAL);
memcpy(&pilot_dl[slot_start], pilot_symbols, SLOT_LEN);
pilot_dl[slot_start] = PILOT_RESET; // force first symbol of the slot to
// contain the pilot sequence reset flag
}

// Pilot symbols within subframe in UL
Expand All @@ -236,7 +239,15 @@ void gen_pilot_symbols(PhyCommon phy, uint is_bs) {
memcpy(&pilot_ul[3 * (SLOT_LEN + SLOT_GUARD_INTERVAL) + NUM_ULCTRL_SLOT * 2],
pilot_symbols, SLOT_LEN);

// force first symbol of the slot to contain the pilot sequence reset flag
pilot_ul[0] = PILOT_RESET;
pilot_ul[SLOT_LEN + SLOT_GUARD_INTERVAL] = PILOT_RESET;
pilot_ul[2 * (SLOT_LEN + SLOT_GUARD_INTERVAL) + NUM_ULCTRL_SLOT * 2] =
PILOT_RESET;
pilot_ul[3 * (SLOT_LEN + SLOT_GUARD_INTERVAL) + NUM_ULCTRL_SLOT * 2] =
PILOT_RESET;

// ulctrl slots
pilot_ul[2 * (SLOT_LEN + SLOT_GUARD_INTERVAL)] = PILOT;
pilot_ul[2 * (SLOT_LEN + SLOT_GUARD_INTERVAL) + 2] = PILOT;
pilot_ul[2 * (SLOT_LEN + SLOT_GUARD_INTERVAL)] = PILOT_RESET;
pilot_ul[2 * (SLOT_LEN + SLOT_GUARD_INTERVAL) + 2] = PILOT_RESET;
}
6 changes: 5 additions & 1 deletion src/phy/phy_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../util/log.h"
#include <libconfig.h>
#include <liquid/liquid.h>
#include <string.h>

void phy_config_load_file(char *config_file) {
config_t cfg;
Expand Down Expand Up @@ -134,7 +135,10 @@ void phy_config_default_64() {
num_data_sc = 32;
num_pilot_sc = 8;
pilot_symbols_per_slot = 7;
pilot_symbols = calloc(SLOT_LEN, 1);

pilot_symbols = malloc(SLOT_LEN);
memset(pilot_symbols, NO_PILOT, SLOT_LEN);
pilot_symbols[0] = PILOT_RESET;
for (int i = 0; i < SLOT_LEN; i += 2)
pilot_symbols[i] = PILOT;

Expand Down
4 changes: 2 additions & 2 deletions src/phy/phy_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ enum {
DATA,
PTT_UP,
PTT_DOWN
}; // definition for tx_symbol allocation variable
enum { NO_PILOT, PILOT }; // definition for pilot_symbols variable
}; // definition for tx_symbol allocation variable
enum { NO_PILOT, PILOT, PILOT_RESET }; // definition for pilot_symbols variable

// ---------------------------- global PHY layer configurtion
// --------------------------------- //
Expand Down
42 changes: 34 additions & 8 deletions src/phy/phy_ue.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ PhyUE phy_ue_init() {
phy->ul_symbol_alloc[0] = calloc(sizeof(uint8_t) * SUBFRAME_LEN, 1);
phy->ul_symbol_alloc[1] = calloc(sizeof(uint8_t) * SUBFRAME_LEN, 1);

phy->dl_symbol_alloc = calloc(SUBFRAME_LEN, 1);
memset(phy->dl_symbol_alloc, DATA,
DLCTRL_LEN); // always listen for dlctrl slot

phy->mac_rx_cb = NULL;
phy->has_synced_once = 0;

Expand Down Expand Up @@ -255,6 +259,15 @@ int phy_ue_proc_dlctrl(PhyUE phy) {
idx++;
}

// assign which for which symbols we have to do rx
memset(&phy->dl_symbol_alloc[DLCTRL_LEN + 2], NOT_USED,
NUM_SLOT * (SLOT_LEN + SLOT_GUARD_INTERVAL));
for (int i = 0; i < NUM_SLOT; i++) {
if (phy->dlslot_assignments[sfn][i] != NOT_ASSIGNED)
memset(&phy->dl_symbol_alloc[DLCTRL_LEN + 2 +
(SLOT_LEN + SLOT_GUARD_INTERVAL) * i],
DATA, SLOT_LEN);
}
// Pass slot assignment to MAC
mac_ue_set_assignments(phy->mac, phy->dlslot_assignments[sfn],
phy->ulslot_assignments[sfn],
Expand Down Expand Up @@ -575,14 +588,16 @@ void phy_ue_write_symbol(PhyUE phy, float complex *txbuf_time) {
}
} else if (phy->ul_symbol_alloc[sfn][tx_symb] == DATA) {
// MAC is associated and have data to send.
if (common->pilot_symbols_tx[tx_symb] == PILOT) {
ofdmframegen_reset(phy->fg); // TODO we use the same msequence in every
// pilot symbol sent. Fix this
ofdmframegen_writesymbol(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
} else {
// reset msequence for pilot generation every slot
if (common->pilot_symbols_tx[tx_symb] == PILOT_RESET)
ofdmframegen_reset(phy->fg);

if (common->pilot_symbols_tx[tx_symb] == NO_PILOT) {
ofdmframegen_writesymbol_nopilot(
phy->fg, common->txdata_f[sfn][tx_symb], txbuf_time);
} else {
ofdmframegen_writesymbol(phy->fg, common->txdata_f[sfn][tx_symb],
txbuf_time);
}
} else if (phy->ul_symbol_alloc[sfn][tx_symb] == PTT_UP) {
memset(txbuf_time, 0, sizeof(float complex) * (nfft + cp_len));
Expand Down Expand Up @@ -622,10 +637,14 @@ void phy_ue_do_rx(PhyUE phy, float complex *rxbuf_time, uint num_samples) {
} else {
remaining_samps = 0;
}
} else {
} else if (phy->dl_symbol_alloc[common->rx_symbol] == DATA) {
// receive symbols
// reset msequence for pilot reception every slot
if (common->pilot_symbols_rx[common->rx_symbol] == PILOT_RESET)
ofdmframesync_reset_msequence(phy->fs);

uint rx_sym = fmin(nfft + cp_len, remaining_samps);
if (common->pilot_symbols_rx[common->rx_symbol] == PILOT ||
if (common->pilot_symbols_rx[common->rx_symbol] != NO_PILOT ||
(common->rx_subframe == 0 && common->rx_symbol == SUBFRAME_LEN - 2)) {
ofdmframesync_execute(phy->fs, rxbuf_time, rx_sym);
LOG(TRACE, "[PHY UE] cfo updated: %.3f Hz\n",
Expand All @@ -635,6 +654,13 @@ void phy_ue_do_rx(PhyUE phy, float complex *rxbuf_time, uint num_samples) {
}
remaining_samps -= rx_sym;
rxbuf_time += rx_sym;
} else {
// no data transmission is scheduled. Receive anyway, but do not adapt
// pilots
uint rx_sym = fmin(nfft + cp_len, remaining_samps);
ofdmframesync_execute_nopilot(phy->fs, rxbuf_time, rx_sym);
remaining_samps -= rx_sym;
rxbuf_time += rx_sym;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/phy/phy_ue.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct PhyUE_s {
// 1. Index: subframe index: 0 -> even, 1->odd
// 2. Index ofdm symbol idx
uint8_t **ul_symbol_alloc;
uint8_t *dl_symbol_alloc;

// Currently used modulation scheme for RX
uint mcs_dl;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/pluto.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ void init_generic(platform hw, uint buf_len, char *config_file) {
// Set RX AGC to slow attack
get_phy_chan(pluto->ctx, RX, 0, &chn);
wr_ch_str(chn, "gain_control_mode",
"slow_attack"); // fast_attack, slow_attack, manual
"fast_attack"); // fast_attack, slow_attack, manual
// wr_ch_lli(chn, "hardwaregain", 26.0);

printf("* Enabling IIO streaming channels\n");
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ void *thread_phy_ue_tx(void *arg) {
num_samples = buflen - tx_shift;

// set PTT signal delay
pluto_ptt_set_switch_delay(hw,
(int)((buflen * KERNEL_BUF_TX + tx_shift) *
1000000.0 / samplerate));
pluto_ptt_set_switch_delay(
hw, (int)((buflen * (KERNEL_BUF_TX - 1) + tx_shift) * 1000000.0 /
samplerate));
}
}
}
Expand Down