comparison gsm-fw/nucleus/smf.c @ 143:afceeeb2cba1

Our nuc-fw is destined to become gsm-fw, so I went ahead and did the big hg mv
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 12 Nov 2013 05:35:48 +0000
parents nuc-fw/nucleus/smf.c@947b1f473960
children
comparison
equal deleted inserted replaced
142:15d5977390c2 143:afceeeb2cba1
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 /* smf.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* SM - Semaphore Management */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains routines to obtain facts about the Semaphore */
25 /* Management component. */
26 /* */
27 /* DATA STRUCTURES */
28 /* */
29 /* None */
30 /* */
31 /* FUNCTIONS */
32 /* */
33 /* SMF_Established_Semaphores Number of created semaphores */
34 /* SMF_Semaphore_Pointers Build semaphore pointer list */
35 /* SMF_Semaphore_Information Retrieve semaphore info */
36 /* */
37 /* DEPENDENCIES */
38 /* */
39 /* cs_extr.h Common Service functions */
40 /* tc_extr.h Thread Control functions */
41 /* sm_extr.h Semaphore functions */
42 /* hi_extr.h History functions */
43 /* */
44 /* HISTORY */
45 /* */
46 /* DATE REMARKS */
47 /* */
48 /* 03-01-1994 Initial version of semaphore */
49 /* fact service file, version 1.1 */
50 /* */
51 /* 03-18-1994 Verified version 1.1 */
52 /* 04-17-1996 updated to version 1.2 */
53 /* 11-18-1996 Protected Informational service */
54 /* from NULL Control Block pointers */
55 /* creating 1.2a. (SPR220) */
56 /* 03-24-1998 Released version 1.3 */
57 /* 03-26-1999 Released 1.11m (new release */
58 /* numbering scheme) */
59 /* 04-17-2002 Released version 1.13m */
60 /* 11-07-2002 Released version 1.14 */
61 /*************************************************************************/
62 #define NU_SOURCE_FILE
63
64
65 #include "cs_extr.h" /* Common service functions */
66 #include "tc_extr.h" /* Thread control functions */
67 #include "sm_extr.h" /* Semaphore functions */
68 #include "hi_extr.h" /* History functions */
69
70
71 /* Define external inner-component global data references. */
72
73 extern CS_NODE *SMD_Created_Semaphores_List;
74 extern UNSIGNED SMD_Total_Semaphores;
75 extern TC_PROTECT SMD_List_Protect;
76
77
78
79 /*************************************************************************/
80 /* */
81 /* FUNCTION */
82 /* */
83 /* SMF_Established_Semaphores */
84 /* */
85 /* DESCRIPTION */
86 /* */
87 /* This function returns the current number of established */
88 /* semaphores. Semaphores previously deleted are no longer */
89 /* considered established. */
90 /* */
91 /* CALLED BY */
92 /* */
93 /* Application */
94 /* */
95 /* CALLS */
96 /* */
97 /* [TCT_Check_Stack] Stack checking function */
98 /* */
99 /* INPUTS */
100 /* */
101 /* None */
102 /* */
103 /* OUTPUTS */
104 /* */
105 /* SMD_Total_Semaphores Number of established */
106 /* semaphores */
107 /* */
108 /* HISTORY */
109 /* */
110 /* DATE REMARKS */
111 /* */
112 /* 03-01-1993 Created initial version 1.0 */
113 /* 04-19-1993 Verified version 1.0 */
114 /* 03-01-1994 Modified function interface, */
115 /* resulting in version 1.1 */
116 /* */
117 /* 03-18-1994 Verified version 1.1 */
118 /* */
119 /*************************************************************************/
120 UNSIGNED SMF_Established_Semaphores(VOID)
121 {
122
123
124 #ifdef NU_ENABLE_STACK_CHECK
125
126 /* Call stack checking function to check for an overflow condition. */
127 TCT_Check_Stack();
128
129 #endif
130
131 /* Return the number of established semaphores. */
132 return(SMD_Total_Semaphores);
133 }
134
135
136 /*************************************************************************/
137 /* */
138 /* FUNCTION */
139 /* */
140 /* SMF_Semaphore_Pointers */
141 /* */
142 /* DESCRIPTION */
143 /* */
144 /* This function builds a list of semaphore pointers, starting at */
145 /* the specified location. The number of semaphore pointers */
146 /* placed in the list is equivalent to the total number of */
147 /* semaphores or the maximum number of pointers specified in the */
148 /* call. */
149 /* */
150 /* CALLED BY */
151 /* */
152 /* Application */
153 /* */
154 /* CALLS */
155 /* */
156 /* [TCT_Check_Stack] Stack checking function */
157 /* TCT_Protect Protect created list */
158 /* TCT_Unprotect Release protection */
159 /* */
160 /* INPUTS */
161 /* */
162 /* pointer_list Pointer to the list area */
163 /* maximum_pointers Maximum number of pointers */
164 /* */
165 /* OUTPUTS */
166 /* */
167 /* pointers Number of semaphores placed */
168 /* in the list */
169 /* HISTORY */
170 /* */
171 /* DATE REMARKS */
172 /* */
173 /* 03-01-1993 Created initial version 1.0 */
174 /* 04-19-1993 Verified version 1.0 */
175 /* 08-09-1993 Corrected pointer retrieval */
176 /* loop, resulting in version 1.0a */
177 /* 08-09-1993 Verified version 1.0a */
178 /* 03-01-1994 Modified function interface, */
179 /* resulting in version 1.1 */
180 /* */
181 /* 03-18-1994 Verified version 1.1 */
182 /* */
183 /*************************************************************************/
184 UNSIGNED SMF_Semaphore_Pointers(NU_SEMAPHORE **pointer_list,
185 UNSIGNED maximum_pointers)
186 {
187 CS_NODE *node_ptr; /* Pointer to each SMB */
188 UNSIGNED pointers; /* Number of pointers in list*/
189 NU_SUPERV_USER_VARIABLES
190
191 /* Switch to supervisor mode */
192 NU_SUPERVISOR_MODE();
193
194 #ifdef NU_ENABLE_STACK_CHECK
195
196 /* Call stack checking function to check for an overflow condition. */
197 TCT_Check_Stack();
198
199 #endif
200
201 /* Initialize the number of pointers returned. */
202 pointers = 0;
203
204 /* Protect against access to the list of created semaphores. */
205 TCT_Protect(&SMD_List_Protect);
206
207 /* Loop until all semaphore pointers are in the list or until the maximum
208 list size is reached. */
209 node_ptr = SMD_Created_Semaphores_List;
210 while ((node_ptr) && (pointers < maximum_pointers))
211 {
212
213 /* Place the node into the destination list. */
214 *pointer_list++ = (NU_SEMAPHORE *) node_ptr;
215
216 /* Increment the pointers variable. */
217 pointers++;
218
219 /* Position the node pointer to the next node. */
220 node_ptr = node_ptr -> cs_next;
221
222 /* Determine if the pointer is at the head of the list. */
223 if (node_ptr == SMD_Created_Semaphores_List)
224
225 /* The list search is complete. */
226 node_ptr = NU_NULL;
227 }
228
229 /* Release protection against access to the list of created semaphores. */
230 TCT_Unprotect();
231
232 /* Return to user mode */
233 NU_USER_MODE();
234
235 /* Return the number of pointers in the list. */
236 return(pointers);
237 }
238
239
240 /*************************************************************************/
241 /* */
242 /* FUNCTION */
243 /* */
244 /* SMF_Semaphore_Information */
245 /* */
246 /* DESCRIPTION */
247 /* */
248 /* This function returns information about the specified semaphore. */
249 /* However, if the supplied semaphore pointer is invalid, the */
250 /* function simply returns an error status. */
251 /* */
252 /* CALLED BY */
253 /* */
254 /* Application */
255 /* */
256 /* CALLS */
257 /* */
258 /* [TCT_Check_Stack] Stack checking function */
259 /* TCT_System_Protect Protect semaphore */
260 /* TCT_Unprotect Release protection */
261 /* */
262 /* INPUTS */
263 /* */
264 /* semaphore_ptr Pointer to the semaphore */
265 /* name Destination for the name */
266 /* current_count Destination for semaphore */
267 /* instance count */
268 /* suspend_type Destination for the type of */
269 /* suspension */
270 /* tasks_waiting Destination for the tasks */
271 /* waiting count */
272 /* first_task Destination for the pointer */
273 /* to the first task waiting */
274 /* */
275 /* OUTPUTS */
276 /* */
277 /* NU_SUCCESS If a valid semaphore pointer */
278 /* is supplied */
279 /* NU_INVALID_SEMAPHORE If semaphore pointer invalid */
280 /* */
281 /* HISTORY */
282 /* */
283 /* DATE REMARKS */
284 /* */
285 /* 03-01-1993 Created initial version 1.0 */
286 /* 04-19-1993 Verified version 1.0 */
287 /* 03-01-1994 Modified function interface, */
288 /* resulting in version 1.1 */
289 /* */
290 /* 03-18-1994 Verified version 1.1 */
291 /* 11-18-1996 Corrected SPR220. */
292 /* */
293 /*************************************************************************/
294 STATUS SMF_Semaphore_Information(NU_SEMAPHORE *semaphore_ptr, CHAR *name,
295 UNSIGNED *current_count, OPTION *suspend_type,
296 UNSIGNED *tasks_waiting, NU_TASK **first_task)
297 {
298
299 SM_SCB *semaphore; /* Semaphore control blk ptr */
300 INT i; /* Working integer variable */
301 STATUS completion; /* Completion status */
302 NU_SUPERV_USER_VARIABLES
303
304 /* Switch to supervisor mode */
305 NU_SUPERVISOR_MODE();
306
307 /* Move input semaphore pointer into internal pointer. */
308 semaphore = (SM_SCB *) semaphore_ptr;
309
310
311 #ifdef NU_ENABLE_STACK_CHECK
312
313 /* Call stack checking function to check for an overflow condition. */
314 TCT_Check_Stack();
315
316 #endif
317
318 /* Determine if this semaphore id is valid. */
319 if ((semaphore != NU_NULL) && (semaphore -> sm_id == SM_SEMAPHORE_ID))
320 {
321
322 /* Setup protection of the semaphore. */
323 TCT_System_Protect();
324
325 /* The semaphore pointer is valid. Reflect this in the completion
326 status and fill in the actual information. */
327 completion = NU_SUCCESS;
328
329 /* Copy the semaphore's name. */
330 for (i = 0; i < NU_MAX_NAME; i++)
331 *name++ = semaphore -> sm_name[i];
332
333 /* Determine the suspension type. */
334 if (semaphore -> sm_fifo_suspend)
335 *suspend_type = NU_FIFO;
336 else
337 *suspend_type = NU_PRIORITY;
338
339 /* Return the current semaphore available instance count. */
340 *current_count = semaphore -> sm_semaphore_count;
341
342 /* Retrieve the number of tasks waiting and the pointer to the
343 first task waiting. */
344 *tasks_waiting = semaphore -> sm_tasks_waiting;
345 if (semaphore -> sm_suspension_list)
346
347 /* There is a task waiting. */
348 *first_task = (NU_TASK *)
349 (semaphore -> sm_suspension_list) -> sm_suspended_task;
350 else
351
352 /* There are no tasks waiting. */
353 *first_task = NU_NULL;
354
355 /* Release protection of the semaphore. */
356 TCT_Unprotect();
357 }
358 else
359
360 /* Indicate that the semaphore pointer is invalid. */
361 completion = NU_INVALID_SEMAPHORE;
362
363 /* Return to user mode */
364 NU_USER_MODE();
365
366 /* Return the appropriate completion status. */
367 return(completion);
368 }
369
370
371
372
373