Infineon Logo AIROC BTSDK v4.9 - Documentation
 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Memory Management

Helper APIs to create heaps and pools and allocate/free buffers from those pools or heaps. More...

Data Structures

struct  wiced_bt_pool_statistics_s
 AIROC Bluetooth buffer pool statistics. More...
 
struct  wiced_bt_heap_statistics_s
 AIROC Bluetooth heap statistics. More...
 
struct  wiced_bt_buffer_q_t
 This queue is a general purpose buffer queue, for application use. More...
 

Macros

#define wiced_bt_buffer_pool_t   wiced_bt_pool_t
 
#define WICED_DEFAULT_HEAP   ((wiced_bt_heap_t *)NULL)
 If an application wants to get a buffer from the default heap, he can use this. More...
 
#define wiced_bt_get_buffer(size)   wiced_bt_get_buffer_from_heap(WICED_DEFAULT_HEAP, (size))
 Allocates a buffer from the DEFAULT heap . More...
 
#define wiced_memory_allocate(size)   wiced_bt_get_buffer(size)
 Function wiced_memory_allocate. More...
 
#define wiced_memory_free(memoryBlock)   wiced_bt_free_buffer(memoryBlock)
 Function wiced_memory_free. More...
 

Typedefs

typedef void wiced_bt_buffer_t
 AIROC Bluetooth Buffer.
 
typedef struct t_wiced_bt_pool wiced_bt_pool_t
 AIROC Bluetooth Pool.
 
typedef struct t_wiced_bt_heap wiced_bt_heap_t
 AIROC Bluetooth Heap.
 
typedef struct
wiced_bt_pool_statistics_s 
wiced_bt_pool_statistics_t
 AIROC Bluetooth buffer pool statistics.
 
typedef struct
wiced_bt_heap_statistics_s 
wiced_bt_heap_statistics_t
 AIROC Bluetooth heap statistics.
 

Functions

uint32_t wiced_memory_get_free_bytes (void)
 Returns the number of free bytes of RAM left. More...
 
wiced_bt_heap_twiced_bt_create_heap (const char *name, void *p_area, int size, wiced_bt_lock_t *p_lock, wiced_bool_t b_make_default)
 Initializes dynamic memory area. More...
 
void wiced_bt_delete_heap (wiced_bt_heap_t *p_heap)
 Deletes the heap created with wiced_bt_create_heap. More...
 
wiced_bt_pool_twiced_bt_create_pool (const char *name, uint32_t buffer_size, uint32_t buffer_cnt, wiced_bt_lock_t *p_lock)
 Creates a buffer pool for application usage. More...
 
void wiced_bt_delete_pool (wiced_bt_pool_t *p_pool)
 Deletes a buffer pool created using wiced_bt_create_pool. More...
 
wiced_bt_buffer_twiced_bt_get_buffer_from_pool (wiced_bt_pool_t *p_pool)
 Get buffer from requested pool. More...
 
wiced_bt_buffer_twiced_bt_get_buffer_from_heap (wiced_bt_heap_t *p_heap, uint32_t size)
 Allocates a buffer from the requested heap. More...
 
uint32_t wiced_bt_get_pool_free_count (wiced_bt_pool_t *p_pool)
 To get the number of buffers available in the pool. More...
 
uint32_t wiced_bt_get_largest_heap_buffer (wiced_bt_heap_t *p_heap)
 To get the size of the largest buffer available in the heap. More...
 
void wiced_bt_free_buffer (wiced_bt_buffer_t *p_buf)
 Frees a buffer back to the pool or heap it came from. More...
 
uint32_t wiced_bt_get_buffer_size (wiced_bt_buffer_t *p_buf)
 Gets the buffer size. More...
 
void wiced_bt_init_q (wiced_bt_buffer_q_t *p_q, wiced_bt_lock_t *p_lock)
 Called by an application to initialize a AIROC buffer queue. More...
 
void wiced_bt_enqueue (wiced_bt_buffer_q_t *p_q, wiced_bt_buffer_t *p_buf)
 Enqueue a buffer at the tail of the queue. More...
 
void wiced_bt_enqueue_head (wiced_bt_buffer_q_t *p_q, wiced_bt_buffer_t *p_buf)
 Enqueue a buffer at the head of the queue. More...
 
wiced_bt_buffer_twiced_bt_dequeue (wiced_bt_buffer_q_t *p_q)
 Dequeues a buffer from the head of a queue. More...
 
wiced_bt_buffer_twiced_bt_remove_from_queue (wiced_bt_buffer_q_t *p_q, wiced_bt_buffer_t *p_buf)
 Dequeue a buffer from the middle of the queue. More...
 
wiced_bt_buffer_twiced_bt_getfirst (wiced_bt_buffer_q_t *p_q)
 Return a pointer to the first buffer in a queue. More...
 
wiced_bt_buffer_twiced_bt_getlast (wiced_bt_buffer_q_t *p_q)
 Return a pointer to the last buffer in a queue. More...
 
wiced_bt_buffer_twiced_bt_getnext (wiced_bt_buffer_t *p_buf)
 Return a pointer to the next buffer in a queue. More...
 
uint32_t wiced_bt_queue_is_empty (wiced_bt_buffer_q_t *p_q)
 Check the status of a queue. More...
 
uint32_t wiced_bt_queue_get_count (wiced_bt_buffer_q_t *p_q)
 Get the number of items in the queue. More...
 
wiced_bt_buffer_twiced_memory_alloc_long_term_mem_block (int size, const char *block_name)
 Allocate long term memory, typically used for control blocks allocated through config, not expected to be freed during the lifetime of the application. More...
 
void wiced_memory_free_long_term_mem_block (wiced_bt_buffer_t *p_mem)
 Free long term memory, used to free memory allocated with wiced_memory_allocate_long_term, typically called during application shutdown. More...
 
wiced_bool_t wiced_bt_get_heap_statistics (void *p_heap, wiced_bt_heap_statistics_t *p_stats)
 Get/Print the heap stats. More...
 
void wiced_set_exception_callback (pf_wiced_exception pf_handler)
 Set the exception callback. More...
 

Detailed Description

Helper APIs to create heaps and pools and allocate/free buffers from those pools or heaps.

When a heap or a pool is created, this utility allocates required chunk of memory from the system and manages it for the creator.

Macro Definition Documentation

#define wiced_bt_get_buffer (   size)    wiced_bt_get_buffer_from_heap(WICED_DEFAULT_HEAP, (size))

Allocates a buffer from the DEFAULT heap .

Parameters
[in]size: size to be allocated
Returns
the pointer to the buffer or NULL on failure
#define WICED_DEFAULT_HEAP   ((wiced_bt_heap_t *)NULL)

If an application wants to get a buffer from the default heap, he can use this.

#define wiced_memory_allocate (   size)    wiced_bt_get_buffer(size)

Function wiced_memory_allocate.

Allocates memory from Dynamic Memory pools

Parameters
[in]size:size of the memory to be allocated
Returns
pointer to the allocated memory on success NULL on failure
#define wiced_memory_free (   memoryBlock)    wiced_bt_free_buffer(memoryBlock)

Function wiced_memory_free.

Frees the buffer

Parameters
[in]p_buf: free memory allocated from Dynamic Memory pools
Returns
None

Function Documentation

wiced_bt_heap_t* wiced_bt_create_heap ( const char *  name,
void *  p_area,
int  size,
wiced_bt_lock_t p_lock,
wiced_bool_t  b_make_default 
)

Initializes dynamic memory area.

Application reserves an area for dynamic variable memory allocations with this call. Application can now allocate variable sized buffers as against fixed sized buffer allocations from the pools initialized with calls to wiced_bt_create_pool and allocated using wiced_bt_get_buffer_from_pool.

Parameters
[in]name: Friendly name of the heap
[in]p_area: Pointer to area to use for the heap. If NULL, AIROC will allocate the area.
[in]size: Size the area passed in. If no area passed in, this is the size of the heap desired.
[in]p_lock: Pointers to lock functions to use during heap manipulation. If NULL, then it is assumed that the application handles disabling of preemption.
[in]b_make_defaultFlag as to whether the heap will be the default heap.
Returns
wiced_bt_heap_t * - pointer to heap, or NULL if the heap creation failed.
wiced_bt_pool_t* wiced_bt_create_pool ( const char *  name,
uint32_t  buffer_size,
uint32_t  buffer_cnt,
wiced_bt_lock_t p_lock 
)

Creates a buffer pool for application usage.

Parameters
[in]name: Friendly name of the heap
[in]buffer_sizeSize of the buffers in the pool
[in]buffer_cnt: Number of buffers in the pool
[in]p_lock: Pointers to lock functions to use during heap manipulation. If NULL, then it is assumed that the application handles disabling of preemption.
Returns
pointer to the created pool on success, or NULL on failure
void wiced_bt_delete_heap ( wiced_bt_heap_t p_heap)

Deletes the heap created with wiced_bt_create_heap.

The heap area is freed back to the platform in case the wiced_bt_create_heap was called with p_area set to NULL.

Parameters
[in]p_heap: Heap created with wiced_bt_create_heap
Returns
void
void wiced_bt_delete_pool ( wiced_bt_pool_t p_pool)

Deletes a buffer pool created using wiced_bt_create_pool.

Parameters
[in]p_pool: pointer of type wiced_bt_pool_t returned through a call to wiced_bt_create_pool
Returns
void
wiced_bt_buffer_t* wiced_bt_dequeue ( wiced_bt_buffer_q_t p_q)

Dequeues a buffer from the head of a queue.

Parameters
[in]p_q: pointer to a queue.
Returns
NULL if queue is empty, else buffer
void wiced_bt_enqueue ( wiced_bt_buffer_q_t p_q,
wiced_bt_buffer_t p_buf 
)

Enqueue a buffer at the tail of the queue.

Parameters
[in]p_q: pointer to a queue.
[in]p_buf: address of the buffer to enqueue
Returns
void
void wiced_bt_enqueue_head ( wiced_bt_buffer_q_t p_q,
wiced_bt_buffer_t p_buf 
)

Enqueue a buffer at the head of the queue.

Parameters
[in]p_q: pointer to a queue.
[in]p_buf: address of the buffer to enqueue
Returns
void
void wiced_bt_free_buffer ( wiced_bt_buffer_t p_buf)

Frees a buffer back to the pool or heap it came from.

Parameters
[in]p_buf: pointer to the start of the (pool/heap) buffer to be freed
Returns
None
wiced_bt_buffer_t* wiced_bt_get_buffer_from_heap ( wiced_bt_heap_t p_heap,
uint32_t  size 
)

Allocates a buffer from the requested heap.

Parameters
[in]p_heap: pointer to heap from which to get the buffer
[in]size: size to be allocated
Returns
the pointer to the buffer or NULL on failure
wiced_bt_buffer_t* wiced_bt_get_buffer_from_pool ( wiced_bt_pool_t p_pool)

Get buffer from requested pool.

Allocates a buffer from the requested pool.

Parameters
[in]p_pool: pointer to pool from which to get the buffer
Returns
the pointer to the buffer or NULL on failure
uint32_t wiced_bt_get_buffer_size ( wiced_bt_buffer_t p_buf)

Gets the buffer size.

Parameters
[in]p_buf: pointer to the start of the buffer
Returns
the buffer size
wiced_bool_t wiced_bt_get_heap_statistics ( void *  p_heap,
wiced_bt_heap_statistics_t p_stats 
)

Get/Print the heap stats.

Parameters
[in]p_heap: heap pointer (output of wiced_bt_create_heap)
[out]p_stats: pointer to receive the heap statistics
Returns
TRUE in case of valid stats returned in p_stats
uint32_t wiced_bt_get_largest_heap_buffer ( wiced_bt_heap_t p_heap)

To get the size of the largest buffer available in the heap.

Parameters
[in]p_heap: heap pointer
Returns
the size of the largest buffer available in the heap
uint32_t wiced_bt_get_pool_free_count ( wiced_bt_pool_t p_pool)

To get the number of buffers available in the pool.

Parameters
[in]p_pool: pool pointer
Returns
the number of buffers available in the pool
wiced_bt_buffer_t* wiced_bt_getfirst ( wiced_bt_buffer_q_t p_q)

Return a pointer to the first buffer in a queue.

Parameters
[in]p_q: pointer to a queue.
Returns
NULL if queue is empty, else buffer address
wiced_bt_buffer_t* wiced_bt_getlast ( wiced_bt_buffer_q_t p_q)

Return a pointer to the last buffer in a queue.

Parameters
[in]p_q: pointer to a queue.
Returns
NULL if queue is empty, else buffer address
wiced_bt_buffer_t* wiced_bt_getnext ( wiced_bt_buffer_t p_buf)

Return a pointer to the next buffer in a queue.

Parameters
[in]p_buf: pointer to the buffer to find the next one from.
Returns
NULL if no more buffers in the queue, else next buffer address
void wiced_bt_init_q ( wiced_bt_buffer_q_t p_q,
wiced_bt_lock_t p_lock 
)

Called by an application to initialize a AIROC buffer queue.

Pointers to lock and unlock functions may be NULL if application has handled preemption outside of the queue management code.

Returns
void
uint32_t wiced_bt_queue_get_count ( wiced_bt_buffer_q_t p_q)

Get the number of items in the queue.

Parameters
[in]p_q: pointer to a queue.
Returns
number of items in the queue
uint32_t wiced_bt_queue_is_empty ( wiced_bt_buffer_q_t p_q)

Check the status of a queue.

Parameters
[in]p_q: pointer to a queue.
Returns
TRUE if queue is empty, else FALSE
wiced_bt_buffer_t* wiced_bt_remove_from_queue ( wiced_bt_buffer_q_t p_q,
wiced_bt_buffer_t p_buf 
)

Dequeue a buffer from the middle of the queue.

Parameters
[in]p_q: pointer to a queue.
[in]p_buf: address of the buffer to dequeue
Returns
NULL if queue is empty, else buffer
wiced_bt_buffer_t* wiced_memory_alloc_long_term_mem_block ( int  size,
const char *  block_name 
)

Allocate long term memory, typically used for control blocks allocated through config, not expected to be freed during the lifetime of the application.

Parameters
[in]size: size of memory to be allocated
Returns
pointer to the allocated memory
void wiced_memory_free_long_term_mem_block ( wiced_bt_buffer_t p_mem)

Free long term memory, used to free memory allocated with wiced_memory_allocate_long_term, typically called during application shutdown.

Parameters
[in]p_mem: pointer memory to be freed
Returns
none
uint32_t wiced_memory_get_free_bytes ( void  )

Returns the number of free bytes of RAM left.

Returns
the number of free bytes of RAM left
void wiced_set_exception_callback ( pf_wiced_exception  pf_handler)

Set the exception callback.

Parameters
[in]pf_handler: Exception callback function
Returns
void