1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /********************************************************************20**
21 Name: common functions - 5
25 Desc: C source code for common timer routines;
29 *********************************************************************21*/
32 /* header include files -- defines (.h) */
34 #include "envopt.h" /* environment options */
35 #include "envdep.h" /* environment dependent */
36 #include "envind.h" /* environment independent */
38 #include "gen.h" /* general */
39 #include "ssi.h" /* system services */
40 #include "cm5.h" /* common functions */
42 /* header/extern include files (.x) */
44 #include "gen.x" /* general */
45 #include "ssi.x" /* system services */
46 #include "cm5.x" /* common functions */
51 #define CM_RMV_TQCP(tqEnt, tgt) \
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; \
62 #define CM_PLC_TQCP(tqEnt, tgt) \
66 (tqEnt)->tail->next = tgt; \
67 (tgt)->prev = (tqEnt)->tail; \
68 (tqEnt)->tail = tgt; \
72 (tqEnt)->first = (tqEnt)->tail = tgt; \
78 /* forward references */
80 /* functions in other modules */
87 * Desc: Handle a timer entry
101 CmTqCp *tqCp, /* timing que control point */
102 CmTqType *tq, /* timing queue */
103 PFV func /* function */
106 PUBLIC Void cmPrcTmr(tqCp, tq, func)
107 CmTqCp *tqCp; /* connection control block */
108 CmTqType *tq; /* message buffer */
109 PFV func; /* function */
125 Txt prntBuf[PRNTSZE];
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
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,
141 expire = tqCp->nxtEnt;
142 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
143 entry = (U32) (expire % (U32)(tqCp->tmrLen));
145 tmp2 = &tq[entry].first;
146 while ((tmp1 = *tmp2) != NULLP)
148 if (tmp1->tqExpire == expire)
150 event = tmp1->tmrEvnt;
152 /* remove and reset this timer control block */
153 (*tmp2) = tmp1->next;
154 tmp1->tmrEvnt = TMR_NONE;
164 } /* end of cmPrcTmr */
166 #else /* not defined SS_FAP */
171 CmTqCp *tqCp, /* timing que control point */
172 CmTqType *tq, /* timing queue */
173 PFV func /* function */
176 PUBLIC Void cmPrcTmr(tqCp, tq, func)
177 CmTqCp *tqCp; /* connection control block */
178 CmTqType *tq; /* message buffer */
179 PFV func; /* function */
186 CmTqType *tqEnt, *tqEnt1;
189 VOLATILE U32 startTime = 0;
194 SStartTask(&startTime, PID_CM_PRC_TMR);
199 Txt prntBuf[PRNTSZE];
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.
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,
215 expire = tqCp->nxtEnt;
216 entry = (U32) (expire % (U32)(tqCp->tmrLen));
218 tqCp->tmp = (tqEnt = &tq[entry])->first;
219 while ((tmp1 = tqCp->tmp) != NULLP)
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))
226 event = tmp1->tmrEvnt;
229 if (!(tmp1->ent2bUpd))
231 CM_RMV_TQCP(tqEnt, tmp1);
232 tmp1->tmrEvnt = TMR_NONE;
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);
250 SStopTask(startTime, PID_CM_PRC_TMR);
252 } /* end of cmPrcTmr */
261 * Desc: initialize timers
265 * Notes: Connection Oriented Control
271 PUBLIC Void cmInitTimers
273 CmTimer *timers, /* timer list */
274 U8 max /* maximum tmrs */
277 PUBLIC Void cmInitTimers(timers, max)
278 CmTimer *timers; /* timer list */
279 U8 max; /* maximum tmrs */
287 for (i = 0, tPtr = timers; i < max; i++, tPtr++)
289 tPtr->tmrEvnt = TMR_NONE;
292 tPtr->next = (struct cmTimer *)NULLP;
293 tPtr->prev = (struct cmTimer *)NULLP;
294 tPtr->ent2bUpd = FALSE;
297 } /* end of cmInitTimers */
303 * Desc: Places Control Block on Timing Queue
314 PUBLIC Void cmPlcCbTq
319 PUBLIC Void cmPlcCbTq(arg)
323 /*added FAP modifications*/
326 /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
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));
337 for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
339 if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
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;
346 tmp = &(arg->tq[ent].first);
348 tmp = &((*tmp)->next);
349 *tmp = &arg->timers[tmrNum];
363 expire = (arg->tqCp->nxtEnt + arg->wait);
364 ent = (U32)(expire % (U32)(arg->tqCp->tmrLen));
366 for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
368 if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
370 target = &arg->timers[tmrNum];
373 target->tmrEvnt = arg->evnt;
374 target->tqExpire = expire;
375 target->cb = arg->cb;
376 target->ent2bUpd = FALSE;
377 target->entIdx = ent;
379 /* Place the timer block in the timer list */
380 CM_PLC_TQCP(tq, target);
387 } /* end of cmPlcCbTq */
393 * Desc: Places Control Block on Timing Queue
404 PUBLIC Void cmRstCbTq
409 PUBLIC Void cmRstCbTq(arg)
415 arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
416 arg->timers[arg->tNum].ent2bUpd = TRUE;
419 } /* end of cmRstCbTq */
425 * Desc: Removes control block from Timing Queue
436 PUBLIC Void cmRmvCbTq
441 PUBLIC Void cmRmvCbTq(arg)
445 /*Added FAP modifications*/
447 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
455 target = &arg->timers[arg->tNum];
456 if (target->tmrEvnt != TMR_NONE)
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;
462 while ((tmp1 = *tmp2) != NULLP)
466 /* find the timer control block to be removed */
467 (*tmp2) = tmp1->next;
468 tmp1->tmrEvnt = TMR_NONE;
475 /* find the next timer control block */
488 target = &arg->timers[arg->tNum];
489 if (target->tmrEvnt != TMR_NONE)
491 ent = (U32) (target->entIdx);
495 * Update the timer pointer in the for correct processing in
498 if (target == arg->tqCp->tmp)
499 arg->tqCp->tmp = target->next;
501 /* Remove the entru from the list */
502 CM_RMV_TQCP( tq , target);
503 target->tmrEvnt = TMR_NONE;
504 target->tqExpire = 0;
510 } /* end of cmRmvCbTq */
512 /**********************************************************************
514 **********************************************************************/