Merge branch 'working_mac' of https://github.com/srslte/srslte into working_mac

master
Paul Sutton 10 years ago
commit ec4ea55a4b

@ -81,7 +81,6 @@ private:
dl_sched_grant cur_grant;
dl_sched_grant pending_ack_grant;
ul_buffer *pending_ul_buffer;
bool is_first_tx;
bool pending_ack;
srslte::log *log_h;

@ -66,6 +66,7 @@ class ra_proc : public proc,timer_callback
void pdcch_to_crnti(bool is_ul_grant);
void timer_expired(uint32_t timer_id);
void* run_prach_thread();
private:
void process_timeadv_cmd(uint32_t ta_cmd);
@ -144,6 +145,9 @@ private:
demux *demux_unit;
pthread_t pt_init_prach;
pthread_cond_t cond;
pthread_mutex_t mutex;
bool start_prach_init;
uint64_t transmitted_contention_id;
uint16_t transmitted_crnti;

@ -148,11 +148,11 @@ void demux::process_pdu(sch_pdu *pdu_msg)
qbuff *dest_lch = mac_io_h->get(pdu_msg->get()->get_sdu_lcid());
if (dest_lch) {
dest_lch->send(pdu_msg->get()->get_sdu_ptr(), pdu_msg->get()->get_sdu_nbytes()*8);
Info("Sent MAC SDU len=%d bytes to lchid=%d\n",
Debug("Sent MAC SDU len=%d bytes to lchid=%d\n",
pdu_msg->get()->get_sdu_nbytes(), pdu_msg->get()->get_sdu_lcid());
if (sdu_handler_) {
sdu_handler_->notify_new_sdu(pdu_msg->get()->get_sdu_lcid());
Info("Notified SDU handler len=%d bytes to lchid=%d\n",
Debug("Notified SDU handler len=%d bytes to lchid=%d\n",
pdu_msg->get()->get_sdu_nbytes(), pdu_msg->get()->get_sdu_lcid());
}

@ -102,7 +102,6 @@ void dl_harq_entity::send_pending_ack_contention_resolution()
*********************************************************/
dl_harq_entity::dl_harq_process::dl_harq_process() : cur_grant(0),pending_ack_grant(0) {
is_first_tx = true;
is_initiated = false;
ack = false;
bzero(&cur_grant, sizeof(srslte::ue::dl_sched_grant));
@ -112,7 +111,6 @@ dl_harq_entity::dl_harq_process::dl_harq_process() : cur_grant(0),pending_ack_gr
void dl_harq_entity::dl_harq_process::reset() {
ack = false;
is_first_tx = true;
bzero(&cur_grant, sizeof(srslte::ue::dl_sched_grant));
if (is_initiated) {
srslte_softbuffer_rx_reset(&softbuffer);
@ -135,8 +133,17 @@ void dl_harq_entity::dl_harq_process::receive_data(uint32_t tti, srslte::ue::dl_
// If data has not yet been successfully decoded
if (ack == false) {
// Combine the received data and attempt to decode it
if (dl_buffer->decode_data(&cur_grant, &softbuffer, payload)) {
ack = true;
} else {
ack = false;
}
Info("DL PID %d: TBS=%d, RV=%d, MCS=%d, crc=%s\n", pid, cur_grant.get_tbs(), cur_grant.get_rv(), cur_grant.get_mcs(), ack?"OK":"NOK");
if (ack) {
// RX OK
if (pid == HARQ_BCCH_PID) {
Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit (BCCH)\n", cur_grant.get_tbs()/8);
@ -150,13 +157,10 @@ void dl_harq_entity::dl_harq_process::receive_data(uint32_t tti, srslte::ue::dl_
Debug("Delivering PDU=%d bytes to Dissassemble and Demux unit\n", cur_grant.get_tbs()/8);
harq_entity->demux_unit->push_pdu(payload, cur_grant.get_tbs());
}
ack = true;
is_first_tx = true;
}
} else {
// RX NOK
ack = false;
}
}
} else {
Warning("DL PID %d: Received duplicate TB. Discarting and retransmitting ACK\n");
}
if (pid == HARQ_BCCH_PID || harq_entity->timers_db->get(mac::TIME_ALIGNMENT)->is_expired()) {
// Do not generate ACK
@ -180,15 +184,15 @@ void dl_harq_entity::dl_harq_process::receive_data(uint32_t tti, srslte::ue::dl_
fprintf(stderr, "Error with DL grant. TBS (%d) exceeds payload buffer length (%d)\n", cur_grant.get_tbs(), max_payload_len);
}
}
Info("DL PID %d: TBS=%d, RV=%d, MCS=%d, crc=%s, PHY TTI: %d\n", pid, cur_grant.get_tbs(), cur_grant.get_rv(), cur_grant.get_mcs(), ack?"OK":"NOK", phy_h->get_current_tti());
}
// Implement 5.3.2.2
void dl_harq_entity::dl_harq_process::set_harq_info(srslte::ue::dl_sched_grant* new_grant) {
bool is_new_transmission = false;
if (new_grant->get_ndi() == true || is_first_tx || (pid == HARQ_BCCH_PID && new_grant->get_rv() == 0)) {
if ((new_grant->get_ndi() != cur_grant.get_ndi() && new_grant->get_tbs() == cur_grant.get_tbs()) || // NDI toggled for same TB (assume TB is identified by TBS)
(pid == HARQ_BCCH_PID && new_grant->get_rv() == 0) || // Broadcast PID and 1st TX (RV=0)
(new_grant->get_tbs() != cur_grant.get_tbs())) // First transmission for this TB
{
is_new_transmission = true;
Debug("Set HARQ Info for new transmission\n");
} else {
@ -196,16 +200,8 @@ void dl_harq_entity::dl_harq_process::set_harq_info(srslte::ue::dl_sched_grant*
Debug("Set HARQ Info for retransmission\n");
}
if (is_first_tx) {
Info("DL PID %d: first TX RV=%d, NDI=%d\n", pid, new_grant->get_rv(), new_grant->get_ndi());
} else {
Info("DL PID %d: %s RV=%d, NDI=%d, LastNDI=%d\n", pid, is_new_transmission?"new TX":"reTX", new_grant->get_rv(),
new_grant->get_ndi(), cur_grant.get_ndi());
}
if (is_first_tx) {
is_first_tx = false;
}
Info("DL PID %d: %s RV=%d, NDI=%d, LastNDI=%d, DCI %s\n", pid, is_new_transmission?"new TX":"reTX", new_grant->get_rv(),
new_grant->get_ndi(), cur_grant.get_ndi(), new_grant->get_dciformat_string());
if (is_new_transmission) {
ack = false;

@ -201,17 +201,17 @@ void mac::main_radio_loop() {
// Check if BSR procedure need to start SR
if (bsr_procedure.need_to_send_sr()) {
Info("Starting SR procedure by BSR request, PHY TTI=%d\n", phy_h->get_current_tti());
Debug("Starting SR procedure by BSR request, PHY TTI=%d\n", phy_h->get_current_tti());
sr_procedure.start();
} else if (bsr_procedure.need_to_reset_sr()) {
Info("Resetting SR procedure by BSR request\n");
Debug("Resetting SR procedure by BSR request\n");
sr_procedure.reset();
}
sr_procedure.step(tti);
// Check SR if we need to start RA
if (sr_procedure.need_random_access()) {
Info("Starting RA procedure by MAC order\n");
Warning("Starting RA procedure by MAC order is DISABLED\n");
//ra_procedure.start_mac_order();
}
@ -244,7 +244,6 @@ void mac::main_radio_loop() {
if (mux_unit.is_pending_ccch_sdu()) {
// Start RA procedure
if (!ra_procedure.in_progress() && !ra_procedure.is_successful()) {
Info("Starting RA procedure by RLC order\n");
ra_procedure.start_rlc_order();
}
}
@ -379,14 +378,17 @@ void mac::process_dl_grants(uint32_t tti) {
uint32_t harq_pid = ue_grant.get_harq_process();
if (i == mac_params::RNTI_TEMP && last_temporal_crnti != params_db.get_param(i)) {
ue_grant.set_ndi(true);
Info("Set NDI=1 for Temp-RNTI DL grant\n");
last_temporal_crnti = params_db.get_param(i);
}
if (i == mac_params::RNTI_C && dl_harq.is_sps(harq_pid)) {
ue_grant.set_ndi(true);
Info("Set NDI=1 for C-RNTI DL grant\n");
}
dl_harq.set_harq_info(harq_pid, &ue_grant);
dl_harq.receive_data(tti, harq_pid, dl_buffer, phy_h);
} else {
/* This is for SPS scheduling */
uint32_t harq_pid = get_harq_sps_pid(tti);
if (ue_grant.get_ndi()) {
ue_grant.set_ndi(false);
@ -428,7 +430,7 @@ void mac::process_dl_grants(uint32_t tti) {
if (!(phy_h->tti_to_subf(si_window_length) != 1 &&
phy_h->tti_to_subf(si_window_start) == 5 && (phy_h->tti_to_SFN(tti)%2) == 0))
{
Info("Searching for DL grant for SI-RNTI window_st=%d, window_len=%d\n", si_window_start, si_window_length);
Debug("Searching for DL grant for SI-RNTI window_st=%d, window_len=%d\n", si_window_start, si_window_length);
dl_sched_grant si_grant(sched_grant::RNTI_TYPE_SIRNTI, SRSLTE_SIRNTI);
if (dl_buffer->get_dl_grant(&si_grant)) {
uint32_t k;
@ -443,9 +445,7 @@ void mac::process_dl_grants(uint32_t tti) {
dl_harq.receive_data(tti, dl_harq_entity::HARQ_BCCH_PID, dl_buffer, phy_h);
params_db.set_param(mac_params::BCCH_SI_WINDOW_ST, 0);
params_db.set_param(mac_params::BCCH_SI_WINDOW_LEN, 0);
} else {
Warning("DL grant not found\n");
}
}
}
}

@ -230,7 +230,7 @@ bool mux::assemble_pdu(uint32_t pdu_sz_nbits) {
// MAC control element for BSR, with exception of BSR included for padding;
sch_subh *bsr_subh = NULL;
if (bsr_payload_sz) {
Info("Including BSR CE size %d\n", bsr_payload_sz);
Debug("Including BSR CE size %d\n", bsr_payload_sz);
if (pdu_msg.new_subh()) {
pdu_msg.next();
bsr_subh = pdu_msg.get();
@ -281,7 +281,7 @@ bool mux::assemble_pdu(uint32_t pdu_sz_nbits) {
}
}
Info("Assembled MAC PDU msg size %d/%d bytes\n", pdu_msg.size(), pdu_sz_nbits/8);
Debug("Assembled MAC PDU msg size %d/%d bytes\n", pdu_msg.size(), pdu_sz_nbits/8);
//pdu_msg.fprint(stdout);
/* Generate MAC PDU and save to buffer */
@ -321,7 +321,7 @@ bool mux::allocate_sdu(uint32_t lcid, sch_pdu *pdu_msg, uint32_t *sdu_sz, bool *
if (is_first) {
*is_first = false;
}
Info("Allocated SDU lcid=%d nbytes=%d\n", lcid, nbytes);
Debug("Allocated SDU lcid=%d nbytes=%d\n", lcid, nbytes);
// Increase number of pop'ed packets from queue
nof_tx_pkts[lcid]++;
return true;

@ -264,10 +264,10 @@ uint32_t bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size)
bsr_sz = bsr.format==LONG_BSR?3:1;
if (total_data <= grant_size && total_data + 1 + bsr_sz > grant_size) {
bsr_sz = 0;
Info("Grant is not enough to accomodate the BSR MAC CE\n");
Debug("Grant is not enough to accomodate the BSR MAC CE\n");
triggered_bsr_type = NONE;
}
Info("Checking if Regular BSR is sent: grant_size=%d, total_data=%d, bsr_sz=%d\n",
Debug("Checking if Regular BSR is sent: grant_size=%d, total_data=%d, bsr_sz=%d\n",
grant_size, total_data, bsr_sz);
}
return bsr_sz;
@ -285,7 +285,7 @@ bool bsr_proc::generate_bsr_on_ul_grant(uint32_t nof_padding_bytes, bsr_t *bsr)
}
generate_bsr(bsr, nof_padding_bytes);
ret = true;
Info("Sending BSR type %s, format %s, nof_padding_bytes=%d\n",
Debug("Sending BSR type %s, format %s, nof_padding_bytes=%d\n",
bsr_type_tostring(triggered_bsr_type), bsr_format_tostring(bsr->format), nof_padding_bytes);
if (timer_periodic && bsr->format != TRUNC_BSR) {
@ -308,6 +308,7 @@ bool bsr_proc::generate_bsr_on_ul_grant(uint32_t nof_padding_bytes, bsr_t *bsr)
bool bsr_proc::need_to_reset_sr() {
if (reset_sr) {
reset_sr = false;
sr_is_sent = false;
return true;
} else {
return false;

@ -47,6 +47,25 @@ uint32_t backoff_table[16] = {0, 10, 20, 30, 40, 60, 80, 120, 160, 240, 320, 480
// Table 7.6-1: DELTA_PREAMBLE values.
int delta_preamble_db_table[5] = {0, 0, -3, -3, 8};
void* init_prach_thread(void *arg) {
ra_proc* ra = (ra_proc*) arg;
return ra->run_prach_thread();
}
void* ra_proc::run_prach_thread() {
pthread_mutex_lock(&mutex);
while(!start_prach_init) {
pthread_cond_wait(&cond, &mutex);
}
pthread_mutex_unlock(&mutex);
if (phy_h->init_prach()) {
return (void*) 0;
} else {
return (void*) -1;
}
}
bool ra_proc::init(mac_params* params_db_, phy* phy_h_, srslte::log* log_h_, srslte::timers* timers_db_,
mux* mux_unit_, demux* demux_unit_)
{
@ -56,6 +75,12 @@ bool ra_proc::init(mac_params* params_db_, phy* phy_h_, srslte::log* log_h_, srs
timers_db = timers_db_;
mux_unit = mux_unit_;
demux_unit= demux_unit_;
start_prach_init = false;
if (pthread_create(&pt_init_prach, NULL, init_prach_thread, this)) {
perror("pthread_create");
}
pthread_mutex_init(&mutex, NULL);
pthread_cond_init(&cond, NULL);
reset();
}
@ -168,15 +193,6 @@ void ra_proc::process_timeadv_cmd(uint32_t ta) {
}
}
void* init_prach_thread(void *arg) {
phy* phy_h = (phy*) arg;
if (phy_h->init_prach()) {
return (void*) 0;
} else {
return (void*) -1;
}
}
void ra_proc::step_initialization() {
read_params();
pdcch_to_crnti_received = PDCCH_CRNTI_NOT_RECEIVED;
@ -185,12 +201,14 @@ void ra_proc::step_initialization() {
first_rar_received = true;
mux_unit->msg3_flush();
backoff_param_ms = 0;
if (pthread_create(&pt_init_prach, NULL, init_prach_thread, phy_h)) {
perror("pthread_create");
state = RA_PROBLEM;
} else {
state = INITIALIZATION_WAIT;
}
// Instruct phy prach init thread to start initialization
pthread_mutex_lock(&mutex);
start_prach_init = true;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
state = INITIALIZATION_WAIT;
}
void ra_proc::step_initialization_wait() {

@ -60,7 +60,7 @@ void sr_proc::step(uint32_t tti)
int last_tx_tti = phy_h->sr_last_tx_tti();
if (last_tx_tti >= 0 && last_tx_tti + 4 < tti) {
sr_counter++;
Info("SR signalling PHY. sr_counter=%d, PHY TTI=%d\n", sr_counter, phy_h->get_current_tti());
Debug("SR signalling PHY. sr_counter=%d, PHY TTI=%d\n", sr_counter, phy_h->get_current_tti());
phy_h->send_sr(true);
}
} else {
@ -94,7 +94,7 @@ void sr_proc::start()
is_pending_sr = true;
}
dsr_transmax = params_db->get_param(mac_params::SR_TRANS_MAX);
Info("SR starting dsrTransMax=%d. sr_counter=%d, PHY TTI=%d\n", dsr_transmax, sr_counter, phy_h->get_current_tti());
Debug("SR starting dsrTransMax=%d. sr_counter=%d, PHY TTI=%d\n", dsr_transmax, sr_counter, phy_h->get_current_tti());
}
}

@ -93,7 +93,7 @@ void ul_harq_entity::run_tti(uint32_t tti, ul_sched_grant *grant, phy *phy_h)
}
if (grant) {
if ((!grant->is_temp_rnti() && grant->get_ndi() == true) ||
if ((!grant->is_temp_rnti() && grant->get_ndi() != proc[pid].get_ndi()) ||
(grant->is_crnti() && !proc[pid].has_grant()) ||
grant->is_from_rar())
{

@ -75,6 +75,16 @@ namespace ue {
uint32_t get_mcs() {
return dl_dci.mcs_idx;
}
const char* get_dciformat_string() {
switch(dl_dci.dci_format) {
case srslte_ra_dl_dci_t::SRSLTE_RA_DCI_FORMAT1:
return "Format1";
case srslte_ra_dl_dci_t::SRSLTE_RA_DCI_FORMAT1A:
return "Format1A";
case srslte_ra_dl_dci_t::SRSLTE_RA_DCI_FORMAT1C:
return "Format1C";
}
}
bool create_from_dci(srslte_dci_msg_t *msg, uint32_t nof_prb, uint32_t ncce_) {
ncce = ncce_;
if (srslte_dci_msg_to_dl_grant(msg, rnti, nof_prb, &dl_dci, &grant)) {

@ -117,6 +117,8 @@ bool dl_buffer::get_ul_grant(ul_sched_grant *grant)
return false;
}
Info("PDCCH: UL DCI Format0 cce_index=%d, n_data_bits=%d\n", ue_dl.last_n_cce, dci_msg.nof_bits);
return grant->create_from_dci(&dci_msg, cell, params_db->get_param(phy_params::PUSCH_HOPPING_OFFSET));
}
}
@ -166,7 +168,7 @@ bool dl_buffer::get_dl_grant(dl_sched_grant *grant)
return false;
}
Info("Found DL DCI cce_index=%d, n_data_bits=%d\n", ue_dl.last_n_cce, dci_msg.nof_bits);
Info("PDCCH: DL DCI %s cce_index=%d, n_data_bits=%d\n", grant->get_dciformat_string(), ue_dl.last_n_cce, dci_msg.nof_bits);
return grant->create_from_dci(&dci_msg, cell.nof_prb, srslte_ue_dl_get_ncce(&ue_dl));
}

@ -199,7 +199,7 @@ bool phy::sr_is_ready_to_send(uint32_t tti_) {
if (srslte_ue_ul_sr_send_tti(I_sr, tti_)) {
sr_enabled = false;
sr_tx_tti = tti_;
Info("SR ready to send for TTI=%d\n", tti_);
Info("SR sending at TTI=%d\n", tti_);
return true;
}
}

@ -147,7 +147,7 @@ bool prach::send(radio *radio_handler, float cfo, srslte_timestamp_t rx_time)
}
radio_handler->tx(signal_buffer, len, tx_time);
Info("PRACH transmitted CFO: %f, preamble=%d, len=%d rx_time=%f, tx_time=%f, PeakAmplitude=%.2f\n",
Debug("PRACH transmitted CFO: %f, preamble=%d, len=%d rx_time=%f, tx_time=%f, PeakAmplitude=%.2f\n",
cfo*15000, preamble_idx, len, rx_time.frac_secs, tx_time.frac_secs, max);
preamble_idx = -1;
}

@ -195,8 +195,8 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof
*/
grant->to_pusch_cfg(tti%10, 0, &ue_ul);
Info("Encoding PUSCH TBS=%d, mod=%s, rb_start=%d n_prb=%d, ack=%s, sr=%s, rnti=%d, sf_idx=%d\n",
grant->get_tbs(), srslte_mod_string(ue_ul.pusch_cfg.grant.mcs.mod), ue_ul.pusch_cfg.grant.n_prb[0],
Info("PUSCH: TTI=%d, TBS=%d, mod=%s, rb_start=%d n_prb=%d, ack=%s, sr=%s, rnti=%d, sf_idx=%d\n",
tti, grant->get_tbs(), srslte_mod_string(ue_ul.pusch_cfg.grant.mcs.mod), ue_ul.pusch_cfg.grant.n_prb[0],
ue_ul.pusch_cfg.grant.L_prb,
uci_data.uci_ack_len>0?(uci_data.uci_ack?"1":"0"):"no",uci_data.scheduling_request?"yes":"no",
grant->get_rnti(), tti%10);
@ -207,7 +207,7 @@ bool ul_buffer::generate_data(ul_sched_grant *grant, srslte_softbuffer_tx_t *sof
grant->get_rnti(),
signal_buffer);
} else {
Info("Encoding PUCCH n_cce=%d, sf_idx=%d, ack=%s, sr=%s\n", last_n_cce, tti%10,
Info("PUCCH: TTI=%d n_cce=%d, sf_idx=%d, ack=%s, sr=%s\n", tti, last_n_cce, tti%10,
uci_data.uci_ack_len>0?(uci_data.uci_ack?"1":"0"):"no",uci_data.scheduling_request?"yes":"no");
n = srslte_ue_ul_pucch_encode(&ue_ul, uci_data, tti%10, signal_buffer);
@ -256,7 +256,7 @@ bool ul_buffer::send(srslte::radio* radio_handler, float time_adv_sec, float cfo
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 PeakAmplitude=%.2f PKT#%d\n",
Debug("TX CFO: %f, len=%d, rx_time= %.6f tx_time = %.6f TA: %.1f PeakAmplitude=%.2f PKT#%d\n",
cfo*15000, SRSLTE_SF_LEN_PRB(cell.nof_prb),
srslte_timestamp_real(&rx_time),
srslte_timestamp_real(&tx_time), time_adv_sec*1000000, max, nof_tx);

@ -523,7 +523,6 @@ int dci_format1_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32_t
data->harq_process = srslte_bit_unpack(&y, 3);
data->ndi = *y++ ? true : false;
// rv version
data->rv_idx = srslte_bit_unpack(&y, 2);
@ -670,10 +669,14 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32
data->harq_process = srslte_bit_unpack(&y, 3);
if (!crc_is_crnti && nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
data->type2_alloc.n_gap = *y++;
if (!crc_is_crnti) {
if (nof_prb >= 50 && data->type2_alloc.mode == SRSLTE_RA_TYPE2_DIST) {
data->type2_alloc.n_gap = *y++;
} else {
y++; // NDI reserved
}
} else {
y++; // bit reserved
data->ndi = *y++ ? true : false;
}
// rv version

@ -371,8 +371,6 @@ int srslte_prach_init(srslte_prach_t *p,
}
}
printf("Ncs=%d, zczc=%d, root_seq_index=%d, format=%d\n", p->N_cs, zero_corr_zone_config, root_seq_index, preamble_format);
// Set up containers
p->prach_bins = srslte_vec_malloc(sizeof(cf_t)*p->N_zc);
p->corr_spec = srslte_vec_malloc(sizeof(cf_t)*p->N_zc);

@ -340,7 +340,7 @@ int srslte_ue_ul_pusch_encode_rnti_softbuffer(srslte_ue_ul_t *q,
softbuffer != NULL &&
output_signal != NULL)
{
if (srslte_pusch_encode_rnti(&q->pusch, &q->pusch_cfg, softbuffer, data, rnti, q->sf_symbols)) {
if (srslte_pusch_uci_encode_rnti(&q->pusch, &q->pusch_cfg, softbuffer, data, uci_data, rnti, q->sf_symbols)) {
fprintf(stderr, "Error encoding TB\n");
return ret;
}

Loading…
Cancel
Save