Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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