Moving all common header file into common_def.h file
[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         tqCp->tmrLen = 1;
217    entry = (U32) (expire % (U32)(tqCp->tmrLen));
218   
219    tqCp->tmp = (tqEnt = &tq[entry])->first;
220    while ((tmp1 = tqCp->tmp) != NULLP)
221    {
222       tqCp->tmp = tmp1->next;
223       /* SRIKY - Temp Fix to overcome timer not firing. Need to take */
224           /* care of wrap around case                                                    */
225       if ((tmp1->tqExpire <= expire) || (tmp1->ent2bUpd))
226       {
227          event = tmp1->tmrEvnt;
228          cb = tmp1->cb;
229  
230          if (!(tmp1->ent2bUpd))
231          {
232             CM_RMV_TQCP(tqEnt, tmp1);
233             tmp1->tmrEvnt = TMR_NONE; 
234             tmp1->tqExpire = 0;     
235             tmp1->cb = NULLP;      
236  
237             func(cb, event);
238          }
239          else
240          {
241             entry1 = (U32) (tmp1->tqExpire % (U32)(tqCp->tmrLen));
242             tqEnt1 = &tq[entry1];
243             CM_RMV_TQCP(tqEnt, tmp1);
244             tmp1->entIdx = entry1; 
245             CM_PLC_TQCP(tqEnt1, tmp1);
246          }
247       }
248    }
249
250    /*stoping Task*/
251    SStopTask(startTime, PID_CM_PRC_TMR);
252    RETVOID;
253 } /* end of cmPrcTmr */
254 #endif /* SS_FAP */
255
256
257 \f
258 /*
259 *
260 *       Fun:   cmInitTimers
261 *
262 *       Desc:  initialize timers
263 *
264 *       Ret:   RETVOID
265 *
266 *       Notes: Connection Oriented Control
267 *
268 *       File:  cm_bdy5.c
269 *
270 */
271 #ifdef ANSI
272 PUBLIC Void cmInitTimers
273 (
274 CmTimer *timers,     /* timer list */
275 U8 max               /* maximum tmrs */
276 )
277 #else
278 PUBLIC Void cmInitTimers(timers, max)
279 CmTimer *timers;     /* timer list */
280 U8 max;              /* maximum tmrs */
281 #endif
282 {
283    CmTimer *tPtr;
284    REG1 U8 i;
285
286    TRC2(cmInitTimers)
287
288    for (i = 0, tPtr = timers; i < max; i++, tPtr++)
289    {
290       tPtr->tmrEvnt = TMR_NONE;
291       tPtr->tqExpire = 0;
292       tPtr->cb = 0;
293       tPtr->next = (struct cmTimer *)NULLP;
294       tPtr->prev = (struct cmTimer *)NULLP;
295       tPtr->ent2bUpd = FALSE;
296    }
297    RETVOID;
298 } /* end of cmInitTimers */
299
300 /*
301 *
302 *       Fun:    cmPlcCbTq
303 *
304 *       Desc:   Places Control Block on Timing Queue
305 *
306 *       Ret:    RETVOID
307 *
308 *       Notes:  None
309 *
310 *       File:   cm_bdy5.c
311 *
312 */
313   
314 #ifdef ANSI
315 PUBLIC Void cmPlcCbTq
316 (
317 CmTmrArg *arg
318 )
319 #else
320 PUBLIC Void cmPlcCbTq(arg)
321 CmTmrArg *arg;
322 #endif
323 {
324 /*added FAP modifications*/
325 #ifdef SS_FAP
326    REG1 U8 tmrNum;
327    /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
328    U32 ent;
329    U32 expire;
330    CmTimer **tmp;
331
332    TRC2(cmPlcCbTq)
333
334    expire = (arg->tqCp->nxtEnt + arg->wait);
335    /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
336    ent = (U32)(expire % (U32)(arg->tqCp->tmrLen));
337
338    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
339    {
340       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
341       {
342          arg->timers[tmrNum].tmrEvnt = arg->evnt;
343          arg->timers[tmrNum].tqExpire = expire;
344          arg->timers[tmrNum].cb = arg->cb;
345          arg->timers[tmrNum].next = NULLP;
346
347          tmp = &(arg->tq[ent].first);
348          while (*tmp)
349             tmp = &((*tmp)->next);
350          *tmp = &arg->timers[tmrNum];
351
352          RETVOID;
353       }
354    }
355    RETVOID;
356 #else
357    REG1 U8 tmrNum;
358    U32 ent;
359    CmTqType *tq;
360    CmTimer  *target;
361    U32 expire;
362    TRC2(cmPlcCbTq)
363  
364    expire = (arg->tqCp->nxtEnt + arg->wait);
365    ent = (U32)(expire % (U32)(arg->tqCp->tmrLen));
366  
367    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
368    {
369       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
370       {
371          target = &arg->timers[tmrNum];
372          tq = &arg->tq[ent]; 
373  
374          target->tmrEvnt = arg->evnt;
375          target->tqExpire = expire;
376          target->cb = arg->cb;
377          target->ent2bUpd = FALSE;
378          target->entIdx   = ent;
379
380          /* Place the timer block in the timer list */
381          CM_PLC_TQCP(tq, target); 
382  
383          RETVOID;
384       }
385    }
386    RETVOID;
387 #endif
388 } /* end of cmPlcCbTq */
389  
390 /*
391 *
392 *       Fun:    cmRstCbTq
393 *
394 *       Desc:   Places Control Block on Timing Queue
395 *
396 *       Ret:    RETVOID
397 *
398 *       Notes:  None
399 *
400 *       File:   cm_bdy5.c
401 *
402 */
403   
404 #ifdef ANSI
405 PUBLIC Void cmRstCbTq
406 (
407 CmTmrArg *arg
408 )
409 #else
410 PUBLIC Void cmRstCbTq(arg)
411 CmTmrArg *arg;
412 #endif
413 {
414    TRC2(cmRstCbTq)
415  
416    arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
417    arg->timers[arg->tNum].ent2bUpd = TRUE; 
418  
419    RETVOID;
420 } /* end of cmRstCbTq */
421
422 /*
423 *
424 *       Fun:    cmRmvCbTq
425 *
426 *       Desc:   Removes control block from Timing Queue
427 *
428 *       Ret:    RETVOID
429 *
430 *       Notes:  None
431 *
432 *       File:   cm_bdy5.c
433 *
434 */
435   
436 #ifdef ANSI
437 PUBLIC Void cmRmvCbTq
438 (
439 CmTmrArg *arg
440 )
441 #else
442 PUBLIC Void cmRmvCbTq(arg)
443 CmTmrArg *arg;
444 #endif
445 {
446 /*Added FAP modifications*/
447 #ifdef SS_FAP
448 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
449    U32 ent;
450    CmTimer *target;
451    CmTimer *tmp1;
452    CmTimer **tmp2;
453
454    TRC2(cmRmvCbTq)
455
456    target = &arg->timers[arg->tNum];
457    if (target->tmrEvnt != TMR_NONE)
458    {
459       /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
460       ent = (U32) (target->tqExpire % (U32)(arg->tqCp->tmrLen));
461       tmp2 = &arg->tq[ent].first;
462
463       while ((tmp1 = *tmp2) != NULLP)
464       {
465          if (tmp1 == target)
466          {
467             /* find the timer control block to be removed */
468             (*tmp2) = tmp1->next;
469             tmp1->tmrEvnt = TMR_NONE;
470             tmp1->tqExpire = 0;
471             tmp1->cb = NULLP;
472             tmp1->next = NULLP;
473             break;
474          }
475          else
476             /* find the next timer control block */
477             tmp2 = &tmp1->next;
478       }
479    }
480    RETVOID;
481 #else
482    U32 ent;
483    CmTimer  *target;
484    CmTqType *tq;
485    
486  
487    TRC2(cmRmvCbTq)
488  
489    target = &arg->timers[arg->tNum];
490    if (target->tmrEvnt != TMR_NONE)
491    {
492       ent = (U32) (target->entIdx);
493       tq = &arg->tq[ent];
494  
495       /* 
496        * Update the timer pointer in the for correct processing in
497        * CmPrcTmr.
498        */
499       if (target == arg->tqCp->tmp)
500          arg->tqCp->tmp = target->next;
501  
502       /* Remove the entru from the list */
503       CM_RMV_TQCP( tq , target);
504       target->tmrEvnt = TMR_NONE;
505       target->tqExpire = 0;
506       target->cb = NULLP;
507  
508    }
509    RETVOID;
510 #endif
511 } /* end of cmRmvCbTq */
512  
513 /**********************************************************************
514          End of file
515 **********************************************************************/