comparison nucleus/pmce.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 /* pmce.c Nucleus PLUS 1.14 */
17 /* */
18 /* COMPONENT */
19 /* */
20 /* PM - Partition Memory Management */
21 /* */
22 /* DESCRIPTION */
23 /* */
24 /* This file contains the error checking routines for the functions */
25 /* in the Partition component. This permits easy removal of error */
26 /* checking logic when it is not needed. */
27 /* */
28 /* DATA STRUCTURES */
29 /* */
30 /* None */
31 /* */
32 /* FUNCTIONS */
33 /* */
34 /* PMCE_Create_Partition_Pool Create a Partition Pool */
35 /* PMCE_Delete_Partition_Pool Delete a Partition Pool */
36 /* PMCE_Allocate_Partition Allocate a partition from a */
37 /* pool */
38 /* PMCE_Deallocate_Partition Deallocate a partition from */
39 /* a pool */
40 /* */
41 /* DEPENDENCIES */
42 /* */
43 /* cs_extr.h Common Service functions */
44 /* tc_extr.h Thread Control functions */
45 /* pm_extr.h Partition functions */
46 /* */
47 /* HISTORY */
48 /* */
49 /* DATE REMARKS */
50 /* */
51 /* 03-01-1993 Created initial version 1.0 */
52 /* 04-19-1993 Verified version 1.0 */
53 /* 03-01-1994 Changed name original error */
54 /* checking file and changed */
55 /* function interfaces, resulting */
56 /* in version 1.1 */
57 /* */
58 /* 03-18-1994 Verified version 1.1 */
59 /* 04-17-1996 updated to version 1.2 */
60 /* 03-24-1998 Released version 1.3 */
61 /* 04-17-2002 Released version 1.13m */
62 /* 11-07-2002 Released version 1.14 */
63 /*************************************************************************/
64 #define NU_SOURCE_FILE
65
66
67 #include "cs_extr.h" /* Common service functions */
68 #include "tc_extr.h" /* Thread control functions */
69 #include "pm_extr.h" /* Partition functions */
70
71
72 /*************************************************************************/
73 /* */
74 /* FUNCTION */
75 /* */
76 /* PMCE_Create_Partition_Pool */
77 /* */
78 /* DESCRIPTION */
79 /* */
80 /* This function performs error checking on the parameters supplied */
81 /* to the create partition pool function. */
82 /* */
83 /* CALLED BY */
84 /* */
85 /* Application */
86 /* */
87 /* CALLS */
88 /* */
89 /* PMC_Create_Partition_Pool Actual create partition pool */
90 /* function */
91 /* */
92 /* INPUTS */
93 /* */
94 /* pool_ptr Partition pool control block */
95 /* pointer */
96 /* name Partition pool name */
97 /* start_address Starting address of the pool */
98 /* pool_size Number of bytes in the pool */
99 /* partition_size Number of bytes in each */
100 /* partition of the pool */
101 /* suspend_type Suspension type */
102 /* */
103 /* OUTPUTS */
104 /* */
105 /* NU_INVALID_POOL Pool control block pointer */
106 /* is NULL */
107 /* NU_INVALID_MEMORY Pool starting address is NULL*/
108 /* NU_INVALID_SIZE Partition size is 0 or it is */
109 /* larger than the pool area */
110 /* NU_INVALID_SUSPEND Suspension selection is not */
111 /* valid */
112 /* */
113 /* HISTORY */
114 /* */
115 /* DATE REMARKS */
116 /* */
117 /* 03-01-1993 Created initial version 1.0 */
118 /* 04-19-1993 Verified version 1.0 */
119 /* 03-01-1994 Modified function interface, */
120 /* resulting in version 1.1 */
121 /* */
122 /* 03-18-1994 Verified version 1.1 */
123 /* */
124 /*************************************************************************/
125 STATUS PMCE_Create_Partition_Pool(NU_PARTITION_POOL *pool_ptr, CHAR *name,
126 VOID *start_address, UNSIGNED pool_size,
127 UNSIGNED partition_size, OPTION suspend_type)
128 {
129
130 PM_PCB *pool; /* Pool control block ptr */
131 STATUS status; /* Completion status */
132 UNSIGNED size; /* Adjusted size of partition*/
133
134
135 /* Move input pool pointer into internal pointer. */
136 pool = (PM_PCB *) pool_ptr;
137
138 /* Adjust the partition size to something that is evenly divisible by
139 the number of bytes in an UNSIGNED data type. */
140 size = ((partition_size + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
141 sizeof(UNSIGNED);
142
143 /* Check for a NULL partition pool control block pointer or a control
144 block that is already created. */
145 if ((pool == NU_NULL) || (pool -> pm_id == PM_PARTITION_ID))
146
147 /* Invalid partition pool control block pointer. */
148 status = NU_INVALID_POOL;
149
150 else if (start_address == NU_NULL)
151
152 /* Invalid memory pointer. */
153 status = NU_INVALID_MEMORY;
154
155 else if ((size == 0) || ((size + PM_OVERHEAD) > pool_size))
156
157 /* Pool could not even accommodate one partition. */
158 status = NU_INVALID_SIZE;
159
160 else if ((suspend_type != NU_FIFO) && (suspend_type != NU_PRIORITY))
161
162 /* Invalid suspension type. */
163 status = NU_INVALID_SUSPEND;
164
165 else
166
167 /* Call the actual service to create the partition pool. */
168 status = PMC_Create_Partition_Pool(pool_ptr, name, start_address,
169 pool_size, partition_size, suspend_type);
170
171 /* Return completion status. */
172 return(status);
173 }
174
175
176 /*************************************************************************/
177 /* */
178 /* FUNCTION */
179 /* */
180 /* PMCE_Delete_Partition_Pool */
181 /* */
182 /* DESCRIPTION */
183 /* */
184 /* This function performs error checking on the parameters supplied */
185 /* to the delete partition pool function. */
186 /* */
187 /* CALLED BY */
188 /* */
189 /* Application */
190 /* */
191 /* CALLS */
192 /* */
193 /* PMC_Delete_Partition_Pool Actual function to delete a */
194 /* partition pool */
195 /* */
196 /* INPUTS */
197 /* */
198 /* pool_ptr Partition pool control block */
199 /* pointer */
200 /* */
201 /* OUTPUTS */
202 /* */
203 /* NU_INVALID_POOL Indicates the supplied pool */
204 /* pointer is invalid */
205 /* */
206 /* HISTORY */
207 /* */
208 /* DATE REMARKS */
209 /* */
210 /* 03-01-1993 Created initial version 1.0 */
211 /* 04-19-1993 Verified version 1.0 */
212 /* 03-01-1994 Modified function interface, */
213 /* resulting in version 1.1 */
214 /* */
215 /* 03-18-1994 Verified version 1.1 */
216 /* */
217 /*************************************************************************/
218 STATUS PMCE_Delete_Partition_Pool(NU_PARTITION_POOL *pool_ptr)
219 {
220
221 PM_PCB *pool; /* Pool control block ptr */
222 STATUS status; /* Completion status */
223
224
225 /* Move input pool pointer into internal pointer. */
226 pool = (PM_PCB *) pool_ptr;
227
228 /* Determine if the partition pool pointer is valid. */
229 if ((pool) && (pool -> pm_id == PM_PARTITION_ID))
230
231 /* Partition pool pointer is valid, call function to delete it. */
232 status = PMC_Delete_Partition_Pool(pool_ptr);
233
234 else
235
236 /* Partition pool pointer is invalid, indicate in completion status. */
237 status = NU_INVALID_POOL;
238
239 /* Return completion status. */
240 return(status);
241 }
242
243
244 /*************************************************************************/
245 /* */
246 /* FUNCTION */
247 /* */
248 /* PMCE_Allocate_Partition */
249 /* */
250 /* DESCRIPTION */
251 /* */
252 /* This function performs error checking on the parameters supplied */
253 /* to the allocate partition function. */
254 /* */
255 /* CALLED BY */
256 /* */
257 /* Application */
258 /* */
259 /* CALLS */
260 /* */
261 /* PMC_Allocate_Partition Actual partition allocate */
262 /* function */
263 /* TCCE_Suspend_Error Check for a task suspension */
264 /* error */
265 /* */
266 /* INPUTS */
267 /* */
268 /* pool_ptr Memory partition pool pointer*/
269 /* return_pointer Pointer to the destination */
270 /* memory pointer */
271 /* suspend Suspension option if full */
272 /* */
273 /* OUTPUTS */
274 /* */
275 /* NU_INVALID_POOL Indicates the pool pointer */
276 /* is invalid */
277 /* NU_INVALID_POINTER Indicates the return pointer */
278 /* is NULL */
279 /* NU_INVALID_SUSPEND Indicates the suspension is */
280 /* invalid */
281 /* */
282 /* HISTORY */
283 /* */
284 /* DATE REMARKS */
285 /* */
286 /* 03-01-1993 Created initial version 1.0 */
287 /* 04-19-1993 Verified version 1.0 */
288 /* 03-01-1994 Modified function interface, */
289 /* resulting in version 1.1 */
290 /* */
291 /* 03-18-1994 Verified version 1.1 */
292 /* */
293 /*************************************************************************/
294 STATUS PMCE_Allocate_Partition(NU_PARTITION_POOL *pool_ptr,
295 VOID **return_pointer, UNSIGNED suspend)
296 {
297
298 PM_PCB *pool; /* Pool control block ptr */
299 STATUS status; /* Completion status */
300
301
302 /* Move input pool pointer into internal pointer. */
303 pool = (PM_PCB *) pool_ptr;
304
305 /* Determine if partition pool pointer is invalid. */
306 if (pool == NU_NULL)
307
308 /* Partition pool pointer is invalid, indicate in completion status. */
309 status = NU_INVALID_POOL;
310
311 else if (pool -> pm_id != PM_PARTITION_ID)
312
313 /* Partition pool pointer is invalid, indicate in completion status. */
314 status = NU_INVALID_POOL;
315
316 else if (return_pointer == NU_NULL)
317
318 /* Return pointer is invalid. */
319 status = NU_INVALID_POINTER;
320
321 else if ((suspend) && (TCCE_Suspend_Error()))
322
323 /* Suspension from a non-task thread. */
324 status = NU_INVALID_SUSPEND;
325
326 else
327
328 /* Parameters are valid, call actual function. */
329 status = PMC_Allocate_Partition(pool_ptr, return_pointer, suspend);
330
331 /* Return the completion status. */
332 return(status);
333 }
334
335
336 /*************************************************************************/
337 /* */
338 /* FUNCTION */
339 /* */
340 /* PMCE_Deallocate_Partition */
341 /* */
342 /* DESCRIPTION */
343 /* */
344 /* This function performs error checking on the parameters supplied */
345 /* to the deallocate partition function. */
346 /* */
347 /* CALLED BY */
348 /* */
349 /* Application */
350 /* */
351 /* CALLS */
352 /* */
353 /* PMC_Deallocate_Partition Deallocate a partition */
354 /* */
355 /* INPUTS */
356 /* */
357 /* partition Pointer to partition memory */
358 /* */
359 /* OUTPUTS */
360 /* */
361 /* NU_INVALID_POINTER Indicates the supplied */
362 /* partition pointer is NULL, */
363 /* or otherwise invalid. */
364 /* NU_SUCCESS */
365 /* */
366 /* HISTORY */
367 /* */
368 /* DATE REMARKS */
369 /* */
370 /* 03-01-1993 Created initial version 1.0 */
371 /* 04-19-1993 Verified version 1.0 */
372 /* 03-01-1994 Modified function interface, */
373 /* resulting in version 1.1 */
374 /* */
375 /* 03-18-1994 Verified version 1.1 */
376 /* */
377 /*************************************************************************/
378 STATUS PMCE_Deallocate_Partition(VOID *partition)
379 {
380
381 PM_PCB *pool; /* Pool pointer */
382 PM_HEADER *header_ptr; /* Pointer to partition hdr */
383 STATUS status; /* Completion status */
384
385
386 /* Pickup the associated pool's pointer. It is inside the header of
387 each partition. */
388 header_ptr = (PM_HEADER *) (((BYTE_PTR) partition) - PM_OVERHEAD);
389
390 /* Determine if the pointer(s) are NULL. */
391 if ((header_ptr == NU_NULL) || (partition == NU_NULL))
392
393 /* Partition pointer is invalid. */
394 status = NU_INVALID_POINTER;
395
396 /* Determine if partition pool pointer is invalid. */
397 else if ((pool = header_ptr -> pm_partition_pool) == NU_NULL)
398
399 /* Partition pointer is invalid, indicate in completion status. */
400 status = NU_INVALID_POINTER;
401
402 else if (pool -> pm_id != PM_PARTITION_ID)
403
404 /* Partition pool pointer is invalid, indicate in completion status. */
405 status = NU_INVALID_POINTER;
406
407 else if (header_ptr -> pm_next_available)
408
409 /* Partition is still linked on the available list- must not be
410 allocated. */
411 status = NU_INVALID_POINTER;
412
413 else
414
415 /* Parameters are valid, call actual function. */
416 status = PMC_Deallocate_Partition(partition);
417
418 /* Return the completion status. */
419 return(status);
420 }
421
422
423
424
425
426