This is a fork due to permission issues
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of 6_songs-from-the-cloud by
mbed-client/nanostack-libservice/mbed-client-libservice/nsdynmemLIB.h@0:f7c60d3e7b8a, 2016-05-18 (annotated)
- Committer:
- maclobdell
- Date:
- Wed May 18 19:06:32 2016 +0000
- Revision:
- 0:f7c60d3e7b8a
clean version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maclobdell | 0:f7c60d3e7b8a | 1 | /* |
maclobdell | 0:f7c60d3e7b8a | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
maclobdell | 0:f7c60d3e7b8a | 3 | * SPDX-License-Identifier: Apache-2.0 |
maclobdell | 0:f7c60d3e7b8a | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
maclobdell | 0:f7c60d3e7b8a | 5 | * not use this file except in compliance with the License. |
maclobdell | 0:f7c60d3e7b8a | 6 | * You may obtain a copy of the License at |
maclobdell | 0:f7c60d3e7b8a | 7 | * |
maclobdell | 0:f7c60d3e7b8a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
maclobdell | 0:f7c60d3e7b8a | 9 | * |
maclobdell | 0:f7c60d3e7b8a | 10 | * Unless required by applicable law or agreed to in writing, software |
maclobdell | 0:f7c60d3e7b8a | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
maclobdell | 0:f7c60d3e7b8a | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
maclobdell | 0:f7c60d3e7b8a | 13 | * See the License for the specific language governing permissions and |
maclobdell | 0:f7c60d3e7b8a | 14 | * limitations under the License. |
maclobdell | 0:f7c60d3e7b8a | 15 | */ |
maclobdell | 0:f7c60d3e7b8a | 16 | |
maclobdell | 0:f7c60d3e7b8a | 17 | |
maclobdell | 0:f7c60d3e7b8a | 18 | /** |
maclobdell | 0:f7c60d3e7b8a | 19 | * \file nsdynmemLIB.h |
maclobdell | 0:f7c60d3e7b8a | 20 | * \brief Dynamical Memory API for library model |
maclobdell | 0:f7c60d3e7b8a | 21 | * |
maclobdell | 0:f7c60d3e7b8a | 22 | */ |
maclobdell | 0:f7c60d3e7b8a | 23 | #ifndef NSDYNMEMLIB_H_ |
maclobdell | 0:f7c60d3e7b8a | 24 | #define NSDYNMEMLIB_H_ |
maclobdell | 0:f7c60d3e7b8a | 25 | #ifdef __cplusplus |
maclobdell | 0:f7c60d3e7b8a | 26 | extern "C" { |
maclobdell | 0:f7c60d3e7b8a | 27 | #endif |
maclobdell | 0:f7c60d3e7b8a | 28 | |
maclobdell | 0:f7c60d3e7b8a | 29 | #include "ns_types.h" |
maclobdell | 0:f7c60d3e7b8a | 30 | |
maclobdell | 0:f7c60d3e7b8a | 31 | /*! |
maclobdell | 0:f7c60d3e7b8a | 32 | * \enum heap_fail_t |
maclobdell | 0:f7c60d3e7b8a | 33 | * \brief Dynamically heap system failure call back event types. |
maclobdell | 0:f7c60d3e7b8a | 34 | */ |
maclobdell | 0:f7c60d3e7b8a | 35 | typedef enum { |
maclobdell | 0:f7c60d3e7b8a | 36 | NS_DYN_MEM_NULL_FREE, /**< ns_dyn_mem_free(), NULL pointer free [obsolete - no longer faulted] */ |
maclobdell | 0:f7c60d3e7b8a | 37 | NS_DYN_MEM_DOUBLE_FREE, /**< ns_dyn_mem_free(), Possible double pointer free */ |
maclobdell | 0:f7c60d3e7b8a | 38 | NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, /**< Allocate size is 0 or smaller or size is bigger than max heap size */ |
maclobdell | 0:f7c60d3e7b8a | 39 | NS_DYN_MEM_POINTER_NOT_VALID, /**< ns_dyn_mem_free(), try to free pointer which not at heap sector */ |
maclobdell | 0:f7c60d3e7b8a | 40 | NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, /**< Heap system detect sector corruption */ |
maclobdell | 0:f7c60d3e7b8a | 41 | 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() */ |
maclobdell | 0:f7c60d3e7b8a | 42 | } heap_fail_t; |
maclobdell | 0:f7c60d3e7b8a | 43 | |
maclobdell | 0:f7c60d3e7b8a | 44 | /** |
maclobdell | 0:f7c60d3e7b8a | 45 | * /struct mem_stat_t |
maclobdell | 0:f7c60d3e7b8a | 46 | * /brief Struct for Memory stats Buffer structure |
maclobdell | 0:f7c60d3e7b8a | 47 | */ |
maclobdell | 0:f7c60d3e7b8a | 48 | typedef struct mem_stat_t { |
maclobdell | 0:f7c60d3e7b8a | 49 | /*Heap stats*/ |
maclobdell | 0:f7c60d3e7b8a | 50 | int16_t heap_sector_size; /**< Heap total Sector len. */ |
maclobdell | 0:f7c60d3e7b8a | 51 | int16_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */ |
maclobdell | 0:f7c60d3e7b8a | 52 | int16_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */ |
maclobdell | 0:f7c60d3e7b8a | 53 | int16_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */ |
maclobdell | 0:f7c60d3e7b8a | 54 | uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */ |
maclobdell | 0:f7c60d3e7b8a | 55 | uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */ |
maclobdell | 0:f7c60d3e7b8a | 56 | } mem_stat_t; |
maclobdell | 0:f7c60d3e7b8a | 57 | |
maclobdell | 0:f7c60d3e7b8a | 58 | /** |
maclobdell | 0:f7c60d3e7b8a | 59 | * \brief Init and set Dynamical heap pointer and length. |
maclobdell | 0:f7c60d3e7b8a | 60 | * |
maclobdell | 0:f7c60d3e7b8a | 61 | * \param heap_ptr Pointer to dynamically heap buffer |
maclobdell | 0:f7c60d3e7b8a | 62 | * \param heap_size size of the heap buffer |
maclobdell | 0:f7c60d3e7b8a | 63 | * \return None |
maclobdell | 0:f7c60d3e7b8a | 64 | */ |
maclobdell | 0:f7c60d3e7b8a | 65 | extern void ns_dyn_mem_init(uint8_t *heap, uint16_t h_size, void (*passed_fptr)(heap_fail_t), mem_stat_t *info_ptr); |
maclobdell | 0:f7c60d3e7b8a | 66 | |
maclobdell | 0:f7c60d3e7b8a | 67 | |
maclobdell | 0:f7c60d3e7b8a | 68 | /** |
maclobdell | 0:f7c60d3e7b8a | 69 | * \brief Free allocated memory. |
maclobdell | 0:f7c60d3e7b8a | 70 | * |
maclobdell | 0:f7c60d3e7b8a | 71 | * \param heap_ptr Pointer to allocated memory |
maclobdell | 0:f7c60d3e7b8a | 72 | * |
maclobdell | 0:f7c60d3e7b8a | 73 | * \return 0, Free OK |
maclobdell | 0:f7c60d3e7b8a | 74 | * \return <0, Free Fail |
maclobdell | 0:f7c60d3e7b8a | 75 | */ |
maclobdell | 0:f7c60d3e7b8a | 76 | extern void ns_dyn_mem_free(void *heap_ptr); |
maclobdell | 0:f7c60d3e7b8a | 77 | /** |
maclobdell | 0:f7c60d3e7b8a | 78 | * \brief Allocate temporary data. |
maclobdell | 0:f7c60d3e7b8a | 79 | * |
maclobdell | 0:f7c60d3e7b8a | 80 | * Space allocate started from beginning of the heap sector |
maclobdell | 0:f7c60d3e7b8a | 81 | * |
maclobdell | 0:f7c60d3e7b8a | 82 | * \param alloc_size Allocated data size |
maclobdell | 0:f7c60d3e7b8a | 83 | * |
maclobdell | 0:f7c60d3e7b8a | 84 | * \return 0, Allocate Fail |
maclobdell | 0:f7c60d3e7b8a | 85 | * \return >0, Pointer to allocated data sector. |
maclobdell | 0:f7c60d3e7b8a | 86 | */ |
maclobdell | 0:f7c60d3e7b8a | 87 | extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size); |
maclobdell | 0:f7c60d3e7b8a | 88 | /** |
maclobdell | 0:f7c60d3e7b8a | 89 | * \brief Allocate long period data. |
maclobdell | 0:f7c60d3e7b8a | 90 | * |
maclobdell | 0:f7c60d3e7b8a | 91 | * Space allocate started from end of the heap sector |
maclobdell | 0:f7c60d3e7b8a | 92 | * |
maclobdell | 0:f7c60d3e7b8a | 93 | * \param alloc_size Allocated data size |
maclobdell | 0:f7c60d3e7b8a | 94 | * |
maclobdell | 0:f7c60d3e7b8a | 95 | * \return 0, Allocate Fail |
maclobdell | 0:f7c60d3e7b8a | 96 | * \return >0, Pointer to allocated data sector. |
maclobdell | 0:f7c60d3e7b8a | 97 | */ |
maclobdell | 0:f7c60d3e7b8a | 98 | extern void *ns_dyn_mem_alloc(int16_t alloc_size); |
maclobdell | 0:f7c60d3e7b8a | 99 | #ifdef __cplusplus |
maclobdell | 0:f7c60d3e7b8a | 100 | } |
maclobdell | 0:f7c60d3e7b8a | 101 | #endif |
maclobdell | 0:f7c60d3e7b8a | 102 | #endif /* NSDYNMEMLIB_H_ */ |
maclobdell | 0:f7c60d3e7b8a | 103 |