Commit 73113728 authored by francescomani's avatar francescomani

apply new timer implementation to other MAC timers

parent 0224cb8a
......@@ -883,6 +883,11 @@ bool is_nr_timer_active(NR_timer_t timer)
return timer.active;
}
bool is_nr_timer_configured(NR_timer_t timer)
{
return (timer.target > 0);
}
bool nr_timer_tick(NR_timer_t *timer)
{
bool expired = false;
......@@ -900,6 +905,11 @@ bool nr_timer_expired(NR_timer_t timer)
return (timer.counter >= timer.target);
}
uint32_t nr_timer_get_counter(NR_timer_t timer)
{
return timer.counter;
}
void nr_timer_setup(NR_timer_t *timer, const uint32_t target, const uint32_t step)
{
timer->target = target;
......
......@@ -158,6 +158,18 @@ bool nr_timer_expired(NR_timer_t timer);
* @return Indication if the timer is active or not
*/
bool is_nr_timer_active(NR_timer_t timer);
/**
* @brief To check if a timer is configured
* @param timer Timer to be checked
* @return Indication if the timer is configured or not
*/
bool is_nr_timer_configured(NR_timer_t timer);
/**
* @brief To check the time elapsed in timer
* @param timer Timer to be checked
* @return Timer counter
*/
uint32_t nr_timer_get_counter(NR_timer_t timer);
extern const nr_bandentry_t nr_bandtable[];
......
......@@ -1506,8 +1506,7 @@ static void configure_maccellgroup(NR_UE_MAC_INST_t *mac, const NR_MAC_CellGroup
for (int i = 0; i < src->schedulingRequestToReleaseList->list.count; i++) {
if (*src->schedulingRequestToReleaseList->list.array[i] == si->sr_id) {
si->SR_COUNTER = 0;
si->sr_ProhibitTimer = 0;
si->sr_ProhibitTimer_Running = 0;
memset(&si->sr_ProhibitTimer, 0, sizeof(si->sr_ProhibitTimer));
si->sr_id = -1; // invalid init value
}
else
......@@ -1528,8 +1527,13 @@ static void configure_maccellgroup(NR_UE_MAC_INST_t *mac, const NR_MAC_CellGroup
}
}
if (mcg->bsr_Config) {
si->periodicBSR_Timer = mcg->bsr_Config->periodicBSR_Timer;
si->retxBSR_Timer = mcg->bsr_Config->retxBSR_Timer;
long mu = mac->current_UL_BWP->scs;
int subframes_per_slot = nr_slots_per_frame[mu] / 10;
nr_timer_setup(&mac->scheduling_info.retxBSR_Timer,
subframes_per_slot * nr_get_sf_periodicBSRTimer(mcg->bsr_Config->periodicBSR_Timer),
1);
int retx_sf = 10 * (1 << mcg->bsr_Config->retxBSR_Timer);
nr_timer_setup(&si->retxBSR_Timer, subframes_per_slot * retx_sf, 1);
if (mcg->bsr_Config->logicalChannelSR_DelayTimer)
LOG_E(NR_MAC, "Handling of logicalChannelSR_DelayTimer not implemented\n");
}
......@@ -1936,9 +1940,6 @@ void nr_rrc_mac_config_req_cg(module_id_t module_id,
AssertFatal(cell_group_config, "CellGroupConfig should not be NULL\n");
NR_UE_MAC_INST_t *mac = get_mac_inst(module_id);
if (cell_group_config->mac_CellGroupConfig)
configure_maccellgroup(mac, cell_group_config->mac_CellGroupConfig);
if (cell_group_config->physicalCellGroupConfig)
configure_physicalcellgroup(mac, cell_group_config->physicalCellGroupConfig);
......@@ -1965,6 +1966,9 @@ void nr_rrc_mac_config_req_cg(module_id_t module_id,
if (mac->current_UL_BWP->rach_ConfigCommon)
build_ssb_to_ro_map(mac);
if (cell_group_config->mac_CellGroupConfig)
configure_maccellgroup(mac, cell_group_config->mac_CellGroupConfig);
if (!mac->dl_config_request || !mac->ul_config_request)
ue_init_config_request(mac, mac->current_DL_BWP->scs);
}
......@@ -71,9 +71,6 @@
#define MAX_NUM_BWP_UE 5
#define NUM_SLOT_FRAME 10
/*!\brief value for indicating BSR Timer is not running */
#define NR_MAC_UE_BSR_TIMER_NOT_RUNNING (0xFFFF)
// ================================================
// SSB to RO mapping private defines and structures
// ================================================
......@@ -206,33 +203,21 @@ typedef struct {
uint8_t SR_pending;
/// SR_COUNTER as defined in 38.321
uint16_t SR_COUNTER;
/// retxBSR-Timer, default value is sf2560
uint16_t retxBSR_Timer;
/// retxBSR_SF, number of subframe before triggering a regular BSR
uint16_t retxBSR_SF;
/// periodicBSR-Timer, default to infinity
uint16_t periodicBSR_Timer;
/// periodicBSR_SF, number of subframe before triggering a periodic BSR
uint16_t periodicBSR_SF;
/// retxBSR-Timer, default value is sf80
NR_timer_t retxBSR_Timer;
/// periodicBSR-Timer, default is sf10
NR_timer_t periodicBSR_Timer;
// time elapsed since Bj was last incremented
NR_timer_t bj_Timer;
/// default value is 0: not configured
uint16_t sr_ProhibitTimer;
/// sr ProhibitTime running
uint8_t sr_ProhibitTimer_Running;
NR_timer_t sr_ProhibitTimer;
// Maximum number of SR transmissions
uint32_t sr_TransMax;
int sr_id;
///timer before triggering a periodic PHR
uint16_t periodicPHR_Timer;
NR_timer_t periodicPHR_Timer;
///timer before triggering a prohibit PHR
uint16_t prohibitPHR_Timer;
///DL Pathloss change value
uint16_t PathlossChange;
///number of subframe before triggering a periodic PHR
int16_t periodicPHR_SF;
///number of subframe before triggering a prohibit PHR
int16_t prohibitPHR_SF;
///DL Pathloss Change in db
uint16_t PathlossChange_db;
NR_timer_t prohibitPHR_Timer;
/// default value is false
uint16_t extendedBSR_Sizes_r10;
/// default value is false
......
......@@ -254,13 +254,6 @@ uint32_t nr_get_pbr(uint8_t prioritizedbitrate);
*/
int nr_get_sf_periodicBSRTimer(uint8_t bucketSize);
/*! \fn int nr_get_sf_retxBSRTimer(uint8_t retxBSR_Timer)
\brief get the number of subframe form the bucket size duration configured by the higher layer
\param[in] retxBSR_Timer timer for regular BSR
\return the time in sf
*/
int nr_get_sf_retxBSRTimer(uint8_t retxBSR_Timer);
int8_t nr_ue_process_dci(module_id_t module_id,
int cc_id,
frame_t frame,
......
......@@ -79,18 +79,23 @@ void nr_ue_init_mac(module_id_t module_idP)
void nr_ue_mac_default_configs(NR_UE_MAC_INST_t *mac)
{
// default values as defined in 38.331 sec 9.2.2
mac->scheduling_info.retxBSR_Timer = NR_BSR_Config__retxBSR_Timer_sf10240;
mac->scheduling_info.periodicBSR_Timer = NR_BSR_Config__periodicBSR_Timer_infinity;
// numerology known only in SA
// (NSA and similar modes get configuration at beginning so applied before sync anyway)
if (get_softmodem_params()->sa) {
int subframes_per_slot = nr_slots_per_frame[get_softmodem_params()->numerology] / 10;
// default value 80sf, step 1 slot
nr_timer_setup(&mac->scheduling_info.retxBSR_Timer, 80 * subframes_per_slot, 1);
}
mac->scheduling_info.SR_COUNTER = 0;
mac->scheduling_info.SR_pending = 0;
mac->scheduling_info.sr_ProhibitTimer = 0;
mac->scheduling_info.sr_ProhibitTimer_Running = 0;
memset(&mac->scheduling_info.sr_ProhibitTimer, 0, sizeof(mac->scheduling_info.sr_ProhibitTimer));
mac->scheduling_info.sr_id = -1; // invalid init value
// set init value 0xFFFF, make sure periodic timer and retx time counters are NOT active, after bsr transmission set the value
// configured by the NW.
mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
memset(&mac->scheduling_info.periodicPHR_Timer, 0, sizeof(mac->scheduling_info.periodicPHR_Timer));
memset(&mac->scheduling_info.prohibitPHR_Timer, 0, sizeof(mac->scheduling_info.prohibitPHR_Timer));
memset(&mac->scheduling_info.bj_Timer, 0, sizeof(mac->scheduling_info.bj_Timer));
memset(&mac->scheduling_info.periodicBSR_Timer, 0, sizeof(mac->scheduling_info.periodicBSR_Timer));
mac->BSR_reporting_active = BSR_TRIGGER_NONE;
for (int i = 0; i < NR_MAX_NUM_LCID; i++) {
......
......@@ -2426,13 +2426,9 @@ int8_t nr_ue_get_SR(module_id_t module_idP, frame_t frameP, slot_t slot)
si->SR_pending); // todo
si->SR_COUNTER++;
// start the sr-prohibittimer : rel 9 and above
if (si->sr_ProhibitTimer > 0) { // timer configured
si->sr_ProhibitTimer--;
si->sr_ProhibitTimer_Running = 1;
} else {
si->sr_ProhibitTimer_Running = 0;
}
// start the sr-prohibittimer
if (is_nr_timer_configured(si->sr_ProhibitTimer))
nr_timer_start(&si->sr_ProhibitTimer);
//mac->ul_active =1;
return (1); //instruct phy to signal SR
} else {
......
......@@ -93,6 +93,17 @@ fapi_nr_ul_config_request_pdu_t *lockGet_ul_config(NR_UE_MAC_INST_t *mac, frame_
void update_mac_timers(NR_UE_MAC_INST_t *mac)
{
nr_timer_tick(&mac->ra.contention_resolution_timer);
nr_timer_tick(&mac->scheduling_info.retxBSR_Timer);
bool periodicBSR_exp = nr_timer_tick(&mac->scheduling_info.periodicBSR_Timer);
if (periodicBSR_exp) {
// Trigger BSR Periodic
mac->BSR_reporting_active |= NR_BSR_TRIGGER_PERIODIC;
LOG_D(NR_MAC, "[UE %d] MAC BSR Triggered PeriodicBSR Timer expiry\n", mac->ue_id);
}
nr_timer_tick(&mac->scheduling_info.sr_ProhibitTimer);
nr_timer_tick(&mac->scheduling_info.periodicPHR_Timer);
nr_timer_tick(&mac->scheduling_info.prohibitPHR_Timer);
nr_timer_tick(&mac->scheduling_info.bj_Timer);
}
void remove_ul_config_last_item(fapi_nr_ul_config_request_pdu_t *pdu)
......@@ -1099,6 +1110,7 @@ void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info)
mac->if_module->scheduled_response(&scheduled_response);
}
bool bj_updated = false;
// update Bj for all active lcids before LCP procedure
LOG_D(NR_MAC, "====================[Frame %d][Slot %d]Logical Channel Prioritization===========\n", frame_tx, slot_tx);
for (nr_lcordered_info_t *lc_bearer = mac->lc_ordered_info; lc_bearer->logicalChannelConfig_ordered != NULL; lc_bearer++) {
......@@ -1113,30 +1125,25 @@ void nr_ue_ul_scheduler(nr_uplink_indication_t *ul_info)
measure Bj
increment the value of Bj by product PBR * T
*/
int T = 1; // time elapsed since Bj was last incremented
// time elapsed since Bj was last incremented
int T_slots = nr_timer_get_counter(mac->scheduling_info.bj_Timer);
int mu = mac->current_UL_BWP->scs;
int T = T_slots * 10 / nr_slots_per_frame[mu]; // in ms
int32_t bj = sched_lc->Bj;
bj += nr_get_pbr(lcconfig->ul_SpecificParameters->prioritisedBitRate) * T;
bj += ((nr_get_pbr(lcconfig->ul_SpecificParameters->prioritisedBitRate) / 1000) * T); // PBR in B/s
if (lcconfig->ul_SpecificParameters->prioritisedBitRate
== NR_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity) {
bj = nr_get_pbr(lcconfig->ul_SpecificParameters->prioritisedBitRate);
}
// bj > max bucket size, set bj to max bucket size, as in ts38.321 5.4.3.1 Logical Channel Prioritization
sched_lc->Bj = min(bj, bucketSize_max);
bj_updated = true;
}
// Call BSR procedure as described in Section 5.4.5 in 38.321
// First check ReTxBSR Timer because it is always configured
// Decrement ReTxBSR Timer if it is running and not null
if ((mac->scheduling_info.retxBSR_SF != MAC_UE_BSR_TIMER_NOT_RUNNING) && (mac->scheduling_info.retxBSR_SF != 0)) {
mac->scheduling_info.retxBSR_SF--;
}
if (bj_updated)
nr_timer_start(&mac->scheduling_info.bj_Timer);
// Decrement Periodic Timer if it is running and not null
if ((mac->scheduling_info.periodicBSR_SF != MAC_UE_BSR_TIMER_NOT_RUNNING) && (mac->scheduling_info.periodicBSR_SF != 0)) {
mac->scheduling_info.periodicBSR_SF--;
}
// Call BSR procedure as described in Section 5.4.5 in 38.321
//Check whether Regular BSR is triggered
if (nr_update_bsr(mod_id, frame_tx, slot_tx, gNB_index) == true) {
......@@ -1270,8 +1277,9 @@ bool nr_update_bsr(module_id_t module_idP, frame_t frameP, slot_t slotP, uint8_t
}
// Trigger Regular BSR if ReTxBSR Timer has expired and UE has data for transmission
if (mac->scheduling_info.retxBSR_SF == 0) {
if (nr_timer_expired(mac->scheduling_info.retxBSR_Timer)) {
bsr_regular_triggered = true;
nr_timer_stop(&mac->scheduling_info.retxBSR_Timer);
if ((mac->BSR_reporting_active & NR_BSR_TRIGGER_REGULAR) == 0) {
LOG_I(NR_MAC, "[UE %d] PDCCH Tick : MAC BSR Triggered ReTxBSR Timer expiry at frame %d slot %d\n",
......@@ -1323,123 +1331,57 @@ nr_locate_BsrIndexByBufferSize(const uint32_t *table, int size, int value) {
}
}
int nr_get_sf_periodicBSRTimer(uint8_t sf_offset) {
int nr_get_sf_periodicBSRTimer(uint8_t sf_offset)
{
switch (sf_offset) {
case NR_BSR_Config__periodicBSR_Timer_sf1:
return 1;
break;
case NR_BSR_Config__periodicBSR_Timer_sf5:
return 5;
break;
case NR_BSR_Config__periodicBSR_Timer_sf10:
return 10;
break;
case NR_BSR_Config__periodicBSR_Timer_sf16:
return 16;
break;
case NR_BSR_Config__periodicBSR_Timer_sf20:
return 20;
break;
case NR_BSR_Config__periodicBSR_Timer_sf32:
return 32;
break;
case NR_BSR_Config__periodicBSR_Timer_sf40:
return 40;
break;
case NR_BSR_Config__periodicBSR_Timer_sf64:
return 64;
break;
case NR_BSR_Config__periodicBSR_Timer_sf80:
return 80;
break;
case NR_BSR_Config__periodicBSR_Timer_sf128:
return 128;
break;
case NR_BSR_Config__periodicBSR_Timer_sf160:
return 160;
break;
case NR_BSR_Config__periodicBSR_Timer_sf320:
return 320;
break;
case NR_BSR_Config__periodicBSR_Timer_sf640:
return 640;
break;
case NR_BSR_Config__periodicBSR_Timer_sf1280:
return 1280;
break;
case NR_BSR_Config__periodicBSR_Timer_sf2560:
return 2560;
break;
case NR_BSR_Config__periodicBSR_Timer_infinity:
default:
return 0xFFFF;
break;
}
}
int nr_get_sf_retxBSRTimer(uint8_t sf_offset) {
switch (sf_offset) {
case NR_BSR_Config__retxBSR_Timer_sf10:
return 10;
break;
case NR_BSR_Config__retxBSR_Timer_sf20:
return 20;
break;
case NR_BSR_Config__retxBSR_Timer_sf40:
return 40;
break;
case NR_BSR_Config__retxBSR_Timer_sf80:
return 80;
break;
case NR_BSR_Config__retxBSR_Timer_sf160:
return 160;
break;
case NR_BSR_Config__retxBSR_Timer_sf320:
return 320;
break;
case NR_BSR_Config__retxBSR_Timer_sf640:
return 640;
break;
case NR_BSR_Config__retxBSR_Timer_sf1280:
return 1280;
break;
case NR_BSR_Config__retxBSR_Timer_sf2560:
return 2560;
break;
case NR_BSR_Config__retxBSR_Timer_sf5120:
return 5120;
break;
case NR_BSR_Config__retxBSR_Timer_sf10240:
return 10240;
break;
default:
return -1;
return UINT_MAX;
break;
}
}
......@@ -2670,22 +2612,7 @@ int nr_ue_get_sdu_mac_ce_pre(module_id_t module_idP,
}
//Restart ReTxBSR Timer at new grant indication (38.321)
if (mac->scheduling_info.retxBSR_SF != MAC_UE_BSR_TIMER_NOT_RUNNING) {
mac->scheduling_info.retxBSR_SF = nr_get_sf_retxBSRTimer(mac->scheduling_info.retxBSR_Timer);
}
// periodicBSR-Timer expires, trigger BSR
if ((mac->scheduling_info.periodicBSR_Timer != NR_BSR_Config__periodicBSR_Timer_infinity)
&& (mac->scheduling_info.periodicBSR_SF == 0)) {
// Trigger BSR Periodic
mac->BSR_reporting_active |= NR_BSR_TRIGGER_PERIODIC;
LOG_D(NR_MAC,
"[UE %d] MAC BSR Triggered PeriodicBSR Timer expiry at frame%d subframe %d TBS=%d\n",
module_idP,
frameP,
subframe,
buflen);
}
nr_timer_start(&mac->scheduling_info.retxBSR_Timer);
//Compute BSR Length if Regular or Periodic BSR is triggered
//WARNING: if BSR long is computed, it may be changed to BSR short during or after multiplexing if there remains less than 1 LCGROUP with data after Tx
......@@ -2887,13 +2814,13 @@ void nr_ue_get_sdu_mac_ce_post(module_id_t module_idP,
mac_ce_p->bsr_header_len,
buflen);
// Reset ReTx BSR Timer
mac->scheduling_info.retxBSR_SF = nr_get_sf_retxBSRTimer(mac->scheduling_info.retxBSR_Timer);
LOG_D(NR_MAC, "[UE %d] MAC ReTx BSR Timer Reset =%d\n", module_idP, mac->scheduling_info.retxBSR_SF);
nr_timer_start(&mac->scheduling_info.retxBSR_Timer);
LOG_D(NR_MAC, "[UE %d] MAC ReTx BSR Timer Reset\n", module_idP);
// Reset Periodic Timer except when BSR is truncated
if ((mac_ce_p->bsr_t == NULL) && (mac->scheduling_info.periodicBSR_Timer != NR_BSR_Config__periodicBSR_Timer_infinity)) {
mac->scheduling_info.periodicBSR_SF = nr_get_sf_periodicBSRTimer(mac->scheduling_info.periodicBSR_Timer);
LOG_D(NR_MAC, "[UE %d] MAC Periodic BSR Timer Reset =%d\n", module_idP, mac->scheduling_info.periodicBSR_SF);
if ((mac_ce_p->bsr_t == NULL) && (mac->scheduling_info.periodicBSR_Timer.target != UINT_MAX)) {
nr_timer_start(&mac->scheduling_info.periodicBSR_Timer);
LOG_D(NR_MAC, "[UE %d] MAC Periodic BSR Timer Reset\n", module_idP);
}
// Reset BSR Trigger flags
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment