BA / Mbed OS BaBoRo1
Committer:
borlanic
Date:
Thu Mar 29 07:02:09 2018 +0000
Revision:
0:380207fcb5c1
Encoder, IMU --> OK; Controller --> in bearbeitung

Who changed what in which revision?

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