m2mb API docs  25.30.003
m2mb API sets documentation
m2mb_os_pool.h
Go to the documentation of this file.
1 /*===============================================================================================*/
2 /* >>> Copyright (C) Telit Communications S.p.A. Italy All Rights Reserved. <<< */
25 #ifndef M2MB_OS_POOL_H
26 #define M2MB_OS_POOL_H
27 
28 
29 /* Global declarations ==========================================================================*/
30 
31 /* must remain 0 */
32 #define M2MB_OS_POOL_INVALID 0
33 #define M2MB_OS_POOL_INVALID_ATTR 0
34 
35 #define M2MB_OS_POOL_BLOCK ( ( MEM_W ) 0x1 )
36 #define M2MB_OS_POOL_BYTE ( ( MEM_W ) 0x0 )
37 
38 /* in bytes */
39 #define M2MB_OS_MIN_POOL_SIZE ( 128 )
40 
41 
42 /*-----------------------------------------------------------------------------------------------
43 
44  can be called directly without specify CMDS_ARGS
45  osRes = m2mb_os_pool_setAttrItem_( &poolAttrHandle,
46  M2MB_OS_POOL_SEL_CMD_CREATE_ATTR, NULL,
47  M2MB_OS_POOL_SEL_CMD_NAME, "myPool",
48  M2MB_OS_POOL_SEL_CMD_USRNAME, "myUserPool",
49  M2MB_OS_POOL_SEL_CMD_POOL_TYPE, M2MB_OS_POOL_BYTE,
50  M2MB_OS_POOL_SEL_CMD_MEM_START, &poolArea,
51  M2MB_OS_POOL_SEL_CMD_MEM_SIZE, Size,
52  M2MB_OS_POOL_SEL_CMD_VADDR, 0x48000000
53  );
54  -----------------------------------------------------------------------------------------------*/
55 #ifdef _WIN32
56 #define m2mb_os_pool_setAttrItem_( h, ... ) m2mb_os_pool_setAttrItem( h, CMDS_ARGS( __VA_ARGS__ ) )
57 #else
58 #define m2mb_os_pool_setAttrItem_( h, args... ) m2mb_os_pool_setAttrItem( h, CMDS_ARGS( args ) )
59 #endif
60 
61 /* Global typedefs ==============================================================================*/
62 
63 typedef struct M2MB_OS_POOL_HANDLE_TAG *M2MB_OS_POOL_HANDLE;
64 typedef struct M2MB_OS_POOL_ATTR_HANDLE_TAG *M2MB_OS_POOL_ATTR_HANDLE;
65 
66 typedef enum
67 {
68  MEM_PERMISSION_RONLY,
69  MEM_PERMISSION_RW,
70  MEM_PERMISSION_SHARE
71 }MEM_PERMISSION_E;
72 
73 /* see m2mb_os_pool_setItem, m2mb_os_pool_getItem and m2mb_os_pool_setAttrItem
74  for the allowd use of M2MB_OS_POOL_SEL_CMD_E values */
75 typedef enum
76 {
77  M2MB_OS_POOL_SEL_CMD_CREATE_ATTR,
78  M2MB_OS_POOL_SEL_CMD_DEL_ATTR,
79  /* use as Os name */
80  M2MB_OS_POOL_SEL_CMD_NAME,
81  /* if set, usr name could be different from Os */
82  M2MB_OS_POOL_SEL_CMD_USRNAME,
83  /* use only to get info on memory pool or create one: multiple of block size or multiple of byte */
84  M2MB_OS_POOL_SEL_CMD_POOL_TYPE,
85  /* select if block type is the size of block granularity for allocation */
86  M2MB_OS_POOL_SEL_CMD_BLOCK_SIZE,
87  /* use only to get info on pool size or to create a pool */
88  M2MB_OS_POOL_SEL_CMD_MEM_SIZE,
89  /* select memory where the pool start */
90  M2MB_OS_POOL_SEL_CMD_MEM_START,
91  /* select Virtual Address to be assigned to the pool: if available */
92  M2MB_OS_POOL_SEL_CMD_VADDR,
93  /* select the permission for the memory area if available */
94  M2MB_OS_POOL_SEL_CMD_PERMISSION,
95 
96  /* ---- */
97  M2MB_OS_POOL_SEL_CMD_END,
98  ENUM_TO_INT( M2MB_OS_POOL_SEL_CMD_E )
99 } M2MB_OS_POOL_SEL_CMD_E;
100 
102 {
103  MEM_W cmd;
104  void *pArg;
106 
107 typedef enum
108 {
109  M2MB_OS_POOL_BYTE_MEMINFO_FRAGMENTS, /* the total number of memory fragments in byte pool */
110  M2MB_OS_POOL_MEMINFO_BYTES_AVAILABLE, /* the total number of available bytes in the pool */
111  M2MB_OS_POOL_MEMINFO_SIZE, /* total size in byte of the pool */
112  M2MB_OS_POOL_MEMINFO_BLOCKS_AVAILABLE, /* the total number of available blocks in the block pool */
113  M2MB_OS_POOL_MEMINFO_BLOCK_SIZE , /* the block size in the block pool */
114  M2MB_OS_POOL_MEMINFO_TOTAL_BLOCKS, /* the total number of blocks in the block pool */
115  M2MB_OS_POOL_MEMINFO_BYTES_MAX_OCCUPATION, /* the max occupation of bytes that have been allocated */
116 
117  /* ---- */
118  M2MB_OS_POOL_MEMINFO_END,
119  ENUM_TO_INT( M2MB_OS_POOL_MEMINFO_E )
120 } M2MB_OS_POOL_MEMINFO_E;
121 
122 /* Global functions =============================================================================*/
123 
124 
125 /*-----------------------------------------------------------------------------------------------*/
204 M2MB_OS_RESULT_E m2mb_os_pool_init( M2MB_OS_POOL_HANDLE *pPoolHandle,
205  M2MB_OS_POOL_ATTR_HANDLE *pPoolAttrHandle
206  );
207 
208 
209 /*-----------------------------------------------------------------------------------------------*/
249 /*-----------------------------------------------------------------------------------------------*/
250 M2MB_OS_RESULT_E m2mb_os_pool_deinit( M2MB_OS_POOL_HANDLE poolHandle );
251 
252 /*-----------------------------------------------------------------------------------------------*/
294 /*-----------------------------------------------------------------------------------------------*/
295 void *m2mb_os_pool_malloc( M2MB_OS_POOL_HANDLE poolHandle, UINT32 size );
296 
297 /*-----------------------------------------------------------------------------------------------*/
338 /*-----------------------------------------------------------------------------------------------*/
339 void *m2mb_os_pool_calloc( M2MB_OS_POOL_HANDLE poolHandle, UINT32 size );
340 
341 /*-----------------------------------------------------------------------------------------------*/
384 /*-----------------------------------------------------------------------------------------------*/
385 void *m2mb_os_pool_realloc( M2MB_OS_POOL_HANDLE poolHOld, M2MB_OS_POOL_HANDLE poolHNew,
386  void *ptrOld, UINT32 newsize );
387 /*-----------------------------------------------------------------------------------------------*/
420 /*-----------------------------------------------------------------------------------------------*/
421 M2MB_OS_RESULT_E m2mb_os_pool_free( M2MB_OS_POOL_HANDLE poolHandle, void *ptrToFree );
422 
423 /*-----------------------------------------------------------------------------------------------*/
468 /*-----------------------------------------------------------------------------------------------*/
469 M2MB_OS_RESULT_E m2mb_os_pool_setAttrItem( M2MB_OS_POOL_ATTR_HANDLE *pPoolAttrHandle,
470  UINT8 nCmds,
471  ...
472  );
473 
474 /*-----------------------------------------------------------------------------------------------*/
543 /*-----------------------------------------------------------------------------------------------*/
544 M2MB_OS_RESULT_E m2mb_os_pool_getItem( M2MB_OS_POOL_HANDLE poolHandle,
545  M2MB_OS_POOL_SEL_CMD_E selCmd,
546  MEM_W *pOut,
547  void *pIn
548  );
549 
550 /*-----------------------------------------------------------------------------------------------*/
598 /*-----------------------------------------------------------------------------------------------*/
599 M2MB_OS_RESULT_E m2mb_os_pool_setItem( M2MB_OS_POOL_HANDLE poolHandle,
600  M2MB_OS_POOL_SEL_CMD_E selCmd,
601  void *pIn
602  );
603 
604 /*-----------------------------------------------------------------------------------------------*/
674 /*-----------------------------------------------------------------------------------------------*/
675 M2MB_OS_RESULT_E m2mb_os_pool_memInfo( M2MB_OS_POOL_HANDLE poolHandle,
676  M2MB_OS_POOL_MEMINFO_E memInfoSelect,
677  MEM_W *pOut );
678 
679 
680 #endif /* M2MB_OS_POOL_H */
681 
m2mb_os_pool_realloc
void * m2mb_os_pool_realloc(M2MB_OS_POOL_HANDLE poolHOld, M2MB_OS_POOL_HANDLE poolHNew, void *ptrOld, UINT32 newsize)
Reallocate memory from specified pool.
m2mb_os_pool_calloc
void * m2mb_os_pool_calloc(M2MB_OS_POOL_HANDLE poolHandle, UINT32 size)
Memory allocation from specified pool and set them to 0.
m2mb_os_pool_deinit
M2MB_OS_RESULT_E m2mb_os_pool_deinit(M2MB_OS_POOL_HANDLE poolHandle)
Pool memory area deinit or deletion.
m2mb_os_pool_malloc
void * m2mb_os_pool_malloc(M2MB_OS_POOL_HANDLE poolHandle, UINT32 size)
Memory allocation from specified pool.
m2mb_os_pool_getItem
M2MB_OS_RESULT_E m2mb_os_pool_getItem(M2MB_OS_POOL_HANDLE poolHandle, M2MB_OS_POOL_SEL_CMD_E selCmd, MEM_W *pOut, void *pIn)
Get specific pool properties.
m2mb_os_pool_memInfo
M2MB_OS_RESULT_E m2mb_os_pool_memInfo(M2MB_OS_POOL_HANDLE poolHandle, M2MB_OS_POOL_MEMINFO_E memInfoSelect, MEM_W *pOut)
Get memory information from specific pool.
m2mb_os_pool_setAttrItem
M2MB_OS_RESULT_E m2mb_os_pool_setAttrItem(M2MB_OS_POOL_ATTR_HANDLE *pPoolAttrHandle, UINT8 nCmds,...)
Set specific pool attributes for pool creation.
m2mb_os_pool_free
M2MB_OS_RESULT_E m2mb_os_pool_free(M2MB_OS_POOL_HANDLE poolHandle, void *ptrToFree)
Free allocated memory from specified pool.
m2mb_os_pool_init
M2MB_OS_RESULT_E m2mb_os_pool_init(M2MB_OS_POOL_HANDLE *pPoolHandle, M2MB_OS_POOL_ATTR_HANDLE *pPoolAttrHandle)
Pool memory area creation.
M2MB_OS_POOL_CMD_ARG_TAG
Definition: m2mb_os_pool.h:101
m2mb_os_pool_setItem
M2MB_OS_RESULT_E m2mb_os_pool_setItem(M2MB_OS_POOL_HANDLE poolHandle, M2MB_OS_POOL_SEL_CMD_E selCmd, void *pIn)
Set specific pool properties.