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