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;
85 DU_LOG("\nINFO --> SCH : Starting Timer Event [%d] with Wait Time [%d] ms", \
90 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
92 dlTotalPrbUsage = ((TotalPrbUsage *)cb);
93 TMR_CALCUATE_WAIT(arg.wait, timerValue, gCb->schTimersInfo.tmrRes);
95 arg.timers = &dlTotalPrbUsage->periodTimer;
96 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
100 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
102 ulTotalPrbUsage = ((TotalPrbUsage *)cb);
103 TMR_CALCUATE_WAIT(arg.wait, timerValue, gCb->schTimersInfo.tmrRes);
105 arg.timers = &ulTotalPrbUsage->periodTimer;
106 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
111 DU_LOG("\nERROR --> SCH : schStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
117 arg.tqCp = &(gCb->schTimersInfo.tmrTqCp);
118 arg.tq = gCb->schTimersInfo.tmrTq;
130 * @brief Handler to stop a timer
132 * @param[in] cb Control block depending on the type of the timer event.
133 * @param[in] tmrType Timer event to be started
137 void schStopTmr(SchCb *gCb, PTR cb, uint8_t tmrType)
143 DU_LOG("\nINFO --> SCH : Stopping Timer Event [%d]", tmrType);
147 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
149 arg.timers = &((TotalPrbUsage *)cb)->periodTimer;
150 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
153 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
155 arg.timers = &((TotalPrbUsage *)cb)->periodTimer;
156 arg.max = MAX_TOTAL_PRB_USAGE_TMR;
162 DU_LOG("\nERROR --> SCH : schStopTmr: Invalid tmr Evnt[%d]", tmrType);
169 arg.tqCp = &gCb->schTimersInfo.tmrTqCp;
170 arg.tq = gCb->schTimersInfo.tmrTq;
182 * @brief Handler to process Timer expiry of DL Total PRB Usage calculation
184 * @param[in] cb Control block depending on the type of the timer event.
185 * @param[in] tmrEvnt Timer event to be started
187 * @return Bool indicating whether the timer is running or not
191 uint8_t SchProcDlTotalPrbUsageTmrExp(TotalPrbUsage *dlTotalPrbUsage)
193 uint8_t percentageOfTotalPrbUsed = 0;
195 if(dlTotalPrbUsage->totalPrbAvailForTx)
196 percentageOfTotalPrbUsed = ((dlTotalPrbUsage->numPrbUsedForTx * 100) / dlTotalPrbUsage->totalPrbAvailForTx);
197 //SchSendStatsIndToMac(dlTotalPrbUsage->schInst, SCH_DL_TOTAL_PRB_USAGE, percentageOfTotalPrbUsed);
200 dlTotalPrbUsage->numPrbUsedForTx = 0;
201 dlTotalPrbUsage->totalPrbAvailForTx = 0;
202 schStartTmr(&schCb[dlTotalPrbUsage->schInst], (PTR)(dlTotalPrbUsage), EVENT_DL_TOTAL_PRB_USAGE_TMR, \
203 dlTotalPrbUsage->periodicity);
209 * @brief Handler to check if the timer is running
211 * @param[in] cb Control block depending on the type of the timer event.
212 * @param[in] tmrEvnt Timer event to be started
214 * @return Bool indicating whether the timer is running or not
218 uint8_t SchProcUlTotalPrbUsageTmrExp(TotalPrbUsage *ulTotalPrbUsage)
220 uint8_t percentageOfTotalPrbUsed = 0;
222 if(ulTotalPrbUsage->totalPrbAvailForTx)
223 percentageOfTotalPrbUsed = ((ulTotalPrbUsage->numPrbUsedForTx * 100) / ulTotalPrbUsage->totalPrbAvailForTx);
224 //SchSendStatsIndToMac(ulTotalPrbUsage->schInst, SCH_UL_TOTAL_PRB_USAGE, percentageOfTotalPrbUsed);
227 ulTotalPrbUsage->numPrbUsedForTx = 0;
228 ulTotalPrbUsage->totalPrbAvailForTx = 0;
229 schStartTmr(&schCb[ulTotalPrbUsage->schInst], (PTR)(ulTotalPrbUsage), EVENT_UL_TOTAL_PRB_USAGE_TMR, \
230 ulTotalPrbUsage->periodicity);
236 * @brief Timer Expiry handler.
240 * Function : schTmrExpiry
242 * This is a callback function used as an input parameter to cmPrcTmr()
243 * to check expiry of any timer. In this function, we are only concerned
244 * about tmrEvnt=Bind timer.
246 * @param[in] PTR cb, Entry for which Timer expired
247 * @param[in] uint8_t tmrEvnt, the Timer Event
251 uint8_t schTmrExpiry(PTR cb, uint8_t tmrEvnt)
255 case EVENT_DL_TOTAL_PRB_USAGE_TMR:
257 SchProcDlTotalPrbUsageTmrExp((TotalPrbUsage*)cb);
260 case EVENT_UL_TOTAL_PRB_USAGE_TMR:
262 SchProcUlTotalPrbUsageTmrExp((TotalPrbUsage*)cb);
267 DU_LOG("\nERROR --> DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
275 * @brief Scheduler instance timer call back function registered with system services.
279 * Function : schActvTmr
281 * This function is invoked for every timer activation
282 * period expiry. Note that SS_MT_TMR flag needs to be enabled for this
283 * as isntId is needed.As part of SRegTmr call for scheduler instance
284 * SS_MT_TMR flag needs to be enabled and schActvTmr needs to be given as
290 short int schActvTmr(Ent ent,Inst inst)
292 Inst schInst = (inst - SCH_INST_START);
294 /* Check if any timer in the scheduler instance has expired */
295 cmPrcTmr(&schCb[schInst].schTimersInfo.tmrTqCp, schCb[schInst].schTimersInfo.tmrTq, (PFV) schTmrExpiry);
299 } /* end of schActvTmr */
301 /**********************************************************************
304 **********************************************************************/