simplified MAC timers. Unified mac and upper timers in same background task

master
Ismael Gomez 7 years ago
parent 5359c42b46
commit 6556941e6d

@ -71,9 +71,9 @@ public:
/* Timer services with ms resolution. /* Timer services with ms resolution.
* timer_id must be lower than MAC_NOF_UPPER_TIMERS * timer_id must be lower than MAC_NOF_UPPER_TIMERS
*/ */
virtual timers::timer* get(uint32_t timer_id) = 0; virtual timers::timer* timer_get(uint32_t timer_id) = 0;
virtual void free(uint32_t timer_id) = 0; virtual void timer_release_id(uint32_t timer_id) = 0;
virtual uint32_t get_unique_id() = 0; virtual uint32_t timer_get_unique_id() = 0;
}; };
class read_pdu_interface class read_pdu_interface

@ -125,7 +125,8 @@ private:
* Timers * Timers
* Ref: 3GPP TS 36.322 v10.0.0 Section 7 * Ref: 3GPP TS 36.322 v10.0.0 Section 7
***************************************************************************/ ***************************************************************************/
uint32_t reordering_timeout_id; srslte::timers::timer *reordering_timer;
uint32_t reordering_timer_id;
bool pdu_lost; bool pdu_lost;

@ -62,7 +62,8 @@ void rlc_um::init(srslte::log *log_,
pdcp = pdcp_; pdcp = pdcp_;
rrc = rrc_; rrc = rrc_;
mac_timers = mac_timers_; mac_timers = mac_timers_;
reordering_timeout_id = mac_timers->get_unique_id(); reordering_timer_id = mac_timers->timer_get_unique_id();
reordering_timer = mac_timers->timer_get(reordering_timer_id);
} }
void rlc_um::configure(srslte_rlc_config_t cnfg_) void rlc_um::configure(srslte_rlc_config_t cnfg_)
@ -105,7 +106,7 @@ void rlc_um::empty_queue() {
void rlc_um::stop() void rlc_um::stop()
{ {
reset(); reset();
mac_timers->free(reordering_timeout_id); mac_timers->timer_release_id(reordering_timer_id);
} }
void rlc_um::reset() void rlc_um::reset()
@ -125,7 +126,7 @@ void rlc_um::reset()
if(tx_sdu) if(tx_sdu)
tx_sdu->reset(); tx_sdu->reset();
if(mac_timers) if(mac_timers)
mac_timers->get(reordering_timeout_id)->stop(); reordering_timer->stop();
// Drop all messages in RX window // Drop all messages in RX window
std::map<uint32_t, rlc_umd_pdu_t>::iterator it; std::map<uint32_t, rlc_umd_pdu_t>::iterator it;
@ -209,7 +210,7 @@ void rlc_um::write_pdu(uint8_t *payload, uint32_t nof_bytes)
void rlc_um::timer_expired(uint32_t timeout_id) void rlc_um::timer_expired(uint32_t timeout_id)
{ {
if(reordering_timeout_id == timeout_id) if(reordering_timer_id == timeout_id)
{ {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
@ -227,11 +228,11 @@ void rlc_um::timer_expired(uint32_t timeout_id)
reassemble_rx_sdus(); reassemble_rx_sdus();
log->debug("Finished reassemble from timeout id=%d\n", timeout_id); log->debug("Finished reassemble from timeout id=%d\n", timeout_id);
} }
mac_timers->get(reordering_timeout_id)->stop(); reordering_timer->stop();
if(RX_MOD_BASE(vr_uh) > RX_MOD_BASE(vr_ur)) if(RX_MOD_BASE(vr_uh) > RX_MOD_BASE(vr_ur))
{ {
mac_timers->get(reordering_timeout_id)->set(this, cfg.t_reordering); reordering_timer->set(this, cfg.t_reordering);
mac_timers->get(reordering_timeout_id)->run(); reordering_timer->run();
vr_ux = vr_uh; vr_ux = vr_uh;
} }
@ -242,7 +243,7 @@ void rlc_um::timer_expired(uint32_t timeout_id)
bool rlc_um::reordering_timeout_running() bool rlc_um::reordering_timeout_running()
{ {
return mac_timers->get(reordering_timeout_id)->is_running(); return reordering_timer->is_running();
} }
/**************************************************************************** /****************************************************************************
@ -404,20 +405,20 @@ void rlc_um::handle_data_pdu(uint8_t *payload, uint32_t nof_bytes)
log->debug("Finished reassemble from received PDU\n"); log->debug("Finished reassemble from received PDU\n");
// Update reordering variables and timers // Update reordering variables and timers
if(mac_timers->get(reordering_timeout_id)->is_running()) if(reordering_timer->is_running())
{ {
if(RX_MOD_BASE(vr_ux) <= RX_MOD_BASE(vr_ur) || if(RX_MOD_BASE(vr_ux) <= RX_MOD_BASE(vr_ur) ||
(!inside_reordering_window(vr_ux) && vr_ux != vr_uh)) (!inside_reordering_window(vr_ux) && vr_ux != vr_uh))
{ {
mac_timers->get(reordering_timeout_id)->stop(); reordering_timer->stop();
} }
} }
if(!mac_timers->get(reordering_timeout_id)->is_running()) if(!reordering_timer->is_running())
{ {
if(RX_MOD_BASE(vr_uh) > RX_MOD_BASE(vr_ur)) if(RX_MOD_BASE(vr_uh) > RX_MOD_BASE(vr_ur))
{ {
mac_timers->get(reordering_timeout_id)->set(this, cfg.t_reordering); reordering_timer->set(this, cfg.t_reordering);
mac_timers->get(reordering_timeout_id)->run(); reordering_timer->run();
vr_ux = vr_uh; vr_ux = vr_uh;
} }
} }

@ -38,12 +38,12 @@ class mac_dummy_timers
:public srslte::mac_interface_timers :public srslte::mac_interface_timers
{ {
public: public:
srslte::timers::timer* get(uint32_t timer_id) srslte::timers::timer* timer_get(uint32_t timer_id)
{ {
return &t; return &t;
} }
uint32_t get_unique_id(){return 0;} uint32_t timer_get_unique_id(){return 0;}
void free(uint32_t id){} void timer_release_id(uint32_t id){}
private: private:
srslte::timers::timer t; srslte::timers::timer t;

@ -38,16 +38,16 @@ class mac_dummy_timers
:public srslte::mac_interface_timers :public srslte::mac_interface_timers
{ {
public: public:
srslte::timers::timer* get(uint32_t timer_id) srslte::timers::timer* timer_get(uint32_t timer_id)
{ {
return &t; return &t;
} }
uint32_t get_unique_id(){return 0;} uint32_t timer_get_unique_id(){return 0;}
void step() void step()
{ {
t.step(); t.step();
} }
void free(uint32_t timer_id) {} void timer_release_id(uint32_t timer_id) {}
private: private:
srslte::timers::timer t; srslte::timers::timer t;
}; };
@ -205,8 +205,8 @@ void loss_test()
} }
// Step the reordering timer until expiry // Step the reordering timer until expiry
while(!timers.get(1)->is_expired()) while(!timers.timer_get(1)->is_expired())
timers.get(1)->step(); timers.timer_get(1)->step();
assert(NBUFS-1 == tester.n_sdus); assert(NBUFS-1 == tester.n_sdus);
} }

@ -103,13 +103,10 @@ public:
bool process_pdus(); bool process_pdus();
void timer_expired(uint32_t timer_id); // Interface for upper-layer timers
srslte::timers::timer* timer_get(uint32_t timer_id);
srslte::timers::timer* get(uint32_t timer_id); void timer_release_id(uint32_t timer_id);
void free(uint32_t timer_id); u_int32_t timer_get_unique_id();
u_int32_t get_unique_id();
const static int NOF_MAC_TIMERS = 20;
uint32_t get_current_tti(); uint32_t get_current_tti();
void get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]); void get_metrics(mac_metrics_t metrics[ENB_METRICS_MAX_USERS]);
@ -182,22 +179,18 @@ private:
/* Class to run upper-layer timers with normal priority */ /* Class to run upper-layer timers with normal priority */
class upper_timers : public thread { class timer_thread : public thread {
public: public:
upper_timers() : timers_db(NOF_MAC_TIMERS),ttisync(10240) {start();} timer_thread(srslte::timers *t) : ttisync(10240),timers(t),running(false) {start();}
void tti_clock(); void tti_clock();
void stop(); void stop();
void reset();
srslte::timers::timer* get(uint32_t timer_id);
void free(uint32_t timer_id);
uint32_t get_unique_id();
private: private:
void run_thread(); void run_thread();
srslte::timers timers_db;
srslte::tti_sync_cv ttisync; srslte::tti_sync_cv ttisync;
srslte::timers *timers;
bool running; bool running;
}; };
upper_timers upper_timers_thread; timer_thread timers_thread;
/* Class to process MAC PDUs from DEMUX unit */ /* Class to process MAC PDUs from DEMUX unit */
class pdu_process : public thread { class pdu_process : public thread {

@ -42,7 +42,8 @@
namespace srsenb { namespace srsenb {
mac::mac() : timers_db((uint32_t) NOF_MAC_TIMERS), mac::mac() : timers_db(128),
timers_thread(&timers_db),
rar_pdu_msg(sched_interface::MAX_RAR_LIST), rar_pdu_msg(sched_interface::MAX_RAR_LIST),
pdu_process_thread(this) pdu_process_thread(this)
{ {
@ -99,7 +100,7 @@ void mac::stop()
srslte_softbuffer_tx_free(&pcch_softbuffer_tx); srslte_softbuffer_tx_free(&pcch_softbuffer_tx);
srslte_softbuffer_tx_free(&rar_softbuffer_tx); srslte_softbuffer_tx_free(&rar_softbuffer_tx);
started = false; started = false;
upper_timers_thread.stop(); timers_thread.stop();
pdu_process_thread.stop(); pdu_process_thread.stop();
} }
@ -109,7 +110,6 @@ void mac::reset()
Info("Resetting MAC\n"); Info("Resetting MAC\n");
timers_db.stop_all(); timers_db.stop_all();
upper_timers_thread.reset();
tti = 0; tti = 0;
last_rnti = 70; last_rnti = 70;
@ -119,23 +119,6 @@ void mac::reset()
} }
uint32_t mac::get_unique_id()
{
return upper_timers_thread.get_unique_id();
}
void mac::free(uint32_t timer_id)
{
upper_timers_thread.free(timer_id);
}
/* Front-end to upper-layer timers */
srslte::timers::timer* mac::get(uint32_t timer_id)
{
return upper_timers_thread.get(timer_id);
}
void mac::start_pcap(srslte::mac_pcap* pcap_) void mac::start_pcap(srslte::mac_pcap* pcap_)
{ {
pcap = pcap_; pcap = pcap_;
@ -645,57 +628,59 @@ void mac::log_step_dl(uint32_t tti)
void mac::tti_clock() void mac::tti_clock()
{ {
upper_timers_thread.tti_clock(); timers_thread.tti_clock();
} }
/******************************************************** /********************************************************
* *
* Class to run upper-layer timers with normal priority * Interface for upper layer timers
* *
*******************************************************/ *******************************************************/
void mac::upper_timers::run_thread() uint32_t mac::timer_get_unique_id()
{ {
running=true; return timers_db.get_unique_id();
ttisync.set_producer_cntr(0);
ttisync.resync();
while(running) {
ttisync.wait();
timers_db.step_all();
}
} }
void mac::upper_timers::free(uint32_t timer_id) void mac::timer_release_id(uint32_t timer_id)
{ {
timers_db.release_id(timer_id); timers_db.release_id(timer_id);
} }
srslte::timers::timer* mac::upper_timers::get(uint32_t timer_id) /* Front-end to upper-layer timers */
srslte::timers::timer* mac::timer_get(uint32_t timer_id)
{ {
if (timer_id < NOF_MAC_TIMERS) {
return timers_db.get(timer_id); return timers_db.get(timer_id);
} else {
fprintf(stderr, "Error requested invalid timer id=%d\n", timer_id);
return NULL;
}
} }
uint32_t mac::upper_timers::get_unique_id()
/********************************************************
*
* Class to run timers with normal priority
*
*******************************************************/
void mac::timer_thread::run_thread()
{ {
return timers_db.get_unique_id(); running=true;
ttisync.set_producer_cntr(0);
ttisync.resync();
while(running) {
ttisync.wait();
timers->step_all();
}
} }
void mac::upper_timers::stop() void mac::timer_thread::stop()
{ {
running=false; running=false;
ttisync.increase(); ttisync.increase();
wait_thread_finish(); wait_thread_finish();
} }
void mac::upper_timers::reset()
{
timers_db.stop_all();
}
void mac::upper_timers::tti_clock() void mac::timer_thread::tti_clock()
{ {
ttisync.increase(); ttisync.increase();
} }

@ -42,7 +42,7 @@ class demux : public srslte::pdu_queue::process_callback
{ {
public: public:
demux(uint8_t nof_harq_proc_); demux(uint8_t nof_harq_proc_);
void init(phy_interface_mac_common* phy_h_, rlc_interface_mac *rlc, srslte::log* log_h_, srslte::timers* timers_db_); void init(phy_interface_mac_common* phy_h_, rlc_interface_mac *rlc, srslte::log* log_h_, srslte::timers::timer* time_alignment_timer);
bool process_pdus(); bool process_pdus();
uint8_t* request_buffer(uint32_t pid, uint32_t len); uint8_t* request_buffer(uint32_t pid, uint32_t len);
@ -74,7 +74,7 @@ private:
phy_interface_mac_common *phy_h; phy_interface_mac_common *phy_h;
srslte::log *log_h; srslte::log *log_h;
srslte::timers *timers_db; srslte::timers::timer *time_alignment_timer;
rlc_interface_mac *rlc; rlc_interface_mac *rlc;
uint8_t nof_harq_proc; uint8_t nof_harq_proc;

@ -35,7 +35,6 @@
#include "srslte/common/log.h" #include "srslte/common/log.h"
#include "srslte/common/timers.h" #include "srslte/common/timers.h"
#include "mac/demux.h" #include "mac/demux.h"
#include "mac/mac_common.h"
#include "mac/dl_sps.h" #include "mac/dl_sps.h"
#include "srslte/common/mac_pcap.h" #include "srslte/common/mac_pcap.h"
@ -58,9 +57,9 @@ public:
pcap = NULL; pcap = NULL;
} }
bool init(srslte::log *log_h_, srslte::timers *timers_, demux *demux_unit_) bool init(srslte::log *log_h_, srslte::timers::timer *timer_aligment_timer_, demux *demux_unit_)
{ {
timers_db = timers_; timer_aligment_timer = timer_aligment_timer_;
demux_unit = demux_unit_; demux_unit = demux_unit_;
si_window_start = 0; si_window_start = 0;
log_h = log_h_; log_h = log_h_;
@ -102,7 +101,7 @@ public:
} else { } else {
if (grant.is_sps_release) { if (grant.is_sps_release) {
dl_sps_assig.clear(); dl_sps_assig.clear();
if (timers_db->get(TIME_ALIGNMENT)->is_running()) { if (timer_aligment_timer->is_running()) {
//phy_h->send_sps_ack(); //phy_h->send_sps_ack();
Warning("PHY Send SPS ACK not implemented\n"); Warning("PHY Send SPS ACK not implemented\n");
} }
@ -282,7 +281,7 @@ private:
Warning("DL PID %d: Received duplicate TB. Discarting and retransmitting ACK\n", pid); Warning("DL PID %d: Received duplicate TB. Discarting and retransmitting ACK\n", pid);
} }
if (pid == HARQ_BCCH_PID || harq_entity->timers_db->get(TIME_ALIGNMENT)->is_expired()) { if (pid == HARQ_BCCH_PID || harq_entity->timer_aligment_timer->is_expired()) {
// Do not generate ACK // Do not generate ACK
Debug("Not generating ACK\n"); Debug("Not generating ACK\n");
action->generate_ack = false; action->generate_ack = false;
@ -397,7 +396,7 @@ private:
std::vector<dl_harq_process> proc; std::vector<dl_harq_process> proc;
srslte::timers *timers_db; srslte::timers::timer *timer_aligment_timer;
demux *demux_unit; demux *demux_unit;
srslte::log *log_h; srslte::log *log_h;
srslte::mac_pcap *pcap; srslte::mac_pcap *pcap;

@ -48,9 +48,9 @@ namespace srsue {
class mac class mac
:public mac_interface_phy :public mac_interface_phy
,public mac_interface_rrc ,public mac_interface_rrc
,public srslte::timer_callback
,public srslte::mac_interface_timers ,public srslte::mac_interface_timers
,public thread ,public thread
,public srslte::timer_callback
{ {
public: public:
mac(); mac();
@ -91,16 +91,18 @@ public:
void get_rntis(ue_rnti_t *rntis); void get_rntis(ue_rnti_t *rntis);
void timer_expired(uint32_t timer_id);
void start_pcap(srslte::mac_pcap* pcap); void start_pcap(srslte::mac_pcap* pcap);
srslte::timers::timer* get(uint32_t timer_id); // Timer callback interface
void free(uint32_t timer_id); void timer_expired(uint32_t timer_id);
u_int32_t get_unique_id();
uint32_t get_current_tti(); uint32_t get_current_tti();
static const int MAC_NOF_UPPER_TIMERS = 20; // Interface for upper-layer timers
srslte::timers::timer* timer_get(uint32_t timer_id);
void timer_release_id(uint32_t timer_id);
uint32_t timer_get_unique_id();
private: private:
void run_thread(); void run_thread();
@ -147,10 +149,29 @@ private:
srslte_softbuffer_rx_t pch_softbuffer; srslte_softbuffer_rx_t pch_softbuffer;
uint8_t pch_payload_buffer[pch_payload_buffer_sz]; uint8_t pch_payload_buffer[pch_payload_buffer_sz];
/* class that runs a thread to trigger timer callbacks in low priority */
class timer_thread : public thread {
public:
timer_thread(srslte::timers *timers_) : ttisync(10240),running(false),timers(timers_) {start();}
void tti_clock();
void stop();
private:
bool running;
void run_thread();
srslte::tti_sync_cv ttisync;
srslte::timers *timers;
};
/* Functions for MAC Timers */ /* Functions for MAC Timers */
srslte::timers timers_db; uint32_t timer_alignment;
uint32_t contention_resolution_timer;
void setup_timers(); void setup_timers();
void timeAlignmentTimerExpire(); void timer_alignment_expire();
srslte::timers timers;
timer_thread timers_thread;
// pointer to MAC PCAP object // pointer to MAC PCAP object
srslte::mac_pcap* pcap; srslte::mac_pcap* pcap;
@ -159,23 +180,6 @@ private:
mac_metrics_t metrics; mac_metrics_t metrics;
/* Class to run upper-layer timers with normal priority */
class upper_timers : public periodic_thread {
public:
upper_timers();
void reset();
void free(uint32_t timer_id);
srslte::timers::timer* get(uint32_t timer_id);
uint32_t get_unique_id();
private:
void run_period();
srslte::timers timers_db;
};
upper_timers upper_timers_thread;
/* Class to process MAC PDUs from DEMUX unit */ /* Class to process MAC PDUs from DEMUX unit */
class pdu_process : public thread { class pdu_process : public thread {
public: public:

@ -1,45 +0,0 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef MAC_COMMON_H
#define MAC_COMMON_H
namespace srsue {
typedef enum {
HARQ_RTT,
TIME_ALIGNMENT,
CONTENTION_TIMER,
BSR_TIMER_PERIODIC,
BSR_TIMER_RETX,
PHR_TIMER_PERIODIC,
PHR_TIMER_PROHIBIT,
NOF_MAC_TIMERS
} mac_timers_t;
} // namespace srsue
#endif // MAC_COMMON_H

@ -81,6 +81,9 @@ private:
bool generate_bsr(bsr_t *bsr, uint32_t nof_padding_bytes); bool generate_bsr(bsr_t *bsr, uint32_t nof_padding_bytes);
char* bsr_type_tostring(triggered_bsr_type_t type); char* bsr_type_tostring(triggered_bsr_type_t type);
char* bsr_format_tostring(bsr_format_t format); char* bsr_format_tostring(bsr_format_t format);
uint32_t timer_periodic_id;
uint32_t timer_retx_id;
}; };
} // namespace srsue } // namespace srsue

@ -50,6 +50,8 @@ public:
bool generate_phr_on_ul_grant(float *phr); bool generate_phr_on_ul_grant(float *phr);
void timer_expired(uint32_t timer_id); void timer_expired(uint32_t timer_id);
void start_timer();
private: private:
bool pathloss_changed(); bool pathloss_changed();
@ -59,11 +61,15 @@ private:
phy_interface_mac* phy_h; phy_interface_mac* phy_h;
srslte::timers* timers_db; srslte::timers* timers_db;
bool initiated; bool initiated;
int timer_prohibit; int timer_prohibit_value;
int timer_periodic; int timer_periodic_value;
int dl_pathloss_change; int dl_pathloss_change;
int last_pathloss_db; int last_pathloss_db;
bool phr_is_triggered; bool phr_is_triggered;
uint32_t timer_periodic_id;
uint32_t timer_prohibit_id;
}; };
} // namespace srsue } // namespace srsue

@ -59,7 +59,6 @@ class ra_proc : public srslte::timer_callback
phy_h = NULL; phy_h = NULL;
log_h = NULL; log_h = NULL;
mac_cfg = NULL; mac_cfg = NULL;
timers_db = NULL;
mux_unit = NULL; mux_unit = NULL;
demux_unit = NULL; demux_unit = NULL;
rrc = NULL; rrc = NULL;
@ -70,6 +69,9 @@ class ra_proc : public srslte::timer_callback
rar_grant_nbytes = 0; rar_grant_nbytes = 0;
rar_grant_tti = 0; rar_grant_tti = 0;
msg3_flushed = false; msg3_flushed = false;
time_alignment_timer = NULL;
contention_resolution_timer = NULL;
}; };
~ra_proc(); ~ra_proc();
@ -79,7 +81,8 @@ class ra_proc : public srslte::timer_callback
srslte::log *log_h, srslte::log *log_h,
mac_interface_rrc::ue_rnti_t *rntis, mac_interface_rrc::ue_rnti_t *rntis,
mac_interface_rrc::mac_cfg_t *mac_cfg, mac_interface_rrc::mac_cfg_t *mac_cfg,
srslte::timers *timers_db, srslte::timers::timer* time_alignment_timer_,
srslte::timers::timer* contention_resolution_timer_,
mux *mux_unit, mux *mux_unit,
demux *demux_unit); demux *demux_unit);
void reset(); void reset();
@ -149,7 +152,6 @@ private:
srslte_softbuffer_rx_t softbuffer_rar; srslte_softbuffer_rx_t softbuffer_rar;
enum { enum {
IDLE = 0, IDLE = 0,
INITIALIZATION, // Section 5.1.1 INITIALIZATION, // Section 5.1.1
@ -174,12 +176,14 @@ private:
phy_interface_mac *phy_h; phy_interface_mac *phy_h;
srslte::log *log_h; srslte::log *log_h;
srslte::timers *timers_db;
mux *mux_unit; mux *mux_unit;
demux *demux_unit; demux *demux_unit;
srslte::mac_pcap *pcap; srslte::mac_pcap *pcap;
rrc_interface_mac *rrc; rrc_interface_mac *rrc;
srslte::timers::timer *time_alignment_timer;
srslte::timers::timer *contention_resolution_timer;
mac_interface_rrc::ue_rnti_t *rntis; mac_interface_rrc::ue_rnti_t *rntis;
mac_interface_rrc::mac_cfg_t *mac_cfg; mac_interface_rrc::mac_cfg_t *mac_cfg;

@ -35,7 +35,6 @@
#include "srslte/interfaces/ue_interfaces.h" #include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/log.h" #include "srslte/common/log.h"
#include "mac/mux.h" #include "mac/mux.h"
#include "mac/mac_common.h"
#include "mac/ul_sps.h" #include "mac/ul_sps.h"
#include "srslte/common/mac_pcap.h" #include "srslte/common/mac_pcap.h"
#include "srslte/common/timers.h" #include "srslte/common/timers.h"
@ -55,8 +54,9 @@ public:
ul_harq_entity() : proc(N) ul_harq_entity() : proc(N)
{ {
contention_timer = NULL;
pcap = NULL; pcap = NULL;
timers_db = NULL;
mux_unit = NULL; mux_unit = NULL;
log_h = NULL; log_h = NULL;
params = NULL; params = NULL;
@ -68,14 +68,14 @@ public:
bool init(srslte::log *log_h_, bool init(srslte::log *log_h_,
mac_interface_rrc_common::ue_rnti_t *rntis_, mac_interface_rrc_common::ue_rnti_t *rntis_,
mac_interface_rrc_common::ul_harq_params_t *params_, mac_interface_rrc_common::ul_harq_params_t *params_,
srslte::timers* timers_db_, srslte::timers::timer* contention_timer_,
mux *mux_unit_) mux *mux_unit_)
{ {
log_h = log_h_; log_h = log_h_;
mux_unit = mux_unit_; mux_unit = mux_unit_;
params = params_; params = params_;
rntis = rntis_; rntis = rntis_;
timers_db = timers_db_; contention_timer = contention_timer_;
for (uint32_t i=0;i<N;i++) { for (uint32_t i=0;i<N;i++) {
if (!proc[i].init(i, this)) { if (!proc[i].init(i, this)) {
return false; return false;
@ -350,7 +350,7 @@ private:
// On every Msg3 retransmission, restart mac-ContentionResolutionTimer as defined in Section 5.1.5 // On every Msg3 retransmission, restart mac-ContentionResolutionTimer as defined in Section 5.1.5
if (is_msg3) { if (is_msg3) {
harq_entity->timers_db->get(CONTENTION_TIMER)->reset(); harq_entity->contention_timer->reset();
} }
harq_entity->mux_unit->pusch_retx(tti_tx, pid); harq_entity->mux_unit->pusch_retx(tti_tx, pid);
@ -415,7 +415,7 @@ private:
ul_sps ul_sps_assig; ul_sps ul_sps_assig;
srslte::timers *timers_db; srslte::timers::timer *contention_timer;
mux *mux_unit; mux *mux_unit;
std::vector<ul_harq_process> proc; std::vector<ul_harq_process> proc;
srslte::log *log_h; srslte::log *log_h;

@ -40,12 +40,12 @@ demux::demux(uint8_t nof_harq_proc_) : mac_msg(20), pending_mac_msg(20), nof_har
{ {
} }
void demux::init(phy_interface_mac_common* phy_h_, rlc_interface_mac *rlc_, srslte::log* log_h_, srslte::timers* timers_db_) void demux::init(phy_interface_mac_common* phy_h_, rlc_interface_mac *rlc_, srslte::log* log_h_, srslte::timers::timer* time_alignment_timer_)
{ {
phy_h = phy_h_; phy_h = phy_h_;
log_h = log_h_; log_h = log_h_;
rlc = rlc_; rlc = rlc_;
timers_db = timers_db_; time_alignment_timer = time_alignment_timer_;
pdus.init(this, log_h); pdus.init(this, log_h);
} }
@ -190,8 +190,8 @@ bool demux::process_ce(srslte::sch_subh *subh) {
Info("Received TA=%d\n", subh->get_ta_cmd()); Info("Received TA=%d\n", subh->get_ta_cmd());
// Start or restart timeAlignmentTimer // Start or restart timeAlignmentTimer
timers_db->get(TIME_ALIGNMENT)->reset(); time_alignment_timer->reset();
timers_db->get(TIME_ALIGNMENT)->run(); time_alignment_timer->run();
break; break;
case srslte::sch_subh::PADDING: case srslte::sch_subh::PADDING:
break; break;

@ -42,7 +42,8 @@
namespace srsue { namespace srsue {
mac::mac() : ttisync(10240), mac::mac() : ttisync(10240),
timers_db((uint32_t) NOF_MAC_TIMERS), timers(64),
timers_thread(&timers),
mux_unit(MAC_NOF_HARQ_PROC), mux_unit(MAC_NOF_HARQ_PROC),
demux_unit(SRSLTE_MAX_TB*MAC_NOF_HARQ_PROC), demux_unit(SRSLTE_MAX_TB*MAC_NOF_HARQ_PROC),
pdu_process_thread(&demux_unit) pdu_process_thread(&demux_unit)
@ -66,14 +67,17 @@ bool mac::init(phy_interface_mac *phy, rlc_interface_mac *rlc, rrc_interface_mac
srslte_softbuffer_rx_init(&pch_softbuffer, 100); srslte_softbuffer_rx_init(&pch_softbuffer, 100);
bsr_procedure.init( rlc_h, log_h, &config, &timers_db); timer_alignment = timers.get_unique_id();
phr_procedure.init(phy_h, log_h, &config, &timers_db); contention_resolution_timer = timers.get_unique_id();
bsr_procedure.init( rlc_h, log_h, &config, &timers);
phr_procedure.init(phy_h, log_h, &config, &timers);
mux_unit.init ( rlc_h, log_h, &bsr_procedure, &phr_procedure); mux_unit.init ( rlc_h, log_h, &bsr_procedure, &phr_procedure);
demux_unit.init (phy_h, rlc_h, log_h, &timers_db); demux_unit.init (phy_h, rlc_h, log_h, timers.get(timer_alignment));
ra_procedure.init (phy_h, rrc, log_h, &uernti, &config, &timers_db, &mux_unit, &demux_unit); ra_procedure.init (phy_h, rrc, log_h, &uernti, &config, timers.get(timer_alignment), timers.get(contention_resolution_timer), &mux_unit, &demux_unit);
sr_procedure.init (phy_h, rrc, log_h, &config); sr_procedure.init (phy_h, rrc, log_h, &config);
ul_harq.init ( log_h, &uernti, &config.ul_harq_params, &timers_db, &mux_unit); ul_harq.init ( log_h, &uernti, &config.ul_harq_params, timers.get(contention_resolution_timer), &mux_unit);
dl_harq.init ( log_h, &timers_db, &demux_unit); dl_harq.init ( log_h, timers.get(timer_alignment), &demux_unit);
reset(); reset();
@ -90,8 +94,8 @@ void mac::stop()
started = false; started = false;
ttisync.increase(); ttisync.increase();
upper_timers_thread.thread_cancel();
pdu_process_thread.stop(); pdu_process_thread.stop();
timers_thread.stop();
wait_thread_finish(); wait_thread_finish();
} }
@ -116,8 +120,7 @@ void mac::reset()
Info("Resetting MAC\n"); Info("Resetting MAC\n");
timers_db.stop_all(); timers.stop_all();
upper_timers_thread.reset();
ul_harq.reset_ndi(); ul_harq.reset_ndi();
@ -157,7 +160,8 @@ void mac::run_thread() {
tti = phy_h->get_current_tti(); tti = phy_h->get_current_tti();
log_h->step(tti); log_h->step(tti);
timers_db.step_all();
timers_thread.tti_clock();
// Step all procedures // Step all procedures
bsr_procedure.step(tti); bsr_procedure.step(tti);
@ -297,7 +301,7 @@ void mac::new_grant_ul(mac_interface_phy::mac_grant_t grant, mac_interface_phy::
/* Start PHR Periodic timer on first UL grant */ /* Start PHR Periodic timer on first UL grant */
if (is_first_ul_grant) { if (is_first_ul_grant) {
is_first_ul_grant = false; is_first_ul_grant = false;
timers_db.get(PHR_TIMER_PERIODIC)->run(); phr_procedure.start_timer();
} }
if (grant.rnti_type == SRSLTE_RNTI_USER && ra_procedure.is_contention_resolution()) { if (grant.rnti_type == SRSLTE_RNTI_USER && ra_procedure.is_contention_resolution()) {
ra_procedure.pdcch_to_crnti(true); ra_procedure.pdcch_to_crnti(true);
@ -343,25 +347,23 @@ void mac::setup_timers()
{ {
int value = liblte_rrc_time_alignment_timer_num[config.main.time_alignment_timer]; int value = liblte_rrc_time_alignment_timer_num[config.main.time_alignment_timer];
if (value > 0) { if (value > 0) {
timers_db.get(TIME_ALIGNMENT)->set(this, value); timers.get(timer_alignment)->set(this, value);
} }
} }
void mac::timer_expired(uint32_t timer_id) void mac::timer_expired(uint32_t timer_id)
{ {
switch(timer_id) { if(timer_id == timer_alignment) {
case TIME_ALIGNMENT: timer_alignment_expire();
timeAlignmentTimerExpire(); } else {
break; Warning("Received callback from unknown timer_id=%d\n", timer_id);
default:
break;
} }
} }
/* Function called on expiry of TimeAlignmentTimer */ /* Function called on expiry of TimeAlignmentTimer */
void mac::timeAlignmentTimerExpire() void mac::timer_alignment_expire()
{ {
printf("timeAlignmentTimer has expired value=%d ms\n", timers_db.get(TIME_ALIGNMENT)->get_timeout()); printf("TimeAlignment timer has expired value=%d ms\n", timers.get(timer_alignment)->get_timeout());
rrc_h->release_pucch_srs(); rrc_h->release_pucch_srs();
dl_harq.reset(); dl_harq.reset();
ul_harq.reset(); ul_harq.reset();
@ -414,24 +416,7 @@ void mac::setup_lcid(uint32_t lcid, uint32_t lcg, uint32_t priority, int PBR_x_t
bsr_procedure.set_priority(lcid, priority); bsr_procedure.set_priority(lcid, priority);
} }
uint32_t mac::get_unique_id() void mac::get_metrics(mac_metrics_t &m)
{
return upper_timers_thread.get_unique_id();
}
/* Front-end to upper-layer timers */
srslte::timers::timer* mac::get(uint32_t timer_id)
{
return upper_timers_thread.get(timer_id);
}
void mac::free(uint32_t timer_id)
{
upper_timers_thread.free(timer_id);
}
void mac::get_metrics(mac_metrics_t &m)
{ {
Info("DL retx: %.2f \%%, perpkt: %.2f, UL retx: %.2f \%% perpkt: %.2f\n", Info("DL retx: %.2f \%%, perpkt: %.2f, UL retx: %.2f \%% perpkt: %.2f\n",
metrics.rx_pkts?((float) 100*metrics.rx_errors/metrics.rx_pkts):0.0, metrics.rx_pkts?((float) 100*metrics.rx_errors/metrics.rx_pkts):0.0,
@ -445,47 +430,59 @@ void mac::free(uint32_t timer_id)
} }
/******************************************************** /********************************************************
* *
* Class to run upper-layer timers with normal priority * Interface for timers used by upper layers
* *
*******************************************************/ *******************************************************/
srslte::timers::timer* mac::timer_get(uint32_t timer_id)
mac::upper_timers::upper_timers() : timers_db(MAC_NOF_UPPER_TIMERS)
{ {
start_periodic(1000, MAC_MAIN_THREAD_PRIO+1); return timers.get(timer_id);
} }
void mac::upper_timers::run_period() void mac::timer_release_id(uint32_t timer_id)
{ {
timers_db.step_all(); timers.release_id(timer_id);
} }
srslte::timers::timer* mac::upper_timers::get(uint32_t timer_id) uint32_t mac::timer_get_unique_id()
{ {
return timers_db.get(timer_id%MAC_NOF_UPPER_TIMERS); return timers.get_unique_id();
} }
uint32_t mac::upper_timers::get_unique_id()
/********************************************************
*
* Class that runs timers in lower priority
*
*******************************************************/
void mac::timer_thread::tti_clock()
{ {
return timers_db.get_unique_id(); ttisync.increase();
} }
void mac::upper_timers::reset() void mac::timer_thread::run_thread()
{ {
timers_db.stop_all(); running=true;
ttisync.set_producer_cntr(0);
ttisync.resync();
while(running) {
ttisync.wait();
timers->step_all();
}
} }
void mac::timer_thread::stop()
void mac::upper_timers::free(uint32_t timer_id)
{ {
timers_db.release_id(timer_id); running=false;
ttisync.increase();
wait_thread_finish();
} }
/********************************************************
/********************************************************
* *
* Class that runs a thread to process DL MAC PDUs from * Class that runs a thread to process DL MAC PDUs from
* DEMUX unit * DEMUX unit

@ -51,16 +51,20 @@ void bsr_proc::init(rlc_interface_mac *rlc_, srslte::log* log_h_, mac_interface_
rlc = rlc_; rlc = rlc_;
mac_cfg = mac_cfg_; mac_cfg = mac_cfg_;
timers_db = timers_db_; timers_db = timers_db_;
timer_periodic_id = timers_db->get_unique_id();
timer_retx_id = timers_db->get_unique_id();
reset(); reset();
initiated = true; initiated = true;
} }
void bsr_proc::reset() void bsr_proc::reset()
{ {
timers_db->get(BSR_TIMER_PERIODIC)->stop(); timers_db->get(timer_periodic_id)->stop();
timers_db->get(BSR_TIMER_PERIODIC)->reset(); timers_db->get(timer_periodic_id)->reset();
timers_db->get(BSR_TIMER_RETX)->stop(); timers_db->get(timer_retx_id)->stop();
timers_db->get(BSR_TIMER_RETX)->reset(); timers_db->get(timer_retx_id)->reset();
reset_sr = false; reset_sr = false;
sr_is_sent = false; sr_is_sent = false;
@ -77,15 +81,13 @@ void bsr_proc::reset()
/* Process Periodic BSR */ /* Process Periodic BSR */
void bsr_proc::timer_expired(uint32_t timer_id) { void bsr_proc::timer_expired(uint32_t timer_id) {
switch(timer_id) { if(timer_id == timer_periodic_id) {
case BSR_TIMER_PERIODIC:
if (triggered_bsr_type == NONE) { if (triggered_bsr_type == NONE) {
// Check condition 4 in Sec 5.4.5 // Check condition 4 in Sec 5.4.5
triggered_bsr_type = PERIODIC; triggered_bsr_type = PERIODIC;
Debug("BSR: Triggering Periodic BSR\n"); Debug("BSR: Triggering Periodic BSR\n");
} }
break; } else if (timer_id == timer_retx_id) {
case BSR_TIMER_RETX:
// Enable reTx of SR only if periodic timer is not infinity // Enable reTx of SR only if periodic timer is not infinity
int periodic = liblte_rrc_periodic_bsr_timer_num[mac_cfg->main.ulsch_cnfg.periodic_bsr_timer]; int periodic = liblte_rrc_periodic_bsr_timer_num[mac_cfg->main.ulsch_cnfg.periodic_bsr_timer];
if (periodic >= 0) { if (periodic >= 0) {
@ -93,7 +95,6 @@ void bsr_proc::timer_expired(uint32_t timer_id) {
Debug("BSR: Triggering BSR reTX\n"); Debug("BSR: Triggering BSR reTX\n");
sr_is_sent = false; sr_is_sent = false;
} }
break;
} }
} }
@ -222,17 +223,17 @@ void bsr_proc::step(uint32_t tti)
} }
int periodic = liblte_rrc_periodic_bsr_timer_num[mac_cfg->main.ulsch_cnfg.periodic_bsr_timer]; int periodic = liblte_rrc_periodic_bsr_timer_num[mac_cfg->main.ulsch_cnfg.periodic_bsr_timer];
if (periodic > 0 && (uint32_t)periodic != timers_db->get(BSR_TIMER_PERIODIC)->get_timeout()) if (periodic > 0 && (uint32_t)periodic != timers_db->get(timer_periodic_id)->get_timeout())
{ {
timers_db->get(BSR_TIMER_PERIODIC)->set(this, periodic); timers_db->get(timer_periodic_id)->set(this, periodic);
timers_db->get(BSR_TIMER_PERIODIC)->run(); timers_db->get(timer_periodic_id)->run();
Info("BSR: Configured timer periodic %d ms\n", periodic); Info("BSR: Configured timer periodic %d ms\n", periodic);
} }
int retx = liblte_rrc_retransmission_bsr_timer_num[mac_cfg->main.ulsch_cnfg.retx_bsr_timer]; int retx = liblte_rrc_retransmission_bsr_timer_num[mac_cfg->main.ulsch_cnfg.retx_bsr_timer];
if (retx > 0 && (uint32_t)retx != timers_db->get(BSR_TIMER_RETX)->get_timeout()) if (retx > 0 && (uint32_t)retx != timers_db->get(timer_retx_id)->get_timeout())
{ {
timers_db->get(BSR_TIMER_RETX)->set(this, retx); timers_db->get(timer_retx_id)->set(this, retx);
timers_db->get(BSR_TIMER_RETX)->run(); timers_db->get(timer_retx_id)->run();
Info("BSR: Configured timer reTX %d ms\n", retx); Info("BSR: Configured timer reTX %d ms\n", retx);
} }
@ -309,18 +310,18 @@ bool bsr_proc::need_to_send_bsr_on_ul_grant(uint32_t grant_size, bsr_t *bsr)
grant_size, total_data, bsr_sz); grant_size, total_data, bsr_sz);
ret = true; ret = true;
} }
if (timers_db->get(BSR_TIMER_PERIODIC)->get_timeout() && bsr->format != TRUNC_BSR) { if (timers_db->get(timer_periodic_id)->get_timeout() && bsr->format != TRUNC_BSR) {
timers_db->get(BSR_TIMER_PERIODIC)->reset(); timers_db->get(timer_periodic_id)->reset();
timers_db->get(BSR_TIMER_PERIODIC)->run(); timers_db->get(timer_periodic_id)->run();
} }
} }
// Cancel all triggered BSR and SR // Cancel all triggered BSR and SR
triggered_bsr_type = NONE; triggered_bsr_type = NONE;
reset_sr = true; reset_sr = true;
// Restart or Start ReTX timer // Restart or Start ReTX timer
if (timers_db->get(BSR_TIMER_RETX)->get_timeout()) { if (timers_db->get(timer_retx_id)->get_timeout()) {
timers_db->get(BSR_TIMER_RETX)->reset(); timers_db->get(timer_retx_id)->reset();
timers_db->get(BSR_TIMER_RETX)->run(); timers_db->get(timer_retx_id)->run();
} }
return ret; return ret;
} }
@ -340,9 +341,9 @@ bool bsr_proc::generate_padding_bsr(uint32_t nof_padding_bytes, bsr_t *bsr)
bsr_type_tostring(triggered_bsr_type), bsr_format_tostring(bsr->format), bsr_type_tostring(triggered_bsr_type), bsr_format_tostring(bsr->format),
bsr->buff_size[0], bsr->buff_size[1], bsr->buff_size[2], bsr->buff_size[3]); bsr->buff_size[0], bsr->buff_size[1], bsr->buff_size[2], bsr->buff_size[3]);
if (timers_db->get(BSR_TIMER_PERIODIC)->get_timeout() && bsr->format != TRUNC_BSR) { if (timers_db->get(timer_periodic_id)->get_timeout() && bsr->format != TRUNC_BSR) {
timers_db->get(BSR_TIMER_PERIODIC)->reset(); timers_db->get(timer_periodic_id)->reset();
timers_db->get(BSR_TIMER_PERIODIC)->run(); timers_db->get(timer_periodic_id)->run();
} }
} }

@ -49,14 +49,18 @@ void phr_proc::init(phy_interface_mac* phy_h_, srslte::log* log_h_, mac_interfac
mac_cfg = mac_cfg_; mac_cfg = mac_cfg_;
timers_db = timers_db_; timers_db = timers_db_;
initiated = true; initiated = true;
timer_periodic_id = timers_db->get_unique_id();
timer_prohibit_id = timers_db->get_unique_id();
reset(); reset();
} }
void phr_proc::reset() void phr_proc::reset()
{ {
phr_is_triggered = false; phr_is_triggered = false;
timer_periodic = -2; timer_periodic_value = -2;
timer_prohibit = -2; timer_prohibit_value = -2;
dl_pathloss_change = -2; dl_pathloss_change = -2;
} }
@ -73,22 +77,25 @@ bool phr_proc::pathloss_changed() {
} }
} }
void phr_proc::start_timer() {
timers_db->get(timer_periodic_id)->run();
}
/* Trigger PHR when timers exire */ /* Trigger PHR when timers exire */
void phr_proc::timer_expired(uint32_t timer_id) { void phr_proc::timer_expired(uint32_t timer_id) {
switch(timer_id) { if(timer_id == timer_periodic_id) {
case PHR_TIMER_PERIODIC: timers_db->get(timer_periodic_id)->reset();
timers_db->get(PHR_TIMER_PERIODIC)->reset(); timers_db->get(timer_periodic_id)->run();
timers_db->get(PHR_TIMER_PERIODIC)->run();
Debug("PHR: Triggered by timer periodic (timer expired).\n"); Debug("PHR: Triggered by timer periodic (timer expired).\n");
phr_is_triggered = true; phr_is_triggered = true;
break; } else if (timer_id == timer_prohibit_id) {
case PHR_TIMER_PROHIBIT:
int pathloss_db = liblte_rrc_dl_pathloss_change_num[mac_cfg->main.phr_cnfg.dl_pathloss_change]; int pathloss_db = liblte_rrc_dl_pathloss_change_num[mac_cfg->main.phr_cnfg.dl_pathloss_change];
if (pathloss_changed()) { if (pathloss_changed()) {
Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f (timer expired)\n", last_pathloss_db); Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f (timer expired)\n", last_pathloss_db);
phr_is_triggered = true; phr_is_triggered = true;
} }
break; } else {
log_h->warning("Received timer callback from unknown timer_id=%d\n", timer_id);
} }
} }
@ -102,28 +109,28 @@ void phr_proc::step(uint32_t tti)
int cfg_timer_periodic = liblte_rrc_periodic_phr_timer_num[mac_cfg->main.phr_cnfg.periodic_phr_timer]; int cfg_timer_periodic = liblte_rrc_periodic_phr_timer_num[mac_cfg->main.phr_cnfg.periodic_phr_timer];
// Setup timers and trigger PHR when configuration changed by higher layers // Setup timers and trigger PHR when configuration changed by higher layers
if (timer_periodic != cfg_timer_periodic && cfg_timer_periodic > 0) if (timer_periodic_value != cfg_timer_periodic && cfg_timer_periodic > 0)
{ {
timer_periodic = cfg_timer_periodic; timer_periodic_value = cfg_timer_periodic;
timers_db->get(PHR_TIMER_PERIODIC)->set(this, timer_periodic); timers_db->get(timer_periodic_id)->set(this, timer_periodic_value);
timers_db->get(PHR_TIMER_PERIODIC)->run(); timers_db->get(timer_periodic_id)->run();
phr_is_triggered = true; phr_is_triggered = true;
Info("PHR: Configured timer periodic %d ms\n", timer_periodic); Info("PHR: Configured timer periodic %d ms\n", timer_periodic_value);
} }
} }
int cfg_timer_prohibit = liblte_rrc_prohibit_phr_timer_num[mac_cfg->main.phr_cnfg.prohibit_phr_timer]; int cfg_timer_prohibit = liblte_rrc_prohibit_phr_timer_num[mac_cfg->main.phr_cnfg.prohibit_phr_timer];
if (timer_prohibit != cfg_timer_prohibit && cfg_timer_prohibit > 0) if (timer_prohibit_value != cfg_timer_prohibit && cfg_timer_prohibit > 0)
{ {
timer_prohibit = cfg_timer_prohibit; timer_prohibit_value = cfg_timer_prohibit;
timers_db->get(PHR_TIMER_PROHIBIT)->set(this, timer_prohibit); timers_db->get(timer_prohibit_id)->set(this, timer_prohibit_value);
timers_db->get(PHR_TIMER_PROHIBIT)->run(); timers_db->get(timer_prohibit_id)->run();
Info("PHR: Configured timer prohibit %d ms\n", timer_prohibit); Info("PHR: Configured timer prohibit %d ms\n", timer_prohibit_value);
phr_is_triggered = true; phr_is_triggered = true;
} }
if (pathloss_changed() && timers_db->get(PHR_TIMER_PROHIBIT)->is_expired()) if (pathloss_changed() && timers_db->get(timer_prohibit_id)->is_expired())
{ {
Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f\n", last_pathloss_db); Info("PHR: Triggered by pathloss difference. cur_pathloss_db=%f\n", last_pathloss_db);
phr_is_triggered = true; phr_is_triggered = true;
@ -140,10 +147,10 @@ bool phr_proc::generate_phr_on_ul_grant(float *phr)
Debug("PHR: Generating PHR=%f\n", phr?*phr:0.0); Debug("PHR: Generating PHR=%f\n", phr?*phr:0.0);
timers_db->get(PHR_TIMER_PERIODIC)->reset(); timers_db->get(timer_periodic_id)->reset();
timers_db->get(PHR_TIMER_PROHIBIT)->reset(); timers_db->get(timer_prohibit_id)->reset();
timers_db->get(PHR_TIMER_PERIODIC)->run(); timers_db->get(timer_periodic_id)->run();
timers_db->get(PHR_TIMER_PROHIBIT)->run(); timers_db->get(timer_prohibit_id)->run();
phr_is_triggered = false; phr_is_triggered = false;

@ -53,7 +53,8 @@ void ra_proc::init(phy_interface_mac* phy_h_,
srslte::log* log_h_, srslte::log* log_h_,
mac_interface_rrc::ue_rnti_t *rntis_, mac_interface_rrc::ue_rnti_t *rntis_,
mac_interface_rrc::mac_cfg_t *mac_cfg_, mac_interface_rrc::mac_cfg_t *mac_cfg_,
srslte::timers* timers_db_, srslte::timers::timer* time_alignment_timer_,
srslte::timers::timer* contention_resolution_timer_,
mux* mux_unit_, mux* mux_unit_,
demux* demux_unit_) demux* demux_unit_)
{ {
@ -61,10 +62,13 @@ void ra_proc::init(phy_interface_mac* phy_h_,
log_h = log_h_; log_h = log_h_;
mac_cfg = mac_cfg_; mac_cfg = mac_cfg_;
rntis = rntis_; rntis = rntis_;
timers_db = timers_db_;
mux_unit = mux_unit_; mux_unit = mux_unit_;
demux_unit= demux_unit_; demux_unit= demux_unit_;
rrc = rrc_; rrc = rrc_;
time_alignment_timer = time_alignment_timer_;
contention_resolution_timer = contention_resolution_timer_;
srslte_softbuffer_rx_init(&softbuffer_rar, 10); srslte_softbuffer_rx_init(&softbuffer_rar, 10);
// Tell demux to call us when a UE CRID is received // Tell demux to call us when a UE CRID is received
@ -119,7 +123,7 @@ void ra_proc::read_params() {
delta_preamble_db = delta_preamble_db_table[configIndex%5]; delta_preamble_db = delta_preamble_db_table[configIndex%5];
if (contentionResolutionTimer > 0) { if (contentionResolutionTimer > 0) {
timers_db->get(CONTENTION_TIMER)->set(this, contentionResolutionTimer); contention_resolution_timer->set(this, contentionResolutionTimer);
} }
} }
@ -169,14 +173,14 @@ void ra_proc::process_timeadv_cmd(uint32_t ta) {
if (preambleIndex == 0) { if (preambleIndex == 0) {
// Preamble not selected by UE MAC // Preamble not selected by UE MAC
phy_h->set_timeadv_rar(ta); phy_h->set_timeadv_rar(ta);
timers_db->get(TIME_ALIGNMENT)->reset(); time_alignment_timer->reset();
timers_db->get(TIME_ALIGNMENT)->run(); time_alignment_timer->run();
Debug("Applying RAR TA CMD %d\n", ta); Debug("Applying RAR TA CMD %d\n", ta);
} else { } else {
// Preamble selected by UE MAC // Preamble selected by UE MAC
if (!timers_db->get(TIME_ALIGNMENT)->is_running()) { if (!time_alignment_timer->is_running()) {
phy_h->set_timeadv_rar(ta); phy_h->set_timeadv_rar(ta);
timers_db->get(TIME_ALIGNMENT)->run(); time_alignment_timer->run();
Debug("Applying RAR TA CMD %d\n", ta); Debug("Applying RAR TA CMD %d\n", ta);
} else { } else {
// Ignore TA CMD // Ignore TA CMD
@ -361,8 +365,8 @@ void ra_proc::tb_decoded_ok() {
state = CONTENTION_RESOLUTION; state = CONTENTION_RESOLUTION;
// Start contention resolution timer // Start contention resolution timer
timers_db->get(CONTENTION_TIMER)->reset(); contention_resolution_timer->reset();
timers_db->get(CONTENTION_TIMER)->run(); contention_resolution_timer->run();
} }
} else { } else {
rDebug("Found RAR for preamble %d\n", rar_pdu_msg.get()->get_rapid()); rDebug("Found RAR for preamble %d\n", rar_pdu_msg.get()->get_rapid());
@ -423,7 +427,7 @@ bool ra_proc::contention_resolution_id_received(uint64_t rx_contention_id) {
rDebug("MAC PDU Contains Contention Resolution ID CE\n"); rDebug("MAC PDU Contains Contention Resolution ID CE\n");
// MAC PDU successfully decoded and contains MAC CE contention Id // MAC PDU successfully decoded and contains MAC CE contention Id
timers_db->get(CONTENTION_TIMER)->stop(); contention_resolution_timer->stop();
if (transmitted_contention_id == rx_contention_id) if (transmitted_contention_id == rx_contention_id)
{ {
@ -459,7 +463,7 @@ void ra_proc::step_contention_resolution() {
(started_by_pdcch && pdcch_to_crnti_received != PDCCH_CRNTI_NOT_RECEIVED)) (started_by_pdcch && pdcch_to_crnti_received != PDCCH_CRNTI_NOT_RECEIVED))
{ {
rDebug("PDCCH for C-RNTI received\n"); rDebug("PDCCH for C-RNTI received\n");
timers_db->get(CONTENTION_TIMER)->stop(); contention_resolution_timer->stop();
rntis->temp_rnti = 0; rntis->temp_rnti = 0;
state = COMPLETION; state = COMPLETION;
} }
@ -571,7 +575,7 @@ void ra_proc::pdcch_to_crnti(bool contains_uplink_grant) {
void ra_proc::harq_retx() void ra_proc::harq_retx()
{ {
timers_db->get(CONTENTION_TIMER)->reset(); contention_resolution_timer->reset();
} }
} }

@ -93,9 +93,9 @@ void rrc::init(phy_interface_rrc *phy_,
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
ue_category = SRSLTE_UE_CATEGORY; ue_category = SRSLTE_UE_CATEGORY;
t301 = mac_timers->get_unique_id(); t301 = mac_timers->timer_get_unique_id();
t310 = mac_timers->get_unique_id(); t310 = mac_timers->timer_get_unique_id();
t311 = mac_timers->get_unique_id(); t311 = mac_timers->timer_get_unique_id();
transaction_id = 0; transaction_id = 0;
@ -233,9 +233,9 @@ void rrc::run_thread() {
set_phy_default(); set_phy_default();
set_mac_default(); set_mac_default();
mac->pcch_start_rx(); mac->pcch_start_rx();
mac_timers->get(t311)->run(); mac_timers->timer_get(t311)->run();
mac_timers->get(t310)->stop(); mac_timers->timer_get(t310)->stop();
mac_timers->get(t311)->stop(); mac_timers->timer_get(t311)->stop();
state = RRC_STATE_IDLE; state = RRC_STATE_IDLE;
break; break;
default: default:
@ -475,11 +475,11 @@ void rrc::cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp) {
// Detection of physical layer problems (5.3.11.1) // Detection of physical layer problems (5.3.11.1)
void rrc::out_of_sync() { void rrc::out_of_sync() {
current_cell->in_sync = false; current_cell->in_sync = false;
if (!mac_timers->get(t311)->is_running() && !mac_timers->get(t310)->is_running()) { if (!mac_timers->timer_get(t311)->is_running() && !mac_timers->timer_get(t310)->is_running()) {
n310_cnt++; n310_cnt++;
if (n310_cnt == N310) { if (n310_cnt == N310) {
mac_timers->get(t310)->reset(); mac_timers->timer_get(t310)->reset();
mac_timers->get(t310)->run(); mac_timers->timer_get(t310)->run();
n310_cnt = 0; n310_cnt = 0;
rrc_log->info("Detected %d out-of-sync from PHY. Starting T310 timer\n", N310); rrc_log->info("Detected %d out-of-sync from PHY. Starting T310 timer\n", N310);
} }
@ -489,10 +489,10 @@ void rrc::out_of_sync() {
// Recovery of physical layer problems (5.3.11.2) // Recovery of physical layer problems (5.3.11.2)
void rrc::in_sync() { void rrc::in_sync() {
current_cell->in_sync = true; current_cell->in_sync = true;
if (mac_timers->get(t310)->is_running()) { if (mac_timers->timer_get(t310)->is_running()) {
n311_cnt++; n311_cnt++;
if (n311_cnt == N311) { if (n311_cnt == N311) {
mac_timers->get(t310)->stop(); mac_timers->timer_get(t310)->stop();
n311_cnt = 0; n311_cnt = 0;
rrc_log->info("Detected %d in-sync from PHY. Stopping T310 timer\n", N311); rrc_log->info("Detected %d in-sync from PHY. Stopping T310 timer\n", N311);
} }
@ -652,9 +652,9 @@ void rrc::send_con_restablish_request() {
rrc_log->info("Initiating RRC Connection Reestablishment Procedure\n"); rrc_log->info("Initiating RRC Connection Reestablishment Procedure\n");
rrc_log->console("RRC Connection Reestablishment\n"); rrc_log->console("RRC Connection Reestablishment\n");
mac_timers->get(t310)->stop(); mac_timers->timer_get(t310)->stop();
mac_timers->get(t311)->reset(); mac_timers->timer_get(t311)->reset();
mac_timers->get(t311)->run(); mac_timers->timer_get(t311)->run();
set_phy_default(); set_phy_default();
mac->reset(); mac->reset();
@ -667,9 +667,9 @@ void rrc::send_con_restablish_request() {
usleep(10000); usleep(10000);
timeout_cnt++; timeout_cnt++;
} }
mac_timers->get(t301)->reset(); mac_timers->timer_get(t301)->reset();
mac_timers->get(t301)->run(); mac_timers->timer_get(t301)->run();
mac_timers->get(t311)->stop(); mac_timers->timer_get(t311)->stop();
rrc_log->info("Cell Selection finished. Initiating transmission of RRC Connection Reestablishment Request\n"); rrc_log->info("Cell Selection finished. Initiating transmission of RRC Connection Reestablishment Request\n");
// Byte align and pack the message bits for PDCP // Byte align and pack the message bits for PDCP
@ -1337,15 +1337,15 @@ void rrc::apply_sib2_configs(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2) {
liblte_rrc_srs_subfr_config_num[sib2->rr_config_common_sib.srs_ul_cnfg.subfr_cnfg], liblte_rrc_srs_subfr_config_num[sib2->rr_config_common_sib.srs_ul_cnfg.subfr_cnfg],
sib2->rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx ? "yes" : "no"); sib2->rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx ? "yes" : "no");
mac_timers->get(t301)->set(this, liblte_rrc_t301_num[sib2->ue_timers_and_constants.t301]); mac_timers->timer_get(t301)->set(this, liblte_rrc_t301_num[sib2->ue_timers_and_constants.t301]);
mac_timers->get(t310)->set(this, liblte_rrc_t310_num[sib2->ue_timers_and_constants.t310]); mac_timers->timer_get(t310)->set(this, liblte_rrc_t310_num[sib2->ue_timers_and_constants.t310]);
mac_timers->get(t311)->set(this, liblte_rrc_t311_num[sib2->ue_timers_and_constants.t311]); mac_timers->timer_get(t311)->set(this, liblte_rrc_t311_num[sib2->ue_timers_and_constants.t311]);
N310 = liblte_rrc_n310_num[sib2->ue_timers_and_constants.n310]; N310 = liblte_rrc_n310_num[sib2->ue_timers_and_constants.n310];
N311 = liblte_rrc_n311_num[sib2->ue_timers_and_constants.n311]; N311 = liblte_rrc_n311_num[sib2->ue_timers_and_constants.n311];
rrc_log->info("Set Constants and Timers: N310=%d, N311=%d, t301=%d, t310=%d, t311=%d\n", rrc_log->info("Set Constants and Timers: N310=%d, N311=%d, t301=%d, t310=%d, t311=%d\n",
N310, N311, mac_timers->get(t301)->get_timeout(), N310, N311, mac_timers->timer_get(t301)->get_timeout(),
mac_timers->get(t310)->get_timeout(), mac_timers->get(t311)->get_timeout()); mac_timers->timer_get(t310)->get_timeout(), mac_timers->timer_get(t311)->get_timeout());
} }
@ -1583,7 +1583,7 @@ void rrc::handle_con_setup(LIBLTE_RRC_CONNECTION_SETUP_STRUCT *setup) {
/* Reception of RRCConnectionReestablishment by the UE 5.3.7.5 */ /* Reception of RRCConnectionReestablishment by the UE 5.3.7.5 */
void rrc::handle_con_reest(LIBLTE_RRC_CONNECTION_REESTABLISHMENT_STRUCT *setup) { void rrc::handle_con_reest(LIBLTE_RRC_CONNECTION_REESTABLISHMENT_STRUCT *setup) {
mac_timers->get(t301)->stop(); mac_timers->timer_get(t301)->stop();
// TODO: Restablish DRB1. Not done because never was suspended // TODO: Restablish DRB1. Not done because never was suspended
@ -1740,8 +1740,8 @@ void rrc::set_mac_default() {
void rrc::set_rrc_default() { void rrc::set_rrc_default() {
N310 = 1; N310 = 1;
N311 = 1; N311 = 1;
mac_timers->get(t310)->set(this, 1000); mac_timers->timer_get(t310)->set(this, 1000);
mac_timers->get(t311)->set(this, 1000); mac_timers->timer_get(t311)->set(this, 1000);
} }

Loading…
Cancel
Save