Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / cm / cm_bdy5.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**
20
21      Name:     common functions - 5
22
23      Type:     C source file
24
25      Desc:     C source code for common timer routines;
26
27      File:     cm_bdy5.c
28
29 *********************************************************************21*/
30
31 \f
32 /* header include files -- defines (.h) */
33
34 #include "envopt.h"        /* environment options */
35 #include "envdep.h"        /* environment dependent */
36 #include "envind.h"        /* environment independent */
37
38 #include "gen.h"           /* general */
39 #include "ssi.h"           /* system services */
40 #include "cm5.h"           /* common functions */
41
42 /* header/extern include files (.x) */
43
44 #include "gen.x"           /* general */
45 #include "ssi.x"           /* system services */
46 #include "cm5.x"           /* common functions */
47
48 \f
49 /* local defines */
50
51 #define CM_RMV_TQCP(tqEnt, tgt)                            \
52 {                                                          \
53    ((tgt)->prev) ? ((tgt)->prev->next = (tgt)->next):      \
54                   ((tqEnt)->first = (tgt)->next);          \
55    ((tgt)->next) ? ((tgt)->next->prev = (tgt)->prev):      \
56                   ((tqEnt)->tail = (tgt)->prev);           \
57    (tgt)->prev = NULLP;                                    \
58    (tgt)->next = NULLP;                                    \
59    (tgt)->ent2bUpd = FALSE;                                \
60 }
61  
62 #define CM_PLC_TQCP(tqEnt, tgt)                            \
63 {                                                          \
64    if ((tqEnt)->tail)                                      \
65    {                                                       \
66       (tqEnt)->tail->next = tgt;                           \
67       (tgt)->prev = (tqEnt)->tail;                         \
68       (tqEnt)->tail = tgt;                                 \
69    }                                                       \
70    else                                                    \
71    {                                                       \
72       (tqEnt)->first = (tqEnt)->tail = tgt;                \
73    }                                                       \
74 }
75
76 /* local externs */
77
78 /* forward references */
79
80 /* functions in other modules */
81
82 \f
83 /*
84 *
85 *       Fun:   cmPrcTmr
86 *
87 *       Desc:  Handle a timer entry
88 *
89 *       Ret:   RETVOID
90 *
91 *       Notes: 
92 *
93 *       File:  cm_bdy5.c
94 *
95 */
96  
97 #ifdef SS_FAP
98 #ifdef ANSI
99 PUBLIC Void cmPrcTmr
100 (
101 CmTqCp   *tqCp,          /* timing que control point */
102 CmTqType *tq,            /* timing queue */
103 PFV      func            /* function */
104 )
105 #else
106 PUBLIC Void cmPrcTmr(tqCp, tq, func)
107 CmTqCp   *tqCp;          /* connection control block */
108 CmTqType *tq;            /* message buffer */
109 PFV      func;           /* function */
110 #endif
111 {
112 /**/
113    U32 expire;
114    U32 entry;
115    S16 event;
116    PTR cb;
117    CmTimer *tmp1;
118    CmTimer **tmp2;
119  
120    TRC2(cmPrcTmr)
121
122 #ifdef CMDBG
123 {
124    DateTime dt;
125    Txt prntBuf[PRNTSZE];
126
127    SGetDateTime(&dt);
128    /* Here the year was being printed as 2 letter value and hence did
129     * not represent accurate information.  It has been modified as
130     * recommended to include the offset of year 1900 used in all Trillium
131     * SSI implementations. Patch cmbdy5c_001.113
132     */
133    sprintf(prntBuf,"%s: date: %02d/%02d/%04d time: %02d:%02d:%02d\n",
134            msArgv[0],dt.month,dt.day,(int)(dt.year + 1900), dt.hour,
135            dt.min, dt.sec);
136    SPrint(prntBuf);
137 }
138 #endif
139
140    ++tqCp->nxtEnt;
141    expire = tqCp->nxtEnt;
142    /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
143    entry = (U32) (expire % (U32)(tqCp->tmrLen));
144
145    tmp2 = &tq[entry].first;
146    while ((tmp1 = *tmp2) != NULLP)
147    {
148       if (tmp1->tqExpire == expire)
149       {
150          event = tmp1->tmrEvnt;
151          cb = tmp1->cb;
152          /* remove and reset this timer control block */
153          (*tmp2) = tmp1->next;
154          tmp1->tmrEvnt = TMR_NONE;
155          tmp1->tqExpire = 0;
156          tmp1->cb = NULLP;
157          tmp1->next = NULLP;
158          func(cb, event);
159       }
160       else
161          tmp2 = &tmp1->next;
162    }
163    RETVOID;
164 } /* end of cmPrcTmr */
165
166 #else /* not defined SS_FAP */
167
168 #ifdef ANSI
169 PUBLIC Void cmPrcTmr
170 (
171 CmTqCp   *tqCp,          /* timing que control point */
172 CmTqType *tq,            /* timing queue */
173 PFV      func            /* function */
174 )
175 #else
176 PUBLIC Void cmPrcTmr(tqCp, tq, func)
177 CmTqCp   *tqCp;          /* connection control block */
178 CmTqType *tq;            /* message buffer */
179 PFV      func;           /* function */
180 #endif
181 {
182 /**/
183    U32 expire;
184    U32 entry, entry1;
185    S16 event;
186    CmTqType *tqEnt, *tqEnt1; 
187    PTR cb;
188    CmTimer *tmp1;
189    VOLATILE U32     startTime = 0;
190    
191    TRC2(cmPrcTmr)
192  
193    /*starting Task*/
194    SStartTask(&startTime, PID_CM_PRC_TMR);
195
196 #ifdef CMDBG
197 {
198    DateTime dt;
199    Txt prntBuf[PRNTSZE];
200  
201    SGetDateTime(&dt);
202    /* Here the year was being printed as 2 letter value and hence did
203     * not represent accurate information.  It has been modified as
204     * recommended to include the offset of year 1900 used in all Trillium
205     * SSI implementations.
206     */
207    sprintf(prntBuf,"%s: date: %02d/%02d/%04d time: %02d:%02d:%02d\n",
208            msArgv[0],dt.month,dt.day,(int)(dt.year + 1900), dt.hour, 
209            dt.min, dt.sec);
210    SPrint(prntBuf);
211 }
212 #endif
213  
214    ++tqCp->nxtEnt;
215    expire = tqCp->nxtEnt;
216    entry = (U32) (expire % (U32)(tqCp->tmrLen));
217   
218    tqCp->tmp = (tqEnt = &tq[entry])->first;
219    while ((tmp1 = tqCp->tmp) != NULLP)
220    {
221       tqCp->tmp = tmp1->next;
222       /* SRIKY - Temp Fix to overcome timer not firing. Need to take */
223           /* care of wrap around case                                                    */
224       if ((tmp1->tqExpire <= expire) || (tmp1->ent2bUpd))
225       {
226          event = tmp1->tmrEvnt;
227          cb = tmp1->cb;
228  
229          if (!(tmp1->ent2bUpd))
230          {
231             CM_RMV_TQCP(tqEnt, tmp1);
232             tmp1->tmrEvnt = TMR_NONE; 
233             tmp1->tqExpire = 0;     
234             tmp1->cb = NULLP;      
235  
236             func(cb, event);
237          }
238          else
239          {
240             entry1 = (U32) (tmp1->tqExpire % (U32)(tqCp->tmrLen));
241             tqEnt1 = &tq[entry1];
242             CM_RMV_TQCP(tqEnt, tmp1);
243             tmp1->entIdx = entry1; 
244             CM_PLC_TQCP(tqEnt1, tmp1);
245          }
246       }
247    }
248
249    /*stoping Task*/
250    SStopTask(startTime, PID_CM_PRC_TMR);
251    RETVOID;
252 } /* end of cmPrcTmr */
253 #endif /* SS_FAP */
254
255
256 \f
257 /*
258 *
259 *       Fun:   cmInitTimers
260 *
261 *       Desc:  initialize timers
262 *
263 *       Ret:   RETVOID
264 *
265 *       Notes: Connection Oriented Control
266 *
267 *       File:  cm_bdy5.c
268 *
269 */
270 #ifdef ANSI
271 PUBLIC Void cmInitTimers
272 (
273 CmTimer *timers,     /* timer list */
274 U8 max               /* maximum tmrs */
275 )
276 #else
277 PUBLIC Void cmInitTimers(timers, max)
278 CmTimer *timers;     /* timer list */
279 U8 max;              /* maximum tmrs */
280 #endif
281 {
282    CmTimer *tPtr;
283    REG1 U8 i;
284
285    TRC2(cmInitTimers)
286
287    for (i = 0, tPtr = timers; i < max; i++, tPtr++)
288    {
289       tPtr->tmrEvnt = TMR_NONE;
290       tPtr->tqExpire = 0;
291       tPtr->cb = 0;
292       tPtr->next = (struct cmTimer *)NULLP;
293       tPtr->prev = (struct cmTimer *)NULLP;
294       tPtr->ent2bUpd = FALSE;
295    }
296    RETVOID;
297 } /* end of cmInitTimers */
298
299 /*
300 *
301 *       Fun:    cmPlcCbTq
302 *
303 *       Desc:   Places Control Block on Timing Queue
304 *
305 *       Ret:    RETVOID
306 *
307 *       Notes:  None
308 *
309 *       File:   cm_bdy5.c
310 *
311 */
312   
313 #ifdef ANSI
314 PUBLIC Void cmPlcCbTq
315 (
316 CmTmrArg *arg
317 )
318 #else
319 PUBLIC Void cmPlcCbTq(arg)
320 CmTmrArg *arg;
321 #endif
322 {
323 /*added FAP modifications*/
324 #ifdef SS_FAP
325    REG1 U8 tmrNum;
326    /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
327    U32 ent;
328    U32 expire;
329    CmTimer **tmp;
330
331    TRC2(cmPlcCbTq)
332
333    expire = (arg->tqCp->nxtEnt + arg->wait);
334    /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
335    ent = (U32)(expire % (U32)(arg->tqCp->tmrLen));
336
337    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
338    {
339       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
340       {
341          arg->timers[tmrNum].tmrEvnt = arg->evnt;
342          arg->timers[tmrNum].tqExpire = expire;
343          arg->timers[tmrNum].cb = arg->cb;
344          arg->timers[tmrNum].next = NULLP;
345
346          tmp = &(arg->tq[ent].first);
347          while (*tmp)
348             tmp = &((*tmp)->next);
349          *tmp = &arg->timers[tmrNum];
350
351          RETVOID;
352       }
353    }
354    RETVOID;
355 #else
356    REG1 U8 tmrNum;
357    U32 ent;
358    CmTqType *tq;
359    CmTimer  *target;
360    U32 expire;
361    TRC2(cmPlcCbTq)
362  
363    expire = (arg->tqCp->nxtEnt + arg->wait);
364    ent = (U32)(expire % (U32)(arg->tqCp->tmrLen));
365  
366    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
367    {
368       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
369       {
370          target = &arg->timers[tmrNum];
371          tq = &arg->tq[ent]; 
372  
373          target->tmrEvnt = arg->evnt;
374          target->tqExpire = expire;
375          target->cb = arg->cb;
376          target->ent2bUpd = FALSE;
377          target->entIdx   = ent;
378
379          /* Place the timer block in the timer list */
380          CM_PLC_TQCP(tq, target); 
381  
382          RETVOID;
383       }
384    }
385    RETVOID;
386 #endif
387 } /* end of cmPlcCbTq */
388  
389 /*
390 *
391 *       Fun:    cmRstCbTq
392 *
393 *       Desc:   Places Control Block on Timing Queue
394 *
395 *       Ret:    RETVOID
396 *
397 *       Notes:  None
398 *
399 *       File:   cm_bdy5.c
400 *
401 */
402   
403 #ifdef ANSI
404 PUBLIC Void cmRstCbTq
405 (
406 CmTmrArg *arg
407 )
408 #else
409 PUBLIC Void cmRstCbTq(arg)
410 CmTmrArg *arg;
411 #endif
412 {
413    TRC2(cmRstCbTq)
414  
415    arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
416    arg->timers[arg->tNum].ent2bUpd = TRUE; 
417  
418    RETVOID;
419 } /* end of cmRstCbTq */
420
421 /*
422 *
423 *       Fun:    cmRmvCbTq
424 *
425 *       Desc:   Removes control block from Timing Queue
426 *
427 *       Ret:    RETVOID
428 *
429 *       Notes:  None
430 *
431 *       File:   cm_bdy5.c
432 *
433 */
434   
435 #ifdef ANSI
436 PUBLIC Void cmRmvCbTq
437 (
438 CmTmrArg *arg
439 )
440 #else
441 PUBLIC Void cmRmvCbTq(arg)
442 CmTmrArg *arg;
443 #endif
444 {
445 /*Added FAP modifications*/
446 #ifdef SS_FAP
447 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
448    U32 ent;
449    CmTimer *target;
450    CmTimer *tmp1;
451    CmTimer **tmp2;
452
453    TRC2(cmRmvCbTq)
454
455    target = &arg->timers[arg->tNum];
456    if (target->tmrEvnt != TMR_NONE)
457    {
458       /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
459       ent = (U32) (target->tqExpire % (U32)(arg->tqCp->tmrLen));
460       tmp2 = &arg->tq[ent].first;
461
462       while ((tmp1 = *tmp2) != NULLP)
463       {
464          if (tmp1 == target)
465          {
466             /* find the timer control block to be removed */
467             (*tmp2) = tmp1->next;
468             tmp1->tmrEvnt = TMR_NONE;
469             tmp1->tqExpire = 0;
470             tmp1->cb = NULLP;
471             tmp1->next = NULLP;
472             break;
473          }
474          else
475             /* find the next timer control block */
476             tmp2 = &tmp1->next;
477       }
478    }
479    RETVOID;
480 #else
481    U32 ent;
482    CmTimer  *target;
483    CmTqType *tq;
484    
485  
486    TRC2(cmRmvCbTq)
487  
488    target = &arg->timers[arg->tNum];
489    if (target->tmrEvnt != TMR_NONE)
490    {
491       ent = (U32) (target->entIdx);
492       tq = &arg->tq[ent];
493  
494       /* 
495        * Update the timer pointer in the for correct processing in
496        * CmPrcTmr.
497        */
498       if (target == arg->tqCp->tmp)
499          arg->tqCp->tmp = target->next;
500  
501       /* Remove the entru from the list */
502       CM_RMV_TQCP( tq , target);
503       target->tmrEvnt = TMR_NONE;
504       target->tqExpire = 0;
505       target->cb = NULLP;
506  
507    }
508    RETVOID;
509 #endif
510 } /* end of cmRmvCbTq */
511  
512 /**********************************************************************
513          End of file
514 **********************************************************************/