Moving all common header file into common_def.h file
[o-du/l2.git] / src / 5gnrsch / rg_sch_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 /************************************************************************
20  
21      Name:     LTE-MAC layer
22   
23      Type:     C source file
24   
25      Desc:     C source code for Entry point fucntions
26   
27      File:     rg_sch_tmr.c 
28   
29 **********************************************************************/
30
31 /** @file rg_sch_tmr.c 
32 @brief This module does processing related to timers for the scheduler.
33 */
34 static const char* RLOG_MODULE_NAME="MAC";
35 static int RLOG_MODULE_ID=4096;
36 static int RLOG_FILE_ID=175;
37
38 /* header include files -- defines (.h) */
39 #include "common_def.h"
40 #include "tfu.h"           /* RGU defines */
41 #include "lrg.h"           /* layer management defines for LTE-MAC */
42 #include "rgr.h"           /* layer management defines for LTE-MAC */
43 #include "rg_env.h"            /* defines and macros for MAC */
44 #include "rg_sch_err.h"            /* defines and macros for MAC */
45 #include "rg_sch_inf.h"            /* defines and macros for MAC */
46 #include "rg_sch.h"            /* defines and macros for MAC */
47 #include "rl_interface.h"
48 #include "rl_common.h"
49
50
51 /* header/extern include files (.x) */
52 #include "tfu.x"           /* RGU types */
53 #include "lrg.x"           /* layer management typedefs for MAC */
54 #include "rgr.x"           /* layer management typedefs for MAC */
55 #include "rg_sch_inf.x"            /* typedefs for MAC */
56 #include "rg_sch.x"            /* typedefs for MAC */
57
58 #ifdef LTE_ADV
59 EXTERN PUBLIC Void rgSCHSCellActivation ARGS((
60 RgSchUeCellInfo  *sCell
61 ));
62 #endif
63  /** @brief This function is a utility function to start timers, it is a
64   * generic function.
65   *
66   * @details
67   *
68   *     Function: rgSCHTmrStartTmr 
69   *
70   *         Processing steps:
71   *         - Starts timer at scheduler
72   *         
73   *   @param[in]  RgSchCellCb    *cell
74   *   @param[in]  Ptr            cb
75   *   @param[in]  S16            tmrEvnt
76   *   @param[in]  U32            tmrVal
77   *   @return  Void
78   */
79 #ifdef ANSI
80 PUBLIC Void rgSCHTmrStartTmr
81 (
82 RgSchCellCb *cell,
83 Ptr         cb,
84 S16         tmrEvnt,
85 U32         tmrVal
86 )
87 #else
88 PUBLIC Void rgSCHTmrStartTmr (cell, cb, tmrEvnt, tmrVal)
89 RgSchCellCb *cell;
90 Ptr         cb;
91 S16         tmrEvnt;
92 U32         tmrVal;
93 #endif
94 {
95    CmTmrArg          arg;
96    RgSchUeCb         *ue;
97 #ifdef LTE_ADV
98    RgSchUeCellInfo *sCellCb = NULLP;
99 #endif
100
101    TRC2(rgSCHTmrStartTmr);
102
103
104 #ifndef LTE_ADV
105    ue = (RgSchUeCb*)cb;
106 #else
107    if(tmrEvnt == RG_SCH_TMR_SCELL_DEACT)
108    {
109       sCellCb = (RgSchUeCellInfo *)cb;
110    }
111    else
112    {
113       ue = (RgSchUeCb*)cb;
114    }
115 #endif
116
117    switch (tmrEvnt)
118    {
119       case RG_SCH_TMR_ACKNACK_REP:
120          arg.timers = &(ue->ackNakRepCb.ackNakRepTmr);
121          RLOG_ARG0(L_ERROR,DBG_INSTID,cell->instIdx, 
122             "Hit AckNackRep timer");
123          break;
124       case RG_SCH_TMR_MEASGAP:
125          arg.timers = &(ue->measGapCb.measGapTmr);
126          break;
127       case RG_SCH_TMR_UL_ACKNACK:
128          arg.timers = &(ue->ackNakRepCb.ackNakRepUlInactvTmr);
129          break;
130       case RG_SCH_TMR_DL_ACKNACK:
131          arg.timers = &(ue->ackNakRepCb.ackNakRepDlInactvTmr);
132          break;
133       case RG_SCH_TMR_UL_MEASGAP:
134          arg.timers = &(ue->measGapCb.measGapUlInactvTmr);
135          break;
136       case RG_SCH_TMR_DL_MEASGAP:
137          arg.timers = &(ue->measGapCb.measGapDlInactvTmr);
138          break;
139       case RG_SCH_TMR_TA:
140          arg.timers = &(ue->taTmr);
141          break;
142         /*MS_WORKAROUND for CR FIXME */
143 #ifndef RGR_V1
144       case RG_SCH_TMR_BSR:
145          {
146             arg.timers = &(ue->bsrTmr);
147             break;
148          }
149 #else
150       case RG_SCH_TMR_BSR:
151          {
152 #ifdef NO_BSR_SR_5GTF
153             RETVOID;
154 #endif
155             arg.timers = &(ue->bsrTmr);
156             break;
157          }
158 #endif
159       case RG_SCH_TMR_TXMODE_TRNSTN:
160          {
161             arg.timers = &(ue->txModeTransTmr);
162             break;
163          }
164 #ifdef LTE_ADV
165       case RG_SCH_TMR_SCELL_DEACT:
166          {
167             arg.timers = &(sCellCb->deactTmr);
168             break;
169          }
170       case RG_SCH_TMR_SCELL_ACT_DELAY:
171          {
172             sCellCb = (RgSchUeCellInfo *)cb;
173             arg.timers = &(sCellCb->actDelayTmr);
174             break;
175          }
176 #endif
177       default:
178          RLOG_ARG0(L_ERROR,DBG_INSTID,cell->instIdx,  
179             "rgSCHTmrStartTmr() Incorrect Timer event");
180          RETVOID;
181    }
182
183    arg.tqCp = &(cell->tqCp);
184    arg.tq   = cell->tq;
185    arg.cb   = (PTR)cb;
186    arg.evnt = tmrEvnt;
187    arg.wait = tmrVal;
188    arg.max  = 1;
189    arg.tNum = NOTUSED;
190    cmPlcCbTq(&arg);
191    RETVOID;
192
193 } /* end of */ 
194
195  /** @brief This function stops the timer.
196   *
197   * @details
198   *
199   *     Function: rgSCHTmrStopTmr 
200   *
201   *         Processing steps:
202   *         - Stops timer at scheduler. 
203   *
204   *   @param[in]  RgSchCellCb    *cell
205   *   @param[in]  S16            tmrEvnt
206   *   @param[in]  Ptr            cb
207   *   @return  Void
208   */
209 #ifdef ANSI
210 PUBLIC Void rgSCHTmrStopTmr
211 (
212 RgSchCellCb   *cell,
213 S16           tmrEvnt,
214 Ptr           cb
215 )
216 #else
217 PUBLIC Void rgSCHTmrStopTmr (cell, tmrEvnt, cb)
218 RgSchCellCb   *cell;
219 S16           tmrEvnt;
220 Ptr           cb;
221 #endif
222 {
223    CmTmrArg          arg;
224    RgSchUeCb         *ue;
225 #ifdef LTE_ADV
226    RgSchUeCellInfo *sCellCb = NULLP;
227 #endif
228
229    TRC2(rgSCHTmrStopTmr);
230
231
232 #ifndef LTE_ADV
233    ue = (RgSchUeCb*)cb;
234 #else
235    if(tmrEvnt == RG_SCH_TMR_SCELL_DEACT)
236    {
237       sCellCb = (RgSchUeCellInfo *)cb;
238    }
239    else
240    {
241       ue = (RgSchUeCb*)cb;
242    }
243 #endif
244
245    switch (tmrEvnt)
246    {
247       case RG_SCH_TMR_ACKNACK_REP:
248          arg.timers = &(ue->ackNakRepCb.ackNakRepTmr);
249          break;
250       case RG_SCH_TMR_MEASGAP:
251          arg.timers = &(ue->measGapCb.measGapTmr);
252          break;
253       case RG_SCH_TMR_UL_ACKNACK:
254          arg.timers = &(ue->ackNakRepCb.ackNakRepUlInactvTmr);
255          break;
256       case RG_SCH_TMR_DL_ACKNACK:
257          arg.timers = &(ue->ackNakRepCb.ackNakRepDlInactvTmr);
258          break;
259       case RG_SCH_TMR_UL_MEASGAP:
260          arg.timers = &(ue->measGapCb.measGapUlInactvTmr);
261          break;
262       case RG_SCH_TMR_DL_MEASGAP:
263          arg.timers = &(ue->measGapCb.measGapDlInactvTmr);
264          break;
265       case RG_SCH_TMR_TA:
266          arg.timers = &(ue->taTmr);
267          break;
268                 /*MS_WORKAROUND for CR FIXME */
269 #ifndef RGR_V1
270       case RG_SCH_TMR_BSR:
271
272          {
273             arg.timers = &(ue->bsrTmr);
274             break;
275          }
276 #else
277       case RG_SCH_TMR_BSR:
278          {
279 #ifdef NO_BSR_SR_5GTF
280             RETVOID;
281 #endif
282             arg.timers = &(ue->bsrTmr);
283             break;
284          }
285
286 #endif
287       case RG_SCH_TMR_TXMODE_TRNSTN:
288          {
289             arg.timers = &(ue->txModeTransTmr);
290             break;
291          }
292 #ifdef LTE_ADV
293       case RG_SCH_TMR_SCELL_DEACT:
294          {
295             arg.timers = &(sCellCb->deactTmr);
296             break;
297          }
298       case RG_SCH_TMR_SCELL_ACT_DELAY:
299          {
300             sCellCb = (RgSchUeCellInfo *)cb;
301             arg.timers = &(sCellCb->actDelayTmr);
302             break;
303          }
304 #endif
305
306       default:
307          RLOG_ARG0(L_ERROR,DBG_INSTID,cell->instIdx,  
308             "rgSCHTmrStopTmr() Incorrect Timer event");
309          RETVOID;
310    }
311
312    arg.tqCp = &(cell->tqCp);
313    arg.tq   = cell->tq;
314    arg.cb   = (PTR)cb;
315    arg.evnt = tmrEvnt;
316    arg.wait = NOTUSED;
317    arg.max  = 0;
318    arg.tNum = NOTUSED;
319    cmRmvCbTq(&arg);
320    RETVOID;
321 } /* end of */ 
322
323  /** @brief This function handles timer expiry.
324   *
325   * @details
326   *
327   *     Function: rgSCHTmrProcTmr
328   *
329   *         Processing steps:
330   *         - Handles processing on timer expiry at scheduler.
331   *
332   *   @param[in]  Ptr            cb
333   *   @param[in]  S16            tmrEvnt
334   *   @return  Void
335   */
336 #ifdef ANSI
337 PUBLIC Void rgSCHTmrProcTmr 
338 (
339 Ptr         cb,
340 S16         tmrEvnt
341 )
342 #else
343 PUBLIC Void rgSCHTmrProcTmr (cb, tmrEvnt)
344 Ptr         cb;
345 S16         tmrEvnt;
346 #endif
347 {
348    RgSchUeCb      *ue = NULLP;
349 #ifdef LTE_ADV
350    RgSchUeCellInfo *sCellCb = NULLP;
351 #endif
352
353    TRC2(rgSCHTmrProcTmr);
354
355 #ifndef LTE_ADV
356    ue = (RgSchUeCb*)cb;
357 #else
358    if(tmrEvnt == RG_SCH_TMR_SCELL_DEACT)
359    {
360       sCellCb = (RgSchUeCellInfo *)cb;
361    }
362    else
363    {
364       ue = (RgSchUeCb*)cb;
365    }
366 #endif
367
368
369    switch (tmrEvnt)
370    {
371       case RG_SCH_TMR_ACKNACK_REP:
372          rgSCHAckNakRepTmrExpry (ue);
373          break;
374       case RG_SCH_TMR_MEASGAP:
375          rgSCHMeasGapANRepTmrExpry (ue);
376          break;
377       case RG_SCH_TMR_UL_MEASGAP:
378       case RG_SCH_TMR_UL_ACKNACK:
379          rgSCHMeasGapANRepUlInactvTmrExpry (ue, (U8)tmrEvnt);
380          break;
381       case RG_SCH_TMR_DL_ACKNACK:
382       case RG_SCH_TMR_DL_MEASGAP:
383          rgSCHMeasGapANRepDlInactvTmrExpry (ue, (U8)tmrEvnt);
384          break;
385       case RG_SCH_TMR_TA:
386 #ifdef EMTC_ENABLE
387          /*TODO Needto handle TA Timer expiry for EMTC UE*/
388          if(TRUE == ue->isEmtcUe)
389          {
390             RLOG0(L_INFO,"TA Timer Expiry is not handled for EMTC UE\n");
391             break;
392          }
393 #endif
394          rgSCHDhmProcTAExp (ue);
395          break;
396                 /*MS_WORKAROUND for CR FIXME */
397 #ifndef RGR_V1
398       case RG_SCH_TMR_BSR:
399          {
400             rgSCHCmnBsrTmrExpry(ue);
401          }
402          break;
403 #else
404       case RG_SCH_TMR_BSR:
405          {
406             rgSCHCmnBsrTmrExpry(ue);
407          }
408          break;
409
410 #endif
411       case RG_SCH_TMR_TXMODE_TRNSTN:
412          {
413             ue->txModeTransCmplt = TRUE;
414             break;
415          }
416 #ifdef LTE_ADV
417       case RG_SCH_TMR_SCELL_DEACT:
418          {
419             rgSCHSCellDeactTmrExpry(sCellCb);
420             break;
421          }
422       case RG_SCH_TMR_SCELL_ACT_DELAY:
423          {
424             sCellCb = (RgSchUeCellInfo *)cb;
425             rgSCHSCellActivation(sCellCb);
426             break;
427          }
428 #endif
429       default:
430         if(ue)
431         {
432            RLOG_ARG0(L_ERROR,DBG_INSTID,ue->cell->instIdx,  
433                  "rgSCHTmrProcTmr() Incorrect Timer event");
434         }
435          RETVOID;
436    }
437    RETVOID;
438 } /* end of */ 
439
440 \f
441 /**********************************************************************
442  
443          End of file
444 **********************************************************************/