mbed os with nrf51 internal bandgap enabled to read battery level

Dependents:   BLE_file_test BLE_Blink ExternalEncoder

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 /*
elessair 0:f269e3021894 2 * Copyright (c) 2014-2016 ARM Limited. All rights reserved.
elessair 0:f269e3021894 3 * SPDX-License-Identifier: Apache-2.0
elessair 0:f269e3021894 4 * Licensed under the Apache License, Version 2.0 (the License); you may
elessair 0:f269e3021894 5 * not use this file except in compliance with the License.
elessair 0:f269e3021894 6 * You may obtain a copy of the License at
elessair 0:f269e3021894 7 *
elessair 0:f269e3021894 8 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 9 *
elessair 0:f269e3021894 10 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
elessair 0:f269e3021894 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 13 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 14 * limitations under the License.
elessair 0:f269e3021894 15 */
elessair 0:f269e3021894 16
elessair 0:f269e3021894 17
elessair 0:f269e3021894 18 /**
elessair 0:f269e3021894 19 * \file nsdynmemLIB.h
elessair 0:f269e3021894 20 * \brief Dynamical Memory API for library model
elessair 0:f269e3021894 21 *
elessair 0:f269e3021894 22 */
elessair 0:f269e3021894 23 #ifndef NSDYNMEMLIB_H_
elessair 0:f269e3021894 24 #define NSDYNMEMLIB_H_
elessair 0:f269e3021894 25 #ifdef __cplusplus
elessair 0:f269e3021894 26 extern "C" {
elessair 0:f269e3021894 27 #endif
elessair 0:f269e3021894 28
elessair 0:f269e3021894 29 #include "ns_types.h"
elessair 0:f269e3021894 30
elessair 0:f269e3021894 31 /*!
elessair 0:f269e3021894 32 * \enum heap_fail_t
elessair 0:f269e3021894 33 * \brief Dynamically heap system failure call back event types.
elessair 0:f269e3021894 34 */
elessair 0:f269e3021894 35 typedef enum {
elessair 0:f269e3021894 36 NS_DYN_MEM_NULL_FREE, /**< ns_dyn_mem_free(), NULL pointer free [obsolete - no longer faulted] */
elessair 0:f269e3021894 37 NS_DYN_MEM_DOUBLE_FREE, /**< ns_dyn_mem_free(), Possible double pointer free */
elessair 0:f269e3021894 38 NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID, /**< Allocate size is 0 or smaller or size is bigger than max heap size */
elessair 0:f269e3021894 39 NS_DYN_MEM_POINTER_NOT_VALID, /**< ns_dyn_mem_free(), try to free pointer which not at heap sector */
elessair 0:f269e3021894 40 NS_DYN_MEM_HEAP_SECTOR_CORRUPTED, /**< Heap system detect sector corruption */
elessair 0:f269e3021894 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() */
elessair 0:f269e3021894 42 } heap_fail_t;
elessair 0:f269e3021894 43
elessair 0:f269e3021894 44 /**
elessair 0:f269e3021894 45 * /struct mem_stat_t
elessair 0:f269e3021894 46 * /brief Struct for Memory stats Buffer structure
elessair 0:f269e3021894 47 */
elessair 0:f269e3021894 48 typedef struct mem_stat_t {
elessair 0:f269e3021894 49 /*Heap stats*/
elessair 0:f269e3021894 50 int16_t heap_sector_size; /**< Heap total Sector len. */
elessair 0:f269e3021894 51 int16_t heap_sector_alloc_cnt; /**< Reserved Heap sector cnt. */
elessair 0:f269e3021894 52 int16_t heap_sector_allocated_bytes; /**< Reserved Heap data in bytes. */
elessair 0:f269e3021894 53 int16_t heap_sector_allocated_bytes_max; /**< Reserved Heap data in bytes max value. */
elessair 0:f269e3021894 54 uint32_t heap_alloc_total_bytes; /**< Total Heap allocated bytes. */
elessair 0:f269e3021894 55 uint32_t heap_alloc_fail_cnt; /**< Counter for Heap allocation fail. */
elessair 0:f269e3021894 56 } mem_stat_t;
elessair 0:f269e3021894 57
elessair 0:f269e3021894 58 /**
elessair 0:f269e3021894 59 * \brief Init and set Dynamical heap pointer and length.
elessair 0:f269e3021894 60 *
elessair 0:f269e3021894 61 * \param heap_ptr Pointer to dynamically heap buffer
elessair 0:f269e3021894 62 * \param heap_size size of the heap buffer
elessair 0:f269e3021894 63 * \return None
elessair 0:f269e3021894 64 */
elessair 0:f269e3021894 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);
elessair 0:f269e3021894 66
elessair 0:f269e3021894 67
elessair 0:f269e3021894 68 /**
elessair 0:f269e3021894 69 * \brief Free allocated memory.
elessair 0:f269e3021894 70 *
elessair 0:f269e3021894 71 * \param heap_ptr Pointer to allocated memory
elessair 0:f269e3021894 72 *
elessair 0:f269e3021894 73 * \return 0, Free OK
elessair 0:f269e3021894 74 * \return <0, Free Fail
elessair 0:f269e3021894 75 */
elessair 0:f269e3021894 76 extern void ns_dyn_mem_free(void *heap_ptr);
elessair 0:f269e3021894 77 /**
elessair 0:f269e3021894 78 * \brief Allocate temporary data.
elessair 0:f269e3021894 79 *
elessair 0:f269e3021894 80 * Space allocate started from beginning of the heap sector
elessair 0:f269e3021894 81 *
elessair 0:f269e3021894 82 * \param alloc_size Allocated data size
elessair 0:f269e3021894 83 *
elessair 0:f269e3021894 84 * \return 0, Allocate Fail
elessair 0:f269e3021894 85 * \return >0, Pointer to allocated data sector.
elessair 0:f269e3021894 86 */
elessair 0:f269e3021894 87 extern void *ns_dyn_mem_temporary_alloc(int16_t alloc_size);
elessair 0:f269e3021894 88 /**
elessair 0:f269e3021894 89 * \brief Allocate long period data.
elessair 0:f269e3021894 90 *
elessair 0:f269e3021894 91 * Space allocate started from end of the heap sector
elessair 0:f269e3021894 92 *
elessair 0:f269e3021894 93 * \param alloc_size Allocated data size
elessair 0:f269e3021894 94 *
elessair 0:f269e3021894 95 * \return 0, Allocate Fail
elessair 0:f269e3021894 96 * \return >0, Pointer to allocated data sector.
elessair 0:f269e3021894 97 */
elessair 0:f269e3021894 98 extern void *ns_dyn_mem_alloc(int16_t alloc_size);
elessair 0:f269e3021894 99
elessair 0:f269e3021894 100 /**
elessair 0:f269e3021894 101 * \brief Get pointer to the current mem_stat_t set via ns_dyn_mem_init.
elessair 0:f269e3021894 102 *
elessair 0:f269e3021894 103 * Get pointer to the statistics information, if one is set during the
elessair 0:f269e3021894 104 * initialization. This may be useful for statistics collection purposes.
elessair 0:f269e3021894 105 *
elessair 0:f269e3021894 106 * Note: the caller may not modify the returned structure.
elessair 0:f269e3021894 107 *
elessair 0:f269e3021894 108 * \return NULL, no mem_stat_t was given on initialization
elessair 0:f269e3021894 109 * \return !=0, Pointer to mem_stat_t.
elessair 0:f269e3021894 110 */
elessair 0:f269e3021894 111 extern const mem_stat_t *ns_dyn_mem_get_mem_stat(void);
elessair 0:f269e3021894 112
elessair 0:f269e3021894 113 #ifdef __cplusplus
elessair 0:f269e3021894 114 }
elessair 0:f269e3021894 115 #endif
elessair 0:f269e3021894 116 #endif /* NSDYNMEMLIB_H_ */
elessair 0:f269e3021894 117