BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:55:34 2018 +0000
Revision:
2:798925c9e4a8
Parent:
1:9c5af431a1f1
bluetooth

Who changed what in which revision?

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