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