Adding new commiter to ODU-High repo
[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:   void
90 *
91 *       Notes: 
92 *
93 *       File:  cm_bdy5.c
94 *
95 */
96  
97 #ifdef SS_FAP
98 Void cmPrcTmr
99 (
100 CmTqCp   *tqCp,          /* timing que control point */
101 CmTqType *tq,            /* timing queue */
102 PFV      func            /* function */
103 )
104 {
105 /**/
106    uint32_t expire;
107    uint32_t entry;
108    S16 event;
109    PTR cb;
110    CmTimer *tmp1;
111    CmTimer **tmp2;
112  
113
114 #ifdef CMDBG
115 {
116    DateTime dt;
117    Txt prntBuf[PRNTSZE];
118
119    SGetDateTime(&dt);
120    /* Here the year was being printed as 2 letter value and hence did
121     * not represent accurate information.  It has been modified as
122     * recommended to include the offset of year 1900 used in all Trillium
123     * SSI implementations. Patch cmbdy5c_001.113
124     */
125    sprintf(prntBuf,"%s: date: %02d/%02d/%04d time: %02d:%02d:%02d\n",
126            msArgv[0],dt.month,dt.day,(int)(dt.year + 1900), dt.hour,
127            dt.min, dt.sec);
128    SPrint(prntBuf);
129 }
130 #endif
131
132    ++tqCp->nxtEnt;
133    expire = tqCp->nxtEnt;
134    /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
135    entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
136
137    tmp2 = &tq[entry].first;
138    while ((tmp1 = *tmp2) != NULLP)
139    {
140       if (tmp1->tqExpire == expire)
141       {
142          event = tmp1->tmrEvnt;
143          cb = tmp1->cb;
144          /* remove and reset this timer control block */
145          (*tmp2) = tmp1->next;
146          tmp1->tmrEvnt = TMR_NONE;
147          tmp1->tqExpire = 0;
148          tmp1->cb = NULLP;
149          tmp1->next = NULLP;
150          func(cb, event);
151       }
152       else
153          tmp2 = &tmp1->next;
154    }
155    return;
156 } /* end of cmPrcTmr */
157
158 #else /* not defined SS_FAP */
159
160 Void cmPrcTmr
161 (
162 CmTqCp   *tqCp,          /* timing que control point */
163 CmTqType *tq,            /* timing queue */
164 PFV      func            /* function */
165 )
166 {
167 /**/
168    uint32_t expire;
169    uint32_t entry, entry1;
170    S16 event;
171    CmTqType *tqEnt, *tqEnt1; 
172    PTR cb;
173    CmTimer *tmp1;
174    volatile uint32_t     startTime = 0;
175    
176  
177    /*starting Task*/
178    SStartTask(&startTime, PID_CM_PRC_TMR);
179
180 #ifdef CMDBG
181 {
182    DateTime dt;
183    Txt prntBuf[PRNTSZE];
184  
185    SGetDateTime(&dt);
186    /* Here the year was being printed as 2 letter value and hence did
187     * not represent accurate information.  It has been modified as
188     * recommended to include the offset of year 1900 used in all Trillium
189     * SSI implementations.
190     */
191    sprintf(prntBuf,"%s: date: %02d/%02d/%04d time: %02d:%02d:%02d\n",
192            msArgv[0],dt.month,dt.day,(int)(dt.year + 1900), dt.hour, 
193            dt.min, dt.sec);
194    SPrint(prntBuf);
195 }
196 #endif
197  
198    ++tqCp->nxtEnt;
199    expire = tqCp->nxtEnt;
200    entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
201   
202    tqCp->tmp = (tqEnt = &tq[entry])->first;
203    while ((tmp1 = tqCp->tmp) != NULLP)
204    {
205       tqCp->tmp = tmp1->next;
206       /* SRIKY - Temp Fix to overcome timer not firing. Need to take */
207           /* care of wrap around case                                                    */
208       if ((tmp1->tqExpire <= expire) || (tmp1->ent2bUpd))
209       {
210          event = tmp1->tmrEvnt;
211          cb = tmp1->cb;
212  
213          if (!(tmp1->ent2bUpd))
214          {
215             CM_RMV_TQCP(tqEnt, tmp1);
216             tmp1->tmrEvnt = TMR_NONE; 
217             tmp1->tqExpire = 0;     
218             tmp1->cb = NULLP;      
219  
220             func(cb, event);
221          }
222          else
223          {
224             entry1 = (uint32_t) (tmp1->tqExpire % (uint32_t)(tqCp->tmrLen));
225             tqEnt1 = &tq[entry1];
226             CM_RMV_TQCP(tqEnt, tmp1);
227             tmp1->entIdx = entry1; 
228             CM_PLC_TQCP(tqEnt1, tmp1);
229          }
230       }
231    }
232
233    /*stoping Task*/
234    SStopTask(startTime, PID_CM_PRC_TMR);
235    return;
236 } /* end of cmPrcTmr */
237 #endif /* SS_FAP */
238
239
240 \f
241 /*
242 *
243 *       Fun:   cmInitTimers
244 *
245 *       Desc:  initialize timers
246 *
247 *       Ret:   void
248 *
249 *       Notes: Connection Oriented Control
250 *
251 *       File:  cm_bdy5.c
252 *
253 */
254 Void cmInitTimers
255 (
256 CmTimer *timers,     /* timer list */
257 uint8_t max               /* maximum tmrs */
258 )
259 {
260    CmTimer *tPtr;
261    REG1 uint8_t i;
262
263
264    for (i = 0, tPtr = timers; i < max; i++, tPtr++)
265    {
266       tPtr->tmrEvnt = TMR_NONE;
267       tPtr->tqExpire = 0;
268       tPtr->cb = 0;
269       tPtr->next = (struct cmTimer *)NULLP;
270       tPtr->prev = (struct cmTimer *)NULLP;
271       tPtr->ent2bUpd = FALSE;
272    }
273    return;
274 } /* end of cmInitTimers */
275
276 /*
277 *
278 *       Fun:    cmPlcCbTq
279 *
280 *       Desc:   Places Control Block on Timing Queue
281 *
282 *       Ret:    void
283 *
284 *       Notes:  None
285 *
286 *       File:   cm_bdy5.c
287 *
288 */
289   
290 Void cmPlcCbTq(CmTmrArg *arg)
291 {
292 /*added FAP modifications*/
293 #ifdef SS_FAP
294    REG1 uint8_t tmrNum;
295    /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
296    uint32_t ent;
297    uint32_t expire;
298    CmTimer **tmp;
299
300
301    expire = (arg->tqCp->nxtEnt + arg->wait);
302    /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
303    ent = (uint32_t)(expire % (uint32_t)(arg->tqCp->tmrLen));
304
305    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
306    {
307       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
308       {
309          arg->timers[tmrNum].tmrEvnt = arg->evnt;
310          arg->timers[tmrNum].tqExpire = expire;
311          arg->timers[tmrNum].cb = arg->cb;
312          arg->timers[tmrNum].next = NULLP;
313
314          tmp = &(arg->tq[ent].first);
315          while (*tmp)
316             tmp = &((*tmp)->next);
317          *tmp = &arg->timers[tmrNum];
318
319          return;
320       }
321    }
322    return;
323 #else
324    REG1 uint8_t tmrNum;
325    uint32_t ent;
326    CmTqType *tq;
327    CmTimer  *target;
328    uint32_t expire;
329  
330    expire = (arg->tqCp->nxtEnt + arg->wait);
331    ent = (uint32_t)(expire % (uint32_t)(arg->tqCp->tmrLen));
332  
333    for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
334    {
335       if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
336       {
337          target = &arg->timers[tmrNum];
338          tq = &arg->tq[ent]; 
339  
340          target->tmrEvnt = arg->evnt;
341          target->tqExpire = expire;
342          target->cb = arg->cb;
343          target->ent2bUpd = FALSE;
344          target->entIdx   = ent;
345
346          /* Place the timer block in the timer list */
347          CM_PLC_TQCP(tq, target); 
348  
349          return;
350       }
351    }
352    return;
353 #endif
354 } /* end of cmPlcCbTq */
355  
356 /*
357 *
358 *       Fun:    cmRstCbTq
359 *
360 *       Desc:   Places Control Block on Timing Queue
361 *
362 *       Ret:    void
363 *
364 *       Notes:  None
365 *
366 *       File:   cm_bdy5.c
367 *
368 */
369   
370 Void cmRstCbTq(CmTmrArg *arg)
371 {
372  
373    arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
374    arg->timers[arg->tNum].ent2bUpd = TRUE; 
375  
376    return;
377 } /* end of cmRstCbTq */
378
379 /*
380 *
381 *       Fun:    cmRmvCbTq
382 *
383 *       Desc:   Removes control block from Timing Queue
384 *
385 *       Ret:    void
386 *
387 *       Notes:  None
388 *
389 *       File:   cm_bdy5.c
390 *
391 */
392   
393 Void cmRmvCbTq(CmTmrArg *arg)
394 {
395 /*Added FAP modifications*/
396 #ifdef SS_FAP
397 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
398    uint32_t ent;
399    CmTimer *target;
400    CmTimer *tmp1;
401    CmTimer **tmp2;
402
403
404    target = &arg->timers[arg->tNum];
405    if (target->tmrEvnt != TMR_NONE)
406    {
407       /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
408       ent = (uint32_t) (target->tqExpire % (uint32_t)(arg->tqCp->tmrLen));
409       tmp2 = &arg->tq[ent].first;
410
411       while ((tmp1 = *tmp2) != NULLP)
412       {
413          if (tmp1 == target)
414          {
415             /* find the timer control block to be removed */
416             (*tmp2) = tmp1->next;
417             tmp1->tmrEvnt = TMR_NONE;
418             tmp1->tqExpire = 0;
419             tmp1->cb = NULLP;
420             tmp1->next = NULLP;
421             break;
422          }
423          else
424             /* find the next timer control block */
425             tmp2 = &tmp1->next;
426       }
427    }
428    return;
429 #else
430    uint32_t ent;
431    CmTimer  *target;
432    CmTqType *tq;
433    
434    target = &arg->timers[arg->tNum];
435    if (target->tmrEvnt != TMR_NONE)
436    {
437       ent = (uint32_t) (target->entIdx);
438       tq = &arg->tq[ent];
439  
440       /* 
441        * Update the timer pointer in the for correct processing in
442        * CmPrcTmr.
443        */
444       if (target == arg->tqCp->tmp)
445          arg->tqCp->tmp = target->next;
446  
447       /* Remove the entru from the list */
448       CM_RMV_TQCP( tq , target);
449       target->tmrEvnt = TMR_NONE;
450       target->tqExpire = 0;
451       target->cb = NULLP;
452  
453    }
454    return;
455 #endif
456 } /* end of cmRmvCbTq */
457  
458 /**********************************************************************
459          End of file
460 **********************************************************************/