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