J-Release Documentation
[o-du/l2.git] / src / mt / ss_timer.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 \f
19 /********************************************************************20**
20  
21      Name:     System Services -- Timing
22  
23      Type:     C source file
24  
25      Desc:     Source code for System Services related to timing.
26  
27      File:     ss_timer.c
28  
29 *********************************************************************21*/
30
31 \f
32 /* header include files (.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 layer */
39 #include "ssi.h"           /* system services */
40
41 #include "ss_err.h"        /* errors */
42 #include "ss_dep.h"        /* implementation-specific */
43 #include "ss_queue.h"      /* queues */
44 #include "ss_msg.h"        /* messaging */
45 #include "ss_mem.h"        /* memory management interface */
46 #include "ss_gen.h"        /* general */
47 #include "cm_mem.h"        /* memory management */
48
49
50
51 /* header/extern include files (.x) */
52
53 #include "gen.x"           /* general layer */
54 #include "ssi.x"           /* system services */
55
56 #include "ss_dep.x"        /* implementation-specific */
57 #include "ss_queue.x"      /* queues */
58 #include "ss_task.x"       /* tasking */
59 #include "ss_timer.x"      /* timers */
60 #include "ss_strm.x"       /* STREAMS */
61 #include "ss_msg.x"        /* messaging */
62 #include "ss_mem.x"        /* memory management interface */
63 #include "ss_drvr.x"       /* driver tasks */
64 #ifdef SS_LOCKLESS_MEMORY
65 #include "cm_llist.x"
66 #include "cm_hash.x"
67 #include "cm_mem_wl.x"        /* common memory manager */
68 #else
69 #include "cm_mem.x"        /* common memory manager */
70 #endif /* SS_LOCKLESS_MEMORY */
71 #include "ss_gen.x"        /* general */
72
73
74 /* Forward declarations */
75
76 /* ss041.103 Declaration for STmrRegHndlr */
77 /* ss015.301 Changed the timer activation function type as all timer activation
78  * functions are enclosed in a union. 
79  */
80 #ifndef SS_MULTIPLE_PROCS
81 static S16 STmrRegHndlr ARGS((
82          Ent ent,
83          Inst inst,
84          S16 period,
85          S16 units,
86          SsTmrActvFn ssTmrActvFn
87       ));
88 /* ss015.301: Removed the timer handler prototypes guarded under SS_MT_TMR and 
89  * handled mtFlag in existing timer handlers. 
90  */
91 #else /* SS_MULTIPLE_PROCS */
92 static S16 STmrRegHndlr ARGS((
93          ProcId proc,
94          Ent ent,
95          Inst inst,
96          S16 period,
97          S16 units,
98          SsTmrActvFn ssTmrActvFn
99       ));
100 #endif /* SS_MULTIPLE_PROCS */
101
102 /* ss041.103 Declaration for STmrDeregHndlr */
103 #ifndef SS_MULTIPLE_PROCS
104 static S16 STmrDeregHndlr ARGS((
105          Ent ent,
106          Inst inst,
107          S16 period,
108          S16 units,
109          SsTmrActvFn ssTmrActvFn
110       ));
111 /* ss015.301 Removed the timer handler prototypes guarded under SS_MT_TMR and 
112  * handled mtFlag in existing timer handlers.
113  */
114 #else /* SS_MULTIPLE_PROCS */
115 static S16 STmrDeregHndlr ARGS((
116          ProcId proc,
117          Ent ent,
118          Inst inst,
119          S16 period,
120          S16 units,
121          SsTmrActvFn ssTmrActvFn
122       ));
123 #endif /* SS_MULTIPLE_PROCS */
124
125
126 \f
127 /* ss028.103 - Modification for SRegCfgTmr Support */
128 /*
129 *
130 *       Fun:   Register Configurable Timer Task - timer
131 *
132 *       Desc:  This function is used to register a timer function for the
133 *              layer. The system services will periodically invoke the
134 *              function passed to it. The timer function will be used by the
135 *              layer to manage the layers internal protocol timers.
136 *
137 *       Ret:   ROK      - ok
138 *              RFAILED  - failed, general (optional)
139 *              ROUTRES  - failed, out of resources (optional)
140 *
141 *       Notes:
142 *
143 *       File:  ss_timer.c
144 *
145 */
146 /* ss029.103: addition: procId added and timer function type modified */ 
147 #ifndef SS_MULTIPLE_PROCS
148 S16 SRegCfgTmr
149 (
150 Ent ent,                    /* entity */
151 Inst inst,                  /* instance */
152 S16 period,                 /* period */
153 S16 units,                  /* period units */
154 PFS16 tmrFnct               /* timer function, typically SActvTmr */
155 )
156 {
157    S16 ret;
158    /* ss015.301 - Enclosed all timer activation functions in a union. */
159    SsTmrActvFn ssTmrActvFn;
160    /* ss041.103 - Moved handling to STmrRegHndlr */
161
162    ssTmrActvFn.mtFlag = FALSE;
163    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;
164    ret = STmrRegHndlr(ent, inst, period, units, ssTmrActvFn);
165
166    return (ret);
167 }
168
169 #else /* SS_MULTIPLE_PROCS */
170
171 S16 SRegCfgTmr
172 (
173 ProcId proc,                /* processor */
174 Ent ent,                    /* entity */
175 Inst inst,                  /* instance */
176 S16 period,                 /* period */
177 S16 units,                  /* period units */
178 PAIFTMRS16 tmrFnct               /* timer function, typically SActvTmr */
179 )
180 {
181    S16 ret;
182    /* ss015.301 - Enclosed all timer activation functions in a union. */
183    SsTmrActvFn ssTmrActvFn;
184    /* ss041.103 - Moved handling to STmrRegHndlr */
185
186    ssTmrActvFn.mtFlag = FALSE;
187    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;
188    ret = STmrRegHndlr(proc, ent, inst, period, units, ssTmrActvFn);
189
190    return (ret);
191 }
192
193 #endif /* SS_MULTIPLE_PROCS */
194
195 \f
196 #ifndef SS_MULTIPLE_PROCS
197 /* ss041.103 - New function for MT timer reg */
198 #ifdef SS_MT_TMR
199 /*
200 *
201 *       Fun:   Register Configurable Timer Task - timer
202 *
203 *       Desc:  This function is used to register a timer function for the
204 *              layer. The system services will periodically invoke the
205 *              function passed to it. The timer function will be used by the
206 *              layer to manage the layers internal protocol timers.
207 *
208 *       Ret:   ROK      - ok
209 *              RFAILED  - failed, general (optional)
210 *              ROUTRES  - failed, out of resources (optional)
211 *
212 *       Notes: By invoking this function, Ent and Inst are passed in the
213 *              timer activation function.
214 *
215 *       File:  ss_timer.c
216 *
217 */
218 S16 SRegCfgTmrMt
219 (
220 Ent ent,                    /* entity */
221 Inst inst,                  /* instance */
222 S16 period,                 /* period */
223 S16 units,                  /* period units */
224 PAIFTMRS16 tmrFnctMt        /* timer function, typically SActvTmr */
225 )
226 {
227    S16 ret;
228    /* ss015.301 - Enclosed all timer activation functions in a union. */
229    SsTmrActvFn ssTmrActvFn;
230
231    ssTmrActvFn.actvFnc.tmrActvFnMt = tmrFnctMt;
232    ssTmrActvFn.mtFlag = TRUE;
233    ret = STmrRegHndlr(ent, inst, period, units, ssTmrActvFn);
234
235    return (ret);
236 }
237 #endif /* SS_MT_TMR */
238 #endif /* not SS_MULTIPLE_PROCS */
239
240 /* ss041.103 - Function for timer registration handling */
241 /*
242 *
243 *       Fun:   Timer registration handler function
244 *
245 *       Desc:  This function is called by the timer registration interface
246 *              functions, and does the actual handling for timer
247 *              registration.
248 *
249 *       Ret:   ROK      - ok
250 *              RFAILED  - failed, general (optional)
251 *              ROUTRES  - failed, out of resources (optional)
252 *
253 *       Notes:
254 *
255 *       File:  ss_timer.c
256 *
257 */
258
259 /* ss015.301 Changed the timer activation function type as all timer activation
260  * functions are enclosed in a union.
261  */
262
263 #ifndef SS_MULTIPLE_PROCS
264
265 static S16 STmrRegHndlr
266 (
267 Ent ent,                    /* entity */
268 Inst inst,                  /* instance */
269 S16 period,                 /* period */
270 S16 units,                  /* period units */
271 SsTmrActvFn ssTmrActvFn               /* timer function, typically SActvTmr */
272 )
273 /* ss015.301: Removed the timer handler prototypes guarded
274  * under SS_MT_TMR and handled mtFlag in existing timer handlers.
275  */
276
277 #else /* SS_MULTIPLE_PROCS */
278
279 static S16 STmrRegHndlr
280 (
281 ProcId proc,                /* processor */
282 Ent ent,                    /* entity */
283 Inst inst,                  /* instance */
284 S16 period,                 /* period */
285 S16 units,                  /* period units */
286 SsTmrActvFn ssTmrActvFn     /* timer function */
287 )
288 #endif /* SS_MULTIPLE_PROCS */
289 {
290 #if (ERRCLASS & ERRCLS_INT_PAR)
291    uint8_t i;
292 #endif
293    S16 ret;
294    SsTmrEntry *tmr;
295 #ifdef SS_MULTIPLE_PROCS
296 #if (ERRCLASS & ERRCLS_INT_PAR)
297    uint16_t procIdIdx;
298 #endif /* ERRCLASS & ERRCLS_INT_PAR */
299 #endif /* SS_MULTPLE_PROCS */
300
301 #if (ERRCLASS & ERRCLS_INT_PAR)
302
303 #ifdef SS_MULTIPLE_PROCS
304    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
305    {
306       SSLOGERROR(ERRCLS_INT_PAR, ESS528, ERRZERO, "Invalid processor/entity/instance");
307       return RFAILED;
308    }
309 #else /* SS_MULTIPLE_PROCS */
310    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
311    {
312       SSLOGERROR(ERRCLS_INT_PAR, ESS529, ERRZERO, "Invalid entity/instance");
313       return RFAILED;
314    }
315 #endif /* SS_MULTIPLE_PROCS */
316
317    /* check period */
318    if (period <= 0)
319    {
320       SSLOGERROR(ERRCLS_INT_PAR, ESS530, ERRZERO, "Invalid period");
321       return RFAILED;
322    }
323
324    /* check period units*/
325    if ((units < 1) || (units > SS_TICKS_SEC))
326    {
327       SSLOGERROR(ERRCLS_INT_PAR, ESS531, ERRZERO, "Invalid period units");
328       return RFAILED;
329    }
330
331    if(ssTmrActvFn.mtFlag == TRUE) 
332    { 
333    /* ss015.301 Enclosed all timer activation functions in a union. */
334 #ifndef SS_MULTIPLE_PROCS
335 #ifdef SS_MT_TMR
336       if (ssTmrActvFn.actvFnc.tmrActvFnMt == NULLP)  
337       {
338          SSLOGERROR(ERRCLS_INT_PAR, ESS532, ERRZERO, "Null pointer");
339          return RFAILED;
340       }
341 #else
342       return RFAILED;
343 #endif
344 #else
345       return RFAILED;
346 #endif
347    }
348    else
349    { 
350       if (ssTmrActvFn.actvFnc.tmrActvFn == NULLP)  
351       {
352           SSLOGERROR(ERRCLS_INT_PAR, ESS532, ERRZERO, "Null pointer");
353           return RFAILED;
354       }
355    } 
356
357 #ifdef SS_MULTIPLE_PROCS
358    /* check if the procId has been registered with SSI */
359    procIdIdx = SGetProcIdIdx(proc);
360
361    if (procIdIdx == SS_INV_PROCID_IDX)
362    {
363       SSLOGERROR(ERRCLS_INT_PAR, ESS533, ERRZERO,
364                      "Could not find proc id index");
365       return RFAILED;
366    }
367 #endif /* SS_MULTIPLE_PROCS */
368
369
370    /* check task ID */
371    /* lock TAPA task table */
372    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
373    if (ret != ROK)
374    {
375       SSLOGERROR(ERRCLS_DEBUG, ESS534, ERRZERO,
376                      "Could not lock TAPA task table");
377       return RFAILED;
378    }
379
380 #ifdef SS_MULTIPLE_PROCS
381    if (osCp.tTskIds[procIdIdx][ent][inst] == SS_TSKNC)
382 #else /* SS_MULTIPLE_PROCS */
383    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
384 #endif /* SS_MULTIPLE_PROCS */
385    {
386       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
387       {
388 #if (ERRCLASS & ERRCLS_DEBUG)
389       SSLOGERROR(ERRCLS_DEBUG, ESS535, ERRZERO,
390                      "Could not release the semaphore");
391       return RFAILED;
392 #endif
393       }
394       SSLOGERROR(ERRCLS_INT_PAR, ESS536, ERRZERO, "Unknown task");
395       return RFAILED;
396    }
397    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
398    {
399 #if (ERRCLASS & ERRCLS_DEBUG)
400       SSLOGERROR(ERRCLS_DEBUG, ESS537, ERRZERO,
401                      "Could not release the semaphore");
402    return RFAILED;
403 #endif
404    }
405
406 #endif
407
408    /* lock the timer table */
409    ret = SLock(&osCp.tmrTblLock);
410    if (ret != ROK)
411    {
412
413 #if (ERRCLASS & ERRCLS_DEBUG)
414       SSLOGERROR(ERRCLS_DEBUG, ESS538, (ErrVal) ret,
415                      "Could not lock timer table");
416 #endif
417       return (ret);
418    }
419
420
421    /* check if we've got room for another timer */
422    if (osCp.numTmrs == SS_MAX_TMRS)
423    {
424       if ( SUnlock(&osCp.tmrTblLock) != ROK)
425       {
426 #if (ERRCLASS & ERRCLS_DEBUG)
427          SSLOGERROR(ERRCLS_DEBUG, ESS539, ERRZERO,
428                      "Could not unlock the semaphore");
429          return RFAILED;
430 #endif
431       }
432
433 #if (ERRCLASS & ERRCLS_DEBUG)
434       SSLOGERROR(ERRCLS_DEBUG, ESS540, ERRZERO, "Too many timers");
435 #endif
436
437       return (ROUTRES);
438    }
439
440 #if (ERRCLASS & ERRCLS_INT_PAR)
441    /* check through the timer table for a matching timer entry */
442    for (i = 0; i < SS_MAX_TMRS; i++)
443    {   
444       if ((osCp.tmrTbl[i].ownerEnt == ent)
445 #ifdef SS_MULTIPLE_PROCS
446             &&  (osCp.tmrTbl[i].ownerProc == proc)
447 #endif /* SS_MULTIPLE_PROCS */
448             && (osCp.tmrTbl[i].ownerInst == inst)
449             /* ss041.103 - Added mtFlag check */
450             /* ss015.301 Enclosed all timer activation functions in a union. */
451 #ifndef SS_MULTIPLE_PROCS
452 #ifdef SS_MT_TMR
453             && (osCp.tmrTbl[i].ssTmrActvFn.mtFlag == ssTmrActvFn.mtFlag)
454             && ((ssTmrActvFn.mtFlag == FALSE
455                   && osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)  
456                || osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFnMt == ssTmrActvFn.actvFnc.tmrActvFnMt)
457 #else
458             && (osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
459 #endif
460 #else
461             && (osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
462 #endif
463             && (osCp.tmrTbl[i].interval == (uint32_t) ((period * SS_TICKS_SEC) / units)))
464       {
465          /* is this timer in use ? (unexpired) */
466          if (osCp.tmrTbl[i].used == TRUE)
467          {  
468             /* to prevent the same timer to be registered with SS  UNLOCK and */
469             /* then RFAIL */
470             if (SUnlock(&osCp.tmrTblLock) != ROK)
471             {
472 #if (ERRCLASS & ERRCLS_DEBUG)
473    SSLOGERROR(ERRCLS_DEBUG, ESS541, ERRZERO, "Could not unlock the semaphore");
474    return RFAILED;
475 #endif
476             }
477             return RFAILED;
478          }
479       }
480    }
481 #endif
482
483    /* fill in the information we have into the timer entry */
484    tmr = &osCp.tmrTbl[osCp.nxtTmrEntry];
485    tmr->tmrId     = osCp.nxtTmrEntry;
486 #ifdef SS_MULTIPLE_PROCS
487    tmr->ownerProc = proc;
488 #endif /* SS_MULTIPLE_PROCS */
489    tmr->ownerEnt  = ent;
490    tmr->ownerInst = inst;
491    tmr->interval  = (uint32_t) ((period * SS_TICKS_SEC) / units);
492    tmr->ssTmrActvFn.mtFlag = ssTmrActvFn.mtFlag;
493
494    /* ss041.103 */
495    /* ss015.301 Enclosed all timer activation functions in a union. */
496 #ifndef SS_MULTIPLE_PROCS
497 #ifdef SS_MT_TMR
498    if (ssTmrActvFn.mtFlag == TRUE)
499    {
500       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = ssTmrActvFn.actvFnc.tmrActvFnMt;  
501    }
502    else
503 #endif
504 #endif
505    {
506       tmr->ssTmrActvFn.actvFnc.tmrActvFn = ssTmrActvFn.actvFnc.tmrActvFn;
507    }
508
509
510    /* ask the implementation to start the timer */
511    ret = ssdRegTmr(tmr);
512    if (ret != ROK)
513    {
514       tmr->tmrId = 0;
515 #ifdef SS_MULTIPLE_PROCS
516       tmr->ownerProc = PROCNC;
517 #endif /* SS_MULTIPLE_PROCS */
518       tmr->ownerEnt = ENTNC;
519       tmr->ownerInst = INSTNC;
520       tmr->interval = 0;
521       /* ss015.301 Enclosed all timer activation functions in a union. */
522       tmr->ssTmrActvFn.mtFlag = FALSE;
523       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
524 #ifndef SS_MULTIPLE_PROCS
525 #ifdef SS_MT_TMR
526       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
527 #endif
528 #endif
529    }
530    else
531    {
532       tmr->used = TRUE;
533       osCp.nxtTmrEntry = tmr->nxt;
534       osCp.numTmrs++;
535    }
536
537
538    /* unlock the timer table */
539    if ( SUnlock(&osCp.tmrTblLock) != ROK)
540    {
541 #if (ERRCLASS & ERRCLS_DEBUG)
542       SSLOGERROR(ERRCLS_DEBUG, ESS542, ERRZERO,
543                      "Could not unlock the semaphore");
544       return RFAILED;
545 #endif
546    }
547
548    return (ret);
549 }
550
551
552 \f
553 /*
554 *
555 *       Fun:   SDeregCfgTmr  
556 *
557 *       Desc:  This function is used to deregister a timer function.
558 *
559 *       Ret:   ROK      - ok
560 *              RFAILED  - failed, general (optional)
561 *
562 *       Notes:
563 *
564 *       File:  ss_timer.c
565 *
566 */
567 /* ss029.103: addition: procId added and timer function type modified */ 
568 #ifndef SS_MULTIPLE_PROCS
569
570 S16 SDeregCfgTmr
571 (
572 Ent ent,                    /* entity */
573 Inst inst,                  /* instance */
574 S16 period,                 /* period */
575 S16 units,                  /* period units */
576 PFS16 tmrFnct               /* timer function */
577 )
578 {
579    S16 ret;
580    /* ss015.301 Enclosed all timer activation functions in a union. */
581    SsTmrActvFn ssTmrActvFn;
582    /* ss041.103 - Moved handling to STmrDeregHndlr */
583
584    ssTmrActvFn.mtFlag = FALSE;
585    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;  
586    ret = STmrDeregHndlr(ent, inst, period, units, ssTmrActvFn);
587
588    return (ret);
589 }
590
591 #else /* SS_MULTIPLE_PROCS */
592
593 S16 SDeregCfgTmr
594 (
595 ProcId proc,                /* processor */
596 Ent ent,                    /* entity */
597 Inst inst,                  /* instance */
598 S16 period,                 /* period */
599 S16 units,                  /* period units */
600 PAIFTMRS16 tmrFnct               /* timer function */
601 )
602 {
603    S16 ret;
604    /* ss015.301 Enclosed all timer activation functions in a union. */ 
605    SsTmrActvFn ssTmrActvFn;
606
607    /* ss041.103 - Moved handling to STmrDeregHndlr */
608
609    ssTmrActvFn.mtFlag = FALSE;
610    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;  
611    ret = STmrDeregHndlr(proc, ent, inst, period, units, ssTmrActvFn);
612
613    return (ret);
614 }
615
616 #endif /* SS_MULTIPLE_PROCS */
617
618 \f
619 /* ss041.103 - Addition to support MT timer dereg */
620 #ifndef SS_MULTIPLE_PROCS
621 #ifdef SS_MT_TMR
622 /*
623 *
624 *       Fun:   SDeregCfgTmrMt
625 *
626 *       Desc:  This function is used to deregister an MT timer function.
627 *
628 *       Ret:   ROK      - ok
629 *              RFAILED  - failed, general (optional)
630 *
631 *       Notes:
632 *
633 *       File:  ss_timer.c
634 *
635 */
636 S16 SDeregCfgTmrMt
637 (
638 Ent ent,                    /* entity */
639 Inst inst,                  /* instance */
640 S16 period,                 /* period */
641 S16 units,                  /* period units */
642 PAIFTMRS16 tmrFnctMt               /* timer function */
643 )
644 {
645    S16 ret;
646    /* ss015.301 Enclosed all timer activation functions in a union. */
647    SsTmrActvFn ssTmrActvFn;
648
649    ssTmrActvFn.actvFnc.tmrActvFnMt = tmrFnctMt;
650    ssTmrActvFn.mtFlag = TRUE;
651
652    ret = STmrDeregHndlr(ent, inst, period, units, ssTmrActvFn);
653
654    return (ret);
655 }
656 #endif /* SS_MT_TMR */
657 #endif /* not SS_MULTIPLE_PROCS */
658
659
660 /* ss041.103 - Addition of STmrDeregHndlr */
661 /*
662 *
663 *       Fun:   STmrDeregHndlr  
664 *
665 *       Desc:  This function is used to deregister a timer function.
666 *
667 *       Ret:   ROK      - ok
668 *              RFAILED  - failed, general (optional)
669 *
670 *       Notes:
671 *
672 *       File:  ss_timer.c
673 *
674 */
675 /* ss029.103: addition: procId added and timer function type modified */ 
676
677 /* ss015.301 Changed the timer activation function type as all timer activation
678  * functions are enclosed in a union.
679  */
680 #ifndef SS_MULTIPLE_PROCS
681 static S16 STmrDeregHndlr
682 (
683 Ent ent,                    /* entity */
684 Inst inst,                  /* instance */
685 S16 period,                 /* period */
686 S16 units,                  /* period units */
687 SsTmrActvFn ssTmrActvFn           /* timer function */
688 )
689 /* ss015.301: Removed the timer handler prototypes guarded under SS_MT_TMR
690  * and handled mtFlag in existing timer handlers.
691  */
692
693 #else /* SS_MULTIPLE_PROCS */
694
695 static S16 STmrDeregHndlr
696 (
697 ProcId proc,                /* processor */
698 Ent ent,                    /* entity */
699 Inst inst,                  /* instance */
700 S16 period,                 /* period */
701 S16 units,                  /* period units */
702 SsTmrActvFn ssTmrActvFn          /* timer function */
703 )
704
705 #endif /* SS_MULTIPLE_PROCS */
706 {
707    S16 ret;
708    S16 idx;
709    SsTmrEntry *tmr;
710 #ifdef SS_MULTIPLE_PROCS
711 #if (ERRCLASS & ERRCLS_INT_PAR)
712    uint16_t procIdIdx;
713 #endif /* ERRCLASS & ERRCLS_INT_PAR */
714 #endif /* SS_MULTIPLE_PROCS */
715
716
717 #if (ERRCLASS & ERRCLS_INT_PAR)
718
719 #ifdef SS_MULTIPLE_PROCS
720    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
721    {
722       SSLOGERROR(ERRCLS_INT_PAR, ESS543, ERRZERO, "Invalid processor/entity/instance");
723       return RFAILED;
724    }
725
726 #else /* SS_MULTIPLE_PROCS */
727    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
728    {
729       SSLOGERROR(ERRCLS_INT_PAR, ESS544, ERRZERO, "Invalid entity/instance");
730       return RFAILED;
731    }
732 #endif /* SS_MULTIPLE_PROCS */
733    /* check period */
734    if (period <= 0)
735    {
736       SSLOGERROR(ERRCLS_INT_PAR, ESS545, ERRZERO, "Invalid period");
737       return RFAILED;
738    }
739
740    /* check period units */
741    if ((units < 1) || (units > SS_TICKS_SEC))
742    {
743       SSLOGERROR(ERRCLS_INT_PAR, ESS546, ERRZERO, "Invalid period units");
744       return RFAILED;
745    }
746
747    /* check timer function */
748    if(ssTmrActvFn.mtFlag == TRUE)
749    {
750 #ifndef SS_MULTIPLE_PROCS
751 #ifdef SS_MT_TMR
752    if (ssTmrActvFn.actvFnc.tmrActvFnMt == NULLP)  
753    {
754       SSLOGERROR(ERRCLS_INT_PAR, ESS547, ERRZERO, "Null pointer");
755       return RFAILED;
756    }
757 #else
758     return RFAILED;
759 #endif
760 #else
761     return RFAILED;
762 #endif
763  
764    }
765    else
766    {
767    if (ssTmrActvFn.actvFnc.tmrActvFn == NULLP)  
768    {
769       SSLOGERROR(ERRCLS_INT_PAR, ESS547, ERRZERO, "Null pointer");
770       return RFAILED;
771    }
772   }
773
774 #ifdef SS_MULTIPLE_PROCS
775    /* check if the procId has been registered with SSI */
776    procIdIdx = SGetProcIdIdx(proc);
777
778    if (procIdIdx == SS_INV_PROCID_IDX)
779    {
780       SSLOGERROR(ERRCLS_INT_PAR, ESS548, ERRZERO,
781                      "Could not find proc id index");
782       return RFAILED;
783    }
784 #endif /* SS_MULTIPLE_PROCS */
785
786    /* check task ID */
787    /* lock TAPA task table */
788    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
789    if (ret != ROK)
790    {
791       SSLOGERROR(ERRCLS_DEBUG, ESS549, ERRZERO,
792                      "Could not lock TAPA task table");
793       return RFAILED;
794    }
795
796 #ifdef SS_MULTIPLE_PROCS
797    if (osCp.tTskIds[procIdIdx][ent][inst] == SS_TSKNC)
798 #else /* SS_MULTIPLE_PROCS */
799    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
800 #endif /* SS_MULTIPLE_PROCS */
801    {
802       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
803       {
804 #if (ERRCLASS & ERRCLS_DEBUG)
805          SSLOGERROR(ERRCLS_DEBUG, ESS550, ERRZERO,
806                      "Could not release the semaphore");
807          return RFAILED;
808 #endif
809       }
810       SSLOGERROR(ERRCLS_INT_PAR, ESS551, ERRZERO, "Unknown task");
811       return RFAILED;
812    }
813    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
814    {
815 #if (ERRCLASS & ERRCLS_DEBUG)
816       SSLOGERROR(ERRCLS_DEBUG, ESS552, ERRZERO,
817                      "Could not release the semaphore");
818       return RFAILED;
819 #endif
820     }
821
822 #endif
823
824    /* lock the timer table */
825    ret = SLock(&osCp.tmrTblLock);
826    if (ret != ROK)
827    {
828
829 #if (ERRCLASS & ERRCLS_DEBUG)
830       SSLOGERROR(ERRCLS_DEBUG, ESS553, (ErrVal) ret,
831                      "Could not lock timer table");
832 #endif
833       return (ret);
834    }
835
836
837    /* Note: Right now, we're using ent, inst and tmrActvFn to locate
838     *       the timer,, this will change to using tmrId, some day.
839     */
840
841    /* locate the timer to delete in the timer table */
842    for (idx = 0;  idx < SS_MAX_TMRS;  idx++)
843    {
844       /* ss021.103 - Modification find timer by ent, inst, func, and period */
845       /* ss029.103: addition: multiple procId related changes */ 
846       if (osCp.tmrTbl[idx].ownerEnt == ent
847 #ifdef SS_MULTIPLE_PROCS
848             &&  osCp.tmrTbl[idx].ownerProc == proc 
849 #endif /* SS_MULTIPLE_PROCS */
850             &&  osCp.tmrTbl[idx].ownerInst == inst
851 #ifndef SS_MULTIPLE_PROCS
852 #ifdef SS_MT_TMR
853            /*
854             *  ss015.301 - Modifed as timer activation functions
855             *  enclosed in a union. 
856             */
857             &&  osCp.tmrTbl[idx].ssTmrActvFn.mtFlag == ssTmrActvFn.mtFlag
858             && ((ssTmrActvFn.mtFlag == FALSE
859                   &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
860                || osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFnMt == ssTmrActvFn.actvFnc.tmrActvFnMt)
861 #else
862             &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn
863 #endif
864 #else
865             &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn
866 #endif
867             &&  osCp.tmrTbl[idx].interval == (uint32_t) ((period * SS_TICKS_SEC) / units))
868       {
869          break;
870       }
871    }
872
873    if (idx == SS_MAX_TMRS)
874    {
875       if ( SUnlock(&osCp.tmrTblLock) != ROK)
876       {
877 #if (ERRCLASS & ERRCLS_DEBUG)
878          SSLOGERROR(ERRCLS_DEBUG, ESS554, ERRZERO,
879                      "Could not unlock the semaphore");
880          return RFAILED;
881 #endif
882       }
883
884 #if (ERRCLASS & ERRCLS_DEBUG)
885       SSLOGERROR(ERRCLS_DEBUG, ESS555, ERRZERO, "Could not locate timer");
886 #endif
887
888       return RFAILED;
889    }
890
891
892    /* ask the implementation to shut down this timer */
893    tmr = &osCp.tmrTbl[idx];
894    ret = ssdDeregTmr(tmr);
895    if (ret == ROK)
896    {
897       tmr->used = FALSE;
898       tmr->tmrId = 0;
899 #ifdef SS_MULTIPLE_PROCS
900       tmr->ownerProc = PROCNC;
901 #endif /* SS_MULTIPLE_PROCS */
902       tmr->ownerEnt = ENTNC;
903       tmr->ownerInst = INSTNC;
904       tmr->interval = 0;
905       /*
906        *  ss015.301: Modifed as timer activation functions enclosed in a union. 
907        */
908       tmr->ssTmrActvFn.mtFlag = FALSE;
909       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
910 #ifndef SS_MULTIPLE_PROCS
911 #ifdef SS_MT_TMR
912       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
913 #endif
914 #endif
915
916       tmr->nxt = osCp.nxtTmrEntry;
917       osCp.nxtTmrEntry = (SsIdx)idx;
918       osCp.numTmrs--;
919    }
920
921
922    /* unlock the timer table */
923    if ( SUnlock(&osCp.tmrTblLock) != ROK)
924    {
925 #if (ERRCLASS & ERRCLS_DEBUG)
926       SSLOGERROR(ERRCLS_DEBUG, ESS556, ERRZERO,
927                      "Could not unlock the semaphore");
928       return RFAILED;
929 #endif
930    }
931
932
933    return (ret);
934 }
935
936 /**********************************************************************
937          End of file
938 **********************************************************************/