838dd3586dda02bb845f91f69d427cfc634941dd
[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       }
56       case EVENT_RIC_SERVICE_UPDATE_TMR:
57       {
58          if(((RicServiceUpdateTimer*)cb)->timer.tmrEvnt == EVENT_RIC_SERVICE_UPDATE_TMR)
59          {
60             DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Timer already running for event [%d]", tmrEvnt);
61             return TRUE;
62          }
63          break;
64       }      
65       default:
66       {
67          DU_LOG("\nERROR  -->  DU_APP : duChkTmr: Invalid tmr Evnt [%d]", tmrEvnt);
68       }
69    }
70
71    return FALSE;
72 }
73
74 /**
75  * @brief Handler to start timer
76  *
77  * @param[in] cb        Control block depending on the type of the timer event.
78  *                      It can be uplink/downlink rbCb or rgu sap control block
79  * @param[in] tmrEvnt   Timer event to be started
80  *
81  * @return  Void
82 */
83
84 void duStartTmr(PTR cb, int16_t tmrEvnt, uint8_t timerValue)
85 {
86    CmTmrArg arg;
87    arg.wait = 0;
88    
89    switch (tmrEvnt)
90    {
91       case EVENT_E2_SETUP_TMR:
92       {
93          CmTimer *e2SetupTimer;
94          e2SetupTimer = ((CmTimer *)cb);
95          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
96
97          arg.timers = e2SetupTimer;
98          arg.max = MAX_E2_SETUP_TMR;
99          break;
100       }
101       case EVENT_RIC_SERVICE_UPDATE_TMR:
102       {
103          RicServiceUpdateTimer *ricServiceUpdateTimer;
104          ricServiceUpdateTimer= ((RicServiceUpdateTimer*)cb);
105          TMR_CALCUATE_WAIT(arg.wait, timerValue, duCb.duTimersInfo.tmrRes);
106
107          arg.timers = &ricServiceUpdateTimer->timer;
108          arg.max = MAX_RIC_SERVICE_UPDATE_TMR;
109          break;
110       }
111       default:
112       {
113          DU_LOG("\nERROR  -->  DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
114       }
115    }
116
117    if(arg.wait != 0)
118    {
119       arg.tqCp   = &(duCb.duTimersInfo.tmrTqCp);
120       arg.tq     = duCb.duTimersInfo.tmrTq;
121       arg.cb     = cb;
122       arg.evnt   = tmrEvnt;
123       arg.tNum   = 0;
124
125       cmPlcCbTq(&arg);
126    }
127    return;
128 }
129
130 /**
131  * @brief Handler to invoke events on expiry of timer.
132  *
133  * @details
134  *    This function is used to handle expiry of timer,it invokes relevant
135  *    functions.
136  *
137  * @param[in] cb        Control block depending on the type of the timer event.
138  *                      It can be uplink/downlink rbCb or rgu sap control block
139  * @param[in] tmrEvnt   Timer event to be started
140  *
141  * @return  Void
142 */
143
144 void duTmrExpiry(PTR cb,int16_t tmrEvnt)
145 {
146    switch (tmrEvnt)
147    {
148       case EVENT_E2_SETUP_TMR:
149       {
150          BuildAndSendE2SetupReq();
151          break;
152       }
153       case EVENT_RIC_SERVICE_UPDATE_TMR:
154       {
155          RicServiceUpdateTimer *ricServiceUpdateTimer;
156          
157          ricServiceUpdateTimer= ((RicServiceUpdateTimer*)cb);
158          BuildAndSendRicServiceUpdate(ricServiceUpdateTimer->ricService);
159          break;
160       }
161       default:
162       {
163          DU_LOG("\nERROR  -->  DU : duStartTmr: Invalid tmr Evnt [%d]", tmrEvnt);
164          break;
165       }
166    }
167
168    return;
169 }
170
171 /**
172  * @brief DU instance timer call back function registered with system services.
173  *
174  * @details
175  *
176  *     Function :  duActvTmr
177  *
178  *     This function is invoked for every timer activation
179  *     period expiry. Note that SS_MT_TMR flag needs to be enabled for this
180  *     as isntId is needed.As part of SRegTmr call for du instance
181  *     SS_MT_TMR flag needs to be enabled and duActvTmr needs to be given as
182  *     callback function
183  *
184  *  @return  short int
185  *      -# ROK
186  **/
187
188 short int duActvTmr(Ent ent,Inst inst)
189 {
190    /* Check if any timer in the du instance has expired */
191    cmPrcTmr(&(duCb.duTimersInfo.tmrTqCp), duCb.duTimersInfo.tmrTq, (PFV) duTmrExpiry);
192
193    return ROK;
194
195 } /* end of duActvTmr */
196
197 /**********************************************************************
198
199          End of file
200 **********************************************************************/
201