Skip to content

Nanostack+mbed-client libservice update #4715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
/**
* \file nsdynmemLIB.h
* \brief Dynamical Memory API for library model
*
* nsdynmemlib provides access to one default heap, along with the ability to use extra user heaps.
* ns_dyn_mem_alloc/free always access the default heap initialised by ns_dyn_mem_init.
* ns_mem_alloc/free access a user heap initialised by ns_mem_init. User heaps are identified by a book-keeping pointer.
*/

#ifndef NSDYNMEMLIB_H_
#define NSDYNMEMLIB_H_
#ifdef __cplusplus
Expand All @@ -28,6 +31,12 @@ extern "C" {

#include "ns_types.h"

// Added to maintain backward compatibility with older implementation of ns_dyn_mem APIs
#define NSDYNMEMLIB_API_VERSION 2

typedef uint16_t ns_mem_block_size_t; //external interface unsigned heap block size type
typedef uint16_t ns_mem_heap_size_t; //total heap size type.

/*!
* \enum heap_fail_t
* \brief Dynamically heap system failure call back event types.
Expand All @@ -47,22 +56,25 @@ typedef enum {
*/
typedef struct mem_stat_t {
/*Heap stats*/
int16_t heap_sector_size; /**< Heap total Sector len. */
int16_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
int16_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
int16_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
ns_mem_heap_size_t heap_sector_size; /**< Heap total Sector len. */
ns_mem_heap_size_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
ns_mem_heap_size_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
ns_mem_heap_size_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */
uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
} mem_stat_t;


typedef struct ns_mem_book ns_mem_book_t;

/**
* \brief Init and set Dynamical heap pointer and length.
*
* \param heap_ptr Pointer to dynamically heap buffer
* \param heap_size size of the heap buffer
* \return None
*/
extern void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr);
extern void ns_dyn_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr);


/**
Expand All @@ -84,7 +96,7 @@ extern void ns_dyn_mem_free(void *heap_ptr);
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size);
extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
/**
* \brief Allocate long period data.
*
Expand All @@ -95,7 +107,7 @@ extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size);
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
extern void *ns_dyn_mem_alloc(int16_t alloc_size);
extern void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size);

/**
* \brief Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
Expand All @@ -110,6 +122,65 @@ extern void *ns_dyn_mem_alloc(int16_t alloc_size);
*/
extern const mem_stat_t *ns_dyn_mem_get_mem_stat(void);

/**
* \brief Init and set Dynamical heap pointer and length.
*
* \param heap_ptr Pointer to dynamically heap buffer
* \param heap_size size of the heap buffer
* \return !=0, Pointer to ns_mem_book_t.
*/
extern ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr);

/**
* \brief Free allocated memory.
*
* \param book Address of book keeping structure
* \param heap_ptr Pointer to allocated memory
*
* \return 0, Free OK
* \return <0, Free Fail
*/
extern void ns_mem_free(ns_mem_book_t *book, void *heap_ptr);
/**
* \brief Allocate temporary data.
*
* Space allocate started from beginning of the heap sector
*
* \param book Address of book keeping structure
* \param alloc_size Allocated data size
*
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
extern void *ns_mem_temporary_alloc(ns_mem_book_t *book, ns_mem_block_size_t alloc_size);
/**
* \brief Allocate long period data.
*
* Space allocate started from end of the heap sector
*
* \param book Address of book keeping structure
* \param alloc_size Allocated data size
*
* \return 0, Allocate Fail
* \return >0, Pointer to allocated data sector.
*/
extern void *ns_mem_alloc(ns_mem_book_t *book, ns_mem_block_size_t alloc_size);

/**
* \brief Get pointer to the current mem_stat_t set via ns_mem_init.
*
* Get pointer to the statistics information, if one is set during the
* initialization. This may be useful for statistics collection purposes.
*
* Note: the caller may not modify the returned structure.
*
* \param book Address of book keeping structure
*
* \return NULL, no mem_stat_t was given on initialization
* \return !=0, Pointer to mem_stat_t.
*/
extern const mem_stat_t *ns_mem_get_mem_stat(ns_mem_book_t *book);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion features/FEATURE_COMMON_PAL/nanostack-libservice/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"extraIncludes": [
"mbed-client-libservice"
],
"dependencies": {},
"dependencies": {
"mbed-trace": "ARMmbed/mbed-trace"
},
"targetDependencies": {}
}
Loading