make DL and UL harq template classes

master
Andre Puschmann 8 years ago
parent 869786a27c
commit 704b8c3dc4

@ -45,15 +45,15 @@
namespace srsue {
template <std::size_t N, typename Tgrant, typename Taction, typename Tphygrant>
class dl_harq_entity
{
public:
const static uint32_t NOF_HARQ_PROC = 8;
const static uint32_t HARQ_BCCH_PID = NOF_HARQ_PROC;
const static uint32_t HARQ_BCCH_PID = N;
dl_harq_entity()
dl_harq_entity() : proc(N+1)
{
pcap = NULL;
}
@ -65,7 +65,7 @@ public:
mac_cfg = mac_cfg_;
si_window_start = 0;
log_h = log_h_;
for (uint32_t i=0;i<NOF_HARQ_PROC+1;i++) {
for (uint32_t i=0;i<N+1;i++) {
if (!proc[i].init(i, this)) {
return false;
}
@ -74,7 +74,7 @@ public:
}
/***************** PHY->MAC interface for DL processes **************************/
void new_grant_dl(mac_interface_phy::mac_grant_t grant, mac_interface_phy::tb_action_dl_t *action)
void new_grant_dl(Tgrant grant, Taction *action)
{
if (grant.rnti_type != SRSLTE_RNTI_SPS) {
uint32_t harq_pid;
@ -82,7 +82,7 @@ public:
if (grant.rnti_type == SRSLTE_RNTI_SI) {
harq_pid = HARQ_BCCH_PID;
} else {
harq_pid = grant.pid%NOF_HARQ_PROC;
harq_pid = grant.pid%N;
}
if (grant.rnti_type == SRSLTE_RNTI_TEMP && last_temporal_crnti != grant.rnti) {
grant.ndi = true;
@ -96,7 +96,7 @@ public:
proc[harq_pid].new_grant_dl(grant, action);
} else {
/* This is for SPS scheduling */
uint32_t harq_pid = get_harq_sps_pid(grant.tti)%NOF_HARQ_PROC;
uint32_t harq_pid = get_harq_sps_pid(grant.tti)%N;
if (grant.ndi) {
grant.ndi = false;
proc[harq_pid].new_grant_dl(grant, action);
@ -121,16 +121,16 @@ public:
void tb_decoded(bool ack, srslte_rnti_type_t rnti_type, uint32_t harq_pid)
{
if (rnti_type == SRSLTE_RNTI_SI) {
proc[NOF_HARQ_PROC].tb_decoded(ack);
proc[N].tb_decoded(ack);
} else {
proc[harq_pid%NOF_HARQ_PROC].tb_decoded(ack);
proc[harq_pid%N].tb_decoded(ack);
}
}
void reset()
{
for (uint32_t i=0;i<NOF_HARQ_PROC+1;i++) {
for (uint32_t i=0;i<N+1;i++) {
proc[i].reset();
}
dl_sps_assig.clear();
@ -138,7 +138,7 @@ public:
void start_pcap(srslte::mac_pcap* pcap_) { pcap = pcap_; }
int get_current_tbs(uint32_t harq_pid) { return proc[harq_pid%NOF_HARQ_PROC].get_current_tbs(); }
int get_current_tbs(uint32_t harq_pid) { return proc[harq_pid%N].get_current_tbs(); }
void set_si_window_start(int si_window_start_) { si_window_start = si_window_start_; }
@ -151,7 +151,7 @@ private:
{
is_initiated = false;
ack = false;
bzero(&cur_grant, sizeof(mac_interface_phy::mac_grant_t));
bzero(&cur_grant, sizeof(Tgrant));
}
bool init(uint32_t pid_, dl_harq_entity *parent)
@ -172,13 +172,13 @@ private:
{
ack = false;
payload_buffer_ptr = NULL;
bzero(&cur_grant, sizeof(mac_interface_phy::mac_grant_t));
bzero(&cur_grant, sizeof(Tgrant));
if (is_initiated) {
srslte_softbuffer_rx_reset(&softbuffer);
}
}
void new_grant_dl(mac_interface_phy::mac_grant_t grant, mac_interface_phy::tb_action_dl_t *action)
void new_grant_dl(Tgrant grant, Taction *action)
{
// Compute RV for BCCH when not specified in PDCCH format
if (pid == HARQ_BCCH_PID && grant.rv == -1) {
@ -201,10 +201,10 @@ private:
// Save grant
grant.last_ndi = cur_grant.ndi;
grant.last_tti = cur_grant.tti;
memcpy(&cur_grant, &grant, sizeof(mac_interface_phy::mac_grant_t));
memcpy(&cur_grant, &grant, sizeof(Tgrant));
// Fill action structure
bzero(action, sizeof(mac_interface_phy::tb_action_dl_t));
bzero(action, sizeof(Taction));
action->default_ack = ack;
action->generate_ack = true;
action->decode_enabled = false;
@ -224,7 +224,7 @@ private:
action->rv = cur_grant.rv;
action->rnti = cur_grant.rnti;
action->softbuffer = &softbuffer;
memcpy(&action->phy_grant, &cur_grant.phy_grant, sizeof(srslte_phy_grant_t));
memcpy(&action->phy_grant, &cur_grant.phy_grant, sizeof(Tphygrant));
n_retx++;
} else {
@ -293,7 +293,7 @@ private:
int get_current_tbs() { return cur_grant.n_bytes*8; }
private:
bool calc_is_new_transmission(mac_interface_phy::mac_grant_t grant)
bool calc_is_new_transmission(Tgrant grant)
{
bool is_new_tb = true;
if ((srslte_tti_interval(grant.tti, cur_grant.tti) <= 8 && (grant.n_bytes == cur_grant.n_bytes)) ||
@ -328,7 +328,7 @@ private:
uint32_t n_retx;
mac_interface_phy::mac_grant_t cur_grant;
Tgrant cur_grant;
srslte_softbuffer_rx_t softbuffer;
};
@ -344,7 +344,8 @@ private:
dl_sps dl_sps_assig;
dl_harq_process proc[NOF_HARQ_PROC+1];
std::vector<dl_harq_process> proc;
srslte::timers *timers_db;
mac_interface_rrc::mac_cfg_t *mac_cfg;
demux *demux_unit;

@ -106,6 +106,7 @@ private:
static const int MAC_MAIN_THREAD_PRIO = 5;
static const int MAC_PDU_THREAD_PRIO = 6;
static const int MAC_NOF_HARQ_PROC = 8;
// Interaction with PHY
srslte::tti_sync_cv ttisync;
@ -130,9 +131,9 @@ private:
mux mux_unit;
demux demux_unit;
/* DL/UL HARQ */
dl_harq_entity dl_harq;
ul_harq_entity ul_harq;
/* DL/UL HARQ */
dl_harq_entity<MAC_NOF_HARQ_PROC, mac_grant_t, tb_action_dl_t, srslte_phy_grant_t> dl_harq;
ul_harq_entity<MAC_NOF_HARQ_PROC, mac_grant_t, tb_action_ul_t, srslte_phy_grant_t> ul_harq;
/* MAC Uplink-related Procedures */
ra_proc ra_procedure;

@ -43,17 +43,18 @@
/* Uplink HARQ entity as defined in 5.4.2 of 36.321 */
namespace srsue {
template <std::size_t N, typename Tgrant, typename Taction, typename Tphygrant>
class ul_harq_entity
{
public:
const static uint32_t NOF_HARQ_PROC = 8;
static uint32_t pidof(uint32_t tti)
{
return (uint32_t) tti%NOF_HARQ_PROC;
return (uint32_t) tti%N;
}
ul_harq_entity() {
ul_harq_entity() : proc(N)
{
pcap = NULL;
timers_db = NULL;
mux_unit = NULL;
@ -61,7 +62,7 @@ public:
mac_cfg = NULL;
rntis = NULL;
average_retx = 0;
nof_pkts = 0;
nof_pkts = 0;
}
bool init(srslte::log *log_h_,
@ -75,7 +76,7 @@ public:
mac_cfg = mac_cfg_;
rntis = rntis_;
timers_db = timers_db_;
for (uint32_t i=0;i<NOF_HARQ_PROC;i++) {
for (uint32_t i=0;i<N;i++) {
if (!proc[i].init(i, this)) {
return false;
}
@ -85,7 +86,7 @@ public:
void reset()
{
for (uint32_t i=0;i<NOF_HARQ_PROC;i++) {
for (uint32_t i=0;i<N;i++) {
proc[i].reset();
}
ul_sps_assig.clear();
@ -93,7 +94,7 @@ public:
void reset_ndi()
{
for (uint32_t i=0;i<NOF_HARQ_PROC;i++) {
for (uint32_t i=0;i<N;i++) {
proc[i].reset_ndi();
}
}
@ -105,7 +106,7 @@ public:
/***************** PHY->MAC interface for UL processes **************************/
void new_grant_ul(mac_interface_phy::mac_grant_t grant, mac_interface_phy::tb_action_ul_t *action)
void new_grant_ul(Tgrant grant, Taction *action)
{
if (grant.rnti_type == SRSLTE_RNTI_USER ||
grant.rnti_type == SRSLTE_RNTI_TEMP ||
@ -125,13 +126,13 @@ public:
}
}
void new_grant_ul_ack(mac_interface_phy::mac_grant_t grant, bool ack, mac_interface_phy::tb_action_ul_t *action)
void new_grant_ul_ack(Tgrant grant, bool ack, Taction *action)
{
set_ack(grant.tti, ack);
new_grant_ul(grant, action);
}
void harq_recv(uint32_t tti, bool ack, mac_interface_phy::tb_action_ul_t *action)
void harq_recv(uint32_t tti, bool ack, Taction *action)
{
set_ack(tti, ack);
run_tti(tti, NULL, action);
@ -162,7 +163,7 @@ private:
is_initiated = false;
is_grant_configured = false;
tti_last_tx = 0;
bzero(&cur_grant, sizeof(mac_interface_phy::mac_grant_t));
bzero(&cur_grant, sizeof(Tgrant));
}
bool init(uint32_t pid_, ul_harq_entity *parent)
@ -191,12 +192,12 @@ private:
current_irv = 0;
tti_last_tx = 0;
is_grant_configured = false;
bzero(&cur_grant, sizeof(mac_interface_phy::mac_grant_t));
bzero(&cur_grant, sizeof(Tgrant));
}
void reset_ndi() { ndi = false; }
void run_tti(uint32_t tti_tx, mac_interface_phy::mac_grant_t *grant, mac_interface_phy::tb_action_ul_t* action)
void run_tti(uint32_t tti_tx, Tgrant *grant, Taction* action)
{
uint32_t max_retx;
if (is_msg3) {
@ -287,7 +288,7 @@ private:
int get_current_tbs() { return cur_grant.n_bytes*8; }
private:
mac_interface_phy::mac_grant_t cur_grant;
Tgrant cur_grant;
uint32_t pid;
uint32_t current_tx_nb;
@ -307,14 +308,14 @@ private:
uint8_t *payload_buffer;
uint8_t *pdu_ptr;
void generate_retx(uint32_t tti_tx, mac_interface_phy::tb_action_ul_t *action)
void generate_retx(uint32_t tti_tx, Taction *action)
{
generate_retx(tti_tx, NULL, action);
}
// Retransmission with or w/o grant (Section 5.4.2.2)
void generate_retx(uint32_t tti_tx, mac_interface_phy::mac_grant_t *grant,
mac_interface_phy::tb_action_ul_t *action)
void generate_retx(uint32_t tti_tx, Tgrant *grant,
Taction *action)
{
int irv_of_rv[4] = {0, 3, 1, 2};
if (grant) {
@ -322,7 +323,7 @@ private:
if (grant->rv) {
current_irv = irv_of_rv[grant->rv%4];
}
memcpy(&cur_grant, grant, sizeof(mac_interface_phy::mac_grant_t));
memcpy(&cur_grant, grant, sizeof(Tgrant));
harq_feedback = false;
Info("UL %d: Adaptive retx=%d, RV=%d, TBS=%d\n",
pid, current_tx_nb, get_rv(), grant->n_bytes);
@ -345,13 +346,12 @@ private:
}
// New transmission (Section 5.4.2.2)
void generate_new_tx(uint32_t tti_tx, bool is_msg3_, mac_interface_phy::mac_grant_t *grant,
mac_interface_phy::tb_action_ul_t *action)
void generate_new_tx(uint32_t tti_tx, bool is_msg3_, Tgrant *grant, Taction *action)
{
if (grant) {
// Compute average number of retransmissions per packet considering previous packet
harq_entity->average_retx = SRSLTE_VEC_CMA((float) current_tx_nb, harq_entity->average_retx, harq_entity->nof_pkts++);
memcpy(&cur_grant, grant, sizeof(mac_interface_phy::mac_grant_t));
memcpy(&cur_grant, grant, sizeof(Tgrant));
harq_feedback = false;
is_grant_configured = true;
current_tx_nb = 0;
@ -364,7 +364,7 @@ private:
}
// Transmission of pending frame (Section 5.4.2.2)
void generate_tx(uint32_t tti_tx, mac_interface_phy::tb_action_ul_t *action)
void generate_tx(uint32_t tti_tx, Taction *action)
{
action->current_tx_nb = current_tx_nb;
current_tx_nb++;
@ -374,7 +374,7 @@ private:
action->softbuffer = &softbuffer;
action->tx_enabled = true;
action->payload_ptr = pdu_ptr;
memcpy(&action->phy_grant, &cur_grant.phy_grant, sizeof(srslte_phy_grant_t));
memcpy(&action->phy_grant, &cur_grant.phy_grant, sizeof(Tphygrant));
current_irv = (current_irv+1)%4;
tti_last_tx = tti_tx;
@ -383,7 +383,7 @@ private:
// Implements Section 5.4.2.1
// Called with UL grant
void run_tti(uint32_t tti, mac_interface_phy::mac_grant_t *grant, mac_interface_phy::tb_action_ul_t* action)
void run_tti(uint32_t tti, Tgrant *grant, Taction* action)
{
uint32_t tti_tx = (tti+4)%10240;
proc[pidof(tti_tx)].run_tti(tti_tx, grant, action);
@ -405,7 +405,7 @@ private:
srslte::timers *timers_db;
mux *mux_unit;
ul_harq_process proc[NOF_HARQ_PROC];
std::vector<ul_harq_process> proc;
srslte::log *log_h;
srslte::mac_pcap *pcap;

Loading…
Cancel
Save