1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 #include "common_def.h"
22 #include "mac_sch_interface.h"
27 * @brief Handler to check if the timer is running
29 * @param[in] cb Control block depending on the type of the timer event.
30 * @param[in] tmrEvnt Timer event to be started
32 * @return Bool indicating whether the timer is running or not
36 bool schChkTmr(PTR cb, int16_t tmrEvnt)
40 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
42 if(((TotalPrbUsage *)cb)->periodTimer.tmrEvnt == EVENT_DL_TOTAL_PRB_USAGE_TMR)
44 DU_LOG("\nDEBUG --> SCH : schChkTmr: Timer Evnt [%d] already running", tmrEvnt);
50 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
52 if(((TotalPrbUsage *)cb)->periodTimer.tmrEvnt == EVENT_UL_TOTAL_PRB_USAGE_TMR)
54 DU_LOG("\nDEBUG --> SCH : schChkTmr: Timer Evnt [%d] already running", tmrEvnt);
62 DU_LOG("\nERROR --> SCH : schChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
70 * @brief Handler to start timer
72 * @param[in] cb Control block depending on the type of the timer event.
73 * @param[in] tmrEvnt Timer event to be started
77 void schStartTmr(SchCb *gCb, PTR cb, int16_t tmrEvnt, uint8_t timerValue)
79 TotalPrbUsage *dlTotalPrbUsage;
80 TotalPrbUsage *ulTotalPrbUsage;
86 DU_LOG("\nDEBUG --> SCH : Starting Timer Event [%d] with Wait Time [%d] ms", \
92 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
94 dlTotalPrbUsage = ((TotalPrbUsage *)cb);
95 TMR_CALCUATE_WAIT(arg.wait, timerValue, gCb->schTimersInfo.tmrRes);
97 arg.timers = &dlTotalPrbUsage->periodTimer;
98 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
102 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
104 ulTotalPrbUsage = ((TotalPrbUsage *)cb);
105 TMR_CALCUATE_WAIT(arg.wait, timerValue, gCb->schTimersInfo.tmrRes);
107 arg.timers = &ulTotalPrbUsage->periodTimer;
108 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
113 DU_LOG("\nERROR --> SCH : schStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
119 arg.tqCp = &(gCb->schTimersInfo.tmrTqCp);
120 arg.tq = gCb->schTimersInfo.tmrTq;
132 * @brief Handler to stop a timer
134 * @param[in] cb Control block depending on the type of the timer event.
135 * @param[in] tmrType Timer event to be started
139 void schStopTmr(SchCb *gCb, PTR cb, uint8_t tmrType)
146 DU_LOG("\nDEBUG --> SCH : Stopping Timer Event [%d]", tmrType);
151 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
153 arg.timers = &((TotalPrbUsage *)cb)->periodTimer;
154 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
157 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
159 arg.timers = &((TotalPrbUsage *)cb)->periodTimer;
160 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
166 DU_LOG("\nERROR --> SCH : schStopTmr: Invalid tmr Evnt[%d]", tmrType);
173 arg.tqCp = &gCb->schTimersInfo.tmrTqCp;
174 arg.tq = gCb->schTimersInfo.tmrTq;
186 * @brief Handler to process Timer expiry of DL Total PRB Usage calculation
188 * @param[in] cb Control block depending on the type of the timer event.
189 * @param[in] tmrEvnt Timer event to be started
191 * @return Bool indicating whether the timer is running or not
195 uint8_t SchProcDlTotalPrbUsageTmrExp(TotalPrbUsage *dlTotalPrbUsage)
197 double percentageOfTotalPrbUsed = 0;
199 if(dlTotalPrbUsage->totalPrbAvailForTx)
200 percentageOfTotalPrbUsed = ((100.0 * dlTotalPrbUsage->numPrbUsedForTx) / dlTotalPrbUsage->totalPrbAvailForTx);
201 SchSendStatsIndToMac(dlTotalPrbUsage->schInst, SCH_DL_TOTAL_PRB_USAGE, percentageOfTotalPrbUsed);
204 dlTotalPrbUsage->numPrbUsedForTx = 0;
205 dlTotalPrbUsage->totalPrbAvailForTx = 0;
206 schStartTmr(&schCb[dlTotalPrbUsage->schInst], (PTR)(dlTotalPrbUsage), EVENT_DL_TOTAL_PRB_USAGE_TMR, \
207 dlTotalPrbUsage->periodicity);
213 * @brief Handler to check if the timer is running
215 * @param[in] cb Control block depending on the type of the timer event.
216 * @param[in] tmrEvnt Timer event to be started
218 * @return Bool indicating whether the timer is running or not
222 uint8_t SchProcUlTotalPrbUsageTmrExp(TotalPrbUsage *ulTotalPrbUsage)
224 double percentageOfTotalPrbUsed = 0;
226 if(ulTotalPrbUsage->totalPrbAvailForTx)
227 percentageOfTotalPrbUsed = ((100.0 * ulTotalPrbUsage->numPrbUsedForTx) / ulTotalPrbUsage->totalPrbAvailForTx);
228 SchSendStatsIndToMac(ulTotalPrbUsage->schInst, SCH_UL_TOTAL_PRB_USAGE, percentageOfTotalPrbUsed);
231 ulTotalPrbUsage->numPrbUsedForTx = 0;
232 ulTotalPrbUsage->totalPrbAvailForTx = 0;
233 schStartTmr(&schCb[ulTotalPrbUsage->schInst], (PTR)(ulTotalPrbUsage), EVENT_UL_TOTAL_PRB_USAGE_TMR, \
234 ulTotalPrbUsage->periodicity);
240 * @brief Timer Expiry handler.
244 * Function : schTmrExpiry
246 * This is a callback function used as an input parameter to cmPrcTmr()
247 * to check expiry of any timer. In this function, we are only concerned
248 * about tmrEvnt=Bind timer.
250 * @param[in] PTR cb, Entry for which Timer expired
251 * @param[in] uint8_t tmrEvnt, the Timer Event
255 uint8_t schTmrExpiry(PTR cb, uint8_t tmrEvnt)
258 DU_LOG("\nDEBUG --> SCH : Timer Expired. Event [%d]", tmrEvnt);
263 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
265 SchProcDlTotalPrbUsageTmrExp((TotalPrbUsage*)cb);
268 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
270 SchProcUlTotalPrbUsageTmrExp((TotalPrbUsage*)cb);
275 DU_LOG("\nERROR --> DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
283 * @brief Scheduler instance timer call back function registered with system services.
287 * Function : schActvTmr
289 * This function is invoked for every timer activation
290 * period expiry. Note that SS_MT_TMR flag needs to be enabled for this
291 * as isntId is needed.As part of SRegTmr call for scheduler instance
292 * SS_MT_TMR flag needs to be enabled and schActvTmr needs to be given as
298 short int schActvTmr(Ent ent,Inst inst)
300 Inst schInst = (inst - SCH_INST_START);
302 /* Check if any timer in the scheduler instance has expired */
303 cmPrcTmr(&schCb[schInst].schTimersInfo.tmrTqCp, schCb[schInst].schTimersInfo.tmrTq, (PFV) schTmrExpiry);
307 } /* end of schActvTmr */
309 /**********************************************************************
312 **********************************************************************/