comparison nucleus/tmf.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*************************************************************************/
2 /* */
3 /* Copyright Mentor Graphics Corporation 2002 */
4 /* All Rights Reserved. */
5 /* */
6 /* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS */
7 /* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS */
8 /* SUBJECT TO LICENSE TERMS. */
9 /* */
10 /*************************************************************************/
11
12 /*************************************************************************/
13 /* */
14 /* FILE NAME VERSION */
15 /* */
16 /* tmf.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* TM - Timer Management */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains information (fact) routines for the Timer */
25 /* Management component. */
26 /* */
27 /* DATA STRUCTURES */
28 /* */
29 /* None */
30 /* */
31 /* FUNCTIONS */
32 /* */
33 /* TMF_Established_Timers Number of established timers */
34 /* TMF_Timer_Pointers Return list of application */
35 /* timer pointers */
36 /* TMF_Timer_Information Return information about the */
37 /* application timer */
38 /* */
39 /* TMF_Get_Remaining_Time Return remaining timer until */
40 /* a timer expires */
41 /* */
42 /* DEPENDENCIES */
43 /* */
44 /* cs_extr.h Common Service functions */
45 /* tc_extr.h Thread Control functions */
46 /* tm_extr.h Timer functions */
47 /* hi_extr.h History functions */
48 /* */
49 /* HISTORY */
50 /* */
51 /* DATE REMARKS */
52 /* */
53 /* 03-01-1994 Created initial version 1.1 from */
54 /* previous version of TMC.C */
55 /* */
56 /* 03-18-1994 Verified version 1.1 */
57 /* 04-17-1996 updated to version 1.2 */
58 /* 11-18-1996 Protected Informational service */
59 /* from NULL Control Block pointers */
60 /* creating 1.2a. (SPR220) */
61 /* 03-24-1998 Released version 1.3 */
62 /* 03-26-1999 Released 1.11m (new release */
63 /* numbering scheme) */
64 /* 04-17-2002 Released version 1.13m */
65 /* 11-07-2002 Released version 1.14 */
66 /*************************************************************************/
67 #define NU_SOURCE_FILE
68
69
70 #include "cs_extr.h" /* Common service functions */
71 #include "tc_extr.h" /* Thread control functions */
72 #include "tm_extr.h" /* Timer functions */
73 #include "hi_extr.h" /* History functions */
74
75
76 /* Define external inner-component global data references. */
77
78 extern CS_NODE *TMD_Created_Timers_List;
79 extern UNSIGNED TMD_Total_Timers;
80 extern TM_TCB *TMD_Active_Timers_List;
81 extern INT TMD_Active_List_Busy;
82 extern TC_PROTECT TMD_Created_List_Protect;
83
84
85
86 /*************************************************************************/
87 /* */
88 /* FUNCTION */
89 /* */
90 /* TMF_Established_Timers */
91 /* */
92 /* DESCRIPTION */
93 /* */
94 /* This function returns the current number of established */
95 /* timers. Timers previously deleted are no longer considered */
96 /* established. */
97 /* */
98 /* CALLED BY */
99 /* */
100 /* Application */
101 /* */
102 /* CALLS */
103 /* */
104 /* [TCT_Check_Stack] Stack checking function */
105 /* */
106 /* INPUTS */
107 /* */
108 /* None */
109 /* */
110 /* OUTPUTS */
111 /* */
112 /* TMD_Total_Timers Number of established */
113 /* timers */
114 /* */
115 /* HISTORY */
116 /* */
117 /* DATE REMARKS */
118 /* */
119 /* 03-01-1993 Created initial version 1.0 */
120 /* 04-19-1993 Verified version 1.0 */
121 /* 03-01-1994 Changed function interface, */
122 /* resulting in version 1.1 */
123 /* */
124 /* 03-18-1994 Verified version 1.1 */
125 /* */
126 /*************************************************************************/
127 UNSIGNED TMF_Established_Timers(VOID)
128 {
129
130
131 #ifdef NU_ENABLE_STACK_CHECK
132
133 /* Call stack checking function to check for an overflow condition. */
134 TCT_Check_Stack();
135
136 #endif
137
138 /* Return the number of established timers. */
139 return(TMD_Total_Timers);
140 }
141
142
143 /*************************************************************************/
144 /* */
145 /* FUNCTION */
146 /* */
147 /* TMF_Timer_Pointers */
148 /* */
149 /* DESCRIPTION */
150 /* */
151 /* This function builds a list of timer pointers, starting at the */
152 /* specified location. The number of timer pointers placed in */
153 /* the list is equivalent to the total number of timers or the */
154 /* maximum number of pointers specified in the call. */
155 /* */
156 /* CALLED BY */
157 /* */
158 /* Application */
159 /* */
160 /* CALLS */
161 /* */
162 /* [TCT_Check_Stack] Stack checking function */
163 /* TCT_Protect Protect created list */
164 /* TCT_Unprotect Release protection */
165 /* */
166 /* INPUTS */
167 /* */
168 /* pointer_list Pointer to the list area */
169 /* maximum_pointers Maximum number of pointers */
170 /* */
171 /* OUTPUTS */
172 /* */
173 /* pointers Number of timers placed */
174 /* in the list */
175 /* HISTORY */
176 /* */
177 /* DATE REMARKS */
178 /* */
179 /* 03-01-1993 Created initial version 1.0 */
180 /* 04-19-1993 Verified version 1.0 */
181 /* 08-09-1993 Corrected problem in pointer */
182 /* retrieval loop, resulting in */
183 /* version 1.0a */
184 /* 08-09-1993 Verified version 1.0a */
185 /* 03-01-1994 Changed function interface, */
186 /* resulting in version 1.1 */
187 /* */
188 /* 03-18-1994 Verified version 1.1 */
189 /* */
190 /*************************************************************************/
191 UNSIGNED TMF_Timer_Pointers(NU_TIMER **pointer_list,
192 UNSIGNED maximum_pointers)
193 {
194
195 CS_NODE *node_ptr; /* Pointer to each TCB */
196 UNSIGNED pointers; /* Number of pointers in list*/
197 NU_SUPERV_USER_VARIABLES
198
199 /* Switch to supervisor mode */
200 NU_SUPERVISOR_MODE();
201
202 #ifdef NU_ENABLE_STACK_CHECK
203
204 /* Call stack checking function to check for an overflow condition. */
205 TCT_Check_Stack();
206
207 #endif
208
209 /* Initialize the number of pointers returned. */
210 pointers = 0;
211
212 /* Protect against access to the list of created timers. */
213 TCT_Protect(&TMD_Created_List_Protect);
214
215 /* Loop until all timer pointers are in the list or until the maximum
216 list size is reached. */
217 node_ptr = TMD_Created_Timers_List;
218 while ((node_ptr) && (pointers < maximum_pointers))
219 {
220
221 /* Place the node into the destination list. */
222 *pointer_list++ = (NU_TIMER *) node_ptr;
223
224 /* Increment the pointers variable. */
225 pointers++;
226
227 /* Position the node pointer to the next node. */
228 node_ptr = node_ptr -> cs_next;
229
230 /* Determine if the pointer is at the head of the list. */
231 if (node_ptr == TMD_Created_Timers_List)
232
233 /* The list search is complete. */
234 node_ptr = NU_NULL;
235 }
236
237 /* Release protection against access to the list of created timers. */
238 TCT_Unprotect();
239
240 /* Return to user mode */
241 NU_USER_MODE();
242
243 /* Return the number of pointers in the list. */
244 return(pointers);
245 }
246
247
248 /*************************************************************************/
249 /* */
250 /* FUNCTION */
251 /* */
252 /* TMF_Timer_Information */
253 /* */
254 /* DESCRIPTION */
255 /* */
256 /* This function returns information about the specified timer. */
257 /* However, if the supplied timer pointer is invalid, the */
258 /* function simply returns an error status. */
259 /* */
260 /* CALLED BY */
261 /* */
262 /* Application */
263 /* */
264 /* CALLS */
265 /* */
266 /* [TCT_Check_Stack] Stack checking function */
267 /* TCT_System_Protect Protect active timer */
268 /* TCT_Unprotect Release protection */
269 /* */
270 /* INPUTS */
271 /* */
272 /* timer_ptr Pointer to the timer */
273 /* name Destination for the name */
274 /* enable Destination for the enable */
275 /* posture */
276 /* expirations Destination for the total */
277 /* number of expirations */
278 /* id Destination for the timer id */
279 /* initial_time Destination for the initial */
280 /* time */
281 /* reschedule_time Destination for the */
282 /* reschedule time */
283 /* */
284 /* OUTPUTS */
285 /* */
286 /* NU_SUCCESS If a valid timer pointer */
287 /* is supplied */
288 /* NU_INVALID_TIMER If timer pointer invalid */
289 /* */
290 /* HISTORY */
291 /* */
292 /* DATE REMARKS */
293 /* */
294 /* 03-01-1993 Created initial version 1.0 */
295 /* 04-19-1993 Verified version 1.0 */
296 /* 08-09-1993 Corrected problem that caused an */
297 /* invalid application timer ID */
298 /* to be returned to the caller, */
299 /* resulting in version 1.0a */
300 /* 08-09-1993 Verified version 1.0a */
301 /* 03-01-1994 Changed function interface, */
302 /* resulting in version 1.1 */
303 /* */
304 /* 03-18-1994 Verified version 1.1 */
305 /* 11-18-1996 Corrected SPR220. */
306 /* */
307 /*************************************************************************/
308 STATUS TMF_Timer_Information(NU_TIMER *timer_ptr, CHAR *name,
309 OPTION *enable, UNSIGNED *expirations, UNSIGNED *id,
310 UNSIGNED *initial_time, UNSIGNED *reschedule_time)
311 {
312
313 TM_APP_TCB *timer; /* Timer control block ptr */
314 INT i; /* Working integer variable */
315 STATUS completion; /* Completion status */
316 NU_SUPERV_USER_VARIABLES
317
318 /* Switch to supervisor mode */
319 NU_SUPERVISOR_MODE();
320
321 /* Move input timer pointer into internal pointer. */
322 timer = (TM_APP_TCB *) timer_ptr;
323
324
325 #ifdef NU_ENABLE_STACK_CHECK
326
327 /* Call stack checking function to check for an overflow condition. */
328 TCT_Check_Stack();
329
330 #endif
331
332 /* Protect the active list. */
333 TCT_System_Protect();
334
335 /* Determine if this timer ID is valid. */
336 if ((timer != NU_NULL) && (timer -> tm_id == TM_TIMER_ID))
337 {
338
339 /* The timer pointer is valid. Reflect this in the completion
340 status and fill in the actual information. */
341 completion = NU_SUCCESS;
342
343 /* Copy the timer's name. */
344 for (i = 0; i < NU_MAX_NAME; i++)
345 *name++ = timer -> tm_name[i];
346
347 /* Determine if the timer is enabled or disabled. */
348 if (timer -> tm_enabled)
349
350 *enable = NU_ENABLE_TIMER;
351 else
352
353 *enable = NU_DISABLE_TIMER;
354
355 /* Fill in the remaining information. */
356 *expirations = timer -> tm_expirations;
357 *id = timer -> tm_expiration_id;
358 *initial_time = timer -> tm_initial_time;
359 *reschedule_time = timer -> tm_reschedule_time;
360 }
361 else
362
363 /* Indicate that the timer pointer is invalid. */
364 completion = NU_INVALID_TIMER;
365
366 /* Release protection. */
367 TCT_Unprotect();
368
369 /* Return to user mode */
370 NU_USER_MODE();
371
372 /* Return the appropriate completion status. */
373 return(completion);
374 }
375
376
377 /*************************************************************************/
378 /* */
379 /* FUNCTION */
380 /* */
381 /* TMF_Get_Remaining_Time */
382 /* */
383 /* DESCRIPTION */
384 /* */
385 /* This function returns the remaining time before expiration for */
386 /* the specified timer. */
387 /* */
388 /* */
389 /* CALLED BY */
390 /* */
391 /* Application */
392 /* */
393 /* CALLS */
394 /* */
395 /* TCT_System_Protect Protect active timer */
396 /* TCT_Unprotect Release protection */
397 /* */
398 /* INPUTS */
399 /* */
400 /* timer_ptr Pointer to the timer */
401 /* */
402 /* OUTPUTS */
403 /* */
404 /* remaining_time time until timer expiration */
405 /* */
406 /* NU_INVALID_TIMER If timer pointer invalid */
407 /* */
408 /* HISTORY */
409 /* */
410 /* DATE REMARKS */
411 /* */
412 /* 07-02-1998 Created service call */
413 /* */
414 /*************************************************************************/
415
416
417 STATUS TMF_Get_Remaining_Time(NU_TIMER *timer_ptr, UNSIGNED *remaining_time)
418 {
419 R1 TM_APP_TCB *timer;
420 TM_TCB *real_TCB;
421 TM_TCB *list_ptr;
422 INT done = 0;
423 STATUS status;
424 NU_SUPERV_USER_VARIABLES
425
426 /* Switch to supervisor mode */
427 NU_SUPERVISOR_MODE();
428
429 /* Protect against simultaneous access to the active timers list*/
430 TCT_System_Protect();
431
432 list_ptr = TMD_Active_Timers_List;
433
434 /* Get the application timer Control Block */
435 timer = (TM_APP_TCB*) timer_ptr;
436
437
438 /* Determine if this timer ID is valid. */
439 if ((timer != NU_NULL) && (timer -> tm_id == TM_TIMER_ID))
440 {
441 /* The timer pointer is valid. Reflect this in the completion
442 status and fill in the actual information. */
443 status = NU_SUCCESS;
444
445 /* Get the actual timer Control block */
446 real_TCB = &(timer->tm_actual_timer);
447
448 if (list_ptr == real_TCB)
449 *remaining_time = list_ptr -> tm_remaining_time;
450 else
451 {
452 if( list_ptr == NU_NULL) /* in case no active timers exist */
453 *remaining_time = 0;
454 else
455 {
456
457 *remaining_time = list_ptr -> tm_remaining_time;
458
459 do
460 {
461 /* Move the list pointer to the next timer in the list. */
462 list_ptr = list_ptr -> tm_next_timer;
463
464 *remaining_time += list_ptr -> tm_remaining_time;
465
466 /* Check to see if we have gotten to the specified timer yet */
467 if (list_ptr == real_TCB)
468 /* Searching is done. */
469 done = NU_TRUE;
470
471 }while (!done);
472 }
473 }
474 }
475 else
476 /* Indicate that the timer pointer is invalid. */
477 status = NU_INVALID_TIMER;
478
479 TCT_Unprotect();
480
481 /* Return to user mode */
482 NU_USER_MODE();
483
484 return (status);
485 }
486
487
488
489