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_STATISTICS_TMR:
42 if(((SchStatsGrp *)cb)->periodTimer.tmrEvnt == EVENT_STATISTICS_TMR)
44 DU_LOG("\nDEBUG --> SCH : schChkTmr: Timer Evnt [%d] already running", tmrEvnt);
51 DU_LOG("\nERROR --> SCH : schChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
58 * @brief Handler to start timer
60 * @param[in] cb Control block depending on the type of the timer event.
61 * @param[in] tmrEvnt Timer event to be started
65 void schStartTmr(SchCb *gCb, PTR cb, int16_t tmrEvnt, uint16_t timerValue)
67 SchStatsGrp *statsGrp = NULLP;
73 DU_LOG("\nDEBUG --> SCH : Starting Timer Event [%d] with Wait Time [%d] ms", \
79 case EVENT_STATISTICS_TMR:
81 statsGrp = ((SchStatsGrp *)cb);
82 TMR_CALCUATE_WAIT(arg.wait, timerValue, gCb->schTimersInfo.tmrRes);
84 arg.timers = &statsGrp->periodTimer;
85 arg.max = MAX_NUM_TMR_PER_STATS_GRP;
91 DU_LOG("\nERROR --> SCH : schStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
97 arg.tqCp = &(gCb->schTimersInfo.tmrTqCp);
98 arg.tq = gCb->schTimersInfo.tmrTq;
110 * @brief Handler to stop a timer
112 * @param[in] cb Control block depending on the type of the timer event.
113 * @param[in] tmrType Timer event to be started
117 void schStopTmr(SchCb *gCb, PTR cb, uint8_t tmrType)
124 DU_LOG("\nDEBUG --> SCH : Stopping Timer Event [%d]", tmrType);
129 case EVENT_STATISTICS_TMR:
131 arg.timers = &((SchStatsGrp *)cb)->periodTimer;
132 arg.max = MAX_NUM_TMR_PER_STATS_GRP;
138 DU_LOG("\nERROR --> SCH : schStopTmr: Invalid tmr Evnt[%d]", tmrType);
145 arg.tqCp = &gCb->schTimersInfo.tmrTqCp;
146 arg.tq = gCb->schTimersInfo.tmrTq;
158 * @brief Handler for Statistics group timer expiry
162 * Function : SchProcStatisticsGrpTmrExp
164 * This function calculates and sends statistics of
165 * the stats-group for which timer expired.
166 * Once Statistics Indication is sent, timer for this
167 * group is restarted.
169 * @param[in] Statistics group control block
173 uint8_t SchProcStatisticsGrpTmrExp(SchStatsGrp *cb)
175 if(schCalcAndSendGrpStats(cb) != ROK)
177 DU_LOG("\nERROR --> SCH : SchProcStatisticsGrpTmrExp: Fails to send group statistics");
179 schStartTmr(&schCb[cb->schInst], (PTR)(cb), EVENT_STATISTICS_TMR, cb->periodicity);
184 * @brief Timer Expiry handler.
188 * Function : schTmrExpiry
190 * This is a callback function used as an input parameter to cmPrcTmr()
191 * to check expiry of any timer. In this function, we are only concerned
192 * about tmrEvnt=Bind timer.
194 * @param[in] PTR cb, Entry for which Timer expired
195 * @param[in] uint8_t tmrEvnt, the Timer Event
199 uint8_t schTmrExpiry(PTR cb, uint8_t tmrEvnt)
202 DU_LOG("\nDEBUG --> SCH : Timer Expired. Event [%d]", tmrEvnt);
207 case EVENT_STATISTICS_TMR:
210 DU_LOG("\nDEBUG --> SCH : Statistics Timer Expired for Subscription Id [%ld] GroupId [%d]", \
211 ((SchStatsGrp*)cb)->subscriptionId, ((SchStatsGrp*)cb)->groupId);
213 SchProcStatisticsGrpTmrExp((SchStatsGrp*)cb);
219 DU_LOG("\nERROR --> DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
227 * @brief Scheduler instance timer call back function registered with system services.
231 * Function : schActvTmr
233 * This function is invoked for every timer activation
234 * period expiry. Note that SS_MT_TMR flag needs to be enabled for this
235 * as isntId is needed.As part of SRegTmr call for scheduler instance
236 * SS_MT_TMR flag needs to be enabled and schActvTmr needs to be given as
242 short int schActvTmr(Ent ent,Inst inst)
244 Inst schInst = (inst - SCH_INST_START);
246 /* Check if any timer in the scheduler instance has expired */
247 cmPrcTmr(&schCb[schInst].schTimersInfo.tmrTqCp, schCb[schInst].schTimersInfo.tmrTq, (PFV) schTmrExpiry);
251 } /* end of schActvTmr */
253 /**********************************************************************
256 **********************************************************************/