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 Void cmPrcTmr(tqCp, tq, func)
107 CmTqCp *tqCp; /* connection control block */
108 CmTqType *tq; /* message buffer */
109 PFV func; /* function */
124 Txt prntBuf[PRNTSZE];
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
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,
140 expire = tqCp->nxtEnt;
141 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
142 entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
144 tmp2 = &tq[entry].first;
145 while ((tmp1 = *tmp2) != NULLP)
147 if (tmp1->tqExpire == expire)
149 event = tmp1->tmrEvnt;
151 /* remove and reset this timer control block */
152 (*tmp2) = tmp1->next;
153 tmp1->tmrEvnt = TMR_NONE;
163 } /* end of cmPrcTmr */
165 #else /* not defined SS_FAP */
170 CmTqCp *tqCp, /* timing que control point */
171 CmTqType *tq, /* timing queue */
172 PFV func /* function */
175 Void cmPrcTmr(tqCp, tq, func)
176 CmTqCp *tqCp; /* connection control block */
177 CmTqType *tq; /* message buffer */
178 PFV func; /* function */
183 uint32_t entry, entry1;
185 CmTqType *tqEnt, *tqEnt1;
188 volatile uint32_t startTime = 0;
192 SStartTask(&startTime, PID_CM_PRC_TMR);
197 Txt prntBuf[PRNTSZE];
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.
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,
213 expire = tqCp->nxtEnt;
215 entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
217 tqCp->tmp = (tqEnt = &tq[entry])->first;
218 while ((tmp1 = tqCp->tmp) != NULLP)
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))
225 event = tmp1->tmrEvnt;
228 if (!(tmp1->ent2bUpd))
230 CM_RMV_TQCP(tqEnt, tmp1);
231 tmp1->tmrEvnt = TMR_NONE;
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);
249 SStopTask(startTime, PID_CM_PRC_TMR);
251 } /* end of cmPrcTmr */
260 * Desc: initialize timers
264 * Notes: Connection Oriented Control
272 CmTimer *timers, /* timer list */
273 uint8_t max /* maximum tmrs */
276 Void cmInitTimers(timers, max)
277 CmTimer *timers; /* timer list */
278 uint8_t max; /* maximum tmrs */
285 for (i = 0, tPtr = timers; i < max; i++, tPtr++)
287 tPtr->tmrEvnt = TMR_NONE;
290 tPtr->next = (struct cmTimer *)NULLP;
291 tPtr->prev = (struct cmTimer *)NULLP;
292 tPtr->ent2bUpd = FALSE;
295 } /* end of cmInitTimers */
301 * Desc: Places Control Block on Timing Queue
321 /*added FAP modifications*/
324 /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
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));
334 for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
336 if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
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;
343 tmp = &(arg->tq[ent].first);
345 tmp = &((*tmp)->next);
346 *tmp = &arg->timers[tmrNum];
359 expire = (arg->tqCp->nxtEnt + arg->wait);
360 ent = (uint32_t)(expire % (uint32_t)(arg->tqCp->tmrLen));
362 for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
364 if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
366 target = &arg->timers[tmrNum];
369 target->tmrEvnt = arg->evnt;
370 target->tqExpire = expire;
371 target->cb = arg->cb;
372 target->ent2bUpd = FALSE;
373 target->entIdx = ent;
375 /* Place the timer block in the timer list */
376 CM_PLC_TQCP(tq, target);
383 } /* end of cmPlcCbTq */
389 * Desc: Places Control Block on Timing Queue
410 arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
411 arg->timers[arg->tNum].ent2bUpd = TRUE;
414 } /* end of cmRstCbTq */
420 * Desc: Removes control block from Timing Queue
440 /*Added FAP modifications*/
442 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
449 target = &arg->timers[arg->tNum];
450 if (target->tmrEvnt != TMR_NONE)
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;
456 while ((tmp1 = *tmp2) != NULLP)
460 /* find the timer control block to be removed */
461 (*tmp2) = tmp1->next;
462 tmp1->tmrEvnt = TMR_NONE;
469 /* find the next timer control block */
479 target = &arg->timers[arg->tNum];
480 if (target->tmrEvnt != TMR_NONE)
482 ent = (uint32_t) (target->entIdx);
486 * Update the timer pointer in the for correct processing in
489 if (target == arg->tqCp->tmp)
490 arg->tqCp->tmp = target->next;
492 /* Remove the entru from the list */
493 CM_RMV_TQCP( tq , target);
494 target->tmrEvnt = TMR_NONE;
495 target->tqExpire = 0;
501 } /* end of cmRmvCbTq */
503 /**********************************************************************
505 **********************************************************************/