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