Jim Carver / Mbed OS mbed-cloud-workshop-connect-PIR

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Committer:
JimCarver
Date:
Fri Oct 12 21:22:49 2018 +0000
Revision:
0:6b753f761943
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 0:6b753f761943 1 /*
JimCarver 0:6b753f761943 2 * Copyright (c) 2014-2016 ARM Limited. All rights reserved.
JimCarver 0:6b753f761943 3 * SPDX-License-Identifier: Apache-2.0
JimCarver 0:6b753f761943 4 * Licensed under the Apache License, Version 2.0 (the License); you may
JimCarver 0:6b753f761943 5 * not use this file except in compliance with the License.
JimCarver 0:6b753f761943 6 * You may obtain a copy of the License at
JimCarver 0:6b753f761943 7 *
JimCarver 0:6b753f761943 8 * http://www.apache.org/licenses/LICENSE-2.0
JimCarver 0:6b753f761943 9 *
JimCarver 0:6b753f761943 10 * Unless required by applicable law or agreed to in writing, software
JimCarver 0:6b753f761943 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
JimCarver 0:6b753f761943 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JimCarver 0:6b753f761943 13 * See the License for the specific language governing permissions and
JimCarver 0:6b753f761943 14 * limitations under the License.
JimCarver 0:6b753f761943 15 */
JimCarver 0:6b753f761943 16
JimCarver 0:6b753f761943 17
JimCarver 0:6b753f761943 18 /**
JimCarver 0:6b753f761943 19 * \file nsdynmemLIB.h
JimCarver 0:6b753f761943 20 * \brief Dynamical Memory API for library model
JimCarver 0:6b753f761943 21 * nsdynmemlib provides access to one default heap, along with the ability to use extra user heaps.
JimCarver 0:6b753f761943 22 * ns_dyn_mem_alloc/free always access the default heap initialised by ns_dyn_mem_init.
JimCarver 0:6b753f761943 23 * ns_mem_alloc/free access a user heap initialised by ns_mem_init. User heaps are identified by a book-keeping pointer.
JimCarver 0:6b753f761943 24 */
JimCarver 0:6b753f761943 25
JimCarver 0:6b753f761943 26 #ifndef NSDYNMEMLIB_H_
JimCarver 0:6b753f761943 27 #define NSDYNMEMLIB_H_
JimCarver 0:6b753f761943 28 #ifdef __cplusplus
JimCarver 0:6b753f761943 29 extern "C" {
JimCarver 0:6b753f761943 30 #endif
JimCarver 0:6b753f761943 31
JimCarver 0:6b753f761943 32 #include "ns_types.h"
JimCarver 0:6b753f761943 33
JimCarver 0:6b753f761943 34 // Added to maintain backward compatibility with older implementation of ns_dyn_mem APIs
JimCarver 0:6b753f761943 35 #define NSDYNMEMLIB_API_VERSION 2
JimCarver 0:6b753f761943 36
JimCarver 0:6b753f761943 37 typedef uint16_t ns_mem_block_size_t; //external interface unsigned heap block size type
JimCarver 0:6b753f761943 38 typedef uint16_t ns_mem_heap_size_t; //total heap size type.
JimCarver 0:6b753f761943 39
JimCarver 0:6b753f761943 40 /*!
JimCarver 0:6b753f761943 41 * \enum heap_fail_t
JimCarver 0:6b753f761943 42 * \brief Dynamically heap system failure call back event types.
JimCarver 0:6b753f761943 43 */
JimCarver 0:6b753f761943 44 typedef enum {
JimCarver 0:6b753f761943 45 NS_DYN_MEM_NULL_FREE, /**< ns_dyn_mem_free(), NULL pointer free [obsolete - no longer faulted] */
JimCarver 0:6b753f761943 46 NS_DYN_MEM_DOUBLE_FREE, /**< ns_dyn_mem_free(), Possible double pointer free */
JimCarver 0:6b753f761943 47 NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, /**< Allocate size is 0 or smaller or size is bigger than max heap size */
JimCarver 0:6b753f761943 48 NS_DYN_MEM_POINTER_NOT_VALID, /**< ns_dyn_mem_free(), try to free pointer which not at heap sector */
JimCarver 0:6b753f761943 49 NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, /**< Heap system detect sector corruption */
JimCarver 0:6b753f761943 50 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() */
JimCarver 0:6b753f761943 51 } heap_fail_t;
JimCarver 0:6b753f761943 52
JimCarver 0:6b753f761943 53 /**
JimCarver 0:6b753f761943 54 * /struct mem_stat_t
JimCarver 0:6b753f761943 55 * /brief Struct for Memory stats Buffer structure
JimCarver 0:6b753f761943 56 */
JimCarver 0:6b753f761943 57 typedef struct mem_stat_t {
JimCarver 0:6b753f761943 58 /*Heap stats*/
JimCarver 0:6b753f761943 59 ns_mem_heap_size_t heap_sector_size; /**< Heap total Sector len. */
JimCarver 0:6b753f761943 60 ns_mem_heap_size_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
JimCarver 0:6b753f761943 61 ns_mem_heap_size_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
JimCarver 0:6b753f761943 62 ns_mem_heap_size_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
JimCarver 0:6b753f761943 63 uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */
JimCarver 0:6b753f761943 64 uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
JimCarver 0:6b753f761943 65 } mem_stat_t;
JimCarver 0:6b753f761943 66
JimCarver 0:6b753f761943 67
JimCarver 0:6b753f761943 68 typedef struct ns_mem_book ns_mem_book_t;
JimCarver 0:6b753f761943 69
JimCarver 0:6b753f761943 70 /**
JimCarver 0:6b753f761943 71 * \brief Init and set Dynamical heap pointer and length.
JimCarver 0:6b753f761943 72 *
JimCarver 0:6b753f761943 73 * \param heap_ptr Pointer to dynamically heap buffer
JimCarver 0:6b753f761943 74 * \param heap_size size of the heap buffer
JimCarver 0:6b753f761943 75 * \return None
JimCarver 0:6b753f761943 76 */
JimCarver 0:6b753f761943 77 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);
JimCarver 0:6b753f761943 78
JimCarver 0:6b753f761943 79
JimCarver 0:6b753f761943 80 /**
JimCarver 0:6b753f761943 81 * \brief Free allocated memory.
JimCarver 0:6b753f761943 82 *
JimCarver 0:6b753f761943 83 * \param heap_ptr Pointer to allocated memory
JimCarver 0:6b753f761943 84 *
JimCarver 0:6b753f761943 85 * \return 0, Free OK
JimCarver 0:6b753f761943 86 * \return <0, Free Fail
JimCarver 0:6b753f761943 87 */
JimCarver 0:6b753f761943 88 extern void ns_dyn_mem_free(void *heap_ptr);
JimCarver 0:6b753f761943 89 /**
JimCarver 0:6b753f761943 90 * \brief Allocate temporary data.
JimCarver 0:6b753f761943 91 *
JimCarver 0:6b753f761943 92 * Space allocate started from beginning of the heap sector
JimCarver 0:6b753f761943 93 *
JimCarver 0:6b753f761943 94 * \param alloc_size Allocated data size
JimCarver 0:6b753f761943 95 *
JimCarver 0:6b753f761943 96 * \return 0, Allocate Fail
JimCarver 0:6b753f761943 97 * \return >0, Pointer to allocated data sector.
JimCarver 0:6b753f761943 98 */
JimCarver 0:6b753f761943 99 extern void *ns_dyn_mem_temporary_alloc(ns_mem_block_size_t alloc_size);
JimCarver 0:6b753f761943 100 /**
JimCarver 0:6b753f761943 101 * \brief Allocate long period data.
JimCarver 0:6b753f761943 102 *
JimCarver 0:6b753f761943 103 * Space allocate started from end of the heap sector
JimCarver 0:6b753f761943 104 *
JimCarver 0:6b753f761943 105 * \param alloc_size Allocated data size
JimCarver 0:6b753f761943 106 *
JimCarver 0:6b753f761943 107 * \return 0, Allocate Fail
JimCarver 0:6b753f761943 108 * \return >0, Pointer to allocated data sector.
JimCarver 0:6b753f761943 109 */
JimCarver 0:6b753f761943 110 extern void *ns_dyn_mem_alloc(ns_mem_block_size_t alloc_size);
JimCarver 0:6b753f761943 111
JimCarver 0:6b753f761943 112 /**
JimCarver 0:6b753f761943 113 * \brief Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
JimCarver 0:6b753f761943 114 *
JimCarver 0:6b753f761943 115 * Get pointer to the statistics information, if one is set during the
JimCarver 0:6b753f761943 116 * initialization. This may be useful for statistics collection purposes.
JimCarver 0:6b753f761943 117 *
JimCarver 0:6b753f761943 118 * Note: the caller may not modify the returned structure.
JimCarver 0:6b753f761943 119 *
JimCarver 0:6b753f761943 120 * \return NULL, no mem_stat_t was given on initialization
JimCarver 0:6b753f761943 121 * \return !=0, Pointer to mem_stat_t.
JimCarver 0:6b753f761943 122 */
JimCarver 0:6b753f761943 123 extern const mem_stat_t *ns_dyn_mem_get_mem_stat(void);
JimCarver 0:6b753f761943 124
JimCarver 0:6b753f761943 125 /**
JimCarver 0:6b753f761943 126 * \brief Init and set Dynamical heap pointer and length.
JimCarver 0:6b753f761943 127 *
JimCarver 0:6b753f761943 128 * \param heap_ptr Pointer to dynamically heap buffer
JimCarver 0:6b753f761943 129 * \param heap_size size of the heap buffer
JimCarver 0:6b753f761943 130 * \return !=0, Pointer to ns_mem_book_t.
JimCarver 0:6b753f761943 131 */
JimCarver 0:6b753f761943 132 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);
JimCarver 0:6b753f761943 133
JimCarver 0:6b753f761943 134 /**
JimCarver 0:6b753f761943 135 * \brief Free allocated memory.
JimCarver 0:6b753f761943 136 *
JimCarver 0:6b753f761943 137 * \param book Address of book keeping structure
JimCarver 0:6b753f761943 138 * \param heap_ptr Pointer to allocated memory
JimCarver 0:6b753f761943 139 *
JimCarver 0:6b753f761943 140 * \return 0, Free OK
JimCarver 0:6b753f761943 141 * \return <0, Free Fail
JimCarver 0:6b753f761943 142 */
JimCarver 0:6b753f761943 143 extern void ns_mem_free(ns_mem_book_t *book, void *heap_ptr);
JimCarver 0:6b753f761943 144 /**
JimCarver 0:6b753f761943 145 * \brief Allocate temporary data.
JimCarver 0:6b753f761943 146 *
JimCarver 0:6b753f761943 147 * Space allocate started from beginning of the heap sector
JimCarver 0:6b753f761943 148 *
JimCarver 0:6b753f761943 149 * \param book Address of book keeping structure
JimCarver 0:6b753f761943 150 * \param alloc_size Allocated data size
JimCarver 0:6b753f761943 151 *
JimCarver 0:6b753f761943 152 * \return 0, Allocate Fail
JimCarver 0:6b753f761943 153 * \return >0, Pointer to allocated data sector.
JimCarver 0:6b753f761943 154 */
JimCarver 0:6b753f761943 155 extern void *ns_mem_temporary_alloc(ns_mem_book_t *book, ns_mem_block_size_t alloc_size);
JimCarver 0:6b753f761943 156 /**
JimCarver 0:6b753f761943 157 * \brief Allocate long period data.
JimCarver 0:6b753f761943 158 *
JimCarver 0:6b753f761943 159 * Space allocate started from end of the heap sector
JimCarver 0:6b753f761943 160 *
JimCarver 0:6b753f761943 161 * \param book Address of book keeping structure
JimCarver 0:6b753f761943 162 * \param alloc_size Allocated data size
JimCarver 0:6b753f761943 163 *
JimCarver 0:6b753f761943 164 * \return 0, Allocate Fail
JimCarver 0:6b753f761943 165 * \return >0, Pointer to allocated data sector.
JimCarver 0:6b753f761943 166 */
JimCarver 0:6b753f761943 167 extern void *ns_mem_alloc(ns_mem_book_t *book, ns_mem_block_size_t alloc_size);
JimCarver 0:6b753f761943 168
JimCarver 0:6b753f761943 169 /**
JimCarver 0:6b753f761943 170 * \brief Get pointer to the current mem_stat_t set via ns_mem_init.
JimCarver 0:6b753f761943 171 *
JimCarver 0:6b753f761943 172 * Get pointer to the statistics information, if one is set during the
JimCarver 0:6b753f761943 173 * initialization. This may be useful for statistics collection purposes.
JimCarver 0:6b753f761943 174 *
JimCarver 0:6b753f761943 175 * Note: the caller may not modify the returned structure.
JimCarver 0:6b753f761943 176 *
JimCarver 0:6b753f761943 177 * \param book Address of book keeping structure
JimCarver 0:6b753f761943 178 *
JimCarver 0:6b753f761943 179 * \return NULL, no mem_stat_t was given on initialization
JimCarver 0:6b753f761943 180 * \return !=0, Pointer to mem_stat_t.
JimCarver 0:6b753f761943 181 */
JimCarver 0:6b753f761943 182 extern const mem_stat_t *ns_mem_get_mem_stat(ns_mem_book_t *book);
JimCarver 0:6b753f761943 183
JimCarver 0:6b753f761943 184 #ifdef __cplusplus
JimCarver 0:6b753f761943 185 }
JimCarver 0:6b753f761943 186 #endif
JimCarver 0:6b753f761943 187 #endif /* NSDYNMEMLIB_H_ */
JimCarver 0:6b753f761943 188