1 /*******************************************************************************
2 * Copyright 2003, Marvell Semiconductor Israel LTD. *
3 * THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL. *
4 * NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT *
5 * OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE *
6 * DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL. *
7 * THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED, *
8 * IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE. *
10 * MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES, *
11 * MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL *
12 * SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K. *
13 * (MJKK), MARVELL SEMICONDUCTOR ISRAEL LTD (MSIL). *
14 ********************************************************************************
17 * FILENAME: $Workfile: mvStack.c $
18 * REVISION: $Revision: 1.1 $
19 * LAST UPDATE: $Modtime: $
22 * This file implements simple Stack LIFO functionality.
23 *******************************************************************************/
34 /* Public functions */
37 /* Purpose: Create new stack
39 * - MV_U32 noOfElements - maximum number of elements in the stack.
40 * Each element 4 bytes size
41 * Return: void* - pointer to created stack.
43 void* mvStackCreate(int numOfElements
)
46 MV_U32
* pStackElements
;
48 pStack
= (MV_STACK
*)mvOsMalloc(sizeof(MV_STACK
));
49 pStackElements
= (MV_U32
*)mvOsMalloc(numOfElements
*sizeof(MV_U32
));
50 if( (pStack
== NULL
) || (pStackElements
== NULL
) )
52 mvOsPrintf("mvStack: Can't create new stack\n");
55 memset(pStackElements
, 0, numOfElements
*sizeof(MV_U32
));
56 pStack
->numOfElements
= numOfElements
;
58 pStack
->stackElements
= pStackElements
;
63 /* Purpose: Delete existing stack
65 * - void* stackHndl - Stack handle as returned by "mvStackCreate()" function
67 * Return: MV_STATUS MV_NOT_FOUND - Failure. StackHandle is not valid.
70 MV_STATUS
mvStackDelete(void* stackHndl
)
72 MV_STACK
* pStack
= (MV_STACK
*)stackHndl
;
74 if( (pStack
== NULL
) || (pStack
->stackElements
== NULL
) )
77 mvOsFree(pStack
->stackElements
);
84 /* PrintOut status of the stack */
85 void mvStackStatus(void* stackHndl
, MV_BOOL isPrintElements
)
88 MV_STACK
* pStack
= (MV_STACK
*)stackHndl
;
90 mvOsPrintf("StackHandle=%p, pElements=%p, numElements=%d, stackIdx=%d\n",
91 stackHndl
, pStack
->stackElements
, pStack
->numOfElements
,
93 if(isPrintElements
== MV_TRUE
)
95 for(i
=0; i
<pStack
->stackIdx
; i
++)
97 mvOsPrintf("%3d. Value=0x%x\n", i
, pStack
->stackElements
[i
]);
This page took 0.053261 seconds and 5 git commands to generate.