NanoStack lib for Cortex-M4

Dependents:   mbedEndpointNetwork mbedEndpointNetworkMJK

Fork of Nanostack_lib by Sensinode

Committer:
sscaglia
Date:
Tue Jul 15 02:52:09 2014 +0000
Revision:
14:b486fa9e70a7
Parent:
11:1b7aaf37a131
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mika Karjalainen 4:c449bead5cf3 1
Mika Karjalainen 4:c449bead5cf3 2
Mika Karjalainen 4:c449bead5cf3 3 /**
Mika Karjalainen 4:c449bead5cf3 4 * \file nsdynmemLIB.h
Mika Karjalainen 4:c449bead5cf3 5 * \brief Dynamical Memory API for library model
Mika Karjalainen 4:c449bead5cf3 6 *
Mika Karjalainen 4:c449bead5cf3 7 */
Mika Karjalainen 4:c449bead5cf3 8 #ifndef NSDYNMEMLIB_H_
Mika Karjalainen 4:c449bead5cf3 9 #define NSDYNMEMLIB_H_
jusu_81 11:1b7aaf37a131 10 #ifdef __cplusplus
jusu_81 11:1b7aaf37a131 11 extern "C" {
jusu_81 11:1b7aaf37a131 12 #endif
Mika Karjalainen 4:c449bead5cf3 13 /*!
Mika Karjalainen 4:c449bead5cf3 14 * \enum heap_fail_t
Mika Karjalainen 4:c449bead5cf3 15 * \brief Dynamically heap system failure call back event types.
Mika Karjalainen 4:c449bead5cf3 16 */
Mika Karjalainen 4:c449bead5cf3 17 typedef enum
Mika Karjalainen 4:c449bead5cf3 18 {
Mika Karjalainen 4:c449bead5cf3 19 NS_DYN_MEM_NULL_FREE, /**< ns_dyn_mem_free(), NULL pointer free */
Mika Karjalainen 4:c449bead5cf3 20 NS_DYN_MEM_DOUBLE_FREE, /**< ns_dyn_mem_free(), Possible double pointer free */
Mika Karjalainen 4:c449bead5cf3 21 NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, /**< Allocate size is 0 or smaller or size is bigger than max heap size */
Mika Karjalainen 4:c449bead5cf3 22 NS_DYN_MEM_POINTER_NOT_VALID, /**< ns_dyn_mem_free(), try to free pointer which not at heap sector */
Mika Karjalainen 4:c449bead5cf3 23 NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, /**< Heap system detect sector corruption */
Mika Karjalainen 4:c449bead5cf3 24 NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED /**< ns_dyn_mem_free(), ns_dyn_mem_temporary_alloc() or ns_dyn_mem_alloc() called before ns_dyn_mem_init() */
Mika Karjalainen 4:c449bead5cf3 25 }heap_fail_t;
Mika Karjalainen 4:c449bead5cf3 26
Mika Karjalainen 4:c449bead5cf3 27 /**
Mika Karjalainen 4:c449bead5cf3 28 * /struct mem_stat_t
Mika Karjalainen 4:c449bead5cf3 29 * /brief Struct for Memory stats Buffer structure
Mika Karjalainen 4:c449bead5cf3 30 */
Mika Karjalainen 4:c449bead5cf3 31 typedef struct mem_stat_t
Mika Karjalainen 4:c449bead5cf3 32 {
Mika Karjalainen 4:c449bead5cf3 33 /*Heap stats*/
Mika Karjalainen 4:c449bead5cf3 34 int16_t heap_sector_size; /**< Heap total Sector len. */
Mika Karjalainen 4:c449bead5cf3 35 int16_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
Mika Karjalainen 4:c449bead5cf3 36 int16_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
Mika Karjalainen 4:c449bead5cf3 37 int16_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
Mika Karjalainen 4:c449bead5cf3 38 uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */
Mika Karjalainen 4:c449bead5cf3 39 uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
Mika Karjalainen 4:c449bead5cf3 40 }mem_stat_t;
Mika Karjalainen 4:c449bead5cf3 41
Mika Karjalainen 4:c449bead5cf3 42 /**
Mika Karjalainen 4:c449bead5cf3 43 * \brief Init and set Dynamical heap pointer and length.
Mika Karjalainen 4:c449bead5cf3 44 *
Mika Karjalainen 4:c449bead5cf3 45 * \param heap_ptr Pointer to dynamically heap buffer
Mika Karjalainen 4:c449bead5cf3 46 * \param heap_size size of the heap buffer
Mika Karjalainen 4:c449bead5cf3 47 * \return None
Mika Karjalainen 4:c449bead5cf3 48 */
Mika Karjalainen 4:c449bead5cf3 49 extern void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t * info_ptr);
Mika Karjalainen 4:c449bead5cf3 50
Mika Karjalainen 4:c449bead5cf3 51
Mika Karjalainen 4:c449bead5cf3 52 /**
Mika Karjalainen 4:c449bead5cf3 53 * \brief Free allocated memory.
Mika Karjalainen 4:c449bead5cf3 54 *
Mika Karjalainen 4:c449bead5cf3 55 * \param heap_ptr Pointer to allocated memory
Mika Karjalainen 4:c449bead5cf3 56 *
Mika Karjalainen 4:c449bead5cf3 57 * \return 0, Free OK
Mika Karjalainen 4:c449bead5cf3 58 * \return <0, Free Fail
Mika Karjalainen 4:c449bead5cf3 59 */
Mika Karjalainen 4:c449bead5cf3 60 extern void ns_dyn_mem_free(void * heap_ptr);
Mika Karjalainen 4:c449bead5cf3 61 /**
Mika Karjalainen 4:c449bead5cf3 62 * \brief Allocate temporary data.
Mika Karjalainen 4:c449bead5cf3 63 *
Mika Karjalainen 4:c449bead5cf3 64 * Space allocate started from beginning of the heap sector
Mika Karjalainen 4:c449bead5cf3 65 *
Mika Karjalainen 4:c449bead5cf3 66 * \param alloc_size Allocated data size
Mika Karjalainen 4:c449bead5cf3 67 *
Mika Karjalainen 4:c449bead5cf3 68 * \return 0, Allocate Fail
Mika Karjalainen 4:c449bead5cf3 69 * \return >0, Pointer to allocated data sector.
Mika Karjalainen 4:c449bead5cf3 70 */
Mika Karjalainen 4:c449bead5cf3 71 extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size);
Mika Karjalainen 4:c449bead5cf3 72 /**
Mika Karjalainen 4:c449bead5cf3 73 * \brief Allocate long period data.
Mika Karjalainen 4:c449bead5cf3 74 *
Mika Karjalainen 4:c449bead5cf3 75 * Space allocate started from end of the heap sector
Mika Karjalainen 4:c449bead5cf3 76 *
Mika Karjalainen 4:c449bead5cf3 77 * \param alloc_size Allocated data size
Mika Karjalainen 4:c449bead5cf3 78 *
Mika Karjalainen 4:c449bead5cf3 79 * \return 0, Allocate Fail
Mika Karjalainen 4:c449bead5cf3 80 * \return >0, Pointer to allocated data sector.
Mika Karjalainen 4:c449bead5cf3 81 */
Mika Karjalainen 4:c449bead5cf3 82 extern void *ns_dyn_mem_alloc(int16_t alloc_size);
jusu_81 11:1b7aaf37a131 83 #ifdef __cplusplus
jusu_81 11:1b7aaf37a131 84 }
jusu_81 11:1b7aaf37a131 85 #endif
Mika Karjalainen 4:c449bead5cf3 86 #endif /* NSDYNMEMLIB_H_ */
Mika Karjalainen 4:c449bead5cf3 87