original files of m241
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
/******************************************************************************
|
||||
|
||||
© 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This is proprietary source code of Freescale Semiconductor Inc.,
|
||||
and its use is subject to the NetComm Device Drivers EULA.
|
||||
The copyright notice above does not evidence any actual or intended
|
||||
publication of such source code.
|
||||
|
||||
**************************************************************************/
|
||||
/**
|
||||
|
||||
@File hash_ext.h
|
||||
|
||||
@Description Hash table implementation
|
||||
|
||||
This is a module that implements a hash table
|
||||
|
||||
User can create (using HASH_Create) the table with a fixed size and
|
||||
|
||||
hash function to his liking.
|
||||
|
||||
@Cautions None.
|
||||
|
||||
*//***************************************************************************/
|
||||
#ifndef __HASH_EXT_H
|
||||
#define __HASH_EXT_H
|
||||
|
||||
|
||||
#include "list_ext.h"
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group etc_id Utility Library Application Programming Interface
|
||||
|
||||
@Description External routines.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group hash_id Hash Table
|
||||
|
||||
@Description Hash Table functions and typedefs.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description The t_HashEntry is infact a t_List.
|
||||
|
||||
*//***************************************************************************/
|
||||
typedef t_List t_HashEntry;
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description The hash table control structure.
|
||||
*//***************************************************************************/
|
||||
typedef struct t_HashTable
|
||||
{
|
||||
uint32_t numOfItems; /**< A counter for the number of items in the table */
|
||||
uint32_t tableSize; /**< A variable holding the number of bins in the table */
|
||||
t_HashEntry * (*f_HashFunc)(t_Handle, t_HashEntry*);
|
||||
/**< A user-defined callback routine for fitting an
|
||||
appropriate bin to a given entry. */
|
||||
t_HashEntry *hashTable; /**< The bins table, after initialization contains
|
||||
tableSize items. */
|
||||
} t_HashTable;
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_Create
|
||||
|
||||
@Description Allocate and initialize the hash table.
|
||||
|
||||
This function allocates memory space and initializes all the
|
||||
members of the hash table object.
|
||||
|
||||
@Param[in] f_HashFunc - The hash function.
|
||||
@Param[in] tableSize - The number of entries in the table.
|
||||
|
||||
@Return Pointer to the created hash table.
|
||||
|
||||
@Cautions f_HashFunc should limit itself to the table size,
|
||||
it's up to the user to check that it does not exceed the limits.
|
||||
*//***************************************************************************/
|
||||
t_HashTable * HASH_Create(t_HashEntry * (*f_HashFunc)(t_Handle, t_HashEntry*),
|
||||
uint32_t tableSize);
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_Terminate
|
||||
|
||||
@Description destructor
|
||||
|
||||
free the allocated memory
|
||||
|
||||
@Param[in] p_HashTable - A pointer to a hash table instance.
|
||||
|
||||
@Return None
|
||||
|
||||
@Cautions User can no longer reach the items through this table.
|
||||
It is recommended to handle this issue before calling this function
|
||||
*//***************************************************************************/
|
||||
void HASH_Terminate(t_HashTable *p_HashTable);
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_Insert
|
||||
|
||||
@Description insert a member to the hash table.
|
||||
|
||||
Insert an item to the location specified by the
|
||||
hash function.
|
||||
|
||||
@Param[in] p_HashTable - A pointer to the hash table instance.
|
||||
@Param[in] p_NewEntry - A pointer to the new entry.
|
||||
|
||||
@Return None
|
||||
*//***************************************************************************/
|
||||
void HASH_Insert(t_HashTable *p_HashTable, t_HashEntry *p_NewEntry);
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_IsEmpty
|
||||
|
||||
@Description Checks if no items are contained in the hash table.
|
||||
|
||||
@Param[in] p_HashTable - A pointer to a hash table instance.
|
||||
|
||||
@Return TRUE when empty , FALSE otherwise.
|
||||
*//***************************************************************************/
|
||||
int32_t HASH_IsEmpty(t_HashTable *p_HashTable);
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_Find
|
||||
|
||||
@Description Finds an entry that is equivalent to the given entry.
|
||||
|
||||
Checks if in the bin that the hash function leads to, there's an
|
||||
item that causes the f_Compare to return TRUE when tested on it.
|
||||
if there is such an item return its address.
|
||||
|
||||
@Param[in] p_HashTable - A pointer to the hash table instance.
|
||||
@Param[in] p_LookFor - A pointer to the requested entry.
|
||||
@Param[in] f_Compare - The compare function.
|
||||
|
||||
@Return Pointer to an entry to the first item for which f_Compare
|
||||
returned TRUE.
|
||||
*//***************************************************************************/
|
||||
t_HashEntry * HASH_Find(t_HashTable *p_HashTable,
|
||||
t_HashEntry *p_LookFor,
|
||||
int32_t (*f_Compare)(t_HashEntry*, t_HashEntry*));
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function HASH_DelInit
|
||||
|
||||
@Description Extracts an item from the hash table.
|
||||
|
||||
@Param[in] p_HashTable - A pointer to the hash table instance.
|
||||
@Param[in] p_HashEntry - A pointer to the deleted entry.
|
||||
|
||||
@Return None.
|
||||
*//***************************************************************************/
|
||||
void HASH_DelInit(t_HashTable* p_HashTable, t_HashEntry *p_HashEntry);
|
||||
|
||||
|
||||
/** @} */ /* end of group hash_id */
|
||||
/** @} */ /* end of group etc_id */
|
||||
|
||||
#endif /* __HASH_EXT_H */
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
/******************************************************************************
|
||||
|
||||
© 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This is proprietary source code of Freescale Semiconductor Inc.,
|
||||
and its use is subject to the NetComm Device Drivers EULA.
|
||||
The copyright notice above does not evidence any actual or intended
|
||||
publication of such source code.
|
||||
|
||||
**************************************************************************/
|
||||
/**************************************************************************//**
|
||||
|
||||
@File list_ext.h
|
||||
|
||||
@Description External prototypes for list.c
|
||||
*//***************************************************************************/
|
||||
|
||||
#ifndef __LIST_EXT_H
|
||||
#define __LIST_EXT_H
|
||||
|
||||
|
||||
#include "std_ext.h"
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group etc_id Utility Library Application Programming Interface
|
||||
|
||||
@Description External routines.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group list_id List
|
||||
|
||||
@Description List module functions,definitions and enums.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description List structure.
|
||||
*//***************************************************************************/
|
||||
typedef struct List
|
||||
{
|
||||
struct List *p_Next; /**< A pointer to the next list object */
|
||||
struct List *p_Prev; /**< A pointer to the previous list object */
|
||||
} t_List;
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_FIRST/LIST_LAST/LIST_NEXT/LIST_PREV
|
||||
|
||||
@Description Macro to get first/last/next/previous entry in a list.
|
||||
|
||||
@Param[in] p_List - A pointer to a list.
|
||||
*//***************************************************************************/
|
||||
#define LIST_FIRST(p_List) (p_List)->p_Next
|
||||
#define LIST_LAST(p_List) (p_List)->p_Prev
|
||||
#define LIST_NEXT LIST_FIRST
|
||||
#define LIST_PREV LIST_LAST
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_INIT
|
||||
|
||||
@Description Macro for initialization of a list struct.
|
||||
|
||||
@Param[in] lst - The t_List object to initialize.
|
||||
*//***************************************************************************/
|
||||
#define LIST_INIT(lst) {&(lst), &(lst)}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST
|
||||
|
||||
@Description Macro to declare of a list.
|
||||
|
||||
@Param[in] listName - The list object name.
|
||||
*//***************************************************************************/
|
||||
#define LIST(listName) t_List listName = LIST_INIT(listName)
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function INIT_LIST
|
||||
|
||||
@Description Macro to initialize a list pointer.
|
||||
|
||||
@Param[in] p_List - The list pointer.
|
||||
*//***************************************************************************/
|
||||
#define INIT_LIST(p_List) LIST_FIRST(p_List) = LIST_LAST(p_List) = (p_List)
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_OBJECT
|
||||
|
||||
@Description Macro to get the struct (object) for this entry.
|
||||
|
||||
@Param[in] type - The type of the struct (object) this list is embedded in.
|
||||
@Param[in] member - The name of the t_List object within the struct.
|
||||
|
||||
@Return The structure pointer for this entry.
|
||||
*//***************************************************************************/
|
||||
#define MEMBER_OFFSET(type, member) ((uint32_t)(&((type *)0)->member))
|
||||
#define LIST_OBJECT(p_List, type, member) \
|
||||
((type *)((char *)(p_List)-MEMBER_OFFSET(type, member)))
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_FOR_EACH
|
||||
|
||||
@Description Macro to iterate over a list.
|
||||
|
||||
@Param[in] p_Pos - A pointer to a list to use as a loop counter.
|
||||
@Param[in] p_Head - A pointer to the head for your list pointer.
|
||||
|
||||
@Cautions You can't delete items with this routine.
|
||||
For deletion use LIST_FOR_EACH_SAFE().
|
||||
*//***************************************************************************/
|
||||
#define LIST_FOR_EACH(p_Pos, p_Head) \
|
||||
for (p_Pos = LIST_FIRST(p_Head); p_Pos != (p_Head); p_Pos = LIST_NEXT(p_Pos))
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_FOR_EACH_SAFE
|
||||
|
||||
@Description Macro to iterate over a list safe against removal of list entry.
|
||||
|
||||
@Param[in] p_Pos - A pointer to a list to use as a loop counter.
|
||||
@Param[in] p_Tmp - Another pointer to a list to use as temporary storage.
|
||||
@Param[in] p_Head - A pointer to the head for your list pointer.
|
||||
*//***************************************************************************/
|
||||
#define LIST_FOR_EACH_SAFE(p_Pos, p_Tmp, p_Head) \
|
||||
for (p_Pos = LIST_FIRST(p_Head), p_Tmp = LIST_FIRST(p_Pos); \
|
||||
p_Pos != (p_Head); \
|
||||
p_Pos = p_Tmp, p_Tmp = LIST_NEXT(p_Pos))
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_FOR_EACH_OBJECT_SAFE
|
||||
|
||||
@Description Macro to iterate over list of given type safely.
|
||||
|
||||
@Param[in] p_Pos - A pointer to a list to use as a loop counter.
|
||||
@Param[in] p_Tmp - Another pointer to a list to use as temporary storage.
|
||||
@Param[in] type - The type of the struct this is embedded in.
|
||||
@Param[in] p_Head - A pointer to the head for your list pointer.
|
||||
@Param[in] member - The name of the list_struct within the struct.
|
||||
|
||||
@Cautions You can't delete items with this routine.
|
||||
For deletion use LIST_FOR_EACH_SAFE().
|
||||
*//***************************************************************************/
|
||||
#define LIST_FOR_EACH_OBJECT_SAFE(p_Pos, p_Tmp, p_Head, type, member) \
|
||||
for (p_Pos = LIST_OBJECT(LIST_FIRST(p_Head), type, member), \
|
||||
p_Tmp = LIST_OBJECT(LIST_FIRST(&p_Pos->member), type, member); \
|
||||
&p_Pos->member != (p_Head); \
|
||||
p_Pos = p_Tmp, \
|
||||
p_Tmp = LIST_OBJECT(LIST_FIRST(&p_Pos->member), type, member))
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_FOR_EACH_OBJECT
|
||||
|
||||
@Description Macro to iterate over list of given type.
|
||||
|
||||
@Param[in] p_Pos - A pointer to a list to use as a loop counter.
|
||||
@Param[in] type - The type of the struct this is embedded in.
|
||||
@Param[in] p_Head - A pointer to the head for your list pointer.
|
||||
@Param[in] member - The name of the list_struct within the struct.
|
||||
|
||||
@Cautions You can't delete items with this routine.
|
||||
For deletion use LIST_FOR_EACH_SAFE().
|
||||
*//***************************************************************************/
|
||||
#define LIST_FOR_EACH_OBJECT(p_Pos, type, p_Head, member) \
|
||||
for (p_Pos = LIST_OBJECT(LIST_FIRST(p_Head), type, member); \
|
||||
&p_Pos->member != (p_Head); \
|
||||
p_Pos = LIST_OBJECT(LIST_FIRST(&(p_Pos->member)), type, member))
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_Add
|
||||
|
||||
@Description Add a new entry to a list.
|
||||
|
||||
Insert a new entry after the specified head.
|
||||
This is good for implementing stacks.
|
||||
|
||||
@Param[in] p_New - A pointer to a new list entry to be added.
|
||||
@Param[in] p_Head - A pointer to a list head to add it after.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_Add(t_List *p_New, t_List *p_Head)
|
||||
{
|
||||
LIST_PREV(LIST_NEXT(p_Head)) = p_New;
|
||||
LIST_NEXT(p_New) = LIST_NEXT(p_Head);
|
||||
LIST_PREV(p_New) = p_Head;
|
||||
LIST_NEXT(p_Head) = p_New;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_AddToTail
|
||||
|
||||
@Description Add a new entry to a list.
|
||||
|
||||
Insert a new entry before the specified head.
|
||||
This is useful for implementing queues.
|
||||
|
||||
@Param[in] p_New - A pointer to a new list entry to be added.
|
||||
@Param[in] p_Head - A pointer to a list head to add it after.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_AddToTail(t_List *p_New, t_List *p_Head)
|
||||
{
|
||||
LIST_NEXT(LIST_PREV(p_Head)) = p_New;
|
||||
LIST_PREV(p_New) = LIST_PREV(p_Head);
|
||||
LIST_NEXT(p_New) = p_Head;
|
||||
LIST_PREV(p_Head) = p_New;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_Del
|
||||
|
||||
@Description Deletes entry from a list.
|
||||
|
||||
@Param[in] p_Entry - A pointer to the element to delete from the list.
|
||||
|
||||
@Return none.
|
||||
|
||||
@Cautions LIST_IsEmpty() on entry does not return true after this,
|
||||
the entry is in an undefined state.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_Del(t_List *p_Entry)
|
||||
{
|
||||
LIST_PREV(LIST_NEXT(p_Entry)) = LIST_PREV(p_Entry);
|
||||
LIST_NEXT(LIST_PREV(p_Entry)) = LIST_NEXT(p_Entry);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_DelAndInit
|
||||
|
||||
@Description Deletes entry from list and reinitialize it.
|
||||
|
||||
@Param[in] p_Entry - A pointer to the element to delete from the list.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_DelAndInit(t_List *p_Entry)
|
||||
{
|
||||
LIST_Del(p_Entry);
|
||||
INIT_LIST(p_Entry);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_Move
|
||||
|
||||
@Description Delete from one list and add as another's head.
|
||||
|
||||
@Param[in] p_Entry - A pointer to the list entry to move.
|
||||
@Param[in] p_Head - A pointer to the list head that will precede our entry.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_Move(t_List *p_Entry, t_List *p_Head)
|
||||
{
|
||||
LIST_Del(p_Entry);
|
||||
LIST_Add(p_Entry, p_Head);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_MoveToTail
|
||||
|
||||
@Description Delete from one list and add as another's tail.
|
||||
|
||||
@Param[in] p_Entry - A pointer to the entry to move.
|
||||
@Param[in] p_Head - A pointer to the list head that will follow our entry.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
static __inline__ void LIST_MoveToTail(t_List *p_Entry, t_List *p_Head)
|
||||
{
|
||||
LIST_Del(p_Entry);
|
||||
LIST_AddToTail(p_Entry, p_Head);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_IsEmpty
|
||||
|
||||
@Description Tests whether a list is empty.
|
||||
|
||||
@Param[in] p_List - A pointer to the list to test.
|
||||
|
||||
@Return 1 if the list is empty, 0 otherwise.
|
||||
*//***************************************************************************/
|
||||
static __inline__ int LIST_IsEmpty(t_List *p_List)
|
||||
{
|
||||
return (LIST_FIRST(p_List) == p_List);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_Append
|
||||
|
||||
@Description Join two lists.
|
||||
|
||||
@Param[in] p_NewList - A pointer to the new list to add.
|
||||
@Param[in] p_Head - A pointer to the place to add it in the first list.
|
||||
|
||||
@Return none.
|
||||
*//***************************************************************************/
|
||||
void LIST_Append(t_List *p_NewList, t_List *p_Head);
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function LIST_NumOfObjs
|
||||
|
||||
@Description Counts number of objects in the list
|
||||
|
||||
@Param[in] p_List - A pointer to the list which objects are to be counted.
|
||||
|
||||
@Return Number of objects in the list.
|
||||
*//***************************************************************************/
|
||||
int LIST_NumOfObjs(t_List *p_List);
|
||||
|
||||
/** @} */ /* end of list_id group */
|
||||
/** @} */ /* end of etc_id group */
|
||||
|
||||
|
||||
#endif /* __LIST_EXT_H */
|
||||
@@ -0,0 +1,303 @@
|
||||
/******************************************************************************
|
||||
|
||||
© 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This is proprietary source code of Freescale Semiconductor Inc.,
|
||||
and its use is subject to the NetComm Device Drivers EULA.
|
||||
The copyright notice above does not evidence any actual or intended
|
||||
publication of such source code.
|
||||
|
||||
**************************************************************************/
|
||||
/**************************************************************************//**
|
||||
|
||||
@File mem_ext.h
|
||||
|
||||
@Description External prototypes for the memory manager object
|
||||
*//***************************************************************************/
|
||||
|
||||
#ifndef __MEM_EXT_H
|
||||
#define __MEM_EXT_H
|
||||
|
||||
#include "std_ext.h"
|
||||
#include "part_ext.h"
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group etc_id Utility Library Application Programming Interface
|
||||
|
||||
@Description External routines.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group mem_id Slab Memory Manager
|
||||
|
||||
@Description Slab Memory Manager module functions, definitions and enums.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/* Each block is of the following structure:
|
||||
*
|
||||
*
|
||||
* +-----------+----------+---------------------------+-----------+-----------+
|
||||
* | Alignment | Prefix | Data | Postfix | Alignment |
|
||||
* | field | field | field | field | Padding |
|
||||
* | | | | | |
|
||||
* +-----------+----------+---------------------------+-----------+-----------+
|
||||
* and at the beginning of all bytes, an additional optional padding might reside
|
||||
* to ensure that the first blocks data field is aligned as requested.
|
||||
*/
|
||||
|
||||
|
||||
#define MEM_MAX_NAME_LENGTH 4
|
||||
|
||||
/**************************************************************************//*
|
||||
@Description Memory Segment structure
|
||||
*//***************************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[MEM_MAX_NAME_LENGTH];
|
||||
/* The segment's name */
|
||||
uint16_t dataSize; /* Size of each data block */
|
||||
uint32_t getFailures; /* Number of times get failed */
|
||||
int allocOwner; /* Memory allocation owner */
|
||||
uint8_t **p_Bases; /* Base addresses of the segments */
|
||||
uint8_t **p_BlocksStack; /* Array of pointers to blocks */
|
||||
uint32_t num; /* Number of blocks in segment */
|
||||
uint32_t current; /* Current block */
|
||||
uint16_t prefixSize; /* How many bytes to reserve before the data */
|
||||
uint16_t postfixSize; /* How many bytes to reserve after the data */
|
||||
uint16_t alignment; /* Requested alignment for the data field */
|
||||
bool consecutiveMem; /* Allocate consecutive data blocks memory */
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
void *p_MemDbg; /* MEM debug database (MEM leaks detection) */
|
||||
uint32_t blockOffset;
|
||||
uint32_t blockSize;
|
||||
#endif /* DEBUG_MEM_LEAKS */
|
||||
t_Handle h_Spinlock;
|
||||
} t_MemorySegment;
|
||||
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_Init
|
||||
|
||||
@Description Create a new memory segment.
|
||||
|
||||
@Param[in] name - Name of memory partition.
|
||||
@Param[in] p_Handle - Handle to new segment is returned through here.
|
||||
@Param[in] num - Number of blocks in new segment.
|
||||
@Param[in] dataSize - Size of blocks in segment.
|
||||
@Param[in] prefixSize - How many bytes to allocate before the data.
|
||||
@Param[in] postfixSize - How many bytes to allocate after the data.
|
||||
@Param[in] alignment - Requested alignment for data field.
|
||||
|
||||
@Return E_OK - success, E_NO_MEMORY - out of memory.
|
||||
*//***************************************************************************/
|
||||
t_Error MEM_Init(char name[],
|
||||
t_Handle *p_Handle,
|
||||
uint32_t num,
|
||||
uint16_t dataSize,
|
||||
uint16_t prefixSize,
|
||||
uint16_t postfixSize,
|
||||
uint16_t alignment);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_InitSmart
|
||||
|
||||
@Description Create a new memory segment.
|
||||
|
||||
@Param[in] name - Name of memory partition.
|
||||
@Param[in] p_Handle - Handle to new segment is returned through here.
|
||||
@Param[in] num - Number of blocks in new segment.
|
||||
@Param[in] dataSize - Size of blocks in segment.
|
||||
@Param[in] prefixSize - How many bytes to allocate before the data.
|
||||
@Param[in] postfixSize - How many bytes to allocate after the data.
|
||||
@Param[in] alignment - Requested alignment for data field.
|
||||
@Param[in] memPartitionId - Memory partition ID for allocation.
|
||||
@Param[in] consecutiveMem - Whether to allocate the memory blocks
|
||||
continuously or not.
|
||||
|
||||
@Return E_OK - success, E_NO_MEMORY - out of memory.
|
||||
*//***************************************************************************/
|
||||
t_Error MEM_InitSmart(char name[],
|
||||
t_Handle *p_Handle,
|
||||
uint32_t num,
|
||||
uint16_t dataSize,
|
||||
uint16_t prefixSize,
|
||||
uint16_t postfixSize,
|
||||
uint16_t alignment,
|
||||
uint8_t memPartitionId,
|
||||
bool consecutiveMem);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_InitByAddress
|
||||
|
||||
@Description Create a new memory segment with a specified base address.
|
||||
|
||||
@Param[in] name - Name of memory partition.
|
||||
@Param[in] p_Handle - Handle to new segment is returned through here.
|
||||
@Param[in] num - Number of blocks in new segment.
|
||||
@Param[in] dataSize - Size of blocks in segment.
|
||||
@Param[in] prefixSize - How many bytes to allocate before the data.
|
||||
@Param[in] postfixSize - How many bytes to allocate after the data.
|
||||
@Param[in] alignment - Requested alignment for data field.
|
||||
@Param[in] address - The required base address.
|
||||
|
||||
@Return E_OK - success, E_NO_MEMORY - out of memory.
|
||||
*//***************************************************************************/
|
||||
t_Error MEM_InitByAddress(char name[],
|
||||
t_Handle *p_Handle,
|
||||
uint32_t num,
|
||||
uint16_t dataSize,
|
||||
uint16_t prefixSize,
|
||||
uint16_t postfixSize,
|
||||
uint16_t alignment,
|
||||
uint8_t *address);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_Free
|
||||
|
||||
@Description Free a specific memory segment.
|
||||
|
||||
@Param[in] h_Mem - Handle to memory segment.
|
||||
|
||||
@Return None.
|
||||
*//***************************************************************************/
|
||||
void MEM_Free(t_Handle h_Mem);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_Get
|
||||
|
||||
@Description Get a block of memory from a segment.
|
||||
|
||||
@Param[in] h_Mem - Handle to memory segment.
|
||||
|
||||
@Return Pointer to new memory block on success,0 otherwise.
|
||||
*//***************************************************************************/
|
||||
void * MEM_Get(t_Handle h_Mem);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_GetN
|
||||
|
||||
@Description Get up to N blocks of memory from a segment.
|
||||
|
||||
The blocks are assumed to be of a fixed size (one size per segment).
|
||||
|
||||
@Param[in] h_Mem - Handle to memory segment.
|
||||
@Param[in] num - Number of blocks to allocate.
|
||||
@Param[out] array - Array of at least num pointers to which the addresses
|
||||
of the allocated blocks are written.
|
||||
|
||||
@Return The number of blocks actually allocated.
|
||||
|
||||
@Cautions Interrupts are disabled for all of the allocation loop.
|
||||
Although this loop is very short for each block (several machine
|
||||
instructions), you should not allocate a very large number
|
||||
of blocks via this routine.
|
||||
*//***************************************************************************/
|
||||
uint16_t MEM_GetN(t_Handle h_Mem, uint32_t num, void *array[]);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_Put
|
||||
|
||||
@Description Put a block of memory back to a segment.
|
||||
|
||||
@Param[in] h_Mem - Handle to memory segment.
|
||||
@Param[in] p_Block - The block to return.
|
||||
|
||||
@Return Pointer to new memory block on success,0 otherwise.
|
||||
*//***************************************************************************/
|
||||
t_Error MEM_Put(t_Handle h_Mem, void *p_Block);
|
||||
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MEM_ComputePartitionSize
|
||||
|
||||
@Description calculate a tight upper boundary of the size of a partition with
|
||||
given attributes.
|
||||
|
||||
The returned value is suitable if one wants to use MEM_InitByAddress().
|
||||
|
||||
@Param[in] num - The number of blocks in the segment.
|
||||
@Param[in] dataSize - Size of block to get.
|
||||
@Param[in] prefixSize - The prefix size
|
||||
@Param postfixSize - The postfix size
|
||||
@Param[in] alignment - The requested alignment value
|
||||
|
||||
@Return The memory block size a segment with the given attributes needs.
|
||||
*//***************************************************************************/
|
||||
uint32_t MEM_ComputePartitionSize(uint32_t num,
|
||||
uint16_t dataSize,
|
||||
uint16_t prefixSize,
|
||||
uint16_t postfixSize,
|
||||
uint16_t alignment);
|
||||
|
||||
|
||||
#ifdef DEBUG_MEM_LEAKS
|
||||
|
||||
#if !(defined(__MWERKS__) && (__dest_os == __ppc_eabi))
|
||||
#error "Memory-Leaks-Debug option is supported only for freescale CodeWarrior"
|
||||
#endif /* __MWERKS__ */
|
||||
/**************************************************************************//**
|
||||
@Function MEM_CheckLeaks
|
||||
|
||||
@Description Report MEM object leaks.
|
||||
|
||||
This routine is automatically called by the MEM_Free() routine,
|
||||
but it can also be invoked while the MEM object is alive.
|
||||
|
||||
@Param[in] h_Mem - Handle to memory segment.
|
||||
|
||||
@Return None.
|
||||
*//***************************************************************************/
|
||||
void MEM_CheckLeaks(t_Handle h_Mem);
|
||||
|
||||
#else /* not DEBUG_MEM_LEAKS */
|
||||
|
||||
#define MEM_CheckLeaks(h_Mem)
|
||||
|
||||
#endif /* not DEBUG_MEM_LEAKS */
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get base of MEM
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetBase(h_Mem) ((t_MemorySegment *)(h_Mem))->p_Bases[0]
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get size of MEM block
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetSize(h_Mem) ((t_MemorySegment *)(h_Mem))->dataSize
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get prefix size of MEM block
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetPrefixSize(h_Mem) ((t_MemorySegment *)(h_Mem))->prefixSize
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get postfix size of MEM block
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetPostfixSize(h_Mem) ((t_MemorySegment *)(h_Mem))->postfixSize
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get alignment of MEM block
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetAlignment(h_Mem) ((t_MemorySegment *)(h_Mem))->alignment
|
||||
|
||||
/**************************************************************************//**
|
||||
@Description Get the number of blocks in the segment
|
||||
*//***************************************************************************/
|
||||
#define MEM_GetNumOfBlocks(h_Mem) ((t_MemorySegment *)(h_Mem))->num
|
||||
|
||||
|
||||
/** @} */ /* end of MEM group */
|
||||
/** @} */ /* end of etc_id group */
|
||||
|
||||
|
||||
#endif /* __MEM_EXT_H */
|
||||
@@ -0,0 +1,152 @@
|
||||
/******************************************************************************
|
||||
|
||||
© 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This is proprietary source code of Freescale Semiconductor Inc.,
|
||||
and its use is subject to the NetComm Device Drivers EULA.
|
||||
The copyright notice above does not evidence any actual or intended
|
||||
publication of such source code.
|
||||
|
||||
**************************************************************************/
|
||||
/**************************************************************************//**
|
||||
|
||||
@File memcpy_ext.h
|
||||
|
||||
@Description Efficient functions for copying and setting blocks of memory.
|
||||
*//***************************************************************************/
|
||||
|
||||
#ifndef __MEMCPY_EXT_H
|
||||
#define __MEMCPY_EXT_H
|
||||
|
||||
#include "std_ext.h"
|
||||
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group etc_id Utility Library Application Programming Interface
|
||||
|
||||
@Description External routines.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group mem_cpy Memory Copy
|
||||
|
||||
@Description Memory Copy module functions,definitions and enums.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MemCpy32
|
||||
|
||||
@Description Copies one memory buffer into another one in 4-byte chunks!
|
||||
Which should be more efficient than byte by byte.
|
||||
|
||||
For large buffers (over 60 bytes) this function is about 4 times
|
||||
more efficient than the trivial memory copy. For short buffers
|
||||
it is reduced to the trivial copy and may be a bit worse.
|
||||
|
||||
@Param[in] pDst - The address of the destination buffer.
|
||||
@Param[in] pSrc - The address of the source buffer.
|
||||
@Param[in] size - The number of bytes that will be copied from pSrc to pDst.
|
||||
|
||||
@Return pDst (the address of the destination buffer).
|
||||
|
||||
@Cautions There is no parameter or boundary checking! It is up to the user
|
||||
to supply non-null parameters as source & destination and size
|
||||
that actually fits into the destination buffer.
|
||||
*//***************************************************************************/
|
||||
void * MemCpy32(void* pDst,void* pSrc, uint32_t size);
|
||||
void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size);
|
||||
void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size);
|
||||
void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MemCpy64
|
||||
|
||||
@Description Copies one memory buffer into another one in 8-byte chunks!
|
||||
Which should be more efficient than byte by byte.
|
||||
|
||||
For large buffers (over 60 bytes) this function is about 8 times
|
||||
more efficient than the trivial memory copy. For short buffers
|
||||
it is reduced to the trivial copy and may be a bit worse.
|
||||
|
||||
Some testing suggests that MemCpy32() preforms better than
|
||||
MemCpy64() over small buffers. On average they break even at
|
||||
100 byte buffers. For buffers larger than that MemCpy64 is
|
||||
superior.
|
||||
|
||||
@Param[in] pDst - The address of the destination buffer.
|
||||
@Param[in] pSrc - The address of the source buffer.
|
||||
@Param[in] size - The number of bytes that will be copied from pSrc to pDst.
|
||||
|
||||
@Return pDst (the address of the destination buffer).
|
||||
|
||||
@Cautions There is no parameter or boundary checking! It is up to the user
|
||||
to supply non null parameters as source & destination and size
|
||||
that actually fits into their buffer.
|
||||
|
||||
Do not use under Linux.
|
||||
*//***************************************************************************/
|
||||
void * MemCpy64(void* pDst,void* pSrc, uint32_t size);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MemSet32
|
||||
|
||||
@Description Sets all bytes of a memory buffer to a specific value, in
|
||||
4-byte chunks.
|
||||
|
||||
@Param[in] pDst - The address of the destination buffer.
|
||||
@Param[in] val - Value to set destination bytes to.
|
||||
@Param[in] size - The number of bytes that will be set to val.
|
||||
|
||||
@Return pDst (the address of the destination buffer).
|
||||
|
||||
@Cautions There is no parameter or boundary checking! It is up to the user
|
||||
to supply non null parameter as destination and size
|
||||
that actually fits into the destination buffer.
|
||||
*//***************************************************************************/
|
||||
void * MemSet32(void* pDst, uint8_t val, uint32_t size);
|
||||
void * IOMemSet32(void* pDst, uint8_t val, uint32_t size);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MemSet64
|
||||
|
||||
@Description Sets all bytes of a memory buffer to a specific value, in
|
||||
8-byte chunks.
|
||||
|
||||
@Param[in] pDst - The address of the destination buffer.
|
||||
@Param[in] val - Value to set destination bytes to.
|
||||
@Param[in] size - The number of bytes that will be set to val.
|
||||
|
||||
@Return pDst (the address of the destination buffer).
|
||||
|
||||
@Cautions There is no parameter or boundary checking! It is up to the user
|
||||
to supply non null parameter as destination and size
|
||||
that actually fits into the destination buffer.
|
||||
*//***************************************************************************/
|
||||
void * MemSet64(void* pDst, uint8_t val, uint32_t size);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function MemDisp
|
||||
|
||||
@Description Displays a block of memory in chunks of 32 bits.
|
||||
|
||||
@Param[in] addr - The address of the memory to dysplay.
|
||||
@Param[in] size - The number of bytes that will be displayed.
|
||||
|
||||
@Return None.
|
||||
|
||||
@Cautions There is no parameter or boundary checking! It is up to the user
|
||||
to supply non null parameter as destination and size
|
||||
that actually fits into the destination buffer.
|
||||
*//***************************************************************************/
|
||||
void MemDisp(uint8_t *addr, int size);
|
||||
|
||||
/** @} */ /* end of mem_cpy group */
|
||||
/** @} */ /* end of etc_id group */
|
||||
|
||||
|
||||
#endif /* __MEMCPY_EXT_H */
|
||||
@@ -0,0 +1,97 @@
|
||||
/******************************************************************************
|
||||
|
||||
© 1995-2003, 2004, 2005-2010 Freescale Semiconductor, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This is proprietary source code of Freescale Semiconductor Inc.,
|
||||
and its use is subject to the NetComm Device Drivers EULA.
|
||||
The copyright notice above does not evidence any actual or intended
|
||||
publication of such source code.
|
||||
|
||||
**************************************************************************/
|
||||
/******************************************************************************
|
||||
|
||||
@File sprint_ext.h
|
||||
|
||||
@Description Debug routines (externals).
|
||||
|
||||
*//***************************************************************************/
|
||||
|
||||
#ifndef __SPRINT_EXT_H
|
||||
#define __SPRINT_EXT_H
|
||||
|
||||
|
||||
#if defined(NCSW_LINUX) && defined(__KERNEL__)
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#else
|
||||
#include <stdio.h>
|
||||
|
||||
#endif /* defined(NCSW_LINUX) && defined(__KERNEL__) */
|
||||
|
||||
#include "std_ext.h"
|
||||
#ifdef NCSW_VXWORKS
|
||||
#include "private/stdioP.h"
|
||||
#endif /* NCSW_VXWORKS */
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group etc_id Utility Library Application Programming Interface
|
||||
|
||||
@Description External routines.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Group sprint_id Sprint
|
||||
|
||||
@Description Sprint & Sscan module functions,definitions and enums.
|
||||
|
||||
@{
|
||||
*//***************************************************************************/
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function Sprint
|
||||
|
||||
@Description Format a string and place it in a buffer.
|
||||
|
||||
@Param[in] buff - The buffer to place the result into.
|
||||
@Param[in] str - The format string to use.
|
||||
@Param[in] ... - Arguments for the format string.
|
||||
|
||||
@Return Number of bytes formatted.
|
||||
*//***************************************************************************/
|
||||
int Sprint(char *buff, const char *str, ...);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function Snprint
|
||||
|
||||
@Description Format a string and place it in a buffer.
|
||||
|
||||
@Param[in] buf - The buffer to place the result into.
|
||||
@Param[in] size - The size of the buffer, including the trailing null space.
|
||||
@Param[in] fmt - The format string to use.
|
||||
@Param[in] ... - Arguments for the format string.
|
||||
|
||||
@Return Number of bytes formatted.
|
||||
*//***************************************************************************/
|
||||
int Snprint(char * buf, uint32_t size, const char *fmt, ...);
|
||||
|
||||
/**************************************************************************//**
|
||||
@Function Sscan
|
||||
|
||||
@Description Unformat a buffer into a list of arguments.
|
||||
|
||||
@Param[in] buf - input buffer.
|
||||
@Param[in] fmt - formatting of buffer.
|
||||
@Param[out] ... - resulting arguments.
|
||||
|
||||
@Return Number of bytes unformatted.
|
||||
*//***************************************************************************/
|
||||
int Sscan(const char * buf, const char * fmt, ...);
|
||||
|
||||
/** @} */ /* end of sprint_id group */
|
||||
/** @} */ /* end of etc_id group */
|
||||
|
||||
|
||||
#endif /* __SPRINT_EXT_H */
|
||||
Reference in New Issue
Block a user