FreeCalypso > hg > freecalypso-sw
comparison gsm-fw/nucleus/mbf.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/mbf.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 /* mbf.c Nucleus PLUS 1.14 */ | |
17 /* */ | |
18 /* COMPONENT */ | |
19 /* */ | |
20 /* MB - Mailbox Management */ | |
21 /* */ | |
22 /* DESCRIPTION */ | |
23 /* */ | |
24 /* This file contains routines to obtain facts about the Mailbox */ | |
25 /* management component. */ | |
26 /* */ | |
27 /* DATA STRUCTURES */ | |
28 /* */ | |
29 /* None */ | |
30 /* */ | |
31 /* FUNCTIONS */ | |
32 /* */ | |
33 /* MBF_Established_Mailboxes Number of created mailboxes */ | |
34 /* MBF_Mailbox_Pointers Build mailbox pointer list */ | |
35 /* MBF_Mailbox_Information Retrieve mailbox information */ | |
36 /* */ | |
37 /* DEPENDENCIES */ | |
38 /* */ | |
39 /* cs_extr.h Common Service functions */ | |
40 /* tc_extr.h Thread Control functions */ | |
41 /* mb_extr.h Mailbox functions */ | |
42 /* hi_extr.h History functions */ | |
43 /* */ | |
44 /* HISTORY */ | |
45 /* */ | |
46 /* DATE REMARKS */ | |
47 /* */ | |
48 /* 03-01-1994 Initial version of mailbox fact */ | |
49 /* 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 "mb_extr.h" /* Mailbox functions */ | |
68 #include "hi_extr.h" /* History functions */ | |
69 | |
70 | |
71 /* Define external inner-component global data references. */ | |
72 | |
73 extern CS_NODE *MBD_Created_Mailboxes_List; | |
74 extern UNSIGNED MBD_Total_Mailboxes; | |
75 extern TC_PROTECT MBD_List_Protect; | |
76 | |
77 | |
78 /* Define internal component function prototypes. */ | |
79 | |
80 VOID MBC_Cleanup(VOID *information); | |
81 | |
82 | |
83 /*************************************************************************/ | |
84 /* */ | |
85 /* FUNCTION */ | |
86 /* */ | |
87 /* MBF_Established_Mailboxes */ | |
88 /* */ | |
89 /* DESCRIPTION */ | |
90 /* */ | |
91 /* This function returns the current number of established */ | |
92 /* mailboxes. Mailboxes previously deleted are no longer */ | |
93 /* considered established. */ | |
94 /* */ | |
95 /* CALLED BY */ | |
96 /* */ | |
97 /* Application */ | |
98 /* */ | |
99 /* CALLS */ | |
100 /* */ | |
101 /* [TCT_Check_Stack] Stack checking function */ | |
102 /* */ | |
103 /* INPUTS */ | |
104 /* */ | |
105 /* None */ | |
106 /* */ | |
107 /* OUTPUTS */ | |
108 /* */ | |
109 /* MBD_Total_Mailboxes Number of established */ | |
110 /* mailboxes */ | |
111 /* */ | |
112 /* HISTORY */ | |
113 /* */ | |
114 /* DATE REMARKS */ | |
115 /* */ | |
116 /* 03-01-1993 Created initial version 1.0 */ | |
117 /* 04-19-1993 Verified version 1.0 */ | |
118 /* */ | |
119 /*************************************************************************/ | |
120 UNSIGNED MBF_Established_Mailboxes(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 mailboxes. */ | |
132 return(MBD_Total_Mailboxes); | |
133 } | |
134 | |
135 | |
136 /*************************************************************************/ | |
137 /* */ | |
138 /* FUNCTION */ | |
139 /* */ | |
140 /* MBF_Mailbox_Pointers */ | |
141 /* */ | |
142 /* DESCRIPTION */ | |
143 /* */ | |
144 /* This function builds a list of mailbox pointers, starting at the */ | |
145 /* specified location. The number of mailbox pointers placed in */ | |
146 /* the list is equivalent to the total number of mailboxes or the */ | |
147 /* maximum number of pointers specified in the call. */ | |
148 /* */ | |
149 /* CALLED BY */ | |
150 /* */ | |
151 /* Application */ | |
152 /* */ | |
153 /* CALLS */ | |
154 /* */ | |
155 /* [TCT_Check_Stack] Stack checking function */ | |
156 /* TCT_Protect Protect created list */ | |
157 /* TCT_Unprotect Release protection */ | |
158 /* */ | |
159 /* INPUTS */ | |
160 /* */ | |
161 /* pointer_list Pointer to the list area */ | |
162 /* maximum_pointers Maximum number of pointers */ | |
163 /* */ | |
164 /* OUTPUTS */ | |
165 /* */ | |
166 /* pointers Number of mailboxes placed */ | |
167 /* in the list */ | |
168 /* HISTORY */ | |
169 /* */ | |
170 /* DATE REMARKS */ | |
171 /* */ | |
172 /* 03-01-1993 Created initial version 1.0 */ | |
173 /* 04-19-1993 Verified version 1.0 */ | |
174 /* 08-09-1993 Corrected pointer retrieval */ | |
175 /* loop, resulting in version 1.0a */ | |
176 /* 08-09-1993 Verified version 1.0a */ | |
177 /* 03-01-1994 Changed function interface to */ | |
178 /* match the prototype, */ | |
179 /* resulting in version 1.1 */ | |
180 /* */ | |
181 /* 03-18-1994 Verified version 1.1 */ | |
182 /* */ | |
183 /*************************************************************************/ | |
184 UNSIGNED MBF_Mailbox_Pointers(NU_MAILBOX **pointer_list, | |
185 UNSIGNED maximum_pointers) | |
186 { | |
187 CS_NODE *node_ptr; /* Pointer to each MCB */ | |
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 mailboxes. */ | |
205 TCT_Protect(&MBD_List_Protect); | |
206 | |
207 /* Loop until all mailbox pointers are in the list or until the maximum | |
208 list size is reached. */ | |
209 node_ptr = MBD_Created_Mailboxes_List; | |
210 while ((node_ptr) && (pointers < maximum_pointers)) | |
211 { | |
212 | |
213 /* Place the node into the destination list. */ | |
214 *pointer_list++ = (NU_MAILBOX *) 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 == MBD_Created_Mailboxes_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 mailboxes. */ | |
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 /* MBF_Mailbox_Information */ | |
245 /* */ | |
246 /* DESCRIPTION */ | |
247 /* */ | |
248 /* This function returns information about the specified mailbox. */ | |
249 /* However, if the supplied mailbox 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 mailbox */ | |
260 /* TCT_Unprotect Release protection */ | |
261 /* */ | |
262 /* INPUTS */ | |
263 /* */ | |
264 /* mailbox_ptr Pointer to the mailbox */ | |
265 /* name Destination for the name */ | |
266 /* suspend_type Destination for the type of */ | |
267 /* suspension */ | |
268 /* message_present Destination for the message */ | |
269 /* present flag */ | |
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 mailbox pointer */ | |
278 /* is supplied */ | |
279 /* NU_INVALID_MAILBOX If mailbox 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 Changed function interface to */ | |
288 /* match the prototype, */ | |
289 /* resulting in version 1.1 */ | |
290 /* */ | |
291 /* 03-18-1994 Verified version 1.1 */ | |
292 /* 11-18-1996 Corrected SPR220. */ | |
293 /* */ | |
294 /*************************************************************************/ | |
295 STATUS MBF_Mailbox_Information(NU_MAILBOX *mailbox_ptr, CHAR *name, | |
296 OPTION *suspend_type, DATA_ELEMENT *message_present, | |
297 UNSIGNED *tasks_waiting, NU_TASK **first_task) | |
298 { | |
299 | |
300 MB_MCB *mailbox; /* Mailbox control block ptr */ | |
301 int i; /* Working integer variable */ | |
302 STATUS completion; /* Completion status */ | |
303 NU_SUPERV_USER_VARIABLES | |
304 | |
305 /* Switch to supervisor mode */ | |
306 NU_SUPERVISOR_MODE(); | |
307 | |
308 /* Move input mailbox pointer into internal pointer. */ | |
309 mailbox = (MB_MCB *) mailbox_ptr; | |
310 | |
311 | |
312 #ifdef NU_ENABLE_STACK_CHECK | |
313 | |
314 /* Call stack checking function to check for an overflow condition. */ | |
315 TCT_Check_Stack(); | |
316 | |
317 #endif | |
318 | |
319 /* Determine if this mailbox id is valid. */ | |
320 if ((mailbox != NU_NULL) && (mailbox -> mb_id == MB_MAILBOX_ID)) | |
321 { | |
322 | |
323 /* Setup protection of the mailbox. */ | |
324 TCT_System_Protect(); | |
325 | |
326 /* The mailbox pointer is valid. Reflect this in the completion | |
327 status and fill in the actual information. */ | |
328 completion = NU_SUCCESS; | |
329 | |
330 /* Copy the mailbox's name. */ | |
331 for (i = 0; i < NU_MAX_NAME; i++) | |
332 *name++ = mailbox -> mb_name[i]; | |
333 | |
334 /* Determine the suspension type. */ | |
335 if (mailbox -> mb_fifo_suspend) | |
336 *suspend_type = NU_FIFO; | |
337 else | |
338 *suspend_type = NU_PRIORITY; | |
339 | |
340 /* Indicate whether or not there is a message in the mailbox. */ | |
341 *message_present = mailbox -> mb_message_present; | |
342 | |
343 /* Retrieve the number of tasks waiting and the pointer to the | |
344 first task waiting. */ | |
345 *tasks_waiting = mailbox -> mb_tasks_waiting; | |
346 if (mailbox -> mb_suspension_list) | |
347 | |
348 /* There is a task waiting. */ | |
349 *first_task = (NU_TASK *) | |
350 (mailbox -> mb_suspension_list) -> mb_suspended_task; | |
351 else | |
352 | |
353 /* There are no tasks waiting. */ | |
354 *first_task = NU_NULL; | |
355 | |
356 /* Release protection. */ | |
357 TCT_Unprotect(); | |
358 } | |
359 else | |
360 | |
361 /* Indicate that the mailbox pointer is invalid. */ | |
362 completion = NU_INVALID_MAILBOX; | |
363 | |
364 /* Return to user mode */ | |
365 NU_USER_MODE(); | |
366 | |
367 /* Return the appropriate completion status. */ | |
368 return(completion); | |
369 } | |
370 | |
371 | |
372 | |
373 | |
374 |