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 /** \addtogroup platform */
elessair 0:f269e3021894 3 /** @{*/
elessair 0:f269e3021894 4 /* mbed Microcontroller Library
elessair 0:f269e3021894 5 * Copyright (c) 2006-2016 ARM Limited
elessair 0:f269e3021894 6 *
elessair 0:f269e3021894 7 * Licensed under the Apache License, Version 2.0 (the "License");
elessair 0:f269e3021894 8 * you may not use this file except in compliance with the License.
elessair 0:f269e3021894 9 * You may obtain a copy of the License at
elessair 0:f269e3021894 10 *
elessair 0:f269e3021894 11 * http://www.apache.org/licenses/LICENSE-2.0
elessair 0:f269e3021894 12 *
elessair 0:f269e3021894 13 * Unless required by applicable law or agreed to in writing, software
elessair 0:f269e3021894 14 * distributed under the License is distributed on an "AS IS" BASIS,
elessair 0:f269e3021894 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
elessair 0:f269e3021894 16 * See the License for the specific language governing permissions and
elessair 0:f269e3021894 17 * limitations under the License.
elessair 0:f269e3021894 18 */
elessair 0:f269e3021894 19
elessair 0:f269e3021894 20 #ifndef __MBED_MEM_TRACE_H__
elessair 0:f269e3021894 21 #define __MBED_MEM_TRACE_H__
elessair 0:f269e3021894 22
elessair 0:f269e3021894 23 #ifdef __cplusplus
elessair 0:f269e3021894 24 extern "C" {
elessair 0:f269e3021894 25 #endif
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 #include <stdint.h>
elessair 0:f269e3021894 28 #include <stddef.h>
elessair 0:f269e3021894 29
elessair 0:f269e3021894 30 /* Operation types for tracer */
elessair 0:f269e3021894 31 enum {
elessair 0:f269e3021894 32 MBED_MEM_TRACE_MALLOC,
elessair 0:f269e3021894 33 MBED_MEM_TRACE_REALLOC,
elessair 0:f269e3021894 34 MBED_MEM_TRACE_CALLOC,
elessair 0:f269e3021894 35 MBED_MEM_TRACE_FREE
elessair 0:f269e3021894 36 };
elessair 0:f269e3021894 37
elessair 0:f269e3021894 38 /* Prefix for the output of the default tracer */
elessair 0:f269e3021894 39 #define MBED_MEM_DEFAULT_TRACER_PREFIX "#"
elessair 0:f269e3021894 40
elessair 0:f269e3021894 41 /**
elessair 0:f269e3021894 42 * Type of the callback used by the memory tracer. This callback is called when a memory
elessair 0:f269e3021894 43 * allocation operation (malloc, realloc, calloc, free) is called and tracing is enabled
elessair 0:f269e3021894 44 * for that memory allocation function.
elessair 0:f269e3021894 45 *
elessair 0:f269e3021894 46 * @param op the ID of the operation (MBED_MEM_TRACE_MALLOC, MBED_MEM_TRACE_REALLOC,
elessair 0:f269e3021894 47 * MBED_MEM_TRACE_CALLOC or MBED_MEM_TRACE_FREE).
elessair 0:f269e3021894 48 * @param res the result that the memory operation returned (NULL for 'free').
elessair 0:f269e3021894 49 * @param caller the caller of the memory operation. Note that the value of 'caller' might be
elessair 0:f269e3021894 50 * unreliable.
elessair 0:f269e3021894 51 *
elessair 0:f269e3021894 52 * The rest of the parameters passed 'mbed_mem_trace_cb_t' are the same as the memory operations
elessair 0:f269e3021894 53 * that triggered its call (see 'man malloc' for details):
elessair 0:f269e3021894 54 *
elessair 0:f269e3021894 55 * - for malloc: cb(MBED_MEM_TRACE_MALLOC, res, caller, size).
elessair 0:f269e3021894 56 * - for realloc: cb(MBED_MEM_TRACE_REALLOC, res, caller, ptr, size).
elessair 0:f269e3021894 57 * - for calloc: cb(MBED_MEM_TRACE_CALLOC, res, caller, nmemb, size).
elessair 0:f269e3021894 58 * - for free: cb(MBED_MEM_TRACE_FREE, NULL, caller, ptr).
elessair 0:f269e3021894 59 */
elessair 0:f269e3021894 60 typedef void (*mbed_mem_trace_cb_t)(uint8_t op, void *res, void* caller, ...);
elessair 0:f269e3021894 61
elessair 0:f269e3021894 62 /**
elessair 0:f269e3021894 63 * Set the callback used by the memory tracer (use NULL for disable tracing).
elessair 0:f269e3021894 64 *
elessair 0:f269e3021894 65 * @param cb the callback to call on each memory operation.
elessair 0:f269e3021894 66 */
elessair 0:f269e3021894 67 void mbed_mem_trace_set_callback(mbed_mem_trace_cb_t cb);
elessair 0:f269e3021894 68
elessair 0:f269e3021894 69 /**
elessair 0:f269e3021894 70 * Trace a call to 'malloc'.
elessair 0:f269e3021894 71 * @param res the result of running 'malloc'.
elessair 0:f269e3021894 72 * @param size the 'size' argument given to 'malloc'.
elessair 0:f269e3021894 73 * @param caller the caller of the memory operation.
elessair 0:f269e3021894 74 * @return 'res' (the first argument).
elessair 0:f269e3021894 75 */
elessair 0:f269e3021894 76 void *mbed_mem_trace_malloc(void *res, size_t size, void *caller);
elessair 0:f269e3021894 77
elessair 0:f269e3021894 78 /**
elessair 0:f269e3021894 79 * Trace a call to 'realloc'.
elessair 0:f269e3021894 80 * @param res the result of running 'realloc'.
elessair 0:f269e3021894 81 * @param ptr the 'ptr' argument given to 'realloc'.
elessair 0:f269e3021894 82 * @param size the 'size' argument given to 'realloc'.
elessair 0:f269e3021894 83 *
elessair 0:f269e3021894 84 * @return 'res' (the first argument).
elessair 0:f269e3021894 85 */
elessair 0:f269e3021894 86 void *mbed_mem_trace_realloc(void *res, void *ptr, size_t size, void *caller);
elessair 0:f269e3021894 87
elessair 0:f269e3021894 88 /**
elessair 0:f269e3021894 89 * Trace a call to 'calloc'.
elessair 0:f269e3021894 90 * @param res the result of running 'calloc'.
elessair 0:f269e3021894 91 * @param nmemb the 'nmemb' argument given to 'calloc'.
elessair 0:f269e3021894 92 * @param size the 'size' argument given to 'calloc'.
elessair 0:f269e3021894 93 * @param caller the caller of the memory operation.
elessair 0:f269e3021894 94 * @Return 'res' (the first argument).
elessair 0:f269e3021894 95 */
elessair 0:f269e3021894 96 void *mbed_mem_trace_calloc(void *res, size_t num, size_t size, void *caller);
elessair 0:f269e3021894 97
elessair 0:f269e3021894 98 /**
elessair 0:f269e3021894 99 * Trace a call to 'free'.
elessair 0:f269e3021894 100 * @param ptr the 'ptr' argument given to 'free'.
elessair 0:f269e3021894 101 * @param caller the caller of the memory operation.
elessair 0:f269e3021894 102 */
elessair 0:f269e3021894 103 void mbed_mem_trace_free(void *ptr, void *caller);
elessair 0:f269e3021894 104
elessair 0:f269e3021894 105 /**
elessair 0:f269e3021894 106 * Default memory trace callback. DO NOT CALL DIRECTLY. It is meant to be used
elessair 0:f269e3021894 107 * as the second argument of 'mbed_mem_trace_setup'.
elessair 0:f269e3021894 108 *
elessair 0:f269e3021894 109 * The default callback outputs trace data using 'printf', in a format that's
elessair 0:f269e3021894 110 * easily parsable by an external tool. For each memory operation, the callback
elessair 0:f269e3021894 111 * outputs a line that begins with '#<op>:<0xresult>;<0xcaller>-':
elessair 0:f269e3021894 112 *
elessair 0:f269e3021894 113 * - 'op' identifies the memory operation ('m' for 'malloc', 'r' for 'realloc',
elessair 0:f269e3021894 114 * 'c' for 'calloc' and 'f' for 'free').
elessair 0:f269e3021894 115 * - 'result' (base 16) is the result of the memor operation. This is always NULL
elessair 0:f269e3021894 116 * for 'free', since 'free' doesn't return anything.
elessair 0:f269e3021894 117 * -'caller' (base 16) is the caller of the memory operation. Note that the value
elessair 0:f269e3021894 118 * of 'caller' might be unreliable.
elessair 0:f269e3021894 119 *
elessair 0:f269e3021894 120 * The rest of the output depends on the operation being traced:
elessair 0:f269e3021894 121 *
elessair 0:f269e3021894 122 * - for 'malloc': 'size', where 'size' is the original argument to 'malloc'.
elessair 0:f269e3021894 123 * - for 'realloc': '0xptr;size', where 'ptr' (base 16) and 'size' are the original arguments to 'realloc'.
elessair 0:f269e3021894 124 * - for 'calloc': 'nmemb;size', where 'nmemb' and 'size' are the original arguments to 'calloc'.
elessair 0:f269e3021894 125 * - for 'free': '0xptr', where 'ptr' (base 16) is the original argument to 'free'.
elessair 0:f269e3021894 126 *
elessair 0:f269e3021894 127 * Examples:
elessair 0:f269e3021894 128 *
elessair 0:f269e3021894 129 * - '#m:0x20003240;0x600d-50' encodes a 'malloc' that returned 0x20003240, was called
elessair 0:f269e3021894 130 * by the instruction at 0x600D with a the 'size' argument equal to 50.
elessair 0:f269e3021894 131 * - '#f:0x0;0x602f-0x20003240' encodes a 'free' that was called by the instruction at
elessair 0:f269e3021894 132 * 0x602f with the 'ptr' argument equal to 0x20003240.
elessair 0:f269e3021894 133 */
elessair 0:f269e3021894 134 void mbed_mem_trace_default_callback(uint8_t op, void *res, void *caller, ...);
elessair 0:f269e3021894 135
elessair 0:f269e3021894 136 #ifdef __cplusplus
elessair 0:f269e3021894 137 }
elessair 0:f269e3021894 138 #endif
elessair 0:f269e3021894 139
elessair 0:f269e3021894 140 #endif// #ifndef __MBED_MEM_TRACE_H__
elessair 0:f269e3021894 141
elessair 0:f269e3021894 142
elessair 0:f269e3021894 143 /** @}*/