U8, U16, U32 data type changes
[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 PRIVATE 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 PRIVATE 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 PRIVATE 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 PRIVATE 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 #ifdef ANSI
149 S16 SRegCfgTmr
150 (
151 Ent ent,                    /* entity */
152 Inst inst,                  /* instance */
153 S16 period,                 /* period */
154 S16 units,                  /* period units */
155 PFS16 tmrFnct               /* timer function, typically SActvTmr */
156 )
157 #else
158 S16 SRegCfgTmr(ent, inst, period, units, tmrFnct)
159 Ent ent;                    /* entity */
160 Inst inst;                  /* instance */
161 S16 period;                 /* period */
162 S16 units;                  /* period units*/
163 PFS16 tmrFnct;              /* timer function, typically SActvTmr */
164 #endif
165 {
166    S16 ret;
167    /* ss015.301 - Enclosed all timer activation functions in a union. */
168    SsTmrActvFn ssTmrActvFn;
169    /* ss041.103 - Moved handling to STmrRegHndlr */
170
171    ssTmrActvFn.mtFlag = FALSE;
172    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;
173    ret = STmrRegHndlr(ent, inst, period, units, ssTmrActvFn);
174
175    return (ret);
176 }
177
178 #else /* SS_MULTIPLE_PROCS */
179
180 #ifdef ANSI
181 S16 SRegCfgTmr
182 (
183 ProcId proc,                /* processor */
184 Ent ent,                    /* entity */
185 Inst inst,                  /* instance */
186 S16 period,                 /* period */
187 S16 units,                  /* period units */
188 PAIFTMRS16 tmrFnct               /* timer function, typically SActvTmr */
189 )
190 #else
191 S16 SRegCfgTmr(proc, ent, inst, period, units, tmrFnct)
192 ProcId proc;                /* processor */
193 Ent ent;                    /* entity */
194 Inst inst;                  /* instance */
195 S16 period;                 /* period */
196 S16 units;                  /* period units*/
197 PAIFTMRS16 tmrFnct;              /* timer function, typically SActvTmr */
198 #endif
199
200 {
201    S16 ret;
202    /* ss015.301 - Enclosed all timer activation functions in a union. */
203    SsTmrActvFn ssTmrActvFn;
204    /* ss041.103 - Moved handling to STmrRegHndlr */
205
206    ssTmrActvFn.mtFlag = FALSE;
207    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;
208    ret = STmrRegHndlr(proc, ent, inst, period, units, ssTmrActvFn);
209
210    return (ret);
211 }
212
213 #endif /* SS_MULTIPLE_PROCS */
214
215 \f
216 #ifndef SS_MULTIPLE_PROCS
217 /* ss041.103 - New function for MT timer reg */
218 #ifdef SS_MT_TMR
219 /*
220 *
221 *       Fun:   Register Configurable Timer Task - timer
222 *
223 *       Desc:  This function is used to register a timer function for the
224 *              layer. The system services will periodically invoke the
225 *              function passed to it. The timer function will be used by the
226 *              layer to manage the layers internal protocol timers.
227 *
228 *       Ret:   ROK      - ok
229 *              RFAILED  - failed, general (optional)
230 *              ROUTRES  - failed, out of resources (optional)
231 *
232 *       Notes: By invoking this function, Ent and Inst are passed in the
233 *              timer activation function.
234 *
235 *       File:  ss_timer.c
236 *
237 */
238 #ifdef ANSI
239 S16 SRegCfgTmrMt
240 (
241 Ent ent,                    /* entity */
242 Inst inst,                  /* instance */
243 S16 period,                 /* period */
244 S16 units,                  /* period units */
245 PAIFTMRS16 tmrFnctMt        /* timer function, typically SActvTmr */
246 )
247 #else
248 S16 SRegCfgTmrMt(ent, inst, period, units, tmrFnctMt)
249 Ent ent;                    /* entity */
250 Inst inst;                  /* instance */
251 S16 period;                 /* period */
252 S16 units;                  /* period units*/
253 PAIFTMRS16 tmrFnctMt;       /* timer function, typically SActvTmr */
254 #endif
255 {
256    S16 ret;
257    /* ss015.301 - Enclosed all timer activation functions in a union. */
258    SsTmrActvFn ssTmrActvFn;
259
260    ssTmrActvFn.actvFnc.tmrActvFnMt = tmrFnctMt;
261    ssTmrActvFn.mtFlag = TRUE;
262    ret = STmrRegHndlr(ent, inst, period, units, ssTmrActvFn);
263
264    return (ret);
265 }
266 #endif /* SS_MT_TMR */
267 #endif /* not SS_MULTIPLE_PROCS */
268
269 /* ss041.103 - Function for timer registration handling */
270 /*
271 *
272 *       Fun:   Timer registration handler function
273 *
274 *       Desc:  This function is called by the timer registration interface
275 *              functions, and does the actual handling for timer
276 *              registration.
277 *
278 *       Ret:   ROK      - ok
279 *              RFAILED  - failed, general (optional)
280 *              ROUTRES  - failed, out of resources (optional)
281 *
282 *       Notes:
283 *
284 *       File:  ss_timer.c
285 *
286 */
287
288 /* ss015.301 Changed the timer activation function type as all timer activation
289  * functions are enclosed in a union.
290  */
291
292 #ifndef SS_MULTIPLE_PROCS
293
294 #ifdef ANSI
295 PRIVATE S16 STmrRegHndlr
296 (
297 Ent ent,                    /* entity */
298 Inst inst,                  /* instance */
299 S16 period,                 /* period */
300 S16 units,                  /* period units */
301 SsTmrActvFn ssTmrActvFn               /* timer function, typically SActvTmr */
302 )
303 #else
304 PRIVATE S16 STmrRegHndlr(ent, inst, period, units, ssTmrActvFn)
305 Ent ent;                    /* entity */
306 Inst inst;                  /* instance */
307 S16 period;                 /* period */
308 S16 units;                  /* period units*/
309 SsTmrActvFn ssTmrActvFn;              /* timer function, typically SActvTmr */
310 #endif
311 /* ss015.301: Removed the timer handler prototypes guarded
312  * under SS_MT_TMR and handled mtFlag in existing timer handlers.
313  */
314
315 #else /* SS_MULTIPLE_PROCS */
316
317 #ifdef ANSI
318 PRIVATE S16 STmrRegHndlr
319 (
320 ProcId proc,                /* processor */
321 Ent ent,                    /* entity */
322 Inst inst,                  /* instance */
323 S16 period,                 /* period */
324 S16 units,                  /* period units */
325 SsTmrActvFn ssTmrActvFn     /* timer function */
326 )
327 #else
328 PRIVATE S16 STmrRegHndlr(proc, ent, inst, period, units, ssTmrActvFn)
329 ProcId proc;                /* processor */
330 Ent ent;                    /* entity */
331 Inst inst;                  /* instance */
332 S16 period;                 /* period */
333 S16 units;                  /* period units*/
334 SsTmrActvFn ssTmrActvFn;         /* timer function */
335 #endif
336
337 #endif /* SS_MULTIPLE_PROCS */
338 {
339 #if (ERRCLASS & ERRCLS_INT_PAR)
340    uint8_t i;
341 #endif
342    S16 ret;
343    SsTmrEntry *tmr;
344 #ifdef SS_MULTIPLE_PROCS
345 #if (ERRCLASS & ERRCLS_INT_PAR)
346    uint16_t procIdIdx;
347 #endif /* ERRCLASS & ERRCLS_INT_PAR */
348 #endif /* SS_MULTPLE_PROCS */
349
350 #if (ERRCLASS & ERRCLS_INT_PAR)
351
352 #ifdef SS_MULTIPLE_PROCS
353    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
354    {
355       SSLOGERROR(ERRCLS_INT_PAR, ESS528, ERRZERO, "Invalid processor/entity/instance");
356       return RFAILED;
357    }
358 #else /* SS_MULTIPLE_PROCS */
359    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
360    {
361       SSLOGERROR(ERRCLS_INT_PAR, ESS529, ERRZERO, "Invalid entity/instance");
362       return RFAILED;
363    }
364 #endif /* SS_MULTIPLE_PROCS */
365
366    /* check period */
367    if (period <= 0)
368    {
369       SSLOGERROR(ERRCLS_INT_PAR, ESS530, ERRZERO, "Invalid period");
370       return RFAILED;
371    }
372
373    /* check period units*/
374    if ((units < 1) || (units > SS_TICKS_SEC))
375    {
376       SSLOGERROR(ERRCLS_INT_PAR, ESS531, ERRZERO, "Invalid period units");
377       return RFAILED;
378    }
379
380    if(ssTmrActvFn.mtFlag == TRUE) 
381    { 
382    /* ss015.301 Enclosed all timer activation functions in a union. */
383 #ifndef SS_MULTIPLE_PROCS
384 #ifdef SS_MT_TMR
385       if (ssTmrActvFn.actvFnc.tmrActvFnMt == NULLP)  
386       {
387          SSLOGERROR(ERRCLS_INT_PAR, ESS532, ERRZERO, "Null pointer");
388          return RFAILED;
389       }
390 #else
391       return RFAILED;
392 #endif
393 #else
394       return RFAILED;
395 #endif
396    }
397    else
398    { 
399       if (ssTmrActvFn.actvFnc.tmrActvFn == NULLP)  
400       {
401           SSLOGERROR(ERRCLS_INT_PAR, ESS532, ERRZERO, "Null pointer");
402           return RFAILED;
403       }
404    } 
405
406 #ifdef SS_MULTIPLE_PROCS
407    /* check if the procId has been registered with SSI */
408    procIdIdx = SGetProcIdIdx(proc);
409
410    if (procIdIdx == SS_INV_PROCID_IDX)
411    {
412       SSLOGERROR(ERRCLS_INT_PAR, ESS533, ERRZERO,
413                      "Could not find proc id index");
414       return RFAILED;
415    }
416 #endif /* SS_MULTIPLE_PROCS */
417
418
419    /* check task ID */
420    /* lock TAPA task table */
421    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
422    if (ret != ROK)
423    {
424       SSLOGERROR(ERRCLS_DEBUG, ESS534, ERRZERO,
425                      "Could not lock TAPA task table");
426       return RFAILED;
427    }
428
429 #ifdef SS_MULTIPLE_PROCS
430    if (osCp.tTskIds[procIdIdx][ent][inst] == SS_TSKNC)
431 #else /* SS_MULTIPLE_PROCS */
432    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
433 #endif /* SS_MULTIPLE_PROCS */
434    {
435       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
436       {
437 #if (ERRCLASS & ERRCLS_DEBUG)
438       SSLOGERROR(ERRCLS_DEBUG, ESS535, ERRZERO,
439                      "Could not release the semaphore");
440       return RFAILED;
441 #endif
442       }
443       SSLOGERROR(ERRCLS_INT_PAR, ESS536, ERRZERO, "Unknown task");
444       return RFAILED;
445    }
446    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
447    {
448 #if (ERRCLASS & ERRCLS_DEBUG)
449       SSLOGERROR(ERRCLS_DEBUG, ESS537, ERRZERO,
450                      "Could not release the semaphore");
451    return RFAILED;
452 #endif
453    }
454
455 #endif
456
457    /* lock the timer table */
458    ret = SLock(&osCp.tmrTblLock);
459    if (ret != ROK)
460    {
461
462 #if (ERRCLASS & ERRCLS_DEBUG)
463       SSLOGERROR(ERRCLS_DEBUG, ESS538, (ErrVal) ret,
464                      "Could not lock timer table");
465 #endif
466       return (ret);
467    }
468
469
470    /* check if we've got room for another timer */
471    if (osCp.numTmrs == SS_MAX_TMRS)
472    {
473       if ( SUnlock(&osCp.tmrTblLock) != ROK)
474       {
475 #if (ERRCLASS & ERRCLS_DEBUG)
476          SSLOGERROR(ERRCLS_DEBUG, ESS539, ERRZERO,
477                      "Could not unlock the semaphore");
478          return RFAILED;
479 #endif
480       }
481
482 #if (ERRCLASS & ERRCLS_DEBUG)
483       SSLOGERROR(ERRCLS_DEBUG, ESS540, ERRZERO, "Too many timers");
484 #endif
485
486       return (ROUTRES);
487    }
488
489 #if (ERRCLASS & ERRCLS_INT_PAR)
490    /* check through the timer table for a matching timer entry */
491    for (i = 0; i < SS_MAX_TMRS; i++)
492    {   
493       if ((osCp.tmrTbl[i].ownerEnt == ent)
494 #ifdef SS_MULTIPLE_PROCS
495             &&  (osCp.tmrTbl[i].ownerProc == proc)
496 #endif /* SS_MULTIPLE_PROCS */
497             && (osCp.tmrTbl[i].ownerInst == inst)
498             /* ss041.103 - Added mtFlag check */
499             /* ss015.301 Enclosed all timer activation functions in a union. */
500 #ifndef SS_MULTIPLE_PROCS
501 #ifdef SS_MT_TMR
502             && (osCp.tmrTbl[i].ssTmrActvFn.mtFlag == ssTmrActvFn.mtFlag)
503             && ((ssTmrActvFn.mtFlag == FALSE
504                   && osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)  
505                || osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFnMt == ssTmrActvFn.actvFnc.tmrActvFnMt)
506 #else
507             && (osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
508 #endif
509 #else
510             && (osCp.tmrTbl[i].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
511 #endif
512             && (osCp.tmrTbl[i].interval == (uint32_t) ((period * SS_TICKS_SEC) / units)))
513       {
514          /* is this timer in use ? (unexpired) */
515          if (osCp.tmrTbl[i].used == TRUE)
516          {  
517             /* to prevent the same timer to be registered with SS  UNLOCK and */
518             /* then RFAIL */
519             if (SUnlock(&osCp.tmrTblLock) != ROK)
520             {
521 #if (ERRCLASS & ERRCLS_DEBUG)
522    SSLOGERROR(ERRCLS_DEBUG, ESS541, ERRZERO, "Could not unlock the semaphore");
523    return RFAILED;
524 #endif
525             }
526             return RFAILED;
527          }
528       }
529    }
530 #endif
531
532    /* fill in the information we have into the timer entry */
533    tmr = &osCp.tmrTbl[osCp.nxtTmrEntry];
534    tmr->tmrId     = osCp.nxtTmrEntry;
535 #ifdef SS_MULTIPLE_PROCS
536    tmr->ownerProc = proc;
537 #endif /* SS_MULTIPLE_PROCS */
538    tmr->ownerEnt  = ent;
539    tmr->ownerInst = inst;
540    tmr->interval  = (uint32_t) ((period * SS_TICKS_SEC) / units);
541    tmr->ssTmrActvFn.mtFlag = ssTmrActvFn.mtFlag;
542
543    /* ss041.103 */
544    /* ss015.301 Enclosed all timer activation functions in a union. */
545 #ifndef SS_MULTIPLE_PROCS
546 #ifdef SS_MT_TMR
547    if (ssTmrActvFn.mtFlag == TRUE)
548    {
549       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = ssTmrActvFn.actvFnc.tmrActvFnMt;  
550    }
551    else
552 #endif
553 #endif
554    {
555       tmr->ssTmrActvFn.actvFnc.tmrActvFn = ssTmrActvFn.actvFnc.tmrActvFn;
556    }
557
558
559    /* ask the implementation to start the timer */
560    ret = ssdRegTmr(tmr);
561    if (ret != ROK)
562    {
563       tmr->tmrId = 0;
564 #ifdef SS_MULTIPLE_PROCS
565       tmr->ownerProc = PROCNC;
566 #endif /* SS_MULTIPLE_PROCS */
567       tmr->ownerEnt = ENTNC;
568       tmr->ownerInst = INSTNC;
569       tmr->interval = 0;
570       /* ss015.301 Enclosed all timer activation functions in a union. */
571       tmr->ssTmrActvFn.mtFlag = FALSE;
572       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
573 #ifndef SS_MULTIPLE_PROCS
574 #ifdef SS_MT_TMR
575       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
576 #endif
577 #endif
578    }
579    else
580    {
581       tmr->used = TRUE;
582       osCp.nxtTmrEntry = tmr->nxt;
583       osCp.numTmrs++;
584    }
585
586
587    /* unlock the timer table */
588    if ( SUnlock(&osCp.tmrTblLock) != ROK)
589    {
590 #if (ERRCLASS & ERRCLS_DEBUG)
591       SSLOGERROR(ERRCLS_DEBUG, ESS542, ERRZERO,
592                      "Could not unlock the semaphore");
593       return RFAILED;
594 #endif
595    }
596
597    return (ret);
598 }
599
600
601 \f
602 /*
603 *
604 *       Fun:   SDeregCfgTmr  
605 *
606 *       Desc:  This function is used to deregister a timer function.
607 *
608 *       Ret:   ROK      - ok
609 *              RFAILED  - failed, general (optional)
610 *
611 *       Notes:
612 *
613 *       File:  ss_timer.c
614 *
615 */
616 /* ss029.103: addition: procId added and timer function type modified */ 
617 #ifndef SS_MULTIPLE_PROCS
618
619 #ifdef ANSI
620 S16 SDeregCfgTmr
621 (
622 Ent ent,                    /* entity */
623 Inst inst,                  /* instance */
624 S16 period,                 /* period */
625 S16 units,                  /* period units */
626 PFS16 tmrFnct               /* timer function */
627 )
628 #else
629 S16 SDeregCfgTmr(ent, inst, period, units, tmrFnct)
630 Ent ent;                    /* entity */
631 Inst inst;                  /* instance */
632 S16 period;                 /* period */
633 S16 units;                  /* period units*/
634 PFS16 tmrFnct;              /* timer function */
635 #endif
636 {
637    S16 ret;
638    /* ss015.301 Enclosed all timer activation functions in a union. */
639    SsTmrActvFn ssTmrActvFn;
640    /* ss041.103 - Moved handling to STmrDeregHndlr */
641
642    ssTmrActvFn.mtFlag = FALSE;
643    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;  
644    ret = STmrDeregHndlr(ent, inst, period, units, ssTmrActvFn);
645
646    return (ret);
647 }
648
649 #else /* SS_MULTIPLE_PROCS */
650
651 #ifdef ANSI
652 S16 SDeregCfgTmr
653 (
654 ProcId proc,                /* processor */
655 Ent ent,                    /* entity */
656 Inst inst,                  /* instance */
657 S16 period,                 /* period */
658 S16 units,                  /* period units */
659 PAIFTMRS16 tmrFnct               /* timer function */
660 )
661 #else
662 S16 SDeregCfgTmr(proc, ent, inst, period, units, tmrFnct)
663 ProcId proc;                /* processor */
664 Ent ent;                    /* entity */
665 Inst inst;                  /* instance */
666 S16 period;                 /* period */
667 S16 units;                  /* period units*/
668 PAIFTMRS16 tmrFnct;              /* timer function */
669 #endif
670 {
671    S16 ret;
672    /* ss015.301 Enclosed all timer activation functions in a union. */ 
673    SsTmrActvFn ssTmrActvFn;
674
675    /* ss041.103 - Moved handling to STmrDeregHndlr */
676
677    ssTmrActvFn.mtFlag = FALSE;
678    ssTmrActvFn.actvFnc.tmrActvFn = tmrFnct;  
679    ret = STmrDeregHndlr(proc, ent, inst, period, units, ssTmrActvFn);
680
681    return (ret);
682 }
683
684 #endif /* SS_MULTIPLE_PROCS */
685
686 \f
687 /* ss041.103 - Addition to support MT timer dereg */
688 #ifndef SS_MULTIPLE_PROCS
689 #ifdef SS_MT_TMR
690 /*
691 *
692 *       Fun:   SDeregCfgTmrMt
693 *
694 *       Desc:  This function is used to deregister an MT timer function.
695 *
696 *       Ret:   ROK      - ok
697 *              RFAILED  - failed, general (optional)
698 *
699 *       Notes:
700 *
701 *       File:  ss_timer.c
702 *
703 */
704 #ifdef ANSI
705 S16 SDeregCfgTmrMt
706 (
707 Ent ent,                    /* entity */
708 Inst inst,                  /* instance */
709 S16 period,                 /* period */
710 S16 units,                  /* period units */
711 PAIFTMRS16 tmrFnctMt               /* timer function */
712 )
713 #else
714 S16 SDeregCfgTmrMt(ent, inst, period, units, tmrFnctMt)
715 Ent ent;                    /* entity */
716 Inst inst;                  /* instance */
717 S16 period;                 /* period */
718 S16 units;                  /* period units*/
719 PAIFTMRS16 tmrFnctMt;              /* timer function */
720 #endif
721 {
722    S16 ret;
723    /* ss015.301 Enclosed all timer activation functions in a union. */
724    SsTmrActvFn ssTmrActvFn;
725
726    ssTmrActvFn.actvFnc.tmrActvFnMt = tmrFnctMt;
727    ssTmrActvFn.mtFlag = TRUE;
728
729    ret = STmrDeregHndlr(ent, inst, period, units, ssTmrActvFn);
730
731    return (ret);
732 }
733 #endif /* SS_MT_TMR */
734 #endif /* not SS_MULTIPLE_PROCS */
735
736
737 /* ss041.103 - Addition of STmrDeregHndlr */
738 /*
739 *
740 *       Fun:   STmrDeregHndlr  
741 *
742 *       Desc:  This function is used to deregister a timer function.
743 *
744 *       Ret:   ROK      - ok
745 *              RFAILED  - failed, general (optional)
746 *
747 *       Notes:
748 *
749 *       File:  ss_timer.c
750 *
751 */
752 /* ss029.103: addition: procId added and timer function type modified */ 
753
754 /* ss015.301 Changed the timer activation function type as all timer activation
755  * functions are enclosed in a union.
756  */
757 #ifndef SS_MULTIPLE_PROCS
758 #ifdef ANSI
759 PRIVATE S16 STmrDeregHndlr
760 (
761 Ent ent,                    /* entity */
762 Inst inst,                  /* instance */
763 S16 period,                 /* period */
764 S16 units,                  /* period units */
765 SsTmrActvFn ssTmrActvFn           /* timer function */
766 )
767 #else
768 /* ss017.301: Modified the prototype of STmrDeregHndlr for Non-ANSI
769  * compilation.
770  */
771 PRIVATE S16 STmrDeregHndlr(ent, inst, period, units, ssTmrActvFn)
772 Ent ent;                    /* entity */
773 Inst inst;                  /* instance */
774 S16 period;                 /* period */
775 S16 units;                  /* period units*/
776 SsTmrActvFn ssTmrActvFn;          /* timer function */
777 #endif
778 /* ss015.301: Removed the timer handler prototypes guarded under SS_MT_TMR
779  * and handled mtFlag in existing timer handlers.
780  */
781
782 #else /* SS_MULTIPLE_PROCS */
783
784 #ifdef ANSI
785 PRIVATE S16 STmrDeregHndlr
786 (
787 ProcId proc,                /* processor */
788 Ent ent,                    /* entity */
789 Inst inst,                  /* instance */
790 S16 period,                 /* period */
791 S16 units,                  /* period units */
792 SsTmrActvFn ssTmrActvFn          /* timer function */
793 )
794 #else
795 PRIVATE S16 STmrDeregHndlr(proc, ent, inst, period, units, ssTmrActvFn)
796 ProcId proc;                /* processor */
797 Ent ent;                    /* entity */
798 Inst inst;                  /* instance */
799 S16 period;                 /* period */
800 S16 units;                  /* period units*/
801 SsTmrActvFn ssTmrActvFn;         /* timer function */
802 #endif
803
804 #endif /* SS_MULTIPLE_PROCS */
805 {
806    S16 ret;
807    S16 idx;
808    SsTmrEntry *tmr;
809 #ifdef SS_MULTIPLE_PROCS
810 #if (ERRCLASS & ERRCLS_INT_PAR)
811    uint16_t procIdIdx;
812 #endif /* ERRCLASS & ERRCLS_INT_PAR */
813 #endif /* SS_MULTIPLE_PROCS */
814
815
816 #if (ERRCLASS & ERRCLS_INT_PAR)
817
818 #ifdef SS_MULTIPLE_PROCS
819    if ((proc == SS_INV_PROCID) || (ent >= SS_MAX_ENT) ||  (inst >= SS_MAX_INST))
820    {
821       SSLOGERROR(ERRCLS_INT_PAR, ESS543, ERRZERO, "Invalid processor/entity/instance");
822       return RFAILED;
823    }
824
825 #else /* SS_MULTIPLE_PROCS */
826    if (ent >= SS_MAX_ENT ||  inst >= SS_MAX_INST)
827    {
828       SSLOGERROR(ERRCLS_INT_PAR, ESS544, ERRZERO, "Invalid entity/instance");
829       return RFAILED;
830    }
831 #endif /* SS_MULTIPLE_PROCS */
832    /* check period */
833    if (period <= 0)
834    {
835       SSLOGERROR(ERRCLS_INT_PAR, ESS545, ERRZERO, "Invalid period");
836       return RFAILED;
837    }
838
839    /* check period units */
840    if ((units < 1) || (units > SS_TICKS_SEC))
841    {
842       SSLOGERROR(ERRCLS_INT_PAR, ESS546, ERRZERO, "Invalid period units");
843       return RFAILED;
844    }
845
846    /* check timer function */
847    if(ssTmrActvFn.mtFlag == TRUE)
848    {
849 #ifndef SS_MULTIPLE_PROCS
850 #ifdef SS_MT_TMR
851    if (ssTmrActvFn.actvFnc.tmrActvFnMt == NULLP)  
852    {
853       SSLOGERROR(ERRCLS_INT_PAR, ESS547, ERRZERO, "Null pointer");
854       return RFAILED;
855    }
856 #else
857     return RFAILED;
858 #endif
859 #else
860     return RFAILED;
861 #endif
862  
863    }
864    else
865    {
866    if (ssTmrActvFn.actvFnc.tmrActvFn == NULLP)  
867    {
868       SSLOGERROR(ERRCLS_INT_PAR, ESS547, ERRZERO, "Null pointer");
869       return RFAILED;
870    }
871   }
872
873 #ifdef SS_MULTIPLE_PROCS
874    /* check if the procId has been registered with SSI */
875    procIdIdx = SGetProcIdIdx(proc);
876
877    if (procIdIdx == SS_INV_PROCID_IDX)
878    {
879       SSLOGERROR(ERRCLS_INT_PAR, ESS548, ERRZERO,
880                      "Could not find proc id index");
881       return RFAILED;
882    }
883 #endif /* SS_MULTIPLE_PROCS */
884
885    /* check task ID */
886    /* lock TAPA task table */
887    SS_ACQUIRE_SEMA(&osCp.tTskTblSem, ret);
888    if (ret != ROK)
889    {
890       SSLOGERROR(ERRCLS_DEBUG, ESS549, ERRZERO,
891                      "Could not lock TAPA task table");
892       return RFAILED;
893    }
894
895 #ifdef SS_MULTIPLE_PROCS
896    if (osCp.tTskIds[procIdIdx][ent][inst] == SS_TSKNC)
897 #else /* SS_MULTIPLE_PROCS */
898    if (osCp.tTskIds[ent][inst] == SS_TSKNC)
899 #endif /* SS_MULTIPLE_PROCS */
900    {
901       if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
902       {
903 #if (ERRCLASS & ERRCLS_DEBUG)
904          SSLOGERROR(ERRCLS_DEBUG, ESS550, ERRZERO,
905                      "Could not release the semaphore");
906          return RFAILED;
907 #endif
908       }
909       SSLOGERROR(ERRCLS_INT_PAR, ESS551, ERRZERO, "Unknown task");
910       return RFAILED;
911    }
912    if ( SS_RELEASE_SEMA(&osCp.tTskTblSem) != ROK)
913    {
914 #if (ERRCLASS & ERRCLS_DEBUG)
915       SSLOGERROR(ERRCLS_DEBUG, ESS552, ERRZERO,
916                      "Could not release the semaphore");
917       return RFAILED;
918 #endif
919     }
920
921 #endif
922
923    /* lock the timer table */
924    ret = SLock(&osCp.tmrTblLock);
925    if (ret != ROK)
926    {
927
928 #if (ERRCLASS & ERRCLS_DEBUG)
929       SSLOGERROR(ERRCLS_DEBUG, ESS553, (ErrVal) ret,
930                      "Could not lock timer table");
931 #endif
932       return (ret);
933    }
934
935
936    /* Note: Right now, we're using ent, inst and tmrActvFn to locate
937     *       the timer,, this will change to using tmrId, some day.
938     */
939
940    /* locate the timer to delete in the timer table */
941    for (idx = 0;  idx < SS_MAX_TMRS;  idx++)
942    {
943       /* ss021.103 - Modification find timer by ent, inst, func, and period */
944       /* ss029.103: addition: multiple procId related changes */ 
945       if (osCp.tmrTbl[idx].ownerEnt == ent
946 #ifdef SS_MULTIPLE_PROCS
947             &&  osCp.tmrTbl[idx].ownerProc == proc 
948 #endif /* SS_MULTIPLE_PROCS */
949             &&  osCp.tmrTbl[idx].ownerInst == inst
950 #ifndef SS_MULTIPLE_PROCS
951 #ifdef SS_MT_TMR
952            /*
953             *  ss015.301 - Modifed as timer activation functions
954             *  enclosed in a union. 
955             */
956             &&  osCp.tmrTbl[idx].ssTmrActvFn.mtFlag == ssTmrActvFn.mtFlag
957             && ((ssTmrActvFn.mtFlag == FALSE
958                   &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn)
959                || osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFnMt == ssTmrActvFn.actvFnc.tmrActvFnMt)
960 #else
961             &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn
962 #endif
963 #else
964             &&  osCp.tmrTbl[idx].ssTmrActvFn.actvFnc.tmrActvFn == ssTmrActvFn.actvFnc.tmrActvFn
965 #endif
966             &&  osCp.tmrTbl[idx].interval == (uint32_t) ((period * SS_TICKS_SEC) / units))
967       {
968          break;
969       }
970    }
971
972    if (idx == SS_MAX_TMRS)
973    {
974       if ( SUnlock(&osCp.tmrTblLock) != ROK)
975       {
976 #if (ERRCLASS & ERRCLS_DEBUG)
977          SSLOGERROR(ERRCLS_DEBUG, ESS554, ERRZERO,
978                      "Could not unlock the semaphore");
979          return RFAILED;
980 #endif
981       }
982
983 #if (ERRCLASS & ERRCLS_DEBUG)
984       SSLOGERROR(ERRCLS_DEBUG, ESS555, ERRZERO, "Could not locate timer");
985 #endif
986
987       return RFAILED;
988    }
989
990
991    /* ask the implementation to shut down this timer */
992    tmr = &osCp.tmrTbl[idx];
993    ret = ssdDeregTmr(tmr);
994    if (ret == ROK)
995    {
996       tmr->used = FALSE;
997       tmr->tmrId = 0;
998 #ifdef SS_MULTIPLE_PROCS
999       tmr->ownerProc = PROCNC;
1000 #endif /* SS_MULTIPLE_PROCS */
1001       tmr->ownerEnt = ENTNC;
1002       tmr->ownerInst = INSTNC;
1003       tmr->interval = 0;
1004       /*
1005        *  ss015.301: Modifed as timer activation functions enclosed in a union. 
1006        */
1007       tmr->ssTmrActvFn.mtFlag = FALSE;
1008       tmr->ssTmrActvFn.actvFnc.tmrActvFn = NULLP;
1009 #ifndef SS_MULTIPLE_PROCS
1010 #ifdef SS_MT_TMR
1011       tmr->ssTmrActvFn.actvFnc.tmrActvFnMt = NULLP;
1012 #endif
1013 #endif
1014
1015       tmr->nxt = osCp.nxtTmrEntry;
1016       osCp.nxtTmrEntry = (SsIdx)idx;
1017       osCp.numTmrs--;
1018    }
1019
1020
1021    /* unlock the timer table */
1022    if ( SUnlock(&osCp.tmrTblLock) != ROK)
1023    {
1024 #if (ERRCLASS & ERRCLS_DEBUG)
1025       SSLOGERROR(ERRCLS_DEBUG, ESS556, ERRZERO,
1026                      "Could not unlock the semaphore");
1027       return RFAILED;
1028 #endif
1029    }
1030
1031
1032    return (ret);
1033 }
1034
1035 /**********************************************************************
1036          End of file
1037 **********************************************************************/