mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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