Adding new commiter to ODU-High repo
[o-du/l2.git] / src / du_app / du_tmr.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 #include "common_def.h"
20 #include "lkw.h"
21 #include "lkw.x"
22 #include "lrg.h"
23 #include "lrg.x"
24 #include "du_tmr.h"
25 #include "du_app_rlc_inf.h"
26 #include "du_app_mac_inf.h"
27 #include "du_cfg.h"
28 #include "du_e2ap_mgr.h"
29 #include "du_mgr.h"
30 #include "du_e2ap_msg_hdl.h"
31
32 /**
33  * @brief Handler to check if the timer is running
34  *
35  * @param[in] cb        Control block depending on the type of the timer event.
36  *                      It can be uplink/downlink rbCb or rgu sap control block
37  * @param[in] tmrEvnt   Timer event to be started
38  *
39  * @return  Bool indicating whether the timer is running or not
40  *      -# ROK
41  *      -# RFAILED
42 */
43
44 bool duChkTmr(PTR cb, int16_t tmrEvnt)
45 {
46    switch (tmrEvnt)
47    {
48       case EVENT_E2_SETUP_TMR:
49       {
50          if(((CmTimer *)cb)->tmrEvnt == EVENT_E2_SETUP_TMR)
51          {
52              DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
53              return TRUE;
54          }
55          break;
56       }
57       case EVENT_RIC_SERVICE_UPDATE_TMR:
58       {
59          if(((RicServiceUpdateTimer*)cb)->timer.tmrEvnt == EVENT_RIC_SERVICE_UPDATE_TMR)
60          {
61             DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Timer already running for event [%d]", tmrEvnt);
62             return TRUE;
63          }
64          break;
65       }      
66       case EVENT_E2_NODE_CONFIG_UPDATE_TMR:
67       {
68          if(((E2NodeConfigUpdateTimer *)cb)->timer.tmrEvnt == EVENT_E2_NODE_CONFIG_UPDATE_TMR)
69          {
70              DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
71              return TRUE;
72          }
73          break;
74       }
75       case EVENT_RIC_SUBSCRIPTION_REPORTING_TMR:
76       {
77          if(((RicSubscription *)cb)->ricSubsReportTimer.tmrEvnt == EVENT_RIC_SUBSCRIPTION_REPORTING_TMR)
78          {
79              DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Timer already running for event [%d]", tmrEvnt);
80              return TRUE;
81          }
82          break;
83       }
84       default:
85       {
86          DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
87       }
88    }
89
90    return FALSE;
91 }
92
93 /**
94  * @brief Handler to start timer
95  *
96  * @param[in] cb        Control block depending on the type of the timer event.
97  *                      It can be uplink/downlink rbCb or rgu sap control block
98  * @param[in] tmrEvnt   Timer event to be started
99  *
100  * @return  Void
101 */
102
103 void duStartTmr(PTR cb, int16_t tmrEvnt, uint32_t timerValue)
104 {
105    CmTmrArg arg;
106    arg.wait = 0;
107    
108    switch (tmrEvnt)
109    {
110       case EVENT_E2_SETUP_TMR:
111       {
112          CmTimer *e2SetupTimer = NULLP;
113          e2SetupTimer = ((CmTimer *)cb);
114          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
115
116          arg.timers = e2SetupTimer;
117          arg.max = MAX_E2_SETUP_TMR;
118          break;
119       }
120       case EVENT_RIC_SERVICE_UPDATE_TMR:
121       {
122          RicServiceUpdateTimer *ricServiceUpdateTimer = NULLP;
123          ricServiceUpdateTimer= ((RicServiceUpdateTimer*)cb);
124          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
125
126          arg.timers = &ricServiceUpdateTimer->timer;
127          arg.max = MAX_RIC_SERVICE_UPDATE_TMR;
128          break;
129       }
130       case EVENT_E2_NODE_CONFIG_UPDATE_TMR:
131       {
132          E2NodeConfigUpdateTimer *cfgUpdateTimer;
133          cfgUpdateTimer = ((E2NodeConfigUpdateTimer*)cb);
134          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
135
136          arg.timers = &cfgUpdateTimer->timer;
137          arg.max = MAX_E2_NODE_CONFIG_UPDATE_TMR;
138          break;
139       }
140       case EVENT_RIC_SUBSCRIPTION_REPORTING_TMR:
141       {
142          RicSubscription *ricSubscription = NULLP;
143          ricSubscription = ((RicSubscription*)cb);
144          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
145
146          arg.timers = &ricSubscription->ricSubsReportTimer;
147          arg.max = MAX_RIC_SUBSCRIPTION_REPORTING_TMR;
148          break;
149       }
150       default:
151       {
152          DU_LOG("\nERROR  -->  DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
153          return;
154       }
155    }
156
157    if(arg.wait != 0)
158    {
159       arg.tqCp   = &(duCb.duTimersInfo.tmrTqCp);
160       arg.tq     = duCb.duTimersInfo.tmrTq;
161       arg.cb     = cb;
162       arg.evnt   = tmrEvnt;
163       arg.tNum   = 0;
164
165       cmPlcCbTq(&arg);
166    }
167    return;
168 }
169
170 /**
171  * @brief Handler to invoke events on expiry of timer.
172  *
173  * @details
174  *    This function is used to handle expiry of timer,it invokes relevant
175  *    functions.
176  *
177  * @param[in] cb        Control block depending on the type of the timer event.
178  *                      It can be uplink/downlink rbCb or rgu sap control block
179  * @param[in] tmrEvnt   Timer event to be started
180  *
181  * @return  Void
182 */
183
184 void duTmrExpiry(PTR cb,int16_t tmrEvnt)
185 {
186    switch (tmrEvnt)
187    {
188       case EVENT_E2_SETUP_TMR:
189       {
190          BuildAndSendE2SetupReq();
191          break;
192       }
193       case EVENT_RIC_SERVICE_UPDATE_TMR:
194       {
195          RicServiceUpdateTimer *ricServiceUpdateTimer;
196          
197          ricServiceUpdateTimer= ((RicServiceUpdateTimer*)cb);
198          BuildAndSendRicServiceUpdate(ricServiceUpdateTimer->ricService);
199          break;
200       }
201       case EVENT_E2_NODE_CONFIG_UPDATE_TMR:
202       {
203          E2NodeConfigUpdateTimer *cfgUpdateTimer;
204          
205          cfgUpdateTimer = ((E2NodeConfigUpdateTimer*)cb);
206          BuildAndSendE2NodeConfigUpdate(&cfgUpdateTimer->configList);
207          break;
208       }
209       case EVENT_RIC_SUBSCRIPTION_REPORTING_TMR:
210       {
211          RicSubscription *ricSubscription = NULLP;
212
213          ricSubscription = ((RicSubscription *)cb);
214          E2apHdlRicSubsReportTmrExp(ricSubscription);
215          break;
216       }
217       default:
218       {
219          DU_LOG("\nERROR  -->  DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
220          break;
221       }
222    }
223
224    return;
225 }
226
227 /**
228  * @brief Handler to stop timer
229  *
230  * @param[in] cb        Control block depending on the type of the timer event.
231  * @param[in] tmrEvnt   Timer event to be stopped
232  *
233  * @return  Void
234 */
235
236 void duStopTmr(PTR cb, uint8_t tmrType)
237 {
238    CmTmrArg   arg;
239    arg.timers = NULLP;
240
241    switch (tmrType)
242    {
243       case EVENT_E2_SETUP_TMR:
244       {
245          CmTimer *e2SetupTimer = NULLP;
246          
247          e2SetupTimer = ((CmTimer *)cb);
248          arg.timers = e2SetupTimer;
249          arg.max = MAX_E2_SETUP_TMR;
250          break;
251       }
252       case EVENT_RIC_SERVICE_UPDATE_TMR:
253       {
254          RicServiceUpdateTimer *ricServiceUpdateTimer = NULLP;
255          
256          ricServiceUpdateTimer= ((RicServiceUpdateTimer*)cb);
257          arg.timers = &ricServiceUpdateTimer->timer;
258          arg.max = MAX_RIC_SERVICE_UPDATE_TMR;
259          break;
260       }
261       case EVENT_E2_NODE_CONFIG_UPDATE_TMR:
262       {
263          E2NodeConfigUpdateTimer *cfgUpdateTimer;
264          
265          cfgUpdateTimer = ((E2NodeConfigUpdateTimer*)cb);
266          arg.timers = &cfgUpdateTimer->timer;
267          arg.max = MAX_E2_NODE_CONFIG_UPDATE_TMR;
268          break;
269       }
270       case EVENT_RIC_SUBSCRIPTION_REPORTING_TMR:
271       {
272          RicSubscription *ricSubscription = NULLP;
273          
274          ricSubscription = ((RicSubscription*)cb);
275          arg.timers = &ricSubscription->ricSubsReportTimer;
276          arg.max = MAX_RIC_SUBSCRIPTION_REPORTING_TMR;
277          break;
278       }
279       default:
280       {
281          DU_LOG("\nERROR  -->  RLC : rlcStopTmr: Invalid tmr Evnt[%d]", tmrType);
282          break;
283       }
284    }
285
286    if (tmrType != TMR0)
287    {
288       arg.tqCp   = &(duCb.duTimersInfo.tmrTqCp);
289       arg.tq     = duCb.duTimersInfo.tmrTq;
290       arg.cb     = cb;
291       arg.evnt   = tmrType;
292       arg.wait   = 0;
293       arg.tNum   = 0;
294       cmRmvCbTq(&arg);
295    }
296
297    return;
298 }
299
300 /**
301  * @brief DU instance timer call back function registered with system services.
302  *
303  * @details
304  *
305  *     Function :  duActvTmr
306  *
307  *     This function is invoked for every timer activation
308  *     period expiry. Note that SS_MT_TMR flag needs to be enabled for this
309  *     as isntId is needed.As part of SRegTmr call for du instance
310  *     SS_MT_TMR flag needs to be enabled and duActvTmr needs to be given as
311  *     callback function
312  *
313  *  @return  short int
314  *      -# ROK
315  **/
316
317 short int duActvTmr(Ent ent,Inst inst)
318 {
319    /* Check if any timer in the du instance has expired */
320    cmPrcTmr(&(duCb.duTimersInfo.tmrTqCp), duCb.duTimersInfo.tmrTq, (PFV) duTmrExpiry);
321
322    return ROK;
323
324 } /* end of duActvTmr */
325
326 /**********************************************************************
327
328          End of file
329 **********************************************************************/
330