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
100 CmTqCp *tqCp, /* timing que control point */
101 CmTqType *tq, /* timing queue */
102 PFV func /* function */
117 Txt prntBuf[PRNTSZE];
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
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,
133 expire = tqCp->nxtEnt;
134 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
135 entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
137 tmp2 = &tq[entry].first;
138 while ((tmp1 = *tmp2) != NULLP)
140 if (tmp1->tqExpire == expire)
142 event = tmp1->tmrEvnt;
144 /* remove and reset this timer control block */
145 (*tmp2) = tmp1->next;
146 tmp1->tmrEvnt = TMR_NONE;
156 } /* end of cmPrcTmr */
158 #else /* not defined SS_FAP */
162 CmTqCp *tqCp, /* timing que control point */
163 CmTqType *tq, /* timing queue */
164 PFV func /* function */
169 uint32_t entry, entry1;
171 CmTqType *tqEnt, *tqEnt1;
174 volatile uint32_t startTime = 0;
178 SStartTask(&startTime, PID_CM_PRC_TMR);
183 Txt prntBuf[PRNTSZE];
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.
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,
199 expire = tqCp->nxtEnt;
201 entry = (uint32_t) (expire % (uint32_t)(tqCp->tmrLen));
203 tqCp->tmp = (tqEnt = &tq[entry])->first;
204 while ((tmp1 = tqCp->tmp) != NULLP)
206 tqCp->tmp = tmp1->next;
207 /* SRIKY - Temp Fix to overcome timer not firing. Need to take */
208 /* care of wrap around case */
209 if ((tmp1->tqExpire <= expire) || (tmp1->ent2bUpd))
211 event = tmp1->tmrEvnt;
214 if (!(tmp1->ent2bUpd))
216 CM_RMV_TQCP(tqEnt, tmp1);
217 tmp1->tmrEvnt = TMR_NONE;
225 entry1 = (uint32_t) (tmp1->tqExpire % (uint32_t)(tqCp->tmrLen));
226 tqEnt1 = &tq[entry1];
227 CM_RMV_TQCP(tqEnt, tmp1);
228 tmp1->entIdx = entry1;
229 CM_PLC_TQCP(tqEnt1, tmp1);
235 SStopTask(startTime, PID_CM_PRC_TMR);
237 } /* end of cmPrcTmr */
246 * Desc: initialize timers
250 * Notes: Connection Oriented Control
257 CmTimer *timers, /* timer list */
258 uint8_t max /* maximum tmrs */
265 for (i = 0, tPtr = timers; i < max; i++, tPtr++)
267 tPtr->tmrEvnt = TMR_NONE;
270 tPtr->next = (struct cmTimer *)NULLP;
271 tPtr->prev = (struct cmTimer *)NULLP;
272 tPtr->ent2bUpd = FALSE;
275 } /* end of cmInitTimers */
281 * Desc: Places Control Block on Timing Queue
291 Void cmPlcCbTq(CmTmrArg *arg)
293 /*added FAP modifications*/
296 /* cm_bdy5_c_001.main_20 - Modification for SRegCfgTmr support */
302 expire = (arg->tqCp->nxtEnt + arg->wait);
303 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
304 ent = (uint32_t)(expire % (uint32_t)(arg->tqCp->tmrLen));
306 for (tmrNum = 0; tmrNum < arg->max; tmrNum++)
308 if (arg->timers[tmrNum].tmrEvnt == TMR_NONE)
310 arg->timers[tmrNum].tmrEvnt = arg->evnt;
311 arg->timers[tmrNum].tqExpire = expire;
312 arg->timers[tmrNum].cb = arg->cb;
313 arg->timers[tmrNum].next = NULLP;
315 tmp = &(arg->tq[ent].first);
317 tmp = &((*tmp)->next);
318 *tmp = &arg->timers[tmrNum];
331 expire = (arg->tqCp->nxtEnt + arg->wait);
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 target = &arg->timers[tmrNum];
341 target->tmrEvnt = arg->evnt;
342 target->tqExpire = expire;
343 target->cb = arg->cb;
344 target->ent2bUpd = FALSE;
345 target->entIdx = ent;
347 /* Place the timer block in the timer list */
348 CM_PLC_TQCP(tq, target);
355 } /* end of cmPlcCbTq */
361 * Desc: Places Control Block on Timing Queue
371 Void cmRstCbTq(CmTmrArg *arg)
374 arg->timers[arg->tNum].tqExpire = arg->tqCp->nxtEnt + arg->wait;
375 arg->timers[arg->tNum].ent2bUpd = TRUE;
378 } /* end of cmRstCbTq */
384 * Desc: Removes control block from Timing Queue
394 Void cmRmvCbTq(CmTmrArg *arg)
396 /*Added FAP modifications*/
398 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
405 target = &arg->timers[arg->tNum];
406 if (target->tmrEvnt != TMR_NONE)
408 /* cm_bdy5_c_002.113 - Modification for SRegCfgTmr support */
409 ent = (uint32_t) (target->tqExpire % (uint32_t)(arg->tqCp->tmrLen));
410 tmp2 = &arg->tq[ent].first;
412 while ((tmp1 = *tmp2) != NULLP)
416 /* find the timer control block to be removed */
417 (*tmp2) = tmp1->next;
418 tmp1->tmrEvnt = TMR_NONE;
425 /* find the next timer control block */
435 target = &arg->timers[arg->tNum];
436 if (target->tmrEvnt != TMR_NONE)
438 ent = (uint32_t) (target->entIdx);
442 * Update the timer pointer in the for correct processing in
445 if (target == arg->tqCp->tmp)
446 arg->tqCp->tmp = target->next;
448 /* Remove the entru from the list */
449 CM_RMV_TQCP( tq , target);
450 target->tmrEvnt = TMR_NONE;
451 target->tqExpire = 0;
457 } /* end of cmRmvCbTq */
459 /**********************************************************************
461 **********************************************************************/