comparison nuc-fw/nucleus/dmf.c @ 79:947b1f473960

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