NanoStack lib for Cortex-M4

Dependents:   mbedEndpointNetwork mbedEndpointNetworkMJK

Fork of Nanostack_lib by Sensinode

Committer:
Mika Karjalainen
Date:
Tue Jun 24 16:48:01 2014 +0300
Revision:
4:c449bead5cf3
Child:
11:1b7aaf37a131
Creating initial nanostack release

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_
Mika Karjalainen 4:c449bead5cf3 10
Mika Karjalainen 4:c449bead5cf3 11 /*!
Mika Karjalainen 4:c449bead5cf3 12 * \enum heap_fail_t
Mika Karjalainen 4:c449bead5cf3 13 * \brief Dynamically heap system failure call back event types.
Mika Karjalainen 4:c449bead5cf3 14 */
Mika Karjalainen 4:c449bead5cf3 15 typedef enum
Mika Karjalainen 4:c449bead5cf3 16 {
Mika Karjalainen 4:c449bead5cf3 17 NS_DYN_MEM_NULL_FREE, /**< ns_dyn_mem_free(), NULL pointer free */
Mika Karjalainen 4:c449bead5cf3 18 NS_DYN_MEM_DOUBLE_FREE, /**< ns_dyn_mem_free(), Possible double pointer free */
Mika Karjalainen 4:c449bead5cf3 19 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 20 NS_DYN_MEM_POINTER_NOT_VALID, /**< ns_dyn_mem_free(), try to free pointer which not at heap sector */
Mika Karjalainen 4:c449bead5cf3 21 NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, /**< Heap system detect sector corruption */
Mika Karjalainen 4:c449bead5cf3 22 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 23 }heap_fail_t;
Mika Karjalainen 4:c449bead5cf3 24
Mika Karjalainen 4:c449bead5cf3 25 /**
Mika Karjalainen 4:c449bead5cf3 26 * /struct mem_stat_t
Mika Karjalainen 4:c449bead5cf3 27 * /brief Struct for Memory stats Buffer structure
Mika Karjalainen 4:c449bead5cf3 28 */
Mika Karjalainen 4:c449bead5cf3 29 typedef struct mem_stat_t
Mika Karjalainen 4:c449bead5cf3 30 {
Mika Karjalainen 4:c449bead5cf3 31 /*Heap stats*/
Mika Karjalainen 4:c449bead5cf3 32 int16_t heap_sector_size; /**< Heap total Sector len. */
Mika Karjalainen 4:c449bead5cf3 33 int16_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
Mika Karjalainen 4:c449bead5cf3 34 int16_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
Mika Karjalainen 4:c449bead5cf3 35 int16_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
Mika Karjalainen 4:c449bead5cf3 36 uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */
Mika Karjalainen 4:c449bead5cf3 37 uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
Mika Karjalainen 4:c449bead5cf3 38 }mem_stat_t;
Mika Karjalainen 4:c449bead5cf3 39
Mika Karjalainen 4:c449bead5cf3 40 /**
Mika Karjalainen 4:c449bead5cf3 41 * \brief Init and set Dynamical heap pointer and length.
Mika Karjalainen 4:c449bead5cf3 42 *
Mika Karjalainen 4:c449bead5cf3 43 * \param heap_ptr Pointer to dynamically heap buffer
Mika Karjalainen 4:c449bead5cf3 44 * \param heap_size size of the heap buffer
Mika Karjalainen 4:c449bead5cf3 45 * \return None
Mika Karjalainen 4:c449bead5cf3 46 */
Mika Karjalainen 4:c449bead5cf3 47 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 48
Mika Karjalainen 4:c449bead5cf3 49
Mika Karjalainen 4:c449bead5cf3 50 /**
Mika Karjalainen 4:c449bead5cf3 51 * \brief Free allocated memory.
Mika Karjalainen 4:c449bead5cf3 52 *
Mika Karjalainen 4:c449bead5cf3 53 * \param heap_ptr Pointer to allocated memory
Mika Karjalainen 4:c449bead5cf3 54 *
Mika Karjalainen 4:c449bead5cf3 55 * \return 0, Free OK
Mika Karjalainen 4:c449bead5cf3 56 * \return <0, Free Fail
Mika Karjalainen 4:c449bead5cf3 57 */
Mika Karjalainen 4:c449bead5cf3 58 extern void ns_dyn_mem_free(void * heap_ptr);
Mika Karjalainen 4:c449bead5cf3 59 /**
Mika Karjalainen 4:c449bead5cf3 60 * \brief Allocate temporary data.
Mika Karjalainen 4:c449bead5cf3 61 *
Mika Karjalainen 4:c449bead5cf3 62 * Space allocate started from beginning of the heap sector
Mika Karjalainen 4:c449bead5cf3 63 *
Mika Karjalainen 4:c449bead5cf3 64 * \param alloc_size Allocated data size
Mika Karjalainen 4:c449bead5cf3 65 *
Mika Karjalainen 4:c449bead5cf3 66 * \return 0, Allocate Fail
Mika Karjalainen 4:c449bead5cf3 67 * \return >0, Pointer to allocated data sector.
Mika Karjalainen 4:c449bead5cf3 68 */
Mika Karjalainen 4:c449bead5cf3 69 extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size);
Mika Karjalainen 4:c449bead5cf3 70 /**
Mika Karjalainen 4:c449bead5cf3 71 * \brief Allocate long period data.
Mika Karjalainen 4:c449bead5cf3 72 *
Mika Karjalainen 4:c449bead5cf3 73 * Space allocate started from end of the heap sector
Mika Karjalainen 4:c449bead5cf3 74 *
Mika Karjalainen 4:c449bead5cf3 75 * \param alloc_size Allocated data size
Mika Karjalainen 4:c449bead5cf3 76 *
Mika Karjalainen 4:c449bead5cf3 77 * \return 0, Allocate Fail
Mika Karjalainen 4:c449bead5cf3 78 * \return >0, Pointer to allocated data sector.
Mika Karjalainen 4:c449bead5cf3 79 */
Mika Karjalainen 4:c449bead5cf3 80 extern void *ns_dyn_mem_alloc(int16_t alloc_size);
Mika Karjalainen 4:c449bead5cf3 81 #endif /* NSDYNMEMLIB_H_ */
Mika Karjalainen 4:c449bead5cf3 82